From 97d2f385d2fdde557bd3f618fa535811799c437a Mon Sep 17 00:00:00 2001 From: skidau Date: Sat, 18 Apr 2015 14:52:58 +0000 Subject: [PATCH] Separate the configured saveType from the runtime saveType --- src/Util.cpp | 24 ++++++++++++------------ src/libretro/libretro.cpp | 5 +++++ src/sdl/SDL.cpp | 5 +++++ src/win32/MainWnd.cpp | 12 ++++++++---- src/win32/MainWndOptions.cpp | 2 +- src/wx/panel.cpp | 12 +++++++++++- 6 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/Util.cpp b/src/Util.cpp index 60ad36a1..fdcc58e9 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -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); } diff --git a/src/libretro/libretro.cpp b/src/libretro/libretro.cpp index 289bf72d..d94ac38c 100644 --- a/src/libretro/libretro.cpp +++ b/src/libretro/libretro.cpp @@ -439,6 +439,11 @@ static void gba_init(void) utilUpdateSystemColorMaps(false); + + if (cpuSaveType == 0) + utilGBAFindSave(size); + else + saveType = cpuSaveType; load_image_preferences(); diff --git a/src/sdl/SDL.cpp b/src/sdl/SDL.cpp index 40af2021..c776ef68 100644 --- a/src/sdl/SDL.cpp +++ b/src/sdl/SDL.cpp @@ -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); diff --git a/src/win32/MainWnd.cpp b/src/win32/MainWnd.cpp index d3bb7d14..d80203fb 100644 --- a/src/win32/MainWnd.cpp +++ b/src/win32/MainWnd.cpp @@ -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); } } diff --git a/src/win32/MainWndOptions.cpp b/src/win32/MainWndOptions.cpp index 4af14df6..2ec51962 100644 --- a/src/win32/MainWndOptions.cpp +++ b/src/win32/MainWndOptions.cpp @@ -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."); diff --git a/src/wx/panel.cpp b/src/wx/panel.cpp index f6de56d4..45b3799b 100644 --- a/src/wx/panel.cpp +++ b/src/wx/panel.cpp @@ -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);