Simplify memory event handlers and ROM recognition a little (bit of speed difference)

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-06-10 22:00:52 +01:00
parent 3e854c7c49
commit fbf098ae00
12 changed files with 50 additions and 54 deletions

View File

@ -20,13 +20,11 @@ public:
void initialise();
protected:
virtual uint8_t& reference(uint16_t address, bool& rom) {
rom = false;
virtual uint8_t& reference(uint16_t address) {
return m_ram.reference(address);
}
virtual uint8_t reference(uint16_t address, bool& rom) const {
rom = false;
virtual uint8_t reference(uint16_t address) const {
return m_ram.reference(address);
}

View File

@ -37,13 +37,11 @@ namespace Fuse {
EightBit::register16_t actual, EightBit::register16_t expected) const;
protected:
virtual uint8_t& reference(uint16_t address, bool& rom) {
rom = false;
virtual uint8_t& reference(uint16_t address) {
return m_ram.reference(address);
}
virtual uint8_t reference(uint16_t address, bool& rom) const {
rom = false;
virtual uint8_t reference(uint16_t address) const {
return m_ram.reference(address);
}

View File

@ -91,7 +91,7 @@ namespace EightBit {
void validateCartridgeType();
void Bus_WrittenByte(uint16_t address);
void Bus_WrittenByte(EightBit::EventArgs);
int runRasterLines(int lines);
int runVerticalBlankLines(int lines);

View File

@ -195,8 +195,8 @@ namespace EightBit {
triggerInterrupt(Interrupts::KeypadPressed);
}
void Bus_WrittenByte(uint16_t address);
void Bus_ReadingByte(uint16_t address);
void Bus_WrittenByte(EightBit::EventArgs);
void Bus_ReadingByte(EightBit::EventArgs);
};
}
}

View File

@ -28,8 +28,9 @@ void EightBit::GameBoy::Bus::loadGameRom(const std::string& path) {
validateCartridgeType();
}
void EightBit::GameBoy::Bus::Bus_WrittenByte(const uint16_t address) {
void EightBit::GameBoy::Bus::Bus_WrittenByte(EightBit::EventArgs) {
const auto address = ADDRESS().word;
const auto value = DATA();
switch (address & 0xe000) {

View File

@ -23,7 +23,8 @@ void EightBit::GameBoy::IoRegisters::transferDma() {
}
}
void EightBit::GameBoy::IoRegisters::Bus_ReadingByte(const uint16_t address) {
void EightBit::GameBoy::IoRegisters::Bus_ReadingByte(EightBit::EventArgs) {
const auto address = m_bus.ADDRESS().word;
const auto io = (address >= BASE) && (address < 0xff80);
if (io) {
auto port = address - BASE;
@ -92,8 +93,9 @@ void EightBit::GameBoy::IoRegisters::Bus_ReadingByte(const uint16_t address) {
}
}
void EightBit::GameBoy::IoRegisters::Bus_WrittenByte(const uint16_t address) {
void EightBit::GameBoy::IoRegisters::Bus_WrittenByte(EightBit::EventArgs) {
const auto address = m_bus.ADDRESS().word;
const auto value = m_bus.DATA();
const auto port = address - BASE;

View File

@ -100,17 +100,15 @@ void Board::Cpu_ExecutingInstruction_Debug(const EightBit::MOS6502& cpu) {
std::cout << "\n";
}
void Board::Memory_ReadingByte_Input(const uint16_t address) {
if (address == m_configuration.getInputAddress()) {
if (DATA() != 0) {
assert(address == ADDRESS().word);
void Board::Memory_ReadingByte_Input(EightBit::EventArgs) {
if (ADDRESS().word == m_configuration.getInputAddress()) {
if (DATA() != 0)
write(0);
}
}
}
void Board::Memory_WrittenByte_Output(const uint16_t address) {
if (address == m_configuration.getOutputAddress()) {
void Board::Memory_WrittenByte_Output(EightBit::EventArgs) {
if (ADDRESS().word == m_configuration.getOutputAddress()) {
#ifdef _MSC_VER
_putch(DATA());
#endif

View File

@ -20,13 +20,11 @@ public:
void initialise();
protected:
virtual uint8_t& reference(uint16_t address, bool& rom) {
rom = false;
virtual uint8_t& reference(uint16_t address) {
return m_ram.reference(address);
}
virtual uint8_t reference(uint16_t address, bool& rom) const {
rom = false;
virtual uint8_t reference(uint16_t address) const {
return m_ram.reference(address);
}
@ -50,8 +48,8 @@ private:
void Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu);
void Memory_ReadingByte_Input(uint16_t address);
void Memory_WrittenByte_Output(uint16_t address);
void Memory_ReadingByte_Input(EightBit::EventArgs);
void Memory_WrittenByte_Output(EightBit::EventArgs);
void Cpu_ExecutedInstruction_Poll(const EightBit::MOS6502& cpu);
};

View File

@ -36,13 +36,11 @@ namespace Fuse {
EightBit::register16_t actual, EightBit::register16_t expected) const;
protected:
virtual uint8_t& reference(uint16_t address, bool& rom) {
rom = false;
virtual uint8_t& reference(uint16_t address) {
return m_ram.reference(address);
}
virtual uint8_t reference(uint16_t address, bool& rom) const {
rom = false;
virtual uint8_t reference(uint16_t address) const {
return m_ram.reference(address);
}

View File

@ -22,13 +22,11 @@ public:
void initialise();
protected:
virtual uint8_t& reference(uint16_t address, bool& rom) {
rom = false;
virtual uint8_t& reference(uint16_t address) {
return m_ram.reference(address);
}
virtual uint8_t reference(uint16_t address, bool& rom) const {
rom = false;
virtual uint8_t reference(uint16_t address) const {
return m_ram.reference(address);
}

View File

@ -4,24 +4,27 @@
#include "Signal.h"
#include "Register.h"
#include "EventArgs.h"
namespace EightBit {
class Bus {
public:
virtual ~Bus() = default;
Signal<uint16_t> WritingByte;
Signal<uint16_t> WrittenByte;
Signal<EventArgs> WritingByte;
Signal<EventArgs> WrittenByte;
Signal<uint16_t> ReadingByte;
Signal<uint16_t> ReadByte;
Signal<EventArgs> ReadingByte;
Signal<EventArgs> ReadByte;
register16_t& ADDRESS() { return m_address; }
register16_t ADDRESS() const { return m_address; }
uint8_t& DATA() { return m_data; }
uint8_t DATA() const { return m_data; }
uint8_t peek() const;
uint8_t peek(uint16_t address) const;
void poke(uint8_t value);
void poke(uint16_t address, uint8_t value);
uint16_t peekWord(uint16_t address) const;
@ -36,8 +39,8 @@ namespace EightBit {
void write(register16_t address, uint8_t value);
protected:
virtual uint8_t& reference(uint16_t address, bool& rom) = 0;
virtual uint8_t reference(uint16_t address, bool& rom) const = 0;
virtual uint8_t& reference(uint16_t address) = 0;
virtual uint8_t reference(uint16_t address) const = 0;
uint8_t& reference();
uint8_t reference() const;

View File

@ -1,16 +1,20 @@
#include "stdafx.h"
#include "Bus.h"
#include "EightBitCompilerDefinitions.h"
uint8_t EightBit::Bus::peek() const {
return reference();
}
uint8_t EightBit::Bus::peek(const uint16_t address) const {
bool rom;
return reference(address, rom);
return reference(address);
}
void EightBit::Bus::poke(const uint8_t value) {
reference() = value;
}
void EightBit::Bus::poke(const uint16_t address, const uint8_t value) {
bool rom;
reference(address, rom) = value;
reference(address) = value;
}
uint16_t EightBit::Bus::peekWord(const uint16_t address) const {
@ -21,9 +25,9 @@ uint16_t EightBit::Bus::peekWord(const uint16_t address) const {
}
uint8_t EightBit::Bus::read() {
ReadingByte.fire(ADDRESS().word);
ReadingByte.fire(EventArgs::empty());
DATA() = reference();
ReadByte.fire(ADDRESS().word);
ReadByte.fire(EventArgs::empty());
return DATA();
}
@ -38,9 +42,9 @@ uint8_t EightBit::Bus::read(const register16_t address) {
}
void EightBit::Bus::write() {
WritingByte.fire(ADDRESS().word);
WritingByte.fire(EventArgs::empty());
reference() = DATA();
WrittenByte.fire(ADDRESS().word);
WrittenByte.fire(EventArgs::empty());
}
void EightBit::Bus::write(const uint8_t value) {
@ -59,11 +63,9 @@ void EightBit::Bus::write(const register16_t address, const uint8_t value) {
}
uint8_t EightBit::Bus::reference() const {
bool rom;
return reference(ADDRESS().word, rom);
return reference(ADDRESS().word);
}
uint8_t& EightBit::Bus::reference() {
bool rom;
return reference(ADDRESS().word, rom);
return reference(ADDRESS().word);
}