no message

This commit is contained in:
BADIM-PC\Vadim 2017-12-29 18:22:21 +03:00
parent ca0a7c7167
commit 7e9cf5648f
3 changed files with 26 additions and 31 deletions

View File

@ -787,27 +787,24 @@ static s32 lua_key(lua_State* lua)
s32 top = lua_gettop(lua);
tic80_input* input = &tic->ram.input;
enum{Count = COUNT_OF(input->keyboard.keys)};
if (top == 0)
{
lua_pushboolean(lua, tic->api.key(tic, tic_key_unknown));
return 1;
lua_pushinteger(lua, tic->api.key(tic, tic_key_unknown));
}
else if (top == 1)
{
tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX;
lua_pushboolean(lua, tic->api.key(tic, key));
}
else
{
luaL_error(lua, "invalid params, key [code]\n");
return 0;
}
return 1;
}
else luaL_error(lua, "invalid params, key [code]\n");
return 0;
}
static s32 lua_keyp(lua_State* lua)
{
@ -818,11 +815,11 @@ static s32 lua_keyp(lua_State* lua)
if (top == 0)
{
lua_pushboolean(lua, tic->api.keyp(tic, tic_key_unknown, -1, -1));
lua_pushinteger(lua, tic->api.keyp(tic, tic_key_unknown, -1, -1));
}
else if(top == 1)
{
tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX;;
tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX;
lua_pushboolean(lua, tic->api.keyp(tic, key, -1, -1));
}

View File

@ -1648,19 +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 bool api_key(tic_mem* tic, tic_key key)
static u32 api_key(tic_mem* tic, tic_key key)
{
if(key >= TIC_KEY_START_INDEX)
return isKeyPressed(&tic->ram.input.keyboard, key);
for(s32 i = 0; i < TIC_KEY_BUFFER; i++)
if(isKeyPressed(&tic->ram.input.keyboard, i))
return true;
return false;
return key >= TIC_KEY_START_INDEX
? isKeyPressed(&tic->ram.input.keyboard, key)
: tic->ram.input.keyboard.data;
}
static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
static u32 api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
{
tic_machine* machine = (tic_machine*)tic;
@ -1677,6 +1672,8 @@ static bool 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];
@ -1684,6 +1681,7 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
if(key)
{
bool wasPressed = false;
for(s32 p = 0; p < TIC_KEY_BUFFER; p++)
{
if(machine->state.keyboard.previous.keys[p] == key)
@ -1694,11 +1692,11 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
}
if(!wasPressed)
return true;
prev.keys[i] = key;
}
}
return false;
return prev.data;
}

View File

@ -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);
bool (*key) (tic_mem* memory, tic_key key);
bool (*keyp) (tic_mem* memory, tic_key key, s32 hold, s32 period);
u32 (*key) (tic_mem* memory, tic_key key);
u32 (*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);