all repos — mgba @ ddfffd22de0a1b726aa16c509a31f26a6ff54edd

mGBA Game Boy Advance Emulator

GBA Memory: Fix prefetch values in Thumb mode
Jeffrey Pfau jeffrey@endrift.com
Mon, 19 Jan 2015 01:16:18 -0800
commit

ddfffd22de0a1b726aa16c509a31f26a6ff54edd

parent

6d43fb78901d0a993c94756abd0a575c29e3f130

1 files changed, 20 insertions(+), 4 deletions(-)

jump to
M src/gba/gba-memory.csrc/gba/gba-memory.c

@@ -304,7 +304,11 @@ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address);

if (gba->performingDMA) { LOAD_16(value, address & 2, &gba->bus); } else { - LOAD_16(value, address & 2, &cpu->prefetch[1]); + uint32_t prefetch = cpu->prefetch[1]; + if (cpu->executionMode == MODE_THUMB) { + prefetch |= prefetch << 16; + } + LOAD_16(value, address & 2, &prefetch); } } break;

@@ -366,7 +370,11 @@ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load16: 0x%08X", address);

if (gba->performingDMA) { LOAD_16(value, address & 2, &gba->bus); } else { - LOAD_16(value, address & 2, &cpu->prefetch[1]); + uint32_t prefetch = cpu->prefetch[1]; + if (cpu->executionMode == MODE_THUMB) { + prefetch |= prefetch << 16; + } + LOAD_16(value, address & 2, &prefetch); } break; }

@@ -399,7 +407,11 @@ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load8: 0x%08x", address);

if (gba->performingDMA) { value = ((uint8_t*) &gba->bus)[address & 3]; } else { - value = ((uint8_t*) &cpu->prefetch[1])[address & 3]; + uint32_t prefetch = cpu->prefetch[1]; + if (cpu->executionMode == MODE_THUMB) { + prefetch |= prefetch << 16; + } + value = ((uint8_t*) &prefetch)[address & 3]; } } break;

@@ -463,7 +475,11 @@ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad memory Load8: 0x%08x", address);

if (gba->performingDMA) { value = ((uint8_t*) &gba->bus)[address & 3]; } else { - value = ((uint8_t*) &cpu->prefetch[1])[address & 3]; + uint32_t prefetch = cpu->prefetch[1]; + if (cpu->executionMode == MODE_THUMB) { + prefetch |= prefetch << 16; + } + value = ((uint8_t*) &prefetch)[address & 3]; } break; }