GBA: Split out save autodetect from no save present
Jeffrey Pfau jeffrey@endrift.com
Mon, 12 Jan 2015 00:59:48 -0800
5 files changed,
26 insertions(+),
17 deletions(-)
M
src/gba/gba-memory.c
→
src/gba/gba-memory.c
@@ -430,7 +430,7 @@ break;
case REGION_CART_SRAM: case REGION_CART_SRAM_MIRROR: wait = memory->waitstatesNonseq16[address >> BASE_OFFSET]; - if (memory->savedata.type == SAVEDATA_NONE) { + if (memory->savedata.type == SAVEDATA_AUTODETECT) { GBALog(gba, GBA_LOG_INFO, "Detected SRAM savegame"); GBASavedataInitSRAM(&memory->savedata); }@@ -586,7 +586,7 @@ GBALog(gba, GBA_LOG_GAME_ERROR, "Bad cartridge Store16: 0x%08X", address);
} break; case REGION_CART2_EX: - if (memory->savedata.type == SAVEDATA_NONE) { + if (memory->savedata.type == SAVEDATA_AUTODETECT) { GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame"); GBASavedataInitEEPROM(&memory->savedata); }@@ -642,7 +642,7 @@ GBALog(gba, GBA_LOG_STUB, "Unimplemented memory Store8: 0x%08X", address);
break; case REGION_CART_SRAM: case REGION_CART_SRAM_MIRROR: - if (memory->savedata.type == SAVEDATA_NONE) { + if (memory->savedata.type == SAVEDATA_AUTODETECT) { if (address == SAVEDATA_FLASH_BASE) { GBALog(gba, GBA_LOG_INFO, "Detected Flash savegame"); GBASavedataInitFlash(&memory->savedata);@@ -1142,7 +1142,7 @@ source += sourceOffset;
dest += destOffset; --wordsRemaining; } else if (destRegion == REGION_CART2_EX) { - if (memory->savedata.type == SAVEDATA_NONE) { + if (memory->savedata.type == SAVEDATA_AUTODETECT) { GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame"); GBASavedataInitEEPROM(&memory->savedata); }
M
src/gba/gba-savedata.c
→
src/gba/gba-savedata.c
@@ -18,7 +18,7 @@ static void _flashErase(struct GBASavedata* savedata);
static void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart); void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) { - savedata->type = SAVEDATA_NONE; + savedata->type = SAVEDATA_AUTODETECT; savedata->data = 0; savedata->command = EEPROM_COMMAND_NULL; savedata->flashState = FLASH_STATE_RAW;@@ -42,7 +42,8 @@ break;
case SAVEDATA_EEPROM: savedata->vf->unmap(savedata->vf, savedata->data, SIZE_CART_EEPROM); break; - case SAVEDATA_NONE: + case SAVEDATA_FORCE_NONE: + case SAVEDATA_AUTODETECT: break; } savedata->vf = 0;@@ -60,12 +61,13 @@ break;
case SAVEDATA_EEPROM: mappedMemoryFree(savedata->data, SIZE_CART_EEPROM); break; - case SAVEDATA_NONE: + case SAVEDATA_FORCE_NONE: + case SAVEDATA_AUTODETECT: break; } } savedata->data = 0; - savedata->type = SAVEDATA_NONE; + savedata->type = SAVEDATA_AUTODETECT; } void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf) {@@ -94,7 +96,8 @@ case SAVEDATA_FLASH1M:
return out->write(out, savedata->data, SIZE_CART_FLASH1M) == SIZE_CART_FLASH1M; case SAVEDATA_EEPROM: return out->write(out, savedata->data, SIZE_CART_EEPROM) == SIZE_CART_EEPROM; - case SAVEDATA_NONE: + case SAVEDATA_AUTODETECT: + case SAVEDATA_FORCE_NONE: return true; } } else if (savedata->vf) {@@ -122,14 +125,16 @@ break;
case SAVEDATA_SRAM: GBASavedataInitSRAM(savedata); break; - case SAVEDATA_NONE: - // TODO: Force none + case SAVEDATA_FORCE_NONE: + savedata->type = SAVEDATA_FORCE_NONE; + break; + case SAVEDATA_AUTODETECT: break; } } void GBASavedataInitFlash(struct GBASavedata* savedata) { - if (savedata->type == SAVEDATA_NONE) { + if (savedata->type == SAVEDATA_AUTODETECT) { savedata->type = SAVEDATA_FLASH512; } if (savedata->type != SAVEDATA_FLASH512 && savedata->type != SAVEDATA_FLASH1M) {@@ -157,7 +162,7 @@ }
} void GBASavedataInitEEPROM(struct GBASavedata* savedata) { - if (savedata->type == SAVEDATA_NONE) { + if (savedata->type == SAVEDATA_AUTODETECT) { savedata->type = SAVEDATA_EEPROM; } else { GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata");@@ -180,7 +185,7 @@ }
} void GBASavedataInitSRAM(struct GBASavedata* savedata) { - if (savedata->type == SAVEDATA_NONE) { + if (savedata->type == SAVEDATA_AUTODETECT) { savedata->type = SAVEDATA_SRAM; } else { GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata");
M
src/gba/gba-savedata.h
→
src/gba/gba-savedata.h
@@ -11,7 +11,8 @@
struct VFile; enum SavedataType { - SAVEDATA_NONE = 0, + SAVEDATA_AUTODETECT = -1, + SAVEDATA_FORCE_NONE = 0, SAVEDATA_SRAM, SAVEDATA_FLASH512, SAVEDATA_FLASH1M,
M
src/gba/gba.c
→
src/gba/gba.c
@@ -109,6 +109,9 @@ { "AX4J", SAVEDATA_FLASH1M, GPIO_NONE, -1 },
{ "AX4E", SAVEDATA_FLASH1M, GPIO_NONE, -1 }, { "AX4P", SAVEDATA_FLASH1M, GPIO_NONE, -1 }, + // Top Gun - Combat Zones + { "A2YE", SAVEDATA_FORCE_NONE, GPIO_NONE, -1 }, + // Wario Ware Twisted { "RZWJ", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO, -1 }, { "RZWE", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO, -1 },
M
src/platform/qt/GamePakView.cpp
→
src/platform/qt/GamePakView.cpp
@@ -50,7 +50,7 @@ return;
} SavedataType savetype = thread->gba->memory.savedata.type; if (m_ui.savetype->currentIndex() > 0) { - if (savetype > SAVEDATA_NONE) { + if (savetype > SAVEDATA_FORCE_NONE) { VFile* vf = thread->gba->memory.savedata.vf; GBASavedataDeinit(&thread->gba->memory.savedata); GBASavedataInit(&thread->gba->memory.savedata, vf);@@ -59,7 +59,7 @@ savetype = static_cast<SavedataType>(m_ui.savetype->currentIndex() - 1);
GBASavedataForceType(&thread->gba->memory.savedata, savetype); } - if (savetype > SAVEDATA_NONE) { + if (savetype > SAVEDATA_AUTODETECT) { m_ui.savetype->setCurrentIndex(savetype + 1); } m_ui.savetype->setEnabled(false);