diff --git a/CHANGES b/CHANGES index ac1e26b5f..6ccbb6823 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,7 @@ Features: Bugfixes: - GB Audio: Make audio unsigned with bias (fixes mgba.io/i/749) - Python: Fix importing .gb or .gba before .core + - GBA: Reset active region as needed when loading a ROM Misc: - GBA Timer: Use global cycles for timers - GBA: Extend oddly-sized ROMs to full address space (fixes mgba.io/i/722) diff --git a/src/gba/gba.c b/src/gba/gba.c index fb3680cc0..3baaea232 100644 --- a/src/gba/gba.c +++ b/src/gba/gba.c @@ -312,6 +312,10 @@ bool GBALoadNull(struct GBA* gba) { gba->memory.romMask = SIZE_CART0 - 1; gba->memory.mirroring = false; gba->romCrc32 = 0; + + if (gba->cpu) { + gba->cpu->memory.setActiveRegion(gba->cpu, gba->cpu->gprs[ARM_PC]); + } return true; } @@ -335,6 +339,9 @@ bool GBALoadMB(struct GBA* gba, struct VFile* vf) { gba->memory.romSize = 0; gba->memory.romMask = 0; gba->romCrc32 = doCrc32(gba->memory.wram, gba->pristineRomSize); + if (gba->cpu && gba->memory.activeRegion == REGION_WORKING_RAM) { + gba->cpu->memory.setActiveRegion(gba->cpu, gba->cpu->gprs[ARM_PC]); + } return true; } @@ -379,6 +386,9 @@ bool GBALoadROM(struct GBA* gba, struct VFile* vf) { gba->memory.romSize = SIZE_CART0; gba->isPristine = false; } + if (gba->cpu && gba->memory.activeRegion >= REGION_CART0) { + gba->cpu->memory.setActiveRegion(gba->cpu, gba->cpu->gprs[ARM_PC]); + } // TODO: error check return true; }