add files into the DLDI volume
This commit is contained in:
parent
2aa1f81301
commit
bfb4769f6f
|
@ -121,7 +121,7 @@ if (ENABLE_OGLRENDERER)
|
||||||
|
|
||||||
target_include_directories(core PRIVATE ${EPOXY_INCLUDE_DIRS})
|
target_include_directories(core PRIVATE ${EPOXY_INCLUDE_DIRS})
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_libraries(core ole32 comctl32 ws2_32 shlwapi ${EPOXY_LIBRARIES})
|
target_link_libraries(core ole32 comctl32 ws2_32 ${EPOXY_LIBRARIES})
|
||||||
elseif (APPLE)
|
elseif (APPLE)
|
||||||
target_link_libraries(core ${EPOXY_LIBRARIES})
|
target_link_libraries(core ${EPOXY_LIBRARIES})
|
||||||
else()
|
else()
|
||||||
|
@ -129,7 +129,7 @@ if (ENABLE_OGLRENDERER)
|
||||||
endif()
|
endif()
|
||||||
else()
|
else()
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
target_link_libraries(core ole32 comctl32 ws2_32 shlwapi)
|
target_link_libraries(core ole32 comctl32 ws2_32)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(core rt)
|
target_link_libraries(core rt)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
#include <shlwapi.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#endif // __WIN32__
|
#endif // __WIN32__
|
||||||
|
@ -28,11 +28,14 @@
|
||||||
#include "Platform.h"
|
#include "Platform.h"
|
||||||
|
|
||||||
|
|
||||||
static int GetDirEntryType(struct dirent* entry)
|
static int GetDirEntryType(const char* path, struct dirent* entry)
|
||||||
{
|
{
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
BOOL res = PathIsDirectoryA(entry->d_name);
|
DWORD res = GetFileAttributesA(path);
|
||||||
return res ? 1:0;
|
if (res == INVALID_FILE_ATTRIBUTES) return -1;
|
||||||
|
if (res & FILE_ATTRIBUTE_DIRECTORY) return 1;
|
||||||
|
if (res & (FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_DEVICE | FILE_ATTRIBUTE_VIRTUAL)) return -1;
|
||||||
|
return 0;
|
||||||
#else
|
#else
|
||||||
if (entry->d_type == DT_DIR) return 1;
|
if (entry->d_type == DT_DIR) return 1;
|
||||||
if (entry->d_type == DT_REG) return 0;
|
if (entry->d_type == DT_REG) return 0;
|
||||||
|
@ -44,7 +47,7 @@ static int GetDirEntryType(struct dirent* entry)
|
||||||
FATStorage::FATStorage()
|
FATStorage::FATStorage()
|
||||||
{
|
{
|
||||||
printf("FATStorage begin\n");
|
printf("FATStorage begin\n");
|
||||||
bool res = Build(".", 0x40000000, "melonDLDI.bin");
|
bool res = Build("dldi", 0x20000000, "melonDLDI.bin");
|
||||||
printf("FATStorage result: %d\n", res);
|
printf("FATStorage result: %d\n", res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +110,47 @@ UINT FATStorage::FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool FATStorage::ImportFile(const char* path, const char* in)
|
||||||
|
{
|
||||||
|
FIL file;
|
||||||
|
FILE* fin;
|
||||||
|
FRESULT res;
|
||||||
|
|
||||||
|
fin = fopen(in, "rb");
|
||||||
|
if (!fin)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
fseek(fin, 0, SEEK_END);
|
||||||
|
u32 len = (u32)ftell(fin);
|
||||||
|
fseek(fin, 0, SEEK_SET);
|
||||||
|
|
||||||
|
res = f_open(&file, path, FA_CREATE_ALWAYS | FA_WRITE);
|
||||||
|
if (res != FR_OK)
|
||||||
|
{
|
||||||
|
fclose(fin);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 buf[0x1000];
|
||||||
|
for (u32 i = 0; i < len; i += 0x1000)
|
||||||
|
{
|
||||||
|
u32 blocklen;
|
||||||
|
if ((i + 0x1000) > len)
|
||||||
|
blocklen = len - i;
|
||||||
|
else
|
||||||
|
blocklen = 0x1000;
|
||||||
|
|
||||||
|
u32 nwrite;
|
||||||
|
fread(buf, blocklen, 1, fin);
|
||||||
|
f_write(&file, buf, blocklen, &nwrite);
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose(fin);
|
||||||
|
f_close(&file);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool FATStorage::BuildSubdirectory(const char* sourcedir, const char* path, int level)
|
bool FATStorage::BuildSubdirectory(const char* sourcedir, const char* path, int level)
|
||||||
{
|
{
|
||||||
if (level >= 32)
|
if (level >= 32)
|
||||||
|
@ -116,7 +160,7 @@ bool FATStorage::BuildSubdirectory(const char* sourcedir, const char* path, int
|
||||||
}
|
}
|
||||||
|
|
||||||
char fullpath[1024] = {0};
|
char fullpath[1024] = {0};
|
||||||
snprintf(fullpath, 1023, "%s/%s", sourcedir, path);
|
snprintf(fullpath, 1023, "%s%s", sourcedir, path);
|
||||||
|
|
||||||
DIR* dir = opendir(fullpath);
|
DIR* dir = opendir(fullpath);
|
||||||
if (!dir) return false;
|
if (!dir) return false;
|
||||||
|
@ -138,23 +182,30 @@ bool FATStorage::BuildSubdirectory(const char* sourcedir, const char* path, int
|
||||||
if (entry->d_name[1] == '.' && entry->d_name[2] == '\0') continue;
|
if (entry->d_name[1] == '.' && entry->d_name[2] == '\0') continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int entrytype = GetDirEntryType(entry);
|
snprintf(fullpath, 1023, "%s%s/%s", sourcedir, path, entry->d_name);
|
||||||
|
|
||||||
|
int entrytype = GetDirEntryType(fullpath, entry);
|
||||||
if (entrytype == -1) continue;
|
if (entrytype == -1) continue;
|
||||||
|
|
||||||
if (entrytype == 1) // directory
|
if (entrytype == 1) // directory
|
||||||
{
|
{
|
||||||
snprintf(fullpath, 1023, "%s/%s", path, entry->d_name);
|
snprintf(fullpath, 1023, "0:%s/%s", path, entry->d_name);
|
||||||
|
FRESULT fres = f_mkdir(fullpath);
|
||||||
printf("DIR: %s/%s\n", sourcedir, fullpath);
|
if (fres == FR_OK)
|
||||||
|
{
|
||||||
if (!BuildSubdirectory(sourcedir, fullpath, level+1))
|
if (!BuildSubdirectory(sourcedir, &fullpath[2], level+1))
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
res = false;
|
res = false;
|
||||||
}
|
}
|
||||||
else // file
|
else // file
|
||||||
{
|
{
|
||||||
snprintf(fullpath, 1023, "%s/%s/%s", sourcedir, path, entry->d_name);
|
char importpath[1024] = {0};
|
||||||
|
snprintf(importpath, 1023, "0:%s/%s", path, entry->d_name);
|
||||||
printf("FILE: %s\n", fullpath);
|
printf("importing %s to %s\n", fullpath, importpath);
|
||||||
|
if (!ImportFile(importpath, fullpath))
|
||||||
|
res = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,7 +218,7 @@ bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename)
|
||||||
{
|
{
|
||||||
filesize = size;
|
filesize = size;
|
||||||
|
|
||||||
FF_File = Platform::OpenLocalFile(filename, "wb");
|
FF_File = Platform::OpenLocalFile(filename, "w+b");
|
||||||
if (!FF_File)
|
if (!FF_File)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -176,8 +227,11 @@ bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename)
|
||||||
|
|
||||||
FRESULT res;
|
FRESULT res;
|
||||||
|
|
||||||
|
// TODO: determine proper FAT type!
|
||||||
|
// for example: libfat tries to determine the FAT type from the number of clusters
|
||||||
|
// which doesn't match the way fatfs handles autodetection
|
||||||
MKFS_PARM fsopt;
|
MKFS_PARM fsopt;
|
||||||
fsopt.fmt = FM_FAT | FM_FAT32;
|
fsopt.fmt = FM_FAT;// | FM_FAT32;
|
||||||
fsopt.au_size = 0;
|
fsopt.au_size = 0;
|
||||||
fsopt.align = 1;
|
fsopt.align = 1;
|
||||||
fsopt.n_fat = 1;
|
fsopt.n_fat = 1;
|
||||||
|
@ -187,8 +241,14 @@ bool FATStorage::Build(const char* sourcedir, u64 size, const char* filename)
|
||||||
res = f_mkfs("0:", &fsopt, workbuf, sizeof(workbuf));
|
res = f_mkfs("0:", &fsopt, workbuf, sizeof(workbuf));
|
||||||
printf("MKFS RES %d\n", res);
|
printf("MKFS RES %d\n", res);
|
||||||
|
|
||||||
|
FATFS fs;
|
||||||
|
res = f_mount(&fs, "0:", 0);
|
||||||
|
printf("MOUNT RES %d\n", res);
|
||||||
|
|
||||||
BuildSubdirectory(sourcedir, "", 0);
|
BuildSubdirectory(sourcedir, "", 0);
|
||||||
|
|
||||||
|
f_unmount("0:");
|
||||||
|
|
||||||
ff_disk_close();
|
ff_disk_close();
|
||||||
fclose(FF_File);
|
fclose(FF_File);
|
||||||
FF_File = nullptr;
|
FF_File = nullptr;
|
||||||
|
|
|
@ -40,6 +40,7 @@ private:
|
||||||
static UINT FF_ReadStorage(BYTE* buf, LBA_t sector, UINT num);
|
static UINT FF_ReadStorage(BYTE* buf, LBA_t sector, UINT num);
|
||||||
static UINT FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num);
|
static UINT FF_WriteStorage(BYTE* buf, LBA_t sector, UINT num);
|
||||||
|
|
||||||
|
bool ImportFile(const char* path, const char* in);
|
||||||
bool BuildSubdirectory(const char* sourcedir, const char* path, int level);
|
bool BuildSubdirectory(const char* sourcedir, const char* path, int level);
|
||||||
bool Build(const char* sourcedir, u64 size, const char* filename);
|
bool Build(const char* sourcedir, u64 size, const char* filename);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1168,8 +1168,8 @@ CartHomebrew::CartHomebrew(u8* rom, u32 len, u32 chipid) : CartCommon(rom, len,
|
||||||
if (Config::DLDIEnable)
|
if (Config::DLDIEnable)
|
||||||
{
|
{
|
||||||
ApplyDLDIPatch(melonDLDI, sizeof(melonDLDI));
|
ApplyDLDIPatch(melonDLDI, sizeof(melonDLDI));
|
||||||
SDFile = Platform::OpenLocalFile(Config::DLDISDPath, "r+b");
|
|
||||||
test = new FATStorage();
|
test = new FATStorage();
|
||||||
|
SDFile = Platform::OpenLocalFile(/*Config::DLDISDPath*/"melonDLDI.bin", "r+b");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
SDFile = nullptr;
|
SDFile = nullptr;
|
||||||
|
@ -1188,7 +1188,7 @@ void CartHomebrew::Reset()
|
||||||
if (SDFile) fclose(SDFile);
|
if (SDFile) fclose(SDFile);
|
||||||
|
|
||||||
if (Config::DLDIEnable)
|
if (Config::DLDIEnable)
|
||||||
SDFile = Platform::OpenLocalFile(Config::DLDISDPath, "r+b");
|
SDFile = Platform::OpenLocalFile(/*Config::DLDISDPath*/"melonDLDI.bin", "r+b");
|
||||||
else
|
else
|
||||||
SDFile = nullptr;
|
SDFile = nullptr;
|
||||||
}
|
}
|
||||||
|
@ -1224,7 +1224,7 @@ int CartHomebrew::ROMCommandStart(u8* cmd, u8* data, u32 len)
|
||||||
{
|
{
|
||||||
u32 sector = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4];
|
u32 sector = (cmd[1]<<24) | (cmd[2]<<16) | (cmd[3]<<8) | cmd[4];
|
||||||
u64 addr = sector * 0x200ULL;
|
u64 addr = sector * 0x200ULL;
|
||||||
|
//printf("SD READ: %08X, %p\n", sector, SDFile);
|
||||||
if (SDFile)
|
if (SDFile)
|
||||||
{
|
{
|
||||||
fseek(SDFile, addr, SEEK_SET);
|
fseek(SDFile, addr, SEEK_SET);
|
||||||
|
|
Loading…
Reference in New Issue