all repos — mgba @ 8b9cd78d0f1451cec0cc560dfa17c27ca06420a0

mGBA Game Boy Advance Emulator

GBA Memory: Misaligned SRAM writes are ignored
Vicki Pfau vi@endrift.com
Thu, 23 Jan 2020 18:25:29 -0800
commit

8b9cd78d0f1451cec0cc560dfa17c27ca06420a0

parent

541715008bea659104a1705caa69a7bfd3f36637

2 files changed, 14 insertions(+), 8 deletions(-)

jump to
M CHANGESCHANGES

@@ -1,4 +1,6 @@

0.9.0: (Future) +Emulation fixes: + - GBA Memory: Misaligned SRAM writes are ignored Other fixes: - Qt: Only dynamically reset video scale if a game is running - Qt: Fix race condition with proxied video events
M src/gba/memory.csrc/gba/memory.c

@@ -772,12 +772,12 @@

#define STORE_SRAM \ if (address & 0x3) { \ mLOG(GBA_MEM, GAME_ERROR, "Unaligned SRAM Store32: 0x%08X", address); \ - value = 0; \ - } \ - GBAStore8(cpu, address & ~0x3, value, cycleCounter); \ - GBAStore8(cpu, (address & ~0x3) | 1, value, cycleCounter); \ - GBAStore8(cpu, (address & ~0x3) | 2, value, cycleCounter); \ - GBAStore8(cpu, (address & ~0x3) | 3, value, cycleCounter); + } else { \ + GBAStore8(cpu, address, value, cycleCounter); \ + GBAStore8(cpu, address | 1, value, cycleCounter); \ + GBAStore8(cpu, address | 2, value, cycleCounter); \ + GBAStore8(cpu, address | 3, value, cycleCounter); \ + } #define STORE_BAD \ mLOG(GBA_MEM, GAME_ERROR, "Bad memory Store32: 0x%08X", address);

@@ -923,8 +923,12 @@ mLOG(GBA_MEM, GAME_ERROR, "Bad memory Store16: 0x%08X", address);

break; case REGION_CART_SRAM: case REGION_CART_SRAM_MIRROR: - GBAStore8(cpu, (address & ~0x1), value, cycleCounter); - GBAStore8(cpu, (address & ~0x1) | 1, value, cycleCounter); + if (address & 1) { + mLOG(GBA_MEM, GAME_ERROR, "Unaligned SRAM Store16: 0x%08X", address); + break; + } + GBAStore8(cpu, address, value, cycleCounter); + GBAStore8(cpu, address | 1, value, cycleCounter); break; default: mLOG(GBA_MEM, GAME_ERROR, "Bad memory Store16: 0x%08X", address);