From ed76038bfaf8c7fe07cf0123ee7ed53a4a2f9bcd Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Fri, 17 Aug 2018 13:59:59 +0100 Subject: [PATCH] More memptr adjustments Signed-off-by: Adrian Conlon --- Intel8080/src/Intel8080.cpp | 10 ++++------ LR35902/inc/ObjectAttribute.h | 8 ++++---- LR35902/src/Display.cpp | 2 +- LR35902/src/IoRegisters.cpp | 5 ++--- LR35902/src/LR35902.cpp | 8 +++----- M6502/src/mos6502.cpp | 8 ++------ M6502/test/Board.cpp | 2 +- Z80/inc/Z80.h | 2 +- Z80/src/Z80.cpp | 26 +++++++++----------------- inc/IntelProcessor.h | 32 ++++++++++++++++---------------- inc/Processor.h | 10 +++++----- src/IntelProcessor.cpp | 8 ++++---- 12 files changed, 52 insertions(+), 69 deletions(-) diff --git a/Intel8080/src/Intel8080.cpp b/Intel8080/src/Intel8080.cpp index 28f5d05..406e58c 100644 --- a/Intel8080/src/Intel8080.cpp +++ b/Intel8080/src/Intel8080.cpp @@ -236,8 +236,7 @@ void EightBit::Intel8080::xhtl() { } void EightBit::Intel8080::writePort(uint8_t port) { - BUS().ADDRESS().low = port; - BUS().ADDRESS().high = A(); + BUS().ADDRESS() = register16_t(port, A()); BUS().DATA() = A(); writePort(); } @@ -247,8 +246,7 @@ void EightBit::Intel8080::writePort() { } uint8_t EightBit::Intel8080::readPort(uint8_t port) { - BUS().ADDRESS().low = port; - BUS().ADDRESS().high = A(); + BUS().ADDRESS() = register16_t(port, A()); return readPort(); } @@ -330,7 +328,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { addCycles(7); break; case 2: // LD (nn),HL - MEMPTR() = fetchWord(); + BUS().ADDRESS() = fetchWord(); setWord(HL()); addCycles(16); break; @@ -354,7 +352,7 @@ void EightBit::Intel8080::execute(int x, int y, int z, int p, int q) { addCycles(7); break; case 2: // LD HL,(nn) - MEMPTR() = fetchWord(); + BUS().ADDRESS() = fetchWord(); HL() = getWord(); addCycles(16); break; diff --git a/LR35902/inc/ObjectAttribute.h b/LR35902/inc/ObjectAttribute.h index fd621ff..0f21327 100644 --- a/LR35902/inc/ObjectAttribute.h +++ b/LR35902/inc/ObjectAttribute.h @@ -21,10 +21,10 @@ namespace EightBit { uint8_t priority() const { return flags() & Processor::Bit7; } - bool highPriority() const { return priority() != 0; } - bool lowPriority() const { return priority() == 0; } - bool flipY() const { return (flags() & Processor::Bit6) != 0; } - bool flipX() const { return (flags() & Processor::Bit5) != 0; } + bool highPriority() const { return !!priority(); } + bool lowPriority() const { return !priority(); } + bool flipY() const { return !!(flags() & Processor::Bit6); } + bool flipX() const { return !!(flags() & Processor::Bit5); } int palette() const { return (flags() & Processor::Bit4) >> 3; } private: diff --git a/LR35902/src/Display.cpp b/LR35902/src/Display.cpp index 6dd0971..9f77eaa 100644 --- a/LR35902/src/Display.cpp +++ b/LR35902/src/Display.cpp @@ -90,7 +90,7 @@ void EightBit::GameBoy::Display::renderBackground() { const auto palette = createPalette(IoRegisters::BGP); - const auto window = (m_control & IoRegisters::WindowEnable) != 0; + const auto window = !!(m_control & IoRegisters::WindowEnable); const auto bgArea = (m_control & IoRegisters::BackgroundCodeAreaSelection) ? 0x1c00 : 0x1800; const auto bgCharacters = (m_control & IoRegisters::BackgroundCharacterDataSelection) ? 0 : 0x800; diff --git a/LR35902/src/IoRegisters.cpp b/LR35902/src/IoRegisters.cpp index b0054aa..e41b58a 100644 --- a/LR35902/src/IoRegisters.cpp +++ b/LR35902/src/IoRegisters.cpp @@ -130,8 +130,7 @@ void EightBit::GameBoy::IoRegisters::Bus_WrittenByte(EightBit::EventArgs) { case SCX: break; case DMA: - m_dmaAddress.high = value; - m_dmaAddress.low = 0; + m_dmaAddress = register16_t(0, value); m_dmaTransferActive = true; break; case LY: // R/O @@ -145,7 +144,7 @@ void EightBit::GameBoy::IoRegisters::Bus_WrittenByte(EightBit::EventArgs) { break; case BOOT_DISABLE: - m_disableBootRom = value != 0; + m_disableBootRom = !!value; break; } } diff --git a/LR35902/src/LR35902.cpp b/LR35902/src/LR35902.cpp index a6d9ef3..8cadb8d 100644 --- a/LR35902/src/LR35902.cpp +++ b/LR35902/src/LR35902.cpp @@ -418,7 +418,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) addCycle(); break; case 1: // GB: LD (nn),SP - MEMPTR() = fetchWord(); + BUS().ADDRESS() = fetchWord(); setWord(SP()); addCycles(5); break; @@ -731,8 +731,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) case 3: // Assorted operations switch (y) { case 0: // JP nn - MEMPTR() = fetchWord(); - jump(MEMPTR()); + jump(MEMPTR() = fetchWord()); addCycles(4); break; case 1: // CB prefix @@ -763,8 +762,7 @@ void EightBit::GameBoy::LR35902::executeOther(int x, int y, int z, int p, int q) case 1: switch (p) { case 0: // CALL nn - MEMPTR() = fetchWord(); - call(MEMPTR()); + call(MEMPTR() = fetchWord()); addCycles(6); break; } diff --git a/M6502/src/mos6502.cpp b/M6502/src/mos6502.cpp index 0d0495d..e8ecade 100644 --- a/M6502/src/mos6502.cpp +++ b/M6502/src/mos6502.cpp @@ -58,15 +58,11 @@ EightBit::register16_t EightBit::MOS6502::getWordPaged(uint8_t page, uint8_t off } uint8_t EightBit::MOS6502::getBytePaged(uint8_t page, uint8_t offset) { - BUS().ADDRESS().low = offset; - BUS().ADDRESS().high = page; - return BUS().read(); + return BUS().read(register16_t(offset, page)); } void EightBit::MOS6502::setBytePaged(uint8_t page, uint8_t offset, uint8_t value) { - BUS().ADDRESS().low = offset; - BUS().ADDRESS().high = page; - BUS().write(value); + BUS().write(register16_t(offset, page), value); } void EightBit::MOS6502::interrupt(uint8_t vector) { diff --git a/M6502/test/Board.cpp b/M6502/test/Board.cpp index c80c006..4aa182a 100644 --- a/M6502/test/Board.cpp +++ b/M6502/test/Board.cpp @@ -102,7 +102,7 @@ void Board::Cpu_ExecutingInstruction_Debug(EightBit::MOS6502& cpu) { void Board::Memory_ReadingByte_Input(EightBit::EventArgs) { if (ADDRESS().word == m_configuration.getInputAddress()) { - if (DATA() != 0) + if (!!DATA()) write(0); } } diff --git a/Z80/inc/Z80.h b/Z80/inc/Z80.h index 3aa67f5..440a3ba 100644 --- a/Z80/inc/Z80.h +++ b/Z80/inc/Z80.h @@ -20,7 +20,7 @@ namespace EightBit { uint8_t variable : 7; refresh_t(const uint8_t value) - : high((value & Bit7) != 0), + : high(!!(value & Bit7)), variable(value & Mask7) { } diff --git a/Z80/src/Z80.cpp b/Z80/src/Z80.cpp index 3ff02cd..89e9914 100644 --- a/Z80/src/Z80.cpp +++ b/Z80/src/Z80.cpp @@ -117,7 +117,6 @@ bool EightBit::Z80::jumpConditionalFlag(const int flag) { void EightBit::Z80::retn() { ret(); - MEMPTR() = PC(); IFF1() = IFF2(); } @@ -589,9 +588,7 @@ void EightBit::Z80::rld() { } void EightBit::Z80::writePort(const uint8_t port) { - BUS().ADDRESS().low = port; - BUS().ADDRESS().high = A(); - MEMPTR() = BUS().ADDRESS(); + MEMPTR() = BUS().ADDRESS() = register16_t(port, A()); BUS().DATA() = A(); writePort(); ++MEMPTR().low; @@ -602,9 +599,7 @@ void EightBit::Z80::writePort() { } uint8_t EightBit::Z80::readPort(const uint8_t port) { - BUS().ADDRESS().low = port; - BUS().ADDRESS().high = A(); - MEMPTR() = BUS().ADDRESS(); + MEMPTR() = BUS().ADDRESS() = register16_t(port, A()); ++MEMPTR().low; return readPort(); } @@ -640,9 +635,7 @@ int EightBit::Z80::step() { addCycles(13); return cycles(); case 2: - MEMPTR().low = BUS().DATA(); - MEMPTR().high = IV(); - call(MEMPTR()); + call(MEMPTR() = register16_t(BUS().DATA(), IV())); addCycles(19); return cycles(); default: @@ -843,7 +836,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p addCycles(15); break; case 3: // Retrieve/store register pair from/to immediate address - MEMPTR() = fetchWord(); + BUS().ADDRESS() = fetchWord(); switch (q) { case 0: // LD (nn), rp[p] setWord(RP(p)); @@ -955,7 +948,7 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 7: // LDDR if (LIKELY(lddr())) { - MEMPTR()= --PC(); + MEMPTR() = --PC(); --PC(); addCycles(5); } @@ -972,14 +965,14 @@ void EightBit::Z80::executeED(const int x, const int y, const int z, const int p break; case 6: // CPIR if (LIKELY(cpir())) { - MEMPTR()= --PC(); + MEMPTR() = --PC(); --PC(); addCycles(5); } break; case 7: // CPDR if (LIKELY(cpdr())) { - MEMPTR()= --PC(); + MEMPTR() = --PC(); --PC(); addCycles(5); } else { @@ -1115,7 +1108,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in addCycles(7); break; case 2: // LD (nn),HL - MEMPTR() = fetchWord(); + BUS().ADDRESS() = fetchWord(); setWord(HL2()); addCycles(16); break; @@ -1145,7 +1138,7 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in addCycles(7); break; case 2: // LD HL,(nn) - MEMPTR() = fetchWord(); + BUS().ADDRESS() = fetchWord(); HL2() = getWord(); addCycles(16); break; @@ -1334,7 +1327,6 @@ void EightBit::Z80::executeOther(const int x, const int y, const int z, const in switch (p) { case 0: // RET ret(); - MEMPTR() = PC(); addCycles(10); break; case 1: // EXX diff --git a/inc/IntelProcessor.h b/inc/IntelProcessor.h index ebe91d2..f5641a7 100644 --- a/inc/IntelProcessor.h +++ b/inc/IntelProcessor.h @@ -128,43 +128,43 @@ namespace EightBit { // void restart(const uint8_t address) { - MEMPTR().low = address; - MEMPTR().high = 0; - call(MEMPTR()); + call(MEMPTR() = register16_t(address, 0)); } bool callConditional(const int condition) { MEMPTR() = fetchWord(); if (condition) call(MEMPTR()); - return condition != 0; + return !!condition; } - bool jumpConditional(const int conditional) { + bool jumpConditional(const int condition) { MEMPTR() = fetchWord(); - if (conditional) + if (condition) jump(MEMPTR()); - return conditional != 0; + return !!condition; } bool returnConditional(const int condition) { - if (condition) { + if (condition) ret(); - MEMPTR() = PC(); - } - return condition != 0; + return !!condition; } void jr(const int8_t offset) { - MEMPTR() = PC() + offset; - jump(MEMPTR()); + jump(MEMPTR() = PC() + offset); } - bool jrConditional(const int conditional) { + bool jrConditional(const int condition) { const auto offset = fetchByte(); - if (conditional) + if (condition) jr(offset); - return conditional != 0; + return !!condition; + } + + virtual void ret() final { + Processor::ret(); + MEMPTR() = PC(); } private: diff --git a/inc/Processor.h b/inc/Processor.h index d9b8910..92897fc 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -91,12 +91,12 @@ namespace EightBit { static void clearFlag(uint8_t& f, const int flag) { f &= ~flag; } static void setFlag(uint8_t& f, const int flag) { f |= flag; } - static void setFlag(uint8_t& f, const int flag, const int condition) { setFlag(f, flag, condition != 0); } - static void setFlag(uint8_t& f, const int flag, const uint32_t condition) { setFlag(f, flag, condition != 0); } + static void setFlag(uint8_t& f, const int flag, const int condition) { setFlag(f, flag, !!condition); } + static void setFlag(uint8_t& f, const int flag, const uint32_t condition) { setFlag(f, flag, !!condition); } static void setFlag(uint8_t& f, const int flag, const bool condition) { condition ? setFlag(f, flag) : clearFlag(f, flag); } - static void clearFlag(uint8_t& f, const int flag, const int condition) { clearFlag(f, flag, condition != 0); } - static void clearFlag(uint8_t& f, const int flag, const uint32_t condition) { clearFlag(f, flag, condition != 0); } + static void clearFlag(uint8_t& f, const int flag, const int condition) { clearFlag(f, flag, !!condition); } + static void clearFlag(uint8_t& f, const int flag, const uint32_t condition) { clearFlag(f, flag, !!condition); } static void clearFlag(uint8_t& f, const int flag, const bool condition) { condition ? clearFlag(f, flag) : setFlag(f, flag); } Processor(Bus& memory); @@ -141,7 +141,7 @@ namespace EightBit { jump(destination); } - void ret() { + virtual void ret() { jump(popWord()); } diff --git a/src/IntelProcessor.cpp b/src/IntelProcessor.cpp index d5cfb5f..13967f4 100644 --- a/src/IntelProcessor.cpp +++ b/src/IntelProcessor.cpp @@ -21,14 +21,14 @@ uint8_t EightBit::IntelProcessor::pop() { } EightBit::register16_t EightBit::IntelProcessor::getWord() { - BUS().ADDRESS() = MEMPTR()++; const auto low = BUS().read(); - ++BUS().ADDRESS(); + MEMPTR() = ++BUS().ADDRESS(); const auto high = BUS().read(); return register16_t(low, high); } void EightBit::IntelProcessor::setWord(const register16_t value) { - BUS().write(MEMPTR()++, value.low); - BUS().write(++BUS().ADDRESS(), value.high); + BUS().write(value.low); + MEMPTR() = ++BUS().ADDRESS(); + BUS().write(value.high); }