Skip to content

Commit

Permalink
move outdated winmm and psp joystick codes to struct _SDL_JoystickDriver
Browse files Browse the repository at this point in the history
build-tested only. (bug #5472.)
  • Loading branch information
sezero committed Jan 24, 2021
1 parent 8f10258 commit fd65aaa
Show file tree
Hide file tree
Showing 4 changed files with 198 additions and 80 deletions.
9 changes: 7 additions & 2 deletions src/joystick/SDL_joystick.c
Expand Up @@ -62,6 +62,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#if defined(SDL_JOYSTICK_DINPUT) || defined(SDL_JOYSTICK_XINPUT)
&SDL_WINDOWS_JoystickDriver,
#endif
#if defined(SDL_JOYSTICK_WINMM)
&SDL_WINMM_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_LINUX
&SDL_LINUX_JoystickDriver,
#endif
Expand All @@ -86,6 +89,9 @@ static SDL_JoystickDriver *SDL_joystick_drivers[] = {
#ifdef SDL_JOYSTICK_OS2
&SDL_OS2_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_PSP
&SDL_PSP_JoystickDriver,
#endif
#ifdef SDL_JOYSTICK_VIRTUAL
&SDL_VIRTUAL_JoystickDriver,
#endif
Expand Down Expand Up @@ -343,7 +349,7 @@ SDL_JoystickAxesCenteredAtZero(SDL_Joystick *joystick)
Uint32 id = MAKE_VIDPID(SDL_JoystickGetVendor(joystick),
SDL_JoystickGetProduct(joystick));

/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/
/*printf("JOYSTICK '%s' VID/PID 0x%.4x/0x%.4x AXES: %d\n", joystick->name, vendor, product, joystick->naxes);*/

if (joystick->naxes == 2) {
/* Assume D-pad or thumbstick style axes are centered at 0 */
Expand Down Expand Up @@ -1249,7 +1255,6 @@ SDL_PrivateJoystickForceRecentering(SDL_Joystick *joystick)
SDL_PrivateJoystickTouchpad(joystick, i, j, SDL_RELEASED, 0.0f, 0.0f, 0.0f);
}
}

}

void SDL_PrivateJoystickRemoved(SDL_JoystickID device_instance)
Expand Down
3 changes: 2 additions & 1 deletion src/joystick/SDL_sysjoystick.h
Expand Up @@ -24,7 +24,6 @@
#define SDL_sysjoystick_h_

/* This is the system specific header for the SDL joystick API */

#include "SDL_joystick.h"
#include "SDL_joystick_c.h"

Expand Down Expand Up @@ -204,7 +203,9 @@ extern SDL_JoystickDriver SDL_LINUX_JoystickDriver;
extern SDL_JoystickDriver SDL_VIRTUAL_JoystickDriver;
extern SDL_JoystickDriver SDL_WGI_JoystickDriver;
extern SDL_JoystickDriver SDL_WINDOWS_JoystickDriver;
extern SDL_JoystickDriver SDL_WINMM_JoystickDriver;
extern SDL_JoystickDriver SDL_OS2_JoystickDriver;
extern SDL_JoystickDriver SDL_PSP_JoystickDriver;

#endif /* SDL_sysjoystick_h_ */

Expand Down
120 changes: 88 additions & 32 deletions src/joystick/psp/SDL_sysjoystick.c
Expand Up @@ -103,7 +103,7 @@ int JoystickUpdate(void *data)
* Joystick 0 should be the system default joystick.
* It should return number of joysticks, or -1 on an unrecoverable fatal error.
*/
int SDL_SYS_JoystickInit(void)
static int PSP_JoystickInit(void)
{
int i;

Expand Down Expand Up @@ -132,43 +132,63 @@ int SDL_SYS_JoystickInit(void)
return 1;
}

int SDL_SYS_NumJoysticks(void)
static int PSP_NumJoysticks(void)
{
return 1;
}

void SDL_SYS_JoystickDetect(void)
static void PSP_JoystickDetect(void)
{
}

#if 0
/* Function to get the device-dependent name of a joystick */
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
static const char *PSP_JoystickName(int idx)
{
if (idx == 0) return "PSP controller";
SDL_SetError("No joystick available with that index");
return NULL;
}
#endif

/* Function to get the device-dependent name of a joystick */
static const char *PSP_JoystickGetDeviceName(int device_index)
{
return "PSP builtin joypad";
}

/* Function to perform the mapping from device index to the instance id for this index */
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
static int PSP_JoystickGetDevicePlayerIndex(int device_index)
{
return device_index;
return -1;
}

/* Function to get the device-dependent name of a joystick */
const char *SDL_SYS_JoystickName(int index)
static void
PSP_JoystickSetDevicePlayerIndex(int device_index, int player_index)
{
if (index == 0)
return "PSP controller";
}

SDL_SetError("No joystick available with that index");
return(NULL);
static SDL_JoystickGUID PSP_JoystickGetDeviceGUID(int device_index)
{
SDL_JoystickGUID guid;
/* the GUID is just the first 16 chars of the name for now */
const char *name = PSP_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 */
static SDL_JoystickID PSP_JoystickGetDeviceInstanceID(int device_index)
{
return device_index;
}

/* Function to open a joystick for use.
The joystick to open is specified by the 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 PSP_JoystickOpen(SDL_Joystick *joystick, int device_index)
{
joystick->nbuttons = 14;
joystick->naxes = 2;
Expand All @@ -177,12 +197,40 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
return 0;
}

static int
PSP_JoystickRumble(SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
return SDL_Unsupported();
}

static int
PSP_JoystickRumbleTriggers(SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
return SDL_Unsupported();
}

static SDL_bool PSP_JoystickHasLED(SDL_Joystick *joystick)
{
return SDL_FALSE;
}

static int
PSP_JoystickSetLED(SDL_Joystick *joystick, Uint8 red, Uint8 green, Uint8 blue)
{
return SDL_Unsupported();
}

static int PSP_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 PSP_JoystickUpdate(SDL_Joystick *joystick)
{
int i;
enum PspCtrlButtons buttons;
Expand Down Expand Up @@ -225,38 +273,46 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
}

/* Function to close a joystick after use */
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
static void PSP_JoystickClose(SDL_Joystick *joystick)
{
}

/* Function to perform any system-specific joystick related cleanup */
void SDL_SYS_JoystickQuit(void)
static void PSP_JoystickQuit(void)
{
/* Cleanup Threads and Semaphore. */
running = 0;
SDL_WaitThread(thread, NULL);
SDL_DestroySemaphore(pad_sem);
}

SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
static SDL_bool
PSP_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;
return SDL_FALSE;
}

SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
SDL_JoystickDriver SDL_PSP_JoystickDriver =
{
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;
}
PSP_JoystickInit,
PSP_NumJoysticks,
PSP_JoystickDetect,
PSP_JoystickGetDeviceName,
PSP_JoystickGetDevicePlayerIndex,
PSP_JoystickSetDevicePlayerIndex,
PSP_JoystickGetDeviceGUID,
PSP_JoystickGetDeviceInstanceID,
PSP_JoystickOpen,
PSP_JoystickRumble,
PSP_JoystickRumbleTriggers,
PSP_JoystickHasLED,
PSP_JoystickSetLED,
PSP_JoystickSetSensorsEnabled,
PSP_JoystickUpdate,
PSP_JoystickClose,
PSP_JoystickQuit,
PSP_JoystickGetGamepadMapping
};

#endif /* SDL_JOYSTICK_PSP */

Expand Down

0 comments on commit fd65aaa

Please sign in to comment.