From 0a9a1e5d4cb30725fe7144f9a09ff9b0b6bd8560 Mon Sep 17 00:00:00 2001 From: Adrian Conlon <98398945+AdrianConlon@users.noreply.github.com> Date: Sun, 7 Jan 2024 16:20:58 +0000 Subject: [PATCH] Complete all the undocumente M6502 features. Hurrah! --- M6502/inc/mos6502.h | 12 ++++++++++++ M6502/src/mos6502.cpp | 15 +++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 9ac11ba..876a795 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -174,6 +174,12 @@ namespace EightBit { BUS().ADDRESS() = address; } + void maybe_fixup(const register16_t address, const uint8_t unfixed_page) noexcept { + if (address.high != unfixed_page) + fixup(address, unfixed_page); + } + + // Status flag operations constexpr void set_flag(int which, int condition) noexcept { P() = setBit(P(), which, condition); } @@ -306,6 +312,12 @@ namespace EightBit { void sha_AbsoluteY() noexcept; void sha_IndirectIndexedY() noexcept; + // TAS + void tas_AbsoluteY() noexcept; + + // LAS + void las_AbsoluteY() noexcept; + // SYA void sya_AbsoluteX() noexcept; diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 98ab8c5..2140faa 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -292,7 +292,7 @@ int EightBit::MOS6502::execute() noexcept { case 0x98: swallow(); A() = through(Y()); break; // TYA (implied) case 0x99: sta_AbsoluteY(); break; // STA (absolute, Y) case 0x9a: swallow(); S() = X(); break; // TXS (implied) - case 0x9b: break; + case 0x9b: tas_AbsoluteY(); break; // *TAS (absolute, Y) case 0x9c: sya_AbsoluteX(); break; // *SYA (absolute, X) case 0x9d: sta_AbsoluteX(); break; // STA (absolute, X) case 0x9e: sxa_AbsoluteY(); break; // *SXA (absolute, Y) @@ -325,7 +325,7 @@ int EightBit::MOS6502::execute() noexcept { case 0xb8: swallow(); reset_flag(VF); break; // CLV (implied) case 0xb9: A() = through(AM_AbsoluteY()); break; // LDA (absolute, Y) case 0xba: swallow(); X() = through(S()); break; // TSX (implied) - case 0xbb: break; + case 0xbb: las_AbsoluteY(); break; // *LAS (absolute, Y) case 0xbc: Y() = through(AM_AbsoluteX()); break; // LDY (absolute, X) case 0xbd: A() = through(AM_AbsoluteX()); break; // LDA (absolute, X) case 0xbe: X() = through(AM_AbsoluteY()); break; // LDX (absolute, Y) @@ -891,6 +891,17 @@ void EightBit::MOS6502::sya_AbsoluteX() noexcept { memoryWrite(Y() & (address.high + 1)); } +void EightBit::MOS6502::tas_AbsoluteY() noexcept { + S() = A() & X(); + sha_AbsoluteY(); +} + +void EightBit::MOS6502::las_AbsoluteY() noexcept { + const auto [address, page] = Address_AbsoluteY(); + maybe_fixup(address, page); + A() = X() = S() = through(memoryRead(address) & S()); +} + void EightBit::MOS6502::sxa_AbsoluteY() noexcept { const auto [address, page] = Address_AbsoluteY(); fixup(address, page);