Slight fixups with FATStorage (#1934)

* Reload the SD card for `CartSD` and all subclasses

* Make `ROMManager::LoadDLDISDCard` delegate to `GetDLDISDCardArgs`

* Add a method overload for `CartSD::SetSDCard`

* Initialize new SD card images with the correct size

* Sync the old card to the host (if applicable) when move-assigning a new one

* Only sync the old card to the host if it's not read-only

* Remove static state in `FATStorage`

- Replace `FF_ReadStorage` and `FF_WriteStorage` with lambda functions
- Keep open and use the single `File` handle throughout the `FATStorage`'s life
This commit is contained in:
Jesse Talavera
2024-01-03 07:32:17 -05:00
committed by GitHub
parent 8bfc6df8de
commit d1cbc41115
5 changed files with 51 additions and 60 deletions

View File

@ -28,6 +28,7 @@
#include "Platform.h"
#include "types.h"
#include "fatfs/ff.h"
#include "FATIO.h"
namespace melonDS
{
@ -39,6 +40,8 @@ namespace melonDS
struct FATStorageArgs
{
std::string Filename;
/// Size of the desired SD card in bytes, or 0 for auto-detect.
u64 Size;
bool ReadOnly;
std::optional<std::string> SourceDir;
@ -74,10 +77,8 @@ private:
Platform::FileHandle* File;
u64 FileSize;
static Platform::FileHandle* FF_File;
static u64 FF_FileSize;
static UINT FF_ReadStorage(BYTE* buf, LBA_t sector, UINT num);
static UINT FF_WriteStorage(const BYTE* buf, LBA_t sector, UINT num);
[[nodiscard]] ff_disk_read_cb FF_ReadStorage() const noexcept;
[[nodiscard]] ff_disk_write_cb FF_WriteStorage() const noexcept;
static u32 ReadSectorsInternal(Platform::FileHandle* file, u64 filelen, u32 start, u32 num, u8* data);
static u32 WriteSectorsInternal(Platform::FileHandle* file, u64 filelen, u32 start, u32 num, const u8* data);