From 75aece30e34a2f86eee2e2540275b324749c236f Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 1 Jan 2018 12:28:00 +0000 Subject: [PATCH] Undocumented instruction: LAX added. Signed-off-by: Adrian Conlon --- M6502/inc/Disassembly.h | 50 +++++++++++++++++++++++++++++++++++++++ M6502/inc/mos6502.h | 24 +++++++++++++++++++ M6502/src/Disassembly.cpp | 9 ++++++- M6502/src/mos6502.cpp | 13 +++++++--- 4 files changed, 92 insertions(+), 4 deletions(-) diff --git a/M6502/inc/Disassembly.h b/M6502/inc/Disassembly.h index 070811c..a6a03e7 100644 --- a/M6502/inc/Disassembly.h +++ b/M6502/inc/Disassembly.h @@ -55,6 +55,10 @@ namespace EightBit { return AM_10_x_dump(bbb) + "\t" + instruction + " " + AM_10_x(bbb); } + std::string disassemble_AM_11(int bbb, const std::string& instruction) const { + return AM_11_dump(bbb) + "\t" + instruction + " " + AM_11(bbb); + } + std::string AM_Immediate_dump() const { return dump_Byte(m_address + 1); } @@ -303,6 +307,52 @@ namespace EightBit { } } + std::string AM_11_dump(int bbb) const { + switch (bbb) { + case 0b000: + return AM_IndexedIndirectX_dump(); + case 0b001: + return AM_ZeroPage_dump(); + case 0b010: + return AM_Immediate_dump(); + case 0b011: + return AM_Absolute_dump(); + case 0b100: + return AM_IndirectIndexedY_dump(); + case 0b101: + return AM_ZeroPageY_dump(); + case 0b110: + throw std::domain_error("Illegal addressing mode"); + case 0b111: + return AM_AbsoluteY_dump(); + default: + UNREACHABLE; + } + } + + std::string AM_11(int bbb) const { + switch (bbb) { + case 0b000: + return AM_IndexedIndirectX(); + case 0b001: + return AM_ZeroPage(); + case 0b010: + return AM_Immediate(); + case 0b011: + return AM_Absolute(); + case 0b100: + return AM_IndirectIndexedY(); + case 0b101: + return AM_ZeroPageY(); + case 0b110: + throw std::domain_error("Illegal addressing mode"); + case 0b111: + return AM_AbsoluteY(); + default: + UNREACHABLE; + } + } + static void dump(std::ostream& out, int value, int width); uint8_t getByte(uint16_t address) const; diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index bbe308e..53252bc 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -432,6 +432,30 @@ namespace EightBit { } } + uint8_t AM_11(int bbb) { + switch (bbb) { + case 0b000: + return AM_IndexedIndirectX(); + case 0b001: + return AM_ZeroPage(); + case 0b010: + return AM_Immediate(); + case 0b011: + return AM_Absolute(); + case 0b100: + return AM_IndirectIndexedY(); + case 0b101: + return AM_ZeroPageY(); + case 0b110: + assert(false); + break; + case 0b111: + return AM_AbsoluteY(); + default: + UNREACHABLE; + } + } + // Operations void ASL(int bbb) { diff --git a/M6502/src/Disassembly.cpp b/M6502/src/Disassembly.cpp index dc3642d..81d24c3 100644 --- a/M6502/src/Disassembly.cpp +++ b/M6502/src/Disassembly.cpp @@ -388,7 +388,14 @@ std::string EightBit::Disassembly::disassemble(uint16_t current) const { } break; case 0b11: - throw std::domain_error("Illegal instruction group"); + switch (aaa) { + case 0b101: + output << disassemble_AM_11(bbb, "*LAX"); + break; + default: + throw std::domain_error("Illegal instruction group"); + } + break; default: UNREACHABLE; } diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 158cfb2..c3a38af 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -15,8 +15,8 @@ EightBit::MOS6502::MOS6502(Bus& bus) /* 7 */ 2, 5, 0, 0, 4, 4, 6, 0, 2, 4, 2, 0, 4, 4, 7, 0, /* 8 */ 2, 6, 0, 0, 3, 3, 3, 0, 2, 0, 2, 0, 4, 4, 4, 0, /* 9 */ 2, 6, 0, 0, 4, 4, 4, 0, 2, 5, 2, 0, 0, 5, 0, 0, - /* A */ 2, 6, 2, 0, 3, 3, 3, 0, 2, 2, 2, 0, 4, 4, 4, 0, - /* B */ 2, 5, 0, 0, 4, 4, 4, 0, 2, 4, 2, 0, 4, 4, 4, 0, + /* A */ 2, 6, 2, 6, 3, 3, 3, 3, 2, 2, 2, 0, 4, 4, 4, 4, + /* B */ 2, 5, 0, 5, 4, 4, 4, 4, 2, 4, 2, 0, 4, 4, 4, 4, /* C */ 2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0, /* D */ 2, 5, 0, 0, 4, 4, 6, 0, 2, 4, 2, 0, 4, 4, 7, 0, /* E */ 2, 6, 0, 0, 3, 3, 5, 0, 2, 2, 2, 0, 4, 4, 6, 0, @@ -410,7 +410,14 @@ int EightBit::MOS6502::execute(uint8_t cell) { } break; case 0b11: - throw std::domain_error("Illegal instruction group"); + switch (decoded.aaa) { + case 0b101: + adjustNZ(X() = A() = AM_11(decoded.bbb)); + break; + default: + throw std::domain_error("Illegal instruction group"); + } + break; default: UNREACHABLE; }