From 773e0d26ffd5e15c99d50bc6e5cb66fe167d85f4 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sat, 6 Jul 2019 16:13:39 -0700 Subject: [PATCH] GB Memory: Better emulate 0xFEA0 region on DMG, MGB and AGB --- CHANGES | 1 + src/gb/memory.c | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index a8304684e..b0e021ceb 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,7 @@ Emulation fixes: - GB Audio: Deschedule channel 1 when disabled by sweep (fixes mgba.io/i/1467) - GBA Memory: Fix STM/LDM to invalid VRAM - GB: Fix savedata initialization (fixes mgba.io/i/1473, mgba.io/i/1478) + - GB Memory: Better emulate 0xFEA0 region on DMG, MGB and AGB Other fixes: - Qt: Fix some Qt display driver race conditions - Core: Improved lockstep driver reliability (Le Hoang Quyen) diff --git a/src/gb/memory.c b/src/gb/memory.c index 15ef917ad..b3b9b8bcf 100644 --- a/src/gb/memory.c +++ b/src/gb/memory.c @@ -234,7 +234,7 @@ uint8_t GBLoad8(struct LR35902Core* cpu, uint16_t address) { if (dmaBus != GB_BUS_CPU && dmaBus == accessBus) { return 0xFF; } - if (address >= GB_BASE_OAM && address < GB_BASE_UNUSABLE) { + if (address >= GB_BASE_OAM && address < GB_BASE_IO) { return 0xFF; } } @@ -471,6 +471,17 @@ uint8_t GBView8(struct LR35902Core* cpu, uint16_t address, int segment) { } if (address < GB_BASE_IO) { mLOG(GB_MEM, GAME_ERROR, "Attempt to read from unusable memory: %04X", address); + if (gb->video.mode < 2) { + switch (gb->model) { + case GB_MODEL_AGB: + return (address & 0xF0) | ((address >> 4) & 0xF); + case GB_MODEL_CGB: + // TODO: R/W behavior + return 0x00; + default: + return 0x00; + } + } return 0xFF; } if (address < GB_BASE_HRAM) {