From f8341f2d205f12e53c643919ade3b269e6a4159b Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 27 Sep 2013 02:07:44 -0700 Subject: [PATCH] Rotate 16-bit unaligned loads --- src/gba/gba-memory.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/gba/gba-memory.c b/src/gba/gba-memory.c index c612d07ac..d1cc76fac 100644 --- a/src/gba/gba-memory.c +++ b/src/gba/gba-memory.c @@ -231,7 +231,9 @@ int16_t GBALoad16(struct ARMMemory* memory, uint32_t address, int* cycleCounter) if (cycleCounter) { *cycleCounter += 2 + wait; } - return value; + // Unaligned 16-bit loads are "unpredictable", but the GBA rotates them, so we have to, too. + int rotate = (address & 1) << 3; + return (value >> rotate) | ((value << rotate) & 0xFF00); } uint8_t GBALoadU8(struct ARMMemory* memory, uint32_t address, int* cycleCounter) {