Core: Add ENABLE_DIRECTORIES to optionally slim down VFS further

This commit is contained in:
Vicki Pfau 2025-02-28 16:18:02 -08:00
parent c302d99d1b
commit 51e813aa9a
12 changed files with 66 additions and 33 deletions

View File

@ -857,7 +857,7 @@ if(ENABLE_SCRIPTING)
endif()
if(ENABLE_VFS)
list(APPEND ENABLES VFS)
list(APPEND ENABLES VFS DIRECTORIES)
endif()
foreach(FEATURE IN LISTS FEATURES)
@ -1001,7 +1001,7 @@ endif()
if(BUILD_LIBRETRO)
file(GLOB RETRO_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/libretro/*.c)
add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC} ${VFS_SRC})
add_library(${BINARY_NAME}_libretro SHARED ${CORE_SRC} ${RETRO_SRC} ${CORE_VFS_SRC})
add_dependencies(${BINARY_NAME}_libretro ${BINARY_NAME}-version-info)
set_target_properties(${BINARY_NAME}_libretro PROPERTIES PREFIX "" COMPILE_DEFINITIONS "__LIBRETRO__;COLOR_16_BIT;COLOR_5_6_5;DISABLE_THREADING;MGBA_STANDALONE;${OS_DEFINES};${FUNCTION_DEFINES};ENABLE_VFS;MINIMAL_CORE=2")
target_link_libraries(${BINARY_NAME}_libretro ${OS_LIB})

View File

@ -50,7 +50,7 @@ struct VFile {
bool (*sync)(struct VFile* vf, void* buffer, size_t size);
};
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct VDirEntry {
const char* (*name)(struct VDirEntry* vde);
enum VFSType (*type)(struct VDirEntry* vde);
@ -64,7 +64,9 @@ struct VDir {
struct VDir* (*openDir)(struct VDir* vd, const char* name);
bool (*deleteFile)(struct VDir* vd, const char* name);
};
#endif
#ifdef ENABLE_VFS
struct VFile* VFileOpen(const char* path, int flags);
#endif
@ -85,7 +87,7 @@ struct VFile* VFileMemChunk(const void* mem, size_t size);
struct mCircleBuffer;
struct VFile* VFileFIFO(struct mCircleBuffer* backing);
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct VDir* VDirOpen(const char* path);
struct VDir* VDirOpenArchive(const char* path);

View File

@ -118,7 +118,7 @@ bool mCheatSaveFile(struct mCheatDevice*, struct VFile*);
bool mCheatParseLibretroFile(struct mCheatDevice*, struct VFile*);
bool mCheatParseEZFChtFile(struct mCheatDevice*, struct VFile*);
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
void mCheatAutosave(struct mCheatDevice*);
#endif

View File

@ -47,7 +47,7 @@ struct mCore {
struct mDebuggerSymbols* symbolTable;
struct mVideoLogger* videoLogger;
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct mDirectorySet dirs;
#endif
#ifndef MINIMAL_CORE
@ -188,18 +188,20 @@ bool mCorePreloadFile(struct mCore* core, const char* path);
bool mCorePreloadVFCB(struct mCore* core, struct VFile* vf, void (cb)(size_t, size_t, void*), void* context);
bool mCorePreloadFileCB(struct mCore* core, const char* path, void (cb)(size_t, size_t, void*), void* context);
bool mCoreLoadSaveFile(struct mCore* core, const char* path, bool temporary);
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
bool mCoreAutoloadSave(struct mCore* core);
bool mCoreAutoloadPatch(struct mCore* core);
bool mCoreAutoloadCheats(struct mCore* core);
bool mCoreLoadSaveFile(struct mCore* core, const char* path, bool temporary);
bool mCoreSaveState(struct mCore* core, int slot, int flags);
bool mCoreLoadState(struct mCore* core, int slot, int flags);
struct VFile* mCoreGetState(struct mCore* core, int slot, bool write);
void mCoreDeleteState(struct mCore* core, int slot);
void mCoreTakeScreenshot(struct mCore* core);
#endif
bool mCoreTakeScreenshotVF(struct mCore* core, struct VFile* vf);
#endif

View File

@ -10,7 +10,7 @@
CXX_GUARD_START
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct VDir;
struct mDirectorySet {

View File

@ -622,7 +622,7 @@ bool mCheatSaveFile(struct mCheatDevice* device, struct VFile* vf) {
return true;
}
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
void mCheatAutosave(struct mCheatDevice* device) {
if (!device->autosave) {
return;

View File

@ -96,8 +96,9 @@ struct mCore* mCoreCreate(enum mPlatform platform) {
#endif
struct mCore* mCoreFind(const char* path) {
struct VDir* archive = VDirOpenArchive(path);
struct mCore* core = NULL;
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct VDir* archive = VDirOpenArchive(path);
if (archive) {
struct VDirEntry* dirent = archive->listNext(archive);
while (dirent) {
@ -114,7 +115,9 @@ struct mCore* mCoreFind(const char* path) {
dirent = archive->listNext(archive);
}
archive->close(archive);
} else {
} else
#endif
{
struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) {
return NULL;
@ -133,7 +136,15 @@ bool mCoreLoadFile(struct mCore* core, const char* path) {
#ifdef FIXED_ROM_BUFFER
return mCorePreloadFile(core, path);
#else
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM);
#else
struct VFile* rom = VFileOpen(path, O_RDONLY);
if (rom && !core->isROM(rom)) {
rom->close(rom);
rom = NULL;
}
#endif
if (!rom) {
return false;
}
@ -210,7 +221,15 @@ bool mCorePreloadVFCB(struct mCore* core, struct VFile* vf, void (cb)(size_t, si
}
bool mCorePreloadFileCB(struct mCore* core, const char* path, void (cb)(size_t, size_t, void*), void* context) {
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct VFile* rom = mDirectorySetOpenPath(&core->dirs, path, core->isROM);
#else
struct VFile* rom = VFileOpen(path, O_RDONLY);
if (rom && !core->isROM(rom)) {
rom->close(rom);
rom = NULL;
}
#endif
if (!rom) {
return false;
}
@ -222,6 +241,19 @@ bool mCorePreloadFileCB(struct mCore* core, const char* path, void (cb)(size_t,
return ret;
}
bool mCoreLoadSaveFile(struct mCore* core, const char* path, bool temporary) {
struct VFile* vf = VFileOpen(path, O_CREAT | O_RDWR);
if (!vf) {
return false;
}
if (temporary) {
return core->loadTemporarySave(core, vf);
} else {
return core->loadSave(core, vf);
}
}
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
bool mCoreAutoloadSave(struct mCore* core) {
if (!core->dirs.save) {
return false;
@ -277,18 +309,6 @@ bool mCoreAutoloadCheats(struct mCore* core) {
return success;
}
bool mCoreLoadSaveFile(struct mCore* core, const char* path, bool temporary) {
struct VFile* vf = VFileOpen(path, O_CREAT | O_RDWR);
if (!vf) {
return false;
}
if (temporary) {
return core->loadTemporarySave(core, vf);
} else {
return core->loadSave(core, vf);
}
}
bool mCoreSaveState(struct mCore* core, int slot, int flags) {
struct VFile* vf = mCoreGetState(core, slot, true);
if (!vf) {
@ -373,6 +393,7 @@ void mCoreTakeScreenshot(struct mCore* core) {
mLOG(STATUS, WARN, "Failed to take screenshot");
}
#endif
#endif
bool mCoreTakeScreenshotVF(struct mCore* core, struct VFile* vf) {
#ifdef USE_PNG
@ -406,7 +427,7 @@ void mCoreLoadConfig(struct mCore* core) {
void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config) {
mCoreConfigMap(config, &core->opts);
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
mDirectorySetMapOptions(&core->dirs, &core->opts);
#endif
if (core->opts.audioBuffers) {

View File

@ -8,7 +8,7 @@
#include <mgba/core/config.h>
#include <mgba-util/vfs.h>
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
void mDirectorySetInit(struct mDirectorySet* dirs) {
dirs->base = NULL;
dirs->archive = NULL;

View File

@ -53,6 +53,10 @@
#cmakedefine ENABLE_DEBUGGERS
#endif
#ifndef ENABLE_DIRECTORIES
#cmakedefine ENABLE_DIRECTORIES
#endif
#ifndef ENABLE_GDB_STUB
#cmakedefine ENABLE_GDB_STUB
#endif

View File

@ -150,7 +150,7 @@ static bool _GBCoreInit(struct mCore* core) {
gbcore->keys = 0;
gb->keySource = &gbcore->keys;
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
mDirectorySetInit(&core->dirs);
#endif
@ -162,7 +162,7 @@ static void _GBCoreDeinit(struct mCore* core) {
GBDestroy(core->board);
mappedMemoryFree(core->cpu, sizeof(struct SM83Core));
mappedMemoryFree(core->board, sizeof(struct GB));
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
mDirectorySetDeinit(&core->dirs);
#endif
#ifdef ENABLE_DEBUGGERS
@ -651,6 +651,7 @@ static void _GBCoreReset(struct mCore* core) {
bios = NULL;
}
}
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
if (!found) {
char path[PATH_MAX];
mCoreConfigDirectory(path, PATH_MAX);
@ -679,6 +680,7 @@ static void _GBCoreReset(struct mCore* core) {
bios = NULL;
}
}
#endif
if (found && bios) {
GBLoadBIOS(gb, bios);
}
@ -1128,7 +1130,7 @@ static void _GBCoreLoadSymbols(struct mCore* core, struct VFile* vf) {
if (!core->symbolTable) {
core->symbolTable = mDebuggerSymbolTableCreate();
}
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
if (!vf && core->dirs.base) {
vf = mDirectorySetOpenSuffix(&core->dirs, core->dirs.base, ".sym", O_RDONLY);
}

View File

@ -296,7 +296,7 @@ static bool _GBACoreInit(struct mCore* core) {
gbacore->proxyRenderer.logger = NULL;
#endif
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
mDirectorySetInit(&core->dirs);
#endif
@ -308,7 +308,7 @@ static void _GBACoreDeinit(struct mCore* core) {
GBADestroy(core->board);
mappedMemoryFree(core->cpu, sizeof(struct ARMCore));
mappedMemoryFree(core->board, sizeof(struct GBA));
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
mDirectorySetDeinit(&core->dirs);
#endif
#ifdef ENABLE_DEBUGGERS
@ -1352,7 +1352,7 @@ static void _GBACoreLoadSymbols(struct mCore* core, struct VFile* vf) {
seek = vf->seek(vf, 0, SEEK_CUR);
vf->seek(vf, 0, SEEK_SET);
}
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
#ifdef USE_ELF
if (!vf && core->dirs.base) {
closeAfter = true;

View File

@ -103,6 +103,7 @@ struct VFile* VFileOpen(const char* path, int flags) {
#endif
}
#ifdef ENABLE_DIRECTORIES
struct VDir* VDirOpenArchive(const char* path) {
struct VDir* dir = 0;
UNUSED(path);
@ -119,6 +120,7 @@ struct VDir* VDirOpenArchive(const char* path) {
return dir;
}
#endif
#endif
ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) {
size_t bytesRead = 0;
@ -250,7 +252,7 @@ void makeAbsolute(const char* path, const char* base, char* out) {
strncpy(out, buf, PATH_MAX);
}
#ifdef ENABLE_VFS
#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES)
struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*)) {
dir->rewind(dir);
struct VDirEntry* dirent = dir->listNext(dir);