From 8508f7aab6ebe0468a9f3513870fa5bd8d632df0 Mon Sep 17 00:00:00 2001 From: skidau Date: Fri, 22 May 2015 15:11:28 +0000 Subject: [PATCH] Used the battery file size as an indicator of the save type unless overridden. --- src/gba/GBA.cpp | 113 +++++++++++++++++++++++++---------------------- src/gba/GBA.h | 1 + src/wx/panel.cpp | 46 ++++++++++++++----- 3 files changed, 95 insertions(+), 65 deletions(-) diff --git a/src/gba/GBA.cpp b/src/gba/GBA.cpp index 5454f766..8cbf1d9e 100644 --- a/src/gba/GBA.cpp +++ b/src/gba/GBA.cpp @@ -3472,6 +3472,62 @@ void CPUInit(const char *biosFileName, bool useBiosFile) } } +void SetSaveType(int st) +{ + switch (st) { + case 0: // automatic + cpuSramEnabled = true; + cpuFlashEnabled = true; + cpuEEPROMEnabled = true; + cpuEEPROMSensorEnabled = false; + gbaSaveType = 0; + cpuSaveGameFunc = flashSaveDecide; + break; + case 1: // EEPROM + eepromReset(); + cpuSramEnabled = false; + cpuFlashEnabled = false; + cpuEEPROMEnabled = true; + cpuEEPROMSensorEnabled = false; + gbaSaveType = 3; + // EEPROM usage is automatically detected + break; + case 2: // SRAM + cpuSramEnabled = true; + cpuFlashEnabled = false; + cpuEEPROMEnabled = false; + cpuEEPROMSensorEnabled = false; + cpuSaveGameFunc = sramDelayedWrite; // to insure we detect the write + gbaSaveType = 1; + break; + case 3: // FLASH + flashReset(); + cpuSramEnabled = false; + cpuFlashEnabled = true; + cpuEEPROMEnabled = false; + cpuEEPROMSensorEnabled = false; + cpuSaveGameFunc = flashDelayedWrite; // to insure we detect the write + gbaSaveType = 2; + break; + case 4: // EEPROM+Sensor + cpuSramEnabled = false; + cpuFlashEnabled = false; + cpuEEPROMEnabled = true; + cpuEEPROMSensorEnabled = true; + // EEPROM usage is automatically detected + gbaSaveType = 3; + break; + case 5: // NONE + cpuSramEnabled = false; + cpuFlashEnabled = false; + cpuEEPROMEnabled = false; + cpuEEPROMSensorEnabled = false; + // no save at all + gbaSaveType = 5; + break; + } +} + void CPUReset() { if(gbaSaveType == 0) { @@ -3479,10 +3535,10 @@ void CPUReset() gbaSaveType = 3; else switch(saveType) { - case 1: + case 2: gbaSaveType = 1; break; - case 2: + case 3: gbaSaveType = 2; break; } @@ -3711,58 +3767,7 @@ void CPUReset() BIOS_RegisterRamReset(0xfe); } - switch(saveType) { - case 0: // automatic - cpuSramEnabled = true; - cpuFlashEnabled = true; - cpuEEPROMEnabled = true; - cpuEEPROMSensorEnabled = false; - gbaSaveType = 0; - cpuSaveGameFunc = flashSaveDecide; - break; - case 1: // EEPROM - eepromReset(); - cpuSramEnabled = false; - cpuFlashEnabled = false; - cpuEEPROMEnabled = true; - cpuEEPROMSensorEnabled = false; - gbaSaveType = 3; - // EEPROM usage is automatically detected - break; - case 2: // SRAM - cpuSramEnabled = true; - cpuFlashEnabled = false; - cpuEEPROMEnabled = false; - cpuEEPROMSensorEnabled = false; - cpuSaveGameFunc = sramDelayedWrite; // to insure we detect the write - gbaSaveType = 1; - break; - case 3: // FLASH - flashReset(); - cpuSramEnabled = false; - cpuFlashEnabled = true; - cpuEEPROMEnabled = false; - cpuEEPROMSensorEnabled = false; - cpuSaveGameFunc = flashDelayedWrite; // to insure we detect the write - gbaSaveType = 2; - break; - case 4: // EEPROM+Sensor - cpuSramEnabled = false; - cpuFlashEnabled = false; - cpuEEPROMEnabled = true; - cpuEEPROMSensorEnabled = true; - // EEPROM usage is automatically detected - gbaSaveType = 3; - break; - case 5: // NONE - cpuSramEnabled = false; - cpuFlashEnabled = false; - cpuEEPROMEnabled = false; - cpuEEPROMSensorEnabled = false; - // no save at all - gbaSaveType = 5; - break; - } + SetSaveType(saveType); ARM_PREFETCH; diff --git a/src/gba/GBA.h b/src/gba/GBA.h index bb922b5b..c0e3fdb4 100644 --- a/src/gba/GBA.h +++ b/src/gba/GBA.h @@ -103,6 +103,7 @@ extern void doMirroring(bool); extern void CPUUpdateRegister(u32, u16); extern void applyTimer (); extern void CPUInit(const char *,bool); +void SetSaveType(int st); extern void CPUReset(); extern void CPULoop(int); extern void CPUCheckDMA(int,int); diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index f2929a93..3d0a581e 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -111,6 +111,7 @@ void GameArea::LoadGame(const wxString &name) // too much trouble for now, though bool loadpatch = autoPatch; wxFileName pfn = loaded_game; + int ovSaveType = 0; if (loadpatch) { @@ -251,15 +252,15 @@ void GameArea::LoadGame(const wxString &name) fsz = 0x10000 << winFlashSize; flashSetSize(fsz); - cpuSaveType = cfg->Read(wxT("saveType"), cpuSaveType); + ovSaveType = cfg->Read(wxT("saveType"), cpuSaveType); - if (cpuSaveType < 0 || cpuSaveType > 5) - cpuSaveType = 0; + if (ovSaveType < 0 || ovSaveType > 5) + ovSaveType = 0; - if (cpuSaveType == 0) + if (ovSaveType == 0) utilGBAFindSave(rom_size); else - saveType = cpuSaveType; + saveType = ovSaveType; mirroringEnable = cfg->Read(wxT("mirroringEnabled"), (long)1); cfg->SetPath(wxT("/")); @@ -277,12 +278,6 @@ void GameArea::LoadGame(const wxString &name) else saveType = cpuSaveType; - // mirroring short ROMs is such an uncommon thing that any - // carts needing it should be added to vba-over.ini. - // on the other hand, I would see nothing wrong with enabling - // by default on carts that are small enough (i.e., always - // set this to true and ignore vba-over.ini). It's just a one-time - // init. mirroringEnable = true; } @@ -367,6 +362,35 @@ void GameArea::LoadGame(const wxString &name) wxString msg; msg.Printf(_("Loaded battery %s"), bat.GetFullPath().c_str()); systemScreenMessage(msg); + + if (cpuSaveType == 0 && ovSaveType == 0 && t == IMAGE_GBA) + { + switch (bat.GetSize().GetValue()) + { + case 0x200: + case 0x2000: + saveType = 1; + break; + + case 0x8000: + saveType = 2; + break; + + case 0x10000: + if (saveType == 1 || saveType == 2) + break; + + case 0x20000: + saveType = 3; + flashSetSize(fnb.length()); + break; + + default: + break; + } + + SetSaveType(saveType); + } } // forget old save writes