mirror of https://github.com/mgba-emu/mgba.git
Scripting: Expose more key functionality
This commit is contained in:
parent
85b619dc78
commit
ced8fb516c
|
@ -325,6 +325,18 @@ static struct mScriptValue* _mScriptCoreChecksum(const struct mCore* core, int t
|
|||
return ret;
|
||||
}
|
||||
|
||||
static void _mScriptCoreAddKey(struct mCore* core, int32_t key) {
|
||||
core->addKeys(core, 1 << key);
|
||||
}
|
||||
|
||||
static void _mScriptCoreClearKey(struct mCore* core, int32_t key) {
|
||||
core->clearKeys(core, 1 << key);
|
||||
}
|
||||
|
||||
static int32_t _mScriptCoreGetKey(struct mCore* core, int32_t key) {
|
||||
return (core->getKeys(core) >> key) & 1;
|
||||
}
|
||||
|
||||
static struct mScriptValue* _mScriptCoreReadRange(struct mCore* core, uint32_t address, uint32_t length) {
|
||||
struct mScriptValue* value = mScriptStringCreateEmpty(length);
|
||||
char* buffer = value->value.string->buffer;
|
||||
|
@ -366,6 +378,9 @@ mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(mCore, step, 0);
|
|||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(mCore, setKeys, 1, U32, keys);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(mCore, addKeys, 1, U32, keys);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_D_METHOD(mCore, clearKeys, 1, U32, keys);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mCore, addKey, _mScriptCoreAddKey, 1, S32, key);
|
||||
mSCRIPT_DECLARE_STRUCT_VOID_METHOD(mCore, clearKey, _mScriptCoreClearKey, 1, S32, key);
|
||||
mSCRIPT_DECLARE_STRUCT_METHOD(mCore, S32, getKey, _mScriptCoreGetKey, 1, S32, key);
|
||||
mSCRIPT_DECLARE_STRUCT_D_METHOD(mCore, U32, getKeys, 0);
|
||||
|
||||
// Memory functions
|
||||
|
@ -413,13 +428,19 @@ mSCRIPT_DEFINE_STRUCT(mCore)
|
|||
mSCRIPT_DEFINE_DOCSTRING("Run a single instruction")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, step)
|
||||
|
||||
mSCRIPT_DEFINE_DOCSTRING("Set the currently active keys")
|
||||
mSCRIPT_DEFINE_DOCSTRING("Set the currently active key list")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, setKeys)
|
||||
mSCRIPT_DEFINE_DOCSTRING("Add keys to the currently active key list")
|
||||
mSCRIPT_DEFINE_DOCSTRING("Add a single key to the currently active key list")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, addKey)
|
||||
mSCRIPT_DEFINE_DOCSTRING("Add a bitmask of keys to the currently active key list")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, addKeys)
|
||||
mSCRIPT_DEFINE_DOCSTRING("Remove keys from the currently active key list")
|
||||
mSCRIPT_DEFINE_DOCSTRING("Remove a single key from the currently active key list")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, clearKey)
|
||||
mSCRIPT_DEFINE_DOCSTRING("Remove a bitmask of keys from the currently active key list")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, clearKeys)
|
||||
mSCRIPT_DEFINE_DOCSTRING("Get the currently active keys")
|
||||
mSCRIPT_DEFINE_DOCSTRING("Get the active state of a given key")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, getKey)
|
||||
mSCRIPT_DEFINE_DOCSTRING("Get the currently active keys as a bitmask")
|
||||
mSCRIPT_DEFINE_STRUCT_METHOD(mCore, getKeys)
|
||||
|
||||
mSCRIPT_DEFINE_DOCSTRING("Read an 8-bit value from the given bus address")
|
||||
|
|
|
@ -8,6 +8,12 @@
|
|||
#include <mgba/core/core.h>
|
||||
#include <mgba/core/serialize.h>
|
||||
#include <mgba/script/macros.h>
|
||||
#ifdef M_CORE_GBA
|
||||
#include <mgba/internal/gba/input.h>
|
||||
#endif
|
||||
#ifdef M_CORE_GB
|
||||
#include <mgba/internal/gb/input.h>
|
||||
#endif
|
||||
|
||||
struct mScriptCallbackManager {
|
||||
struct mScriptContext* context;
|
||||
|
@ -62,5 +68,33 @@ void mScriptContextAttachStdlib(struct mScriptContext* context) {
|
|||
mSCRIPT_CONSTANT_PAIR(mCHECKSUM, CRC32),
|
||||
mSCRIPT_CONSTANT_SENTINEL
|
||||
});
|
||||
#ifdef M_CORE_GBA
|
||||
mScriptContextExportConstants(context, "GBA_KEY", (struct mScriptKVPair[]) {
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, A),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, B),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, SELECT),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, START),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, RIGHT),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, LEFT),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, UP),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, DOWN),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, R),
|
||||
mSCRIPT_CONSTANT_PAIR(GBA_KEY, L),
|
||||
mSCRIPT_CONSTANT_SENTINEL
|
||||
});
|
||||
#endif
|
||||
#ifdef M_CORE_GB
|
||||
mScriptContextExportConstants(context, "GB_KEY", (struct mScriptKVPair[]) {
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, A),
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, B),
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, SELECT),
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, START),
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, RIGHT),
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, LEFT),
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, UP),
|
||||
mSCRIPT_CONSTANT_PAIR(GB_KEY, DOWN),
|
||||
mSCRIPT_CONSTANT_SENTINEL
|
||||
});
|
||||
#endif
|
||||
mScriptContextSetGlobal(context, "C", context->constants);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue