Used the battery file size as an indicator of the save type unless overridden.

This commit is contained in:
skidau 2015-05-22 15:11:28 +00:00
parent da898721e1
commit 8508f7aab6
3 changed files with 95 additions and 65 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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