mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2025-01-08 11:29:26 +00:00
Refactor to allow peek/poke/reference to share a common implementation as much as possible.
Signed-off-by: Adrian.Conlon <adrian.conlon@gmail.com>
This commit is contained in:
parent
19c0b93262
commit
9964070b85
@ -182,11 +182,6 @@ namespace EightBit {
|
||||
void loadBootRom(const std::string& path);
|
||||
void loadGameRom(const std::string& path);
|
||||
|
||||
virtual uint8_t peek(uint16_t address);
|
||||
virtual void poke(uint16_t address, uint8_t value);
|
||||
|
||||
virtual uint8_t& reference();
|
||||
|
||||
private:
|
||||
std::vector<uint8_t> m_bootRom;
|
||||
std::vector<uint8_t> m_gameRom;
|
||||
@ -214,6 +209,6 @@ namespace EightBit {
|
||||
|
||||
void validateCartridgeType();
|
||||
|
||||
uint8_t& reference(uint16_t address, bool& rom);
|
||||
virtual uint8_t& reference(uint16_t address, bool& rom);
|
||||
};
|
||||
}
|
@ -53,22 +53,6 @@ uint8_t& EightBit::Bus::reference(uint16_t address, bool& rom) {
|
||||
return m_bus[effective];
|
||||
}
|
||||
|
||||
uint8_t& EightBit::Bus::reference() {
|
||||
bool rom;
|
||||
auto& value = reference(ADDRESS().word, rom);
|
||||
return rom ? placeDATA(value) : referenceDATA(value);
|
||||
}
|
||||
|
||||
uint8_t EightBit::Bus::peek(uint16_t address) {
|
||||
bool rom;
|
||||
return reference(address, rom);
|
||||
}
|
||||
|
||||
void EightBit::Bus::poke(uint16_t address, uint8_t value) {
|
||||
bool rom;
|
||||
reference(address, rom) = value;
|
||||
}
|
||||
|
||||
void EightBit::Bus::Bus_WrittenByte(const AddressEventArgs& e) {
|
||||
|
||||
const auto address = e.getAddress();
|
||||
@ -90,7 +74,7 @@ void EightBit::Bus::Bus_WrittenByte(const AddressEventArgs& e) {
|
||||
m_disableBootRom = value != 0;
|
||||
break;
|
||||
case BASE + DIV:
|
||||
reference() = 0;
|
||||
Memory::reference() = 0;
|
||||
m_timerCounter = 0;
|
||||
break;
|
||||
}
|
||||
|
19
inc/Memory.h
19
inc/Memory.h
@ -31,7 +31,6 @@ namespace EightBit {
|
||||
|
||||
class Memory {
|
||||
public:
|
||||
|
||||
Memory(uint16_t addressMask);
|
||||
virtual ~Memory();
|
||||
|
||||
@ -53,10 +52,10 @@ namespace EightBit {
|
||||
return DATA();
|
||||
}
|
||||
|
||||
virtual uint8_t peek(uint16_t address);
|
||||
virtual void poke(uint16_t address, uint8_t value);
|
||||
uint8_t peek(uint16_t address);
|
||||
void poke(uint16_t address, uint8_t value);
|
||||
|
||||
virtual uint16_t peekWord(uint16_t address);
|
||||
uint16_t peekWord(uint16_t address);
|
||||
|
||||
virtual int effectiveAddress(int address) const {
|
||||
return address & m_addressMask;
|
||||
@ -120,9 +119,15 @@ namespace EightBit {
|
||||
WrittenByte.fire(AddressEventArgs(ADDRESS().word, DATA()));
|
||||
}
|
||||
|
||||
virtual uint8_t& reference() {
|
||||
auto effective = effectiveAddress(ADDRESS().word);
|
||||
return m_locked[effective] ? placeDATA(m_bus[effective]) : referenceDATA(m_bus[effective]);
|
||||
virtual uint8_t& reference(uint16_t address, bool& rom) {
|
||||
rom = m_locked[address];
|
||||
return m_bus[address];
|
||||
}
|
||||
|
||||
uint8_t& reference() {
|
||||
bool rom;
|
||||
auto& value = reference(ADDRESS().word, rom);
|
||||
return rom ? placeDATA(value) : referenceDATA(value);
|
||||
}
|
||||
|
||||
int loadMemory(const std::string& path, uint16_t offset);
|
||||
|
@ -20,11 +20,13 @@ EightBit::Memory::~Memory() {
|
||||
}
|
||||
|
||||
uint8_t EightBit::Memory::peek(uint16_t address) {
|
||||
return m_bus[address];
|
||||
bool rom;
|
||||
return reference(address, rom);
|
||||
}
|
||||
|
||||
void EightBit::Memory::poke(uint16_t address, uint8_t value) {
|
||||
m_bus[address] = value;
|
||||
bool rom;
|
||||
reference(address, rom) = value;
|
||||
}
|
||||
|
||||
uint16_t EightBit::Memory::peekWord(uint16_t address) {
|
||||
|
Loading…
Reference in New Issue
Block a user