keep only one handle of the NAND file around

This commit is contained in:
RSDuck
2021-01-17 19:56:02 +01:00
parent 53d5def919
commit 1d6cc3c6ef
5 changed files with 60 additions and 46 deletions

View File

@ -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();