GBA: Refactor out savetype forcing

This commit is contained in:
Jeffrey Pfau 2014-12-30 22:56:17 -08:00
parent 1e60a30114
commit a55a3cb4d4
3 changed files with 21 additions and 15 deletions

View File

@ -109,6 +109,25 @@ bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out) {
return true; return true;
} }
void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type) {
switch (type) {
case SAVEDATA_FLASH512:
case SAVEDATA_FLASH1M:
savedata->type = type;
GBASavedataInitFlash(savedata);
break;
case SAVEDATA_EEPROM:
GBASavedataInitEEPROM(savedata);
break;
case SAVEDATA_SRAM:
GBASavedataInitSRAM(savedata);
break;
case SAVEDATA_NONE:
// TODO: Force none
break;
}
}
void GBASavedataInitFlash(struct GBASavedata* savedata) { void GBASavedataInitFlash(struct GBASavedata* savedata) {
if (savedata->type == SAVEDATA_NONE) { if (savedata->type == SAVEDATA_NONE) {
savedata->type = SAVEDATA_FLASH512; savedata->type = SAVEDATA_FLASH512;

View File

@ -83,6 +83,7 @@ void GBASavedataDeinit(struct GBASavedata* savedata);
void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf); void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf);
void GBASavedataUnmask(struct GBASavedata* savedata); void GBASavedataUnmask(struct GBASavedata* savedata);
bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out); bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out);
void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type);
void GBASavedataInitFlash(struct GBASavedata* savedata); void GBASavedataInitFlash(struct GBASavedata* savedata);
void GBASavedataInitEEPROM(struct GBASavedata* savedata); void GBASavedataInitEEPROM(struct GBASavedata* savedata);

View File

@ -706,21 +706,7 @@ void _checkOverrides(struct GBA* gba, uint32_t id) {
const uint32_t* overrideId = (const uint32_t*) _overrides[i].id; const uint32_t* overrideId = (const uint32_t*) _overrides[i].id;
if (*overrideId == id) { if (*overrideId == id) {
GBALog(gba, GBA_LOG_DEBUG, "Found override for game %s!", _overrides[i].id); GBALog(gba, GBA_LOG_DEBUG, "Found override for game %s!", _overrides[i].id);
switch (_overrides[i].type) { GBASavedataForceType(&gba->memory.savedata, _overrides[i].type);
case SAVEDATA_FLASH512:
case SAVEDATA_FLASH1M:
gba->memory.savedata.type = _overrides[i].type;
GBASavedataInitFlash(&gba->memory.savedata);
break;
case SAVEDATA_EEPROM:
GBASavedataInitEEPROM(&gba->memory.savedata);
break;
case SAVEDATA_SRAM:
GBASavedataInitSRAM(&gba->memory.savedata);
break;
case SAVEDATA_NONE:
break;
}
if (_overrides[i].gpio & GPIO_RTC) { if (_overrides[i].gpio & GPIO_RTC) {
GBAGPIOInitRTC(&gba->memory.gpio); GBAGPIOInitRTC(&gba->memory.gpio);