From 66d3a5ae29d791dd5ca91ee789351835ecf08bf0 Mon Sep 17 00:00:00 2001 From: "Adrian.Conlon" Date: Tue, 13 Jun 2017 23:43:21 +0100 Subject: [PATCH] Couple of small simplifications. Signed-off-by: Adrian.Conlon --- Intel8080/inc/Intel8080.h | 22 +++++++++++----------- LR35902/inc/Bus.h | 2 +- LR35902/src/LR35902.cpp | 2 +- Z80/src/Z80.cpp | 4 ++-- inc/IntelProcessor.h | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Intel8080/inc/Intel8080.h b/Intel8080/inc/Intel8080.h index 299daba..280d3f9 100644 --- a/Intel8080/inc/Intel8080.h +++ b/Intel8080/inc/Intel8080.h @@ -83,8 +83,8 @@ namespace EightBit { return cycles + instruction.count; } - void adjustSign(uint8_t value) { F().S = ((value & 0x80) != 0); } - void adjustZero(uint8_t value) { F().Z = (value == 0); } + void adjustSign(uint8_t value) { F().S = ((value & Bit7) != 0); } + void adjustZero(uint8_t value) { F().Z = !value; } void adjustParity(uint8_t value) { static const uint8_t lookup[0x10] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 }; @@ -108,12 +108,12 @@ namespace EightBit { void postIncrement(uint8_t value) { adjustSZP(value); - F().AC = lowNibble(value) == 0; + F().AC = !lowNibble(value); } void postDecrement(uint8_t value) { adjustSZP(value); - F().AC = lowNibble(value) != 0xf; + F().AC = lowNibble(value) != Mask4; } static Instruction INS(instruction_t method, AddressingMode mode, std::string disassembly, int cycles); @@ -127,11 +127,11 @@ namespace EightBit { uint16_t subtraction = A() - value; adjustSZP((uint8_t)subtraction); adjustAuxiliaryCarrySub(value, subtraction); - F().C = subtraction > 0xff; + F().C = subtraction & Bit8; } void anda(uint8_t value) { - F().AC = (((A() | value) & 0x8) != 0); + F().AC = (((A() | value) & Bit3) != 0); F().C = false; adjustSZP(A() &= value); } @@ -151,7 +151,7 @@ namespace EightBit { sum.word = A() + value + carry; adjustAuxiliaryCarryAdd(value, sum.word); A() = sum.low; - F().C = sum.word > 0xff; + F().C = sum.word & Bit8; adjustSZP(A()); } @@ -170,7 +170,7 @@ namespace EightBit { difference.word = A() - value - carry; adjustAuxiliaryCarrySub(value, difference.word); A() = difference.low; - F().C = difference.word > 0xff; + F().C = difference.word & Bit8; adjustSZP(A()); } @@ -592,7 +592,7 @@ namespace EightBit { // rotate void rlc() { - auto carry = A() & 0x80; + auto carry = A() & Bit7; A() <<= 1; A() |= carry >> 7; F().C = carry != 0; @@ -606,7 +606,7 @@ namespace EightBit { } void ral() { - auto carry = A() & 0x80; + auto carry = A() & Bit7; A() <<= 1; A() |= (uint8_t)F().C; F().C = carry != 0; @@ -621,7 +621,7 @@ namespace EightBit { // specials - void cma() { A() ^= 0xff; } + void cma() { A() ^= Mask8; } void stc() { F().C = true; } void cmc() { F().C = !F().C; } diff --git a/LR35902/inc/Bus.h b/LR35902/inc/Bus.h index de98757..56135d8 100644 --- a/LR35902/inc/Bus.h +++ b/LR35902/inc/Bus.h @@ -95,7 +95,7 @@ namespace EightBit { void loadBootRom(const std::string& path); bool isBootRom(uint16_t address) const { - return (address < m_boot.size()) && (peek(BASE + BOOT_DISABLE) == 0); + return (address < m_boot.size()) && !peek(BASE + BOOT_DISABLE); } virtual uint8_t peek(uint16_t address) const; diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index 0c50c85..507b4bb 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -356,7 +356,7 @@ void EightBit::LR35902::daa() { uint8_t a = A(); - auto lowAdjust = (F() & HC) | ((A() & 0xf) > 9); + auto lowAdjust = (F() & HC) | ((A() & Mask4) > 9); auto highAdjust = (F() & CF) | (A() > 0x99); if (F() & NF) { diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index bb3a329..8a4a143 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -516,7 +516,7 @@ void EightBit::Z80::neg() { auto original = A(); A() = 0; sub(A(), original); - setFlag(PF, original == 0x80); + setFlag(PF, original == Bit7); setFlag(CF, original); } @@ -524,7 +524,7 @@ void EightBit::Z80::daa() { uint8_t a = A(); - auto lowAdjust = (F() & HC) | ((A() & 0xf) > 9); + auto lowAdjust = (F() & HC) | ((A() & Mask4) > 9); auto highAdjust = (F() & CF) | (A() > 0x99); if (F() & NF) { diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index c6543ee..54ab8a2 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -22,12 +22,12 @@ namespace EightBit { bool calculateHalfCarryAdd(uint8_t before, uint8_t value, int calculation) { auto index = buildHalfCarryIndex(before, value, calculation); - return m_halfCarryTableAdd[index & 0x7]; + return m_halfCarryTableAdd[index & Mask3]; } bool calculateHalfCarrySub(uint8_t before, uint8_t value, int calculation) { auto index = buildHalfCarryIndex(before, value, calculation); - return m_halfCarryTableSub[index & 0x7]; + return m_halfCarryTableSub[index & Mask3]; } void push(uint8_t value);