move outdated winmm and psp joystick codes to struct _SDL_JoystickDriver

build-tested only. (bug #5472.)
This commit is contained in:
Ozkan Sezer
2021-01-23 17:30:50 +03:00
parent 8f1025899a
commit fd65aaa9a8
4 changed files with 198 additions and 80 deletions

View File

@@ -146,14 +146,14 @@ GetJoystickName(int index, const char *szRegKey)
return (name);
}
static int SDL_SYS_numjoysticks = 0;
static int numjoysticks = 0;
/* Function to scan the system for joysticks.
* Joystick 0 should be the system default joystick.
* It should return 0, or -1 on an unrecoverable fatal error.
*/
int
SDL_SYS_JoystickInit(void)
static int
WINMM_JoystickInit(void)
{
int i;
int maxdevs;
@@ -168,9 +168,9 @@ SDL_SYS_JoystickInit(void)
}
/* Loop over all potential joystick devices */
SDL_SYS_numjoysticks = 0;
numjoysticks = 0;
maxdevs = joyGetNumDevs();
for (i = JOYSTICKID1; i < maxdevs && SDL_SYS_numjoysticks < MAX_JOYSTICKS; ++i) {
for (i = JOYSTICKID1; i < maxdevs && numjoysticks < MAX_JOYSTICKS; ++i) {
joyinfo.dwSize = sizeof(joyinfo);
joyinfo.dwFlags = JOY_RETURNALL;
@@ -178,31 +178,31 @@ SDL_SYS_JoystickInit(void)
if (result == JOYERR_NOERROR) {
result = joyGetDevCapsA(i, &joycaps, sizeof(joycaps));
if (result == JOYERR_NOERROR) {
SYS_JoystickID[SDL_SYS_numjoysticks] = i;
SYS_Joystick[SDL_SYS_numjoysticks] = joycaps;
SYS_JoystickName[SDL_SYS_numjoysticks] =
SYS_JoystickID[numjoysticks] = i;
SYS_Joystick[numjoysticks] = joycaps;
SYS_JoystickName[numjoysticks] =
GetJoystickName(i, joycaps.szRegKey);
SDL_SYS_numjoysticks++;
numjoysticks++;
}
}
}
return (SDL_SYS_numjoysticks);
return numjoysticks;
}
int
SDL_SYS_NumJoysticks(void)
static int
WINMM_NumJoysticks(void)
{
return SDL_SYS_numjoysticks;
return numjoysticks;
}
void
SDL_SYS_JoystickDetect(void)
static void
WINMM_JoystickDetect(void)
{
}
/* Function to get the device-dependent name of a joystick */
const char *
SDL_SYS_JoystickNameForDeviceIndex(int device_index)
static const char *
WINMM_JoystickGetDeviceName(int device_index)
{
if (SYS_JoystickName[device_index] != NULL) {
return (SYS_JoystickName[device_index]);
@@ -211,8 +211,29 @@ SDL_SYS_JoystickNameForDeviceIndex(int device_index)
}
}
static int
WINMM_JoystickGetDevicePlayerIndex(int device_index)
{
return -1;
}
static void
WINMM_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
}
static SDL_JoystickGUID WINMM_JoystickGetDeviceGUID(int device_index)
{
SDL_JoystickGUID guid;
/* the GUID is just the first 16 chars of the name for now */
const char *name = WINMM_JoystickGetDeviceName(device_index);
SDL_zero(guid);
SDL_memcpy(&guid, name, SDL_min(sizeof(guid), SDL_strlen(name)));
return guid;
}
/* Function to perform the mapping from device index to the instance id for this index */
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
static SDL_JoystickID WINMM_JoystickGetDeviceInstanceID(int device_index)
{
return device_index;
}
@@ -222,15 +243,14 @@ SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
This should fill the nbuttons and naxes fields of the joystick structure.
It returns 0, or -1 if there is an error.
*/
int
SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
static int
WINMM_JoystickOpen(SDL_Joystick * joystick, int device_index)
{
int index, i;
int caps_flags[MAX_AXES - 2] =
{ JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV };
int axis_min[MAX_AXES], axis_max[MAX_AXES];
/* shortcut */
index = device_index;
axis_min[0] = SYS_Joystick[index].wXmin;
@@ -302,18 +322,46 @@ TranslatePOV(DWORD value)
return (pos);
}
static int
WINMM_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
return SDL_Unsupported();
}
static int
WINMM_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
return SDL_Unsupported();
}
static SDL_bool WINMM_JoystickHasLED(SDL_Joystick *joystick)
{
return SDL_FALSE;
}
static int
WINMM_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
return SDL_Unsupported();
}
static int WINMM_JoystickSetSensorsEnabled(SDL_Joystick *joystick, SDL_bool enabled)
{
return SDL_Unsupported();
}
/* Function to update the state of a joystick - called as a device poll.
* This function shouldn't update the joystick structure directly,
* but instead should call SDL_PrivateJoystick*() to deliver events
* and update joystick device state.
*/
void
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
static void
WINMM_JoystickUpdate(SDL_Joystick * joystick)
{
MMRESULT result;
int i;
DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ,
JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
};
DWORD pos[MAX_AXES];
struct _transaxis *transaxis;
@@ -365,15 +413,15 @@ SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
}
/* Function to close a joystick after use */
void
SDL_SYS_JoystickClose(SDL_Joystick * joystick)
static void
WINMM_JoystickClose(SDL_Joystick * joystick)
{
SDL_free(joystick->hwdata);
}
/* Function to perform any system-specific joystick related cleanup */
void
SDL_SYS_JoystickQuit(void)
static void
WINMM_JoystickQuit(void)
{
int i;
for (i = 0; i < MAX_JOYSTICKS; i++) {
@@ -382,24 +430,10 @@ SDL_SYS_JoystickQuit(void)
}
}
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
static SDL_bool
WINMM_JoystickGetGamepadMapping(int device_index, SDL_GamepadMapping *out)
{
SDL_JoystickGUID guid;
/* the GUID is just the first 16 chars of the name for now */
const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid;
}
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
{
SDL_JoystickGUID guid;
/* the GUID is just the first 16 chars of the name for now */
const char *name = joystick->name;
SDL_zero( guid );
SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
return guid;
return SDL_FALSE;
}
@@ -447,6 +481,28 @@ SetMMerror(char *function, int code)
SDL_SetError("%s", errbuf);
}
SDL_JoystickDriver SDL_WINMM_JoystickDriver =
{
WINMM_JoystickInit,
WINMM_NumJoysticks,
WINMM_JoystickDetect,
WINMM_JoystickGetDeviceName,
WINMM_JoystickGetDevicePlayerIndex,
WINMM_JoystickSetDevicePlayerIndex,
WINMM_JoystickGetDeviceGUID,
WINMM_JoystickGetDeviceInstanceID,
WINMM_JoystickOpen,
WINMM_JoystickRumble,
WINMM_JoystickRumbleTriggers,
WINMM_JoystickHasLED,
WINMM_JoystickSetLED,
WINMM_JoystickSetSensorsEnabled,
WINMM_JoystickUpdate,
WINMM_JoystickClose,
WINMM_JoystickQuit,
WINMM_JoystickGetGamepadMapping
};
#endif /* SDL_JOYSTICK_WINMM */
/* vi: set ts=4 sw=4 expandtab: */