Added Atari joystick support (thanks Patrice!)
authorSam Lantinga <slouken@libsdl.org>
Thu, 07 Mar 2002 20:23:11 +0000
changeset 3028a86bdf34f0f
parent 301 fb4c4c6a2773
child 303 767c10b9ec9f
Added Atari joystick support (thanks Patrice!)
README.MiNT
configure.in
src/joystick/Makefile.am
src/joystick/mint/.cvsignore
src/joystick/mint/Makefile.am
src/joystick/mint/SDL_sysjoystick.c
     1.1 --- a/README.MiNT	Wed Mar 06 19:14:17 2002 +0000
     1.2 +++ b/README.MiNT	Thu Mar 07 20:23:11 2002 +0000
     1.3 @@ -49,19 +49,19 @@
     1.4  Mouse (XBIOS, GEM, Ikbd)
     1.5  Video (XBIOS (Fullscreen), GEM (Windowed and Fullscreen))
     1.6  Timer (VBL vector)
     1.7 +Joystick and joypad support (Ikbd, Hardware)
     1.8  
     1.9  - What is missing:
    1.10  Audio support (TOS)
    1.11  CDROM support (Metados, /dev/cdrom)
    1.12 -Joystick and joypad support (Hardware)
    1.13  Threads support (TOS)
    1.14  
    1.15  - Driver combinations:
    1.16 -Video	Kbd	Mouse	Timer
    1.17 -xbios	ikbd	ikbd	vbl
    1.18 -xbios	gemdos	xbios	vbl
    1.19 -xbios	bios	xbios	vbl
    1.20 -gem	gem	gem	vbl
    1.21 +Video	Kbd	Mouse	Timer	Jstick	Joypads
    1.22 +xbios	ikbd	ikbd	vbl	ikbd	hardware
    1.23 +xbios	gemdos	xbios	vbl	-	hardware
    1.24 +xbios	bios	xbios	vbl	-	hardware
    1.25 +gem	gem	gem	vbl	-	hardware
    1.26  
    1.27  ==============================================================================
    1.28  V.  Environment variables:
    1.29 @@ -75,6 +75,38 @@
    1.30  	Set to 'xbios' to force xbios video driver
    1.31  	Set to 'gem' to force gem video driver
    1.32  
    1.33 +SDL_JOYSTICK_ATARI:
    1.34 +	Use any of these strings in the environment variable to enable or
    1.35 +	disable a joystick:
    1.36 +
    1.37 +	'ikbd-joy1-[on|off]' for IKBD joystick on port 1
    1.38 +	'porta-pad-[on|off]' for joypad on port A
    1.39 +	'porta-joy0-[on|off]' for joystick 0 on port A
    1.40 +	'porta-joy1-[on|off]' for joystick 1 on port A
    1.41 +	'porta-lp-[on|off]' for lightpen on port A
    1.42 +	'porta-anpad-[on|off]' for analog paddle on port A
    1.43 +	'portb-pad-[on|off]' for joypad on port B
    1.44 +	'portb-joy0-[on|off]' for joystick 0 on port B
    1.45 +	'portb-joy1-[on|off]' for joystick 1 on port B
    1.46 +	'portb-anpad-[on|off]' for analog paddle on port B
    1.47 +
    1.48 +	Default configuration is:
    1.49 +		'ikbd-joy1-on' (if IKBD events driver enabled)
    1.50 +		'porta-pad-on portb-pad-on' (if available on the machine)
    1.51 +
    1.52 +	port[a|b]-[pad|joy?|lp|anpad]-* strings are mutually exclusives.
    1.53 +	On such a port, you can only use a joypad OR 1 or 2 joysticks OR
    1.54 +	a lightpen OR an analog paddle. You must disable joypad before
    1.55 +	setting another controller.
    1.56 +
    1.57 +	IKBD joystick only available when the IKBD events driver is enabled.
    1.58 +	The second joystick port on IKBD is used by the mouse, so not usable.
    1.59 +
    1.60 +	Joypads are multibuttons controller (Atari Jaguar console-like).
    1.61 +	Joysticks are 1 button, 2 axis controllers.
    1.62 +	Lightpen and analog paddle are 2 buttons, 2 axis controllers. The 2
    1.63 +	buttons are those affected to 1 button joysticks on the same port.
    1.64 +
    1.65  -- 
    1.66  Patrice Mandin <pmandin@caramail.com>
    1.67  http://www.multimania.com/pmandin
     2.1 --- a/configure.in	Wed Mar 06 19:14:17 2002 +0000
     2.2 +++ b/configure.in	Thu Mar 07 20:23:11 2002 +0000
     2.3 @@ -2281,10 +2281,9 @@
     2.4              AUDIO_DRIVERS="$AUDIO_DRIVERS sun/libaudio_sun.la"
     2.5          fi
     2.6          # Set up files for the joystick library
     2.7 -        # (No joystick support yet)
     2.8          if test x$enable_joystick = xyes; then
     2.9 -            JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS dummy"
    2.10 -            JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS dummy/libjoystick_dummy.la"
    2.11 +            JOYSTICK_SUBDIRS="$JOYSTICK_SUBDIRS mint"
    2.12 +            JOYSTICK_DRIVERS="$JOYSTICK_DRIVERS mint/libjoystick_mint.la"
    2.13          fi
    2.14          # Set up files for the cdrom library
    2.15          if test x$enable_cdrom = xyes; then
    2.16 @@ -2489,6 +2488,7 @@
    2.17  src/joystick/dummy/Makefile
    2.18  src/joystick/linux/Makefile
    2.19  src/joystick/macos/Makefile
    2.20 +src/joystick/mint/Makefile
    2.21  src/joystick/win32/Makefile
    2.22  src/cdrom/Makefile
    2.23  src/cdrom/aix/Makefile
     3.1 --- a/src/joystick/Makefile.am	Wed Mar 06 19:14:17 2002 +0000
     3.2 +++ b/src/joystick/Makefile.am	Thu Mar 07 20:23:11 2002 +0000
     3.3 @@ -5,7 +5,7 @@
     3.4  
     3.5  # Define which subdirectories need to be built
     3.6  SUBDIRS = @JOYSTICK_SUBDIRS@
     3.7 -DIST_SUBDIRS = dummy amigaos beos bsd darwin linux macos win32
     3.8 +DIST_SUBDIRS = dummy amigaos beos bsd darwin linux macos mint win32
     3.9  
    3.10  DRIVERS = @JOYSTICK_DRIVERS@
    3.11  
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/src/joystick/mint/.cvsignore	Thu Mar 07 20:23:11 2002 +0000
     4.3 @@ -0,0 +1,6 @@
     4.4 +Makefile.in
     4.5 +Makefile
     4.6 +.libs
     4.7 +*.o
     4.8 +*.lo
     4.9 +*.la
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/joystick/mint/Makefile.am	Thu Mar 07 20:23:11 2002 +0000
     5.3 @@ -0,0 +1,8 @@
     5.4 +
     5.5 +## Makefile.am for the MiNT joystick driver for SDL
     5.6 +
     5.7 +noinst_LTLIBRARIES = libjoystick_mint.la
     5.8 +libjoystick_mint_la_SOURCES = $(SRCS)
     5.9 +
    5.10 +# The SDL joystick driver sources
    5.11 +SRCS =  SDL_sysjoystick.c
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/joystick/mint/SDL_sysjoystick.c	Thu Mar 07 20:23:11 2002 +0000
     6.3 @@ -0,0 +1,625 @@
     6.4 +/*
     6.5 +    SDL - Simple DirectMedia Layer
     6.6 +    Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
     6.7 +
     6.8 +    This library is free software; you can redistribute it and/or
     6.9 +    modify it under the terms of the GNU Library General Public
    6.10 +    License as published by the Free Software Foundation; either
    6.11 +    version 2 of the License, or (at your option) any later version.
    6.12 +
    6.13 +    This library is distributed in the hope that it will be useful,
    6.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    6.16 +    Library General Public License for more details.
    6.17 +
    6.18 +    You should have received a copy of the GNU Library General Public
    6.19 +    License along with this library; if not, write to the Free
    6.20 +    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    6.21 +
    6.22 +    Sam Lantinga
    6.23 +    slouken@libsdl.org
    6.24 +*/
    6.25 +
    6.26 +#ifdef SAVE_RCSID
    6.27 +static char rcsid =
    6.28 + "@(#) $Id$";
    6.29 +#endif
    6.30 +
    6.31 +/*
    6.32 + *	Atari Joystick/Joypad drivers
    6.33 + *
    6.34 + *	Patrice Mandin
    6.35 + */
    6.36 +
    6.37 +#include <stdlib.h>
    6.38 +#include <string.h>
    6.39 +
    6.40 +#include <sys/cookie.h>
    6.41 +#include <mint/osbind.h>
    6.42 +
    6.43 +#include "SDL_types.h"
    6.44 +#include "SDL_error.h"
    6.45 +#include "SDL_joystick.h"
    6.46 +#include "SDL_sysjoystick.h"
    6.47 +#include "SDL_joystick_c.h"
    6.48 +
    6.49 +#include "../video/ataricommon/SDL_ikbdinterrupt_s.h"
    6.50 +
    6.51 +/*--- Const ---*/
    6.52 +
    6.53 +/* We can have:
    6.54 +	1 joystick on IKBD port 1 (port 0 is used by mouse)
    6.55 +	2 joypads on ports A,B
    6.56 +	  or 4 joysticks on joypads ports A,B
    6.57 +	  or 1 lightpen on joypad port A
    6.58 +	  or 2 analog paddles on joypads ports A,B
    6.59 +	2 joysticks on parallel port
    6.60 +*/
    6.61 +
    6.62 +enum {
    6.63 +	IKBD_JOY1=0,
    6.64 +	PORTA_PAD,
    6.65 +	PORTB_PAD,
    6.66 +	PORTA_JOY0,
    6.67 +	PORTA_JOY1,
    6.68 +	PORTB_JOY0,
    6.69 +	PORTB_JOY1,
    6.70 +	PORTA_LP,
    6.71 +	PORTA_ANPAD,
    6.72 +	PORTB_ANPAD,
    6.73 +#if 0
    6.74 +	PARA_JOY0,
    6.75 +	PARA_JOY1,
    6.76 +#endif
    6.77 +	MAX_JOYSTICKS
    6.78 +};
    6.79 +
    6.80 +enum {
    6.81 +	MCH_ST=0,
    6.82 +	MCH_STE,
    6.83 +	MCH_TT,
    6.84 +	MCH_F30
    6.85 +};
    6.86 +
    6.87 +/*	Joypad buttons
    6.88 + *		Procontroller note:
    6.89 + *			L,R are connected to 4,6
    6.90 + *			X,Y,Z are connected to 7,8,9
    6.91 + */
    6.92 +
    6.93 +enum {
    6.94 +	JP_UP=0,	JP_DOWN,	JP_LEFT,	JP_RIGHT,
    6.95 +	JP_KPMULT,	JP_KP7,		JP_KP4,		JP_KP1,
    6.96 +	JP_KP0,		JP_KP8,		JP_KP5,		JP_KP2,
    6.97 +	JP_KPNUM,	JP_KP9,		JP_KP6,		JP_KP3,
    6.98 +	JP_PAUSE,	JP_FIRE0,	JP_UNDEF0,	JP_FIRE1,
    6.99 +	JP_UNDEF1,	JP_FIRE2,	JP_UNDEF2,	JP_OPTION
   6.100 +};
   6.101 +
   6.102 +#define JP_NUM_BUTTONS 17
   6.103 +
   6.104 +#define PORT_JS_RIGHT	(1<<0)
   6.105 +#define PORT_JS_LEFT	(1<<1)
   6.106 +#define PORT_JS_DOWN	(1<<2)
   6.107 +#define PORT_JS_UP		(1<<3)
   6.108 +#define PORT_JS_FIRE	(1<<4)
   6.109 +
   6.110 +/*--- Types ---*/
   6.111 +
   6.112 +typedef struct {
   6.113 +	SDL_bool enabled;
   6.114 +	unsigned char *name;
   6.115 +	Uint32 prevstate;
   6.116 +} atarijoy_t;
   6.117 +
   6.118 +/*--- Variables ---*/
   6.119 +
   6.120 +static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
   6.121 +	{SDL_FALSE,"IKBD joystick port 1",0},
   6.122 +	{SDL_FALSE,"Joypad port A",0},
   6.123 +	{SDL_FALSE,"Joypad port B",0},
   6.124 +	{SDL_FALSE,"Joystick 0 port A",0},
   6.125 +	{SDL_FALSE,"Joystick 1 port A",0},
   6.126 +	{SDL_FALSE,"Joystick 0 port B",0},
   6.127 +	{SDL_FALSE,"Joystick 1 port B",0},
   6.128 +	{SDL_FALSE,"Lightpen port A",0},
   6.129 +	{SDL_FALSE,"Analog paddle port A",0},
   6.130 +	{SDL_FALSE,"Analog paddle port B",0}
   6.131 +#if 0
   6.132 +	,{SDL_FALSE,"Joystick 0 parallel port",0},
   6.133 +	{SDL_FALSE,"Joystick 1 parallel port",0}
   6.134 +#endif
   6.135 +};
   6.136 +
   6.137 +static const int jp_buttons[JP_NUM_BUTTONS]={
   6.138 +	JP_KPMULT,	JP_KP7,		JP_KP4,		JP_KP1,
   6.139 +	JP_KP0,		JP_KP8,		JP_KP5,		JP_KP2,
   6.140 +	JP_KPNUM,	JP_KP9,		JP_KP6,		JP_KP3,
   6.141 +	JP_PAUSE,	JP_FIRE0,	JP_FIRE1,	JP_FIRE2,
   6.142 +	JP_OPTION
   6.143 +};
   6.144 +
   6.145 +static SDL_bool joypad_ports_enabled=SDL_FALSE;
   6.146 +
   6.147 +/* Updated joypad ports */
   6.148 +static Uint16 jp_paddles[4];
   6.149 +static Uint16 jp_lightpens[2];
   6.150 +static Uint16 jp_directions;
   6.151 +static Uint16 jp_fires;
   6.152 +static Uint32 jp_joypads[2];
   6.153 +
   6.154 +/*--- Functions prototypes ---*/
   6.155 +
   6.156 +static int GetEnabledAtariJoystick(int index);
   6.157 +static void UpdateJoypads(void);
   6.158 +
   6.159 +/*--- Functions ---*/
   6.160 +
   6.161 +int SDL_SYS_JoystickInit(void)
   6.162 +{
   6.163 +	int i;
   6.164 +	unsigned long cookie_mch;
   6.165 +	const char *envr=getenv("SDL_JOYSTICK_ATARI");
   6.166 +	const char *env_evt=getenv("SDL_ATARI_EVENTSDRIVER");
   6.167 +	SDL_bool ikbd_enabled=SDL_FALSE;
   6.168 +	
   6.169 +#define TEST_JOY_ENABLED(env,idstring,num) \
   6.170 +	if (strstr(env,idstring"-off")) { \
   6.171 +		atarijoysticks[num].enabled=SDL_FALSE; \
   6.172 +	} \
   6.173 +	if (strstr(env,idstring"-on")) { \
   6.174 +		atarijoysticks[num].enabled=SDL_TRUE; \
   6.175 +	}
   6.176 +
   6.177 +	/* Cookie _MCH present ? if not, assume ST machine */
   6.178 +	if (Getcookie(C__MCH, &cookie_mch) != C_FOUND) {
   6.179 +		cookie_mch = MCH_ST << 16;
   6.180 +	}
   6.181 +
   6.182 +	/* Enable some default joysticks */
   6.183 +	if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
   6.184 +		(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
   6.185 +		ikbd_enabled=SDL_TRUE;
   6.186 +		if (env_evt) {
   6.187 +			if (!strcmp(env_evt,"ikbd")) {
   6.188 +				ikbd_enabled=SDL_FALSE;
   6.189 +			}
   6.190 +		}
   6.191 +		atarijoysticks[IKBD_JOY1].enabled=ikbd_enabled;
   6.192 +	}
   6.193 +	if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
   6.194 +		atarijoysticks[PORTA_PAD].enabled=SDL_TRUE;
   6.195 +		atarijoysticks[PORTB_PAD].enabled=SDL_TRUE;
   6.196 +	}
   6.197 +
   6.198 +	/* Read environment for joysticks to enable */
   6.199 +	if (envr) {
   6.200 +		/* IKBD on any Atari, maybe clones */
   6.201 +		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
   6.202 +			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
   6.203 +			if (env_evt) {
   6.204 +				if (strcmp(env_evt,"ikbd")) {
   6.205 +					TEST_JOY_ENABLED(envr, "ikbd-joy1", IKBD_JOY1);
   6.206 +				}
   6.207 +			}
   6.208 +		}
   6.209 +		/* Joypads ports only on STE and Falcon */
   6.210 +		if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
   6.211 +			TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
   6.212 +			if (!atarijoysticks[PORTA_PAD].enabled) {
   6.213 +				TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
   6.214 +				TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
   6.215 +				if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {
   6.216 +					TEST_JOY_ENABLED(envr, "porta-lp", PORTA_LP);
   6.217 +					if (!atarijoysticks[PORTA_LP].enabled) {
   6.218 +						TEST_JOY_ENABLED(envr, "porta-anpad", PORTA_ANPAD);
   6.219 +					}
   6.220 +				}
   6.221 +			}
   6.222 +
   6.223 +			TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD);
   6.224 +			if (!atarijoysticks[PORTB_PAD].enabled) {
   6.225 +				TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
   6.226 +				TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
   6.227 +				if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
   6.228 +					TEST_JOY_ENABLED(envr, "portb-anpad", PORTB_ANPAD);
   6.229 +				}
   6.230 +			}
   6.231 +		}
   6.232 +#if 0
   6.233 +		/* Parallel port on any Atari, maybe clones */
   6.234 +		if ((cookie_mch == MCH_ST<<16) || ((cookie_mch>>16) == MCH_STE) ||
   6.235 +			(cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16)) {
   6.236 +			TEST_JOY_ENABLED(envr, "para-joy0", PARA_JOY0);
   6.237 +			TEST_JOY_ENABLED(envr, "para-joy1", PARA_JOY1);
   6.238 +		}
   6.239 +#endif
   6.240 +	}
   6.241 +
   6.242 +	/* Need to update joypad ports ? */
   6.243 +	joypad_ports_enabled=SDL_FALSE;
   6.244 +	for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) {
   6.245 +		if (atarijoysticks[i].enabled) {
   6.246 +			joypad_ports_enabled=SDL_TRUE;
   6.247 +			break;
   6.248 +		}
   6.249 +	}
   6.250 +
   6.251 +	SDL_numjoysticks = 0;
   6.252 +	for (i=0;i<MAX_JOYSTICKS;i++) {
   6.253 +		if (atarijoysticks[i].enabled) {
   6.254 +			++SDL_numjoysticks;
   6.255 +		}
   6.256 +	}
   6.257 +
   6.258 +	return(SDL_numjoysticks);
   6.259 +}
   6.260 +
   6.261 +static int GetEnabledAtariJoystick(int index)
   6.262 +{
   6.263 +	int i,j;
   6.264 +
   6.265 +	/* Return the nth'index' enabled atari joystick */
   6.266 +	j=0;
   6.267 +	for (i=0;i<MAX_JOYSTICKS;i++) {
   6.268 +		if (atarijoysticks[i].enabled) {
   6.269 +			if (j==index) {
   6.270 +				break;
   6.271 +			} else {
   6.272 +				j++;
   6.273 +			}
   6.274 +		}
   6.275 +	}
   6.276 +	if (i==MAX_JOYSTICKS)
   6.277 +		return -1;
   6.278 +
   6.279 +	return i;
   6.280 +}
   6.281 +
   6.282 +const char *SDL_SYS_JoystickName(int index)
   6.283 +{
   6.284 +	int numjoystick;
   6.285 +
   6.286 +	numjoystick=GetEnabledAtariJoystick(index);
   6.287 +	if (numjoystick==-1)
   6.288 +		return NULL;
   6.289 +
   6.290 +	return(atarijoysticks[numjoystick].name);
   6.291 +}
   6.292 +
   6.293 +int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
   6.294 +{
   6.295 +	int numjoystick;
   6.296 +	
   6.297 +	numjoystick=GetEnabledAtariJoystick(joystick->index);
   6.298 +	if (numjoystick==-1)
   6.299 +		return -1;
   6.300 +	
   6.301 +	if ((numjoystick==PORTA_PAD) || (numjoystick==PORTB_PAD)) {
   6.302 +		joystick->nbuttons=JP_NUM_BUTTONS;
   6.303 +	} else if ((numjoystick==PORTA_LP) || (numjoystick==PORTA_ANPAD) ||
   6.304 +				(numjoystick==PORTB_ANPAD)) {
   6.305 +		joystick->nbuttons=2;
   6.306 +	} else {
   6.307 +		joystick->nbuttons=1;
   6.308 +	}
   6.309 +	joystick->naxes=2;
   6.310 +	joystick->nballs=0;
   6.311 +	joystick->nhats=0;
   6.312 +
   6.313 +	return(0);
   6.314 +}
   6.315 +
   6.316 +void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
   6.317 +{
   6.318 +	int numjoystick;
   6.319 +	Uint32 curstate,prevstate;
   6.320 +	Sint16 curaxis;
   6.321 +	
   6.322 +	numjoystick=GetEnabledAtariJoystick(joystick->index);
   6.323 +	if (numjoystick==-1)
   6.324 +		return;
   6.325 +
   6.326 +	prevstate = atarijoysticks[numjoystick].prevstate;
   6.327 +
   6.328 +	if (joypad_ports_enabled) {
   6.329 +		Supexec(UpdateJoypads);
   6.330 +	}
   6.331 +
   6.332 +	switch (numjoystick) {
   6.333 +		case IKBD_JOY1:
   6.334 +			{
   6.335 +				curstate = SDL_AtariIkbd_joystick & 0xff;
   6.336 +				if (curstate != prevstate) {
   6.337 +					/* X axis */
   6.338 +					if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) {
   6.339 +						curaxis=0;
   6.340 +						if (curstate & IKBD_JOY_LEFT) {
   6.341 +							curaxis=-128;
   6.342 +						} else if (curstate & IKBD_JOY_RIGHT) {
   6.343 +							curaxis=127;
   6.344 +						}					
   6.345 +						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   6.346 +					}
   6.347 +					/* Y axis */
   6.348 +					if ((curstate & (IKBD_JOY_UP|IKBD_JOY_DOWN)) != (prevstate & (IKBD_JOY_UP|IKBD_JOY_DOWN))) {
   6.349 +						curaxis=0;
   6.350 +						if (curstate & IKBD_JOY_UP) {
   6.351 +							curaxis=-128;
   6.352 +						} else if (curstate & IKBD_JOY_DOWN) {
   6.353 +							curaxis=127;
   6.354 +						}					
   6.355 +						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   6.356 +					}
   6.357 +					/* Button */
   6.358 +					if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) {
   6.359 +						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
   6.360 +					}
   6.361 +					if (!(curstate & IKBD_JOY_FIRE) && (prevstate & IKBD_JOY_FIRE)) {
   6.362 +						SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
   6.363 +					}
   6.364 +				}
   6.365 +				atarijoysticks[IKBD_JOY1].prevstate = curstate;
   6.366 +			}
   6.367 +			break;
   6.368 +		case PORTA_PAD:
   6.369 +		case PORTB_PAD:
   6.370 +			{
   6.371 +				int numjoypad,i;
   6.372 +				
   6.373 +				numjoypad=0;
   6.374 +/*				if (numjoystick==PORTA_PAD) numjoypad=0;*/
   6.375 +				if (numjoystick==PORTB_PAD) numjoypad=1;
   6.376 +				
   6.377 +				curstate=jp_joypads[numjoypad];
   6.378 +				if (curstate!=prevstate) {
   6.379 +					/* X axis */
   6.380 +					if ((curstate & ((1<<JP_LEFT)|(1<<JP_RIGHT))) != (prevstate & ((1<<JP_LEFT)|(1<<JP_RIGHT)))) {
   6.381 +						curaxis=0;
   6.382 +						if (curstate & (1<<JP_LEFT)) {
   6.383 +							curaxis=-128;
   6.384 +						} else if (curstate & (1<<JP_RIGHT)) {
   6.385 +							curaxis=127;
   6.386 +						}					
   6.387 +						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   6.388 +					}
   6.389 +					/* Y axis */
   6.390 +					if ((curstate & ((1<<JP_UP)|(1<<JP_DOWN))) != (prevstate & ((1<<JP_UP)|(1<<JP_DOWN)))) {
   6.391 +						curaxis=0;
   6.392 +						if (curstate & (1<<JP_UP)) {
   6.393 +							curaxis=-128;
   6.394 +						} else if (curstate & (1<<JP_DOWN)) {
   6.395 +							curaxis=127;
   6.396 +						}					
   6.397 +						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   6.398 +					}
   6.399 +					/* Buttons */
   6.400 +					for (i=0;i<JP_NUM_BUTTONS;i++) {
   6.401 +						int button;
   6.402 +						
   6.403 +						button=1<<jp_buttons[i];
   6.404 +
   6.405 +						if ((curstate & button) && !(prevstate & button)) {
   6.406 +							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
   6.407 +						}
   6.408 +						if (!(curstate & button) && (prevstate & button)) {
   6.409 +							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
   6.410 +						}
   6.411 +					}
   6.412 +				}
   6.413 +				atarijoysticks[numjoystick].prevstate = curstate;
   6.414 +			}
   6.415 +			break;
   6.416 +		case PORTA_JOY0:
   6.417 +		case PORTA_JOY1:
   6.418 +		case PORTB_JOY0:
   6.419 +		case PORTB_JOY1:
   6.420 +			{
   6.421 +				int fire_shift=0,dir_shift=0;
   6.422 +				
   6.423 +				if (numjoystick==PORTA_JOY0) {	fire_shift=0; dir_shift=0; }
   6.424 +				if (numjoystick==PORTA_JOY1) {	fire_shift=1; dir_shift=4; }
   6.425 +				if (numjoystick==PORTB_JOY0) {	fire_shift=2; dir_shift=8; }
   6.426 +				if (numjoystick==PORTB_JOY1) {	fire_shift=3; dir_shift=12; }
   6.427 +
   6.428 +				curstate = (jp_directions>>dir_shift) & 15;
   6.429 +				curstate |= ((jp_fires>>fire_shift) & 1)<<4;
   6.430 +
   6.431 +				if (curstate != prevstate) {
   6.432 +					/* X axis */
   6.433 +					if ((curstate & (PORT_JS_LEFT|PORT_JS_RIGHT)) != (prevstate & (PORT_JS_LEFT|PORT_JS_RIGHT))) {
   6.434 +						curaxis=0;
   6.435 +						if (curstate & PORT_JS_LEFT) {
   6.436 +							curaxis=-128;
   6.437 +						} else if (curstate & PORT_JS_RIGHT) {
   6.438 +							curaxis=127;
   6.439 +						}					
   6.440 +						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   6.441 +					}
   6.442 +					/* Y axis */
   6.443 +					if ((curstate & (PORT_JS_UP|PORT_JS_DOWN)) != (prevstate & (PORT_JS_UP|PORT_JS_DOWN))) {
   6.444 +						curaxis=0;
   6.445 +						if (curstate & PORT_JS_UP) {
   6.446 +							curaxis=-128;
   6.447 +						} else if (curstate & PORT_JS_DOWN) {
   6.448 +							curaxis=127;
   6.449 +						}					
   6.450 +						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   6.451 +					}
   6.452 +					/* Button */
   6.453 +					if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) {
   6.454 +						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
   6.455 +					}
   6.456 +					if (!(curstate & PORT_JS_FIRE) && (prevstate & PORT_JS_FIRE)) {
   6.457 +						SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);
   6.458 +					}
   6.459 +				}
   6.460 +				atarijoysticks[numjoystick].prevstate = curstate;
   6.461 +			}
   6.462 +			break;
   6.463 +		case PORTA_LP:
   6.464 +			{
   6.465 +				int i;
   6.466 +
   6.467 +				curstate = jp_lightpens[0]>>1;
   6.468 +				curstate |= (jp_lightpens[1]>>1)<<15;
   6.469 +				curstate |= (jp_fires & 3)<<30;
   6.470 +
   6.471 +				if (curstate != prevstate) {
   6.472 +					/* X axis */
   6.473 +					SDL_PrivateJoystickAxis(joystick,0,(jp_lightpens[0]>>8)-128);
   6.474 +					/* Y axis */
   6.475 +					SDL_PrivateJoystickAxis(joystick,1,(jp_lightpens[1]>>8)-128);
   6.476 +					/* Buttons */
   6.477 +					for (i=0;i<2;i++) {
   6.478 +						int button;
   6.479 +						
   6.480 +						button=1<<(30+i);
   6.481 +
   6.482 +						if ((curstate & button) && !(prevstate & button)) {
   6.483 +							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
   6.484 +						}
   6.485 +						if (!(curstate & button) && (prevstate & button)) {
   6.486 +							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
   6.487 +						}
   6.488 +					}
   6.489 +				}
   6.490 +				atarijoysticks[numjoystick].prevstate = curstate;
   6.491 +			}
   6.492 +			break;
   6.493 +		case PORTA_ANPAD:
   6.494 +		case PORTB_ANPAD:
   6.495 +			{
   6.496 +				int numpaddle, i;
   6.497 +				
   6.498 +				numpaddle=0<<1;
   6.499 +				if (numjoystick==PORTB_ANPAD) numpaddle=1<<1;
   6.500 +
   6.501 +				curstate = jp_paddles[numpaddle]>>1;
   6.502 +				curstate |= (jp_paddles[numpaddle+1]>>1)<<15;
   6.503 +				curstate |= ((jp_fires>>numpaddle) & 3)<<30;
   6.504 +
   6.505 +				if (curstate != prevstate) {
   6.506 +					/* X axis */
   6.507 +					SDL_PrivateJoystickAxis(joystick,0,(jp_paddles[numpaddle]>>8)-128);
   6.508 +					/* Y axis */
   6.509 +					SDL_PrivateJoystickAxis(joystick,1,(jp_paddles[numpaddle+1]>>8)-128);
   6.510 +					/* Buttons */
   6.511 +					for (i=0;i<2;i++) {
   6.512 +						int button;
   6.513 +						
   6.514 +						button=1<<(30+i);
   6.515 +
   6.516 +						if ((curstate & button) && !(prevstate & button)) {
   6.517 +							SDL_PrivateJoystickButton(joystick,i,SDL_PRESSED);
   6.518 +						}
   6.519 +						if (!(curstate & button) && (prevstate & button)) {
   6.520 +							SDL_PrivateJoystickButton(joystick,i,SDL_RELEASED);
   6.521 +						}
   6.522 +					}
   6.523 +				}
   6.524 +				atarijoysticks[numjoystick].prevstate = curstate;
   6.525 +			}
   6.526 +			break;
   6.527 +#if 0
   6.528 +		case PARA_JOY0:
   6.529 +		case PARA_JOY1:
   6.530 +			break;
   6.531 +#endif
   6.532 +	};
   6.533 +
   6.534 +	return;
   6.535 +}
   6.536 +
   6.537 +void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
   6.538 +{
   6.539 +	return;
   6.540 +}
   6.541 +
   6.542 +void SDL_SYS_JoystickQuit(void)
   6.543 +{
   6.544 +	SDL_numjoysticks=0;
   6.545 +	return;
   6.546 +}
   6.547 +
   6.548 +/*--- Joypad I/O read/write interface ---*/
   6.549 +
   6.550 +#define JOYPAD_IO_BASE (0xffff9200)
   6.551 +struct JOYPAD_IO_S {
   6.552 +	Uint16 fires;
   6.553 +	Uint16 directions;
   6.554 +	Uint16 dummy1[6];
   6.555 +	Uint16 paddles[4];
   6.556 +	Uint16 dummy2[4];
   6.557 +	Uint16 lightpens[2];
   6.558 +};
   6.559 +#define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
   6.560 +
   6.561 +static void UpdateJoypads(void)
   6.562 +{
   6.563 +	Uint16 tmp;
   6.564 +
   6.565 +	/*--- This function is called in supervisor mode ---*/
   6.566 +
   6.567 +	/* Update joysticks */
   6.568 +	jp_fires = (~(JOYPAD_IO.fires)) & 15;
   6.569 +	jp_directions = (~(JOYPAD_IO.directions));
   6.570 +	
   6.571 +	/* Update lightpen */
   6.572 +	tmp = JOYPAD_IO.lightpens[0] & 1023;
   6.573 +	jp_lightpens[0] = (tmp<<6) | (tmp>>4);
   6.574 +	tmp = JOYPAD_IO.lightpens[1] & 1023;
   6.575 +	jp_lightpens[1] = (tmp<<6) | (tmp>>4);
   6.576 +	
   6.577 +	/* Update paddles */
   6.578 +	tmp = (JOYPAD_IO.paddles[0] & 255);
   6.579 +	jp_paddles[0] = (tmp<<8) | tmp;
   6.580 +	tmp = (JOYPAD_IO.paddles[1] & 255);
   6.581 +	jp_paddles[1] = (tmp<<8) | tmp;
   6.582 +	tmp = (JOYPAD_IO.paddles[2] & 255);
   6.583 +	jp_paddles[2] = (tmp<<8) | tmp;
   6.584 +	tmp = (JOYPAD_IO.paddles[3] & 255);
   6.585 +	jp_paddles[3] = (tmp<<8) | tmp;
   6.586 +
   6.587 +	/* Update joypad 0 */	
   6.588 +	JOYPAD_IO.directions=0xfffe;
   6.589 +	jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16);
   6.590 +	JOYPAD_IO.directions=0xfffe;
   6.591 +	jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15;
   6.592 +
   6.593 +	JOYPAD_IO.directions=0xfffd;
   6.594 +	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2);
   6.595 +	JOYPAD_IO.directions=0xfffd;
   6.596 +	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4;
   6.597 +
   6.598 +	JOYPAD_IO.directions=0xfffb;
   6.599 +	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4);
   6.600 +	JOYPAD_IO.directions=0xfffb;
   6.601 +	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8;
   6.602 +
   6.603 +	JOYPAD_IO.directions=0xfff7;
   6.604 +	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6);
   6.605 +	JOYPAD_IO.directions=0xfff7;
   6.606 +	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12;
   6.607 +
   6.608 +	/* Update joypad 1 */	
   6.609 +	JOYPAD_IO.directions=0xffef;
   6.610 +	jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2);
   6.611 +	JOYPAD_IO.directions=0xffef;
   6.612 +	jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15;
   6.613 +
   6.614 +	JOYPAD_IO.directions=0xffdf;
   6.615 +	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16);
   6.616 +	JOYPAD_IO.directions=0xffdf;
   6.617 +	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4;
   6.618 +
   6.619 +	JOYPAD_IO.directions=0xffbf;
   6.620 +	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2);
   6.621 +	JOYPAD_IO.directions=0xffbf;
   6.622 +	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8;
   6.623 +
   6.624 +	JOYPAD_IO.directions=0xff7f;
   6.625 +	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4);
   6.626 +	JOYPAD_IO.directions=0xff7f;
   6.627 +	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12;
   6.628 +}