diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index 711a529..13d7214 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -38,21 +38,10 @@ namespace EightBit { const std::array& getInstructions() const { return instructions; } - register16_t& AF() { return af; } - uint8_t& A() { return AF().high; } - uint8_t& F() { return AF().low; } - - register16_t& BC() { return bc; } - uint8_t& B() { return BC().high; } - uint8_t& C() { return BC().low; } - - register16_t& DE() { return de; } - uint8_t& D() { return DE().high; } - uint8_t& E() { return DE().low; } - - register16_t& HL() { return hl; } - uint8_t& H() { return HL().high; } - uint8_t& L() { return HL().low; } + virtual register16_t& AF() override { return af; } + virtual register16_t& BC() override { return bc; } + virtual register16_t& DE() override { return de; } + virtual register16_t& HL() override { return hl; } bool isInterruptable() const { return m_interrupt; @@ -81,17 +70,6 @@ namespace EightBit { bool m_interrupt; - void clearFlag(int flag) { F() &= ~flag; } - void setFlag(int flag) { F() |= flag; } - - void setFlag(int flag, int condition) { setFlag(flag, condition != 0); } - void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); } - void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); } - - void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); } - void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); } - void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); } - int execute(uint8_t opcode); int execute(const Instruction& instruction) { diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 262a53f..353d6cb 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -36,35 +36,23 @@ namespace EightBit { // Mutable access to processor!! - register16_t& AF() { + virtual register16_t& AF() override { m_accumulatorFlag.low &= 0xf0; return m_accumulatorFlag; } - uint8_t& A() { return AF().high; } - uint8_t& F() { return AF().low; } - - register16_t& BC() { + virtual register16_t& BC() override { return m_registers[BC_IDX]; } - uint8_t& B() { return BC().high; } - uint8_t& C() { return BC().low; } - - register16_t& DE() { + virtual register16_t& DE() override { return m_registers[DE_IDX]; } - uint8_t& D() { return DE().high; } - uint8_t& E() { return DE().low; } - - register16_t& HL() { + virtual register16_t& HL() override { return m_registers[HL_IDX]; } - uint8_t& H() { return HL().high; } - uint8_t& L() { return HL().low; } - virtual void reset(); virtual void initialise(); @@ -87,17 +75,6 @@ namespace EightBit { return execute(fetchByte()); } - void clearFlag(int flag) { F() &= ~flag; } - void setFlag(int flag) { F() |= flag; } - - void setFlag(int flag, int condition) { setFlag(flag, condition != 0); } - void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); } - void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); } - - void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); } - void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); } - void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); } - uint8_t& R(int r) { switch (r) { case 0: diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index 9c5355f..4be69ba 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -41,34 +41,22 @@ namespace EightBit { // Mutable access to processor!! - register16_t& AF() { + virtual register16_t& AF() override { return m_accumulatorFlags[m_accumulatorFlagsSet]; } - uint8_t& A() { return AF().high; } - uint8_t& F() { return AF().low; } - - register16_t& BC() { + virtual register16_t& BC() override { return m_registers[m_registerSet][BC_IDX]; } - uint8_t& B() { return BC().high; } - uint8_t& C() { return BC().low; } - - register16_t& DE() { + virtual register16_t& DE() override { return m_registers[m_registerSet][DE_IDX]; } - uint8_t& D() { return DE().high; } - uint8_t& E() { return DE().low; } - - register16_t& HL() { + virtual register16_t& HL() override { return m_registers[m_registerSet][HL_IDX]; } - uint8_t& H() { return HL().high; } - uint8_t& L() { return HL().low; } - register16_t& IX() { return m_ix; } uint8_t& IXH() { return IX().high; } uint8_t& IXL() { return IX().low; } @@ -136,17 +124,6 @@ namespace EightBit { REFRESH() = (REFRESH() & Bit7) | incremented; } - void clearFlag(int flag) { F() &= ~flag; } - void setFlag(int flag) { F() |= flag; } - - void setFlag(int flag, int condition) { setFlag(flag, condition != 0); } - void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); } - void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); } - - void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); } - void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); } - void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); } - uint8_t& DISPLACED() { m_memory.ADDRESS().word = MEMPTR().word = (m_prefixDD ? IX() : IY()).word + m_displacement; return m_memory.reference(); diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index 46e0756..fe7c97d 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -10,9 +10,36 @@ namespace EightBit { virtual void initialise(); + virtual register16_t& AF() = 0; + uint8_t& A() { return AF().high; } + uint8_t& F() { return AF().low; } + + virtual register16_t& BC() = 0; + uint8_t& B() { return BC().high; } + uint8_t& C() { return BC().low; } + + virtual register16_t& DE() = 0; + uint8_t& D() { return DE().high; } + uint8_t& E() { return DE().low; } + + virtual register16_t& HL() = 0; + uint8_t& H() { return HL().high; } + uint8_t& L() { return HL().low; } + protected: IntelProcessor(Memory& memory); + void clearFlag(int flag) { F() &= ~flag; } + void setFlag(int flag) { F() |= flag; } + + void setFlag(int flag, int condition) { setFlag(flag, condition != 0); } + void setFlag(int flag, uint32_t condition) { setFlag(flag, condition != 0); } + void setFlag(int flag, bool condition) { condition ? setFlag(flag) : clearFlag(flag); } + + void clearFlag(int flag, int condition) { clearFlag(flag, condition != 0); } + void clearFlag(int flag, uint32_t condition) { clearFlag(flag, condition != 0); } + void clearFlag(int flag, bool condition) { condition ? clearFlag(flag) : setFlag(flag); } + std::array m_halfCarryTableAdd = { { false, false, true, false, true, false, true, true } }; std::array m_halfCarryTableSub = { { false, true, true, true, false, false, false, true } };