From 19966f6ad8fe5f3cec8b2e994c629139dbfbfa52 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Sat, 22 Jul 2017 10:05:35 +0100 Subject: [PATCH] Z80 eight bit increment/decrement can be simplified a little Signed-off-by: Adrian.Conlon --- Z80/inc/Z80.h | 4 ++-- Z80/src/Z80.cpp | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index fe32944..8147247 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -264,8 +264,8 @@ namespace EightBit { void executeED(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 retn(); void reti(); diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index f855525..0a10bc8 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -108,18 +108,18 @@ int EightBit::Z80::interrupt(bool maskable, uint8_t value) { #pragma region Flag manipulation helpers -void EightBit::Z80::postIncrement(uint8_t& f, uint8_t value) { - adjustSZXY(f, value); +void EightBit::Z80::increment(uint8_t& f, uint8_t& operand) { clearFlag(f, NF); - setFlag(f, VF, value == Bit7); - clearFlag(f, HC, lowNibble(value)); + adjustSZXY(f, ++operand); + setFlag(f, VF, operand == Bit7); + clearFlag(f, HC, lowNibble(operand)); } -void EightBit::Z80::postDecrement(uint8_t& f, uint8_t value) { - adjustSZXY(f, value); +void EightBit::Z80::decrement(uint8_t& f, uint8_t& operand) { setFlag(f, NF); - setFlag(f, VF, value == Mask7); - clearFlag(f, HC, lowNibble(value + 1)); + clearFlag(f, HC, lowNibble(operand)); + adjustSZXY(f, --operand); + setFlag(f, VF, operand == Mask7); } #pragma endregion Flag manipulation helpers @@ -636,7 +636,7 @@ void EightBit::Z80::ini(uint8_t& f) { auto value = m_memory.DATA(); m_memory.ADDRESS().word = HL().word++; m_memory.reference() = value; - postDecrement(f, --B()); + decrement(f, B()); setFlag(f, NF); } @@ -647,7 +647,7 @@ void EightBit::Z80::ind(uint8_t& f) { auto value = m_memory.DATA(); m_memory.ADDRESS().word = HL().word--; m_memory.reference() = value; - postDecrement(f, --B()); + decrement(f, B()); setFlag(f, NF); } @@ -669,7 +669,7 @@ void EightBit::Z80::blockOut(uint8_t& f) { auto value = m_memory.reference(); m_memory.ADDRESS().word = BC().word; writePort(); - postDecrement(f, --B()); + decrement(f, B()); setFlag(f, NF, value & Bit7); setFlag(f, HC | CF, (L() + value) > 0xff); adjustParity(f, ((value + L()) & 7) ^ B()); @@ -1235,11 +1235,11 @@ void EightBit::Z80::executeOther(int x, int y, int z, int p, int q) { cycles += 6; break; case 4: // 8-bit INC - postIncrement(f, ++R(y, a)); // INC r + increment(f, R(y, a)); // INC r cycles += 4; break; case 5: // 8-bit DEC - postDecrement(f, --R(y, a)); // DEC r + decrement(f, R(y, a)); // DEC r cycles += 4; if (y == 6) cycles += 7;