--- uae/src/sdl-joystick.c 2018/04/24 17:14:20 1.1.1.2 +++ uae/src/sdl-joystick.c 2018/04/24 17:16:35 1.1.1.3 @@ -5,51 +5,35 @@ * * Copyright 1997 Bernd Schmidt * Copyright 1998 Krister Walfridsson - * Copyright 2003-2004 Richard Drummond + * Copyright 2003-2005 Richard Drummond */ #include "sysconfig.h" #include "sysdeps.h" -#include "config.h" #include "options.h" #include "inputdevice.h" #include -static int nr_joysticks; +static unsigned int nr_joysticks; static int initialized; struct joyinfo { SDL_Joystick *joy; - int axles; - int buttons; + unsigned int axles; + unsigned int buttons; }; static struct joyinfo joys[MAX_INPUT_DEVICES]; -static int isjoy (int pcport, int amigaport) -{ - if (pcport == 0) - return JSEM_ISJOY0 (amigaport, &currprefs); - else - return JSEM_ISJOY1 (amigaport, &currprefs); -} -static void read_joy(int nr) +static void read_joy (unsigned int nr) { - int num, i, axes, axis; + unsigned int num, i, axes, axis; SDL_Joystick *joy; if (currprefs.input_selected_setting == 0) { - if (nr >= 2) - return; - if (isjoy (nr, 0)) { - if (JSEM_ISNUMPAD (0, &currprefs) || JSEM_ISCURSOR (0, &currprefs) || JSEM_ISSOMEWHEREELSE (0, &currprefs)) - return; - } else if (isjoy (nr, 1)) { - if (JSEM_ISNUMPAD (1, &currprefs) || JSEM_ISCURSOR (1, &currprefs) || JSEM_ISSOMEWHEREELSE (1, &currprefs)) - return; - } else + if (jsem_isjoy (0, &currprefs) != (int)nr && jsem_isjoy (1, &currprefs) != (int)nr) return; } joy = joys[nr].joy; @@ -66,17 +50,17 @@ static void read_joy(int nr) } } -static int get_joystick_num (void) +static unsigned int get_joystick_num (void) { return nr_joysticks; } -static int get_joystick_widget_num (int joy) +static unsigned int get_joystick_widget_num (unsigned int joy) { return joys[joy].axles + joys[joy].buttons; } -static int get_joystick_widget_type (int joy, int num, char *name) +static int get_joystick_widget_type (unsigned int joy, unsigned int num, char *name, uae_u32 *code) { if (num >= joys[joy].axles && num < joys[joy].axles + joys[joy].buttons) { if (name) @@ -90,7 +74,7 @@ static int get_joystick_widget_type (int return IDEV_WIDGET_NONE; } -static int get_joystick_widget_first (int joy, int type) +static int get_joystick_widget_first (unsigned int joy, int type) { switch (type) { case IDEV_WIDGET_BUTTON: @@ -101,17 +85,15 @@ static int get_joystick_widget_first (in return -1; } -static char *get_joystick_name (int joy) +static const char *get_joystick_name (unsigned int joy) { - static char name[100]; - sprintf (name, "%d: %s", joy + 1, SDL_JoystickName (joy)); - return name; + return SDL_JoystickName (joy); } static void read_joysticks (void) { if (get_joystick_num ()) { - int i; + unsigned int i; SDL_JoystickUpdate (); for (i = 0; i < get_joystick_num (); i++) read_joy (i); @@ -124,7 +106,7 @@ static int init_joysticks (void) if (!initialized) { if (SDL_InitSubSystem (SDL_INIT_JOYSTICK) == 0) { - int i; + unsigned int i; nr_joysticks = SDL_NumJoysticks (); write_log ("Found %d joystick(s)\n", nr_joysticks); @@ -147,29 +129,38 @@ static int init_joysticks (void) static void close_joysticks (void) { - int i; - for (i = 0; i < get_joystick_num(); i++) { + unsigned int i; + for (i = 0; i < nr_joysticks; i++) { SDL_JoystickClose (joys[i].joy); joys[i].joy = 0; } + nr_joysticks = 0; - if (initialized) + if (initialized) { SDL_QuitSubSystem (SDL_INIT_JOYSTICK); + initialized = 0; + } } -static int acquire_joy (int num, int flags) +static int acquire_joy (unsigned int num, int flags) { return num < get_joystick_num (); } -static void unacquire_joy (int num) +static void unacquire_joy (unsigned int num) { } struct inputdevice_functions inputdevicefunc_joystick = { - init_joysticks, close_joysticks, acquire_joy, unacquire_joy, - read_joysticks, get_joystick_num, get_joystick_name, - get_joystick_widget_num, get_joystick_widget_type, + init_joysticks, + close_joysticks, + acquire_joy, + unacquire_joy, + read_joysticks, + get_joystick_num, + get_joystick_name, + get_joystick_widget_num, + get_joystick_widget_type, get_joystick_widget_first }; @@ -178,7 +169,7 @@ struct inputdevice_functions inputdevice */ void input_get_default_joystick (struct uae_input_device *uid) { - int i, port; + unsigned int i, port; for (i = 0; i < nr_joysticks; i++) { port = i & 1; @@ -186,7 +177,7 @@ void input_get_default_joystick (struct uid[i].eventid[ID_AXIS_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_VERT : INPUTEVENT_JOY1_VERT; uid[i].eventid[ID_BUTTON_OFFSET + 0][0] = port ? INPUTEVENT_JOY2_FIRE_BUTTON : INPUTEVENT_JOY1_FIRE_BUTTON; uid[i].eventid[ID_BUTTON_OFFSET + 1][0] = port ? INPUTEVENT_JOY2_2ND_BUTTON : INPUTEVENT_JOY1_2ND_BUTTON; - uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_3RD_BUTTON : INPUTEVENT_JOY1_3RD_BUTTON; + uid[i].eventid[ID_BUTTON_OFFSET + 2][0] = port ? INPUTEVENT_JOY2_FIRE_BUTTON_AF : INPUTEVENT_JOY1_FIRE_BUTTON_AF; } uid[0].enabled = 1; }