diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index f34cca5..989e418 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -274,9 +274,9 @@ namespace EightBit { m_memory.reference() = data; } - void lxi_b() { Processor::fetchWord(BC()); } - void lxi_d() { Processor::fetchWord(DE()); } - void lxi_h() { Processor::fetchWord(HL()); } + void lxi_b() { fetchWord(BC()); } + void lxi_d() { fetchWord(DE()); } + void lxi_h() { fetchWord(HL()); } void stax_r(register16_t& destination) { m_memory.ADDRESS() = destination; @@ -350,7 +350,7 @@ namespace EightBit { } void lxi_sp() { - Processor::fetchWord(SP()); + fetchWord(SP()); } void inx_sp() { ++SP().word; } diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 8b8f4a2..7ebe9c8 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -524,7 +524,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) { case 1: // 16-bit load immediate/add switch (q) { case 0: // LD rp,nn - Processor::fetchWord(RP(p)); + fetchWord(RP(p)); cycles += 3; break; case 1: // ADD HL,rp diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 9823b54..7224bf4 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -1160,7 +1160,7 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) { case 1: // 16-bit load immediate/add switch (q) { case 0: // LD rp,nn - Processor::fetchWord(RP(p)); + fetchWord(RP(p)); cycles += 10; break; case 1: // ADD HL,rp diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index 67a1538..aa4805d 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -13,6 +13,8 @@ namespace EightBit { virtual void initialise(); + register16_t& SP() { return sp; } + virtual register16_t& AF() = 0; uint8_t& A() { return AF().high; } uint8_t& F() { return AF().low; } @@ -105,6 +107,16 @@ namespace EightBit { return m_halfCarryTableSub[index & Mask3]; } + uint8_t fetchByte() { + m_memory.ADDRESS().word = PC().word++; + return m_memory.reference(); + } + + void fetchWord(register16_t& output) { + output.low = fetchByte(); + output.high = fetchByte(); + } + void push(uint8_t value) { m_memory.ADDRESS().word = --SP().word; m_memory.reference() = value; @@ -126,7 +138,7 @@ namespace EightBit { } void fetchWord() { - Processor::fetchWord(MEMPTR()); + fetchWord(MEMPTR()); } // @@ -205,5 +217,6 @@ namespace EightBit { private: register16_t m_memptr; + register16_t sp; }; } \ No newline at end of file diff --git a/inc/Processor.h b/inc/Processor.h index 7c1da28..8113c21 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -47,7 +47,6 @@ namespace EightBit { const Memory& getMemory() const { return m_memory; } register16_t& PC() { return pc; } - register16_t& SP() { return sp; } bool isHalted() const { return m_halted; } void halt() { --PC().word; m_halted = true; } @@ -62,19 +61,8 @@ namespace EightBit { Memory& m_memory; int cycles; - uint8_t fetchByte() { - m_memory.ADDRESS().word = PC().word++; - return m_memory.reference(); - } - - void fetchWord(register16_t& output) { - output.low = fetchByte(); - output.high = fetchByte(); - } - private: register16_t pc; - register16_t sp; bool m_halted; }; } \ No newline at end of file diff --git a/src/IntelProcessor.cpp b/src/IntelProcessor.cpp index 5f89687..042bffc 100644 --- a/src/IntelProcessor.cpp +++ b/src/IntelProcessor.cpp @@ -4,9 +4,11 @@ EightBit::IntelProcessor::IntelProcessor(Memory& memory) : Processor(memory) { MEMPTR().word = 0; + SP().word = 0xffff; } void EightBit::IntelProcessor::initialise() { Processor::initialise(); MEMPTR().word = 0; + SP().word = 0xffff; } diff --git a/src/Processor.cpp b/src/Processor.cpp index 5a177c6..19d952d 100644 --- a/src/Processor.cpp +++ b/src/Processor.cpp @@ -5,7 +5,6 @@ EightBit::Processor::Processor(Memory& memory) : m_memory(memory), cycles(0), m_halted(false) { - SP().word = 0xffff; PC().word = 0; } @@ -14,6 +13,5 @@ void EightBit::Processor::reset() { } void EightBit::Processor::initialise() { - SP().word = 0xffff; reset(); }