Add teamtap support (4 joypads adapter on 1 port) SDL-1.2
authorPatrice Mandin <patmandin@gmail.com>
Wed, 02 Aug 2006 21:26:31 +0000
branchSDL-1.2
changeset 385028db418c7573
parent 3849 49ed2682da54
child 3851 405a192b68e7
Add teamtap support (4 joypads adapter on 1 port)
README.MiNT
src/joystick/mint/SDL_sysjoystick.c
     1.1 --- a/README.MiNT	Mon Jul 24 23:29:01 2006 +0000
     1.2 +++ b/README.MiNT	Wed Aug 02 21:26:31 2006 +0000
     1.3 @@ -127,12 +127,12 @@
     1.4  
     1.5  	'ikbd-joy1-[on|off]' for IKBD joystick on port 1 (hardware access)
     1.6  	'xbios-joy1-[on|off]' for IKBD joystick on port 1 (xbios access)
     1.7 -	'porta-pad-[on|off]' for joypad on port A
     1.8 +	'porta-pad-[on|off]' for joypad and/or teamtap on port A
     1.9  	'porta-joy0-[on|off]' for joystick 0 on port A
    1.10  	'porta-joy1-[on|off]' for joystick 1 on port A
    1.11  	'porta-lp-[on|off]' for lightpen on port A
    1.12  	'porta-anpad-[on|off]' for analog paddle on port A
    1.13 -	'portb-pad-[on|off]' for joypad on port B
    1.14 +	'portb-pad-[on|off]' for joypad and/or teamtap on port B
    1.15  	'portb-joy0-[on|off]' for joystick 0 on port B
    1.16  	'portb-joy1-[on|off]' for joystick 1 on port B
    1.17  	'portb-anpad-[on|off]' for analog paddle on port B
    1.18 @@ -213,7 +213,7 @@
    1.19  	Available on all machines (I think).
    1.20  
    1.21  Joypad driver:
    1.22 -	Available if _MCH cookie is STE or Falcon.
    1.23 +	Available if _MCH cookie is STE or Falcon. Supports teamtap.
    1.24  
    1.25  PTH timer driver:
    1.26  	Available with multitasking OS.
     2.1 --- a/src/joystick/mint/SDL_sysjoystick.c	Mon Jul 24 23:29:01 2006 +0000
     2.2 +++ b/src/joystick/mint/SDL_sysjoystick.c	Wed Aug 02 21:26:31 2006 +0000
     2.3 @@ -44,19 +44,28 @@
     2.4  
     2.5  /* We can have:
     2.6  	1 joystick on IKBD port 1, read via hardware I/O
     2.7 -      or same joystick on IKBD port 1, read via xbios
     2.8 -	2 joypads on ports A,B
     2.9 -	  or 4 joysticks on joypads ports A,B
    2.10 +	  or same joystick on IKBD port 1, read via xbios
    2.11 +	1 joypad on port A (up to 4 with teamtap)
    2.12 +	  or 2 joysticks on joypad port A
    2.13 +	  or 1 analog paddle on joypad port A
    2.14  	  or 1 lightpen on joypad port A
    2.15 -	  or 2 analog paddles on joypads ports A,B
    2.16 +	1 joypad on port B (up to 4 with teamtap)
    2.17 +	  or 2 joysticks on joypad port B
    2.18 +	  or 1 analog paddle on joypad port B
    2.19  	2 joysticks on parallel port
    2.20  */
    2.21  
    2.22  enum {
    2.23  	IKBD_JOY1=0,
    2.24  	XBIOS_JOY1,
    2.25 -	PORTA_PAD,
    2.26 -	PORTB_PAD,
    2.27 +	PORTA_PAD0,
    2.28 +	PORTA_PAD1,
    2.29 +	PORTA_PAD2,
    2.30 +	PORTA_PAD3,
    2.31 +	PORTB_PAD0,
    2.32 +	PORTB_PAD1,
    2.33 +	PORTB_PAD2,
    2.34 +	PORTB_PAD3,
    2.35  	PORTA_JOY0,
    2.36  	PORTA_JOY1,
    2.37  	PORTB_JOY0,
    2.38 @@ -116,8 +125,14 @@
    2.39  static atarijoy_t atarijoysticks[MAX_JOYSTICKS]={
    2.40  	{SDL_FALSE,"IKBD joystick port 1",0},
    2.41  	{SDL_FALSE,"Xbios joystick port 1",0},
    2.42 -	{SDL_FALSE,"Joypad port A",0},
    2.43 -	{SDL_FALSE,"Joypad port B",0},
    2.44 +	{SDL_FALSE,"Joypad 0 port A",0},
    2.45 +	{SDL_FALSE,"Joypad 1 port A",0},
    2.46 +	{SDL_FALSE,"Joypad 2 port A",0},
    2.47 +	{SDL_FALSE,"Joypad 3 port A",0},
    2.48 +	{SDL_FALSE,"Joypad 0 port B",0},
    2.49 +	{SDL_FALSE,"Joypad 1 port B",0},
    2.50 +	{SDL_FALSE,"Joypad 2 port B",0},
    2.51 +	{SDL_FALSE,"Joypad 3 port B",0},
    2.52  	{SDL_FALSE,"Joystick 0 port A",0},
    2.53  	{SDL_FALSE,"Joystick 1 port A",0},
    2.54  	{SDL_FALSE,"Joystick 0 port B",0},
    2.55 @@ -146,7 +161,7 @@
    2.56  static Uint16 jp_lightpens[2];
    2.57  static Uint16 jp_directions;
    2.58  static Uint16 jp_fires;
    2.59 -static Uint32 jp_joypads[2];
    2.60 +static Uint32 jp_joypads[8];
    2.61  
    2.62  /*--- Functions prototypes ---*/
    2.63  
    2.64 @@ -181,8 +196,14 @@
    2.65  		atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0);
    2.66  	}
    2.67  	if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
    2.68 -		atarijoysticks[PORTA_PAD].enabled=SDL_TRUE;
    2.69 -		atarijoysticks[PORTB_PAD].enabled=SDL_TRUE;
    2.70 +		atarijoysticks[PORTA_PAD0].enabled = 
    2.71 +			atarijoysticks[PORTA_PAD1].enabled =
    2.72 +			atarijoysticks[PORTA_PAD2].enabled =
    2.73 +			atarijoysticks[PORTA_PAD3].enabled =
    2.74 +			atarijoysticks[PORTB_PAD0].enabled =
    2.75 +			atarijoysticks[PORTB_PAD1].enabled =
    2.76 +			atarijoysticks[PORTB_PAD2].enabled =
    2.77 +			atarijoysticks[PORTB_PAD3].enabled = SDL_TRUE;
    2.78  	}
    2.79  	if (!atarijoysticks[IKBD_JOY1].enabled) {
    2.80  		atarijoysticks[XBIOS_JOY1].enabled=(SDL_AtariXbios_enabled!=0);
    2.81 @@ -200,8 +221,8 @@
    2.82  		}
    2.83  		/* Joypads ports only on STE and Falcon */
    2.84  		if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) {
    2.85 -			TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
    2.86 -			if (!atarijoysticks[PORTA_PAD].enabled) {
    2.87 +			TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD0);
    2.88 +			if (!atarijoysticks[PORTA_PAD0].enabled) {
    2.89  				TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
    2.90  				TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
    2.91  				if (!(atarijoysticks[PORTA_JOY0].enabled) && !(atarijoysticks[PORTA_JOY1].enabled)) {
    2.92 @@ -212,8 +233,8 @@
    2.93  				}
    2.94  			}
    2.95  
    2.96 -			TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD);
    2.97 -			if (!atarijoysticks[PORTB_PAD].enabled) {
    2.98 +			TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD0);
    2.99 +			if (!atarijoysticks[PORTB_PAD0].enabled) {
   2.100  				TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
   2.101  				TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
   2.102  				if (!(atarijoysticks[PORTB_JOY0].enabled) && !(atarijoysticks[PORTB_JOY1].enabled)) {
   2.103 @@ -239,7 +260,7 @@
   2.104  
   2.105  	/* Need to update joypad ports ? */
   2.106  	joypad_ports_enabled=SDL_FALSE;
   2.107 -	for (i=PORTA_PAD;i<=PORTB_ANPAD;i++) {
   2.108 +	for (i=PORTA_PAD0;i<=PORTB_ANPAD;i++) {
   2.109  		if (atarijoysticks[i].enabled) {
   2.110  			joypad_ports_enabled=SDL_TRUE;
   2.111  			break;
   2.112 @@ -303,8 +324,14 @@
   2.113  	joystick->nballs=0;
   2.114  
   2.115  	switch(numjoystick) {
   2.116 -		case PORTA_PAD:
   2.117 -		case PORTB_PAD:
   2.118 +		case PORTA_PAD0:
   2.119 +		case PORTA_PAD1:
   2.120 +		case PORTA_PAD2:
   2.121 +		case PORTA_PAD3:
   2.122 +		case PORTB_PAD0:
   2.123 +		case PORTB_PAD1:
   2.124 +		case PORTB_PAD2:
   2.125 +		case PORTB_PAD3:
   2.126  			joystick->nhats=1;
   2.127  			joystick->nbuttons=JP_NUM_BUTTONS;
   2.128  			break;
   2.129 @@ -379,13 +406,36 @@
   2.130  				atarijoysticks[numjoystick].prevstate = curstate;
   2.131  			}
   2.132  			break;
   2.133 -		case PORTA_PAD:
   2.134 -		case PORTB_PAD:
   2.135 +		case PORTA_PAD0:
   2.136 +		case PORTA_PAD1:
   2.137 +		case PORTA_PAD2:
   2.138 +		case PORTA_PAD3:
   2.139 +		case PORTB_PAD0:
   2.140 +		case PORTB_PAD1:
   2.141 +		case PORTB_PAD2:
   2.142 +		case PORTB_PAD3:
   2.143  			{
   2.144  				int numjoypad,i;
   2.145  				
   2.146 -				numjoypad=0;
   2.147 -				if (numjoystick==PORTB_PAD) numjoypad=1;
   2.148 +				numjoypad = 0;
   2.149 +				switch(numjoystick) {
   2.150 +					case PORTA_PAD0:
   2.151 +						numjoypad = 0;	break;
   2.152 +					case PORTA_PAD1:
   2.153 +						numjoypad = 1;	break;
   2.154 +					case PORTA_PAD2:
   2.155 +						numjoypad = 2;	break;
   2.156 +					case PORTA_PAD3:
   2.157 +						numjoypad = 3;	break;
   2.158 +					case PORTB_PAD0:
   2.159 +						numjoypad = 4;	break;
   2.160 +					case PORTB_PAD1:
   2.161 +						numjoypad = 5;	break;
   2.162 +					case PORTB_PAD2:
   2.163 +						numjoypad = 6;	break;
   2.164 +					case PORTB_PAD3:
   2.165 +						numjoypad = 7;	break;
   2.166 +				}				
   2.167  				
   2.168  				curstate=jp_joypads[numjoypad];
   2.169  				if (curstate!=prevstate) {
   2.170 @@ -561,9 +611,21 @@
   2.171  };
   2.172  #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
   2.173  
   2.174 +static const Uint16 joypad_masks[8*4]={
   2.175 +	0xfffe, 0xfffd, 0xfffb, 0xfff7,
   2.176 +	0xfff0, 0xfff1, 0xfff2, 0xfff3,
   2.177 +	0xfff4, 0xfff5, 0xfff6, 0xfff8,
   2.178 +	0xfff9, 0xfffa, 0xfffc, 0xffff,
   2.179 +	0xffef, 0xffdf, 0xffbf, 0xff7f,
   2.180 +	0xff0f, 0xff1f, 0xff2f, 0xff3f,
   2.181 +	0xff4f, 0xff5f, 0xff6f, 0xff8f,
   2.182 +	0xff9f, 0xffaf, 0xffcf, 0xffff
   2.183 +};
   2.184 +
   2.185  static void UpdateJoypads(void)
   2.186  {
   2.187 -	Uint16 tmp;
   2.188 +	Uint16 tmp, i, j;
   2.189 +	Uint32 cur_fire, cur_dir;
   2.190  
   2.191  	/*--- This function is called in supervisor mode ---*/
   2.192  
   2.193 @@ -587,47 +649,35 @@
   2.194  	tmp = (JOYPAD_IO.paddles[3] & 255);
   2.195  	jp_paddles[3] = (tmp<<8) | tmp;
   2.196  
   2.197 -	/* Update joypad 0 */	
   2.198 -	JOYPAD_IO.directions=0xfffe;
   2.199 -	jp_joypads[0]=((~(JOYPAD_IO.fires)) & 3)<<(16);
   2.200 -	JOYPAD_IO.directions=0xfffe;
   2.201 -	jp_joypads[0] |= ((~(JOYPAD_IO.directions))>>8) & 15;
   2.202 +	/* Update joypads on teamtap port A */	
   2.203 +	for (i=0; i<4; i++) {
   2.204 +		jp_joypads[i] = 0;
   2.205 +		for (j=0; j<4; j++) {
   2.206 +			JOYPAD_IO.directions = joypad_masks[(i*4)+j];
   2.207  
   2.208 -	JOYPAD_IO.directions=0xfffd;
   2.209 -	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+2);
   2.210 -	JOYPAD_IO.directions=0xfffd;
   2.211 -	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<4;
   2.212 +			cur_fire = (~(JOYPAD_IO.fires) & 3)<<16;
   2.213 +			cur_dir = (~(JOYPAD_IO.directions)>>8) & 15;
   2.214  
   2.215 -	JOYPAD_IO.directions=0xfffb;
   2.216 -	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+4);
   2.217 -	JOYPAD_IO.directions=0xfffb;
   2.218 -	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<8;
   2.219 +			jp_joypads[i] |= cur_fire<<(j*2);
   2.220 +			jp_joypads[i] |= cur_dir<<(j*4);
   2.221 +		}
   2.222 +	}
   2.223  
   2.224 -	JOYPAD_IO.directions=0xfff7;
   2.225 -	jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3)<<(16+6);
   2.226 -	JOYPAD_IO.directions=0xfff7;
   2.227 -	jp_joypads[0] |= (((~(JOYPAD_IO.directions))>>8) & 15)<<12;
   2.228 +	/* Update joypads on teamtap port B */	
   2.229 +	for (i=4; i<8; i++) {
   2.230 +		jp_joypads[i] = 0;
   2.231 +		for (j=0; j<4; j++) {
   2.232 +			JOYPAD_IO.directions = joypad_masks[(i*4)+j];
   2.233  
   2.234 -	/* Update joypad 1 */	
   2.235 -	JOYPAD_IO.directions=0xffef;
   2.236 -	jp_joypads[1]=((~(JOYPAD_IO.fires)) & (3<<2))<<(16-2);
   2.237 -	JOYPAD_IO.directions=0xffef;
   2.238 -	jp_joypads[1] |= ((~(JOYPAD_IO.directions))>>12) & 15;
   2.239 +			cur_fire = (~(JOYPAD_IO.fires) & 0xc)<<14;
   2.240 +			cur_dir = (~(JOYPAD_IO.directions)>>12) & 15;
   2.241  
   2.242 -	JOYPAD_IO.directions=0xffdf;
   2.243 -	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16);
   2.244 -	JOYPAD_IO.directions=0xffdf;
   2.245 -	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<4;
   2.246 +			jp_joypads[i] |= cur_fire<<(j*2);
   2.247 +			jp_joypads[i] |= cur_dir<<(j*4);
   2.248 +		}
   2.249 +	}
   2.250  
   2.251 -	JOYPAD_IO.directions=0xffbf;
   2.252 -	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+2);
   2.253 -	JOYPAD_IO.directions=0xffbf;
   2.254 -	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<8;
   2.255 -
   2.256 -	JOYPAD_IO.directions=0xff7f;
   2.257 -	jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3<<2))<<(16+4);
   2.258 -	JOYPAD_IO.directions=0xff7f;
   2.259 -	jp_joypads[1] |= (((~(JOYPAD_IO.directions))>>12) & 15)<<12;
   2.260 +	JOYPAD_IO.directions=0xffff;
   2.261  }
   2.262  
   2.263  #endif /* SDL_JOYSTICK_MINT */