changeset 963:92c247cec42d

No need to try to emulate analog axis when SDL support digital hats
author Patrice Mandin <patmandin@gmail.com>
date Sun, 31 Oct 2004 13:15:33 +0000
parents 176240cf4405
children d9209754ebee
files README.MiNT src/joystick/mint/SDL_sysjoystick.c
diffstat 2 files changed, 71 insertions(+), 76 deletions(-) [+]
line wrap: on
line diff
--- a/README.MiNT	Fri Oct 29 11:19:03 2004 +0000
+++ b/README.MiNT	Sun Oct 31 13:15:33 2004 +0000
@@ -48,18 +48,18 @@
 Mouse (XBIOS, GEM, Ikbd)
 Video (XBIOS (Fullscreen), GEM (Windowed and Fullscreen))
 Timer (VBL vector, GNU pth library)
-Joystick and joypad (Ikbd, Hardware)
+Joysticks and joypads (Ikbd, Hardware)
 Audio (Hardware, XBIOS, GSXB, MCSN, STFA, /dev/audio if threads enabled)
 Threads (Multitasking OS only via GNU pth library)
 Shared object loader (using LDG library from http://ldg.atari.org/)
 Audio CD (MetaDOS)
 
 - Driver combinations:
-Video	Kbd	Mouse	Timer	Joystick
-xbios	ikbd	ikbd	vbl(2)	ikbd
-xbios	gemdos	xbios	vbl(2)	xbios
-xbios	bios	xbios	vbl(2)	xbios
-gem	gem	gem(1)	vbl(2)	xbios
+Video   Kbd     Mouse   Timer   Joysticks Joypads
+xbios   ikbd    ikbd    vbl(2)  ikbd      hardware
+xbios   gemdos  xbios   vbl(2)  xbios     hardware
+xbios   bios    xbios   vbl(2)  xbios     hardware
+gem     gem     gem(1)  vbl(2)  xbios     hardware
 
 (1) GEM does not report relative mouse motion, so xbios mouse driver is used
 to report this type event.
@@ -116,10 +116,11 @@
 
 	The second joystick port on IKBD is used by the mouse, so not usable.
 
-	Joypads are multibuttons controller (Atari Jaguar console-like).
-	Joysticks are 1 button, 2 axis controllers.
-	Lightpen and analog paddle are 2 buttons, 2 axis controllers. The 2
-	buttons are those affected to 1 button joysticks on the same port.
+	Descriptions of joysticks/joypads:
+	- Joypads: 1 hat, 17 buttons (Atari Jaguar console-like).
+	- Joysticks: 1 hat, 1 button.
+	- Lightpen, analog paddles: 2 axis, 2 buttons. The 2 buttons are those
+	  affected to 1 button joysticks on the same port.
 
 ==============================================================================
 VI.  More informations about drivers:
--- a/src/joystick/mint/SDL_sysjoystick.c	Fri Oct 29 11:19:03 2004 +0000
+++ b/src/joystick/mint/SDL_sysjoystick.c	Sun Oct 31 13:15:33 2004 +0000
@@ -302,17 +302,27 @@
 	if (numjoystick==-1)
 		return -1;
 	
-	if ((numjoystick==PORTA_PAD) || (numjoystick==PORTB_PAD)) {
-		joystick->nbuttons=JP_NUM_BUTTONS;
-	} else if ((numjoystick==PORTA_LP) || (numjoystick==PORTA_ANPAD) ||
-				(numjoystick==PORTB_ANPAD)) {
-		joystick->nbuttons=2;
-	} else {
-		joystick->nbuttons=1;
+	joystick->naxes=0;
+	joystick->nhats=0;
+	joystick->nballs=0;
+
+	switch(numjoystick) {
+		case PORTA_PAD:
+		case PORTB_PAD:
+			joystick->nhats=1;
+			joystick->nbuttons=JP_NUM_BUTTONS;
+			break;
+		case PORTA_LP:
+		case PORTA_ANPAD:
+		case PORTB_ANPAD:
+			joystick->naxes=2;
+			joystick->nbuttons=2;
+			break;
+		default:
+			joystick->nhats=1;
+			joystick->nbuttons=1;
+			break;
 	}
-	joystick->naxes=2;
-	joystick->nballs=0;
-	joystick->nhats=0;
 
 	return(0);
 }
@@ -320,8 +330,8 @@
 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
 {
 	int numjoystick;
+	Uint8 hatstate;
 	Uint32 curstate,prevstate;
-	Sint16 curaxis;
 	
 	numjoystick=GetEnabledAtariJoystick(joystick->index);
 	if (numjoystick==-1)
@@ -347,26 +357,21 @@
 				}
 
 				if (curstate != prevstate) {
-					/* X axis */
-					if ((curstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT)) != (prevstate & (IKBD_JOY_LEFT|IKBD_JOY_RIGHT))) {
-						curaxis=0;
-						if (curstate & IKBD_JOY_LEFT) {
-							curaxis=0x8000;
-						} else if (curstate & IKBD_JOY_RIGHT) {
-							curaxis=0x7fff;
-						}					
-						SDL_PrivateJoystickAxis(joystick,0,curaxis);
+					hatstate = SDL_HAT_CENTERED;
+					if (curstate & IKBD_JOY_LEFT) {
+						hatstate |= SDL_HAT_LEFT;
+					}
+					if (curstate & IKBD_JOY_RIGHT) {
+						hatstate |= SDL_HAT_RIGHT;
 					}
-					/* Y axis */
-					if ((curstate & (IKBD_JOY_UP|IKBD_JOY_DOWN)) != (prevstate & (IKBD_JOY_UP|IKBD_JOY_DOWN))) {
-						curaxis=0;
-						if (curstate & IKBD_JOY_UP) {
-							curaxis=0x8000;
-						} else if (curstate & IKBD_JOY_DOWN) {
-							curaxis=0x7fff;
-						}					
-						SDL_PrivateJoystickAxis(joystick,1,curaxis);
+					if (curstate & IKBD_JOY_UP) {
+						hatstate |= SDL_HAT_UP;
 					}
+					if (curstate & IKBD_JOY_DOWN) {
+						hatstate |= SDL_HAT_DOWN;
+					}
+					SDL_PrivateJoystickHat(joystick, 0, hatstate);
+
 					/* Button */
 					if ((curstate & IKBD_JOY_FIRE) && !(prevstate & IKBD_JOY_FIRE)) {
 						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);
@@ -384,31 +389,25 @@
 				int numjoypad,i;
 				
 				numjoypad=0;
-/*				if (numjoystick==PORTA_PAD) numjoypad=0;*/
 				if (numjoystick==PORTB_PAD) numjoypad=1;
 				
 				curstate=jp_joypads[numjoypad];
 				if (curstate!=prevstate) {
-					/* X axis */
-					if ((curstate & ((1<<JP_LEFT)|(1<<JP_RIGHT))) != (prevstate & ((1<<JP_LEFT)|(1<<JP_RIGHT)))) {
-						curaxis=0;
-						if (curstate & (1<<JP_LEFT)) {
-							curaxis=0x8000;
-						} else if (curstate & (1<<JP_RIGHT)) {
-							curaxis=0x7fff;
-						}					
-						SDL_PrivateJoystickAxis(joystick,0,curaxis);
+					hatstate = SDL_HAT_CENTERED;
+					if (curstate & (1<<JP_LEFT)) {
+						hatstate |= SDL_HAT_LEFT;
+					}
+					if (curstate & (1<<JP_RIGHT)) {
+						hatstate |= SDL_HAT_RIGHT;
 					}
-					/* Y axis */
-					if ((curstate & ((1<<JP_UP)|(1<<JP_DOWN))) != (prevstate & ((1<<JP_UP)|(1<<JP_DOWN)))) {
-						curaxis=0;
-						if (curstate & (1<<JP_UP)) {
-							curaxis=0x8000;
-						} else if (curstate & (1<<JP_DOWN)) {
-							curaxis=0x7fff;
-						}					
-						SDL_PrivateJoystickAxis(joystick,1,curaxis);
+					if (curstate & (1<<JP_UP)) {
+						hatstate |= SDL_HAT_UP;
 					}
+					if (curstate & (1<<JP_DOWN)) {
+						hatstate |= SDL_HAT_DOWN;
+					}
+					SDL_PrivateJoystickHat(joystick, 0, hatstate);
+
 					/* Buttons */
 					for (i=0;i<JP_NUM_BUTTONS;i++) {
 						int button;
@@ -442,26 +441,21 @@
 				curstate |= ((jp_fires>>fire_shift) & 1)<<4;
 
 				if (curstate != prevstate) {
-					/* X axis */
-					if ((curstate & (PORT_JS_LEFT|PORT_JS_RIGHT)) != (prevstate & (PORT_JS_LEFT|PORT_JS_RIGHT))) {
-						curaxis=0;
-						if (curstate & PORT_JS_LEFT) {
-							curaxis=0x8000;
-						} else if (curstate & PORT_JS_RIGHT) {
-							curaxis=0x7fff;
-						}					
-						SDL_PrivateJoystickAxis(joystick,0,curaxis);
+					hatstate = SDL_HAT_CENTERED;
+					if (curstate & PORT_JS_LEFT) {
+						hatstate |= SDL_HAT_LEFT;
+					}
+					if (curstate & PORT_JS_RIGHT) {
+						hatstate |= SDL_HAT_RIGHT;
 					}
-					/* Y axis */
-					if ((curstate & (PORT_JS_UP|PORT_JS_DOWN)) != (prevstate & (PORT_JS_UP|PORT_JS_DOWN))) {
-						curaxis=0;
-						if (curstate & PORT_JS_UP) {
-							curaxis=0x8000;
-						} else if (curstate & PORT_JS_DOWN) {
-							curaxis=0x7fff;
-						}					
-						SDL_PrivateJoystickAxis(joystick,1,curaxis);
+					if (curstate & PORT_JS_UP) {
+						hatstate |= SDL_HAT_UP;
 					}
+					if (curstate & PORT_JS_DOWN) {
+						hatstate |= SDL_HAT_DOWN;
+					}
+					SDL_PrivateJoystickHat(joystick, 0, hatstate);
+
 					/* Button */
 					if ((curstate & PORT_JS_FIRE) && !(prevstate & PORT_JS_FIRE)) {
 						SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);