1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2006 Sam Lantinga
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 #ifdef SDL_JOYSTICK_MINT
25
26 /*
27 * Atari Joystick/Joypad drivers
28 *
29 * Patrice Mandin
30 */
31
32 #include <mint/cookie.h>
33 #include <mint/osbind.h>
34
35 #include "SDL_events.h"
36 #include "../SDL_sysjoystick.h"
37 #include "../SDL_joystick_c.h"
38
39 #include "../../video/ataricommon/SDL_ikbdinterrupt_s.h"
40 #include "../../video/ataricommon/SDL_xbiosevents_c.h"
41 #include "../../video/ataricommon/SDL_xbiosinterrupt_s.h"
42
43 /*--- Const ---*/
44
45 /* We can have:
46 1 joystick on IKBD port 1, read via hardware I/O
47 or same joystick on IKBD port 1, read via xbios
48 1 joypad on port A (up to 4 with teamtap)
49 or 2 joysticks on joypad port A
50 or 1 analog paddle on joypad port A
51 or 1 lightpen on joypad port A
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
55 2 joysticks on parallel port
56 */
57
58 enum {
59 IKBD_JOY1=0,
60 XBIOS_JOY1,
61 PORTA_PAD0,
62 PORTA_PAD1,
63 PORTA_PAD2,
64 PORTA_PAD3,
65 PORTB_PAD0,
66 PORTB_PAD1,
67 PORTB_PAD2,
68 PORTB_PAD3,
69 PORTA_JOY0,
70 PORTA_JOY1,
71 PORTB_JOY0,
72 PORTB_JOY1,
73 PORTA_LP,
74 PORTA_ANPAD,
75 PORTB_ANPAD,
76 #if 0
77 PARA_JOY0,
78 PARA_JOY1,
79 #endif
80 MAX_JOYSTICKS
81 };
82
83 enum {
84 MCH_ST=0,
85 MCH_STE,
86 MCH_TT,
87 MCH_F30,
88 MCH_CLONE,
89 MCH_ARANYM
90 };
91
92 /* Joypad buttons
93 * Procontroller note:
94 * L,R are connected to 4,6
95 * X,Y,Z are connected to 7,8,9
96 */
97
98 enum {
99 JP_UP=0, JP_DOWN, JP_LEFT, JP_RIGHT,
100 JP_KPMULT, JP_KP7, JP_KP4, JP_KP1,
101 JP_KP0, JP_KP8, JP_KP5, JP_KP2,
102 JP_KPNUM, JP_KP9, JP_KP6, JP_KP3,
103 JP_PAUSE, JP_FIRE0, JP_UNDEF0, JP_FIRE1,
104 JP_UNDEF1, JP_FIRE2, JP_UNDEF2, JP_OPTION
105 };
106
107 #define JP_NUM_BUTTONS 17
108
109 #define PORT_JS_RIGHT (1<<0)
110 #define PORT_JS_LEFT (1<<1)
111 #define PORT_JS_DOWN (1<<2)
112 #define PORT_JS_UP (1<<3)
113 #define PORT_JS_FIRE (1<<4)
114
115 /*--- Types ---*/
116
117 typedef struct {
118 SDL_bool enabled;
119 unsigned char *name;
120 Uint32 prevstate;
121 } atarijoy_t;
122
123 /*--- Variables ---*/
124
125 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
126 {SDL_FALSE,"IKBD joystick port 1",0},
127 {SDL_FALSE,"Xbios joystick port 1",0},
128 {SDL_FALSE,"Joypad 0 port A",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},
136 {SDL_FALSE,"Joystick 0 port A",0},
137 {SDL_FALSE,"Joystick 1 port A",0},
138 {SDL_FALSE,"Joystick 0 port B",0},
139 {SDL_FALSE,"Joystick 1 port B",0},
140 {SDL_FALSE,"Lightpen port A",0},
141 {SDL_FALSE,"Analog paddle port A",0},
142 {SDL_FALSE,"Analog paddle port B",0}
143 #if 0
144 ,{SDL_FALSE,"Joystick 0 parallel port",0},
145 {SDL_FALSE,"Joystick 1 parallel port",0}
146 #endif
147 };
148
149 static const int jp_buttons[JP_NUM_BUTTONS]={
150 JP_FIRE0, JP_FIRE1, JP_FIRE2, JP_PAUSE,
151 JP_OPTION, JP_KPMULT, JP_KPNUM, JP_KP0,
152 JP_KP1, JP_KP2, JP_KP3, JP_KP4,
153 JP_KP5, JP_KP6, JP_KP7, JP_KP8,
154 JP_KP9
155 };
156
157 static SDL_bool joypad_ports_enabled=SDL_FALSE;
158
159 /* Updated joypad ports */
160 static Uint16 jp_paddles[4];
161 static Uint16 jp_lightpens[2];
162 static Uint16 jp_directions;
163 static Uint16 jp_fires;
164 static Uint32 jp_joypads[8];
165
166 /*--- Functions prototypes ---*/
167
168 static int GetEnabledAtariJoystick(int index);
169 static void UpdateJoypads(void);
170
171 /*--- Functions ---*/
172
SDL_SYS_JoystickInit(void)173 int SDL_SYS_JoystickInit(void)
174 {
175 int i;
176 unsigned long cookie_mch;
177 const char *envr=SDL_getenv("SDL_JOYSTICK_ATARI");
178
179 #define TEST_JOY_ENABLED(env,idstring,num) \
180 if (SDL_strstr(env,idstring"-off")) { \
181 atarijoysticks[num].enabled=SDL_FALSE; \
182 } \
183 if (SDL_strstr(env,idstring"-on")) { \
184 atarijoysticks[num].enabled=SDL_TRUE; \
185 }
186
187 /* Cookie _MCH present ? if not, assume ST machine */
188 if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) {
189 cookie_mch = MCH_ST << 16;
190 }
191
192 /* Enable some default joysticks */
193 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
194 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) ||
195 (cookie_mch == MCH_ARANYM<<16)) {
196 atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0);
197 }
198 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
199 atarijoysticks[PORTA_PAD0].enabled =
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;
207 }
208 if (!atarijoysticks[IKBD_JOY1].enabled) {
209 atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0);
210 }
211
212 /* Read environment for joysticks to enable */
213 if (envr) {
214 /* IKBD on any Atari, maybe clones */
215 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
216 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) ||
217 (cookie_mch == MCH_ARANYM<<16)) {
218 if (SDL_AtariIkbd_enabled!=0) {
219 TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
220 }
221 }
222 /* Joypads ports only on STE and Falcon */
223 if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
224 TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD0);
225 if (!atarijoysticks[PORTA_PAD0].enabled) {
226 TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
227 TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
228 if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {
229 TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
230 if (!atarijoysticks[PORTA_LP].enabled) {
231 TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
232 }
233 }
234 }
235
236 TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD0);
237 if (!atarijoysticks[PORTB_PAD0].enabled) {
238 TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
239 TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
240 if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
241 TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
242 }
243 }
244 }
245
246 if (!atarijoysticks[IKBD_JOY1].enabled) {
247 if (SDL_AtariXbios_enabled!=0) {
248 TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1);
249 }
250 }
251 #if 0
252 /* Parallel port on any Atari, maybe clones */
253 if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
254 (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
255 TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);
256 TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1);
257 }
258 #endif
259 }
260
261 /* Need to update joypad ports ? */
262 joypad_ports_enabled=SDL_FALSE;
263 for (i=PORTA_PAD0;i<=PORTB_ANPAD;i++) {
264 if (atarijoysticks[i].enabled) {
265 joypad_ports_enabled=SDL_TRUE;
266 break;
267 }
268 }
269
270 SDL_numjoysticks = 0;
271 for (i=0;i<MAX_JOYSTICKS;i++) {
272 if (atarijoysticks[i].enabled) {
273 ++SDL_numjoysticks;
274 }
275 }
276
277 return(SDL_numjoysticks);
278 }
279
GetEnabledAtariJoystick(int index)280 static int GetEnabledAtariJoystick(int index)
281 {
282 int i,j;
283
284 /* Return the nth'index' enabled atari joystick */
285 j=0;
286 for (i=0;i<MAX_JOYSTICKS;i++) {
287 if (!atarijoysticks[i].enabled) {
288 continue;
289 }
290
291 if (j==index) {
292 break;
293 }
294
295 ++j;
296 }
297 if (i==MAX_JOYSTICKS)
298 return -1;
299
300 return i;
301 }
302
SDL_SYS_JoystickName(int index)303 const char *SDL_SYS_JoystickName(int index)
304 {
305 int numjoystick;
306
307 numjoystick=GetEnabledAtariJoystick(index);
308 if (numjoystick==-1)
309 return NULL;
310
311 return(atarijoysticks[numjoystick].name);
312 }
313
SDL_SYS_JoystickOpen(SDL_Joystick * joystick)314 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
315 {
316 int numjoystick;
317
318 numjoystick=GetEnabledAtariJoystick(joystick->index);
319 if (numjoystick==-1)
320 return -1;
321
322 joystick->naxes=0;
323 joystick->nhats=0;
324 joystick->nballs=0;
325
326 switch(numjoystick) {
327 case PORTA_PAD0:
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:
335 joystick->nhats=1;
336 joystick->nbuttons=JP_NUM_BUTTONS;
337 break;
338 case PORTA_LP:
339 case PORTA_ANPAD:
340 case PORTB_ANPAD:
341 joystick->naxes=2;
342 joystick->nbuttons=2;
343 break;
344 default:
345 joystick->nhats=1;
346 joystick->nbuttons=1;
347 break;
348 }
349
350 return(0);
351 }
352
SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)353 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
354 {
355 int numjoystick;
356 Uint8 hatstate;
357 Uint32 curstate,prevstate;
358
359 numjoystick=GetEnabledAtariJoystick(joystick->index);
360 if (numjoystick==-1)
361 return;
362
363 prevstate = atarijoysticks[numjoystick].prevstate;
364
365 if (joypad_ports_enabled) {
366 Supexec(UpdateJoypads);
367 }
368
369 switch (numjoystick) {
370 case IKBD_JOY1:
371 case XBIOS_JOY1:
372 {
373 curstate = 0;
374
375 if (numjoystick==IKBD_JOY1) {
376 curstate = SDL_AtariIkbd_joystick & 0xff;
377 }
378 if (numjoystick==XBIOS_JOY1) {
379 curstate = SDL_AtariXbios_joystick & 0xff;
380 }
381
382 if (curstate != prevstate) {
383 hatstate = SDL_HAT_CENTERED;
384 if (curstate & IKBD_JOY_LEFT) {
385 hatstate |= SDL_HAT_LEFT;
386 }
387 if (curstate & IKBD_JOY_RIGHT) {
388 hatstate |= SDL_HAT_RIGHT;
389 }
390 if (curstate & IKBD_JOY_UP) {
391 hatstate |= SDL_HAT_UP;
392 }
393 if (curstate & IKBD_JOY_DOWN) {
394 hatstate |= SDL_HAT_DOWN;
395 }
396 SDL_PrivateJoystickHat(joystick, 0, hatstate);
397
398 /* Button */
399 if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) {
400 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
401 }
402 if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) {
403 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
404 }
405 }
406 atarijoysticks[numjoystick].prevstate = curstate;
407 }
408 break;
409 case PORTA_PAD0:
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:
417 {
418 int numjoypad,i;
419
420 numjoypad = 0;
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 }
439
440 curstate=jp_joypads[numjoypad];
441 if (curstate!=prevstate) {
442 hatstate = SDL_HAT_CENTERED;
443 if (curstate & (1<<JP_LEFT)) {
444 hatstate |= SDL_HAT_LEFT;
445 }
446 if (curstate & (1<<JP_RIGHT)) {
447 hatstate |= SDL_HAT_RIGHT;
448 }
449 if (curstate & (1<<JP_UP)) {
450 hatstate |= SDL_HAT_UP;
451 }
452 if (curstate & (1<<JP_DOWN)) {
453 hatstate |= SDL_HAT_DOWN;
454 }
455 SDL_PrivateJoystickHat(joystick, 0, hatstate);
456
457 /* Buttons */
458 for (i=0;i<JP_NUM_BUTTONS;i++) {
459 int button;
460
461 button=1<<jp_buttons[i];
462
463 if ((curstate & button) && !(prevstate & button)) {
464 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
465 }
466 if (!(curstate & button) && (prevstate & button)) {
467 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
468 }
469 }
470 }
471 atarijoysticks[numjoystick].prevstate = curstate;
472 }
473 break;
474 case PORTA_JOY0:
475 case PORTA_JOY1:
476 case PORTB_JOY0:
477 case PORTB_JOY1:
478 {
479 int fire_shift=0,dir_shift=0;
480
481 if (numjoystick==PORTA_JOY0) { fire_shift=0; dir_shift=0; }
482 if (numjoystick==PORTA_JOY1) { fire_shift=1; dir_shift=4; }
483 if (numjoystick==PORTB_JOY0) { fire_shift=2; dir_shift=8; }
484 if (numjoystick==PORTB_JOY1) { fire_shift=3; dir_shift=12; }
485
486 curstate = (jp_directions>>dir_shift) & 15;
487 curstate |= ((jp_fires>>fire_shift) & 1)<<4;
488
489 if (curstate != prevstate) {
490 hatstate = SDL_HAT_CENTERED;
491 if (curstate & PORT_JS_LEFT) {
492 hatstate |= SDL_HAT_LEFT;
493 }
494 if (curstate & PORT_JS_RIGHT) {
495 hatstate |= SDL_HAT_RIGHT;
496 }
497 if (curstate & PORT_JS_UP) {
498 hatstate |= SDL_HAT_UP;
499 }
500 if (curstate & PORT_JS_DOWN) {
501 hatstate |= SDL_HAT_DOWN;
502 }
503 SDL_PrivateJoystickHat(joystick, 0, hatstate);
504
505 /* Button */
506 if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) {
507 SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
508 }
509 if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) {
510 SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
511 }
512 }
513 atarijoysticks[numjoystick].prevstate = curstate;
514 }
515 break;
516 case PORTA_LP:
517 {
518 int i;
519
520 curstate = jp_lightpens[0]>>1;
521 curstate |= (jp_lightpens[1]>>1)<<15;
522 curstate |= (jp_fires & 3)<<30;
523
524 if (curstate != prevstate) {
525 /* X axis */
526 SDL_PrivateJoystickAxis(joystick,0,jp_lightpens[0] ^ 0x8000);
527 /* Y axis */
528 SDL_PrivateJoystickAxis(joystick,1,jp_lightpens[1] ^ 0x8000);
529 /* Buttons */
530 for (i=0;i<2;i++) {
531 int button;
532
533 button=1<<(30+i);
534
535 if ((curstate & button) && !(prevstate & button)) {
536 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
537 }
538 if (!(curstate & button) && (prevstate & button)) {
539 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
540 }
541 }
542 }
543 atarijoysticks[numjoystick].prevstate = curstate;
544 }
545 break;
546 case PORTA_ANPAD:
547 case PORTB_ANPAD:
548 {
549 int numpaddle, i;
550
551 numpaddle=0<<1;
552 if (numjoystick==PORTB_ANPAD) numpaddle=1<<1;
553
554 curstate = jp_paddles[numpaddle]>>1;
555 curstate |= (jp_paddles[numpaddle+1]>>1)<<15;
556 curstate |= ((jp_fires>>numpaddle) & 3)<<30;
557
558 if (curstate != prevstate) {
559 /* X axis */
560 SDL_PrivateJoystickAxis(joystick,0,jp_paddles[numpaddle] ^ 0x8000);
561 /* Y axis */
562 SDL_PrivateJoystickAxis(joystick,1,jp_paddles[numpaddle+1] ^ 0x8000);
563 /* Buttons */
564 for (i=0;i<2;i++) {
565 int button;
566
567 button=1<<(30+i);
568
569 if ((curstate & button) && !(prevstate & button)) {
570 SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
571 }
572 if (!(curstate & button) && (prevstate & button)) {
573 SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
574 }
575 }
576 }
577 atarijoysticks[numjoystick].prevstate = curstate;
578 }
579 break;
580 #if 0
581 case PARA_JOY0:
582 case PARA_JOY1:
583 break;
584 #endif
585 };
586
587 return;
588 }
589
SDL_SYS_JoystickClose(SDL_Joystick * joystick)590 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
591 {
592 return;
593 }
594
SDL_SYS_JoystickQuit(void)595 void SDL_SYS_JoystickQuit(void)
596 {
597 SDL_numjoysticks=0;
598 return;
599 }
600
601 /*--- Joypad I/O read/write interface ---*/
602
603 #define JOYPAD_IO_BASE (0xffff9200)
604 struct JOYPAD_IO_S {
605 Uint16 fires;
606 Uint16 directions;
607 Uint16 dummy1[6];
608 Uint16 paddles[4];
609 Uint16 dummy2[4];
610 Uint16 lightpens[2];
611 };
612 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
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
UpdateJoypads(void)625 static void UpdateJoypads(void)
626 {
627 Uint16 tmp, i, j;
628 Uint32 cur_fire, cur_dir;
629
630 /*--- This function is called in supervisor mode ---*/
631
632 /* Update joysticks */
633 jp_fires = (~(JOYPAD_IO.fires)) & 15;
634 jp_directions = (~(JOYPAD_IO.directions));
635
636 /* Update lightpen */
637 tmp = JOYPAD_IO.lightpens[0] & 1023;
638 jp_lightpens[0] = (tmp<<6) | (tmp>>4);
639 tmp = JOYPAD_IO.lightpens[1] & 1023;
640 jp_lightpens[1] = (tmp<<6) | (tmp>>4);
641
642 /* Update paddles */
643 tmp = (JOYPAD_IO.paddles[0] & 255);
644 jp_paddles[0] = (tmp<<8) | tmp;
645 tmp = (JOYPAD_IO.paddles[1] & 255);
646 jp_paddles[1] = (tmp<<8) | tmp;
647 tmp = (JOYPAD_IO.paddles[2] & 255);
648 jp_paddles[2] = (tmp<<8) | tmp;
649 tmp = (JOYPAD_IO.paddles[3] & 255);
650 jp_paddles[3] = (tmp<<8) | tmp;
651
652 /* Update joypads on teamtap port A */
653 for (i=0; i<4; i++) {
654 jp_joypads[i] = 0;
655 for (j=0; j<4; j++) {
656 JOYPAD_IO.directions = joypad_masks[(i*4)+j];
657
658 cur_fire = (~(JOYPAD_IO.fires) & 3)<<16;
659 cur_dir = (~(JOYPAD_IO.directions)>>8) & 15;
660
661 jp_joypads[i] |= cur_fire<<(j*2);
662 jp_joypads[i] |= cur_dir<<(j*4);
663 }
664 }
665
666 /* Update joypads on teamtap port B */
667 for (i=4; i<8; i++) {
668 jp_joypads[i] = 0;
669 for (j=0; j<4; j++) {
670 JOYPAD_IO.directions = joypad_masks[(i*4)+j];
671
672 cur_fire = (~(JOYPAD_IO.fires) & 0xc)<<14;
673 cur_dir = (~(JOYPAD_IO.directions)>>12) & 15;
674
675 jp_joypads[i] |= cur_fire<<(j*2);
676 jp_joypads[i] |= cur_dir<<(j*4);
677 }
678 }
679
680 JOYPAD_IO.directions=0xffff;
681 }
682
683 #endif /* SDL_JOYSTICK_MINT */
684