No need to try to emulate analog axis when SDL support digital hats
authorPatrice Mandin <patmandin@gmail.com>
Sun, 31 Oct 2004 13:15:33 +0000
changeset 96392c247cec42d
parent 962 176240cf4405
child 964 d9209754ebee
No need to try to emulate analog axis when SDL support digital hats
README.MiNT
src/joystick/mint/SDL_sysjoystick.c
     1.1 --- a/README.MiNT	Fri Oct 29 11:19:03 2004 +0000
     1.2 +++ b/README.MiNT	Sun Oct 31 13:15:33 2004 +0000
     1.3 @@ -48,18 +48,18 @@
     1.4  Mouse (XBIOS, GEM, Ikbd)
     1.5  Video (XBIOS (Fullscreen), GEM (Windowed and Fullscreen))
     1.6  Timer (VBL vector, GNU pth library)
     1.7 -Joystick and joypad (Ikbd, Hardware)
     1.8 +Joysticks and joypads (Ikbd, Hardware)
     1.9  Audio (Hardware, XBIOS, GSXB, MCSN, STFA, /dev/audio if threads enabled)
    1.10  Threads (Multitasking OS only via GNU pth library)
    1.11  Shared object loader (using LDG library from http://ldg.atari.org/)
    1.12  Audio CD (MetaDOS)
    1.13  
    1.14  - Driver combinations:
    1.15 -Video	Kbd	Mouse	Timer	Joystick
    1.16 -xbios	ikbd	ikbd	vbl(2)	ikbd
    1.17 -xbios	gemdos	xbios	vbl(2)	xbios
    1.18 -xbios	bios	xbios	vbl(2)	xbios
    1.19 -gem	gem	gem(1)	vbl(2)	xbios
    1.20 +Video   Kbd     Mouse   Timer   Joysticks Joypads
    1.21 +xbios   ikbd    ikbd    vbl(2)  ikbd      hardware
    1.22 +xbios   gemdos  xbios   vbl(2)  xbios     hardware
    1.23 +xbios   bios    xbios   vbl(2)  xbios     hardware
    1.24 +gem     gem     gem(1)  vbl(2)  xbios     hardware
    1.25  
    1.26  (1) GEM does not report relative mouse motion, so xbios mouse driver is used
    1.27  to report this type event.
    1.28 @@ -116,10 +116,11 @@
    1.29  
    1.30  	The second joystick port on IKBD is used by the mouse, so not usable.
    1.31  
    1.32 -	Joypads are multibuttons controller (Atari Jaguar console-like).
    1.33 -	Joysticks are 1 button, 2 axis controllers.
    1.34 -	Lightpen and analog paddle are 2 buttons, 2 axis controllers. The 2
    1.35 -	buttons are those affected to 1 button joysticks on the same port.
    1.36 +	Descriptions of joysticks/joypads:
    1.37 +	- Joypads: 1 hat, 17 buttons (Atari Jaguar console-like).
    1.38 +	- Joysticks: 1 hat, 1 button.
    1.39 +	- Lightpen, analog paddles: 2 axis, 2 buttons. The 2 buttons are those
    1.40 +	  affected to 1 button joysticks on the same port.
    1.41  
    1.42  ==============================================================================
    1.43  VI.  More informations about drivers:
     2.1 --- a/src/joystick/mint/SDL_sysjoystick.c	Fri Oct 29 11:19:03 2004 +0000
     2.2 +++ b/src/joystick/mint/SDL_sysjoystick.c	Sun Oct 31 13:15:33 2004 +0000
     2.3 @@ -302,17 +302,27 @@
     2.4  	if (numjoystick==-1)
     2.5  		return -1;
     2.6  	
     2.7 -	if ((numjoystick==PORTA_PAD) || (numjoystick==PORTB_PAD)) {
     2.8 -		joystick->nbuttons=JP_NUM_BUTTONS;
     2.9 -	} else if ((numjoystick==PORTA_LP) || (numjoystick==PORTA_ANPAD) ||
    2.10 -				(numjoystick==PORTB_ANPAD)) {
    2.11 -		joystick->nbuttons=2;
    2.12 -	} else {
    2.13 -		joystick->nbuttons=1;
    2.14 +	joystick->naxes=0;
    2.15 +	joystick->nhats=0;
    2.16 +	joystick->nballs=0;
    2.17 +
    2.18 +	switch(numjoystick) {
    2.19 +		case PORTA_PAD:
    2.20 +		case PORTB_PAD:
    2.21 +			joystick->nhats=1;
    2.22 +			joystick->nbuttons=JP_NUM_BUTTONS;
    2.23 +			break;
    2.24 +		case PORTA_LP:
    2.25 +		case PORTA_ANPAD:
    2.26 +		case PORTB_ANPAD:
    2.27 +			joystick->naxes=2;
    2.28 +			joystick->nbuttons=2;
    2.29 +			break;
    2.30 +		default:
    2.31 +			joystick->nhats=1;
    2.32 +			joystick->nbuttons=1;
    2.33 +			break;
    2.34  	}
    2.35 -	joystick->naxes=2;
    2.36 -	joystick->nballs=0;
    2.37 -	joystick->nhats=0;
    2.38  
    2.39  	return(0);
    2.40  }
    2.41 @@ -320,8 +330,8 @@
    2.42  void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
    2.43  {
    2.44  	int numjoystick;
    2.45 +	Uint8 hatstate;
    2.46  	Uint32 curstate,prevstate;
    2.47 -	Sint16 curaxis;
    2.48  	
    2.49  	numjoystick=GetEnabledAtariJoystick(joystick->index);
    2.50  	if (numjoystick==-1)
    2.51 @@ -347,26 +357,21 @@
    2.52  				}
    2.53  
    2.54  				if (curstate != prevstate) {
    2.55 -					/* X axis */
    2.56 -					if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) {
    2.57 -						curaxis=0;
    2.58 -						if (curstate & IKBD_JOY_LEFT) {
    2.59 -							curaxis=0x8000;
    2.60 -						} else if (curstate & IKBD_JOY_RIGHT) {
    2.61 -							curaxis=0x7fff;
    2.62 -						}					
    2.63 -						SDL_PrivateJoystickAxis(joystick,0,curaxis);
    2.64 +					hatstate = SDL_HAT_CENTERED;
    2.65 +					if (curstate & IKBD_JOY_LEFT) {
    2.66 +						hatstate |= SDL_HAT_LEFT;
    2.67  					}
    2.68 -					/* Y axis */
    2.69 -					if ((curstate & (IKBD_JOY_UP|IKBD_JOY_DOWN)) != (prevstate & (IKBD_JOY_UP|IKBD_JOY_DOWN))) {
    2.70 -						curaxis=0;
    2.71 -						if (curstate & IKBD_JOY_UP) {
    2.72 -							curaxis=0x8000;
    2.73 -						} else if (curstate & IKBD_JOY_DOWN) {
    2.74 -							curaxis=0x7fff;
    2.75 -						}					
    2.76 -						SDL_PrivateJoystickAxis(joystick,1,curaxis);
    2.77 +					if (curstate & IKBD_JOY_RIGHT) {
    2.78 +						hatstate |= SDL_HAT_RIGHT;
    2.79  					}
    2.80 +					if (curstate & IKBD_JOY_UP) {
    2.81 +						hatstate |= SDL_HAT_UP;
    2.82 +					}
    2.83 +					if (curstate & IKBD_JOY_DOWN) {
    2.84 +						hatstate |= SDL_HAT_DOWN;
    2.85 +					}
    2.86 +					SDL_PrivateJoystickHat(joystick, 0, hatstate);
    2.87 +
    2.88  					/* Button */
    2.89  					if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) {
    2.90  						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
    2.91 @@ -384,31 +389,25 @@
    2.92  				int numjoypad,i;
    2.93  				
    2.94  				numjoypad=0;
    2.95 -/*				if (numjoystick==PORTA_PAD) numjoypad=0;*/
    2.96  				if (numjoystick==PORTB_PAD) numjoypad=1;
    2.97  				
    2.98  				curstate=jp_joypads[numjoypad];
    2.99  				if (curstate!=prevstate) {
   2.100 -					/* X axis */
   2.101 -					if ((curstate & ((1<<JP_LEFT)|(1<<JP_RIGHT))) != (prevstate & ((1<<JP_LEFT)|(1<<JP_RIGHT)))) {
   2.102 -						curaxis=0;
   2.103 -						if (curstate & (1<<JP_LEFT)) {
   2.104 -							curaxis=0x8000;
   2.105 -						} else if (curstate & (1<<JP_RIGHT)) {
   2.106 -							curaxis=0x7fff;
   2.107 -						}					
   2.108 -						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   2.109 +					hatstate = SDL_HAT_CENTERED;
   2.110 +					if (curstate & (1<<JP_LEFT)) {
   2.111 +						hatstate |= SDL_HAT_LEFT;
   2.112  					}
   2.113 -					/* Y axis */
   2.114 -					if ((curstate & ((1<<JP_UP)|(1<<JP_DOWN))) != (prevstate & ((1<<JP_UP)|(1<<JP_DOWN)))) {
   2.115 -						curaxis=0;
   2.116 -						if (curstate & (1<<JP_UP)) {
   2.117 -							curaxis=0x8000;
   2.118 -						} else if (curstate & (1<<JP_DOWN)) {
   2.119 -							curaxis=0x7fff;
   2.120 -						}					
   2.121 -						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   2.122 +					if (curstate & (1<<JP_RIGHT)) {
   2.123 +						hatstate |= SDL_HAT_RIGHT;
   2.124  					}
   2.125 +					if (curstate & (1<<JP_UP)) {
   2.126 +						hatstate |= SDL_HAT_UP;
   2.127 +					}
   2.128 +					if (curstate & (1<<JP_DOWN)) {
   2.129 +						hatstate |= SDL_HAT_DOWN;
   2.130 +					}
   2.131 +					SDL_PrivateJoystickHat(joystick, 0, hatstate);
   2.132 +
   2.133  					/* Buttons */
   2.134  					for (i=0;i<JP_NUM_BUTTONS;i++) {
   2.135  						int button;
   2.136 @@ -442,26 +441,21 @@
   2.137  				curstate |= ((jp_fires>>fire_shift) & 1)<<4;
   2.138  
   2.139  				if (curstate != prevstate) {
   2.140 -					/* X axis */
   2.141 -					if ((curstate & (PORT_JS_LEFT|PORT_JS_RIGHT)) != (prevstate & (PORT_JS_LEFT|PORT_JS_RIGHT))) {
   2.142 -						curaxis=0;
   2.143 -						if (curstate & PORT_JS_LEFT) {
   2.144 -							curaxis=0x8000;
   2.145 -						} else if (curstate & PORT_JS_RIGHT) {
   2.146 -							curaxis=0x7fff;
   2.147 -						}					
   2.148 -						SDL_PrivateJoystickAxis(joystick,0,curaxis);
   2.149 +					hatstate = SDL_HAT_CENTERED;
   2.150 +					if (curstate & PORT_JS_LEFT) {
   2.151 +						hatstate |= SDL_HAT_LEFT;
   2.152  					}
   2.153 -					/* Y axis */
   2.154 -					if ((curstate & (PORT_JS_UP|PORT_JS_DOWN)) != (prevstate & (PORT_JS_UP|PORT_JS_DOWN))) {
   2.155 -						curaxis=0;
   2.156 -						if (curstate & PORT_JS_UP) {
   2.157 -							curaxis=0x8000;
   2.158 -						} else if (curstate & PORT_JS_DOWN) {
   2.159 -							curaxis=0x7fff;
   2.160 -						}					
   2.161 -						SDL_PrivateJoystickAxis(joystick,1,curaxis);
   2.162 +					if (curstate & PORT_JS_RIGHT) {
   2.163 +						hatstate |= SDL_HAT_RIGHT;
   2.164  					}
   2.165 +					if (curstate & PORT_JS_UP) {
   2.166 +						hatstate |= SDL_HAT_UP;
   2.167 +					}
   2.168 +					if (curstate & PORT_JS_DOWN) {
   2.169 +						hatstate |= SDL_HAT_DOWN;
   2.170 +					}
   2.171 +					SDL_PrivateJoystickHat(joystick, 0, hatstate);
   2.172 +
   2.173  					/* Button */
   2.174  					if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) {
   2.175  						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);