From 4676e102d03e3849b8a0fc728a590e1ed1550b36 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Mon, 3 Aug 2020 17:31:22 +0200 Subject: [PATCH] (input/drivers_joypad) Add TODO/FIXME notes --- input/drivers_joypad/ctr_joypad.c | 3 ++ input/drivers_joypad/dinput_hybrid_joypad.c | 2 +- input/drivers_joypad/dinput_joypad.c | 2 +- input/drivers_joypad/dos_joypad.c | 2 +- input/drivers_joypad/gx_joypad.c | 17 +++++---- input/drivers_joypad/hid_joypad.c | 4 +- input/drivers_joypad/linuxraw_joypad.c | 1 + input/drivers_joypad/mfi_joypad.m | 13 +++---- input/drivers_joypad/parport_joypad.c | 1 + input/drivers_joypad/ps2_joypad.c | 2 +- input/drivers_joypad/ps3_joypad.c | 1 + input/drivers_joypad/ps4_joypad.c | 9 +++-- input/drivers_joypad/psp_joypad.c | 4 ++ input/drivers_joypad/rwebpad_joypad.c | 42 +++++++-------------- input/drivers_joypad/sdl_joypad.c | 40 ++++++++++++-------- input/drivers_joypad/switch_joypad.c | 1 + input/drivers_joypad/udev_joypad.c | 1 + input/drivers_joypad/xdk_joypad.c | 1 + input/drivers_joypad/xinput_hybrid_joypad.c | 35 ++++++++--------- input/drivers_joypad/xinput_joypad.c | 29 +++++++------- 20 files changed, 105 insertions(+), 105 deletions(-) diff --git a/input/drivers_joypad/ctr_joypad.c b/input/drivers_joypad/ctr_joypad.c index 76a33b11e3..e86df5161d 100644 --- a/input/drivers_joypad/ctr_joypad.c +++ b/input/drivers_joypad/ctr_joypad.c @@ -28,8 +28,11 @@ #include "string.h" #include "3ds.h" +/* TODO/FIXME - static globals */ static uint32_t pad_state; static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; + +/* TODO/FIXME - global referenced outside */ extern uint64_t lifecycle_state; static const char *ctr_joypad_name(unsigned pad) diff --git a/input/drivers_joypad/dinput_hybrid_joypad.c b/input/drivers_joypad/dinput_hybrid_joypad.c index 265bcecf3c..4d684c8561 100644 --- a/input/drivers_joypad/dinput_hybrid_joypad.c +++ b/input/drivers_joypad/dinput_hybrid_joypad.c @@ -39,7 +39,7 @@ #include "../../verbosity.h" #include "dinput_joypad.h" -/* TODO/FIXME - globals */ +/* TODO/FIXME - globals referenced outside */ struct dinput_joypad_data g_pads[MAX_USERS]; unsigned g_joypad_cnt; diff --git a/input/drivers_joypad/dinput_joypad.c b/input/drivers_joypad/dinput_joypad.c index 804ea3c7ff..353cf43f48 100644 --- a/input/drivers_joypad/dinput_joypad.c +++ b/input/drivers_joypad/dinput_joypad.c @@ -36,7 +36,7 @@ #include "../../verbosity.h" #include "dinput_joypad.h" -/* TODO/FIXME - globals */ +/* TODO/FIXME - globals referenced outside */ struct dinput_joypad_data g_pads[MAX_USERS]; unsigned g_joypad_cnt; diff --git a/input/drivers_joypad/dos_joypad.c b/input/drivers_joypad/dos_joypad.c index bf1f2dea4d..3a5e07b185 100644 --- a/input/drivers_joypad/dos_joypad.c +++ b/input/drivers_joypad/dos_joypad.c @@ -38,8 +38,8 @@ #define LOCK_VAR(x) LockData((void*)&x, sizeof(x)) #define LOCK_FUNC(x) LockCode(x, (int)x##_End - (int)x) +/* TODO/FIXME - static globals */ static uint16_t normal_keys[LAST_KEYCODE + 1]; - static _go32_dpmi_seginfo old_kbd_int; static _go32_dpmi_seginfo kbd_int; diff --git a/input/drivers_joypad/gx_joypad.c b/input/drivers_joypad/gx_joypad.c index a0a5bd164c..e2f4dbc7bf 100644 --- a/input/drivers_joypad/gx_joypad.c +++ b/input/drivers_joypad/gx_joypad.c @@ -61,6 +61,7 @@ struct gx_mousedata bool valid; }; +/* TODO/FIXME - static global */ static struct gx_mousedata gx_mouse[2]; #endif @@ -119,14 +120,14 @@ enum #define GC_JOYSTICK_THRESHOLD (48 * 256) #define WII_JOYSTICK_THRESHOLD (40 * 256) +/* TODO/FIXME - global referenced outside */ extern uint64_t lifecycle_state; + +/* TODO/FIXME - static globals */ static uint64_t pad_state[DEFAULT_MAX_PADS]; static uint32_t pad_type[DEFAULT_MAX_PADS] = { WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER, WPAD_EXP_NOCONTROLLER }; static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; static bool g_menu = false; - -static bool gx_joypad_query_pad(unsigned pad); - #ifdef HW_RVL static bool g_quit = false; @@ -435,6 +436,11 @@ static int16_t WPAD_StickY(WPADData *data, u8 right) } #endif +static bool gx_joypad_query_pad(unsigned pad) +{ + return pad < MAX_USERS && pad_type[pad] != WPAD_EXP_NOCONTROLLER; +} + static void gx_joypad_poll(void) { unsigned i, j, port; @@ -637,11 +643,6 @@ static bool gx_joypad_init(void *data) return true; } -static bool gx_joypad_query_pad(unsigned pad) -{ - return pad < MAX_USERS && pad_type[pad] != WPAD_EXP_NOCONTROLLER; -} - static void gx_joypad_destroy(void) { #ifdef HW_RVL diff --git a/input/drivers_joypad/hid_joypad.c b/input/drivers_joypad/hid_joypad.c index 9d7f2073e6..810d654acf 100644 --- a/input/drivers_joypad/hid_joypad.c +++ b/input/drivers_joypad/hid_joypad.c @@ -17,6 +17,7 @@ #include "../../tasks/tasks_internal.h" #include "../input_driver.h" +/* TODO/FIXME - static global */ static const hid_driver_t *generic_hid = NULL; static bool hid_joypad_init(void *data) @@ -24,9 +25,6 @@ static bool hid_joypad_init(void *data) generic_hid = input_hid_init_first(); if (!generic_hid) return false; - - (void)data; - return true; } diff --git a/input/drivers_joypad/linuxraw_joypad.c b/input/drivers_joypad/linuxraw_joypad.c index 26b8b8dfcf..56f2e99a4f 100644 --- a/input/drivers_joypad/linuxraw_joypad.c +++ b/input/drivers_joypad/linuxraw_joypad.c @@ -48,6 +48,7 @@ struct linuxraw_joypad char *ident; }; +/* TODO/FIXME - static globals */ static struct linuxraw_joypad linuxraw_pads[MAX_USERS]; static int linuxraw_epoll = 0; static int linuxraw_inotify = 0; diff --git a/input/drivers_joypad/mfi_joypad.m b/input/drivers_joypad/mfi_joypad.m index 17ce29127e..666de39412 100644 --- a/input/drivers_joypad/mfi_joypad.m +++ b/input/drivers_joypad/mfi_joypad.m @@ -31,18 +31,17 @@ #define MAX_MFI_CONTROLLERS 4 #endif -static uint32_t mfi_buttons[MAX_USERS]; -static int16_t mfi_axes[MAX_USERS][4]; - -static uint32_t mfi_controllers[MAX_MFI_CONTROLLERS]; - -static NSMutableArray *mfiControllers; - enum { GCCONTROLLER_PLAYER_INDEX_UNSET = -1, }; +/* TODO/FIXME - static globals */ +static uint32_t mfi_buttons[MAX_USERS]; +static int16_t mfi_axes[MAX_USERS][4]; +static uint32_t mfi_controllers[MAX_MFI_CONTROLLERS]; +static NSMutableArray *mfiControllers; + static bool apple_gamecontroller_available(void) { int major, minor; diff --git a/input/drivers_joypad/parport_joypad.c b/input/drivers_joypad/parport_joypad.c index 47c331398d..f9bc41b732 100644 --- a/input/drivers_joypad/parport_joypad.c +++ b/input/drivers_joypad/parport_joypad.c @@ -48,6 +48,7 @@ struct parport_joypad char *ident; }; +/* TODO/FIXME - static global */ static struct parport_joypad parport_pads[MAX_USERS]; static void parport_poll_pad(struct parport_joypad *pad) diff --git a/input/drivers_joypad/ps2_joypad.c b/input/drivers_joypad/ps2_joypad.c index 5534e6ca76..70e35bc226 100644 --- a/input/drivers_joypad/ps2_joypad.c +++ b/input/drivers_joypad/ps2_joypad.c @@ -27,8 +27,8 @@ #define PS2_ANALOG_STICKS 2 #define PS2_ANALOG_AXIS 2 +/* TODO/FIXME - static globals */ static unsigned char padBuf[2][256] ALIGNED(64); - static uint64_t pad_state[DEFAULT_MAX_PADS]; static int16_t analog_state[DEFAULT_MAX_PADS][PS2_ANALOG_STICKS][PS2_ANALOG_AXIS]; diff --git a/input/drivers_joypad/ps3_joypad.c b/input/drivers_joypad/ps3_joypad.c index 25ec68dcb3..5162d09b73 100644 --- a/input/drivers_joypad/ps3_joypad.c +++ b/input/drivers_joypad/ps3_joypad.c @@ -21,6 +21,7 @@ #include "../../tasks/tasks_internal.h" +/* TODO/FIXME - static globals */ static uint64_t pad_state[DEFAULT_MAX_PADS]; static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; static uint64_t pads_connected[DEFAULT_MAX_PADS]; diff --git a/input/drivers_joypad/ps4_joypad.c b/input/drivers_joypad/ps4_joypad.c index b3d5cd9fb5..8430a9a0b4 100644 --- a/input/drivers_joypad/ps4_joypad.c +++ b/input/drivers_joypad/ps4_joypad.c @@ -49,11 +49,13 @@ #define ORBISPAD_TOUCH_PAD 0x00100000 #define ORBISPAD_INTERCEPTED 0x80000000 -typedef struct SceUserServiceLoginUserIdList { - int32_t userId[SCE_USER_SERVICE_MAX_LOGIN_USERS]; +typedef struct SceUserServiceLoginUserIdList +{ + int32_t userId[SCE_USER_SERVICE_MAX_LOGIN_USERS]; } SceUserServiceLoginUserIdList; -int sceUserServiceGetLoginUserIdList(SceUserServiceLoginUserIdList* userIdList); +int sceUserServiceGetLoginUserIdList( + SceUserServiceLoginUserIdList* userIdList); /* * Global var's @@ -65,6 +67,7 @@ typedef struct bool connected; } ds_joypad_state; +/* TODO/FIXME - static globals */ static ds_joypad_state ds_joypad_states[PS4_MAX_ORBISPADS]; static uint64_t pad_state[PS4_MAX_ORBISPADS]; static int16_t analog_state[PS4_MAX_ORBISPADS][2][2]; diff --git a/input/drivers_joypad/psp_joypad.c b/input/drivers_joypad/psp_joypad.c index d904473182..67e1bfcfdc 100644 --- a/input/drivers_joypad/psp_joypad.c +++ b/input/drivers_joypad/psp_joypad.c @@ -35,6 +35,8 @@ #include #include #include + +/* TODO/FIXME - static globals */ static int psp2_model; static SceCtrlPortInfo old_ctrl_info, curr_ctrl_info; static SceCtrlActuator actuators[DEFAULT_MAX_PADS] = {0}; @@ -53,9 +55,11 @@ static SceCtrlActuator actuators[DEFAULT_MAX_PADS] = {0}; #define SE_AREA(x, y) AREA(SCREEN_HALF_WIDTH, SCREEN_HALF_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, (x), (y)) #endif +/* TODO/FIXME - static globals */ static uint64_t pad_state[DEFAULT_MAX_PADS]; static int16_t analog_state[DEFAULT_MAX_PADS][2][2]; +/* TODO/FIXME - global referenced outside */ extern uint64_t lifecycle_state; static const char *psp_joypad_name(unsigned pad) diff --git a/input/drivers_joypad/rwebpad_joypad.c b/input/drivers_joypad/rwebpad_joypad.c index 3907c15489..c088d22761 100644 --- a/input/drivers_joypad/rwebpad_joypad.c +++ b/input/drivers_joypad/rwebpad_joypad.c @@ -33,10 +33,6 @@ static EM_BOOL rwebpad_gamepad_cb(int event_type, unsigned vid = 0; unsigned pid = 0; - (void)event_type; - (void)gamepad_event; - (void)user_data; - if (strncmp(gamepad_event->mapping, "standard", sizeof(gamepad_event->mapping)) == 0) { @@ -45,46 +41,40 @@ static EM_BOOL rwebpad_gamepad_cb(int event_type, pid = 1; } - if (event_type == EMSCRIPTEN_EVENT_GAMEPADCONNECTED) - input_autoconfigure_connect( + switch (event_type) + { + case EMSCRIPTEN_EVENT_GAMEPADCONNECTED: + input_autoconfigure_connect( gamepad_event->id, /* name */ NULL, /* display name */ rwebpad_joypad.ident, /* driver */ gamepad_event->index, /* idx */ vid, /* vid */ pid); /* pid */ - else if (event_type == EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED) - input_autoconfigure_disconnect(gamepad_event->index, - rwebpad_joypad.ident); + break; + case EMSCRIPTEN_EVENT_GAMEPADDISCONNECTED: + input_autoconfigure_disconnect(gamepad_event->index, + rwebpad_joypad.ident); + break; + default: + break; + } return EM_TRUE; } static bool rwebpad_joypad_init(void *data) { - EMSCRIPTEN_RESULT r; - (void)data; - - r = emscripten_sample_gamepad_data(); + EMSCRIPTEN_RESULT r = emscripten_sample_gamepad_data(); if (r == EMSCRIPTEN_RESULT_NOT_SUPPORTED) return false; /* callbacks needs to be registered for gamepads to connect */ r = emscripten_set_gamepadconnected_callback(NULL, false, rwebpad_gamepad_cb); - if (r != EMSCRIPTEN_RESULT_SUCCESS) - { - RARCH_ERR( - "[EMSCRIPTEN/PAD] failed to create connect callback: %d\n", r); - } r = emscripten_set_gamepaddisconnected_callback(NULL, false, rwebpad_gamepad_cb); - if (r != EMSCRIPTEN_RESULT_SUCCESS) - { - RARCH_ERR( - "[EMSCRIPTEN/PAD] failed to create disconnect callback: %d\n", r); - } return true; } @@ -93,7 +83,6 @@ static const char *rwebpad_joypad_name(unsigned pad) { static EmscriptenGamepadEvent gamepad_state; EMSCRIPTEN_RESULT r = emscripten_get_gamepad_status(pad, &gamepad_state); - if (r == EMSCRIPTEN_RESULT_SUCCESS) return gamepad_state.id; return ""; @@ -215,13 +204,10 @@ static bool rwebpad_joypad_query_pad(unsigned pad) if (r == EMSCRIPTEN_RESULT_SUCCESS) return gamepad_state.connected == EM_TRUE; - return false; } -static void rwebpad_joypad_destroy(void) -{ -} +static void rwebpad_joypad_destroy(void) { } input_device_driver_t rwebpad_joypad = { rwebpad_joypad_init, diff --git a/input/drivers_joypad/sdl_joypad.c b/input/drivers_joypad/sdl_joypad.c index e7132d331b..65b3410843 100644 --- a/input/drivers_joypad/sdl_joypad.c +++ b/input/drivers_joypad/sdl_joypad.c @@ -42,15 +42,10 @@ typedef struct _sdl_joypad #endif } sdl_joypad_t; -#ifdef HAVE_SDL2 -const int g_subsystem = SDL_INIT_GAMECONTROLLER; -#else -const int g_subsystem = SDL_INIT_JOYSTICK; -#endif - +/* TODO/FIXME - static globals */ static sdl_joypad_t sdl_pads[MAX_USERS]; #ifdef HAVE_SDL2 -static bool g_has_haptic; +static bool g_has_haptic = false; #endif static const char *sdl_joypad_name(unsigned pad) @@ -182,11 +177,16 @@ static void sdl_pad_connect(unsigned id) pad->num_balls = SDL_JoystickNumBalls(pad->joypad); } - pad->haptic = g_has_haptic ? SDL_HapticOpenFromJoystick(pad->joypad) : NULL; + pad->haptic = NULL; + + if (g_has_haptic) + { + pad->haptic = SDL_HapticOpenFromJoystick(pad->joypad); - if (g_has_haptic && !pad->haptic) - RARCH_WARN("[SDL]: Couldn't open haptic device of the joypad #%u: %s\n", - id, SDL_GetError()); + if (!pad->haptic) + RARCH_WARN("[SDL]: Couldn't open haptic device of the joypad #%u: %s\n", + id, SDL_GetError()); + } pad->rumble_effect = -1; @@ -236,25 +236,33 @@ static void sdl_pad_disconnect(unsigned id) static void sdl_joypad_destroy(void) { unsigned i; +#ifdef HAVE_SDL2 + int subsystem = SDL_INIT_GAMECONTROLLER; +#else + int subsystem = SDL_INIT_JOYSTICK; +#endif for (i = 0; i < MAX_USERS; i++) sdl_pad_disconnect(i); - SDL_QuitSubSystem(g_subsystem); + SDL_QuitSubSystem(subsystem); memset(sdl_pads, 0, sizeof(sdl_pads)); } static bool sdl_joypad_init(void *data) { unsigned i, num_sticks; - - (void)data; +#ifdef HAVE_SDL2 + int subsystem = SDL_INIT_GAMECONTROLLER; +#else + int subsystem = SDL_INIT_JOYSTICK; +#endif if (SDL_WasInit(0) == 0) { - if (SDL_Init(g_subsystem) < 0) + if (SDL_Init(subsystem) < 0) return false; } - else if (SDL_InitSubSystem(g_subsystem) < 0) + else if (SDL_InitSubSystem(subsystem) < 0) return false; #if HAVE_SDL2 diff --git a/input/drivers_joypad/switch_joypad.c b/input/drivers_joypad/switch_joypad.c index d275a740c6..95744331e6 100644 --- a/input/drivers_joypad/switch_joypad.c +++ b/input/drivers_joypad/switch_joypad.c @@ -19,6 +19,7 @@ /* TODO/FIXME - weird header include */ #include "string.h" +/* TODO/FIXME - global referenced outside */ extern uint64_t lifecycle_state; /* TODO/FIXME - static globals */ diff --git a/input/drivers_joypad/udev_joypad.c b/input/drivers_joypad/udev_joypad.c index 9cebb2e381..166452fb51 100644 --- a/input/drivers_joypad/udev_joypad.c +++ b/input/drivers_joypad/udev_joypad.c @@ -95,6 +95,7 @@ struct joypad_udev_entry struct udev_list_entry *item; }; +/* TODO/FIXME - static globals */ static struct udev *udev_joypad_fd = NULL; static struct udev_monitor *udev_joypad_mon = NULL; static struct udev_joypad udev_pads[MAX_USERS]; diff --git a/input/drivers_joypad/xdk_joypad.c b/input/drivers_joypad/xdk_joypad.c index f3eb766691..3e6b39f7ff 100644 --- a/input/drivers_joypad/xdk_joypad.c +++ b/input/drivers_joypad/xdk_joypad.c @@ -27,6 +27,7 @@ typedef struct bool connected; } xinput_joypad_state; +/* TODO/FIXME - static globals */ static xinput_joypad_state g_xinput_states[DEFAULT_MAX_PADS]; static HANDLE gamepads[DEFAULT_MAX_PADS]; diff --git a/input/drivers_joypad/xinput_hybrid_joypad.c b/input/drivers_joypad/xinput_hybrid_joypad.c index bdec926dfd..992bd01862 100644 --- a/input/drivers_joypad/xinput_hybrid_joypad.c +++ b/input/drivers_joypad/xinput_hybrid_joypad.c @@ -60,26 +60,6 @@ * For each pad index, the appropriate entry will be set to -1 if it is not * a 360 pad, or the correct XInput user number (0..3 inclusive) if it is. */ -static int g_xinput_pad_indexes[MAX_USERS]; -static unsigned g_last_xinput_pad_idx; -static bool g_xinput_block_pads; - -#ifdef HAVE_DYNAMIC -/* For xinput1_n.dll */ -static dylib_t g_xinput_dll = NULL; -#endif - -/* Function pointer, to be assigned with dylib_proc */ -typedef uint32_t (__stdcall *XInputGetStateEx_t)(uint32_t, XINPUT_STATE*); -static XInputGetStateEx_t g_XInputGetStateEx; - -typedef uint32_t (__stdcall *XInputSetState_t)(uint32_t, XINPUT_VIBRATION*); -static XInputSetState_t g_XInputSetState; - -/* Guide button may or may not be available */ -static bool g_xinput_guide_button_supported = false; -static unsigned g_xinput_num_buttons = 0; - typedef struct { XINPUT_STATE xstate; @@ -87,6 +67,21 @@ typedef struct } xinput_joypad_state; /* TODO/FIXME - static globals */ +static int g_xinput_pad_indexes[MAX_USERS]; +static unsigned g_last_xinput_pad_idx; +static bool g_xinput_block_pads; +#ifdef HAVE_DYNAMIC +/* For xinput1_n.dll */ +static dylib_t g_xinput_dll = NULL; +#endif +/* Function pointer, to be assigned with dylib_proc */ +typedef uint32_t (__stdcall *XInputGetStateEx_t)(uint32_t, XINPUT_STATE*); +typedef uint32_t (__stdcall *XInputSetState_t)(uint32_t, XINPUT_VIBRATION*); +/* Guide button may or may not be available */ +static bool g_xinput_guide_button_supported = false; +static unsigned g_xinput_num_buttons = 0; +static XInputSetState_t g_XInputSetState; +static XInputGetStateEx_t g_XInputGetStateEx; static XINPUT_VIBRATION g_xinput_rumble_states[4]; static xinput_joypad_state g_xinput_states[4]; diff --git a/input/drivers_joypad/xinput_joypad.c b/input/drivers_joypad/xinput_joypad.c index 0cc5898c53..9fa6ae55ad 100644 --- a/input/drivers_joypad/xinput_joypad.c +++ b/input/drivers_joypad/xinput_joypad.c @@ -44,29 +44,26 @@ #include "xinput_joypad.h" -#ifdef HAVE_DYNAMIC -/* For xinput1_n.dll */ -static dylib_t g_xinput_dll = NULL; -#endif - -/* Function pointer, to be assigned with dylib_proc */ -typedef uint32_t (__stdcall *XInputGetStateEx_t)(uint32_t, XINPUT_STATE*); -static XInputGetStateEx_t g_XInputGetStateEx; - -typedef uint32_t (__stdcall *XInputSetState_t)(uint32_t, XINPUT_VIBRATION*); -static XInputSetState_t g_XInputSetState; - -/* Guide button may or may not be available */ -static bool g_xinput_guide_button_supported = false; -static unsigned g_xinput_num_buttons = 0; - typedef struct { XINPUT_STATE xstate; bool connected; } xinput_joypad_state; +/* Function pointer, to be assigned with dylib_proc */ +typedef uint32_t (__stdcall *XInputGetStateEx_t)(uint32_t, XINPUT_STATE*); +typedef uint32_t (__stdcall *XInputSetState_t)(uint32_t, XINPUT_VIBRATION*); + /* TODO/FIXME - static globals */ +#ifdef HAVE_DYNAMIC +/* For xinput1_n.dll */ +static dylib_t g_xinput_dll = NULL; +#endif +/* Guide button may or may not be available */ +static bool g_xinput_guide_button_supported = false; +static unsigned g_xinput_num_buttons = 0; +static XInputSetState_t g_XInputSetState; +static XInputGetStateEx_t g_XInputGetStateEx; static XINPUT_VIBRATION g_xinput_rumble_states[4]; static xinput_joypad_state g_xinput_states[4];