diff options
Diffstat (limited to 'asmmon.c')
-rw-r--r-- | asmmon.c | 647 |
1 files changed, 419 insertions, 228 deletions
@@ -213,98 +213,95 @@ void disasm(uint8_t prefix, uint8_t opcode, uint64_t value) { int asmmon(const char *fn) { /* 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( 1, "ADC", 0x01, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00); SETOP( 2, "AAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02); - SETOP( 3, "JMP", 0x00, 0xD0, 0x00, 0x00, 0x04, 0x14, 0x24, 0x10, 0x00); - SETOP( 4, "PHB", 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP( 5, "PHP", 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP( 6, "LDA", 0x09, 0x39, 0x59, 0x79, 0x99, 0xB9, 0xD9, 0x19, 0x00); - SETOP( 7, "LDY", 0x0A, 0x3A, 0x5A, 0x00, 0x7A, 0x9A, 0x00, 0x1A, 0x00); - SETOP( 8, "LDX", 0x0B, 0x3B, 0x00, 0x5B, 0x7B, 0x00, 0x9B, 0x1B, 0x00); - SETOP( 9, "TAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C); - SETOP(10, "LDB", 0x0E, 0x3E, 0x5E, 0x7E, 0x9E, 0xBE, 0xDE, 0x1E, 0x00); - SETOP(11, "SBC", 0x11, 0x15, 0x00, 0x00, 0x00, 0x00, 0x00, 0x13, 0x00); - SETOP(12, "SAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12); - SETOP(13, "PLB", 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(14, "PLP", 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(15, "TBA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C); - SETOP(16, "JSR", 0x00, 0x20, 0x00, 0x00, 0x34, 0x44, 0x54, 0x00, 0x00); - SETOP(17, "AND", 0x21, 0x25, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00); - SETOP(18, "ABA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22); - SETOP(19, "CPB", 0x26, 0x46, 0x00, 0x00, 0x56, 0x66, 0x76, 0x36, 0x00); - SETOP(20, "STT", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x28); - SETOP(21, "STA", 0x00, 0x49, 0x69, 0x89, 0xA9, 0xC9, 0xE9, 0x29, 0x00); - SETOP(22, "STY", 0x00, 0x4A, 0x6A, 0x00, 0x8A, 0xAA, 0x00, 0x2A, 0x00); - SETOP(23, "STX", 0x00, 0x4B, 0x00, 0x6B, 0x8B, 0x00, 0xAB, 0x2B, 0x00); - SETOP(24, "TAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2C); - SETOP(25, "STB", 0x00, 0x4E, 0x6E, 0x8E, 0xAE, 0xCE, 0xEE, 0x2E, 0x00); - SETOP(26, "BPO", 0x00, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00); - SETOP(27, "ORA", 0x31, 0x35, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x00); - SETOP(28, "OAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32); - SETOP(29, "SEI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x38); - SETOP(30, "TYA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3C); - SETOP(31, "BNG", 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00); - SETOP(32, "XOR", 0x41, 0x45, 0x00, 0x00, 0x00, 0x00, 0x00, 0x43, 0x00); - SETOP(33, "XAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42); - SETOP(34, "CLI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48); - SETOP(35, "TAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4C); - SETOP(36, "BCS", 0x00, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00); - SETOP(37, "LSL", 0x51, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0x53, 0x00); - SETOP(38, "LLB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52); - SETOP(39, "SEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58); - SETOP(40, "TXA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5C); - SETOP(41, "BCC", 0x00, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00); - SETOP(42, "LSR", 0x61, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00); - SETOP(43, "LRB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62); - SETOP(44, "CLC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x68); - SETOP(45, "TYX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C); - SETOP(46, "BEQ", 0x00, 0xA4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00); - SETOP(47, "ROL", 0x71, 0x75, 0x00, 0x00, 0x00, 0x00, 0x00, 0x73, 0x00); - SETOP(48, "RLB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72); - SETOP(49, "SSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78); - SETOP(50, "TXY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7C); - SETOP(51, "BNE", 0x00, 0xB4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00); - SETOP(52, "ROR", 0x81, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x83, 0x00); - SETOP(53, "RRB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82); - SETOP(54, "INY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86); - SETOP(55, "CSP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88); - SETOP(56, "TSX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8C); - SETOP(57, "BVS", 0x00, 0xC4, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00); - SETOP(58, "MUL", 0x91, 0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x93, 0x00); - SETOP(59, "MAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92); - SETOP(60, "DEY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x96); - SETOP(61, "SEV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98); - SETOP(62, "TXS", 0x9C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(63, "BVC", 0x00, 0xD4, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00); - SETOP(64, "DIV", 0xA1, 0xA5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA3, 0x00); - SETOP(65, "DAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2); - SETOP(66, "INX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA6); - SETOP(67, "CLV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA8); - SETOP(68, "PHY", 0xAC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(69, "RTS", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0); - SETOP(70, "CMP", 0xB1, 0xB5, 0x00, 0x00, 0xF1, 0xF3, 0xF5, 0xB3, 0x00); - SETOP(71, "CAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2); - SETOP(72, "DEX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB6); - SETOP(73, "ENT", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8); - SETOP(74, "CPY", 0xBA, 0xDA, 0x00, 0x00, 0xEA, 0xFA, 0x00, 0xCA, 0x00); - SETOP(75, "CPX", 0xBB, 0xDB, 0x00, 0x00, 0xEB, 0x00, 0xFB, 0xCB, 0x00); - SETOP(76, "PLY", 0xBC, 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, "WAI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC8); - SETOP(81, "PHX", 0xCC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - 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, "PLX", 0xDC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(85, "JSL", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0x00); - SETOP(86, "ASR", 0xE1, 0xE5, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE3, 0x00); - SETOP(87, "ARB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE2); - SETOP(88, "NOP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8); - SETOP(89, "PHA", 0xEC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); - SETOP(90, "RTL", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF0); - SETOP(91, "BRK", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8); - SETOP(92, "PLA", 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 3, "PHP", 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 4, "CPB", 0x09, 0x2D, 0x00, 0x00, 0x55, 0xAD, 0xAC, 0x2C, 0x00); + SETOP( 5, "PHB", 0x0A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP( 6, "DEC", 0x00, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0xE5); + SETOP( 7, "JMP", 0x00, 0x0E, 0x00, 0x00, 0xCE, 0x00, 0x00, 0x10, 0x00); + SETOP( 8, "SBC", 0x11, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00); + SETOP( 9, "SAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12); + SETOP(10, "ENT", 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(11, "CPY", 0x19, 0x3D, 0x00, 0x00, 0x85, 0x00, 0x00, 0x4C, 0x00); + SETOP(12, "PLB", 0x1A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(13, "INC", 0x00, 0x1D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1C, 0xF5); + SETOP(14, "JSR", 0x00, 0x1E, 0x00, 0x00, 0xBE, 0x00, 0x00, 0x00, 0x00); + SETOP(15, "JSL", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00); + SETOP(16, "AND", 0x21, 0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00); + SETOP(17, "ABA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22); + SETOP(18, "PLP", 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(19, "CPX", 0x29, 0x4D, 0x00, 0x00, 0xB5, 0x00, 0x00, 0x3C, 0x00); + SETOP(20, "PHY", 0x2A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(21, "BPO", 0x00, 0x2E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x00); + SETOP(22, "ORA", 0x31, 0x36, 0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x00); + SETOP(23, "OAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x32); + SETOP(24, "STT", 0x38, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(25, "PLY", 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(26, "BNG", 0x00, 0x3E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00); + SETOP(27, "XOR", 0x41, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x44, 0x00); + SETOP(28, "XAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x42); + SETOP(29, "PHA", 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(30, "PHX", 0x4A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(31, "BCS", 0x00, 0x4E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x00); + SETOP(32, "LSL", 0x51, 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x54, 0x00); + SETOP(33, "LLB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x52); + SETOP(34, "CLC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x58); + SETOP(35, "PLX", 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(36, "BCC", 0x00, 0x5E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x00); + SETOP(37, "LSR", 0x61, 0x66, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00); + SETOP(38, "LRB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x62); + SETOP(39, "PLA", 0x68, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(40, "TAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6A); + SETOP(41, "BEQ", 0x00, 0x6E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00); + SETOP(42, "ROL", 0x71, 0x76, 0x00, 0x00, 0x00, 0x00, 0x00, 0x74, 0x00); + SETOP(43, "RLB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x72); + SETOP(44, "SEC", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78); + SETOP(45, "TBA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7A); + SETOP(46, "BNE", 0x00, 0x7E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x00); + SETOP(47, "ROR", 0x81, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x84, 0x00); + SETOP(48, "RRB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x82); + SETOP(49, "DEY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88); + SETOP(50, "TAY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8A); + SETOP(51, "BVS", 0x00, 0x8E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x90, 0x00); + SETOP(52, "MUL", 0x91, 0x96, 0x00, 0x00, 0x00, 0x00, 0x00, 0x94, 0x00); + SETOP(53, "MAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x92); + SETOP(54, "CLI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x98); + SETOP(55, "TYA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9A); + SETOP(56, "BVC", 0x00, 0x9E, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA0, 0x00); + SETOP(57, "DIV", 0xA1, 0xA6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA4, 0x00); + SETOP(58, "DAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA2); + SETOP(59, "INY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xA8); + SETOP(60, "TAX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAA); + SETOP(61, "RTS", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xAE); + SETOP(62, "RTL", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB0); + SETOP(63, "CMP", 0xB1, 0xB6, 0x00, 0x00, 0x25, 0x7D, 0x7C, 0xB4, 0x00); + SETOP(64, "CAB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB2); + SETOP(65, "SEI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB8); + SETOP(66, "LDX", 0xB9, 0xBD, 0x00, 0xC9, 0x95, 0x00, 0x00, 0xBC, 0x00); + SETOP(67, "TXA", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xBA); + SETOP(68, "RTI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0); + SETOP(69, "LDA", 0xC1, 0xC6, 0x79, 0x39, 0x05, 0x5D, 0x5C, 0xC4, 0x00); + SETOP(70, "DEX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC5); + SETOP(71, "CLV", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC8); + SETOP(72, "TYX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xCA); + SETOP(73, "STA", 0x00, 0xCD, 0x89, 0x49, 0x15, 0x6D, 0x6C, 0xCC, 0x00); + SETOP(74, "TSX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD0); + SETOP(75, "LDB", 0xD1, 0xD6, 0x99, 0x59, 0x35, 0x8D, 0x8C, 0xD4, 0x00); + SETOP(76, "INX", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD5); + SETOP(77, "WAI", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xD8); + SETOP(78, "TXY", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xDA); + SETOP(79, "STB", 0x00, 0xDD, 0xA9, 0x69, 0x45, 0x9D, 0x9C, 0xDC, 0x00); + SETOP(80, "TXS", 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); + SETOP(81, "LDY", 0xE1, 0xE6, 0xE9, 0x00, 0x65, 0x00, 0x00, 0xE4, 0x00); + SETOP(82, "BRK", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE8); + SETOP(83, "NOP", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEA); + SETOP(84, "STY", 0x00, 0xED, 0xF9, 0x00, 0x75, 0x00, 0x00, 0xEC, 0x00); + SETOP(85, "DEB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xEE); + SETOP(86, "ASR", 0xF1, 0xF6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF4, 0x00); + SETOP(87, "ARB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF2); + SETOP(88, "STX", 0x00, 0xFD, 0x00, 0xD9, 0xA5, 0x00, 0x00, 0xFC, 0x00); + SETOP(89, "INB", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE); FILE *fp; if (strcasecmp(fn, "stdin") != 0) { fp = fopen(fn, "r"); @@ -322,13 +319,16 @@ int asmmon(const char *fn) { char mode[3]; opent op; uint8_t addrmode = IMPL; + uint8_t addrtok = 0; uint64_t value = 0; char *oprand; + char *oprand2; char *cmd; char ir[2] = ""; /* Index register. */ int a = 0; int b = 0; char *tmp = malloc(sizeof(char *)*128); + char *tmp2; size_t size; prefix = 0; done = 0; @@ -348,8 +348,18 @@ int asmmon(const char *fn) { strtok_r(ins, ".", &postfix); if (oprand != NULL) { for (int i = 0; i < strlen(oprand); i++) { - if (oprand[i] == '(') - addrmode = IND; + switch (oprand[i]) { + case '(': + addrmode = IND; + break; + case '+': + addrtok = 1; + break; + case '-': + addrtok = 2; + + } + if (oprand[i] == '"') break; if (a && oprand[a] == ',') { @@ -467,9 +477,9 @@ int asmmon(const char *fn) { else if (start < 0xFFFFFFFFFFFFFFFF) printf("$%016llx: ", start); prefix = addr[start]; - if ((prefix & 0x07) == 0x07) { + if ((prefix & 0x03) == 0x03) { start+=1; - addrsize = (prefix & 8) >> 3; + addrsize = (prefix & 0x0C) >> 2; rs = (prefix & 0x30) >> 4; regsize = (1 << rs); } else { @@ -484,17 +494,17 @@ int asmmon(const char *fn) { break; case IMM: value = addr[start]; - if (regsize >= 2) - value |= addr[start+1] << 8; - if (regsize >= 4) { - value |= addr[start+2] << 16; - value |= addr[start+3] << 24; - } - if (regsize >= 8) { - value |= (uint64_t)addr[start+4] << 32; - value |= (uint64_t)addr[start+5] << 40; - value |= (uint64_t)addr[start+6] << 48; - value |= (uint64_t)addr[start+7] << 56; + switch (regsize) { + case 8: + value |= (uint64_t)addr[start+7] << 56; + value |= (uint64_t)addr[start+6] << 48; + value |= (uint64_t)addr[start+5] << 40; + value |= (uint64_t)addr[start+4] << 32; + case 4: + value |= addr[start+3] << 24; + value |= addr[start+2] << 16; + case 2: + value |= addr[start+1] << 8; } start += regsize; break; @@ -505,28 +515,61 @@ int asmmon(const char *fn) { case INDX: case INDY: value = addr[start]; - if (addrsize) { - value |= addr[start+1] << 8; - value |= addr[start+2] << 16; - value |= addr[start+3] << 24; - start+=4; - } else { - start+=1; + switch (addrsize) { + case 0: + start+=1; + break; + case 1: + value |= addr[start+1] << 8; + value |= addr[start+2] << 16; + start+=3; + break; + case 2: + value |= addr[start+1] << 8; + value |= addr[start+2] << 16; + value |= addr[start+3] << 24; + value |= (uint64_t)addr[start+4] << 32; + value |= (uint64_t)addr[start+5] << 40; + start+=6; + break; + case 3: + value |= addr[start+1] << 8; + value |= addr[start+2] << 16; + value |= addr[start+3] << 24; + start+=4; + break; } break; case ABS: value = addr[start]; value |= addr[start+1] << 8; - if (addrsize) { - value |= (uint64_t)addr[start+2] << 16; - value |= (uint64_t)addr[start+3] << 24; - value |= (uint64_t)addr[start+4] << 32; - value |= (uint64_t)addr[start+5] << 40; - value |= (uint64_t)addr[start+6] << 48; - value |= (uint64_t)addr[start+7] << 56; - start+=8; - } else { - start+=2; + switch (addrsize) { + case 0: + start+=2; + break; + case 1: + value |= addr[start+2] << 16; + value |= addr[start+3] << 24; + value |= (uint64_t)addr[start+4] << 32; + start+=5; + break; + case 2: + value |= addr[start+2] << 16; + value |= addr[start+3] << 24; + value |= (uint64_t)addr[start+4] << 32; + value |= (uint64_t)addr[start+5] << 40; + value |= (uint64_t)addr[start+6] << 48; + start+=7; + break; + case 3: + value |= addr[start+2] << 16; + value |= addr[start+3] << 24; + value |= (uint64_t)addr[start+4] << 32; + value |= (uint64_t)addr[start+5] << 40; + value |= (uint64_t)addr[start+6] << 48; + value |= (uint64_t)addr[start+7] << 56; + start+=8; + break; } break; } @@ -578,9 +621,14 @@ int asmmon(const char *fn) { sprintf(oprand, "%llx", value); break; } - if (oprand[i] == '"' && !strcasecmp(ins, ".byte")) { - qstr = 1; - continue; + if (!strcasecmp(ins, ".byte")) { + if (oprand[i] == '"') { + qstr = 1; + continue; + } else if (oprand[i] == '\'') { + qstr = 2; + continue; + } } if (oprand[i] == '$') { qstr = 0; @@ -597,7 +645,7 @@ int asmmon(const char *fn) { switch (oprand[i]) { case 0: puts("oof, unterminated string."); - qstr = 2; + qstr = 4; break; case '"': value = '\0'; @@ -642,6 +690,55 @@ int asmmon(const char *fn) { break; } addr[address++] = (uint8_t)value & 0xFF; + } else if (qstr == 2) { + switch (oprand[i]) { + case 0: + puts("oof, unterminated string."); + qstr = 4; + break; + case '\'': + c = '\0'; + tmpstr[slen++] = '\0'; + qstr = 3; + break; + case '\\': + switch (oprand[i+1]) { + case 'n': + value = '\n'; + c = '\n'; + tmpstr[slen++] = '\\'; + tmpstr[slen++] = 'n'; + break; + case 't': + value = '\t'; + c = '\t'; + tmpstr[slen++] = '\\'; + tmpstr[slen++] = 't'; + break; + case 'r': + value = '\r'; + c = '\r'; + tmpstr[slen++] = '\\'; + tmpstr[slen++] = 'r'; + break; + case '0': + break; + default: + value = oprand[i]; + tmpstr[slen++] = '\\'; + tmpstr[slen++] = oprand[i]; + break; + } + i++; + break; + default: + value = oprand[i]; + c = oprand[i]; + tmpstr[slen++] = c; + break; + } + if (qstr != 3) + addr[address++] = (uint8_t)value & 0xFF; } } if (!strcasecmp(ins, ".byte") && !qstr) @@ -695,13 +792,19 @@ int asmmon(const char *fn) { done |= 32; } else if (oprand != NULL && !strcasecmp(ins, "TXS")) - prefix = 0x17; + prefix = 0x13; if (!(done & 2) && oprand != NULL) { mode[0] = oprand[0]; mode[1] = oprand[1]; - if (oprand[0] == '#' || oprand[0] == '$' || (oprand[0] == '(' && (oprand[1] == '$' || oprand[1] == '%'))) { + strtok_r(oprand, "+-", &oprand2); + if (ir[0] == 'x' || ir[0] == 'y') + oprand2 = strtok_r(oprand2, ",)", &tmp2); + uint8_t isimm = oprand[0] == '#'; + /* This flag is used for checking if there is a secondary token. */ + uint8_t issectok = (oprand[1] == '$' || oprand[1] == '%' || isdigit(oprand[1])); + if (oprand[0] == '$' || (isimm && issectok) || (oprand[0] == '(' && issectok)) { oprand = strtok(oprand, "#($%"); - if (mode[0] == '#') { + if (isimm) { addrmode = IMM; done |= 32; if (mode[1] == '$') @@ -717,19 +820,27 @@ int asmmon(const char *fn) { value = strtoull(oprand, NULL, 2); else value = strtoull(oprand, NULL, 10); - if (value & 0xFFFFFF00 && (ir[0] == 'x' || ir[0] == 'y')) - prefix |= 0xF; if (mode[0] != '(') { - if (value & 0xFFFF0000 || (value <= 0xFF) || - (value & 0xFF00 && address <= 0xFFFF && (ir[0] == 'x' || ir[0] == 'y'))) { + if ((value & 0xFF0000 || value & 0xFFFF00000000 || value & 0xFFFF0000 || !(value & 0xFF00))) addrmode = ZM; - if (value & 0xFFFFFF00) - prefix |= 0xF; - } else if (value & 0xFFFFFFFF00000000 || (value & 0xFF00 && address <= 0xFFFF)) { + else if (value & 0xFF00000000 || value & 0xFF000000000000 || value & 0xFF00000000000000 || (value & 0xFF00)) addrmode = ABS; - if (value & 0xFFFFFFFF00000000) - prefix |= 0xF; - } + } + if (addrmode == ZM || addrmode == IND) { + if (value & 0xFFFF00) + prefix |= 0x7; + else if (value & 0xFFFF00000000) + prefix |= 0xB; + else if (value & 0xFFFF000000) + prefix |= 0xF; + } + if (addrmode == ABS) { + if (value & 0xFF00000000) + prefix |= 0x7; + else if (value & 0xFF000000000000) + prefix |= 0xB; + else if (value & 0xFF00000000000000) + prefix |= 0xF; } if ((addrmode == 2 || addrmode == 6) && ir != NULL) { switch (ir[0]) { @@ -752,8 +863,13 @@ int asmmon(const char *fn) { } } } else { - if (mode[0] == '(') + if (mode[0] == '(') { oprand = strtok(oprand, "#($%"); + } else if (isimm) { + oprand = strtok(oprand, "#"); + addrmode = IMM; + done |= 32; + } for (int i = 0; i < strlen(oprand); i++) { if (oprand[i] == ';') { done |= 16; @@ -761,37 +877,47 @@ int asmmon(const char *fn) { } if ((isalnum(oprand[i]) || oprand[i] == '_') && oprand[i] != '"') { value = use_label(oprand, address); - if (value & 0xFFFFFF00 && (ir[0] == 'x' || ir[0] == 'y')) - prefix |= 0xF; - if (mode[0] != '(') { - if (value & 0xFFFF0000 || (value <= 0xFF) || - (value <= 0xFFFF && address <= 0xFFFF && (ir[0] == 'x' || ir[0] == 'y'))) { - addrmode = ZM; - if (value & 0xFFFFFF00) + if (!isimm) { + if (mode[0] != '(') { + if ((value & 0xFF0000 || value & 0xFFFF00000000 || value & 0xFFFF0000 || !(value & 0xFF00))) + addrmode = ZM; + else if (value & 0xFF00000000 || value & 0xFF000000000000 || value & 0xFF00000000000000 || (value & 0xFF00)) + addrmode = ABS; + } + if (addrmode == ZM || addrmode == IND) { + if (value & 0xFFFF00) + prefix |= 0x7; + else if (value & 0xFFFF00000000) + prefix |= 0xB; + else if (value & 0xFFFF000000) prefix |= 0xF; - } else if (value & 0xFFFFFFFF00000000 || (value & 0xFF00 && address <= 0xFFFF)) { - addrmode = ABS; - if (value & 0xFFFFFFFF00000000) + } + if (addrmode == ABS) { + if (value & 0xFF00000000) + prefix |= 0x7; + else if (value & 0xFF000000000000) + prefix |= 0xB; + else if (value & 0xFF00000000000000) prefix |= 0xF; } - } - if ((addrmode == ZM || addrmode == IND) && ir != NULL && a) { - switch (ir[0]) { - case 'x': - if (addrmode == ZM) - addrmode = ZMX; - else if (addrmode == IND) - addrmode = INDX; - break; - case 'y': - if (addrmode == ZM) - addrmode = ZMY; - else if (addrmode == IND) - addrmode = INDY; - break; - default: - done |= 32; - break; + if ((addrmode == ZM || addrmode == IND) && ir != NULL && a) { + switch (ir[0]) { + case 'x': + if (addrmode == ZM) + addrmode = ZMX; + else if (addrmode == IND) + addrmode = INDX; + break; + case 'y': + if (addrmode == ZM) + addrmode = ZMY; + else if (addrmode == IND) + addrmode = INDY; + break; + default: + done |= 32; + break; + } } } sprintf(oprand, "%llx", value); @@ -799,6 +925,25 @@ int asmmon(const char *fn) { } } } + if (oprand2 != NULL && (addrtok == 1 || addrtok == 2)) { + uint64_t val2 = 0; + mode[0] = oprand2[0]; + oprand2 = strtok(oprand2, "$%"); + if (mode[0] == '$') + val2 = strtoull(oprand2, NULL, 16); + else if (mode[0] == '%') + val2 = strtoull(oprand2, NULL, 2); + else + val2 = strtoull(oprand2, NULL, 10); + switch (addrtok) { + case 1: + value += val2; + break; + case 2: + value -= val2; + break; + } + } } if (ins != NULL && !(done & 6)) { uint8_t i; @@ -861,11 +1006,11 @@ int asmmon(const char *fn) { } if (postfix != NULL && !(done & 8)) { if (!strcasecmp(postfix, "w") || !strcasecmp(postfix, "2")) { - prefix |= 0x17; + prefix |= 0x13; } else if (!strcasecmp(postfix, "d") || !strcasecmp(postfix, "4")) { - prefix |= 0x27; + prefix |= 0x23; } else if (!strcasecmp(postfix, "q") || !strcasecmp(postfix, "8")) { - prefix |= 0x37; + prefix |= 0x33; } else if (!prefix) { done |=8; } @@ -873,6 +1018,7 @@ int asmmon(const char *fn) { done |=8; } uint8_t r; + uint8_t r2; if (!(done & 8)) { r = prefix; addr[address] = prefix; @@ -880,6 +1026,7 @@ int asmmon(const char *fn) { } else { r = 0; } + r2 = 1 << ((prefix & 0x30) >> 4); switch (addrmode) { case IMPL: if (op.impl || op.impl == CPS) { @@ -921,18 +1068,21 @@ int asmmon(const char *fn) { break; default: addr[address] = value & 0xFF; - if (r & 0x10) + if (r & 0x10) { addr[address+1] = value >> 8; - if (r & 0x20) + } + if (r & 0x20) { addr[address+2] = value >> 16; addr[address+3] = value >> 24; - if (r & 0x30) + } + if (r & 0x30) { addr[address+4] = value >> 32; addr[address+5] = value >> 40; addr[address+6] = value >> 48; addr[address+7] = value >> 56; + } - address+=(1 << ((r & 0x30) >> 4)); + address+=r2; break; } break; @@ -944,14 +1094,20 @@ int asmmon(const char *fn) { if (op.zm) { addr[address++] = op.zm; addr[address] = value & 0xFF; - if ((r & 8) == 8) { - addr[address+1] = value >> 8; - addr[address+2] = value >> 16; - addr[address+3] = value >> 24; - address+=4; - } else { - address+=1; + switch ((r & 0x0C) >> 2) { + case 2: + addr[address+5] = (uint64_t)value >> 40; + addr[address+4] = (uint64_t)value >> 32; + address += 2; + case 3: + addr[address+3] = value >> 24; + address += 1; + case 1: + addr[address+2] = value >> 16; + addr[address+1] = value >> 8; + address += 2; } + address += 1; break; } else { fprintf(stderr, "oof, %s does not use Zero Matrix.\n", op.mnemonic); @@ -961,14 +1117,20 @@ int asmmon(const char *fn) { if (op.zmx) { addr[address++] = op.zmx; addr[address] = value & 0xFF; - if ((r & 8) == 8) { - addr[address+1] = value >> 8; - addr[address+2] = value >> 16; - addr[address+3] = value >> 24; - address+=4; - } else { - address+=1; + switch ((r & 0x0C) >> 2) { + case 2: + addr[address+5] = (uint64_t)value >> 40; + addr[address+4] = (uint64_t)value >> 32; + address += 2; + case 3: + addr[address+3] = value >> 24; + address += 1; + case 1: + addr[address+2] = value >> 16; + addr[address+1] = value >> 8; + address += 2; } + address += 1; break; } else { fprintf(stderr, "oof, %s does not use Zero Matrix, indexed with x.\n", op.mnemonic); @@ -978,14 +1140,20 @@ int asmmon(const char *fn) { if (op.zmy) { addr[address++] = op.zmy; addr[address] = value & 0xFF; - if ((r & 8) == 8) { - addr[address+1] = value >> 8; - addr[address+2] = value >> 16; - addr[address+3] = value >> 24; - address+=4; - } else { - address+=1; + switch ((r & 0x0C) >> 2) { + case 2: + addr[address+5] = (uint64_t)value >> 40; + addr[address+4] = (uint64_t)value >> 32; + address += 2; + case 3: + addr[address+3] = value >> 24; + address += 1; + case 1: + addr[address+2] = value >> 16; + addr[address+1] = value >> 8; + address += 2; } + address += 1; break; } else { fprintf(stderr, "oof, %s does not use Zero Matrix, indexed with y.\n", op.mnemonic); @@ -996,17 +1164,21 @@ int asmmon(const char *fn) { addr[address++] = op.abs; addr[address] = value & 0xFF; addr[address+1] = value >> 8; - if ((r & 8) == 8) { - addr[address+2] = value >> 16; - addr[address+3] = value >> 24; - addr[address+4] = value >> 32; - addr[address+5] = value >> 40; - addr[address+6] = value >> 48; - addr[address+7] = value >> 56; - address+=8; - } else { - address+=2; + switch ((r & 0x0C) >> 2) { + case 3: + addr[address+7] = value >> 56; + address += 1; + case 2: + addr[address+6] = (uint64_t)value >> 48; + addr[address+5] = (uint64_t)value >> 40; + address += 2; + case 1: + addr[address+4] = (uint64_t)value >> 32; + addr[address+3] = value >> 24; + addr[address+2] = value >> 16; + address += 3; } + address += 2; break; } else { fprintf(stderr, "oof, %s cannot be an absolute dictator.\n", op.mnemonic); @@ -1016,14 +1188,20 @@ int asmmon(const char *fn) { if (op.ind) { addr[address++] = op.ind; addr[address] = value & 0xFF; - if ((r & 8) == 8) { - addr[address+1] = value >> 8; - addr[address+2] = value >> 16; - addr[address+3] = value >> 24; - address+=4; - } else { - address+=1; + switch ((r & 0x0C) >> 2) { + case 2: + addr[address+5] = (uint64_t)value >> 40; + addr[address+4] = (uint64_t)value >> 32; + address += 2; + case 3: + addr[address+3] = value >> 24; + address += 1; + case 1: + addr[address+2] = value >> 16; + addr[address+1] = value >> 8; + address += 2; } + address += 1; break; } else { fprintf(stderr, "oof, %s cannot use pointers.\n", op.mnemonic); @@ -1033,14 +1211,20 @@ int asmmon(const char *fn) { if (op.inx) { addr[address++] = op.inx; addr[address] = value & 0xFF; - if ((r & 8) == 8) { - addr[address+1] = value >> 8; - addr[address+2] = value >> 16; - addr[address+3] = value >> 24; - address+=4; - } else { - address+=1; + switch ((r & 0x0C) >> 2) { + case 2: + addr[address+5] = (uint64_t)value >> 40; + addr[address+4] = (uint64_t)value >> 32; + address += 2; + case 3: + addr[address+3] = value >> 24; + address += 1; + case 1: + addr[address+2] = value >> 16; + addr[address+1] = value >> 8; + address += 2; } + address += 1; break; } else { fprintf(stderr, "oof, %s does not use Indexed Indirect.\n", op.mnemonic); @@ -1050,14 +1234,20 @@ int asmmon(const char *fn) { if (op.iny) { addr[address++] = op.iny; addr[address] = value & 0xFF; - if ((r & 8) == 8) { - addr[address+1] = value >> 8; - addr[address+2] = value >> 16; - addr[address+3] = value >> 24; - address+=4; - } else { - address+=1; + switch ((r & 0x0C) >> 2) { + case 2: + addr[address+5] = (uint64_t)value >> 40; + addr[address+4] = (uint64_t)value >> 32; + address += 2; + case 3: + addr[address+3] = value >> 24; + address += 1; + case 1: + addr[address+2] = value >> 16; + addr[address+1] = value >> 8; + address += 2; } + address += 1; break; } else { fprintf(stderr, "oof, %s does not use Indirect Indexed.\n", op.mnemonic); @@ -1067,6 +1257,7 @@ int asmmon(const char *fn) { #if debug if (!(done & 6)) { printf("instruction: %s, ", ins); + printf("addrmode: %s, ", adrmode[addrmode]); #if (!__GLIBC__) || (__TINYC__) printf("Postfix: %s, ", (postfix != NULL) ? postfix : "none"); #else |