comparison src/joystick/mint/SDL_sysjoystick.c @ 2029:8640d90b0406

Add teamtap support
author Patrice Mandin <patmandin@gmail.com>
date Sat, 16 Sep 2006 17:13:41 +0000
parents c121d94672cb
children adf732f1f016
comparison
equal deleted inserted replaced
2028:6dbe2a67b23b 2029:8640d90b0406
42 42
43 /*--- Const ---*/ 43 /*--- Const ---*/
44 44
45 /* We can have: 45 /* We can have:
46 1 joystick on IKBD port 1, read via hardware I/O 46 1 joystick on IKBD port 1, read via hardware I/O
47 or same joystick on IKBD port 1, read via xbios 47 or same joystick on IKBD port 1, read via xbios
48 2 joypads on ports A,B 48 1 joypad on port A (up to 4 with teamtap)
49 or 4 joysticks on joypads ports A,B 49 or 2 joysticks on joypad port A
50 or 1 analog paddle on joypad port A
50 or 1 lightpen on joypad port A 51 or 1 lightpen on joypad port A
51 or 2 analog paddles on joypads ports A,B 52 1 joypad on port B (up to 4 with teamtap)
53 or 2 joysticks on joypad port B
54 or 1 analog paddle on joypad port B
52 2 joysticks on parallel port 55 2 joysticks on parallel port
53 */ 56 */
54 57
55 enum 58 enum
56 { 59 {
57 IKBD_JOY1 = 0, 60 IKBD_JOY1 = 0,
58 XBIOS_JOY1, 61 XBIOS_JOY1,
59 PORTA_PAD, 62 PORTA_PAD0,
60 PORTB_PAD, 63 PORTA_PAD1,
64 PORTA_PAD2,
65 PORTA_PAD3,
66 PORTB_PAD0,
67 PORTB_PAD1,
68 PORTB_PAD2,
69 PORTB_PAD3,
61 PORTA_JOY0, 70 PORTA_JOY0,
62 PORTA_JOY1, 71 PORTA_JOY1,
63 PORTB_JOY0, 72 PORTB_JOY0,
64 PORTB_JOY1, 73 PORTB_JOY1,
65 PORTA_LP, 74 PORTA_LP,
118 /*--- Variables ---*/ 127 /*--- Variables ---*/
119 128
120 static atarijoy_t atarijoysticks[MAX_JOYSTICKS] = { 129 static atarijoy_t atarijoysticks[MAX_JOYSTICKS] = {
121 {SDL_FALSE, "IKBD joystick port 1", 0}, 130 {SDL_FALSE, "IKBD joystick port 1", 0},
122 {SDL_FALSE, "Xbios joystick port 1", 0}, 131 {SDL_FALSE, "Xbios joystick port 1", 0},
123 {SDL_FALSE, "Joypad port A", 0}, 132 {SDL_FALSE, "Joypad 0 port A", 0},
124 {SDL_FALSE, "Joypad port B", 0}, 133 {SDL_FALSE, "Joypad 1 port A", 0},
134 {SDL_FALSE, "Joypad 2 port A", 0},
135 {SDL_FALSE, "Joypad 3 port A", 0},
136 {SDL_FALSE, "Joypad 0 port B", 0},
137 {SDL_FALSE, "Joypad 1 port B", 0},
138 {SDL_FALSE, "Joypad 2 port B", 0},
139 {SDL_FALSE, "Joypad 3 port B", 0},
125 {SDL_FALSE, "Joystick 0 port A", 0}, 140 {SDL_FALSE, "Joystick 0 port A", 0},
126 {SDL_FALSE, "Joystick 1 port A", 0}, 141 {SDL_FALSE, "Joystick 1 port A", 0},
127 {SDL_FALSE, "Joystick 0 port B", 0}, 142 {SDL_FALSE, "Joystick 0 port B", 0},
128 {SDL_FALSE, "Joystick 1 port B", 0}, 143 {SDL_FALSE, "Joystick 1 port B", 0},
129 {SDL_FALSE, "Lightpen port A", 0}, 144 {SDL_FALSE, "Lightpen port A", 0},
148 /* Updated joypad ports */ 163 /* Updated joypad ports */
149 static Uint16 jp_paddles[4]; 164 static Uint16 jp_paddles[4];
150 static Uint16 jp_lightpens[2]; 165 static Uint16 jp_lightpens[2];
151 static Uint16 jp_directions; 166 static Uint16 jp_directions;
152 static Uint16 jp_fires; 167 static Uint16 jp_fires;
153 static Uint32 jp_joypads[2]; 168 static Uint32 jp_joypads[8];
154 169
155 /*--- Functions prototypes ---*/ 170 /*--- Functions prototypes ---*/
156 171
157 static int GetEnabledAtariJoystick(int index); 172 static int GetEnabledAtariJoystick(int index);
158 static void UpdateJoypads(void); 173 static void UpdateJoypads(void);
184 (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16) || 199 (cookie_mch == MCH_TT << 16) || (cookie_mch == MCH_F30 << 16) ||
185 (cookie_mch == MCH_ARANYM << 16)) { 200 (cookie_mch == MCH_ARANYM << 16)) {
186 atarijoysticks[IKBD_JOY1].enabled = (SDL_AtariIkbd_enabled != 0); 201 atarijoysticks[IKBD_JOY1].enabled = (SDL_AtariIkbd_enabled != 0);
187 } 202 }
188 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) { 203 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) {
189 atarijoysticks[PORTA_PAD].enabled = SDL_TRUE; 204 atarijoysticks[PORTA_PAD0].enabled =
190 atarijoysticks[PORTB_PAD].enabled = SDL_TRUE; 205 atarijoysticks[PORTA_PAD1].enabled =
206 atarijoysticks[PORTA_PAD2].enabled =
207 atarijoysticks[PORTA_PAD3].enabled =
208 atarijoysticks[PORTB_PAD0].enabled =
209 atarijoysticks[PORTB_PAD1].enabled =
210 atarijoysticks[PORTB_PAD2].enabled =
211 atarijoysticks[PORTB_PAD3].enabled = SDL_TRUE;
191 } 212 }
192 if (!atarijoysticks[IKBD_JOY1].enabled) { 213 if (!atarijoysticks[IKBD_JOY1].enabled) {
193 atarijoysticks[XBIOS_JOY1].enabled = (SDL_AtariXbios_enabled != 0); 214 atarijoysticks[XBIOS_JOY1].enabled = (SDL_AtariXbios_enabled != 0);
194 } 215 }
195 216
203 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1); 224 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
204 } 225 }
205 } 226 }
206 /* Joypads ports only on STE and Falcon */ 227 /* Joypads ports only on STE and Falcon */
207 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) { 228 if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) {
208 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD); 229 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD0);
209 if (!atarijoysticks[PORTA_PAD].enabled) { 230 if (!atarijoysticks[PORTA_PAD0].enabled) {
210 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0); 231 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
211 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1); 232 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
212 if (!(atarijoysticks[PORTA_JOY0].enabled) 233 if (!(atarijoysticks[PORTA_JOY0].enabled)
213 && !(atarijoysticks[PORTA_JOY1].enabled)) { 234 && !(atarijoysticks[PORTA_JOY1].enabled)) {
214 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP); 235 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
216 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD); 237 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
217 } 238 }
218 } 239 }
219 } 240 }
220 241
221 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD); 242 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD0);
222 if (!atarijoysticks[PORTB_PAD].enabled) { 243 if (!atarijoysticks[PORTB_PAD0].enabled) {
223 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0); 244 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
224 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1); 245 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
225 if (!(atarijoysticks[PORTB_JOY0].enabled) 246 if (!(atarijoysticks[PORTB_JOY0].enabled)
226 && !(atarijoysticks[PORTB_JOY1].enabled)) { 247 && !(atarijoysticks[PORTB_JOY1].enabled)) {
227 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD); 248 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
245 #endif 266 #endif
246 } 267 }
247 268
248 /* Need to update joypad ports ? */ 269 /* Need to update joypad ports ? */
249 joypad_ports_enabled = SDL_FALSE; 270 joypad_ports_enabled = SDL_FALSE;
250 for (i = PORTA_PAD; i <= PORTB_ANPAD; i++) { 271 for (i = PORTA_PAD0; i <= PORTB_ANPAD; i++) {
251 if (atarijoysticks[i].enabled) { 272 if (atarijoysticks[i].enabled) {
252 joypad_ports_enabled = SDL_TRUE; 273 joypad_ports_enabled = SDL_TRUE;
253 break; 274 break;
254 } 275 }
255 } 276 }
312 joystick->naxes = 0; 333 joystick->naxes = 0;
313 joystick->nhats = 0; 334 joystick->nhats = 0;
314 joystick->nballs = 0; 335 joystick->nballs = 0;
315 336
316 switch (numjoystick) { 337 switch (numjoystick) {
317 case PORTA_PAD: 338 case PORTA_PAD0:
318 case PORTB_PAD: 339 case PORTA_PAD1:
340 case PORTA_PAD2:
341 case PORTA_PAD3:
342 case PORTB_PAD0:
343 case PORTB_PAD1:
344 case PORTB_PAD2:
345 case PORTB_PAD3:
319 joystick->nhats = 1; 346 joystick->nhats = 1;
320 joystick->nbuttons = JP_NUM_BUTTONS; 347 joystick->nbuttons = JP_NUM_BUTTONS;
321 break; 348 break;
322 case PORTA_LP: 349 case PORTA_LP:
323 case PORTA_ANPAD: 350 case PORTA_ANPAD:
391 } 418 }
392 } 419 }
393 atarijoysticks[numjoystick].prevstate = curstate; 420 atarijoysticks[numjoystick].prevstate = curstate;
394 } 421 }
395 break; 422 break;
396 case PORTA_PAD: 423 case PORTA_PAD0:
397 case PORTB_PAD: 424 case PORTA_PAD1:
425 case PORTA_PAD2:
426 case PORTA_PAD3:
427 case PORTB_PAD0:
428 case PORTB_PAD1:
429 case PORTB_PAD2:
430 case PORTB_PAD3:
398 { 431 {
399 int numjoypad, i; 432 int numjoypad, i;
400 433
401 numjoypad = 0; 434 numjoypad = 0;
402 if (numjoystick == PORTB_PAD) 435 switch(numjoystick) {
403 numjoypad = 1; 436 case PORTA_PAD0:
437 numjoypad = 0; break;
438 case PORTA_PAD1:
439 numjoypad = 1; break;
440 case PORTA_PAD2:
441 numjoypad = 2; break;
442 case PORTA_PAD3:
443 numjoypad = 3; break;
444 case PORTB_PAD0:
445 numjoypad = 4; break;
446 case PORTB_PAD1:
447 numjoypad = 5; break;
448 case PORTB_PAD2:
449 numjoypad = 6; break;
450 case PORTB_PAD3:
451 numjoypad = 7; break;
452 }
404 453
405 curstate = jp_joypads[numjoypad]; 454 curstate = jp_joypads[numjoypad];
406 if (curstate != prevstate) { 455 if (curstate != prevstate) {
407 hatstate = SDL_HAT_CENTERED; 456 hatstate = SDL_HAT_CENTERED;
408 if (curstate & (1 << JP_LEFT)) { 457 if (curstate & (1 << JP_LEFT)) {
596 Uint16 dummy2[4]; 645 Uint16 dummy2[4];
597 Uint16 lightpens[2]; 646 Uint16 lightpens[2];
598 }; 647 };
599 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE)) 648 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
600 649
650 static const Uint16 joypad_masks[8*4]={
651 0xfffe, 0xfffd, 0xfffb, 0xfff7,
652 0xfff0, 0xfff1, 0xfff2, 0xfff3,
653 0xfff4, 0xfff5, 0xfff6, 0xfff8,
654 0xfff9, 0xfffa, 0xfffc, 0xffff,
655 0xffef, 0xffdf, 0xffbf, 0xff7f,
656 0xff0f, 0xff1f, 0xff2f, 0xff3f,
657 0xff4f, 0xff5f, 0xff6f, 0xff8f,
658 0xff9f, 0xffaf, 0xffcf, 0xffff
659 };
660
601 static void 661 static void
602 UpdateJoypads(void) 662 UpdateJoypads(void)
603 { 663 {
604 Uint16 tmp; 664 Uint16 tmp;
605 665
623 tmp = (JOYPAD_IO.paddles[2] & 255); 683 tmp = (JOYPAD_IO.paddles[2] & 255);
624 jp_paddles[2] = (tmp << 8) | tmp; 684 jp_paddles[2] = (tmp << 8) | tmp;
625 tmp = (JOYPAD_IO.paddles[3] & 255); 685 tmp = (JOYPAD_IO.paddles[3] & 255);
626 jp_paddles[3] = (tmp << 8) | tmp; 686 jp_paddles[3] = (tmp << 8) | tmp;
627 687
628 /* Update joypad 0 */ 688 /* Update joypads on teamtap port A */
629 JOYPAD_IO.directions = 0xfffe; 689 for (i=0; i<4; i++) {
630 jp_joypads[0] = ((~(JOYPAD_IO.fires)) & 3) << (16); 690 jp_joypads[i] = 0;
631 JOYPAD_IO.directions = 0xfffe; 691 for (j=0; j<4; j++) {
632 jp_joypads[0] |= ((~(JOYPAD_IO.directions)) >> 8) & 15; 692 JOYPAD_IO.directions = joypad_masks[(i*4)+j];
633 693
634 JOYPAD_IO.directions = 0xfffd; 694 cur_fire = (~(JOYPAD_IO.fires) & 3)<<16;
635 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 2); 695 cur_dir = (~(JOYPAD_IO.directions)>>8) & 15;
636 JOYPAD_IO.directions = 0xfffd; 696
637 jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 4; 697 jp_joypads[i] |= cur_fire<<(j*2);
638 698 jp_joypads[i] |= cur_dir<<(j*4);
639 JOYPAD_IO.directions = 0xfffb; 699 }
640 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 4); 700 }
641 JOYPAD_IO.directions = 0xfffb; 701
642 jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 8; 702 /* Update joypads on teamtap port B */
643 703 for (i=4; i<8; i++) {
644 JOYPAD_IO.directions = 0xfff7; 704 jp_joypads[i] = 0;
645 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 6); 705 for (j=0; j<4; j++) {
646 JOYPAD_IO.directions = 0xfff7; 706 JOYPAD_IO.directions = joypad_masks[(i*4)+j];
647 jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 12; 707
648 708 cur_fire = (~(JOYPAD_IO.fires) & 0xc)<<14;
649 /* Update joypad 1 */ 709 cur_dir = (~(JOYPAD_IO.directions)>>12) & 15;
650 JOYPAD_IO.directions = 0xffef; 710
651 jp_joypads[1] = ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 - 2); 711 jp_joypads[i] |= cur_fire<<(j*2);
652 JOYPAD_IO.directions = 0xffef; 712 jp_joypads[i] |= cur_dir<<(j*4);
653 jp_joypads[1] |= ((~(JOYPAD_IO.directions)) >> 12) & 15; 713 }
654 714 }
655 JOYPAD_IO.directions = 0xffdf; 715
656 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16); 716 JOYPAD_IO.directions=0xffff;
657 JOYPAD_IO.directions = 0xffdf;
658 jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 4;
659
660 JOYPAD_IO.directions = 0xffbf;
661 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 2);
662 JOYPAD_IO.directions = 0xffbf;
663 jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 8;
664
665 JOYPAD_IO.directions = 0xff7f;
666 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 4);
667 JOYPAD_IO.directions = 0xff7f;
668 jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 12;
669 } 717 }
670 718
671 #endif /* SDL_JOYSTICK_MINT */ 719 #endif /* SDL_JOYSTICK_MINT */
672 /* vi: set ts=4 sw=4 expandtab: */ 720 /* vi: set ts=4 sw=4 expandtab: */