diff --git a/src/jsapi.c b/src/jsapi.c index 45cf382..7fb6907 100644 --- a/src/jsapi.c +++ b/src/jsapi.c @@ -246,9 +246,9 @@ static s32 duk_key(duk_context* duk) } 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)); else { @@ -271,9 +271,9 @@ static s32 duk_keyp(duk_context* duk) } 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"); return 0; diff --git a/src/keycodes.c b/src/keycodes.c index 1cbd04d..52bb3ac 100644 --- a/src/keycodes.c +++ b/src/keycodes.c @@ -39,7 +39,7 @@ [SDL_SCANCODE_9] = tic_key_9, [SDL_SCANCODE_0] = tic_key_0, [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_TAB] = tic_key_tab, [SDL_SCANCODE_SPACE] = tic_key_space, @@ -56,18 +56,18 @@ [SDL_SCANCODE_PERIOD] = tic_key_period, [SDL_SCANCODE_SLASH] = tic_key_slash, [SDL_SCANCODE_CAPSLOCK] = tic_key_capslock, -[SDL_SCANCODE_F1] = tic_key_f1, -[SDL_SCANCODE_F2] = tic_key_f2, -[SDL_SCANCODE_F3] = tic_key_f3, -[SDL_SCANCODE_F4] = tic_key_f4, -[SDL_SCANCODE_F5] = tic_key_f5, -[SDL_SCANCODE_F6] = tic_key_f6, -[SDL_SCANCODE_F7] = tic_key_f7, -[SDL_SCANCODE_F8] = tic_key_f8, -[SDL_SCANCODE_F9] = tic_key_f9, -[SDL_SCANCODE_F10] = tic_key_f10, -[SDL_SCANCODE_F11] = tic_key_f11, -[SDL_SCANCODE_F12] = tic_key_f12, +[SDL_SCANCODE_F1] = tic_key_unknown, +[SDL_SCANCODE_F2] = tic_key_unknown, +[SDL_SCANCODE_F3] = tic_key_unknown, +[SDL_SCANCODE_F4] = tic_key_unknown, +[SDL_SCANCODE_F5] = tic_key_unknown, +[SDL_SCANCODE_F6] = tic_key_unknown, +[SDL_SCANCODE_F7] = tic_key_unknown, +[SDL_SCANCODE_F8] = tic_key_unknown, +[SDL_SCANCODE_F9] = tic_key_unknown, +[SDL_SCANCODE_F10] = tic_key_unknown, +[SDL_SCANCODE_F11] = tic_key_unknown, +[SDL_SCANCODE_F12] = tic_key_unknown, [70] = tic_key_unknown, [71] = tic_key_unknown, [72] = tic_key_unknown, @@ -225,7 +225,8 @@ [SDL_SCANCODE_LCTRL] = tic_key_ctrl, [SDL_SCANCODE_LSHIFT] = tic_key_shift, [SDL_SCANCODE_LALT] = tic_key_alt, -[227] = tic_key_unknown, +[SDL_SCANCODE_RGUI] = tic_key_ctrl, [SDL_SCANCODE_RCTRL] = tic_key_ctrl, [SDL_SCANCODE_RSHIFT] = tic_key_shift, [SDL_SCANCODE_RALT] = tic_key_alt, +[SDL_SCANCODE_RGUI] = tic_key_ctrl, diff --git a/src/luaapi.c b/src/luaapi.c index 0184c69..9b77edf 100644 --- a/src/luaapi.c +++ b/src/luaapi.c @@ -793,9 +793,9 @@ static s32 lua_key(lua_State* lua) } 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)); else { @@ -825,9 +825,9 @@ static s32 lua_keyp(lua_State* lua) } 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"); } diff --git a/src/machine.h b/src/machine.h index bdb8dca..d938718 100644 --- a/src/machine.h +++ b/src/machine.h @@ -73,7 +73,7 @@ typedef struct { tic80_keyboard previous; - u32 holds[TIC_KEYS_COUNT]; + u32 holds[tic_keys_count]; } keyboard; Clip clip; diff --git a/src/tic.c b/src/tic.c index 3489013..90afc57 100644 --- a/src/tic.c +++ b/src/tic.c @@ -1286,7 +1286,7 @@ static void api_tick_start(tic_mem* memory, const tic_sfx* sfxsrc, const tic_mus } // 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 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) { - return key >= TIC_KEY_START_INDEX + return key > tic_key_unknown ? isKeyPressed(&tic->ram.input.keyboard, key) : 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; - if(key >= TIC_KEY_START_INDEX) + if(key > tic_key_unknown) { bool prevDown = hold >= 0 && period >= 0 && machine->state.keyboard.holds[key] >= hold ? period && machine->state.keyboard.holds[key] % period diff --git a/src/tic.h b/src/tic.h index fcded04..5823d8b 100644 --- a/src/tic.h +++ b/src/tic.h @@ -420,10 +420,6 @@ typedef union enum { tic_key_unknown, - tic_key_up, - tic_key_down, - tic_key_left, - tic_key_right, tic_key_a, tic_key_b, tic_key_c, @@ -495,14 +491,15 @@ enum tic_key_delete, tic_key_end, tic_key_pagedown, + tic_key_right, + tic_key_left, + tic_key_down, + tic_key_up, tic_key_ctrl, tic_key_shift, tic_key_alt, //////////////// - tic_last_key + tic_keys_count }; - -#define TIC_KEY_START_INDEX (tic_key_up) -#define TIC_KEYS_COUNT (tic_last_key)