21#include "../../SDL_internal.h"
32#include "../SDL_sysjoystick.h"
33#include "../SDL_joystick_c.h"
39#include "../../thread/SDL_systhread.h"
42static SceCtrlData pad = { .Lx = 0, .Ly = 0, .Buttons = 0 };
43static SDL_sem *pad_sem =
NULL;
45static int running = 0;
46static const enum PspCtrlButtons button_map[] = {
47 PSP_CTRL_TRIANGLE, PSP_CTRL_CIRCLE, PSP_CTRL_CROSS, PSP_CTRL_SQUARE,
48 PSP_CTRL_LTRIGGER, PSP_CTRL_RTRIGGER,
49 PSP_CTRL_DOWN, PSP_CTRL_LEFT, PSP_CTRL_UP, PSP_CTRL_RIGHT,
50 PSP_CTRL_SELECT, PSP_CTRL_START, PSP_CTRL_HOME, PSP_CTRL_HOLD };
51static int analog_map[256];
60static point
a = { 0, 0 };
61static point
b = { 50, 0 };
62static point
c = { 78, 32767 };
63static point
d = { 128, 32767 };
66static SDL_INLINE void lerp (point *dest, point *
a, point *
b,
float t)
68 dest->x =
a->x + (
b->x -
a->x)*
t;
69 dest->y =
a->y + (
b->y -
a->y)*
t;
73static int calc_bezier_y(
float t)
75 point ab, bc, cd, abbc, bccd, dest;
76 lerp (&ab, &
a, &
b,
t);
77 lerp (&bc, &
b, &
c,
t);
78 lerp (&cd, &
c, &
d,
t);
79 lerp (&abbc, &ab, &bc,
t);
80 lerp (&bccd, &bc, &cd,
t);
81 lerp (&dest, &abbc, &bccd,
t);
88int JoystickUpdate(
void *
data)
92 sceCtrlPeekBufferPositive(&pad, 1);
95 sceKernelDelayThread(1000000 / 60);
106int SDL_SYS_JoystickInit(
void)
111 sceCtrlSetSamplingCycle(0);
112 sceCtrlSetSamplingMode(PSP_CTRL_MODE_ANALOG);
125 for (
i = 0;
i < 128;
i++)
127 float t = (float)
i/127.0f;
128 analog_map[
i+128] = calc_bezier_y(
t);
129 analog_map[127-
i] = -1 * analog_map[
i+128];
135int SDL_SYS_NumJoysticks(
void)
140void SDL_SYS_JoystickDetect(
void)
145const char * SDL_SYS_JoystickNameForDeviceIndex(
int device_index)
147 return "PSP builtin joypad";
151SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(
int device_index)
157const char *SDL_SYS_JoystickName(
int index)
160 return "PSP controller";
171int SDL_SYS_JoystickOpen(SDL_Joystick *joystick,
int device_index)
173 joystick->nbuttons = 14;
185void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
188 enum PspCtrlButtons buttons;
189 enum PspCtrlButtons changed;
191 static enum PspCtrlButtons old_buttons = 0;
192 static unsigned char old_x = 0, old_y = 0;
195 buttons = pad.Buttons;
211 changed = old_buttons ^ buttons;
212 old_buttons = buttons;
214 for(
i=0;
i<
sizeof(button_map)/
sizeof(button_map[0]);
i++) {
215 if(changed & button_map[
i]) {
218 (buttons & button_map[
i]) ?
224 sceKernelDelayThread(0);
228void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
233void SDL_SYS_JoystickQuit(
void)
245 const char *
name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
255 const char *
name = joystick->name;
#define SDL_DestroySemaphore
#define SDL_CreateSemaphore
SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char int SDL_PRINTF_FORMAT_STRING const char const char SDL_SCANF_FORMAT_STRING const char return SDL_ThreadFunction const char void return Uint32 return Uint32 SDL_AssertionHandler void SDL_SpinLock SDL_atomic_t int int return SDL_atomic_t return void void void return void return int return SDL_AudioSpec SDL_AudioSpec return int int return return int SDL_RWops int SDL_AudioSpec Uint8 ** d
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
GLint GLint GLint GLint GLint GLint y
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
GLint GLint GLint GLint GLint x
GLboolean GLboolean GLboolean b
GLboolean GLboolean GLboolean GLboolean a
GLuint const GLchar * name
SDL_Thread * SDL_CreateThreadInternal(int(*fn)(void *), const char *name, const size_t stacksize, void *data)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)