src/joystick/mint/SDL_sysjoystick.c
author Sam Lantinga
Sat, 25 Feb 2006 15:01:44 +0000
changeset 1429 aff0170f9f1b
parent 1412 a8181c4040b8
child 1635 92947e3a18db
permissions -rw-r--r--
Date: Sat, 25 Feb 2006 14:26:19 +0100 (CET)
From: "Torsten Giebl"
Subject: [SDL] testpalette.diff

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