From 2388342a1afb8e90caacfbd24c31f155ba995ccc Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Fri, 18 Jun 2021 01:00:18 -0700 Subject: [PATCH] GBA Memory: Fix prefetch mask when swapping modes within a region --- CHANGES | 1 + src/gba/memory.c | 6 ++++++ src/gba/serialize.c | 1 + 3 files changed, 8 insertions(+) diff --git a/CHANGES b/CHANGES index c8f691b77..6ee9b0f91 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ Emulation fixes: - GB Video: Clear VRAM on reset (fixes mgba.io/i/2152) - GBA SIO: Add missing NORMAL8 implementation bits (fixes mgba.io/i/2172) - GBA SIO: Fix missing interrupt on an unattached NORMAL transfer + - GBA Memory: Fix prefetch mask when swapping modes within a region - GBA Video: Revert scanline latching changes (fixes mgba.io/i/2153, mgba.io/i/2149) Other fixes: - 3DS: Fix disabling "wide" mode on 2DS (fixes mgba.io/i/2167) diff --git a/src/gba/memory.c b/src/gba/memory.c index 05cec7c67..6a1631c5e 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -121,6 +121,7 @@ void GBAMemoryReset(struct GBA* gba) { memset(gba->memory.io, 0, sizeof(gba->memory.io)); GBAAdjustWaitstates(gba, 0); + gba->memory.activeRegion = -1; gba->memory.agbPrintProtect = 0; gba->memory.agbPrintBase = 0; memset(&gba->memory.agbPrintCtx, 0, sizeof(gba->memory.agbPrintCtx)); @@ -260,6 +261,11 @@ static void GBASetActiveRegion(struct ARMCore* cpu, uint32_t address) { gba->lastJump = address; memory->lastPrefetchedPc = 0; if (newRegion == memory->activeRegion) { + if (cpu->cpsr.t) { + cpu->memory.activeMask |= WORD_SIZE_THUMB; + } else { + cpu->memory.activeMask &= -WORD_SIZE_ARM; + } if (newRegion < REGION_CART0 || (address & (SIZE_CART0 - 1)) < memory->romSize) { return; } diff --git a/src/gba/serialize.c b/src/gba/serialize.c index 022d7b92f..d3ce97d1c 100644 --- a/src/gba/serialize.c +++ b/src/gba/serialize.c @@ -158,6 +158,7 @@ bool GBADeserialize(struct GBA* gba, const struct GBASerializedState* state) { mLOG(GBA_STATE, WARN, "Savestate has unaligned PC and is probably corrupted"); gba->cpu->gprs[ARM_PC] &= ~1; } + gba->memory.activeRegion = -1; gba->cpu->memory.setActiveRegion(gba->cpu, gba->cpu->gprs[ARM_PC]); if (state->biosPrefetch) { LOAD_32(gba->memory.biosPrefetch, 0, &state->biosPrefetch);