GBA Memory: Fix Matrix memory bounding
Vicki Pfau vi@endrift.com
Sat, 23 Jan 2021 19:06:04 -0800
1 files changed,
5 insertions(+),
3 deletions(-)
jump to
M
src/gba/matrix.c
→
src/gba/matrix.c
@@ -11,6 +11,8 @@ #include <mgba/internal/gba/memory.h>
#include <mgba/internal/gba/serialize.h> #include <mgba-util/vfs.h> +#define MAPPING_MASK (GBA_MATRIX_MAPPINGS_MAX - 1) + static void _remapMatrix(struct GBA* gba) { if (gba->memory.matrix.vaddr & 0xFFFFE1FF) { mLOG(GBA_MEM, ERROR, "Invalid Matrix mapping: %08X", gba->memory.matrix.vaddr);@@ -24,11 +26,11 @@ if ((gba->memory.matrix.vaddr + gba->memory.matrix.size - 1) & 0xFFFFE000) {
mLOG(GBA_MEM, ERROR, "Invalid Matrix mapping end: %08X", gba->memory.matrix.vaddr + gba->memory.matrix.size); return; } - int start = (gba->memory.matrix.vaddr >> 9) & 0x1F; - int size = (gba->memory.matrix.size >> 9) & 0x1F; + int start = gba->memory.matrix.vaddr >> 9; + int size = (gba->memory.matrix.size >> 9) & MAPPING_MASK; int i; for (i = 0; i < size; ++i) { - gba->memory.matrix.mappings[start + i] = gba->memory.matrix.paddr + (i << 9); + gba->memory.matrix.mappings[(start + i) & MAPPING_MASK] = gba->memory.matrix.paddr + (i << 9); } gba->romVf->seek(gba->romVf, gba->memory.matrix.paddr, SEEK_SET);