From 8b9cd78d0f1451cec0cc560dfa17c27ca06420a0 Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Thu, 23 Jan 2020 18:25:29 -0800 Subject: [PATCH] GBA Memory: Misaligned SRAM writes are ignored --- CHANGES | 2 ++ src/gba/memory.c | 20 ++++++++++++-------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 6c06fad42..e565468c4 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/src/gba/memory.c b/src/gba/memory.c index 091bfa1e1..d2ba5a419 100644 --- a/src/gba/memory.c +++ b/src/gba/memory.c @@ -772,12 +772,12 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) { #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 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle 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);