keyboard input works

This commit is contained in:
BADIM-PC\Vadim
2018-01-24 16:13:46 +03:00
parent ce0aef409b
commit 29ab09efd0
6 changed files with 88 additions and 33 deletions
+20 -3
View File
@@ -1263,7 +1263,7 @@ static bool isNoiseWaveform(const tic_waveform* wave)
static bool isKeyPressed(const tic80_keyboard* input, tic_key key)
{
for(s32 i = 0; i < TIC_KEY_BUFFER; i++)
for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
if(input->keys[i] == key)
return true;
@@ -1689,7 +1689,7 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
return !prevDown && down;
}
for(s32 i = 0; i < TIC_KEY_BUFFER; i++)
for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
{
tic_key key = tic->ram.input.keyboard.keys[i];
@@ -1697,7 +1697,7 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
{
bool wasPressed = false;
for(s32 p = 0; p < TIC_KEY_BUFFER; p++)
for(s32 p = 0; p < TIC80_KEY_BUFFER; p++)
{
if(machine->state.keyboard.previous.keys[p] == key)
{
@@ -1714,7 +1714,23 @@ static bool api_keyp(tic_mem* tic, tic_key key, s32 hold, s32 period)
return false;
}
static char api_keytext(tic_mem* tic)
{
static const char Symbols[] = "abcdefghijklmnopqrstuvwxyz0123456789-=[]\\;'`,./ ";
static const char Shift[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ)!@#$%^&*(_+{}|:\"~<>? ";
enum{Count = sizeof Symbols, Hold = 20, Period = 3};
for(s32 i = 0; i < TIC80_KEY_BUFFER; i++)
{
tic_key key = tic->ram.input.keyboard.keys[i];
if(key > 0 && key < Count && tic->api.keyp(tic, key, Hold, Period))
return tic->api.key(tic, tic_key_shift) ? Shift[key-1] : Symbols[key-1];
}
return 0;
}
static void api_load(tic_cartridge* cart, const u8* buffer, s32 size, bool palette)
{
const u8* end = buffer + size;
@@ -1944,6 +1960,7 @@ static void initApi(tic_api* api)
INIT_API(btnp);
INIT_API(key);
INIT_API(keyp);
INIT_API(keytext);
INIT_API(load);
INIT_API(save);
INIT_API(tick_start);