aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2018-10-24 00:24:36 +0200
committerStapleButter <thetotalworm@gmail.com>2018-10-24 00:24:36 +0200
commit8b4ba2d8b9833fec88df8a3549af30b3ec704469 (patch)
tree747b85790f771ed8f750f0291553eb3ba9216547 /src
parent1edf2aed3b4c0e02d5a094d04d337578d4f967b9 (diff)
separate SRAM setting coded, I guess
Diffstat (limited to 'src')
-rw-r--r--src/Config.cpp4
-rw-r--r--src/Config.h2
-rw-r--r--src/NDS.cpp6
-rw-r--r--src/NDS.h1
-rw-r--r--src/NDSCart.cpp12
-rw-r--r--src/NDSCart.h2
-rw-r--r--src/libui_sdl/main.cpp60
7 files changed, 79 insertions, 8 deletions
diff --git a/src/Config.cpp b/src/Config.cpp
index d98ffd3..035c304 100644
--- a/src/Config.cpp
+++ b/src/Config.cpp
@@ -53,6 +53,8 @@ int Threaded3D;
int SocketBindAnyAddr;
+int SavestateRelocSRAM;
+
typedef struct
{
char Name[16];
@@ -107,6 +109,8 @@ ConfigEntry ConfigFile[] =
{"SockBindAnyAddr", 0, &SocketBindAnyAddr, 0, NULL, 0},
+ {"SavStaRelocSRAM", 0, &SavestateRelocSRAM, 1, NULL, 0},
+
{"", -1, NULL, 0, NULL, 0}
};
diff --git a/src/Config.h b/src/Config.h
index 08e4e86..d7b0858 100644
--- a/src/Config.h
+++ b/src/Config.h
@@ -46,6 +46,8 @@ extern int Threaded3D;
extern int SocketBindAnyAddr;
+extern int SavestateRelocSRAM;
+
}
#endif // CONFIG_H
diff --git a/src/NDS.cpp b/src/NDS.cpp
index 8528307..e0086c8 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -562,6 +562,12 @@ void LoadBIOS()
Running = true;
}
+void RelocateSave(const char* path, bool write)
+{
+ printf("SRAM: relocating to %s (write=%s)\n", path, write?"true":"false");
+ NDSCart::RelocateSave(path, write);
+}
+
void CalcIterationCycles()
{
diff --git a/src/NDS.h b/src/NDS.h
index 99d80b4..e7c2b98 100644
--- a/src/NDS.h
+++ b/src/NDS.h
@@ -114,6 +114,7 @@ bool DoSavestate(Savestate* file);
bool LoadROM(const char* path, const char* sram, bool direct);
void LoadBIOS();
void SetupDirectBoot();
+void RelocateSave(const char* path, bool write);
u32 RunFrame();
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp
index 44d6ca9..03dfe4c 100644
--- a/src/NDSCart.cpp
+++ b/src/NDSCart.cpp
@@ -196,8 +196,14 @@ void LoadSave(const char* path)
StatusReg = 0x00;
}
-void RelocateSave(const char* path)
+void RelocateSave(const char* path, bool write)
{
+ if (!write)
+ {
+ LoadSave(path); // lazy
+ return;
+ }
+
strncpy(SRAMPath, path, 1023);
SRAMPath[1023] = '\0';
@@ -1143,10 +1149,10 @@ bool LoadROM(const char* path, const char* sram, bool direct)
return true;
}
-void RelocateSave(const char* path)
+void RelocateSave(const char* path, bool write)
{
// herp derp
- NDSCart_SRAM::RelocateSave(path);
+ NDSCart_SRAM::RelocateSave(path, write);
}
void ReadROM(u32 addr, u32 len, u32 offset)
diff --git a/src/NDSCart.h b/src/NDSCart.h
index ee6ebdb..ac8f8fe 100644
--- a/src/NDSCart.h
+++ b/src/NDSCart.h
@@ -45,7 +45,7 @@ void Reset();
void DoSavestate(Savestate* file);
bool LoadROM(const char* path, const char* sram, bool direct);
-void RelocateSave(const char* path);
+void RelocateSave(const char* path, bool write);
void WriteROMCnt(u32 val);
u32 ReadROMData();
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);
@@ -1368,6 +1409,15 @@ int main(int argc, char** argv)
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");
for (int i = 0; i < 4; i++)
@@ -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);