support for file based and sd partition based emusd

This commit is contained in:
Christoph Baumann
2025-05-20 00:40:48 +02:00
parent 865b9dc1a4
commit 9b95d026f3
25 changed files with 1691 additions and 294 deletions

View File

@@ -1,8 +1,12 @@
#include "sfd.h"
#include <storage/emmc.h>
#include <storage/sdmmc.h>
#include <storage/file_based_storage.h>
#include <libs/fatfs/diskio.h>
#include <string.h>
static bool file_based;
static sdmmc_storage_t *_storage;
static u32 _offset;
static u32 _size;
@@ -14,7 +18,11 @@ static void ensure_partition(){
}
sdmmc_storage_t *sfd_get_storage(){
return _storage;
if(file_based){
return NULL;
}else{
return _storage;
}
}
int sfd_read(u32 sector, u32 count, void *buff){
@@ -22,8 +30,13 @@ int sfd_read(u32 sector, u32 count, void *buff){
if(sector + count > _size){
return 0;
}
ensure_partition();
res = sdmmc_storage_read(_storage, sector + _offset, count, buff);
if(file_based){
res = file_based_storage_read(sector, count, buff);
}else{
ensure_partition();
res = sdmmc_storage_read(_storage, sector + _offset, count, buff);
}
return res;
}
@@ -32,8 +45,14 @@ int sfd_write(u32 sector, u32 count, void *buff){
if(sector + count > _size){
return 0;
}
ensure_partition();
res = sdmmc_storage_write(_storage, sector + _offset, count, buff);
if(file_based){
res = file_based_storage_write(sector, count, buff);
}else{
ensure_partition();
res = sdmmc_storage_write(_storage, sector + _offset, count, buff);
}
return res;
}
@@ -45,10 +64,23 @@ bool sfd_init(sdmmc_storage_t *storage, u32 offset, u32 size){
return true;
}
bool sfd_file_based_init(const char *base_path) {
file_based = true;
if(!file_based_storage_init(base_path)){
gfx_printf("file based init fail\n");
return 0;
}
_size = file_based_storage_get_total_size();
disk_set_info(DRIVE_SFD, SET_SECTOR_COUNT, &_size);
return 1;
}
void sfd_end(){
_storage = NULL;
_offset = 0;
_size = 0;
u32 size = 0;
file_based = false;
disk_set_info(DRIVE_SFD, SET_SECTOR_COUNT, &size);
}

View File

@@ -7,6 +7,7 @@
int sfd_read(u32 sector, u32 count, void *buff);
int sfd_write(u32 sector, u32 count, void *buff);
bool sfd_file_based_init(const char *base_path);
bool sfd_init(sdmmc_storage_t *storage, u32 offset, u32 size);
void sfd_end();