From 0a02c32695e9da84163f31983da70c345fbb2bb3 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Fri, 21 Jul 2017 19:23:36 +0100 Subject: [PATCH] Some things (namely shift.rotate instructions) don't need to be quite so close to the Z80 implementation. Signed-off-by: Adrian.Conlon --- LR35902/inc/LR35902.h | 22 +++++++-------- LR35902/src/LR35902.cpp | 62 +++++++++++++++++------------------------ 2 files changed, 37 insertions(+), 47 deletions(-) diff --git a/LR35902/inc/LR35902.h b/LR35902/inc/LR35902.h index 60567b1..d08640c 100644 --- a/LR35902/inc/LR35902.h +++ b/LR35902/inc/LR35902.h @@ -184,17 +184,17 @@ namespace EightBit { static void orr(uint8_t& f, uint8_t& operand, uint8_t value); static void compare(uint8_t& f, uint8_t check, uint8_t value); - static uint8_t& rlc(uint8_t& f, uint8_t& operand); - static uint8_t& rrc(uint8_t& f, uint8_t& operand); - static uint8_t& rl(uint8_t& f, uint8_t& operand); - static uint8_t& rr(uint8_t& f, uint8_t& operand); - static uint8_t& sla(uint8_t& f, uint8_t& operand); - static uint8_t& sra(uint8_t& f, uint8_t& operand); - static uint8_t& srl(uint8_t& f, uint8_t& operand); + static void rlc(uint8_t& f, uint8_t& operand); + static void rrc(uint8_t& f, uint8_t& operand); + static void rl(uint8_t& f, uint8_t& operand); + static void rr(uint8_t& f, uint8_t& operand); + static void sla(uint8_t& f, uint8_t& operand); + static void sra(uint8_t& f, uint8_t& operand); + static void srl(uint8_t& f, uint8_t& operand); - static uint8_t& bit(uint8_t& f, int n, uint8_t& operand); - static uint8_t& res(int n, uint8_t& operand); - static uint8_t& set(int n, uint8_t& operand); + static void bit(uint8_t& f, int n, uint8_t& operand); + static void res(int n, uint8_t& operand); + static void set(int n, uint8_t& operand); static void daa(uint8_t& a, uint8_t& f); @@ -202,6 +202,6 @@ namespace EightBit { static void ccf(uint8_t& a, uint8_t& f); static void cpl(uint8_t& a, uint8_t& f); - uint8_t& swap(uint8_t& f, uint8_t& operand); + static void swap(uint8_t& f, uint8_t& operand); }; } \ No newline at end of file diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index e52ac2a..2222787 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -240,84 +240,76 @@ void EightBit::LR35902::compare(uint8_t& f, uint8_t check, uint8_t value) { #pragma region Shift and rotate -uint8_t& EightBit::LR35902::rlc(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::rlc(uint8_t& f, uint8_t& operand) { clearFlag(f, NF | HC); setFlag(f, CF, operand & Bit7); operand = _rotl8(operand, 1); adjustZero(f, operand); - return operand; } -uint8_t& EightBit::LR35902::rrc(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::rrc(uint8_t& f, uint8_t& operand) { clearFlag(f, NF | HC); setFlag(f, CF, operand & Bit0); operand = _rotr8(operand, 1); adjustZero(f, operand); - return operand; } -uint8_t& EightBit::LR35902::rl(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::rl(uint8_t& f, uint8_t& operand) { clearFlag(f, NF | HC); const auto carry = (f & CF) >> 4; setFlag(f, CF, operand & Bit7); operand = (operand << 1) | carry; adjustZero(f, operand); - return operand; } -uint8_t& EightBit::LR35902::rr(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::rr(uint8_t& f, uint8_t& operand) { clearFlag(f, NF | HC); const auto carry = (f & CF) >> 4; setFlag(f, CF, operand & Bit0); operand = (operand >> 1) | (carry << 7); adjustZero(f, operand); - return operand; } // -uint8_t& EightBit::LR35902::sla(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::sla(uint8_t& f, uint8_t& operand) { clearFlag(f, NF | HC); setFlag(f, CF, operand & Bit7); operand <<= 1; adjustZero(f, operand); - return operand; } -uint8_t& EightBit::LR35902::sra(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::sra(uint8_t& f, uint8_t& operand) { clearFlag(f, NF | HC); setFlag(f, CF, operand & Bit0); operand = (operand >> 1) | operand & Bit7; adjustZero(f, operand); - return operand; } -uint8_t& EightBit::LR35902::srl(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::srl(uint8_t& f, uint8_t& operand) { clearFlag(f, NF | HC); setFlag(f, CF, operand & Bit0); operand = (operand >> 1) & ~Bit7; adjustZero(f, operand); - return operand; } #pragma endregion Shift and rotate #pragma region BIT/SET/RES -uint8_t& EightBit::LR35902::bit(uint8_t& f, int n, uint8_t& operand) { +void EightBit::LR35902::bit(uint8_t& f, int n, uint8_t& operand) { auto carry = f & CF; uint8_t discarded = operand; andr(f, discarded, 1 << n); setFlag(f, CF, carry); - return operand; } -uint8_t& EightBit::LR35902::res(int n, uint8_t& operand) { - return operand &= ~(1 << n); +void EightBit::LR35902::res(int n, uint8_t& operand) { + operand &= ~(1 << n); } -uint8_t& EightBit::LR35902::set(int n, uint8_t& operand) { - return operand |= (1 << n); +void EightBit::LR35902::set(int n, uint8_t& operand) { + operand |= (1 << n); } #pragma endregion BIT/SET/RES @@ -358,18 +350,16 @@ void EightBit::LR35902::scf(uint8_t& a, uint8_t& f) { } void EightBit::LR35902::ccf(uint8_t& a, uint8_t& f) { - auto carry = f & CF; - clearFlag(f, CF, carry); clearFlag(f, NF | HC); + clearFlag(f, CF, f & CF); } -uint8_t& EightBit::LR35902::swap(uint8_t& f, uint8_t& operand) { +void EightBit::LR35902::swap(uint8_t& f, uint8_t& operand) { auto low = lowNibble(operand); auto high = highNibble(operand); operand = promoteNibble(low) | demoteNibble(high); adjustZero(f, operand); clearFlag(f, NF | HC | CF); - return operand; } #pragma endregion Miscellaneous instructions @@ -410,28 +400,28 @@ void EightBit::LR35902::executeCB(int x, int y, int z, int p, int q) { case 0: // rot[y] r[z] switch (y) { case 0: - adjustZero(f, rlc(f, R(z, a))); + rlc(f, R(z, a)); break; case 1: - adjustZero(f, rrc(f, R(z, a))); + rrc(f, R(z, a)); break; case 2: - adjustZero(f, rl(f, R(z, a))); + rl(f, R(z, a)); break; case 3: - adjustZero(f, rr(f, R(z, a))); + rr(f, R(z, a)); break; case 4: - adjustZero(f, sla(f, R(z, a))); + sla(f, R(z, a)); break; case 5: - adjustZero(f, sra(f, R(z, a))); + sra(f, R(z, a)); break; case 6: - adjustZero(f, swap(f, R(z, a))); + swap(f, R(z, a)); break; case 7: - adjustZero(f, srl(f, R(z, a))); + srl(f, R(z, a)); break; default: __assume(0); @@ -607,16 +597,16 @@ void EightBit::LR35902::executeOther(int x, int y, int z, int p, int q) { case 7: // Assorted operations on accumulator/flags switch (y) { case 0: - adjustZero(f, rlc(f, a)); + rlc(f, a); break; case 1: - adjustZero(f, rrc(f, a)); + rrc(f, a); break; case 2: - adjustZero(f, rl(f, a)); + rl(f, a); break; case 3: - adjustZero(f, rr(f, a)); + rr(f, a); break; case 4: daa(a, f);