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()
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)
source_group("Windows-specific code" FILES ${OS_SRC})
elseif(UNIX)
@ -230,7 +230,7 @@ elseif(UNIX)
add_definitions(-D_GNU_SOURCE)
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)
source_group("POSIX-specific code" FILES ${OS_SRC})
endif()
@ -349,6 +349,9 @@ elseif(NOT CMAKE_SYSTEM_NAME STREQUAL "Linux")
endif()
check_include_files("xlocale.h" HAVE_XLOCALE)
set(ENABLE_VFS ON)
if(CMAKE_SYSTEM_NAME STREQUAL "Generic")
if(NOT IS_EMBEDDED)
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})
endif()
if(ENABLE_VFS)
list(APPEND ENABLES VFS)
endif()
foreach(FEATURE IN LISTS FEATURES)
list(APPEND FEATURE_DEFINES "USE_${FEATURE}")
endforeach()
@ -890,7 +897,11 @@ list(APPEND CORE_SRC
${THIRD_PARTY_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)
set(ENABLE_EXTRA ON)
if(M_CORE_GBA)
@ -922,7 +933,7 @@ if(NOT SKIP_LIBRARY)
endif()
if(BUILD_SHARED)
add_library(${BINARY_NAME} SHARED ${SRC} ${VFS_SRC})
add_library(${BINARY_NAME} SHARED ${SRC})
set(EXPORT_DEFINES MGBA_DLL)
if(BUILD_STATIC)
add_library(${BINARY_NAME}-static STATIC ${SRC})
@ -993,7 +1004,7 @@ if(BUILD_LIBRETRO)
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)
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);
#ifdef ENABLE_VFS
bool ConfigurationRead(struct Configuration*, const char* path);
bool ConfigurationReadVFile(struct Configuration*, struct VFile* vf);
bool ConfigurationWrite(const struct Configuration*, const char* path);
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);
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* 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);
#ifdef ENABLE_VFS
struct mImage* mImageLoad(const char* path);
#endif
struct mImage* mImageLoadVF(struct VFile* vf);
struct mImage* mImageConvertToFormat(const struct mImage*, enum mColorFormat format);
void mImageDestroy(struct mImage*);
#ifdef ENABLE_VFS
bool mImageSave(const struct mImage*, const char* path, const char* format);
#endif
bool mImageSaveVF(const struct mImage*, struct VFile* vf, const char* format);
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);
};
#ifdef ENABLE_VFS
struct VDirEntry {
const char* (*name)(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* VFileFromFD(int fd);
#endif
struct VFile* VFileFromMemory(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 VFile* VFileFIFO(struct mCircleBuffer* backing);
#ifdef ENABLE_VFS
struct VDir* VDirOpen(const char* path);
struct VDir* VDirOpenArchive(const char* path);
@ -92,20 +95,20 @@ struct VDir* VDeviceList(void);
#endif
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
struct VFile* VFileFOpen(const char* path, const char* mode);
struct VFile* VFileFromFILE(FILE* file);
#endif
#endif
void separatePath(const char* path, char* dirname, char* basename, char* extension);
bool isAbsolute(const char* path);
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 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 mCheatParseEZFChtFile(struct mCheatDevice*, struct VFile*);
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
void mCheatAutosave(struct mCheatDevice*);
#endif

View File

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

View File

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

View File

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

View File

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

View File

@ -70,7 +70,9 @@ void mScriptBridgeDebuggerEntered(struct mScriptBridge*, enum mDebuggerEntryReas
#endif
void mScriptBridgeRun(struct mScriptBridge*);
#ifdef ENABLE_VFS
bool mScriptBridgeLoadScript(struct mScriptBridge*, const char* name);
#endif
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);
struct EReaderScan;
#ifdef USE_PNG
#if defined(USE_PNG) && defined(ENABLE_VFS)
MGBA_EXPORT struct EReaderScan* EReaderScanLoadImagePNG(const char* filename);
#endif
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 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);
#endif
CXX_GUARD_END

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -129,6 +129,7 @@ void mScriptBridgeRun(struct mScriptBridge* sb) {
HashTableEnumerate(&sb->engines, _seRun, NULL);
}
#ifdef ENABLE_VFS
bool mScriptBridgeLoadScript(struct mScriptBridge* sb, const char* name) {
struct VFile* vf = VFileOpen(name, O_RDONLY);
if (!vf) {
@ -143,6 +144,7 @@ bool mScriptBridgeLoadScript(struct mScriptBridge* sb, const char* name) {
vf->close(vf);
return info.success;
}
#endif
bool mScriptBridgeLookupSymbol(struct mScriptBridge* sb, const char* name, int32_t* out) {
struct mScriptSymbol info = {
@ -417,6 +419,7 @@ static struct mScriptValue* _mScriptCoreSaveState(struct mCore* core, int32_t fl
return value;
}
#ifdef ENABLE_VFS
static int _mScriptCoreSaveStateFile(struct mCore* core, const char* path, int flags) {
struct VFile* vf = VFileOpen(path, O_WRONLY | O_TRUNC | O_CREAT);
if (!vf) {
@ -427,13 +430,6 @@ static int _mScriptCoreSaveStateFile(struct mCore* core, const char* path, int f
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) {
struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) {
@ -456,6 +452,14 @@ static void _mScriptCoreTakeScreenshot(struct mCore* core, const char* filename)
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) {
size_t stride;
@ -480,10 +484,12 @@ static struct mScriptValue* _mScriptCoreTakeScreenshotToImage(struct mCore* core
return result;
}
#ifdef ENABLE_VFS
// Loading functions
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, loadSaveFile, mCoreLoadSaveFile, 2, CHARP, path, BOOL, temporary);
#endif
// Info functions
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);
// 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, 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, 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);
// Miscellaneous functions
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_DEFINE_STRUCT(mCore)
mSCRIPT_DEFINE_CLASS_DOCSTRING(
"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_STRUCT_METHOD(mCore, loadFile)
mSCRIPT_DEFINE_DOCSTRING("Load the save data associated with the currently loaded ROM file")
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_STRUCT_METHOD(mCore, loadSaveFile)
#endif
mSCRIPT_DEFINE_DOCSTRING("Get which platform is being emulated. See C.PLATFORM for possible values")
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_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_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_STRUCT_METHOD(mCore, saveStateFile)
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_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_STRUCT_METHOD(mCore, loadStateFile)
mSCRIPT_DEFINE_DOCSTRING("Save a screenshot to a file")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, screenshot)
#endif
mSCRIPT_DEFINE_DOCSTRING("Get a screenshot in an struct::mImage")
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, screenshotToImage)
mSCRIPT_DEFINE_END;

View File

@ -8,7 +8,7 @@
#include <mgba/core/core.h>
#include <mgba-util/vfs.h>
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
M_TEST_DEFINE(findNullPath) {
struct mCore* core = mCoreFind(NULL);
assert_null(core);
@ -29,7 +29,7 @@ M_TEST_DEFINE(findEmpty) {
}
M_TEST_SUITE_DEFINE(mCore,
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
cmocka_unit_test(findNullPath),
#endif
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 _dumpWord(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 _finish(struct CLIDebugger*, struct CLIDebugVector*);
static void _setStackTraceMode(struct CLIDebugger*, struct CLIDebugVector*);
#ifdef ENABLE_VFS
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 _findSymbol(struct CLIDebugger*, struct CLIDebugVector*);
@ -96,6 +98,9 @@ static struct CLIDebuggerCommandSummary _debuggerCommands[] = {
{ "help", _printHelp, "S", "Print help" },
{ "listb", _listBreakpoints, "", "List breakpoints" },
{ "listw", _listWatchpoints, "", "List watchpoints" },
#ifdef ENABLE_VFS
{ "load-symbols", _loadSymbols, "S", "Load symbols from an external file" },
#endif
{ "next", _next, "", "Execute next instruction" },
{ "print", _print, "S+", "Print a value" },
{ "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/4", _readWord, "I", "Read a word from a specified offset" },
{ "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" },
{ "status", _printStatus, "", "Print the current status" },
{ "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" },
{ "w/1", _writeByte, "II", "Write a byte 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/2", _dumpHalfword, "Ii", "Examine halfwords 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)
{ "!", _breakInto, "", "Break into attached debugger (for developers)" },
#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) {
if (!dv) {
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) {
return;
}
#ifdef ENABLE_VFS
if (dv->next && dv->next->charValue) {
debugger->traceVf = VFileOpen(dv->next->charValue, O_CREAT | O_WRONLY | O_APPEND);
}
#endif
if (_doTrace(debugger)) {
debugger->d.isPaused = false;
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) {
struct mDebuggerSymbols* symbolTable = debugger->d.p->core->symbolTable;
if (!symbolTable) {
@ -1431,6 +1438,7 @@ static void _loadSymbols(struct CLIDebugger* debugger, struct CLIDebugVector* dv
}
vf->close(vf);
}
#endif
static void _setSymbol(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
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);
el_set(elbe->elstate, EL_HIST, history, elbe->histate);
#ifdef ENABLE_VFS
char path[PATH_MAX + 1];
mCoreConfigDirectory(path, PATH_MAX);
if (path[0]) {
@ -99,6 +100,7 @@ static void CLIDebuggerEditLineInit(struct CLIDebuggerBackend* be) {
vf->close(vf);
}
}
#endif
MutexInit(&elbe->promptMutex);
ConditionInit(&elbe->promptRead);
@ -120,6 +122,7 @@ static void CLIDebuggerEditLineDeinit(struct CLIDebuggerBackend* be) {
MutexUnlock(&elbe->promptMutex);
ThreadJoin(&elbe->promptThread);
#ifdef ENABLE_VFS
char path[PATH_MAX + 1];
mCoreConfigDirectory(path, PATH_MAX);
if (path[0]) {
@ -139,6 +142,7 @@ static void CLIDebuggerEditLineDeinit(struct CLIDebuggerBackend* be) {
vf->close(vf);
}
}
#endif
history_end(elbe->histate);
el_end(elbe->elstate);
free(elbe);

View File

@ -3,10 +3,14 @@ set(SOURCE_FILES
commandline.c
proxy-backend.c
thread-proxy.c
updater.c
video-backend.c
video-logger.c)
if(ENABLE_VFS)
list(APPEND SOURCE_FILES
updater.c)
endif()
set(GUI_FILES
gui/cheats.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) {
#ifdef ENABLE_VFS
if (args->patch) {
struct VFile* patch = VFileOpen(args->patch, O_RDONLY);
if (patch) {
@ -266,6 +267,10 @@ void mArgumentsApplyFileLoads(const struct mArguments* args, struct mCore* core)
} else {
mCoreAutoloadCheats(core);
}
#else
UNUSED(args);
UNUSED(core);
#endif
}
void mArgumentsDeinit(struct mArguments* args) {

View File

@ -149,7 +149,7 @@ static bool _GBCoreInit(struct mCore* core) {
gbcore->keys = 0;
gb->keySource = &gbcore->keys;
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
mDirectorySetInit(&core->dirs);
#endif
@ -161,7 +161,7 @@ static void _GBCoreDeinit(struct mCore* core) {
GBDestroy(core->board);
mappedMemoryFree(core->cpu, sizeof(struct SM83Core));
mappedMemoryFree(core->board, sizeof(struct GB));
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
mDirectorySetDeinit(&core->dirs);
#endif
#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) {
struct VFile* bios = NULL;
bool found = false;
@ -1108,7 +1108,7 @@ static void _GBCoreDetachDebugger(struct mCore* core) {
static void _GBCoreLoadSymbols(struct mCore* core, struct VFile* vf) {
core->symbolTable = mDebuggerSymbolTableCreate();
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
if (!vf && core->dirs.base) {
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 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 _save(struct CLIDebugger*, struct CLIDebugVector*);
#endif
struct CLIDebuggerCommandSummary _GBCLIDebuggerCommands[] = {
{ "frame", _frame, "", "Frame advance" },
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
{ "load", _load, "*", "Load a savestate" },
{ "save", _save, "*", "Save a savestate" },
#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;
}
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
static void _load(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
struct CLIDebuggerBackend* be = debugger->backend;
if (!dv || dv->type != CLIDV_INT_TYPE) {

View File

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

View File

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

View File

@ -16,14 +16,14 @@ static void _GBACLIDebuggerInit(struct CLIDebuggerSystem*);
static bool _GBACLIDebuggerCustom(struct CLIDebuggerSystem*);
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 _save(struct CLIDebugger*, struct CLIDebugVector*);
#endif
struct CLIDebuggerCommandSummary _GBACLIDebuggerCommands[] = {
{ "frame", _frame, "", "Frame advance" },
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
{ "load", _load, "*", "Load a savestate" },
{ "save", _save, "*", "Save a savestate" },
#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)]);
}
#if !defined(MINIMAL_CORE) || MINIMAL_CORE < 2
#ifdef ENABLE_VFS
static void _load(struct CLIDebugger* debugger, struct CLIDebugVector* dv) {
struct CLIDebuggerBackend* be = debugger->backend;
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)
list(APPEND OS_DEFINES USE_VFS_3DS)
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()
set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE)
set(VFS_SRC ${VFS_SRC} PARENT_SCOPE)
set(OS_DEFINES ${OS_DEFINES} PARENT_SCOPE)
list(APPEND GUI_SRC

View File

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

View File

@ -106,8 +106,10 @@ void mGLES2ShaderDeinit(struct mGLES2Shader*);
void mGLES2ShaderAttach(struct mGLES2Context*, struct mGLES2Shader*, size_t nShaders);
void mGLES2ShaderDetach(struct mGLES2Context*);
#ifdef ENABLE_VFS
struct VDir;
bool mGLES2ShaderLoad(struct VideoShader*, struct VDir*);
#endif
void mGLES2ShaderFree(struct VideoShader*);
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)
source_group("PS Vita-specific code" FILES ${OS_SRC})
list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sce-vfs.c)
set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE)
list(APPEND VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sce-vfs.c)
set(VFS_SRC ${VFS_SRC} PARENT_SCOPE)
set(OS_LIB -lvita2d -l${M_LIBRARY}
-lSceAppMgr_stub

View File

@ -5,7 +5,7 @@ find_library(GLAPI_LIBRARY glapi REQUIRED)
find_library(EGL_LIBRARY EGL REQUIRED)
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)
include_directories(AFTER ${OPENGLES3_INCLUDE_DIR} ${OPENGL_EGL_INCLUDE_DIR})
@ -17,7 +17,7 @@ else()
find_library(NOUVEAU_LIBRARY drm_nouveau REQUIRED)
list(APPEND OS_LIB nx)
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_LIB ${OS_LIB} PARENT_SCOPE)

View File

@ -9,14 +9,14 @@ if(WIIDRC_LIBRARY)
endif()
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})
list(APPEND OS_LIB wiiuse bte fat ogc)
set(OS_LIB ${OS_LIB} PARENT_SCOPE)
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)
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/types.c)
if(USE_JSON_C)
if(USE_JSON_C AND ENABLE_VFS)
list(APPEND SOURCE_FILES storage.c)
endif()

View File

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

View File

@ -29,6 +29,7 @@ static struct mScriptValue* _mImageNew(unsigned width, unsigned height) {
return result;
}
#ifdef ENABLE_VFS
static struct mScriptValue* _mImageLoad(const char* path) {
struct mImage* image = mImageLoad(path);
if (!image) {
@ -39,6 +40,7 @@ static struct mScriptValue* _mImageLoad(const char* path) {
result->flags = mSCRIPT_VALUE_FLAG_DEINIT;
return result;
}
#endif
static struct mScriptValue* _mImageNewPainter(struct mScriptValue* 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_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, 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_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, save)
mSCRIPT_NO_DEFAULT,
mSCRIPT_CHARP("PNG")
mSCRIPT_DEFINE_DEFAULTS_END;
mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, drawImage)
mSCRIPT_NO_DEFAULT,
mSCRIPT_NO_DEFAULT,
@ -71,13 +67,23 @@ mSCRIPT_DEFINE_STRUCT_BINDING_DEFAULTS(mImage, drawImage)
mSCRIPT_F32(1.0f)
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_CLASS_DOCSTRING(
"A single, static image."
)
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_STRUCT_METHOD(mImage, save)
#endif
mSCRIPT_DEFINE_DOCSTRING("Get the ARGB value of the pixel at a given coordinate")
mSCRIPT_DEFINE_STRUCT_METHOD(mImage, getPixel)
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_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);
#endif
mSCRIPT_BIND_FUNCTION(mImageNewPainter_Binding, W(mScriptPainter), _mImageNewPainter, 1, W(mImage), image);
void _mPainterSetBlend(struct mPainter* painter, bool enable) {
@ -186,12 +194,16 @@ mSCRIPT_DEFINE_END;
void mScriptContextAttachImage(struct mScriptContext* context) {
mScriptContextExportNamespace(context, "image", (struct mScriptKVPair[]) {
mSCRIPT_KV_PAIR(new, &mImageNew_Binding),
#ifdef ENABLE_VFS
mSCRIPT_KV_PAIR(load, &mImageLoad_Binding),
#endif
mSCRIPT_KV_PAIR(newPainter, &mImageNewPainter_Binding),
mSCRIPT_KV_SENTINEL
});
mScriptContextSetDocstring(context, "image", "Methods for creating struct::mImage and struct::mPainter instances");
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");
#endif
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;
}
#ifdef ENABLE_VFS
bool ConfigurationRead(struct Configuration* configuration, const char* path) {
struct VFile* vf = VFileOpen(path, O_RDONLY);
if (!vf) {
@ -170,12 +171,6 @@ bool ConfigurationRead(struct Configuration* configuration, const char* path) {
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) {
struct VFile* vf = VFileOpen(path, O_WRONLY | O_CREAT | O_TRUNC);
if (!vf) {
@ -186,12 +181,6 @@ bool ConfigurationWrite(const struct Configuration* configuration, const char* p
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) {
const struct Table* currentSection = &configuration->root;
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);
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) {
struct ConfigurationSectionHandlerData handlerData = { handler, user };

View File

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

View File

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

View File

@ -18,6 +18,7 @@
#include <windows.h>
#endif
#ifdef ENABLE_VFS
struct VFile* VFileOpen(const char* path, int flags) {
#ifdef USE_VFS_FILE
const char* chflags;
@ -115,6 +116,7 @@ struct VDir* VDirOpenArchive(const char* path) {
#endif
return dir;
}
#endif
ssize_t VFileReadline(struct VFile* vf, char* buffer, size_t size) {
size_t bytesRead = 0;
@ -246,6 +248,7 @@ void makeAbsolute(const char* path, const char* base, char* out) {
strncpy(out, buf, PATH_MAX);
}
#ifdef ENABLE_VFS
struct VFile* VDirFindFirst(struct VDir* dir, bool (*filter)(struct VFile*)) {
dir->rewind(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';
return dir->openFile(dir, path, mode);
}
#endif