Whoops: The "Bus" class *really* isn't allowed to know the "endianness" of the attached processor!

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-08-27 11:27:33 +01:00
parent a5e51f7140
commit a8cc289149
11 changed files with 24 additions and 12 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;
}
////

View File

@ -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);

View File

@ -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;

View File

@ -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<class T> uint8_t read(const T address) {
ADDRESS() = address;

View File

@ -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;

View File

@ -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; }

View File

@ -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;
}

View File

@ -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();

View File

@ -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;
}