GBA: Split out save autodetect from no save present

This commit is contained in:
Jeffrey Pfau 2015-01-12 00:59:48 -08:00
parent 19648c786d
commit eced06bc2a
5 changed files with 26 additions and 17 deletions

View File

@ -430,7 +430,7 @@ uint32_t GBALoad8(struct ARMCore* cpu, uint32_t address, int* cycleCounter) {
case REGION_CART_SRAM: case REGION_CART_SRAM:
case REGION_CART_SRAM_MIRROR: case REGION_CART_SRAM_MIRROR:
wait = memory->waitstatesNonseq16[address >> BASE_OFFSET]; 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"); GBALog(gba, GBA_LOG_INFO, "Detected SRAM savegame");
GBASavedataInitSRAM(&memory->savedata); GBASavedataInitSRAM(&memory->savedata);
} }
@ -586,7 +586,7 @@ void GBAStore16(struct ARMCore* cpu, uint32_t address, int16_t value, int* cycle
} }
break; break;
case REGION_CART2_EX: case REGION_CART2_EX:
if (memory->savedata.type == SAVEDATA_NONE) { if (memory->savedata.type == SAVEDATA_AUTODETECT) {
GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame"); GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame");
GBASavedataInitEEPROM(&memory->savedata); GBASavedataInitEEPROM(&memory->savedata);
} }
@ -642,7 +642,7 @@ void GBAStore8(struct ARMCore* cpu, uint32_t address, int8_t value, int* cycleCo
break; break;
case REGION_CART_SRAM: case REGION_CART_SRAM:
case REGION_CART_SRAM_MIRROR: case REGION_CART_SRAM_MIRROR:
if (memory->savedata.type == SAVEDATA_NONE) { if (memory->savedata.type == SAVEDATA_AUTODETECT) {
if (address == SAVEDATA_FLASH_BASE) { if (address == SAVEDATA_FLASH_BASE) {
GBALog(gba, GBA_LOG_INFO, "Detected Flash savegame"); GBALog(gba, GBA_LOG_INFO, "Detected Flash savegame");
GBASavedataInitFlash(&memory->savedata); GBASavedataInitFlash(&memory->savedata);
@ -1142,7 +1142,7 @@ void GBAMemoryServiceDMA(struct GBA* gba, int number, struct GBADMA* info) {
dest += destOffset; dest += destOffset;
--wordsRemaining; --wordsRemaining;
} else if (destRegion == REGION_CART2_EX) { } 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"); GBALog(gba, GBA_LOG_INFO, "Detected EEPROM savegame");
GBASavedataInitEEPROM(&memory->savedata); GBASavedataInitEEPROM(&memory->savedata);
} }

View File

@ -18,7 +18,7 @@ static void _flashErase(struct GBASavedata* savedata);
static void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart); static void _flashEraseSector(struct GBASavedata* savedata, uint16_t sectorStart);
void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) { void GBASavedataInit(struct GBASavedata* savedata, struct VFile* vf) {
savedata->type = SAVEDATA_NONE; savedata->type = SAVEDATA_AUTODETECT;
savedata->data = 0; savedata->data = 0;
savedata->command = EEPROM_COMMAND_NULL; savedata->command = EEPROM_COMMAND_NULL;
savedata->flashState = FLASH_STATE_RAW; savedata->flashState = FLASH_STATE_RAW;
@ -42,7 +42,8 @@ void GBASavedataDeinit(struct GBASavedata* savedata) {
case SAVEDATA_EEPROM: case SAVEDATA_EEPROM:
savedata->vf->unmap(savedata->vf, savedata->data, SIZE_CART_EEPROM); savedata->vf->unmap(savedata->vf, savedata->data, SIZE_CART_EEPROM);
break; break;
case SAVEDATA_NONE: case SAVEDATA_FORCE_NONE:
case SAVEDATA_AUTODETECT:
break; break;
} }
savedata->vf = 0; savedata->vf = 0;
@ -60,12 +61,13 @@ void GBASavedataDeinit(struct GBASavedata* savedata) {
case SAVEDATA_EEPROM: case SAVEDATA_EEPROM:
mappedMemoryFree(savedata->data, SIZE_CART_EEPROM); mappedMemoryFree(savedata->data, SIZE_CART_EEPROM);
break; break;
case SAVEDATA_NONE: case SAVEDATA_FORCE_NONE:
case SAVEDATA_AUTODETECT:
break; break;
} }
} }
savedata->data = 0; savedata->data = 0;
savedata->type = SAVEDATA_NONE; savedata->type = SAVEDATA_AUTODETECT;
} }
void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf) { void GBASavedataMask(struct GBASavedata* savedata, struct VFile* vf) {
@ -94,7 +96,8 @@ bool GBASavedataClone(struct GBASavedata* savedata, struct VFile* out) {
return out->write(out, savedata->data, SIZE_CART_FLASH1M) == SIZE_CART_FLASH1M; return out->write(out, savedata->data, SIZE_CART_FLASH1M) == SIZE_CART_FLASH1M;
case SAVEDATA_EEPROM: case SAVEDATA_EEPROM:
return out->write(out, savedata->data, SIZE_CART_EEPROM) == SIZE_CART_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; return true;
} }
} else if (savedata->vf) { } else if (savedata->vf) {
@ -122,14 +125,16 @@ void GBASavedataForceType(struct GBASavedata* savedata, enum SavedataType type)
case SAVEDATA_SRAM: case SAVEDATA_SRAM:
GBASavedataInitSRAM(savedata); GBASavedataInitSRAM(savedata);
break; break;
case SAVEDATA_NONE: case SAVEDATA_FORCE_NONE:
// TODO: Force none savedata->type = SAVEDATA_FORCE_NONE;
break;
case SAVEDATA_AUTODETECT:
break; break;
} }
} }
void GBASavedataInitFlash(struct GBASavedata* savedata) { void GBASavedataInitFlash(struct GBASavedata* savedata) {
if (savedata->type == SAVEDATA_NONE) { if (savedata->type == SAVEDATA_AUTODETECT) {
savedata->type = SAVEDATA_FLASH512; savedata->type = SAVEDATA_FLASH512;
} }
if (savedata->type != SAVEDATA_FLASH512 && savedata->type != SAVEDATA_FLASH1M) { if (savedata->type != SAVEDATA_FLASH512 && savedata->type != SAVEDATA_FLASH1M) {
@ -157,7 +162,7 @@ void GBASavedataInitFlash(struct GBASavedata* savedata) {
} }
void GBASavedataInitEEPROM(struct GBASavedata* savedata) { void GBASavedataInitEEPROM(struct GBASavedata* savedata) {
if (savedata->type == SAVEDATA_NONE) { if (savedata->type == SAVEDATA_AUTODETECT) {
savedata->type = SAVEDATA_EEPROM; savedata->type = SAVEDATA_EEPROM;
} else { } else {
GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata"); GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata");
@ -180,7 +185,7 @@ void GBASavedataInitEEPROM(struct GBASavedata* savedata) {
} }
void GBASavedataInitSRAM(struct GBASavedata* savedata) { void GBASavedataInitSRAM(struct GBASavedata* savedata) {
if (savedata->type == SAVEDATA_NONE) { if (savedata->type == SAVEDATA_AUTODETECT) {
savedata->type = SAVEDATA_SRAM; savedata->type = SAVEDATA_SRAM;
} else { } else {
GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata"); GBALog(0, GBA_LOG_WARN, "Can't re-initialize savedata");

View File

@ -11,7 +11,8 @@
struct VFile; struct VFile;
enum SavedataType { enum SavedataType {
SAVEDATA_NONE = 0, SAVEDATA_AUTODETECT = -1,
SAVEDATA_FORCE_NONE = 0,
SAVEDATA_SRAM, SAVEDATA_SRAM,
SAVEDATA_FLASH512, SAVEDATA_FLASH512,
SAVEDATA_FLASH1M, SAVEDATA_FLASH1M,

View File

@ -109,6 +109,9 @@ static const struct GBACartridgeOverride _overrides[] = {
{ "AX4E", SAVEDATA_FLASH1M, GPIO_NONE, -1 }, { "AX4E", SAVEDATA_FLASH1M, GPIO_NONE, -1 },
{ "AX4P", 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 // Wario Ware Twisted
{ "RZWJ", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO, -1 }, { "RZWJ", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO, -1 },
{ "RZWE", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO, -1 }, { "RZWE", SAVEDATA_SRAM, GPIO_RUMBLE | GPIO_GYRO, -1 },

View File

@ -50,7 +50,7 @@ void GamePakView::gameStarted(GBAThread* thread) {
} }
SavedataType savetype = thread->gba->memory.savedata.type; SavedataType savetype = thread->gba->memory.savedata.type;
if (m_ui.savetype->currentIndex() > 0) { if (m_ui.savetype->currentIndex() > 0) {
if (savetype > SAVEDATA_NONE) { if (savetype > SAVEDATA_FORCE_NONE) {
VFile* vf = thread->gba->memory.savedata.vf; VFile* vf = thread->gba->memory.savedata.vf;
GBASavedataDeinit(&thread->gba->memory.savedata); GBASavedataDeinit(&thread->gba->memory.savedata);
GBASavedataInit(&thread->gba->memory.savedata, vf); GBASavedataInit(&thread->gba->memory.savedata, vf);
@ -59,7 +59,7 @@ void GamePakView::gameStarted(GBAThread* thread) {
GBASavedataForceType(&thread->gba->memory.savedata, savetype); GBASavedataForceType(&thread->gba->memory.savedata, savetype);
} }
if (savetype > SAVEDATA_NONE) { if (savetype > SAVEDATA_AUTODETECT) {
m_ui.savetype->setCurrentIndex(savetype + 1); m_ui.savetype->setCurrentIndex(savetype + 1);
} }
m_ui.savetype->setEnabled(false); m_ui.savetype->setEnabled(false);