diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index b0208ca..afe81e2 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -36,8 +36,6 @@ namespace EightBit { virtual register16_t& DE() override { return de; } virtual register16_t& HL() override { return hl; } - virtual void initialise(); - private: InputOutput& m_ports; diff --git a/Intel8080/src/Intel8080.cpp b/Intel8080/src/Intel8080.cpp index 5341558..069b862 100644 --- a/Intel8080/src/Intel8080.cpp +++ b/Intel8080/src/Intel8080.cpp @@ -7,12 +7,7 @@ EightBit::Intel8080::Intel8080(Memory& memory, InputOutput& ports) : IntelProcessor(memory), m_interrupt(false), m_ports(ports) { - bc.word = de.word = hl.word = 0; -} - -void EightBit::Intel8080::initialise() { - IntelProcessor::initialise(); - AF().word = BC().word = DE().word = HL().word = 0; + bc.word = de.word = hl.word = Mask16; } #pragma endregion Reset and initialisation diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 81e5cce..093a6c7 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -30,8 +30,7 @@ namespace EightBit { virtual register16_t& DE() override { return de; } virtual register16_t& HL() override { return hl; } - virtual void reset(); - virtual void initialise(); + virtual void reset() override; static int framesPerSecond() { return 60; } static int cyclesPerFrame() { return cyclesPerSecond() / framesPerSecond(); } diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index fd728ad..c14b723 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -9,24 +9,14 @@ EightBit::LR35902::LR35902(Bus& memory) : IntelProcessor(memory), m_bus(memory), m_ime(false), + m_stopped(false), m_prefixCB(false) { } void EightBit::LR35902::reset() { IntelProcessor::reset(); - SP().word = Mask16 - 1; di(); -} - -void EightBit::LR35902::initialise() { - - IntelProcessor::initialise(); - - AF().word = Mask16; - BC().word = Mask16; - DE().word = Mask16; - HL().word = Mask16; - + SP().word = Mask16 - 1; m_prefixCB = false; } diff --git a/M6502/inc/mos6502.h b/M6502/inc/mos6502.h index 7a7819a..c962863 100644 --- a/M6502/inc/mos6502.h +++ b/M6502/inc/mos6502.h @@ -58,8 +58,8 @@ namespace EightBit { uint8_t& S() { return s; } uint8_t& P() { return p; } - virtual void initialise(); - virtual void reset(); + virtual void initialise() override; + virtual void reset() override; private: void adjustZero(uint8_t datum) { clearFlag(P(), ZF, datum); } diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index cac272e..7bbdc41 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -28,19 +28,14 @@ void EightBit::MOS6502::initialise() { Processor::initialise(); - for (int i = 0; i < 0x100; ++i) { + for (int i = 0; i < 0x100; ++i) m_decodedOpcodes[i] = i; - } - - PC().word = 0; X() = Bit7; Y() = 0; A() = 0; P() = RF; S() = Mask8; - - MEMPTR().word = 0; } int EightBit::MOS6502::step() { diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index 37bc9cf..2658d5f 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -95,8 +95,7 @@ namespace EightBit { m_accumulatorFlagsSet = !m_accumulatorFlagsSet; } - virtual void reset(); - virtual void initialise(); + virtual void reset() override; protected: virtual int fetchExecute() override { diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 8fd1939..0c66b73 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -27,21 +27,14 @@ EightBit::Z80::Z80(Memory& memory, InputOutput& ports) } void EightBit::Z80::reset() { + IntelProcessor::reset(); + di(); -} - -void EightBit::Z80::initialise() { - - IntelProcessor::initialise(); - IM() = 0; - AF().word = 0xffff; - - BC().word = 0xffff; - DE().word = 0xffff; - HL().word = 0xffff; + REFRESH() = 0; + IV() = 0xff; exxAF(); exx(); @@ -55,13 +48,7 @@ void EightBit::Z80::initialise() { IX().word = 0xffff; IY().word = 0xffff; - REFRESH() = 0x7f; - IV() = 0xff; - - m_prefixCB = false; - m_prefixDD = false; - m_prefixED = false; - m_prefixFD = false; + m_prefixCB = m_prefixDD = m_prefixED = m_prefixFD = false; } #pragma endregion Reset and initialisation diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index d40af74..e33be19 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -34,7 +34,8 @@ namespace EightBit { return m_decodedOpcodes[i]; } - virtual void initialise(); + virtual void initialise() override; + virtual void reset() override; register16_t& SP() { return sp; } diff --git a/inc/Processor.h b/inc/Processor.h index 3d3f713..86fc0e3 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -66,8 +66,7 @@ namespace EightBit { void powerOff() { m_power = false; } virtual void initialise(); - - void reset(); + virtual void reset(); virtual int run(int limit); virtual int singleStep(); diff --git a/src/IntelProcessor.cpp b/src/IntelProcessor.cpp index d49abe6..005a81a 100644 --- a/src/IntelProcessor.cpp +++ b/src/IntelProcessor.cpp @@ -3,17 +3,17 @@ EightBit::IntelProcessor::IntelProcessor(Memory& memory) : Processor(memory) { - MEMPTR().word = 0; - SP().word = 0xffff; + SP().word = Mask16; } void EightBit::IntelProcessor::initialise() { Processor::initialise(); - for (int i = 0; i < 0x100; ++i) { m_decodedOpcodes[i] = i; } - - MEMPTR().word = 0; - SP().word = 0xffff; } + +void EightBit::IntelProcessor::reset() { + Processor::reset(); + SP().word = AF().word = BC().word = DE().word = HL().word = Mask16; +} \ No newline at end of file diff --git a/src/Processor.cpp b/src/Processor.cpp index a356f89..23b2a18 100644 --- a/src/Processor.cpp +++ b/src/Processor.cpp @@ -6,11 +6,11 @@ EightBit::Processor::Processor(Memory& memory) cycles(0), m_halted(false), m_power(false) { - PC().word = 0; + PC().word = MEMPTR().word = 0; } void EightBit::Processor::reset() { - PC().word = 0; + PC().word = MEMPTR().word = 0; } void EightBit::Processor::initialise() {