mirror of
https://github.com/MoleskiCoder/EightBit.git
synced 2024-09-01 15:29:11 +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 loadBootRom(const std::string& path);
|
||||||
void loadGameRom(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:
|
private:
|
||||||
std::vector<uint8_t> m_bootRom;
|
std::vector<uint8_t> m_bootRom;
|
||||||
std::vector<uint8_t> m_gameRom;
|
std::vector<uint8_t> m_gameRom;
|
||||||
@ -214,6 +209,6 @@ namespace EightBit {
|
|||||||
|
|
||||||
void validateCartridgeType();
|
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];
|
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) {
|
void EightBit::Bus::Bus_WrittenByte(const AddressEventArgs& e) {
|
||||||
|
|
||||||
const auto address = e.getAddress();
|
const auto address = e.getAddress();
|
||||||
@ -90,7 +74,7 @@ void EightBit::Bus::Bus_WrittenByte(const AddressEventArgs& e) {
|
|||||||
m_disableBootRom = value != 0;
|
m_disableBootRom = value != 0;
|
||||||
break;
|
break;
|
||||||
case BASE + DIV:
|
case BASE + DIV:
|
||||||
reference() = 0;
|
Memory::reference() = 0;
|
||||||
m_timerCounter = 0;
|
m_timerCounter = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
19
inc/Memory.h
19
inc/Memory.h
@ -31,7 +31,6 @@ namespace EightBit {
|
|||||||
|
|
||||||
class Memory {
|
class Memory {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Memory(uint16_t addressMask);
|
Memory(uint16_t addressMask);
|
||||||
virtual ~Memory();
|
virtual ~Memory();
|
||||||
|
|
||||||
@ -53,10 +52,10 @@ namespace EightBit {
|
|||||||
return DATA();
|
return DATA();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint8_t peek(uint16_t address);
|
uint8_t peek(uint16_t address);
|
||||||
virtual void poke(uint16_t address, uint8_t value);
|
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 {
|
virtual int effectiveAddress(int address) const {
|
||||||
return address & m_addressMask;
|
return address & m_addressMask;
|
||||||
@ -120,9 +119,15 @@ namespace EightBit {
|
|||||||
WrittenByte.fire(AddressEventArgs(ADDRESS().word, DATA()));
|
WrittenByte.fire(AddressEventArgs(ADDRESS().word, DATA()));
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual uint8_t& reference() {
|
virtual uint8_t& reference(uint16_t address, bool& rom) {
|
||||||
auto effective = effectiveAddress(ADDRESS().word);
|
rom = m_locked[address];
|
||||||
return m_locked[effective] ? placeDATA(m_bus[effective]) : referenceDATA(m_bus[effective]);
|
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);
|
int loadMemory(const std::string& path, uint16_t offset);
|
||||||
|
@ -20,11 +20,13 @@ EightBit::Memory::~Memory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t EightBit::Memory::peek(uint16_t address) {
|
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) {
|
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) {
|
uint16_t EightBit::Memory::peekWord(uint16_t address) {
|
||||||
|
Loading…
Reference in New Issue
Block a user