all repos — mgba @ a55a3cb4d4cad2f838e12ce27e61ad97b79dd525

mGBA Game Boy Advance Emulator

GBA: Refactor out savetype forcing
Jeffrey Pfau jeffrey@endrift.com
Tue, 30 Dec 2014 22:56:17 -0800
commit

a55a3cb4d4cad2f838e12ce27e61ad97b79dd525

parent

1e60a3011467aad08307bf3245789e8f1df93302

3 files changed, 21 insertions(+), 15 deletions(-)

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

@@ -109,6 +109,25 @@ }

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) { if (savedata->type == SAVEDATA_NONE) { savedata->type = SAVEDATA_FLASH512;
M src/gba/gba-savedata.hsrc/gba/gba-savedata.h

@@ -83,6 +83,7 @@

void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf); void GBASavedataUnmask(struct GBASavedata* savedata); bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out); +void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type); void GBASavedataInitFlash(struct GBASavedata* savedata); void GBASavedataInitEEPROM(struct GBASavedata* savedata);
M src/gba/gba.csrc/gba/gba.c

@@ -706,21 +706,7 @@ for (i = 0; _overrides[i].id[0]; ++i) {

const uint32_t* overrideId = (const uint32_t*) _overrides[i].id; if (*overrideId == id) { GBALog(gba, GBA_LOG_DEBUG, "Found override for game %s!", _overrides[i].id); - switch (_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; - } + GBASavedataForceType(&gba->memory.savedata, _overrides[i].type); if (_overrides[i].gpio & GPIO_RTC) { GBAGPIOInitRTC(&gba->memory.gpio);