diff --git a/Intel8080/src/Disassembler.cpp b/Intel8080/src/Disassembler.cpp index c1484a7..854f106 100644 --- a/Intel8080/src/Disassembler.cpp +++ b/Intel8080/src/Disassembler.cpp @@ -181,7 +181,7 @@ void EightBit::Disassembler::disassemble(std::ostringstream& output, Intel8080& auto q = (y & 1); auto immediate = bus.peek(pc + 1); - auto absolute = bus.peekWord(pc + 1); + auto absolute = cpu.peekWord(pc + 1).word; auto displacement = (int8_t)immediate; auto relative = pc + displacement + 2; auto indexedImmediate = bus.peek(pc + 1); diff --git a/LR35902/src/Disassembler.cpp b/LR35902/src/Disassembler.cpp index d861286..a0b7daa 100644 --- a/LR35902/src/Disassembler.cpp +++ b/LR35902/src/Disassembler.cpp @@ -162,7 +162,7 @@ void EightBit::GameBoy::Disassembler::disassemble(std::ostringstream& output, LR auto q = (y & 1); auto immediate = bus.peek(pc + 1); - auto absolute = bus.peekWord(pc + 1); + auto absolute = cpu.peekWord(pc + 1).word; auto displacement = (int8_t)immediate; auto relative = pc + displacement + 2; auto indexedImmediate = bus.peek(pc + 1); diff --git a/M6502/src/Disassembly.cpp b/M6502/src/Disassembly.cpp index 988468b..5bdfbfb 100644 --- a/M6502/src/Disassembly.cpp +++ b/M6502/src/Disassembly.cpp @@ -473,7 +473,7 @@ uint8_t EightBit::Disassembly::getByte(uint16_t address) const { } uint16_t EightBit::Disassembly::getWord(uint16_t address) const { - return processor.BUS().peekWord(address); + return processor.peekWord(address).word; } //// diff --git a/Z80/src/Disassembler.cpp b/Z80/src/Disassembler.cpp index 8909525..7844018 100644 --- a/Z80/src/Disassembler.cpp +++ b/Z80/src/Disassembler.cpp @@ -193,7 +193,7 @@ void EightBit::Disassembler::disassemble(std::ostringstream& output, Z80& cpu, u auto q = decoded.q; auto immediate = bus.peek(pc + 1); - auto absolute = bus.peekWord(pc + 1); + auto absolute = cpu.peekWord(pc + 1).word; auto displacement = (int8_t)immediate; auto relative = pc + displacement + 2; auto indexedImmediate = bus.peek(pc + 1); diff --git a/inc/BigEndianProcessor.h b/inc/BigEndianProcessor.h index c0eea35..2341d52 100644 --- a/inc/BigEndianProcessor.h +++ b/inc/BigEndianProcessor.h @@ -6,6 +6,9 @@ namespace EightBit { class BigEndianProcessor : public Processor { + public: + virtual register16_t peekWord(register16_t address) final; + protected: BigEndianProcessor(Bus& memory); virtual ~BigEndianProcessor() = default; diff --git a/inc/Bus.h b/inc/Bus.h index 9ee8f56..23f3383 100644 --- a/inc/Bus.h +++ b/inc/Bus.h @@ -28,8 +28,6 @@ namespace EightBit { void poke(uint8_t value) { reference() = value; } void poke(uint16_t address, uint8_t value) { reference(address) = value; } - uint16_t peekWord(uint16_t address); - uint8_t read(); template uint8_t read(const T address) { ADDRESS() = address; diff --git a/inc/LittleEndianProcessor.h b/inc/LittleEndianProcessor.h index 0c279c9..0e72244 100644 --- a/inc/LittleEndianProcessor.h +++ b/inc/LittleEndianProcessor.h @@ -6,6 +6,9 @@ namespace EightBit { class LittleEndianProcessor : public Processor { + public: + virtual register16_t peekWord(register16_t address) final; + protected: LittleEndianProcessor(Bus& memory); virtual ~LittleEndianProcessor() = default; diff --git a/inc/Processor.h b/inc/Processor.h index e0a41d5..c83d7a1 100644 --- a/inc/Processor.h +++ b/inc/Processor.h @@ -88,6 +88,8 @@ namespace EightBit { int cycles() const { return m_cycles; } + virtual register16_t peekWord(register16_t address) = 0; + protected: static void clearFlag(uint8_t& f, const int flag) { f &= ~flag; } static void setFlag(uint8_t& f, const int flag) { f |= flag; } diff --git a/src/BigEndianProcessor.cpp b/src/BigEndianProcessor.cpp index 0d9493f..a11f9c6 100644 --- a/src/BigEndianProcessor.cpp +++ b/src/BigEndianProcessor.cpp @@ -46,3 +46,9 @@ EightBit::register16_t EightBit::BigEndianProcessor::popWord() { const auto low = pop(); return register16_t(low, high); } + +EightBit::register16_t EightBit::BigEndianProcessor::peekWord(const register16_t address) { + const auto high = BUS().peek(address.word); + const auto low = BUS().peek(address.word + 1); + return register16_t(low, high).word; +} diff --git a/src/Bus.cpp b/src/Bus.cpp index fc2274a..07ef0b2 100644 --- a/src/Bus.cpp +++ b/src/Bus.cpp @@ -1,12 +1,6 @@ #include "stdafx.h" #include "Bus.h" -uint16_t EightBit::Bus::peekWord(const uint16_t address) { - const auto low = peek(address); - const auto high = peek(address + 1); - return register16_t(low, high).word; -} - uint8_t EightBit::Bus::read() { ReadingByte.fire(EventArgs::empty()); DATA() = reference(); diff --git a/src/LittleEndianProcessor.cpp b/src/LittleEndianProcessor.cpp index f644c97..acc3d59 100644 --- a/src/LittleEndianProcessor.cpp +++ b/src/LittleEndianProcessor.cpp @@ -46,3 +46,9 @@ EightBit::register16_t EightBit::LittleEndianProcessor::popWord() { const auto high = pop(); return register16_t(low, high); } + +EightBit::register16_t EightBit::LittleEndianProcessor::peekWord(const register16_t address) { + const auto low = BUS().peek(address.word); + const auto high = BUS().peek(address.word + 1); + return register16_t(low, high).word; +}