mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-08-09 16:24:56 +00:00
Add pre/post read/write memory events.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
@@ -258,7 +258,7 @@ namespace EightBit {
|
||||
int m_timerCounter;
|
||||
int m_timerRate;
|
||||
|
||||
void Bus_WrittenByte(const AddressEventArgs& e);
|
||||
void Bus_WrittenByte(uint16_t address);
|
||||
|
||||
void checkTimer(int cycles);
|
||||
|
||||
|
@@ -48,10 +48,9 @@ void EightBit::GameBoy::Bus::loadGameRom(const std::string& path) {
|
||||
validateCartridgeType();
|
||||
}
|
||||
|
||||
void EightBit::GameBoy::Bus::Bus_WrittenByte(const AddressEventArgs& e) {
|
||||
void EightBit::GameBoy::Bus::Bus_WrittenByte(const uint16_t address) {
|
||||
|
||||
const auto address = e.getAddress();
|
||||
const auto value = e.getCell();
|
||||
const auto value = DATA();
|
||||
|
||||
auto handled = false;
|
||||
|
||||
|
@@ -105,20 +105,18 @@ void Board::Cpu_ExecutingInstruction_Debug(const EightBit::MOS6502& cpu) {
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
void Board::Memory_ReadByte_Input(const EightBit::AddressEventArgs& e) {
|
||||
auto address = e.getAddress();
|
||||
void Board::Memory_ReadByte_Input(const uint16_t address) {
|
||||
if (address == m_configuration.getInputAddress()) {
|
||||
auto cell = e.getCell();
|
||||
if (cell != 0) {
|
||||
if (DATA() != 0) {
|
||||
assert(address == ADDRESS().word);
|
||||
write(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Board::Memory_WrittenByte_Output(const EightBit::AddressEventArgs& e) {
|
||||
if (e.getAddress() == m_configuration.getOutputAddress()) {
|
||||
_putch(e.getCell());
|
||||
void Board::Memory_WrittenByte_Output(const uint16_t address) {
|
||||
if (address == m_configuration.getOutputAddress()) {
|
||||
_putch(DATA());
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,6 @@
|
||||
#include <Ram.h>
|
||||
#include <Bus.h>
|
||||
#include <Profiler.h>
|
||||
#include <EventArgs.h>
|
||||
#include <Disassembly.h>
|
||||
#include <mos6502.h>
|
||||
#include <Symbols.h>
|
||||
@@ -46,8 +45,8 @@ private:
|
||||
|
||||
void Cpu_ExecutedInstruction_StopLoop(const EightBit::MOS6502& cpu);
|
||||
|
||||
void Memory_ReadByte_Input(const EightBit::AddressEventArgs& e);
|
||||
void Memory_WrittenByte_Output(const EightBit::AddressEventArgs& e);
|
||||
void Memory_ReadByte_Input(uint16_t address);
|
||||
void Memory_WrittenByte_Output(uint16_t address);
|
||||
|
||||
void Cpu_ExecutedInstruction_Poll(const EightBit::MOS6502& cpu);
|
||||
};
|
||||
|
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace EightBit {
|
||||
class AddressEventArgs {
|
||||
private:
|
||||
uint16_t m_address;
|
||||
uint8_t m_cell;
|
||||
|
||||
public:
|
||||
AddressEventArgs(uint16_t address, uint8_t cell)
|
||||
: m_address(address), m_cell(cell) {}
|
||||
|
||||
uint16_t getAddress() const { return m_address; }
|
||||
uint8_t getCell() const { return m_cell; }
|
||||
};
|
||||
}
|
28
inc/Bus.h
28
inc/Bus.h
@@ -3,7 +3,6 @@
|
||||
#include <cstdint>
|
||||
|
||||
#include "Signal.h"
|
||||
#include "AddressEventArgs.h"
|
||||
#include "Register.h"
|
||||
|
||||
namespace EightBit {
|
||||
@@ -14,8 +13,11 @@ namespace EightBit {
|
||||
m_address.word = 0xffff;
|
||||
}
|
||||
|
||||
Signal<AddressEventArgs> WrittenByte;
|
||||
Signal<AddressEventArgs> ReadByte;
|
||||
Signal<uint16_t> WritingByte;
|
||||
Signal<uint16_t> WrittenByte;
|
||||
|
||||
Signal<uint16_t> ReadingByte;
|
||||
Signal<uint16_t> ReadByte;
|
||||
|
||||
register16_t& ADDRESS() { return m_address; }
|
||||
uint8_t& DATA() { return *m_data; }
|
||||
@@ -49,6 +51,7 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
uint8_t read() {
|
||||
fireReadingBusEvent();
|
||||
auto content = reference();
|
||||
fireReadBusEvent();
|
||||
return content;
|
||||
@@ -65,8 +68,9 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
void write(uint8_t value) {
|
||||
fireWritingBusEvent();
|
||||
reference() = value;
|
||||
fireWriteBusEvent();
|
||||
fireWrittenBusEvent();
|
||||
}
|
||||
|
||||
void write(uint16_t offset, uint8_t value) {
|
||||
@@ -80,12 +84,20 @@ namespace EightBit {
|
||||
}
|
||||
|
||||
protected:
|
||||
void fireReadBusEvent() {
|
||||
ReadByte.fire(AddressEventArgs(ADDRESS().word, DATA()));
|
||||
void fireReadingBusEvent() {
|
||||
ReadingByte.fire(ADDRESS().word);
|
||||
}
|
||||
|
||||
void fireWriteBusEvent() {
|
||||
WrittenByte.fire(AddressEventArgs(ADDRESS().word, DATA()));
|
||||
void fireReadBusEvent() {
|
||||
ReadByte.fire(ADDRESS().word);
|
||||
}
|
||||
|
||||
void fireWritingBusEvent() {
|
||||
WritingByte.fire(ADDRESS().word);
|
||||
}
|
||||
|
||||
void fireWrittenBusEvent() {
|
||||
WrittenByte.fire(ADDRESS().word);
|
||||
}
|
||||
|
||||
virtual uint8_t& reference(uint16_t address, bool& rom) = 0;
|
||||
|
@@ -138,7 +138,6 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\inc\AddressEventArgs.h" />
|
||||
<ClInclude Include="..\inc\Bus.h" />
|
||||
<ClInclude Include="..\inc\EventArgs.h" />
|
||||
<ClInclude Include="..\inc\InputOutput.h" />
|
||||
|
@@ -32,9 +32,6 @@
|
||||
<ClInclude Include="..\inc\TestHarness.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\inc\AddressEventArgs.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\inc\InputOutput.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
|
Reference in New Issue
Block a user