diff options
author | WaluigiWare64 <68647953+WaluigiWare64@users.noreply.github.com> | 2020-12-19 17:43:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-19 17:43:53 +0000 |
commit | df190b04000a8a3c5052de3fd695f6c26892f353 (patch) | |
tree | 85c53cda9b5e6c73dcfb82f97272e509f023788b /src/NDSCart.cpp | |
parent | d6cade25f4ac6b2ebac9d4830ab7b10294bc4c89 (diff) | |
parent | 659dc58d4d8290d8ef1930d9f21007c0ec4c3739 (diff) |
Merge branch 'master' into feature/zip-support
Diffstat (limited to 'src/NDSCart.cpp')
-rw-r--r-- | src/NDSCart.cpp | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/NDSCart.cpp b/src/NDSCart.cpp index 077bf48..2d8396a 100644 --- a/src/NDSCart.cpp +++ b/src/NDSCart.cpp @@ -37,6 +37,7 @@ u8* SRAM; u32 SRAMLength; char SRAMPath[1024]; +bool SRAMFileDirty; void (*WriteFunc)(u8 val, bool islast); @@ -445,14 +446,21 @@ void Write(u8 val, u32 hold) break; } - if (islast && (CurCmd == 0x02 || CurCmd == 0x0A) && (SRAMLength > 0)) + SRAMFileDirty |= islast && (CurCmd == 0x02 || CurCmd == 0x0A) && (SRAMLength > 0); +} + +void FlushSRAMFile() +{ + if (!SRAMFileDirty) + return; + + SRAMFileDirty = false; + + FILE* f = Platform::OpenFile(SRAMPath, "wb"); + if (f) { - FILE* f = Platform::OpenFile(SRAMPath, "wb"); - if (f) - { - fwrite(SRAM, SRAMLength, 1, f); - fclose(f); - } + fwrite(SRAM, SRAMLength, 1, f); + fclose(f); } } @@ -1034,6 +1042,11 @@ void RelocateSave(const char* path, bool write) NDSCart_SRAM::RelocateSave(path, write); } +void FlushSRAMFile() +{ + NDSCart_SRAM::FlushSRAMFile(); +} + int ImportSRAM(const u8* data, u32 length) { memcpy(NDSCart_SRAM::SRAM, data, std::min(length, NDSCart_SRAM::SRAMLength)); |