Conglomerate save data initialization to ensure the struct is always initialized

This commit is contained in:
Jeffrey Pfau 2013-10-18 08:36:05 -07:00
parent d99bf7fdff
commit 3acabb01c8
2 changed files with 4 additions and 7 deletions

View File

@ -317,7 +317,6 @@ int8_t GBALoad8(struct ARMMemory* memory, uint32_t address, int* cycleCounter) {
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 @@ void GBAStore16(struct ARMMemory* memory, uint32_t address, int16_t value, int*
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 @@ void GBAStore8(struct ARMMemory* memory, uint32_t address, int8_t value, int* cy
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 @@ void GBAMemoryServiceDMA(struct GBAMemory* memory, int number, struct GBADMA* in
}
} else if (destRegion == REGION_CART2_EX) {
if (memory->savedata.type == SAVEDATA_NONE) {
GBASavedataInit(&memory->savedata, memory->p->savefile);
GBASavedataInitEEPROM(&memory->savedata);
}
while (wordsRemaining) {

View File

@ -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 @@ void GBALoadROM(struct GBA* gba, int fd, const char* fname) {
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: