/*
    CaPriCe Forever - Amstrad CPC 464/664/6128 emulator
    Copyright (C) 2014-2018 by Frédéric Coste

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/


#include "z80dasm.h"
#include "..\STD\strings.h"


/*****************************************************************************
 *
 *   z80dasm.c
 *   Portable Z80 disassembler
 *
 *   Copyright Juergen Buchmueller, all rights reserved.
 *
 *   - This source code is released as freeware for non-commercial purposes.
 *   - You are free to use and redistribute this code in modified or
 *     unmodified form, provided you list me in the credits.
 *   - If you modify this source code, you must add a notice to each modified
 *     source file that it has been changed.  If you're a nice person, you
 *     will clearly mark each change too.  :)
 *   - If you wish to use this for commercial purposes, please contact me at
 *     pullmoll@t-online.de
 *   - The author of this copywritten work reserves the right to change the
 *     terms of its usage and license at any time, including retroactively
 *   - This entire notice must remain in the source code.
 *
 *****************************************************************************/


//===================
// PATCH begin
#ifdef _PATCH_ENABLE

#endif /* _PATCH_ENABLE */
// PATCH end
//===================


#ifdef __cplusplus
extern "C" {
#endif

 
enum Z80Mnemonics
{
	zADC  , zADD  , zAND  , zBIT  , zCALL , zCCF  , zCP   , zCPD  ,
	zCPDR , zCPI  , zCPIR , zCPL  , zDAA  , zDB   , zDEC  , zDI   ,
	zDJNZ , zEI   , zEX   , zEXX  , zHLT  , zIM   , zIN   , zINC  ,
	zIND  , zINDR , zINI  , zINIR , zJP   , zJR   , zLD   , zLDD  ,
	zLDDR , zLDI  , zLDIR , zNEG  , zNOP  , zOR   , zOTDR , zOTIR ,
	zOUT  , zOUTD , zOUTI , zPOP  , zPUSH , zRES  , zRET  , zRETI ,
	zRETN , zRL   , zRLA  , zRLC  , zRLCA , zRLD  , zRR   , zRRA  ,
	zRRC  , zRRCA , zRRD  , zRST  , zSBC  , zSCF  , zSET  , zSLA  ,
	zSLL  , zSRA  , zSRL  , zSUB  , zXOR
};
static const char * Z80MnemonicStr[] =
{
	"adc" , "add" , "and" , "bit" , "call", "ccf" , "cp"  , "cpd" ,
	"cpdr", "cpi" , "cpir", "cpl" , "daa" , "db"  , "dec" , "di"  ,
	"djnz", "ei"  , "ex"  , "exx" , "halt", "im"  , "in"  , "inc" ,
	"ind" , "indr", "ini" , "inir", "jp"  , "jr"  , "ld"  , "ldd" ,
	"lddr", "ldi" , "ldir", "neg" , "nop" , "or"  , "otdr", "otir",
	"out" , "outd", "outi", "pop" , "push", "res" , "ret" , "reti",
	"retn", "rl"  , "rla" , "rlc" , "rlca", "rld" , "rr"  , "rra" ,
	"rrc" , "rrca", "rrd" , "rst" , "sbc" , "scf" , "set" , "sla" ,
	"sll" , "sra" , "srl" , "sub" , "xor"
};


typedef struct
{
	unsigned char mnemonic;
	const char *arguments;
} Z80DASM;

static const Z80DASM mnemonic_xx_cb[256] =
{
	{zRLC,"b=Y"},   {zRLC,"c=Y"},   {zRLC,"d=Y"},   {zRLC,"e=Y"},
	{zRLC,"H=Y"},   {zRLC,"l=Y"},   {zRLC,"Y"},     {zRLC,"a=Y"},
	{zRRC,"b=Y"},   {zRRC,"c=Y"},   {zRRC,"d=Y"},   {zRRC,"e=Y"},
	{zRRC,"h=Y"},   {zRRC,"l=Y"},   {zRRC,"Y"},     {zRRC,"a=Y"},
	{zRL,"b=Y"},    {zRL,"c=Y"},    {zRL,"d=Y"},    {zRL,"e=Y"},
	{zRL,"h=Y"},    {zRL,"l=Y"},    {zRL,"Y"},      {zRL,"a=Y"},
	{zRR,"b=Y"},    {zRR,"c=Y"},    {zRR,"d=Y"},    {zRR,"e=Y"},
	{zRR,"h=Y"},    {zRR,"l=Y"},    {zRR,"Y"},      {zRR,"a=Y"},
	{zSLA,"b=Y"},   {zSLA,"c=Y"},   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=5,Y"}, {zSET,"l=5,Y"}, {zSET,"5,Y"},   {zSET,"a=5,Y"},
	{zSET,"b=6,Y"}, {zSET,"c=6,Y"}, {zSET,"d=6,Y"}, {zSET,"e=6,Y"},
	{zSET,"h=6,Y"}, {zSET,"l=6,Y"}, {zSET,"6,Y"},   {zSET,"a=6,Y"},
	{zSET,"b=7,Y"}, {zSET,"c=7,Y"}, {zSET,"d=7,Y"}, {zSET,"e=7,Y"},
	{zSET,"h=7,Y"}, {zSET,"l=7,Y"}, {zSET,"7,Y"},   {zSET,"a=7,Y"}
};

static const Z80DASM mnemonic_cb[256] =
{
	{zRLC,"b"},     {zRLC,"c"},     {zRLC,"d"},      {zRLC,"e"},
	{zRLC,"h"},     {zRLC,"l"},     {zRLC,"(hl)H"},  {zRLC,"a"},
	{zRRC,"b"},     {zRRC,"c"},     {zRRC,"d"},      {zRRC,"e"},
	{zRRC,"h"},     {zRRC,"l"},     {zRRC,"(hl)H"},  {zRRC,"a"},
	{zRL,"b"},      {zRL,"c"},      {zRL,"d"},       {zRL,"e"},
	{zRL,"h"},      {zRL,"l"},      {zRL,"(hl)H"},   {zRL,"a"},
	{zRR,"b"},      {zRR,"c"},      {zRR,"d"},       {zRR,"e"},
	{zRR,"h"},      {zRR,"l"},      {zRR,"(hl)H"},   {zRR,"a"},
	{zSLA,"b"},     {zSLA,"c"},     {zSLA,"d"},      {zSLA,"e"},
	{zSLA,"h"},     {zSLA,"l"},     {zSLA,"(hl)H"},  {zSLA,"a"},
	{zSRA,"b"},     {zSRA,"c"},     {zSRA,"d"},      {zSRA,"e"},
	{zSRA,"h"},     {zSRA,"l"},     {zSRA,"(hl)H"},  {zSRA,"a"},
	{zSLL,"b"},     {zSLL,"c"},     {zSLL,"d"},      {zSLL,"e"},
	{zSLL,"h"},     {zSLL,"l"},     {zSLL,"(hl)H"},  {zSLL,"a"},
	{zSRL,"b"},     {zSRL,"c"},     {zSRL,"d"},      {zSRL,"e"},
	{zSRL,"h"},     {zSRL,"l"},     {zSRL,"(hl)H"},  {zSRL,"a"},
	{zBIT,"0,b"},   {zBIT,"0,c"},   {zBIT,"0,d"},    {zBIT,"0,e"},
	{zBIT,"0,h"},   {zBIT,"0,l"},   {zBIT,"0,(hl)H"},{zBIT,"0,a"},
	{zBIT,"1,b"},   {zBIT,"1,c"},   {zBIT,"1,d"},    {zBIT,"1,e"},
	{zBIT,"1,h"},   {zBIT,"1,l"},   {zBIT,"1,(hl)H"},{zBIT,"1,a"},
	{zBIT,"2,b"},   {zBIT,"2,c"},   {zBIT,"2,d"},    {zBIT,"2,e"},
	{zBIT,"2,h"},   {zBIT,"2,l"},   {zBIT,"2,(hl)H"},{zBIT,"2,a"},
	{zBIT,"3,b"},   {zBIT,"3,c"},   {zBIT,"3,d"},    {zBIT,"3,e"},
	{zBIT,"3,h"},   {zBIT,"3,l"},   {zBIT,"3,(hl)H"},{zBIT,"3,a"},
	{zBIT,"4,b"},   {zBIT,"4,c"},   {zBIT,"4,d"},    {zBIT,"4,e"},
	{zBIT,"4,h"},   {zBIT,"4,l"},   {zBIT,"4,(hl)H"},{zBIT,"4,a"},
	{zBIT,"5,b"},   {zBIT,"5,c"},   {zBIT,"5,d"},    {zBIT,"5,e"},
	{zBIT,"5,h"},   {zBIT,"5,l"},   {zBIT,"5,(hl)H"},{zBIT,"5,a"},
	{zBIT,"6,b"},   {zBIT,"6,c"},   {zBIT,"6,d"},    {zBIT,"6,e"},
	{zBIT,"6,h"},   {zBIT,"6,l"},   {zBIT,"6,(hl)H"},{zBIT,"6,a"},
	{zBIT,"7,b"},   {zBIT,"7,c"},   {zBIT,"7,d"},    {zBIT,"7,e"},
	{zBIT,"7,h"},   {zBIT,"7,l"},   {zBIT,"7,(hl)H"},{zBIT,"7,a"},
	{zRES,"0,b"},   {zRES,"0,c"},   {zRES,"0,d"},    {zRES,"0,e"},
	{zRES,"0,h"},   {zRES,"0,l"},   {zRES,"0,(hl)H"},{zRES,"0,a"},
	{zRES,"1,b"},   {zRES,"1,c"},   {zRES,"1,d"},    {zRES,"1,e"},
	{zRES,"1,h"},   {zRES,"1,l"},   {zRES,"1,(hl)H"},{zRES,"1,a"},
	{zRES,"2,b"},   {zRES,"2,c"},   {zRES,"2,d"},    {zRES,"2,e"},
	{zRES,"2,h"},   {zRES,"2,l"},   {zRES,"2,(hl)H"},{zRES,"2,a"},
	{zRES,"3,b"},   {zRES,"3,c"},   {zRES,"3,d"},    {zRES,"3,e"},
	{zRES,"3,h"},   {zRES,"3,l"},   {zRES,"3,(hl)H"},{zRES,"3,a"},
	{zRES,"4,b"},   {zRES,"4,c"},   {zRES,"4,d"},    {zRES,"4,e"},
	{zRES,"4,h"},   {zRES,"4,l"},   {zRES,"4,(hl)H"},{zRES,"4,a"},
	{zRES,"5,b"},   {zRES,"5,c"},   {zRES,"5,d"},    {zRES,"5,e"},
	{zRES,"5,h"},   {zRES,"5,l"},   {zRES,"5,(hl)H"},{zRES,"5,a"},
	{zRES,"6,b"},   {zRES,"6,c"},   {zRES,"6,d"},    {zRES,"6,e"},
	{zRES,"6,h"},   {zRES,"6,l"},   {zRES,"6,(hl)H"},{zRES,"6,a"},
	{zRES,"7,b"},   {zRES,"7,c"},   {zRES,"7,d"},    {zRES,"7,e"},
	{zRES,"7,h"},   {zRES,"7,l"},   {zRES,"7,(hl)H"},{zRES,"7,a"},
	{zSET,"0,b"},   {zSET,"0,c"},   {zSET,"0,d"},    {zSET,"0,e"},
	{zSET,"0,h"},   {zSET,"0,l"},   {zSET,"0,(hl)H"},{zSET,"0,a"},
	{zSET,"1,b"},   {zSET,"1,c"},   {zSET,"1,d"},    {zSET,"1,e"},
	{zSET,"1,h"},   {zSET,"1,l"},   {zSET,"1,(hl)H"},{zSET,"1,a"},
	{zSET,"2,b"},   {zSET,"2,c"},   {zSET,"2,d"},    {zSET,"2,e"},
	{zSET,"2,h"},   {zSET,"2,l"},   {zSET,"2,(hl)H"},{zSET,"2,a"},
	{zSET,"3,b"},   {zSET,"3,c"},   {zSET,"3,d"},    {zSET,"3,e"},
	{zSET,"3,h"},   {zSET,"3,l"},   {zSET,"3,(hl)H"},{zSET,"3,a"},
	{zSET,"4,b"},   {zSET,"4,c"},   {zSET,"4,d"},    {zSET,"4,e"},
	{zSET,"4,h"},   {zSET,"4,l"},   {zSET,"4,(hl)H"},{zSET,"4,a"},
	{zSET,"5,b"},   {zSET,"5,c"},   {zSET,"5,d"},    {zSET,"5,e"},
	{zSET,"5,h"},   {zSET,"5,l"},   {zSET,"5,(hl)H"},{zSET,"5,a"},
	{zSET,"6,b"},   {zSET,"6,c"},   {zSET,"6,d"},    {zSET,"6,e"},
	{zSET,"6,h"},   {zSET,"6,l"},   {zSET,"6,(hl)H"},{zSET,"6,a"},
	{zSET,"7,b"},   {zSET,"7,c"},   {zSET,"7,d"},    {zSET,"7,e"},
	{zSET,"7,h"},   {zSET,"7,l"},   {zSET,"7,(hl)H"},{zSET,"7,a"}
};

static const Z80DASM mnemonic_ed[256] =
{
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zIN,"b,(c)"},  {zOUT,"(c),b"}, {zSBC,"hl,bc"}, {zLD,"(W),bc"},
	{zNEG,0},       {zRETN,0},      {zIM,"0"},      {zLD,"i,a"},
	{zIN,"c,(c)"},  {zOUT,"(c),c"}, {zADC,"hl,bc"}, {zLD,"bc,(W)"},
	{zNEG,"*"},     {zRETI,0},      {zIM,"0"},      {zLD,"r,a"},
	{zIN,"d,(c)"},  {zOUT,"(c),d"}, {zSBC,"hl,de"}, {zLD,"(W),de"},
	{zNEG,"*"},     {zRETN,0},      {zIM,"1"},      {zLD,"a,i"},
	{zIN,"e,(c)"},  {zOUT,"(c),e"}, {zADC,"hl,de"}, {zLD,"de,(W)"},
	{zNEG,"*"},     {zRETI,0},      {zIM,"2"},      {zLD,"a,r"},
	{zIN,"h,(c)"},  {zOUT,"(c),h"}, {zSBC,"hl,hl"}, {zLD,"(W),hl"},
	{zNEG,"*"},     {zRETN,0},      {zIM,"0"},      {zRRD,"(hl)"},
	{zIN,"l,(c)"},  {zOUT,"(c),l"}, {zADC,"hl,hl"}, {zLD,"hl,(W)"},
	{zNEG,"*"},     {zRETI,0},      {zIM,"0"},      {zRLD,"(hl)"},
	{zIN,"0,(c)"},  {zOUT,"(c),0"}, {zSBC,"hl,sp"}, {zLD,"(W),sp"},
	{zNEG,"*"},     {zRETN,0},      {zIM,"1"},      {zDB,"?"},
	{zIN,"a,(c)"},  {zOUT,"(c),a"}, {zADC,"hl,sp"}, {zLD,"sp,(W)"},
	{zNEG,"*"},     {zRETI,0},      {zIM,"2"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLDI,0},       {zCPI,0},       {zINI,0},       {zOUTI,0},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLDD,0},       {zCPD,0},       {zIND,0},       {zOUTD,0},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLDIR,0},      {zCPIR,0},      {zINIR,0},      {zOTIR,0},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLDDR,0},      {zCPDR,0},      {zINDR,0},      {zOTDR,0},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"}
};

static const Z80DASM mnemonic_xx[256] =
{
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zADD,"I,bc"},  {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zADD,"I,de"},  {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zLD,"I,N"},    {zLD,"(W),I"},  {zINC,"I"},
	{zINC,"Ih"},    {zDEC,"Ih"},    {zLD,"Ih,B"},   {zDB,"?"},
	{zDB,"?"},      {zADD,"I,I"},   {zLD,"I,(W)"},  {zDEC,"I"},
	{zINC,"Il"},    {zDEC,"Il"},    {zLD,"Il,B"},   {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zINC,"X"},     {zDEC,"X"},     {zLD,"X,B"},    {zDB,"?"},
	{zDB,"?"},      {zADD,"I,sp"},  {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLD,"b,Ih"},   {zLD,"b,Il"},   {zLD,"b,X"},    {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLD,"c,Ih"},   {zLD,"c,Il"},   {zLD,"c,X"},    {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLD,"d,Ih"},   {zLD,"d,Il"},   {zLD,"d,X"},    {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLD,"e,Ih"},   {zLD,"e,Il"},   {zLD,"e,X"},    {zDB,"?"},
	{zLD,"Ih,b"},   {zLD,"Ih,c"},   {zLD,"Ih,d"},   {zLD,"Ih,e"},
	{zLD,"Ih,Ih"},  {zLD,"Ih,Il"},  {zLD,"h,X"},    {zLD,"Ih,a"},
	{zLD,"Il,b"},   {zLD,"Il,c"},   {zLD,"Il,d"},   {zLD,"Il,e"},
	{zLD,"Il,Ih"},  {zLD,"Il,Il"},  {zLD,"l,X"},    {zLD,"Il,a"},
	{zLD,"X,b"},    {zLD,"X,c"},    {zLD,"X,d"},    {zLD,"X,e"},
	{zLD,"X,h"},    {zLD,"X,l"},    {zDB,"?"},      {zLD,"X,a"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zLD,"a,Ih"},   {zLD,"a,Il"},   {zLD,"a,X"},    {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zADD,"a,Ih"},  {zADD,"a,Il"},  {zADD,"a,X"},   {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zADC,"a,Ih"},  {zADC,"a,Il"},  {zADC,"a,X"},   {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zSUB,"Ih"},    {zSUB,"Il"},    {zSUB,"X"},     {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zSBC,"a,Ih"},  {zSBC,"a,Il"},  {zSBC,"a,X"},   {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zAND,"Ih"},    {zAND,"Il"},    {zAND,"X"},     {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zXOR,"Ih"},    {zXOR,"Il"},    {zXOR,"X"},     {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zOR,"Ih"},     {zOR,"Il"},     {zOR,"X"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zCP,"Ih"},     {zCP,"Il"},     {zCP,"X"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"cb"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zPOP,"I"},     {zDB,"?"},      {zEX,"(sp),I"},
	{zDB,"?"},      {zPUSH,"I"},    {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zJP,"(I)"},    {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zLD,"sp,I"},   {zDB,"?"},      {zDB,"?"},
	{zDB,"?"},      {zDB,"?"},      {zDB,"?"},      {zDB,"?"}
};

static const Z80DASM mnemonic_main[256] =
{
	{zNOP,0},       {zLD,"bc,N"},   {zLD,"(bc),a"}, {zINC,"bc"},
	{zINC,"b"},     {zDEC,"b"},     {zLD,"b,B"},    {zRLCA,0},
	{zEX,"af,af'"}, {zADD,"hl,bc"}, {zLD,"a,(bc)"}, {zDEC,"bc"},
	{zINC,"c"},     {zDEC,"c"},     {zLD,"c,B"},    {zRRCA,0},
	{zDJNZ,"O"},    {zLD,"de,N"},   {zLD,"(de),a"}, {zINC,"de"},
	{zINC,"d"},     {zDEC,"d"},     {zLD,"d,B"},    {zRLA,0},
	{zJR,"O"},      {zADD,"hl,de"}, {zLD,"a,(de)"}, {zDEC,"de"},
	{zINC,"e"},     {zDEC,"e"},     {zLD,"e,B"},    {zRRA,0},
	{zJR,"nz,O"},   {zLD,"hl,N"},   {zLD,"(W),hl"}, {zINC,"hl"},
	{zINC,"h"},     {zDEC,"h"},     {zLD,"h,B"},    {zDAA,0},
	{zJR,"z,O"},    {zADD,"hl,hl"}, {zLD,"hl,(W)"}, {zDEC,"hl"},
	{zINC,"l"},     {zDEC,"l"},     {zLD,"l,B"},    {zCPL,0},
	{zJR,"nc,O"},   {zLD,"sp,N"},   {zLD,"(W),a"},  {zINC,"sp"},
	{zINC,"(hl)H"}, {zDEC,"(hl)H"}, {zLD,"(hl),B"}, {zSCF,0},
	{zJR,"c,O"},    {zADD,"hl,sp"}, {zLD,"a,(W)"},  {zDEC,"sp"},
	{zINC,"a"},     {zDEC,"a"},     {zLD,"a,B"},    {zCCF,0},
	{zLD,"b,b"},    {zLD,"b,c"},    {zLD,"b,d"},    {zLD,"b,e"},
	{zLD,"b,h"},    {zLD,"b,l"},    {zLD,"b,(hl)"}, {zLD,"b,a"},
	{zLD,"c,b"},    {zLD,"c,c"},    {zLD,"c,d"},    {zLD,"c,e"},
	{zLD,"c,h"},    {zLD,"c,l"},    {zLD,"c,(hl)"}, {zLD,"c,a"},
	{zLD,"d,b"},    {zLD,"d,c"},    {zLD,"d,d"},    {zLD,"d,e"},
	{zLD,"d,h"},    {zLD,"d,l"},    {zLD,"d,(hl)"}, {zLD,"d,a"},
	{zLD,"e,b"},    {zLD,"e,c"},    {zLD,"e,d"},    {zLD,"e,e"},
	{zLD,"e,h"},    {zLD,"e,l"},    {zLD,"e,(hl)"}, {zLD,"e,a"},
	{zLD,"h,b"},    {zLD,"h,c"},    {zLD,"h,d"},    {zLD,"h,e"},
	{zLD,"h,h"},    {zLD,"h,l"},    {zLD,"h,(hl)"}, {zLD,"h,a"},
	{zLD,"l,b"},    {zLD,"l,c"},    {zLD,"l,d"},    {zLD,"l,e"},
	{zLD,"l,h"},    {zLD,"l,l"},    {zLD,"l,(hl)"}, {zLD,"l,a"},
	{zLD,"(hl),b"}, {zLD,"(hl),c"}, {zLD,"(hl),d"}, {zLD,"(hl),e"},
	{zLD,"(hl),h"}, {zLD,"(hl),l"}, {zHLT,0},       {zLD,"(hl),a"},
	{zLD,"a,b"},    {zLD,"a,c"},    {zLD,"a,d"},    {zLD,"a,e"},
	{zLD,"a,h"},    {zLD,"a,l"},    {zLD,"a,(hl)"}, {zLD,"a,a"},
	{zADD,"a,b"},   {zADD,"a,c"},   {zADD,"a,d"},   {zADD,"a,e"},
	{zADD,"a,h"},   {zADD,"a,l"},   {zADD,"a,(hl)"},{zADD,"a,a"},
	{zADC,"a,b"},   {zADC,"a,c"},   {zADC,"a,d"},   {zADC,"a,e"},
	{zADC,"a,h"},   {zADC,"a,l"},   {zADC,"a,(hl)"},{zADC,"a,a"},
	{zSUB,"b"},     {zSUB,"c"},     {zSUB,"d"},     {zSUB,"e"},
	{zSUB,"h"},     {zSUB,"l"},     {zSUB,"(hl)"},  {zSUB,"a"},
	{zSBC,"a,b"},   {zSBC,"a,c"},   {zSBC,"a,d"},   {zSBC,"a,e"},
	{zSBC,"a,h"},   {zSBC,"a,l"},   {zSBC,"a,(hl)"},{zSBC,"a,a"},
	{zAND,"b"},     {zAND,"c"},     {zAND,"d"},     {zAND,"e"},
	{zAND,"h"},     {zAND,"l"},     {zAND,"(hl)H"}, {zAND,"a"},
	{zXOR,"b"},     {zXOR,"c"},     {zXOR,"d"},     {zXOR,"e"},
	{zXOR,"h"},     {zXOR,"l"},     {zXOR,"(hl)H"}, {zXOR,"a"},
	{zOR,"b"},      {zOR,"c"},      {zOR,"d"},      {zOR,"e"},
	{zOR,"h"},      {zOR,"l"},      {zOR,"(hl)H"},  {zOR,"a"},
	{zCP,"b"},      {zCP,"c"},      {zCP,"d"},      {zCP,"e"},
	{zCP,"h"},      {zCP,"l"},      {zCP,"(hl)H"},  {zCP,"a"},
	{zRET,"nz"},    {zPOP,"bc"},    {zJP,"nz,A"},   {zJP,"A"},
	{zCALL,"nz,A"}, {zPUSH,"bc"},   {zADD,"a,B"},   {zRST,"V"},
	{zRET,"z"},     {zRET,0},       {zJP,"z,A"},    {zDB,"cb"},
	{zCALL,"z,A"},  {zCALL,"A"},    {zADC,"a,B"},   {zRST,"V"},
	{zRET,"nc"},    {zPOP,"de"},    {zJP,"nc,A"},   {zOUT,"(P),a"},
	{zCALL,"nc,A"}, {zPUSH,"de"},   {zSUB,"B"},     {zRST,"V"},
	{zRET,"c"},     {zEXX,0},       {zJP,"c,A"},    {zIN,"a,(P)"},
	{zCALL,"c,A"},  {zDB,"dd"},     {zSBC,"a,B"},   {zRST,"V"},
	{zRET,"po"},    {zPOP,"hl"},    {zJP,"po,A"},   {zEX,"(sp),hl"},
	{zCALL,"po,A"}, {zPUSH,"hl"},   {zAND,"B"},     {zRST,"V"},
	{zRET,"pe"},    {zJP,"(hl)"},   {zJP,"pe,A"},   {zEX,"de,hl"},
	{zCALL,"pe,A"}, {zDB,"ed"},     {zXOR,"B"},     {zRST,"V"},
	{zRET,"p"},     {zPOP,"af"},    {zJP,"p,A"},    {zDI,0},
	{zCALL,"p,A"},  {zPUSH,"af"},   {zOR,"B"},      {zRST,"V"},
	{zRET,"m"},     {zLD,"sp,hl"},  {zJP,"m,A"},    {zEI,0},
	{zCALL,"m,A"},  {zDB,"fd"},     {zCP,"B"},      {zRST,"V"}
};



tULong Z80dasmDecodeInstruction(tULong addr, TZ80dasmParam* Param)
{
const Z80DASM *d;
const char *ixy;
tUShort ea;
tUShort pc;
tUChar OpCode;
tChar offset;
char* MachineCodeNextChar;
char* InstructionNextChar;
char* MemoryContentNextChar;
//tZ80* Z80 = Param->NativeCPC->Z80;
//tUShort xy;

  if (Param->NativeCPC == cNull) return 0;
  if (Param->MachineCode == cNull) return 0;
  if (Param->Instruction == cNull) return 0;
  if (Param->MemoryContent == cNull) return 0;

  pc = (tUShort)addr;
	OpCode = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
  addr++;

	MachineCodeNextChar = StringAddHexByte((tChar*)Param->MachineCode, OpCode);
  MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
  Param->Instruction[0] = '\0';
  Param->MemoryContent[0] = '\0';

  d = cNull;
  while (d == cNull)
  {
	  switch (OpCode)
	  {
	    case 0xcb:
      {
        OpCode = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
        addr++;
				MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, OpCode);
				MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
		    d = &mnemonic_cb[OpCode];
      }
		  break;

	    case 0xed:
      {
        OpCode = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
        addr++;
				MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, OpCode);
				MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
		    d = &mnemonic_ed[OpCode];
      }
		  break;

	    case 0xdd:
      {
		    ixy = "ix";
        OpCode = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
        addr++;
				MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, OpCode);
				MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
		    if (OpCode == 0xcb)
		    {
          offset = (tChar)Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, (tUChar)offset);
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
          OpCode = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, OpCode);
          MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
					/*if (Param->DummyZ80 == 0)
          {
            xy = _IX;
          }*/
          //ea = (xy + offset) & 0xffff;
			    d = &mnemonic_xx_cb[OpCode];
		    }
		    else
        {
          d = &mnemonic_xx[OpCode];
        }
      }
      break;

	    case 0xfd:
      {
		    ixy = "iy";
        OpCode = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
        addr++;
				MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, OpCode);
				MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
		    if (OpCode == 0xcb)
		    {
          offset = (tChar)Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, (tUChar)offset);
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
          OpCode = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, OpCode);
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
					/*if (Param->DummyZ80 == 0)
          {
            xy = _IY;
          }*/
          //ea = (xy + offset) & 0xffff;
			    d = &mnemonic_xx_cb[OpCode];
		    }
		    else
        {
          d = &mnemonic_xx[OpCode];
        }
      }
		  break;

	    default:
      {
		    d = &mnemonic_main[OpCode];
      }
		  break;
    }
	}

  // Add mnemonic
	InstructionNextChar = StringAddString((tChar*)Param->Instruction,
                                        (const tChar*)Z80MnemonicStr[d->mnemonic]);

  // Add arguments
	if (d->arguments)
	{
    const char *src = d->arguments;

		InstructionNextChar = StringAddSpace((tChar*)InstructionNextChar);

		while (*src)
		{
			switch (*src)
			{
			  case '?':   /* illegal opcode */
        {
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"ILLEGAL ");
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)Param->MachineCode);
        }
        break;

			  case 'A':
        {
          ea = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
          ea += Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress) << 8;
          addr++;
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"#");
					InstructionNextChar = StringAddHexShort((tChar*)InstructionNextChar, ea);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, (ea & 0xff));
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, ((ea >> 8) & 0xff));
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
        }
        break;

			  case 'B':   /* Byte op arg */
        {
          ea = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"#");
					InstructionNextChar = StringAddHexByte((tChar*)InstructionNextChar, ea);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, ea);
          MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
        }
				break;

			  case 'N':   /* Immediate 16 bit */
        {
          ea = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
          ea += Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress) << 8;
          addr++;
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"#");
					InstructionNextChar = StringAddHexShort((tChar*)InstructionNextChar, ea);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, (ea & 0xff));
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, ((ea >> 8) & 0xff));
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
        }
				break;

  			case 'O':   /* Offset relative to PC */
        {
				  offset = (tChar)Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"#");
					InstructionNextChar = StringAddHexShort((tChar*)InstructionNextChar, ((pc + offset + 2) & 0xffff));
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, (tUChar)offset);
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
        }
				break;

			  case 'P':   /* Port number */
        {
          ea = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"#");
					InstructionNextChar = StringAddHexByte((tChar*)InstructionNextChar, ea);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, ea);
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
        }
				break;

			  case 'V':   /* Restart vector */
        {
				  ea = OpCode & 0x38;
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"#");
					InstructionNextChar = StringAddHexByte((tChar*)InstructionNextChar, ea);
        }
				break;

			  case 'W':   /* Memory address word */
        {
          ea = Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
          ea += Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress) << 8;
          addr++;
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"#");
					InstructionNextChar = StringAddHexShort((tChar*)InstructionNextChar, ea);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, (ea & 0xff));
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, ((ea >> 8) & 0xff));
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
        }
				break;

			  case 'X':
        {
				  offset = (tChar)Param->ReadFunction(Param->NativeCPC, addr - Param->StartAddress);
          addr++;
          //ea = (xy + offset) & 0xffff;
        }
			  case 'Y':
        {
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"(");
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)ixy);
          if (offset >= 0)
          {
						InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"+#");
						InstructionNextChar = StringAddHexByte((tChar*)InstructionNextChar, offset);
          }
          else
          {
						InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)"-#");
						InstructionNextChar = StringAddHexByte((tChar*)InstructionNextChar, -offset);
          }
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)")");
					MachineCodeNextChar = StringAddHexByte((tChar*)MachineCodeNextChar, ((tUChar)offset & 0xff));
					MachineCodeNextChar = StringAddSpace((tChar*)MachineCodeNextChar);
        }
				break;

			  case 'I':
        {
					InstructionNextChar = StringAddString((tChar*)InstructionNextChar, (const tChar*)ixy);
        }
				break;

			  case 'H':
        {
          tUChar byte = 0;
          if (Param->DummyZ80 == 0)
          {
            byte = Param->ReadFunction(Param->NativeCPC, Param->NativeCPC->Z80->Regs.HL.UShort.l);
          }
					MemoryContentNextChar = StringAddString((tChar*)Param->MemoryContent, (const tChar*)"(HL)=#");
          StringAddHexByte((tChar*)MemoryContentNextChar, byte);
        }
				break;

        default:
        {
          InstructionNextChar = StringAddChar((tChar*)InstructionNextChar, *src);
        }
      }
      
      src++;
    }
  }

  return addr;
}
//---------------------------------------------------------------------------


#ifdef __cplusplus
}  /* End of the 'extern "C"' block */
#endif

