mirror of https://github.com/mgba-emu/mgba.git
Conglomerate save data initialization to ensure the struct is always initialized
This commit is contained in:
parent
d99bf7fdff
commit
3acabb01c8
|
@ -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) {
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue