Mercurial > sdl-ios-xcode
comparison src/joystick/win32/SDL_mmjoystick.c @ 1895:c121d94672cb
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 10 Jul 2006 21:04:37 +0000 |
parents | 5e86e34453d4 |
children | 6051761b5934 |
comparison
equal
deleted
inserted
replaced
1894:c69cee13dd76 | 1895:c121d94672cb |
---|---|
34 #include "SDL_joystick.h" | 34 #include "SDL_joystick.h" |
35 #include "../SDL_sysjoystick.h" | 35 #include "../SDL_sysjoystick.h" |
36 #include "../SDL_joystick_c.h" | 36 #include "../SDL_joystick_c.h" |
37 | 37 |
38 #define MAX_JOYSTICKS 16 | 38 #define MAX_JOYSTICKS 16 |
39 #define MAX_AXES 6 /* each joystick can have up to 6 axes */ | 39 #define MAX_AXES 6 /* each joystick can have up to 6 axes */ |
40 #define MAX_BUTTONS 32 /* and 32 buttons */ | 40 #define MAX_BUTTONS 32 /* and 32 buttons */ |
41 #define AXIS_MIN -32768 /* minimum value for axis coordinate */ | 41 #define AXIS_MIN -32768 /* minimum value for axis coordinate */ |
42 #define AXIS_MAX 32767 /* maximum value for axis coordinate */ | 42 #define AXIS_MAX 32767 /* maximum value for axis coordinate */ |
43 /* limit axis to 256 possible positions to filter out noise */ | 43 /* limit axis to 256 possible positions to filter out noise */ |
44 #define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256) | 44 #define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256) |
45 #define JOY_BUTTON_FLAG(n) (1<<n) | 45 #define JOY_BUTTON_FLAG(n) (1<<n) |
46 | 46 |
47 | 47 |
48 /* array to hold joystick ID values */ | 48 /* array to hold joystick ID values */ |
49 static UINT SYS_JoystickID[MAX_JOYSTICKS]; | 49 static UINT SYS_JoystickID[MAX_JOYSTICKS]; |
50 static JOYCAPS SYS_Joystick[MAX_JOYSTICKS]; | 50 static JOYCAPS SYS_Joystick[MAX_JOYSTICKS]; |
51 static char *SYS_JoystickName[MAX_JOYSTICKS]; | 51 static char *SYS_JoystickName[MAX_JOYSTICKS]; |
52 | 52 |
53 /* The private structure used to keep track of a joystick */ | 53 /* The private structure used to keep track of a joystick */ |
54 struct joystick_hwdata | 54 struct joystick_hwdata |
55 { | 55 { |
56 /* joystick ID */ | 56 /* joystick ID */ |
57 UINT id; | 57 UINT id; |
58 | 58 |
59 /* values used to translate device-specific coordinates into | 59 /* values used to translate device-specific coordinates into |
60 SDL-standard ranges */ | 60 SDL-standard ranges */ |
61 struct _transaxis { | 61 struct _transaxis |
62 int offset; | 62 { |
63 float scale; | 63 int offset; |
64 } transaxis[6]; | 64 float scale; |
65 } transaxis[6]; | |
65 }; | 66 }; |
66 | 67 |
67 /* Convert a win32 Multimedia API return code to a text message */ | 68 /* Convert a win32 Multimedia API return code to a text message */ |
68 static void SetMMerror(char *function, int code); | 69 static void SetMMerror(char *function, int code); |
69 | 70 |
70 | 71 |
71 static char *GetJoystickName(int index, const char *szRegKey) | 72 static char * |
72 { | 73 GetJoystickName(int index, const char *szRegKey) |
73 /* added 7/24/2004 by Eckhard Stolberg */ | 74 { |
74 /* | 75 /* added 7/24/2004 by Eckhard Stolberg */ |
75 see if there is a joystick for the current | 76 /* |
76 index (1-16) listed in the registry | 77 see if there is a joystick for the current |
77 */ | 78 index (1-16) listed in the registry |
78 char *name = NULL; | 79 */ |
79 HKEY hKey; | 80 char *name = NULL; |
80 DWORD regsize; | 81 HKEY hKey; |
81 LONG regresult; | 82 DWORD regsize; |
82 unsigned char regkey[256]; | 83 LONG regresult; |
83 unsigned char regvalue[256]; | 84 unsigned char regkey[256]; |
84 unsigned char regname[256]; | 85 unsigned char regvalue[256]; |
85 | 86 unsigned char regname[256]; |
86 SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s", | 87 |
87 REGSTR_PATH_JOYCONFIG, | 88 SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s\\%s", |
88 szRegKey, | 89 REGSTR_PATH_JOYCONFIG, szRegKey, REGSTR_KEY_JOYCURR); |
89 REGSTR_KEY_JOYCURR); | 90 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, |
90 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, | 91 (LPTSTR) & regkey, 0, KEY_READ, &hKey); |
91 (LPTSTR) ®key, 0, KEY_READ, &hKey); | 92 if (regresult == ERROR_SUCCESS) { |
92 if (regresult == ERROR_SUCCESS) | 93 /* |
93 { | 94 find the registry key name for the |
94 /* | 95 joystick's properties |
95 find the registry key name for the | 96 */ |
96 joystick's properties | 97 regsize = sizeof(regname); |
97 */ | 98 SDL_snprintf((char *) regvalue, SDL_arraysize(regvalue), |
98 regsize = sizeof(regname); | 99 "Joystick%d%s", index + 1, REGSTR_VAL_JOYOEMNAME); |
99 SDL_snprintf((char *) regvalue, SDL_arraysize(regvalue), | 100 regresult = RegQueryValueExA(hKey, |
100 "Joystick%d%s", index+1, | 101 (char *) regvalue, 0, 0, |
101 REGSTR_VAL_JOYOEMNAME); | 102 (LPBYTE) & regname, (LPDWORD) & regsize); |
102 regresult = RegQueryValueExA(hKey, | 103 RegCloseKey(hKey); |
103 (char *) regvalue, 0, 0, (LPBYTE) ®name, | 104 if (regresult == ERROR_SUCCESS) { |
104 (LPDWORD) ®size); | 105 /* open that registry key */ |
105 RegCloseKey(hKey); | 106 SDL_snprintf((char *) regkey, SDL_arraysize(regkey), |
106 if (regresult == ERROR_SUCCESS) | 107 "%s\\%s", REGSTR_PATH_JOYOEM, regname); |
107 { | 108 regresult = |
108 /* open that registry key */ | 109 RegOpenKeyExA(HKEY_LOCAL_MACHINE, (char *) regkey, 0, |
109 SDL_snprintf((char *) regkey, SDL_arraysize(regkey), "%s\\%s", | 110 KEY_READ, &hKey); |
110 REGSTR_PATH_JOYOEM, regname); | 111 if (regresult == ERROR_SUCCESS) { |
111 regresult = RegOpenKeyExA(HKEY_LOCAL_MACHINE, | 112 /* find the size for the OEM name text */ |
112 (char *) regkey, 0, KEY_READ, &hKey); | 113 regsize = sizeof(regvalue); |
113 if (regresult == ERROR_SUCCESS) | 114 regresult = |
114 { | 115 RegQueryValueExA(hKey, |
115 /* find the size for the OEM name text */ | 116 REGSTR_VAL_JOYOEMNAME, |
116 regsize = sizeof(regvalue); | 117 0, 0, NULL, (LPDWORD) & regsize); |
117 regresult = | 118 if (regresult == ERROR_SUCCESS) { |
118 RegQueryValueExA(hKey, | 119 /* |
119 REGSTR_VAL_JOYOEMNAME, | 120 allocate enough memory |
120 0, 0, NULL, | 121 for the OEM name text ... |
121 (LPDWORD) ®size); | 122 */ |
122 if (regresult == ERROR_SUCCESS) | 123 name = (char *) SDL_malloc(regsize); |
123 { | 124 /* ... and read it from the registry */ |
124 /* | 125 regresult = |
125 allocate enough memory | 126 RegQueryValueExA(hKey, |
126 for the OEM name text ... | 127 REGSTR_VAL_JOYOEMNAME, 0, 0, |
127 */ | 128 (LPBYTE) name, (LPDWORD) & regsize); |
128 name = (char *) SDL_malloc(regsize); | 129 RegCloseKey(hKey); |
129 /* ... and read it from the registry */ | 130 } |
130 regresult = | 131 } |
131 RegQueryValueExA(hKey, | 132 } |
132 REGSTR_VAL_JOYOEMNAME, 0, 0, | 133 } |
133 (LPBYTE) name, | 134 return (name); |
134 (LPDWORD) ®size); | |
135 RegCloseKey(hKey); | |
136 } | |
137 } | |
138 } | |
139 } | |
140 return(name); | |
141 } | 135 } |
142 | 136 |
143 /* Function to scan the system for joysticks. | 137 /* Function to scan the system for joysticks. |
144 * This function should set SDL_numjoysticks to the number of available | 138 * This function should set SDL_numjoysticks to the number of available |
145 * joysticks. Joystick 0 should be the system default joystick. | 139 * joysticks. Joystick 0 should be the system default joystick. |
146 * It should return 0, or -1 on an unrecoverable fatal error. | 140 * It should return 0, or -1 on an unrecoverable fatal error. |
147 */ | 141 */ |
148 int SDL_SYS_JoystickInit(void) | 142 int |
149 { | 143 SDL_SYS_JoystickInit(void) |
150 int i; | 144 { |
151 int maxdevs; | 145 int i; |
152 int numdevs; | 146 int maxdevs; |
153 JOYINFOEX joyinfo; | 147 int numdevs; |
154 JOYCAPS joycaps; | 148 JOYINFOEX joyinfo; |
155 MMRESULT result; | 149 JOYCAPS joycaps; |
156 | 150 MMRESULT result; |
157 /* Reset the joystick ID & name mapping tables */ | 151 |
158 for ( i = 0; i < MAX_JOYSTICKS; ++i ) { | 152 /* Reset the joystick ID & name mapping tables */ |
159 SYS_JoystickID[i] = 0; | 153 for (i = 0; i < MAX_JOYSTICKS; ++i) { |
160 SYS_JoystickName[i] = NULL; | 154 SYS_JoystickID[i] = 0; |
161 } | 155 SYS_JoystickName[i] = NULL; |
162 | 156 } |
163 /* Loop over all potential joystick devices */ | 157 |
164 numdevs = 0; | 158 /* Loop over all potential joystick devices */ |
165 maxdevs = joyGetNumDevs(); | 159 numdevs = 0; |
166 for ( i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i ) { | 160 maxdevs = joyGetNumDevs(); |
167 | 161 for (i = JOYSTICKID1; i < maxdevs && numdevs < MAX_JOYSTICKS; ++i) { |
168 joyinfo.dwSize = sizeof(joyinfo); | 162 |
169 joyinfo.dwFlags = JOY_RETURNALL; | 163 joyinfo.dwSize = sizeof(joyinfo); |
170 result = joyGetPosEx(SYS_JoystickID[i], &joyinfo); | 164 joyinfo.dwFlags = JOY_RETURNALL; |
171 if ( result == JOYERR_NOERROR ) { | 165 result = joyGetPosEx(SYS_JoystickID[i], &joyinfo); |
172 result = joyGetDevCaps(i, &joycaps, sizeof(joycaps)); | 166 if (result == JOYERR_NOERROR) { |
173 if ( result == JOYERR_NOERROR ) { | 167 result = joyGetDevCaps(i, &joycaps, sizeof(joycaps)); |
174 SYS_JoystickID[numdevs] = i; | 168 if (result == JOYERR_NOERROR) { |
175 SYS_Joystick[numdevs] = joycaps; | 169 SYS_JoystickID[numdevs] = i; |
176 SYS_JoystickName[numdevs] = GetJoystickName(i, joycaps.szRegKey); | 170 SYS_Joystick[numdevs] = joycaps; |
177 numdevs++; | 171 SYS_JoystickName[numdevs] = |
178 } | 172 GetJoystickName(i, joycaps.szRegKey); |
179 } | 173 numdevs++; |
180 } | 174 } |
181 return(numdevs); | 175 } |
176 } | |
177 return (numdevs); | |
182 } | 178 } |
183 | 179 |
184 /* Function to get the device-dependent name of a joystick */ | 180 /* Function to get the device-dependent name of a joystick */ |
185 const char *SDL_SYS_JoystickName(int index) | 181 const char * |
186 { | 182 SDL_SYS_JoystickName(int index) |
187 if ( SYS_JoystickName[index] != NULL ) { | 183 { |
188 return(SYS_JoystickName[index]); | 184 if (SYS_JoystickName[index] != NULL) { |
189 } else { | 185 return (SYS_JoystickName[index]); |
190 return(SYS_Joystick[index].szPname); | 186 } else { |
191 } | 187 return (SYS_Joystick[index].szPname); |
188 } | |
192 } | 189 } |
193 | 190 |
194 /* Function to open a joystick for use. | 191 /* Function to open a joystick for use. |
195 The joystick to open is specified by the index field of the joystick. | 192 The joystick to open is specified by the index field of the joystick. |
196 This should fill the nbuttons and naxes fields of the joystick structure. | 193 This should fill the nbuttons and naxes fields of the joystick structure. |
197 It returns 0, or -1 if there is an error. | 194 It returns 0, or -1 if there is an error. |
198 */ | 195 */ |
199 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) | 196 int |
200 { | 197 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) |
201 int index, i; | 198 { |
202 int caps_flags[MAX_AXES-2] = | 199 int index, i; |
203 { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV }; | 200 int caps_flags[MAX_AXES - 2] = |
204 int axis_min[MAX_AXES], axis_max[MAX_AXES]; | 201 { JOYCAPS_HASZ, JOYCAPS_HASR, JOYCAPS_HASU, JOYCAPS_HASV }; |
205 | 202 int axis_min[MAX_AXES], axis_max[MAX_AXES]; |
206 | 203 |
207 /* shortcut */ | 204 |
208 index = joystick->index; | 205 /* shortcut */ |
209 axis_min[0] = SYS_Joystick[index].wXmin; | 206 index = joystick->index; |
210 axis_max[0] = SYS_Joystick[index].wXmax; | 207 axis_min[0] = SYS_Joystick[index].wXmin; |
211 axis_min[1] = SYS_Joystick[index].wYmin; | 208 axis_max[0] = SYS_Joystick[index].wXmax; |
212 axis_max[1] = SYS_Joystick[index].wYmax; | 209 axis_min[1] = SYS_Joystick[index].wYmin; |
213 axis_min[2] = SYS_Joystick[index].wZmin; | 210 axis_max[1] = SYS_Joystick[index].wYmax; |
214 axis_max[2] = SYS_Joystick[index].wZmax; | 211 axis_min[2] = SYS_Joystick[index].wZmin; |
215 axis_min[3] = SYS_Joystick[index].wRmin; | 212 axis_max[2] = SYS_Joystick[index].wZmax; |
216 axis_max[3] = SYS_Joystick[index].wRmax; | 213 axis_min[3] = SYS_Joystick[index].wRmin; |
217 axis_min[4] = SYS_Joystick[index].wUmin; | 214 axis_max[3] = SYS_Joystick[index].wRmax; |
218 axis_max[4] = SYS_Joystick[index].wUmax; | 215 axis_min[4] = SYS_Joystick[index].wUmin; |
219 axis_min[5] = SYS_Joystick[index].wVmin; | 216 axis_max[4] = SYS_Joystick[index].wUmax; |
220 axis_max[5] = SYS_Joystick[index].wVmax; | 217 axis_min[5] = SYS_Joystick[index].wVmin; |
221 | 218 axis_max[5] = SYS_Joystick[index].wVmax; |
222 /* allocate memory for system specific hardware data */ | 219 |
223 joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); | 220 /* allocate memory for system specific hardware data */ |
224 if (joystick->hwdata == NULL) | 221 joystick->hwdata = |
225 { | 222 (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata)); |
226 SDL_OutOfMemory(); | 223 if (joystick->hwdata == NULL) { |
227 return(-1); | 224 SDL_OutOfMemory(); |
228 } | 225 return (-1); |
229 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); | 226 } |
230 | 227 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata)); |
231 /* set hardware data */ | 228 |
232 joystick->hwdata->id = SYS_JoystickID[index]; | 229 /* set hardware data */ |
233 for ( i = 0; i < MAX_AXES; ++i ) { | 230 joystick->hwdata->id = SYS_JoystickID[index]; |
234 if ( (i<2) || (SYS_Joystick[index].wCaps & caps_flags[i-2]) ) { | 231 for (i = 0; i < MAX_AXES; ++i) { |
235 joystick->hwdata->transaxis[i].offset = | 232 if ((i < 2) || (SYS_Joystick[index].wCaps & caps_flags[i - 2])) { |
236 AXIS_MIN - axis_min[i]; | 233 joystick->hwdata->transaxis[i].offset = AXIS_MIN - axis_min[i]; |
237 joystick->hwdata->transaxis[i].scale = | 234 joystick->hwdata->transaxis[i].scale = |
238 (float)(AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]); | 235 (float) (AXIS_MAX - AXIS_MIN) / (axis_max[i] - axis_min[i]); |
239 } else { | 236 } else { |
240 joystick->hwdata->transaxis[i].offset = 0; | 237 joystick->hwdata->transaxis[i].offset = 0; |
241 joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */ | 238 joystick->hwdata->transaxis[i].scale = 1.0; /* Just in case */ |
242 } | 239 } |
243 } | 240 } |
244 | 241 |
245 /* fill nbuttons, naxes, and nhats fields */ | 242 /* fill nbuttons, naxes, and nhats fields */ |
246 joystick->nbuttons = SYS_Joystick[index].wNumButtons; | 243 joystick->nbuttons = SYS_Joystick[index].wNumButtons; |
247 joystick->naxes = SYS_Joystick[index].wNumAxes; | 244 joystick->naxes = SYS_Joystick[index].wNumAxes; |
248 if ( SYS_Joystick[index].wCaps & JOYCAPS_HASPOV ) { | 245 if (SYS_Joystick[index].wCaps & JOYCAPS_HASPOV) { |
249 joystick->nhats = 1; | 246 joystick->nhats = 1; |
250 } else { | 247 } else { |
251 joystick->nhats = 0; | 248 joystick->nhats = 0; |
252 } | 249 } |
253 return(0); | 250 return (0); |
254 } | 251 } |
255 | 252 |
256 static Uint8 TranslatePOV(DWORD value) | 253 static Uint8 |
257 { | 254 TranslatePOV(DWORD value) |
258 Uint8 pos; | 255 { |
259 | 256 Uint8 pos; |
260 pos = SDL_HAT_CENTERED; | 257 |
261 if ( value != JOY_POVCENTERED ) { | 258 pos = SDL_HAT_CENTERED; |
262 if ( (value > JOY_POVLEFT) || (value < JOY_POVRIGHT) ) { | 259 if (value != JOY_POVCENTERED) { |
263 pos |= SDL_HAT_UP; | 260 if ((value > JOY_POVLEFT) || (value < JOY_POVRIGHT)) { |
264 } | 261 pos |= SDL_HAT_UP; |
265 if ( (value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD) ) { | 262 } |
266 pos |= SDL_HAT_RIGHT; | 263 if ((value > JOY_POVFORWARD) && (value < JOY_POVBACKWARD)) { |
267 } | 264 pos |= SDL_HAT_RIGHT; |
268 if ( (value > JOY_POVRIGHT) && (value < JOY_POVLEFT) ) { | 265 } |
269 pos |= SDL_HAT_DOWN; | 266 if ((value > JOY_POVRIGHT) && (value < JOY_POVLEFT)) { |
270 } | 267 pos |= SDL_HAT_DOWN; |
271 if ( value > JOY_POVBACKWARD ) { | 268 } |
272 pos |= SDL_HAT_LEFT; | 269 if (value > JOY_POVBACKWARD) { |
273 } | 270 pos |= SDL_HAT_LEFT; |
274 } | 271 } |
275 return(pos); | 272 } |
273 return (pos); | |
276 } | 274 } |
277 | 275 |
278 /* Function to update the state of a joystick - called as a device poll. | 276 /* Function to update the state of a joystick - called as a device poll. |
279 * This function shouldn't update the joystick structure directly, | 277 * This function shouldn't update the joystick structure directly, |
280 * but instead should call SDL_PrivateJoystick*() to deliver events | 278 * but instead should call SDL_PrivateJoystick*() to deliver events |
281 * and update joystick device state. | 279 * and update joystick device state. |
282 */ | 280 */ |
283 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) | 281 void |
284 { | 282 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
285 MMRESULT result; | 283 { |
286 int i; | 284 MMRESULT result; |
287 DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, | 285 int i; |
288 JOY_RETURNR, JOY_RETURNU, JOY_RETURNV }; | 286 DWORD flags[MAX_AXES] = { JOY_RETURNX, JOY_RETURNY, JOY_RETURNZ, |
289 DWORD pos[MAX_AXES]; | 287 JOY_RETURNR, JOY_RETURNU, JOY_RETURNV |
290 struct _transaxis *transaxis; | 288 }; |
291 int value, change; | 289 DWORD pos[MAX_AXES]; |
292 JOYINFOEX joyinfo; | 290 struct _transaxis *transaxis; |
293 | 291 int value, change; |
294 joyinfo.dwSize = sizeof(joyinfo); | 292 JOYINFOEX joyinfo; |
295 joyinfo.dwFlags = JOY_RETURNALL|JOY_RETURNPOVCTS; | 293 |
296 if ( ! joystick->hats ) { | 294 joyinfo.dwSize = sizeof(joyinfo); |
297 joyinfo.dwFlags &= ~(JOY_RETURNPOV|JOY_RETURNPOVCTS); | 295 joyinfo.dwFlags = JOY_RETURNALL | JOY_RETURNPOVCTS; |
298 } | 296 if (!joystick->hats) { |
299 result = joyGetPosEx(joystick->hwdata->id, &joyinfo); | 297 joyinfo.dwFlags &= ~(JOY_RETURNPOV | JOY_RETURNPOVCTS); |
300 if ( result != JOYERR_NOERROR ) { | 298 } |
301 SetMMerror("joyGetPosEx", result); | 299 result = joyGetPosEx(joystick->hwdata->id, &joyinfo); |
302 return; | 300 if (result != JOYERR_NOERROR) { |
303 } | 301 SetMMerror("joyGetPosEx", result); |
304 | 302 return; |
305 /* joystick motion events */ | 303 } |
306 pos[0] = joyinfo.dwXpos; | 304 |
307 pos[1] = joyinfo.dwYpos; | 305 /* joystick motion events */ |
308 pos[2] = joyinfo.dwZpos; | 306 pos[0] = joyinfo.dwXpos; |
309 pos[3] = joyinfo.dwRpos; | 307 pos[1] = joyinfo.dwYpos; |
310 pos[4] = joyinfo.dwUpos; | 308 pos[2] = joyinfo.dwZpos; |
311 pos[5] = joyinfo.dwVpos; | 309 pos[3] = joyinfo.dwRpos; |
312 | 310 pos[4] = joyinfo.dwUpos; |
313 transaxis = joystick->hwdata->transaxis; | 311 pos[5] = joyinfo.dwVpos; |
314 for (i = 0; i < joystick->naxes; i++) { | 312 |
315 if (joyinfo.dwFlags & flags[i]) { | 313 transaxis = joystick->hwdata->transaxis; |
316 value = (int)(((float)pos[i] + transaxis[i].offset) * transaxis[i].scale); | 314 for (i = 0; i < joystick->naxes; i++) { |
317 change = (value - joystick->axes[i]); | 315 if (joyinfo.dwFlags & flags[i]) { |
318 if ( (change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD) ) { | 316 value = |
319 SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)value); | 317 (int) (((float) pos[i] + |
320 } | 318 transaxis[i].offset) * transaxis[i].scale); |
321 } | 319 change = (value - joystick->axes[i]); |
322 } | 320 if ((change < -JOY_AXIS_THRESHOLD) |
323 | 321 || (change > JOY_AXIS_THRESHOLD)) { |
324 /* joystick button events */ | 322 SDL_PrivateJoystickAxis(joystick, (Uint8) i, (Sint16) value); |
325 if ( joyinfo.dwFlags & JOY_RETURNBUTTONS ) { | 323 } |
326 for ( i = 0; i < joystick->nbuttons; ++i ) { | 324 } |
327 if ( joyinfo.dwButtons & JOY_BUTTON_FLAG(i) ) { | 325 } |
328 if ( ! joystick->buttons[i] ) { | 326 |
329 SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_PRESSED); | 327 /* joystick button events */ |
330 } | 328 if (joyinfo.dwFlags & JOY_RETURNBUTTONS) { |
331 } else { | 329 for (i = 0; i < joystick->nbuttons; ++i) { |
332 if ( joystick->buttons[i] ) { | 330 if (joyinfo.dwButtons & JOY_BUTTON_FLAG(i)) { |
333 SDL_PrivateJoystickButton(joystick, (Uint8)i, SDL_RELEASED); | 331 if (!joystick->buttons[i]) { |
334 } | 332 SDL_PrivateJoystickButton(joystick, (Uint8) i, |
335 } | 333 SDL_PRESSED); |
336 } | 334 } |
337 } | 335 } else { |
338 | 336 if (joystick->buttons[i]) { |
339 /* joystick hat events */ | 337 SDL_PrivateJoystickButton(joystick, (Uint8) i, |
340 if ( joyinfo.dwFlags & JOY_RETURNPOV ) { | 338 SDL_RELEASED); |
341 Uint8 pos; | 339 } |
342 | 340 } |
343 pos = TranslatePOV(joyinfo.dwPOV); | 341 } |
344 if ( pos != joystick->hats[0] ) { | 342 } |
345 SDL_PrivateJoystickHat(joystick, 0, pos); | 343 |
346 } | 344 /* joystick hat events */ |
347 } | 345 if (joyinfo.dwFlags & JOY_RETURNPOV) { |
346 Uint8 pos; | |
347 | |
348 pos = TranslatePOV(joyinfo.dwPOV); | |
349 if (pos != joystick->hats[0]) { | |
350 SDL_PrivateJoystickHat(joystick, 0, pos); | |
351 } | |
352 } | |
348 } | 353 } |
349 | 354 |
350 /* Function to close a joystick after use */ | 355 /* Function to close a joystick after use */ |
351 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) | 356 void |
352 { | 357 SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
353 if (joystick->hwdata != NULL) { | 358 { |
354 /* free system specific hardware data */ | 359 if (joystick->hwdata != NULL) { |
355 SDL_free(joystick->hwdata); | 360 /* free system specific hardware data */ |
356 } | 361 SDL_free(joystick->hwdata); |
362 } | |
357 } | 363 } |
358 | 364 |
359 /* Function to perform any system-specific joystick related cleanup */ | 365 /* Function to perform any system-specific joystick related cleanup */ |
360 void SDL_SYS_JoystickQuit(void) | 366 void |
361 { | 367 SDL_SYS_JoystickQuit(void) |
362 int i; | 368 { |
363 for (i = 0; i < MAX_JOYSTICKS; i++) { | 369 int i; |
364 if ( SYS_JoystickName[i] != NULL ) { | 370 for (i = 0; i < MAX_JOYSTICKS; i++) { |
365 SDL_free(SYS_JoystickName[i]); | 371 if (SYS_JoystickName[i] != NULL) { |
366 } | 372 SDL_free(SYS_JoystickName[i]); |
367 } | 373 } |
374 } | |
368 } | 375 } |
369 | 376 |
370 | 377 |
371 /* implementation functions */ | 378 /* implementation functions */ |
372 void SetMMerror(char *function, int code) | 379 void |
373 { | 380 SetMMerror(char *function, int code) |
374 static char *error; | 381 { |
375 static char errbuf[1024]; | 382 static char *error; |
376 | 383 static char errbuf[1024]; |
377 errbuf[0] = 0; | 384 |
378 switch (code) | 385 errbuf[0] = 0; |
379 { | 386 switch (code) { |
380 case MMSYSERR_NODRIVER: | 387 case MMSYSERR_NODRIVER: |
381 error = "Joystick driver not present"; | 388 error = "Joystick driver not present"; |
382 break; | 389 break; |
383 | 390 |
384 case MMSYSERR_INVALPARAM: | 391 case MMSYSERR_INVALPARAM: |
385 case JOYERR_PARMS: | 392 case JOYERR_PARMS: |
386 error = "Invalid parameter(s)"; | 393 error = "Invalid parameter(s)"; |
387 break; | 394 break; |
388 | 395 |
389 case MMSYSERR_BADDEVICEID: | 396 case MMSYSERR_BADDEVICEID: |
390 error = "Bad device ID"; | 397 error = "Bad device ID"; |
391 break; | 398 break; |
392 | 399 |
393 case JOYERR_UNPLUGGED: | 400 case JOYERR_UNPLUGGED: |
394 error = "Joystick not attached"; | 401 error = "Joystick not attached"; |
395 break; | 402 break; |
396 | 403 |
397 case JOYERR_NOCANDO: | 404 case JOYERR_NOCANDO: |
398 error = "Can't capture joystick input"; | 405 error = "Can't capture joystick input"; |
399 break; | 406 break; |
400 | 407 |
401 default: | 408 default: |
402 SDL_snprintf(errbuf, SDL_arraysize(errbuf), | 409 SDL_snprintf(errbuf, SDL_arraysize(errbuf), |
403 "%s: Unknown Multimedia system error: 0x%x", | 410 "%s: Unknown Multimedia system error: 0x%x", |
404 function, code); | 411 function, code); |
405 break; | 412 break; |
406 } | 413 } |
407 | 414 |
408 if ( ! errbuf[0] ) { | 415 if (!errbuf[0]) { |
409 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, error); | 416 SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: %s", function, |
410 } | 417 error); |
411 SDL_SetError("%s", errbuf); | 418 } |
419 SDL_SetError("%s", errbuf); | |
412 } | 420 } |
413 | 421 |
414 #endif /* SDL_JOYSTICK_WINMM */ | 422 #endif /* SDL_JOYSTICK_WINMM */ |
423 /* vi: set ts=4 sw=4 expandtab: */ |