Separate the configured saveType from the runtime saveType

This commit is contained in:
skidau 2015-04-18 14:52:58 +00:00
parent f2b22ad484
commit 97d2f385d2
6 changed files with 42 additions and 18 deletions

View File

@ -700,7 +700,7 @@ void utilGBAFindSave(const int size)
{
u32 *p = (u32 *)&rom[0];
u32 *end = (u32 *)(&rom[0] + size);
int saveType = 0;
int detectedSaveType = 0;
int flashSize = 0x10000;
bool rtcFound = false;
@ -709,23 +709,23 @@ void utilGBAFindSave(const int size)
if(d == 0x52504545) {
if(memcmp(p, "EEPROM_", 7) == 0) {
if(saveType == 0)
saveType = 1;
if(detectedSaveType == 0)
detectedSaveType = 1;
}
} else if (d == 0x4D415253) {
if(memcmp(p, "SRAM_", 5) == 0) {
if(saveType == 0)
saveType = 2;
if(detectedSaveType == 0)
detectedSaveType = 2;
}
} else if (d == 0x53414C46) {
if(memcmp(p, "FLASH1M_", 8) == 0) {
if(saveType == 0) {
saveType = 3;
if(detectedSaveType == 0) {
detectedSaveType = 3;
flashSize = 0x20000;
}
} else if(memcmp(p, "FLASH", 5) == 0) {
if(saveType == 0) {
saveType = 3;
if(detectedSaveType == 0) {
detectedSaveType = 3;
flashSize = 0x10000;
}
}
@ -736,11 +736,11 @@ void utilGBAFindSave(const int size)
p++;
}
// if no matches found, then set it to NONE
if(saveType == 0) {
saveType = 5;
if(detectedSaveType == 0) {
detectedSaveType = 5;
}
rtcEnable(rtcFound);
cpuSaveType = saveType;
saveType = detectedSaveType;
flashSetSize(flashSize);
}

View File

@ -440,6 +440,11 @@ static void gba_init(void)
utilUpdateSystemColorMaps(false);
if (cpuSaveType == 0)
utilGBAFindSave(size);
else
saveType = cpuSaveType;
load_image_preferences();
if(flashSize == 0x10000 || flashSize == 0x20000)

View File

@ -1653,6 +1653,11 @@ int main(int argc, char **argv)
int size = CPULoadRom(szFile);
failed = (size == 0);
if(!failed) {
if (cpuSaveType == 0)
utilGBAFindSave(size);
else
saveType = cpuSaveType;
sdlApplyPerImagePreferences();
doMirroring(mirroringEnable);

View File

@ -525,6 +525,8 @@ bool MainWnd::FileRun()
if (cpuSaveType == 0)
utilGBAFindSave(theApp.romSize);
else
saveType = cpuSaveType;
GetModuleFileName(NULL, tempName, 2048);
@ -1114,8 +1116,9 @@ void MainWnd::OnFileLoadDotCode()
FALSE);
if (file.DoModal() == IDOK)
{
theApp.loadDotCodeFile = file.GetPathName();
SetLoadDotCodeFile(theApp.loadDotCodeFile);
const char* filename = file.GetPathName();
strcpy(loadDotCodeFile, filename);
SetLoadDotCodeFile(loadDotCodeFile);
}
}
@ -1136,8 +1139,9 @@ void MainWnd::OnFileSaveDotCode()
TRUE);
if (file.DoModal() == IDOK)
{
theApp.saveDotCodeFile = file.GetPathName();
SetLoadDotCodeFile(theApp.saveDotCodeFile);
const char* filename = file.GetPathName();
strcpy(saveDotCodeFile, filename);
SetLoadDotCodeFile(saveDotCodeFile);
}
}

View File

@ -803,7 +803,7 @@ void MainWnd::OnOptionsEmulatorSavetypeDetectNow()
CString answer( _T( "This cartridge has probably no backup media." ) );
utilGBAFindSave(theApp.romSize);
switch (cpuSaveType)
switch (saveType)
{
case 0:
answer = _T("This cartridge has probably no backup media.");

View File

@ -202,6 +202,12 @@ void GameArea::LoadGame(const wxString &name)
cpuSaveType = cfg->Read(wxT("saveType"), gopts.save_type);
if(cpuSaveType < 0 || cpuSaveType > 5)
cpuSaveType = gopts.save_type;
if (cpuSaveType == 0)
utilGBAFindSave(size);
else
saveType = cpuSaveType;
mirroringEnable = cfg->Read(wxT("mirroringEnabled"), (long)0);
cfg->SetPath(wxT("/"));
@ -209,13 +215,17 @@ void GameArea::LoadGame(const wxString &name)
rtcEnable(gopts.rtc);
flashSetSize(0x10000 << gopts.flash_size);
cpuSaveType = gopts.save_type;
if (cpuSaveType == 0)
utilGBAFindSave(size);
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 = false;
mirroringEnable = true;
}
doMirroring(mirroringEnable);