Add an address masking to the memory mapping structure.

Signed-off-by: Adrian Conlon <Adrian.conlon@gmail.com>
This commit is contained in:
Adrian Conlon 2018-11-01 23:43:29 +00:00
parent 7af81018c9
commit 68a785ceec
10 changed files with 24 additions and 23 deletions

View File

@ -21,7 +21,7 @@ public:
protected:
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite };
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
}
private:

View File

@ -38,7 +38,7 @@ namespace Fuse {
protected:
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite };
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
}
public:

View File

@ -164,31 +164,31 @@ void EightBit::GameBoy::Bus::validateCartridgeType() {
EightBit::MemoryMapping EightBit::GameBoy::Bus::mapping(uint16_t address) {
if ((address < 0x100) && IO().bootRomEnabled())
return { m_bootRom, 0x0000, MemoryMapping::ReadOnly };
return { m_bootRom, 0x0000, 0xffff, MemoryMapping::ReadOnly };
if ((address < 0x4000) && gameRomEnabled())
return { m_gameRomBanks[0], 0x0000, MemoryMapping::ReadOnly };
return { m_gameRomBanks[0], 0x0000, 0xffff, MemoryMapping::ReadOnly };
if ((address < 0x8000) && gameRomEnabled())
return { m_gameRomBanks[m_romBank], 0x4000, MemoryMapping::ReadOnly };
return { m_gameRomBanks[m_romBank], 0x4000, 0xffff, MemoryMapping::ReadOnly };
if (address < 0xa000)
return { VRAM(), 0x8000, MemoryMapping::ReadWrite };
return { VRAM(), 0x8000, 0xffff, MemoryMapping::ReadWrite };
if (address < 0xc000) {
if (m_ramBanks.size() == 0)
return { m_unmapped2000, 0xa000, MemoryMapping::ReadOnly };
return { m_unmapped2000, 0xa000, 0xffff, MemoryMapping::ReadOnly };
else
return { m_ramBanks[m_ramBank], 0xa000, MemoryMapping::ReadWrite };
return { m_ramBanks[m_ramBank], 0xa000, 0xffff, MemoryMapping::ReadWrite };
}
if (address < 0xe000)
return { m_lowInternalRam, 0xc000, MemoryMapping::ReadWrite };
return { m_lowInternalRam, 0xc000, 0xffff, MemoryMapping::ReadWrite };
if (address < 0xfe00)
return { m_lowInternalRam, 0xe000, MemoryMapping::ReadWrite }; // Low internal RAM mirror
return { m_lowInternalRam, 0xe000, 0xffff, MemoryMapping::ReadWrite }; // Low internal RAM mirror
if (address < 0xfea0)
return { OAMRAM(), 0xfe00, MemoryMapping::ReadWrite };
return { OAMRAM(), 0xfe00, 0xffff, MemoryMapping::ReadWrite };
if (address < IoRegisters::BASE)
return { m_unmapped60, 0xfea0, MemoryMapping::ReadOnly };
return { m_unmapped60, 0xfea0, 0xffff, MemoryMapping::ReadOnly };
if (address < 0xff80)
return { IO(), IoRegisters::BASE, MemoryMapping::ReadWrite };
return { m_highInternalRam, 0xff80, MemoryMapping::ReadWrite };
return { IO(), IoRegisters::BASE, 0xffff, MemoryMapping::ReadWrite };
return { m_highInternalRam, 0xff80, 0xffff, MemoryMapping::ReadWrite };
}
int EightBit::GameBoy::Bus::runRasterLines() {

View File

@ -21,7 +21,7 @@ public:
protected:
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite };
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
}
private:

View File

@ -60,15 +60,15 @@ void Board::Cpu_ExecutedInstruction_Debug(EightBit::mc6809&) {
EightBit::MemoryMapping Board::mapping(uint16_t address) {
if (address < 0x8000)
return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite };
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
if (address < 0xa000)
return { m_unused2000, 0x8000, EightBit::MemoryMapping::ReadOnly };
return { m_unused2000, 0x8000, 0xffff, EightBit::MemoryMapping::ReadOnly };
if (address < 0xc000)
return { m_io, 0xa000, EightBit::MemoryMapping::ReadWrite };
return { m_io, 0xa000, 0xffff, EightBit::MemoryMapping::ReadWrite };
return { m_rom, 0xc000, EightBit::MemoryMapping::ReadOnly };
return { m_rom, 0xc000, 0xffff, EightBit::MemoryMapping::ReadOnly };
}
void Board::Bus_WrittenByte_Acia(EightBit::EventArgs&) {

View File

@ -13,5 +13,5 @@ void Board::initialise() {
}
EightBit::MemoryMapping Board::mapping(uint16_t) {
return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite };
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
}

View File

@ -37,7 +37,7 @@ namespace Fuse {
protected:
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite };
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
}
public:

View File

@ -22,7 +22,7 @@ public:
protected:
virtual EightBit::MemoryMapping mapping(uint16_t address) final {
return { m_ram, 0x0000, EightBit::MemoryMapping::ReadWrite };
return { m_ram, 0x0000, 0xffff, EightBit::MemoryMapping::ReadWrite };
}
private:

View File

@ -11,6 +11,7 @@ namespace EightBit {
Memory& memory;
uint16_t begin = 0xffff;
uint16_t mask = 0U;
AccessLevel access = Unknown;
};
}

View File

@ -90,7 +90,7 @@ std::map<uint16_t, std::vector<uint8_t>> EightBit::Bus::parseHexFile(const std::
uint8_t& EightBit::Bus::reference(const uint16_t address) {
const auto mapped = mapping(address);
const uint16_t offset = address - mapped.begin;
const uint16_t offset = (address - mapped.begin) & mapped.mask;
if (mapped.access == MemoryMapping::ReadOnly)
return DATA() = mapped.memory.peek(offset);
Ram& ram = (Ram&)(mapped.memory);