Mercurial > sdl-ios-xcode
comparison src/joystick/mint/SDL_sysjoystick.c @ 963:92c247cec42d
No need to try to emulate analog axis when SDL support digital hats
author | Patrice Mandin <patmandin@gmail.com> |
---|---|
date | Sun, 31 Oct 2004 13:15:33 +0000 |
parents | b8d311d90021 |
children | e89d7f826b4a |
comparison
equal
deleted
inserted
replaced
962:176240cf4405 | 963:92c247cec42d |
---|---|
300 | 300 |
301 numjoystick=GetEnabledAtariJoystick(joystick->index); | 301 numjoystick=GetEnabledAtariJoystick(joystick->index); |
302 if (numjoystick==-1) | 302 if (numjoystick==-1) |
303 return -1; | 303 return -1; |
304 | 304 |
305 if ((numjoystick==PORTA_PAD) || (numjoystick==PORTB_PAD)) { | 305 joystick->naxes=0; |
306 joystick->nbuttons=JP_NUM_BUTTONS; | 306 joystick->nhats=0; |
307 } else if ((numjoystick==PORTA_LP) || (numjoystick==PORTA_ANPAD) || | |
308 (numjoystick==PORTB_ANPAD)) { | |
309 joystick->nbuttons=2; | |
310 } else { | |
311 joystick->nbuttons=1; | |
312 } | |
313 joystick->naxes=2; | |
314 joystick->nballs=0; | 307 joystick->nballs=0; |
315 joystick->nhats=0; | 308 |
309 switch(numjoystick) { | |
310 case PORTA_PAD: | |
311 case PORTB_PAD: | |
312 joystick->nhats=1; | |
313 joystick->nbuttons=JP_NUM_BUTTONS; | |
314 break; | |
315 case PORTA_LP: | |
316 case PORTA_ANPAD: | |
317 case PORTB_ANPAD: | |
318 joystick->naxes=2; | |
319 joystick->nbuttons=2; | |
320 break; | |
321 default: | |
322 joystick->nhats=1; | |
323 joystick->nbuttons=1; | |
324 break; | |
325 } | |
316 | 326 |
317 return(0); | 327 return(0); |
318 } | 328 } |
319 | 329 |
320 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) | 330 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) |
321 { | 331 { |
322 int numjoystick; | 332 int numjoystick; |
333 Uint8 hatstate; | |
323 Uint32 curstate,prevstate; | 334 Uint32 curstate,prevstate; |
324 Sint16 curaxis; | |
325 | 335 |
326 numjoystick=GetEnabledAtariJoystick(joystick->index); | 336 numjoystick=GetEnabledAtariJoystick(joystick->index); |
327 if (numjoystick==-1) | 337 if (numjoystick==-1) |
328 return; | 338 return; |
329 | 339 |
345 if (numjoystick==XBIOS_JOY1) { | 355 if (numjoystick==XBIOS_JOY1) { |
346 curstate = SDL_AtariXbios_joystick & 0xff; | 356 curstate = SDL_AtariXbios_joystick & 0xff; |
347 } | 357 } |
348 | 358 |
349 if (curstate != prevstate) { | 359 if (curstate != prevstate) { |
350 /* X axis */ | 360 hatstate = SDL_HAT_CENTERED; |
351 if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) { | 361 if (curstate & IKBD_JOY_LEFT) { |
352 curaxis=0; | 362 hatstate |= SDL_HAT_LEFT; |
353 if (curstate & IKBD_JOY_LEFT) { | 363 } |
354 curaxis=0x8000; | 364 if (curstate & IKBD_JOY_RIGHT) { |
355 } else if (curstate & IKBD_JOY_RIGHT) { | 365 hatstate |= SDL_HAT_RIGHT; |
356 curaxis=0x7fff; | 366 } |
357 } | 367 if (curstate & IKBD_JOY_UP) { |
358 SDL_PrivateJoystickAxis(joystick,0,curaxis); | 368 hatstate |= SDL_HAT_UP; |
359 } | 369 } |
360 /* Y axis */ | 370 if (curstate & IKBD_JOY_DOWN) { |
361 if ((curstate & (IKBD_JOY_UP|IKBD_JOY_DOWN)) != (prevstate & (IKBD_JOY_UP|IKBD_JOY_DOWN))) { | 371 hatstate |= SDL_HAT_DOWN; |
362 curaxis=0; | 372 } |
363 if (curstate & IKBD_JOY_UP) { | 373 SDL_PrivateJoystickHat(joystick, 0, hatstate); |
364 curaxis=0x8000; | 374 |
365 } else if (curstate & IKBD_JOY_DOWN) { | |
366 curaxis=0x7fff; | |
367 } | |
368 SDL_PrivateJoystickAxis(joystick,1,curaxis); | |
369 } | |
370 /* Button */ | 375 /* Button */ |
371 if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) { | 376 if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) { |
372 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); | 377 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); |
373 } | 378 } |
374 if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) { | 379 if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) { |
382 case PORTB_PAD: | 387 case PORTB_PAD: |
383 { | 388 { |
384 int numjoypad,i; | 389 int numjoypad,i; |
385 | 390 |
386 numjoypad=0; | 391 numjoypad=0; |
387 /* if (numjoystick==PORTA_PAD) numjoypad=0;*/ | |
388 if (numjoystick==PORTB_PAD) numjoypad=1; | 392 if (numjoystick==PORTB_PAD) numjoypad=1; |
389 | 393 |
390 curstate=jp_joypads[numjoypad]; | 394 curstate=jp_joypads[numjoypad]; |
391 if (curstate!=prevstate) { | 395 if (curstate!=prevstate) { |
392 /* X axis */ | 396 hatstate = SDL_HAT_CENTERED; |
393 if ((curstate & ((1<<JP_LEFT)|(1<<JP_RIGHT))) != (prevstate & ((1<<JP_LEFT)|(1<<JP_RIGHT)))) { | 397 if (curstate & (1<<JP_LEFT)) { |
394 curaxis=0; | 398 hatstate |= SDL_HAT_LEFT; |
395 if (curstate & (1<<JP_LEFT)) { | 399 } |
396 curaxis=0x8000; | 400 if (curstate & (1<<JP_RIGHT)) { |
397 } else if (curstate & (1<<JP_RIGHT)) { | 401 hatstate |= SDL_HAT_RIGHT; |
398 curaxis=0x7fff; | 402 } |
399 } | 403 if (curstate & (1<<JP_UP)) { |
400 SDL_PrivateJoystickAxis(joystick,0,curaxis); | 404 hatstate |= SDL_HAT_UP; |
401 } | 405 } |
402 /* Y axis */ | 406 if (curstate & (1<<JP_DOWN)) { |
403 if ((curstate & ((1<<JP_UP)|(1<<JP_DOWN))) != (prevstate & ((1<<JP_UP)|(1<<JP_DOWN)))) { | 407 hatstate |= SDL_HAT_DOWN; |
404 curaxis=0; | 408 } |
405 if (curstate & (1<<JP_UP)) { | 409 SDL_PrivateJoystickHat(joystick, 0, hatstate); |
406 curaxis=0x8000; | 410 |
407 } else if (curstate & (1<<JP_DOWN)) { | |
408 curaxis=0x7fff; | |
409 } | |
410 SDL_PrivateJoystickAxis(joystick,1,curaxis); | |
411 } | |
412 /* Buttons */ | 411 /* Buttons */ |
413 for (i=0;i<JP_NUM_BUTTONS;i++) { | 412 for (i=0;i<JP_NUM_BUTTONS;i++) { |
414 int button; | 413 int button; |
415 | 414 |
416 button=1<<jp_buttons[i]; | 415 button=1<<jp_buttons[i]; |
440 | 439 |
441 curstate = (jp_directions>>dir_shift) & 15; | 440 curstate = (jp_directions>>dir_shift) & 15; |
442 curstate |= ((jp_fires>>fire_shift) & 1)<<4; | 441 curstate |= ((jp_fires>>fire_shift) & 1)<<4; |
443 | 442 |
444 if (curstate != prevstate) { | 443 if (curstate != prevstate) { |
445 /* X axis */ | 444 hatstate = SDL_HAT_CENTERED; |
446 if ((curstate & (PORT_JS_LEFT|PORT_JS_RIGHT)) != (prevstate & (PORT_JS_LEFT|PORT_JS_RIGHT))) { | 445 if (curstate & PORT_JS_LEFT) { |
447 curaxis=0; | 446 hatstate |= SDL_HAT_LEFT; |
448 if (curstate & PORT_JS_LEFT) { | 447 } |
449 curaxis=0x8000; | 448 if (curstate & PORT_JS_RIGHT) { |
450 } else if (curstate & PORT_JS_RIGHT) { | 449 hatstate |= SDL_HAT_RIGHT; |
451 curaxis=0x7fff; | 450 } |
452 } | 451 if (curstate & PORT_JS_UP) { |
453 SDL_PrivateJoystickAxis(joystick,0,curaxis); | 452 hatstate |= SDL_HAT_UP; |
454 } | 453 } |
455 /* Y axis */ | 454 if (curstate & PORT_JS_DOWN) { |
456 if ((curstate & (PORT_JS_UP|PORT_JS_DOWN)) != (prevstate & (PORT_JS_UP|PORT_JS_DOWN))) { | 455 hatstate |= SDL_HAT_DOWN; |
457 curaxis=0; | 456 } |
458 if (curstate & PORT_JS_UP) { | 457 SDL_PrivateJoystickHat(joystick, 0, hatstate); |
459 curaxis=0x8000; | 458 |
460 } else if (curstate & PORT_JS_DOWN) { | |
461 curaxis=0x7fff; | |
462 } | |
463 SDL_PrivateJoystickAxis(joystick,1,curaxis); | |
464 } | |
465 /* Button */ | 459 /* Button */ |
466 if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) { | 460 if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) { |
467 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); | 461 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED); |
468 } | 462 } |
469 if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) { | 463 if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) { |