From 023d2cb9a913ad5b291ed6a9f20386f87c31994b Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 21 Jun 2019 11:21:07 +0200 Subject: [PATCH] (Libretro) implement new environment callback RETRO_ENVIRONMENT_GET_INPUT_BITMASKS --- dynamic.c | 4 ++++ libretro-common/include/libretro.h | 16 +++++++++++++++- retroarch.c | 11 +++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/dynamic.c b/dynamic.c index 3fed3dce28..82c491d023 100644 --- a/dynamic.c +++ b/dynamic.c @@ -1842,6 +1842,10 @@ bool rarch_environment_cb(unsigned cmd, void *data) break; } + case RETRO_ENVIRONMENT_GET_INPUT_BITMASKS: + /* Just falldown, the function will return true */ + break; + case RETRO_ENVIRONMENT_GET_TARGET_REFRESH_RATE: { /* Try to use the polled refresh rate first. */ diff --git a/libretro-common/include/libretro.h b/libretro-common/include/libretro.h index a096eacef4..8daec83601 100644 --- a/libretro-common/include/libretro.h +++ b/libretro-common/include/libretro.h @@ -202,6 +202,8 @@ extern "C" { #define RETRO_DEVICE_ID_JOYPAD_L3 14 #define RETRO_DEVICE_ID_JOYPAD_R3 15 +#define RETRO_DEVICE_ID_JOYPAD_MASK 256 + /* Index / Id values for ANALOG device. */ #define RETRO_DEVICE_INDEX_ANALOG_LEFT 0 #define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1 @@ -1092,10 +1094,22 @@ enum retro_mod * refresh rate/framerate. */ +#define RETRO_ENVIRONMENT_GET_INPUT_BITMASKS (51 | RETRO_ENVIRONMENT_EXPERIMENTAL) + /* bool * -- + * Boolean value that indicates whether or not the frontend supports + * input bitmasks being returned by retro_input_state_t. The advantage + * of this is that retro_input_state_t has to be only called once to + * grab all button states instead of multiple times. + * + * If it returns true, you can pass RETRO_DEVICE_ID_JOYPAD_MASK as 'id' + * to retro_input_state_t (make sure 'device' is set to RETRO_DEVICE_JOYPAD). + * It will return a bitmask of all the digital buttons. + */ + /* VFS functionality */ /* File paths: - * File paths passed as parameters when using this api shall be well formed UNIX-style, + * File paths passed as parameters when using this API shall be well formed UNIX-style, * using "/" (unquoted forward slash) as directory separator regardless of the platform's native separator. * Paths shall also include at least one forward slash ("game.bin" is an invalid path, use "./game.bin" instead). * Other than the directory separator, cores shall not make assumptions about path format: diff --git a/retroarch.c b/retroarch.c index 9cc885d27b..9366ba9de8 100644 --- a/retroarch.c +++ b/retroarch.c @@ -2541,6 +2541,17 @@ int16_t input_state(unsigned port, unsigned device, is in action for that button*/ bool reset_state = false; + if ( (device == RETRO_DEVICE_JOYPAD) && + (id == RETRO_DEVICE_ID_JOYPAD_MASK)) + { + unsigned i; + + for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++) + if (input_state(port, device, idx, i)) + res |= (1 << i); + return res; + } + device &= RETRO_DEVICE_MASK; if (bsv_movie_get_input(&bsv_result))