mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -06:00
properly make the DSi NAND instance-unique
This commit is contained in:
43
src/DSi.cpp
43
src/DSi.cpp
@ -511,30 +511,24 @@ void SetupDirectBoot()
|
|||||||
ARM9Write32(0x02FFE000+i, tmp);
|
ARM9Write32(0x02FFE000+i, tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE* nand = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_NANDPath), "r+b");
|
if (DSi_NAND::Init(&DSi::ARM7iBIOS[0x8308]))
|
||||||
if (nand)
|
|
||||||
{
|
{
|
||||||
if (DSi_NAND::Init(nand, &DSi::ARM7iBIOS[0x8308]))
|
u8 userdata[0x1B0];
|
||||||
{
|
DSi_NAND::ReadUserData(userdata);
|
||||||
u8 userdata[0x1B0];
|
for (u32 i = 0; i < 0x128; i+=4)
|
||||||
DSi_NAND::ReadUserData(userdata);
|
ARM9Write32(0x02000400+i, *(u32*)&userdata[0x88+i]);
|
||||||
for (u32 i = 0; i < 0x128; i+=4)
|
|
||||||
ARM9Write32(0x02000400+i, *(u32*)&userdata[0x88+i]);
|
|
||||||
|
|
||||||
u8 hwinfoS[0xA4];
|
u8 hwinfoS[0xA4];
|
||||||
u8 hwinfoN[0x9C];
|
u8 hwinfoN[0x9C];
|
||||||
DSi_NAND::ReadHardwareInfo(hwinfoS, hwinfoN);
|
DSi_NAND::ReadHardwareInfo(hwinfoS, hwinfoN);
|
||||||
|
|
||||||
for (u32 i = 0; i < 0x14; i+=4)
|
for (u32 i = 0; i < 0x14; i+=4)
|
||||||
ARM9Write32(0x02000600+i, *(u32*)&hwinfoN[0x88+i]);
|
ARM9Write32(0x02000600+i, *(u32*)&hwinfoN[0x88+i]);
|
||||||
|
|
||||||
for (u32 i = 0; i < 0x18; i+=4)
|
for (u32 i = 0; i < 0x18; i+=4)
|
||||||
ARM9Write32(0x02FFFD68+i, *(u32*)&hwinfoS[0x88+i]);
|
ARM9Write32(0x02FFFD68+i, *(u32*)&hwinfoS[0x88+i]);
|
||||||
|
|
||||||
DSi_NAND::DeInit();
|
DSi_NAND::DeInit();
|
||||||
}
|
|
||||||
|
|
||||||
fclose(nand);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 nwifiver = SPI_Firmware::GetNWifiVersion();
|
u8 nwifiver = SPI_Firmware::GetNWifiVersion();
|
||||||
@ -707,19 +701,14 @@ bool LoadNAND()
|
|||||||
{
|
{
|
||||||
printf("Loading DSi NAND\n");
|
printf("Loading DSi NAND\n");
|
||||||
|
|
||||||
FILE* nand = Platform::OpenLocalFile(Platform::GetConfigString(Platform::DSi_NANDPath), "r+b");
|
if (!DSi_NAND::Init(&DSi::ARM7iBIOS[0x8308]))
|
||||||
if (!nand)
|
|
||||||
{
|
|
||||||
printf("Failed to open DSi NAND\n");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!DSi_NAND::Init(nand, &DSi::ARM7iBIOS[0x8308]))
|
|
||||||
{
|
{
|
||||||
printf("Failed to load DSi NAND\n");
|
printf("Failed to load DSi NAND\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FILE* nand = DSi_NAND::GetFile();
|
||||||
|
|
||||||
// Make sure NWRAM is accessible.
|
// Make sure NWRAM is accessible.
|
||||||
// The Bits are set to the startup values in Reset() and we might
|
// The Bits are set to the startup values in Reset() and we might
|
||||||
// still have them on default (0) or some bits cleared by the previous
|
// still have them on default (0) or some bits cleared by the previous
|
||||||
|
@ -49,8 +49,48 @@ UINT FF_ReadNAND(BYTE* buf, LBA_t sector, UINT num);
|
|||||||
UINT FF_WriteNAND(BYTE* buf, LBA_t sector, UINT num);
|
UINT FF_WriteNAND(BYTE* buf, LBA_t sector, UINT num);
|
||||||
|
|
||||||
|
|
||||||
bool Init(FILE* nandfile, u8* es_keyY)
|
bool Init(u8* es_keyY)
|
||||||
{
|
{
|
||||||
|
CurFile = nullptr;
|
||||||
|
|
||||||
|
std::string nandpath = Platform::GetConfigString(Platform::DSi_NANDPath);
|
||||||
|
std::string instnand = nandpath + Platform::InstanceFileSuffix();
|
||||||
|
|
||||||
|
FILE* nandfile = Platform::OpenLocalFile(instnand, "r+b");
|
||||||
|
if ((!nandfile) && (Platform::InstanceID() > 0))
|
||||||
|
{
|
||||||
|
FILE* orig = Platform::OpenLocalFile(nandpath, "rb");
|
||||||
|
if (!orig)
|
||||||
|
{
|
||||||
|
printf("Failed to open DSi NAND\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(orig, 0, SEEK_END);
|
||||||
|
long len = ftell(orig);
|
||||||
|
fseek(orig, 0, SEEK_SET);
|
||||||
|
|
||||||
|
nandfile = Platform::OpenLocalFile(instnand, "w+b");
|
||||||
|
if (nandfile)
|
||||||
|
{
|
||||||
|
u8* tmpbuf = new u8[0x10000];
|
||||||
|
for (long i = 0; i < len; i+=0x10000)
|
||||||
|
{
|
||||||
|
long blklen = 0x10000;
|
||||||
|
if ((i+blklen) > len) blklen = len-i;
|
||||||
|
|
||||||
|
fread(tmpbuf, blklen, 1, orig);
|
||||||
|
fwrite(tmpbuf, blklen, 1, nandfile);
|
||||||
|
}
|
||||||
|
delete[] tmpbuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(orig);
|
||||||
|
fclose(nandfile);
|
||||||
|
|
||||||
|
nandfile = Platform::OpenLocalFile(instnand, "r+b");
|
||||||
|
}
|
||||||
|
|
||||||
if (!nandfile)
|
if (!nandfile)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -138,10 +178,17 @@ void DeInit()
|
|||||||
f_unmount("0:");
|
f_unmount("0:");
|
||||||
ff_disk_close();
|
ff_disk_close();
|
||||||
|
|
||||||
|
if (CurFile) fclose(CurFile);
|
||||||
CurFile = nullptr;
|
CurFile = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FILE* GetFile()
|
||||||
|
{
|
||||||
|
return CurFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void GetIDs(u8* emmc_cid, u64& consoleid)
|
void GetIDs(u8* emmc_cid, u64& consoleid)
|
||||||
{
|
{
|
||||||
memcpy(emmc_cid, eMMC_CID, 16);
|
memcpy(emmc_cid, eMMC_CID, 16);
|
||||||
|
@ -34,9 +34,11 @@ enum
|
|||||||
TitleData_BannerSav,
|
TitleData_BannerSav,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Init(FILE* nand, u8* es_keyY);
|
bool Init(u8* es_keyY);
|
||||||
void DeInit();
|
void DeInit();
|
||||||
|
|
||||||
|
FILE* GetFile();
|
||||||
|
|
||||||
void GetIDs(u8* emmc_cid, u64& consoleid);
|
void GetIDs(u8* emmc_cid, u64& consoleid);
|
||||||
|
|
||||||
void ReadHardwareInfo(u8* dataS, u8* dataN);
|
void ReadHardwareInfo(u8* dataS, u8* dataN);
|
||||||
|
@ -136,7 +136,10 @@ void DSi_SDHost::Reset()
|
|||||||
else
|
else
|
||||||
sd = nullptr;
|
sd = nullptr;
|
||||||
|
|
||||||
mmc = new DSi_MMCStorage(this, true, Platform::GetConfigString(Platform::DSi_NANDPath));
|
std::string nandpath = Platform::GetConfigString(Platform::DSi_NANDPath);
|
||||||
|
std::string instnand = nandpath + Platform::InstanceFileSuffix();
|
||||||
|
|
||||||
|
mmc = new DSi_MMCStorage(this, true, instnand);
|
||||||
mmc->SetCID(DSi::eMMC_CID);
|
mmc->SetCID(DSi::eMMC_CID);
|
||||||
|
|
||||||
Ports[0] = sd;
|
Ports[0] = sd;
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
#include "ui_TitleImportDialog.h"
|
#include "ui_TitleImportDialog.h"
|
||||||
|
|
||||||
|
|
||||||
FILE* TitleManagerDialog::curNAND = nullptr;
|
bool TitleManagerDialog::NANDInited = false;
|
||||||
TitleManagerDialog* TitleManagerDialog::currentDlg = nullptr;
|
TitleManagerDialog* TitleManagerDialog::currentDlg = nullptr;
|
||||||
|
|
||||||
extern std::string EmuDirectory;
|
extern std::string EmuDirectory;
|
||||||
@ -136,6 +136,8 @@ void TitleManagerDialog::createTitleItem(u32 category, u32 titleid)
|
|||||||
|
|
||||||
bool TitleManagerDialog::openNAND()
|
bool TitleManagerDialog::openNAND()
|
||||||
{
|
{
|
||||||
|
NANDInited = false;
|
||||||
|
|
||||||
FILE* bios7i = Platform::OpenLocalFile(Config::DSiBIOS7Path, "rb");
|
FILE* bios7i = Platform::OpenLocalFile(Config::DSiBIOS7Path, "rb");
|
||||||
if (!bios7i)
|
if (!bios7i)
|
||||||
return false;
|
return false;
|
||||||
@ -145,28 +147,21 @@ bool TitleManagerDialog::openNAND()
|
|||||||
fread(es_keyY, 16, 1, bios7i);
|
fread(es_keyY, 16, 1, bios7i);
|
||||||
fclose(bios7i);
|
fclose(bios7i);
|
||||||
|
|
||||||
curNAND = Platform::OpenLocalFile(Config::DSiNANDPath, "r+b");
|
if (!DSi_NAND::Init(es_keyY))
|
||||||
if (!curNAND)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!DSi_NAND::Init(curNAND, es_keyY))
|
|
||||||
{
|
{
|
||||||
fclose(curNAND);
|
|
||||||
curNAND = nullptr;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NANDInited = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TitleManagerDialog::closeNAND()
|
void TitleManagerDialog::closeNAND()
|
||||||
{
|
{
|
||||||
if (curNAND)
|
if (NANDInited)
|
||||||
{
|
{
|
||||||
DSi_NAND::DeInit();
|
DSi_NAND::DeInit();
|
||||||
|
NANDInited = false;
|
||||||
fclose(curNAND);
|
|
||||||
curNAND = nullptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ public:
|
|||||||
explicit TitleManagerDialog(QWidget* parent);
|
explicit TitleManagerDialog(QWidget* parent);
|
||||||
~TitleManagerDialog();
|
~TitleManagerDialog();
|
||||||
|
|
||||||
static FILE* curNAND;
|
static bool NANDInited;
|
||||||
static bool openNAND();
|
static bool openNAND();
|
||||||
static void closeNAND();
|
static void closeNAND();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user