Skip to content

Commit 0eba709

Browse files
committed
GBA Core: Flush pipeline if CPSR is directly written
1 parent 69c99d4 commit 0eba709

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ Other fixes:
4747
- Debugger: Fix writing to specific segment in command-line debugger
4848
- GB Video: Fix video log replaying freezing when video is disabled
4949
- GBA: Fix getting game info for multiboot ROMs
50+
- GBA Core: Flush pipeline if CPSR is directly written
5051
- GBA e-Reader: Early-exit when processing 0-sized lists
5152
- mGUI: Load parent directory if last used directory is missing (fixes mgba.io/i/3379)
5253
- Qt: Fix savestate preview sizes with different scales (fixes mgba.io/i/2560)

src/gba/core.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,21 @@ static bool _GBACoreWriteRegister(struct mCore* core, const char* name, const vo
12631263
case 'c':
12641264
case 'C':
12651265
if (strcmp(name, "cpsr") == 0) {
1266+
uint32_t pc = cpu->gprs[ARM_PC] & -WORD_SIZE_THUMB;
1267+
enum ExecutionMode mode = cpu->cpsr.t;
12661268
cpu->cpsr.packed = value & 0xF00000FF;
12671269
_ARMReadCPSR(cpu);
1270+
if (mode != cpu->cpsr.t) {
1271+
// Mode changed, flush the prefetch
1272+
if (cpu->cpsr.t == MODE_ARM) {
1273+
pc &= -WORD_SIZE_ARM;
1274+
LOAD_32(cpu->prefetch[0], (pc - WORD_SIZE_ARM) & cpu->memory.activeMask, cpu->memory.activeRegion);
1275+
LOAD_32(cpu->prefetch[1], pc & cpu->memory.activeMask, cpu->memory.activeRegion);
1276+
} else {
1277+
LOAD_16(cpu->prefetch[0], (pc - WORD_SIZE_THUMB) & cpu->memory.activeMask, cpu->memory.activeRegion);
1278+
LOAD_16(cpu->prefetch[1], pc & cpu->memory.activeMask, cpu->memory.activeRegion);
1279+
}
1280+
}
12681281
return true;
12691282
}
12701283
return false;

0 commit comments

Comments
 (0)