#484 key api always should return bool value
This commit is contained in:
@@ -242,7 +242,7 @@ static s32 duk_key(duk_context* duk)
|
|||||||
|
|
||||||
if (duk_is_null_or_undefined(duk, 0))
|
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
|
else
|
||||||
{
|
{
|
||||||
@@ -267,7 +267,7 @@ static s32 duk_keyp(duk_context* duk)
|
|||||||
|
|
||||||
if (duk_is_null_or_undefined(duk, 0))
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -789,7 +789,7 @@ static s32 lua_key(lua_State* lua)
|
|||||||
|
|
||||||
if (top == 0)
|
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)
|
else if (top == 1)
|
||||||
{
|
{
|
||||||
@@ -821,7 +821,7 @@ static s32 lua_keyp(lua_State* lua)
|
|||||||
|
|
||||||
if (top == 0)
|
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
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
10
src/tic.c
10
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);
|
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
|
return key >= TIC_KEY_START_INDEX
|
||||||
? isKeyPressed(&tic->ram.input.keyboard, key)
|
? isKeyPressed(&tic->ram.input.keyboard, key)
|
||||||
: tic->ram.input.keyboard.data;
|
: 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;
|
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;
|
return !prevDown && down;
|
||||||
}
|
}
|
||||||
|
|
||||||
tic80_keyboard prev = {.data = 0};
|
|
||||||
|
|
||||||
for(s32 i = 0; i < TIC_KEY_BUFFER; i++)
|
for(s32 i = 0; i < TIC_KEY_BUFFER; i++)
|
||||||
{
|
{
|
||||||
tic_key key = tic->ram.input.keyboard.keys[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)
|
if(!wasPressed)
|
||||||
prev.keys[i] = key;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return prev.data;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -154,8 +154,8 @@ typedef struct
|
|||||||
void (*resume) (tic_mem* memory);
|
void (*resume) (tic_mem* memory);
|
||||||
void (*sync) (tic_mem* memory, u32 mask, s32 bank, bool toCart);
|
void (*sync) (tic_mem* memory, u32 mask, s32 bank, bool toCart);
|
||||||
u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period);
|
u32 (*btnp) (tic_mem* memory, s32 id, s32 hold, s32 period);
|
||||||
u32 (*key) (tic_mem* memory, tic_key key);
|
bool (*key) (tic_mem* memory, tic_key key);
|
||||||
u32 (*keyp) (tic_mem* memory, tic_key key, s32 hold, s32 period);
|
bool (*keyp) (tic_mem* memory, tic_key key, s32 hold, s32 period);
|
||||||
|
|
||||||
void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette);
|
void (*load) (tic_cartridge* rom, const u8* buffer, s32 size, bool palette);
|
||||||
s32 (*save) (const tic_cartridge* rom, u8* buffer);
|
s32 (*save) (const tic_cartridge* rom, u8* buffer);
|
||||||
|
|||||||
Reference in New Issue
Block a user