From 9a264c7c06fb0edf81aa447e047d5c79c04ed5cc Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Sat, 22 Jul 2017 10:23:13 +0100 Subject: [PATCH] Bring the LR35902 and i8080 increment/decrement implementations in line with the Z80. Signed-off-by: Adrian.Conlon --- Intel8080/inc/Intel8080.h | 48 ++++++++++++++++++--------------------- LR35902/inc/LR35902.h | 4 ++-- LR35902/src/LR35902.cpp | 16 ++++++------- 3 files changed, 32 insertions(+), 36 deletions(-) diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index 14ca744..5a78849 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -90,14 +90,14 @@ namespace EightBit { clearFlag(f, AC, calculateHalfCarrySub(before, value, calculation)); } - static void postIncrement(uint8_t& f, uint8_t value) { - adjustSZP(f, value); - clearFlag(f, AC, lowNibble(value)); + static void increment(uint8_t& f, uint8_t& operand) { + adjustSZP(f, ++operand); + clearFlag(f, AC, lowNibble(operand)); } - static void postDecrement(uint8_t& f, uint8_t value) { - adjustSZP(f, value); - setFlag(f, AC, lowNibble(value) != Mask4); + static void decrement(uint8_t& f, uint8_t& operand) { + adjustSZP(f, --operand); + setFlag(f, AC, lowNibble(operand) != Mask4); } static Instruction INS(instruction_t method, AddressingMode mode, std::string disassembly, int cycles); @@ -420,34 +420,30 @@ namespace EightBit { // increment and decrement - void inr_a() { postIncrement(F(), ++A()); } - void inr_b() { postIncrement(F(), ++B()); } - void inr_c() { postIncrement(F(), ++C()); } - void inr_d() { postIncrement(F(), ++D()); } - void inr_e() { postIncrement(F(), ++E()); } - void inr_h() { postIncrement(F(), ++H()); } - void inr_l() { postIncrement(F(), ++L()); } + void inr_a() { increment(F(), A()); } + void inr_b() { increment(F(), B()); } + void inr_c() { increment(F(), C()); } + void inr_d() { increment(F(), D()); } + void inr_e() { increment(F(), E()); } + void inr_h() { increment(F(), H()); } + void inr_l() { increment(F(), L()); } void inr_m() { m_memory.ADDRESS() = HL(); - auto value = m_memory.reference(); - postIncrement(F(), ++value); - m_memory.reference() = value; + increment(F(), m_memory.reference()); } - void dcr_a() { postDecrement(F(), --A()); } - void dcr_b() { postDecrement(F(), --B()); } - void dcr_c() { postDecrement(F(), --C()); } - void dcr_d() { postDecrement(F(), --D()); } - void dcr_e() { postDecrement(F(), --E()); } - void dcr_h() { postDecrement(F(), --H()); } - void dcr_l() { postDecrement(F(), --L()); } + void dcr_a() { decrement(F(), A()); } + void dcr_b() { decrement(F(), B()); } + void dcr_c() { decrement(F(), C()); } + void dcr_d() { decrement(F(), D()); } + void dcr_e() { decrement(F(), E()); } + void dcr_h() { decrement(F(), H()); } + void dcr_l() { decrement(F(), L()); } void dcr_m() { m_memory.ADDRESS() = HL(); - auto value = m_memory.reference(); - postDecrement(F(), --value); - m_memory.reference() = value; + decrement(F(), m_memory.reference()); } void inx_b() { ++BC().word; } diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index d08640c..9352131 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -162,8 +162,8 @@ namespace EightBit { void executeCB(int x, int y, int z, int p, int q); void executeOther(int x, int y, int z, int p, int q); - static void postIncrement(uint8_t& f, uint8_t value); - static void postDecrement(uint8_t& f, uint8_t value); + static void increment(uint8_t& f, uint8_t& operand); + static void decrement(uint8_t& f, uint8_t& operand); void reti(); diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 2222787..c3fc23c 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -51,16 +51,16 @@ int EightBit::LR35902::interrupt(uint8_t value) { #pragma region Flag manipulation helpers -void EightBit::LR35902::postIncrement(uint8_t& f, uint8_t value) { - adjustZero(f, value); +void EightBit::LR35902::increment(uint8_t& f, uint8_t& operand) { clearFlag(f, NF); - clearFlag(f, HC, lowNibble(value)); + adjustZero(f, ++operand); + clearFlag(f, HC, lowNibble(operand)); } -void EightBit::LR35902::postDecrement(uint8_t& f, uint8_t value) { - adjustZero(f, value); +void EightBit::LR35902::decrement(uint8_t& f, uint8_t& operand) { setFlag(f, NF); - clearFlag(f, HC, lowNibble(value + 1)); + clearFlag(f, HC, lowNibble(operand)); + adjustZero(f, --operand); } #pragma endregion Flag manipulation helpers @@ -573,7 +573,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) { cycles += 2; break; case 4: // 8-bit INC - postIncrement(f, ++R(y, a)); // INC r + increment(f, R(y, a)); // INC r cycles++; if (y == 6) { m_bus.fireWriteBusEvent(); @@ -581,7 +581,7 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) { } break; case 5: // 8-bit DEC - postDecrement(f, --R(y, a)); // DEC r + decrement(f, R(y, a)); // DEC r cycles++; if (y == 6) { m_bus.fireWriteBusEvent();