src/joystick/mint/SDL_sysjoystick.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 10 Mar 2002 03:33:59 +0000
changeset 305 9c6613983e85
parent 302 8a86bdf34f0f
child 507 7853b6af5957
permissions -rw-r--r--
Atari port cleanups from Patrice
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Library General Public
     7     License as published by the Free Software Foundation; either
     8     version 2 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     Library General Public License for more details.
    14 
    15     You should have received a copy of the GNU Library General Public
    16     License along with this library; if not, write to the Free
    17     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 
    23 #ifdef SAVE_RCSID
    24 static char rcsid =
    25  "@(#) $Id$";
    26 #endif
    27 
    28 /*
    29  *	Atari Joystick/Joypad drivers
    30  *
    31  *	Patrice Mandin
    32  */
    33 
    34 #include <stdio.h>
    35 #include <stdlib.h>
    36 #include <string.h>
    37 
    38 #include <sys/cookie.h>
    39 #include <mint/osbind.h>
    40 
    41 #include "SDL_types.h"
    42 #include "SDL_error.h"
    43 #include "SDL_joystick.h"
    44 #include "SDL_sysjoystick.h"
    45 #include "SDL_joystick_c.h"
    46 
    47 #include "SDL_ikbdinterrupt_s.h"
    48 #include "SDL_xbiosevents_c.h"
    49 #include "SDL_xbiosinterrupt_s.h"
    50 
    51 /*--- Const ---*/
    52 
    53 /* We can have:
    54 	1 joystick on IKBD port 1, read via hardware I/O
    55       or same joystick on IKBD port 1, read via xbios
    56 	2 joypads on ports A,B
    57 	  or 4 joysticks on joypads ports A,B
    58 	  or 1 lightpen on joypad port A
    59 	  or 2 analog paddles on joypads ports A,B
    60 	2 joysticks on parallel port
    61 */
    62 
    63 enum {
    64 	IKBD_JOY1=0,
    65 	XBIOS_JOY1,
    66 	PORTA_PAD,
    67 	PORTB_PAD,
    68 	PORTA_JOY0,
    69 	PORTA_JOY1,
    70 	PORTB_JOY0,
    71 	PORTB_JOY1,
    72 	PORTA_LP,
    73 	PORTA_ANPAD,
    74 	PORTB_ANPAD,
    75 #if 0
    76 	PARA_JOY0,
    77 	PARA_JOY1,
    78 #endif
    79 	MAX_JOYSTICKS
    80 };
    81 
    82 enum {
    83 	MCH_ST=0,
    84 	MCH_STE,
    85 	MCH_TT,
    86 	MCH_F30
    87 };
    88 
    89 /*	Joypad buttons
    90  *		Procontroller note:
    91  *			L,R are connected to 4,6
    92  *			X,Y,Z are connected to 7,8,9
    93  */
    94 
    95 enum {
    96 	JP_UP=0,	JP_DOWN,	JP_LEFT,	JP_RIGHT,
    97 	JP_KPMULT,	JP_KP7,		JP_KP4,		JP_KP1,
    98 	JP_KP0,		JP_KP8,		JP_KP5,		JP_KP2,
    99 	JP_KPNUM,	JP_KP9,		JP_KP6,		JP_KP3,
   100 	JP_PAUSE,	JP_FIRE0,	JP_UNDEF0,	JP_FIRE1,
   101 	JP_UNDEF1,	JP_FIRE2,	JP_UNDEF2,	JP_OPTION
   102 };
   103 
   104 #define JP_NUM_BUTTONS 17
   105 
   106 #define PORT_JS_RIGHT	(1<<0)
   107 #define PORT_JS_LEFT	(1<<1)
   108 #define PORT_JS_DOWN	(1<<2)
   109 #define PORT_JS_UP		(1<<3)
   110 #define PORT_JS_FIRE	(1<<4)
   111 
   112 /*--- Types ---*/
   113 
   114 typedef struct {
   115 	SDL_bool enabled;
   116 	unsigned char *name;
   117 	Uint32 prevstate;
   118 } atarijoy_t;
   119 
   120 /*--- Variables ---*/
   121 
   122 static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
   123 	{SDL_FALSE,"IKBD joystick port 1",0},
   124 	{SDL_FALSE,"Xbios joystick port 1",0},
   125 	{SDL_FALSE,"Joypad port A",0},
   126 	{SDL_FALSE,"Joypad port B",0},
   127 	{SDL_FALSE,"Joystick 0 port A",0},
   128 	{SDL_FALSE,"Joystick 1 port A",0},
   129 	{SDL_FALSE,"Joystick 0 port B",0},
   130 	{SDL_FALSE,"Joystick 1 port B",0},
   131 	{SDL_FALSE,"Lightpen port A",0},
   132 	{SDL_FALSE,"Analog paddle port A",0},
   133 	{SDL_FALSE,"Analog paddle port B",0}
   134 #if 0
   135 	,{SDL_FALSE,"Joystick 0 parallel port",0},
   136 	{SDL_FALSE,"Joystick 1 parallel port",0}
   137 #endif
   138 };
   139 
   140 static const int jp_buttons[JP_NUM_BUTTONS]={
   141 	JP_FIRE0,	JP_FIRE1,	JP_FIRE2,	JP_PAUSE,
   142 	JP_OPTION,	JP_KPMULT,	JP_KPNUM,	JP_KP0,
   143 	JP_KP1,		JP_KP2,		JP_KP3,		JP_KP4,
   144 	JP_KP5,		JP_KP6,		JP_KP7,		JP_KP8,
   145 	JP_KP9
   146 };
   147 
   148 static SDL_bool joypad_ports_enabled=SDL_FALSE;
   149 
   150 /* Updated joypad ports */
   151 static Uint16 jp_paddles[4];
   152 static Uint16 jp_lightpens[2];
   153 static Uint16 jp_directions;
   154 static Uint16 jp_fires;
   155 static Uint32 jp_joypads[2];
   156 
   157 /*--- Functions prototypes ---*/
   158 
   159 static int GetEnabledAtariJoystick(int index);
   160 static void UpdateJoypads(void);
   161 
   162 /*--- Functions ---*/
   163 
   164 int SDL_SYS_JoystickInit(void)
   165 {
   166 	int i;
   167 	unsigned long cookie_mch;
   168 	const char *envr=getenv("SDL_JOYSTICK_ATARI");
   169 	
   170 #define TEST_JOY_ENABLED(env,idstring,num) \
   171 	if (strstr(env,idstring"-off")) { \
   172 		atarijoysticks[num].enabled=SDL_FALSE; \
   173 	} \
   174 	if (strstr(env,idstring"-on")) { \
   175 		atarijoysticks[num].enabled=SDL_TRUE; \
   176 	}
   177 
   178 	/* Cookie _MCH present ? if not, assume ST machine */
   179 	if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) {
   180 		cookie_mch = MCH_ST << 16;
   181 	}
   182 
   183 	/* Enable some default joysticks */
   184 	if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
   185 		(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
   186 		atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0);
   187 	}
   188 	if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
   189 		atarijoysticks[PORTA_PAD].enabled=SDL_TRUE;
   190 		atarijoysticks[PORTB_PAD].enabled=SDL_TRUE;
   191 	}
   192 	if (!atarijoysticks[IKBD_JOY1].enabled) {
   193 		atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0);
   194 	}
   195 
   196 	/* Read environment for joysticks to enable */
   197 	if (envr) {
   198 		/* IKBD on any Atari, maybe clones */
   199 		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
   200 			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
   201 			if (SDL_AtariIkbd_enabled!=0) {
   202 				TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
   203 			}
   204 		}
   205 		/* Joypads ports only on STE and Falcon */
   206 		if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
   207 			TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
   208 			if (!atarijoysticks[PORTA_PAD].enabled) {
   209 				TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
   210 				TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
   211 				if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {
   212 					TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
   213 					if (!atarijoysticks[PORTA_LP].enabled) {
   214 						TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
   215 					}
   216 				}
   217 			}
   218 
   219 			TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD);
   220 			if (!atarijoysticks[PORTB_PAD].enabled) {
   221 				TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
   222 				TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
   223 				if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
   224 					TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
   225 				}
   226 			}
   227 		}
   228 
   229 		if (!atarijoysticks[IKBD_JOY1].enabled) {
   230 			if (SDL_AtariXbios_enabled!=0) {
   231 				TEST_JOY_ENABLED(envr, "xbios-joy1", XBIOS_JOY1);
   232 			}
   233 		}
   234 #if 0
   235 		/* Parallel port on any Atari, maybe clones */
   236 		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
   237 			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
   238 			TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);
   239 			TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1);
   240 		}
   241 #endif
   242 	}
   243 
   244 	/* Need to update joypad ports ? */
   245 	joypad_ports_enabled=SDL_FALSE;
   246 	for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) {
   247 		if (atarijoysticks[i].enabled) {
   248 			joypad_ports_enabled=SDL_TRUE;
   249 			break;
   250 		}
   251 	}
   252 
   253 	SDL_numjoysticks = 0;
   254 	for (i=0;i<MAX_JOYSTICKS;i++) {
   255 		if (atarijoysticks[i].enabled) {
   256 			++SDL_numjoysticks;
   257 		}
   258 	}
   259 
   260 	return(SDL_numjoysticks);
   261 }
   262 
   263 static int GetEnabledAtariJoystick(int index)
   264 {
   265 	int i,j;
   266 
   267 	/* Return the nth'index' enabled atari joystick */
   268 	j=0;
   269 	for (i=0;i<MAX_JOYSTICKS;i++) {
   270 		if (!atarijoysticks[i].enabled) {
   271 			continue;
   272 		}
   273 
   274 		if (j==index) {
   275 			break;
   276 		}
   277 
   278 		++j;
   279 	}
   280 	if (i==MAX_JOYSTICKS)
   281 		return -1;
   282 
   283 	return i;
   284 }
   285 
   286 const char *SDL_SYS_JoystickName(int index)
   287 {
   288 	int numjoystick;
   289 
   290 	numjoystick=GetEnabledAtariJoystick(index);
   291 	if (numjoystick==-1)
   292 		return NULL;
   293 
   294 	return(atarijoysticks[numjoystick].name);
   295 }
   296 
   297 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
   298 {
   299 	int numjoystick;
   300 	
   301 	numjoystick=GetEnabledAtariJoystick(joystick->index);
   302 	if (numjoystick==-1)
   303 		return -1;
   304 	
   305 	if ((numjoystick==PORTA_PAD) || (numjoystick==PORTB_PAD)) {
   306 		joystick->nbuttons=JP_NUM_BUTTONS;
   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;
   315 	joystick->nhats=0;
   316 
   317 	return(0);
   318 }
   319 
   320 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
   321 {
   322 	int numjoystick;
   323 	Uint32 curstate,prevstate;
   324 	Sint16 curaxis;
   325 	
   326 	numjoystick=GetEnabledAtariJoystick(joystick->index);
   327 	if (numjoystick==-1)
   328 		return;
   329 
   330 	prevstate = atarijoysticks[numjoystick].prevstate;
   331 
   332 	if (joypad_ports_enabled) {
   333 		Supexec(UpdateJoypads);
   334 	}
   335 
   336 	switch (numjoystick) {
   337 		case IKBD_JOY1:
   338 		case XBIOS_JOY1:
   339 			{
   340 				curstate = 0;
   341 
   342 				if (numjoystick==IKBD_JOY1) {
   343 					curstate = SDL_AtariIkbd_joystick & 0xff;
   344 				}
   345 				if (numjoystick==XBIOS_JOY1) {
   346 					curstate = SDL_AtariXbios_joystick & 0xff;
   347 				}
   348 
   349 				if (curstate != prevstate) {
   350 					/* X axis */
   351 					if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) {
   352 						curaxis=0;
   353 						if (curstate & IKBD_JOY_LEFT) {
   354 							curaxis=-128;
   355 						} else if (curstate & IKBD_JOY_RIGHT) {
   356 							curaxis=127;
   357 						}					
   358 						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   359 					}
   360 					/* Y axis */
   361 					if ((curstate & (IKBD_JOY_UP|IKBD_JOY_DOWN)) != (prevstate & (IKBD_JOY_UP|IKBD_JOY_DOWN))) {
   362 						curaxis=0;
   363 						if (curstate & IKBD_JOY_UP) {
   364 							curaxis=-128;
   365 						} else if (curstate & IKBD_JOY_DOWN) {
   366 							curaxis=127;
   367 						}					
   368 						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   369 					}
   370 					/* Button */
   371 					if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) {
   372 						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
   373 					}
   374 					if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) {
   375 						SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
   376 					}
   377 				}
   378 				atarijoysticks[numjoystick].prevstate = curstate;
   379 			}
   380 			break;
   381 		case PORTA_PAD:
   382 		case PORTB_PAD:
   383 			{
   384 				int numjoypad,i;
   385 				
   386 				numjoypad=0;
   387 /*				if (numjoystick==PORTA_PAD) numjoypad=0;*/
   388 				if (numjoystick==PORTB_PAD) numjoypad=1;
   389 				
   390 				curstate=jp_joypads[numjoypad];
   391 				if (curstate!=prevstate) {
   392 					/* X axis */
   393 					if ((curstate & ((1<<JP_LEFT)|(1<<JP_RIGHT))) != (prevstate & ((1<<JP_LEFT)|(1<<JP_RIGHT)))) {
   394 						curaxis=0;
   395 						if (curstate & (1<<JP_LEFT)) {
   396 							curaxis=-128;
   397 						} else if (curstate & (1<<JP_RIGHT)) {
   398 							curaxis=127;
   399 						}					
   400 						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   401 					}
   402 					/* Y axis */
   403 					if ((curstate & ((1<<JP_UP)|(1<<JP_DOWN))) != (prevstate & ((1<<JP_UP)|(1<<JP_DOWN)))) {
   404 						curaxis=0;
   405 						if (curstate & (1<<JP_UP)) {
   406 							curaxis=-128;
   407 						} else if (curstate & (1<<JP_DOWN)) {
   408 							curaxis=127;
   409 						}					
   410 						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   411 					}
   412 					/* Buttons */
   413 					for (i=0;i<JP_NUM_BUTTONS;i++) {
   414 						int button;
   415 						
   416 						button=1<<jp_buttons[i];
   417 
   418 						if ((curstate & button) && !(prevstate & button)) {
   419 							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
   420 						}
   421 						if (!(curstate & button) && (prevstate & button)) {
   422 							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
   423 						}
   424 					}
   425 				}
   426 				atarijoysticks[numjoystick].prevstate = curstate;
   427 			}
   428 			break;
   429 		case PORTA_JOY0:
   430 		case PORTA_JOY1:
   431 		case PORTB_JOY0:
   432 		case PORTB_JOY1:
   433 			{
   434 				int fire_shift=0,dir_shift=0;
   435 				
   436 				if (numjoystick==PORTA_JOY0) {	fire_shift=0; dir_shift=0; }
   437 				if (numjoystick==PORTA_JOY1) {	fire_shift=1; dir_shift=4; }
   438 				if (numjoystick==PORTB_JOY0) {	fire_shift=2; dir_shift=8; }
   439 				if (numjoystick==PORTB_JOY1) {	fire_shift=3; dir_shift=12; }
   440 
   441 				curstate = (jp_directions>>dir_shift) & 15;
   442 				curstate |= ((jp_fires>>fire_shift) & 1)<<4;
   443 
   444 				if (curstate != prevstate) {
   445 					/* X axis */
   446 					if ((curstate & (PORT_JS_LEFT|PORT_JS_RIGHT)) != (prevstate & (PORT_JS_LEFT|PORT_JS_RIGHT))) {
   447 						curaxis=0;
   448 						if (curstate & PORT_JS_LEFT) {
   449 							curaxis=-128;
   450 						} else if (curstate & PORT_JS_RIGHT) {
   451 							curaxis=127;
   452 						}					
   453 						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   454 					}
   455 					/* Y axis */
   456 					if ((curstate & (PORT_JS_UP|PORT_JS_DOWN)) != (prevstate & (PORT_JS_UP|PORT_JS_DOWN))) {
   457 						curaxis=0;
   458 						if (curstate & PORT_JS_UP) {
   459 							curaxis=-128;
   460 						} else if (curstate & PORT_JS_DOWN) {
   461 							curaxis=127;
   462 						}					
   463 						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   464 					}
   465 					/* Button */
   466 					if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) {
   467 						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
   468 					}
   469 					if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) {
   470 						SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
   471 					}
   472 				}
   473 				atarijoysticks[numjoystick].prevstate = curstate;
   474 			}
   475 			break;
   476 		case PORTA_LP:
   477 			{
   478 				int i;
   479 
   480 				curstate = jp_lightpens[0]>>1;
   481 				curstate |= (jp_lightpens[1]>>1)<<15;
   482 				curstate |= (jp_fires & 3)<<30;
   483 
   484 				if (curstate != prevstate) {
   485 					/* X axis */
   486 					SDL_PrivateJoystickAxis(joystick,0,(jp_lightpens[0]>>8)-128);
   487 					/* Y axis */
   488 					SDL_PrivateJoystickAxis(joystick,1,(jp_lightpens[1]>>8)-128);
   489 					/* Buttons */
   490 					for (i=0;i<2;i++) {
   491 						int button;
   492 						
   493 						button=1<<(30+i);
   494 
   495 						if ((curstate & button) && !(prevstate & button)) {
   496 							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
   497 						}
   498 						if (!(curstate & button) && (prevstate & button)) {
   499 							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
   500 						}
   501 					}
   502 				}
   503 				atarijoysticks[numjoystick].prevstate = curstate;
   504 			}
   505 			break;
   506 		case PORTA_ANPAD:
   507 		case PORTB_ANPAD:
   508 			{
   509 				int numpaddle, i;
   510 				
   511 				numpaddle=0<<1;
   512 				if (numjoystick==PORTB_ANPAD) numpaddle=1<<1;
   513 
   514 				curstate = jp_paddles[numpaddle]>>1;
   515 				curstate |= (jp_paddles[numpaddle+1]>>1)<<15;
   516 				curstate |= ((jp_fires>>numpaddle) & 3)<<30;
   517 
   518 				if (curstate != prevstate) {
   519 					/* X axis */
   520 					SDL_PrivateJoystickAxis(joystick,0,(jp_paddles[numpaddle]>>8)-128);
   521 					/* Y axis */
   522 					SDL_PrivateJoystickAxis(joystick,1,(jp_paddles[numpaddle+1]>>8)-128);
   523 					/* Buttons */
   524 					for (i=0;i<2;i++) {
   525 						int button;
   526 						
   527 						button=1<<(30+i);
   528 
   529 						if ((curstate & button) && !(prevstate & button)) {
   530 							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
   531 						}
   532 						if (!(curstate & button) && (prevstate & button)) {
   533 							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
   534 						}
   535 					}
   536 				}
   537 				atarijoysticks[numjoystick].prevstate = curstate;
   538 			}
   539 			break;
   540 #if 0
   541 		case PARA_JOY0:
   542 		case PARA_JOY1:
   543 			break;
   544 #endif
   545 	};
   546 
   547 	return;
   548 }
   549 
   550 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
   551 {
   552 	return;
   553 }
   554 
   555 void SDL_SYS_JoystickQuit(void)
   556 {
   557 	SDL_numjoysticks=0;
   558 	return;
   559 }
   560 
   561 /*--- Joypad I/O read/write interface ---*/
   562 
   563 #define JOYPAD_IO_BASE (0xffff9200)
   564 struct JOYPAD_IO_S {
   565 	Uint16 fires;
   566 	Uint16 directions;
   567 	Uint16 dummy1[6];
   568 	Uint16 paddles[4];
   569 	Uint16 dummy2[4];
   570 	Uint16 lightpens[2];
   571 };
   572 #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
   573 
   574 static void UpdateJoypads(void)
   575 {
   576 	Uint16 tmp;
   577 
   578 	/*--- This function is called in supervisor mode ---*/
   579 
   580 	/* Update joysticks */
   581 	jp_fires = (~(JOYPAD_IO.fires)) & 15;
   582 	jp_directions = (~(JOYPAD_IO.directions));
   583 	
   584 	/* Update lightpen */
   585 	tmp = JOYPAD_IO.lightpens[0] & 1023;
   586 	jp_lightpens[0] = (tmp<<6) | (tmp>>4);
   587 	tmp = JOYPAD_IO.lightpens[1] & 1023;
   588 	jp_lightpens[1] = (tmp<<6) | (tmp>>4);
   589 	
   590 	/* Update paddles */
   591 	tmp = (JOYPAD_IO.paddles[0] & 255);
   592 	jp_paddles[0] = (tmp<<8) | tmp;
   593 	tmp = (JOYPAD_IO.paddles[1] & 255);
   594 	jp_paddles[1] = (tmp<<8) | tmp;
   595 	tmp = (JOYPAD_IO.paddles[2] & 255);
   596 	jp_paddles[2] = (tmp<<8) | tmp;
   597 	tmp = (JOYPAD_IO.paddles[3] & 255);
   598 	jp_paddles[3] = (tmp<<8) | tmp;
   599 
   600 	/* Update joypad 0 */	
   601 	JOYPAD_IO.directions=0xfffe;
   602 	jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16);
   603 	JOYPAD_IO.directions=0xfffe;
   604 	jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15;
   605 
   606 	JOYPAD_IO.directions=0xfffd;
   607 	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2);
   608 	JOYPAD_IO.directions=0xfffd;
   609 	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4;
   610 
   611 	JOYPAD_IO.directions=0xfffb;
   612 	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4);
   613 	JOYPAD_IO.directions=0xfffb;
   614 	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8;
   615 
   616 	JOYPAD_IO.directions=0xfff7;
   617 	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6);
   618 	JOYPAD_IO.directions=0xfff7;
   619 	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12;
   620 
   621 	/* Update joypad 1 */	
   622 	JOYPAD_IO.directions=0xffef;
   623 	jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2);
   624 	JOYPAD_IO.directions=0xffef;
   625 	jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15;
   626 
   627 	JOYPAD_IO.directions=0xffdf;
   628 	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16);
   629 	JOYPAD_IO.directions=0xffdf;
   630 	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4;
   631 
   632 	JOYPAD_IO.directions=0xffbf;
   633 	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2);
   634 	JOYPAD_IO.directions=0xffbf;
   635 	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8;
   636 
   637 	JOYPAD_IO.directions=0xff7f;
   638 	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4);
   639 	JOYPAD_IO.directions=0xff7f;
   640 	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12;
   641 }