Add teamtap support
authorPatrice Mandin <patmandin@gmail.com>
Sat, 16 Sep 2006 17:13:41 +0000
changeset 20298640d90b0406
parent 2028 6dbe2a67b23b
child 2030 d774e9d7c2a8
Add teamtap support
README.MiNT
src/joystick/mint/SDL_sysjoystick.c
     1.1 --- a/README.MiNT	Sat Sep 16 17:02:38 2006 +0000
     1.2 +++ b/README.MiNT	Sat Sep 16 17:13:41 2006 +0000
     1.3 @@ -124,12 +124,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
     2.1 --- a/src/joystick/mint/SDL_sysjoystick.c	Sat Sep 16 17:02:38 2006 +0000
     2.2 +++ b/src/joystick/mint/SDL_sysjoystick.c	Sat Sep 16 17:13:41 2006 +0000
     2.3 @@ -44,11 +44,14 @@
     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 @@ -56,8 +59,14 @@
    2.23  {
    2.24      IKBD_JOY1 = 0,
    2.25      XBIOS_JOY1,
    2.26 -    PORTA_PAD,
    2.27 -    PORTB_PAD,
    2.28 +    PORTA_PAD0,
    2.29 +    PORTA_PAD1,
    2.30 +    PORTA_PAD2,
    2.31 +    PORTA_PAD3,
    2.32 +    PORTB_PAD0,
    2.33 +    PORTB_PAD1,
    2.34 +    PORTB_PAD2,
    2.35 +    PORTB_PAD3,
    2.36      PORTA_JOY0,
    2.37      PORTA_JOY1,
    2.38      PORTB_JOY0,
    2.39 @@ -120,8 +129,14 @@
    2.40  static atarijoy_t atarijoysticks[MAX_JOYSTICKS] = {
    2.41      {SDL_FALSE, "IKBD joystick port 1", 0},
    2.42      {SDL_FALSE, "Xbios joystick port 1", 0},
    2.43 -    {SDL_FALSE, "Joypad port A", 0},
    2.44 -    {SDL_FALSE, "Joypad port B", 0},
    2.45 +    {SDL_FALSE, "Joypad 0 port A", 0},
    2.46 +    {SDL_FALSE, "Joypad 1 port A", 0},
    2.47 +    {SDL_FALSE, "Joypad 2 port A", 0},
    2.48 +    {SDL_FALSE, "Joypad 3 port A", 0},
    2.49 +    {SDL_FALSE, "Joypad 0 port B", 0},
    2.50 +    {SDL_FALSE, "Joypad 1 port B", 0},
    2.51 +    {SDL_FALSE, "Joypad 2 port B", 0},
    2.52 +    {SDL_FALSE, "Joypad 3 port B", 0},
    2.53      {SDL_FALSE, "Joystick 0 port A", 0},
    2.54      {SDL_FALSE, "Joystick 1 port A", 0},
    2.55      {SDL_FALSE, "Joystick 0 port B", 0},
    2.56 @@ -150,7 +165,7 @@
    2.57  static Uint16 jp_lightpens[2];
    2.58  static Uint16 jp_directions;
    2.59  static Uint16 jp_fires;
    2.60 -static Uint32 jp_joypads[2];
    2.61 +static Uint32 jp_joypads[8];
    2.62  
    2.63  /*--- Functions prototypes ---*/
    2.64  
    2.65 @@ -186,8 +201,14 @@
    2.66          atarijoysticks[IKBD_JOY1].enabled = (SDL_AtariIkbd_enabled != 0);
    2.67      }
    2.68      if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) {
    2.69 -        atarijoysticks[PORTA_PAD].enabled = SDL_TRUE;
    2.70 -        atarijoysticks[PORTB_PAD].enabled = SDL_TRUE;
    2.71 +        atarijoysticks[PORTA_PAD0].enabled =
    2.72 +        atarijoysticks[PORTA_PAD1].enabled =
    2.73 +        atarijoysticks[PORTA_PAD2].enabled =
    2.74 +        atarijoysticks[PORTA_PAD3].enabled =
    2.75 +        atarijoysticks[PORTB_PAD0].enabled =
    2.76 +        atarijoysticks[PORTB_PAD1].enabled =
    2.77 +        atarijoysticks[PORTB_PAD2].enabled =
    2.78 +        atarijoysticks[PORTB_PAD3].enabled = SDL_TRUE;
    2.79      }
    2.80      if (!atarijoysticks[IKBD_JOY1].enabled) {
    2.81          atarijoysticks[XBIOS_JOY1].enabled = (SDL_AtariXbios_enabled != 0);
    2.82 @@ -205,8 +226,8 @@
    2.83          }
    2.84          /* Joypads ports only on STE and Falcon */
    2.85          if ((cookie_mch == MCH_STE << 16) || (cookie_mch == MCH_F30 << 16)) {
    2.86 -            TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD);
    2.87 -            if (!atarijoysticks[PORTA_PAD].enabled) {
    2.88 +            TEST_JOY_ENABLED(envr, "porta-pad", PORTA_PAD0);
    2.89 +            if (!atarijoysticks[PORTA_PAD0].enabled) {
    2.90                  TEST_JOY_ENABLED(envr, "porta-joy0", PORTA_JOY0);
    2.91                  TEST_JOY_ENABLED(envr, "porta-joy1", PORTA_JOY1);
    2.92                  if (!(atarijoysticks[PORTA_JOY0].enabled)
    2.93 @@ -218,8 +239,8 @@
    2.94                  }
    2.95              }
    2.96  
    2.97 -            TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD);
    2.98 -            if (!atarijoysticks[PORTB_PAD].enabled) {
    2.99 +            TEST_JOY_ENABLED(envr, "portb-pad", PORTB_PAD0);
   2.100 +            if (!atarijoysticks[PORTB_PAD0].enabled) {
   2.101                  TEST_JOY_ENABLED(envr, "portb-joy0", PORTB_JOY0);
   2.102                  TEST_JOY_ENABLED(envr, "portb-joy1", PORTB_JOY1);
   2.103                  if (!(atarijoysticks[PORTB_JOY0].enabled)
   2.104 @@ -247,7 +268,7 @@
   2.105  
   2.106      /* Need to update joypad ports ? */
   2.107      joypad_ports_enabled = SDL_FALSE;
   2.108 -    for (i = PORTA_PAD; i <= PORTB_ANPAD; i++) {
   2.109 +    for (i = PORTA_PAD0; i <= PORTB_ANPAD; i++) {
   2.110          if (atarijoysticks[i].enabled) {
   2.111              joypad_ports_enabled = SDL_TRUE;
   2.112              break;
   2.113 @@ -314,8 +335,14 @@
   2.114      joystick->nballs = 0;
   2.115  
   2.116      switch (numjoystick) {
   2.117 -    case PORTA_PAD:
   2.118 -    case PORTB_PAD:
   2.119 +    case PORTA_PAD0:
   2.120 +    case PORTA_PAD1:
   2.121 +    case PORTA_PAD2:
   2.122 +    case PORTA_PAD3:
   2.123 +    case PORTB_PAD0:
   2.124 +    case PORTB_PAD1:
   2.125 +    case PORTB_PAD2:
   2.126 +    case PORTB_PAD3:
   2.127          joystick->nhats = 1;
   2.128          joystick->nbuttons = JP_NUM_BUTTONS;
   2.129          break;
   2.130 @@ -393,14 +420,36 @@
   2.131              atarijoysticks[numjoystick].prevstate = curstate;
   2.132          }
   2.133          break;
   2.134 -    case PORTA_PAD:
   2.135 -    case PORTB_PAD:
   2.136 +    case PORTA_PAD0:
   2.137 +    case PORTA_PAD1:
   2.138 +    case PORTA_PAD2:
   2.139 +    case PORTA_PAD3:
   2.140 +    case PORTB_PAD0:
   2.141 +    case PORTB_PAD1:
   2.142 +    case PORTB_PAD2:
   2.143 +    case PORTB_PAD3:
   2.144          {
   2.145              int numjoypad, i;
   2.146  
   2.147              numjoypad = 0;
   2.148 -            if (numjoystick == PORTB_PAD)
   2.149 -                numjoypad = 1;
   2.150 +            switch(numjoystick) {
   2.151 +            case PORTA_PAD0:
   2.152 +                numjoypad = 0;    break;
   2.153 +            case PORTA_PAD1:
   2.154 +                numjoypad = 1;    break;
   2.155 +            case PORTA_PAD2:
   2.156 +                numjoypad = 2;    break;
   2.157 +            case PORTA_PAD3:
   2.158 +                numjoypad = 3;    break;
   2.159 +            case PORTB_PAD0:
   2.160 +                numjoypad = 4;    break;
   2.161 +            case PORTB_PAD1:
   2.162 +                numjoypad = 5;    break;
   2.163 +            case PORTB_PAD2:
   2.164 +                numjoypad = 6;    break;
   2.165 +            case PORTB_PAD3:
   2.166 +                numjoypad = 7;    break;
   2.167 +            }				
   2.168  
   2.169              curstate = jp_joypads[numjoypad];
   2.170              if (curstate != prevstate) {
   2.171 @@ -598,6 +647,17 @@
   2.172  };
   2.173  #define JOYPAD_IO ((*(volatile struct JOYPAD_IO_S *)JOYPAD_IO_BASE))
   2.174  
   2.175 +static const Uint16 joypad_masks[8*4]={
   2.176 +    0xfffe, 0xfffd, 0xfffb, 0xfff7,
   2.177 +    0xfff0, 0xfff1, 0xfff2, 0xfff3,
   2.178 +    0xfff4, 0xfff5, 0xfff6, 0xfff8,
   2.179 +    0xfff9, 0xfffa, 0xfffc, 0xffff,
   2.180 +    0xffef, 0xffdf, 0xffbf, 0xff7f,
   2.181 +    0xff0f, 0xff1f, 0xff2f, 0xff3f,
   2.182 +    0xff4f, 0xff5f, 0xff6f, 0xff8f,
   2.183 +    0xff9f, 0xffaf, 0xffcf, 0xffff
   2.184 +};
   2.185 +
   2.186  static void
   2.187  UpdateJoypads(void)
   2.188  {
   2.189 @@ -625,47 +685,35 @@
   2.190      tmp = (JOYPAD_IO.paddles[3] & 255);
   2.191      jp_paddles[3] = (tmp << 8) | tmp;
   2.192  
   2.193 -    /* Update joypad 0 */
   2.194 -    JOYPAD_IO.directions = 0xfffe;
   2.195 -    jp_joypads[0] = ((~(JOYPAD_IO.fires)) & 3) << (16);
   2.196 -    JOYPAD_IO.directions = 0xfffe;
   2.197 -    jp_joypads[0] |= ((~(JOYPAD_IO.directions)) >> 8) & 15;
   2.198 +    /* Update joypads on teamtap port A */	
   2.199 +    for (i=0; i<4; i++) {
   2.200 +        jp_joypads[i] = 0;
   2.201 +        for (j=0; j<4; j++) {
   2.202 +            JOYPAD_IO.directions = joypad_masks[(i*4)+j];
   2.203  
   2.204 -    JOYPAD_IO.directions = 0xfffd;
   2.205 -    jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 2);
   2.206 -    JOYPAD_IO.directions = 0xfffd;
   2.207 -    jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 4;
   2.208 +            cur_fire = (~(JOYPAD_IO.fires) & 3)<<16;
   2.209 +            cur_dir = (~(JOYPAD_IO.directions)>>8) & 15;
   2.210  
   2.211 -    JOYPAD_IO.directions = 0xfffb;
   2.212 -    jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 4);
   2.213 -    JOYPAD_IO.directions = 0xfffb;
   2.214 -    jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 8;
   2.215 +            jp_joypads[i] |= cur_fire<<(j*2);
   2.216 +            jp_joypads[i] |= cur_dir<<(j*4);
   2.217 +        }
   2.218 +    }
   2.219  
   2.220 -    JOYPAD_IO.directions = 0xfff7;
   2.221 -    jp_joypads[0] |= ((~(JOYPAD_IO.fires)) & 3) << (16 + 6);
   2.222 -    JOYPAD_IO.directions = 0xfff7;
   2.223 -    jp_joypads[0] |= (((~(JOYPAD_IO.directions)) >> 8) & 15) << 12;
   2.224 +    /* Update joypads on teamtap port B */	
   2.225 +    for (i=4; i<8; i++) {
   2.226 +        jp_joypads[i] = 0;
   2.227 +        for (j=0; j<4; j++) {
   2.228 +            JOYPAD_IO.directions = joypad_masks[(i*4)+j];
   2.229  
   2.230 -    /* Update joypad 1 */
   2.231 -    JOYPAD_IO.directions = 0xffef;
   2.232 -    jp_joypads[1] = ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 - 2);
   2.233 -    JOYPAD_IO.directions = 0xffef;
   2.234 -    jp_joypads[1] |= ((~(JOYPAD_IO.directions)) >> 12) & 15;
   2.235 +            cur_fire = (~(JOYPAD_IO.fires) & 0xc)<<14;
   2.236 +            cur_dir = (~(JOYPAD_IO.directions)>>12) & 15;
   2.237  
   2.238 -    JOYPAD_IO.directions = 0xffdf;
   2.239 -    jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16);
   2.240 -    JOYPAD_IO.directions = 0xffdf;
   2.241 -    jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 4;
   2.242 +            jp_joypads[i] |= cur_fire<<(j*2);
   2.243 +            jp_joypads[i] |= cur_dir<<(j*4);
   2.244 +        }
   2.245 +    }
   2.246  
   2.247 -    JOYPAD_IO.directions = 0xffbf;
   2.248 -    jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 2);
   2.249 -    JOYPAD_IO.directions = 0xffbf;
   2.250 -    jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 8;
   2.251 -
   2.252 -    JOYPAD_IO.directions = 0xff7f;
   2.253 -    jp_joypads[1] |= ((~(JOYPAD_IO.fires)) & (3 << 2)) << (16 + 4);
   2.254 -    JOYPAD_IO.directions = 0xff7f;
   2.255 -    jp_joypads[1] |= (((~(JOYPAD_IO.directions)) >> 12) & 15) << 12;
   2.256 +    JOYPAD_IO.directions=0xffff;
   2.257  }
   2.258  
   2.259  #endif /* SDL_JOYSTICK_MINT */