mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 06:10:03 -06:00
Refactor DSi_NAND (#1844)
* Refactor diskio's contents - Change ff_disk_read_cb/write_cb into a std::function instead of a raw pointer - Add const specifiers as needed * Refactor DSi_NAND to manage the file system's mounted lifetime with RAII * Split NANDMount into NANDMount and NANDImage - NANDImage is used for information about the NAND that doesn't require decryption or filesystem access - NANDMount is used to actually access the file system - Both classes manage their respective resources (the NAND file handle and the NAND's mount) with RAII - Also split the file loading into another function that I will remove in a later PR * Make NANDMount immovable * Remove NAND-loading code that I had sectioned off into a function - Incomplete copypasta - I must have gotten distracted * Tidy up NANDImage's initialization - Don't unmount the disk image if the constructor fails (that's NANDMount's job now) - Only assign CurFile if the constructor succeeds * Add some const-correctness * Move DSi NAND initialization to the frontend - The NANDImage is now installed via a unique_ptr in DSi * Remove Platform::DSi_NANDPath - Not Config::DSiNANDPath; that can still be configured as usual - The core no longer needs to care
This commit is contained in:

committed by
GitHub

parent
b2fcff97c1
commit
d4e51f8060
@ -20,6 +20,7 @@
|
||||
#include <string.h>
|
||||
#include "DSi.h"
|
||||
#include "DSi_SD.h"
|
||||
#include "DSi_NAND.h"
|
||||
#include "DSi_NWifi.h"
|
||||
#include "Platform.h"
|
||||
|
||||
@ -137,11 +138,8 @@ void DSi_SDHost::Reset()
|
||||
else
|
||||
sd = nullptr;
|
||||
|
||||
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 = new DSi_MMCStorage(this, *DSi::NANDImage);
|
||||
mmc->SetCID(DSi::NANDImage->GetEMMCID().data());
|
||||
|
||||
Ports[0] = sd;
|
||||
Ports[1] = mmc;
|
||||
@ -768,14 +766,9 @@ void DSi_SDHost::CheckSwapFIFO()
|
||||
|
||||
#define MMC_DESC (Internal?"NAND":"SDcard")
|
||||
|
||||
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const std::string& filename)
|
||||
: DSi_SDDevice(host)
|
||||
DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, DSi_NAND::NANDImage& nand)
|
||||
: DSi_SDDevice(host), Internal(true), NAND(&nand), SD(nullptr)
|
||||
{
|
||||
Internal = internal;
|
||||
File = Platform::OpenLocalFile(filename, FileMode::ReadWriteExisting);
|
||||
|
||||
SD = nullptr;
|
||||
|
||||
ReadOnly = false;
|
||||
}
|
||||
|
||||
@ -783,7 +776,7 @@ DSi_MMCStorage::DSi_MMCStorage(DSi_SDHost* host, bool internal, const std::strin
|
||||
: DSi_SDDevice(host)
|
||||
{
|
||||
Internal = internal;
|
||||
File = nullptr;
|
||||
NAND = nullptr;
|
||||
|
||||
SD = new FATStorage(filename, size, readonly, sourcedir);
|
||||
SD->Open();
|
||||
@ -798,10 +791,8 @@ DSi_MMCStorage::~DSi_MMCStorage()
|
||||
SD->Close();
|
||||
delete SD;
|
||||
}
|
||||
if (File)
|
||||
{
|
||||
CloseFile(File);
|
||||
}
|
||||
|
||||
// Do not close the NANDImage, it's not owned by this object
|
||||
}
|
||||
|
||||
void DSi_MMCStorage::Reset()
|
||||
@ -925,7 +916,7 @@ void DSi_MMCStorage::SendCMD(u8 cmd, u32 param)
|
||||
|
||||
case 12: // stop operation
|
||||
SetState(0x04);
|
||||
if (File) FileFlush(File);
|
||||
if (NAND) FileFlush(NAND->GetFile());
|
||||
RWCommand = 0;
|
||||
Host->SendResponse(CSR, true);
|
||||
return;
|
||||
@ -1052,10 +1043,10 @@ u32 DSi_MMCStorage::ReadBlock(u64 addr)
|
||||
{
|
||||
SD->ReadSectors((u32)(addr >> 9), 1, data);
|
||||
}
|
||||
else if (File)
|
||||
else if (NAND)
|
||||
{
|
||||
FileSeek(File, addr, FileSeekOrigin::Start);
|
||||
FileRead(&data[addr & 0x1FF], 1, len, File);
|
||||
FileSeek(NAND->GetFile(), addr, FileSeekOrigin::Start);
|
||||
FileRead(&data[addr & 0x1FF], 1, len, NAND->GetFile());
|
||||
}
|
||||
|
||||
return Host->DataRX(&data[addr & 0x1FF], len);
|
||||
@ -1082,10 +1073,10 @@ u32 DSi_MMCStorage::WriteBlock(u64 addr)
|
||||
{
|
||||
SD->WriteSectors((u32)(addr >> 9), 1, data);
|
||||
}
|
||||
else if (File)
|
||||
else if (NAND)
|
||||
{
|
||||
FileSeek(File, addr, FileSeekOrigin::Start);
|
||||
FileWrite(&data[addr & 0x1FF], 1, len, File);
|
||||
FileSeek(NAND->GetFile(), addr, FileSeekOrigin::Start);
|
||||
FileWrite(&data[addr & 0x1FF], 1, len, NAND->GetFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user