1 /*****************************************************************************
2 *
3 * z80dasm.c
4 * Portable Z80 disassembler
5 *
6 * Copyright (C) 1998 Juergen Buchmueller, all rights reserved.
7 *
8 * - This source code is released as freeware for non-commercial purposes.
9 * - You are free to use and redistribute this code in modified or
10 * unmodified form, provided you list me in the credits.
11 * - If you modify this source code, you must add a notice to each modified
12 * source file that it has been changed. If you're a nice person, you
13 * will clearly mark each change too. :)
14 * - If you wish to use this for commercial purposes, please contact me at
15 * pullmoll@t-online.de
16 * - The author of this copywritten work reserves the right to change the
17 * terms of its usage and license at any time, including retroactively
18 * - This entire notice must remain in the source code.
19 *
20 *****************************************************************************/
21
22 #include <stdio.h>
23 #include <string.h>
24 #ifdef MAME_DEBUG
25 #include "driver.h"
26 #include "mamedbg.h"
27 #include "z80.h"
28
29 enum e_mnemonics {
30 zADC ,zADD ,zAND ,zBIT ,zCALL ,zCCF ,zCP ,zCPD ,
31 zCPDR ,zCPI ,zCPIR ,zCPL ,zDAA ,zDB ,zDEC ,zDI ,
32 zDJNZ ,zEI ,zEX ,zEXX ,zHLT ,zIM ,zIN ,zINC ,
33 zIND ,zINDR ,zINI ,zINIR ,zJP ,zJR ,zLD ,zLDD ,
34 zLDDR ,zLDI ,zLDIR ,zNEG ,zNOP ,zOR ,zOTDR ,zOTIR ,
35 zOUT ,zOUTD ,zOUTI ,zPOP ,zPUSH ,zRES ,zRET ,zRETI ,
36 zRETN ,zRL ,zRLA ,zRLC ,zRLCA ,zRLD ,zRR ,zRRA ,
37 zRRC ,zRRCA ,zRRD ,zRST ,zSBC ,zSCF ,zSET ,zSLA ,
38 zSLL ,zSRA ,zSRL ,zSUB ,zXOR
39 };
40
41 static const char *s_mnemonic[] = {
42 "adc", "add", "and", "bit", "call","ccf", "cp", "cpd",
43 "cpdr","cpi", "cpir","cpl", "daa", "db", "dec", "di",
44 "djnz","ei", "ex", "exx", "halt","im", "in", "inc",
45 "ind", "indr","ini", "inir","jp", "jr", "ld", "ldd",
46 "lddr","ldi", "ldir","neg", "nop", "or", "otdr","otir",
47 "out", "outd","outi","pop", "push","res", "ret", "reti",
48 "retn","rl", "rla", "rlc", "rlca","rld", "rr", "rra",
49 "rrc", "rrca","rrd", "rst", "sbc", "scf", "set", "sla",
50 "sll", "sra", "srl", "sub", "xor "
51 };
52
53 typedef struct {
54 UINT8 access;
55 UINT8 mnemonic;
56 const char *arguments;
57 } z80dasm;
58
59 #define _0 EA_NONE
60 #define _JP EA_ABS_PC
61 #define _JR EA_REL_PC
62 #define _RM EA_MEM_RD
63 #define _WM EA_MEM_WR
64 #define _RW EA_MEM_RDWR
65 #define _RP EA_PORT_RD
66 #define _WP EA_PORT_WR
67
68 static z80dasm mnemonic_xx_cb[256]= {
69 {_RW,zRLC,"b=Y"}, {_RW,zRLC,"c=Y"}, {_RW,zRLC,"d=Y"}, {_RW,zRLC,"e=Y"},
70 {_RW,zRLC,"h=Y"}, {_RW,zRLC,"l=Y"}, {_RW,zRLC,"Y"}, {_RW,zRLC,"a=Y"},
71 {_RW,zRRC,"b=Y"}, {_RW,zRRC,"c=Y"}, {_RW,zRRC,"d=Y"}, {_RW,zRRC,"e=Y"},
72 {_RW,zRRC,"h=Y"}, {_RW,zRRC,"l=Y"}, {_RW,zRRC,"Y"}, {_RW,zRRC,"a=Y"},
73 {_RW,zRL,"b=Y"}, {_RW,zRL,"c=Y"}, {_RW,zRL,"d=Y"}, {_RW,zRL,"e=Y"},
74 {_RW,zRL,"h=Y"}, {_RW,zRL,"l=Y"}, {_RW,zRL,"Y"}, {_RW,zRL,"a=Y"},
75 {_RW,zRR,"b=Y"}, {_RW,zRR,"c=Y"}, {_RW,zRR,"d=Y"}, {_RW,zRR,"e=Y"},
76 {_RW,zRR,"h=Y"}, {_RW,zRR,"l=Y"}, {_RW,zRR,"Y"}, {_RW,zRR,"a=Y"},
77 {_RW,zSLA,"b=Y"}, {_RW,zSLA,"c=Y"}, {_RW,zSLA,"d=Y"}, {_RW,zSLA,"e=Y"},
78 {_RW,zSLA,"h=Y"}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
131 {_WM,zSET,"b=7,Y"}, {_WM,zSET,"c=7,Y"}, {_WM,zSET,"d=7,Y"}, {_WM,zSET,"e=7,Y"},
132 {_WM,zSET,"h=7,Y"}, {_WM,zSET,"l=7,Y"}, {_WM,zSET,"7,Y"}, {_WM,zSET,"a=7,Y"}
133 };
134
135 static z80dasm mnemonic_cb[256] = {
136 {_0, zRLC,"b"}, {_0, zRLC,"c"}, {_0, zRLC,"d"}, {_0, zRLC,"e"},
137 {_0, zRLC,"h"}, {_0, zRLC,"l"}, {_RW,zRLC,"(hl)"}, {_0, zRLC,"a"},
138 {_0, zRRC,"b"}, {_0, zRRC,"c"}, {_0, zRRC,"d"}, {_0, zRRC,"e"},
139 {_0, zRRC,"h"}, {_0, zRRC,"l"}, {_RW,zRRC,"(hl)"}, {_0, zRRC,"a"},
140 {_0, zRL,"b"}, {_0, zRL,"c"}, {_0, zRL,"d"}, {_0, zRL,"e"},
141 {_0, zRL,"h"}, {_0, zRL,"l"}, {_RW,zRL,"(hl)"}, {_0, zRL,"a"},
142 {_0, zRR,"b"}, {_0, zRR,"c"}, {_0, zRR,"d"}, {_0, zRR,"e"},
143 {_0, zRR,"h"}, {_0, zRR,"l"}, {_RW,zRR,"(hl)"}, {_0, zRR,"a"},
144 {_0, zSLA,"b"}, {_0, zSLA,"c"}, {_0, zSLA,"d"}, {_0, zSLA,"e"},
145 {_0, zSLA,"h"}, {_0, zSLA,"l"}, {_RW,zSLA,"(hl)"}, {_0, zSLA,"a"},
146 {_0, zSRA,"b"}, {_0, zSRA,"c"}, {_0, zSRA,"d"}, {_0, zSRA,"e"},
147 {_0, zSRA,"h"}, {_0, zSRA,"l"}, {_RW,zSRA,"(hl)"}, {_0, zSRA,"a"},
148 {_0, zSLL,"b"}, {_0, zSLL,"c"}, {_0, zSLL,"d"}, {_0, zSLL,"e"},
149 {_0, zSLL,"h"}, {_0, zSLL,"l"}, {_RW,zSLL,"(hl)"}, {_0, zSLL,"a"},
150 {_0, zSRL,"b"}, {_0, zSRL,"c"}, {_0, zSRL,"d"}, {_0, zSRL,"e"},
151 {_0, zSRL,"h"}, {_0, zSRL,"l"}, {_RW,zSRL,"(hl)"}, {_0, zSRL,"a"},
152 {_0, zBIT,"0,b"}, {_0, zBIT,"0,c"}, {_0, zBIT,"0,d"}, {_0, zBIT,"0,e"},
153 {_0, zBIT,"0,h"}, {_0, zBIT,"0,l"}, {_RM,zBIT,"0,(hl)"},{_0, zBIT,"0,a"},
154 {_0, zBIT,"1,b"}, {_0, zBIT,"1,c"}, {_0, zBIT,"1,d"}, {_0, zBIT,"1,e"},
155 {_0, zBIT,"1,h"}, {_0, zBIT,"1,l"}, {_RM,zBIT,"1,(hl)"},{_0, zBIT,"1,a"},
156 {_0, zBIT,"2,b"}, {_0, zBIT,"2,c"}, {_0, zBIT,"2,d"}, {_0, zBIT,"2,e"},
157 {_0, zBIT,"2,h"}, {_0, zBIT,"2,l"}, {_RM,zBIT,"2,(hl)"},{_0, zBIT,"2,a"},
158 {_0, zBIT,"3,b"}, {_0, zBIT,"3,c"}, {_0, zBIT,"3,d"}, {_0, zBIT,"3,e"},
159 {_0, zBIT,"3,h"}, {_0, zBIT,"3,l"}, {_RM,zBIT,"3,(hl)"},{_0, zBIT,"3,a"},
160 {_0, zBIT,"4,b"}, {_0, zBIT,"4,c"}, {_0, zBIT,"4,d"}, {_0, zBIT,"4,e"},
161 {_0, zBIT,"4,h"}, {_0, zBIT,"4,l"}, {_RM,zBIT,"4,(hl)"},{_0, zBIT,"4,a"},
162 {_0, zBIT,"5,b"}, {_0, zBIT,"5,c"}, {_0, zBIT,"5,d"}, {_0, zBIT,"5,e"},
163 {_0, zBIT,"5,h"}, {_0, zBIT,"5,l"}, {_RM,zBIT,"5,(hl)"},{_0, zBIT,"5,a"},
164 {_0, zBIT,"6,b"}, {_0, zBIT,"6,c"}, {_0, zBIT,"6,d"}, {_0, zBIT,"6,e"},
165 {_0, zBIT,"6,h"}, {_0, zBIT,"6,l"}, {_RM,zBIT,"6,(hl)"},{_0, zBIT,"6,a"},
166 {_0, zBIT,"7,b"}, {_0, zBIT,"7,c"}, {_0, zBIT,"7,d"}, {_0, zBIT,"7,e"},
167 {_0, zBIT,"7,h"}, {_0, zBIT,"7,l"}, {_RM,zBIT,"7,(hl)"},{_0, zBIT,"7,a"},
168 {_0, zRES,"0,b"}, {_0, zRES,"0,c"}, {_0, zRES,"0,d"}, {_0, zRES,"0,e"},
169 {_0, zRES,"0,h"}, {_0, zRES,"0,l"}, {_WM,zRES,"0,(hl)"},{_0, zRES,"0,a"},
170 {_0, zRES,"1,b"}, {_0, zRES,"1,c"}, {_0, zRES,"1,d"}, {_0, zRES,"1,e"},
171 {_0, zRES,"1,h"}, {_0, zRES,"1,l"}, {_WM,zRES,"1,(hl)"},{_0, zRES,"1,a"},
172 {_0, zRES,"2,b"}, {_0, zRES,"2,c"}, {_0, zRES,"2,d"}, {_0, zRES,"2,e"},
173 {_0, zRES,"2,h"}, {_0, zRES,"2,l"}, {_WM,zRES,"2,(hl)"},{_0, zRES,"2,a"},
174 {_0, zRES,"3,b"}, {_0, zRES,"3,c"}, {_0, zRES,"3,d"}, {_0, zRES,"3,e"},
175 {_0, zRES,"3,h"}, {_0, zRES,"3,l"}, {_WM,zRES,"3,(hl)"},{_0, zRES,"3,a"},
176 {_0, zRES,"4,b"}, {_0, zRES,"4,c"}, {_0, zRES,"4,d"}, {_0, zRES,"4,e"},
177 {_0, zRES,"4,h"}, {_0, zRES,"4,l"}, {_WM,zRES,"4,(hl)"},{_0, zRES,"4,a"},
178 {_0, zRES,"5,b"}, {_0, zRES,"5,c"}, {_0, zRES,"5,d"}, {_0, zRES,"5,e"},
179 {_0, zRES,"5,h"}, {_0, zRES,"5,l"}, {_WM,zRES,"5,(hl)"},{_0, zRES,"5,a"},
180 {_0, zRES,"6,b"}, {_0, zRES,"6,c"}, {_0, zRES,"6,d"}, {_0, zRES,"6,e"},
181 {_0, zRES,"6,h"}, {_0, zRES,"6,l"}, {_WM,zRES,"6,(hl)"},{_0, zRES,"6,a"},
182 {_0, zRES,"7,b"}, {_0, zRES,"7,c"}, {_0, zRES,"7,d"}, {_0, zRES,"7,e"},
183 {_0, zRES,"7,h"}, {_0, zRES,"7,l"}, {_WM,zRES,"7,(hl)"},{_0, zRES,"7,a"},
184 {_0, zSET,"0,b"}, {_0, zSET,"0,c"}, {_0, zSET,"0,d"}, {_0, zSET,"0,e"},
185 {_0, zSET,"0,h"}, {_0, zSET,"0,l"}, {_WM,zSET,"0,(hl)"},{_0, zSET,"0,a"},
186 {_0, zSET,"1,b"}, {_0, zSET,"1,c"}, {_0, zSET,"1,d"}, {_0, zSET,"1,e"},
187 {_0, zSET,"1,h"}, {_0, zSET,"1,l"}, {_WM,zSET,"1,(hl)"},{_0, zSET,"1,a"},
188 {_0, zSET,"2,b"}, {_0, zSET,"2,c"}, {_0, zSET,"2,d"}, {_0, zSET,"2,e"},
189 {_0, zSET,"2,h"}, {_0, zSET,"2,l"}, {_WM,zSET,"2,(hl)"},{_0, zSET,"2,a"},
190 {_0, zSET,"3,b"}, {_0, zSET,"3,c"}, {_0, zSET,"3,d"}, {_0, zSET,"3,e"},
191 {_0, zSET,"3,h"}, {_0, zSET,"3,l"}, {_WM,zSET,"3,(hl)"},{_0, zSET,"3,a"},
192 {_0, zSET,"4,b"}, {_0, zSET,"4,c"}, {_0, zSET,"4,d"}, {_0, zSET,"4,e"},
193 {_0, zSET,"4,h"}, {_0, zSET,"4,l"}, {_WM,zSET,"4,(hl)"},{_0, zSET,"4,a"},
194 {_0, zSET,"5,b"}, {_0, zSET,"5,c"}, {_0, zSET,"5,d"}, {_0, zSET,"5,e"},
195 {_0, zSET,"5,h"}, {_0, zSET,"5,l"}, {_WM,zSET,"5,(hl)"},{_0, zSET,"5,a"},
196 {_0, zSET,"6,b"}, {_0, zSET,"6,c"}, {_0, zSET,"6,d"}, {_0, zSET,"6,e"},
197 {_0, zSET,"6,h"}, {_0, zSET,"6,l"}, {_WM,zSET,"6,(hl)"},{_0, zSET,"6,a"},
198 {_0, zSET,"7,b"}, {_0, zSET,"7,c"}, {_0, zSET,"7,d"}, {_0, zSET,"7,e"},
199 {_0, zSET,"7,h"}, {_0, zSET,"7,l"}, {_WM,zSET,"7,(hl)"},{_0, zSET,"7,a"}
200 };
201
202 static z80dasm mnemonic_ed[256]= {
203 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
204 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
205 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
206 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
207 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
208 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
209 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
210 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
211 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
212 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
213 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
214 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
215 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
216 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
217 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
218 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
219 {_RP,zIN,"b,(c)"}, {_WP,zOUT,"(c),b"}, {_0, zSBC,"hl,bc"}, {_WM,zLD,"(W),bc"},
220 {_0, zNEG,0}, {_0, zRETN,0}, {_0, zIM,"0"}, {_0, zLD,"i,a"},
221 {_RP,zIN,"c,(c)"}, {_WP,zOUT,"(c),c"}, {_0, zADC,"hl,bc"}, {_RM,zLD,"bc,(W)"},
222 {_0, zNEG,"*"}, {_0, zRETI,0}, {_0, zIM,"0"}, {_0, zLD,"r,a"},
223 {_RP,zIN,"d,(c)"}, {_WP,zOUT,"(c),d"}, {_0, zSBC,"hl,de"}, {_WM,zLD,"(W),de"},
224 {_0, zNEG,"*"}, {_0, zRETN,0}, {_0, zIM,"1"}, {_0, zLD,"a,i"},
225 {_RP,zIN,"e,(c)"}, {_WP,zOUT,"(c),e"}, {_0, zADC,"hl,de"}, {_RM,zLD,"de,(W)"},
226 {_0, zNEG,"*"}, {_0, zRETI,0}, {_0, zIM,"2"}, {_0, zLD,"a,r"},
227 {_RP,zIN,"h,(c)"}, {_WP,zOUT,"(c),h"}, {_0, zSBC,"hl,hl"}, {_WM,zLD,"(W),hl"},
228 {_0, zNEG,"*"}, {_0, zRETN,0}, {_0, zIM,"0"}, {_RW,zRRD,"(hl)"},
229 {_RP,zIN,"l,(c)"}, {_WP,zOUT,"(c),l"}, {_0, zADC,"hl,hl"}, {_RM,zLD,"hl,(W)"},
230 {_0, zNEG,"*"}, {_0, zRETI,0}, {_0, zIM,"0"}, {_RW,zRLD,"(hl)"},
231 {_RP,zIN,"0,(c)"}, {_WP,zOUT,"(c),0"}, {_0, zSBC,"hl,sp"}, {_WM,zLD,"(W),sp"},
232 {_0, zNEG,"*"}, {_0, zRETN,0}, {_0, zIM,"1"}, {_0, zDB,"?"},
233 {_RP,zIN,"a,(c)"}, {_WP,zOUT,"(c),a"}, {_0, zADC,"hl,sp"}, {_RM,zLD,"sp,(W)"},
234 {_0, zNEG,"*"}, {_0, zRETI,0}, {_0, zIM,"2"}, {_0, zDB,"?"},
235 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
236 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
237 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
238 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
239 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
240 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
241 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
242 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
243 {_RW,zLDI,0}, {_RM,zCPI,0}, {_RP,zINI,0}, {_WP,zOUTI,0},
244 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
245 {_RW,zLDD,0}, {_RM,zCPD,0}, {_RP,zIND,0}, {_WP,zOUTD,0},
246 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
247 {_RW,zLDIR,0}, {_RM,zCPIR,0}, {_RP,zINIR,0}, {_WP,zOTIR,0},
248 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
249 {_RW,zLDDR,0}, {_RM,zCPDR,0}, {_RP,zINDR,0}, {_WP,zOTDR,0},
250 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
251 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
252 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
253 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
254 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
255 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
256 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
257 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
258 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
259 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
260 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
261 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
262 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
263 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
264 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
265 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
266 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}
267 };
268
269 static z80dasm mnemonic_xx[256]= {
270 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
271 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
272 {_0, zDB,"?"}, {_0, zADD,"I,bc"}, {_0, zDB,"?"}, {_0, zDB,"?"},
273 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
274 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
275 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
276 {_0, zDB,"?"}, {_0, zADD,"I,de"}, {_0, zDB,"?"}, {_0, zDB,"?"},
277 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
278 {_0, zDB,"?"}, {_0, zLD,"I,N"}, {_WM,zLD,"(W),I"}, {_0, zINC,"I"},
279 {_0, zINC,"Ih"}, {_0, zDEC,"Ih"}, {_0, zLD,"Ih,B"}, {_0, zDB,"?"},
280 {_0, zDB,"?"}, {_0, zADD,"I,I"}, {_RM,zLD,"I,(W)"}, {_0, zDEC,"I"},
281 {_0, zINC,"Il"}, {_0, zDEC,"Il"}, {_0, zLD,"Il,B"}, {_0, zDB,"?"},
282 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
283 {_RW,zINC,"X"}, {_RW,zDEC,"X"}, {_WM,zLD,"X,B"}, {_0, zDB,"?"},
284 {_0, zDB,"?"}, {_0, zADD,"I,sp"}, {_0, zDB,"?"}, {_0, zDB,"?"},
285 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
286 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
287 {_0, zLD,"b,Ih"}, {_0, zLD,"b,Il"}, {_RM,zLD,"b,X"}, {_0, zDB,"?"},
288 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
289 {_0, zLD,"c,Ih"}, {_0, zLD,"c,Il"}, {_RM,zLD,"c,X"}, {_0, zDB,"?"},
290 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
291 {_0, zLD,"d,Ih"}, {_0, zLD,"d,Il"}, {_RM,zLD,"d,X"}, {_0, zDB,"?"},
292 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
293 {_0, zLD,"e,Ih"}, {_0, zLD,"e,Il"}, {_RM,zLD,"e,X"}, {_0, zDB,"?"},
294 {_0, zLD,"Ih,b"}, {_0, zLD,"Ih,c"}, {_0, zLD,"Ih,d"}, {_0, zLD,"Ih,e"},
295 {_0, zLD,"Ih,Ih"}, {_0, zLD,"Ih,Il"}, {_RM,zLD,"h,X"}, {_0, zLD,"Ih,a"},
296 {_0, zLD,"Il,b"}, {_0, zLD,"Il,c"}, {_0, zLD,"Il,d"}, {_0, zLD,"Il,e"},
297 {_0, zLD,"Il,Ih"}, {_0, zLD,"Il,Il"}, {_RM,zLD,"l,X"}, {_0, zLD,"Il,a"},
298 {_WM,zLD,"X,b"}, {_WM,zLD,"X,c"}, {_WM,zLD,"X,d"}, {_WM,zLD,"X,e"},
299 {_WM,zLD,"X,h"}, {_WM,zLD,"X,l"}, {_0, zDB,"?"}, {_WM,zLD,"X,a"},
300 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
301 {_0, zLD,"a,Ih"}, {_0, zLD,"a,Il"}, {_RM,zLD,"a,X"}, {_0, zDB,"?"},
302 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
303 {_0, zADD,"a,Ih"}, {_0, zADD,"a,Il"}, {_RM,zADD,"a,X"}, {_0, zDB,"?"},
304 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
305 {_0, zADC,"a,Ih"}, {_0, zADC,"a,Il"}, {_RM,zADC,"a,X"}, {_0, zDB,"?"},
306 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
307 {_0, zSUB,"Ih"}, {_0, zSUB,"Il"}, {_RM,zSUB,"X"}, {_0, zDB,"?"},
308 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
309 {_0, zSBC,"a,Ih"}, {_0, zSBC,"a,Il"}, {_RM,zSBC,"a,X"}, {_0, zDB,"?"},
310 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
311 {_0, zAND,"Ih"}, {_0, zAND,"Il"}, {_RM,zAND,"X"}, {_0, zDB,"?"},
312 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
313 {_0, zXOR,"Ih"}, {_0, zXOR,"Il"}, {_RM,zXOR,"X"}, {_0, zDB,"?"},
314 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
315 {_0, zOR,"Ih"}, {_0, zOR,"Il"}, {_RM,zOR,"X"}, {_0, zDB,"?"},
316 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
317 {_0, zCP,"Ih"}, {_0, zCP,"Il"}, {_RM,zCP,"X"}, {_0, zDB,"?"},
318 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
319 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
320 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"cb"},
321 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
322 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
323 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
324 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
325 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
326 {_0, zDB,"?"}, {_0, zPOP,"I"}, {_0, zDB,"?"}, {_RW,zEX,"(sp),I"},
327 {_0, zDB,"?"}, {_0, zPUSH,"I"}, {_0, zDB,"?"}, {_0, zDB,"?"},
328 {_0, zDB,"?"}, {_JP,zJP,"(I)"}, {_0, zDB,"?"}, {_0, zDB,"?"},
329 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
330 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
331 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"},
332 {_0, zDB,"?"}, {_0, zLD,"sp,I"}, {_0, zDB,"?"}, {_0, zDB,"?"},
333 {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}, {_0, zDB,"?"}
334 };
335
336 static z80dasm mnemonic_main[256]= {
337 {_0, zNOP,0}, {_0, zLD,"bc,N"}, {_WM,zLD,"(bc),a"}, {_0, zINC,"bc"},
338 {_0, zINC,"b"}, {_0, zDEC,"b"}, {_0, zLD,"b,B"}, {_0, zRLCA,0},
339 {_0, zEX,"af,af'"}, {_0, zADD,"hl,bc"}, {_RM,zLD,"a,(bc)"}, {_0, zDEC,"bc"},
340 {_0, zINC,"c"}, {_0, zDEC,"c"}, {_0, zLD,"c,B"}, {_0, zRRCA,0},
341 {_JR,zDJNZ,"O"}, {_0, zLD,"de,N"}, {_WM,zLD,"(de),a"}, {_0, zINC,"de"},
342 {_0, zINC,"d"}, {_0, zDEC,"d"}, {_0, zLD,"d,B"}, {_0, zRLA,0},
343 {_JR,zJR,"O"}, {_0, zADD,"hl,de"}, {_RM,zLD,"a,(de)"}, {_0, zDEC,"de"},
344 {_0, zINC,"e"}, {_0, zDEC,"e"}, {_0, zLD,"e,B"}, {_0, zRRA,0},
345 {_JR,zJR,"nz,O"}, {_0, zLD,"hl,N"}, {_WM,zLD,"(W),hl"}, {_0, zINC,"hl"},
346 {_0, zINC,"h"}, {_0, zDEC,"h"}, {_0, zLD,"h,B"}, {_0, zDAA,0},
347 {_JR,zJR,"z,O"}, {_0, zADD,"hl,hl"}, {_RM,zLD,"hl,(W)"}, {_0, zDEC,"hl"},
348 {_0, zINC,"l"}, {_0, zDEC,"l"}, {_0, zLD,"l,B"}, {_0, zCPL,0},
349 {_JR,zJR,"nc,O"}, {_0, zLD,"sp,N"}, {_WM,zLD,"(W),a"}, {_0, zINC,"sp"},
350 {_RW,zINC,"(hl)"}, {_RW,zDEC,"(hl)"}, {_WM,zLD,"(hl),B"}, {_0, zSCF,0},
351 {_JR,zJR,"c,O"}, {_0, zADD,"hl,sp"}, {_RM,zLD,"a,(W)"}, {_0, zDEC,"sp"},
352 {_0, zINC,"a"}, {_0, zDEC,"a"}, {_0, zLD,"a,B"}, {_0, zCCF,0},
353 {_0, zLD,"b,b"}, {_0, zLD,"b,c"}, {_0, zLD,"b,d"}, {_0, zLD,"b,e"},
354 {_0, zLD,"b,h"}, {_0, zLD,"b,l"}, {_RM,zLD,"b,(hl)"}, {_0, zLD,"b,a"},
355 {_0, zLD,"c,b"}, {_0, zLD,"c,c"}, {_0, zLD,"c,d"}, {_0, zLD,"c,e"},
356 {_0, zLD,"c,h"}, {_0, zLD,"c,l"}, {_RM,zLD,"c,(hl)"}, {_0, zLD,"c,a"},
357 {_0, zLD,"d,b"}, {_0, zLD,"d,c"}, {_0, zLD,"d,d"}, {_0, zLD,"d,e"},
358 {_0, zLD,"d,h"}, {_0, zLD,"d,l"}, {_RM,zLD,"d,(hl)"}, {_0, zLD,"d,a"},
359 {_0, zLD,"e,b"}, {_0, zLD,"e,c"}, {_0, zLD,"e,d"}, {_0, zLD,"e,e"},
360 {_0, zLD,"e,h"}, {_0, zLD,"e,l"}, {_RM,zLD,"e,(hl)"}, {_0, zLD,"e,a"},
361 {_0, zLD,"h,b"}, {_0, zLD,"h,c"}, {_0, zLD,"h,d"}, {_0, zLD,"h,e"},
362 {_0, zLD,"h,h"}, {_0, zLD,"h,l"}, {_RM,zLD,"h,(hl)"}, {_0, zLD,"h,a"},
363 {_0, zLD,"l,b"}, {_0, zLD,"l,c"}, {_0, zLD,"l,d"}, {_0, zLD,"l,e"},
364 {_0, zLD,"l,h"}, {_0, zLD,"l,l"}, {_RM,zLD,"l,(hl)"}, {_0, zLD,"l,a"},
365 {_WM,zLD,"(hl),b"}, {_WM,zLD,"(hl),c"}, {_WM,zLD,"(hl),d"}, {_WM,zLD,"(hl),e"},
366 {_WM,zLD,"(hl),h"}, {_WM,zLD,"(hl),l"}, {_0, zHLT,0}, {_WM,zLD,"(hl),a"},
367 {_0, zLD,"a,b"}, {_0, zLD,"a,c"}, {_0, zLD,"a,d"}, {_0, zLD,"a,e"},
368 {_0, zLD,"a,h"}, {_0, zLD,"a,l"}, {_RM,zLD,"a,(hl)"}, {_0, zLD,"a,a"},
369 {_0, zADD,"a,b"}, {_0, zADD,"a,c"}, {_0, zADD,"a,d"}, {_0, zADD,"a,e"},
370 {_0, zADD,"a,h"}, {_0, zADD,"a,l"}, {_RM,zADD,"a,(hl)"},{_0, zADD,"a,a"},
371 {_0, zADC,"a,b"}, {_0, zADC,"a,c"}, {_0, zADC,"a,d"}, {_0, zADC,"a,e"},
372 {_0, zADC,"a,h"}, {_0, zADC,"a,l"}, {_RM,zADC,"a,(hl)"},{_0, zADC,"a,a"},
373 {_0, zSUB,"b"}, {_0, zSUB,"c"}, {_0, zSUB,"d"}, {_0, zSUB,"e"},
374 {_0, zSUB,"h"}, {_0, zSUB,"l"}, {_RM,zSUB,"(hl)"}, {_0, zSUB,"a"},
375 {_0, zSBC,"a,b"}, {_0, zSBC,"a,c"}, {_0, zSBC,"a,d"}, {_0, zSBC,"a,e"},
376 {_0, zSBC,"a,h"}, {_0, zSBC,"a,l"}, {_RM,zSBC,"a,(hl)"},{_0, zSBC,"a,a"},
377 {_0, zAND,"b"}, {_0, zAND,"c"}, {_0, zAND,"d"}, {_0, zAND,"e"},
378 {_0, zAND,"h"}, {_0, zAND,"l"}, {_RM,zAND,"(hl)"}, {_0, zAND,"a"},
379 {_0, zXOR,"b"}, {_0, zXOR,"c"}, {_0, zXOR,"d"}, {_0, zXOR,"e"},
380 {_0, zXOR,"h"}, {_0, zXOR,"l"}, {_RM,zXOR,"(hl)"}, {_0, zXOR,"a"},
381 {_0, zOR,"b"}, {_0, zOR,"c"}, {_0, zOR,"d"}, {_0, zOR,"e"},
382 {_0, zOR,"h"}, {_0, zOR,"l"}, {_RM,zOR,"(hl)"}, {_0, zOR,"a"},
383 {_0, zCP,"b"}, {_0, zCP,"c"}, {_0, zCP,"d"}, {_0, zCP,"e"},
384 {_0, zCP,"h"}, {_0, zCP,"l"}, {_RM,zCP,"(hl)"}, {_0, zCP,"a"},
385 {_0, zRET,"nz"}, {_0, zPOP,"bc"}, {_JP,zJP,"nz,A"}, {_JP,zJP,"A"},
386 {_JP,zCALL,"nz,A"}, {_0, zPUSH,"bc"}, {_0, zADD,"a,B"}, {_JP,zRST,"V"},
387 {_0, zRET,"z"}, {_0, zRET,0}, {_JP,zJP,"z,A"}, {_0, zDB,"cb"},
388 {_JP,zCALL,"z,A"}, {_JP,zCALL,"A"}, {_0, zADC,"a,B"}, {_JP,zRST,"V"},
389 {_0, zRET,"nc"}, {_0, zPOP,"de"}, {_JP,zJP,"nc,A"}, {_WP,zOUT,"(P),a"},
390 {_JP,zCALL,"nc,A"}, {_0, zPUSH,"de"}, {_0, zSUB,"B"}, {_JP,zRST,"V"},
391 {_0, zRET,"c"}, {_0, zEXX,0}, {_JP,zJP,"c,A"}, {_RP,zIN,"a,(P)"},
392 {_JP,zCALL,"c,A"}, {_0, zDB,"dd"}, {_0, zSBC,"a,B"}, {_JP,zRST,"V"},
393 {_0, zRET,"po"}, {_0, zPOP,"hl"}, {_JP,zJP,"po,A"}, {_RW,zEX,"(sp),hl"},
394 {_JP,zCALL,"po,A"}, {_0, zPUSH,"hl"}, {_0, zAND,"B"}, {_JP,zRST,"V"},
395 {_0, zRET,"pe"}, {_JP,zJP,"(hl)"}, {_JP,zJP,"pe,A"}, {_0, zEX,"de,hl"},
396 {_JP,zCALL,"pe,A"}, {_0, zDB,"ed"}, {_0, zXOR,"B"}, {_JP,zRST,"V"},
397 {_0, zRET,"p"}, {_0, zPOP,"af"}, {_JP,zJP,"p,A"}, {_0, zDI,0},
398 {_JP,zCALL,"p,A"}, {_0, zPUSH,"af"}, {_0, zOR,"B"}, {_JP,zRST,"V"},
399 {_0, zRET,"m"}, {_0, zLD,"sp,hl"}, {_JP,zJP,"m,A"}, {_0, zEI,0},
400 {_JP,zCALL,"m,A"}, {_0, zDB,"fd"}, {_0, zCP,"B"}, {_JP,zRST,"V"}
401 };
402
sign(INT8 offset)403 static char sign(INT8 offset)
404 {
405 return (offset < 0)? '-':'+';
406 }
407
offs(INT8 offset)408 static int offs(INT8 offset)
409 {
410 if (offset < 0) return -offset;
411 return offset;
412 }
413
414 /****************************************************************************
415 * Disassemble opcode at PC and return number of bytes it takes
416 ****************************************************************************/
DasmZ80(char * buffer,unsigned pc)417 unsigned DasmZ80( char *buffer, unsigned pc )
418 {
419 z80dasm *d;
420 const char *symbol, *src;
421 const char *ixy;
422 char *dst;
423 unsigned PC = pc;
424 INT8 offset = 0;
425 UINT8 op, op1;
426 UINT16 ea = 0, xy = 0;
427
428 ixy = "oops!!";
429 dst = buffer;
430 symbol = NULL;
431
432 op = cpu_readop( pc++ );
433 op1 = 0; /* keep GCC happy */
434
435 switch (op)
436 {
437 case 0xcb:
438 op = cpu_readop(pc++);
439 d = &mnemonic_cb[op];
440 break;
441 case 0xed:
442 op1 = cpu_readop(pc++);
443 d = &mnemonic_ed[op1];
444 break;
445 case 0xdd:
446 ixy = "ix";
447 op1 = cpu_readop(pc++);
448 if( op1 == 0xcb )
449 {
450 offset = (INT8) cpu_readop_arg(pc++);
451 op1 = cpu_readop_arg(pc++); /* fourth byte from OP_RAM! */
452 xy = z80_get_reg( Z80_IX );
453 ea = (xy + offset) & 0xffff;
454 d = &mnemonic_xx_cb[op1];
455 }
456 else d = &mnemonic_xx[op1];
457 break;
458 case 0xfd:
459 ixy = "iy";
460 op1 = cpu_readop(pc++);
461 if( op1 == 0xcb )
462 {
463 offset = (INT8) cpu_readop_arg(pc++);
464 op1 = cpu_readop_arg(pc++); /* fourth byte from OP_RAM! */
465 xy = z80_get_reg( Z80_IY );
466 ea = (ea + offset) & 0xffff;
467 d = &mnemonic_xx_cb[op1];
468 }
469 else d = &mnemonic_xx[op1];
470 break;
471 default:
472 d = &mnemonic_main[op];
473 break;
474 }
475
476 if( d->arguments )
477 {
478 dst += sprintf(dst, "%-4s ", s_mnemonic[d->mnemonic]);
479 src = d->arguments;
480 while( *src )
481 {
482 switch( *src )
483 {
484 case '?': /* illegal opcode */
485 dst += sprintf( dst, "$%02x,$%02x", op, op1);
486 break;
487 case 'A':
488 ea = cpu_readop_arg(pc) + ( cpu_readop_arg((pc+1)&0xffff) << 8);
489 pc += 2;
490 symbol = set_ea_info(0, ea, EA_UINT16, d->access);
491 dst += sprintf( dst, "%s", symbol );
492 break;
493 case 'B': /* Byte op arg */
494 ea = cpu_readop_arg( pc++ );
495 symbol = set_ea_info(1, ea, EA_UINT8, EA_VALUE);
496 dst += sprintf( dst, "%s", symbol );
497 break;
498 case '(': /* Memory byte at (HL) */
499 *dst++ = *src;
500 if( !strncmp( src, "(bc)", 4) )
501 {
502 ea = z80_get_reg( Z80_BC );
503 set_ea_info(0, ea, EA_UINT8, d->access);
504 }
505 else
506 if( !strncmp( src, "(de)", 4) )
507 {
508 ea = z80_get_reg( Z80_DE );
509 set_ea_info(0, ea, EA_UINT8, d->access);
510 }
511 else
512 if( !strncmp( src, "(hl)", 4) )
513 {
514 ea = z80_get_reg( Z80_HL );
515 if( d->access == EA_ABS_PC )
516 set_ea_info(0, ea, EA_DEFAULT, EA_ABS_PC);
517 else
518 set_ea_info(0, ea, EA_UINT8, d->access);
519 }
520 else
521 if( !strncmp( src, "(sp)", 4) )
522 {
523 ea = z80_get_reg( Z80_SP );
524 set_ea_info(0, ea, EA_UINT16, d->access);
525 }
526 else
527 if( !strncmp( src, "(P)", 3) )
528 {
529 ea = (z80_get_reg( Z80_AF ) & 0xff00) | cpu_readop_arg( pc );
530 set_ea_info(0, ea, EA_UINT16, d->access);
531 }
532 else
533 if( !strncmp( src, "(c)", 3) )
534 {
535 ea = z80_get_reg( Z80_BC );
536 set_ea_info(0, ea, EA_UINT16, d->access);
537 }
538 else
539 if( !strncmp( src, "(I)", 3) )
540 {
541 ea = xy;
542 set_ea_info(0, ea, EA_DEFAULT, d->access);
543 }
544 break;
545 case 'N': /* Immediate 16 bit */
546 ea = cpu_readop_arg(pc) + ( cpu_readop_arg((pc+1)&0xffff) << 8 );
547 pc += 2;
548 symbol = set_ea_info(1, ea, EA_UINT16, EA_VALUE );
549 dst += sprintf( dst, "%s", symbol );
550 break;
551 case 'O': /* Offset relative to PC */
552 offset = (INT8) cpu_readop_arg(pc++);
553 symbol = set_ea_info(0, PC, offset + 2, d->access);
554 dst += sprintf( dst, "%s", symbol );
555 break;
556 case 'P': /* Port number */
557 ea = cpu_readop_arg( pc++ );
558 dst += sprintf( dst, "$%02X", ea );
559 break;
560 case 'V': /* Restart vector */
561 ea = op & 0x38;
562 symbol = set_ea_info(0, ea, EA_UINT8, d->access);
563 dst += sprintf( dst, "%s", symbol );
564 break;
565 case 'W': /* Memory address word */
566 ea = cpu_readop_arg(pc) + ( cpu_readop_arg((pc+1)&0xffff) << 8);
567 pc += 2;
568 symbol = set_ea_info(0, ea, EA_UINT16, d->access);
569 dst += sprintf( dst, "%s", symbol );
570 break;
571 case 'X':
572 offset = (INT8) cpu_readop_arg(pc++);
573 ea = (xy + offset) & 0xffff;
574 case 'Y':
575 symbol = set_ea_info(0, ea, EA_UINT8, d->access);
576 dst += sprintf( dst,"(%s%c$%02x)", ixy, sign(offset), offs(offset) );
577 break;
578 case 'I':
579 dst += sprintf( dst, "%s", ixy);
580 break;
581 default:
582 *dst++ = *src;
583 }
584 src++;
585 }
586 *dst = '\0';
587 }
588 else
589 {
590 dst += sprintf(dst, "%s", s_mnemonic[d->mnemonic]);
591 }
592
593 return pc - PC;
594 }
595
596 #endif
597
598