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;
156 SDL_SYS_JoystickInit(
void)
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);
193 SDL_SYS_NumJoysticks(
void)
195 return SDL_SYS_numjoysticks;
199 SDL_SYS_JoystickDetect(
void)
205 SDL_SYS_JoystickNameForDeviceIndex(
int device_index)
207 if (SYS_JoystickName[device_index] !=
NULL) {
208 return (SYS_JoystickName[device_index]);
215 SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(
int device_index)
226 SDL_SYS_JoystickOpen(SDL_Joystick *
joystick,
int 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;
283 TranslatePOV(DWORD
value)
288 if (value != JOY_POVCENTERED) {
289 if ((value > JOY_POVLEFT) || (value < JOY_POVRIGHT)) {
292 if ((value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD)) {
295 if ((value > JOY_POVRIGHT) && (value < JOY_POVLEFT)) {
298 if (value > JOY_POVBACKWARD) {
311 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
315 DWORD
flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ,
316 JOY_RETURNR, JOY_RETURNU, JOY_RETURNV
319 struct _transaxis *transaxis;
323 joyinfo.dwSize =
sizeof(joyinfo);
324 joyinfo.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS;
325 if (!joystick->hats) {
326 joyinfo.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS);
328 result = joyGetPosEx(joystick->hwdata->id, &joyinfo);
329 if (result != JOYERR_NOERROR) {
330 SetMMerror(
"joyGetPosEx", result);
335 pos[0] = joyinfo.dwXpos;
336 pos[1] = joyinfo.dwYpos;
337 pos[2] = joyinfo.dwZpos;
338 pos[3] = joyinfo.dwRpos;
339 pos[4] = joyinfo.dwUpos;
340 pos[5] = joyinfo.dwVpos;
342 transaxis = joystick->hwdata->transaxis;
343 for (i = 0; i < joystick->naxes; i++) {
344 if (joyinfo.dwFlags & flags[i]) {
345 value = (int) (((
float) pos[i] + transaxis[i].
offset) * transaxis[
i].scale);
351 if (joyinfo.dwFlags & JOY_RETURNBUTTONS) {
352 for (i = 0; i < joystick->nbuttons; ++
i) {
353 if (joyinfo.dwButtons & JOY_BUTTON_FLAG(i)) {
362 if (joyinfo.dwFlags & JOY_RETURNPOV) {
369 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
376 SDL_SYS_JoystickQuit(
void)
379 for (i = 0; i < MAX_JOYSTICKS; i++) {
381 SYS_JoystickName[
i] =
NULL;
389 const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
399 const char *name = joystick->name;
408 SetMMerror(
char *
function,
int code)
411 static char errbuf[1024];
415 case MMSYSERR_NODRIVER:
416 error =
"Joystick driver not present";
419 case MMSYSERR_INVALPARAM:
421 error =
"Invalid parameter(s)";
424 case MMSYSERR_BADDEVICEID:
425 error =
"Bad device ID";
428 case JOYERR_UNPLUGGED:
429 error =
"Joystick not attached";
433 error =
"Can't capture joystick input";
438 "%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)
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
GLuint const GLchar * name
#define SDL_JOYSTICK_AXIS_MIN
#define SDL_JOYSTICK_AXIS_MAX
GLsizei const GLfloat * value
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)
#define SDL_OutOfMemory()
#define SDL_arraysize(array)