Mercurial > sdl-ios-xcode
comparison src/joystick/mint/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 |
---|---|
152 static Uint16 jp_fires; | 152 static Uint16 jp_fires; |
153 static Uint32 jp_joypads[2]; | 153 static Uint32 jp_joypads[2]; |
154 | 154 |
155 /*--- Functions prototypes ---*/ | 155 /*--- Functions prototypes ---*/ |
156 | 156 |
157 static int GetEnabledAtariJoystick (int index); | 157 static int GetEnabledAtariJoystick(int index); |
158 static void UpdateJoypads (void); | 158 static void UpdateJoypads(void); |
159 | 159 |
160 /*--- Functions ---*/ | 160 /*--- Functions ---*/ |
161 | 161 |
162 int | 162 int |
163 SDL_SYS_JoystickInit (void) | 163 SDL_SYS_JoystickInit(void) |
164 { | 164 { |
165 int i; | 165 int i; |
166 unsigned long cookie_mch; | 166 unsigned long cookie_mch; |
167 const char *envr = SDL_getenv ("SDL_JOYSTICK_ATARI"); | 167 const char *envr = SDL_getenv("SDL_JOYSTICK_ATARI"); |
168 | 168 |
169 #define TEST_JOY_ENABLED(env,idstring,num) \ | 169 #define TEST_JOY_ENABLED(env,idstring,num) \ |
170 if (SDL_strstr(env,idstring"-off")) { \ | 170 if (SDL_strstr(env,idstring"-off")) { \ |
171 atarijoysticks[num].enabled=SDL_FALSE; \ | 171 atarijoysticks[num].enabled=SDL_FALSE; \ |
172 } \ | 172 } \ |
173 if (SDL_strstr(env,idstring"-on")) { \ | 173 if (SDL_strstr(env,idstring"-on")) { \ |
174 atarijoysticks[num].enabled=SDL_TRUE; \ | 174 atarijoysticks[num].enabled=SDL_TRUE; \ |
175 } | 175 } |
176 | 176 |
177 /* Cookie _MCH present ? if not, assume ST machine */ | 177 /* Cookie _MCH present ? if not, assume ST machine */ |
178 if (Getcookie (C__MCH, &cookie_mch) != C_FOUND) { | 178 if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) { |
179 cookie_mch = MCH_ST << 16; | 179 cookie_mch = MCH_ST << 16; |
180 } | 180 } |
181 | 181 |
182 /* Enable some default joysticks */ | 182 /* Enable some default joysticks */ |
183 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) || | 183 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) || |
198 /* IKBD on any Atari, maybe clones */ | 198 /* IKBD on any Atari, maybe clones */ |
199 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) | 199 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) |
200 || (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16) | 200 || (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16) |
201 || (cookie_mch == MCH_ARANYM << 16)) { | 201 || (cookie_mch == MCH_ARANYM << 16)) { |
202 if (SDL_AtariIkbd_enabled != 0) { | 202 if (SDL_AtariIkbd_enabled != 0) { |
203 TEST_JOY_ENABLED (envr, "ikbd-joy1", IKBD_JOY1); | 203 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1); |
204 } | 204 } |
205 } | 205 } |
206 /* Joypads ports only on STE and Falcon */ | 206 /* Joypads ports only on STE and Falcon */ |
207 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) { | 207 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) { |
208 TEST_JOY_ENABLED (envr, "porta-pad", PORTA_PAD); | 208 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD); |
209 if (!atarijoysticks[PORTA_PAD].enabled) { | 209 if (!atarijoysticks[PORTA_PAD].enabled) { |
210 TEST_JOY_ENABLED (envr, "porta-joy0", PORTA_JOY0); | 210 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0); |
211 TEST_JOY_ENABLED (envr, "porta-joy1", PORTA_JOY1); | 211 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1); |
212 if (!(atarijoysticks[PORTA_JOY0].enabled) | 212 if (!(atarijoysticks[PORTA_JOY0].enabled) |
213 && !(atarijoysticks[PORTA_JOY1].enabled)) { | 213 && !(atarijoysticks[PORTA_JOY1].enabled)) { |
214 TEST_JOY_ENABLED (envr, "porta-lp", PORTA_LP); | 214 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP); |
215 if (!atarijoysticks[PORTA_LP].enabled) { | 215 if (!atarijoysticks[PORTA_LP].enabled) { |
216 TEST_JOY_ENABLED (envr, "porta-anpad", PORTA_ANPAD); | 216 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD); |
217 } | 217 } |
218 } | 218 } |
219 } | 219 } |
220 | 220 |
221 TEST_JOY_ENABLED (envr, "portb-pad", PORTB_PAD); | 221 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD); |
222 if (!atarijoysticks[PORTB_PAD].enabled) { | 222 if (!atarijoysticks[PORTB_PAD].enabled) { |
223 TEST_JOY_ENABLED (envr, "portb-joy0", PORTB_JOY0); | 223 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0); |
224 TEST_JOY_ENABLED (envr, "portb-joy1", PORTB_JOY1); | 224 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1); |
225 if (!(atarijoysticks[PORTB_JOY0].enabled) | 225 if (!(atarijoysticks[PORTB_JOY0].enabled) |
226 && !(atarijoysticks[PORTB_JOY1].enabled)) { | 226 && !(atarijoysticks[PORTB_JOY1].enabled)) { |
227 TEST_JOY_ENABLED (envr, "portb-anpad", PORTB_ANPAD); | 227 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD); |
228 } | 228 } |
229 } | 229 } |
230 } | 230 } |
231 | 231 |
232 if (!atarijoysticks[IKBD_JOY1].enabled) { | 232 if (!atarijoysticks[IKBD_JOY1].enabled) { |
233 if (SDL_AtariXbios_enabled != 0) { | 233 if (SDL_AtariXbios_enabled != 0) { |
234 TEST_JOY_ENABLED (envr, "xbios-joy1", XBIOS_JOY1); | 234 TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1); |
235 } | 235 } |
236 } | 236 } |
237 #if 0 | 237 #if 0 |
238 /* Parallel port on any Atari, maybe clones */ | 238 /* Parallel port on any Atari, maybe clones */ |
239 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) | 239 if ((cookie_mch == MCH_ST << 16) || ((cookie_mch >> 16) == MCH_STE) |
240 || (cookie_mch == MCH_TT << 16) | 240 || (cookie_mch == MCH_TT << 16) |
241 || (cookie_mch == MCH_F30 << 16)) { | 241 || (cookie_mch == MCH_F30 << 16)) { |
242 TEST_JOY_ENABLED (envr, "para-joy0", PARA_JOY0); | 242 TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0); |
243 TEST_JOY_ENABLED (envr, "para-joy1", PARA_JOY1); | 243 TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1); |
244 } | 244 } |
245 #endif | 245 #endif |
246 } | 246 } |
247 | 247 |
248 /* Need to update joypad ports ? */ | 248 /* Need to update joypad ports ? */ |
263 | 263 |
264 return (SDL_numjoysticks); | 264 return (SDL_numjoysticks); |
265 } | 265 } |
266 | 266 |
267 static int | 267 static int |
268 GetEnabledAtariJoystick (int index) | 268 GetEnabledAtariJoystick(int index) |
269 { | 269 { |
270 int i, j; | 270 int i, j; |
271 | 271 |
272 /* Return the nth'index' enabled atari joystick */ | 272 /* Return the nth'index' enabled atari joystick */ |
273 j = 0; | 273 j = 0; |
287 | 287 |
288 return i; | 288 return i; |
289 } | 289 } |
290 | 290 |
291 const char * | 291 const char * |
292 SDL_SYS_JoystickName (int index) | 292 SDL_SYS_JoystickName(int index) |
293 { | 293 { |
294 int numjoystick; | 294 int numjoystick; |
295 | 295 |
296 numjoystick = GetEnabledAtariJoystick (index); | 296 numjoystick = GetEnabledAtariJoystick(index); |
297 if (numjoystick == -1) | 297 if (numjoystick == -1) |
298 return NULL; | 298 return NULL; |
299 | 299 |
300 return (atarijoysticks[numjoystick].name); | 300 return (atarijoysticks[numjoystick].name); |
301 } | 301 } |
302 | 302 |
303 int | 303 int |
304 SDL_SYS_JoystickOpen (SDL_Joystick * joystick) | 304 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) |
305 { | 305 { |
306 int numjoystick; | 306 int numjoystick; |
307 | 307 |
308 numjoystick = GetEnabledAtariJoystick (joystick->index); | 308 numjoystick = GetEnabledAtariJoystick(joystick->index); |
309 if (numjoystick == -1) | 309 if (numjoystick == -1) |
310 return -1; | 310 return -1; |
311 | 311 |
312 joystick->naxes = 0; | 312 joystick->naxes = 0; |
313 joystick->nhats = 0; | 313 joystick->nhats = 0; |
333 | 333 |
334 return (0); | 334 return (0); |
335 } | 335 } |
336 | 336 |
337 void | 337 void |
338 SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) | 338 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
339 { | 339 { |
340 int numjoystick; | 340 int numjoystick; |
341 Uint8 hatstate; | 341 Uint8 hatstate; |
342 Uint32 curstate, prevstate; | 342 Uint32 curstate, prevstate; |
343 | 343 |
344 numjoystick = GetEnabledAtariJoystick (joystick->index); | 344 numjoystick = GetEnabledAtariJoystick(joystick->index); |
345 if (numjoystick == -1) | 345 if (numjoystick == -1) |
346 return; | 346 return; |
347 | 347 |
348 prevstate = atarijoysticks[numjoystick].prevstate; | 348 prevstate = atarijoysticks[numjoystick].prevstate; |
349 | 349 |
350 if (joypad_ports_enabled) { | 350 if (joypad_ports_enabled) { |
351 Supexec (UpdateJoypads); | 351 Supexec(UpdateJoypads); |
352 } | 352 } |
353 | 353 |
354 switch (numjoystick) { | 354 switch (numjoystick) { |
355 case IKBD_JOY1: | 355 case IKBD_JOY1: |
356 case XBIOS_JOY1: | 356 case XBIOS_JOY1: |
376 hatstate |= SDL_HAT_UP; | 376 hatstate |= SDL_HAT_UP; |
377 } | 377 } |
378 if (curstate & IKBD_JOY_DOWN) { | 378 if (curstate & IKBD_JOY_DOWN) { |
379 hatstate |= SDL_HAT_DOWN; | 379 hatstate |= SDL_HAT_DOWN; |
380 } | 380 } |
381 SDL_PrivateJoystickHat (joystick, 0, hatstate); | 381 SDL_PrivateJoystickHat(joystick, 0, hatstate); |
382 | 382 |
383 /* Button */ | 383 /* Button */ |
384 if ((curstate & IKBD_JOY_FIRE) | 384 if ((curstate & IKBD_JOY_FIRE) |
385 && !(prevstate & IKBD_JOY_FIRE)) { | 385 && !(prevstate & IKBD_JOY_FIRE)) { |
386 SDL_PrivateJoystickButton (joystick, 0, SDL_PRESSED); | 386 SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); |
387 } | 387 } |
388 if (!(curstate & IKBD_JOY_FIRE) | 388 if (!(curstate & IKBD_JOY_FIRE) |
389 && (prevstate & IKBD_JOY_FIRE)) { | 389 && (prevstate & IKBD_JOY_FIRE)) { |
390 SDL_PrivateJoystickButton (joystick, 0, SDL_RELEASED); | 390 SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); |
391 } | 391 } |
392 } | 392 } |
393 atarijoysticks[numjoystick].prevstate = curstate; | 393 atarijoysticks[numjoystick].prevstate = curstate; |
394 } | 394 } |
395 break; | 395 break; |
415 hatstate |= SDL_HAT_UP; | 415 hatstate |= SDL_HAT_UP; |
416 } | 416 } |
417 if (curstate & (1 << JP_DOWN)) { | 417 if (curstate & (1 << JP_DOWN)) { |
418 hatstate |= SDL_HAT_DOWN; | 418 hatstate |= SDL_HAT_DOWN; |
419 } | 419 } |
420 SDL_PrivateJoystickHat (joystick, 0, hatstate); | 420 SDL_PrivateJoystickHat(joystick, 0, hatstate); |
421 | 421 |
422 /* Buttons */ | 422 /* Buttons */ |
423 for (i = 0; i < JP_NUM_BUTTONS; i++) { | 423 for (i = 0; i < JP_NUM_BUTTONS; i++) { |
424 int button; | 424 int button; |
425 | 425 |
426 button = 1 << jp_buttons[i]; | 426 button = 1 << jp_buttons[i]; |
427 | 427 |
428 if ((curstate & button) && !(prevstate & button)) { | 428 if ((curstate & button) && !(prevstate & button)) { |
429 SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); | 429 SDL_PrivateJoystickButton(joystick, i, SDL_PRESSED); |
430 } | 430 } |
431 if (!(curstate & button) && (prevstate & button)) { | 431 if (!(curstate & button) && (prevstate & button)) { |
432 SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); | 432 SDL_PrivateJoystickButton(joystick, i, SDL_RELEASED); |
433 } | 433 } |
434 } | 434 } |
435 } | 435 } |
436 atarijoysticks[numjoystick].prevstate = curstate; | 436 atarijoysticks[numjoystick].prevstate = curstate; |
437 } | 437 } |
475 hatstate |= SDL_HAT_UP; | 475 hatstate |= SDL_HAT_UP; |
476 } | 476 } |
477 if (curstate & PORT_JS_DOWN) { | 477 if (curstate & PORT_JS_DOWN) { |
478 hatstate |= SDL_HAT_DOWN; | 478 hatstate |= SDL_HAT_DOWN; |
479 } | 479 } |
480 SDL_PrivateJoystickHat (joystick, 0, hatstate); | 480 SDL_PrivateJoystickHat(joystick, 0, hatstate); |
481 | 481 |
482 /* Button */ | 482 /* Button */ |
483 if ((curstate & PORT_JS_FIRE) | 483 if ((curstate & PORT_JS_FIRE) |
484 && !(prevstate & PORT_JS_FIRE)) { | 484 && !(prevstate & PORT_JS_FIRE)) { |
485 SDL_PrivateJoystickButton (joystick, 0, SDL_PRESSED); | 485 SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); |
486 } | 486 } |
487 if (!(curstate & PORT_JS_FIRE) | 487 if (!(curstate & PORT_JS_FIRE) |
488 && (prevstate & PORT_JS_FIRE)) { | 488 && (prevstate & PORT_JS_FIRE)) { |
489 SDL_PrivateJoystickButton (joystick, 0, SDL_RELEASED); | 489 SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); |
490 } | 490 } |
491 } | 491 } |
492 atarijoysticks[numjoystick].prevstate = curstate; | 492 atarijoysticks[numjoystick].prevstate = curstate; |
493 } | 493 } |
494 break; | 494 break; |
500 curstate |= (jp_lightpens[1] >> 1) << 15; | 500 curstate |= (jp_lightpens[1] >> 1) << 15; |
501 curstate |= (jp_fires & 3) << 30; | 501 curstate |= (jp_fires & 3) << 30; |
502 | 502 |
503 if (curstate != prevstate) { | 503 if (curstate != prevstate) { |
504 /* X axis */ | 504 /* X axis */ |
505 SDL_PrivateJoystickAxis (joystick, 0, | 505 SDL_PrivateJoystickAxis(joystick, 0, |
506 jp_lightpens[0] ^ 0x8000); | 506 jp_lightpens[0] ^ 0x8000); |
507 /* Y axis */ | 507 /* Y axis */ |
508 SDL_PrivateJoystickAxis (joystick, 1, | 508 SDL_PrivateJoystickAxis(joystick, 1, |
509 jp_lightpens[1] ^ 0x8000); | 509 jp_lightpens[1] ^ 0x8000); |
510 /* Buttons */ | 510 /* Buttons */ |
511 for (i = 0; i < 2; i++) { | 511 for (i = 0; i < 2; i++) { |
512 int button; | 512 int button; |
513 | 513 |
514 button = 1 << (30 + i); | 514 button = 1 << (30 + i); |
515 | 515 |
516 if ((curstate & button) && !(prevstate & button)) { | 516 if ((curstate & button) && !(prevstate & button)) { |
517 SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); | 517 SDL_PrivateJoystickButton(joystick, i, SDL_PRESSED); |
518 } | 518 } |
519 if (!(curstate & button) && (prevstate & button)) { | 519 if (!(curstate & button) && (prevstate & button)) { |
520 SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); | 520 SDL_PrivateJoystickButton(joystick, i, SDL_RELEASED); |
521 } | 521 } |
522 } | 522 } |
523 } | 523 } |
524 atarijoysticks[numjoystick].prevstate = curstate; | 524 atarijoysticks[numjoystick].prevstate = curstate; |
525 } | 525 } |
537 curstate |= (jp_paddles[numpaddle + 1] >> 1) << 15; | 537 curstate |= (jp_paddles[numpaddle + 1] >> 1) << 15; |
538 curstate |= ((jp_fires >> numpaddle) & 3) << 30; | 538 curstate |= ((jp_fires >> numpaddle) & 3) << 30; |
539 | 539 |
540 if (curstate != prevstate) { | 540 if (curstate != prevstate) { |
541 /* X axis */ | 541 /* X axis */ |
542 SDL_PrivateJoystickAxis (joystick, 0, | 542 SDL_PrivateJoystickAxis(joystick, 0, |
543 jp_paddles[numpaddle] ^ 0x8000); | 543 jp_paddles[numpaddle] ^ 0x8000); |
544 /* Y axis */ | 544 /* Y axis */ |
545 SDL_PrivateJoystickAxis (joystick, 1, | 545 SDL_PrivateJoystickAxis(joystick, 1, |
546 jp_paddles[numpaddle + 1] ^ 0x8000); | 546 jp_paddles[numpaddle + 1] ^ 0x8000); |
547 /* Buttons */ | 547 /* Buttons */ |
548 for (i = 0; i < 2; i++) { | 548 for (i = 0; i < 2; i++) { |
549 int button; | 549 int button; |
550 | 550 |
551 button = 1 << (30 + i); | 551 button = 1 << (30 + i); |
552 | 552 |
553 if ((curstate & button) && !(prevstate & button)) { | 553 if ((curstate & button) && !(prevstate & button)) { |
554 SDL_PrivateJoystickButton (joystick, i, SDL_PRESSED); | 554 SDL_PrivateJoystickButton(joystick, i, SDL_PRESSED); |
555 } | 555 } |
556 if (!(curstate & button) && (prevstate & button)) { | 556 if (!(curstate & button) && (prevstate & button)) { |
557 SDL_PrivateJoystickButton (joystick, i, SDL_RELEASED); | 557 SDL_PrivateJoystickButton(joystick, i, SDL_RELEASED); |
558 } | 558 } |
559 } | 559 } |
560 } | 560 } |
561 atarijoysticks[numjoystick].prevstate = curstate; | 561 atarijoysticks[numjoystick].prevstate = curstate; |
562 } | 562 } |
570 | 570 |
571 return; | 571 return; |
572 } | 572 } |
573 | 573 |
574 void | 574 void |
575 SDL_SYS_JoystickClose (SDL_Joystick * joystick) | 575 SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
576 { | 576 { |
577 return; | 577 return; |
578 } | 578 } |
579 | 579 |
580 void | 580 void |
581 SDL_SYS_JoystickQuit (void) | 581 SDL_SYS_JoystickQuit(void) |
582 { | 582 { |
583 SDL_numjoysticks = 0; | 583 SDL_numjoysticks = 0; |
584 return; | 584 return; |
585 } | 585 } |
586 | 586 |
597 Uint16 lightpens[2]; | 597 Uint16 lightpens[2]; |
598 }; | 598 }; |
599 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE)) | 599 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE)) |
600 | 600 |
601 static void | 601 static void |
602 UpdateJoypads (void) | 602 UpdateJoypads(void) |
603 { | 603 { |
604 Uint16 tmp; | 604 Uint16 tmp; |
605 | 605 |
606 /*--- This function is called in supervisor mode ---*/ | 606 /*--- This function is called in supervisor mode ---*/ |
607 | 607 |