Fixed bug #888 SDL-1.2
authorSam Lantinga
Tue, 17 Nov 2009 05:14:23 +0000
branchSDL-1.2
changeset 4385a2bb14457446
parent 4384 6800e2560310
child 4386 dcb26ac38e6b
Fixed bug #888

The OS/2 joystick code included an IBM header and was in violation of the license.
Ryan may put this back someday with a legal header. :)
src/joystick/os2/SDL_sysjoystick.c
src/joystick/os2/joyos2.h
     1.1 --- a/src/joystick/os2/SDL_sysjoystick.c	Tue Nov 17 04:59:13 2009 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,668 +0,0 @@
     1.4 -/*
     1.5 -    SDL - Simple DirectMedia Layer
     1.6 -    Copyright (C) 1997-2009 Sam Lantinga
     1.7 -
     1.8 -    This library is free software; you can redistribute it and/or
     1.9 -    modify it under the terms of the GNU Lesser General Public
    1.10 -    License as published by the Free Software Foundation; either
    1.11 -    version 2.1 of the License, or (at your option) any later version.
    1.12 -
    1.13 -    This library is distributed in the hope that it will be useful,
    1.14 -    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 -    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 -    Lesser General Public License for more details.
    1.17 -
    1.18 -    You should have received a copy of the GNU Lesser General Public
    1.19 -    License along with this library; if not, write to the Free Software
    1.20 -    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 -
    1.22 -    Sam Lantinga
    1.23 -    slouken@libsdl.org
    1.24 -*/
    1.25 -#include "SDL_config.h"
    1.26 -
    1.27 -#ifdef SDL_JOYSTICK_OS2
    1.28 -
    1.29 -/* OS/2 Joystick driver, contributed by Daniel Caetano */
    1.30 -
    1.31 -#include <mem.h>
    1.32 -
    1.33 -#define INCL_DOSDEVICES
    1.34 -#define INCL_DOSDEVIOCTL
    1.35 -#define INCL_DOSMEMMGR
    1.36 -#include <os2.h>
    1.37 -#include "joyos2.h"
    1.38 -
    1.39 -#include "SDL_joystick.h"
    1.40 -#include "SDL_events.h"
    1.41 -#include "../SDL_sysjoystick.h"
    1.42 -#include "../SDL_joystick_c.h"
    1.43 -
    1.44 -HFILE hJoyPort = NULL;		/* Joystick GAME$ Port Address */
    1.45 -#define MAX_JOYSTICKS	2	/* Maximum of two joysticks */
    1.46 -#define MAX_AXES	4			/* each joystick can have up to 4 axes */
    1.47 -#define MAX_BUTTONS	8		/* 8 buttons */
    1.48 -#define MAX_HATS	0			/* 0 hats - OS/2 doesn't support it */
    1.49 -#define MAX_BALLS	0			/* and 0 balls - OS/2 doesn't support it */
    1.50 -#define AXIS_MIN -32768		/* minimum value for axes coordinate */
    1.51 -#define AXIS_MAX 32767		/* maximum value for axes coordinate */
    1.52 -#define MAX_JOYNAME	128	/* Joystick name may have 128 characters */
    1.53 -/* limit axes to 256 possible positions to filter out noise */
    1.54 -#define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256)
    1.55 -/* Calc Button Flag for buttons A to D */
    1.56 -#define JOY_BUTTON_FLAG(n) (1<<n)
    1.57 -
    1.58 -/* Joystick data... hold information about detected devices */
    1.59 -typedef struct SYS_JoyData_s
    1.60 -{
    1.61 -Sint8					id;								// Device ID
    1.62 -char					szDeviceName[MAX_JOYNAME];	// Device Name
    1.63 -char					axes;								// Number of axes
    1.64 -char					buttons;							// Number of buttons
    1.65 -char					hats;								// Number of buttons
    1.66 -char					balls;							// Number of buttons
    1.67 -int					axes_min[MAX_AXES];			// minimum callibration value for axes
    1.68 -int					axes_med[MAX_AXES];			// medium callibration value for axes
    1.69 -int					axes_max[MAX_AXES];			// maximum callibration value for axes
    1.70 -int					buttoncalc[4];					// Used for buttons 5, 6, 7 and 8.
    1.71 -} SYS_JoyData_t, *SYS_JoyData_p;
    1.72 -
    1.73 -SYS_JoyData_t SYS_JoyData[MAX_JOYSTICKS];
    1.74 -
    1.75 -
    1.76 -/* Structure used to convert data from OS/2 driver format to SDL format */
    1.77 -struct joystick_hwdata
    1.78 -{
    1.79 -Sint8					id;
    1.80 -struct _transaxes
    1.81 -	{
    1.82 -	int offset;					/* Center Offset */
    1.83 -	float scale1;				/* Center to left/up Scale */
    1.84 -	float scale2;				/* Center to right/down Scale */
    1.85 -	} transaxes[MAX_AXES];
    1.86 -};
    1.87 -
    1.88 -/* Structure used to get values from Joystick Environment Variable */
    1.89 -struct _joycfg
    1.90 -{
    1.91 -char	name[MAX_JOYNAME];
    1.92 -unsigned int	axes;
    1.93 -unsigned int	buttons;
    1.94 -unsigned int	hats;
    1.95 -unsigned int	balls;
    1.96 -};
    1.97 -
    1.98 -/* OS/2 Implementation Function Prototypes */
    1.99 -APIRET joyPortOpen(HFILE * hGame);
   1.100 -void joyPortClose(HFILE * hGame);
   1.101 -int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars);
   1.102 -int joyGetEnv(struct _joycfg * joydata);
   1.103 -
   1.104 -
   1.105 -
   1.106 -/************************************************************************/
   1.107 -/* Function to scan the system for joysticks.									*/
   1.108 -/* This function should set SDL_numjoysticks to the number of available	*/
   1.109 -/* joysticks.  Joystick 0 should be the system default joystick.			*/
   1.110 -/* It should return 0, or -1 on an unrecoverable fatal error.				*/
   1.111 -/************************************************************************/
   1.112 -int SDL_SYS_JoystickInit(void)
   1.113 -{
   1.114 -APIRET rc;											/* Generic OS/2 return code */
   1.115 -GAME_PORT_STRUCT	stJoyStatus;				/* Joystick Status Structure */
   1.116 -GAME_PARM_STRUCT	stGameParms;				/* Joystick Parameter Structure */
   1.117 -GAME_CALIB_STRUCT	stGameCalib;				/* Calibration Struct */
   1.118 -ULONG ulDataLen;									/* Size of data */
   1.119 -ULONG ulLastTick;						/* Tick Counter for timing operations */
   1.120 -Uint8 maxdevs;										/* Maximum number of devices */
   1.121 -Uint8 numdevs;										/* Number of present devices */
   1.122 -Uint8 maxbut;										/* Maximum number of buttons... */
   1.123 -Uint8 i;												/* Temporary Count Vars */
   1.124 -Uint8 ucNewJoystickMask;										/* Mask for Joystick Detection */
   1.125 -struct _joycfg joycfg;							/* Joy Configuration from envvar */
   1.126 -
   1.127 -
   1.128 -/* Get Max Number of Devices */
   1.129 -rc = joyPortOpen(&hJoyPort); /* Open GAME$ port */
   1.130 -if (rc != 0) return 0;	/* Cannot open... report no joystick */
   1.131 -ulDataLen = sizeof(stGameParms);
   1.132 -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_PARMS,
   1.133 -	NULL, 0, NULL, &stGameParms, ulDataLen, &ulDataLen); /* Ask device info */
   1.134 -if (rc != 0)
   1.135 -	{
   1.136 -	joyPortClose(&hJoyPort);
   1.137 -	SDL_SetError("Could not read joystick port.");
   1.138 -	return -1;
   1.139 -	}
   1.140 -if (stGameParms.useA != 0) maxdevs++;
   1.141 -if (stGameParms.useB != 0) maxdevs++;
   1.142 -if ( maxdevs > MAX_JOYSTICKS ) maxdevs = MAX_JOYSTICKS;
   1.143 -
   1.144 -/* Defines min/max axes values (callibration) */
   1.145 -ulDataLen = sizeof(stGameCalib);
   1.146 -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_CALIB,
   1.147 -	NULL, 0, NULL, &stGameCalib, ulDataLen, &ulDataLen);
   1.148 -if (rc != 0)
   1.149 -	{
   1.150 -	joyPortClose(&hJoyPort);
   1.151 -	SDL_SetError("Could not read callibration data.");
   1.152 -	return -1;
   1.153 -	}
   1.154 -
   1.155 -/* Determine how many joysticks are active */
   1.156 -numdevs = 0;	/* Points no device */
   1.157 -ucNewJoystickMask = 0x0F;	/* read all 4 joystick axis */
   1.158 -ulDataLen = sizeof(ucNewJoystickMask);
   1.159 -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_RESET,
   1.160 -		&ucNewJoystickMask, ulDataLen, &ulDataLen, NULL, 0, NULL);
   1.161 -if (rc == 0)
   1.162 -	{
   1.163 -	ulDataLen = sizeof(stJoyStatus);
   1.164 -	rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
   1.165 -		NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen);
   1.166 -	if (rc != 0)
   1.167 -		{
   1.168 -		joyPortClose(&hJoyPort);
   1.169 -		SDL_SetError("Could not call joystick port.");
   1.170 -		return -1;
   1.171 -		}
   1.172 -	ulLastTick = stJoyStatus.ulJs_Ticks;
   1.173 -	while (stJoyStatus.ulJs_Ticks == ulLastTick)
   1.174 -		{
   1.175 -		rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
   1.176 -			NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen);
   1.177 -		}
   1.178 -	if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) numdevs++;
   1.179 -	if (((stJoyStatus.ucJs_JoyStickMask >> 2) & 0x03) > 0) numdevs++;
   1.180 -	}
   1.181 -
   1.182 -if (numdevs>maxdevs) numdevs=maxdevs;
   1.183 -
   1.184 -/* If *any* joystick was detected... Let's configure SDL for them */
   1.185 -if (numdevs > 0)
   1.186 -	{
   1.187 -	/* Verify if it is a "user defined" joystick */
   1.188 -	if (joyGetEnv(&joycfg))
   1.189 -		{
   1.190 -		GAME_3POS_STRUCT * axis[4];
   1.191 -		axis[0] = &stGameCalib.Ax;
   1.192 -		axis[1] = &stGameCalib.Ay;
   1.193 -		axis[2] = &stGameCalib.Bx;
   1.194 -		axis[3] = &stGameCalib.By;
   1.195 -		/* Say it has one device only (user defined is always one device only) */
   1.196 -		numdevs = 1;
   1.197 -		/* Define Device 0 as... */
   1.198 -		SYS_JoyData[0].id=0;
   1.199 -		/* Define Number of Axes... up to 4 */
   1.200 -		if (joycfg.axes>MAX_AXES) joycfg.axes = MAX_AXES;
   1.201 -		SYS_JoyData[0].axes = joycfg.axes;
   1.202 -		/* Define number of buttons... 8 if 2 axes, 6 if 3 axes and 4 if 4 axes */
   1.203 -		maxbut = MAX_BUTTONS;
   1.204 -		if (joycfg.axes>2) maxbut-=((joycfg.axes-2)<<1); /* MAX_BUTTONS - 2*(axes-2) */
   1.205 -		if (joycfg.buttons > maxbut) joycfg.buttons = maxbut;
   1.206 -		SYS_JoyData[0].buttons = joycfg.buttons;
   1.207 -		/* Define number of hats */
   1.208 -		if (joycfg.hats > MAX_HATS) joycfg.hats = MAX_HATS;
   1.209 -		SYS_JoyData[0].hats = joycfg.hats;
   1.210 -		/* Define number of balls */
   1.211 -		if (joycfg.balls > MAX_BALLS) joycfg.balls = MAX_BALLS;
   1.212 -		SYS_JoyData[0].balls = joycfg.balls;
   1.213 -		/* Initialize Axes Callibration Values */
   1.214 -		for (i=0; i<joycfg.axes; i++)
   1.215 -			{
   1.216 -			SYS_JoyData[0].axes_min[i] = axis[i]->lower;
   1.217 -			SYS_JoyData[0].axes_med[i] = axis[i]->centre;
   1.218 -			SYS_JoyData[0].axes_max[i] = axis[i]->upper;
   1.219 -			}
   1.220 -		/* Initialize Buttons 5 to 8 structures */
   1.221 -		if (joycfg.buttons>=5) SYS_JoyData[0].buttoncalc[0]=((axis[2]->lower+axis[3]->centre)>>1);
   1.222 -		if (joycfg.buttons>=6) SYS_JoyData[0].buttoncalc[1]=((axis[3]->lower+axis[3]->centre)>>1);
   1.223 -		if (joycfg.buttons>=7) SYS_JoyData[0].buttoncalc[2]=((axis[2]->upper+axis[3]->centre)>>1);
   1.224 -		if (joycfg.buttons>=8) SYS_JoyData[0].buttoncalc[3]=((axis[3]->upper+axis[3]->centre)>>1);
   1.225 -		/* Intialize Joystick Name */
   1.226 -		SDL_strlcpy (SYS_JoyData[0].szDeviceName,joycfg.name, SDL_arraysize(SYS_JoyData[0].szDeviceName));
   1.227 -		}
   1.228 -	/* Default Init ... autoconfig */
   1.229 -	else
   1.230 -		{
   1.231 -		/* if two devices were detected... configure as Joy1 4 axis and Joy2 2 axis */
   1.232 -		if (numdevs==2)
   1.233 -			{
   1.234 -			/* Define Device 0 as 4 axes, 4 buttons */
   1.235 -			SYS_JoyData[0].id=0;
   1.236 -			SYS_JoyData[0].axes = 4;
   1.237 -			SYS_JoyData[0].buttons = 4;
   1.238 -			SYS_JoyData[0].hats = 0;
   1.239 -			SYS_JoyData[0].balls = 0;
   1.240 -			SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower;
   1.241 -			SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre;
   1.242 -			SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper;
   1.243 -			SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower;
   1.244 -			SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre;
   1.245 -			SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper;
   1.246 -			SYS_JoyData[0].axes_min[2] = stGameCalib.Bx.lower;
   1.247 -			SYS_JoyData[0].axes_med[2] = stGameCalib.Bx.centre;
   1.248 -			SYS_JoyData[0].axes_max[2] = stGameCalib.Bx.upper;
   1.249 -			SYS_JoyData[0].axes_min[3] = stGameCalib.By.lower;
   1.250 -			SYS_JoyData[0].axes_med[3] = stGameCalib.By.centre;
   1.251 -			SYS_JoyData[0].axes_max[3] = stGameCalib.By.upper;
   1.252 -			/* Define Device 1 as 2 axes, 2 buttons */
   1.253 -			SYS_JoyData[1].id=1;
   1.254 -			SYS_JoyData[1].axes = 2;
   1.255 -			SYS_JoyData[1].buttons = 2;
   1.256 -			SYS_JoyData[1].hats = 0;
   1.257 -			SYS_JoyData[1].balls = 0;
   1.258 -			SYS_JoyData[1].axes_min[0] = stGameCalib.Bx.lower;
   1.259 -			SYS_JoyData[1].axes_med[0] = stGameCalib.Bx.centre;
   1.260 -			SYS_JoyData[1].axes_max[0] = stGameCalib.Bx.upper;
   1.261 -			SYS_JoyData[1].axes_min[1] = stGameCalib.By.lower;
   1.262 -			SYS_JoyData[1].axes_med[1] = stGameCalib.By.centre;
   1.263 -			SYS_JoyData[1].axes_max[1] = stGameCalib.By.upper;
   1.264 -			}
   1.265 -		/* One joystick only? */
   1.266 -		else
   1.267 -			{
   1.268 -			/* If it is joystick A... */
   1.269 -			if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0)
   1.270 -				{
   1.271 -				/* Define Device 0 as 2 axes, 4 buttons */
   1.272 -				SYS_JoyData[0].id=0;
   1.273 -				SYS_JoyData[0].axes = 2;
   1.274 -				SYS_JoyData[0].buttons = 4;
   1.275 -				SYS_JoyData[0].hats = 0;
   1.276 -				SYS_JoyData[0].balls = 0;
   1.277 -				SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower;
   1.278 -				SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre;
   1.279 -				SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper;
   1.280 -				SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower;
   1.281 -				SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre;
   1.282 -				SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper;
   1.283 -				}
   1.284 -			/* If not, it is joystick B */
   1.285 -			else
   1.286 -				{
   1.287 -				/* Define Device 1 as 2 axes, 2 buttons */
   1.288 -				SYS_JoyData[0].id=1;
   1.289 -				SYS_JoyData[0].axes = 2;
   1.290 -				SYS_JoyData[0].buttons = 2;
   1.291 -				SYS_JoyData[0].hats = 0;
   1.292 -				SYS_JoyData[0].balls = 0;
   1.293 -				SYS_JoyData[0].axes_min[0] = stGameCalib.Bx.lower;
   1.294 -				SYS_JoyData[0].axes_med[0] = stGameCalib.Bx.centre;
   1.295 -				SYS_JoyData[0].axes_max[0] = stGameCalib.Bx.upper;
   1.296 -				SYS_JoyData[0].axes_min[1] = stGameCalib.By.lower;
   1.297 -				SYS_JoyData[0].axes_med[1] = stGameCalib.By.centre;
   1.298 -				SYS_JoyData[0].axes_max[1] = stGameCalib.By.upper;
   1.299 -				}
   1.300 -			}
   1.301 -		/* Hack to define Joystick Port Names */
   1.302 -		if ( numdevs > maxdevs ) numdevs = maxdevs;
   1.303 -		for (i=0; i<numdevs; i++)
   1.304 -                  SDL_snprintf (SYS_JoyData[i].szDeviceName, SDL_arraysize(SYS_JoyData[i].szDeviceName), "Default Joystick %c", 'A'+SYS_JoyData[i].id);
   1.305 -
   1.306 -                }
   1.307 -	}
   1.308 -/* Return the number of devices found */
   1.309 -return(numdevs);
   1.310 -}
   1.311 -
   1.312 -
   1.313 -/***********************************************************/
   1.314 -/* Function to get the device-dependent name of a joystick */
   1.315 -/***********************************************************/
   1.316 -const char *SDL_SYS_JoystickName(int index)
   1.317 -{
   1.318 -/* No need to verify if device exists, already done in upper layer */
   1.319 -return(SYS_JoyData[index].szDeviceName);
   1.320 -}
   1.321 -
   1.322 -
   1.323 -
   1.324 -/******************************************************************************/
   1.325 -/* Function to open a joystick for use.													*/
   1.326 -/* The joystick to open is specified by the index field of the joystick.		*/
   1.327 -/* This should fill the nbuttons and naxes fields of the joystick structure.	*/
   1.328 -/* It returns 0, or -1 if there is an error.												*/
   1.329 -/******************************************************************************/
   1.330 -int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
   1.331 -{
   1.332 -int index;		/* Index shortcut for index in joystick structure */
   1.333 -int i;			/* Generic Counter */
   1.334 -
   1.335 -/* allocate memory for system specific hardware data */
   1.336 -joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
   1.337 -if (joystick->hwdata == NULL)
   1.338 -	{
   1.339 -	SDL_OutOfMemory();
   1.340 -	return(-1);
   1.341 -	}
   1.342 -/* Reset Hardware Data */
   1.343 -SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
   1.344 -
   1.345 -/* ShortCut Pointer */
   1.346 -index = joystick->index;
   1.347 -/* Define offsets and scales for all axes */
   1.348 -joystick->hwdata->id = SYS_JoyData[index].id;
   1.349 -for ( i = 0; i < MAX_AXES; ++i )
   1.350 -	{
   1.351 -	if ( (i<2) || i < SYS_JoyData[index].axes )
   1.352 -		{
   1.353 -		joystick->hwdata->transaxes[i].offset = ((AXIS_MAX + AXIS_MIN)>>1) - SYS_JoyData[index].axes_med[i];
   1.354 -		//joystick->hwdata->transaxes[i].scale = (float)((AXIS_MAX - AXIS_MIN)/(SYS_JoyData[index].axes_max[i]-SYS_JoyData[index].axes_min[i]));
   1.355 -		joystick->hwdata->transaxes[i].scale1 = (float)abs((AXIS_MIN/SYS_JoyData[index].axes_min[i]));
   1.356 -		joystick->hwdata->transaxes[i].scale2 = (float)abs((AXIS_MAX/SYS_JoyData[index].axes_max[i]));
   1.357 -		}
   1.358 -	else
   1.359 -		{
   1.360 -		joystick->hwdata->transaxes[i].offset = 0;
   1.361 -		//joystick->hwdata->transaxes[i].scale = 1.0; /* Just in case */
   1.362 -		joystick->hwdata->transaxes[i].scale1 = 1.0; /* Just in case */
   1.363 -		joystick->hwdata->transaxes[i].scale2 = 1.0; /* Just in case */
   1.364 -		}
   1.365 -	}
   1.366 -
   1.367 -/* fill nbuttons, naxes, and nhats fields */
   1.368 -joystick->nbuttons = SYS_JoyData[index].buttons;
   1.369 -joystick->naxes = SYS_JoyData[index].axes;
   1.370 -/* joystick->nhats = SYS_JoyData[index].hats; */
   1.371 -joystick->nhats = 0; /* No support for hats at this time */
   1.372 -/* joystick->nballs = SYS_JoyData[index].balls; */
   1.373 -joystick->nballs = 0; /* No support for balls at this time */
   1.374 -return 0;
   1.375 -}
   1.376 -
   1.377 -
   1.378 -
   1.379 -/***************************************************************************/
   1.380 -/* Function to update the state of a joystick - called as a device poll.	*/
   1.381 -/* This function shouldn't update the joystick structure directly,			*/
   1.382 -/* but instead should call SDL_PrivateJoystick*() to deliver events			*/
   1.383 -/* and update joystick device state.													*/
   1.384 -/***************************************************************************/
   1.385 -void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
   1.386 -{
   1.387 -APIRET rc;									/* Generic OS/2 return code */
   1.388 -int index;									/* index shortcurt to joystick index */
   1.389 -int i;										/* Generic counter */
   1.390 -int normbut;								/* Number of buttons reported by joystick */
   1.391 -int corr;									/* Correction for button names */
   1.392 -Sint16 value, change;					/* Values used to update axis values */
   1.393 -struct _transaxes *transaxes;			/* Shortcut for Correction structure */
   1.394 -Uint32 pos[MAX_AXES];					/* Vector to inform the Axis status */
   1.395 -ULONG ulDataLen;							/* Size of data */
   1.396 -GAME_STATUS_STRUCT stGameStatus;		/* Joystick Status Structure */
   1.397 -
   1.398 -ulDataLen = sizeof(stGameStatus);
   1.399 -rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_STATUS,
   1.400 -	NULL, 0, NULL, &stGameStatus, ulDataLen, &ulDataLen);
   1.401 -if (rc != 0)
   1.402 -	{
   1.403 -	SDL_SetError("Could not read joystick status.");
   1.404 -	return; /* Could not read data */
   1.405 -	}
   1.406 -
   1.407 -/* Shortcut pointer */
   1.408 -index = joystick->index;
   1.409 -/* joystick motion events */
   1.410 -
   1.411 -if (SYS_JoyData[index].id == 0)
   1.412 -	{
   1.413 -	pos[0] = stGameStatus.curdata.A.x;
   1.414 -	pos[1] = stGameStatus.curdata.A.y;
   1.415 -	if (SYS_JoyData[index].axes >= 3)	pos[2] = stGameStatus.curdata.B.x;
   1.416 -	else pos[2]=0;
   1.417 -	if (SYS_JoyData[index].axes >= 4)	pos[3] = stGameStatus.curdata.B.y;
   1.418 -	else pos[3]=0;
   1.419 -	pos[4]=0;	/* OS/2 basic drivers do not support more than 4 axes joysticks */
   1.420 -	pos[5]=0;
   1.421 -	}
   1.422 -else if (SYS_JoyData[index].id == 1)
   1.423 -	{
   1.424 -	pos[0] = stGameStatus.curdata.B.x;
   1.425 -	pos[1] = stGameStatus.curdata.B.y;
   1.426 -	pos[2]=0;
   1.427 -	pos[3]=0;
   1.428 -	pos[4]=0;
   1.429 -	pos[5]=0;
   1.430 -	}
   1.431 -
   1.432 -/* Corrects the movements using the callibration */
   1.433 -transaxes = joystick->hwdata->transaxes;
   1.434 -for (i = 0; i < joystick->naxes; i++)
   1.435 -	{
   1.436 -	value = pos[i] + transaxes[i].offset;
   1.437 -	if (value<0)
   1.438 -		{
   1.439 -		value*=transaxes[i].scale1;
   1.440 -		if (value>0) value = AXIS_MIN;
   1.441 -		}
   1.442 -	else
   1.443 -		{
   1.444 -		value*=transaxes[i].scale2;
   1.445 -		if (value<0) value = AXIS_MAX;
   1.446 -		}
   1.447 -	change = (value - joystick->axes[i]);
   1.448 -	if ( (change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD) )
   1.449 -		{
   1.450 -		SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)value);
   1.451 -		}
   1.452 -	}
   1.453 -
   1.454 -/* joystick button A to D events */
   1.455 -if (SYS_JoyData[index].id == 1) corr = 2;
   1.456 -else corr = 0;
   1.457 -normbut=4;	/* Number of normal buttons */
   1.458 -if (joystick->nbuttons<normbut) normbut = joystick->nbuttons;
   1.459 -for ( i = corr; (i-corr) < normbut; ++i )
   1.460 -	{
   1.461 -	/*
   1.462 -		Button A: 1110 0000
   1.463 -		Button B: 1101 0000
   1.464 -		Button C: 1011 0000
   1.465 -		Button D: 0111 0000
   1.466 -	*/
   1.467 -	if ( (~stGameStatus.curdata.butMask)>>4 & JOY_BUTTON_FLAG(i) )
   1.468 -		{
   1.469 -		if ( ! joystick->buttons[i-corr] )
   1.470 -			{
   1.471 -			SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_PRESSED);
   1.472 -			}
   1.473 -		}
   1.474 -	else
   1.475 -		{
   1.476 -		if ( joystick->buttons[i-corr] )
   1.477 -			{
   1.478 -			SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_RELEASED);
   1.479 -			}
   1.480 -		}
   1.481 -	}
   1.482 -
   1.483 -/* Joystick button E to H buttons */
   1.484 -	/*
   1.485 -		Button E: Axis 2 X Left
   1.486 -		Button F: Axis 2 Y Up
   1.487 -		Button G: Axis 2 X Right
   1.488 -		Button H: Axis 2 Y Down
   1.489 -	*/
   1.490 -if (joystick->nbuttons>=5)
   1.491 -	{
   1.492 -	if (stGameStatus.curdata.B.x < SYS_JoyData[index].buttoncalc[0]) SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_PRESSED);
   1.493 -	else SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_RELEASED);
   1.494 -	}
   1.495 -if (joystick->nbuttons>=6)
   1.496 -	{
   1.497 -	if (stGameStatus.curdata.B.y < SYS_JoyData[index].buttoncalc[1]) SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_PRESSED);
   1.498 -	else SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_RELEASED);
   1.499 -	}
   1.500 -if (joystick->nbuttons>=7)
   1.501 -	{
   1.502 -	if (stGameStatus.curdata.B.x > SYS_JoyData[index].buttoncalc[2]) SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_PRESSED);
   1.503 -	else SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_RELEASED);
   1.504 -	}
   1.505 -if (joystick->nbuttons>=8)
   1.506 -	{
   1.507 -	if (stGameStatus.curdata.B.y > SYS_JoyData[index].buttoncalc[3]) SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_PRESSED);
   1.508 -	else SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_RELEASED);
   1.509 -	}
   1.510 -
   1.511 -/* joystick hat events */
   1.512 -/* Not Supported under OS/2 */
   1.513 -/* joystick ball events */
   1.514 -/* Not Supported under OS/2 */
   1.515 -}
   1.516 -
   1.517 -
   1.518 -
   1.519 -/******************************************/
   1.520 -/* Function to close a joystick after use */
   1.521 -/******************************************/
   1.522 -void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
   1.523 -{
   1.524 -if (joystick->hwdata != NULL)
   1.525 -	{
   1.526 -	/* free system specific hardware data */
   1.527 -	SDL_free(joystick->hwdata);
   1.528 -	}
   1.529 -}
   1.530 -
   1.531 -
   1.532 -
   1.533 -/********************************************************************/
   1.534 -/* Function to perform any system-specific joystick related cleanup */
   1.535 -/********************************************************************/
   1.536 -void SDL_SYS_JoystickQuit(void)
   1.537 -{
   1.538 -joyPortClose(&hJoyPort);
   1.539 -}
   1.540 -
   1.541 -
   1.542 -
   1.543 -/************************/
   1.544 -/************************/
   1.545 -/* OS/2 Implementations */
   1.546 -/************************/
   1.547 -/************************/
   1.548 -
   1.549 -
   1.550 -/*****************************************/
   1.551 -/* Open Joystick Port, if not opened yet */
   1.552 -/*****************************************/
   1.553 -APIRET joyPortOpen(HFILE * hGame)
   1.554 -{
   1.555 -APIRET		rc;				/* Generic Return Code */
   1.556 -ULONG			ulAction;		/* ? */
   1.557 -ULONG			ulVersion;		/* Version of joystick driver */
   1.558 -ULONG			ulDataLen;		/* Size of version data */
   1.559 -
   1.560 -/* Verifies if joyport is not already open... */
   1.561 -if (*hGame != NULL) return 0;
   1.562 -/* Open GAME$ for read */
   1.563 -rc = DosOpen((PSZ)GAMEPDDNAME, hGame, &ulAction, 0, FILE_READONLY,
   1.564 -	FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL);
   1.565 -if (rc != 0)
   1.566 -	{
   1.567 -	SDL_SetError("Could not open Joystick Port.");
   1.568 -	return -1;
   1.569 -	}
   1.570 -	
   1.571 -/* Get Joystick Driver Version... must be 2.0 or higher */
   1.572 -ulVersion = 0;
   1.573 -ulDataLen = sizeof(ulVersion);
   1.574 -rc = DosDevIOCtl( *hGame, IOCTL_CAT_USER, GAME_GET_VERSION,
   1.575 -	NULL, 0, NULL, &ulVersion, ulDataLen, &ulDataLen);
   1.576 -if (rc != 0)
   1.577 -	{
   1.578 -	joyPortClose(hGame);
   1.579 -	SDL_SetError("Could not get Joystick Driver version.");
   1.580 -	return -1;	
   1.581 -	}
   1.582 -if (ulVersion < GAME_VERSION)
   1.583 -	{
   1.584 -	joyPortClose(hGame);
   1.585 -	SDL_SetError("Driver too old. At least IBM driver version 2.0 required.");
   1.586 -	return -1;
   1.587 -	}
   1.588 -return 0;
   1.589 -}
   1.590 -
   1.591 -
   1.592 -
   1.593 -/****************************/
   1.594 -/* Close JoyPort, if opened */
   1.595 -/****************************/
   1.596 -void joyPortClose(HFILE * hGame)
   1.597 -{
   1.598 -if (*hGame != NULL) DosClose(*hGame);
   1.599 -*hGame = NULL;
   1.600 -}
   1.601 -
   1.602 -
   1.603 -
   1.604 -/***************************/
   1.605 -/* Get SDL Joystick EnvVar */
   1.606 -/***************************/
   1.607 -int joyGetEnv(struct _joycfg * joydata)
   1.608 -{
   1.609 -char *joyenv;				/* Pointer to tested character */
   1.610 -char tempnumber[5];		/* Temporary place to put numeric texts */
   1.611 -
   1.612 -joyenv = SDL_getenv("SDL_OS2_JOYSTICK");
   1.613 -if (joyenv == NULL) return 0;
   1.614 -/* Joystick Environment is defined! */
   1.615 -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
   1.616 -/* If the string name starts with '... get if fully */
   1.617 -if (*joyenv=='\'') joyenv+=joyGetData(++joyenv,joydata->name,'\'',sizeof(joydata->name));
   1.618 -/* If not, get it until the next space */
   1.619 -else if (*joyenv=='\"') joyenv+=joyGetData(++joyenv,joydata->name,'\"',sizeof(joydata->name));
   1.620 -else joyenv+=joyGetData(joyenv,joydata->name,' ',sizeof(joydata->name));
   1.621 -/* Now get the number of axes */
   1.622 -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
   1.623 -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
   1.624 -joydata->axes = atoi(tempnumber);
   1.625 -/* Now get the number of buttons */
   1.626 -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
   1.627 -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
   1.628 -joydata->buttons = atoi(tempnumber);
   1.629 -/* Now get the number of hats */
   1.630 -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
   1.631 -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
   1.632 -joydata->hats = atoi(tempnumber);
   1.633 -/* Now get the number of balls */
   1.634 -while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
   1.635 -joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
   1.636 -joydata->balls = atoi(tempnumber);
   1.637 -return 1;
   1.638 -}
   1.639 -
   1.640 -
   1.641 -
   1.642 -/************************************************************************/
   1.643 -/* Get a text from in the string starting in joyenv until it finds		*/
   1.644 -/* the stopchar or maxchars is reached. The result is placed in name.	*/
   1.645 -/************************************************************************/
   1.646 -int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars)
   1.647 -{
   1.648 -char *nameptr;			/* Pointer to the selected character */
   1.649 -int chcnt=0;			/* Count how many characters where copied */
   1.650 -
   1.651 -nameptr=name;
   1.652 -while (*joyenv!=stopchar && *joyenv!=0)
   1.653 -	{
   1.654 -	if (nameptr<(name+(maxchars-1)))
   1.655 -		{
   1.656 -		*nameptr = *joyenv; /* Only copy if smaller than maximum */
   1.657 -		nameptr++;
   1.658 -		}
   1.659 -	chcnt++;
   1.660 -	joyenv++;
   1.661 -	}
   1.662 -if (*joyenv==stopchar)
   1.663 -	{
   1.664 -	joyenv++; /* Jump stopchar */
   1.665 -	chcnt++;
   1.666 -	}
   1.667 -*nameptr = 0; /* Mark last byte */
   1.668 -return chcnt;
   1.669 -}
   1.670 -
   1.671 -#endif /* SDL_JOYSTICK_OS2 */
     2.1 --- a/src/joystick/os2/joyos2.h	Tue Nov 17 04:59:13 2009 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,177 +0,0 @@
     2.4 -/*****************************************************************************/
     2.5 -/*                                                                           */
     2.6 -/* COPYRIGHT    Copyright (C) 1995 IBM Corporation                           */
     2.7 -/*                                                                           */
     2.8 -/*    The following IBM OS/2 source code is provided to you solely for       */
     2.9 -/*    the purpose of assisting you in your development of OS/2 device        */
    2.10 -/*    drivers. You may use this code in accordance with the IBM License      */
    2.11 -/*    Agreement provided in the IBM Device Driver Source Kit for OS/2. This  */
    2.12 -/*    Copyright statement may not be removed.                                */
    2.13 -/*                                                                           */
    2.14 -/*****************************************************************************/
    2.15 -#ifndef JOYOS2_H
    2.16 -#define JOYOS2_H
    2.17 -
    2.18 -/****** GAMEPORT.SYS joystick definitions, start *****************************/
    2.19 -#define GAME_VERSION    0x20           /* 2.0 First IBM version */
    2.20 -#define GAMEPDDNAME     "GAME$   "
    2.21 -#define IOCTL_CAT_USER	0x80
    2.22 -#define GAME_PORT_GET	0x20		/* read GAMEPORT.SYS values */
    2.23 -#define GAME_PORT_RESET 0x60		/* reset joystick mask with given value */
    2.24 -
    2.25 -#pragma pack(1)				/* pack structure size is 1 byte */
    2.26 -typedef struct {			/* GAMEPORT.SYS structure */
    2.27 -	USHORT	usJs_AxCnt;		/* Joystick_A X position */
    2.28 -	USHORT	usJs_AyCnt;		/* Joystick_A Y position */
    2.29 -	USHORT	usJs_BxCnt;		/* Joystick_B X position */
    2.30 -	USHORT	usJs_ByCnt;		/* Joystick_B Y position */
    2.31 -	USHORT	usJs_ButtonA1Cnt;	/* button A1 press count */
    2.32 -	USHORT	usJs_ButtonA2Cnt;	/* button A2 press count */
    2.33 -	USHORT	usJs_ButtonB1Cnt;	/* button B1 press count */
    2.34 -	USHORT	usJs_ButtonB2Cnt;	/* button B2 press count */
    2.35 -	UCHAR	ucJs_JoyStickMask;	/* mask of connected joystick pots */
    2.36 -	UCHAR	ucJs_ButtonStatus;	/* bits of switches down */
    2.37 -	ULONG	ulJs_Ticks;		/* joystick clock ticks */
    2.38 -} GAME_PORT_STRUCT;
    2.39 -#pragma pack()				/*reset to normal pack size */
    2.40 -/****** GAMEPORT.SYS joystick definitions, end *******************************/
    2.41 -
    2.42 -
    2.43 -/****************************************************************************/
    2.44 -#define GAME_GET_VERSION                0x01
    2.45 -#define GAME_GET_PARMS                  0x02
    2.46 -#define GAME_SET_PARMS                  0x03
    2.47 -#define GAME_GET_CALIB                  0x04
    2.48 -#define GAME_SET_CALIB                  0x05
    2.49 -#define GAME_GET_DIGSET                 0x06
    2.50 -#define GAME_SET_DIGSET                 0x07
    2.51 -#define GAME_GET_STATUS                 0x10
    2.52 -#define GAME_GET_STATUS_BUTWAIT         0x11
    2.53 -#define GAME_GET_STATUS_SAMPWAIT        0x12
    2.54 -/****************************************************************************/
    2.55 -
    2.56 -/****************************************************************************/
    2.57 -// bit masks for each axis
    2.58 -#define JOY_AX_BIT      0x01
    2.59 -#define JOY_AY_BIT      0x02
    2.60 -#define JOY_A_BITS      (JOY_AX_BIT|JOY_AY_BIT)
    2.61 -#define JOY_BX_BIT      0x04
    2.62 -#define JOY_BY_BIT      0x08
    2.63 -#define JOY_B_BITS      (JOY_BX_BIT|JOY_BY_BIT)
    2.64 -#define JOY_ALLPOS_BITS (JOY_A_BITS|JOY_B_BITS)
    2.65 -
    2.66 -// bit masks for each button
    2.67 -#define JOY_BUT1_BIT    0x10
    2.68 -#define JOY_BUT2_BIT    0x20
    2.69 -#define JOY_BUT3_BIT    0x40
    2.70 -#define JOY_BUT4_BIT    0x80
    2.71 -#define JOY_ALL_BUTS    (JOY_BUT1_BIT|JOY_BUT2_BIT|JOY_BUT3_BIT|JOY_BUT4_BIT)
    2.72 -/****************************************************************************/
    2.73 -
    2.74 -/****************************************************************************/
    2.75 -// 1-D position struct used for each axis
    2.76 -typedef SHORT   GAME_POS;       /* some data formats require signed values */
    2.77 -
    2.78 -// simple 2-D position for each joystick
    2.79 -typedef struct
    2.80 -{
    2.81 -        GAME_POS                x;
    2.82 -        GAME_POS                y;
    2.83 -}
    2.84 -GAME_2DPOS_STRUCT;
    2.85 -
    2.86 -// struct defining the instantaneous state of both sticks and all buttons
    2.87 -typedef struct
    2.88 -{
    2.89 -        GAME_2DPOS_STRUCT       A;
    2.90 -        GAME_2DPOS_STRUCT       B;
    2.91 -        USHORT                  butMask;
    2.92 -}
    2.93 -GAME_DATA_STRUCT;
    2.94 -
    2.95 -// struct to be used for calibration and digital response on each axis
    2.96 -typedef struct
    2.97 -{
    2.98 -        GAME_POS                lower;
    2.99 -        GAME_POS                centre;
   2.100 -        GAME_POS                upper;
   2.101 -}
   2.102 -GAME_3POS_STRUCT;
   2.103 -/****************************************************************************/
   2.104 -
   2.105 -/****************************************************************************/
   2.106 -// status struct returned to OS/2 applications:
   2.107 -// current data for all sticks as well as button counts since last read
   2.108 -typedef struct
   2.109 -{
   2.110 -        GAME_DATA_STRUCT        curdata;
   2.111 -        USHORT                  b1cnt;
   2.112 -        USHORT                  b2cnt;
   2.113 -        USHORT                  b3cnt;
   2.114 -        USHORT                  b4cnt;
   2.115 -}
   2.116 -GAME_STATUS_STRUCT;
   2.117 -/****************************************************************************/
   2.118 -
   2.119 -/****************************************************************************/
   2.120 -/* in use bitmasks originating in 0.2b */
   2.121 -#define GAME_USE_BOTH_OLDMASK   0x01    /* for backward compat with bool */
   2.122 -#define GAME_USE_X_NEWMASK      0x02
   2.123 -#define GAME_USE_Y_NEWMASK      0x04
   2.124 -#define GAME_USE_X_EITHERMASK   (GAME_USE_X_NEWMASK|GAME_USE_BOTH_OLDMASK)
   2.125 -#define GAME_USE_Y_EITHERMASK   (GAME_USE_Y_NEWMASK|GAME_USE_BOTH_OLDMASK)
   2.126 -#define GAME_USE_BOTH_NEWMASK   (GAME_USE_X_NEWMASK|GAME_USE_Y_NEWMASK)
   2.127 -
   2.128 -/* only timed sampling implemented in version 1.0 */
   2.129 -#define GAME_MODE_TIMED         1       /* timed sampling */
   2.130 -#define GAME_MODE_REQUEST       2       /* request driven sampling */
   2.131 -
   2.132 -/* only raw implemented in version 1.0 */
   2.133 -#define GAME_DATA_FORMAT_RAW    1       /* [l,c,r]   */
   2.134 -#define GAME_DATA_FORMAT_SIGNED 2       /* [-l,0,+r] */
   2.135 -#define GAME_DATA_FORMAT_BINARY 3       /* {-1,0,+1} */
   2.136 -#define GAME_DATA_FORMAT_SCALED 4       /* [-10,+10] */
   2.137 -
   2.138 -// parameters defining the operation of the driver
   2.139 -typedef struct
   2.140 -{
   2.141 -        USHORT                  useA;           /* new bitmasks: see above */
   2.142 -        USHORT                  useB;
   2.143 -        USHORT                  mode;           /* see consts above */
   2.144 -        USHORT                  format;         /* see consts above */
   2.145 -        USHORT                  sampDiv;        /* samp freq = 32 / n */
   2.146 -        USHORT                  scale;          /* scaling factor */
   2.147 -        USHORT                  res1;           /* must be 0 */
   2.148 -        USHORT                  res2;           /* must be 0 */
   2.149 -}
   2.150 -GAME_PARM_STRUCT;
   2.151 -/****************************************************************************/
   2.152 -
   2.153 -/****************************************************************************/
   2.154 -// calibration values for each axis:
   2.155 -//      - upper limit on value to be considered in lower range
   2.156 -//      - centre value
   2.157 -//      - lower limit on value to be considered in upper range
   2.158 -typedef struct
   2.159 -{
   2.160 -        GAME_3POS_STRUCT        Ax;
   2.161 -        GAME_3POS_STRUCT        Ay;
   2.162 -        GAME_3POS_STRUCT        Bx;
   2.163 -        GAME_3POS_STRUCT        By;
   2.164 -}
   2.165 -GAME_CALIB_STRUCT;
   2.166 -/****************************************************************************/
   2.167 -
   2.168 -/****************************************************************************/
   2.169 -// struct defining the digital response values for all axes
   2.170 -typedef struct
   2.171 -{
   2.172 -        GAME_3POS_STRUCT        Ax;
   2.173 -        GAME_3POS_STRUCT        Ay;
   2.174 -        GAME_3POS_STRUCT        Bx;
   2.175 -        GAME_3POS_STRUCT        By;
   2.176 -}
   2.177 -GAME_DIGSET_STRUCT;
   2.178 -/****************************************************************************/
   2.179 -
   2.180 -#endif