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;
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;
};
}

View File

@ -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
}