diff --git a/driver.h b/driver.h index a14d9a743d..68e5976b37 100644 --- a/driver.h +++ b/driver.h @@ -39,6 +39,8 @@ #include "frontend/menu/backend/menu_backend.h" #include "frontend/menu/disp/menu_display.h" +#include "retro.h" + #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -428,10 +430,12 @@ typedef struct driver const video_driver_t *video; const input_driver_t *input; const input_osk_driver_t *osk; - void *osk_data; const camera_driver_t *camera; - void *camera_data; const location_driver_t *location; + struct retro_callbacks retro_ctx; + + void *osk_data; + void *camera_data; void *location_data; void *audio_data; void *video_data; diff --git a/frontend/menu/menu_common.c b/frontend/menu/menu_common.c index a820a76b87..0ed3a2a2a8 100644 --- a/frontend/menu/menu_common.c +++ b/frontend/menu/menu_common.c @@ -323,7 +323,8 @@ bool menu_iterate(retro_input_t input, return false; } - rarch_input_poll(); + driver.retro_ctx.poll_cb(); + input_state = menu_input(); if (driver.menu->do_held) diff --git a/general.h b/general.h index b3362c43dc..1265a9f70c 100644 --- a/general.h +++ b/general.h @@ -811,7 +811,6 @@ bool rarch_main_iterate(void); void rarch_main_deinit(void); void rarch_render_cached_frame(void); void rarch_deinit_msg_queue(void); -void rarch_input_poll(void); void rarch_check_block_hotkey(bool pressed); bool rarch_check_fullscreen(bool pressed); void rarch_disk_control_set_eject(bool state, bool log); diff --git a/libretro_version_1.c b/libretro_version_1.c index 06a1d2785e..254b3f1fd9 100644 --- a/libretro_version_1.c +++ b/libretro_version_1.c @@ -25,6 +25,7 @@ #include #include "general.h" #include "performance.h" +#include "input/keyboard_line.h" static void video_frame(const void *data, unsigned width, unsigned height, size_t pitch) @@ -227,6 +228,141 @@ static size_t audio_sample_batch_rewind(const int16_t *data, size_t frames) return frames; } +#ifdef HAVE_OVERLAY +static inline void input_poll_overlay(void) +{ + input_overlay_state_t old_key_state; + unsigned i, j, device; + uint16_t key_mod = 0; + bool polled = false; + + memcpy(old_key_state.keys, driver.overlay_state.keys, + sizeof(driver.overlay_state.keys)); + memset(&driver.overlay_state, 0, sizeof(driver.overlay_state)); + + device = input_overlay_full_screen(driver.overlay) ? + RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER; + + for (i = 0; + driver.input->input_state(driver.input_data, NULL, 0, device, i, + RETRO_DEVICE_ID_POINTER_PRESSED); + i++) + { + int16_t x = driver.input->input_state(driver.input_data, NULL, 0, + device, i, RETRO_DEVICE_ID_POINTER_X); + int16_t y = driver.input->input_state(driver.input_data, NULL, 0, + device, i, RETRO_DEVICE_ID_POINTER_Y); + + input_overlay_state_t polled_data; + input_overlay_poll(driver.overlay, &polled_data, x, y); + + driver.overlay_state.buttons |= polled_data.buttons; + + for (j = 0; j < ARRAY_SIZE(driver.overlay_state.keys); j++) + driver.overlay_state.keys[j] |= polled_data.keys[j]; + + /* Fingers pressed later take prio and matched up + * with overlay poll priorities. */ + for (j = 0; j < 4; j++) + if (polled_data.analog[j]) + driver.overlay_state.analog[j] = polled_data.analog[j]; + + polled = true; + } + + key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LSHIFT) || + OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RSHIFT)) ? + RETROKMOD_SHIFT : 0; + key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LCTRL) || + OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RCTRL)) ? + RETROKMOD_CTRL : 0; + key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LALT) || + OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RALT)) ? + RETROKMOD_ALT : 0; + key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LMETA) || + OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RMETA)) ? + RETROKMOD_META : 0; + + /* CAPSLOCK SCROLLOCK NUMLOCK */ + for (i = 0; i < ARRAY_SIZE(driver.overlay_state.keys); i++) + { + if (driver.overlay_state.keys[i] != old_key_state.keys[i]) + { + uint32_t orig_bits = old_key_state.keys[i]; + uint32_t new_bits = driver.overlay_state.keys[i]; + + for (j = 0; j < 32; j++) + if ((orig_bits & (1 << j)) != (new_bits & (1 << j))) + input_keyboard_event(new_bits & (1 << j), i * 32 + j, 0, key_mod); + } + } + + /* Map "analog" buttons to analog axes like regular input drivers do. */ + for (j = 0; j < 4; j++) + { + if (!driver.overlay_state.analog[j]) + { + unsigned bind_plus = RARCH_ANALOG_LEFT_X_PLUS + 2 * j; + unsigned bind_minus = bind_plus + 1; + driver.overlay_state.analog[j] += (driver.overlay_state.buttons & + (1ULL << bind_plus)) ? 0x7fff : 0; + driver.overlay_state.analog[j] -= (driver.overlay_state.buttons & + (1ULL << bind_minus)) ? 0x7fff : 0; + } + } + + /* Check for analog_dpad_mode. + * Map analogs to d-pad buttons when configured. */ + switch (g_settings.input.analog_dpad_mode[0]) + { + case ANALOG_DPAD_LSTICK: + case ANALOG_DPAD_RSTICK: + { + unsigned analog_base = g_settings.input.analog_dpad_mode[0] == + ANALOG_DPAD_LSTICK ? 0 : 2; + float analog_x = (float)driver.overlay_state.analog[analog_base + 0] / 0x7fff; + float analog_y = (float)driver.overlay_state.analog[analog_base + 1] / 0x7fff; + driver.overlay_state.buttons |= + (analog_x <= -g_settings.input.axis_threshold) ? + (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; + driver.overlay_state.buttons |= + (analog_x >= g_settings.input.axis_threshold) ? + (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; + driver.overlay_state.buttons |= + (analog_y <= -g_settings.input.axis_threshold) ? + (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; + driver.overlay_state.buttons |= + (analog_y >= g_settings.input.axis_threshold) ? + (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; + break; + } + + default: + break; + } + + if (polled) + input_overlay_post_poll(driver.overlay); + else + input_overlay_poll_clear(driver.overlay); +} +#endif + +static void input_poll(void) +{ + driver.input->poll(driver.input_data); + +#ifdef HAVE_OVERLAY + if (driver.overlay) + input_poll_overlay(); +#endif + +#ifdef HAVE_COMMAND + if (driver.command) + rarch_cmd_poll(driver.command); +#endif +} + void retro_set_default_callbacks(void *data) { struct retro_callbacks *cbs = (struct retro_callbacks*)data; @@ -238,6 +374,7 @@ void retro_set_default_callbacks(void *data) cbs->sample_cb = audio_sample; cbs->sample_batch_cb = audio_sample_batch; cbs->state_cb = input_state; + cbs->poll_cb = input_poll; } void retro_init_libretro_cbs(void *data) @@ -251,7 +388,7 @@ void retro_init_libretro_cbs(void *data) pretro_set_audio_sample(audio_sample); pretro_set_audio_sample_batch(audio_sample_batch); pretro_set_input_state(input_state); - pretro_set_input_poll(rarch_input_poll); + pretro_set_input_poll(input_poll); retro_set_default_callbacks(cbs); diff --git a/retro.h b/retro.h index e5e7eff43f..e16ed00a2e 100644 --- a/retro.h +++ b/retro.h @@ -15,8 +15,8 @@ * If not, see . */ -#ifndef _RETRO_IMPLEMENTATION_H -#define _RETRO_IMPLEMENTATION_H +#ifndef _RETRO_IMPLEMENTATION_V1_H +#define _RETRO_IMPLEMENTATION_V1_H #include "libretro.h" @@ -26,6 +26,7 @@ typedef struct retro_callbacks retro_audio_sample_t sample_cb; retro_audio_sample_batch_t sample_batch_cb; retro_input_state_t state_cb; + retro_input_poll_t poll_cb; } retro_callbacks_t; void retro_init_libretro_cbs(void *data); diff --git a/retroarch.c b/retroarch.c index 58f2415d2f..c5e35cd83f 100644 --- a/retroarch.c +++ b/retroarch.c @@ -58,8 +58,6 @@ #include "msvc/msvc_compat.h" #endif -struct retro_callbacks retro_ctx; - /* To avoid continous switching if we hold the button down, we require * that the button must go from pressed to unpressed back to pressed * to be able to toggle between then. @@ -446,8 +444,8 @@ void rarch_render_cached_frame(void) * freed the memory, but no known implementations do this. * It would be really stupid at any rate ... */ - if (retro_ctx.frame_cb) - retro_ctx.frame_cb(frame, + if (driver.retro_ctx.frame_cb) + driver.retro_ctx.frame_cb(frame, g_extern.frame_cache.width, g_extern.frame_cache.height, g_extern.frame_cache.pitch); @@ -540,141 +538,6 @@ bool rarch_audio_flush(const int16_t *data, size_t samples) return true; } -#ifdef HAVE_OVERLAY -static inline void input_poll_overlay(void) -{ - input_overlay_state_t old_key_state; - unsigned i, j, device; - uint16_t key_mod = 0; - bool polled = false; - - memcpy(old_key_state.keys, driver.overlay_state.keys, - sizeof(driver.overlay_state.keys)); - memset(&driver.overlay_state, 0, sizeof(driver.overlay_state)); - - device = input_overlay_full_screen(driver.overlay) ? - RARCH_DEVICE_POINTER_SCREEN : RETRO_DEVICE_POINTER; - - for (i = 0; - driver.input->input_state(driver.input_data, NULL, 0, device, i, - RETRO_DEVICE_ID_POINTER_PRESSED); - i++) - { - int16_t x = driver.input->input_state(driver.input_data, NULL, 0, - device, i, RETRO_DEVICE_ID_POINTER_X); - int16_t y = driver.input->input_state(driver.input_data, NULL, 0, - device, i, RETRO_DEVICE_ID_POINTER_Y); - - input_overlay_state_t polled_data; - input_overlay_poll(driver.overlay, &polled_data, x, y); - - driver.overlay_state.buttons |= polled_data.buttons; - - for (j = 0; j < ARRAY_SIZE(driver.overlay_state.keys); j++) - driver.overlay_state.keys[j] |= polled_data.keys[j]; - - /* Fingers pressed later take prio and matched up - * with overlay poll priorities. */ - for (j = 0; j < 4; j++) - if (polled_data.analog[j]) - driver.overlay_state.analog[j] = polled_data.analog[j]; - - polled = true; - } - - key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LSHIFT) || - OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RSHIFT)) ? - RETROKMOD_SHIFT : 0; - key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LCTRL) || - OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RCTRL)) ? - RETROKMOD_CTRL : 0; - key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LALT) || - OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RALT)) ? - RETROKMOD_ALT : 0; - key_mod |= (OVERLAY_GET_KEY(&driver.overlay_state, RETROK_LMETA) || - OVERLAY_GET_KEY(&driver.overlay_state, RETROK_RMETA)) ? - RETROKMOD_META : 0; - - /* CAPSLOCK SCROLLOCK NUMLOCK */ - for (i = 0; i < ARRAY_SIZE(driver.overlay_state.keys); i++) - { - if (driver.overlay_state.keys[i] != old_key_state.keys[i]) - { - uint32_t orig_bits = old_key_state.keys[i]; - uint32_t new_bits = driver.overlay_state.keys[i]; - - for (j = 0; j < 32; j++) - if ((orig_bits & (1 << j)) != (new_bits & (1 << j))) - input_keyboard_event(new_bits & (1 << j), i * 32 + j, 0, key_mod); - } - } - - /* Map "analog" buttons to analog axes like regular input drivers do. */ - for (j = 0; j < 4; j++) - { - if (!driver.overlay_state.analog[j]) - { - unsigned bind_plus = RARCH_ANALOG_LEFT_X_PLUS + 2 * j; - unsigned bind_minus = bind_plus + 1; - driver.overlay_state.analog[j] += (driver.overlay_state.buttons & - (1ULL << bind_plus)) ? 0x7fff : 0; - driver.overlay_state.analog[j] -= (driver.overlay_state.buttons & - (1ULL << bind_minus)) ? 0x7fff : 0; - } - } - - /* Check for analog_dpad_mode. - * Map analogs to d-pad buttons when configured. */ - switch (g_settings.input.analog_dpad_mode[0]) - { - case ANALOG_DPAD_LSTICK: - case ANALOG_DPAD_RSTICK: - { - unsigned analog_base = g_settings.input.analog_dpad_mode[0] == - ANALOG_DPAD_LSTICK ? 0 : 2; - float analog_x = (float)driver.overlay_state.analog[analog_base + 0] / 0x7fff; - float analog_y = (float)driver.overlay_state.analog[analog_base + 1] / 0x7fff; - driver.overlay_state.buttons |= - (analog_x <= -g_settings.input.axis_threshold) ? - (1ULL << RETRO_DEVICE_ID_JOYPAD_LEFT) : 0; - driver.overlay_state.buttons |= - (analog_x >= g_settings.input.axis_threshold) ? - (1ULL << RETRO_DEVICE_ID_JOYPAD_RIGHT) : 0; - driver.overlay_state.buttons |= - (analog_y <= -g_settings.input.axis_threshold) ? - (1ULL << RETRO_DEVICE_ID_JOYPAD_UP) : 0; - driver.overlay_state.buttons |= - (analog_y >= g_settings.input.axis_threshold) ? - (1ULL << RETRO_DEVICE_ID_JOYPAD_DOWN) : 0; - break; - } - - default: - break; - } - - if (polled) - input_overlay_post_poll(driver.overlay); - else - input_overlay_poll_clear(driver.overlay); -} -#endif - -void rarch_input_poll(void) -{ - driver.input->poll(driver.input_data); - -#ifdef HAVE_OVERLAY - if (driver.overlay) - input_poll_overlay(); -#endif - -#ifdef HAVE_COMMAND - if (driver.command) - rarch_cmd_poll(driver.command); -#endif -} - #if !defined(_WIN32) && !defined(GLOBAL_CONFIG_DIR) #if defined(__HAIKU__) #define GLOBAL_CONFIG_DIR "/system/settings" @@ -2858,7 +2721,7 @@ int rarch_main_init(int argc, char *argv[]) #endif } - retro_init_libretro_cbs(&retro_ctx); + retro_init_libretro_cbs(&driver.retro_ctx); init_system_av_info(); init_drivers(); @@ -3003,7 +2866,7 @@ void rarch_main_set_state(unsigned cmd) rarch_main_set_state(RARCH_ACTION_STATE_QUIT); break; case RARCH_ACTION_STATE_FLUSH_INPUT: - rarch_input_poll(); + driver.retro_ctx.poll_cb(); #ifdef HAVE_MENU menu_input(); #endif @@ -3405,7 +3268,7 @@ bool rarch_main_iterate(void) if (!do_state_checks(input, old_input, trigger_input)) { - rarch_input_poll(); + driver.retro_ctx.poll_cb(); rarch_sleep(10); return true; }