diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/NDSCart.cpp | 28 | ||||
-rw-r--r-- | src/NDSCart.h | 1 | ||||
-rw-r--r-- | src/libui_sdl/main.cpp | 41 |
3 files changed, 58 insertions, 12 deletions
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index ab2a5f9..44d6ca9 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -36,7 +36,7 @@ namespace NDSCart_SRAM u8* SRAM; u32 SRAMLength; -char SRAMPath[256]; +char SRAMPath[1024]; void (*WriteFunc)(u8 val, bool islast); @@ -148,8 +148,8 @@ void LoadSave(const char* path) Discover_AddrLength = 0x7FFFFFFF; Discover_LikelySize = 0; - strncpy(SRAMPath, path, 255); - SRAMPath[255] = '\0'; + strncpy(SRAMPath, path, 1023); + SRAMPath[1023] = '\0'; FILE* f = melon_fopen(path, "rb"); if (f) @@ -196,6 +196,22 @@ void LoadSave(const char* path) StatusReg = 0x00; } +void RelocateSave(const char* path) +{ + strncpy(SRAMPath, path, 1023); + SRAMPath[1023] = '\0'; + + FILE* f = melon_fopen(path, "wb"); + if (!f) + { + printf("NDSCart_SRAM::RelocateSave: failed to create new file. fuck\n"); + return; + } + + fwrite(SRAM, SRAMLength, 1, f); + fclose(f); +} + u8 Read() { return Data; @@ -1127,6 +1143,12 @@ bool LoadROM(const char* path, const char* sram, bool direct) return true; } +void RelocateSave(const char* path) +{ + // herp derp + NDSCart_SRAM::RelocateSave(path); +} + void ReadROM(u32 addr, u32 len, u32 offset) { if (!CartInserted) return; diff --git a/src/NDSCart.h b/src/NDSCart.h index d00d40e..ee6ebdb 100644 --- a/src/NDSCart.h +++ b/src/NDSCart.h @@ -45,6 +45,7 @@ void Reset(); void DoSavestate(Savestate* file); bool LoadROM(const char* path, const char* sram, bool direct); +void RelocateSave(const char* path); void WriteROMCnt(u32 val); u32 ReadROMData(); diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index 6072804..bea9685 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -24,6 +24,7 @@ #include "libui/ui.h" #include "../types.h" +#include "../melon_fopen.h" #include "../version.h" #include "../Config.h" @@ -58,6 +59,8 @@ uiMenuItem* MenuItem_SaveState; uiMenuItem* MenuItem_LoadState; uiMenuItem* MenuItem_UndoStateLoad; +uiMenuItem* MenuItem_LoadStateSlot[8]; + uiMenuItem* MenuItem_Pause; uiMenuItem* MenuItem_Reset; uiMenuItem* MenuItem_Stop; @@ -104,8 +107,18 @@ void SetupScreenRects(int width, int height); void SaveState(int slot); void LoadState(int slot); void UndoStateLoad(); +void GetSavestateName(int slot, char* filename, int len); + +bool FileExists(char* name) +{ + FILE* f = melon_fopen(name, "rb"); + if (!f) return false; + fclose(f); + return true; +} + void UpdateWindowTitle(void* data) { @@ -751,6 +764,14 @@ void Run() uiMenuItemEnable(MenuItem_LoadState); uiMenuItemEnable(MenuItem_UndoStateLoad); + for (int i = 0; i < 8; i++) + { + char ssfile[1024]; + GetSavestateName(i+1, ssfile, 1024); + if (FileExists(ssfile)) uiMenuItemEnable(MenuItem_LoadStateSlot[i]); + else uiMenuItemDisable(MenuItem_LoadStateSlot[i]); + } + uiMenuItemEnable(MenuItem_Pause); uiMenuItemEnable(MenuItem_Reset); uiMenuItemEnable(MenuItem_Stop); @@ -867,6 +888,12 @@ void LoadState(int slot) uiFreeText(file); } + if (!FileExists(filename)) + { + EmuRunning = prevstatus; + return; + } + // backup Savestate* backup = new Savestate("timewarp.mln", true); NDS::DoSavestate(backup); @@ -926,6 +953,9 @@ void SaveState(int slot) { NDS::DoSavestate(state); delete state; + + if (slot > 0) + uiMenuItemEnable(MenuItem_LoadStateSlot[slot-1]); } EmuRunning = prevstatus; @@ -1216,15 +1246,6 @@ void ApplyNewSettings() } -bool _fileexists(char* name) -{ - FILE* f = fopen(name, "rb"); - if (!f) return false; - fclose(f); - return true; -} - - int main(int argc, char** argv) { srand(time(NULL)); @@ -1313,6 +1334,8 @@ int main(int argc, char** argv) uiMenuItem* ssitem = uiMenuAppendItem(submenu, name); uiMenuItemOnClicked(ssitem, OnLoadState, (void*)&kSavestateNum[i]); + + if (i < 8) MenuItem_LoadStateSlot[i] = ssitem; } MenuItem_LoadState = uiMenuAppendSubmenu(menu, submenu); |