-/* ========================================================================= */
-/* platform dependant joystick functions */
-/* ========================================================================= */
-
-#if defined(PLATFORM_UNIX) && !defined(TARGET_SDL)
-void UnixInitJoysticks()
-{
- int i;
-
- for (i=0; i<MAX_PLAYERS; i++)
- {
- char *device_name = setup.input[i].joy.device_name;
-
- /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
- if (joystick.fd[i] != -1)
- {
- close(joystick.fd[i]);
- joystick.fd[i] = -1;
- }
-
- if (!setup.input[i].use_joystick)
- continue;
-
- if (access(device_name, R_OK) != 0)
- {
- Error(ERR_WARN, "cannot access joystick device '%s'", device_name);
- continue;
- }
-
- if ((joystick.fd[i] = open(device_name, O_RDONLY)) < 0)
- {
- Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
- continue;
- }
-
- joystick.status = JOYSTICK_ACTIVATED;
- }
-}
-
-boolean UnixReadJoystick(int fd, int *x, int *y, boolean *b1, boolean *b2)
-{
-#if defined(PLATFORM_FREEBSD)
- struct joystick joy_ctrl;
-#else
- struct joystick_control
- {
- int buttons;
- int x;
- int y;
- } joy_ctrl;
-#endif
-
- if (read(fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl))
- return FALSE;
-
- if (x != NULL)
- *x = joy_ctrl.x;
- if (y != NULL)
- *y = joy_ctrl.y;
-
-#if defined(PLATFORM_FREEBSD)
- if (b1 != NULL)
- *b1 = joy_ctrl.b1;
- if (b2 != NULL)
- *b2 = joy_ctrl.b2;
-#else
- if (b1 != NULL)
- *b1 = joy_ctrl.buttons & 1;
- if (b2 != NULL)
- *b2 = joy_ctrl.buttons & 2;
-#endif
-
- return TRUE;
-}
-#endif /* PLATFORM_UNIX && !TARGET_SDL */
-
-
-/* ========================================================================= */
-/* platform independant joystick functions */
-/* ========================================================================= */
-
-#define TRANSLATE_JOYSYMBOL_TO_JOYNAME 0
-#define TRANSLATE_JOYNAME_TO_JOYSYMBOL 1
-
-void translate_joyname(int *joysymbol, char **name, int mode)
-{
- static struct
- {
- int joysymbol;
- char *name;
- } translate_joy[] =
- {
- { JOY_LEFT, "joystick_left" },
- { JOY_RIGHT, "joystick_right" },
- { JOY_UP, "joystick_up" },
- { JOY_DOWN, "joystick_down" },
- { JOY_BUTTON_1, "joystick_button_1" },
- { JOY_BUTTON_2, "joystick_button_2" },
- };
-
- int i;
-
- if (mode == TRANSLATE_JOYSYMBOL_TO_JOYNAME)
- {
- *name = "[undefined]";
-
- for (i=0; i<6; i++)
- {
- if (*joysymbol == translate_joy[i].joysymbol)
- {
- *name = translate_joy[i].name;
- break;
- }
- }
- }
- else if (mode == TRANSLATE_JOYNAME_TO_JOYSYMBOL)
- {
- *joysymbol = 0;
-
- for (i=0; i<6; i++)
- {
- if (strcmp(*name, translate_joy[i].name) == 0)
- {
- *joysymbol = translate_joy[i].joysymbol;
- break;
- }
- }
- }
-}
-
-char *getJoyNameFromJoySymbol(int joysymbol)
-{
- char *name;
-
- translate_joyname(&joysymbol, &name, TRANSLATE_JOYSYMBOL_TO_JOYNAME);
- return name;
-}
-
-int getJoySymbolFromJoyName(char *name)
-{
- int joysymbol;
-
- translate_joyname(&joysymbol, &name, TRANSLATE_JOYNAME_TO_JOYSYMBOL);
- return joysymbol;
-}