From 93088b355c4dc54160a308e8c35318e91fef6c5c Mon Sep 17 00:00:00 2001 From: Adrian Conlon <98398945+AdrianConlon@users.noreply.github.com> Date: Sun, 31 Dec 2023 14:58:15 +0000 Subject: [PATCH] M6502: Unify accumulator write page boundary fixup code --- M6502/inc/mos6502.h | 5 +++++ M6502/src/mos6502.cpp | 15 ++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index cec6105..5c8737c 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -190,6 +190,11 @@ namespace EightBit { void sta_AbsoluteY() noexcept; void sta_IndirectIndexedY() noexcept; + void write_A_with_fixup(const register16_t& address, uint8_t unfixed_page) noexcept { + getBytePaged(unfixed_page, address.low); // Possible fixup for page boundary crossing + memoryWrite(address, A()); + } + uint8_t x = 0; // index register X uint8_t y = 0; // index register Y uint8_t a = 0; // accumulator diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index b520650..c53947a 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -73,14 +73,14 @@ void EightBit::MOS6502::handleINT() noexcept { void EightBit::MOS6502::interrupt() noexcept { const bool reset = m_handlingRESET; const bool nmi = m_handlingNMI; - const bool irq = m_handlingINT; - const bool hardware = nmi || irq || reset; - const bool software = !hardware; if (reset) { dummyPush(PC().high); dummyPush(PC().low); dummyPush(P()); } else { + const bool irq = m_handlingINT; + const bool hardware = nmi || irq || reset; + const bool software = !hardware; pushWord(PC()); push(P() | (software ? BF : 0)); } @@ -748,18 +748,15 @@ void EightBit::MOS6502::sre(const uint8_t value) noexcept { void EightBit::MOS6502::sta_AbsoluteX() noexcept { const auto [address, page] = Address_AbsoluteX(); - getBytePaged(page, address.low); - memoryWrite(address, A()); + write_A_with_fixup(address, page); } void EightBit::MOS6502::sta_AbsoluteY() noexcept { const auto [address, page] = Address_AbsoluteY(); - getBytePaged(page, address.low); - memoryWrite(address, A()); + write_A_with_fixup(address, page); } void EightBit::MOS6502::sta_IndirectIndexedY() noexcept { const auto [address, page] = Address_IndirectIndexedY(); - getBytePaged(page, address.low); // Possible fixup for page boundary crossing - memoryWrite(address, A()); + write_A_with_fixup(address, page); }