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