Scripting: Add loading API

This commit is contained in:
Vicki Pfau 2022-07-01 00:34:33 -07:00
parent 84e60e99f4
commit 9515de7212
3 changed files with 26 additions and 0 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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")