diff --git a/CMakeLists.txt b/CMakeLists.txt index ad464bab0..8c7413c1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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}) diff --git a/include/mgba-util/vfs.h b/include/mgba-util/vfs.h index 0279fb755..c23515e5d 100644 --- a/include/mgba-util/vfs.h +++ b/include/mgba-util/vfs.h @@ -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); diff --git a/include/mgba/core/cheats.h b/include/mgba/core/cheats.h index a1c6c555c..9f16b24ea 100644 --- a/include/mgba/core/cheats.h +++ b/include/mgba/core/cheats.h @@ -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 diff --git a/include/mgba/core/core.h b/include/mgba/core/core.h index 94dfb1114..64eda6627 100644 --- a/include/mgba/core/core.h +++ b/include/mgba/core/core.h @@ -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 diff --git a/include/mgba/core/directories.h b/include/mgba/core/directories.h index f9f59cb8d..5d65be8a3 100644 --- a/include/mgba/core/directories.h +++ b/include/mgba/core/directories.h @@ -10,7 +10,7 @@ CXX_GUARD_START -#ifdef ENABLE_VFS +#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES) struct VDir; struct mDirectorySet { diff --git a/src/core/cheats.c b/src/core/cheats.c index 2fc97c3ac..977d0b7fa 100644 --- a/src/core/cheats.c +++ b/src/core/cheats.c @@ -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; diff --git a/src/core/core.c b/src/core/core.c index ba7ef914c..5422a09d3 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -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) { diff --git a/src/core/directories.c b/src/core/directories.c index e0748f829..2337f5d47 100644 --- a/src/core/directories.c +++ b/src/core/directories.c @@ -8,7 +8,7 @@ #include #include -#ifdef ENABLE_VFS +#if defined(ENABLE_VFS) && defined(ENABLE_DIRECTORIES) void mDirectorySetInit(struct mDirectorySet* dirs) { dirs->base = NULL; dirs->archive = NULL; diff --git a/src/core/flags.h.in b/src/core/flags.h.in index 3507df032..1071d42c3 100644 --- a/src/core/flags.h.in +++ b/src/core/flags.h.in @@ -53,6 +53,10 @@ #cmakedefine ENABLE_DEBUGGERS #endif +#ifndef ENABLE_DIRECTORIES +#cmakedefine ENABLE_DIRECTORIES +#endif + #ifndef ENABLE_GDB_STUB #cmakedefine ENABLE_GDB_STUB #endif diff --git a/src/gb/core.c b/src/gb/core.c index f71b570e0..a97dd175f 100644 --- a/src/gb/core.c +++ b/src/gb/core.c @@ -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); } diff --git a/src/gba/core.c b/src/gba/core.c index b369c92df..65ec999f2 100644 --- a/src/gba/core.c +++ b/src/gba/core.c @@ -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; diff --git a/src/util/vfs.c b/src/util/vfs.c index a14100bbf..cb9ed40ba 100644 --- a/src/util/vfs.c +++ b/src/util/vfs.c @@ -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);