mirror of https://github.com/mgba-emu/mgba.git
GBA Memory: Fix Matrix memory bounding
This commit is contained in:
parent
79c40d9359
commit
3b1b890f3e
|
@ -11,6 +11,8 @@
|
||||||
#include <mgba/internal/gba/serialize.h>
|
#include <mgba/internal/gba/serialize.h>
|
||||||
#include <mgba-util/vfs.h>
|
#include <mgba-util/vfs.h>
|
||||||
|
|
||||||
|
#define MAPPING_MASK (GBA_MATRIX_MAPPINGS_MAX - 1)
|
||||||
|
|
||||||
static void _remapMatrix(struct GBA* gba) {
|
static void _remapMatrix(struct GBA* gba) {
|
||||||
if (gba->memory.matrix.vaddr & 0xFFFFE1FF) {
|
if (gba->memory.matrix.vaddr & 0xFFFFE1FF) {
|
||||||
mLOG(GBA_MEM, ERROR, "Invalid Matrix mapping: %08X", gba->memory.matrix.vaddr);
|
mLOG(GBA_MEM, ERROR, "Invalid Matrix mapping: %08X", gba->memory.matrix.vaddr);
|
||||||
|
@ -24,11 +26,11 @@ static void _remapMatrix(struct GBA* gba) {
|
||||||
mLOG(GBA_MEM, ERROR, "Invalid Matrix mapping end: %08X", gba->memory.matrix.vaddr + gba->memory.matrix.size);
|
mLOG(GBA_MEM, ERROR, "Invalid Matrix mapping end: %08X", gba->memory.matrix.vaddr + gba->memory.matrix.size);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int start = (gba->memory.matrix.vaddr >> 9) & 0x1F;
|
int start = gba->memory.matrix.vaddr >> 9;
|
||||||
int size = (gba->memory.matrix.size >> 9) & 0x1F;
|
int size = (gba->memory.matrix.size >> 9) & MAPPING_MASK;
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < size; ++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);
|
gba->romVf->seek(gba->romVf, gba->memory.matrix.paddr, SEEK_SET);
|
||||||
|
|
Loading…
Reference in New Issue