21 #include "../../SDL_internal.h" 23 #ifdef SDL_JOYSTICK_WINMM 27 #include "../../core/windows/SDL_windows.h" 33 #include "../SDL_sysjoystick.h" 34 #include "../SDL_joystick_c.h" 36 #ifdef REGSTR_VAL_JOYOEMNAME 37 #undef REGSTR_VAL_JOYOEMNAME 39 #define REGSTR_VAL_JOYOEMNAME "OEMName" 41 #define MAX_JOYSTICKS 16 43 #define MAX_BUTTONS 32 44 #define JOY_BUTTON_FLAG(n) (1<<n) 48 static UINT SYS_JoystickID[MAX_JOYSTICKS];
50 static char *SYS_JoystickName[MAX_JOYSTICKS];
68 static void SetMMerror(
char *
function,
int code);
72 GetJoystickName(
int index,
const char *szRegKey)
94 REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR);
95 hTopKey = HKEY_LOCAL_MACHINE;
96 regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
97 if (regresult != ERROR_SUCCESS) {
98 hTopKey = HKEY_CURRENT_USER;
99 regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
101 if (regresult != ERROR_SUCCESS) {
106 regsize =
sizeof(regname);
108 REGSTR_VAL_JOYOEMNAME);
110 RegQueryValueExA(hKey, regvalue, 0, 0, (LPBYTE) regname, ®size);
113 if (regresult != ERROR_SUCCESS) {
124 REGSTR_PATH_JOYOEM, regname);
125 regresult = RegOpenKeyExA(hTopKey, regkey, 0, KEY_READ, &hKey);
126 if (regresult != ERROR_SUCCESS) {
131 regsize =
sizeof(regvalue);
133 RegQueryValueExA(hKey, REGSTR_VAL_JOYOEMNAME, 0, 0,
NULL, ®size);
134 if (regresult == ERROR_SUCCESS) {
139 regresult = RegQueryValueExA(hKey,
140 REGSTR_VAL_JOYOEMNAME, 0, 0,
141 (LPBYTE) name, ®size);
149 static int SDL_SYS_numjoysticks = 0;
165 for (i = 0; i < MAX_JOYSTICKS; ++
i) {
166 SYS_JoystickID[
i] = 0;
167 SYS_JoystickName[
i] =
NULL;
171 SDL_SYS_numjoysticks = 0;
172 maxdevs = joyGetNumDevs();
173 for (i = JOYSTICKID1; i < maxdevs && SDL_SYS_numjoysticks < MAX_JOYSTICKS; ++
i) {
175 joyinfo.dwSize =
sizeof(joyinfo);
176 joyinfo.dwFlags = JOY_RETURNALL;
177 result = joyGetPosEx(i, &joyinfo);
178 if (result == JOYERR_NOERROR) {
179 result = joyGetDevCapsA(i, &joycaps,
sizeof(joycaps));
180 if (result == JOYERR_NOERROR) {
181 SYS_JoystickID[SDL_SYS_numjoysticks] =
i;
183 SYS_JoystickName[SDL_SYS_numjoysticks] =
184 GetJoystickName(i, joycaps.szRegKey);
185 SDL_SYS_numjoysticks++;
189 return (SDL_SYS_numjoysticks);
195 return SDL_SYS_numjoysticks;
207 if (SYS_JoystickName[device_index] !=
NULL) {
208 return (SYS_JoystickName[device_index]);
229 int caps_flags[MAX_AXES - 2] =
230 { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV };
231 int axis_min[MAX_AXES], axis_max[MAX_AXES];
235 index = device_index;
250 joystick->instance_id = device_index;
253 if (joystick->hwdata ==
NULL) {
256 SDL_memset(joystick->hwdata, 0,
sizeof(*joystick->hwdata));
259 joystick->hwdata->id = SYS_JoystickID[
index];
260 for (i = 0; i < MAX_AXES; ++
i) {
261 if ((i < 2) || (
SYS_Joystick[index].wCaps & caps_flags[i - 2])) {
263 joystick->hwdata->transaxis[
i].scale =
266 joystick->hwdata->transaxis[
i].offset = 0;
267 joystick->hwdata->transaxis[
i].scale = 1.0;
289 TranslatePOV(DWORD
value)
294 if (value != JOY_POVCENTERED) {
295 if ((value > JOY_POVLEFT) || (value < JOY_POVRIGHT)) {
298 if ((value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD)) {
301 if ((value > JOY_POVRIGHT) && (value < JOY_POVLEFT)) {
304 if (value > JOY_POVBACKWARD) {
321 DWORD
flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ,
322 JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
325 struct _transaxis *transaxis;
329 joyinfo.dwSize =
sizeof(joyinfo);
330 joyinfo.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS;
331 if (!joystick->hats) {
332 joyinfo.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS);
334 result = joyGetPosEx(joystick->hwdata->id, &joyinfo);
335 if (result != JOYERR_NOERROR) {
336 SetMMerror(
"joyGetPosEx", result);
341 pos[0] = joyinfo.dwXpos;
342 pos[1] = joyinfo.dwYpos;
343 pos[2] = joyinfo.dwZpos;
344 pos[3] = joyinfo.dwRpos;
345 pos[4] = joyinfo.dwUpos;
346 pos[5] = joyinfo.dwVpos;
348 transaxis = joystick->hwdata->transaxis;
349 for (i = 0; i < joystick->naxes; i++) {
350 if (joyinfo.dwFlags & flags[i]) {
351 value = (int) (((
float) pos[i] + transaxis[i].
offset) * transaxis[
i].scale);
357 if (joyinfo.dwFlags & JOY_RETURNBUTTONS) {
358 for (i = 0; i < joystick->nbuttons; ++
i) {
359 if (joyinfo.dwButtons & JOY_BUTTON_FLAG(i)) {
368 if (joyinfo.dwFlags & JOY_RETURNPOV) {
371 pos = TranslatePOV(joyinfo.dwPOV);
388 for (i = 0; i < MAX_JOYSTICKS; i++) {
390 SYS_JoystickName[
i] =
NULL;
408 const char *name = joystick->name;
417 SetMMerror(
char *
function,
int code)
420 static char errbuf[1024];
424 case MMSYSERR_NODRIVER:
425 error =
"Joystick driver not present";
428 case MMSYSERR_INVALPARAM:
430 error =
"Invalid parameter(s)";
433 case MMSYSERR_BADDEVICEID:
434 error =
"Bad device ID";
437 case JOYERR_UNPLUGGED:
438 error =
"Joystick not attached";
442 error =
"Can't capture joystick input";
447 "%s: Unknown Multimedia system error: 0x%x",
GLenum GLenum GLenum GLenum GLenum scale
JoyStick_DeviceData * SYS_Joystick
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
void SDL_SYS_JoystickQuit(void)
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
GLuint const GLchar * name
#define SDL_JOYSTICK_AXIS_MIN
#define SDL_JOYSTICK_AXIS_MAX
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
GLsizei const GLfloat * value
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
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)
int SDL_SYS_JoystickInit(void)
#define SDL_OutOfMemory()
int SDL_SYS_NumJoysticks(void)
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
#define SDL_arraysize(array)
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
void SDL_SYS_JoystickDetect(void)