diff options
author | Adrian Siekierka <kontakt@asie.pl> | 2023-12-15 08:19:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-15 08:19:53 +0100 |
commit | 6f47c9ed4c0e5b1035089805f272c6965343f113 (patch) | |
tree | fadad3548cea8de7fe5ae380d4ff857909c9cb27 /src/FATStorage.cpp | |
parent | 9bfc9c08ffe88de4b54734d6fd03182c0a51e181 (diff) |
Support emulating R4 Revolution/M3DS Simply cartridges. (#1854)
* Support emulating R4 Revolution/M3DS Simply cartridges.
* NDSCartR4: Write state information to savestate file.
* NDSCart: Use strncmp instead of strcmp for R4 detection.
* NDSCartR4: stylistic improvements
* NDSCartR4: rudimentary Ace3DS support
* NDSCartR4: fix boot when firmware enabled
* NDSCartR4: Fix for namespace changes
---------
Co-authored-by: RSDuck <RSDuck@users.noreply.github.com>
Diffstat (limited to 'src/FATStorage.cpp')
-rw-r--r-- | src/FATStorage.cpp | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/FATStorage.cpp b/src/FATStorage.cpp index 2de42e8..52011a8 100644 --- a/src/FATStorage.cpp +++ b/src/FATStorage.cpp @@ -144,6 +144,48 @@ bool FATStorage::InjectFile(const std::string& path, u8* data, u32 len) return nwrite==len; } +u32 FATStorage::ReadFile(const std::string& path, u32 start, u32 len, u8* data) +{ + if (!File) return false; + if (FF_File) return false; + + FF_File = File; + FF_FileSize = FileSize; + ff_disk_open(FF_ReadStorage, FF_WriteStorage, (LBA_t)(FileSize>>9)); + + FRESULT res; + FATFS fs; + + res = f_mount(&fs, "0:", 1); + if (res != FR_OK) + { + ff_disk_close(); + FF_File = nullptr; + return false; + } + + std::string prefixedPath("0:/"); + prefixedPath += path; + FF_FIL file; + res = f_open(&file, prefixedPath.c_str(), FA_READ); + if (res != FR_OK) + { + f_unmount("0:"); + ff_disk_close(); + FF_File = nullptr; + return false; + } + + u32 nread; + f_lseek(&file, start); + f_read(&file, data, len, &nread); + f_close(&file); + + f_unmount("0:"); + ff_disk_close(); + FF_File = nullptr; + return nread; +} u32 FATStorage::ReadSectors(u32 start, u32 num, u8* data) const { @@ -156,6 +198,11 @@ u32 FATStorage::WriteSectors(u32 start, u32 num, const u8* data) return WriteSectorsInternal(File, FileSize, start, num, data); } +u64 FATStorage::GetSectorCount() const +{ + return FileSize / 0x200; +} + FileHandle* FATStorage::FF_File; u64 FATStorage::FF_FileSize; |