all repos — mgba @ f4fa4231351c6beb34f01c5e31231bca5db7ab94

mGBA Game Boy Advance Emulator

EEPROM only works in DMAs
Jeffrey Pfau jeffrey@endrift.com
Sat, 27 Apr 2013 20:39:14 -0700
commit

f4fa4231351c6beb34f01c5e31231bca5db7ab94

parent

4380ec0260036841fda2b4e539286553a7601ef2

1 files changed, 33 insertions(+), 12 deletions(-)

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

@@ -129,7 +129,9 @@ case BASE_CART1:

case BASE_CART1_EX: case BASE_CART2: case BASE_CART2_EX: - return gbaMemory->rom[(address & (SIZE_CART0 - 1)) >> 2]; + if ((address & (SIZE_CART0 - 1)) < gbaMemory->romSize) { + return gbaMemory->rom[(address & (SIZE_CART0 - 1)) >> 2]; + } case BASE_CART_SRAM: break; default:

@@ -163,7 +165,9 @@ case BASE_CART1:

case BASE_CART1_EX: case BASE_CART2: case BASE_CART2_EX: - return ((int16_t*) gbaMemory->rom)[(address & (SIZE_CART0 - 1)) >> 1]; + if ((address & (SIZE_CART0 - 1)) < gbaMemory->romSize) { + return ((int16_t*) gbaMemory->rom)[(address & (SIZE_CART0 - 1)) >> 1]; + } case BASE_CART_SRAM: break; default:

@@ -196,12 +200,9 @@ case BASE_CART0_EX:

case BASE_CART1: case BASE_CART1_EX: case BASE_CART2: - return ((uint16_t*) gbaMemory->rom)[(address & (SIZE_CART0 - 1)) >> 1]; case BASE_CART2_EX: if ((address & (SIZE_CART0 - 1)) < gbaMemory->romSize) { return ((uint16_t*) gbaMemory->rom)[(address & (SIZE_CART0 - 1)) >> 1]; - } else { - return GBASavedataReadEEPROM(&gbaMemory->savedata); } case BASE_CART_SRAM: break;

@@ -236,7 +237,9 @@ case BASE_CART1:

case BASE_CART1_EX: case BASE_CART2: case BASE_CART2_EX: - return ((int8_t*) gbaMemory->rom)[address & (SIZE_CART0 - 1)]; + if ((address & (SIZE_CART0 - 1)) < gbaMemory->romSize) { + return ((int8_t*) gbaMemory->rom)[address & (SIZE_CART0 - 1)]; + } case BASE_CART_SRAM: if (gbaMemory->savedata.type == SAVEDATA_NONE) { GBASavedataInitSRAM(&gbaMemory->savedata);

@@ -275,7 +278,9 @@ case BASE_CART1:

case BASE_CART1_EX: case BASE_CART2: case BASE_CART2_EX: - return ((uint8_t*) gbaMemory->rom)[address & (SIZE_CART0 - 1)]; + if ((address & (SIZE_CART0 - 1)) < gbaMemory->romSize) { + return ((uint8_t*) gbaMemory->rom)[address & (SIZE_CART0 - 1)]; + } case BASE_CART_SRAM: if (gbaMemory->savedata.type == SAVEDATA_NONE) { GBASavedataInitSRAM(&gbaMemory->savedata);

@@ -593,11 +598,27 @@ dest += destOffset;

} } else { uint16_t word; - while (wordsRemaining--) { - word = GBALoadU16(&memory->d, source); - GBAStore16(&memory->d, dest, word); - source += sourceOffset; - dest += destOffset; + if (source >> BASE_OFFSET == BASE_CART2_EX && memory->savedata.type == SAVEDATA_EEPROM) { + while (wordsRemaining--) { + word = GBASavedataReadEEPROM(&memory->savedata); + GBAStore16(&memory->d, dest, word); + source += sourceOffset; + dest += destOffset; + } + } else if (dest >> BASE_OFFSET == BASE_CART2_EX && memory->savedata.type == SAVEDATA_EEPROM) { + while (wordsRemaining--) { + word = GBALoadU16(&memory->d, source); + GBASavedataWriteEEPROM(&memory->savedata, word); + source += sourceOffset; + dest += destOffset; + } + } else { + while (wordsRemaining--) { + word = GBALoadU16(&memory->d, source); + GBAStore16(&memory->d, dest, word); + source += sourceOffset; + dest += destOffset; + } } }