diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index b93bbe0..c7d7bb9 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -84,24 +84,15 @@ namespace EightBit { void interrupt() noexcept; - constexpr void setStackAddress(uint8_t position) noexcept { - BUS().ADDRESS() = { position, 1 }; - } - - constexpr void pushDownStackAddress(uint8_t value) noexcept { - BUS().DATA() = value; - setStackAddress(S()--); - } - - constexpr void popUpStackAddress() noexcept { - setStackAddress(++S()); - } + constexpr void updateStack(uint8_t position) noexcept { BUS().ADDRESS() = { position, 1 }; } + constexpr void lowerStack() noexcept { updateStack(S()--); } + constexpr void raiseStack() noexcept { updateStack(++S()); } void push(uint8_t value) noexcept final; [[nodiscard]] uint8_t pop() noexcept final; // Dummy stack push, used during RESET - void dummyPush(uint8_t value) noexcept; + void dummyPush() noexcept; // Addressing modes @@ -282,7 +273,6 @@ namespace EightBit { bool m_handlingNMI = false; bool m_handlingINT = false; - //uint8_t m_unfixed_page = 0; uint8_t m_fixed_page = 0; }; } \ No newline at end of file diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 75cab5a..a953e53 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -94,9 +94,9 @@ void EightBit::MOS6502::interrupt() noexcept { const bool reset = m_handlingRESET; const bool nmi = m_handlingNMI; if (reset) { - dummyPush(PC().high); - dummyPush(PC().low); - dummyPush(P()); + dummyPush(); + dummyPush(); + dummyPush(); } else { const bool irq = m_handlingINT; const bool hardware = nmi || irq || reset; @@ -407,17 +407,17 @@ void EightBit::MOS6502::execute() noexcept { //// void EightBit::MOS6502::push(uint8_t value) noexcept { - pushDownStackAddress(value); - memoryWrite(); + lowerStack(); + memoryWrite(value); } uint8_t EightBit::MOS6502::pop() noexcept { - popUpStackAddress(); + raiseStack(); return memoryRead(); } -void EightBit::MOS6502::dummyPush(uint8_t value) noexcept { - pushDownStackAddress(value); +void EightBit::MOS6502::dummyPush() noexcept { + lowerStack(); tick(); // In place of the memory write }