/* disassembler for 6811 $Log: dis.c,v $ * Revision 1.10 1994/03/22 22:01:38 ted * fully bracketed structure initializers and added type * declaration to init_dis. all to make gcc -Wall be happy. * * Revision 1.9 1994/02/02 19:25:18 teller * some changes made before in error * * Revision 1.8 1994/01/27 00:50:02 teller * the rest of the errors involving ldaa and ldab are fixed * * Revision 1.7 1994/01/27 00:42:56 teller * ldaa direct was 3 bytes instead of 2 and ldab direct same.... also ldas changed to ldaas * * Revision 1.6 1993/09/24 20:03:29 teller * error in printout of cpx immediate * * Revision 1.5 1993/09/23 21:12:09 teller * some displays/comments incorrect for CPD, CPX, CPY * * Revision 1.4 1993/03/02 05:45:00 ted * fixed direct mode disassembly * * Revision 1.2 1993/01/27 23:22:34 ted * added some commands for multi-stepping and support for breakpoints * and disassembling * * Revision 1.2 1993/01/27 23:22:34 ted * added some commands for multi-stepping and support for breakpoints * and disassembling * */ #include #include "sim.h" typedef struct { char *name; /* the name of the op code */ char *format; /* the format of the arguments */ int bytes; /* the number of bytes (excluding prefix) */ } disop; disop page1[] = { /* unprefixed instructions */ /* 0x00 */ {"test", "", 1}, /* 0x01 */ {"nop", "", 1}, /* 0x02 */ {"idiv", "", 1}, /* 0x03 */ {"fdiv", "", 1}, /* 0x04 */ {"lsrd", "", 1}, /* 0x05 */ {"asld", "", 1}, /* 0x06 */ {"tap", "", 1}, /* 0x07 */ {"tpa", "", 1}, /* 0x08 */ {"inx", "", 1}, /* 0x09 */ {"dex", "", 1}, /* 0x0a */ {"clv", "", 1}, /* 0x0b */ {"sev", "", 1}, /* 0x0c */ {"clc", "", 1}, /* 0x0d */ {"sec", "", 1}, /* 0x0e */ {"cli", "", 1}, /* 0x0f */ {"sei", "", 1}, /* 0x10 */ {"sba", "", 1}, /* 0x11 */ {"cba", "", 1}, /* 0x12 */ {"brset", "", 1}, /* 0x13 */ {"brclr", "", 1}, /* 0x14 */ {"bset", "", 1}, /* 0x15 */ {"bclr", "", 1}, /* 0x16 */ {"tab", "", 1}, /* 0x17 */ {"tba", "", 1}, /* 0x18 */ {"place holder", "", 0}, /* 0x19 */ {"daa", "", 1}, /* 0x1a */ {"place holder", "", 0}, /* 0x1b */ {"aba", "", 1}, /* 0x1c */ {"bset add,x", "%02x,x", 2}, /* 0x1d */ {"bclr add,x", "%02x,x", 2}, /* 0x1e */ {"brset", "%02x,x %02x %02x", 4}, /* 0x1f */ {"brclr", "%02x,x %02x %02x", 4}, /* 0x20 */ {"bra", "%02x", 2}, /* 0x21 */ {"brn", "%02x", 2}, /* 0x22 */ {"bhi", "%02x", 2}, /* 0x23 */ {"bls", "%02x", 2}, /* 0x24 */ {"bcc", "%02x", 2}, /* 0x25 */ {"bcs", "%02x", 2}, /* 0x26 */ {"bne", "%02x", 2}, /* 0x27 */ {"beq", "%02x", 2}, /* 0x28 */ {"bvc", "%02x", 2}, /* 0x29 */ {"bvs", "%02x", 2}, /* 0x2a */ {"bpl", "%02x", 2}, /* 0x2b */ {"bmi", "%02x", 2}, /* 0x2c */ {"bge", "%02x", 2}, /* 0x2d */ {"blt", "%02x", 2}, /* 0x2e */ {"bgt", "%02x", 2}, /* 0x2f */ {"ble", "%02x", 2}, /* 0x30 */ {"tsx", "", 1}, /* 0x31 */ {"ins", "", 1}, /* 0x32 */ {"pula", "", 1}, /* 0x33 */ {"pulb", "", 1}, /* 0x34 */ {"des", "", 1}, /* 0x35 */ {"txs", "", 1}, /* 0x36 */ {"psha", "", 1}, /* 0x37 */ {"pshb", "", 1}, /* 0x38 */ {"pulx", "", 1}, /* 0x39 */ {"rts", "", 1}, /* 0x3a */ {"abx", "", 1}, /* 0x3b */ {"rti", "", 1}, /* 0x3c */ {"pshx", "", 1}, /* 0x3d */ {"mul", "", 1}, /* 0x3e */ {"wai", "", 1}, /* 0x3f */ {"swi", "", 1}, /* 0x40 */ {"nega", "", 1}, /* 0x41 */ {"illegal", "", 1}, /* 0x42 */ {"illegal", "", 1}, /* 0x43 */ {"coma", "", 1}, /* 0x44 */ {"lsra", "", 1}, /* 0x45 */ {"illegal", "", 1}, /* 0x46 */ {"rora", "", 1}, /* 0x47 */ {"asra", "", 1}, /* 0x48 */ {"asla", "", 1}, /* 0x49 */ {"rola", "", 1}, /* 0x4a */ {"deca", "", 1}, /* 0x4b */ {"illegal", "", 1}, /* 0x4c */ {"inca", "", 1}, /* 0x4d */ {"tsta", "", 1}, /* 0x4e */ {"illegal", "", 1}, /* 0x4f */ {"clra", "", 1}, /* 0x50 */ {"negb", "", 1}, /* 0x51 */ {"illegal", "", 1}, /* 0x52 */ {"illegal", "", 1}, /* 0x53 */ {"comb", "", 1}, /* 0x54 */ {"lsrb", "", 1}, /* 0x55 */ {"illegal", "", 1}, /* 0x56 */ {"rorb", "", 1}, /* 0x57 */ {"asrb", "", 1}, /* 0x58 */ {"aslb", "", 1}, /* 0x59 */ {"rolb", "", 1}, /* 0x5a */ {"decb", "", 1}, /* 0x5b */ {"illegal", "", 1}, /* 0x5c */ {"incb", "", 1}, /* 0x5d */ {"tstb", "", 1}, /* 0x5e */ {"illegal", "", 1}, /* 0x5f */ {"clrb", "", 1}, /* 0x60 */ {"neg", "%02x,x", 2}, /* 0x61 */ {"illegal", "", 1}, /* 0x62 */ {"illegal", "", 1}, /* 0x63 */ {"com", "%02x,x", 2}, /* 0x64 */ {"lsr", "%02x,x", 2}, /* 0x65 */ {"illegal", "", 1}, /* 0x66 */ {"ror", "%02x,x", 2}, /* 0x67 */ {"asr", "%02x,x", 2}, /* 0x68 */ {"asl", "%02x,x", 2}, /* 0x69 */ {"rol", "", 1}, /* 0x6a */ {"dec", "%02x,x", 2}, /* 0x6b */ {"illegal", "", 1}, /* 0x6c */ {"inc", "%02x,x", 2}, /* 0x6d */ {"tst", "%02x,x", 2}, /* 0x6e */ {"jmp", "%02x,x", 2}, /* 0x6f */ {"clr", "%02x,x", 2}, /* 0x70 */ {"neg", "%02x%02x", 3}, /* 0x71 */ {"illegal", "", 1}, /* 0x72 */ {"illegal", "", 1}, /* 0x73 */ {"com", "%02x%02x", 3}, /* 0x74 */ {"lsr", "%02x%02x", 3}, /* 0x75 */ {"illegal", "", 1}, /* 0x76 */ {"ror", "%02x%02x", 3}, /* 0x77 */ {"asr", "%02x%02x", 3}, /* 0x78 */ {"asl", "%02x%02x", 3}, /* 0x79 */ {"rol", "%02x%02x", 3}, /* 0x7a */ {"dec", "%02x%02x", 3}, /* 0x7b */ {"illegal", "", 1}, /* 0x7c */ {"inc", "%02x%02x", 3}, /* 0x7d */ {"tst", "%02x%02x", 3}, /* 0x7e */ {"jmp", "%02x%02x", 3}, /* 0x7f */ {"clr", "%02x%02x", 3}, /* 0x80 */ {"suba", "#%02x", 2}, /* 0x81 */ {"cmpa", "#%02x", 2}, /* 0x82 */ {"sbca", "#%02x", 2}, /* 0x83 */ {"subd", "#%02x%02x", 3}, /* 0x84 */ {"anda", "#%02x", 2}, /* 0x85 */ {"bita", "#%02x", 2}, /* 0x86 */ {"ldaa", "#%02x", 2}, /* 0x87 */ {"illegal", "", 1}, /* 0x88 */ {"eora", "#%02x", 2}, /* 0x89 */ {"adca", "#%02x", 2}, /* 0x8a */ {"ora", "#%02x", 2}, /* 0x8b */ {"adda", "#%02x", 2}, /* 0x8c */ {"cpx", "#%02x%02x", 3}, /* 0x8d */ {"bsr dest", "%02x", 2}, /* 0x8e */ {"lds", "#%02x%02x", 3}, /* 0x8f */ {"xgdx", "", 1}, /* 0x90 */ {"suba", "%02x", 3}, /* 0x91 */ {"cmpa", "%02x", 3}, /* 0x92 */ {"sbca", "%02x", 3}, /* 0x93 */ {"subd", "%02x", 3}, /* 0x94 */ {"anda", "%02x", 3}, /* 0x95 */ {"bita", "%02x", 3}, /* 0x96 */ {"ldaa", "%02x", 2}, /* 0x97 */ {"sta", "%02x", 3}, /* 0x98 */ {"eora", "%02x", 3}, /* 0x99 */ {"adca", "%02x", 3}, /* 0x9a */ {"ora", "%02x", 3}, /* 0x9b */ {"adda", "%02x", 3}, /* 0x9c */ {"cmpx", "%02x", 3}, /* 0x9d */ {"jsr", "%02x", 3}, /* 0x9e */ {"lds", "%02x", 3}, /* 0x9f */ {"sts", "%02x", 3}, /* 0xa0 */ {"suba", "%02x,x", 2}, /* 0xa1 */ {"cmpa", "%02x,x", 2}, /* 0xa2 */ {"sbca", "%02x,x", 2}, /* 0xa3 */ {"subd", "%02x,x", 2}, /* 0xa4 */ {"anda", "%02x,x", 2}, /* 0xa5 */ {"bita", "%02x,x", 2}, /* 0xa6 */ {"ldaa", "%02x,x", 2}, /* 0xa7 */ {"sta", "%02x,x", 2}, /* 0xa8 */ {"eora", "%02x,x", 2}, /* 0xa9 */ {"adca", "%02x,x", 2}, /* 0xaa */ {"ora", "%02x,x", 2}, /* 0xab */ {"adda", "%02x,x", 2}, /* 0xac */ {"cpx", "%02x,x", 2}, /* 0xad */ {"jsr", "%02x,x", 2}, /* 0xae */ {"lds", "%02x,x", 2}, /* 0xaf */ {"sts", "%02x,x", 2}, /* 0xb0 */ {"suba", "%02x%02x", 3}, /* 0xb1 */ {"cmpa", "%02x%02x", 3}, /* 0xb2 */ {"sbca", "%02x%02x", 3}, /* 0xb3 */ {"subd", "%02x%02x", 3}, /* 0xb4 */ {"anda", "%02x%02x", 3}, /* 0xb5 */ {"bita", "%02x%02x", 3}, /* 0xb6 */ {"ldaa", "%02x%02x", 3}, /* 0xb7 */ {"sta", "%02x%02x", 3}, /* 0xb8 */ {"eora", "%02x%02x", 3}, /* 0xb9 */ {"adca", "%02x%02x", 3}, /* 0xba */ {"ora", "%02x%02x", 3}, /* 0xbb */ {"adda", "%02x%02x", 3}, /* 0xbc */ {"cmpx", "%02x%02x", 3}, /* 0xbd */ {"jsr", "%02x%02x", 3}, /* 0xbe */ {"lds", "%02x%02x", 3}, /* 0xbf */ {"sts", "%02x%02x", 3}, /* 0xc0 */ {"subb", "#%02x", 2}, /* 0xc1 */ {"cmpb", "#%02x", 2}, /* 0xc2 */ {"sbcb", "#%02x", 2}, /* 0xc3 */ {"addd", "#%02x%02x", 3}, /* 0xc4 */ {"andb", "#%02x", 2}, /* 0xc5 */ {"bitb", "#%02x", 2}, /* 0xc6 */ {"ldab", "#%02x", 2}, /* 0xc7 */ {"illegal", "", 1}, /* 0xc8 */ {"eorb", "#%02x", 2}, /* 0xc9 */ {"adcb", "#%02x", 2}, /* 0xca */ {"orab", "#%02x", 2}, /* 0xcb */ {"addb", "#%02x", 2}, /* 0xcc */ {"ldd", "#%02x%02x", 3}, /* 0xcd */ {"place holder", "", 0}, /* 0xce */ {"ldx", "#%02x%02x", 3}, /* 0xcf */ {"stop", "", 1}, /* 0xd0 */ {"subb", "%02x", 3}, /* 0xd1 */ {"cmpb", "%02x", 3}, /* 0xd2 */ {"sbcb", "%02x", 3}, /* 0xd3 */ {"addd", "%02x", 3}, /* 0xd4 */ {"andb", "%02x", 3}, /* 0xd5 */ {"bitb", "%02x", 3}, /* 0xd6 */ {"ldab", "%02x", 2}, /* 0xd7 */ {"stab", "%02x", 3}, /* 0xd8 */ {"eorb", "%02x", 3}, /* 0xd9 */ {"adcb", "%02x", 3}, /* 0xda */ {"orab", "%02x", 3}, /* 0xdb */ {"addb", "%02x", 3}, /* 0xdc */ {"ldd", "%02x", 3}, /* 0xdd */ {"stad", "%02x", 3}, /* 0xde */ {"ldx", "%02x", 3}, /* 0xdf */ {"stx", "%02x", 3}, /* 0xe0 */ {"subb", "%02x,x", 2}, /* 0xe1 */ {"cmpb", "%02x,x", 2}, /* 0xe2 */ {"sbcb", "%02x,x", 2}, /* 0xe3 */ {"addd", "%02x,x", 2}, /* 0xe4 */ {"andb", "%02x,x", 2}, /* 0xe5 */ {"bitb", "%02x,x", 2}, /* 0xe6 */ {"ldab", "%02x,x", 2}, /* 0xe7 */ {"stb", "%02x,x", 2}, /* 0xe8 */ {"eorb", "%02x,x", 2}, /* 0xe9 */ {"adcb", "%02x,x", 2}, /* 0xea */ {"orb", "%02x,x", 2}, /* 0xeb */ {"addb", "%02x,x", 2}, /* 0xec */ {"ldd", "%02x,x", 2}, /* 0xed */ {"stad", "%02x,x", 2}, /* 0xee */ {"ldx", "%02x,x", 2}, /* 0xef */ {"stx", "%02x,x", 2}, /* 0xf0 */ {"subb", "%02x%02x", 3}, /* 0xf1 */ {"cmpb", "%02x%02x", 3}, /* 0xf2 */ {"sbcb", "%02x%02x", 3}, /* 0xf3 */ {"addd", "%02x%02x", 3}, /* 0xf4 */ {"andb", "%02x%02x", 3}, /* 0xf5 */ {"bitb", "%02x%02x", 3}, /* 0xf6 */ {"ldab", "%02x%02x", 3}, /* 0xf7 */ {"stb", "%02x%02x", 3}, /* 0xf8 */ {"eorb", "%02x%02x", 3}, /* 0xf9 */ {"adcb", "%02x%02x", 3}, /* 0xfa */ {"orb", "%02x%02x", 3}, /* 0xfb */ {"addb", "%02x%02x", 3}, /* 0xfc */ {"ldd", "%02x%02x", 3}, /* 0xfd */ {"stad", "%02x%02x", 3}, /* 0xfe */ {"ldx", "%02x%02x", 3}, /* 0xff */ {"stx", "%02x%02x", 3}, }; disop page2[] = { /* ops prefixed by page2 prefix */ /* 00 */ {"illegal", "", 1}, /* 01 */ {"illegal", "", 1}, /* 02 */ {"illegal", "", 1}, /* 03 */ {"illegal", "", 1}, /* 04 */ {"illegal", "", 1}, /* 05 */ {"illegal", "", 1}, /* 06 */ {"illegal", "", 1}, /* 07 */ {"illegal", "", 1}, /* 08 */ {"iny", "", 2}, /* 09 */ {"dey", "", 2}, /* 0a */ {"illegal", "", 1}, /* 0b */ {"illegal", "", 1}, /* 0c */ {"illegal", "", 1}, /* 0d */ {"illegal", "", 1}, /* 0e */ {"illegal", "", 1}, /* 0f */ {"illegal", "", 1}, /* 10 */ {"illegal", "", 1}, /* 11 */ {"illegal", "", 1}, /* 12 */ {"illegal", "", 1}, /* 13 */ {"illegal", "", 1}, /* 14 */ {"illegal", "", 1}, /* 15 */ {"illegal", "", 1}, /* 16 */ {"illegal", "", 1}, /* 17 */ {"illegal", "", 1}, /* 18 */ {"illegal", "", 1}, /* 19 */ {"illegal", "", 1}, /* 1a */ {"illegal", "", 1}, /* 1b */ {"illegal", "", 1}, /* 1c */ {"bset", "%02x,y %02x", 4}, /* 1d */ {"bclr", "%02x,y %02x", 4}, /* 1e */ {"brset", "%02x,y %02x %02x", 5}, /* 1f */ {"brclr", "%02x,y %02x %02x", 5}, /* 20 */ {"illegal", "", 1}, /* 21 */ {"illegal", "", 1}, /* 22 */ {"illegal", "", 1}, /* 23 */ {"illegal", "", 1}, /* 24 */ {"illegal", "", 1}, /* 25 */ {"illegal", "", 1}, /* 26 */ {"illegal", "", 1}, /* 27 */ {"illegal", "", 1}, /* 28 */ {"illegal", "", 1}, /* 29 */ {"illegal", "", 1}, /* 2a */ {"illegal", "", 1}, /* 2b */ {"illegal", "", 1}, /* 2c */ {"illegal", "", 1}, /* 2d */ {"illegal", "", 1}, /* 2e */ {"illegal", "", 1}, /* 2f */ {"illegal", "", 1}, /* 30 */ {"tsy", "", 2}, /* 31 */ {"illegal", "", 1}, /* 32 */ {"illegal", "", 1}, /* 33 */ {"illegal", "", 1}, /* 34 */ {"illegal", "", 1}, /* 35 */ {"tys", "", 2}, /* 36 */ {"illegal", "", 1}, /* 37 */ {"illegal", "", 1}, /* 38 */ {"puly", "", 2}, /* 39 */ {"illegal", "", 1}, /* 3a */ {"aby", "", 2}, /* 3b */ {"illegal", "", 1}, /* 3c */ {"pshy", "", 2}, /* 3d */ {"illegal", "", 1}, /* 3e */ {"illegal", "", 1}, /* 3f */ {"illegal", "", 1}, /* 40 */ {"illegal", "", 1}, /* 41 */ {"illegal", "", 1}, /* 42 */ {"illegal", "", 1}, /* 43 */ {"illegal", "", 1}, /* 44 */ {"illegal", "", 1}, /* 45 */ {"illegal", "", 1}, /* 46 */ {"illegal", "", 1}, /* 47 */ {"illegal", "", 1}, /* 48 */ {"illegal", "", 1}, /* 49 */ {"illegal", "", 1}, /* 4a */ {"illegal", "", 1}, /* 4b */ {"illegal", "", 1}, /* 4c */ {"illegal", "", 1}, /* 4d */ {"illegal", "", 1}, /* 4e */ {"illegal", "", 1}, /* 4f */ {"illegal", "", 1}, /* 50 */ {"illegal", "", 1}, /* 51 */ {"illegal", "", 1}, /* 52 */ {"illegal", "", 1}, /* 53 */ {"illegal", "", 1}, /* 54 */ {"illegal", "", 1}, /* 55 */ {"illegal", "", 1}, /* 56 */ {"illegal", "", 1}, /* 57 */ {"illegal", "", 1}, /* 58 */ {"illegal", "", 1}, /* 59 */ {"illegal", "", 1}, /* 5a */ {"illegal", "", 1}, /* 5b */ {"illegal", "", 1}, /* 5c */ {"illegal", "", 1}, /* 5d */ {"illegal", "", 1}, /* 5e */ {"illegal", "", 1}, /* 5f */ {"illegal", "", 1}, /* 60 */ {"neg", "%02x,y", 3}, /* 61 */ {"illegal", "", 1}, /* 62 */ {"illegal", "", 1}, /* 63 */ {"com", "%02x,y", 3}, /* 64 */ {"lsr", "%02x,y", 3}, /* 65 */ {"illegal", "", 1}, /* 66 */ {"ror", "%02x,y", 3}, /* 67 */ {"asr", "%02x,y", 3}, /* 68 */ {"asl", "%02x,y", 3}, /* 69 */ {"rol", "%02x,y", 3}, /* 6a */ {"dec", "%02x,y", 3}, /* 6b */ {"illegal", "", 1}, /* 6c */ {"inc", "%02x,y", 3}, /* 6d */ {"tst", "%02x,y", 3}, /* 6e */ {"jmp", "%02x,y", 3}, /* 6f */ {"clr", "%02x,y", 3}, /* 70 */ {"illegal", "", 1}, /* 71 */ {"illegal", "", 1}, /* 72 */ {"illegal", "", 1}, /* 73 */ {"illegal", "", 1}, /* 74 */ {"illegal", "", 1}, /* 75 */ {"illegal", "", 1}, /* 76 */ {"illegal", "", 1}, /* 77 */ {"illegal", "", 1}, /* 78 */ {"illegal", "", 1}, /* 79 */ {"illegal", "", 1}, /* 7a */ {"illegal", "", 1}, /* 7b */ {"illegal", "", 1}, /* 7c */ {"illegal", "", 1}, /* 7d */ {"illegal", "", 1}, /* 7e */ {"illegal", "", 1}, /* 7f */ {"illegal", "", 1}, /* 80 */ {"illegal", "", 1}, /* 81 */ {"illegal", "", 1}, /* 82 */ {"illegal", "", 1}, /* 83 */ {"illegal", "", 1}, /* 84 */ {"illegal", "", 1}, /* 85 */ {"illegal", "", 1}, /* 86 */ {"illegal", "", 1}, /* 87 */ {"illegal", "", 1}, /* 88 */ {"illegal", "", 1}, /* 89 */ {"illegal", "", 1}, /* 8a */ {"illegal", "", 1}, /* 8b */ {"illegal", "", 1}, /* 8c */ {"cpy", "#%02x%02x", 4}, /* 8d */ {"illegal", "", 1}, /* 8e */ {"illegal", "", 1}, /* 8f */ {"xgdy", "", 2}, /* 90 */ {"illegal", "", 1}, /* 91 */ {"illegal", "", 1}, /* 92 */ {"illegal", "", 1}, /* 93 */ {"illegal", "", 1}, /* 94 */ {"illegal", "", 1}, /* 95 */ {"illegal", "", 1}, /* 96 */ {"illegal", "", 1}, /* 97 */ {"illegal", "", 1}, /* 98 */ {"illegal", "", 1}, /* 99 */ {"illegal", "", 1}, /* 9a */ {"illegal", "", 1}, /* 9b */ {"illegal", "", 1}, /* 9c */ {"cpy", "%02x", 3}, /* 9d */ {"illegal", "", 1}, /* 9e */ {"illegal", "", 1}, /* 9f */ {"illegal", "", 1}, /* a0 */ {"suba", "%02x,y", 3}, /* a1 */ {"cmpa", "%02x,y", 3}, /* a2 */ {"sbca", "%02x,y", 3}, /* a3 */ {"subd", "%02x,y", 3}, /* a4 */ {"anda", "%02x,y", 3}, /* a5 */ {"bita", "%02x,y", 3}, /* a6 */ {"ldaa", "%02x,y", 3}, /* a7 */ {"sta", "%02x,y", 3}, /* a8 */ {"eora", "%02x,y", 3}, /* a9 */ {"adca", "%02x,y", 3}, /* aa */ {"ora", "%02x,y", 3}, /* ab */ {"adda", "%02x,y", 3}, /* ac */ {"cpy", "%02x,y", 3}, /* ad */ {"jsr", "%02x,y", 3}, /* ae */ {"illegal", "", 1}, /* af */ {"sts", "%02x,y", 3}, /* b0 */ {"illegal", "", 1}, /* b1 */ {"illegal", "", 1}, /* b2 */ {"illegal", "", 1}, /* b3 */ {"illegal", "", 1}, /* b4 */ {"illegal", "", 1}, /* b5 */ {"illegal", "", 1}, /* b6 */ {"illegal", "", 1}, /* b7 */ {"illegal", "", 1}, /* b8 */ {"illegal", "", 1}, /* b9 */ {"illegal", "", 1}, /* ba */ {"illegal", "", 1}, /* bb */ {"illegal", "", 1}, /* bc */ {"cpy", "%02x%02x", 4}, /* bd */ {"illegal", "", 1}, /* be */ {"illegal", "", 1}, /* bf */ {"illegal", "", 1}, /* c0 */ {"illegal", "", 1}, /* c1 */ {"illegal", "", 1}, /* c2 */ {"illegal", "", 1}, /* c3 */ {"illegal", "", 1}, /* c4 */ {"illegal", "", 1}, /* c5 */ {"illegal", "", 1}, /* c6 */ {"illegal", "", 1}, /* c7 */ {"illegal", "", 1}, /* c8 */ {"illegal", "", 1}, /* c9 */ {"illegal", "", 1}, /* ca */ {"illegal", "", 1}, /* cb */ {"illegal", "", 1}, /* cc */ {"illegal", "", 1}, /* 0xcd */ {"illegal", "", 1}, /* ce */ {"ldy", "#%02x%02x", 4}, /* cf */ {"illegal", "", 1}, /* d0 */ {"illegal", "", 1}, /* d1 */ {"illegal", "", 1}, /* d2 */ {"illegal", "", 1}, /* d3 */ {"illegal", "", 1}, /* d4 */ {"illegal", "", 1}, /* d5 */ {"illegal", "", 1}, /* d6 */ {"illegal", "", 1}, /* d7 */ {"illegal", "", 1}, /* d8 */ {"illegal", "", 1}, /* d9 */ {"illegal", "", 1}, /* da */ {"illegal", "", 1}, /* db */ {"illegal", "", 1}, /* dc */ {"illegal", "", 1}, /* dd */ {"illegal", "", 1}, /* de */ {"ldy", "%02x", 3}, /* df */ {"sty", "%02x", 3}, /* e0 */ {"subb", "%02x,y", 3}, /* e1 */ {"cmpb", "%02x,y", 3}, /* e2 */ {"sbcb", "%02x,y", 3}, /* e3 */ {"addd", "%02x,y", 3}, /* e4 */ {"andb", "%02x,y", 3}, /* e5 */ {"bitb", "%02x,y", 3}, /* e6 */ {"ldab", "%02x,y", 3}, /* e7 */ {"stb", "%02x,y", 3}, /* e8 */ {"eorb", "%02x,y", 3}, /* e9 */ {"adcb", "%02x,y", 3}, /* ea */ {"orb", "%02x,y", 3}, /* eb */ {"addb", "%02x,y", 3}, /* ec */ {"ldad", "%02x,y", 3}, /* ed */ {"stad", "%02x,y", 3}, /* ee */ {"ldy", "%02x,y", 3}, /* ef */ {"sty", "%02x,y", 3}, /* f0 */ {"illegal", "", 1}, /* f1 */ {"illegal", "", 1}, /* f2 */ {"illegal", "", 1}, /* f3 */ {"illegal", "", 1}, /* f4 */ {"illegal", "", 1}, /* f5 */ {"illegal", "", 1}, /* f6 */ {"illegal", "", 1}, /* f7 */ {"illegal", "", 1}, /* f8 */ {"illegal", "", 1}, /* f9 */ {"illegal", "", 1}, /* fa */ {"illegal", "", 1}, /* fb */ {"illegal", "", 1}, /* fc */ {"illegal", "", 1}, /* fd */ {"illegal", "", 1}, /* fe */ {"ldy", "%02x%02x", 4}, /* ff */ {"sty", "%02x%02x", 4}, }; disop page3[256]; /* only a few ops follow page 3 prefix */ disop page4[256]; /* and even fewer follow page 4 prefix */ /* initialization is from sparse vectors */ typedef struct { int index; disop op; } dis_init; dis_init page3_inits[] = { {0x83, {"cmpd", "#%02x%02x", 4}}, {0x93, {"cmpd", "%02x", 3}}, {0xa3, {"cmpd", "%02x,x", 3}}, {0xac, {"cmpd", "%02x,y", 3}}, {0xb3, {"cmpd", "%02x%02x", 4}}, {0xee, {"ldy", "%02x,x", 3}}, {0xef, {"sty", "%02x,x", 3}}, {0, {"", "", 0}}, }; dis_init page4_inits[] = { {0xa3, {"cmpd", "%02x,y", 3}}, {0xac, {"cmpx", "%02x,y", 3}}, {0xee, {"ldx", "%02x,y", 3}}, {0xef, {"stx", "02x,y", 3}}, {0, {"", "", 0}}, }; /* to disassemble a byte stream, we just disassemble one instruction at a time */ int disassemble(FILE *f, byte *code) { disop op; switch (code[0]) { case 0x18: /* page 2 prefix? */ code++; op = page2[*code]; break; case 0x1a: /* page 3? */ code++; op = page3[*code]; break; case 0xcd: /* page 4? */ code++; op = page4[*code]; break; default: /* none of above, must be page 1 */ op = page1[*code]; break; } fprintf(f, " %s ", op.name); fprintf(f, op.format, /* we always *offer* all the bytes */ code[1], code[2], code[3]); fprintf(f, "\n"); return op.bytes; } disop illegal_op = {"illegal", "", 1}; /* initializat consists of reading the sparse page 3 and 4 initialization records and stuffing them into the real page 3 and 4 */ void init_dis() { int i; for (i=0;i<256;i++) { page3[i] = illegal_op; page4[i] = illegal_op; } for (i=0;page3_inits[i].index;i++) { page3[page3_inits[i].index] = page3_inits[i].op; } for (i=0;page4_inits[i].index;i++) { page4[page4_inits[i].index] = page4_inits[i].op; } }