From 1d6cc3c6ef8cf724883d3f12fa5a06fe25bf5839 Mon Sep 17 00:00:00 2001 From: RSDuck Date: Sun, 17 Jan 2021 19:56:02 +0100 Subject: keep only one handle of the NAND file around --- src/frontend/Util_ROM.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'src/frontend/Util_ROM.cpp') diff --git a/src/frontend/Util_ROM.cpp b/src/frontend/Util_ROM.cpp index 9f22f5f..065b319 100644 --- a/src/frontend/Util_ROM.cpp +++ b/src/frontend/Util_ROM.cpp @@ -25,6 +25,7 @@ #include "Platform.h" #include "NDS.h" +#include "DSi.h" #include "GBACart.h" #include "AREngine.h" @@ -199,18 +200,27 @@ int VerifyDSiFirmware() return Load_OK; } -int VerifyDSiNAND() +int SetupDSiNAND() { FILE* f; long len; - f = Platform::OpenLocalFile(Config::DSiNANDPath, "rb"); + f = Platform::OpenLocalFile(Config::DSiNANDPath, "r+b"); if (!f) return Load_DSiNANDMissing; // TODO: some basic checks // check that it has the nocash footer, and all - fclose(f); + DSi::SDMMCFile = f; + + if (Config::DSiSDEnable) + { + f = Platform::OpenLocalFile(Config::DSiSDPath, "r+b"); + if (f) + DSi::SDIOFile = f; + else + DSi::SDIOFile = Platform::OpenLocalFile(Config::DSiSDPath, "w+b"); + } return Load_OK; } @@ -243,6 +253,8 @@ void LoadCheats() int LoadBIOS() { + DSi::CloseDSiNAND(); + int res; res = VerifyDSBIOS(); @@ -256,7 +268,7 @@ int LoadBIOS() res = VerifyDSiFirmware(); if (res != Load_OK) return res; - res = VerifyDSiNAND(); + res = SetupDSiNAND(); if (res != Load_OK) return res; } else @@ -285,6 +297,8 @@ int LoadBIOS() int LoadROM(const char* file, int slot) { + DSi::CloseDSiNAND(); + int res; bool directboot = Config::DirectBoot != 0; @@ -305,7 +319,7 @@ int LoadROM(const char* file, int slot) res = VerifyDSiFirmware(); if (res != Load_OK) return res; - res = VerifyDSiNAND(); + res = SetupDSiNAND(); if (res != Load_OK) return res; GBACart::Eject(); @@ -376,10 +390,14 @@ void UnloadROM(int slot) } ROMPath[slot][0] = '\0'; + + DSi::CloseDSiNAND(); } int Reset() { + DSi::CloseDSiNAND(); + int res; bool directboot = Config::DirectBoot != 0; @@ -394,7 +412,7 @@ int Reset() res = VerifyDSiFirmware(); if (res != Load_OK) return res; - res = VerifyDSiNAND(); + res = SetupDSiNAND(); if (res != Load_OK) return res; GBACart::Eject(); -- cgit v1.2.3