diff --git a/Makefile.emscripten b/Makefile.emscripten index a6d976ce5f..119d1671e1 100644 --- a/Makefile.emscripten +++ b/Makefile.emscripten @@ -60,7 +60,7 @@ WANT_MINIZ = 1 MEMORY = 67108864 LTO = 0 # XXX: setting this to 1/2 currently crashes Firefox nightly -PRECISE_F32 = 0 +PRECISE_F32 = 2 ifneq ($(NATIVE_ZLIB),) WANT_MINIZ = 0 diff --git a/emscripten/RWebInput.h b/emscripten/RWebInput.h index 437d3f9e63..cc7dad1945 100644 --- a/emscripten/RWebInput.h +++ b/emscripten/RWebInput.h @@ -17,7 +17,7 @@ typedef struct rwebinput_state { - char keys[32]; + uint8_t keys[32]; int mouse_x; int mouse_y; char mouse_l; diff --git a/emscripten/library_rwebinput.js b/emscripten/library_rwebinput.js index 7f45a747d8..7b02bbd834 100644 --- a/emscripten/library_rwebinput.js +++ b/emscripten/library_rwebinput.js @@ -58,7 +58,7 @@ var LibraryRWebInput = { } }, - RWebInputInit: function(latency) { + RWebInputInit: function() { if (RI.contexts.length === 0) { document.addEventListener('keyup', RI.eventHandler, false); document.addEventListener('keydown', RI.eventHandler, false); diff --git a/input/input_common.c b/input/input_common.c index 3e58a92422..c723f0d5bd 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -662,6 +662,22 @@ const struct rarch_key_map rarch_key_map_rwebinput[] = { { 88, RETROK_x }, { 89, RETROK_y }, { 90, RETROK_z }, + { 222, RETROK_QUOTE }, + { 188, RETROK_COMMA }, + { 173, RETROK_MINUS }, + { 191, RETROK_SLASH }, + { 59, RETROK_SEMICOLON }, + { 61, RETROK_EQUALS }, + { 219, RETROK_LEFTBRACKET }, + { 220, RETROK_BACKSLASH }, + { 221, RETROK_RIGHTBRACKET }, + { 188, RETROK_KP_PERIOD }, + { 17, RETROK_RCTRL }, + { 18, RETROK_RALT }, + { 190, RETROK_PERIOD }, + { 145, RETROK_SCROLLOCK }, + { 20, RETROK_CAPSLOCK }, + { 144, RETROK_NUMLOCK }, { 0, RETROK_UNKNOWN }, }; #endif diff --git a/input/rwebinput_input.c b/input/rwebinput_input.c index ce50c9f29c..5cfaa5c781 100644 --- a/input/rwebinput_input.c +++ b/input/rwebinput_input.c @@ -19,6 +19,7 @@ #include "../boolean.h" #include "../general.h" +#include "keyboard_line.h" #include "../emscripten/RWebInput.h" @@ -92,6 +93,17 @@ static int16_t rwebinput_mouse_state(rwebinput_input_t *rwebinput, unsigned id) } } +static int16_t rwebinput_analog_pressed(rwebinput_input_t *rwebinput, const struct retro_keybind *binds, unsigned index, unsigned id) +{ + unsigned id_minus = 0; + unsigned id_plus = 0; + input_conv_analog_id_to_bind_id(index, id, &id_minus, &id_plus); + + int16_t pressed_minus = rwebinput_is_pressed(rwebinput, binds, id_minus) ? -0x7fff : 0; + int16_t pressed_plus = rwebinput_is_pressed(rwebinput, binds, id_plus) ? 0x7fff : 0; + return pressed_plus + pressed_minus; +} + static int16_t rwebinput_input_state(void *data, const struct retro_keybind **binds, unsigned port, unsigned device, unsigned index, unsigned id) { rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; @@ -101,6 +113,9 @@ static int16_t rwebinput_input_state(void *data, const struct retro_keybind **bi case RETRO_DEVICE_JOYPAD: return rwebinput_is_pressed(rwebinput, binds[port], id); + case RETRO_DEVICE_ANALOG: + return rwebinput_analog_pressed(rwebinput, binds[port], index, id); + case RETRO_DEVICE_KEYBOARD: return rwebinput_key_pressed(rwebinput, id); @@ -127,6 +142,23 @@ static void rwebinput_input_poll(void *data) rwebinput_input_t *rwebinput = (rwebinput_input_t*)data; rwebinput_state_t *state = RWebInputPoll(rwebinput->context); + + // get new keys + for (unsigned i = 0; i < 32; i++) + { + if (state->keys[i] != rwebinput->state.keys[i]) + { + uint8_t diff = state->keys[i] ^ rwebinput->state.keys[i]; + for (unsigned k = 0; diff; diff >>= 1, k++) + { + if (diff & 1) + { + input_keyboard_event((state->keys[i] & (1 << k)) != 0, input_translate_keysym_to_rk(i * 8 + k), 0, 0); + } + } + } + } + memcpy(&rwebinput->state, state, sizeof(rwebinput->state)); } @@ -141,6 +173,7 @@ static uint64_t rwebinput_get_capabilities(void *data) uint64_t caps = 0; caps |= (1 << RETRO_DEVICE_JOYPAD); + caps |= (1 << RETRO_DEVICE_ANALOG); caps |= (1 << RETRO_DEVICE_KEYBOARD); caps |= (1 << RETRO_DEVICE_MOUSE);