1 /* ======================================================================== */
2 /* ========================= LICENSING & COPYRIGHT ======================== */
3 /* ======================================================================== */
4 
5 static const char* copyright_notice =
6 "DEBABELIZER\n"
7 "Version 2.3 internal alpha 1\n"
8 "A portable Motorola M680x0 disassembler.\n"
9 "Copyright 1999 Karl Stenerud.  All rights reserved.\n"
10 "\n"
11 "This code is freeware and may be freely used as long as this copyright\n"
12 "notice remains unaltered in the source code and any binary files\n"
13 "containing this code in compiled form.\n"
14 "\n"
15 "The latest version of this code can be obtained at:\n"
16 "(home page pending)\n"
17 ;
18 
19 
20 /* ======================================================================== */
21 /* ================================ INCLUDES ============================== */
22 /* ======================================================================== */
23 
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include "d68k.h"
28 #include "d68kconf.h"
29 #include "x68kmemory.h"
30 
31 #ifndef CLIB_DECL
32 #define CLIB_DECL
33 #endif
34 
35 /* ======================================================================== */
36 /* ============================ GENERAL DEFINES =========================== */
37 /* ======================================================================== */
38 
39 /* unsigned int and int must be at least 32 bits wide */
40 #undef uint
41 #define uint unsigned int
42 
43 /* Bit Isolation Functions */
44 #define BIT_0(A)  ((A) & 0x00000001)
45 #define BIT_1(A)  ((A) & 0x00000002)
46 #define BIT_2(A)  ((A) & 0x00000004)
47 #define BIT_3(A)  ((A) & 0x00000008)
48 #define BIT_4(A)  ((A) & 0x00000010)
49 #define BIT_5(A)  ((A) & 0x00000020)
50 #define BIT_6(A)  ((A) & 0x00000040)
51 #define BIT_7(A)  ((A) & 0x00000080)
52 #define BIT_8(A)  ((A) & 0x00000100)
53 #define BIT_9(A)  ((A) & 0x00000200)
54 #define BIT_A(A)  ((A) & 0x00000400)
55 #define BIT_B(A)  ((A) & 0x00000800)
56 #define BIT_C(A)  ((A) & 0x00001000)
57 #define BIT_D(A)  ((A) & 0x00002000)
58 #define BIT_E(A)  ((A) & 0x00004000)
59 #define BIT_F(A)  ((A) & 0x00008000)
60 #define BIT_10(A) ((A) & 0x00010000)
61 #define BIT_11(A) ((A) & 0x00020000)
62 #define BIT_12(A) ((A) & 0x00040000)
63 #define BIT_13(A) ((A) & 0x00080000)
64 #define BIT_14(A) ((A) & 0x00100000)
65 #define BIT_15(A) ((A) & 0x00200000)
66 #define BIT_16(A) ((A) & 0x00400000)
67 #define BIT_17(A) ((A) & 0x00800000)
68 #define BIT_18(A) ((A) & 0x01000000)
69 #define BIT_19(A) ((A) & 0x02000000)
70 #define BIT_1A(A) ((A) & 0x04000000)
71 #define BIT_1B(A) ((A) & 0x08000000)
72 #define BIT_1C(A) ((A) & 0x10000000)
73 #define BIT_1D(A) ((A) & 0x20000000)
74 #define BIT_1E(A) ((A) & 0x40000000)
75 #define BIT_1F(A) ((A) & 0x80000000)
76 
77 
78 /* Extension word formats */
79 #define EXT_8BIT_DISPLACEMENT(A)          ((A)&0xff)
80 #define EXT_FULL(A)                       BIT_8(A)
81 #define EXT_EFFECTIVE_ZERO(A)             (((A)&0xe4) == 0xc4 || ((A)&0xe2) == 0xc0)
82 #define EXT_BASE_REGISTER_PRESENT(A)      (!BIT_7(A))
83 #define EXT_INDEX_REGISTER_PRESENT(A)     (!BIT_6(A))
84 #define EXT_INDEX_REGISTER(A)             (((A)>>12)&7)
85 #define EXT_INDEX_PRE_POST(A)             (EXT_INDEX_PRESENT(A) && (A)&3)
86 #define EXT_INDEX_PRE(A)                  (EXT_INDEX_PRESENT(A) && ((A)&7) < 4 && ((A)&7) != 0)
87 #define EXT_INDEX_POST(A)                 (EXT_INDEX_PRESENT(A) && ((A)&7) > 4)
88 #define EXT_INDEX_SCALE(A)                (((A)>>9)&3)
89 #define EXT_INDEX_LONG(A)                 BIT_B(A)
90 #define EXT_INDEX_AR(A)                   BIT_F(A)
91 #define EXT_BASE_DISPLACEMENT_PRESENT(A)  (((A)&0x30) > 0x10)
92 #define EXT_BASE_DISPLACEMENT_WORD(A)     (((A)&0x30) == 0x20)
93 #define EXT_BASE_DISPLACEMENT_LONG(A)     (((A)&0x30) == 0x30)
94 #define EXT_OUTER_DISPLACEMENT_PRESENT(A) (((A)&3) > 1 && ((A)&0x47) < 0x44)
95 #define EXT_OUTER_DISPLACEMENT_WORD(A)    (((A)&3) == 2 && ((A)&0x47) < 0x44)
96 #define EXT_OUTER_DISPLACEMENT_LONG(A)    (((A)&3) == 3 && ((A)&0x47) < 0x44)
97 
98 
99 
100 /* ======================================================================== */
101 /* =============================== PROTOTYPES ============================= */
102 /* ======================================================================== */
103 
104 /* Read external memory */
105 uint  read_8  (uint address);
106 uint  read_16 (uint address);
107 uint  read_32 (uint address);
108 
109 /* Read data at the PC and increment PC */
110 uint  read_imm_8(void);
111 uint  read_imm_16(void);
112 uint  read_imm_32(void);
113 
114 /* Read data at the PC but don't imcrement the PC */
115 uint  peek_imm_8(void);
116 uint  peek_imm_16(void);
117 uint  peek_imm_32(void);
118 
119 /* make signed integers 100% portably */
120 static int make_int_8(int value);
121 static int make_int_16(int value);
122 
123 /* make a string of a hex value */
124 static char* make_signed_hex_str_8(uint val);
125 static char* make_signed_hex_str_16(uint val);
126 static char* make_signed_hex_str_32(uint val);
127 
128 /* make string of ea mode */
129 static char* get_ea_mode_str(uint instruction, uint size);
130 
131 char* get_ea_mode_str_8(uint instruction);
132 char* get_ea_mode_str_16(uint instruction);
133 char* get_ea_mode_str_32(uint instruction);
134 
135 /* make string of immediate value */
136 static char* get_imm_str_s(uint size);
137 static char* get_imm_str_u(uint size);
138 
139 char* get_imm_str_s8(void);
140 char* get_imm_str_s16(void);
141 char* get_imm_str_s32(void);
142 
143 /* Stuff to build the opcode handler jump table */
144 static void  build_opcode_table(void);
145 static int   valid_ea(uint opcode, uint mask);
146 static int CLIB_DECL compare_nof_true_bits(const void *aptr, const void *bptr);
147 
148 
149 /* used to build opcode handler jump table */
150 typedef struct
151 {
152    void (*opcode_handler)(void); /* handler function */
153    uint mask;                    /* mask on opcode */
154    uint match;                   /* what to match after masking */
155    uint ea_mask;                 /* what ea modes are allowed */
156 } opcode_struct;
157 
158 
159 
160 /* ======================================================================== */
161 /* ================================= DATA ================================= */
162 /* ======================================================================== */
163 
164 /* Opcode handler jump table */
165 static void (*g_instruction_table[0x10000])(void);
166 /* Flag if disassembler initialized */
167 static int  g_initialized = 0;
168 
169 static char g_dasm_str[100]; /* string to hold disassembly */
170 static char g_helper_str[100]; /* string to hold helpful info */
171 static uint g_cpu_pc;        /* program counter */
172 static uint g_cpu_ir;        /* instruction register */
173 
174 /* used by ops like asr, ror, addq, etc */
175 static uint g_3bit_qdata_table[8] = {8, 1, 2, 3, 4, 5, 6, 7};
176 
177 static uint g_5bit_data_table[32] =
178 {
179    32,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15,
180    16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31
181 };
182 
183 static char* g_cc[16] =
184 {"t", "f", "hi", "ls", "cc", "cs", "ne", "eq", "vc", "vs", "pl", "mi", "ge", "lt", "gt", "le"};
185 
186 static char* g_cpcc[64] =
187 {/* 000    001    010    011    100    101    110    111 */
188      "f",  "eq", "ogt", "oge", "olt", "ole", "ogl",  "or", /* 000 */
189     "un", "ueq", "ugt", "uge", "ult", "ule",  "ne",   "t", /* 001 */
190     "sf", "seq",  "gt",  "ge",  "lt",  "le",  "gl"  "gle", /* 010 */
191   "ngle", "ngl", "nle", "nlt", "nge", "ngt", "sne",  "st", /* 011 */
192      "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?", /* 100 */
193      "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?", /* 101 */
194      "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?", /* 110 */
195      "?",   "?",   "?",   "?",   "?",   "?",   "?",   "?"  /* 111 */
196 };
197 
198 /* ======================================================================== */
199 /* =========================== UTILITY FUNCTIONS ========================== */
200 /* ======================================================================== */
201 
202 /* Pass up the memory requests */
203 #define read_8(address) (m68k_read_memory_8((address)&0xffffff)&0xff)
204 #define read_16(address) (m68k_read_memory_16((address)&0xffffff)&0xffff)
205 #define read_32(address) (m68k_read_memory_32((address)&0xffffff)&0xffffffff)
206 
207 #define read_imm_8()  m68k_read_memory_8(((g_cpu_pc+=2)-1)&0xffffff)
208 #define read_imm_16() m68k_read_memory_16(((g_cpu_pc+=2)-2)&0xffffff)
209 #define read_imm_32() m68k_read_memory_32(((g_cpu_pc+=4)-4)&0xffffff)
210 
211 #define peek_imm_8()  m68k_read_memory_8(g_cpu_pc & 0xffffff)
212 #define peek_imm_16() m68k_read_memory_16(g_cpu_pc & 0xffffff)
213 #define peek_imm_32() m68k_read_memory_32(g_cpu_pc & 0xffffff)
214 
215 /* Fake a split interface */
216 #define get_ea_mode_str_8(instruction) get_ea_mode_str(instruction, 0)
217 #define get_ea_mode_str_16(instruction) get_ea_mode_str(instruction, 1)
218 #define get_ea_mode_str_32(instruction) get_ea_mode_str(instruction, 2)
219 
220 #define get_imm_str_s8() get_imm_str_s(0)
221 #define get_imm_str_s16() get_imm_str_s(1)
222 #define get_imm_str_s32() get_imm_str_s(2)
223 
224 #define get_imm_str_u8() get_imm_str_u(0)
225 #define get_imm_str_u16() get_imm_str_u(1)
226 #define get_imm_str_u32() get_imm_str_u(2)
227 
228 
229 /* 100% portable signed int generators */
make_int_8(int value)230 static int make_int_8(int value)
231 {
232    return (value & 0x80) ? value | ~0xff : value & 0xff;
233 }
234 
make_int_16(int value)235 static int make_int_16(int value)
236 {
237    return (value & 0x8000) ? value | ~0xffff : value & 0xffff;
238 }
239 
240 
241 /* Get string representation of hex values */
make_signed_hex_str_8(uint val)242 static char* make_signed_hex_str_8(uint val)
243 {
244    static char str[20];
245 
246    val &= 0xff;
247 
248    if(val & 0x80)
249       sprintf(str, "-$%x", (0-val) & 0x7f);
250    else
251       sprintf(str, "$%x", val & 0x7f);
252 
253    return str;
254 }
255 
make_signed_hex_str_16(uint val)256 static char* make_signed_hex_str_16(uint val)
257 {
258    static char str[20];
259 
260    val &= 0xffff;
261 
262    if(val & 0x8000)
263       sprintf(str, "-$%x", (0-val) & 0x7fff);
264    else
265       sprintf(str, "$%x", val & 0x7fff);
266 
267    return str;
268 }
269 
make_signed_hex_str_32(uint val)270 static char* make_signed_hex_str_32(uint val)
271 {
272    static char str[20];
273 
274    val &= 0xffffffff;
275 
276    if(val & 0x80000000)
277       sprintf(str, "-$%x", (0-val) & 0x7fffffff);
278    else
279       sprintf(str, "$%x", val & 0x7fffffff);
280 
281    return str;
282 }
283 
284 
285 /* make string of immediate value */
get_imm_str_s(uint size)286 static char* get_imm_str_s(uint size)
287 {
288    static char str[15];
289    if(size == 0)
290       sprintf(str, "#%s", make_signed_hex_str_8(read_imm_8()));
291    else if(size == 1)
292       sprintf(str, "#%s", make_signed_hex_str_16(read_imm_16()));
293    else
294       sprintf(str, "#%s", make_signed_hex_str_32(read_imm_32()));
295    return str;
296 }
297 
get_imm_str_u(uint size)298 static char* get_imm_str_u(uint size)
299 {
300    static char str[15];
301    if(size == 0)
302       sprintf(str, "#$%x", read_imm_8() & 0xff);
303    else if(size == 1)
304       sprintf(str, "#$%x", read_imm_16() & 0xffff);
305    else
306       sprintf(str, "#$%x", read_imm_32() & 0xffffffff);
307    return str;
308 }
309 
310 /* Make string of effective address mode */
get_ea_mode_str(uint instruction,uint size)311 static char* get_ea_mode_str(uint instruction, uint size)
312 {
313    static char b1[64];
314    static char b2[64];
315    static char* mode = b2;
316    uint extension;
317    uint base;
318    uint outer;
319    char base_reg[4];
320    char index_reg[8];
321    uint preindex;
322    uint postindex;
323    uint comma = 0;
324    uint temp_value = 0;
325 
326    /* Switch buffers so we don't clobber on a double-call to this function */
327    mode = mode == b1 ? b2 : b1;
328 
329    switch(instruction & 0x3f)
330    {
331       case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x06: case 0x07:
332       /* data register direct */
333          sprintf(mode, "D%d", instruction&7);
334          break;
335       case 0x08: case 0x09: case 0x0a: case 0x0b: case 0x0c: case 0x0d: case 0x0e: case 0x0f:
336       /* address register direct */
337          sprintf(mode, "A%d", instruction&7);
338          break;
339       case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x16: case 0x17:
340       /* address register indirect */
341          sprintf(mode, "(A%d)", instruction&7);
342          break;
343       case 0x18: case 0x19: case 0x1a: case 0x1b: case 0x1c: case 0x1d: case 0x1e: case 0x1f:
344       /* address register indirect with postincrement */
345          sprintf(mode, "(A%d)+", instruction&7);
346          break;
347       case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x26: case 0x27:
348       /* address register indirect with predecrement */
349          sprintf(mode, "-(A%d)", instruction&7);
350          break;
351       case 0x28: case 0x29: case 0x2a: case 0x2b: case 0x2c: case 0x2d: case 0x2e: case 0x2f:
352       /* address register indirect with displacement*/
353          sprintf(mode, "(%s,A%d)", make_signed_hex_str_16(read_imm_16()), instruction&7);
354          break;
355       case 0x30: case 0x31: case 0x32: case 0x33: case 0x34: case 0x35: case 0x36: case 0x37:
356       /* address register indirect with index */
357          extension = read_imm_16();
358 
359          if(EXT_FULL(extension))
360          {
361             if(EXT_EFFECTIVE_ZERO(extension))
362             {
363                strcpy(mode, "0");
364                break;
365             }
366             base = EXT_BASE_DISPLACEMENT_PRESENT(extension) ? (EXT_BASE_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
367             outer = EXT_OUTER_DISPLACEMENT_PRESENT(extension) ? (EXT_OUTER_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
368             if(EXT_BASE_REGISTER_PRESENT(extension))
369                sprintf(base_reg, "A%d", instruction&7);
370             else
371                *base_reg = 0;
372             if(EXT_INDEX_REGISTER_PRESENT(extension))
373             {
374                sprintf(index_reg, "%c%d.%c", EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
375                if(EXT_INDEX_SCALE(extension))
376                   sprintf(index_reg+strlen(index_reg), "*%d", 1 << EXT_INDEX_SCALE(extension));
377             }
378             else
379                *index_reg = 0;
380             preindex = (extension&7) > 0 && (extension&7) < 4;
381             postindex = (extension&7) > 4;
382 
383             strcpy(mode, "(");
384             if(preindex || postindex)
385                strcat(mode, "[");
386             if(base)
387             {
388                strcat(mode, make_signed_hex_str_16(base));
389                comma = 1;
390             }
391             if(*base_reg)
392             {
393                if(comma)
394                   strcat(mode, ",");
395                strcat(mode, base_reg);
396                comma = 1;
397             }
398             if(postindex)
399             {
400                strcat(mode, "]");
401                comma = 1;
402             }
403             if(*index_reg)
404             {
405                if(comma)
406                   strcat(mode, ",");
407                strcat(mode, index_reg);
408                comma = 1;
409             }
410             if(preindex)
411             {
412                strcat(mode, "]");
413                comma = 1;
414             }
415             if(outer)
416             {
417                if(comma)
418                   strcat(mode, ",");
419                strcat(mode, make_signed_hex_str_16(outer));
420             }
421             strcat(mode, ")");
422             break;
423          }
424 
425          if(EXT_8BIT_DISPLACEMENT(extension) == 0)
426             sprintf(mode, "(A%d,%c%d.%c", instruction&7, EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
427          else
428             sprintf(mode, "(%s,A%d,%c%d.%c", make_signed_hex_str_8(extension), instruction&7, EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
429          if(EXT_INDEX_SCALE(extension))
430             sprintf(mode+strlen(mode), "*%d", 1 << EXT_INDEX_SCALE(extension));
431          strcat(mode, ")");
432          break;
433       case 0x38:
434       /* absolute short address */
435          sprintf(mode, "$%x.w", read_imm_16());
436          break;
437       case 0x39:
438       /* absolute long address */
439          sprintf(mode, "$%x.l", read_imm_32());
440          break;
441       case 0x3a:
442       /* program counter with displacement */
443          temp_value = read_imm_16();
444          sprintf(mode, "(%s,PC)", make_signed_hex_str_16(temp_value));
445          sprintf(g_helper_str, "; ($%x)", (make_int_16(temp_value) + g_cpu_pc-2) & 0xffffffff);
446          break;
447       case 0x3b:
448       /* program counter with index */
449          extension = read_imm_16();
450 
451          if(EXT_FULL(extension))
452          {
453             if(EXT_EFFECTIVE_ZERO(extension))
454             {
455                strcpy(mode, "0");
456                break;
457             }
458             base = EXT_BASE_DISPLACEMENT_PRESENT(extension) ? (EXT_BASE_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
459             outer = EXT_OUTER_DISPLACEMENT_PRESENT(extension) ? (EXT_OUTER_DISPLACEMENT_LONG(extension) ? read_imm_32() : read_imm_16()) : 0;
460             if(EXT_BASE_REGISTER_PRESENT(extension))
461                strcpy(base_reg, "PC");
462             else
463                *base_reg = 0;
464             if(EXT_INDEX_REGISTER_PRESENT(extension))
465             {
466                sprintf(index_reg, "%c%d.%c", EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
467                if(EXT_INDEX_SCALE(extension))
468                   sprintf(index_reg+strlen(index_reg), "*%d", 1 << EXT_INDEX_SCALE(extension));
469             }
470             else
471                *index_reg = 0;
472             preindex = (extension&7) > 0 && (extension&7) < 4;
473             postindex = (extension&7) > 4;
474 
475             strcpy(mode, "(");
476             if(preindex || postindex)
477                strcat(mode, "[");
478             if(base)
479             {
480                strcat(mode, make_signed_hex_str_16(base));
481                comma = 1;
482             }
483             if(*base_reg)
484             {
485                if(comma)
486                   strcat(mode, ",");
487                strcat(mode, base_reg);
488                comma = 1;
489             }
490             if(postindex)
491             {
492                strcat(mode, "]");
493                comma = 1;
494             }
495             if(*index_reg)
496             {
497                if(comma)
498                   strcat(mode, ",");
499                strcat(mode, index_reg);
500                comma = 1;
501             }
502             if(preindex)
503             {
504                strcat(mode, "]");
505                comma = 1;
506             }
507             if(outer)
508             {
509                if(comma)
510                   strcat(mode, ",");
511                strcat(mode, make_signed_hex_str_16(outer));
512             }
513             strcat(mode, ")");
514             break;
515          }
516 
517          if(EXT_8BIT_DISPLACEMENT(extension) == 0)
518             sprintf(mode, "(PC,%c%d.%c", EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
519          else
520             sprintf(mode, "(%s,PC,%c%d.%c", make_signed_hex_str_8(extension), EXT_INDEX_AR(extension) ? 'A' : 'D', EXT_INDEX_REGISTER(extension), EXT_INDEX_LONG(extension) ? 'l' : 'w');
521          if(EXT_INDEX_SCALE(extension))
522             sprintf(mode+strlen(mode), "*%d", 1 << EXT_INDEX_SCALE(extension));
523          strcat(mode, ")");
524          break;
525       case 0x3c:
526       /* Immediate */
527          sprintf(mode, "%s", get_imm_str_u(size));
528          break;
529       default:
530          sprintf(mode, "INVALID %x", instruction & 0x3f);
531    }
532    return mode;
533 }
534 
535 
536 
537 /* ======================================================================== */
538 /* ================================= API ================================== */
539 /* ======================================================================== */
540 
541 /* Disasemble one instruction at pc and store in str_buff */
m68k_disassemble(char * str_buff,int pc)542 int m68k_disassemble(char* str_buff, int pc)
543 {
544    if(!g_initialized)
545    {
546       build_opcode_table();
547       g_initialized = 1;
548    }
549    g_cpu_pc = pc;
550    g_helper_str[0] = 0;
551    g_cpu_ir = read_imm_16();
552    g_instruction_table[g_cpu_ir]();
553    sprintf(str_buff, "%s%s", g_dasm_str, g_helper_str);
554    return g_cpu_pc - pc;
555 }
556 
m68k_disassemble_quick(int pc)557 char* m68k_disassemble_quick(int pc)
558 {
559    static char dasm_str[200];
560 
561    if(!g_initialized)
562    {
563       build_opcode_table();
564       g_initialized = 1;
565    }
566    g_cpu_pc = pc;
567    g_helper_str[0] = 0;
568    g_cpu_ir = read_imm_16();
569    g_instruction_table[g_cpu_ir]();
570    sprintf(dasm_str, "%s%s", g_dasm_str, g_helper_str);
571    return dasm_str;
572 }
573 
574 
575 /* ======================================================================== */
576 /* ========================= INSTRUCTION HANDLERS ========================= */
577 /* ======================================================================== */
578 /* Instruction handler function names follow this convention:
579  *
580  * d68000_NAME_EXTENSIONS(void)
581  * where NAME is the name of the opcode it handles and EXTENSIONS are any
582  * extensions for special instances of that opcode.
583  *
584  * Examples:
585  *   d68000_add_er_8(): add opcode, from effective address to register,
586  *                      size = byte
587  *
588  *   d68000_asr_s_8(): arithmetic shift right, static count, size = byte
589  *
590  *
591  * Common extensions:
592  * 8   : size = byte
593  * 16  : size = word
594  * 32  : size = long
595  * rr  : register to register
596  * mm  : memory to memory
597  * r   : register
598  * s   : static
599  * er  : effective address -> register
600  * re  : register -> effective address
601  * ea  : using effective address mode of operation
602  * d   : data register direct
603  * a   : address register direct
604  * ai  : address register indirect
605  * pi  : address register indirect with postincrement
606  * pd  : address register indirect with predecrement
607  * di  : address register indirect with displacement
608  * ix  : address register indirect with index
609  * aw  : absolute word
610  * al  : absolute long
611  */
612 
d68000_1010(void)613 static void d68000_1010(void)
614 {
615    sprintf(g_dasm_str, "dc.w    $%04x; opcode 1010", g_cpu_ir);
616 }
617 
618 
d68000_1111(void)619 static void d68000_1111(void)
620 {
621    sprintf(g_dasm_str, "dc.w    $%04x; opcode 1111", g_cpu_ir);
622 }
623 
624 
d68000_abcd_rr(void)625 static void d68000_abcd_rr(void)
626 {
627    sprintf(g_dasm_str, "abcd    D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
628 }
629 
630 
d68000_abcd_mm(void)631 static void d68000_abcd_mm(void)
632 {
633    sprintf(g_dasm_str, "abcd    -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
634 }
635 
d68000_add_er_8(void)636 static void d68000_add_er_8(void)
637 {
638    sprintf(g_dasm_str, "add.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
639 }
640 
641 
d68000_add_er_16(void)642 static void d68000_add_er_16(void)
643 {
644    sprintf(g_dasm_str, "add.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
645 }
646 
d68000_add_er_32(void)647 static void d68000_add_er_32(void)
648 {
649    sprintf(g_dasm_str, "add.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
650 }
651 
d68000_add_re_8(void)652 static void d68000_add_re_8(void)
653 {
654    sprintf(g_dasm_str, "add.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
655 }
656 
d68000_add_re_16(void)657 static void d68000_add_re_16(void)
658 {
659    sprintf(g_dasm_str, "add.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
660 }
661 
d68000_add_re_32(void)662 static void d68000_add_re_32(void)
663 {
664    sprintf(g_dasm_str, "add.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
665 }
666 
d68000_adda_16(void)667 static void d68000_adda_16(void)
668 {
669    sprintf(g_dasm_str, "adda.w  %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
670 }
671 
d68000_adda_32(void)672 static void d68000_adda_32(void)
673 {
674    sprintf(g_dasm_str, "adda.l  %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
675 }
676 
d68000_addi_8(void)677 static void d68000_addi_8(void)
678 {
679    char* str = get_imm_str_s8();
680    sprintf(g_dasm_str, "addi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
681 }
682 
d68000_addi_16(void)683 static void d68000_addi_16(void)
684 {
685    char* str = get_imm_str_s16();
686    sprintf(g_dasm_str, "addi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
687 }
688 
d68000_addi_32(void)689 static void d68000_addi_32(void)
690 {
691    char* str = get_imm_str_s32();
692    sprintf(g_dasm_str, "addi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
693 }
694 
d68000_addq_8(void)695 static void d68000_addq_8(void)
696 {
697    sprintf(g_dasm_str, "addq.b  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_8(g_cpu_ir));
698 }
699 
d68000_addq_16(void)700 static void d68000_addq_16(void)
701 {
702    sprintf(g_dasm_str, "addq.w  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_16(g_cpu_ir));
703 }
704 
d68000_addq_32(void)705 static void d68000_addq_32(void)
706 {
707    sprintf(g_dasm_str, "addq.l  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_32(g_cpu_ir));
708 }
709 
d68000_addx_rr_8(void)710 static void d68000_addx_rr_8(void)
711 {
712    sprintf(g_dasm_str, "addx.b  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
713 }
714 
d68000_addx_rr_16(void)715 static void d68000_addx_rr_16(void)
716 {
717    sprintf(g_dasm_str, "addx.w  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
718 }
719 
d68000_addx_rr_32(void)720 static void d68000_addx_rr_32(void)
721 {
722    sprintf(g_dasm_str, "addx.l  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
723 }
724 
d68000_addx_mm_8(void)725 static void d68000_addx_mm_8(void)
726 {
727    sprintf(g_dasm_str, "addx.b  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
728 }
729 
d68000_addx_mm_16(void)730 static void d68000_addx_mm_16(void)
731 {
732    sprintf(g_dasm_str, "addx.w  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
733 }
734 
d68000_addx_mm_32(void)735 static void d68000_addx_mm_32(void)
736 {
737    sprintf(g_dasm_str, "addx.l  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
738 }
739 
d68000_and_er_8(void)740 static void d68000_and_er_8(void)
741 {
742    sprintf(g_dasm_str, "and.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
743 }
744 
d68000_and_er_16(void)745 static void d68000_and_er_16(void)
746 {
747    sprintf(g_dasm_str, "and.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
748 }
749 
d68000_and_er_32(void)750 static void d68000_and_er_32(void)
751 {
752    sprintf(g_dasm_str, "and.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
753 }
754 
d68000_and_re_8(void)755 static void d68000_and_re_8(void)
756 {
757    sprintf(g_dasm_str, "and.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
758 }
759 
d68000_and_re_16(void)760 static void d68000_and_re_16(void)
761 {
762    sprintf(g_dasm_str, "and.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
763 }
764 
d68000_and_re_32(void)765 static void d68000_and_re_32(void)
766 {
767    sprintf(g_dasm_str, "and.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
768 }
769 
d68000_andi_8(void)770 static void d68000_andi_8(void)
771 {
772    char* str = get_imm_str_u8();
773    sprintf(g_dasm_str, "andi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
774 }
775 
d68000_andi_16(void)776 static void d68000_andi_16(void)
777 {
778    char* str = get_imm_str_u16();
779    sprintf(g_dasm_str, "andi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
780 }
781 
d68000_andi_32(void)782 static void d68000_andi_32(void)
783 {
784    char* str = get_imm_str_u32();
785    sprintf(g_dasm_str, "andi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
786 }
787 
d68000_andi_to_ccr(void)788 static void d68000_andi_to_ccr(void)
789 {
790    sprintf(g_dasm_str, "andi    %s, CCR", get_imm_str_u8());
791 }
792 
d68000_andi_to_sr(void)793 static void d68000_andi_to_sr(void)
794 {
795    sprintf(g_dasm_str, "andi    %s, SR", get_imm_str_u16());
796 }
797 
d68000_asr_s_8(void)798 static void d68000_asr_s_8(void)
799 {
800    sprintf(g_dasm_str, "asr.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
801 }
802 
d68000_asr_s_16(void)803 static void d68000_asr_s_16(void)
804 {
805    sprintf(g_dasm_str, "asr.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
806 }
807 
d68000_asr_s_32(void)808 static void d68000_asr_s_32(void)
809 {
810    sprintf(g_dasm_str, "asr.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
811 }
812 
d68000_asr_r_8(void)813 static void d68000_asr_r_8(void)
814 {
815    sprintf(g_dasm_str, "asr.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
816 }
817 
d68000_asr_r_16(void)818 static void d68000_asr_r_16(void)
819 {
820    sprintf(g_dasm_str, "asr.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
821 }
822 
d68000_asr_r_32(void)823 static void d68000_asr_r_32(void)
824 {
825    sprintf(g_dasm_str, "asr.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
826 }
827 
d68000_asr_ea(void)828 static void d68000_asr_ea(void)
829 {
830    sprintf(g_dasm_str, "asr.w   %s", get_ea_mode_str_16(g_cpu_ir));
831 }
832 
d68000_asl_s_8(void)833 static void d68000_asl_s_8(void)
834 {
835    sprintf(g_dasm_str, "asl.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
836 }
837 
d68000_asl_s_16(void)838 static void d68000_asl_s_16(void)
839 {
840    sprintf(g_dasm_str, "asl.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
841 }
842 
d68000_asl_s_32(void)843 static void d68000_asl_s_32(void)
844 {
845    sprintf(g_dasm_str, "asl.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
846 }
847 
d68000_asl_r_8(void)848 static void d68000_asl_r_8(void)
849 {
850    sprintf(g_dasm_str, "asl.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
851 }
852 
d68000_asl_r_16(void)853 static void d68000_asl_r_16(void)
854 {
855    sprintf(g_dasm_str, "asl.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
856 }
857 
d68000_asl_r_32(void)858 static void d68000_asl_r_32(void)
859 {
860    sprintf(g_dasm_str, "asl.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
861 }
862 
d68000_asl_ea(void)863 static void d68000_asl_ea(void)
864 {
865    sprintf(g_dasm_str, "asl.w   %s", get_ea_mode_str_16(g_cpu_ir));
866 }
867 
d68000_bcc_8(void)868 static void d68000_bcc_8(void)
869 {
870    uint temp_pc = g_cpu_pc;
871    sprintf(g_dasm_str, "b%-2s     %x", g_cc[(g_cpu_ir>>8)&0xf], temp_pc + make_int_8(g_cpu_ir));
872 }
873 
d68000_bcc_16(void)874 static void d68000_bcc_16(void)
875 {
876    uint temp_pc = g_cpu_pc;
877    sprintf(g_dasm_str, "b%-2s     %x", g_cc[(g_cpu_ir>>8)&0xf], temp_pc + make_int_16(read_imm_16()));
878 }
879 
d68020_bcc_32(void)880 static void d68020_bcc_32(void)
881 {
882    uint temp_pc = g_cpu_pc;
883    sprintf(g_dasm_str, "b%-2s     %x; (2+)", g_cc[(g_cpu_ir>>8)&0xf], temp_pc + read_imm_32());
884 }
885 
d68000_bchg_r(void)886 static void d68000_bchg_r(void)
887 {
888    sprintf(g_dasm_str, "bchg    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
889 }
890 
d68000_bchg_s(void)891 static void d68000_bchg_s(void)
892 {
893    char* str = get_imm_str_s8();
894    sprintf(g_dasm_str, "bchg    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
895 }
896 
d68000_bclr_r(void)897 static void d68000_bclr_r(void)
898 {
899    sprintf(g_dasm_str, "bclr    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
900 }
901 
d68000_bclr_s(void)902 static void d68000_bclr_s(void)
903 {
904    char* str = get_imm_str_s8();
905    sprintf(g_dasm_str, "bclr    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
906 }
907 
d68010_bkpt(void)908 static void d68010_bkpt(void)
909 {
910    sprintf(g_dasm_str, "bkpt #%d; (1+)", g_cpu_ir&7);
911 }
912 
d68020_bfchg(void)913 static void d68020_bfchg(void)
914 {
915    uint extension = read_imm_16();
916    char offset[3];
917    char width[3];
918 
919    if(BIT_B(extension))
920       sprintf(offset, "D%d", (extension>>6)&7);
921    else
922       sprintf(offset, "%d", (extension>>6)&31);
923    if(BIT_5(extension))
924       sprintf(width, "D%d", (extension>>6)&7);
925    else
926       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
927    sprintf(g_dasm_str, "bfchg   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
928 }
929 
d68020_bfclr(void)930 static void d68020_bfclr(void)
931 {
932    uint extension = read_imm_16();
933    char offset[3];
934    char width[3];
935 
936    if(BIT_B(extension))
937       sprintf(offset, "D%d", (extension>>6)&7);
938    else
939       sprintf(offset, "%d", (extension>>6)&31);
940    if(BIT_5(extension))
941       sprintf(width, "D%d", (extension>>6)&7);
942    else
943       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
944    sprintf(g_dasm_str, "bfclr   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
945 }
946 
d68020_bfexts(void)947 static void d68020_bfexts(void)
948 {
949    uint extension = read_imm_16();
950    char offset[3];
951    char width[3];
952 
953    if(BIT_B(extension))
954       sprintf(offset, "D%d", (extension>>6)&7);
955    else
956       sprintf(offset, "%d", (extension>>6)&31);
957    if(BIT_5(extension))
958       sprintf(width, "D%d", (extension>>6)&7);
959    else
960       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
961    sprintf(g_dasm_str, "bfexts  %s {%s:%s}, D%d; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width, (extension>>12)&7);
962 }
963 
d68020_bfextu(void)964 static void d68020_bfextu(void)
965 {
966    uint extension = read_imm_16();
967    char offset[3];
968    char width[3];
969 
970    if(BIT_B(extension))
971       sprintf(offset, "D%d", (extension>>6)&7);
972    else
973       sprintf(offset, "%d", (extension>>6)&31);
974    if(BIT_5(extension))
975       sprintf(width, "D%d", (extension>>6)&7);
976    else
977       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
978    sprintf(g_dasm_str, "bfextu  %s {%s:%s}, D%d; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width, (extension>>12)&7);
979 }
980 
d68020_bfffo(void)981 static void d68020_bfffo(void)
982 {
983    uint extension = read_imm_16();
984    char offset[3];
985    char width[3];
986 
987    if(BIT_B(extension))
988       sprintf(offset, "D%d", (extension>>6)&7);
989    else
990       sprintf(offset, "%d", (extension>>6)&31);
991    if(BIT_5(extension))
992       sprintf(width, "D%d", (extension>>6)&7);
993    else
994       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
995    sprintf(g_dasm_str, "bfffo   %s {%s:%s}, D%d; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width, (extension>>12)&7);
996 }
997 
d68020_bfins(void)998 static void d68020_bfins(void)
999 {
1000    uint extension = read_imm_16();
1001    char offset[3];
1002    char width[3];
1003 
1004    if(BIT_B(extension))
1005       sprintf(offset, "D%d", (extension>>6)&7);
1006    else
1007       sprintf(offset, "%d", (extension>>6)&31);
1008    if(BIT_5(extension))
1009       sprintf(width, "D%d", (extension>>6)&7);
1010    else
1011       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
1012    sprintf(g_dasm_str, "bfins   %s {%s:%s}, D%d; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width, (extension>>12)&7);
1013 }
1014 
d68020_bfset(void)1015 static void d68020_bfset(void)
1016 {
1017    uint extension = read_imm_16();
1018    char offset[3];
1019    char width[3];
1020 
1021    if(BIT_B(extension))
1022       sprintf(offset, "D%d", (extension>>6)&7);
1023    else
1024       sprintf(offset, "%d", (extension>>6)&31);
1025    if(BIT_5(extension))
1026       sprintf(width, "D%d", (extension>>6)&7);
1027    else
1028       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
1029    sprintf(g_dasm_str, "bfset   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
1030 }
1031 
d68020_bftst(void)1032 static void d68020_bftst(void)
1033 {
1034    uint extension = read_imm_16();
1035    char offset[3];
1036    char width[3];
1037 
1038    if(BIT_B(extension))
1039       sprintf(offset, "D%d", (extension>>6)&7);
1040    else
1041       sprintf(offset, "%d", (extension>>6)&31);
1042    if(BIT_5(extension))
1043       sprintf(width, "D%d", (extension>>6)&7);
1044    else
1045       sprintf(width, "%d", g_5bit_data_table[(extension>>6)&31]);
1046    sprintf(g_dasm_str, "bftst   %s {%s:%s}; (2+)", get_ea_mode_str_8(g_cpu_ir), offset, width);
1047 }
1048 
d68000_bra_8(void)1049 static void d68000_bra_8(void)
1050 {
1051    uint temp_pc = g_cpu_pc;
1052    sprintf(g_dasm_str, "bra     %x", temp_pc + make_int_8(g_cpu_ir));
1053 }
1054 
d68000_bra_16(void)1055 static void d68000_bra_16(void)
1056 {
1057    uint temp_pc = g_cpu_pc;
1058    sprintf(g_dasm_str, "bra     %x", temp_pc + make_int_16(read_imm_16()));
1059 }
1060 
d68020_bra_32(void)1061 static void d68020_bra_32(void)
1062 {
1063    uint temp_pc = g_cpu_pc;
1064    sprintf(g_dasm_str, "bra     %x; (2+)", temp_pc + read_imm_32());
1065 }
1066 
d68000_bset_r(void)1067 static void d68000_bset_r(void)
1068 {
1069    sprintf(g_dasm_str, "bset    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
1070 }
1071 
d68000_bset_s(void)1072 static void d68000_bset_s(void)
1073 {
1074    char* str = get_imm_str_s8();
1075    sprintf(g_dasm_str, "bset    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
1076 }
1077 
d68000_bsr_8(void)1078 static void d68000_bsr_8(void)
1079 {
1080    uint temp_pc = g_cpu_pc;
1081    sprintf(g_dasm_str, "bsr     %x", temp_pc + make_int_8(g_cpu_ir));
1082 }
1083 
d68000_bsr_16(void)1084 static void d68000_bsr_16(void)
1085 {
1086    uint temp_pc = g_cpu_pc;
1087    sprintf(g_dasm_str, "bsr     %x", temp_pc + make_int_16(read_imm_16()));
1088 }
1089 
d68020_bsr_32(void)1090 static void d68020_bsr_32(void)
1091 {
1092    uint temp_pc = g_cpu_pc;
1093    sprintf(g_dasm_str, "bsr     %x; (2+)", temp_pc + peek_imm_32());
1094 }
1095 
d68000_btst_r(void)1096 static void d68000_btst_r(void)
1097 {
1098    sprintf(g_dasm_str, "btst    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
1099 }
1100 
d68000_btst_s(void)1101 static void d68000_btst_s(void)
1102 {
1103    char* str = get_imm_str_s8();
1104    sprintf(g_dasm_str, "btst    %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
1105 }
1106 
d68020_callm(void)1107 static void d68020_callm(void)
1108 {
1109    char* str = get_imm_str_u8();
1110    sprintf(g_dasm_str, "callm   %s, %s; (2)", str, get_ea_mode_str_8(g_cpu_ir));
1111 }
1112 
d68020_cas_8(void)1113 static void d68020_cas_8(void)
1114 {
1115    uint extension = read_imm_16();
1116    sprintf(g_dasm_str, "cas.b   D%d, D%d, %s; (2+)", extension&7, (extension>>8)&7, get_ea_mode_str_8(g_cpu_ir));
1117 }
1118 
d68020_cas_16(void)1119 static void d68020_cas_16(void)
1120 {
1121    uint extension = read_imm_16();
1122    sprintf(g_dasm_str, "cas.w   D%d, D%d, %s; (2+)", extension&7, (extension>>8)&7, get_ea_mode_str_16(g_cpu_ir));
1123 }
1124 
d68020_cas_32(void)1125 static void d68020_cas_32(void)
1126 {
1127    uint extension = read_imm_16();
1128    sprintf(g_dasm_str, "cas.l   D%d, D%d, %s; (2+)", extension&7, (extension>>8)&7, get_ea_mode_str_32(g_cpu_ir));
1129 }
1130 
d68020_cas2_16(void)1131 static void d68020_cas2_16(void)
1132 {
1133    uint extension = read_imm_32();
1134    sprintf(g_dasm_str, "cas2.w  D%d:D%d:D%d:D%d, (%c%d):(%c%d); (2+)",
1135       (extension>>16)&7, extension&7, (extension>>22)&7, (extension>>6)&7,
1136       BIT_1F(extension) ? 'A' : 'D', (extension>>28)&7,
1137       BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
1138 }
1139 
d68020_cas2_32(void)1140 static void d68020_cas2_32(void)
1141 {
1142    uint extension = read_imm_32();
1143    sprintf(g_dasm_str, "cas2.l  D%d:D%d:D%d:D%d, (%c%d):(%c%d); (2+)",
1144       (extension>>16)&7, extension&7, (extension>>22)&7, (extension>>6)&7,
1145       BIT_1F(extension) ? 'A' : 'D', (extension>>28)&7,
1146       BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
1147 }
1148 
d68000_chk_16(void)1149 static void d68000_chk_16(void)
1150 {
1151    sprintf(g_dasm_str, "chk.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
1152 }
1153 
d68020_chk_32(void)1154 static void d68020_chk_32(void)
1155 {
1156    sprintf(g_dasm_str, "chk.l   %s, D%d; (2+)", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
1157 }
1158 
d68020_chk2_cmp2_8(void)1159 static void d68020_chk2_cmp2_8(void)
1160 {
1161    uint extension = read_imm_16();
1162    sprintf(g_dasm_str, "%s.b  %s, %c%d; (2+)", BIT_B(extension) ? "chk2" : "cmp2", get_ea_mode_str_8(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
1163 }
1164 
d68020_chk2_cmp2_16(void)1165 static void d68020_chk2_cmp2_16(void)
1166 {
1167    uint extension = read_imm_16();
1168    sprintf(g_dasm_str, "%s.w  %s, %c%d; (2+)", BIT_B(extension) ? "chk2" : "cmp2", get_ea_mode_str_16(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
1169 }
1170 
d68020_chk2_cmp2_32(void)1171 static void d68020_chk2_cmp2_32(void)
1172 {
1173    uint extension = read_imm_16();
1174    sprintf(g_dasm_str, "%s.l  %s, %c%d; (2+)", BIT_B(extension) ? "chk2" : "cmp2", get_ea_mode_str_32(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
1175 }
1176 
d68040_cinv(void)1177 static void d68040_cinv(void)
1178 {
1179    switch((g_cpu_ir>>3)&3)
1180    {
1181       case 0:
1182          sprintf(g_dasm_str, "cinv (illegal scope); (4)");
1183          break;
1184       case 1:
1185          sprintf(g_dasm_str, "cinvl   %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
1186          break;
1187       case 2:
1188          sprintf(g_dasm_str, "cinvp   %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
1189          break;
1190       case 3:
1191          sprintf(g_dasm_str, "cinva   %d; (4)", (g_cpu_ir>>6)&3);
1192          break;
1193    }
1194 }
1195 
d68000_clr_8(void)1196 static void d68000_clr_8(void)
1197 {
1198    sprintf(g_dasm_str, "clr.b   %s", get_ea_mode_str_8(g_cpu_ir));
1199 }
1200 
d68000_clr_16(void)1201 static void d68000_clr_16(void)
1202 {
1203    sprintf(g_dasm_str, "clr.w   %s", get_ea_mode_str_16(g_cpu_ir));
1204 }
1205 
d68000_clr_32(void)1206 static void d68000_clr_32(void)
1207 {
1208    sprintf(g_dasm_str, "clr.l   %s", get_ea_mode_str_32(g_cpu_ir));
1209 }
1210 
d68000_cmp_8(void)1211 static void d68000_cmp_8(void)
1212 {
1213    sprintf(g_dasm_str, "cmp.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
1214 }
1215 
d68000_cmp_16(void)1216 static void d68000_cmp_16(void)
1217 {
1218    sprintf(g_dasm_str, "cmp.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
1219 }
1220 
d68000_cmp_32(void)1221 static void d68000_cmp_32(void)
1222 {
1223    sprintf(g_dasm_str, "cmp.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
1224 }
1225 
d68000_cmpa_16(void)1226 static void d68000_cmpa_16(void)
1227 {
1228    sprintf(g_dasm_str, "cmpa.w  %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
1229 }
1230 
d68000_cmpa_32(void)1231 static void d68000_cmpa_32(void)
1232 {
1233    sprintf(g_dasm_str, "cmpa.l  %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
1234 }
1235 
d68000_cmpi_8(void)1236 static void d68000_cmpi_8(void)
1237 {
1238    char* str = get_imm_str_s8();
1239    sprintf(g_dasm_str, "cmpi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
1240 }
1241 
d68020_cmpi_pcdi_8(void)1242 static void d68020_cmpi_pcdi_8(void)
1243 {
1244    char* str = get_imm_str_s8();
1245    sprintf(g_dasm_str, "cmpi.b  %s, %s; (2+)", str, get_ea_mode_str_8(g_cpu_ir));
1246 }
1247 
d68020_cmpi_pcix_8(void)1248 static void d68020_cmpi_pcix_8(void)
1249 {
1250    char* str = get_imm_str_s8();
1251    sprintf(g_dasm_str, "cmpi.b  %s, %s; (2+)", str, get_ea_mode_str_8(g_cpu_ir));
1252 }
1253 
d68000_cmpi_16(void)1254 static void d68000_cmpi_16(void)
1255 {
1256    char* str = get_imm_str_s16();
1257    sprintf(g_dasm_str, "cmpi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
1258 }
1259 
d68020_cmpi_pcdi_16(void)1260 static void d68020_cmpi_pcdi_16(void)
1261 {
1262    char* str = get_imm_str_s16();
1263    sprintf(g_dasm_str, "cmpi.w  %s, %s; (2+)", str, get_ea_mode_str_16(g_cpu_ir));
1264 }
1265 
d68020_cmpi_pcix_16(void)1266 static void d68020_cmpi_pcix_16(void)
1267 {
1268    char* str = get_imm_str_s16();
1269    sprintf(g_dasm_str, "cmpi.w  %s, %s; (2+)", str, get_ea_mode_str_16(g_cpu_ir));
1270 }
1271 
d68000_cmpi_32(void)1272 static void d68000_cmpi_32(void)
1273 {
1274    char* str = get_imm_str_s32();
1275    sprintf(g_dasm_str, "cmpi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
1276 }
1277 
d68020_cmpi_pcdi_32(void)1278 static void d68020_cmpi_pcdi_32(void)
1279 {
1280    char* str = get_imm_str_s32();
1281    sprintf(g_dasm_str, "cmpi.l  %s, %s; (2+)", str, get_ea_mode_str_32(g_cpu_ir));
1282 }
1283 
d68020_cmpi_pcix_32(void)1284 static void d68020_cmpi_pcix_32(void)
1285 {
1286    char* str = get_imm_str_s32();
1287    sprintf(g_dasm_str, "cmpi.l  %s, %s; (2+)", str, get_ea_mode_str_32(g_cpu_ir));
1288 }
1289 
d68000_cmpm_8(void)1290 static void d68000_cmpm_8(void)
1291 {
1292    sprintf(g_dasm_str, "cmpm.b  (A%d)+, (A%d)+", g_cpu_ir&7, (g_cpu_ir>>9)&7);
1293 }
1294 
d68000_cmpm_16(void)1295 static void d68000_cmpm_16(void)
1296 {
1297    sprintf(g_dasm_str, "cmpm.w  (A%d)+, (A%d)+", g_cpu_ir&7, (g_cpu_ir>>9)&7);
1298 }
1299 
d68000_cmpm_32(void)1300 static void d68000_cmpm_32(void)
1301 {
1302    sprintf(g_dasm_str, "cmpm.l  (A%d)+, (A%d)+", g_cpu_ir&7, (g_cpu_ir>>9)&7);
1303 }
1304 
d68020_cpbcc_16(void)1305 static void d68020_cpbcc_16(void)
1306 {
1307    uint extension = read_imm_16();
1308    uint new_pc = g_cpu_pc;
1309    new_pc += make_int_16(peek_imm_16());
1310    sprintf(g_dasm_str, "%db%-4s  %s; %x (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[g_cpu_ir&0x3f], get_imm_str_s16(), new_pc, extension);
1311 }
1312 
d68020_cpbcc_32(void)1313 static void d68020_cpbcc_32(void)
1314 {
1315    uint extension = read_imm_16();
1316    uint new_pc = g_cpu_pc;
1317    new_pc += peek_imm_32();
1318    sprintf(g_dasm_str, "%db%-4s  %s; %x (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[g_cpu_ir&0x3f], get_imm_str_s16(), new_pc, extension);
1319 }
1320 
d68020_cpdbcc(void)1321 static void d68020_cpdbcc(void)
1322 {
1323    uint extension1 = read_imm_16();
1324    uint extension2 = read_imm_16();
1325    uint new_pc = g_cpu_pc;
1326    new_pc += make_int_16(peek_imm_16());
1327    sprintf(g_dasm_str, "%ddb%-4s D%d,%s; %x (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], g_cpu_ir&7, get_imm_str_s16(), new_pc, extension2);
1328 }
1329 
d68020_cpgen(void)1330 static void d68020_cpgen(void)
1331 {
1332    sprintf(g_dasm_str, "%dgen    %s; (2-3)", (g_cpu_ir>>9)&7, get_imm_str_u32());
1333 }
1334 
d68020_cprestore(void)1335 static void d68020_cprestore(void)
1336 {
1337    sprintf(g_dasm_str, "%drestore %s; (2-3)", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
1338 }
1339 
d68020_cpsave(void)1340 static void d68020_cpsave(void)
1341 {
1342    sprintf(g_dasm_str, "%dsave   %s; (2-3)", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
1343 }
1344 
d68020_cpscc(void)1345 static void d68020_cpscc(void)
1346 {
1347    uint extension1 = read_imm_16();
1348    uint extension2 = read_imm_16();
1349    sprintf(g_dasm_str, "%ds%-4s  %s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], get_ea_mode_str_8(g_cpu_ir), extension2);
1350 }
1351 
d68020_cptrapcc_0(void)1352 static void d68020_cptrapcc_0(void)
1353 {
1354    uint extension1 = read_imm_16();
1355    uint extension2 = read_imm_16();
1356    sprintf(g_dasm_str, "%dtrap%-4s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], extension2);
1357 }
1358 
d68020_cptrapcc_16(void)1359 static void d68020_cptrapcc_16(void)
1360 {
1361    uint extension1 = read_imm_16();
1362    uint extension2 = read_imm_16();
1363    sprintf(g_dasm_str, "%dtrap%-4s %s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], get_imm_str_u16(), extension2);
1364 }
1365 
d68020_cptrapcc_32(void)1366 static void d68020_cptrapcc_32(void)
1367 {
1368    uint extension1 = read_imm_16();
1369    uint extension2 = read_imm_16();
1370    sprintf(g_dasm_str, "%dtrap%-4s %s; (extension = %x) (2-3)", (g_cpu_ir>>9)&7, g_cpcc[extension1&0x3f], get_imm_str_u32(), extension2);
1371 }
1372 
d68040_cpush(void)1373 static void d68040_cpush(void)
1374 {
1375    switch((g_cpu_ir>>3)&3)
1376    {
1377       case 0:
1378          sprintf(g_dasm_str, "cpush (illegal scope); (4)");
1379          break;
1380       case 1:
1381          sprintf(g_dasm_str, "cpushl  %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
1382          break;
1383       case 2:
1384          sprintf(g_dasm_str, "cpushp  %d, (A%d); (4)", (g_cpu_ir>>6)&3, g_cpu_ir&7);
1385          break;
1386       case 3:
1387          sprintf(g_dasm_str, "cpusha  %d; (4)", (g_cpu_ir>>6)&3);
1388          break;
1389    }
1390 }
1391 
d68000_dbra(void)1392 static void d68000_dbra(void)
1393 {
1394    uint temp_pc = g_cpu_pc;
1395    sprintf(g_dasm_str, "dbra    D%d, %x", g_cpu_ir & 7, temp_pc + make_int_16(read_imm_16()));
1396 }
1397 
d68000_dbcc(void)1398 static void d68000_dbcc(void)
1399 {
1400    uint temp_pc = g_cpu_pc;
1401    sprintf(g_dasm_str, "db%-2s    D%d, %x", g_cc[(g_cpu_ir>>8)&0xf], g_cpu_ir & 7, temp_pc + make_int_16(read_imm_16()));
1402 }
1403 
d68000_divs(void)1404 static void d68000_divs(void)
1405 {
1406    sprintf(g_dasm_str, "divs.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
1407 }
1408 
d68000_divu(void)1409 static void d68000_divu(void)
1410 {
1411    sprintf(g_dasm_str, "divu.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
1412 }
1413 
d68020_divl(void)1414 static void d68020_divl(void)
1415 {
1416    uint extension = read_imm_16();
1417 
1418    if((extension&7) == ((extension>>12)&7))
1419       sprintf(g_dasm_str, "div%c.l  %s, D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), (extension>>12)&7);
1420    else if(BIT_A(extension))
1421       sprintf(g_dasm_str, "div%c.l  %s, D%d:D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), extension&7, (extension>>12)&7);
1422    else
1423       sprintf(g_dasm_str, "div%cl.l %s, D%d:D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), extension&7, (extension>>12)&7);
1424 }
1425 
d68000_eor_8(void)1426 static void d68000_eor_8(void)
1427 {
1428    sprintf(g_dasm_str, "eor.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
1429 }
1430 
d68000_eor_16(void)1431 static void d68000_eor_16(void)
1432 {
1433    sprintf(g_dasm_str, "eor.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
1434 }
1435 
d68000_eor_32(void)1436 static void d68000_eor_32(void)
1437 {
1438    sprintf(g_dasm_str, "eor.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
1439 }
1440 
d68000_eori_8(void)1441 static void d68000_eori_8(void)
1442 {
1443    char* str = get_imm_str_u8();
1444    sprintf(g_dasm_str, "eori.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
1445 }
1446 
d68000_eori_16(void)1447 static void d68000_eori_16(void)
1448 {
1449    char* str = get_imm_str_u16();
1450    sprintf(g_dasm_str, "eori.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
1451 }
1452 
d68000_eori_32(void)1453 static void d68000_eori_32(void)
1454 {
1455    char* str = get_imm_str_u32();
1456    sprintf(g_dasm_str, "eori.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
1457 }
1458 
d68000_eori_to_ccr(void)1459 static void d68000_eori_to_ccr(void)
1460 {
1461    sprintf(g_dasm_str, "eori    %s, CCR", get_imm_str_u8());
1462 }
1463 
d68000_eori_to_sr(void)1464 static void d68000_eori_to_sr(void)
1465 {
1466    sprintf(g_dasm_str, "eori    %s, SR", get_imm_str_u16());
1467 }
1468 
d68000_exg_dd(void)1469 static void d68000_exg_dd(void)
1470 {
1471    sprintf(g_dasm_str, "exg     D%d, D%d", ((g_cpu_ir>>9)&7), g_cpu_ir&7);
1472 }
1473 
d68000_exg_aa(void)1474 static void d68000_exg_aa(void)
1475 {
1476    sprintf(g_dasm_str, "exg     A%d, A%d", ((g_cpu_ir>>9)&7), g_cpu_ir&7);
1477 }
1478 
d68000_exg_da(void)1479 static void d68000_exg_da(void)
1480 {
1481    sprintf(g_dasm_str, "exg     D%d, A%d", ((g_cpu_ir>>9)&7), g_cpu_ir&7);
1482 }
1483 
d68000_ext_16(void)1484 static void d68000_ext_16(void)
1485 {
1486    sprintf(g_dasm_str, "ext.w   D%d", g_cpu_ir&7);
1487 }
1488 
d68000_ext_32(void)1489 static void d68000_ext_32(void)
1490 {
1491    sprintf(g_dasm_str, "ext.l   D%d", g_cpu_ir&7);
1492 }
1493 
d68020_extb_32(void)1494 static void d68020_extb_32(void)
1495 {
1496    sprintf(g_dasm_str, "extb.l  D%d; (2+)", g_cpu_ir&7);
1497 }
1498 
d68000_jmp(void)1499 static void d68000_jmp(void)
1500 {
1501    sprintf(g_dasm_str, "jmp     %s", get_ea_mode_str_32(g_cpu_ir));
1502 }
1503 
d68000_jsr(void)1504 static void d68000_jsr(void)
1505 {
1506    sprintf(g_dasm_str, "jsr     %s", get_ea_mode_str_32(g_cpu_ir));
1507 }
1508 
d68000_lea(void)1509 static void d68000_lea(void)
1510 {
1511    sprintf(g_dasm_str, "lea     %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
1512 }
1513 
d68000_link_16(void)1514 static void d68000_link_16(void)
1515 {
1516    sprintf(g_dasm_str, "link    A%d, %s", g_cpu_ir&7, get_imm_str_s16());
1517 }
1518 
d68020_link_32(void)1519 static void d68020_link_32(void)
1520 {
1521    sprintf(g_dasm_str, "link    A%d, %s; (2+)", g_cpu_ir&7, get_imm_str_s32());
1522 }
1523 
d68000_lsr_s_8(void)1524 static void d68000_lsr_s_8(void)
1525 {
1526    sprintf(g_dasm_str, "lsr.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
1527 }
1528 
d68000_lsr_s_16(void)1529 static void d68000_lsr_s_16(void)
1530 {
1531    sprintf(g_dasm_str, "lsr.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
1532 }
1533 
d68000_lsr_s_32(void)1534 static void d68000_lsr_s_32(void)
1535 {
1536    sprintf(g_dasm_str, "lsr.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
1537 }
1538 
d68000_lsr_r_8(void)1539 static void d68000_lsr_r_8(void)
1540 {
1541    sprintf(g_dasm_str, "lsr.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
1542 }
1543 
d68000_lsr_r_16(void)1544 static void d68000_lsr_r_16(void)
1545 {
1546    sprintf(g_dasm_str, "lsr.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
1547 }
1548 
d68000_lsr_r_32(void)1549 static void d68000_lsr_r_32(void)
1550 {
1551    sprintf(g_dasm_str, "lsr.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
1552 }
1553 
d68000_lsr_ea(void)1554 static void d68000_lsr_ea(void)
1555 {
1556    sprintf(g_dasm_str, "lsr.w   %s", get_ea_mode_str_32(g_cpu_ir));
1557 }
1558 
d68000_lsl_s_8(void)1559 static void d68000_lsl_s_8(void)
1560 {
1561    sprintf(g_dasm_str, "lsl.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
1562 }
1563 
d68000_lsl_s_16(void)1564 static void d68000_lsl_s_16(void)
1565 {
1566    sprintf(g_dasm_str, "lsl.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
1567 }
1568 
d68000_lsl_s_32(void)1569 static void d68000_lsl_s_32(void)
1570 {
1571    sprintf(g_dasm_str, "lsl.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
1572 }
1573 
d68000_lsl_r_8(void)1574 static void d68000_lsl_r_8(void)
1575 {
1576    sprintf(g_dasm_str, "lsl.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
1577 }
1578 
d68000_lsl_r_16(void)1579 static void d68000_lsl_r_16(void)
1580 {
1581    sprintf(g_dasm_str, "lsl.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
1582 }
1583 
d68000_lsl_r_32(void)1584 static void d68000_lsl_r_32(void)
1585 {
1586    sprintf(g_dasm_str, "lsl.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
1587 }
1588 
d68000_lsl_ea(void)1589 static void d68000_lsl_ea(void)
1590 {
1591    sprintf(g_dasm_str, "lsl.w   %s", get_ea_mode_str_32(g_cpu_ir));
1592 }
1593 
d68000_move_8(void)1594 static void d68000_move_8(void)
1595 {
1596    char* str = get_ea_mode_str_8(g_cpu_ir);
1597    sprintf(g_dasm_str, "move.b  %s, %s", str, get_ea_mode_str_8(((g_cpu_ir>>9) & 7) | ((g_cpu_ir>>3) & 0x38)));
1598 }
1599 
d68000_move_16(void)1600 static void d68000_move_16(void)
1601 {
1602    char* str = get_ea_mode_str_16(g_cpu_ir);
1603    sprintf(g_dasm_str, "move.w  %s, %s", str, get_ea_mode_str_16(((g_cpu_ir>>9) & 7) | ((g_cpu_ir>>3) & 0x38)));
1604 }
1605 
d68000_move_32(void)1606 static void d68000_move_32(void)
1607 {
1608    char* str = get_ea_mode_str_32(g_cpu_ir);
1609    sprintf(g_dasm_str, "move.l  %s, %s", str, get_ea_mode_str_32(((g_cpu_ir>>9) & 7) | ((g_cpu_ir>>3) & 0x38)));
1610 }
1611 
d68000_movea_16(void)1612 static void d68000_movea_16(void)
1613 {
1614    sprintf(g_dasm_str, "movea.w %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
1615 }
1616 
d68000_movea_32(void)1617 static void d68000_movea_32(void)
1618 {
1619    sprintf(g_dasm_str, "movea.l %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
1620 }
1621 
d68000_move_to_ccr(void)1622 static void d68000_move_to_ccr(void)
1623 {
1624    sprintf(g_dasm_str, "move    %s, CCR", get_ea_mode_str_8(g_cpu_ir));
1625 }
1626 
d68010_move_fr_ccr(void)1627 static void d68010_move_fr_ccr(void)
1628 {
1629    sprintf(g_dasm_str, "move    CCR, %s; (1+)", get_ea_mode_str_8(g_cpu_ir));
1630 }
1631 
d68000_move_fr_sr(void)1632 static void d68000_move_fr_sr(void)
1633 {
1634    sprintf(g_dasm_str, "move    SR, %s", get_ea_mode_str_16(g_cpu_ir));
1635 }
1636 
d68000_move_to_sr(void)1637 static void d68000_move_to_sr(void)
1638 {
1639    sprintf(g_dasm_str, "move    %s, SR", get_ea_mode_str_16(g_cpu_ir));
1640 }
1641 
d68000_move_fr_usp(void)1642 static void d68000_move_fr_usp(void)
1643 {
1644    sprintf(g_dasm_str, "move    USP, A%d", g_cpu_ir&7);
1645 }
1646 
d68000_move_to_usp(void)1647 static void d68000_move_to_usp(void)
1648 {
1649    sprintf(g_dasm_str, "move    A%d, USP", g_cpu_ir&7);
1650 }
1651 
d68010_movec(void)1652 static void d68010_movec(void)
1653 {
1654    uint extension = read_imm_16();
1655    char* reg_name;
1656    char* processor;
1657 
1658    switch(extension & 0xfff)
1659    {
1660       case 0x000:
1661          reg_name = "SFC";
1662          processor = "1+";
1663          break;
1664       case 0x001:
1665          reg_name = "DFC";
1666          processor = "1+";
1667          break;
1668       case 0x800:
1669          reg_name = "USP";
1670          processor = "1+";
1671          break;
1672       case 0x801:
1673          reg_name = "VBR";
1674          processor = "1+";
1675          break;
1676       case 0x002:
1677          reg_name = "CACR";
1678          processor = "2+";
1679          break;
1680       case 0x802:
1681          reg_name = "CAAR";
1682          processor = "2,3";
1683          break;
1684       case 0x803:
1685          reg_name = "MSP";
1686          processor = "2+";
1687          break;
1688       case 0x804:
1689          reg_name = "ISP";
1690          processor = "2+";
1691          break;
1692       case 0x003:
1693          reg_name = "TC";
1694          processor = "4+";
1695          break;
1696       case 0x004:
1697          reg_name = "ITT0";
1698          processor = "4+";
1699          break;
1700       case 0x005:
1701          reg_name = "ITT1";
1702          processor = "4+";
1703          break;
1704       case 0x006:
1705          reg_name = "DTT0";
1706          processor = "4+";
1707          break;
1708       case 0x007:
1709          reg_name = "DTT1";
1710          processor = "4+";
1711          break;
1712       case 0x805:
1713          reg_name = "MMUSR";
1714          processor = "4+";
1715          break;
1716       case 0x806:
1717          reg_name = "URP";
1718          processor = "4+";
1719          break;
1720       case 0x807:
1721          reg_name = "SRP";
1722          processor = "4+";
1723          break;
1724       default:
1725          reg_name = make_signed_hex_str_16(extension & 0xfff);
1726          processor = "?";
1727    }
1728 
1729    if(BIT_1(g_cpu_ir))
1730       sprintf(g_dasm_str, "movec %c%d, %s; (%s)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, reg_name, processor);
1731    else
1732       sprintf(g_dasm_str, "movec %s, %c%d; (%s)", reg_name, BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, processor);
1733 }
1734 
d68000_movem_pd_16(void)1735 static void d68000_movem_pd_16(void)
1736 {
1737    uint data = read_imm_16();
1738    char buffer[40];
1739    uint first;
1740    uint run_length;
1741    uint i;
1742 
1743    buffer[0] = 0;
1744    for(i=0;i<8;i++)
1745    {
1746       if(data&(1<<(15-i)))
1747       {
1748          first = i;
1749          run_length = 0;
1750          for(i++;i<8;i++)
1751             if(data&(1<<(15-i)))
1752                run_length++;
1753          if(buffer[0] != 0)
1754             strcat(buffer, "/");
1755          sprintf(buffer+strlen(buffer), "D%d", first);
1756          if(run_length > 0)
1757             sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
1758       }
1759    }
1760    for(i=0;i<8;i++)
1761    {
1762       if(data&(1<<(7-i)))
1763       {
1764          first = i;
1765          run_length = 0;
1766          for(i++;i<8;i++)
1767             if(data&(1<<(7-i)))
1768                run_length++;
1769          if(buffer[0] != 0)
1770             strcat(buffer, "/");
1771          sprintf(buffer+strlen(buffer), "A%d", first);
1772          if(run_length > 0)
1773             sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
1774       }
1775    }
1776    sprintf(g_dasm_str, "movem.w %s, %s", buffer, get_ea_mode_str_16(g_cpu_ir));
1777 }
1778 
d68000_movem_pd_32(void)1779 static void d68000_movem_pd_32(void)
1780 {
1781    uint data = read_imm_16();
1782    char buffer[40];
1783    uint first;
1784    uint run_length;
1785    uint i;
1786 
1787    buffer[0] = 0;
1788    for(i=0;i<8;i++)
1789    {
1790       if(data&(1<<(15-i)))
1791       {
1792          first = i;
1793          run_length = 0;
1794          for(i++;i<8;i++)
1795             if(data&(1<<(15-i)))
1796                run_length++;
1797          if(buffer[0] != 0)
1798             strcat(buffer, "/");
1799          sprintf(buffer+strlen(buffer), "D%d", first);
1800          if(run_length > 0)
1801             sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
1802       }
1803    }
1804    for(i=0;i<8;i++)
1805    {
1806       if(data&(1<<(7-i)))
1807       {
1808          first = i;
1809          run_length = 0;
1810          for(i++;i<8;i++)
1811             if(data&(1<<(7-i)))
1812                run_length++;
1813          if(buffer[0] != 0)
1814             strcat(buffer, "/");
1815          sprintf(buffer+strlen(buffer), "A%d", first);
1816          if(run_length > 0)
1817             sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
1818       }
1819    }
1820    sprintf(g_dasm_str, "movem.l %s, %s", buffer, get_ea_mode_str_32(g_cpu_ir));
1821 }
1822 
d68000_movem_er_16(void)1823 static void d68000_movem_er_16(void)
1824 {
1825    uint data = read_imm_16();
1826    char buffer[40];
1827    uint first;
1828    uint run_length;
1829    uint i;
1830 
1831    buffer[0] = 0;
1832    for(i=0;i<8;i++)
1833    {
1834       if(data&(1<<i))
1835       {
1836          first = i;
1837          run_length = 0;
1838          for(i++;i<8;i++)
1839             if(data&(1<<i))
1840                run_length++;
1841          if(buffer[0] != 0)
1842             strcat(buffer, "/");
1843          sprintf(buffer+strlen(buffer), "D%d", first);
1844          if(run_length > 0)
1845             sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
1846       }
1847    }
1848    for(i=0;i<8;i++)
1849    {
1850       if(data&(1<<(i+8)))
1851       {
1852          first = i;
1853          run_length = 0;
1854          for(i++;i<8;i++)
1855             if(data&(1<<(i+8)))
1856                run_length++;
1857          if(buffer[0] != 0)
1858             strcat(buffer, "/");
1859          sprintf(buffer+strlen(buffer), "A%d", first);
1860          if(run_length > 0)
1861             sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
1862       }
1863    }
1864    sprintf(g_dasm_str, "movem.w %s, %s", get_ea_mode_str_16(g_cpu_ir), buffer);
1865 }
1866 
d68000_movem_er_32(void)1867 static void d68000_movem_er_32(void)
1868 {
1869    uint data = read_imm_16();
1870    char buffer[40];
1871    uint first;
1872    uint run_length;
1873    uint i;
1874 
1875    buffer[0] = 0;
1876    for(i=0;i<8;i++)
1877    {
1878       if(data&(1<<i))
1879       {
1880          first = i;
1881          run_length = 0;
1882          for(i++;i<8;i++)
1883             if(data&(1<<i))
1884                run_length++;
1885          if(buffer[0] != 0)
1886             strcat(buffer, "/");
1887          sprintf(buffer+strlen(buffer), "D%d", first);
1888          if(run_length > 0)
1889             sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
1890       }
1891    }
1892    for(i=0;i<8;i++)
1893    {
1894       if(data&(1<<(i+8)))
1895       {
1896          first = i;
1897          run_length = 0;
1898          for(i++;i<8;i++)
1899             if(data&(1<<(i+8)))
1900                run_length++;
1901          if(buffer[0] != 0)
1902             strcat(buffer, "/");
1903          sprintf(buffer+strlen(buffer), "A%d", first);
1904          if(run_length > 0)
1905             sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
1906       }
1907    }
1908    sprintf(g_dasm_str, "movem.l %s, %s", get_ea_mode_str_32(g_cpu_ir), buffer);
1909 }
1910 
d68000_movem_re_16(void)1911 static void d68000_movem_re_16(void)
1912 {
1913    uint data = read_imm_16();
1914    char buffer[40];
1915    uint first;
1916    uint run_length;
1917    uint i;
1918 
1919    buffer[0] = 0;
1920    for(i=0;i<8;i++)
1921    {
1922       if(data&(1<<i))
1923       {
1924          first = i;
1925          run_length = 0;
1926          for(i++;i<8;i++)
1927             if(data&(1<<i))
1928                run_length++;
1929          if(buffer[0] != 0)
1930             strcat(buffer, "/");
1931          sprintf(buffer+strlen(buffer), "D%d", first);
1932          if(run_length > 0)
1933             sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
1934       }
1935    }
1936    for(i=0;i<8;i++)
1937    {
1938       if(data&(1<<(i+8)))
1939       {
1940          first = i;
1941          run_length = 0;
1942          for(i++;i<8;i++)
1943             if(data&(1<<(i+8)))
1944                run_length++;
1945          if(buffer[0] != 0)
1946             strcat(buffer, "/");
1947          sprintf(buffer+strlen(buffer), "A%d", first);
1948          if(run_length > 0)
1949             sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
1950       }
1951    }
1952    sprintf(g_dasm_str, "movem.w %s, %s", buffer, get_ea_mode_str_16(g_cpu_ir));
1953 }
1954 
d68000_movem_re_32(void)1955 static void d68000_movem_re_32(void)
1956 {
1957    uint data = read_imm_16();
1958    char buffer[40];
1959    uint first;
1960    uint run_length;
1961    uint i;
1962 
1963    buffer[0] = 0;
1964    for(i=0;i<8;i++)
1965    {
1966       if(data&(1<<i))
1967       {
1968          first = i;
1969          run_length = 0;
1970          for(i++;i<8;i++)
1971             if(data&(1<<i))
1972                run_length++;
1973          if(buffer[0] != 0)
1974             strcat(buffer, "/");
1975          sprintf(buffer+strlen(buffer), "D%d", first);
1976          if(run_length > 0)
1977             sprintf(buffer+strlen(buffer), "-D%d", first + run_length);
1978       }
1979    }
1980    for(i=0;i<8;i++)
1981    {
1982       if(data&(1<<(i+8)))
1983       {
1984          first = i;
1985          run_length = 0;
1986          for(i++;i<8;i++)
1987             if(data&(1<<(i+8)))
1988                run_length++;
1989          if(buffer[0] != 0)
1990             strcat(buffer, "/");
1991          sprintf(buffer+strlen(buffer), "A%d", first);
1992          if(run_length > 0)
1993             sprintf(buffer+strlen(buffer), "-A%d", first + run_length);
1994       }
1995    }
1996    sprintf(g_dasm_str, "movem.l %s, %s", buffer, get_ea_mode_str_32(g_cpu_ir));
1997 }
1998 
d68000_movep_re_16(void)1999 static void d68000_movep_re_16(void)
2000 {
2001    sprintf(g_dasm_str, "movep.w D%d, ($%x,A%d)", (g_cpu_ir>>9)&7, read_imm_16(), g_cpu_ir&7);
2002 }
2003 
d68000_movep_re_32(void)2004 static void d68000_movep_re_32(void)
2005 {
2006    sprintf(g_dasm_str, "movep.l D%d, ($%x,A%d)", (g_cpu_ir>>9)&7, read_imm_16(), g_cpu_ir&7);
2007 }
2008 
d68000_movep_er_16(void)2009 static void d68000_movep_er_16(void)
2010 {
2011    sprintf(g_dasm_str, "movep.w ($%x,A%d), D%d", read_imm_16(), g_cpu_ir&7, (g_cpu_ir>>9)&7);
2012 }
2013 
d68000_movep_er_32(void)2014 static void d68000_movep_er_32(void)
2015 {
2016    sprintf(g_dasm_str, "movep.l ($%x,A%d), D%d", read_imm_16(), g_cpu_ir&7, (g_cpu_ir>>9)&7);
2017 }
2018 
d68010_moves_8(void)2019 static void d68010_moves_8(void)
2020 {
2021    uint extension = read_imm_16();
2022    if(BIT_B(extension))
2023       sprintf(g_dasm_str, "moves.b %c%d, %s; (1+)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, get_ea_mode_str_8(g_cpu_ir));
2024    else
2025       sprintf(g_dasm_str, "moves.b %s, %c%d; (1+)", get_ea_mode_str_8(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
2026 }
2027 
d68010_moves_16(void)2028 static void d68010_moves_16(void)
2029 {
2030    uint extension = read_imm_16();
2031    if(BIT_B(extension))
2032       sprintf(g_dasm_str, "moves.b %c%d, %s; (1+)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, get_ea_mode_str_16(g_cpu_ir));
2033    else
2034       sprintf(g_dasm_str, "moves.b %s, %c%d; (1+)", get_ea_mode_str_16(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
2035 }
2036 
d68010_moves_32(void)2037 static void d68010_moves_32(void)
2038 {
2039    uint extension = read_imm_16();
2040    if(BIT_B(extension))
2041       sprintf(g_dasm_str, "moves.b %c%d, %s; (1+)", BIT_F(extension) ? 'A' : 'D', (extension>>12)&7, get_ea_mode_str_32(g_cpu_ir));
2042    else
2043       sprintf(g_dasm_str, "moves.b %s, %c%d; (1+)", get_ea_mode_str_32(g_cpu_ir), BIT_F(extension) ? 'A' : 'D', (extension>>12)&7);
2044 }
2045 
d68000_moveq(void)2046 static void d68000_moveq(void)
2047 {
2048    sprintf(g_dasm_str, "moveq   #%s, D%d", make_signed_hex_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
2049 }
2050 
d68040_move16_pi_pi(void)2051 static void d68040_move16_pi_pi(void)
2052 {
2053    sprintf(g_dasm_str, "move16  (A%d)+, (A%d)+; (4)", g_cpu_ir&7, (read_imm_16()>>12)&7);
2054 }
2055 
d68040_move16_pi_al(void)2056 static void d68040_move16_pi_al(void)
2057 {
2058    sprintf(g_dasm_str, "move16  (A%d)+, %s; (4)", g_cpu_ir&7, get_imm_str_u32());
2059 }
2060 
d68040_move16_al_pi(void)2061 static void d68040_move16_al_pi(void)
2062 {
2063    sprintf(g_dasm_str, "move16  %s, (A%d)+; (4)", get_imm_str_u32(), g_cpu_ir&7);
2064 }
2065 
d68040_move16_ai_al(void)2066 static void d68040_move16_ai_al(void)
2067 {
2068    sprintf(g_dasm_str, "move16  (A%d), %s; (4)", g_cpu_ir&7, get_imm_str_u32());
2069 }
2070 
d68040_move16_al_ai(void)2071 static void d68040_move16_al_ai(void)
2072 {
2073    sprintf(g_dasm_str, "move16  %s, (A%d); (4)", get_imm_str_u32(), g_cpu_ir&7);
2074 }
2075 
d68000_muls(void)2076 static void d68000_muls(void)
2077 {
2078    sprintf(g_dasm_str, "muls.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
2079 }
2080 
d68000_mulu(void)2081 static void d68000_mulu(void)
2082 {
2083    sprintf(g_dasm_str, "mulu.w  %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
2084 }
2085 
d68020_mull(void)2086 static void d68020_mull(void)
2087 {
2088    uint extension = read_imm_16();
2089 
2090    if(BIT_A(extension))
2091       sprintf(g_dasm_str, "mul%c.l  %s, D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), (extension>>12)&7);
2092    else
2093       sprintf(g_dasm_str, "mul%c.l %s, D%d-D%d; (2+)", BIT_B(extension) ? 's' : 'u', get_ea_mode_str_32(g_cpu_ir), extension&7, (extension>>12)&7);
2094 }
2095 
d68000_nbcd(void)2096 static void d68000_nbcd(void)
2097 {
2098    sprintf(g_dasm_str, "nbcd    %s", get_ea_mode_str_8(g_cpu_ir));
2099 }
2100 
d68000_neg_8(void)2101 static void d68000_neg_8(void)
2102 {
2103    sprintf(g_dasm_str, "neg.b   %s", get_ea_mode_str_8(g_cpu_ir));
2104 }
2105 
d68000_neg_16(void)2106 static void d68000_neg_16(void)
2107 {
2108    sprintf(g_dasm_str, "neg.w   %s", get_ea_mode_str_16(g_cpu_ir));
2109 }
2110 
d68000_neg_32(void)2111 static void d68000_neg_32(void)
2112 {
2113    sprintf(g_dasm_str, "neg.l   %s", get_ea_mode_str_32(g_cpu_ir));
2114 }
2115 
d68000_negx_8(void)2116 static void d68000_negx_8(void)
2117 {
2118    sprintf(g_dasm_str, "negx.b  %s", get_ea_mode_str_8(g_cpu_ir));
2119 }
2120 
d68000_negx_16(void)2121 static void d68000_negx_16(void)
2122 {
2123    sprintf(g_dasm_str, "negx.w  %s", get_ea_mode_str_16(g_cpu_ir));
2124 }
2125 
d68000_negx_32(void)2126 static void d68000_negx_32(void)
2127 {
2128    sprintf(g_dasm_str, "negx.l  %s", get_ea_mode_str_32(g_cpu_ir));
2129 }
2130 
d68000_nop(void)2131 static void d68000_nop(void)
2132 {
2133    sprintf(g_dasm_str, "nop");
2134 }
2135 
d68000_not_8(void)2136 static void d68000_not_8(void)
2137 {
2138    sprintf(g_dasm_str, "not.b   %s", get_ea_mode_str_8(g_cpu_ir));
2139 }
2140 
d68000_not_16(void)2141 static void d68000_not_16(void)
2142 {
2143    sprintf(g_dasm_str, "not.w   %s", get_ea_mode_str_16(g_cpu_ir));
2144 }
2145 
d68000_not_32(void)2146 static void d68000_not_32(void)
2147 {
2148    sprintf(g_dasm_str, "not.l   %s", get_ea_mode_str_32(g_cpu_ir));
2149 }
2150 
d68000_or_er_8(void)2151 static void d68000_or_er_8(void)
2152 {
2153    sprintf(g_dasm_str, "or.b    %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
2154 }
2155 
d68000_or_er_16(void)2156 static void d68000_or_er_16(void)
2157 {
2158    sprintf(g_dasm_str, "or.w    %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
2159 }
2160 
d68000_or_er_32(void)2161 static void d68000_or_er_32(void)
2162 {
2163    sprintf(g_dasm_str, "or.l    %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
2164 }
2165 
d68000_or_re_8(void)2166 static void d68000_or_re_8(void)
2167 {
2168    sprintf(g_dasm_str, "or.b    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
2169 }
2170 
d68000_or_re_16(void)2171 static void d68000_or_re_16(void)
2172 {
2173    sprintf(g_dasm_str, "or.w    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
2174 }
2175 
d68000_or_re_32(void)2176 static void d68000_or_re_32(void)
2177 {
2178    sprintf(g_dasm_str, "or.l    D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
2179 }
2180 
d68000_ori_8(void)2181 static void d68000_ori_8(void)
2182 {
2183    char* str = get_imm_str_u8();
2184    sprintf(g_dasm_str, "ori.b   %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
2185 }
2186 
d68000_ori_16(void)2187 static void d68000_ori_16(void)
2188 {
2189    char* str = get_imm_str_u16();
2190    sprintf(g_dasm_str, "ori.w   %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
2191 }
2192 
d68000_ori_32(void)2193 static void d68000_ori_32(void)
2194 {
2195    char* str = get_imm_str_u32();
2196    sprintf(g_dasm_str, "ori.l   %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
2197 }
2198 
d68000_ori_to_ccr(void)2199 static void d68000_ori_to_ccr(void)
2200 {
2201    sprintf(g_dasm_str, "ori     %s, CCR", get_imm_str_u8());
2202 }
2203 
d68000_ori_to_sr(void)2204 static void d68000_ori_to_sr(void)
2205 {
2206    sprintf(g_dasm_str, "ori     %s, SR", get_imm_str_u16());
2207 }
2208 
d68020_pack_rr(void)2209 static void d68020_pack_rr(void)
2210 {
2211    sprintf(g_dasm_str, "pack    D%d, D%d, %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
2212 }
2213 
d68020_pack_mm(void)2214 static void d68020_pack_mm(void)
2215 {
2216    sprintf(g_dasm_str, "pack    -(A%d), -(A%d), %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
2217 }
2218 
d68000_pea(void)2219 static void d68000_pea(void)
2220 {
2221    sprintf(g_dasm_str, "pea     %s", get_ea_mode_str_32(g_cpu_ir));
2222 }
2223 
d68000_reset(void)2224 static void d68000_reset(void)
2225 {
2226    sprintf(g_dasm_str, "reset");
2227 }
2228 
d68000_ror_s_8(void)2229 static void d68000_ror_s_8(void)
2230 {
2231    sprintf(g_dasm_str, "ror.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2232 }
2233 
d68000_ror_s_16(void)2234 static void d68000_ror_s_16(void)
2235 {
2236    sprintf(g_dasm_str, "ror.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7],g_cpu_ir&7);
2237 }
2238 
d68000_ror_s_32(void)2239 static void d68000_ror_s_32(void)
2240 {
2241    sprintf(g_dasm_str, "ror.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2242 }
2243 
d68000_ror_r_8(void)2244 static void d68000_ror_r_8(void)
2245 {
2246    sprintf(g_dasm_str, "ror.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2247 }
2248 
d68000_ror_r_16(void)2249 static void d68000_ror_r_16(void)
2250 {
2251    sprintf(g_dasm_str, "ror.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2252 }
2253 
d68000_ror_r_32(void)2254 static void d68000_ror_r_32(void)
2255 {
2256    sprintf(g_dasm_str, "ror.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2257 }
2258 
d68000_ror_ea(void)2259 static void d68000_ror_ea(void)
2260 {
2261    sprintf(g_dasm_str, "ror.w   %s", get_ea_mode_str_32(g_cpu_ir));
2262 }
2263 
d68000_rol_s_8(void)2264 static void d68000_rol_s_8(void)
2265 {
2266    sprintf(g_dasm_str, "rol.b   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2267 }
2268 
d68000_rol_s_16(void)2269 static void d68000_rol_s_16(void)
2270 {
2271    sprintf(g_dasm_str, "rol.w   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2272 }
2273 
d68000_rol_s_32(void)2274 static void d68000_rol_s_32(void)
2275 {
2276    sprintf(g_dasm_str, "rol.l   #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2277 }
2278 
d68000_rol_r_8(void)2279 static void d68000_rol_r_8(void)
2280 {
2281    sprintf(g_dasm_str, "rol.b   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2282 }
2283 
d68000_rol_r_16(void)2284 static void d68000_rol_r_16(void)
2285 {
2286    sprintf(g_dasm_str, "rol.w   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2287 }
2288 
d68000_rol_r_32(void)2289 static void d68000_rol_r_32(void)
2290 {
2291    sprintf(g_dasm_str, "rol.l   D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2292 }
2293 
d68000_rol_ea(void)2294 static void d68000_rol_ea(void)
2295 {
2296    sprintf(g_dasm_str, "rol.w   %s", get_ea_mode_str_32(g_cpu_ir));
2297 }
2298 
d68000_roxr_s_8(void)2299 static void d68000_roxr_s_8(void)
2300 {
2301    sprintf(g_dasm_str, "roxr.b  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2302 }
2303 
d68000_roxr_s_16(void)2304 static void d68000_roxr_s_16(void)
2305 {
2306    sprintf(g_dasm_str, "roxr.w  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2307 }
2308 
2309 
d68000_roxr_s_32(void)2310 static void d68000_roxr_s_32(void)
2311 {
2312    sprintf(g_dasm_str, "roxr.l  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2313 }
2314 
d68000_roxr_r_8(void)2315 static void d68000_roxr_r_8(void)
2316 {
2317    sprintf(g_dasm_str, "roxr.b  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2318 }
2319 
d68000_roxr_r_16(void)2320 static void d68000_roxr_r_16(void)
2321 {
2322    sprintf(g_dasm_str, "roxr.w  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2323 }
2324 
d68000_roxr_r_32(void)2325 static void d68000_roxr_r_32(void)
2326 {
2327    sprintf(g_dasm_str, "roxr.l  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2328 }
2329 
d68000_roxr_ea(void)2330 static void d68000_roxr_ea(void)
2331 {
2332    sprintf(g_dasm_str, "roxr.w  %s", get_ea_mode_str_32(g_cpu_ir));
2333 }
2334 
d68000_roxl_s_8(void)2335 static void d68000_roxl_s_8(void)
2336 {
2337    sprintf(g_dasm_str, "roxl.b  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2338 }
2339 
d68000_roxl_s_16(void)2340 static void d68000_roxl_s_16(void)
2341 {
2342    sprintf(g_dasm_str, "roxl.w  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2343 }
2344 
d68000_roxl_s_32(void)2345 static void d68000_roxl_s_32(void)
2346 {
2347    sprintf(g_dasm_str, "roxl.l  #%d, D%d", g_3bit_qdata_table[(g_cpu_ir>>9)&7], g_cpu_ir&7);
2348 }
2349 
d68000_roxl_r_8(void)2350 static void d68000_roxl_r_8(void)
2351 {
2352    sprintf(g_dasm_str, "roxl.b  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2353 }
2354 
d68000_roxl_r_16(void)2355 static void d68000_roxl_r_16(void)
2356 {
2357    sprintf(g_dasm_str, "roxl.w  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2358 }
2359 
d68000_roxl_r_32(void)2360 static void d68000_roxl_r_32(void)
2361 {
2362    sprintf(g_dasm_str, "roxl.l  D%d, D%d", (g_cpu_ir>>9)&7, g_cpu_ir&7);
2363 }
2364 
d68000_roxl_ea(void)2365 static void d68000_roxl_ea(void)
2366 {
2367    sprintf(g_dasm_str, "roxl.w  %s", get_ea_mode_str_32(g_cpu_ir));
2368 }
2369 
d68010_rtd(void)2370 static void d68010_rtd(void)
2371 {
2372    sprintf(g_dasm_str, "rtd     %s; (1+)", get_imm_str_s16());
2373 }
2374 
d68000_rte(void)2375 static void d68000_rte(void)
2376 {
2377    sprintf(g_dasm_str, "rte");
2378 }
2379 
d68020_rtm(void)2380 static void d68020_rtm(void)
2381 {
2382    sprintf(g_dasm_str, "rtm     %c%d; (2+)", BIT_3(g_cpu_ir) ? 'A' : 'D', g_cpu_ir&7);
2383 }
2384 
d68000_rtr(void)2385 static void d68000_rtr(void)
2386 {
2387    sprintf(g_dasm_str, "rtr");
2388 }
2389 
d68000_rts(void)2390 static void d68000_rts(void)
2391 {
2392    sprintf(g_dasm_str, "rts");
2393 }
2394 
d68000_sbcd_rr(void)2395 static void d68000_sbcd_rr(void)
2396 {
2397    sprintf(g_dasm_str, "sbcd    D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2398 }
2399 
d68000_sbcd_mm(void)2400 static void d68000_sbcd_mm(void)
2401 {
2402    sprintf(g_dasm_str, "sbcd    -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2403 }
2404 
d68000_scc(void)2405 static void d68000_scc(void)
2406 {
2407    sprintf(g_dasm_str, "s%-2s     %s", g_cc[(g_cpu_ir>>8)&0xf], get_ea_mode_str_8(g_cpu_ir));
2408 }
2409 
d68000_stop(void)2410 static void d68000_stop(void)
2411 {
2412    sprintf(g_dasm_str, "stop    %s", get_imm_str_s16());
2413 }
2414 
d68000_sub_er_8(void)2415 static void d68000_sub_er_8(void)
2416 {
2417    sprintf(g_dasm_str, "sub.b   %s, D%d", get_ea_mode_str_8(g_cpu_ir), (g_cpu_ir>>9)&7);
2418 }
2419 
d68000_sub_er_16(void)2420 static void d68000_sub_er_16(void)
2421 {
2422    sprintf(g_dasm_str, "sub.w   %s, D%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
2423 }
2424 
d68000_sub_er_32(void)2425 static void d68000_sub_er_32(void)
2426 {
2427    sprintf(g_dasm_str, "sub.l   %s, D%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
2428 }
2429 
d68000_sub_re_8(void)2430 static void d68000_sub_re_8(void)
2431 {
2432    sprintf(g_dasm_str, "sub.b   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_8(g_cpu_ir));
2433 }
2434 
d68000_sub_re_16(void)2435 static void d68000_sub_re_16(void)
2436 {
2437    sprintf(g_dasm_str, "sub.w   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_16(g_cpu_ir));
2438 }
2439 
d68000_sub_re_32(void)2440 static void d68000_sub_re_32(void)
2441 {
2442    sprintf(g_dasm_str, "sub.l   D%d, %s", (g_cpu_ir>>9)&7, get_ea_mode_str_32(g_cpu_ir));
2443 }
2444 
d68000_suba_16(void)2445 static void d68000_suba_16(void)
2446 {
2447    sprintf(g_dasm_str, "suba.w  %s, A%d", get_ea_mode_str_16(g_cpu_ir), (g_cpu_ir>>9)&7);
2448 }
2449 
d68000_suba_32(void)2450 static void d68000_suba_32(void)
2451 {
2452    sprintf(g_dasm_str, "suba.l  %s, A%d", get_ea_mode_str_32(g_cpu_ir), (g_cpu_ir>>9)&7);
2453 }
2454 
d68000_subi_8(void)2455 static void d68000_subi_8(void)
2456 {
2457    char* str = get_imm_str_s8();
2458    sprintf(g_dasm_str, "subi.b  %s, %s", str, get_ea_mode_str_8(g_cpu_ir));
2459 }
2460 
d68000_subi_16(void)2461 static void d68000_subi_16(void)
2462 {
2463    char* str = get_imm_str_s16();
2464    sprintf(g_dasm_str, "subi.w  %s, %s", str, get_ea_mode_str_16(g_cpu_ir));
2465 }
2466 
d68000_subi_32(void)2467 static void d68000_subi_32(void)
2468 {
2469    char* str = get_imm_str_s32();
2470    sprintf(g_dasm_str, "subi.l  %s, %s", str, get_ea_mode_str_32(g_cpu_ir));
2471 }
2472 
d68000_subq_8(void)2473 static void d68000_subq_8(void)
2474 {
2475    sprintf(g_dasm_str, "subq.b  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_8(g_cpu_ir));
2476 }
2477 
d68000_subq_16(void)2478 static void d68000_subq_16(void)
2479 {
2480    sprintf(g_dasm_str, "subq.w  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_16(g_cpu_ir));
2481 }
2482 
d68000_subq_32(void)2483 static void d68000_subq_32(void)
2484 {
2485    sprintf(g_dasm_str, "subq.l  #%d, %s", g_3bit_qdata_table[(g_cpu_ir>>9)&7], get_ea_mode_str_32(g_cpu_ir));
2486 }
2487 
d68000_subx_rr_8(void)2488 static void d68000_subx_rr_8(void)
2489 {
2490    sprintf(g_dasm_str, "subx.b  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2491 }
2492 
d68000_subx_rr_16(void)2493 static void d68000_subx_rr_16(void)
2494 {
2495    sprintf(g_dasm_str, "subx.w  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2496 }
2497 
d68000_subx_rr_32(void)2498 static void d68000_subx_rr_32(void)
2499 {
2500    sprintf(g_dasm_str, "subx.l  D%d, D%d", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2501 }
2502 
d68000_subx_mm_8(void)2503 static void d68000_subx_mm_8(void)
2504 {
2505    sprintf(g_dasm_str, "subx.b  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2506 }
2507 
d68000_subx_mm_16(void)2508 static void d68000_subx_mm_16(void)
2509 {
2510    sprintf(g_dasm_str, "subx.w  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2511 }
2512 
d68000_subx_mm_32(void)2513 static void d68000_subx_mm_32(void)
2514 {
2515    sprintf(g_dasm_str, "subx.l  -(A%d), -(A%d)", g_cpu_ir&7, (g_cpu_ir>>9)&7);
2516 }
2517 
d68000_swap(void)2518 static void d68000_swap(void)
2519 {
2520    sprintf(g_dasm_str, "swap    D%d", g_cpu_ir&7);
2521 }
2522 
d68000_tas(void)2523 static void d68000_tas(void)
2524 {
2525    sprintf(g_dasm_str, "tas     %s", get_ea_mode_str_8(g_cpu_ir));
2526 }
2527 
d68000_trap(void)2528 static void d68000_trap(void)
2529 {
2530    sprintf(g_dasm_str, "trap    #$%x", g_cpu_ir&0xf);
2531 }
2532 
d68020_trapcc_0(void)2533 static void d68020_trapcc_0(void)
2534 {
2535    sprintf(g_dasm_str, "trap%-2s; (2+)", g_cc[(g_cpu_ir>>8)&0xf]);
2536 }
2537 
d68020_trapcc_16(void)2538 static void d68020_trapcc_16(void)
2539 {
2540    sprintf(g_dasm_str, "trap%-2s  %s; (2+)", g_cc[(g_cpu_ir>>8)&0xf], get_imm_str_u16());
2541 }
2542 
d68020_trapcc_32(void)2543 static void d68020_trapcc_32(void)
2544 {
2545    sprintf(g_dasm_str, "trap%-2s  %s; (2+)", g_cc[(g_cpu_ir>>8)&0xf], get_imm_str_u32());
2546 }
2547 
d68000_trapv(void)2548 static void d68000_trapv(void)
2549 {
2550    sprintf(g_dasm_str, "trapv");
2551 }
2552 
d68000_tst_8(void)2553 static void d68000_tst_8(void)
2554 {
2555    sprintf(g_dasm_str, "tst.b   %s", get_ea_mode_str_8(g_cpu_ir));
2556 }
2557 
d68020_tst_pcdi_8(void)2558 static void d68020_tst_pcdi_8(void)
2559 {
2560    sprintf(g_dasm_str, "tst.b   %s; (2+)", get_ea_mode_str_8(g_cpu_ir));
2561 }
2562 
d68020_tst_pcix_8(void)2563 static void d68020_tst_pcix_8(void)
2564 {
2565    sprintf(g_dasm_str, "tst.b   %s; (2+)", get_ea_mode_str_8(g_cpu_ir));
2566 }
2567 
d68020_tst_i_8(void)2568 static void d68020_tst_i_8(void)
2569 {
2570    sprintf(g_dasm_str, "tst.b   %s; (2+)", get_ea_mode_str_8(g_cpu_ir));
2571 }
2572 
d68000_tst_16(void)2573 static void d68000_tst_16(void)
2574 {
2575    sprintf(g_dasm_str, "tst.w   %s", get_ea_mode_str_16(g_cpu_ir));
2576 }
2577 
d68020_tst_a_16(void)2578 static void d68020_tst_a_16(void)
2579 {
2580    sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
2581 }
2582 
d68020_tst_pcdi_16(void)2583 static void d68020_tst_pcdi_16(void)
2584 {
2585    sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
2586 }
2587 
d68020_tst_pcix_16(void)2588 static void d68020_tst_pcix_16(void)
2589 {
2590    sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
2591 }
2592 
d68020_tst_i_16(void)2593 static void d68020_tst_i_16(void)
2594 {
2595    sprintf(g_dasm_str, "tst.w   %s; (2+)", get_ea_mode_str_16(g_cpu_ir));
2596 }
2597 
d68000_tst_32(void)2598 static void d68000_tst_32(void)
2599 {
2600    sprintf(g_dasm_str, "tst.l   %s", get_ea_mode_str_32(g_cpu_ir));
2601 }
2602 
d68020_tst_a_32(void)2603 static void d68020_tst_a_32(void)
2604 {
2605    sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
2606 }
2607 
d68020_tst_pcdi_32(void)2608 static void d68020_tst_pcdi_32(void)
2609 {
2610    sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
2611 }
2612 
d68020_tst_pcix_32(void)2613 static void d68020_tst_pcix_32(void)
2614 {
2615    sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
2616 }
2617 
d68020_tst_i_32(void)2618 static void d68020_tst_i_32(void)
2619 {
2620    sprintf(g_dasm_str, "tst.l   %s; (2+)", get_ea_mode_str_32(g_cpu_ir));
2621 }
2622 
d68000_unlk(void)2623 static void d68000_unlk(void)
2624 {
2625    sprintf(g_dasm_str, "unlk    A%d", g_cpu_ir&7);
2626 }
2627 
d68020_unpk_rr(void)2628 static void d68020_unpk_rr(void)
2629 {
2630    sprintf(g_dasm_str, "unpk    D%d, D%d, %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
2631 }
2632 
d68020_unpk_mm(void)2633 static void d68020_unpk_mm(void)
2634 {
2635    sprintf(g_dasm_str, "unpk    -(A%d), -(A%d), %s; (2+)", g_cpu_ir&7, (g_cpu_ir>>9)&7, get_imm_str_u16());
2636 }
2637 
2638 
d68000_illegal(void)2639 static void d68000_illegal(void)
2640 {
2641    sprintf(g_dasm_str, "dc.w $%04x; ILLEGAL", g_cpu_ir);
2642 }
2643 
2644 
2645 
2646 /* ======================================================================== */
2647 /* ======================= INSTRUCTION TABLE BUILDER ====================== */
2648 /* ======================================================================== */
2649 
2650 /* EA Masks:
2651 800 = data register direct
2652 400 = address register direct
2653 200 = address register indirect
2654 100 = ARI postincrement
2655  80 = ARI pre-decrement
2656  40 = ARI displacement
2657  20 = ARI index
2658  10 = absolute short
2659   8 = absolute long
2660   4 = immediate / sr
2661   2 = pc displacement
2662   1 = pc idx
2663 */
2664 
2665 static opcode_struct g_opcode_info[] =
2666 {
2667 /*  opcode handler    mask    match   ea mask */
2668    {d68000_1010         , 0xf000, 0xa000, 0x000},
2669    {d68000_1111         , 0xf000, 0xf000, 0x000},
2670    {d68000_abcd_rr      , 0xf1f8, 0xc100, 0x000},
2671    {d68000_abcd_mm      , 0xf1f8, 0xc108, 0x000},
2672    {d68000_add_er_8     , 0xf1c0, 0xd000, 0xbff},
2673    {d68000_add_er_16    , 0xf1c0, 0xd040, 0xfff},
2674    {d68000_add_er_32    , 0xf1c0, 0xd080, 0xfff},
2675    {d68000_add_re_8     , 0xf1c0, 0xd100, 0x3f8},
2676    {d68000_add_re_16    , 0xf1c0, 0xd140, 0x3f8},
2677    {d68000_add_re_32    , 0xf1c0, 0xd180, 0x3f8},
2678    {d68000_adda_16      , 0xf1c0, 0xd0c0, 0xfff},
2679    {d68000_adda_32      , 0xf1c0, 0xd1c0, 0xfff},
2680    {d68000_addi_8       , 0xffc0, 0x0600, 0xbf8},
2681    {d68000_addi_16      , 0xffc0, 0x0640, 0xbf8},
2682    {d68000_addi_32      , 0xffc0, 0x0680, 0xbf8},
2683    {d68000_addq_8       , 0xf1c0, 0x5000, 0xbf8},
2684    {d68000_addq_16      , 0xf1c0, 0x5040, 0xff8},
2685    {d68000_addq_32      , 0xf1c0, 0x5080, 0xff8},
2686    {d68000_addx_rr_8    , 0xf1f8, 0xd100, 0x000},
2687    {d68000_addx_rr_16   , 0xf1f8, 0xd140, 0x000},
2688    {d68000_addx_rr_32   , 0xf1f8, 0xd180, 0x000},
2689    {d68000_addx_mm_8    , 0xf1f8, 0xd108, 0x000},
2690    {d68000_addx_mm_16   , 0xf1f8, 0xd148, 0x000},
2691    {d68000_addx_mm_32   , 0xf1f8, 0xd188, 0x000},
2692    {d68000_and_er_8     , 0xf1c0, 0xc000, 0xbff},
2693    {d68000_and_er_16    , 0xf1c0, 0xc040, 0xbff},
2694    {d68000_and_er_32    , 0xf1c0, 0xc080, 0xbff},
2695    {d68000_and_re_8     , 0xf1c0, 0xc100, 0x3f8},
2696    {d68000_and_re_16    , 0xf1c0, 0xc140, 0x3f8},
2697    {d68000_and_re_32    , 0xf1c0, 0xc180, 0x3f8},
2698    {d68000_andi_to_ccr  , 0xffff, 0x023c, 0x000},
2699    {d68000_andi_to_sr   , 0xffff, 0x027c, 0x000},
2700    {d68000_andi_8       , 0xffc0, 0x0200, 0xbf8},
2701    {d68000_andi_16      , 0xffc0, 0x0240, 0xbf8},
2702    {d68000_andi_32      , 0xffc0, 0x0280, 0xbf8},
2703    {d68000_asr_s_8      , 0xf1f8, 0xe000, 0x000},
2704    {d68000_asr_s_16     , 0xf1f8, 0xe040, 0x000},
2705    {d68000_asr_s_32     , 0xf1f8, 0xe080, 0x000},
2706    {d68000_asr_r_8      , 0xf1f8, 0xe020, 0x000},
2707    {d68000_asr_r_16     , 0xf1f8, 0xe060, 0x000},
2708    {d68000_asr_r_32     , 0xf1f8, 0xe0a0, 0x000},
2709    {d68000_asr_ea       , 0xffc0, 0xe0c0, 0x3f8},
2710    {d68000_asl_s_8      , 0xf1f8, 0xe100, 0x000},
2711    {d68000_asl_s_16     , 0xf1f8, 0xe140, 0x000},
2712    {d68000_asl_s_32     , 0xf1f8, 0xe180, 0x000},
2713    {d68000_asl_r_8      , 0xf1f8, 0xe120, 0x000},
2714    {d68000_asl_r_16     , 0xf1f8, 0xe160, 0x000},
2715    {d68000_asl_r_32     , 0xf1f8, 0xe1a0, 0x000},
2716    {d68000_asl_ea       , 0xffc0, 0xe1c0, 0x3f8},
2717    {d68000_bcc_8        , 0xf000, 0x6000, 0x000},
2718    {d68000_bcc_16       , 0xf0ff, 0x6000, 0x000},
2719    {d68020_bcc_32       , 0xf0ff, 0x60ff, 0x000},
2720    {d68000_bchg_r       , 0xf1c0, 0x0140, 0xbf8},
2721    {d68000_bchg_s       , 0xffc0, 0x0840, 0xbf8},
2722    {d68000_bclr_r       , 0xf1c0, 0x0180, 0xbf8},
2723    {d68000_bclr_s       , 0xffc0, 0x0880, 0xbf8},
2724    {d68020_bfchg        , 0xffc0, 0xeac0, 0xa78},
2725    {d68020_bfclr        , 0xffc0, 0xecc0, 0xa78},
2726    {d68020_bfexts       , 0xffc0, 0xebc0, 0xa7b},
2727    {d68020_bfextu       , 0xffc0, 0xe9c0, 0xa7b},
2728    {d68020_bfffo        , 0xffc0, 0xedc0, 0xa7b},
2729    {d68020_bfins        , 0xffc0, 0xefc0, 0xa78},
2730    {d68020_bfset        , 0xffc0, 0xeec0, 0xa78},
2731    {d68020_bftst        , 0xffc0, 0xe8c0, 0xa7b},
2732    {d68010_bkpt         , 0xfff8, 0x4848, 0x000},
2733    {d68000_bra_8        , 0xff00, 0x6000, 0x000},
2734    {d68000_bra_16       , 0xffff, 0x6000, 0x000},
2735    {d68020_bra_32       , 0xffff, 0x60ff, 0x000},
2736    {d68000_bset_r       , 0xf1c0, 0x01c0, 0xbf8},
2737    {d68000_bset_s       , 0xffc0, 0x08c0, 0xbf8},
2738    {d68000_bsr_8        , 0xff00, 0x6100, 0x000},
2739    {d68000_bsr_16       , 0xffff, 0x6100, 0x000},
2740    {d68020_bsr_32       , 0xffff, 0x61ff, 0x000},
2741    {d68000_btst_r       , 0xf1c0, 0x0100, 0xbff},
2742    {d68000_btst_s       , 0xffc0, 0x0800, 0xbfb},
2743    {d68020_callm        , 0xffc0, 0x06c0, 0x27b},
2744    {d68020_cas_8        , 0xffc0, 0x0ac0, 0x3f8},
2745    {d68020_cas_16       , 0xffc0, 0x0cc0, 0x3f8},
2746    {d68020_cas_32       , 0xffc0, 0x0ec0, 0x3f8},
2747    {d68020_cas2_16      , 0xffff, 0x0cfc, 0x000},
2748    {d68020_cas2_32      , 0xffff, 0x0efc, 0x000},
2749    {d68000_chk_16       , 0xf1c0, 0x4180, 0xbff},
2750    {d68020_chk_32       , 0xf1c0, 0x4100, 0xbff},
2751    {d68020_chk2_cmp2_8  , 0xffc0, 0x00c0, 0x27b},
2752    {d68020_chk2_cmp2_16 , 0xffc0, 0x02c0, 0x27b},
2753    {d68020_chk2_cmp2_32 , 0xffc0, 0x04c0, 0x27b},
2754    {d68040_cinv         , 0xff20, 0xf400, 0x000},
2755    {d68000_clr_8        , 0xffc0, 0x4200, 0xbf8},
2756    {d68000_clr_16       , 0xffc0, 0x4240, 0xbf8},
2757    {d68000_clr_32       , 0xffc0, 0x4280, 0xbf8},
2758    {d68000_cmp_8        , 0xf1c0, 0xb000, 0xbff},
2759    {d68000_cmp_16       , 0xf1c0, 0xb040, 0xfff},
2760    {d68000_cmp_32       , 0xf1c0, 0xb080, 0xfff},
2761    {d68000_cmpa_16      , 0xf1c0, 0xb0c0, 0xfff},
2762    {d68000_cmpa_32      , 0xf1c0, 0xb1c0, 0xfff},
2763    {d68000_cmpi_8       , 0xffc0, 0x0c00, 0xbf8},
2764    {d68020_cmpi_pcdi_8  , 0xffff, 0x0c3a, 0x000},
2765    {d68020_cmpi_pcix_8  , 0xffff, 0x0c3b, 0x000},
2766    {d68000_cmpi_16      , 0xffc0, 0x0c40, 0xbf8},
2767    {d68020_cmpi_pcdi_16 , 0xffff, 0x0c7a, 0x000},
2768    {d68020_cmpi_pcix_16 , 0xffff, 0x0c7b, 0x000},
2769    {d68000_cmpi_32      , 0xffc0, 0x0c80, 0xbf8},
2770    {d68020_cmpi_pcdi_32 , 0xffff, 0x0cba, 0x000},
2771    {d68020_cmpi_pcix_32 , 0xffff, 0x0cbb, 0x000},
2772    {d68000_cmpm_8       , 0xf1f8, 0xb108, 0x000},
2773    {d68000_cmpm_16      , 0xf1f8, 0xb148, 0x000},
2774    {d68000_cmpm_32      , 0xf1f8, 0xb188, 0x000},
2775    {d68020_cpbcc_16     , 0xf1c0, 0xf080, 0x000},
2776    {d68020_cpbcc_32     , 0xf1c0, 0xf0c0, 0x000},
2777    {d68020_cpdbcc       , 0xf1f8, 0xf048, 0x000},
2778    {d68020_cpgen        , 0xf1c0, 0xf000, 0x000},
2779    {d68020_cprestore    , 0xf1c0, 0xf140, 0x37f},
2780    {d68020_cpsave       , 0xf1c0, 0xf100, 0x2f8},
2781    {d68020_cpscc        , 0xf1c0, 0xf040, 0xbf8},
2782    {d68020_cptrapcc_0   , 0xf1ff, 0xf07c, 0x000},
2783    {d68020_cptrapcc_16  , 0xf1ff, 0xf07a, 0x000},
2784    {d68020_cptrapcc_32  , 0xf1ff, 0xf07b, 0x000},
2785    {d68040_cpush        , 0xff20, 0xf420, 0x000},
2786    {d68000_dbcc         , 0xf0f8, 0x50c8, 0x000},
2787    {d68000_dbra         , 0xfff8, 0x51c8, 0x000},
2788    {d68000_divs         , 0xf1c0, 0x81c0, 0xbff},
2789    {d68000_divu         , 0xf1c0, 0x80c0, 0xbff},
2790    {d68020_divl         , 0xffc0, 0x4c40, 0xbff},
2791    {d68000_eor_8        , 0xf1c0, 0xb100, 0xbf8},
2792    {d68000_eor_16       , 0xf1c0, 0xb140, 0xbf8},
2793    {d68000_eor_32       , 0xf1c0, 0xb180, 0xbf8},
2794    {d68000_eori_to_ccr  , 0xffff, 0x0a3c, 0x000},
2795    {d68000_eori_to_sr   , 0xffff, 0x0a7c, 0x000},
2796    {d68000_eori_8       , 0xffc0, 0x0a00, 0xbf8},
2797    {d68000_eori_16      , 0xffc0, 0x0a40, 0xbf8},
2798    {d68000_eori_32      , 0xffc0, 0x0a80, 0xbf8},
2799    {d68000_exg_dd       , 0xf1f8, 0xc140, 0x000},
2800    {d68000_exg_aa       , 0xf1f8, 0xc148, 0x000},
2801    {d68000_exg_da       , 0xf1f8, 0xc188, 0x000},
2802    {d68020_extb_32      , 0xfff8, 0x49c0, 0x000},
2803    {d68000_ext_16       , 0xfff8, 0x4880, 0x000},
2804    {d68000_ext_32       , 0xfff8, 0x48c0, 0x000},
2805    {d68000_illegal      , 0xffff, 0x4afc, 0x000},
2806    {d68000_jmp          , 0xffc0, 0x4ec0, 0x27b},
2807    {d68000_jsr          , 0xffc0, 0x4e80, 0x27b},
2808    {d68000_lea          , 0xf1c0, 0x41c0, 0x27b},
2809    {d68000_link_16      , 0xfff8, 0x4e50, 0x000},
2810    {d68020_link_32      , 0xfff8, 0x4808, 0x000},
2811    {d68000_lsr_s_8      , 0xf1f8, 0xe008, 0x000},
2812    {d68000_lsr_s_16     , 0xf1f8, 0xe048, 0x000},
2813    {d68000_lsr_s_32     , 0xf1f8, 0xe088, 0x000},
2814    {d68000_lsr_r_8      , 0xf1f8, 0xe028, 0x000},
2815    {d68000_lsr_r_16     , 0xf1f8, 0xe068, 0x000},
2816    {d68000_lsr_r_32     , 0xf1f8, 0xe0a8, 0x000},
2817    {d68000_lsr_ea       , 0xffc0, 0xe2c0, 0x3f8},
2818    {d68000_lsl_s_8      , 0xf1f8, 0xe108, 0x000},
2819    {d68000_lsl_s_16     , 0xf1f8, 0xe148, 0x000},
2820    {d68000_lsl_s_32     , 0xf1f8, 0xe188, 0x000},
2821    {d68000_lsl_r_8      , 0xf1f8, 0xe128, 0x000},
2822    {d68000_lsl_r_16     , 0xf1f8, 0xe168, 0x000},
2823    {d68000_lsl_r_32     , 0xf1f8, 0xe1a8, 0x000},
2824    {d68000_lsl_ea       , 0xffc0, 0xe3c0, 0x3f8},
2825    {d68000_move_8       , 0xf000, 0x1000, 0xbff},
2826    {d68000_move_16      , 0xf000, 0x3000, 0xfff},
2827    {d68000_move_32      , 0xf000, 0x2000, 0xfff},
2828    {d68000_movea_16     , 0xf1c0, 0x3040, 0xfff},
2829    {d68000_movea_32     , 0xf1c0, 0x2040, 0xfff},
2830    {d68000_move_to_ccr  , 0xffc0, 0x44c0, 0xbff},
2831    {d68010_move_fr_ccr  , 0xffc0, 0x42c0, 0xbf8},
2832    {d68000_move_to_sr   , 0xffc0, 0x46c0, 0xbff},
2833    {d68000_move_fr_sr   , 0xffc0, 0x40c0, 0xbf8},
2834    {d68000_move_to_usp  , 0xfff8, 0x4e60, 0x000},
2835    {d68000_move_fr_usp  , 0xfff8, 0x4e68, 0x000},
2836    {d68010_movec        , 0xfffe, 0x4e7a, 0x000},
2837    {d68000_movem_pd_16  , 0xfff8, 0x48a0, 0x000},
2838    {d68000_movem_pd_32  , 0xfff8, 0x48e0, 0x000},
2839    {d68000_movem_re_16  , 0xffc0, 0x4880, 0x2f8},
2840    {d68000_movem_re_32  , 0xffc0, 0x48c0, 0x2f8},
2841    {d68000_movem_er_16  , 0xffc0, 0x4c80, 0x37b},
2842    {d68000_movem_er_32  , 0xffc0, 0x4cc0, 0x37b},
2843    {d68000_movep_er_16  , 0xf1f8, 0x0108, 0x000},
2844    {d68000_movep_er_32  , 0xf1f8, 0x0148, 0x000},
2845    {d68000_movep_re_16  , 0xf1f8, 0x0188, 0x000},
2846    {d68000_movep_re_32  , 0xf1f8, 0x01c8, 0x000},
2847    {d68010_moves_8      , 0xffc0, 0x0e00, 0x3f8},
2848    {d68010_moves_16     , 0xffc0, 0x0e40, 0x3f8},
2849    {d68010_moves_32     , 0xffc0, 0x0e80, 0x3f8},
2850    {d68000_moveq        , 0xf100, 0x7000, 0x000},
2851    {d68040_move16_pi_pi , 0xfff8, 0xf620, 0x000},
2852    {d68040_move16_pi_al , 0xfff8, 0xf600, 0x000},
2853    {d68040_move16_al_pi , 0xfff8, 0xf608, 0x000},
2854    {d68040_move16_ai_al , 0xfff8, 0xf610, 0x000},
2855    {d68040_move16_al_ai , 0xfff8, 0xf618, 0x000},
2856    {d68000_muls         , 0xf1c0, 0xc1c0, 0xbff},
2857    {d68000_mulu         , 0xf1c0, 0xc0c0, 0xbff},
2858    {d68020_mull         , 0xffc0, 0x4c00, 0xbff},
2859    {d68000_nbcd         , 0xffc0, 0x4800, 0xbf8},
2860    {d68000_neg_8        , 0xffc0, 0x4400, 0xbf8},
2861    {d68000_neg_16       , 0xffc0, 0x4440, 0xbf8},
2862    {d68000_neg_32       , 0xffc0, 0x4480, 0xbf8},
2863    {d68000_negx_8       , 0xffc0, 0x4000, 0xbf8},
2864    {d68000_negx_16      , 0xffc0, 0x4040, 0xbf8},
2865    {d68000_negx_32      , 0xffc0, 0x4080, 0xbf8},
2866    {d68000_nop          , 0xffff, 0x4e71, 0x000},
2867    {d68000_not_8        , 0xffc0, 0x4600, 0xbf8},
2868    {d68000_not_16       , 0xffc0, 0x4640, 0xbf8},
2869    {d68000_not_32       , 0xffc0, 0x4680, 0xbf8},
2870    {d68000_or_er_8      , 0xf1c0, 0x8000, 0xbff},
2871    {d68000_or_er_16     , 0xf1c0, 0x8040, 0xbff},
2872    {d68000_or_er_32     , 0xf1c0, 0x8080, 0xbff},
2873    {d68000_or_re_8      , 0xf1c0, 0x8100, 0x3f8},
2874    {d68000_or_re_16     , 0xf1c0, 0x8140, 0x3f8},
2875    {d68000_or_re_32     , 0xf1c0, 0x8180, 0x3f8},
2876    {d68000_ori_to_ccr   , 0xffff, 0x003c, 0x000},
2877    {d68000_ori_to_sr    , 0xffff, 0x007c, 0x000},
2878    {d68000_ori_8        , 0xffc0, 0x0000, 0xbf8},
2879    {d68000_ori_16       , 0xffc0, 0x0040, 0xbf8},
2880    {d68000_ori_32       , 0xffc0, 0x0080, 0xbf8},
2881    {d68020_pack_rr      , 0xf1f8, 0x8140, 0x000},
2882    {d68020_pack_mm      , 0xf1f8, 0x8148, 0x000},
2883    {d68000_pea          , 0xffc0, 0x4840, 0x27b},
2884    {d68000_reset        , 0xffff, 0x4e70, 0x000},
2885    {d68000_ror_s_8      , 0xf1f8, 0xe018, 0x000},
2886    {d68000_ror_s_16     , 0xf1f8, 0xe058, 0x000},
2887    {d68000_ror_s_32     , 0xf1f8, 0xe098, 0x000},
2888    {d68000_ror_r_8      , 0xf1f8, 0xe038, 0x000},
2889    {d68000_ror_r_16     , 0xf1f8, 0xe078, 0x000},
2890    {d68000_ror_r_32     , 0xf1f8, 0xe0b8, 0x000},
2891    {d68000_ror_ea       , 0xffc0, 0xe6c0, 0x3f8},
2892    {d68000_rol_s_8      , 0xf1f8, 0xe118, 0x000},
2893    {d68000_rol_s_16     , 0xf1f8, 0xe158, 0x000},
2894    {d68000_rol_s_32     , 0xf1f8, 0xe198, 0x000},
2895    {d68000_rol_r_8      , 0xf1f8, 0xe138, 0x000},
2896    {d68000_rol_r_16     , 0xf1f8, 0xe178, 0x000},
2897    {d68000_rol_r_32     , 0xf1f8, 0xe1b8, 0x000},
2898    {d68000_rol_ea       , 0xffc0, 0xe7c0, 0x3f8},
2899    {d68000_roxr_s_8     , 0xf1f8, 0xe010, 0x000},
2900    {d68000_roxr_s_16    , 0xf1f8, 0xe050, 0x000},
2901    {d68000_roxr_s_32    , 0xf1f8, 0xe090, 0x000},
2902    {d68000_roxr_r_8     , 0xf1f8, 0xe030, 0x000},
2903    {d68000_roxr_r_16    , 0xf1f8, 0xe070, 0x000},
2904    {d68000_roxr_r_32    , 0xf1f8, 0xe0b0, 0x000},
2905    {d68000_roxr_ea      , 0xffc0, 0xe4c0, 0x3f8},
2906    {d68000_roxl_s_8     , 0xf1f8, 0xe110, 0x000},
2907    {d68000_roxl_s_16    , 0xf1f8, 0xe150, 0x000},
2908    {d68000_roxl_s_32    , 0xf1f8, 0xe190, 0x000},
2909    {d68000_roxl_r_8     , 0xf1f8, 0xe130, 0x000},
2910    {d68000_roxl_r_16    , 0xf1f8, 0xe170, 0x000},
2911    {d68000_roxl_r_32    , 0xf1f8, 0xe1b0, 0x000},
2912    {d68000_roxl_ea      , 0xffc0, 0xe5c0, 0x3f8},
2913    {d68010_rtd          , 0xffff, 0x4e74, 0x000},
2914    {d68000_rte          , 0xffff, 0x4e73, 0x000},
2915    {d68020_rtm          , 0xfff0, 0x06c0, 0x000},
2916    {d68000_rtr          , 0xffff, 0x4e77, 0x000},
2917    {d68000_rts          , 0xffff, 0x4e75, 0x000},
2918    {d68000_sbcd_rr      , 0xf1f8, 0x8100, 0x000},
2919    {d68000_sbcd_mm      , 0xf1f8, 0x8108, 0x000},
2920    {d68000_scc          , 0xf0c0, 0x50c0, 0xbf8},
2921    {d68000_stop         , 0xffff, 0x4e72, 0x000},
2922    {d68000_sub_er_8     , 0xf1c0, 0x9000, 0xbff},
2923    {d68000_sub_er_16    , 0xf1c0, 0x9040, 0xfff},
2924    {d68000_sub_er_32    , 0xf1c0, 0x9080, 0xfff},
2925    {d68000_sub_re_8     , 0xf1c0, 0x9100, 0x3f8},
2926    {d68000_sub_re_16    , 0xf1c0, 0x9140, 0x3f8},
2927    {d68000_sub_re_32    , 0xf1c0, 0x9180, 0x3f8},
2928    {d68000_suba_16      , 0xf1c0, 0x90c0, 0xfff},
2929    {d68000_suba_32      , 0xf1c0, 0x91c0, 0xfff},
2930    {d68000_subi_8       , 0xffc0, 0x0400, 0xbf8},
2931    {d68000_subi_16      , 0xffc0, 0x0440, 0xbf8},
2932    {d68000_subi_32      , 0xffc0, 0x0480, 0xbf8},
2933    {d68000_subq_8       , 0xf1c0, 0x5100, 0xbf8},
2934    {d68000_subq_16      , 0xf1c0, 0x5140, 0xff8},
2935    {d68000_subq_32      , 0xf1c0, 0x5180, 0xff8},
2936    {d68000_subx_rr_8    , 0xf1f8, 0x9100, 0x000},
2937    {d68000_subx_rr_16   , 0xf1f8, 0x9140, 0x000},
2938    {d68000_subx_rr_32   , 0xf1f8, 0x9180, 0x000},
2939    {d68000_subx_mm_8    , 0xf1f8, 0x9108, 0x000},
2940    {d68000_subx_mm_16   , 0xf1f8, 0x9148, 0x000},
2941    {d68000_subx_mm_32   , 0xf1f8, 0x9188, 0x000},
2942    {d68000_swap         , 0xfff8, 0x4840, 0x000},
2943    {d68000_tas          , 0xffc0, 0x4ac0, 0xbf8},
2944    {d68000_trap         , 0xfff0, 0x4e40, 0x000},
2945    {d68020_trapcc_0     , 0xf0ff, 0x50fc, 0x000},
2946    {d68020_trapcc_16    , 0xf0ff, 0x50fa, 0x000},
2947    {d68020_trapcc_32    , 0xf0ff, 0x50fb, 0x000},
2948    {d68000_trapv        , 0xffff, 0x4e76, 0x000},
2949    {d68000_tst_8        , 0xffc0, 0x4a00, 0xbf8},
2950    {d68020_tst_pcdi_8   , 0xffff, 0x4a3a, 0x000},
2951    {d68020_tst_pcix_8   , 0xffff, 0x4a3b, 0x000},
2952    {d68020_tst_i_8      , 0xffff, 0x4a3c, 0x000},
2953    {d68000_tst_16       , 0xffc0, 0x4a40, 0xbf8},
2954    {d68020_tst_a_16     , 0xfff8, 0x4a48, 0x000},
2955    {d68020_tst_pcdi_16  , 0xffff, 0x4a7a, 0x000},
2956    {d68020_tst_pcix_16  , 0xffff, 0x4a7b, 0x000},
2957    {d68020_tst_i_16     , 0xffff, 0x4a7c, 0x000},
2958    {d68000_tst_32       , 0xffc0, 0x4a80, 0xbf8},
2959    {d68020_tst_a_32     , 0xfff8, 0x4a88, 0x000},
2960    {d68020_tst_pcdi_32  , 0xffff, 0x4aba, 0x000},
2961    {d68020_tst_pcix_32  , 0xffff, 0x4abb, 0x000},
2962    {d68020_tst_i_32     , 0xffff, 0x4abc, 0x000},
2963    {d68000_unlk         , 0xfff8, 0x4e58, 0x000},
2964    {d68020_unpk_rr      , 0xf1f8, 0x8180, 0x000},
2965    {d68020_unpk_mm      , 0xf1f8, 0x8188, 0x000},
2966    {0, 0, 0, 0}
2967 };
2968 
2969 /* Check if opcode is using a valid ea mode */
valid_ea(uint opcode,uint mask)2970 static int valid_ea(uint opcode, uint mask)
2971 {
2972    if(mask == 0)
2973       return 1;
2974 
2975    switch(opcode & 0x3f)
2976    {
2977       case 0x00: case 0x01: case 0x02: case 0x03:
2978       case 0x04: case 0x05: case 0x06: case 0x07:
2979          return (mask & 0x800) != 0;
2980       case 0x08: case 0x09: case 0x0a: case 0x0b:
2981       case 0x0c: case 0x0d: case 0x0e: case 0x0f:
2982          return (mask & 0x400) != 0;
2983       case 0x10: case 0x11: case 0x12: case 0x13:
2984       case 0x14: case 0x15: case 0x16: case 0x17:
2985          return (mask & 0x200) != 0;
2986       case 0x18: case 0x19: case 0x1a: case 0x1b:
2987       case 0x1c: case 0x1d: case 0x1e: case 0x1f:
2988          return (mask & 0x100) != 0;
2989       case 0x20: case 0x21: case 0x22: case 0x23:
2990       case 0x24: case 0x25: case 0x26: case 0x27:
2991          return (mask & 0x080) != 0;
2992       case 0x28: case 0x29: case 0x2a: case 0x2b:
2993       case 0x2c: case 0x2d: case 0x2e: case 0x2f:
2994          return (mask & 0x040) != 0;
2995       case 0x30: case 0x31: case 0x32: case 0x33:
2996       case 0x34: case 0x35: case 0x36: case 0x37:
2997          return (mask & 0x020) != 0;
2998       case 0x38:
2999          return (mask & 0x010) != 0;
3000       case 0x39:
3001          return (mask & 0x008) != 0;
3002       case 0x3a:
3003          return (mask & 0x002) != 0;
3004       case 0x3b:
3005          return (mask & 0x001) != 0;
3006       case 0x3c:
3007          return (mask & 0x004) != 0;
3008    }
3009    return 0;
3010 
3011 }
3012 
3013 /* Used by qsort */
compare_nof_true_bits(const void * aptr,const void * bptr)3014 static int CLIB_DECL compare_nof_true_bits(const void *aptr, const void *bptr)
3015 {
3016    uint a = ((opcode_struct*)aptr)->mask;
3017    uint b = ((opcode_struct*)bptr)->mask;
3018 
3019    a = ((a & 0xAAAA) >> 1) + (a & 0x5555);
3020    a = ((a & 0xCCCC) >> 2) + (a & 0x3333);
3021    a = ((a & 0xF0F0) >> 4) + (a & 0x0F0F);
3022    a = ((a & 0xFF00) >> 8) + (a & 0x00FF);
3023 
3024    b = ((b & 0xAAAA) >> 1) + (b & 0x5555);
3025    b = ((b & 0xCCCC) >> 2) + (b & 0x3333);
3026    b = ((b & 0xF0F0) >> 4) + (b & 0x0F0F);
3027    b = ((b & 0xFF00) >> 8) + (b & 0x00FF);
3028 
3029    return b - a; /* reversed to get greatest to least sorting */
3030 }
3031 
3032 /* build the opcode handler jump table */
build_opcode_table(void)3033 static void build_opcode_table(void)
3034 {
3035    uint i;
3036    uint opcode;
3037    opcode_struct* ostruct;
3038    uint opcode_info_length = 0;
3039 
3040    (void)copyright_notice;
3041 
3042    for(ostruct = g_opcode_info;ostruct->opcode_handler != 0;ostruct++)
3043       opcode_info_length++;
3044 
3045    qsort((void *)g_opcode_info, opcode_info_length, sizeof(g_opcode_info[0]), compare_nof_true_bits);
3046 
3047    for(i=0;i<0x10000;i++)
3048    {
3049       g_instruction_table[i] = d68000_illegal; /* default to illegal */
3050       opcode = i;
3051       /* search through opcode info for a match */
3052       for(ostruct = g_opcode_info;ostruct->opcode_handler != 0;ostruct++)
3053       {
3054          /* match opcode mask and allowed ea modes */
3055          if((opcode & ostruct->mask) == ostruct->match)
3056          {
3057             /* Handle destination ea for move instructions */
3058             if((ostruct->opcode_handler == d68000_move_8 ||
3059                 ostruct->opcode_handler == d68000_move_16 ||
3060                 ostruct->opcode_handler == d68000_move_32) &&
3061                 !valid_ea(((opcode>>9)&7) | ((opcode>>3)&0x38), 0xbf8))
3062                   continue;
3063             if(valid_ea(opcode, ostruct->ea_mask))
3064             {
3065                g_instruction_table[i] = ostruct->opcode_handler;
3066                break;
3067             }
3068          }
3069       }
3070    }
3071 }
3072 
d68k_is_valid_instruction(int instruction)3073 int d68k_is_valid_instruction(int instruction)
3074 {
3075    return g_instruction_table[instruction&0xffff] != d68000_illegal;
3076 }
3077 
3078 /* ======================================================================== */
3079 /* ============================== END OF FILE ============================= */
3080 /* ======================================================================== */
3081