From 59e9adf57c53418da7b91074b95dff5c458fb203 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Mon, 28 Aug 2017 13:19:17 +0100 Subject: [PATCH] Share more of push/pop implementation across processors. Signed-off-by: Adrian.Conlon --- M6502/inc/mos6502.h | 6 ++---- M6502/src/mos6502.cpp | 25 +++++++------------------ inc/IntelProcessor.h | 10 ---------- inc/Processor.h | 13 +++++++++++++ 4 files changed, 22 insertions(+), 32 deletions(-) diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index fe48f73..180ac2a 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -87,10 +87,8 @@ namespace EightBit { adjustNegative(datum); } - void pushByte(uint8_t value); - uint8_t popByte(); - void pushWord(register16_t value); - void popWord(register16_t& output); + virtual void push(uint8_t value) override; + virtual uint8_t pop() override; #pragma region 6502 addressing modes diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index f5b906b..21e1ab4 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -80,7 +80,7 @@ void EightBit::MOS6502::getWord(uint16_t offset, register16_t& output) { void EightBit::MOS6502::interrupt(uint16_t vector) { pushWord(PC()); - pushByte(P()); + push(P()); setFlag(P(), IF); getWord(vector, PC()); } @@ -144,7 +144,7 @@ int EightBit::MOS6502::execute(uint8_t cell) { RTI(); break; case 0b010: // PHA - pushByte(A()); + push(A()); break; case 0b011: // JMP JMP_abs(); @@ -165,7 +165,7 @@ int EightBit::MOS6502::execute(uint8_t cell) { RTS(); break; case 0b010: // PLA - adjustNZ(A() = popByte()); + adjustNZ(A() = pop()); break; case 0b011: // JMP (abs) JMP_ind(); @@ -347,24 +347,14 @@ int EightBit::MOS6502::execute(uint8_t cell) { //// -void EightBit::MOS6502::pushByte(uint8_t value) { +void EightBit::MOS6502::push(uint8_t value) { setByte(PageOne + S()--, value); } -uint8_t EightBit::MOS6502::popByte() { +uint8_t EightBit::MOS6502::pop() { return getByte(PageOne + ++S()); } -void EightBit::MOS6502::pushWord(register16_t value) { - pushByte(value.high); - pushByte(value.low); -} - -void EightBit::MOS6502::popWord(register16_t& output) { - output.low = popByte(); - output.high = popByte(); -} - //// void EightBit::MOS6502::ROR(uint8_t& output) { @@ -508,12 +498,11 @@ void EightBit::MOS6502::Branch(bool flag) { void EightBit::MOS6502::PHP() { setFlag(P(), BF); - pushByte(P()); + push(P()); } void EightBit::MOS6502::PLP() { - P() = popByte(); - setFlag(P(), RF); + P() = pop() | RF; } // diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index a47153d..278f9fc 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -123,20 +123,10 @@ namespace EightBit { m_memory.write(--SP().word, value); } - void pushWord(const register16_t& value) { - push(value.high); - push(value.low); - } - virtual uint8_t pop() { return m_memory.read(SP().word++); } - void popWord(register16_t& output) { - output.low = pop(); - output.high = pop(); - } - void fetchWord() { Processor::fetchWord(MEMPTR()); } diff --git a/inc/Processor.h b/inc/Processor.h index 9dae3af..f6e44bf 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -88,6 +88,19 @@ namespace EightBit { return execute(fetchByte()); } + virtual void push(uint8_t value) = 0; + virtual uint8_t pop() = 0; + + void pushWord(const register16_t& value) { + push(value.high); + push(value.low); + } + + void popWord(register16_t& output) { + output.low = pop(); + output.high = pop(); + } + private: register16_t pc; bool m_halted;