z80-dis.c 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991
  1. /* Print Z80, Z180, EZ80 and R800 instructions
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. Contributed by Arnold Metselaar <arnold_m@operamail.com>
  4. This file is part of the GNU opcodes library.
  5. This library is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3, or (at your option)
  8. any later version.
  9. It is distributed in the hope that it will be useful, but WITHOUT
  10. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
  12. License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "disassemble.h"
  19. #include <stdio.h>
  20. struct buffer
  21. {
  22. bfd_vma base;
  23. int n_fetch;
  24. int n_used;
  25. signed char data[6];
  26. long inss; /* instruction set bit mask, taken from bfd_mach */
  27. int nn_len; /* address length: 2 - Z80 mode, 3 - ADL mode*/
  28. } ;
  29. typedef int (*func)(struct buffer *, disassemble_info *, const char *);
  30. struct tab_elt
  31. {
  32. unsigned char val;
  33. unsigned char mask;
  34. func fp;
  35. const char * text;
  36. unsigned inss; /* bit mask of supported bfd_mach_* or 0 for all mach */
  37. } ;
  38. #define INSS_ALL 0
  39. #define INSS_Z80 ((1 << bfd_mach_z80) | (1 << bfd_mach_z80strict) | (1 << bfd_mach_z80full))
  40. #define INSS_R800 (1 << bfd_mach_r800)
  41. #define INSS_GBZ80 (1 << bfd_mach_gbz80)
  42. #define INSS_Z180 (1 << bfd_mach_z180)
  43. #define INSS_EZ80_Z80 (1 << bfd_mach_ez80_z80)
  44. #define INSS_EZ80_ADL (1 << bfd_mach_ez80_adl)
  45. #define INSS_EZ80 (INSS_EZ80_ADL | INSS_EZ80_Z80)
  46. #define INSS_Z80N (1 << bfd_mach_z80n)
  47. #define TXTSIZ 24
  48. /* Names of 16-bit registers. */
  49. static const char * rr_str[] = { "bc", "de", "hl", "sp" };
  50. /* Names of 8-bit registers. */
  51. static const char * r_str[] = { "b", "c", "d", "e", "h", "l", "(hl)", "a" };
  52. /* Texts for condition codes. */
  53. static const char * cc_str[] = { "nz", "z", "nc", "c", "po", "pe", "p", "m" };
  54. /* Instruction names for 8-bit arithmetic, operand "a" is often implicit */
  55. static const char * arit_str[] =
  56. {
  57. "add a,", "adc a,", "sub ", "sbc a,", "and ", "xor ", "or ", "cp "
  58. } ;
  59. static const char * arit_str_gbz80[] =
  60. {
  61. "add a,", "adc a,", "sub a,", "sbc a,", "and ", "xor ", "or ", "cp "
  62. } ;
  63. static const char * arit_str_ez80[] =
  64. {
  65. "add a,", "adc a,", "sub a,", "sbc a,", "and a,", "xor a,", "or a,", "cp a,"
  66. } ;
  67. static int
  68. mach_inst (struct buffer *buf, const struct tab_elt *p)
  69. {
  70. return !p->inss || (p->inss & buf->inss);
  71. }
  72. static int
  73. fetch_data (struct buffer *buf, disassemble_info * info, int n)
  74. {
  75. int r;
  76. if (buf->n_fetch + n > (int)sizeof (buf->data))
  77. abort ();
  78. r = info->read_memory_func (buf->base + buf->n_fetch,
  79. (unsigned char*) buf->data + buf->n_fetch,
  80. n, info);
  81. if (r == 0)
  82. buf->n_fetch += n;
  83. else
  84. info->memory_error_func (r, buf->base + buf->n_fetch, info);
  85. return !r;
  86. }
  87. static int
  88. prt (struct buffer *buf, disassemble_info * info, const char *txt)
  89. {
  90. info->fprintf_func (info->stream, "%s", txt);
  91. buf->n_used = buf->n_fetch;
  92. return 1;
  93. }
  94. static int
  95. prt_e (struct buffer *buf, disassemble_info * info, const char *txt)
  96. {
  97. char e;
  98. int target_addr;
  99. if (fetch_data (buf, info, 1))
  100. {
  101. e = buf->data[1];
  102. target_addr = (buf->base + 2 + e) & 0xffff;
  103. buf->n_used = buf->n_fetch;
  104. info->fprintf_func (info->stream, "%s0x%04x", txt, target_addr);
  105. }
  106. else
  107. buf->n_used = -1;
  108. return buf->n_used;
  109. }
  110. static int
  111. jr_cc (struct buffer *buf, disassemble_info * info, const char *txt)
  112. {
  113. char mytxt[TXTSIZ];
  114. snprintf (mytxt, TXTSIZ, txt, cc_str[(buf->data[0] >> 3) & 3]);
  115. return prt_e (buf, info, mytxt);
  116. }
  117. static int
  118. prt_nn (struct buffer *buf, disassemble_info * info, const char *txt)
  119. {
  120. int nn;
  121. unsigned char *p;
  122. int i;
  123. p = (unsigned char*) buf->data + buf->n_fetch;
  124. if (fetch_data (buf, info, buf->nn_len))
  125. {
  126. nn = 0;
  127. i = buf->nn_len;
  128. while (i--)
  129. nn = nn * 0x100 + p[i];
  130. info->fprintf_func (info->stream, txt, nn);
  131. buf->n_used = buf->n_fetch;
  132. }
  133. else
  134. buf->n_used = -1;
  135. return buf->n_used;
  136. }
  137. static int
  138. prt_rr_nn (struct buffer *buf, disassemble_info * info, const char *txt)
  139. {
  140. char mytxt[TXTSIZ];
  141. int rr;
  142. rr = (buf->data[buf->n_fetch - 1] >> 4) & 3;
  143. snprintf (mytxt, TXTSIZ, txt, rr_str[rr]);
  144. return prt_nn (buf, info, mytxt);
  145. }
  146. static int
  147. prt_rr (struct buffer *buf, disassemble_info * info, const char *txt)
  148. {
  149. info->fprintf_func (info->stream, "%s%s", txt,
  150. rr_str[(buf->data[buf->n_fetch - 1] >> 4) & 3]);
  151. buf->n_used = buf->n_fetch;
  152. return buf->n_used;
  153. }
  154. static int
  155. prt_n (struct buffer *buf, disassemble_info * info, const char *txt)
  156. {
  157. int n;
  158. unsigned char *p;
  159. p = (unsigned char*) buf->data + buf->n_fetch;
  160. if (fetch_data (buf, info, 1))
  161. {
  162. n = p[0];
  163. info->fprintf_func (info->stream, txt, n);
  164. buf->n_used = buf->n_fetch;
  165. }
  166. else
  167. buf->n_used = -1;
  168. return buf->n_used;
  169. }
  170. static int
  171. prt_n_n (struct buffer *buf, disassemble_info * info, const char *txt)
  172. {
  173. char mytxt[TXTSIZ];
  174. int n;
  175. unsigned char *p;
  176. p = (unsigned char*) buf->data + buf->n_fetch;
  177. if (fetch_data (buf, info, 1))
  178. {
  179. n = p[0];
  180. snprintf (mytxt, TXTSIZ, txt, n);
  181. buf->n_used = buf->n_fetch;
  182. }
  183. else
  184. buf->n_used = -1;
  185. return prt_n (buf, info, mytxt);
  186. }
  187. static int
  188. prt_r_n (struct buffer *buf, disassemble_info * info, const char *txt)
  189. {
  190. char mytxt[TXTSIZ];
  191. int r;
  192. r = (buf->data[buf->n_fetch - 1] >> 3) & 7;
  193. snprintf (mytxt, TXTSIZ, txt, r_str[r]);
  194. return prt_n (buf, info, mytxt);
  195. }
  196. static int
  197. ld_r_n (struct buffer *buf, disassemble_info * info, const char *txt)
  198. {
  199. char mytxt[TXTSIZ];
  200. snprintf (mytxt, TXTSIZ, txt, r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]);
  201. return prt_n (buf, info, mytxt);
  202. }
  203. static int
  204. prt_r (struct buffer *buf, disassemble_info * info, const char *txt)
  205. {
  206. info->fprintf_func (info->stream, txt,
  207. r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7]);
  208. buf->n_used = buf->n_fetch;
  209. return buf->n_used;
  210. }
  211. static int
  212. ld_r_r (struct buffer *buf, disassemble_info * info, const char *txt)
  213. {
  214. info->fprintf_func (info->stream, txt,
  215. r_str[(buf->data[buf->n_fetch - 1] >> 3) & 7],
  216. r_str[buf->data[buf->n_fetch - 1] & 7]);
  217. buf->n_used = buf->n_fetch;
  218. return buf->n_used;
  219. }
  220. static int
  221. prt_d (struct buffer *buf, disassemble_info * info, const char *txt)
  222. {
  223. int d;
  224. signed char *p;
  225. p = buf->data + buf->n_fetch;
  226. if (fetch_data (buf, info, 1))
  227. {
  228. d = p[0];
  229. info->fprintf_func (info->stream, txt, d);
  230. buf->n_used = buf->n_fetch;
  231. }
  232. else
  233. buf->n_used = -1;
  234. return buf->n_used;
  235. }
  236. static int
  237. prt_rr_d (struct buffer *buf, disassemble_info * info, const char *txt)
  238. {
  239. char mytxt[TXTSIZ];
  240. int rr;
  241. rr = (buf->data[buf->n_fetch - 1] >> 4) & 3;
  242. if (rr == 3) /* SP is not supported */
  243. return 0;
  244. snprintf (mytxt, TXTSIZ, txt, rr_str[rr]);
  245. return prt_d (buf, info, mytxt);
  246. }
  247. static int
  248. arit_r (struct buffer *buf, disassemble_info * info, const char *txt)
  249. {
  250. const char * const *arit;
  251. if (buf->inss & INSS_EZ80)
  252. arit = arit_str_ez80;
  253. else if (buf->inss & INSS_GBZ80)
  254. arit = arit_str_gbz80;
  255. else
  256. arit = arit_str;
  257. info->fprintf_func (info->stream, txt,
  258. arit[(buf->data[buf->n_fetch - 1] >> 3) & 7],
  259. r_str[buf->data[buf->n_fetch - 1] & 7]);
  260. buf->n_used = buf->n_fetch;
  261. return buf->n_used;
  262. }
  263. static int
  264. prt_cc (struct buffer *buf, disassemble_info * info, const char *txt)
  265. {
  266. info->fprintf_func (info->stream, "%s%s", txt,
  267. cc_str[(buf->data[0] >> 3) & 7]);
  268. buf->n_used = buf->n_fetch;
  269. return buf->n_used;
  270. }
  271. static int
  272. pop_rr (struct buffer *buf, disassemble_info * info, const char *txt)
  273. {
  274. static char *rr_stack[] = { "bc","de","hl","af"};
  275. info->fprintf_func (info->stream, "%s %s", txt,
  276. rr_stack[(buf->data[0] >> 4) & 3]);
  277. buf->n_used = buf->n_fetch;
  278. return buf->n_used;
  279. }
  280. static int
  281. jp_cc_nn (struct buffer *buf, disassemble_info * info, const char *txt)
  282. {
  283. char mytxt[TXTSIZ];
  284. snprintf (mytxt,TXTSIZ,
  285. "%s%s,0x%%04x", txt, cc_str[(buf->data[0] >> 3) & 7]);
  286. return prt_nn (buf, info, mytxt);
  287. }
  288. static int
  289. arit_n (struct buffer *buf, disassemble_info * info, const char *txt)
  290. {
  291. char mytxt[TXTSIZ];
  292. const char * const *arit;
  293. if (buf->inss & INSS_EZ80)
  294. arit = arit_str_ez80;
  295. else if (buf->inss & INSS_GBZ80)
  296. arit = arit_str_gbz80;
  297. else
  298. arit = arit_str;
  299. snprintf (mytxt,TXTSIZ, txt, arit[(buf->data[0] >> 3) & 7]);
  300. return prt_n (buf, info, mytxt);
  301. }
  302. static int
  303. rst (struct buffer *buf, disassemble_info * info, const char *txt)
  304. {
  305. info->fprintf_func (info->stream, txt, buf->data[0] & 0x38);
  306. buf->n_used = buf->n_fetch;
  307. return buf->n_used;
  308. }
  309. static int
  310. cis (struct buffer *buf, disassemble_info * info, const char *txt ATTRIBUTE_UNUSED)
  311. {
  312. static char * opar[] = { "ld", "cp", "in", "out" };
  313. char * op;
  314. char c;
  315. c = buf->data[1];
  316. op = ((0x13 & c) == 0x13) ? "ot" : (opar[c & 3]);
  317. info->fprintf_func (info->stream,
  318. "%s%c%s", op,
  319. (c & 0x08) ? 'd' : 'i',
  320. (c & 0x10) ? "r" : "");
  321. buf->n_used = 2;
  322. return buf->n_used;
  323. }
  324. static int
  325. cism (struct buffer *buf, disassemble_info * info, const char *txt ATTRIBUTE_UNUSED)
  326. {
  327. static char * opar[] = { "in%cm%s", "ot%cm%s" };
  328. char * op;
  329. char c;
  330. c = buf->data[1];
  331. op = opar[c & 1];
  332. info->fprintf_func (info->stream,
  333. op,
  334. (c & 0x08) ? 'd' : 'i',
  335. (c & 0x10) ? "r" : "");
  336. buf->n_used = 2;
  337. return buf->n_used;
  338. }
  339. static int
  340. dump (struct buffer *buf, disassemble_info * info, const char *txt)
  341. {
  342. int i;
  343. info->fprintf_func (info->stream, "defb ");
  344. for (i = 0; txt[i]; ++i)
  345. info->fprintf_func (info->stream, i ? ", 0x%02x" : "0x%02x",
  346. (unsigned char) buf->data[i]);
  347. buf->n_used = i;
  348. return buf->n_used;
  349. }
  350. /* Table to disassemble machine codes with prefix 0xED. */
  351. static const struct tab_elt opc_ed[] =
  352. {
  353. { 0x30, 0xFF, prt, "mul d,e", INSS_Z80N },
  354. { 0x31, 0xFF, prt, "add hl,a", INSS_Z80N },
  355. { 0x31, 0xFF, prt, "ld iy,(hl)", INSS_EZ80 },
  356. { 0x30, 0xFE, dump, "xx", INSS_ALL }, /* do not move this line */
  357. { 0x00, 0xC7, prt_r_n, "in0 %s,(0x%%02x)", INSS_Z180|INSS_EZ80 },
  358. { 0x01, 0xC7, prt_r_n, "out0 (0x%%02x),%s", INSS_Z180|INSS_EZ80 },
  359. { 0x32, 0xFF, prt_d, "lea ix,ix%+d", INSS_EZ80 },
  360. { 0x33, 0xFF, prt_d, "lea iy,iy%+d", INSS_EZ80 },
  361. { 0x02, 0xCF, prt_rr_d, "lea %s,ix%%+d", INSS_EZ80 },
  362. { 0x03, 0xCF, prt_rr_d, "lea %s,iy%%+d", INSS_EZ80 },
  363. { 0x04, 0xC7, prt_r, "tst %s", INSS_Z180},
  364. { 0x04, 0xC7, prt_r, "tst a,%s", INSS_EZ80 },
  365. { 0x07, 0xFF, prt, "ld bc,(hl)", INSS_EZ80 },
  366. { 0x3F, 0xFF, prt, "ld (hl),ix", INSS_EZ80 },
  367. { 0x0F, 0xCF, prt_rr, "ld (hl),", INSS_EZ80 },
  368. { 0x17, 0xFF, prt, "ld de,(hl)", INSS_EZ80 },
  369. { 0x23, 0xFF, prt, "swapnib", INSS_Z80N },
  370. { 0x24, 0xFF, prt, "mirror", INSS_Z80N },
  371. { 0x27, 0xFF, prt, "ld hl,(hl)", INSS_EZ80 },
  372. { 0x27, 0xFF, prt_n, "test 0x%02x", INSS_Z80N },
  373. { 0x28, 0xFF, prt, "bsla de,b", INSS_Z80N },
  374. { 0x29, 0xFF, prt, "bsra de,b", INSS_Z80N },
  375. { 0x2A, 0xFF, prt, "bsrl de,b", INSS_Z80N },
  376. { 0x2B, 0xFF, prt, "bsrf de,b", INSS_Z80N },
  377. { 0x2C, 0xFF, prt, "bslc de,b", INSS_Z80N },
  378. { 0x32, 0xFF, prt, "add de,a", INSS_Z80N },
  379. { 0x33, 0xFF, prt, "add bc,a", INSS_Z80N },
  380. { 0x34, 0xFF, prt_nn, "add hl,0x%04x", INSS_Z80N },
  381. { 0x35, 0xFF, prt_nn, "add de,0x%04x", INSS_Z80N },
  382. { 0x36, 0xFF, prt_nn, "add bc,0x%04x", INSS_Z80N },
  383. { 0x37, 0xFF, prt, "ld ix,(hl)", INSS_EZ80 },
  384. { 0x3E, 0xFF, prt, "ld (hl),iy", INSS_EZ80 },
  385. { 0x70, 0xFF, prt, "in f,(c)", INSS_Z80 | INSS_R800 | INSS_Z80N },
  386. { 0x70, 0xFF, dump, "xx", INSS_ALL },
  387. { 0x40, 0xC7, prt_r, "in %s,(bc)", INSS_EZ80 },
  388. { 0x40, 0xC7, prt_r, "in %s,(c)", INSS_ALL },
  389. { 0x71, 0xFF, prt, "out (c),0", INSS_Z80 | INSS_Z80N },
  390. { 0x71, 0xFF, dump, "xx", INSS_ALL },
  391. { 0x41, 0xC7, prt_r, "out (bc),%s", INSS_EZ80 },
  392. { 0x41, 0xC7, prt_r, "out (c),%s", INSS_ALL },
  393. { 0x42, 0xCF, prt_rr, "sbc hl,", INSS_ALL },
  394. { 0x43, 0xCF, prt_rr_nn, "ld (0x%%04x),%s", INSS_ALL },
  395. { 0x44, 0xFF, prt, "neg", INSS_ALL },
  396. { 0x45, 0xFF, prt, "retn", INSS_ALL },
  397. { 0x46, 0xFF, prt, "im 0", INSS_ALL },
  398. { 0x47, 0xFF, prt, "ld i,a", INSS_ALL },
  399. { 0x4A, 0xCF, prt_rr, "adc hl,", INSS_ALL },
  400. { 0x4B, 0xCF, prt_rr_nn, "ld %s,(0x%%04x)", INSS_ALL },
  401. { 0x4C, 0xCF, prt_rr, "mlt ", INSS_Z180|INSS_EZ80 },
  402. { 0x4D, 0xFF, prt, "reti", INSS_ALL },
  403. { 0x4F, 0xFF, prt, "ld r,a", INSS_ALL },
  404. { 0x54, 0xFF, prt_d, "lea ix,iy%+d", INSS_EZ80 },
  405. { 0x55, 0xFF, prt_d, "lea iy,ix%+d", INSS_EZ80 },
  406. { 0x56, 0xFF, prt, "im 1", INSS_ALL },
  407. { 0x57, 0xFF, prt, "ld a,i", INSS_ALL },
  408. { 0x5E, 0xFF, prt, "im 2", INSS_ALL },
  409. { 0x5F, 0xFF, prt, "ld a,r", INSS_ALL },
  410. { 0x64, 0xFF, prt_n, "tst 0x%02x", INSS_Z180 },
  411. { 0x64, 0xFF, prt_n, "tst a,0x%02x", INSS_EZ80 },
  412. { 0x65, 0xFF, prt_d, "pea ix%+d", INSS_EZ80 },
  413. { 0x66, 0xFF, prt_d, "pea iy%+d", INSS_EZ80 },
  414. { 0x67, 0xFF, prt, "rrd", INSS_ALL },
  415. { 0x6D, 0xFF, prt, "ld mb,a", INSS_EZ80 },
  416. { 0x6E, 0xFF, prt, "ld a,mb", INSS_EZ80 },
  417. { 0x6F, 0xFF, prt, "rld", INSS_ALL },
  418. { 0x74, 0xFF, prt_n, "tstio 0x%02x", INSS_Z180|INSS_EZ80 },
  419. { 0x76, 0xFF, prt, "slp", INSS_Z180|INSS_EZ80 },
  420. { 0x7D, 0xFF, prt, "stmix", INSS_EZ80 },
  421. { 0x7E, 0xFF, prt, "rsmix", INSS_EZ80 },
  422. { 0x82, 0xE6, cism, "", INSS_Z180|INSS_EZ80 },
  423. { 0x84, 0xFF, prt, "ini2", INSS_EZ80 },
  424. { 0x8A, 0xFF, prt_n_n, "push 0x%02x%%02x", INSS_Z80N },
  425. { 0x8C, 0xFF, prt, "ind2", INSS_EZ80 },
  426. { 0x90, 0xFF, prt, "outinb", INSS_Z80N },
  427. { 0x91, 0xFF, prt_n_n, "nextreg 0x%02x,0x%%02x", INSS_Z80N },
  428. { 0x92, 0xFF, prt_n, "nextreg 0x%02x,a", INSS_Z80N },
  429. { 0x93, 0xFF, prt, "pixeldn", INSS_Z80N },
  430. { 0x94, 0xFF, prt, "ini2r", INSS_EZ80 },
  431. { 0x94, 0xFF, prt, "pixelad", INSS_Z80N },
  432. { 0x95, 0xFF, prt, "setae", INSS_Z80N },
  433. { 0x98, 0xFF, prt, "jp (c)", INSS_Z80N },
  434. { 0x9c, 0xFF, prt, "ind2r", INSS_EZ80 },
  435. { 0xA0, 0xE4, cis, "", INSS_ALL },
  436. { 0xA4, 0xFF, prt, "outi2", INSS_EZ80 },
  437. { 0xA4, 0xFF, prt, "ldix", INSS_Z80N },
  438. { 0xAC, 0xFF, prt, "outd2", INSS_EZ80 },
  439. { 0xAC, 0xFF, prt, "lddx", INSS_Z80N },
  440. { 0xA5, 0xFF, prt, "ldws", INSS_Z80N },
  441. { 0xB4, 0xFF, prt, "oti2r", INSS_EZ80 },
  442. { 0xB4, 0xFF, prt, "ldirx", INSS_Z80N },
  443. { 0xB7, 0xFF, prt, "ldpirx", INSS_Z80N },
  444. { 0xBC, 0xFF, prt, "otd2r", INSS_EZ80 },
  445. { 0xBC, 0xFF, prt, "lddrx", INSS_Z80N },
  446. { 0xC2, 0xFF, prt, "inirx", INSS_EZ80 },
  447. { 0xC3, 0xFF, prt, "otirx", INSS_EZ80 },
  448. { 0xC7, 0xFF, prt, "ld i,hl", INSS_EZ80 },
  449. { 0xCA, 0xFF, prt, "indrx", INSS_EZ80 },
  450. { 0xCB, 0xFF, prt, "otdrx", INSS_EZ80 },
  451. { 0xC3, 0xFF, prt, "muluw hl,bc", INSS_R800 },
  452. { 0xC5, 0xE7, prt_r, "mulub a,%s", INSS_R800 },
  453. { 0xD7, 0xFF, prt, "ld hl,i", INSS_EZ80 },
  454. { 0xF3, 0xFF, prt, "muluw hl,sp", INSS_R800 },
  455. { 0x00, 0x00, dump, "xx", INSS_ALL }
  456. };
  457. static int
  458. pref_ed (struct buffer *buf, disassemble_info *info,
  459. const char *txt ATTRIBUTE_UNUSED)
  460. {
  461. const struct tab_elt *p;
  462. if (fetch_data (buf, info, 1))
  463. {
  464. for (p = opc_ed; p->val != (buf->data[1] & p->mask) || !mach_inst (buf, p); ++p)
  465. ;
  466. p->fp (buf, info, p->text);
  467. }
  468. else
  469. buf->n_used = -1;
  470. return buf->n_used;
  471. }
  472. /* Instruction names for the instructions addressing single bits. */
  473. static char *cb1_str[] = { "", "bit", "res", "set"};
  474. /* Instruction names for shifts and rotates. */
  475. static char *cb2_str[] =
  476. {
  477. "rlc", "rrc", "rl", "rr", "sla", "sra", "sli", "srl"
  478. };
  479. static int
  480. pref_cb (struct buffer *buf, disassemble_info *info,
  481. const char *txt ATTRIBUTE_UNUSED)
  482. {
  483. const char *op_txt;
  484. int idx;
  485. if (fetch_data (buf, info, 1))
  486. {
  487. buf->n_used = 2;
  488. if ((buf->data[1] & 0xc0) == 0)
  489. {
  490. idx = (buf->data[1] >> 3) & 7;
  491. if ((buf->inss & INSS_GBZ80) && (idx == 6))
  492. op_txt = "swap";
  493. else
  494. op_txt = cb2_str[idx];
  495. info->fprintf_func (info->stream, "%s %s",
  496. op_txt,
  497. r_str[buf->data[1] & 7]);
  498. }
  499. else
  500. info->fprintf_func (info->stream, "%s %d,%s",
  501. cb1_str[(buf->data[1] >> 6) & 3],
  502. (buf->data[1] >> 3) & 7,
  503. r_str[buf->data[1] & 7]);
  504. }
  505. else
  506. buf->n_used = -1;
  507. return buf->n_used;
  508. }
  509. static int
  510. addvv (struct buffer * buf, disassemble_info * info, const char *txt)
  511. {
  512. info->fprintf_func (info->stream, "add %s,%s", txt, txt);
  513. return buf->n_used = buf->n_fetch;
  514. }
  515. static int
  516. ld_v_v (struct buffer * buf, disassemble_info * info, const char *txt)
  517. {
  518. char mytxt[TXTSIZ];
  519. snprintf (mytxt, TXTSIZ, "ld %s%%s,%s%%s", txt, txt);
  520. return ld_r_r (buf, info, mytxt);
  521. }
  522. static int
  523. prt_d_n (struct buffer *buf, disassemble_info * info, const char *txt)
  524. {
  525. char mytxt[TXTSIZ];
  526. int d;
  527. signed char *p;
  528. p = buf->data + buf->n_fetch;
  529. if (fetch_data (buf, info, 1))
  530. {
  531. d = p[0];
  532. snprintf (mytxt, TXTSIZ, txt, d);
  533. return prt_n (buf, info, mytxt);
  534. }
  535. else
  536. buf->n_used = -1;
  537. return buf->n_used;
  538. }
  539. static int
  540. arit_d (struct buffer *buf, disassemble_info * info, const char *txt)
  541. {
  542. char mytxt[TXTSIZ];
  543. signed char c;
  544. const char * const *arit;
  545. arit = (buf->inss & INSS_EZ80) ? arit_str_ez80 : arit_str;
  546. c = buf->data[buf->n_fetch - 1];
  547. snprintf (mytxt, TXTSIZ, txt, arit[(c >> 3) & 7]);
  548. return prt_d (buf, info, mytxt);
  549. }
  550. static int
  551. ld_r_d (struct buffer *buf, disassemble_info * info, const char *txt)
  552. {
  553. char mytxt[TXTSIZ];
  554. signed char c;
  555. c = buf->data[buf->n_fetch - 1];
  556. snprintf (mytxt, TXTSIZ, txt, r_str[(c >> 3) & 7]);
  557. return prt_d (buf, info, mytxt);
  558. }
  559. static int
  560. ld_d_r (struct buffer *buf, disassemble_info * info, const char *txt)
  561. {
  562. char mytxt[TXTSIZ];
  563. signed char c;
  564. c = buf->data[buf->n_fetch - 1];
  565. snprintf (mytxt, TXTSIZ, txt, r_str[c & 7]);
  566. return prt_d (buf, info, mytxt);
  567. }
  568. static int
  569. ld_ii_ii (struct buffer *buf, disassemble_info * info, const char *txt)
  570. {
  571. char mytxt[TXTSIZ];
  572. signed char c;
  573. int p;
  574. static const char *ii[2] = { "ix", "iy" };
  575. p = (buf->data[buf->n_fetch - 2] == (signed char) 0xdd) ? 0 : 1;
  576. c = buf->data[buf->n_fetch - 1];
  577. if ((c & 0x07) != 0x07)
  578. p = 1 - p; /* 0 -> 1, 1 -> 0 */
  579. snprintf (mytxt, TXTSIZ, txt, ii[p]);
  580. return prt_d (buf, info, mytxt);
  581. }
  582. static int
  583. pref_xd_cb (struct buffer * buf, disassemble_info * info, const char *txt)
  584. {
  585. if (fetch_data (buf, info, 2))
  586. {
  587. int d;
  588. char arg[TXTSIZ];
  589. signed char *p;
  590. buf->n_used = 4;
  591. p = buf->data;
  592. d = p[2];
  593. if (((p[3] & 0xC0) == 0x40) || ((p[3] & 7) == 0x06))
  594. snprintf (arg, TXTSIZ, "(%s%+d)", txt, d);
  595. else
  596. snprintf (arg, TXTSIZ, "(%s%+d),%s", txt, d, r_str[p[3] & 7]);
  597. if ((p[3] & 0xc0) == 0)
  598. info->fprintf_func (info->stream, "%s %s",
  599. cb2_str[(buf->data[3] >> 3) & 7],
  600. arg);
  601. else
  602. info->fprintf_func (info->stream, "%s %d,%s",
  603. cb1_str[(buf->data[3] >> 6) & 3],
  604. (buf->data[3] >> 3) & 7,
  605. arg);
  606. }
  607. else
  608. buf->n_used = -1;
  609. return buf->n_used;
  610. }
  611. /* Table to disassemble machine codes with prefix 0xDD or 0xFD. */
  612. static struct tab_elt opc_ind[] =
  613. {
  614. { 0x07, 0xFF, prt_d, "ld bc,(%s%%+d)", INSS_EZ80 },
  615. { 0x0F, 0xFF, prt_d, "ld (%s%%+d),bc", INSS_EZ80 },
  616. { 0x17, 0xFF, prt_d, "ld de,(%s%%+d)", INSS_EZ80 },
  617. { 0x1F, 0xFF, prt_d, "ld (%s%%+d),de", INSS_EZ80 },
  618. { 0x24, 0xF7, prt_r, "inc %s%%s", INSS_ALL },
  619. { 0x25, 0xF7, prt_r, "dec %s%%s", INSS_ALL },
  620. { 0x26, 0xF7, ld_r_n, "ld %s%%s,0x%%%%02x", INSS_ALL },
  621. { 0x27, 0xFF, prt_d, "ld hl,(%s%%+d)", INSS_EZ80 },
  622. { 0x2F, 0xFF, prt_d, "ld (%s%%+d),hl", INSS_EZ80 },
  623. { 0x21, 0xFF, prt_nn, "ld %s,0x%%04x", INSS_ALL },
  624. { 0x22, 0xFF, prt_nn, "ld (0x%%04x),%s", INSS_ALL },
  625. { 0x2A, 0xFF, prt_nn, "ld %s,(0x%%04x)", INSS_ALL },
  626. { 0x23, 0xFF, prt, "inc %s", INSS_ALL },
  627. { 0x2B, 0xFF, prt, "dec %s", INSS_ALL },
  628. { 0x29, 0xFF, addvv, "%s", INSS_ALL },
  629. { 0x31, 0xFF, ld_ii_ii, "ld %%s,(%s%%%%+d)", INSS_EZ80 },
  630. { 0x37, 0xFF, ld_ii_ii, "ld %%s,(%s%%%%+d)", INSS_EZ80 },
  631. { 0x3E, 0xFE, ld_ii_ii, "ld (%s%%%%+d),%%s", INSS_EZ80 },
  632. { 0x09, 0xCF, prt_rr, "add %s,", INSS_ALL },
  633. { 0x34, 0xFF, prt_d, "inc (%s%%+d)", INSS_ALL },
  634. { 0x35, 0xFF, prt_d, "dec (%s%%+d)", INSS_ALL },
  635. { 0x36, 0xFF, prt_d_n, "ld (%s%%+d),0x%%%%02x", INSS_ALL },
  636. { 0x76, 0xFF, dump, "h", INSS_ALL },
  637. { 0x46, 0xC7, ld_r_d, "ld %%s,(%s%%%%+d)", INSS_ALL },
  638. { 0x70, 0xF8, ld_d_r, "ld (%s%%%%+d),%%s", INSS_ALL },
  639. { 0x64, 0xF6, ld_v_v, "%s", INSS_ALL },
  640. { 0x60, 0xF0, ld_r_r, "ld %s%%s,%%s", INSS_ALL },
  641. { 0x44, 0xC6, ld_r_r, "ld %%s,%s%%s", INSS_ALL },
  642. { 0x86, 0xC7, arit_d, "%%s(%s%%%%+d)", INSS_ALL },
  643. { 0x84, 0xC6, arit_r, "%%s%s%%s", INSS_ALL },
  644. { 0xE1, 0xFF, prt, "pop %s", INSS_ALL },
  645. { 0xE5, 0xFF, prt, "push %s", INSS_ALL },
  646. { 0xCB, 0xFF, pref_xd_cb, "%s", INSS_ALL },
  647. { 0xE3, 0xFF, prt, "ex (sp),%s", INSS_ALL },
  648. { 0xE9, 0xFF, prt, "jp (%s)", INSS_ALL },
  649. { 0xF9, 0xFF, prt, "ld sp,%s", INSS_ALL },
  650. { 0x00, 0x00, dump, "?", INSS_ALL },
  651. } ;
  652. static int
  653. pref_ind (struct buffer *buf, disassemble_info *info, const char *txt)
  654. {
  655. if (fetch_data (buf, info, 1))
  656. {
  657. char mytxt[TXTSIZ];
  658. struct tab_elt *p;
  659. for (p = opc_ind; p->val != (buf->data[1] & p->mask) || !mach_inst (buf, p); ++p)
  660. ;
  661. snprintf (mytxt, TXTSIZ, p->text, txt);
  662. p->fp (buf, info, mytxt);
  663. }
  664. else
  665. buf->n_used = -1;
  666. return buf->n_used;
  667. }
  668. static int
  669. print_insn_z80_buf (struct buffer *buf, disassemble_info *info);
  670. static int
  671. suffix (struct buffer *buf, disassemble_info *info, const char *txt)
  672. {
  673. char mybuf[TXTSIZ*4];
  674. fprintf_ftype old_fprintf;
  675. void *old_stream;
  676. char *p;
  677. switch (txt[2])
  678. {
  679. case 'l': /* SIL or LIL */
  680. buf->nn_len = 3;
  681. break;
  682. case 's': /* SIS or LIS */
  683. buf->nn_len = 2;
  684. break;
  685. default:
  686. abort ();
  687. }
  688. if (!fetch_data (buf, info, 1)
  689. || buf->data[1] == 0x40
  690. || buf->data[1] == 0x49
  691. || buf->data[1] == 0x52
  692. || buf->data[1] == 0x5b)
  693. {
  694. /* Double prefix, or end of data. */
  695. info->fprintf_func (info->stream, ".db 0x%02x ; %s", (unsigned)buf->data[0], txt);
  696. buf->n_used = 1;
  697. return buf->n_used;
  698. }
  699. old_fprintf = info->fprintf_func;
  700. old_stream = info->stream;
  701. info->fprintf_func = (fprintf_ftype) &sprintf;
  702. info->stream = mybuf;
  703. mybuf[0] = 0;
  704. buf->base++;
  705. if (print_insn_z80_buf (buf, info) >= 0)
  706. buf->n_used++;
  707. info->fprintf_func = old_fprintf;
  708. info->stream = old_stream;
  709. for (p = mybuf; *p; ++p)
  710. if (*p == ' ')
  711. break;
  712. if (*p)
  713. {
  714. *p++ = '\0';
  715. info->fprintf_func (info->stream, "%s.%s %s", mybuf, txt, p);
  716. }
  717. else
  718. info->fprintf_func (info->stream, "%s.%s", mybuf, txt);
  719. return buf->n_used;
  720. }
  721. /* Table to disassemble machine codes without prefix. */
  722. static const struct tab_elt
  723. opc_main[] =
  724. {
  725. { 0x00, 0xFF, prt, "nop", INSS_ALL },
  726. { 0x01, 0xCF, prt_rr_nn, "ld %s,0x%%04x", INSS_ALL },
  727. { 0x02, 0xFF, prt, "ld (bc),a", INSS_ALL },
  728. { 0x03, 0xCF, prt_rr, "inc ", INSS_ALL },
  729. { 0x04, 0xC7, prt_r, "inc %s", INSS_ALL },
  730. { 0x05, 0xC7, prt_r, "dec %s", INSS_ALL },
  731. { 0x06, 0xC7, ld_r_n, "ld %s,0x%%02x", INSS_ALL },
  732. { 0x07, 0xFF, prt, "rlca", INSS_ALL },
  733. { 0x08, 0xFF, prt, "ex af,af'", ~INSS_GBZ80 },
  734. { 0x09, 0xCF, prt_rr, "add hl,", INSS_ALL },
  735. { 0x0A, 0xFF, prt, "ld a,(bc)", INSS_ALL },
  736. { 0x0B, 0xCF, prt_rr, "dec ", INSS_ALL },
  737. { 0x0F, 0xFF, prt, "rrca", INSS_ALL },
  738. { 0x10, 0xFF, prt_e, "djnz ", ~INSS_GBZ80 },
  739. { 0x12, 0xFF, prt, "ld (de),a", INSS_ALL },
  740. { 0x17, 0xFF, prt, "rla", INSS_ALL },
  741. { 0x18, 0xFF, prt_e, "jr ", INSS_ALL },
  742. { 0x1A, 0xFF, prt, "ld a,(de)", INSS_ALL },
  743. { 0x1F, 0xFF, prt, "rra", INSS_ALL },
  744. { 0x20, 0xE7, jr_cc, "jr %s,", INSS_ALL },
  745. { 0x22, 0xFF, prt_nn, "ld (0x%04x),hl", ~INSS_GBZ80 },
  746. { 0x27, 0xFF, prt, "daa", INSS_ALL },
  747. { 0x2A, 0xFF, prt_nn, "ld hl,(0x%04x)", ~INSS_GBZ80 },
  748. { 0x2F, 0xFF, prt, "cpl", INSS_ALL },
  749. { 0x32, 0xFF, prt_nn, "ld (0x%04x),a", INSS_ALL },
  750. { 0x37, 0xFF, prt, "scf", INSS_ALL },
  751. { 0x3A, 0xFF, prt_nn, "ld a,(0x%04x)", INSS_ALL },
  752. { 0x3F, 0xFF, prt, "ccf", INSS_ALL },
  753. { 0x76, 0xFF, prt, "halt", INSS_ALL },
  754. { 0x40, 0xFF, suffix, "sis", INSS_EZ80 },
  755. { 0x49, 0xFF, suffix, "lis", INSS_EZ80 },
  756. { 0x52, 0xFF, suffix, "sil", INSS_EZ80 },
  757. { 0x5B, 0xFF, suffix, "lil", INSS_EZ80 },
  758. { 0x40, 0xC0, ld_r_r, "ld %s,%s", INSS_ALL},
  759. { 0x80, 0xC0, arit_r, "%s%s", INSS_ALL },
  760. { 0xC0, 0xC7, prt_cc, "ret ", INSS_ALL },
  761. { 0xC1, 0xCF, pop_rr, "pop", INSS_ALL },
  762. { 0xC2, 0xC7, jp_cc_nn, "jp ", INSS_ALL },
  763. { 0xC3, 0xFF, prt_nn, "jp 0x%04x", INSS_ALL },
  764. { 0xC4, 0xC7, jp_cc_nn, "call ", INSS_ALL },
  765. { 0xC5, 0xCF, pop_rr, "push", INSS_ALL },
  766. { 0xC6, 0xC7, arit_n, "%s0x%%02x", INSS_ALL },
  767. { 0xC7, 0xC7, rst, "rst 0x%02x", INSS_ALL },
  768. { 0xC9, 0xFF, prt, "ret", INSS_ALL },
  769. { 0xCB, 0xFF, pref_cb, "", INSS_ALL },
  770. { 0xCD, 0xFF, prt_nn, "call 0x%04x", INSS_ALL },
  771. { 0xD3, 0xFF, prt_n, "out (0x%02x),a", ~INSS_GBZ80 },
  772. { 0xD9, 0xFF, prt, "exx", ~INSS_GBZ80 },
  773. { 0xDB, 0xFF, prt_n, "in a,(0x%02x)", ~INSS_GBZ80 },
  774. { 0xDD, 0xFF, pref_ind, "ix", ~INSS_GBZ80 },
  775. { 0xE3, 0xFF, prt, "ex (sp),hl", ~INSS_GBZ80 },
  776. { 0xE9, 0xFF, prt, "jp (hl)", INSS_ALL },
  777. { 0xEB, 0xFF, prt, "ex de,hl", ~INSS_GBZ80 },
  778. { 0xED, 0xFF, pref_ed, "", ~INSS_GBZ80 },
  779. { 0xF3, 0xFF, prt, "di", INSS_ALL },
  780. { 0xF9, 0xFF, prt, "ld sp,hl", INSS_ALL },
  781. { 0xFB, 0xFF, prt, "ei", INSS_ALL },
  782. { 0xFD, 0xFF, pref_ind, "iy", ~INSS_GBZ80 },
  783. { 0x00, 0x00, prt, "????", INSS_ALL },
  784. } ;
  785. /* Separate GBZ80 main opcode table due to many differences */
  786. static const struct tab_elt
  787. opc_main_gbz80[] =
  788. {
  789. { 0x00, 0xFF, prt,"nop", INSS_ALL },
  790. { 0x01, 0xCF, prt_rr_nn, "ld %s,0x%%04x", INSS_ALL },
  791. { 0x02, 0xFF, prt, "ld (bc),a", INSS_ALL },
  792. { 0x03, 0xCF, prt_rr, "inc ", INSS_ALL },
  793. { 0x04, 0xC7, prt_r, "inc %s", INSS_ALL },
  794. { 0x05, 0xC7, prt_r, "dec %s", INSS_ALL },
  795. { 0x06, 0xC7, ld_r_n, "ld %s,0x%%02x", INSS_ALL },
  796. { 0x07, 0xFF, prt, "rlca", INSS_ALL },
  797. { 0x08, 0xFF, prt_nn, "ld (0x%04x),sp", INSS_GBZ80 },
  798. { 0x09, 0xCF, prt_rr, "add hl,", INSS_ALL },
  799. { 0x0A, 0xFF, prt, "ld a,(bc)", INSS_ALL },
  800. { 0x0B, 0xCF, prt_rr, "dec ", INSS_ALL },
  801. { 0x0F, 0xFF, prt, "rrca", INSS_ALL },
  802. { 0x10, 0xFF, prt, "stop", INSS_GBZ80 },
  803. { 0x12, 0xFF, prt, "ld (de),a", INSS_ALL },
  804. { 0x17, 0xFF, prt, "rla", INSS_ALL },
  805. { 0x18, 0xFF, prt_e, "jr ", INSS_ALL },
  806. { 0x1A, 0xFF, prt, "ld a,(de)", INSS_ALL },
  807. { 0x1F, 0xFF, prt, "rra", INSS_ALL },
  808. { 0x20, 0xE7, jr_cc, "jr %s,", INSS_ALL },
  809. { 0x22, 0xFF, prt, "ld (hl+),a", INSS_GBZ80 },
  810. { 0x27, 0xFF, prt, "daa", INSS_ALL },
  811. { 0x2A, 0xFF, prt, "ld a,(hl+)", INSS_GBZ80 },
  812. { 0x2F, 0xFF, prt, "cpl", INSS_ALL },
  813. { 0x32, 0xFF, prt, "ld (hl-),a", INSS_GBZ80 },
  814. { 0x37, 0xFF, prt, "scf", INSS_ALL },
  815. { 0x3A, 0xFF, prt, "ld a,(hl-)", INSS_GBZ80 },
  816. { 0x3F, 0xFF, prt, "ccf", INSS_ALL },
  817. { 0x76, 0xFF, prt, "halt", INSS_ALL },
  818. { 0x40, 0xC0, ld_r_r, "ld %s,%s", INSS_ALL},
  819. { 0x80, 0xC0, arit_r, "%s%s", INSS_ALL },
  820. { 0xC0, 0xE7, prt_cc, "ret ", INSS_ALL },
  821. { 0xC1, 0xCF, pop_rr, "pop", INSS_ALL },
  822. { 0xC2, 0xE7, jp_cc_nn, "jp ", INSS_ALL },
  823. { 0xC3, 0xFF, prt_nn, "jp 0x%04x", INSS_ALL },
  824. { 0xC4, 0xE7, jp_cc_nn, "call ", INSS_ALL },
  825. { 0xC5, 0xCF, pop_rr, "push", INSS_ALL },
  826. { 0xC6, 0xC7, arit_n, "%s0x%%02x", INSS_ALL },
  827. { 0xC7, 0xC7, rst, "rst 0x%02x", INSS_ALL },
  828. { 0xC9, 0xFF, prt, "ret", INSS_ALL },
  829. { 0xCB, 0xFF, pref_cb, "", INSS_ALL },
  830. { 0xCD, 0xFF, prt_nn, "call 0x%04x", INSS_ALL },
  831. { 0xD9, 0xFF, prt, "reti", INSS_GBZ80 },
  832. { 0xE0, 0xFF, prt_n, "ldh (0x%02x),a", INSS_GBZ80 },
  833. { 0xE2, 0xFF, prt, "ldh (c),a", INSS_GBZ80 },
  834. { 0xE8, 0xFF, prt_d, "add sp,%d", INSS_GBZ80 },
  835. { 0xE9, 0xFF, prt, "jp (hl)", INSS_ALL },
  836. { 0xEA, 0xFF, prt_nn, "ld (0x%04x),a", INSS_GBZ80 },
  837. { 0xF0, 0xFF, prt_n, "ldh a,(0x%02x)", INSS_GBZ80 },
  838. { 0xF2, 0xFF, prt, "ldh a,(c)", INSS_GBZ80 },
  839. { 0xF3, 0xFF, prt, "di", INSS_ALL },
  840. { 0xF8, 0xFF, prt_d, "ldhl sp,%d", INSS_GBZ80 },
  841. { 0xF9, 0xFF, prt, "ld sp,hl", INSS_ALL },
  842. { 0xFA, 0xFF, prt_nn, "ld a,(0x%04x)", INSS_GBZ80 },
  843. { 0xFB, 0xFF, prt, "ei", INSS_ALL },
  844. { 0x00, 0x00, dump, "?", INSS_ALL },
  845. } ;
  846. int
  847. print_insn_z80 (bfd_vma addr, disassemble_info * info)
  848. {
  849. struct buffer buf;
  850. buf.base = addr;
  851. buf.inss = 1 << info->mach;
  852. buf.nn_len = info->mach == bfd_mach_ez80_adl ? 3 : 2;
  853. info->bytes_per_line = (buf.inss & INSS_EZ80) ? 6 : 4; /* <ss pp oo nn mm MM> OR <pp oo nn mm> */
  854. return print_insn_z80_buf (&buf, info);
  855. }
  856. static int
  857. print_insn_z80_buf (struct buffer *buf, disassemble_info *info)
  858. {
  859. const struct tab_elt *p;
  860. buf->n_fetch = 0;
  861. buf->n_used = 0;
  862. if (! fetch_data (buf, info, 1))
  863. return -1;
  864. p = (buf->inss & INSS_GBZ80) ? opc_main_gbz80 : opc_main;
  865. for (; p->val != (buf->data[0] & p->mask) || !mach_inst (buf, p); ++p)
  866. ;
  867. p->fp (buf, info, p->text);
  868. return buf->n_used;
  869. }