From 8b4ba2d8b9833fec88df8a3549af30b3ec704469 Mon Sep 17 00:00:00 2001 From: StapleButter Date: Wed, 24 Oct 2018 00:24:36 +0200 Subject: separate SRAM setting coded, I guess --- src/libui_sdl/main.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 4 deletions(-) (limited to 'src/libui_sdl') diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index bea9685..149e356 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -65,6 +65,8 @@ uiMenuItem* MenuItem_Pause; uiMenuItem* MenuItem_Reset; uiMenuItem* MenuItem_Stop; +uiMenuItem* MenuItem_SavestateSRAMReloc; + uiMenuItem* MenuItem_ScreenRot[4]; uiMenuItem* MenuItem_ScreenGap[6]; uiMenuItem* MenuItem_ScreenLayout[3]; @@ -818,7 +820,10 @@ void TryLoadROM(char* file, int prevstatus) SetupSRAMPath(); if (NDS::LoadROM(ROMPath, SRAMPath, Config::DirectBoot)) + { + strncpy(PrevSRAMPath, SRAMPath, 1024); // safety Run(); + } else { uiMsgBoxError(MainWindow, @@ -846,11 +851,10 @@ void GetSavestateName(int slot, char* filename, int len) } else { - int len = strlen(ROMPath); - pos = len; + int l = strlen(ROMPath); + pos = l; while (ROMPath[pos] != '.' && pos > 0) pos--; - if (pos == 0) pos = len; - else pos++; + if (pos == 0) pos = l; // avoid buffer overflow. shoddy if (pos > len-5) pos = len-5; @@ -913,6 +917,18 @@ void LoadState(int slot) NDS::DoSavestate(state); delete state; + if (Config::SavestateRelocSRAM && ROMPath[0]!='\0') + { + strncpy(PrevSRAMPath, SRAMPath, 1024); + + strncpy(SRAMPath, filename, 1019); + int len = strlen(SRAMPath); + strcpy(&SRAMPath[len], ".sav"); + SRAMPath[len+4] = '\0'; + + NDS::RelocateSave(SRAMPath, false); + } + EmuRunning = prevstatus; } @@ -956,6 +972,16 @@ void SaveState(int slot) if (slot > 0) uiMenuItemEnable(MenuItem_LoadStateSlot[slot-1]); + + if (Config::SavestateRelocSRAM && ROMPath[0]!='\0') + { + strncpy(SRAMPath, filename, 1019); + int len = strlen(SRAMPath); + strcpy(&SRAMPath[len], ".sav"); + SRAMPath[len+4] = '\0'; + + NDS::RelocateSave(SRAMPath, true); + } } EmuRunning = prevstatus; @@ -974,6 +1000,12 @@ void UndoStateLoad() NDS::DoSavestate(backup); delete backup; + if (ROMPath[0]!='\0') + { + strncpy(SRAMPath, PrevSRAMPath, 1024); + NDS::RelocateSave(SRAMPath, false); + } + EmuRunning = prevstatus; } @@ -1096,7 +1128,10 @@ void OnReset(uiMenuItem* item, uiWindow* window, void* blarg) if (ROMPath[0] == '\0') NDS::LoadBIOS(); else + { + SetupSRAMPath(); NDS::LoadROM(ROMPath, SRAMPath, Config::DirectBoot); + } Run(); } @@ -1119,6 +1154,12 @@ void OnOpenInputConfig(uiMenuItem* item, uiWindow* window, void* blarg) } +void OnSetSavestateSRAMReloc(uiMenuItem* item, uiWindow* window, void* param) +{ + Config::SavestateRelocSRAM = uiMenuItemChecked(item) ? 1:0; +} + + void EnsureProperMinSize() { bool isHori = (ScreenRotation == 1 || ScreenRotation == 3); @@ -1367,6 +1408,15 @@ int main(int argc, char** argv) menuitem = uiMenuAppendItem(menu, "Input config"); uiMenuItemOnClicked(menuitem, OnOpenInputConfig, NULL); uiMenuAppendSeparator(menu); + { + uiMenu* submenu = uiNewMenu("Savestate settings"); + + MenuItem_SavestateSRAMReloc = uiMenuAppendCheckItem(submenu, "Separate savefiles"); + uiMenuItemOnClicked(MenuItem_SavestateSRAMReloc, OnSetSavestateSRAMReloc, NULL); + + uiMenuAppendSubmenu(menu, submenu); + } + uiMenuAppendSeparator(menu); { uiMenu* submenu = uiNewMenu("Screen rotation"); @@ -1471,6 +1521,8 @@ int main(int argc, char** argv) SANITIZE(ScreenSizing, 0, 3); #undef SANITIZE + uiMenuItemSetChecked(MenuItem_SavestateSRAMReloc, Config::SavestateRelocSRAM?1:0); + uiMenuItemSetChecked(MenuItem_ScreenRot[ScreenRotation], 1); uiMenuItemSetChecked(MenuItem_ScreenLayout[ScreenLayout], 1); uiMenuItemSetChecked(MenuItem_ScreenSizing[ScreenSizing], 1); -- cgit v1.2.3