diff options
Diffstat (limited to 'asmmon.c')
-rw-r--r-- | asmmon.c | 357 |
1 files changed, 203 insertions, 154 deletions
@@ -4,11 +4,12 @@ #define debug 1 -#define OPNUM 91 -#define SETOP(num, _mne, _IMM, _ZM, _ZMX, _ZMY, _ABS, _IMPL) \ +#define OPNUM 93 +#define SETOP(num, _mne, _IMM, _ZM, _ZMX, _ZMY, _IND, _INX, _INY, _ABS, _IMPL) \ {opcodes[num].mnemonic[3] = '\0'; strncpy(opcodes[num].mnemonic, _mne, 3); \ opcodes[num].imm = _IMM; \ opcodes[num].zm = _ZM; opcodes[num].zmx = _ZMX; opcodes[num].zmy = _ZMY; \ +opcodes[num].ind = _IND; opcodes[num].inx = _INX; opcodes[num].iny = _INY; \ opcodes[num].abs = _ABS; opcodes[num].impl = _IMPL;} @@ -125,98 +126,100 @@ void viewmem(uint64_t address) { } int asmmon(const char *fn) { opent opcodes[OPNUM]; - /* mne IMM ZM ZMX ZMY ABS IMPL*/ - SETOP(0, "CPS", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(1, "ADC", 0x01, 0x05, 0x00, 0x00, 0x03, 0x00); - SETOP(2, "PHP", 0x08, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(3, "PHA", 0x09, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(4, "PHY", 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(5, "TAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B); - SETOP(6, "PHX", 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(7, "TAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D); - SETOP(8, "TYX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E); - SETOP(9, "JMP", 0x00, 0xD0, 0x00, 0x00, 0x10, 0x00); - SETOP(10, "SBC", 0x11, 0x15, 0x00, 0x00, 0x13, 0x00); - SETOP(11, "PLP", 0x18, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(12, "PLA", 0x19, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(13, "PLY", 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(14, "TYA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B); - SETOP(15, "PLX", 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(16, "TXA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D); - SETOP(17, "TXY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E); - SETOP(18, "JSR", 0x00, 0x20, 0x00, 0x00, 0x00, 0x00); - SETOP(19, "AND", 0x21, 0x2B, 0x00, 0x00, 0x29, 0x00); - SETOP(20, "ANY", 0x22, 0x82, 0x00, 0x00, 0x52, 0x00); - SETOP(21, "AAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x23); - SETOP(22, "ANX", 0x24, 0x84, 0x00, 0x00, 0x54, 0x00); - SETOP(23, "AAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x25); - SETOP(24, "STT", 0x28, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(25, "TAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C); - SETOP(26, "TSX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E); - SETOP(27, "BPO", 0x00, 0x00, 0x00, 0x00, 0x30, 0x00); - SETOP(28, "ORA", 0x31, 0x3B, 0x00, 0x00, 0x39, 0x00); - SETOP(29, "ORY", 0x32, 0x00, 0x00, 0x00, 0x62, 0x00); - SETOP(23, "OAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x33); - SETOP(31, "ORX", 0x34, 0x94, 0x00, 0x00, 0x64, 0x00); - SETOP(32, "OAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x35); - SETOP(33, "SEI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x38); - SETOP(34, "TBA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C); - SETOP(35, "TXS", 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(36, "BNG", 0x00, 0x00, 0x00, 0x00, 0x40, 0x00); - SETOP(37, "XOR", 0x41, 0x4B, 0x00, 0x00, 0x49, 0x00); - SETOP(38, "XRY", 0x42, 0xA2, 0x00, 0x00, 0x72, 0x00); - SETOP(39, "XAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x43); - SETOP(40, "XRX", 0x44, 0xA4, 0x00, 0x00, 0x74, 0x00); - SETOP(41, "XAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x45); - SETOP(42, "CLI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x48); - SETOP(43, "BCS", 0x00, 0x00, 0x00, 0x00, 0x50, 0x00); - SETOP(44, "LSL", 0x51, 0x55, 0x00, 0x00, 0x53, 0x00); - SETOP(45, "SEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x58); - SETOP(46, "STA", 0x00, 0x7B, 0x8B, 0x9B, 0x5B, 0x00); - SETOP(47, "STY", 0x00, 0x7D, 0x8D, 0x00, 0x5D, 0x00); - SETOP(48, "STX", 0x00, 0x7E, 0x00, 0x9E, 0x5E, 0x00); - SETOP(49, "BCC", 0x00, 0x00, 0x00, 0x00, 0x60, 0x00); - SETOP(50, "LSR", 0x61, 0x65, 0x00, 0x00, 0x63, 0x00); - SETOP(51, "CLC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x68); - SETOP(52, "LDA", 0x69, 0x79, 0x89, 0x99, 0x59, 0x00); - SETOP(53, "LDY", 0x6A, 0x7A, 0x8A, 0x00, 0x5A, 0x00); - SETOP(54, "LDX", 0x6C, 0x7C, 0x00, 0x9C, 0x5C, 0x00); - SETOP(55, "BEQ", 0x00, 0x00, 0x00, 0x00, 0x70, 0x00); - SETOP(56, "ROL", 0x71, 0x75, 0x00, 0x00, 0x73, 0x00); - SETOP(57, "SSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x78); - SETOP(58, "BNE", 0x00, 0x00, 0x00, 0x00, 0x80, 0x00); - SETOP(59, "ROR", 0x81, 0x85, 0x00, 0x00, 0x83, 0x00); - SETOP(60, "CSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x88); - SETOP(61, "BVS", 0x00, 0x00, 0x00, 0x00, 0x90, 0x00); - SETOP(62, "MUL", 0x91, 0x95, 0x00, 0x00, 0x93, 0x00); - SETOP(63, "SEV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x98); - SETOP(64, "BVC", 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00); - SETOP(65, "DIV", 0xA1, 0xA5, 0x00, 0x00, 0xA3, 0x00); - SETOP(66, "CLV", 0x00, 0x00, 0x00, 0x00, 0x00, 0xA8); - SETOP(67, "ASR", 0xA9, 0xAD, 0x00, 0x00, 0xAB, 0x00); - SETOP(68, "RTS", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0); - SETOP(69, "CMP", 0xB1, 0xF5, 0x00, 0x00, 0xE5, 0x00); - SETOP(70, "CPY", 0xB2, 0xF2, 0x00, 0x00, 0xE2, 0x00); - SETOP(71, "CAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB3); - SETOP(72, "CPX", 0xB4, 0xF4, 0x00, 0x00, 0xE4, 0x00); - SETOP(73, "CAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xB5); - SETOP(74, "ENT", 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(75, "RTI", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0); - SETOP(76, "INC", 0x00, 0xE3, 0x00, 0x00, 0xE1, 0xC1); - SETOP(77, "INY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2); - SETOP(78, "IAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3); - SETOP(79, "INX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC4); - SETOP(80, "IAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5); - SETOP(81, "DEC", 0x00, 0xF3, 0x00, 0x00, 0xF1, 0xD1); - SETOP(82, "DEY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD2); - SETOP(83, "DAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD3); - SETOP(84, "DEX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD4); - SETOP(85, "DAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD5); - SETOP(86, "WAI", 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8); - SETOP(87, "JSL", 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00); - SETOP(88, "NOP", 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8); - SETOP(89, "RTL", 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0); - SETOP(90, "BRK", 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8); + /* mne IMM ZM ZMX ZMY IND INX INY ABS IMPL*/ + SETOP( 0, "CPS", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 1, "ADC", 0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x00); + SETOP( 2, "AAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02); + SETOP( 3, "PHB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06); + SETOP( 4, "PHP", 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 5, "PHA", 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 6, "PHY", 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 7, "TAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0B); + SETOP( 8, "PHX", 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 9, "TAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0D); + SETOP(10, "TYX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0E); + SETOP(11, "JMP", 0x00, 0xD0, 0x00, 0x00, 0x04, 0x14, 0x24, 0x10, 0x00); + SETOP(12, "SBC", 0x11, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00); + SETOP(13, "SAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12); + SETOP(14, "PLB", 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(15, "PLP", 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(16, "PLA", 0x19, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(17, "PLY", 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(18, "TYA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1B); + SETOP(19, "PLX", 0x1C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(20, "TXA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1D); + SETOP(21, "TXY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1E); + SETOP(22, "JSR", 0x00, 0x20, 0x00, 0x00, 0x34, 0x44, 0x54, 0x00, 0x00); + SETOP(23, "AND", 0x21, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00); + SETOP(24, "ABA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22); + SETOP(25, "STT", 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(26, "TAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x26); + SETOP(27, "TSX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2E); + SETOP(28, "BPO", 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00); + SETOP(29, "ORA", 0x31, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00); + SETOP(30, "OAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32); + SETOP(31, "TBA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36); + SETOP(32, "SEI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38); + SETOP(33, "TXS", 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(34, "BNG", 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00); + SETOP(35, "XOR", 0x41, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00); + SETOP(36, "XAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42); + SETOP(37, "CLI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48); + SETOP(38, "BCS", 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00); + SETOP(39, "LSL", 0x51, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x00); + SETOP(40, "LLB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52); + SETOP(41, "STB", 0x00, 0x7F, 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0x5F, 0x00); + SETOP(42, "SEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58); + SETOP(43, "STA", 0x00, 0x7B, 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0x5B, 0x00); + SETOP(44, "STY", 0x00, 0x7D, 0x8D, 0x00, 0xAD, 0xBD, 0x00, 0x5D, 0x00); + SETOP(45, "STX", 0x00, 0x7E, 0x00, 0x9E, 0xAE, 0x00, 0xCE, 0x5E, 0x00); + SETOP(46, "BCC", 0x00, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00); + SETOP(47, "LSR", 0x61, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00); + SETOP(48, "LRB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62); + SETOP(49, "LDB", 0x66, 0x76, 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0x56, 0x00); + SETOP(50, "CLC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68); + SETOP(51, "LDA", 0x69, 0x79, 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0x59, 0x00); + SETOP(52, "LDY", 0x6A, 0x7A, 0x8A, 0x00, 0xAA, 0xBA, 0x00, 0x5A, 0x00); + SETOP(53, "LDX", 0x6C, 0x7C, 0x00, 0x9C, 0xAC, 0x00, 0xCC, 0x5C, 0x00); + SETOP(54, "BEQ", 0x00, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00); + SETOP(55, "ROL", 0x71, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00); + SETOP(56, "RLB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72); + SETOP(57, "SSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78); + SETOP(58, "BNE", 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00); + SETOP(59, "ROR", 0x81, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x00); + SETOP(60, "RRB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82); + SETOP(61, "CSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88); + SETOP(62, "BVS", 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00); + SETOP(63, "MUL", 0x91, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x00); + SETOP(64, "MAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92); + SETOP(65, "SEV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98); + SETOP(66, "BVC", 0x00, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00); + SETOP(67, "DIV", 0xA1, 0xA5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA3, 0x00); + SETOP(68, "DAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2); + SETOP(69, "CLV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA8); + SETOP(70, "RTS", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0); + SETOP(71, "CMP", 0xB1, 0xB5, 0x00, 0x00, 0xE9, 0xEB, 0xED, 0xB3, 0x00); + SETOP(72, "CAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2); + SETOP(73, "CPY", 0x2A, 0x3B, 0x00, 0x00, 0xEA, 0xFA, 0x00, 0x2B, 0x00); + SETOP(74, "CPX", 0xBC, 0x3D, 0x00, 0x00, 0xEC, 0x00, 0xFC, 0x2D, 0x00); + SETOP(75, "CPB", 0xD6, 0xF6, 0x00, 0x00, 0xDF, 0xEF, 0xFF, 0xE6, 0x00); + SETOP(76, "ENT", 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(77, "RTI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0); + SETOP(78, "INC", 0x00, 0xC5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC3, 0xC1); + SETOP(79, "IAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC2); + SETOP(80, "INY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3A); + SETOP(81, "INX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C); + SETOP(82, "DEC", 0x00, 0xD5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD3, 0xD1); + SETOP(83, "DBA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD2); + SETOP(84, "DEY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4A); + SETOP(85, "DEX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C); + SETOP(86, "WAI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8); + SETOP(87, "JSL", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00); + SETOP(88, "ASR", 0xE1, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE3, 0x00); + SETOP(89, "ARB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE2); + SETOP(90, "NOP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8); + SETOP(91, "RTL", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0); + SETOP(92, "BRK", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8); FILE *fp; if (strcasecmp(fn, "stdin") != 0) { fp = fopen(fn, "r"); @@ -256,30 +259,31 @@ int asmmon(const char *fn) { strtok_r(ins, ".", &postfix); if (oprand != NULL) { for (int i = 0; i < strlen(oprand); i++) { + if (oprand[i] == '(') + addrmode = 6; if (oprand[i] == '"') break; - if (oprand[i] == 'x' || oprand[i] == 'X') { - ir[0] = 'x'; - ir[1] = '\0'; - break; - } - if (oprand[i] == 'y' || oprand[i] == 'Y') { - ir[0] = 'y'; - ir[1] = '\0'; - break; + if (a && oprand[a] == ',') { + if (oprand[i] == 'x' || oprand[i] == 'X') { + ir[0] = 'x'; + ir[1] = '\0'; + } + if (oprand[i] == 'y' || oprand[i+1] == 'Y') { + ir[0] = 'y'; + ir[1] = '\0'; + } } - if (oprand[i] == ',' || oprand[i] == ';') { + if (oprand[i] == ',' || oprand[i] == ';') a = i; - } } if (a) oprand[a] = '\0'; } } - if (strcasecmp(cmd, "quit") == 0 || strcasecmp(cmd, "q") == 0) { + if (!strcasecmp(cmd, "quit") || !strcasecmp(cmd, "q")) { return 2; } - if (strcasecmp(cmd, "viewmem") == 0) { + if (!strcasecmp(cmd, "viewmem") || !strcasecmp(cmd, "vm") || !strcasecmp(cmd, "v")) { done |= 4; viewmem(address); } @@ -437,51 +441,56 @@ int asmmon(const char *fn) { } } - if (oprand == NULL && !strcasecmp(ins, "TXS")) + if (oprand == NULL && !strcasecmp(ins, "TXS")) { addrmode = 1; + done |= 32; + } else if (oprand != NULL && !strcasecmp(ins, "TXS")) addr[address++] = 0x17; if (!(done & 2) && oprand != NULL) { - if (oprand[0] == '#' || oprand[0] == '$') { - if(oprand[0] == '#' && (oprand[1] == '$' || oprand[1] == '%')) { - mode[1] = oprand[1]; - mode[2] = '\0'; - } else { - mode[1] = '\0'; - } - mode[0] = oprand[0]; - oprand = strtok(oprand, "#$%"); + mode[0] = oprand[0]; + mode[1] = oprand[1]; + if (oprand[0] == '#' || oprand[0] == '$' || oprand[0] == '(') { + oprand = strtok(oprand, "#($%"); if (mode[0] == '#') { addrmode = 1; + done |= 32; if (mode[1] == '$') value = strtoull(oprand, NULL, 16); - if (mode[1] == '%') + else if (mode[1] == '%') value = strtoull(oprand, NULL, 2); - } - if (mode[0] == '$') { - value = strtoull(oprand, NULL, 16); - if (value == 0) - addrmode = 2; - if (value & 0xFFFFFFFF) { - char *stf[] = {"BPO", "BNG", "BCS", "BCC", "BEQ", "BNE", "BVS", "BVC"}; - for (int i = 0; i < 8; i++) { - if (strcasecmp(ins, stf[i]) == 0) { - addrmode = 5; - break; - } else { - addrmode = 2; - } + else + value = strtoull(oprand, NULL, 10); + } else { + if (mode[0] == '$' || mode[1] == '$') + value = strtoull(oprand, NULL, 16); + else if (mode[0] == '%' || mode[1] == '%') + value = strtoull(oprand, NULL, 2); + else + value = strtoull(oprand, NULL, 10); + if (mode[0] != '(') { + if (value & 0xFFFFFFFF || !value) { + addrmode = 2; + } else if (value & 0xFFFFFFFF00000000) { + addrmode = 5; } - } else if (value & 0xFFFFFFFF00000000) { - addrmode = 5; } - if (addrmode == 2 && ir != NULL) { + if ((addrmode == 2 || addrmode == 6) && ir != NULL) { switch (ir[0]) { case 'x': - addrmode = 3; + if (addrmode == 2) + addrmode = 3; + else if (addrmode == 6) + addrmode = 7; break; case 'y': - addrmode = 4; + if (addrmode == 2) + addrmode = 4; + else if (addrmode == 6) + addrmode = 8; + break; + default: + done |= 32; break; } } @@ -494,28 +503,29 @@ int asmmon(const char *fn) { } if ((isalnum(oprand[i]) || oprand[i] == '_') && oprand[i] != '"') { value = use_label(oprand, address); - if (value == 0) - addrmode = 2; - if (value & 0xFFFFFFFF || value == 0) { - char *stf[] = {"BPO", "BNG", "BCS", "BCC", "BEQ", "BNE", "BVS", "BVC"}; - for (int i = 0; i < 8; i++) { - if (!strcasecmp(ins, stf[i])) { - addrmode = 5; - break; - } else { - addrmode = 2; - } + if (mode[0] != '(') { + if (value & 0xFFFFFFFF || !value) { + addrmode = 2; + } else if (value & 0xFFFFFFFF00000000) { + addrmode = 5; } - } else if (value & 0xFFFFFFFF00000000) { - addrmode = 5; } - if (addrmode == 2 && ir != NULL) { + if ((addrmode == 2 || addrmode == 6) && ir != NULL && a) { switch (ir[0]) { case 'x': - addrmode = 3; + if (addrmode == 2) + addrmode = 3; + else if (addrmode == 6) + addrmode = 7; break; case 'y': - addrmode = 4; + if (addrmode == 2) + addrmode = 4; + else if (addrmode == 6) + addrmode = 8; + break; + default: + done |= 32; break; } } @@ -716,6 +726,45 @@ int asmmon(const char *fn) { fprintf(stderr, "oof, %s cannot be an absolute dictator.\n", op.mnemonic); } break; + case 6: + if (op.ind) { + addr[address++] = op.ind; + addr[address] = value & 0xFF; + addr[address+1] = value >> 8; + addr[address+2] = value >> 16; + addr[address+3] = value >> 24; + address+=4; + break; + } else { + fprintf(stderr, "oof, %s cannot use pointers.\n", op.mnemonic); + } + break; + case 7: + if (op.inx) { + addr[address++] = op.inx; + addr[address] = value & 0xFF; + addr[address+1] = value >> 8; + addr[address+2] = value >> 16; + addr[address+3] = value >> 24; + address+=4; + break; + } else { + fprintf(stderr, "oof, %s does not use Indexed Indirect.\n", op.mnemonic); + } + break; + case 8: + if (op.iny) { + addr[address++] = op.iny; + addr[address] = value & 0xFF; + addr[address+1] = value >> 8; + addr[address+2] = value >> 16; + addr[address+3] = value >> 24; + address+=4; + break; + } else { + fprintf(stderr, "oof, %s does not use Indirect Indexed.\n", op.mnemonic); + } + break; } #if debug if (!(done & 6)) { @@ -726,7 +775,7 @@ int asmmon(const char *fn) { printf("Postfix: %s, ", (postfix[0] != '\0') ? postfix : "none"); #endif printf("Operand: %s, ", (oprand != NULL && !(done & 16)) ? oprand : "none"); - printf("Index Register: %s, ", (ir != NULL) ? ir : "none"); + printf("Index Register: %s, ", (ir != NULL && !(done & 32)) ? ir : "none"); printf("Address: $%llx\n", address); } #endif |