# HG changeset patch # User Patrice Mandin # Date 1240599842 0 # Node ID 3370c734fd4937a0ed6d93bd7faf6652228cc374 # Parent 34068be6aa0b7cd5f0d96752e46a67659681fe4e Add Teamtap autodetection, to avoid generating ghost events if it is not present diff -r 34068be6aa0b -r 3370c734fd49 src/joystick/mint/SDL_sysjoystick.c --- a/src/joystick/mint/SDL_sysjoystick.c Mon Apr 13 09:03:35 2009 +0000 +++ b/src/joystick/mint/SDL_sysjoystick.c Fri Apr 24 19:04:02 2009 +0000 @@ -112,6 +112,96 @@ #define PORT_JS_UP (1<<3) #define PORT_JS_FIRE (1<<4) +enum { + TEAMTAP_MAYBE=0, + TEAMTAP_YES, + TEAMTAP_NO +}; + +/* Teamtap detection values */ +static const Uint32 teamtap_ghosts[20][4]={ + {1<>16) == MCH_STE) || - (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || - (cookie_mch == MCH_ARANYM<<16)) { + (cookie_mch == MCH_TT<<16) || (cookie_mch == MCH_F30<<16) || + (cookie_mch == MCH_ARANYM<<16)) + { atarijoysticks[IKBD_JOY1].enabled=(SDL_AtariIkbd_enabled!=0); } - if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16)) { + if ((cookie_mch == MCH_STE<<16) || (cookie_mch == MCH_F30<<16) || + (cookie_mch == MCH_ARANYM<<16)) + { atarijoysticks[PORTA_PAD0].enabled = atarijoysticks[PORTA_PAD1].enabled = atarijoysticks[PORTA_PAD2].enabled = @@ -351,6 +445,42 @@ return(0); } +/* Detect Teamtap using ghost events */ +static void detect_teamtap(int num_port) +{ + int i,j; + + /* Check if joypad 1,2,3 triggered but not 0 */ + for (i=1; i<4; i++) { + if (jp_joypads[num_port*4+i] && (jp_joypads[num_port*4]==0)) { + has_teamtap[num_port] = TEAMTAP_YES; + return; + } + } + + /* Check if joypad 0 on a given port triggered ghost events for + * other joypads + */ + for (i=0; i<20; i++) { + int with_teamtap=1; + + if (jp_joypads[num_port*4]!=teamtap_ghosts[i][0]) + continue; + + /* If any button on first joypad pressed, check other pads */ + for (j=1; j<4; j++) { + if ((jp_joypads[num_port*4+j] & teamtap_ghosts[i][j]) + ==teamtap_ghosts[i][j]) + { + with_teamtap = 0; + } + } + + has_teamtap[num_port] = (with_teamtap ? TEAMTAP_YES : TEAMTAP_NO); + break; + } +} + void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) { int numjoystick; @@ -416,9 +546,9 @@ case PORTB_PAD2: case PORTB_PAD3: { - int numjoypad,i; + int numjoypad,i,numport; - numjoypad = 0; + numjoypad = numport = 0; switch(numjoystick) { case PORTA_PAD0: numjoypad = 0; break; @@ -429,16 +559,28 @@ case PORTA_PAD3: numjoypad = 3; break; case PORTB_PAD0: - numjoypad = 4; break; + numjoypad = 4; numport = 1; break; case PORTB_PAD1: - numjoypad = 5; break; + numjoypad = 5; numport = 1; break; case PORTB_PAD2: - numjoypad = 6; break; + numjoypad = 6; numport = 1; break; case PORTB_PAD3: - numjoypad = 7; break; + numjoypad = 7; numport = 1; break; } - curstate=jp_joypads[numjoypad] & 0xabffff; + jp_joypads[numjoypad] &= 0xabffff; + + if (has_teamtap[numport]==TEAMTAP_MAYBE) { + detect_teamtap(numport); + } + /* No events for PORTX_PAD[1,2,3] if no teamtap detected */ + if (has_teamtap[numport] == TEAMTAP_NO) { + if ((numjoypad & 3)!=0) { + return; + } + } + + curstate=jp_joypads[numjoypad]; if (curstate!=prevstate) { hatstate = SDL_HAT_CENTERED; if (curstate & (1<