comparison src/joystick/os2/SDL_sysjoystick.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
91 unsigned int hats; 91 unsigned int hats;
92 unsigned int balls; 92 unsigned int balls;
93 }; 93 };
94 94
95 /* OS/2 Implementation Function Prototypes */ 95 /* OS/2 Implementation Function Prototypes */
96 APIRET joyPortOpen (HFILE * hGame); 96 APIRET joyPortOpen(HFILE * hGame);
97 void joyPortClose (HFILE * hGame); 97 void joyPortClose(HFILE * hGame);
98 int joyGetData (char *joyenv, char *name, char stopchar, size_t maxchars); 98 int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars);
99 int joyGetEnv (struct _joycfg *joydata); 99 int joyGetEnv(struct _joycfg *joydata);
100 100
101 101
102 102
103 /************************************************************************/ 103 /************************************************************************/
104 /* Function to scan the system for joysticks. */ 104 /* Function to scan the system for joysticks. */
105 /* This function should set SDL_numjoysticks to the number of available */ 105 /* This function should set SDL_numjoysticks to the number of available */
106 /* joysticks. Joystick 0 should be the system default joystick. */ 106 /* joysticks. Joystick 0 should be the system default joystick. */
107 /* It should return 0, or -1 on an unrecoverable fatal error. */ 107 /* It should return 0, or -1 on an unrecoverable fatal error. */
108 /************************************************************************/ 108 /************************************************************************/
109 int 109 int
110 SDL_SYS_JoystickInit (void) 110 SDL_SYS_JoystickInit(void)
111 { 111 {
112 APIRET rc; /* Generic OS/2 return code */ 112 APIRET rc; /* Generic OS/2 return code */
113 GAME_PORT_STRUCT stJoyStatus; /* Joystick Status Structure */ 113 GAME_PORT_STRUCT stJoyStatus; /* Joystick Status Structure */
114 GAME_PARM_STRUCT stGameParms; /* Joystick Parameter Structure */ 114 GAME_PARM_STRUCT stGameParms; /* Joystick Parameter Structure */
115 GAME_CALIB_STRUCT stGameCalib; /* Calibration Struct */ 115 GAME_CALIB_STRUCT stGameCalib; /* Calibration Struct */
122 Uint8 ucNewJoystickMask; /* Mask for Joystick Detection */ 122 Uint8 ucNewJoystickMask; /* Mask for Joystick Detection */
123 struct _joycfg joycfg; /* Joy Configuration from envvar */ 123 struct _joycfg joycfg; /* Joy Configuration from envvar */
124 124
125 125
126 /* Get Max Number of Devices */ 126 /* Get Max Number of Devices */
127 rc = joyPortOpen (&hJoyPort); /* Open GAME$ port */ 127 rc = joyPortOpen(&hJoyPort); /* Open GAME$ port */
128 if (rc != 0) 128 if (rc != 0)
129 return 0; /* Cannot open... report no joystick */ 129 return 0; /* Cannot open... report no joystick */
130 ulDataLen = sizeof (stGameParms); 130 ulDataLen = sizeof(stGameParms);
131 rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_GET_PARMS, NULL, 0, NULL, &stGameParms, ulDataLen, &ulDataLen); /* Ask device info */ 131 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_PARMS, NULL, 0, NULL, &stGameParms, ulDataLen, &ulDataLen); /* Ask device info */
132 if (rc != 0) { 132 if (rc != 0) {
133 joyPortClose (&hJoyPort); 133 joyPortClose(&hJoyPort);
134 SDL_SetError ("Could not read joystick port."); 134 SDL_SetError("Could not read joystick port.");
135 return -1; 135 return -1;
136 } 136 }
137 if (stGameParms.useA != 0) 137 if (stGameParms.useA != 0)
138 maxdevs++; 138 maxdevs++;
139 if (stGameParms.useB != 0) 139 if (stGameParms.useB != 0)
140 maxdevs++; 140 maxdevs++;
141 if (maxdevs > MAX_JOYSTICKS) 141 if (maxdevs > MAX_JOYSTICKS)
142 maxdevs = MAX_JOYSTICKS; 142 maxdevs = MAX_JOYSTICKS;
143 143
144 /* Defines min/max axes values (callibration) */ 144 /* Defines min/max axes values (callibration) */
145 ulDataLen = sizeof (stGameCalib); 145 ulDataLen = sizeof(stGameCalib);
146 rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_GET_CALIB, 146 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_CALIB,
147 NULL, 0, NULL, &stGameCalib, ulDataLen, &ulDataLen); 147 NULL, 0, NULL, &stGameCalib, ulDataLen, &ulDataLen);
148 if (rc != 0) { 148 if (rc != 0) {
149 joyPortClose (&hJoyPort); 149 joyPortClose(&hJoyPort);
150 SDL_SetError ("Could not read callibration data."); 150 SDL_SetError("Could not read callibration data.");
151 return -1; 151 return -1;
152 } 152 }
153 153
154 /* Determine how many joysticks are active */ 154 /* Determine how many joysticks are active */
155 numdevs = 0; /* Points no device */ 155 numdevs = 0; /* Points no device */
156 ucNewJoystickMask = 0x0F; /* read all 4 joystick axis */ 156 ucNewJoystickMask = 0x0F; /* read all 4 joystick axis */
157 ulDataLen = sizeof (ucNewJoystickMask); 157 ulDataLen = sizeof(ucNewJoystickMask);
158 rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_PORT_RESET, 158 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_RESET,
159 &ucNewJoystickMask, ulDataLen, &ulDataLen, NULL, 0, 159 &ucNewJoystickMask, ulDataLen, &ulDataLen, NULL, 0,
160 NULL); 160 NULL);
161 if (rc == 0) { 161 if (rc == 0) {
162 ulDataLen = sizeof (stJoyStatus); 162 ulDataLen = sizeof(stJoyStatus);
163 rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET, 163 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
164 NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen); 164 NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen);
165 if (rc != 0) { 165 if (rc != 0) {
166 joyPortClose (&hJoyPort); 166 joyPortClose(&hJoyPort);
167 SDL_SetError ("Could not call joystick port."); 167 SDL_SetError("Could not call joystick port.");
168 return -1; 168 return -1;
169 } 169 }
170 ulLastTick = stJoyStatus.ulJs_Ticks; 170 ulLastTick = stJoyStatus.ulJs_Ticks;
171 while (stJoyStatus.ulJs_Ticks == ulLastTick) { 171 while (stJoyStatus.ulJs_Ticks == ulLastTick) {
172 rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET, 172 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
173 NULL, 0, NULL, &stJoyStatus, ulDataLen, 173 NULL, 0, NULL, &stJoyStatus, ulDataLen,
174 &ulDataLen); 174 &ulDataLen);
175 } 175 }
176 if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) 176 if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0)
177 numdevs++; 177 numdevs++;
178 if (((stJoyStatus.ucJs_JoyStickMask >> 2) & 0x03) > 0) 178 if (((stJoyStatus.ucJs_JoyStickMask >> 2) & 0x03) > 0)
179 numdevs++; 179 numdevs++;
183 numdevs = maxdevs; 183 numdevs = maxdevs;
184 184
185 /* If *any* joystick was detected... Let's configure SDL for them */ 185 /* If *any* joystick was detected... Let's configure SDL for them */
186 if (numdevs > 0) { 186 if (numdevs > 0) {
187 /* Verify if it is a "user defined" joystick */ 187 /* Verify if it is a "user defined" joystick */
188 if (joyGetEnv (&joycfg)) { 188 if (joyGetEnv(&joycfg)) {
189 GAME_3POS_STRUCT *axis[4]; 189 GAME_3POS_STRUCT *axis[4];
190 axis[0] = &stGameCalib.Ax; 190 axis[0] = &stGameCalib.Ax;
191 axis[1] = &stGameCalib.Ay; 191 axis[1] = &stGameCalib.Ay;
192 axis[2] = &stGameCalib.Bx; 192 axis[2] = &stGameCalib.Bx;
193 axis[3] = &stGameCalib.By; 193 axis[3] = &stGameCalib.By;
232 ((axis[2]->upper + axis[3]->centre) >> 1); 232 ((axis[2]->upper + axis[3]->centre) >> 1);
233 if (joycfg.buttons >= 8) 233 if (joycfg.buttons >= 8)
234 SYS_JoyData[0].buttoncalc[3] = 234 SYS_JoyData[0].buttoncalc[3] =
235 ((axis[3]->upper + axis[3]->centre) >> 1); 235 ((axis[3]->upper + axis[3]->centre) >> 1);
236 /* Intialize Joystick Name */ 236 /* Intialize Joystick Name */
237 SDL_strlcpy (SYS_JoyData[0].szDeviceName, joycfg.name, 237 SDL_strlcpy(SYS_JoyData[0].szDeviceName, joycfg.name,
238 SDL_arraysize (SYS_JoyData[0].szDeviceName)); 238 SDL_arraysize(SYS_JoyData[0].szDeviceName));
239 } 239 }
240 /* Default Init ... autoconfig */ 240 /* Default Init ... autoconfig */
241 else { 241 else {
242 /* if two devices were detected... configure as Joy1 4 axis and Joy2 2 axis */ 242 /* if two devices were detected... configure as Joy1 4 axis and Joy2 2 axis */
243 if (numdevs == 2) { 243 if (numdevs == 2) {
307 } 307 }
308 /* Hack to define Joystick Port Names */ 308 /* Hack to define Joystick Port Names */
309 if (numdevs > maxdevs) 309 if (numdevs > maxdevs)
310 numdevs = maxdevs; 310 numdevs = maxdevs;
311 for (i = 0; i < numdevs; i++) 311 for (i = 0; i < numdevs; i++)
312 SDL_snprintf (SYS_JoyData[i].szDeviceName, 312 SDL_snprintf(SYS_JoyData[i].szDeviceName,
313 SDL_arraysize (SYS_JoyData[i].szDeviceName), 313 SDL_arraysize(SYS_JoyData[i].szDeviceName),
314 "Default Joystick %c", 'A' + SYS_JoyData[i].id); 314 "Default Joystick %c", 'A' + SYS_JoyData[i].id);
315 315
316 } 316 }
317 } 317 }
318 /* Return the number of devices found */ 318 /* Return the number of devices found */
319 return (numdevs); 319 return (numdevs);
322 322
323 /***********************************************************/ 323 /***********************************************************/
324 /* Function to get the device-dependent name of a joystick */ 324 /* Function to get the device-dependent name of a joystick */
325 /***********************************************************/ 325 /***********************************************************/
326 const char * 326 const char *
327 SDL_SYS_JoystickName (int index) 327 SDL_SYS_JoystickName(int index)
328 { 328 {
329 /* No need to verify if device exists, already done in upper layer */ 329 /* No need to verify if device exists, already done in upper layer */
330 return (SYS_JoyData[index].szDeviceName); 330 return (SYS_JoyData[index].szDeviceName);
331 } 331 }
332 332
337 /* The joystick to open is specified by the index field of the joystick. */ 337 /* The joystick to open is specified by the index field of the joystick. */
338 /* This should fill the nbuttons and naxes fields of the joystick structure. */ 338 /* This should fill the nbuttons and naxes fields of the joystick structure. */
339 /* It returns 0, or -1 if there is an error. */ 339 /* It returns 0, or -1 if there is an error. */
340 /******************************************************************************/ 340 /******************************************************************************/
341 int 341 int
342 SDL_SYS_JoystickOpen (SDL_Joystick * joystick) 342 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
343 { 343 {
344 int index; /* Index shortcut for index in joystick structure */ 344 int index; /* Index shortcut for index in joystick structure */
345 int i; /* Generic Counter */ 345 int i; /* Generic Counter */
346 346
347 /* allocate memory for system specific hardware data */ 347 /* allocate memory for system specific hardware data */
348 joystick->hwdata = 348 joystick->hwdata =
349 (struct joystick_hwdata *) SDL_malloc (sizeof (*joystick->hwdata)); 349 (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
350 if (joystick->hwdata == NULL) { 350 if (joystick->hwdata == NULL) {
351 SDL_OutOfMemory (); 351 SDL_OutOfMemory();
352 return (-1); 352 return (-1);
353 } 353 }
354 /* Reset Hardware Data */ 354 /* Reset Hardware Data */
355 SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); 355 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
356 356
357 /* ShortCut Pointer */ 357 /* ShortCut Pointer */
358 index = joystick->index; 358 index = joystick->index;
359 /* Define offsets and scales for all axes */ 359 /* Define offsets and scales for all axes */
360 joystick->hwdata->id = SYS_JoyData[index].id; 360 joystick->hwdata->id = SYS_JoyData[index].id;
362 if ((i < 2) || i < SYS_JoyData[index].axes) { 362 if ((i < 2) || i < SYS_JoyData[index].axes) {
363 joystick->hwdata->transaxes[i].offset = 363 joystick->hwdata->transaxes[i].offset =
364 ((AXIS_MAX + AXIS_MIN) >> 1) - SYS_JoyData[index].axes_med[i]; 364 ((AXIS_MAX + AXIS_MIN) >> 1) - SYS_JoyData[index].axes_med[i];
365 //joystick->hwdata->transaxes[i].scale = (float)((AXIS_MAX - AXIS_MIN)/(SYS_JoyData[index].axes_max[i]-SYS_JoyData[index].axes_min[i])); 365 //joystick->hwdata->transaxes[i].scale = (float)((AXIS_MAX - AXIS_MIN)/(SYS_JoyData[index].axes_max[i]-SYS_JoyData[index].axes_min[i]));
366 joystick->hwdata->transaxes[i].scale1 = 366 joystick->hwdata->transaxes[i].scale1 =
367 (float) abs ((AXIS_MIN / SYS_JoyData[index].axes_min[i])); 367 (float) abs((AXIS_MIN / SYS_JoyData[index].axes_min[i]));
368 joystick->hwdata->transaxes[i].scale2 = 368 joystick->hwdata->transaxes[i].scale2 =
369 (float) abs ((AXIS_MAX / SYS_JoyData[index].axes_max[i])); 369 (float) abs((AXIS_MAX / SYS_JoyData[index].axes_max[i]));
370 } else { 370 } else {
371 joystick->hwdata->transaxes[i].offset = 0; 371 joystick->hwdata->transaxes[i].offset = 0;
372 //joystick->hwdata->transaxes[i].scale = 1.0; /* Just in case */ 372 //joystick->hwdata->transaxes[i].scale = 1.0; /* Just in case */
373 joystick->hwdata->transaxes[i].scale1 = 1.0; /* Just in case */ 373 joystick->hwdata->transaxes[i].scale1 = 1.0; /* Just in case */
374 joystick->hwdata->transaxes[i].scale2 = 1.0; /* Just in case */ 374 joystick->hwdata->transaxes[i].scale2 = 1.0; /* Just in case */
392 /* This function shouldn't update the joystick structure directly, */ 392 /* This function shouldn't update the joystick structure directly, */
393 /* but instead should call SDL_PrivateJoystick*() to deliver events */ 393 /* but instead should call SDL_PrivateJoystick*() to deliver events */
394 /* and update joystick device state. */ 394 /* and update joystick device state. */
395 /***************************************************************************/ 395 /***************************************************************************/
396 void 396 void
397 SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) 397 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
398 { 398 {
399 APIRET rc; /* Generic OS/2 return code */ 399 APIRET rc; /* Generic OS/2 return code */
400 int index; /* index shortcurt to joystick index */ 400 int index; /* index shortcurt to joystick index */
401 int i; /* Generic counter */ 401 int i; /* Generic counter */
402 int normbut; /* Number of buttons reported by joystick */ 402 int normbut; /* Number of buttons reported by joystick */
405 struct _transaxes *transaxes; /* Shortcut for Correction structure */ 405 struct _transaxes *transaxes; /* Shortcut for Correction structure */
406 Uint32 pos[MAX_AXES]; /* Vector to inform the Axis status */ 406 Uint32 pos[MAX_AXES]; /* Vector to inform the Axis status */
407 ULONG ulDataLen; /* Size of data */ 407 ULONG ulDataLen; /* Size of data */
408 GAME_STATUS_STRUCT stGameStatus; /* Joystick Status Structure */ 408 GAME_STATUS_STRUCT stGameStatus; /* Joystick Status Structure */
409 409
410 ulDataLen = sizeof (stGameStatus); 410 ulDataLen = sizeof(stGameStatus);
411 rc = DosDevIOCtl (hJoyPort, IOCTL_CAT_USER, GAME_GET_STATUS, 411 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_STATUS,
412 NULL, 0, NULL, &stGameStatus, ulDataLen, &ulDataLen); 412 NULL, 0, NULL, &stGameStatus, ulDataLen, &ulDataLen);
413 if (rc != 0) { 413 if (rc != 0) {
414 SDL_SetError ("Could not read joystick status."); 414 SDL_SetError("Could not read joystick status.");
415 return; /* Could not read data */ 415 return; /* Could not read data */
416 } 416 }
417 417
418 /* Shortcut pointer */ 418 /* Shortcut pointer */
419 index = joystick->index; 419 index = joystick->index;
454 if (value < 0) 454 if (value < 0)
455 value = AXIS_MAX; 455 value = AXIS_MAX;
456 } 456 }
457 change = (value - joystick->axes[i]); 457 change = (value - joystick->axes[i]);
458 if ((change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD)) { 458 if ((change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD)) {
459 SDL_PrivateJoystickAxis (joystick, (Uint8) i, (Sint16) value); 459 SDL_PrivateJoystickAxis(joystick, (Uint8) i, (Sint16) value);
460 } 460 }
461 } 461 }
462 462
463 /* joystick button A to D events */ 463 /* joystick button A to D events */
464 if (SYS_JoyData[index].id == 1) 464 if (SYS_JoyData[index].id == 1)
473 Button A: 1110 0000 473 Button A: 1110 0000
474 Button B: 1101 0000 474 Button B: 1101 0000
475 Button C: 1011 0000 475 Button C: 1011 0000
476 Button D: 0111 0000 476 Button D: 0111 0000
477 */ 477 */
478 if ((~stGameStatus.curdata.butMask) >> 4 & JOY_BUTTON_FLAG (i)) { 478 if ((~stGameStatus.curdata.butMask) >> 4 & JOY_BUTTON_FLAG(i)) {
479 if (!joystick->buttons[i - corr]) { 479 if (!joystick->buttons[i - corr]) {
480 SDL_PrivateJoystickButton (joystick, (Uint8) (i - corr), 480 SDL_PrivateJoystickButton(joystick, (Uint8) (i - corr),
481 SDL_PRESSED); 481 SDL_PRESSED);
482 } 482 }
483 } else { 483 } else {
484 if (joystick->buttons[i - corr]) { 484 if (joystick->buttons[i - corr]) {
485 SDL_PrivateJoystickButton (joystick, (Uint8) (i - corr), 485 SDL_PrivateJoystickButton(joystick, (Uint8) (i - corr),
486 SDL_RELEASED); 486 SDL_RELEASED);
487 } 487 }
488 } 488 }
489 } 489 }
490 490
491 /* Joystick button E to H buttons */ 491 /* Joystick button E to H buttons */
495 Button G: Axis 2 X Right 495 Button G: Axis 2 X Right
496 Button H: Axis 2 Y Down 496 Button H: Axis 2 Y Down
497 */ 497 */
498 if (joystick->nbuttons >= 5) { 498 if (joystick->nbuttons >= 5) {
499 if (stGameStatus.curdata.B.x < SYS_JoyData[index].buttoncalc[0]) 499 if (stGameStatus.curdata.B.x < SYS_JoyData[index].buttoncalc[0])
500 SDL_PrivateJoystickButton (joystick, (Uint8) 4, SDL_PRESSED); 500 SDL_PrivateJoystickButton(joystick, (Uint8) 4, SDL_PRESSED);
501 else 501 else
502 SDL_PrivateJoystickButton (joystick, (Uint8) 4, SDL_RELEASED); 502 SDL_PrivateJoystickButton(joystick, (Uint8) 4, SDL_RELEASED);
503 } 503 }
504 if (joystick->nbuttons >= 6) { 504 if (joystick->nbuttons >= 6) {
505 if (stGameStatus.curdata.B.y < SYS_JoyData[index].buttoncalc[1]) 505 if (stGameStatus.curdata.B.y < SYS_JoyData[index].buttoncalc[1])
506 SDL_PrivateJoystickButton (joystick, (Uint8) 5, SDL_PRESSED); 506 SDL_PrivateJoystickButton(joystick, (Uint8) 5, SDL_PRESSED);
507 else 507 else
508 SDL_PrivateJoystickButton (joystick, (Uint8) 5, SDL_RELEASED); 508 SDL_PrivateJoystickButton(joystick, (Uint8) 5, SDL_RELEASED);
509 } 509 }
510 if (joystick->nbuttons >= 7) { 510 if (joystick->nbuttons >= 7) {
511 if (stGameStatus.curdata.B.x > SYS_JoyData[index].buttoncalc[2]) 511 if (stGameStatus.curdata.B.x > SYS_JoyData[index].buttoncalc[2])
512 SDL_PrivateJoystickButton (joystick, (Uint8) 6, SDL_PRESSED); 512 SDL_PrivateJoystickButton(joystick, (Uint8) 6, SDL_PRESSED);
513 else 513 else
514 SDL_PrivateJoystickButton (joystick, (Uint8) 6, SDL_RELEASED); 514 SDL_PrivateJoystickButton(joystick, (Uint8) 6, SDL_RELEASED);
515 } 515 }
516 if (joystick->nbuttons >= 8) { 516 if (joystick->nbuttons >= 8) {
517 if (stGameStatus.curdata.B.y > SYS_JoyData[index].buttoncalc[3]) 517 if (stGameStatus.curdata.B.y > SYS_JoyData[index].buttoncalc[3])
518 SDL_PrivateJoystickButton (joystick, (Uint8) 7, SDL_PRESSED); 518 SDL_PrivateJoystickButton(joystick, (Uint8) 7, SDL_PRESSED);
519 else 519 else
520 SDL_PrivateJoystickButton (joystick, (Uint8) 7, SDL_RELEASED); 520 SDL_PrivateJoystickButton(joystick, (Uint8) 7, SDL_RELEASED);
521 } 521 }
522 522
523 /* joystick hat events */ 523 /* joystick hat events */
524 /* Not Supported under OS/2 */ 524 /* Not Supported under OS/2 */
525 /* joystick ball events */ 525 /* joystick ball events */
530 530
531 /******************************************/ 531 /******************************************/
532 /* Function to close a joystick after use */ 532 /* Function to close a joystick after use */
533 /******************************************/ 533 /******************************************/
534 void 534 void
535 SDL_SYS_JoystickClose (SDL_Joystick * joystick) 535 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
536 { 536 {
537 if (joystick->hwdata != NULL) { 537 if (joystick->hwdata != NULL) {
538 /* free system specific hardware data */ 538 /* free system specific hardware data */
539 SDL_free (joystick->hwdata); 539 SDL_free(joystick->hwdata);
540 } 540 }
541 } 541 }
542 542
543 543
544 544
545 /********************************************************************/ 545 /********************************************************************/
546 /* Function to perform any system-specific joystick related cleanup */ 546 /* Function to perform any system-specific joystick related cleanup */
547 /********************************************************************/ 547 /********************************************************************/
548 void 548 void
549 SDL_SYS_JoystickQuit (void) 549 SDL_SYS_JoystickQuit(void)
550 { 550 {
551 joyPortClose (&hJoyPort); 551 joyPortClose(&hJoyPort);
552 } 552 }
553 553
554 554
555 555
556 /************************/ 556 /************************/
562 562
563 /*****************************************/ 563 /*****************************************/
564 /* Open Joystick Port, if not opened yet */ 564 /* Open Joystick Port, if not opened yet */
565 /*****************************************/ 565 /*****************************************/
566 APIRET 566 APIRET
567 joyPortOpen (HFILE * hGame) 567 joyPortOpen(HFILE * hGame)
568 { 568 {
569 APIRET rc; /* Generic Return Code */ 569 APIRET rc; /* Generic Return Code */
570 ULONG ulAction; /* ? */ 570 ULONG ulAction; /* ? */
571 ULONG ulVersion; /* Version of joystick driver */ 571 ULONG ulVersion; /* Version of joystick driver */
572 ULONG ulDataLen; /* Size of version data */ 572 ULONG ulDataLen; /* Size of version data */
573 573
574 /* Verifies if joyport is not already open... */ 574 /* Verifies if joyport is not already open... */
575 if (*hGame != NULL) 575 if (*hGame != NULL)
576 return 0; 576 return 0;
577 /* Open GAME$ for read */ 577 /* Open GAME$ for read */
578 rc = DosOpen ((PSZ) GAMEPDDNAME, hGame, &ulAction, 0, FILE_READONLY, 578 rc = DosOpen((PSZ) GAMEPDDNAME, hGame, &ulAction, 0, FILE_READONLY,
579 FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 579 FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL);
580 NULL);
581 if (rc != 0) { 580 if (rc != 0) {
582 SDL_SetError ("Could not open Joystick Port."); 581 SDL_SetError("Could not open Joystick Port.");
583 return -1; 582 return -1;
584 } 583 }
585 584
586 /* Get Joystick Driver Version... must be 2.0 or higher */ 585 /* Get Joystick Driver Version... must be 2.0 or higher */
587 ulVersion = 0; 586 ulVersion = 0;
588 ulDataLen = sizeof (ulVersion); 587 ulDataLen = sizeof(ulVersion);
589 rc = DosDevIOCtl (*hGame, IOCTL_CAT_USER, GAME_GET_VERSION, 588 rc = DosDevIOCtl(*hGame, IOCTL_CAT_USER, GAME_GET_VERSION,
590 NULL, 0, NULL, &ulVersion, ulDataLen, &ulDataLen); 589 NULL, 0, NULL, &ulVersion, ulDataLen, &ulDataLen);
591 if (rc != 0) { 590 if (rc != 0) {
592 joyPortClose (hGame); 591 joyPortClose(hGame);
593 SDL_SetError ("Could not get Joystick Driver version."); 592 SDL_SetError("Could not get Joystick Driver version.");
594 return -1; 593 return -1;
595 } 594 }
596 if (ulVersion < GAME_VERSION) { 595 if (ulVersion < GAME_VERSION) {
597 joyPortClose (hGame); 596 joyPortClose(hGame);
598 SDL_SetError 597 SDL_SetError
599 ("Driver too old. At least IBM driver version 2.0 required."); 598 ("Driver too old. At least IBM driver version 2.0 required.");
600 return -1; 599 return -1;
601 } 600 }
602 return 0; 601 return 0;
606 605
607 /****************************/ 606 /****************************/
608 /* Close JoyPort, if opened */ 607 /* Close JoyPort, if opened */
609 /****************************/ 608 /****************************/
610 void 609 void
611 joyPortClose (HFILE * hGame) 610 joyPortClose(HFILE * hGame)
612 { 611 {
613 if (*hGame != NULL) 612 if (*hGame != NULL)
614 DosClose (*hGame); 613 DosClose(*hGame);
615 *hGame = NULL; 614 *hGame = NULL;
616 } 615 }
617 616
618 617
619 618
620 /***************************/ 619 /***************************/
621 /* Get SDL Joystick EnvVar */ 620 /* Get SDL Joystick EnvVar */
622 /***************************/ 621 /***************************/
623 int 622 int
624 joyGetEnv (struct _joycfg *joydata) 623 joyGetEnv(struct _joycfg *joydata)
625 { 624 {
626 char *joyenv; /* Pointer to tested character */ 625 char *joyenv; /* Pointer to tested character */
627 char tempnumber[5]; /* Temporary place to put numeric texts */ 626 char tempnumber[5]; /* Temporary place to put numeric texts */
628 627
629 joyenv = SDL_getenv ("SDL_OS2_JOYSTICK"); 628 joyenv = SDL_getenv("SDL_OS2_JOYSTICK");
630 if (joyenv == NULL) 629 if (joyenv == NULL)
631 return 0; 630 return 0;
632 /* Joystick Environment is defined! */ 631 /* Joystick Environment is defined! */
633 while (*joyenv == ' ' && *joyenv != 0) 632 while (*joyenv == ' ' && *joyenv != 0)
634 joyenv++; /* jump spaces... */ 633 joyenv++; /* jump spaces... */
635 /* If the string name starts with '... get if fully */ 634 /* If the string name starts with '... get if fully */
636 if (*joyenv == '\'') 635 if (*joyenv == '\'')
637 joyenv += 636 joyenv +=
638 joyGetData (++joyenv, joydata->name, '\'', 637 joyGetData(++joyenv, joydata->name, '\'', sizeof(joydata->name));
639 sizeof (joydata->name));
640 /* If not, get it until the next space */ 638 /* If not, get it until the next space */
641 else if (*joyenv == '\"') 639 else if (*joyenv == '\"')
642 joyenv += 640 joyenv +=
643 joyGetData (++joyenv, joydata->name, '\"', 641 joyGetData(++joyenv, joydata->name, '\"', sizeof(joydata->name));
644 sizeof (joydata->name));
645 else 642 else
646 joyenv += 643 joyenv +=
647 joyGetData (joyenv, joydata->name, ' ', sizeof (joydata->name)); 644 joyGetData(joyenv, joydata->name, ' ', sizeof(joydata->name));
648 /* Now get the number of axes */ 645 /* Now get the number of axes */
649 while (*joyenv == ' ' && *joyenv != 0) 646 while (*joyenv == ' ' && *joyenv != 0)
650 joyenv++; /* jump spaces... */ 647 joyenv++; /* jump spaces... */
651 joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); 648 joyenv += joyGetData(joyenv, tempnumber, ' ', sizeof(tempnumber));
652 joydata->axes = atoi (tempnumber); 649 joydata->axes = atoi(tempnumber);
653 /* Now get the number of buttons */ 650 /* Now get the number of buttons */
654 while (*joyenv == ' ' && *joyenv != 0) 651 while (*joyenv == ' ' && *joyenv != 0)
655 joyenv++; /* jump spaces... */ 652 joyenv++; /* jump spaces... */
656 joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); 653 joyenv += joyGetData(joyenv, tempnumber, ' ', sizeof(tempnumber));
657 joydata->buttons = atoi (tempnumber); 654 joydata->buttons = atoi(tempnumber);
658 /* Now get the number of hats */ 655 /* Now get the number of hats */
659 while (*joyenv == ' ' && *joyenv != 0) 656 while (*joyenv == ' ' && *joyenv != 0)
660 joyenv++; /* jump spaces... */ 657 joyenv++; /* jump spaces... */
661 joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); 658 joyenv += joyGetData(joyenv, tempnumber, ' ', sizeof(tempnumber));
662 joydata->hats = atoi (tempnumber); 659 joydata->hats = atoi(tempnumber);
663 /* Now get the number of balls */ 660 /* Now get the number of balls */
664 while (*joyenv == ' ' && *joyenv != 0) 661 while (*joyenv == ' ' && *joyenv != 0)
665 joyenv++; /* jump spaces... */ 662 joyenv++; /* jump spaces... */
666 joyenv += joyGetData (joyenv, tempnumber, ' ', sizeof (tempnumber)); 663 joyenv += joyGetData(joyenv, tempnumber, ' ', sizeof(tempnumber));
667 joydata->balls = atoi (tempnumber); 664 joydata->balls = atoi(tempnumber);
668 return 1; 665 return 1;
669 } 666 }
670 667
671 668
672 669
673 /************************************************************************/ 670 /************************************************************************/
674 /* Get a text from in the string starting in joyenv until it finds */ 671 /* Get a text from in the string starting in joyenv until it finds */
675 /* the stopchar or maxchars is reached. The result is placed in name. */ 672 /* the stopchar or maxchars is reached. The result is placed in name. */
676 /************************************************************************/ 673 /************************************************************************/
677 int 674 int
678 joyGetData (char *joyenv, char *name, char stopchar, size_t maxchars) 675 joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars)
679 { 676 {
680 char *nameptr; /* Pointer to the selected character */ 677 char *nameptr; /* Pointer to the selected character */
681 int chcnt = 0; /* Count how many characters where copied */ 678 int chcnt = 0; /* Count how many characters where copied */
682 679
683 nameptr = name; 680 nameptr = name;