Simplify stack actions

This commit is contained in:
Adrian Conlon 2024-03-20 10:29:20 +00:00
parent ad1ab61f74
commit 0a6ab11fbb
2 changed files with 12 additions and 22 deletions

View File

@ -84,24 +84,15 @@ namespace EightBit {
void interrupt() noexcept; void interrupt() noexcept;
constexpr void setStackAddress(uint8_t position) noexcept { constexpr void updateStack(uint8_t position) noexcept { BUS().ADDRESS() = { position, 1 }; }
BUS().ADDRESS() = { position, 1 }; constexpr void lowerStack() noexcept { updateStack(S()--); }
} constexpr void raiseStack() noexcept { updateStack(++S()); }
constexpr void pushDownStackAddress(uint8_t value) noexcept {
BUS().DATA() = value;
setStackAddress(S()--);
}
constexpr void popUpStackAddress() noexcept {
setStackAddress(++S());
}
void push(uint8_t value) noexcept final; void push(uint8_t value) noexcept final;
[[nodiscard]] uint8_t pop() noexcept final; [[nodiscard]] uint8_t pop() noexcept final;
// Dummy stack push, used during RESET // Dummy stack push, used during RESET
void dummyPush(uint8_t value) noexcept; void dummyPush() noexcept;
// Addressing modes // Addressing modes
@ -282,7 +273,6 @@ namespace EightBit {
bool m_handlingNMI = false; bool m_handlingNMI = false;
bool m_handlingINT = false; bool m_handlingINT = false;
//uint8_t m_unfixed_page = 0;
uint8_t m_fixed_page = 0; uint8_t m_fixed_page = 0;
}; };
} }

View File

@ -94,9 +94,9 @@ void EightBit::MOS6502::interrupt() noexcept {
const bool reset = m_handlingRESET; const bool reset = m_handlingRESET;
const bool nmi = m_handlingNMI; const bool nmi = m_handlingNMI;
if (reset) { if (reset) {
dummyPush(PC().high); dummyPush();
dummyPush(PC().low); dummyPush();
dummyPush(P()); dummyPush();
} else { } else {
const bool irq = m_handlingINT; const bool irq = m_handlingINT;
const bool hardware = nmi || irq || reset; const bool hardware = nmi || irq || reset;
@ -407,17 +407,17 @@ void EightBit::MOS6502::execute() noexcept {
//// ////
void EightBit::MOS6502::push(uint8_t value) noexcept { void EightBit::MOS6502::push(uint8_t value) noexcept {
pushDownStackAddress(value); lowerStack();
memoryWrite(); memoryWrite(value);
} }
uint8_t EightBit::MOS6502::pop() noexcept { uint8_t EightBit::MOS6502::pop() noexcept {
popUpStackAddress(); raiseStack();
return memoryRead(); return memoryRead();
} }
void EightBit::MOS6502::dummyPush(uint8_t value) noexcept { void EightBit::MOS6502::dummyPush() noexcept {
pushDownStackAddress(value); lowerStack();
tick(); // In place of the memory write tick(); // In place of the memory write
} }