GB Memory: Support running from blocked memory
Vicki Pfau vi@endrift.com
Wed, 05 Dec 2018 19:39:29 -0800
2 files changed,
12 insertions(+),
0 deletions(-)
M
src/gb/memory.c
→
src/gb/memory.c
@@ -45,6 +45,8 @@ GB_BUS_RAM, // 0xC000
GB_BUS_CPU // 0xE000 }; +static const uint8_t _blockedRegion[1] = { 0xFF }; + static void _pristineCow(struct GB* gba); static uint8_t GBFastLoad8(struct LR35902Core* cpu, uint16_t address) {@@ -91,6 +93,15 @@ break;
default: cpu->memory.cpuLoad8 = GBLoad8; break; + } + if (gb->memory.dmaRemaining) { + const enum GBBus* block = gb->model < GB_MODEL_CGB ? _oamBlockDMG : _oamBlockCGB; + enum GBBus dmaBus = block[memory->dmaSource >> 13]; + enum GBBus accessBus = block[address >> 13]; + if ((dmaBus != GB_BUS_CPU && dmaBus == accessBus) || (address >= GB_BASE_OAM && address < GB_BASE_UNUSABLE)) { + cpu->memory.activeRegion = _blockedRegion; + cpu->memory.activeMask = 0; + } } }