From af375ab10f41d9ed9b58004861366c15cf5febc7 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Thu, 22 Jun 2017 19:00:53 +0100 Subject: [PATCH] Some more shared code. Signed-off-by: Adrian.Conlon --- Intel8080/inc/Intel8080.h | 23 +++++++++++------------ LR35902/inc/LR35902.h | 2 -- LR35902/src/LR35902.cpp | 38 +++++++++++++++++--------------------- Z80/src/Z80.cpp | 3 +-- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index b06663d..ba976b3 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -109,12 +109,8 @@ namespace EightBit { // void compare(uint8_t value) { - const auto& a = A(); - auto& f = F(); - uint16_t subtraction = a - value; - adjustSZP(f, (uint8_t)subtraction); - adjustAuxiliaryCarrySub(f, a, value, subtraction); - setFlag(f, CF, subtraction & Bit8); + auto check = A(); + sub(check, value); } void anda(uint8_t value) { @@ -159,15 +155,18 @@ namespace EightBit { HL().word = (uint16_t)sum; } - void sub(uint8_t value, int carry = 0) { - auto& a = A(); + void sub(uint8_t& operand, uint8_t value, int carry = 0) { auto& f = F(); register16_t difference; - difference.word = a - value - carry; - adjustAuxiliaryCarrySub(f, a, value, difference.word); - a = difference.low; + difference.word = operand - value - carry; + adjustAuxiliaryCarrySub(f, operand, value, difference.word); + operand = difference.low; setFlag(f, CF, difference.word & Bit8); - adjustSZP(f, a); + adjustSZP(f, operand); + } + + void sub(uint8_t value, int carry = 0) { + sub(A(), value, carry); } void sbb(uint8_t value) { diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index a425691..cfc41e6 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -124,8 +124,6 @@ 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 adjustZero(uint8_t& f, uint8_t value); - static void postIncrement(uint8_t& f, uint8_t value); static void postDecrement(uint8_t& f, uint8_t value); diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 79ccc89..376eda9 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -50,18 +50,14 @@ int EightBit::LR35902::interrupt(uint8_t value) { #pragma region Flag manipulation helpers -void EightBit::LR35902::adjustZero(uint8_t& f, uint8_t value) { - clearFlag(f, ZF, value); -} - void EightBit::LR35902::postIncrement(uint8_t& f, uint8_t value) { - adjustZero(f, value); + adjustZero(f, value); clearFlag(f, NF); clearFlag(f, HC, lowNibble(value)); } void EightBit::LR35902::postDecrement(uint8_t& f, uint8_t value) { - adjustZero(f, value); + adjustZero(f, value); setFlag(f, NF); clearFlag(f, HC, lowNibble(value + 1)); } @@ -194,7 +190,7 @@ void EightBit::LR35902::add(uint8_t& operand, uint8_t value, int carry) { clearFlag(f, NF); setFlag(f, CF, result.word & Bit8); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::adc(uint8_t& operand, uint8_t value) { @@ -214,7 +210,7 @@ void EightBit::LR35902::sub(uint8_t& operand, uint8_t value, int carry) { setFlag(f, NF); setFlag(f, CF, result.word & Bit8); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::sbc(uint8_t& operand, uint8_t value) { @@ -226,21 +222,21 @@ void EightBit::LR35902::andr(uint8_t& operand, uint8_t value) { operand &= value; setFlag(f, HC); clearFlag(f, CF | NF); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::xorr(uint8_t& operand, uint8_t value) { auto& f = F(); operand ^= value; clearFlag(f, HC | CF | NF); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::orr(uint8_t& operand, uint8_t value) { auto& f = F(); operand |= value; clearFlag(f, HC | CF | NF); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::compare(uint8_t value) { @@ -259,7 +255,7 @@ void EightBit::LR35902::rlc(uint8_t& operand) { setFlag(f, CF, carry); carry ? operand |= Bit0 : operand &= ~Bit0; clearFlag(f, NF | HC); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::rrc(uint8_t& operand) { @@ -269,7 +265,7 @@ void EightBit::LR35902::rrc(uint8_t& operand) { carry ? operand |= Bit7 : operand &= ~Bit7; setFlag(f, CF, carry); clearFlag(f, NF | HC); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::rl(uint8_t& operand) { @@ -280,7 +276,7 @@ void EightBit::LR35902::rl(uint8_t& operand) { oldCarry ? operand |= Bit0 : operand &= ~Bit0; setFlag(f, CF, newCarry); clearFlag(f, NF | HC); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::rr(uint8_t& operand) { @@ -291,7 +287,7 @@ void EightBit::LR35902::rr(uint8_t& operand) { operand |= oldCarry << 7; setFlag(f, CF, newCarry); clearFlag(f, NF | HC); - adjustZero(f, operand); + adjustZero(f, operand); } // @@ -302,7 +298,7 @@ void EightBit::LR35902::sla(uint8_t& operand) { operand <<= 1; setFlag(f, CF, newCarry); clearFlag(f, NF | HC); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::sra(uint8_t& operand) { @@ -313,7 +309,7 @@ void EightBit::LR35902::sra(uint8_t& operand) { operand |= new7; setFlag(f, CF, newCarry); clearFlag(f, NF | HC); - adjustZero(f, operand); + adjustZero(f, operand); } void EightBit::LR35902::srl(uint8_t& operand) { @@ -323,7 +319,7 @@ void EightBit::LR35902::srl(uint8_t& operand) { operand &= ~Bit7; // clear bit 7 setFlag(f, CF, newCarry); clearFlag(f, NF | HC); - adjustZero(f, operand); + adjustZero(f, operand); } #pragma endregion Shift and rotate @@ -375,7 +371,7 @@ void EightBit::LR35902::daa() { f = (f & (CF | NF)) | (A() > 0x99) | ((A() ^ a) & HC); - adjustZero(f, a); + adjustZero(f, a); A() = a; } @@ -404,7 +400,7 @@ void EightBit::LR35902::swap(uint8_t& operand) { auto low = lowNibble(operand); auto high = highNibble(operand); operand = promoteNibble(low) | demoteNibble(high); - adjustZero(f, operand); + adjustZero(f, operand); clearFlag(f, NF | HC | CF); } @@ -466,7 +462,7 @@ void EightBit::LR35902::executeCB(int x, int y, int z, int p, int q) { srl(R(z)); break; } - adjustZero(F(), R(z)); + adjustZero(F(), R(z)); cycles += 2; if (z == 6) cycles += 2; diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index b93bd04..9051471 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -356,10 +356,9 @@ void EightBit::Z80::orr(uint8_t& operand, uint8_t value) { } void EightBit::Z80::compare(uint8_t value) { - auto& f = F(); auto check = A(); sub(check, value); - adjustXY(f, value); + adjustXY(F(), value); } #pragma endregion ALU