diff --git a/include/mgba/core/core.h b/include/mgba/core/core.h index b1440f2fe..7d72c7148 100644 --- a/include/mgba/core/core.h +++ b/include/mgba/core/core.h @@ -181,6 +181,8 @@ bool mCoreAutoloadSave(struct mCore* core); bool mCoreAutoloadPatch(struct mCore* core); bool mCoreAutoloadCheats(struct mCore* core); +bool mCoreLoadSaveFile(struct mCore* core, const char* path, bool temporary); + bool mCoreSaveState(struct mCore* core, int slot, int flags); bool mCoreLoadState(struct mCore* core, int slot, int flags); struct VFile* mCoreGetState(struct mCore* core, int slot, bool write); diff --git a/src/core/core.c b/src/core/core.c index 931b7feda..c4c3a3ce8 100644 --- a/src/core/core.c +++ b/src/core/core.c @@ -259,6 +259,18 @@ bool mCoreAutoloadCheats(struct mCore* core) { return success; } +bool mCoreLoadSaveFile(struct mCore* core, const char* path, bool temporary) { + struct VFile* vf = VFileOpen(path, O_CREAT | O_RDWR); + if (!vf) { + return false; + } + if (temporary) { + return core->loadTemporarySave(core, vf); + } else { + return core->loadSave(core, vf); + } +} + bool mCoreSaveState(struct mCore* core, int slot, int flags) { struct VFile* vf = mCoreGetState(core, slot, true); if (!vf) { diff --git a/src/core/scripting.c b/src/core/scripting.c index 480227b99..96f972438 100644 --- a/src/core/scripting.c +++ b/src/core/scripting.c @@ -393,6 +393,11 @@ static void _mScriptCoreTakeScreenshot(struct mCore* core, const char* filename) } } +// Loading functions +mSCRIPT_DECLARE_STRUCT_METHOD(mCore, S32, loadFile, mCoreLoadFile, 1, CHARP, path); +mSCRIPT_DECLARE_STRUCT_METHOD(mCore, S32, autoloadSave, mCoreAutoloadSave, 0); +mSCRIPT_DECLARE_STRUCT_METHOD(mCore, S32, loadSaveFile, mCoreLoadSaveFile, 2, CHARP, path, S8, temporary); + // Info functions mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, S32, platform, 0); mSCRIPT_DECLARE_STRUCT_CD_METHOD(mCore, U32, frameCounter, 0); @@ -442,6 +447,13 @@ mSCRIPT_DEFINE_STRUCT(mCore) mSCRIPT_DEFINE_CLASS_DOCSTRING( "An instance of an emulator core." ) + 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) + mSCRIPT_DEFINE_DOCSTRING("Get which platform is being emulated. See C.PLATFORM for possible values") mSCRIPT_DEFINE_STRUCT_METHOD(mCore, platform) mSCRIPT_DEFINE_DOCSTRING("Get the number of the current frame")