From cb89eb8c82dcf3f6816e2a7d8eb28521a10aa2df Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Thu, 4 Jan 2018 21:47:50 +0000 Subject: [PATCH] Add undocumented 6502 instruction: ISB Signed-off-by: Adrian Conlon --- M6502/inc/mos6502.h | 12 +++++++++--- M6502/src/Disassembly.cpp | 17 ++++++++++++++++- M6502/src/mos6502.cpp | 21 ++++++++++++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 05f60ed..4370132 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -572,9 +572,15 @@ namespace EightBit { } void DCP(int bbb) { - const auto result = AM_11_x(bbb) - 1; - setByte(result); - CMP(A(), result); + auto operand = AM_11_x(bbb); + setByte(--operand); + CMP(A(), operand); + } + + void ISB(int bbb) { + auto operand = AM_01(bbb); + setByte(++operand); + A() = SBC(A(), operand); } void ROR(uint8_t& output); diff --git a/M6502/src/Disassembly.cpp b/M6502/src/Disassembly.cpp index 5400b20..eaa9f7a 100644 --- a/M6502/src/Disassembly.cpp +++ b/M6502/src/Disassembly.cpp @@ -399,7 +399,22 @@ std::string EightBit::Disassembly::disassemble(uint16_t current) const { output << disassemble_AM_11_x(bbb, "*DCP"); break; case 0b111: - output << disassemble_AM_11(bbb, "*SBC"); + switch (bbb) { + case 0b000: // *ISB + case 0b001: + case 0b011: + case 0b100: + case 0b101: + case 0b110: + case 0b111: + output << disassemble_AM_01(bbb, "*ISB"); + break; + case 0b010: + output << disassemble_AM_11(bbb, "*SBC"); + break; + default: + UNREACHABLE; + } break; default: throw std::domain_error("Illegal instruction group"); diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 6fd18af..760c23d 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -19,8 +19,8 @@ EightBit::MOS6502::MOS6502(Bus& bus) /* B */ 2, 5, 0, 5, 4, 4, 4, 4, 2, 4, 2, 0, 4, 4, 4, 4, /* C */ 2, 6, 0, 8, 3, 3, 5, 5, 2, 2, 2, 0, 4, 4, 6, 6, /* D */ 2, 5, 0, 7, 4, 4, 6, 6, 2, 4, 2, 6, 4, 4, 7, 6, - /* E */ 2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 2, 4, 4, 6, 0, - /* F */ 2, 5, 0, 0, 4, 4, 6, 0, 2, 4, 2, 0, 4, 4, 7, 0, + /* E */ 2, 6, 0, 8, 3, 3, 5, 5, 2, 2, 2, 2, 4, 4, 6, 6, + /* F */ 2, 5, 0, 7, 4, 4, 6, 6, 2, 4, 2, 6, 4, 4, 7, 6, }; @@ -421,7 +421,22 @@ int EightBit::MOS6502::execute(uint8_t cell) { DCP(decoded.bbb); break; case 0b111: // *SBC - A() = SBC(A(), AM_11(decoded.bbb)); + switch (decoded.bbb) { + case 0b000: // *ISB + case 0b001: + case 0b011: + case 0b100: + case 0b101: + case 0b110: + case 0b111: + ISB(decoded.bbb); + break; + case 0b010: + A() = SBC(A(), AM_11(decoded.bbb)); + break; + default: + UNREACHABLE; + } break; default: throw std::domain_error("Illegal instruction group");