GBA Memory: Misaligned SRAM writes are ignored
Vicki Pfau vi@endrift.com
Thu, 23 Jan 2020 18:25:29 -0800
2 files changed,
14 insertions(+),
8 deletions(-)
M
src/gba/memory.c
→
src/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);