From 2d8c3d4b125e888ce1dbfe09622a81e3308e7e9a Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Mon, 11 Jun 2018 00:50:46 +0100 Subject: [PATCH] Simplify AF usage. Keeps speed roughly as before Signed-off-by: Adrian Conlon --- Z80/inc/Z80.h | 134 ++++----- Z80/src/Z80.cpp | 751 ++++++++++++++++++++++++------------------------ 2 files changed, 435 insertions(+), 450 deletions(-) diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index e45a33f..49038ce 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -141,7 +141,7 @@ namespace EightBit { m_displacement = fetchByte(); } - uint8_t R(const int r, const uint8_t a) { + uint8_t R(const int r) { ASSUME(r >= 0); ASSUME(r <= 7); switch (r) { @@ -160,13 +160,13 @@ namespace EightBit { case 6: return BUS().read(UNLIKELY(m_displaced) ? displacedAddress() : HL().word); case 7: - return a; + return A(); default: UNREACHABLE; } } - void R(const int r, uint8_t& a, const uint8_t value) { + void R(const int r, const uint8_t value) { ASSUME(r >= 0); ASSUME(r <= 7); switch (r) { @@ -192,14 +192,14 @@ namespace EightBit { BUS().write(UNLIKELY(m_displaced) ? displacedAddress() : HL().word, value); break; case 7: - a = value; + A() = value; break; default: UNREACHABLE; } } - uint8_t R2(const int r, const uint8_t a) { + uint8_t R2(const int r) { ASSUME(r >= 0); ASSUME(r <= 7); switch (r) { @@ -218,13 +218,13 @@ namespace EightBit { case 6: return BUS().read(HL()); case 7: - return a; + return A(); default: UNREACHABLE; } } - void R2(const int r, uint8_t& a, const uint8_t value) { + void R2(const int r, const uint8_t value) { ASSUME(r >= 0); ASSUME(r <= 7); switch (r) { @@ -250,7 +250,7 @@ namespace EightBit { BUS().write(HL(), value); break; case 7: - a = value; + A() = value; break; default: UNREACHABLE; @@ -369,14 +369,14 @@ namespace EightBit { setFlag(f, VF, overflow); } - static void subtract(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0); + void subtract(uint8_t& operand, uint8_t value, int carry = 0); - void executeCB(uint8_t& a, uint8_t& f, int x, int y, int z); - void executeED(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q); - void executeOther(uint8_t& a, uint8_t& f, int x, int y, int z, int p, int q); + void executeCB(int x, int y, int z); + 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 increment(uint8_t& f, uint8_t& operand); - static void decrement(uint8_t& f, uint8_t& operand); + void increment(uint8_t& operand); + void decrement(uint8_t& operand); void di(); void ei(); @@ -384,84 +384,84 @@ namespace EightBit { void retn(); void reti(); - bool jrConditionalFlag(uint8_t f, int flag); - bool returnConditionalFlag(uint8_t f, int flag); - bool jumpConditionalFlag(uint8_t f, int flag); - bool callConditionalFlag(uint8_t f, int flag); + bool jrConditionalFlag(int flag); + bool returnConditionalFlag(int flag); + bool jumpConditionalFlag(int flag); + bool callConditionalFlag(int flag); - void sbc(uint8_t& f, register16_t& operand, register16_t value); - void adc(uint8_t& f, register16_t& operand, register16_t value); - void add(uint8_t& f, register16_t& operand, register16_t value); + void sbc(register16_t& operand, register16_t value); + void adc(register16_t& operand, register16_t value); + void add(register16_t& operand, register16_t value); - static void add(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0); - static void adc(uint8_t& f, uint8_t& operand, uint8_t value); - static void sub(uint8_t& f, uint8_t& operand, uint8_t value, int carry = 0); - static void sbc(uint8_t& f, uint8_t& operand, uint8_t value); - static void andr(uint8_t& f, uint8_t& operand, uint8_t value); - static void xorr(uint8_t& f, uint8_t& operand, uint8_t value); - static void orr(uint8_t& f, uint8_t& operand, uint8_t value); - static void compare(uint8_t& f, uint8_t check, uint8_t value); + void add(uint8_t value, int carry = 0); + void adc(uint8_t value); + void sub(uint8_t value, int carry = 0); + void sbc(uint8_t value); + void andr(uint8_t value); + void xorr(uint8_t value); + void orr(uint8_t value); + void compare(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 sll(uint8_t& f, uint8_t operand); - static uint8_t srl(uint8_t& f, uint8_t operand); + void rlc(uint8_t& operand); + void rrc(uint8_t& operand); + void rl(uint8_t& operand); + void rr(uint8_t& operand); + void sla(uint8_t& operand); + void sra(uint8_t& operand); + void sll(uint8_t& operand); + void srl(uint8_t& operand); - static uint8_t bit(uint8_t& f, int n, uint8_t operand); + uint8_t bit(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 daa(uint8_t& a, uint8_t& f); + void daa(); - static void scf(uint8_t a, uint8_t& f); - static void ccf(uint8_t a, uint8_t& f); - static void cpl(uint8_t& a, uint8_t& f); + void scf(); + void ccf(); + void cpl(); void xhtl(register16_t& operand); - void blockCompare(uint8_t a, uint8_t& f); + void blockCompare(); - void cpi(uint8_t a, uint8_t& f); - bool cpir(uint8_t a, uint8_t& f); + void cpi(); + bool cpir(); - void cpd(uint8_t a, uint8_t& f); - bool cpdr(uint8_t a, uint8_t& f); + void cpd(); + bool cpdr(); - void blockLoad(uint8_t a, uint8_t& f, register16_t source, register16_t destination); + void blockLoad(register16_t source, register16_t destination); - void ldi(uint8_t a, uint8_t& f); - bool ldir(uint8_t a, uint8_t& f); + void ldi(); + bool ldir(); - void ldd(uint8_t a, uint8_t& f); - bool lddr(uint8_t a, uint8_t& f); + void ldd(); + bool lddr(); - void ini(uint8_t& f); - bool inir(uint8_t& f); + void ini(); + bool inir(); - void ind(uint8_t& f); - bool indr(uint8_t& f); + void ind(); + bool indr(); - void blockOut(uint8_t& f); + void blockOut(); - void outi(uint8_t& f); - bool otir(uint8_t& f); + void outi(); + bool otir(); - void outd(uint8_t& f); - bool otdr(uint8_t& f); + void outd(); + bool otdr(); - static void neg(uint8_t& a, uint8_t& f); + void neg(); - void rrd(uint8_t& a, uint8_t& f); - void rld(uint8_t& a, uint8_t& f); + void rrd(); + void rld(); - void writePort(uint8_t port, uint8_t a); + void writePort(uint8_t port); void writePort(); - void readPort(uint8_t port, uint8_t& a); - void readPort(); + uint8_t readPort(uint8_t port); + uint8_t readPort(); }; } \ No newline at end of file diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 2755246..91922d3 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -75,57 +75,57 @@ void EightBit::Z80::ei() { IFF1() = IFF2() = true; } -void EightBit::Z80::increment(uint8_t& f, uint8_t& operand) { - clearFlag(f, NF); - adjustSZXY(f, ++operand); - setFlag(f, VF, operand == Bit7); - clearFlag(f, HC, lowNibble(operand)); +void EightBit::Z80::increment(uint8_t& operand) { + clearFlag(F(), NF); + adjustSZXY(F(), ++operand); + setFlag(F(), VF, operand == Bit7); + clearFlag(F(), HC, lowNibble(operand)); } -void EightBit::Z80::decrement(uint8_t& f, uint8_t& operand) { - setFlag(f, NF); - clearFlag(f, HC, lowNibble(operand)); - adjustSZXY(f, --operand); - setFlag(f, VF, operand == Mask7); +void EightBit::Z80::decrement(uint8_t& operand) { + setFlag(F(), NF); + clearFlag(F(), HC, lowNibble(operand)); + adjustSZXY(F(), --operand); + setFlag(F(), VF, operand == Mask7); } -bool EightBit::Z80::jrConditionalFlag(const uint8_t f, const int flag) { +bool EightBit::Z80::jrConditionalFlag(const int flag) { ASSUME(flag >= 0); ASSUME(flag <= 3); switch (flag) { case 0: // NZ - return jrConditional(!(f & ZF)); + return jrConditional(!(F() & ZF)); case 1: // Z - return jrConditional(f & ZF); + return jrConditional(F() & ZF); case 2: // NC - return jrConditional(!(f & CF)); + return jrConditional(!(F() & CF)); case 3: // C - return jrConditional(f & CF); + return jrConditional(F() & CF); default: UNREACHABLE; } } -bool EightBit::Z80::jumpConditionalFlag(const uint8_t f, const int flag) { +bool EightBit::Z80::jumpConditionalFlag(const int flag) { ASSUME(flag >= 0); ASSUME(flag <= 7); switch (flag) { case 0: // NZ - return jumpConditional(!(f & ZF)); + return jumpConditional(!(F() & ZF)); case 1: // Z - return jumpConditional(f & ZF); + return jumpConditional(F() & ZF); case 2: // NC - return jumpConditional(!(f & CF)); + return jumpConditional(!(F() & CF)); case 3: // C - return jumpConditional(f & CF); + return jumpConditional(F() & CF); case 4: // PO - return jumpConditional(!(f & PF)); + return jumpConditional(!(F() & PF)); case 5: // PE - return jumpConditional(f & PF); + return jumpConditional(F() & PF); case 6: // P - return jumpConditional(!(f & SF)); + return jumpConditional(!(F() & SF)); case 7: // M - return jumpConditional(f & SF); + return jumpConditional(F() & SF); default: UNREACHABLE; } @@ -141,103 +141,103 @@ void EightBit::Z80::reti() { retn(); } -bool EightBit::Z80::returnConditionalFlag(const uint8_t f, const int flag) { +bool EightBit::Z80::returnConditionalFlag(const int flag) { ASSUME(flag >= 0); ASSUME(flag <= 7); switch (flag) { case 0: // NZ - return returnConditional(!(f & ZF)); + return returnConditional(!(F() & ZF)); case 1: // Z - return returnConditional(f & ZF); + return returnConditional(F() & ZF); case 2: // NC - return returnConditional(!(f & CF)); + return returnConditional(!(F() & CF)); case 3: // C - return returnConditional(f & CF); + return returnConditional(F() & CF); case 4: // PO - return returnConditional(!(f & PF)); + return returnConditional(!(F() & PF)); case 5: // PE - return returnConditional(f & PF); + return returnConditional(F() & PF); case 6: // P - return returnConditional(!(f & SF)); + return returnConditional(!(F() & SF)); case 7: // M - return returnConditional(f & SF); + return returnConditional(F() & SF); default: UNREACHABLE; } } -bool EightBit::Z80::callConditionalFlag(const uint8_t f, const int flag) { +bool EightBit::Z80::callConditionalFlag(const int flag) { ASSUME(flag >= 0); ASSUME(flag <= 7); switch (flag) { case 0: // NZ - return callConditional(!(f & ZF)); + return callConditional(!(F() & ZF)); case 1: // Z - return callConditional(f & ZF); + return callConditional(F() & ZF); case 2: // NC - return callConditional(!(f & CF)); + return callConditional(!(F() & CF)); case 3: // C - return callConditional(f & CF); + return callConditional(F() & CF); case 4: // PO - return callConditional(!(f & PF)); + return callConditional(!(F() & PF)); case 5: // PE - return callConditional(f & PF); + return callConditional(F() & PF); case 6: // P - return callConditional(!(f & SF)); + return callConditional(!(F() & SF)); case 7: // M - return callConditional(f & SF); + return callConditional(F() & SF); default: UNREACHABLE; } } -void EightBit::Z80::sbc(uint8_t& f, register16_t& operand, const register16_t value) { +void EightBit::Z80::sbc(register16_t& operand, const register16_t value) { MEMPTR() = operand; const auto beforeNegative = MEMPTR().high & SF; const auto valueNegative = value.high & SF; - const auto result = MEMPTR().word - value.word - (f & CF); + const auto result = MEMPTR().word - value.word - (F() & CF); operand.word = result; const auto afterNegative = operand.high & SF; - setFlag(f, SF, afterNegative); - clearFlag(f, ZF, operand.word); - adjustHalfCarrySub(f, MEMPTR().high, value.high, operand.high); - adjustOverflowSub(f, beforeNegative, valueNegative, afterNegative); - setFlag(f, NF); - setFlag(f, CF, result & Bit16); - adjustXY(f, operand.high); + setFlag(F(), SF, afterNegative); + clearFlag(F(), ZF, operand.word); + adjustHalfCarrySub(F(), MEMPTR().high, value.high, operand.high); + adjustOverflowSub(F(), beforeNegative, valueNegative, afterNegative); + setFlag(F(), NF); + setFlag(F(), CF, result & Bit16); + adjustXY(F(), operand.high); ++MEMPTR().word; } -void EightBit::Z80::adc(uint8_t& f, register16_t& operand, const register16_t value) { +void EightBit::Z80::adc(register16_t& operand, const register16_t value) { MEMPTR() = operand; const auto beforeNegative = MEMPTR().high & SF; const auto valueNegative = value.high & SF; - const auto result = MEMPTR().word + value.word + (f & CF); + const auto result = MEMPTR().word + value.word + (F() & CF); operand.word = result; const auto afterNegative = operand.high & SF; - setFlag(f, SF, afterNegative); - clearFlag(f, ZF, operand.word); - adjustHalfCarryAdd(f, MEMPTR().high, value.high, operand.high); - adjustOverflowAdd(f, beforeNegative, valueNegative, afterNegative); - clearFlag(f, NF); - setFlag(f, CF, result & Bit16); - adjustXY(f, operand.high); + setFlag(F(), SF, afterNegative); + clearFlag(F(), ZF, operand.word); + adjustHalfCarryAdd(F(), MEMPTR().high, value.high, operand.high); + adjustOverflowAdd(F(), beforeNegative, valueNegative, afterNegative); + clearFlag(F(), NF); + setFlag(F(), CF, result & Bit16); + adjustXY(F(), operand.high); ++MEMPTR().word; } -void EightBit::Z80::add(uint8_t& f, register16_t& operand, const register16_t value) { +void EightBit::Z80::add(register16_t& operand, const register16_t value) { MEMPTR() = operand; @@ -245,157 +245,150 @@ void EightBit::Z80::add(uint8_t& f, register16_t& operand, const register16_t va operand.word = result; - clearFlag(f, NF); - setFlag(f, CF, result & Bit16); - adjustHalfCarryAdd(f, MEMPTR().high, value.high, operand.high); - adjustXY(f, operand.high); + clearFlag(F(), NF); + setFlag(F(), CF, result & Bit16); + adjustHalfCarryAdd(F(), MEMPTR().high, value.high, operand.high); + adjustXY(F(), operand.high); ++MEMPTR().word; } -void EightBit::Z80::add(uint8_t& f, uint8_t& operand, const uint8_t value, const int carry) { +void EightBit::Z80::add(const uint8_t value, const int carry) { register16_t result; - result.word = operand + value + carry; + result.word = A() + value + carry; - adjustHalfCarryAdd(f, operand, value, result.low); - adjustOverflowAdd(f, operand, value, result.low); + adjustHalfCarryAdd(F(), A(), value, result.low); + adjustOverflowAdd(F(), A(), value, result.low); - operand = result.low; + A() = result.low; - clearFlag(f, NF); - setFlag(f, CF, result.word & Bit8); - adjustSZXY(f, operand); + clearFlag(F(), NF); + setFlag(F(), CF, result.word & Bit8); + adjustSZXY(F(), A()); } -void EightBit::Z80::adc(uint8_t& f, uint8_t& operand, const uint8_t value) { - add(f, operand, value, f & CF); +void EightBit::Z80::adc(const uint8_t value) { + add(value, F() & CF); } -void EightBit::Z80::subtract(uint8_t& f, uint8_t& operand, const uint8_t value, const int carry) { +void EightBit::Z80::subtract(uint8_t& operand, const uint8_t value, const int carry) { register16_t result; result.word = operand - value - carry; - adjustHalfCarrySub(f, operand, value, result.low); - adjustOverflowSub(f, operand, value, result.low); + adjustHalfCarrySub(F(), operand, value, result.low); + adjustOverflowSub(F(), operand, value, result.low); operand = result.low; - setFlag(f, NF); - setFlag(f, CF, result.word & Bit8); - adjustSZ(f, operand); + setFlag(F(), NF); + setFlag(F(), CF, result.word & Bit8); + adjustSZ(F(), operand); } -void EightBit::Z80::sub(uint8_t& f, uint8_t& operand, const uint8_t value, const int carry) { - subtract(f, operand, value, carry); - adjustXY(f, operand); +void EightBit::Z80::sub(const uint8_t value, const int carry) { + subtract(A(), value, carry); + adjustXY(F(), A()); } -void EightBit::Z80::sbc(uint8_t& f, uint8_t& operand, const uint8_t value) { - sub(f, operand, value, f & CF); +void EightBit::Z80::sbc(const uint8_t value) { + sub(value, F() & CF); } -void EightBit::Z80::andr(uint8_t& f, uint8_t& operand, const uint8_t value) { - setFlag(f, HC); - clearFlag(f, CF | NF); - adjustSZPXY(f, operand &= value); +void EightBit::Z80::andr(const uint8_t value) { + setFlag(F(), HC); + clearFlag(F(), CF | NF); + adjustSZPXY(F(), A() &= value); } -void EightBit::Z80::xorr(uint8_t& f, uint8_t& operand, const uint8_t value) { - clearFlag(f, HC | CF | NF); - adjustSZPXY(f, operand ^= value); +void EightBit::Z80::xorr(const uint8_t value) { + clearFlag(F(), HC | CF | NF); + adjustSZPXY(F(), A() ^= value); } -void EightBit::Z80::orr(uint8_t& f, uint8_t& operand, const uint8_t value) { - clearFlag(f, HC | CF | NF); - adjustSZPXY(f, operand |= value); +void EightBit::Z80::orr(const uint8_t value) { + clearFlag(F(), HC | CF | NF); + adjustSZPXY(F(), A() |= value); } -void EightBit::Z80::compare(uint8_t& f, uint8_t check, const uint8_t value) { - subtract(f, check, value); - adjustXY(f, value); +void EightBit::Z80::compare(const uint8_t value) { + auto original = A(); + subtract(original, value); + adjustXY(F(), value); } -uint8_t EightBit::Z80::rlc(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); +void EightBit::Z80::rlc(uint8_t& operand) { + clearFlag(F(), NF | HC); const auto carry = operand & Bit7; operand = (operand << 1) | (carry >> 7); - setFlag(f, CF, carry); - adjustXY(f, operand); - return operand; + setFlag(F(), CF, carry); + adjustXY(F(), operand); } -uint8_t EightBit::Z80::rrc(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); +void EightBit::Z80::rrc(uint8_t& operand) { + clearFlag(F(), NF | HC); const auto carry = operand & Bit0; operand = (operand >> 1) | (carry << 7); - setFlag(f, CF, carry); - adjustXY(f, operand); - return operand; + setFlag(F(), CF, carry); + adjustXY(F(), operand); } -uint8_t EightBit::Z80::rl(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); - const auto carry = f & CF; - setFlag(f, CF, operand & Bit7); +void EightBit::Z80::rl(uint8_t& operand) { + clearFlag(F(), NF | HC); + const auto carry = F() & CF; + setFlag(F(), CF, operand & Bit7); operand = (operand << 1) | carry; - adjustXY(f, operand); - return operand; + adjustXY(F(), operand); } -uint8_t EightBit::Z80::rr(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); - const auto carry = f & CF; - setFlag(f, CF, operand & Bit0); +void EightBit::Z80::rr(uint8_t& operand) { + clearFlag(F(), NF | HC); + const auto carry = F() & CF; + setFlag(F(), CF, operand & Bit0); operand = (operand >> 1) | (carry << 7); - adjustXY(f, operand); - return operand; + adjustXY(F(), operand); } // -uint8_t EightBit::Z80::sla(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); - setFlag(f, CF, operand & Bit7); +void EightBit::Z80::sla(uint8_t& operand) { + clearFlag(F(), NF | HC); + setFlag(F(), CF, operand & Bit7); operand <<= 1; - adjustXY(f, operand); - return operand; + adjustXY(F(), operand); } -uint8_t EightBit::Z80::sra(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); - setFlag(f, CF, operand & Bit0); +void EightBit::Z80::sra(uint8_t& operand) { + clearFlag(F(), NF | HC); + setFlag(F(), CF, operand & Bit0); operand = (operand >> 1) | (operand & Bit7); - adjustXY(f, operand); - return operand; + adjustXY(F(), operand); } -uint8_t EightBit::Z80::sll(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); - setFlag(f, CF, operand & Bit7); +void EightBit::Z80::sll(uint8_t& operand) { + clearFlag(F(), NF | HC); + setFlag(F(), CF, operand & Bit7); operand = (operand << 1) | Bit0; - adjustXY(f, operand); - return operand; + adjustXY(F(), operand); } -uint8_t EightBit::Z80::srl(uint8_t& f, uint8_t operand) { - clearFlag(f, NF | HC); - setFlag(f, CF, operand & Bit0); +void EightBit::Z80::srl(uint8_t& operand) { + clearFlag(F(), NF | HC); + setFlag(F(), CF, operand & Bit0); operand = (operand >> 1) & ~Bit7; - adjustXY(f, operand); - setFlag(f, ZF, operand); - return operand; + adjustXY(F(), operand); + setFlag(F(), ZF, operand); } -uint8_t EightBit::Z80::bit(uint8_t& f, const int n, const uint8_t operand) { +uint8_t EightBit::Z80::bit(const int n, const uint8_t operand) { ASSUME(n >= 0); ASSUME(n <= 7); - setFlag(f, HC); - clearFlag(f, NF); + setFlag(F(), HC); + clearFlag(F(), NF); const auto discarded = operand & (1 << n); - adjustSZXY(f, discarded); - clearFlag(f, PF, discarded); + adjustSZXY(F(), discarded); + clearFlag(F(), PF, discarded); return operand; } @@ -411,30 +404,30 @@ uint8_t EightBit::Z80::set(const int n, const uint8_t operand) { return operand | (1 << n); } -void EightBit::Z80::neg(uint8_t& a, uint8_t& f) { +void EightBit::Z80::neg() { - setFlag(f, PF, a == Bit7); - setFlag(f, CF, a); - setFlag(f, NF); + setFlag(F(), PF, A() == Bit7); + setFlag(F(), CF, A()); + setFlag(F(), NF); - const auto original = a; + const auto original = A(); - a = (~a + 1); // two's complement + A() = (~A() + 1); // two's complement - adjustHalfCarrySub(f, 0U, original, a); - adjustOverflowSub(f, 0U, original, a); + adjustHalfCarrySub(F(), 0U, original, A()); + adjustOverflowSub(F(), 0U, original, A()); - adjustSZXY(f, a); + adjustSZXY(F(), A()); } -void EightBit::Z80::daa(uint8_t& a, uint8_t& f) { +void EightBit::Z80::daa() { - auto updated = a; + auto updated = A(); - const auto lowAdjust = (f & HC) || (lowNibble(a) > 9); - const auto highAdjust = (f & CF) || (a > 0x99); + const auto lowAdjust = (F() & HC) || (lowNibble(A()) > 9); + const auto highAdjust = (F() & CF) || (A() > 0x99); - if (f & NF) { + if (F() & NF) { if (lowAdjust) updated -= 6; if (highAdjust) @@ -446,28 +439,28 @@ void EightBit::Z80::daa(uint8_t& a, uint8_t& f) { updated += 0x60; } - f = (f & (CF | NF)) | (a > 0x99 ? CF : 0) | ((a ^ updated) & HC); + F() = (F() & (CF | NF)) | (A() > 0x99 ? CF : 0) | ((A() ^ updated) & HC); - adjustSZPXY(f, a = updated); + adjustSZPXY(F(), A() = updated); } -void EightBit::Z80::cpl(uint8_t& a, uint8_t& f) { - setFlag(f, HC | NF); - adjustXY(f, a = ~a); +void EightBit::Z80::cpl() { + setFlag(F(), HC | NF); + adjustXY(F(), A() = ~A()); } -void EightBit::Z80::scf(const uint8_t a, uint8_t& f) { - setFlag(f, CF); - clearFlag(f, HC | NF); - adjustXY(f, a); +void EightBit::Z80::scf() { + setFlag(F(), CF); + clearFlag(F(), HC | NF); + adjustXY(F(), A()); } -void EightBit::Z80::ccf(const uint8_t a, uint8_t& f) { - clearFlag(f, NF); - const auto carry = f & CF; - setFlag(f, HC, carry); - clearFlag(f, CF, carry); - adjustXY(f, a); +void EightBit::Z80::ccf() { + clearFlag(F(), NF); + const auto carry = F() & CF; + setFlag(F(), HC, carry); + clearFlag(F(), CF, carry); + adjustXY(F(), A()); } void EightBit::Z80::xhtl(register16_t& operand) { @@ -480,164 +473,162 @@ void EightBit::Z80::xhtl(register16_t& operand) { operand.high = MEMPTR().high; } -void EightBit::Z80::blockCompare(const uint8_t a, uint8_t& f) { +void EightBit::Z80::blockCompare() { const auto value = BUS().read(HL()); - uint8_t result = a - value; + uint8_t result = A() - value; - setFlag(f, PF, --BC().word); + setFlag(F(), PF, --BC().word); - adjustSZ(f, result); - adjustHalfCarrySub(f, a, value, result); - setFlag(f, NF); + adjustSZ(F(), result); + adjustHalfCarrySub(F(), A(), value, result); + setFlag(F(), NF); - result -= ((f & HC) >> 4); + result -= ((F() & HC) >> 4); - setFlag(f, YF, result & Bit1); - setFlag(f, XF, result & Bit3); + setFlag(F(), YF, result & Bit1); + setFlag(F(), XF, result & Bit3); } -void EightBit::Z80::cpi(const uint8_t a, uint8_t& f) { - blockCompare(a, f); +void EightBit::Z80::cpi() { + blockCompare(); ++HL().word; ++MEMPTR().word; } -void EightBit::Z80::cpd(const uint8_t a, uint8_t& f) { - blockCompare(a, f); +void EightBit::Z80::cpd() { + blockCompare(); --HL().word; --MEMPTR().word; } -bool EightBit::Z80::cpir(const uint8_t a, uint8_t& f) { - cpi(a, f); - return (f & PF) && !(f & ZF); // See CPI +bool EightBit::Z80::cpir() { + cpi(); + return (F() & PF) && !(F() & ZF); // See CPI } -bool EightBit::Z80::cpdr(const uint8_t a, uint8_t& f) { - cpd(a, f); - return (f & PF) && !(f & ZF); // See CPD +bool EightBit::Z80::cpdr() { + cpd(); + return (F() & PF) && !(F() & ZF); // See CPD } -void EightBit::Z80::blockLoad(const uint8_t a, uint8_t& f, const register16_t source, const register16_t destination) { +void EightBit::Z80::blockLoad(const register16_t source, const register16_t destination) { const auto value = BUS().read(source); BUS().write(destination, value); - const auto xy = a + value; - setFlag(f, XF, xy & 8); - setFlag(f, YF, xy & 2); - clearFlag(f, NF | HC); - setFlag(f, PF, --BC().word); + const auto xy = A() + value; + setFlag(F(), XF, xy & 8); + setFlag(F(), YF, xy & 2); + clearFlag(F(), NF | HC); + setFlag(F(), PF, --BC().word); } -void EightBit::Z80::ldd(const uint8_t a, uint8_t& f) { - blockLoad(a, f, HL(), DE()); +void EightBit::Z80::ldd() { + blockLoad(HL(), DE()); --HL().word; --DE().word; } -void EightBit::Z80::ldi(const uint8_t a, uint8_t& f) { - blockLoad(a, f, HL(), DE()); +void EightBit::Z80::ldi() { + blockLoad(HL(), DE()); ++HL().word; ++DE().word; } -bool EightBit::Z80::ldir(const uint8_t a, uint8_t& f) { - ldi(a, f); - return !!(f & PF); // See LDI +bool EightBit::Z80::ldir() { + ldi(); + return !!(F() & PF); // See LDI } -bool EightBit::Z80::lddr(const uint8_t a, uint8_t& f) { - ldd(a, f); - return !!(f & PF); // See LDD +bool EightBit::Z80::lddr() { + ldd(); + return !!(F() & PF); // See LDD } -void EightBit::Z80::ini(uint8_t& f) { +void EightBit::Z80::ini() { MEMPTR() = BUS().ADDRESS() = BC(); ++MEMPTR().word; - readPort(); - const auto value = BUS().DATA(); + const auto value = readPort(); BUS().write(HL().word++, value); - decrement(f, B()); - setFlag(f, NF); + decrement(B()); + setFlag(F(), NF); } -void EightBit::Z80::ind(uint8_t& f) { +void EightBit::Z80::ind() { MEMPTR() = BUS().ADDRESS() = BC(); --MEMPTR().word; - readPort(); - const auto value = BUS().DATA(); + const auto value = readPort(); BUS().write(HL().word--, value); - decrement(f, B()); - setFlag(f, NF); + decrement(B()); + setFlag(F(), NF); } -bool EightBit::Z80::inir(uint8_t& f) { - ini(f); - return !(f & ZF); // See INI +bool EightBit::Z80::inir() { + ini(); + return !(F() & ZF); // See INI } -bool EightBit::Z80::indr(uint8_t& f) { - ind(f); - return !(f & ZF); // See IND +bool EightBit::Z80::indr() { + ind(); + return !(F() & ZF); // See IND } -void EightBit::Z80::blockOut(uint8_t& f) { +void EightBit::Z80::blockOut() { const auto value = BUS().read(); BUS().ADDRESS() = BC(); writePort(); - decrement(f, B()); - setFlag(f, NF, value & Bit7); - setFlag(f, HC | CF, (L() + value) > 0xff); - adjustParity(f, ((value + L()) & 7) ^ B()); + decrement(B()); + setFlag(F(), NF, value & Bit7); + setFlag(F(), HC | CF, (L() + value) > 0xff); + adjustParity(F(), ((value + L()) & 7) ^ B()); } -void EightBit::Z80::outi(uint8_t& f) { +void EightBit::Z80::outi() { BUS().ADDRESS().word = HL().word++; - blockOut(f); + blockOut(); MEMPTR().word = BC().word + 1; } -void EightBit::Z80::outd(uint8_t& f) { +void EightBit::Z80::outd() { BUS().ADDRESS().word = HL().word--; - blockOut(f); + blockOut(); MEMPTR().word = BC().word - 1; } -bool EightBit::Z80::otir(uint8_t& f) { - outi(f); - return !(f & ZF); // See OUTI +bool EightBit::Z80::otir() { + outi(); + return !(F() & ZF); // See OUTI } -bool EightBit::Z80::otdr(uint8_t& f) { - outd(f); - return !(f & ZF); // See OUTD +bool EightBit::Z80::otdr() { + outd(); + return !(F() & ZF); // See OUTD } -void EightBit::Z80::rrd(uint8_t& a, uint8_t& f) { +void EightBit::Z80::rrd() { MEMPTR() = BUS().ADDRESS() = HL(); ++MEMPTR().word; const auto memory = BUS().read(); - BUS().write(promoteNibble(a) | highNibble(memory)); - a = higherNibble(a) | lowerNibble(memory); - adjustSZPXY(f, a); - clearFlag(f, NF | HC); + BUS().write(promoteNibble(A()) | highNibble(memory)); + A() = higherNibble(A()) | lowerNibble(memory); + adjustSZPXY(F(), A()); + clearFlag(F(), NF | HC); } -void EightBit::Z80::rld(uint8_t& a, uint8_t& f) { +void EightBit::Z80::rld() { MEMPTR() = BUS().ADDRESS() = HL(); ++MEMPTR().word; const auto memory = BUS().read(); - BUS().write(promoteNibble(memory) | lowNibble(a)); - a = higherNibble(a) | highNibble(memory); - adjustSZPXY(f, a); - clearFlag(f, NF | HC); + BUS().write(promoteNibble(memory) | lowNibble(A())); + A() = higherNibble(A()) | highNibble(memory); + adjustSZPXY(F(), A()); + clearFlag(F(), NF | HC); } -void EightBit::Z80::writePort(const uint8_t port, const uint8_t data) { +void EightBit::Z80::writePort(const uint8_t port) { BUS().ADDRESS().low = port; - BUS().ADDRESS().high = data; + BUS().ADDRESS().high = A(); MEMPTR() = BUS().ADDRESS(); - BUS().DATA() = data; + BUS().DATA() = A(); writePort(); ++MEMPTR().low; } @@ -646,17 +637,16 @@ void EightBit::Z80::writePort() { m_ports.write(BUS().ADDRESS().low, BUS().DATA()); } -void EightBit::Z80::readPort(const uint8_t port, uint8_t& a) { +uint8_t EightBit::Z80::readPort(const uint8_t port) { BUS().ADDRESS().low = port; - BUS().ADDRESS().high = a; + BUS().ADDRESS().high = A(); MEMPTR() = BUS().ADDRESS(); - readPort(); - a = BUS().DATA(); ++MEMPTR().low; + return readPort(); } -void EightBit::Z80::readPort() { - BUS().DATA() = m_ports.read(BUS().ADDRESS().low); +uint8_t EightBit::Z80::readPort() { + return BUS().DATA() = m_ports.read(BUS().ADDRESS().low); } int EightBit::Z80::step() { @@ -721,18 +711,14 @@ int EightBit::Z80::execute(const uint8_t opcode) { const auto p = decoded.p; const auto q = decoded.q; - auto& af = AF(); - auto& a = af.high; - auto& f = af.low; - const auto prefixed = m_prefixCB || m_prefixED; if (LIKELY(!prefixed)) { - executeOther(a, f, x, y, z, p, q); + executeOther(x, y, z, p, q); } else { if (m_prefixCB) - executeCB(a, f, x, y, z); + executeCB(x, y, z); else if (m_prefixED) - executeED(a, f, x, y, z, p, q); + executeED(x, y, z, p, q); else UNREACHABLE; } @@ -741,7 +727,7 @@ int EightBit::Z80::execute(const uint8_t opcode) { return cycles(); } -void EightBit::Z80::executeCB(uint8_t& a, uint8_t& f, const int x, const int y, const int z) { +void EightBit::Z80::executeCB(const int x, const int y, const int z) { ASSUME(x >= 0); ASSUME(x <= 3); ASSUME(y >= 0); @@ -750,43 +736,43 @@ void EightBit::Z80::executeCB(uint8_t& a, uint8_t& f, const int x, const int y, ASSUME(z <= 7); switch (x) { case 0: { // rot[y] r[z] - auto operand = LIKELY(!m_displaced) ? R(z, a) : BUS().read(displacedAddress()); + auto operand = LIKELY(!m_displaced) ? R(z) : BUS().read(displacedAddress()); switch (y) { case 0: - operand = rlc(f, operand); + rlc(operand); break; case 1: - operand = rrc(f, operand); + rrc(operand); break; case 2: - operand = rl(f, operand); + rl(operand); break; case 3: - operand = rr(f, operand); + rr(operand); break; case 4: - operand = sla(f, operand); + sla(operand); break; case 5: - operand = sra(f, operand); + sra(operand); break; case 6: - operand = sll(f, operand); + sll(operand); break; case 7: - operand = srl(f, operand); + srl(operand); break; default: UNREACHABLE; } - adjustSZP(f, operand); + adjustSZP(F(), operand); if (UNLIKELY(m_displaced)) { if (LIKELY(z != 6)) - R2(z, a, operand); + R2(z, operand); BUS().write(operand); addCycles(15); } else { - R(z, a, operand); + R(z, operand); if (UNLIKELY(z == 6)) addCycles(7); } @@ -795,16 +781,16 @@ void EightBit::Z80::executeCB(uint8_t& a, uint8_t& f, const int x, const int y, } case 1: // BIT y, r[z] addCycles(8); if (UNLIKELY(m_displaced)) { - bit(f, y, BUS().read(displacedAddress())); - adjustXY(f, MEMPTR().high); + bit(y, BUS().read(displacedAddress())); + adjustXY(F(), MEMPTR().high); addCycles(12); } else { - const auto operand = bit(f, y, R(z, a)); + const auto operand = bit(y, R(z)); if (UNLIKELY(z == 6)) { - adjustXY(f, MEMPTR().high); + adjustXY(F(), MEMPTR().high); addCycles(4); } else { - adjustXY(f, operand); + adjustXY(F(), operand); } } break; @@ -814,10 +800,10 @@ void EightBit::Z80::executeCB(uint8_t& a, uint8_t& f, const int x, const int y, auto operand = BUS().read(displacedAddress()); operand = res(y, operand); BUS().write(operand); - R2(z, a, operand); + R2(z, operand); addCycles(15); } else { - R(z, a, res(y, R(z, a))); + R(z, res(y, R(z))); if (UNLIKELY(z == 6)) addCycles(7); } @@ -828,10 +814,10 @@ void EightBit::Z80::executeCB(uint8_t& a, uint8_t& f, const int x, const int y, auto operand = BUS().read(displacedAddress()); operand = set(y, operand); BUS().write(operand); - R2(z, a, operand); + R2(z, operand); addCycles(15); } else { - R(z, a, set(y, R(z, a))); + R(z, set(y, R(z))); if (UNLIKELY(z == 6)) addCycles(7); } @@ -841,7 +827,7 @@ void EightBit::Z80::executeCB(uint8_t& a, uint8_t& f, const int x, const int y, } } -void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, const int z, const int p, const int q) { +void EightBit::Z80::executeED(const int x, const int y, const int z, const int p, const int q) { ASSUME(x >= 0); ASSUME(x <= 3); ASSUME(y >= 0); @@ -860,14 +846,14 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, case 1: switch (z) { case 0: // Input from port with 16-bit address - MEMPTR() = BUS().ADDRESS() = BC(); - ++MEMPTR().word; + MEMPTR() = BUS().ADDRESS() = BC(); + ++MEMPTR().word; readPort(); - if (LIKELY(y != 6)) // IN r[y],(C) - R(y, a, BUS().DATA()); - adjustSZPXY(f, BUS().DATA()); - clearFlag(f, NF | HC); - addCycles(12); + if (LIKELY(y != 6)) // IN r[y],(C) + R(y, BUS().DATA()); + adjustSZPXY(F(), BUS().DATA()); + clearFlag(F(), NF | HC); + addCycles(12); break; case 1: // Output to port with 16-bit address MEMPTR() = BUS().ADDRESS() = BC(); @@ -875,17 +861,17 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, if (UNLIKELY(y == 6)) // OUT (C),0 BUS().DATA() = 0; else // OUT (C),r[y] - BUS().DATA() = R(y, a); + BUS().DATA() = R(y); writePort(); addCycles(12); break; case 2: // 16-bit add/subtract with carry switch (q) { case 0: // SBC HL, rp[p] - sbc(f, HL2(), RP(p)); + sbc(HL2(), RP(p)); break; case 1: // ADC HL, rp[p] - adc(f, HL2(), RP(p)); + adc(HL2(), RP(p)); break; default: UNREACHABLE; @@ -908,7 +894,7 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, addCycles(20); break; case 4: // Negate accumulator - neg(a, f); + neg(); addCycles(8); break; case 5: // Return from interrupt @@ -948,33 +934,33 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, case 7: // Assorted ops switch (y) { case 0: // LD I,A - IV() = a; + IV() = A(); addCycles(9); break; case 1: // LD R,A - REFRESH() = a; + REFRESH() = A(); addCycles(9); break; case 2: // LD A,I - a = IV(); - adjustSZXY(f, a); - clearFlag(f, NF | HC); - setFlag(f, PF, IFF2()); + A() = IV(); + adjustSZXY(F(), A()); + clearFlag(F(), NF | HC); + setFlag(F(), PF, IFF2()); addCycles(9); break; case 3: // LD A,R - a = REFRESH(); - adjustSZXY(f, a); - clearFlag(f, NF | HC); - setFlag(f, PF, IFF2()); + A() = REFRESH(); + adjustSZXY(F(), A()); + clearFlag(F(), NF | HC); + setFlag(F(), PF, IFF2()); addCycles(9); break; case 4: // RRD - rrd(a, f); + rrd(); addCycles(18); break; case 5: // RLD - rld(a, f); + rld(); addCycles(18); break; case 6: // NOP @@ -994,20 +980,20 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, case 0: // LD switch (y) { case 4: // LDI - ldi(a, f); + ldi(); break; case 5: // LDD - ldd(a, f); + ldd(); break; case 6: // LDIR - if (LIKELY(ldir(a, f))) { + if (LIKELY(ldir())) { MEMPTR().word = --PC().word; --PC().word; addCycles(5); } break; case 7: // LDDR - if (LIKELY(lddr(a, f))) { + if (LIKELY(lddr())) { MEMPTR().word = --PC().word; --PC().word; addCycles(5); @@ -1018,20 +1004,20 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, case 1: // CP switch (y) { case 4: // CPI - cpi(a, f); + cpi(); break; case 5: // CPD - cpd(a, f); + cpd(); break; case 6: // CPIR - if (LIKELY(cpir(a, f))) { + if (LIKELY(cpir())) { MEMPTR().word = --PC().word; --PC().word; addCycles(5); } break; case 7: // CPDR - if (LIKELY(cpdr(a, f))) { + if (LIKELY(cpdr())) { MEMPTR().word = --PC().word; --PC().word; addCycles(5); @@ -1044,19 +1030,19 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, case 2: // IN switch (y) { case 4: // INI - ini(f); + ini(); break; case 5: // IND - ind(f); + ind(); break; case 6: // INIR - if (LIKELY(inir(f))) { + if (LIKELY(inir())) { PC().word -= 2; addCycles(5); } break; case 7: // INDR - if (LIKELY(indr(f))) { + if (LIKELY(indr())) { PC().word -= 2; addCycles(5); } @@ -1066,19 +1052,19 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, case 3: // OUT switch (y) { case 4: // OUTI - outi(f); + outi(); break; case 5: // OUTD - outd(f); + outd(); break; case 6: // OTIR - if (LIKELY(otir(f))) { + if (LIKELY(otir())) { PC().word -= 2; addCycles(5); } break; case 7: // OTDR - if (LIKELY(otdr(f))) { + if (LIKELY(otdr())) { PC().word -= 2; addCycles(5); } @@ -1091,7 +1077,7 @@ void EightBit::Z80::executeED(uint8_t& a, uint8_t& f, const int x, const int y, } } -void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int y, const int z, const int p, const int q) { +void EightBit::Z80::executeOther(const int x, const int y, const int z, const int p, const int q) { ASSUME(x >= 0); ASSUME(x <= 3); ASSUME(y >= 0); @@ -1127,7 +1113,7 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 5: case 6: case 7: - if (UNLIKELY(jrConditionalFlag(f, y - 4))) + if (UNLIKELY(jrConditionalFlag(y - 4))) addCycles(5); addCycles(5); break; @@ -1142,7 +1128,7 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int addCycles(10); break; case 1: // ADD HL,rp - add(f, HL2(), RP(p)); + add(HL2(), RP(p)); addCycles(11); break; default: @@ -1156,16 +1142,15 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 0: // LD (BC),A MEMPTR() = BUS().ADDRESS() = BC(); ++MEMPTR().word; - BUS().DATA() = a; + MEMPTR().high = BUS().DATA() = A(); BUS().write(); - MEMPTR().high = a; addCycles(7); break; case 1: // LD (DE),A MEMPTR() = BUS().ADDRESS() = DE(); ++MEMPTR().word; - BUS().write(a); - MEMPTR().high = a; + MEMPTR().high = BUS().DATA() = A(); + BUS().write(); addCycles(7); break; case 2: // LD (nn),HL @@ -1176,8 +1161,8 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 3: // LD (nn),A MEMPTR() = BUS().ADDRESS() = fetchWord(); ++MEMPTR().word; - BUS().write(a); - MEMPTR().high = a; + MEMPTR().high = BUS().DATA() = A(); + BUS().write(); addCycles(13); break; default: @@ -1189,13 +1174,13 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 0: // LD A,(BC) MEMPTR() = BUS().ADDRESS() = BC(); ++MEMPTR().word; - a = BUS().read(); + A() = BUS().read(); addCycles(7); break; case 1: // LD A,(DE) MEMPTR() = BUS().ADDRESS() = DE(); ++MEMPTR().word; - a = BUS().read(); + A() = BUS().read(); addCycles(7); break; case 2: // LD HL,(nn) @@ -1206,7 +1191,7 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 3: // LD A,(nn) MEMPTR() = BUS().ADDRESS() = fetchWord(); ++MEMPTR().word; - a = BUS().read(); + A() = BUS().read(); addCycles(13); break; default: @@ -1233,9 +1218,9 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 4: { // 8-bit INC if (UNLIKELY(m_displaced && (y == 6))) fetchDisplacement(); - auto operand = R(y, a); - increment(f, operand); - R(y, a, operand); + auto operand = R(y); + increment(operand); + R(y, operand); addCycles(4); break; } case 5: { // 8-bit DEC @@ -1244,9 +1229,9 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int if (UNLIKELY(m_displaced)) fetchDisplacement(); } - auto operand = R(y, a); - decrement(f, operand); - R(y, a, operand); + auto operand = R(y); + decrement(operand); + R(y, operand); addCycles(4); break; } case 6: // 8-bit load immediate @@ -1255,34 +1240,34 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int if (UNLIKELY(m_displaced)) fetchDisplacement(); } - R(y, a, fetchByte()); // LD r,n + R(y, fetchByte()); // LD r,n addCycles(7); break; case 7: // Assorted operations on accumulator/flags switch (y) { case 0: - a = rlc(f, a); + rlc(A()); break; case 1: - a = rrc(f, a); + rrc(A()); break; case 2: - a = rl(f, a); + rl(A()); break; case 3: - a = rr(f, a); + rr(A()); break; case 4: - daa(a, f); + daa(); break; case 5: - cpl(a, f); + cpl(); break; case 6: - scf(a, f); + scf(); break; case 7: - ccf(a, f); + ccf(); break; default: UNREACHABLE; @@ -1303,11 +1288,11 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int fetchDisplacement(); switch (y) { case 4: - H() = R(z, a); + H() = R(z); normal = false; break; case 5: - L() = R(z, a); + L() = R(z); normal = false; break; } @@ -1316,18 +1301,18 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int fetchDisplacement(); switch (z) { case 4: - R(y, a, H()); + R(y, H()); normal = false; break; case 5: - R(y, a, L()); + R(y, L()); normal = false; break; } } } if (LIKELY(normal)) - R(y, a, R(z, a)); + R(y, R(z)); if (UNLIKELY((y == 6) || (z == 6))) // M operations addCycles(3); } @@ -1341,28 +1326,28 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int } switch (y) { case 0: // ADD A,r - add(f, a, R(z, a)); + add(R(z)); break; case 1: // ADC A,r - adc(f, a, R(z, a)); + adc(R(z)); break; case 2: // SUB r - sub(f, a, R(z, a)); + sub(R(z)); break; case 3: // SBC A,r - sbc(f, a, R(z, a)); + sbc(R(z)); break; case 4: // AND r - andr(f, a, R(z, a)); + andr(R(z)); break; case 5: // XOR r - xorr(f, a, R(z, a)); + xorr(R(z)); break; case 6: // OR r - orr(f, a, R(z, a)); + orr(R(z)); break; case 7: // CP r - compare(f, a, R(z, a)); + compare(R(z)); break; default: UNREACHABLE; @@ -1372,7 +1357,7 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 3: switch (z) { case 0: // Conditional return - if (UNLIKELY(returnConditionalFlag(f, y))) + if (UNLIKELY(returnConditionalFlag(y))) addCycles(6); addCycles(5); break; @@ -1410,7 +1395,7 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int } break; case 2: // Conditional jump - jumpConditionalFlag(f, y); + jumpConditionalFlag(y); addCycles(10); break; case 3: // Assorted operations @@ -1427,11 +1412,11 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int execute(fetchByte()); break; case 2: // OUT (n),A - writePort(fetchByte(), a); + writePort(fetchByte()); addCycles(11); break; case 3: // IN A,(n) - readPort(fetchByte(), a); + A() = readPort(fetchByte()); addCycles(11); break; case 4: // EX (SP),HL @@ -1455,7 +1440,7 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int } break; case 4: // Conditional call: CALL cc[y], nn - if (UNLIKELY(callConditionalFlag(f, y))) + if (UNLIKELY(callConditionalFlag(y))) addCycles(7); addCycles(10); break; @@ -1497,28 +1482,28 @@ void EightBit::Z80::executeOther(uint8_t& a, uint8_t& f, const int x, const int case 6: // Operate on accumulator and immediate operand: alu[y] n switch (y) { case 0: // ADD A,n - add(f, a, fetchByte()); + add(fetchByte()); break; case 1: // ADC A,n - adc(f, a, fetchByte()); + adc(fetchByte()); break; case 2: // SUB n - sub(f, a, fetchByte()); + sub(fetchByte()); break; case 3: // SBC A,n - sbc(f, a, fetchByte()); + sbc(fetchByte()); break; case 4: // AND n - andr(f, a, fetchByte()); + andr(fetchByte()); break; case 5: // XOR n - xorr(f, a, fetchByte()); + xorr(fetchByte()); break; case 6: // OR n - orr(f, a, fetchByte()); + orr(fetchByte()); break; case 7: // CP n - compare(f, a, fetchByte()); + compare(fetchByte()); break; default: UNREACHABLE;