- if (joystick_nr >= SDL_NumJoysticks())
- joystick_nr = -1;
-
- /* misuse joystick file descriptor variable to store joystick number */
- stored_player[i].joystick_fd = joystick_nr;
-
- /* this allows subsequent calls to 'InitJoysticks' for re-initialization */
- if (Check_SDL_JoystickOpened(joystick_nr))
- Close_SDL_Joystick(joystick_nr);
-
- if (!setup.input[i].use_joystick)
- continue;
-
- if (!Open_SDL_Joystick(joystick_nr))
- {
- Error(ERR_WARN, "cannot open joystick %d", joystick_nr);
- continue;
- }
-
- joystick_status = JOYSTICK_AVAILABLE;
- }
-
-#else /* !TARGET_SDL */
-
-#if defined(PLATFORM_UNIX)
- 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 (stored_player[i].joystick_fd != -1)
- {
- close(stored_player[i].joystick_fd);
- stored_player[i].joystick_fd = -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 ((stored_player[i].joystick_fd = open(device_name, O_RDONLY)) < 0)
- {
- Error(ERR_WARN, "cannot open joystick device '%s'", device_name);
- continue;
- }
-
- joystick_status = JOYSTICK_AVAILABLE;
- }
-
-#else /* !PLATFORM_UNIX */
-
- /* try to access two joysticks; if that fails, try to access just one */
- if (install_joystick(JOY_TYPE_2PADS) == 0 ||
- install_joystick(JOY_TYPE_AUTODETECT) == 0)
- joystick_status = JOYSTICK_AVAILABLE;
-
- /*
- load_joystick_data(JOYSTICK_FILENAME);
- */
-
- for (i=0; i<MAX_PLAYERS; i++)
- {
- char *device_name = setup.input[i].joy.device_name;
- int joystick_nr = getJoystickNrFromDeviceName(device_name);
-
- if (joystick_nr >= num_joysticks)
- joystick_nr = -1;
-
- /* misuse joystick file descriptor variable to store joystick number */
- stored_player[i].joystick_fd = joystick_nr;
- }
-#endif
-
-#endif /* !TARGET_SDL */