src/SDL12_compat.c
changeset 82 c5f7371d4fcc
parent 81 f41fab5c1927
child 83 3dc6727acc6b
     1.1 --- a/src/SDL12_compat.c	Thu Feb 21 00:30:29 2019 -0500
     1.2 +++ b/src/SDL12_compat.c	Thu Feb 21 02:31:37 2019 -0500
     1.3 @@ -702,6 +702,12 @@
     1.4      SDL12_Rect **modes12;  /* ptrs to each item in modeslist, for SDL_ListModes() */
     1.5  } VideoModeList;
     1.6  
     1.7 +typedef struct
     1.8 +{
     1.9 +    int device_index;
    1.10 +    SDL_Joystick *joystick;
    1.11 +} JoystickOpenedItem;
    1.12 +
    1.13  // !!! FIXME: go through all of these.
    1.14  static VideoModeList *VideoModes = NULL;
    1.15  static int VideoModesCount = 0;
    1.16 @@ -722,6 +728,7 @@
    1.17  static SDL12_Cursor *CurrentCursor12 = NULL;
    1.18  static Uint8 EventStates[SDL12_NUMEVENTS];
    1.19  static int SwapInterval = 0;
    1.20 +static JoystickOpenedItem JoystickOpenList[16];
    1.21  
    1.22  // !!! FIXME: need a mutex for the event queue.
    1.23  #define SDL12_MAXEVENTS 128
    1.24 @@ -843,10 +850,93 @@
    1.25      return SDL20_HasSSE();
    1.26  }
    1.27  
    1.28 +DECLSPEC SDL_Joystick * SDLCALL
    1.29 +SDL_JoystickOpen(int device_index)
    1.30 +{
    1.31 +    int i;
    1.32 +    SDL20_LockJoysticks();
    1.33 +    for (i = 0; i < SDL_arraysize(JoystickOpenList); i++) {
    1.34 +        if (JoystickOpenList[i].joystick == NULL) {
    1.35 +            break;
    1.36 +        }
    1.37 +    }
    1.38 +
    1.39 +    if (i == SDL_arraysize(JoystickOpenList)) {
    1.40 +        SDL20_UnlockJoysticks();
    1.41 +        SDL20_SetError("Too many open joysticks");
    1.42 +        return NULL;
    1.43 +    }
    1.44 +
    1.45 +    JoystickOpenList[i].joystick = SDL20_JoystickOpen(device_index);
    1.46 +    if (JoystickOpenList[i].joystick) {
    1.47 +        JoystickOpenList[i].device_index = device_index;
    1.48 +    }
    1.49 +
    1.50 +    SDL20_UnlockJoysticks();
    1.51 +    return JoystickOpenList[i].joystick;
    1.52 +}
    1.53 +
    1.54 +DECLSPEC void SDLCALL
    1.55 +SDL_JoystickClose(SDL_Joystick *joystick)
    1.56 +{
    1.57 +    int i;
    1.58 +    SDL20_LockJoysticks();
    1.59 +    for (i = 0; i < SDL_arraysize(JoystickOpenList); i++) {
    1.60 +        if (JoystickOpenList[i].joystick == joystick) {
    1.61 +            break;
    1.62 +        }
    1.63 +    }
    1.64 +
    1.65 +    if (i < SDL_arraysize(JoystickOpenList)) {
    1.66 +        JoystickOpenList[i].joystick = NULL;
    1.67 +    }
    1.68 +
    1.69 +    SDL20_UnlockJoysticks();
    1.70 +
    1.71 +    SDL20_JoystickClose(joystick);
    1.72 +}
    1.73 +
    1.74 +DECLSPEC const char * SDLCALL
    1.75 +SDL_JoystickName(int device_index)
    1.76 +{
    1.77 +    return SDL20_JoystickNameForIndex(device_index);
    1.78 +}
    1.79 +
    1.80 +DECLSPEC int SDLCALL
    1.81 +SDL_JoystickIndex(SDL_Joystick *joystick)
    1.82 +{
    1.83 +    int i;
    1.84 +
    1.85 +    SDL20_LockJoysticks(); {
    1.86 +        for (i = 0; i < SDL_arraysize(JoystickOpenList); i++) {
    1.87 +            if (JoystickOpenList[i].joystick == joystick) {
    1.88 +                break;
    1.89 +            }
    1.90 +        }
    1.91 +
    1.92 +        if (i < SDL_arraysize(JoystickOpenList)) {
    1.93 +            SDL20_UnlockJoysticks();
    1.94 +            return JoystickOpenList[i].device_index;
    1.95 +        }
    1.96 +
    1.97 +    }
    1.98 +    SDL20_UnlockJoysticks();
    1.99 +    return SDL20_SetError("Can't find joystick");
   1.100 +}
   1.101 +
   1.102  DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index)
   1.103  {
   1.104 -    FIXME("write me");
   1.105 -    return 0;
   1.106 +    int retval = 0;
   1.107 +    int i;
   1.108 +    SDL20_LockJoysticks();
   1.109 +    for (i = 0; i < SDL_arraysize(JoystickOpenList); i++) {
   1.110 +        if ((JoystickOpenList[i].joystick) && (JoystickOpenList[i].device_index == device_index)) {
   1.111 +            retval = 1;
   1.112 +            break;
   1.113 +        }
   1.114 +    }
   1.115 +    SDL20_UnlockJoysticks();
   1.116 +    return retval;
   1.117  }
   1.118  
   1.119  static int