comparison src/joystick/mint/SDL_sysjoystick.c @ 3850:28db418c7573 SDL-1.2

Add teamtap support (4 joypads adapter on 1 port)
author Patrice Mandin <patmandin@gmail.com>
date Wed, 02 Aug 2006 21:26:31 +0000
parents 92947e3a18db
children de46a1bfcbdb
comparison
equal deleted inserted replaced
3849:49ed2682da54 3850:28db418c7573
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 IKBD_JOY1=0, 59 IKBD_JOY1=0,
57 XBIOS_JOY1, 60 XBIOS_JOY1,
58 PORTA_PAD, 61 PORTA_PAD0,
59 PORTB_PAD, 62 PORTA_PAD1,
63 PORTA_PAD2,
64 PORTA_PAD3,
65 PORTB_PAD0,
66 PORTB_PAD1,
67 PORTB_PAD2,
68 PORTB_PAD3,
60 PORTA_JOY0, 69 PORTA_JOY0,
61 PORTA_JOY1, 70 PORTA_JOY1,
62 PORTB_JOY0, 71 PORTB_JOY0,
63 PORTB_JOY1, 72 PORTB_JOY1,
64 PORTA_LP, 73 PORTA_LP,
114 /*--- Variables ---*/ 123 /*--- Variables ---*/
115 124
116 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={ 125 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
117 {SDL_FALSE,"IKBD joystick port 1",0}, 126 {SDL_FALSE,"IKBD joystick port 1",0},
118 {SDL_FALSE,"Xbios joystick port 1",0}, 127 {SDL_FALSE,"Xbios joystick port 1",0},
119 {SDL_FALSE,"Joypad port A",0}, 128 {SDL_FALSE,"Joypad 0 port A",0},
120 {SDL_FALSE,"Joypad port B",0}, 129 {SDL_FALSE,"Joypad 1 port A",0},
130 {SDL_FALSE,"Joypad 2 port A",0},
131 {SDL_FALSE,"Joypad 3 port A",0},
132 {SDL_FALSE,"Joypad 0 port B",0},
133 {SDL_FALSE,"Joypad 1 port B",0},
134 {SDL_FALSE,"Joypad 2 port B",0},
135 {SDL_FALSE,"Joypad 3 port B",0},
121 {SDL_FALSE,"Joystick 0 port A",0}, 136 {SDL_FALSE,"Joystick 0 port A",0},
122 {SDL_FALSE,"Joystick 1 port A",0}, 137 {SDL_FALSE,"Joystick 1 port A",0},
123 {SDL_FALSE,"Joystick 0 port B",0}, 138 {SDL_FALSE,"Joystick 0 port B",0},
124 {SDL_FALSE,"Joystick 1 port B",0}, 139 {SDL_FALSE,"Joystick 1 port B",0},
125 {SDL_FALSE,"Lightpen port A",0}, 140 {SDL_FALSE,"Lightpen port A",0},
144 /* Updated joypad ports */ 159 /* Updated joypad ports */
145 static Uint16 jp_paddles[4]; 160 static Uint16 jp_paddles[4];
146 static Uint16 jp_lightpens[2]; 161 static Uint16 jp_lightpens[2];
147 static Uint16 jp_directions; 162 static Uint16 jp_directions;
148 static Uint16 jp_fires; 163 static Uint16 jp_fires;
149 static Uint32 jp_joypads[2]; 164 static Uint32 jp_joypads[8];
150 165
151 /*--- Functions prototypes ---*/ 166 /*--- Functions prototypes ---*/
152 167
153 static int GetEnabledAtariJoystick(int index); 168 static int GetEnabledAtariJoystick(int index);
154 static void UpdateJoypads(void); 169 static void UpdateJoypads(void);
179 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || 194 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) ||
180 (cookie_mch == MCH_ARANYM<<16)) { 195 (cookie_mch == MCH_ARANYM<<16)) {
181 atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0); 196 atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0);
182 } 197 }
183 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { 198 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
184 atarijoysticks[PORTA_PAD].enabled=SDL_TRUE; 199 atarijoysticks[PORTA_PAD0].enabled =
185 atarijoysticks[PORTB_PAD].enabled=SDL_TRUE; 200 atarijoysticks[PORTA_PAD1].enabled =
201 atarijoysticks[PORTA_PAD2].enabled =
202 atarijoysticks[PORTA_PAD3].enabled =
203 atarijoysticks[PORTB_PAD0].enabled =
204 atarijoysticks[PORTB_PAD1].enabled =
205 atarijoysticks[PORTB_PAD2].enabled =
206 atarijoysticks[PORTB_PAD3].enabled = SDL_TRUE;
186 } 207 }
187 if (!atarijoysticks[IKBD_JOY1].enabled) { 208 if (!atarijoysticks[IKBD_JOY1].enabled) {
188 atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0); 209 atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0);
189 } 210 }
190 211
198 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1); 219 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
199 } 220 }
200 } 221 }
201 /* Joypads ports only on STE and Falcon */ 222 /* Joypads ports only on STE and Falcon */
202 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { 223 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
203 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD); 224 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD0);
204 if (!atarijoysticks[PORTA_PAD].enabled) { 225 if (!atarijoysticks[PORTA_PAD0].enabled) {
205 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0); 226 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
206 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1); 227 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
207 if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) { 228 if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {
208 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP); 229 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
209 if (!atarijoysticks[PORTA_LP].enabled) { 230 if (!atarijoysticks[PORTA_LP].enabled) {
210 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD); 231 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
211 } 232 }
212 } 233 }
213 } 234 }
214 235
215 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD); 236 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD0);
216 if (!atarijoysticks[PORTB_PAD].enabled) { 237 if (!atarijoysticks[PORTB_PAD0].enabled) {
217 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0); 238 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
218 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1); 239 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
219 if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) { 240 if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
220 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD); 241 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
221 } 242 }
237 #endif 258 #endif
238 } 259 }
239 260
240 /* Need to update joypad ports ? */ 261 /* Need to update joypad ports ? */
241 joypad_ports_enabled=SDL_FALSE; 262 joypad_ports_enabled=SDL_FALSE;
242 for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) { 263 for (i=PORTA_PAD0;i<=PORTB_ANPAD;i++) {
243 if (atarijoysticks[i].enabled) { 264 if (atarijoysticks[i].enabled) {
244 joypad_ports_enabled=SDL_TRUE; 265 joypad_ports_enabled=SDL_TRUE;
245 break; 266 break;
246 } 267 }
247 } 268 }
301 joystick->naxes=0; 322 joystick->naxes=0;
302 joystick->nhats=0; 323 joystick->nhats=0;
303 joystick->nballs=0; 324 joystick->nballs=0;
304 325
305 switch(numjoystick) { 326 switch(numjoystick) {
306 case PORTA_PAD: 327 case PORTA_PAD0:
307 case PORTB_PAD: 328 case PORTA_PAD1:
329 case PORTA_PAD2:
330 case PORTA_PAD3:
331 case PORTB_PAD0:
332 case PORTB_PAD1:
333 case PORTB_PAD2:
334 case PORTB_PAD3:
308 joystick->nhats=1; 335 joystick->nhats=1;
309 joystick->nbuttons=JP_NUM_BUTTONS; 336 joystick->nbuttons=JP_NUM_BUTTONS;
310 break; 337 break;
311 case PORTA_LP: 338 case PORTA_LP:
312 case PORTA_ANPAD: 339 case PORTA_ANPAD:
377 } 404 }
378 } 405 }
379 atarijoysticks[numjoystick].prevstate = curstate; 406 atarijoysticks[numjoystick].prevstate = curstate;
380 } 407 }
381 break; 408 break;
382 case PORTA_PAD: 409 case PORTA_PAD0:
383 case PORTB_PAD: 410 case PORTA_PAD1:
411 case PORTA_PAD2:
412 case PORTA_PAD3:
413 case PORTB_PAD0:
414 case PORTB_PAD1:
415 case PORTB_PAD2:
416 case PORTB_PAD3:
384 { 417 {
385 int numjoypad,i; 418 int numjoypad,i;
386 419
387 numjoypad=0; 420 numjoypad = 0;
388 if (numjoystick==PORTB_PAD) numjoypad=1; 421 switch(numjoystick) {
422 case PORTA_PAD0:
423 numjoypad = 0; break;
424 case PORTA_PAD1:
425 numjoypad = 1; break;
426 case PORTA_PAD2:
427 numjoypad = 2; break;
428 case PORTA_PAD3:
429 numjoypad = 3; break;
430 case PORTB_PAD0:
431 numjoypad = 4; break;
432 case PORTB_PAD1:
433 numjoypad = 5; break;
434 case PORTB_PAD2:
435 numjoypad = 6; break;
436 case PORTB_PAD3:
437 numjoypad = 7; break;
438 }
389 439
390 curstate=jp_joypads[numjoypad]; 440 curstate=jp_joypads[numjoypad];
391 if (curstate!=prevstate) { 441 if (curstate!=prevstate) {
392 hatstate = SDL_HAT_CENTERED; 442 hatstate = SDL_HAT_CENTERED;
393 if (curstate & (1<<JP_LEFT)) { 443 if (curstate & (1<<JP_LEFT)) {
559 Uint16 dummy2[4]; 609 Uint16 dummy2[4];
560 Uint16 lightpens[2]; 610 Uint16 lightpens[2];
561 }; 611 };
562 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE)) 612 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
563 613
614 static const Uint16 joypad_masks[8*4]={
615 0xfffe, 0xfffd, 0xfffb, 0xfff7,
616 0xfff0, 0xfff1, 0xfff2, 0xfff3,
617 0xfff4, 0xfff5, 0xfff6, 0xfff8,
618 0xfff9, 0xfffa, 0xfffc, 0xffff,
619 0xffef, 0xffdf, 0xffbf, 0xff7f,
620 0xff0f, 0xff1f, 0xff2f, 0xff3f,
621 0xff4f, 0xff5f, 0xff6f, 0xff8f,
622 0xff9f, 0xffaf, 0xffcf, 0xffff
623 };
624
564 static void UpdateJoypads(void) 625 static void UpdateJoypads(void)
565 { 626 {
566 Uint16 tmp; 627 Uint16 tmp, i, j;
628 Uint32 cur_fire, cur_dir;
567 629
568 /*--- This function is called in supervisor mode ---*/ 630 /*--- This function is called in supervisor mode ---*/
569 631
570 /* Update joysticks */ 632 /* Update joysticks */
571 jp_fires = (~(JOYPAD_IO.fires)) & 15; 633 jp_fires = (~(JOYPAD_IO.fires)) & 15;
585 tmp = (JOYPAD_IO.paddles[2] & 255); 647 tmp = (JOYPAD_IO.paddles[2] & 255);
586 jp_paddles[2] = (tmp<<8) | tmp; 648 jp_paddles[2] = (tmp<<8) | tmp;
587 tmp = (JOYPAD_IO.paddles[3] & 255); 649 tmp = (JOYPAD_IO.paddles[3] & 255);
588 jp_paddles[3] = (tmp<<8) | tmp; 650 jp_paddles[3] = (tmp<<8) | tmp;
589 651
590 /* Update joypad 0 */ 652 /* Update joypads on teamtap port A */
591 JOYPAD_IO.directions=0xfffe; 653 for (i=0; i<4; i++) {
592 jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16); 654 jp_joypads[i] = 0;
593 JOYPAD_IO.directions=0xfffe; 655 for (j=0; j<4; j++) {
594 jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15; 656 JOYPAD_IO.directions = joypad_masks[(i*4)+j];
595 657
596 JOYPAD_IO.directions=0xfffd; 658 cur_fire = (~(JOYPAD_IO.fires) & 3)<<16;
597 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2); 659 cur_dir = (~(JOYPAD_IO.directions)>>8) & 15;
598 JOYPAD_IO.directions=0xfffd; 660
599 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4; 661 jp_joypads[i] |= cur_fire<<(j*2);
600 662 jp_joypads[i] |= cur_dir<<(j*4);
601 JOYPAD_IO.directions=0xfffb; 663 }
602 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4); 664 }
603 JOYPAD_IO.directions=0xfffb; 665
604 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8; 666 /* Update joypads on teamtap port B */
605 667 for (i=4; i<8; i++) {
606 JOYPAD_IO.directions=0xfff7; 668 jp_joypads[i] = 0;
607 jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6); 669 for (j=0; j<4; j++) {
608 JOYPAD_IO.directions=0xfff7; 670 JOYPAD_IO.directions = joypad_masks[(i*4)+j];
609 jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12; 671
610 672 cur_fire = (~(JOYPAD_IO.fires) & 0xc)<<14;
611 /* Update joypad 1 */ 673 cur_dir = (~(JOYPAD_IO.directions)>>12) & 15;
612 JOYPAD_IO.directions=0xffef; 674
613 jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2); 675 jp_joypads[i] |= cur_fire<<(j*2);
614 JOYPAD_IO.directions=0xffef; 676 jp_joypads[i] |= cur_dir<<(j*4);
615 jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15; 677 }
616 678 }
617 JOYPAD_IO.directions=0xffdf; 679
618 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16); 680 JOYPAD_IO.directions=0xffff;
619 JOYPAD_IO.directions=0xffdf;
620 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4;
621
622 JOYPAD_IO.directions=0xffbf;
623 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2);
624 JOYPAD_IO.directions=0xffbf;
625 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8;
626
627 JOYPAD_IO.directions=0xff7f;
628 jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4);
629 JOYPAD_IO.directions=0xff7f;
630 jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12;
631 } 681 }
632 682
633 #endif /* SDL_JOYSTICK_MINT */ 683 #endif /* SDL_JOYSTICK_MINT */