All: Split ENABLE_VFS out from MINIMAL_CORE=2

This commit is contained in:
Vicki Pfau 2024-04-22 03:07:54 -07:00
parent 2cbbaea483
commit 21d4f0f5fc
43 changed files with 199 additions and 95 deletions

View File

@ -220,7 +220,7 @@ if(WIN32)
endif() endif()
endif() endif()
list(APPEND OS_LIB ws2_32 shlwapi) list(APPEND OS_LIB ws2_32 shlwapi)
list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/vfs-w32.c) list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/vfs-w32.c)
file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/*.c) file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/windows/*.c)
source_group("Windows-specific code" FILES ${OS_SRC}) source_group("Windows-specific code" FILES ${OS_SRC})
elseif(UNIX) elseif(UNIX)
@ -230,7 +230,7 @@ elseif(UNIX)
add_definitions(-D_GNU_SOURCE) add_definitions(-D_GNU_SOURCE)
endif() endif()
list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c) list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${CMAKE_CURRENT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/posix/*.c) file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/platform/posix/*.c)
source_group("POSIX-specific code" FILES ${OS_SRC}) source_group("POSIX-specific code" FILES ${OS_SRC})
endif() endif()
@ -349,6 +349,9 @@ elseif(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif() endif()
check_include_files("xlocale.h" HAVE_XLOCALE) check_include_files("xlocale.h" HAVE_XLOCALE)
set(ENABLE_VFS ON)
if(CMAKE_SYSTEM_NAME STREQUAL "Generic") if(CMAKE_SYSTEM_NAME STREQUAL "Generic")
if(NOT IS_EMBEDDED) if(NOT IS_EMBEDDED)
set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE) set(DISABLE_DEPS ON CACHE BOOL "This platform cannot build with dependencies" FORCE)
@ -852,6 +855,10 @@ if(ENABLE_SCRIPTING)
list(APPEND TEST_SRC ${SCRIPT_TEST_SRC}) list(APPEND TEST_SRC ${SCRIPT_TEST_SRC})
endif() endif()
if(ENABLE_VFS)
list(APPEND ENABLES VFS)
endif()
foreach(FEATURE IN LISTS FEATURES) foreach(FEATURE IN LISTS FEATURES)
list(APPEND FEATURE_DEFINES "USE_${FEATURE}") list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
endforeach() endforeach()
@ -890,7 +897,11 @@ list(APPEND CORE_SRC
${THIRD_PARTY_SRC}) ${THIRD_PARTY_SRC})
list(APPEND TEST_SRC ${UTIL_TEST_SRC}) list(APPEND TEST_SRC ${UTIL_TEST_SRC})
set(SRC ${CORE_SRC} ${VFS_SRC}) set(SRC ${CORE_SRC})
if(ENABLE_VFS)
list(APPEND SRC ${VFS_SRC})
endif()
if(NOT MINIMAL_CORE) if(NOT MINIMAL_CORE)
set(ENABLE_EXTRA ON) set(ENABLE_EXTRA ON)
if(M_CORE_GBA) if(M_CORE_GBA)
@ -922,7 +933,7 @@ if(NOT SKIP_LIBRARY)
endif() endif()
if(BUILD_SHARED) if(BUILD_SHARED)
add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC}) add_library(${BINARY_NAME} SHARED ${SRC})
set(EXPORT_DEFINES MGBA_DLL) set(EXPORT_DEFINES MGBA_DLL)
if(BUILD_STATIC) if(BUILD_STATIC)
add_library(${BINARY_NAME}-static STATIC ${SRC}) add_library(${BINARY_NAME}-static STATIC ${SRC})
@ -993,7 +1004,7 @@ if(BUILD_LIBRETRO)
endif() endif()
endif() endif()
if(BUILD_QT AND (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME STREQUAL "Linux")) if(BUILD_QT AND (WIN32 OR APPLE OR CMAKE_SYSTEM_NAME STREQUAL "Linux") AND ENABLE_VFS)
set(BUILD_UPDATER ON) set(BUILD_UPDATER ON)
endif() endif()

View File

@ -34,10 +34,12 @@ const char* ConfigurationGetValue(const struct Configuration*, const char* secti
void ConfigurationClearValue(struct Configuration*, const char* section, const char* key); void ConfigurationClearValue(struct Configuration*, const char* section, const char* key);
#ifdef ENABLE_VFS
bool ConfigurationRead(struct Configuration*, const char* path); bool ConfigurationRead(struct Configuration*, const char* path);
bool ConfigurationReadVFile(struct Configuration*, struct VFile* vf);
bool ConfigurationWrite(const struct Configuration*, const char* path); bool ConfigurationWrite(const struct Configuration*, const char* path);
bool ConfigurationWriteSection(const struct Configuration*, const char* path, const char* section); bool ConfigurationWriteSection(const struct Configuration*, const char* path, const char* section);
#endif
bool ConfigurationReadVFile(struct Configuration*, struct VFile* vf);
bool ConfigurationWriteVFile(const struct Configuration*, struct VFile* vf); bool ConfigurationWriteVFile(const struct Configuration*, struct VFile* vf);
void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user); void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user);

View File

@ -114,12 +114,16 @@ struct VFile;
struct mImage* mImageCreate(unsigned width, unsigned height, enum mColorFormat format); struct mImage* mImageCreate(unsigned width, unsigned height, enum mColorFormat format);
struct mImage* mImageCreateWithStride(unsigned width, unsigned height, unsigned stride, enum mColorFormat format); struct mImage* mImageCreateWithStride(unsigned width, unsigned height, unsigned stride, enum mColorFormat format);
struct mImage* mImageCreateFromConstBuffer(unsigned width, unsigned height, unsigned stride, enum mColorFormat format, const void* pixels); struct mImage* mImageCreateFromConstBuffer(unsigned width, unsigned height, unsigned stride, enum mColorFormat format, const void* pixels);
#ifdef ENABLE_VFS
struct mImage* mImageLoad(const char* path); struct mImage* mImageLoad(const char* path);
#endif
struct mImage* mImageLoadVF(struct VFile* vf); struct mImage* mImageLoadVF(struct VFile* vf);
struct mImage* mImageConvertToFormat(const struct mImage*, enum mColorFormat format); struct mImage* mImageConvertToFormat(const struct mImage*, enum mColorFormat format);
void mImageDestroy(struct mImage*); void mImageDestroy(struct mImage*);
#ifdef ENABLE_VFS
bool mImageSave(const struct mImage*, const char* path, const char* format); bool mImageSave(const struct mImage*, const char* path, const char* format);
#endif
bool mImageSaveVF(const struct mImage*, struct VFile* vf, const char* format); bool mImageSaveVF(const struct mImage*, struct VFile* vf, const char* format);
uint32_t mImageGetPixel(const struct mImage* image, unsigned x, unsigned y); uint32_t mImageGetPixel(const struct mImage* image, unsigned x, unsigned y);

View File

@ -50,6 +50,7 @@ struct VFile {
bool (*sync)(struct VFile* vf, void* buffer, size_t size); bool (*sync)(struct VFile* vf, void* buffer, size_t size);
}; };
#ifdef ENABLE_VFS
struct VDirEntry { struct VDirEntry {
const char* (*name)(struct VDirEntry* vde); const char* (*name)(struct VDirEntry* vde);
enum VFSType (*type)(struct VDirEntry* vde); enum VFSType (*type)(struct VDirEntry* vde);
@ -68,6 +69,7 @@ struct VFile* VFileOpen(const char* path, int flags);
struct VFile* VFileOpenFD(const char* path, int flags); struct VFile* VFileOpenFD(const char* path, int flags);
struct VFile* VFileFromFD(int fd); struct VFile* VFileFromFD(int fd);
#endif
struct VFile* VFileFromMemory(void* mem, size_t size); struct VFile* VFileFromMemory(void* mem, size_t size);
struct VFile* VFileFromConstMemory(const void* mem, size_t size); struct VFile* VFileFromConstMemory(const void* mem, size_t size);
@ -76,6 +78,7 @@ struct VFile* VFileMemChunk(const void* mem, size_t size);
struct mCircleBuffer; struct mCircleBuffer;
struct VFile* VFileFIFO(struct mCircleBuffer* backing); struct VFile* VFileFIFO(struct mCircleBuffer* backing);
#ifdef ENABLE_VFS
struct VDir* VDirOpen(const char* path); struct VDir* VDirOpen(const char* path);
struct VDir* VDirOpenArchive(const char* path); struct VDir* VDirOpenArchive(const char* path);
@ -92,20 +95,20 @@ struct VDir* VDeviceList(void);
#endif #endif
bool VDirCreate(const char* path); bool VDirCreate(const char* path);
struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*));
struct VFile* VDirFindNextAvailable(struct VDir*, const char* basename, const char* infix, const char* suffix, int mode);
#ifdef USE_VFS_FILE #ifdef USE_VFS_FILE
struct VFile* VFileFOpen(const char* path, const char* mode); struct VFile* VFileFOpen(const char* path, const char* mode);
struct VFile* VFileFromFILE(FILE* file); struct VFile* VFileFromFILE(FILE* file);
#endif #endif
#endif
void separatePath(const char* path, char* dirname, char* basename, char* extension); void separatePath(const char* path, char* dirname, char* basename, char* extension);
bool isAbsolute(const char* path); bool isAbsolute(const char* path);
void makeAbsolute(const char* path, const char* base, char* out); void makeAbsolute(const char* path, const char* base, char* out);
struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*));
struct VFile* VDirFindNextAvailable(struct VDir*, const char* basename, const char* infix, const char* suffix, int mode);
ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size); ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size);
ssize_t VFileWrite32LE(struct VFile* vf, int32_t word); ssize_t VFileWrite32LE(struct VFile* vf, int32_t word);

View File

@ -118,7 +118,7 @@ bool mCheatSaveFile(struct mCheatDevice*, struct VFile*);
bool mCheatParseLibretroFile(struct mCheatDevice*, struct VFile*); bool mCheatParseLibretroFile(struct mCheatDevice*, struct VFile*);
bool mCheatParseEZFChtFile(struct mCheatDevice*, struct VFile*); bool mCheatParseEZFChtFile(struct mCheatDevice*, struct VFile*);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
void mCheatAutosave(struct mCheatDevice*); void mCheatAutosave(struct mCheatDevice*);
#endif #endif

View File

@ -64,7 +64,7 @@ struct mCoreOptions {
void mCoreConfigInit(struct mCoreConfig*, const char* port); void mCoreConfigInit(struct mCoreConfig*, const char* port);
void mCoreConfigDeinit(struct mCoreConfig*); void mCoreConfigDeinit(struct mCoreConfig*);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
bool mCoreConfigLoad(struct mCoreConfig*); bool mCoreConfigLoad(struct mCoreConfig*);
bool mCoreConfigSave(const struct mCoreConfig*); bool mCoreConfigSave(const struct mCoreConfig*);
bool mCoreConfigLoadPath(struct mCoreConfig*, const char* path); bool mCoreConfigLoadPath(struct mCoreConfig*, const char* path);

View File

@ -11,7 +11,7 @@
CXX_GUARD_START CXX_GUARD_START
#include <mgba/core/config.h> #include <mgba/core/config.h>
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
#include <mgba/core/directories.h> #include <mgba/core/directories.h>
#endif #endif
#ifndef MINIMAL_CORE #ifndef MINIMAL_CORE
@ -46,7 +46,7 @@ struct mCore {
struct mDebuggerSymbols* symbolTable; struct mDebuggerSymbols* symbolTable;
struct mVideoLogger* videoLogger; struct mVideoLogger* videoLogger;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
struct mDirectorySet dirs; struct mDirectorySet dirs;
#endif #endif
#ifndef MINIMAL_CORE #ifndef MINIMAL_CORE
@ -176,7 +176,7 @@ struct mCore {
#endif #endif
}; };
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
struct mCore* mCoreFind(const char* path); struct mCore* mCoreFind(const char* path);
bool mCoreLoadFile(struct mCore* core, const char* path); bool mCoreLoadFile(struct mCore* core, const char* path);

View File

@ -10,7 +10,7 @@
CXX_GUARD_START CXX_GUARD_START
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
struct VDir; struct VDir;
struct mDirectorySet { struct mDirectorySet {

View File

@ -10,6 +10,8 @@
CXX_GUARD_START CXX_GUARD_START
#ifdef ENABLE_VFS
#include <mgba/core/core.h> #include <mgba/core/core.h>
#include <mgba-util/vector.h> #include <mgba-util/vector.h>
@ -48,6 +50,8 @@ void mLibraryAttachGameDB(struct mLibrary* library, const struct NoIntroDB* db);
#endif #endif
#endif
CXX_GUARD_END CXX_GUARD_END
#endif #endif

View File

@ -70,7 +70,9 @@ void mScriptBridgeDebuggerEntered(struct mScriptBridge*, enum mDebuggerEntryReas
#endif #endif
void mScriptBridgeRun(struct mScriptBridge*); void mScriptBridgeRun(struct mScriptBridge*);
#ifdef ENABLE_VFS
bool mScriptBridgeLoadScript(struct mScriptBridge*, const char* name); bool mScriptBridgeLoadScript(struct mScriptBridge*, const char* name);
#endif
bool mScriptBridgeLookupSymbol(struct mScriptBridge*, const char* name, int32_t* out); bool mScriptBridgeLookupSymbol(struct mScriptBridge*, const char* name, int32_t* out);

View File

@ -139,7 +139,7 @@ struct GBA;
void GBACartEReaderQueueCard(struct GBA* gba, const void* data, size_t size); void GBACartEReaderQueueCard(struct GBA* gba, const void* data, size_t size);
struct EReaderScan; struct EReaderScan;
#ifdef USE_PNG #if defined(USE_PNG) && defined(ENABLE_VFS)
MGBA_EXPORT struct EReaderScan* EReaderScanLoadImagePNG(const char* filename); MGBA_EXPORT struct EReaderScan* EReaderScanLoadImagePNG(const char* filename);
#endif #endif
MGBA_EXPORT struct EReaderScan* EReaderScanLoadImage(const void* pixels, unsigned width, unsigned height, unsigned stride); MGBA_EXPORT struct EReaderScan* EReaderScanLoadImage(const void* pixels, unsigned width, unsigned height, unsigned stride);
@ -149,7 +149,9 @@ MGBA_EXPORT void EReaderScanDestroy(struct EReaderScan*);
MGBA_EXPORT bool EReaderScanCard(struct EReaderScan*); MGBA_EXPORT bool EReaderScanCard(struct EReaderScan*);
MGBA_EXPORT void EReaderScanOutputBitmap(const struct EReaderScan*, void* output, size_t stride); MGBA_EXPORT void EReaderScanOutputBitmap(const struct EReaderScan*, void* output, size_t stride);
#ifdef ENABLE_VFS
MGBA_EXPORT bool EReaderScanSaveRaw(const struct EReaderScan*, const char* filename, bool strict); MGBA_EXPORT bool EReaderScanSaveRaw(const struct EReaderScan*, const char* filename, bool strict);
#endif
CXX_GUARD_END CXX_GUARD_END

View File

@ -109,7 +109,9 @@ const char* mScriptEngineGetDocstring(struct mScriptEngineContext*, const char*
struct VFile; struct VFile;
bool mScriptContextLoadVF(struct mScriptContext*, const char* name, struct VFile* vf); bool mScriptContextLoadVF(struct mScriptContext*, const char* name, struct VFile* vf);
#ifdef ENABLE_VFS
bool mScriptContextLoadFile(struct mScriptContext*, const char* path); bool mScriptContextLoadFile(struct mScriptContext*, const char* path);
#endif
struct mScriptContext* mScriptActiveContext(void); struct mScriptContext* mScriptActiveContext(void);
bool mScriptContextActivate(struct mScriptContext*); bool mScriptContextActivate(struct mScriptContext*);

View File

@ -8,7 +8,6 @@ set(SOURCE_FILES
directories.c directories.c
input.c input.c
interface.c interface.c
library.c
lockstep.c lockstep.c
log.c log.c
map-cache.c map-cache.c
@ -23,6 +22,11 @@ set(SOURCE_FILES
set(TEST_FILES set(TEST_FILES
test/core.c) test/core.c)
if(ENABLE_VFS)
list(APPEND SOURCE_FILES
library.c)
endif()
if(ENABLE_SCRIPTING) if(ENABLE_SCRIPTING)
set(SCRIPTING_FILES set(SCRIPTING_FILES
scripting.c) scripting.c)

View File

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

View File

@ -167,7 +167,7 @@ void mCoreConfigDeinit(struct mCoreConfig* config) {
free(config->port); free(config->port);
} }
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
bool mCoreConfigLoad(struct mCoreConfig* config) { bool mCoreConfigLoad(struct mCoreConfig* config) {
char path[PATH_MAX + 1]; char path[PATH_MAX + 1];
mCoreConfigDirectory(path, PATH_MAX); mCoreConfigDirectory(path, PATH_MAX);

View File

@ -15,6 +15,10 @@
#include <mgba-util/elf-read.h> #include <mgba-util/elf-read.h>
#endif #endif
#ifdef USE_PNG
#include <mgba-util/image/png-io.h>
#endif
#ifdef M_CORE_GB #ifdef M_CORE_GB
#include <mgba/gb/core.h> #include <mgba/gb/core.h>
#include <mgba/gb/interface.h> #include <mgba/gb/interface.h>
@ -86,9 +90,7 @@ struct mCore* mCoreCreate(enum mPlatform platform) {
return NULL; return NULL;
} }
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
#include <mgba-util/image/png-io.h>
#ifdef PSP2 #ifdef PSP2
#include <psp2/photoexport.h> #include <psp2/photoexport.h>
#endif #endif
@ -381,7 +383,7 @@ void mCoreInitConfig(struct mCore* core, const char* port) {
} }
void mCoreLoadConfig(struct mCore* core) { void mCoreLoadConfig(struct mCore* core) {
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
mCoreConfigLoad(&core->config); mCoreConfigLoad(&core->config);
#endif #endif
mCoreLoadForeignConfig(core, &core->config); mCoreLoadForeignConfig(core, &core->config);
@ -389,7 +391,7 @@ void mCoreLoadConfig(struct mCore* core) {
void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config) { void mCoreLoadForeignConfig(struct mCore* core, const struct mCoreConfig* config) {
mCoreConfigMap(config, &core->opts); mCoreConfigMap(config, &core->opts);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
mDirectorySetMapOptions(&core->dirs, &core->opts); mDirectorySetMapOptions(&core->dirs, &core->opts);
#endif #endif
if (core->opts.audioBuffers) { if (core->opts.audioBuffers) {

View File

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

View File

@ -61,6 +61,10 @@
#cmakedefine ENABLE_SCRIPTING #cmakedefine ENABLE_SCRIPTING
#endif #endif
#ifndef ENABLE_VFS
#cmakedefine ENABLE_VFS
#endif
// USE flags // USE flags
#ifndef USE_DISCORD_RPC #ifndef USE_DISCORD_RPC

View File

@ -278,15 +278,16 @@ void mStandardLoggerDeinit(struct mStandardLogger* logger) {
} }
void mStandardLoggerConfig(struct mStandardLogger* logger, struct mCoreConfig* config) { void mStandardLoggerConfig(struct mStandardLogger* logger, struct mCoreConfig* config) {
#ifdef ENABLE_VFS
bool logToFile = false; bool logToFile = false;
const char* logFile = mCoreConfigGetValue(config, "logFile"); const char* logFile = mCoreConfigGetValue(config, "logFile");
mCoreConfigGetBoolValue(config, "logToStdout", &logger->logToStdout);
mCoreConfigGetBoolValue(config, "logToFile", &logToFile); mCoreConfigGetBoolValue(config, "logToFile", &logToFile);
if (logToFile && logFile) { if (logToFile && logFile) {
logger->logFile = VFileOpen(logFile, O_WRONLY | O_CREAT | O_APPEND); logger->logFile = VFileOpen(logFile, O_WRONLY | O_CREAT | O_APPEND);
} }
#endif
mCoreConfigGetBoolValue(config, "logToStdout", &logger->logToStdout);
mLogFilterLoad(logger->d.filter, config); mLogFilterLoad(logger->d.filter, config);
} }

View File

@ -129,6 +129,7 @@ void mScriptBridgeRun(struct mScriptBridge* sb) {
HashTableEnumerate(&sb->engines, _seRun, NULL); HashTableEnumerate(&sb->engines, _seRun, NULL);
} }
#ifdef ENABLE_VFS
bool mScriptBridgeLoadScript(struct mScriptBridge* sb, const char* name) { bool mScriptBridgeLoadScript(struct mScriptBridge* sb, const char* name) {
struct VFile* vf = VFileOpen(name, O_RDONLY); struct VFile* vf = VFileOpen(name, O_RDONLY);
if (!vf) { if (!vf) {
@ -143,6 +144,7 @@ bool mScriptBridgeLoadScript(struct mScriptBridge* sb, const char* name) {
vf->close(vf); vf->close(vf);
return info.success; return info.success;
} }
#endif
bool mScriptBridgeLookupSymbol(struct mScriptBridge* sb, const char* name, int32_t* out) { bool mScriptBridgeLookupSymbol(struct mScriptBridge* sb, const char* name, int32_t* out) {
struct mScriptSymbol info = { struct mScriptSymbol info = {
@ -417,6 +419,7 @@ static struct mScriptValue* _mScriptCoreSaveState(struct mCore* core, int32_t fl
return value; return value;
} }
#ifdef ENABLE_VFS
static int _mScriptCoreSaveStateFile(struct mCore* core, const char* path, int flags) { static int _mScriptCoreSaveStateFile(struct mCore* core, const char* path, int flags) {
struct VFile* vf = VFileOpen(path, O_WRONLY | O_TRUNC | O_CREAT); struct VFile* vf = VFileOpen(path, O_WRONLY | O_TRUNC | O_CREAT);
if (!vf) { if (!vf) {
@ -427,13 +430,6 @@ static int _mScriptCoreSaveStateFile(struct mCore* core, const char* path, int f
return ok; return ok;
} }
static int32_t _mScriptCoreLoadState(struct mCore* core, struct mScriptString* buffer, int32_t flags) {
struct VFile* vf = VFileFromConstMemory(buffer->buffer, buffer->size);
int ret = mCoreLoadStateNamed(core, vf, flags);
vf->close(vf);
return ret;
}
static int _mScriptCoreLoadStateFile(struct mCore* core, const char* path, int flags) { static int _mScriptCoreLoadStateFile(struct mCore* core, const char* path, int flags) {
struct VFile* vf = VFileOpen(path, O_RDONLY); struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) { if (!vf) {
@ -456,6 +452,14 @@ static void _mScriptCoreTakeScreenshot(struct mCore* core, const char* filename)
mCoreTakeScreenshot(core); mCoreTakeScreenshot(core);
} }
} }
#endif
static int32_t _mScriptCoreLoadState(struct mCore* core, struct mScriptString* buffer, int32_t flags) {
struct VFile* vf = VFileFromConstMemory(buffer->buffer, buffer->size);
int ret = mCoreLoadStateNamed(core, vf, flags);
vf->close(vf);
return ret;
}
static struct mScriptValue* _mScriptCoreTakeScreenshotToImage(struct mCore* core) { static struct mScriptValue* _mScriptCoreTakeScreenshotToImage(struct mCore* core) {
size_t stride; size_t stride;
@ -480,10 +484,12 @@ static struct mScriptValue* _mScriptCoreTakeScreenshotToImage(struct mCore* core
return result; return result;
} }
#ifdef ENABLE_VFS
// Loading functions // Loading functions
mSCRIPT_DECLARE_STRUCT_METHOD(mCore, BOOL, loadFile, mCoreLoadFile, 1, CHARP, path); mSCRIPT_DECLARE_STRUCT_METHOD(mCore, BOOL, loadFile, mCoreLoadFile, 1, CHARP, path);
mSCRIPT_DECLARE_STRUCT_METHOD(mCore, BOOL, autoloadSave, mCoreAutoloadSave, 0); mSCRIPT_DECLARE_STRUCT_METHOD(mCore, BOOL, autoloadSave, mCoreAutoloadSave, 0);
mSCRIPT_DECLARE_STRUCT_METHOD(mCore, BOOL, loadSaveFile, mCoreLoadSaveFile, 2, CHARP, path, BOOL, temporary); mSCRIPT_DECLARE_STRUCT_METHOD(mCore, BOOL, loadSaveFile, mCoreLoadSaveFile, 2, CHARP, path, BOOL, temporary);
#endif
// Info functions // Info functions
mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, S32, platform, 0); mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, S32, platform, 0);
@ -523,27 +529,31 @@ mSCRIPT_DECLARE_STRUCT_METHOD(mCore, WSTR, readRegister, _mScriptCoreReadRegiste
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mCore, writeRegister, _mScriptCoreWriteRegister, 2, CHARP, regName, S32, value); mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mCore, writeRegister, _mScriptCoreWriteRegister, 2, CHARP, regName, S32, value);
// Savestate functions // Savestate functions
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, saveStateSlot, mCoreSaveState, 2, S32, slot, S32, flags);
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, WSTR, saveStateBuffer, _mScriptCoreSaveState, 1, S32, flags); mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, WSTR, saveStateBuffer, _mScriptCoreSaveState, 1, S32, flags);
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, loadStateBuffer, _mScriptCoreLoadState, 2, STR, buffer, S32, flags);
#ifdef ENABLE_VFS
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, saveStateSlot, mCoreSaveState, 2, S32, slot, S32, flags);
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, saveStateFile, _mScriptCoreSaveStateFile, 2, CHARP, path, S32, flags); mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, saveStateFile, _mScriptCoreSaveStateFile, 2, CHARP, path, S32, flags);
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, loadStateSlot, mCoreLoadState, 2, S32, slot, S32, flags); mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, loadStateSlot, mCoreLoadState, 2, S32, slot, S32, flags);
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, loadStateBuffer, _mScriptCoreLoadState, 2, STR, buffer, S32, flags);
mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, loadStateFile, _mScriptCoreLoadStateFile, 2, CHARP, path, S32, flags); mSCRIPT_DECLARE_STRUCT_METHOD_WITH_DEFAULTS(mCore, BOOL, loadStateFile, _mScriptCoreLoadStateFile, 2, CHARP, path, S32, flags);
// Miscellaneous functions // Miscellaneous functions
mSCRIPT_DECLARE_STRUCT_VOID_METHOD_WITH_DEFAULTS(mCore, screenshot, _mScriptCoreTakeScreenshot, 1, CHARP, filename); mSCRIPT_DECLARE_STRUCT_VOID_METHOD_WITH_DEFAULTS(mCore, screenshot, _mScriptCoreTakeScreenshot, 1, CHARP, filename);
#endif
mSCRIPT_DECLARE_STRUCT_METHOD(mCore, W(mImage), screenshotToImage, _mScriptCoreTakeScreenshotToImage, 0); mSCRIPT_DECLARE_STRUCT_METHOD(mCore, W(mImage), screenshotToImage, _mScriptCoreTakeScreenshotToImage, 0);
mSCRIPT_DEFINE_STRUCT(mCore) mSCRIPT_DEFINE_STRUCT(mCore)
mSCRIPT_DEFINE_CLASS_DOCSTRING( mSCRIPT_DEFINE_CLASS_DOCSTRING(
"An instance of an emulator core." "An instance of an emulator core."
) )
#ifdef ENABLE_VFS
mSCRIPT_DEFINE_DOCSTRING("Load a ROM file into the current state of this core") mSCRIPT_DEFINE_DOCSTRING("Load a ROM file into the current state of this core")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadFile) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadFile)
mSCRIPT_DEFINE_DOCSTRING("Load the save data associated with the currently loaded ROM file") mSCRIPT_DEFINE_DOCSTRING("Load the save data associated with the currently loaded ROM file")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, autoloadSave) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, autoloadSave)
mSCRIPT_DEFINE_DOCSTRING("Load save data from the given path. If the `temporary` flag is set, the given save data will not be written back to disk") mSCRIPT_DEFINE_DOCSTRING("Load save data from the given path. If the `temporary` flag is set, the given save data will not be written back to disk")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadSaveFile) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadSaveFile)
#endif
mSCRIPT_DEFINE_DOCSTRING("Get which platform is being emulated. See C.PLATFORM for possible values") mSCRIPT_DEFINE_DOCSTRING("Get which platform is being emulated. See C.PLATFORM for possible values")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, platform) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, platform)
@ -605,21 +615,23 @@ mSCRIPT_DEFINE_STRUCT(mCore)
mSCRIPT_DEFINE_DOCSTRING("Write the value of the register with the given name") mSCRIPT_DEFINE_DOCSTRING("Write the value of the register with the given name")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, writeRegister) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, writeRegister)
mSCRIPT_DEFINE_DOCSTRING("Save state to the slot number. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, saveStateSlot)
mSCRIPT_DEFINE_DOCSTRING("Save state and return as a buffer. See C.SAVESTATE for possible values for `flags`") mSCRIPT_DEFINE_DOCSTRING("Save state and return as a buffer. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, saveStateBuffer) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, saveStateBuffer)
mSCRIPT_DEFINE_DOCSTRING("Load state from a buffer. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadStateBuffer)
#ifdef ENABLE_VFS
mSCRIPT_DEFINE_DOCSTRING("Save state to the slot number. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, saveStateSlot)
mSCRIPT_DEFINE_DOCSTRING("Save state to the given path. See C.SAVESTATE for possible values for `flags`") mSCRIPT_DEFINE_DOCSTRING("Save state to the given path. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, saveStateFile) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, saveStateFile)
mSCRIPT_DEFINE_DOCSTRING("Load state from the slot number. See C.SAVESTATE for possible values for `flags`") mSCRIPT_DEFINE_DOCSTRING("Load state from the slot number. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadStateSlot) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadStateSlot)
mSCRIPT_DEFINE_DOCSTRING("Load state from a buffer. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadStateBuffer)
mSCRIPT_DEFINE_DOCSTRING("Load state from the given path. See C.SAVESTATE for possible values for `flags`") mSCRIPT_DEFINE_DOCSTRING("Load state from the given path. See C.SAVESTATE for possible values for `flags`")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadStateFile) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, loadStateFile)
mSCRIPT_DEFINE_DOCSTRING("Save a screenshot to a file") mSCRIPT_DEFINE_DOCSTRING("Save a screenshot to a file")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, screenshot) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, screenshot)
#endif
mSCRIPT_DEFINE_DOCSTRING("Get a screenshot in an struct::mImage") mSCRIPT_DEFINE_DOCSTRING("Get a screenshot in an struct::mImage")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, screenshotToImage) mSCRIPT_DEFINE_STRUCT_METHOD(mCore, screenshotToImage)
mSCRIPT_DEFINE_END; mSCRIPT_DEFINE_END;

View File

@ -8,7 +8,7 @@
#include <mgba/core/core.h> #include <mgba/core/core.h>
#include <mgba-util/vfs.h> #include <mgba-util/vfs.h>
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
M_TEST_DEFINE(findNullPath) { M_TEST_DEFINE(findNullPath) {
struct mCore* core = mCoreFind(NULL); struct mCore* core = mCoreFind(NULL);
assert_null(core); assert_null(core);
@ -29,7 +29,7 @@ M_TEST_DEFINE(findEmpty) {
} }
M_TEST_SUITE_DEFINE(mCore, M_TEST_SUITE_DEFINE(mCore,
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
cmocka_unit_test(findNullPath), cmocka_unit_test(findNullPath),
#endif #endif
cmocka_unit_test(findNullVF), cmocka_unit_test(findNullVF),

View File

@ -75,13 +75,15 @@ static void _dumpByte(struct CLIDebugger*, struct CLIDebugVector*);
static void _dumpHalfword(struct CLIDebugger*, struct CLIDebugVector*); static void _dumpHalfword(struct CLIDebugger*, struct CLIDebugVector*);
static void _dumpWord(struct CLIDebugger*, struct CLIDebugVector*); static void _dumpWord(struct CLIDebugger*, struct CLIDebugVector*);
static void _events(struct CLIDebugger*, struct CLIDebugVector*); static void _events(struct CLIDebugger*, struct CLIDebugVector*);
#ifdef ENABLE_SCRIPTING
static void _source(struct CLIDebugger*, struct CLIDebugVector*);
#endif
static void _backtrace(struct CLIDebugger*, struct CLIDebugVector*); static void _backtrace(struct CLIDebugger*, struct CLIDebugVector*);
static void _finish(struct CLIDebugger*, struct CLIDebugVector*); static void _finish(struct CLIDebugger*, struct CLIDebugVector*);
static void _setStackTraceMode(struct CLIDebugger*, struct CLIDebugVector*); static void _setStackTraceMode(struct CLIDebugger*, struct CLIDebugVector*);
#ifdef ENABLE_VFS
static void _loadSymbols(struct CLIDebugger*, struct CLIDebugVector*); static void _loadSymbols(struct CLIDebugger*, struct CLIDebugVector*);
#ifdef ENABLE_SCRIPTING
static void _source(struct CLIDebugger*, struct CLIDebugVector*);
#endif
#endif
static void _setSymbol(struct CLIDebugger*, struct CLIDebugVector*); static void _setSymbol(struct CLIDebugger*, struct CLIDebugVector*);
static void _findSymbol(struct CLIDebugger*, struct CLIDebugVector*); static void _findSymbol(struct CLIDebugger*, struct CLIDebugVector*);
@ -96,6 +98,9 @@ static struct CLIDebuggerCommandSummary _debuggerCommands[] = {
{ "help", _printHelp, "S", "Print help" }, { "help", _printHelp, "S", "Print help" },
{ "listb", _listBreakpoints, "", "List breakpoints" }, { "listb", _listBreakpoints, "", "List breakpoints" },
{ "listw", _listWatchpoints, "", "List watchpoints" }, { "listw", _listWatchpoints, "", "List watchpoints" },
#ifdef ENABLE_VFS
{ "load-symbols", _loadSymbols, "S", "Load symbols from an external file" },
#endif
{ "next", _next, "", "Execute next instruction" }, { "next", _next, "", "Execute next instruction" },
{ "print", _print, "S+", "Print a value" }, { "print", _print, "S+", "Print a value" },
{ "print/t", _printBin, "S+", "Print a value as binary" }, { "print/t", _printBin, "S+", "Print a value as binary" },
@ -106,10 +111,12 @@ static struct CLIDebuggerCommandSummary _debuggerCommands[] = {
{ "r/2", _readHalfword, "I", "Read a halfword from a specified offset" }, { "r/2", _readHalfword, "I", "Read a halfword from a specified offset" },
{ "r/4", _readWord, "I", "Read a word from a specified offset" }, { "r/4", _readWord, "I", "Read a word from a specified offset" },
{ "set", _setSymbol, "SI", "Assign a symbol to an address" }, { "set", _setSymbol, "SI", "Assign a symbol to an address" },
#if defined(ENABLE_SCRIPTING) && defined(ENABLE_VFS)
{ "source", _source, "S", "Load a script" },
#endif
{ "stack", _setStackTraceMode, "S", "Change the stack tracing mode" }, { "stack", _setStackTraceMode, "S", "Change the stack tracing mode" },
{ "status", _printStatus, "", "Print the current status" }, { "status", _printStatus, "", "Print the current status" },
{ "symbol", _findSymbol, "I", "Find the symbol name for an address" }, { "symbol", _findSymbol, "I", "Find the symbol name for an address" },
{ "load-symbols", _loadSymbols, "S", "Load symbols from an external file" },
{ "trace", _trace, "Is", "Trace a number of instructions" }, { "trace", _trace, "Is", "Trace a number of instructions" },
{ "w/1", _writeByte, "II", "Write a byte at a specified offset" }, { "w/1", _writeByte, "II", "Write a byte at a specified offset" },
{ "w/2", _writeHalfword, "II", "Write a halfword at a specified offset" }, { "w/2", _writeHalfword, "II", "Write a halfword at a specified offset" },
@ -126,9 +133,6 @@ static struct CLIDebuggerCommandSummary _debuggerCommands[] = {
{ "x/1", _dumpByte, "Ii", "Examine bytes at a specified offset" }, { "x/1", _dumpByte, "Ii", "Examine bytes at a specified offset" },
{ "x/2", _dumpHalfword, "Ii", "Examine halfwords at a specified offset" }, { "x/2", _dumpHalfword, "Ii", "Examine halfwords at a specified offset" },
{ "x/4", _dumpWord, "Ii", "Examine words at a specified offset" }, { "x/4", _dumpWord, "Ii", "Examine words at a specified offset" },
#ifdef ENABLE_SCRIPTING
{ "source", _source, "S", "Load a script" },
#endif
#if !defined(NDEBUG) && !defined(_WIN32) #if !defined(NDEBUG) && !defined(_WIN32)
{ "!", _breakInto, "", "Break into attached debugger (for developers)" }, { "!", _breakInto, "", "Break into attached debugger (for developers)" },
#endif #endif
@ -586,7 +590,7 @@ static void _dumpWord(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
} }
} }
#ifdef ENABLE_SCRIPTING #if defined(ENABLE_SCRIPTING) && defined(ENABLE_VFS)
static void _source(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { static void _source(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
if (!dv) { if (!dv) {
debugger->backend->printf(debugger->backend, "Needs a filename\n"); debugger->backend->printf(debugger->backend, "Needs a filename\n");
@ -829,9 +833,11 @@ static void _trace(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
if (debugger->traceRemaining == 0) { if (debugger->traceRemaining == 0) {
return; return;
} }
#ifdef ENABLE_VFS
if (dv->next && dv->next->charValue) { if (dv->next && dv->next->charValue) {
debugger->traceVf = VFileOpen(dv->next->charValue, O_CREAT | O_WRONLY | O_APPEND); debugger->traceVf = VFileOpen(dv->next->charValue, O_CREAT | O_WRONLY | O_APPEND);
} }
#endif
if (_doTrace(debugger)) { if (_doTrace(debugger)) {
debugger->d.isPaused = false; debugger->d.isPaused = false;
mDebuggerUpdatePaused(debugger->d.p); mDebuggerUpdatePaused(debugger->d.p);
@ -1398,6 +1404,7 @@ static void _setStackTraceMode(struct CLIDebugger* debugger, struct CLIDebugVect
} }
} }
#ifdef ENABLE_VFS
static void _loadSymbols(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { static void _loadSymbols(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
struct mDebuggerSymbols* symbolTable = debugger->d.p->core->symbolTable; struct mDebuggerSymbols* symbolTable = debugger->d.p->core->symbolTable;
if (!symbolTable) { if (!symbolTable) {
@ -1431,6 +1438,7 @@ static void _loadSymbols(struct CLIDebugger* debugger, struct CLIDebugVector* dv
} }
vf->close(vf); vf->close(vf);
} }
#endif
static void _setSymbol(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { static void _setSymbol(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
struct mDebuggerSymbols* symbolTable = debugger->d.p->core->symbolTable; struct mDebuggerSymbols* symbolTable = debugger->d.p->core->symbolTable;

View File

@ -85,6 +85,7 @@ static void CLIDebuggerEditLineInit(struct CLIDebuggerBackend* be) {
history(elbe->histate, &ev, H_SETSIZE, 200); history(elbe->histate, &ev, H_SETSIZE, 200);
el_set(elbe->elstate, EL_HIST, history, elbe->histate); el_set(elbe->elstate, EL_HIST, history, elbe->histate);
#ifdef ENABLE_VFS
char path[PATH_MAX + 1]; char path[PATH_MAX + 1];
mCoreConfigDirectory(path, PATH_MAX); mCoreConfigDirectory(path, PATH_MAX);
if (path[0]) { if (path[0]) {
@ -99,6 +100,7 @@ static void CLIDebuggerEditLineInit(struct CLIDebuggerBackend* be) {
vf->close(vf); vf->close(vf);
} }
} }
#endif
MutexInit(&elbe->promptMutex); MutexInit(&elbe->promptMutex);
ConditionInit(&elbe->promptRead); ConditionInit(&elbe->promptRead);
@ -120,6 +122,7 @@ static void CLIDebuggerEditLineDeinit(struct CLIDebuggerBackend* be) {
MutexUnlock(&elbe->promptMutex); MutexUnlock(&elbe->promptMutex);
ThreadJoin(&elbe->promptThread); ThreadJoin(&elbe->promptThread);
#ifdef ENABLE_VFS
char path[PATH_MAX + 1]; char path[PATH_MAX + 1];
mCoreConfigDirectory(path, PATH_MAX); mCoreConfigDirectory(path, PATH_MAX);
if (path[0]) { if (path[0]) {
@ -139,6 +142,7 @@ static void CLIDebuggerEditLineDeinit(struct CLIDebuggerBackend* be) {
vf->close(vf); vf->close(vf);
} }
} }
#endif
history_end(elbe->histate); history_end(elbe->histate);
el_end(elbe->elstate); el_end(elbe->elstate);
free(elbe); free(elbe);

View File

@ -3,10 +3,14 @@ set(SOURCE_FILES
commandline.c commandline.c
proxy-backend.c proxy-backend.c
thread-proxy.c thread-proxy.c
updater.c
video-backend.c video-backend.c
video-logger.c) video-logger.c)
if(ENABLE_VFS)
list(APPEND SOURCE_FILES
updater.c)
endif()
set(GUI_FILES set(GUI_FILES
gui/cheats.c gui/cheats.c
gui/gui-config.c gui/gui-config.c

View File

@ -245,6 +245,7 @@ bool mArgumentsApplyDebugger(const struct mArguments* args, struct mCore* core,
} }
void mArgumentsApplyFileLoads(const struct mArguments* args, struct mCore* core) { void mArgumentsApplyFileLoads(const struct mArguments* args, struct mCore* core) {
#ifdef ENABLE_VFS
if (args->patch) { if (args->patch) {
struct VFile* patch = VFileOpen(args->patch, O_RDONLY); struct VFile* patch = VFileOpen(args->patch, O_RDONLY);
if (patch) { if (patch) {
@ -266,6 +267,10 @@ void mArgumentsApplyFileLoads(const struct mArguments* args, struct mCore* core)
} else { } else {
mCoreAutoloadCheats(core); mCoreAutoloadCheats(core);
} }
#else
UNUSED(args);
UNUSED(core);
#endif
} }
void mArgumentsDeinit(struct mArguments* args) { void mArgumentsDeinit(struct mArguments* args) {

View File

@ -149,7 +149,7 @@ static bool _GBCoreInit(struct mCore* core) {
gbcore->keys = 0; gbcore->keys = 0;
gb->keySource = &gbcore->keys; gb->keySource = &gbcore->keys;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
mDirectorySetInit(&core->dirs); mDirectorySetInit(&core->dirs);
#endif #endif
@ -161,7 +161,7 @@ static void _GBCoreDeinit(struct mCore* core) {
GBDestroy(core->board); GBDestroy(core->board);
mappedMemoryFree(core->cpu, sizeof(struct SM83Core)); mappedMemoryFree(core->cpu, sizeof(struct SM83Core));
mappedMemoryFree(core->board, sizeof(struct GB)); mappedMemoryFree(core->board, sizeof(struct GB));
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
mDirectorySetDeinit(&core->dirs); mDirectorySetDeinit(&core->dirs);
#endif #endif
#ifdef ENABLE_DEBUGGERS #ifdef ENABLE_DEBUGGERS
@ -597,7 +597,7 @@ static void _GBCoreReset(struct mCore* core) {
} }
} }
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
if (!gb->biosVf && core->opts.useBios) { if (!gb->biosVf && core->opts.useBios) {
struct VFile* bios = NULL; struct VFile* bios = NULL;
bool found = false; bool found = false;
@ -1108,7 +1108,7 @@ static void _GBCoreDetachDebugger(struct mCore* core) {
static void _GBCoreLoadSymbols(struct mCore* core, struct VFile* vf) { static void _GBCoreLoadSymbols(struct mCore* core, struct VFile* vf) {
core->symbolTable = mDebuggerSymbolTableCreate(); core->symbolTable = mDebuggerSymbolTableCreate();
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
if (!vf && core->dirs.base) { if (!vf && core->dirs.base) {
vf = mDirectorySetOpenSuffix(&core->dirs, core->dirs.base, ".sym", O_RDONLY); vf = mDirectorySetOpenSuffix(&core->dirs, core->dirs.base, ".sym", O_RDONLY);
} }

View File

@ -16,14 +16,14 @@ static void _GBCLIDebuggerInit(struct CLIDebuggerSystem*);
static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem*); static bool _GBCLIDebuggerCustom(struct CLIDebuggerSystem*);
static void _frame(struct CLIDebugger*, struct CLIDebugVector*); static void _frame(struct CLIDebugger*, struct CLIDebugVector*);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
static void _load(struct CLIDebugger*, struct CLIDebugVector*); static void _load(struct CLIDebugger*, struct CLIDebugVector*);
static void _save(struct CLIDebugger*, struct CLIDebugVector*); static void _save(struct CLIDebugger*, struct CLIDebugVector*);
#endif #endif
struct CLIDebuggerCommandSummary _GBCLIDebuggerCommands[] = { struct CLIDebuggerCommandSummary _GBCLIDebuggerCommands[] = {
{ "frame", _frame, "", "Frame advance" }, { "frame", _frame, "", "Frame advance" },
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
{ "load", _load, "*", "Load a savestate" }, { "load", _load, "*", "Load a savestate" },
{ "save", _save, "*", "Save a savestate" }, { "save", _save, "*", "Save a savestate" },
#endif #endif
@ -78,7 +78,7 @@ static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
gbDebugger->inVblank = GBRegisterSTATGetMode(((struct GB*) gbDebugger->core->board)->memory.io[GB_REG_STAT]) == 1; gbDebugger->inVblank = GBRegisterSTATGetMode(((struct GB*) gbDebugger->core->board)->memory.io[GB_REG_STAT]) == 1;
} }
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
static void _load(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { static void _load(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
struct CLIDebuggerBackend* be = debugger->backend; struct CLIDebuggerBackend* be = debugger->backend;
if (!dv || dv->type != CLIDV_INT_TYPE) { if (!dv || dv->type != CLIDV_INT_TYPE) {

View File

@ -875,7 +875,7 @@ void EReaderScanDestroy(struct EReaderScan* scan) {
free(scan); free(scan);
} }
#ifdef USE_PNG #if defined(USE_PNG) && defined(ENABLE_VFS)
struct EReaderScan* EReaderScanLoadImagePNG(const char* filename) { struct EReaderScan* EReaderScanLoadImagePNG(const char* filename) {
struct VFile* vf = VFileOpen(filename, O_RDONLY); struct VFile* vf = VFileOpen(filename, O_RDONLY);
if (!vf) { if (!vf) {
@ -1564,6 +1564,7 @@ void EReaderScanOutputBitmap(const struct EReaderScan* scan, void* output, size_
} }
} }
#ifdef ENABLE_VFS
bool EReaderScanSaveRaw(const struct EReaderScan* scan, const char* filename, bool strict) { bool EReaderScanSaveRaw(const struct EReaderScan* scan, const char* filename, bool strict) {
size_t blocks = EReaderBlockListSize(&scan->blocks); size_t blocks = EReaderBlockListSize(&scan->blocks);
if (!blocks) { if (!blocks) {
@ -1633,5 +1634,6 @@ bool EReaderScanSaveRaw(const struct EReaderScan* scan, const char* filename, bo
free(data); free(data);
return true; return true;
} }
#endif
#endif #endif

View File

@ -294,7 +294,7 @@ static bool _GBACoreInit(struct mCore* core) {
gbacore->proxyRenderer.logger = NULL; gbacore->proxyRenderer.logger = NULL;
#endif #endif
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
mDirectorySetInit(&core->dirs); mDirectorySetInit(&core->dirs);
#endif #endif
@ -306,7 +306,7 @@ static void _GBACoreDeinit(struct mCore* core) {
GBADestroy(core->board); GBADestroy(core->board);
mappedMemoryFree(core->cpu, sizeof(struct ARMCore)); mappedMemoryFree(core->cpu, sizeof(struct ARMCore));
mappedMemoryFree(core->board, sizeof(struct GBA)); mappedMemoryFree(core->board, sizeof(struct GBA));
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
mDirectorySetDeinit(&core->dirs); mDirectorySetDeinit(&core->dirs);
#endif #endif
#ifdef ENABLE_DEBUGGERS #ifdef ENABLE_DEBUGGERS
@ -741,7 +741,7 @@ static void _GBACoreReset(struct mCore* core) {
} }
gbacore->memoryBlockType = -2; gbacore->memoryBlockType = -2;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
if (!gba->biosVf && core->opts.useBios) { if (!gba->biosVf && core->opts.useBios) {
struct VFile* bios = NULL; struct VFile* bios = NULL;
bool found = false; bool found = false;
@ -1244,7 +1244,7 @@ static void _GBACoreDetachDebugger(struct mCore* core) {
static void _GBACoreLoadSymbols(struct mCore* core, struct VFile* vf) { static void _GBACoreLoadSymbols(struct mCore* core, struct VFile* vf) {
bool closeAfter = false; bool closeAfter = false;
core->symbolTable = mDebuggerSymbolTableCreate(); core->symbolTable = mDebuggerSymbolTableCreate();
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
#ifdef USE_ELF #ifdef USE_ELF
if (!vf && core->dirs.base) { if (!vf && core->dirs.base) {
closeAfter = true; closeAfter = true;

View File

@ -16,14 +16,14 @@ static void _GBACLIDebuggerInit(struct CLIDebuggerSystem*);
static bool _GBACLIDebuggerCustom(struct CLIDebuggerSystem*); static bool _GBACLIDebuggerCustom(struct CLIDebuggerSystem*);
static void _frame(struct CLIDebugger*, struct CLIDebugVector*); static void _frame(struct CLIDebugger*, struct CLIDebugVector*);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
static void _load(struct CLIDebugger*, struct CLIDebugVector*); static void _load(struct CLIDebugger*, struct CLIDebugVector*);
static void _save(struct CLIDebugger*, struct CLIDebugVector*); static void _save(struct CLIDebugger*, struct CLIDebugVector*);
#endif #endif
struct CLIDebuggerCommandSummary _GBACLIDebuggerCommands[] = { struct CLIDebuggerCommandSummary _GBACLIDebuggerCommands[] = {
{ "frame", _frame, "", "Frame advance" }, { "frame", _frame, "", "Frame advance" },
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
{ "load", _load, "*", "Load a savestate" }, { "load", _load, "*", "Load a savestate" },
{ "save", _save, "*", "Save a savestate" }, { "save", _save, "*", "Save a savestate" },
#endif #endif
@ -77,7 +77,7 @@ static void _frame(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
gbaDebugger->inVblank = GBARegisterDISPSTATGetInVblank(((struct GBA*) gbaDebugger->core->board)->memory.io[GBA_REG(DISPSTAT)]); gbaDebugger->inVblank = GBARegisterDISPSTATGetInVblank(((struct GBA*) gbaDebugger->core->board)->memory.io[GBA_REG(DISPSTAT)]);
} }
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
static void _load(struct CLIDebugger* debugger, struct CLIDebugVector* dv) { static void _load(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
struct CLIDebuggerBackend* be = debugger->backend; struct CLIDebuggerBackend* be = debugger->backend;
if (!dv || dv->type != CLIDV_INT_TYPE) { if (!dv || dv->type != CLIDV_INT_TYPE) {

View File

@ -31,9 +31,9 @@ source_group("3DS-specific code" FILES ${OS_SRC})
if(USE_VFS_3DS) if(USE_VFS_3DS)
list(APPEND OS_DEFINES USE_VFS_3DS) list(APPEND OS_DEFINES USE_VFS_3DS)
else() else()
list(APPEND CORE_VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c) list(APPEND VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
endif() endif()
set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE) set(VFS_SRC ${VFS_SRC} PARENT_SCOPE)
set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE) set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE)
list(APPEND GUI_SRC list(APPEND GUI_SRC

View File

@ -1081,6 +1081,7 @@ static bool _loadUniform(struct Configuration* description, size_t pass, struct
return true; return true;
} }
#ifdef ENABLE_VFS
bool mGLES2ShaderLoad(struct VideoShader* shader, struct VDir* dir) { bool mGLES2ShaderLoad(struct VideoShader* shader, struct VDir* dir) {
struct VFile* manifest = dir->openFile(dir, "manifest.ini", O_RDONLY); struct VFile* manifest = dir->openFile(dir, "manifest.ini", O_RDONLY);
if (!manifest) { if (!manifest) {
@ -1204,6 +1205,7 @@ bool mGLES2ShaderLoad(struct VideoShader* shader, struct VDir* dir) {
ConfigurationDeinit(&description); ConfigurationDeinit(&description);
return success; return success;
} }
#endif
void mGLES2ShaderFree(struct VideoShader* shader) { void mGLES2ShaderFree(struct VideoShader* shader) {
free((void*) shader->name); free((void*) shader->name);

View File

@ -106,8 +106,10 @@ void mGLES2ShaderDeinit(struct mGLES2Shader*);
void mGLES2ShaderAttach(struct mGLES2Context*, struct mGLES2Shader*, size_t nShaders); void mGLES2ShaderAttach(struct mGLES2Context*, struct mGLES2Shader*, size_t nShaders);
void mGLES2ShaderDetach(struct mGLES2Context*); void mGLES2ShaderDetach(struct mGLES2Context*);
#ifdef ENABLE_VFS
struct VDir; struct VDir;
bool mGLES2ShaderLoad(struct VideoShader*, struct VDir*); bool mGLES2ShaderLoad(struct VideoShader*, struct VDir*);
#endif
void mGLES2ShaderFree(struct VideoShader*); void mGLES2ShaderFree(struct VideoShader*);
CXX_GUARD_END CXX_GUARD_END

View File

@ -10,8 +10,8 @@ file(GLOB OS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/psp2-*.c)
set(OS_SRC ${OS_SRC} PARENT_SCOPE) set(OS_SRC ${OS_SRC} PARENT_SCOPE)
source_group("PS Vita-specific code" FILES ${OS_SRC}) source_group("PS Vita-specific code" FILES ${OS_SRC})
list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sce-vfs.c) list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sce-vfs.c)
set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE) set(VFS_SRC ${VFS_SRC} PARENT_SCOPE)
set(OS_LIB -lvita2d -l${M_LIBRARY} set(OS_LIB -lvita2d -l${M_LIBRARY}
-lSceAppMgr_stub -lSceAppMgr_stub

View File

@ -5,7 +5,7 @@ find_library(GLAPI_LIBRARY glapi REQUIRED)
find_library(EGL_LIBRARY EGL REQUIRED) find_library(EGL_LIBRARY EGL REQUIRED)
set(OS_DEFINES _GNU_SOURCE IOAPI_NO_64) set(OS_DEFINES _GNU_SOURCE IOAPI_NO_64)
list(APPEND CORE_VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c) list(APPEND VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c)
list(APPEND GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c) list(APPEND GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c)
include_directories(AFTER ${OPENGLES3_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIR}) include_directories(AFTER ${OPENGLES3_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIR})
@ -17,7 +17,7 @@ else()
find_library(NOUVEAU_LIBRARY drm_nouveau REQUIRED) find_library(NOUVEAU_LIBRARY drm_nouveau REQUIRED)
list(APPEND OS_LIB nx) list(APPEND OS_LIB nx)
endif() endif()
set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE) set(VFS_SRC ${VFS_SRC} PARENT_SCOPE)
set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE) set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE)
set(OS_LIB ${OS_LIB} PARENT_SCOPE) set(OS_LIB ${OS_LIB} PARENT_SCOPE)

View File

@ -9,14 +9,14 @@ if(WIIDRC_LIBRARY)
endif() endif()
set(OS_DEFINES _GNU_SOURCE COLOR_16_BIT COLOR_5_6_5 IOAPI_NO_64 FIXED_ROM_BUFFER) set(OS_DEFINES _GNU_SOURCE COLOR_16_BIT COLOR_5_6_5 IOAPI_NO_64 FIXED_ROM_BUFFER)
list(APPEND CORE_VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-devlist.c) list(APPEND VFS_SRC ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-fd.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-dirent.c ${PROJECT_SOURCE_DIR}/src/util/vfs/vfs-devlist.c)
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})
list(APPEND OS_LIB wiiuse bte fat ogc) list(APPEND OS_LIB wiiuse bte fat ogc)
set(OS_LIB ${OS_LIB} PARENT_SCOPE) set(OS_LIB ${OS_LIB} PARENT_SCOPE)
source_group("Wii-specific code" FILES ${OS_SRC}) source_group("Wii-specific code" FILES ${OS_SRC})
set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE) set(VFS_SRC ${VFS_SRC} PARENT_SCOPE)
set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE) set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE)
list(APPEND GUI_SRC ${CMAKE_CURRENT_BINARY_DIR}/font.c ${CMAKE_CURRENT_BINARY_DIR}/icons.c ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c) list(APPEND GUI_SRC ${CMAKE_CURRENT_BINARY_DIR}/font.c ${CMAKE_CURRENT_BINARY_DIR}/icons.c ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c)

View File

@ -12,7 +12,7 @@ set(TEST_FILES
test/classes.c test/classes.c
test/types.c) test/types.c)
if(USE_JSON_C) if(USE_JSON_C AND ENABLE_VFS)
list(APPEND SOURCE_FILES storage.c) list(APPEND SOURCE_FILES storage.c)
endif() endif()

View File

@ -424,6 +424,7 @@ bool mScriptContextLoadVF(struct mScriptContext* context, const char* name, stru
return info.context->load(info.context, name, vf); return info.context->load(info.context, name, vf);
} }
#ifdef ENABLE_VFS
bool mScriptContextLoadFile(struct mScriptContext* context, const char* path) { bool mScriptContextLoadFile(struct mScriptContext* context, const char* path) {
struct VFile* vf = VFileOpen(path, O_RDONLY); struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) { if (!vf) {
@ -433,6 +434,7 @@ bool mScriptContextLoadFile(struct mScriptContext* context, const char* path) {
vf->close(vf); vf->close(vf);
return ret; return ret;
} }
#endif
struct mScriptContext* mScriptActiveContext(void) { struct mScriptContext* mScriptActiveContext(void) {
return ThreadLocalGetValue(_threadContext); return ThreadLocalGetValue(_threadContext);

View File

@ -29,6 +29,7 @@ static struct mScriptValue* _mImageNew(unsigned width, unsigned height) {
return result; return result;
} }
#ifdef ENABLE_VFS
static struct mScriptValue* _mImageLoad(const char* path) { static struct mScriptValue* _mImageLoad(const char* path) {
struct mImage* image = mImageLoad(path); struct mImage* image = mImageLoad(path);
if (!image) { if (!image) {
@ -39,6 +40,7 @@ static struct mScriptValue* _mImageLoad(const char* path) {
result->flags = mSCRIPT_VALUE_FLAG_DEINIT; result->flags = mSCRIPT_VALUE_FLAG_DEINIT;
return result; return result;
} }
#endif
static struct mScriptValue* _mImageNewPainter(struct mScriptValue* image) { static struct mScriptValue* _mImageNewPainter(struct mScriptValue* image) {
mScriptValueRef(image); mScriptValueRef(image);
@ -54,16 +56,10 @@ static struct mScriptValue* _mImageNewPainter(struct mScriptValue* image) {
mSCRIPT_DECLARE_STRUCT_C_METHOD(mImage, U32, getPixel, mImageGetPixel, 2, U32, x, U32, y); mSCRIPT_DECLARE_STRUCT_C_METHOD(mImage, U32, getPixel, mImageGetPixel, 2, U32, x, U32, y);
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mImage, setPixel, mImageSetPixel, 3, U32, x, U32, y, U32, color); mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mImage, setPixel, mImageSetPixel, 3, U32, x, U32, y, U32, color);
mSCRIPT_DECLARE_STRUCT_C_METHOD_WITH_DEFAULTS(mImage, BOOL, save, mImageSave, 2, CHARP, path, CHARP, format);
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mImage, _deinit, mImageDestroy, 0); mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mImage, _deinit, mImageDestroy, 0);
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mImage, drawImageOpaque, mImageBlit, 3, CS(mImage), image, U32, x, U32, y); mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mImage, drawImageOpaque, mImageBlit, 3, CS(mImage), image, U32, x, U32, y);
mSCRIPT_DECLARE_STRUCT_VOID_METHOD_WITH_DEFAULTS(mImage, drawImage, mImageCompositeWithAlpha, 4, CS(mImage), image, U32, x, U32, y, F32, alpha); mSCRIPT_DECLARE_STRUCT_VOID_METHOD_WITH_DEFAULTS(mImage, drawImage, mImageCompositeWithAlpha, 4, CS(mImage), image, U32, x, U32, y, F32, alpha);
mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, save)
mSCRIPT_NO_DEFAULT,
mSCRIPT_CHARP("PNG")
mSCRIPT_DEFINE_DEFAULTS_END;
mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, drawImage) mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, drawImage)
mSCRIPT_NO_DEFAULT, mSCRIPT_NO_DEFAULT,
mSCRIPT_NO_DEFAULT, mSCRIPT_NO_DEFAULT,
@ -71,13 +67,23 @@ mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, drawImage)
mSCRIPT_F32(1.0f) mSCRIPT_F32(1.0f)
mSCRIPT_DEFINE_DEFAULTS_END; mSCRIPT_DEFINE_DEFAULTS_END;
#ifdef ENABLE_VFS
mSCRIPT_DECLARE_STRUCT_C_METHOD_WITH_DEFAULTS(mImage, BOOL, save, mImageSave, 2, CHARP, path, CHARP, format);
mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, save)
mSCRIPT_NO_DEFAULT,
mSCRIPT_CHARP("PNG")
mSCRIPT_DEFINE_DEFAULTS_END;
#endif
mSCRIPT_DEFINE_STRUCT(mImage) mSCRIPT_DEFINE_STRUCT(mImage)
mSCRIPT_DEFINE_CLASS_DOCSTRING( mSCRIPT_DEFINE_CLASS_DOCSTRING(
"A single, static image." "A single, static image."
) )
mSCRIPT_DEFINE_STRUCT_DEINIT(mImage) mSCRIPT_DEFINE_STRUCT_DEINIT(mImage)
#ifdef ENABLE_VFS
mSCRIPT_DEFINE_DOCSTRING("Save the image to a file. Currently, only `PNG` format is supported") mSCRIPT_DEFINE_DOCSTRING("Save the image to a file. Currently, only `PNG` format is supported")
mSCRIPT_DEFINE_STRUCT_METHOD(mImage, save) mSCRIPT_DEFINE_STRUCT_METHOD(mImage, save)
#endif
mSCRIPT_DEFINE_DOCSTRING("Get the ARGB value of the pixel at a given coordinate") mSCRIPT_DEFINE_DOCSTRING("Get the ARGB value of the pixel at a given coordinate")
mSCRIPT_DEFINE_STRUCT_METHOD(mImage, getPixel) mSCRIPT_DEFINE_STRUCT_METHOD(mImage, getPixel)
mSCRIPT_DEFINE_DOCSTRING("Set the ARGB value of the pixel at a given coordinate") mSCRIPT_DEFINE_DOCSTRING("Set the ARGB value of the pixel at a given coordinate")
@ -93,7 +99,9 @@ mSCRIPT_DEFINE_STRUCT(mImage)
mSCRIPT_DEFINE_END; mSCRIPT_DEFINE_END;
mSCRIPT_BIND_FUNCTION(mImageNew_Binding, W(mImage), _mImageNew, 2, U32, width, U32, height); mSCRIPT_BIND_FUNCTION(mImageNew_Binding, W(mImage), _mImageNew, 2, U32, width, U32, height);
#ifdef ENABLE_VFS
mSCRIPT_BIND_FUNCTION(mImageLoad_Binding, W(mImage), _mImageLoad, 1, CHARP, path); mSCRIPT_BIND_FUNCTION(mImageLoad_Binding, W(mImage), _mImageLoad, 1, CHARP, path);
#endif
mSCRIPT_BIND_FUNCTION(mImageNewPainter_Binding, W(mScriptPainter), _mImageNewPainter, 1, W(mImage), image); mSCRIPT_BIND_FUNCTION(mImageNewPainter_Binding, W(mScriptPainter), _mImageNewPainter, 1, W(mImage), image);
void _mPainterSetBlend(struct mPainter* painter, bool enable) { void _mPainterSetBlend(struct mPainter* painter, bool enable) {
@ -186,12 +194,16 @@ mSCRIPT_DEFINE_END;
void mScriptContextAttachImage(struct mScriptContext* context) { void mScriptContextAttachImage(struct mScriptContext* context) {
mScriptContextExportNamespace(context, "image", (struct mScriptKVPair[]) { mScriptContextExportNamespace(context, "image", (struct mScriptKVPair[]) {
mSCRIPT_KV_PAIR(new, &mImageNew_Binding), mSCRIPT_KV_PAIR(new, &mImageNew_Binding),
#ifdef ENABLE_VFS
mSCRIPT_KV_PAIR(load, &mImageLoad_Binding), mSCRIPT_KV_PAIR(load, &mImageLoad_Binding),
#endif
mSCRIPT_KV_PAIR(newPainter, &mImageNewPainter_Binding), mSCRIPT_KV_PAIR(newPainter, &mImageNewPainter_Binding),
mSCRIPT_KV_SENTINEL mSCRIPT_KV_SENTINEL
}); });
mScriptContextSetDocstring(context, "image", "Methods for creating struct::mImage and struct::mPainter instances"); mScriptContextSetDocstring(context, "image", "Methods for creating struct::mImage and struct::mPainter instances");
mScriptContextSetDocstring(context, "image.new", "Create a new image with the given dimensions"); mScriptContextSetDocstring(context, "image.new", "Create a new image with the given dimensions");
#ifdef ENABLE_VFS
mScriptContextSetDocstring(context, "image.load", "Load an image from a path. Currently, only `PNG` format is supported"); mScriptContextSetDocstring(context, "image.load", "Load an image from a path. Currently, only `PNG` format is supported");
#endif
mScriptContextSetDocstring(context, "image.newPainter", "Create a new painter from an existing image"); mScriptContextSetDocstring(context, "image.newPainter", "Create a new painter from an existing image");
} }

View File

@ -160,6 +160,7 @@ static char* _vfgets(char* stream, int size, void* user) {
return 0; return 0;
} }
#ifdef ENABLE_VFS
bool ConfigurationRead(struct Configuration* configuration, const char* path) { bool ConfigurationRead(struct Configuration* configuration, const char* path) {
struct VFile* vf = VFileOpen(path, O_RDONLY); struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) { if (!vf) {
@ -170,12 +171,6 @@ bool ConfigurationRead(struct Configuration* configuration, const char* path) {
return res; return res;
} }
bool ConfigurationReadVFile(struct Configuration* configuration, struct VFile* vf) {
HashTableClear(&configuration->root);
HashTableClear(&configuration->sections);
return ini_parse_stream(_vfgets, vf, _iniRead, configuration) == 0;
}
bool ConfigurationWrite(const struct Configuration* configuration, const char* path) { bool ConfigurationWrite(const struct Configuration* configuration, const char* path) {
struct VFile* vf = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC); struct VFile* vf = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) { if (!vf) {
@ -186,12 +181,6 @@ bool ConfigurationWrite(const struct Configuration* configuration, const char* p
return res; return res;
} }
bool ConfigurationWriteVFile(const struct Configuration* configuration, struct VFile* vf) {
HashTableEnumerate(&configuration->root, _keyHandler, vf);
HashTableEnumerate(&configuration->sections, _sectionHandler, vf);
return true;
}
bool ConfigurationWriteSection(const struct Configuration* configuration, const char* path, const char* section) { bool ConfigurationWriteSection(const struct Configuration* configuration, const char* path, const char* section) {
const struct Table* currentSection = &configuration->root; const struct Table* currentSection = &configuration->root;
struct VFile* vf = VFileOpen(path, O_WRONLY | O_CREAT | O_APPEND); struct VFile* vf = VFileOpen(path, O_WRONLY | O_CREAT | O_APPEND);
@ -213,6 +202,19 @@ bool ConfigurationWriteSection(const struct Configuration* configuration, const
vf->close(vf); vf->close(vf);
return true; return true;
} }
#endif
bool ConfigurationReadVFile(struct Configuration* configuration, struct VFile* vf) {
HashTableClear(&configuration->root);
HashTableClear(&configuration->sections);
return ini_parse_stream(_vfgets, vf, _iniRead, configuration) == 0;
}
bool ConfigurationWriteVFile(const struct Configuration* configuration, struct VFile* vf) {
HashTableEnumerate(&configuration->root, _keyHandler, vf);
HashTableEnumerate(&configuration->sections, _sectionHandler, vf);
return true;
}
void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user) { void ConfigurationEnumerateSections(const struct Configuration* configuration, void (*handler)(const char* sectionName, void* user), void* user) {
struct ConfigurationSectionHandlerData handlerData = { handler, user }; struct ConfigurationSectionHandlerData handlerData = { handler, user };

View File

@ -132,6 +132,7 @@ struct mImage* mImageCreateFromConstBuffer(unsigned width, unsigned height, unsi
return image; return image;
} }
#ifdef ENABLE_VFS
struct mImage* mImageLoad(const char* path) { struct mImage* mImageLoad(const char* path) {
struct VFile* vf = VFileOpen(path, O_RDONLY); struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) { if (!vf) {
@ -141,6 +142,7 @@ struct mImage* mImageLoad(const char* path) {
vf->close(vf); vf->close(vf);
return image; return image;
} }
#endif
#ifdef USE_PNG #ifdef USE_PNG
static struct mImage* mImageLoadPNG(struct VFile* vf) { static struct mImage* mImageLoadPNG(struct VFile* vf) {
@ -299,6 +301,7 @@ void mImageDestroy(struct mImage* image) {
free(image); free(image);
} }
#ifdef ENABLE_VFS
bool mImageSave(const struct mImage* image, const char* path, const char* format) { bool mImageSave(const struct mImage* image, const char* path, const char* format) {
struct VFile* vf = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC); struct VFile* vf = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) { if (!vf) {
@ -314,6 +317,7 @@ bool mImageSave(const struct mImage* image, const char* path, const char* format
vf->close(vf); vf->close(vf);
return success; return success;
} }
#endif
#ifdef USE_PNG #ifdef USE_PNG
bool mImageSavePNG(const struct mImage* image, struct VFile* vf) { bool mImageSavePNG(const struct mImage* image, struct VFile* vf) {

View File

@ -7,7 +7,7 @@
#include <mgba-util/vfs.h> #include <mgba-util/vfs.h>
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
M_TEST_DEFINE(openNullPathR) { M_TEST_DEFINE(openNullPathR) {
struct VFile* vf = VFileOpen(NULL, O_RDONLY); struct VFile* vf = VFileOpen(NULL, O_RDONLY);
assert_null(vf); assert_null(vf);
@ -146,7 +146,7 @@ M_TEST_DEFINE(mapMemChunk) {
} }
M_TEST_SUITE_DEFINE(VFS, M_TEST_SUITE_DEFINE(VFS,
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2 #ifdef ENABLE_VFS
cmocka_unit_test(openNullPathR), cmocka_unit_test(openNullPathR),
cmocka_unit_test(openNullPathW), cmocka_unit_test(openNullPathW),
cmocka_unit_test(openNullPathCreate), cmocka_unit_test(openNullPathCreate),

View File

@ -18,6 +18,7 @@
#include <windows.h> #include <windows.h>
#endif #endif
#ifdef ENABLE_VFS
struct VFile* VFileOpen(const char* path, int flags) { struct VFile* VFileOpen(const char* path, int flags) {
#ifdef USE_VFS_FILE #ifdef USE_VFS_FILE
const char* chflags; const char* chflags;
@ -115,6 +116,7 @@ struct VDir* VDirOpenArchive(const char* path) {
#endif #endif
return dir; return dir;
} }
#endif
ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) { ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) {
size_t bytesRead = 0; size_t bytesRead = 0;
@ -246,6 +248,7 @@ void makeAbsolute(const char* path, const char* base, char* out) {
strncpy(out, buf, PATH_MAX); strncpy(out, buf, PATH_MAX);
} }
#ifdef ENABLE_VFS
struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*)) { struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*)) {
dir->rewind(dir); dir->rewind(dir);
struct VDirEntry* dirent = dir->listNext(dir); struct VDirEntry* dirent = dir->listNext(dir);
@ -310,3 +313,4 @@ struct VFile* VDirFindNextAvailable(struct VDir* dir, const char* basename, cons
path[PATH_MAX - 1] = '\0'; path[PATH_MAX - 1] = '\0';
return dir->openFile(dir, path, mode); return dir->openFile(dir, path, mode);
} }
#endif