Don't use ESC and F1-F12 buttons in keyboard input #492

This commit is contained in:
BADIM-PC\Vadim 2018-01-03 15:52:12 +03:00
parent 1e09c653ec
commit 1f7823ea6e
6 changed files with 32 additions and 34 deletions

View File

@ -246,9 +246,9 @@ static s32 duk_key(duk_context* duk)
} }
else else
{ {
tic_key key = duk_to_int(duk, 0) + TIC_KEY_START_INDEX; tic_key key = duk_to_int(duk, 0);
if(key < TIC_KEYS_COUNT) if(key < tic_keys_count)
duk_push_boolean(duk, tic->api.key(tic, key)); duk_push_boolean(duk, tic->api.key(tic, key));
else else
{ {
@ -271,9 +271,9 @@ static s32 duk_keyp(duk_context* duk)
} }
else else
{ {
tic_key key = duk_to_int(duk, 0) + TIC_KEY_START_INDEX; tic_key key = duk_to_int(duk, 0);
if(key >= TIC_KEYS_COUNT) if(key >= tic_keys_count)
{ {
duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n"); duk_error(duk, DUK_ERR_ERROR, "unknown keyboard code\n");
return 0; return 0;

View File

@ -39,7 +39,7 @@
[SDL_SCANCODE_9] = tic_key_9, [SDL_SCANCODE_9] = tic_key_9,
[SDL_SCANCODE_0] = tic_key_0, [SDL_SCANCODE_0] = tic_key_0,
[SDL_SCANCODE_RETURN] = tic_key_return, [SDL_SCANCODE_RETURN] = tic_key_return,
[SDL_SCANCODE_ESCAPE] = tic_key_escape, [SDL_SCANCODE_ESCAPE] = tic_key_unknown,
[SDL_SCANCODE_BACKSPACE] = tic_key_backspace, [SDL_SCANCODE_BACKSPACE] = tic_key_backspace,
[SDL_SCANCODE_TAB] = tic_key_tab, [SDL_SCANCODE_TAB] = tic_key_tab,
[SDL_SCANCODE_SPACE] = tic_key_space, [SDL_SCANCODE_SPACE] = tic_key_space,
@ -56,18 +56,18 @@
[SDL_SCANCODE_PERIOD] = tic_key_period, [SDL_SCANCODE_PERIOD] = tic_key_period,
[SDL_SCANCODE_SLASH] = tic_key_slash, [SDL_SCANCODE_SLASH] = tic_key_slash,
[SDL_SCANCODE_CAPSLOCK] = tic_key_capslock, [SDL_SCANCODE_CAPSLOCK] = tic_key_capslock,
[SDL_SCANCODE_F1] = tic_key_f1, [SDL_SCANCODE_F1] = tic_key_unknown,
[SDL_SCANCODE_F2] = tic_key_f2, [SDL_SCANCODE_F2] = tic_key_unknown,
[SDL_SCANCODE_F3] = tic_key_f3, [SDL_SCANCODE_F3] = tic_key_unknown,
[SDL_SCANCODE_F4] = tic_key_f4, [SDL_SCANCODE_F4] = tic_key_unknown,
[SDL_SCANCODE_F5] = tic_key_f5, [SDL_SCANCODE_F5] = tic_key_unknown,
[SDL_SCANCODE_F6] = tic_key_f6, [SDL_SCANCODE_F6] = tic_key_unknown,
[SDL_SCANCODE_F7] = tic_key_f7, [SDL_SCANCODE_F7] = tic_key_unknown,
[SDL_SCANCODE_F8] = tic_key_f8, [SDL_SCANCODE_F8] = tic_key_unknown,
[SDL_SCANCODE_F9] = tic_key_f9, [SDL_SCANCODE_F9] = tic_key_unknown,
[SDL_SCANCODE_F10] = tic_key_f10, [SDL_SCANCODE_F10] = tic_key_unknown,
[SDL_SCANCODE_F11] = tic_key_f11, [SDL_SCANCODE_F11] = tic_key_unknown,
[SDL_SCANCODE_F12] = tic_key_f12, [SDL_SCANCODE_F12] = tic_key_unknown,
[70] = tic_key_unknown, [70] = tic_key_unknown,
[71] = tic_key_unknown, [71] = tic_key_unknown,
[72] = tic_key_unknown, [72] = tic_key_unknown,
@ -225,7 +225,8 @@
[SDL_SCANCODE_LCTRL] = tic_key_ctrl, [SDL_SCANCODE_LCTRL] = tic_key_ctrl,
[SDL_SCANCODE_LSHIFT] = tic_key_shift, [SDL_SCANCODE_LSHIFT] = tic_key_shift,
[SDL_SCANCODE_LALT] = tic_key_alt, [SDL_SCANCODE_LALT] = tic_key_alt,
[227] = tic_key_unknown, [SDL_SCANCODE_RGUI] = tic_key_ctrl,
[SDL_SCANCODE_RCTRL] = tic_key_ctrl, [SDL_SCANCODE_RCTRL] = tic_key_ctrl,
[SDL_SCANCODE_RSHIFT] = tic_key_shift, [SDL_SCANCODE_RSHIFT] = tic_key_shift,
[SDL_SCANCODE_RALT] = tic_key_alt, [SDL_SCANCODE_RALT] = tic_key_alt,
[SDL_SCANCODE_RGUI] = tic_key_ctrl,

View File

@ -793,9 +793,9 @@ static s32 lua_key(lua_State* lua)
} }
else if (top == 1) else if (top == 1)
{ {
tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX; tic_key key = getLuaNumber(lua, 1);
if(key < TIC_KEYS_COUNT) if(key < tic_keys_count)
lua_pushboolean(lua, tic->api.key(tic, key)); lua_pushboolean(lua, tic->api.key(tic, key));
else else
{ {
@ -825,9 +825,9 @@ static s32 lua_keyp(lua_State* lua)
} }
else else
{ {
tic_key key = getLuaNumber(lua, 1) + TIC_KEY_START_INDEX; tic_key key = getLuaNumber(lua, 1);
if(key >= TIC_KEYS_COUNT) if(key >= tic_keys_count)
{ {
luaL_error(lua, "unknown keyboard code\n"); luaL_error(lua, "unknown keyboard code\n");
} }

View File

@ -73,7 +73,7 @@ typedef struct
{ {
tic80_keyboard previous; tic80_keyboard previous;
u32 holds[TIC_KEYS_COUNT]; u32 holds[tic_keys_count];
} keyboard; } keyboard;
Clip clip; Clip clip;

View File

@ -1286,7 +1286,7 @@ static void api_tick_start(tic_mem* memory, const tic_sfx* sfxsrc, const tic_mus
} }
// process keyboard // process keyboard
for(s32 i = TIC_KEY_START_INDEX; i < TIC_KEYS_COUNT; i++) for(s32 i = 0; i < tic_keys_count; i++)
{ {
bool prevDown = isKeyPressed(&machine->state.keyboard.previous, i); bool prevDown = isKeyPressed(&machine->state.keyboard.previous, i);
bool down = isKeyPressed(&memory->ram.input.keyboard, i); bool down = isKeyPressed(&memory->ram.input.keyboard, i);
@ -1650,7 +1650,7 @@ static u32 api_btnp(tic_mem* tic, s32 index, s32 hold, s32 period)
static bool 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_unknown
? isKeyPressed(&tic->ram.input.keyboard, key) ? isKeyPressed(&tic->ram.input.keyboard, key)
: tic->ram.input.keyboard.data; : tic->ram.input.keyboard.data;
} }
@ -1659,7 +1659,7 @@ 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;
if(key >= TIC_KEY_START_INDEX) if(key > tic_key_unknown)
{ {
bool prevDown = hold >= 0 && period >= 0 && machine->state.keyboard.holds[key] >= hold bool prevDown = hold >= 0 && period >= 0 && machine->state.keyboard.holds[key] >= hold
? period && machine->state.keyboard.holds[key] % period ? period && machine->state.keyboard.holds[key] % period

View File

@ -420,10 +420,6 @@ typedef union
enum enum
{ {
tic_key_unknown, tic_key_unknown,
tic_key_up,
tic_key_down,
tic_key_left,
tic_key_right,
tic_key_a, tic_key_a,
tic_key_b, tic_key_b,
tic_key_c, tic_key_c,
@ -495,14 +491,15 @@ enum
tic_key_delete, tic_key_delete,
tic_key_end, tic_key_end,
tic_key_pagedown, tic_key_pagedown,
tic_key_right,
tic_key_left,
tic_key_down,
tic_key_up,
tic_key_ctrl, tic_key_ctrl,
tic_key_shift, tic_key_shift,
tic_key_alt, tic_key_alt,
//////////////// ////////////////
tic_last_key tic_keys_count
}; };
#define TIC_KEY_START_INDEX (tic_key_up)
#define TIC_KEYS_COUNT (tic_last_key)