diff --git a/src/jsapi.c b/src/jsapi.c index 3fa311a..1d02dbc 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -242,7 +242,7 @@ static s32 duk_key(duk_context* duk) if (duk_is_null_or_undefined(duk, 0)) { - duk_push_uint(duk, tic->api.key(tic, tic_key_unknown)); + duk_push_boolean(duk, tic->api.key(tic, tic_key_unknown)); } else { @@ -267,7 +267,7 @@ static s32 duk_keyp(duk_context* duk) if (duk_is_null_or_undefined(duk, 0)) { - duk_push_uint(duk, tic->api.keyp(tic, tic_key_unknown, -1, -1)); + duk_push_boolean(duk, tic->api.keyp(tic, tic_key_unknown, -1, -1)); } else { diff --git a/src/luaapi.c b/src/luaapi.c index 761e8d6..0b005b8 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -789,7 +789,7 @@ static s32 lua_key(lua_State* lua) if (top == 0) { - lua_pushinteger(lua, tic->api.key(tic, tic_key_unknown)); + lua_pushboolean(lua, tic->api.key(tic, tic_key_unknown)); } else if (top == 1) { @@ -821,7 +821,7 @@ static s32 lua_keyp(lua_State* lua) if (top == 0) { - lua_pushinteger(lua, tic->api.keyp(tic, tic_key_unknown, -1, -1)); + lua_pushboolean(lua, tic->api.keyp(tic, tic_key_unknown, -1, -1)); } else { diff --git a/src/tic.c b/src/tic.c index bc956fa..3489013 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1648,14 +1648,14 @@ static u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period) return ((~previous.data) & machine->memory.ram.input.gamepads.data) & (1 << index); } -static u32 api_key(tic_mem* tic, tic_key key) +static bool api_key(tic_mem* tic, tic_key key) { return key >= TIC_KEY_START_INDEX ? isKeyPressed(&tic->ram.input.keyboard, key) : tic->ram.input.keyboard.data; } -static u32 api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period) +static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period) { tic_machine* machine = (tic_machine*)tic; @@ -1672,8 +1672,6 @@ static u32 api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period) return !prevDown && down; } - tic80_keyboard prev = {.data = 0}; - for(s32 i = 0; i < TIC_KEY_BUFFER; i++) { tic_key key = tic->ram.input.keyboard.keys[i]; @@ -1692,11 +1690,11 @@ static u32 api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period) } if(!wasPressed) - prev.keys[i] = key; + return true; } } - return prev.data; + return false; } diff --git a/src/ticapi.h b/src/ticapi.h index 98a11e6..4fc66f4 100644 --- a/src/ticapi.h +++ b/src/ticapi.h @@ -154,8 +154,8 @@ typedef struct void (*resume) (tic_mem* memory); void (*sync) (tic_mem* memory, u32 mask, s32 bank, bool toCart); u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period); - u32 (*key) (tic_mem* memory, tic_key key); - u32 (*keyp) (tic_mem* memory, tic_key key, s32 hold, s32 period); + bool (*key) (tic_mem* memory, tic_key key); + bool (*keyp) (tic_mem* memory, tic_key key, s32 hold, s32 period); void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette); s32 (*save) (const tic_cartridge* rom, u8* buffer);