all repos — mgba @ 3acabb01c88bcd5f95bb2e9501657e288318675c

mGBA Game Boy Advance Emulator

Conglomerate save data initialization to ensure the struct is always initialized
Jeffrey Pfau jeffrey@endrift.com
Fri, 18 Oct 2013 08:36:05 -0700
commit

3acabb01c88bcd5f95bb2e9501657e288318675c

parent

d99bf7fdffb5a2787ea8030d668dd3eeb0b463b8

2 files changed, 4 insertions(+), 7 deletions(-)

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

@@ -317,7 +317,6 @@ break;

case BASE_CART_SRAM: wait = gbaMemory->waitstates16[address >> BASE_OFFSET]; if (gbaMemory->savedata.type == SAVEDATA_NONE) { - GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile); GBASavedataInitSRAM(&gbaMemory->savedata); } else if (gbaMemory->savedata.type == SAVEDATA_SRAM) { value = gbaMemory->savedata.data[address & (SIZE_CART_SRAM - 1)];

@@ -416,7 +415,6 @@ GBALog(gbaMemory->p, GBA_LOG_STUB, "Unimplemented memory Store16: 0x%08X", address);

break; case BASE_CART2_EX: if (gbaMemory->savedata.type == SAVEDATA_NONE) { - GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile); GBASavedataInitEEPROM(&gbaMemory->savedata); } GBASavedataWriteEEPROM(&gbaMemory->savedata, value, 1);

@@ -469,7 +467,6 @@ GBALog(gbaMemory->p, GBA_LOG_STUB, "Unimplemented memory Store8: 0x%08X", address);

break; case BASE_CART_SRAM: if (gbaMemory->savedata.type == SAVEDATA_NONE) { - GBASavedataInit(&gbaMemory->savedata, gbaMemory->p->savefile); if (address == SAVEDATA_FLASH_BASE) { GBASavedataInitFlash(&gbaMemory->savedata); } else {

@@ -723,7 +720,6 @@ dest += destOffset;

} } else if (destRegion == REGION_CART2_EX) { if (memory->savedata.type == SAVEDATA_NONE) { - GBASavedataInit(&memory->savedata, memory->p->savefile); GBASavedataInitEEPROM(&memory->savedata); } while (wordsRemaining) {
M src/gba/gba.csrc/gba/gba.c

@@ -38,6 +38,7 @@ void GBAInit(struct GBA* gba) {

gba->errno = GBA_NO_ERROR; gba->errstr = 0; gba->debugger = 0; + gba->savefile = 0; ARMInit(&gba->cpu);

@@ -281,6 +282,9 @@ gba->memory.rom = mmap(0, SIZE_CART0, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);

gba->activeFile = fname; fstat(fd, &info); gba->memory.romSize = info.st_size; + if (gba->savefile) { + GBASavedataInit(&gba->memory.savedata, gba->savefile); + } _checkOverrides(gba, ((struct GBACartridge*) gba->memory.rom)->id); // TODO: error check }

@@ -454,9 +458,6 @@ void _checkOverrides(struct GBA* gba, uint32_t id) {

int i; for (i = 0; _savedataOverrides[i].id; ++i) { if (_savedataOverrides[i].id == id) { - if (_savedataOverrides[i].type != SAVEDATA_NONE) { - GBASavedataInit(&gba->memory.savedata, gba->savefile); - } gba->memory.savedata.type = _savedataOverrides[i].type; switch (_savedataOverrides[i].type) { case SAVEDATA_FLASH512: