From 0332db8961ef1b11b4f9e0326d3683b8e5d17730 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Wed, 5 Dec 2018 19:39:29 -0800 Subject: [PATCH] GB Memory: Support running from blocked memory --- CHANGES | 1 + src/gb/memory.c | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGES b/CHANGES index 1753ee27a..d9fc51a9f 100644 --- a/CHANGES +++ b/CHANGES @@ -6,6 +6,7 @@ Bugfixes: Misc: - GBA Savedata: EEPROM performance fixes - GBA Savedata: Automatically map 1Mbit Flash files as 1Mbit Flash + - GB Memory: Support running from blocked memory 0.7.0: (Future) Features: diff --git a/src/gb/memory.c b/src/gb/memory.c index b2e229c4d..15ef917ad 100644 --- a/src/gb/memory.c +++ b/src/gb/memory.c @@ -45,6 +45,8 @@ static const enum GBBus _oamBlockCGB[] = { 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) { @@ -92,6 +94,15 @@ static void GBSetActiveRegion(struct LR35902Core* cpu, uint16_t address) { 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; + } + } } static void _GBMemoryDMAService(struct mTiming* timing, void* context, uint32_t cyclesLate);