From 9d76ae567b5352f5a0c5a0191af2b231211285d1 Mon Sep 17 00:00:00 2001 From: Patrice Mandin Date: Sun, 31 Oct 2004 13:15:33 +0000 Subject: [PATCH] No need to try to emulate analog axis when SDL support digital hats --- README.MiNT | 21 ++--- src/joystick/mint/SDL_sysjoystick.c | 126 +++++++++++++--------------- 2 files changed, 71 insertions(+), 76 deletions(-) diff --git a/README.MiNT b/README.MiNT index bc59f641b..b55ea88bf 100644 --- a/README.MiNT +++ b/README.MiNT @@ -48,18 +48,18 @@ Keyboard (GEMDOS, BIOS, GEM, Ikbd) 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 @@ SDL_JOYSTICK_ATARI: 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: diff --git a/src/joystick/mint/SDL_sysjoystick.c b/src/joystick/mint/SDL_sysjoystick.c index a93035a7f..9edd2e13c 100644 --- a/src/joystick/mint/SDL_sysjoystick.c +++ b/src/joystick/mint/SDL_sysjoystick.c @@ -302,17 +302,27 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) 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=2; - joystick->nballs=0; + 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; + } return(0); } @@ -320,8 +330,8 @@ int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) 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 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) } 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; } - /* 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_RIGHT) { + hatstate |= SDL_HAT_RIGHT; + } + 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 @@ void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) 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<>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; } - /* 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_RIGHT) { + hatstate |= SDL_HAT_RIGHT; } + 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);