annotate src/joystick/os2/SDL_sysjoystick.c @ 1761:39715a34a0be

Fixed execv warning when libtool creates wrapper executables
author Sam Lantinga <slouken@libsdl.org>
date Wed, 03 May 2006 16:35:29 +0000
parents 92947e3a18db
children 782fd950bd46 c121d94672cb a1b03ba2fcd0
rev   line source
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
1 /*
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
4
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
6 modify it under the terms of the GNU Lesser General Public
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
9
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
13 Lesser General Public License for more details.
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
14
1312
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
15 You should have received a copy of the GNU Lesser General Public
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
16 License along with this library; if not, write to the Free Software
c9b51268668f Updated copyright information and removed rcs id lines (problematic in branch merges)
Sam Lantinga <slouken@libsdl.org>
parents: 1190
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
18
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
19 Sam Lantinga
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
20 slouken@libsdl.org
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
21 */
1402
d910939febfa Use consistent identifiers for the various platforms we support.
Sam Lantinga <slouken@libsdl.org>
parents: 1379
diff changeset
22 #include "SDL_config.h"
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
23
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1442
diff changeset
24 #ifdef SDL_JOYSTICK_OS2
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1442
diff changeset
25
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
26 /* OS/2 Joystick driver, contributed by Daniel Caetano */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
27
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
28 #include <mem.h>
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
29
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
30 #define INCL_DOSDEVICES
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
31 #define INCL_DOSDEVIOCTL
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
32 #define INCL_DOSMEMMGR
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
33 #include <os2.h>
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
34 #include "joyos2.h"
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
35
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
36 #include "SDL_joystick.h"
1442
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
37 #include "SDL_events.h"
1361
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
38 #include "../SDL_sysjoystick.h"
19418e4422cb New configure-based build system. Still work in progress, but much improved
Sam Lantinga <slouken@libsdl.org>
parents: 1358
diff changeset
39 #include "../SDL_joystick_c.h"
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
40
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
41 HFILE hJoyPort = NULL; /* Joystick GAME$ Port Address */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
42 #define MAX_JOYSTICKS 2 /* Maximum of two joysticks */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
43 #define MAX_AXES 4 /* each joystick can have up to 4 axes */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
44 #define MAX_BUTTONS 8 /* 8 buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
45 #define MAX_HATS 0 /* 0 hats - OS/2 doesn't support it */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
46 #define MAX_BALLS 0 /* and 0 balls - OS/2 doesn't support it */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
47 #define AXIS_MIN -32768 /* minimum value for axes coordinate */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
48 #define AXIS_MAX 32767 /* maximum value for axes coordinate */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
49 #define MAX_JOYNAME 128 /* Joystick name may have 128 characters */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
50 /* limit axes to 256 possible positions to filter out noise */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
51 #define JOY_AXIS_THRESHOLD (((AXIS_MAX)-(AXIS_MIN))/256)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
52 /* Calc Button Flag for buttons A to D */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
53 #define JOY_BUTTON_FLAG(n) (1<<n)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
54
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
55 /* Joystick data... hold information about detected devices */
1442
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
56 typedef struct SYS_JoyData_s
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
57 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
58 Sint8 id; // Device ID
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
59 char szDeviceName[MAX_JOYNAME]; // Device Name
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
60 char axes; // Number of axes
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
61 char buttons; // Number of buttons
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
62 char hats; // Number of buttons
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
63 char balls; // Number of buttons
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
64 int axes_min[MAX_AXES]; // minimum callibration value for axes
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
65 int axes_med[MAX_AXES]; // medium callibration value for axes
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
66 int axes_max[MAX_AXES]; // maximum callibration value for axes
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
67 int buttoncalc[4]; // Used for buttons 5, 6, 7 and 8.
1442
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
68 } SYS_JoyData_t, *SYS_JoyData_p;
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
69
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
70 SYS_JoyData_t SYS_JoyData[MAX_JOYSTICKS];
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
71
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
72
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
73 /* Structure used to convert data from OS/2 driver format to SDL format */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
74 struct joystick_hwdata
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
75 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
76 Sint8 id;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
77 struct _transaxes
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
78 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
79 int offset; /* Center Offset */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
80 float scale1; /* Center to left/up Scale */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
81 float scale2; /* Center to right/down Scale */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
82 } transaxes[MAX_AXES];
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
83 };
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
84
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
85 /* Structure used to get values from Joystick Environment Variable */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
86 struct _joycfg
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
87 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
88 char name[MAX_JOYNAME];
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
89 unsigned int axes;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
90 unsigned int buttons;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
91 unsigned int hats;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
92 unsigned int balls;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
93 };
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
94
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
95 /* OS/2 Implementation Function Prototypes */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
96 APIRET joyPortOpen(HFILE * hGame);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
97 void joyPortClose(HFILE * hGame);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
98 int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
99 int joyGetEnv(struct _joycfg * joydata);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
100
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
101
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
102
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
103 /************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
104 /* Function to scan the system for joysticks. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
105 /* This function should set SDL_numjoysticks to the number of available */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
106 /* joysticks. Joystick 0 should be the system default joystick. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
107 /* It should return 0, or -1 on an unrecoverable fatal error. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
108 /************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
109 int SDL_SYS_JoystickInit(void)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
110 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
111 APIRET rc; /* Generic OS/2 return code */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
112 GAME_PORT_STRUCT stJoyStatus; /* Joystick Status Structure */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
113 GAME_PARM_STRUCT stGameParms; /* Joystick Parameter Structure */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
114 GAME_CALIB_STRUCT stGameCalib; /* Calibration Struct */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
115 ULONG ulDataLen; /* Size of data */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
116 ULONG ulLastTick; /* Tick Counter for timing operations */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
117 Uint8 maxdevs; /* Maximum number of devices */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
118 Uint8 numdevs; /* Number of present devices */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
119 Uint8 maxbut; /* Maximum number of buttons... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
120 Uint8 i; /* Temporary Count Vars */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
121 Uint8 ucNewJoystickMask; /* Mask for Joystick Detection */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
122 struct _joycfg joycfg; /* Joy Configuration from envvar */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
123
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
124
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
125 /* Get Max Number of Devices */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
126 rc = joyPortOpen(&hJoyPort); /* Open GAME$ port */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
127 if (rc != 0) return 0; /* Cannot open... report no joystick */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
128 ulDataLen = sizeof(stGameParms);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
129 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_PARMS,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
130 NULL, 0, NULL, &stGameParms, ulDataLen, &ulDataLen); /* Ask device info */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
131 if (rc != 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
132 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
133 joyPortClose(&hJoyPort);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
134 SDL_SetError("Could not read joystick port.");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
135 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
136 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
137 if (stGameParms.useA != 0) maxdevs++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
138 if (stGameParms.useB != 0) maxdevs++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
139 if ( maxdevs > MAX_JOYSTICKS ) maxdevs = MAX_JOYSTICKS;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
140
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
141 /* Defines min/max axes values (callibration) */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
142 ulDataLen = sizeof(stGameCalib);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
143 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_CALIB,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
144 NULL, 0, NULL, &stGameCalib, ulDataLen, &ulDataLen);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
145 if (rc != 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
146 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
147 joyPortClose(&hJoyPort);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
148 SDL_SetError("Could not read callibration data.");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
149 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
150 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
151
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
152 /* Determine how many joysticks are active */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
153 numdevs = 0; /* Points no device */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
154 ucNewJoystickMask = 0x0F; /* read all 4 joystick axis */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
155 ulDataLen = sizeof(ucNewJoystickMask);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
156 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_RESET,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
157 &ucNewJoystickMask, ulDataLen, &ulDataLen, NULL, 0, NULL);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
158 if (rc == 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
159 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
160 ulDataLen = sizeof(stJoyStatus);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
161 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
162 NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
163 if (rc != 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
164 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
165 joyPortClose(&hJoyPort);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
166 SDL_SetError("Could not call joystick port.");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
167 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
168 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
169 ulLastTick = stJoyStatus.ulJs_Ticks;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
170 while (stJoyStatus.ulJs_Ticks == ulLastTick)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
171 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
172 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_PORT_GET,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
173 NULL, 0, NULL, &stJoyStatus, ulDataLen, &ulDataLen);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
174 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
175 if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0) numdevs++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
176 if (((stJoyStatus.ucJs_JoyStickMask >> 2) & 0x03) > 0) numdevs++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
177 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
178
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
179 if (numdevs>maxdevs) numdevs=maxdevs;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
180
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
181 /* If *any* joystick was detected... Let's configure SDL for them */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
182 if (numdevs > 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
183 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
184 /* Verify if it is a "user defined" joystick */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
185 if (joyGetEnv(&joycfg))
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
186 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
187 GAME_3POS_STRUCT * axis[4];
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
188 axis[0] = &stGameCalib.Ax;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
189 axis[1] = &stGameCalib.Ay;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
190 axis[2] = &stGameCalib.Bx;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
191 axis[3] = &stGameCalib.By;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
192 /* Say it has one device only (user defined is always one device only) */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
193 numdevs = 1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
194 /* Define Device 0 as... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
195 SYS_JoyData[0].id=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
196 /* Define Number of Axes... up to 4 */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
197 if (joycfg.axes>MAX_AXES) joycfg.axes = MAX_AXES;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
198 SYS_JoyData[0].axes = joycfg.axes;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
199 /* Define number of buttons... 8 if 2 axes, 6 if 3 axes and 4 if 4 axes */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
200 maxbut = MAX_BUTTONS;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
201 if (joycfg.axes>2) maxbut-=((joycfg.axes-2)<<1); /* MAX_BUTTONS - 2*(axes-2) */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
202 if (joycfg.buttons > maxbut) joycfg.buttons = maxbut;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
203 SYS_JoyData[0].buttons = joycfg.buttons;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
204 /* Define number of hats */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
205 if (joycfg.hats > MAX_HATS) joycfg.hats = MAX_HATS;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
206 SYS_JoyData[0].hats = joycfg.hats;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
207 /* Define number of balls */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
208 if (joycfg.balls > MAX_BALLS) joycfg.balls = MAX_BALLS;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
209 SYS_JoyData[0].balls = joycfg.balls;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
210 /* Initialize Axes Callibration Values */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
211 for (i=0; i<joycfg.axes; i++)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
212 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
213 SYS_JoyData[0].axes_min[i] = axis[i]->lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
214 SYS_JoyData[0].axes_med[i] = axis[i]->centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
215 SYS_JoyData[0].axes_max[i] = axis[i]->upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
216 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
217 /* Initialize Buttons 5 to 8 structures */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
218 if (joycfg.buttons>=5) SYS_JoyData[0].buttoncalc[0]=((axis[2]->lower+axis[3]->centre)>>1);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
219 if (joycfg.buttons>=6) SYS_JoyData[0].buttoncalc[1]=((axis[3]->lower+axis[3]->centre)>>1);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
220 if (joycfg.buttons>=7) SYS_JoyData[0].buttoncalc[2]=((axis[2]->upper+axis[3]->centre)>>1);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
221 if (joycfg.buttons>=8) SYS_JoyData[0].buttoncalc[3]=((axis[3]->upper+axis[3]->centre)>>1);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
222 /* Intialize Joystick Name */
1379
c0a74f199ecf Use only safe string functions
Sam Lantinga <slouken@libsdl.org>
parents: 1375
diff changeset
223 SDL_strlcpy (SYS_JoyData[0].szDeviceName,joycfg.name, SDL_arraysize(SYS_JoyData[0].szDeviceName));
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
224 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
225 /* Default Init ... autoconfig */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
226 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
227 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
228 /* if two devices were detected... configure as Joy1 4 axis and Joy2 2 axis */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
229 if (numdevs==2)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
230 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
231 /* Define Device 0 as 4 axes, 4 buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
232 SYS_JoyData[0].id=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
233 SYS_JoyData[0].axes = 4;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
234 SYS_JoyData[0].buttons = 4;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
235 SYS_JoyData[0].hats = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
236 SYS_JoyData[0].balls = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
237 SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
238 SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
239 SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
240 SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
241 SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
242 SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
243 SYS_JoyData[0].axes_min[2] = stGameCalib.Bx.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
244 SYS_JoyData[0].axes_med[2] = stGameCalib.Bx.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
245 SYS_JoyData[0].axes_max[2] = stGameCalib.Bx.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
246 SYS_JoyData[0].axes_min[3] = stGameCalib.By.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
247 SYS_JoyData[0].axes_med[3] = stGameCalib.By.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
248 SYS_JoyData[0].axes_max[3] = stGameCalib.By.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
249 /* Define Device 1 as 2 axes, 2 buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
250 SYS_JoyData[1].id=1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
251 SYS_JoyData[1].axes = 2;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
252 SYS_JoyData[1].buttons = 2;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
253 SYS_JoyData[1].hats = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
254 SYS_JoyData[1].balls = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
255 SYS_JoyData[1].axes_min[0] = stGameCalib.Bx.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
256 SYS_JoyData[1].axes_med[0] = stGameCalib.Bx.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
257 SYS_JoyData[1].axes_max[0] = stGameCalib.Bx.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
258 SYS_JoyData[1].axes_min[1] = stGameCalib.By.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
259 SYS_JoyData[1].axes_med[1] = stGameCalib.By.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
260 SYS_JoyData[1].axes_max[1] = stGameCalib.By.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
261 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
262 /* One joystick only? */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
263 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
264 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
265 /* If it is joystick A... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
266 if ((stJoyStatus.ucJs_JoyStickMask & 0x03) > 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
267 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
268 /* Define Device 0 as 2 axes, 4 buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
269 SYS_JoyData[0].id=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
270 SYS_JoyData[0].axes = 2;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
271 SYS_JoyData[0].buttons = 4;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
272 SYS_JoyData[0].hats = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
273 SYS_JoyData[0].balls = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
274 SYS_JoyData[0].axes_min[0] = stGameCalib.Ax.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
275 SYS_JoyData[0].axes_med[0] = stGameCalib.Ax.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
276 SYS_JoyData[0].axes_max[0] = stGameCalib.Ax.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
277 SYS_JoyData[0].axes_min[1] = stGameCalib.Ay.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
278 SYS_JoyData[0].axes_med[1] = stGameCalib.Ay.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
279 SYS_JoyData[0].axes_max[1] = stGameCalib.Ay.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
280 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
281 /* If not, it is joystick B */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
282 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
283 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
284 /* Define Device 1 as 2 axes, 2 buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
285 SYS_JoyData[0].id=1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
286 SYS_JoyData[0].axes = 2;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
287 SYS_JoyData[0].buttons = 2;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
288 SYS_JoyData[0].hats = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
289 SYS_JoyData[0].balls = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
290 SYS_JoyData[0].axes_min[0] = stGameCalib.Bx.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
291 SYS_JoyData[0].axes_med[0] = stGameCalib.Bx.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
292 SYS_JoyData[0].axes_max[0] = stGameCalib.Bx.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
293 SYS_JoyData[0].axes_min[1] = stGameCalib.By.lower;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
294 SYS_JoyData[0].axes_med[1] = stGameCalib.By.centre;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
295 SYS_JoyData[0].axes_max[1] = stGameCalib.By.upper;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
296 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
297 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
298 /* Hack to define Joystick Port Names */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
299 if ( numdevs > maxdevs ) numdevs = maxdevs;
1442
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
300 for (i=0; i<numdevs; i++)
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
301 SDL_snprintf (SYS_JoyData[i].szDeviceName, SDL_arraysize(SYS_JoyData[i].szDeviceName), "Default Joystick %c", 'A'+SYS_JoyData[i].id);
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
302
e3242177fe4a Updated OS/2 build, yay!
Sam Lantinga <slouken@libsdl.org>
parents: 1402
diff changeset
303 }
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
304 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
305 /* Return the number of devices found */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
306 return(numdevs);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
307 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
308
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
309
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
310 /***********************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
311 /* Function to get the device-dependent name of a joystick */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
312 /***********************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
313 const char *SDL_SYS_JoystickName(int index)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
314 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
315 /* No need to verify if device exists, already done in upper layer */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
316 return(SYS_JoyData[index].szDeviceName);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
317 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
318
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
319
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
320
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
321 /******************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
322 /* Function to open a joystick for use. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
323 /* The joystick to open is specified by the index field of the joystick. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
324 /* This should fill the nbuttons and naxes fields of the joystick structure. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
325 /* It returns 0, or -1 if there is an error. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
326 /******************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
327 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
328 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
329 int index; /* Index shortcut for index in joystick structure */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
330 int i; /* Generic Counter */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
331
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
332 /* allocate memory for system specific hardware data */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
333 joystick->hwdata = (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
334 if (joystick->hwdata == NULL)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
335 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
336 SDL_OutOfMemory();
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
337 return(-1);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
338 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
339 /* Reset Hardware Data */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
340 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
341
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
342 /* ShortCut Pointer */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
343 index = joystick->index;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
344 /* Define offsets and scales for all axes */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
345 joystick->hwdata->id = SYS_JoyData[index].id;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
346 for ( i = 0; i < MAX_AXES; ++i )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
347 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
348 if ( (i<2) || i < SYS_JoyData[index].axes )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
349 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
350 joystick->hwdata->transaxes[i].offset = ((AXIS_MAX + AXIS_MIN)>>1) - SYS_JoyData[index].axes_med[i];
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
351 //joystick->hwdata->transaxes[i].scale = (float)((AXIS_MAX - AXIS_MIN)/(SYS_JoyData[index].axes_max[i]-SYS_JoyData[index].axes_min[i]));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
352 joystick->hwdata->transaxes[i].scale1 = (float)abs((AXIS_MIN/SYS_JoyData[index].axes_min[i]));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
353 joystick->hwdata->transaxes[i].scale2 = (float)abs((AXIS_MAX/SYS_JoyData[index].axes_max[i]));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
354 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
355 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
356 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
357 joystick->hwdata->transaxes[i].offset = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
358 //joystick->hwdata->transaxes[i].scale = 1.0; /* Just in case */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
359 joystick->hwdata->transaxes[i].scale1 = 1.0; /* Just in case */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
360 joystick->hwdata->transaxes[i].scale2 = 1.0; /* Just in case */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
361 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
362 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
363
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
364 /* fill nbuttons, naxes, and nhats fields */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
365 joystick->nbuttons = SYS_JoyData[index].buttons;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
366 joystick->naxes = SYS_JoyData[index].axes;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
367 /* joystick->nhats = SYS_JoyData[index].hats; */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
368 joystick->nhats = 0; /* No support for hats at this time */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
369 /* joystick->nballs = SYS_JoyData[index].balls; */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
370 joystick->nballs = 0; /* No support for balls at this time */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
371 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
372 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
373
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
374
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
375
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
376 /***************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
377 /* Function to update the state of a joystick - called as a device poll. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
378 /* This function shouldn't update the joystick structure directly, */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
379 /* but instead should call SDL_PrivateJoystick*() to deliver events */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
380 /* and update joystick device state. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
381 /***************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
382 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
383 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
384 APIRET rc; /* Generic OS/2 return code */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
385 int index; /* index shortcurt to joystick index */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
386 int i; /* Generic counter */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
387 int normbut; /* Number of buttons reported by joystick */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
388 int corr; /* Correction for button names */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
389 Sint16 value, change; /* Values used to update axis values */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
390 struct _transaxes *transaxes; /* Shortcut for Correction structure */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
391 Uint32 pos[MAX_AXES]; /* Vector to inform the Axis status */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
392 ULONG ulDataLen; /* Size of data */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
393 GAME_STATUS_STRUCT stGameStatus; /* Joystick Status Structure */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
394
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
395 ulDataLen = sizeof(stGameStatus);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
396 rc = DosDevIOCtl(hJoyPort, IOCTL_CAT_USER, GAME_GET_STATUS,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
397 NULL, 0, NULL, &stGameStatus, ulDataLen, &ulDataLen);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
398 if (rc != 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
399 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
400 SDL_SetError("Could not read joystick status.");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
401 return; /* Could not read data */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
402 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
403
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
404 /* Shortcut pointer */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
405 index = joystick->index;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
406 /* joystick motion events */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
407
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
408 if (SYS_JoyData[index].id == 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
409 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
410 pos[0] = stGameStatus.curdata.A.x;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
411 pos[1] = stGameStatus.curdata.A.y;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
412 if (SYS_JoyData[index].axes >= 3) pos[2] = stGameStatus.curdata.B.x;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
413 else pos[2]=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
414 if (SYS_JoyData[index].axes >= 4) pos[3] = stGameStatus.curdata.B.y;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
415 else pos[3]=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
416 pos[4]=0; /* OS/2 basic drivers do not support more than 4 axes joysticks */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
417 pos[5]=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
418 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
419 else if (SYS_JoyData[index].id == 1)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
420 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
421 pos[0] = stGameStatus.curdata.B.x;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
422 pos[1] = stGameStatus.curdata.B.y;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
423 pos[2]=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
424 pos[3]=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
425 pos[4]=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
426 pos[5]=0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
427 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
428
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
429 /* Corrects the movements using the callibration */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
430 transaxes = joystick->hwdata->transaxes;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
431 for (i = 0; i < joystick->naxes; i++)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
432 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
433 value = pos[i] + transaxes[i].offset;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
434 if (value<0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
435 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
436 value*=transaxes[i].scale1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
437 if (value>0) value = AXIS_MIN;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
438 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
439 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
440 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
441 value*=transaxes[i].scale2;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
442 if (value<0) value = AXIS_MAX;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
443 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
444 change = (value - joystick->axes[i]);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
445 if ( (change < -JOY_AXIS_THRESHOLD) || (change > JOY_AXIS_THRESHOLD) )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
446 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
447 SDL_PrivateJoystickAxis(joystick, (Uint8)i, (Sint16)value);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
448 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
449 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
450
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
451 /* joystick button A to D events */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
452 if (SYS_JoyData[index].id == 1) corr = 2;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
453 else corr = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
454 normbut=4; /* Number of normal buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
455 if (joystick->nbuttons<normbut) normbut = joystick->nbuttons;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
456 for ( i = corr; (i-corr) < normbut; ++i )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
457 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
458 /*
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
459 Button A: 1110 0000
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
460 Button B: 1101 0000
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
461 Button C: 1011 0000
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
462 Button D: 0111 0000
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
463 */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
464 if ( (~stGameStatus.curdata.butMask)>>4 & JOY_BUTTON_FLAG(i) )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
465 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
466 if ( ! joystick->buttons[i-corr] )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
467 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
468 SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_PRESSED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
469 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
470 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
471 else
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
472 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
473 if ( joystick->buttons[i-corr] )
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
474 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
475 SDL_PrivateJoystickButton(joystick, (Uint8)(i-corr), SDL_RELEASED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
476 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
477 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
478 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
479
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
480 /* Joystick button E to H buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
481 /*
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
482 Button E: Axis 2 X Left
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
483 Button F: Axis 2 Y Up
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
484 Button G: Axis 2 X Right
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
485 Button H: Axis 2 Y Down
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
486 */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
487 if (joystick->nbuttons>=5)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
488 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
489 if (stGameStatus.curdata.B.x < SYS_JoyData[index].buttoncalc[0]) SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_PRESSED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
490 else SDL_PrivateJoystickButton(joystick, (Uint8)4, SDL_RELEASED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
491 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
492 if (joystick->nbuttons>=6)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
493 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
494 if (stGameStatus.curdata.B.y < SYS_JoyData[index].buttoncalc[1]) SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_PRESSED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
495 else SDL_PrivateJoystickButton(joystick, (Uint8)5, SDL_RELEASED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
496 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
497 if (joystick->nbuttons>=7)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
498 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
499 if (stGameStatus.curdata.B.x > SYS_JoyData[index].buttoncalc[2]) SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_PRESSED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
500 else SDL_PrivateJoystickButton(joystick, (Uint8)6, SDL_RELEASED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
501 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
502 if (joystick->nbuttons>=8)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
503 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
504 if (stGameStatus.curdata.B.y > SYS_JoyData[index].buttoncalc[3]) SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_PRESSED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
505 else SDL_PrivateJoystickButton(joystick, (Uint8)7, SDL_RELEASED);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
506 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
507
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
508 /* joystick hat events */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
509 /* Not Supported under OS/2 */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
510 /* joystick ball events */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
511 /* Not Supported under OS/2 */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
512 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
513
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
514
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
515
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
516 /******************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
517 /* Function to close a joystick after use */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
518 /******************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
519 void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
520 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
521 if (joystick->hwdata != NULL)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
522 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
523 /* free system specific hardware data */
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
524 SDL_free(joystick->hwdata);
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
525 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
526 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
527
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
528
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
529
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
530 /********************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
531 /* Function to perform any system-specific joystick related cleanup */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
532 /********************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
533 void SDL_SYS_JoystickQuit(void)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
534 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
535 joyPortClose(&hJoyPort);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
536 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
537
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
538
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
539
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
540 /************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
541 /************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
542 /* OS/2 Implementations */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
543 /************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
544 /************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
545
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
546
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
547 /*****************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
548 /* Open Joystick Port, if not opened yet */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
549 /*****************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
550 APIRET joyPortOpen(HFILE * hGame)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
551 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
552 APIRET rc; /* Generic Return Code */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
553 ULONG ulAction; /* ? */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
554 ULONG ulVersion; /* Version of joystick driver */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
555 ULONG ulDataLen; /* Size of version data */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
556
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
557 /* Verifies if joyport is not already open... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
558 if (*hGame != NULL) return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
559 /* Open GAME$ for read */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
560 rc = DosOpen((PSZ)GAMEPDDNAME, hGame, &ulAction, 0, FILE_READONLY,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
561 FILE_OPEN, OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, NULL);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
562 if (rc != 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
563 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
564 SDL_SetError("Could not open Joystick Port.");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
565 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
566 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
567
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
568 /* Get Joystick Driver Version... must be 2.0 or higher */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
569 ulVersion = 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
570 ulDataLen = sizeof(ulVersion);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
571 rc = DosDevIOCtl( *hGame, IOCTL_CAT_USER, GAME_GET_VERSION,
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
572 NULL, 0, NULL, &ulVersion, ulDataLen, &ulDataLen);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
573 if (rc != 0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
574 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
575 joyPortClose(hGame);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
576 SDL_SetError("Could not get Joystick Driver version.");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
577 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
578 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
579 if (ulVersion < GAME_VERSION)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
580 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
581 joyPortClose(hGame);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
582 SDL_SetError("Driver too old. At least IBM driver version 2.0 required.");
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
583 return -1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
584 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
585 return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
586 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
587
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
588
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
589
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
590 /****************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
591 /* Close JoyPort, if opened */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
592 /****************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
593 void joyPortClose(HFILE * hGame)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
594 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
595 if (*hGame != NULL) DosClose(*hGame);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
596 *hGame = NULL;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
597 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
598
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
599
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
600
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
601 /***************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
602 /* Get SDL Joystick EnvVar */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
603 /***************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
604 int joyGetEnv(struct _joycfg * joydata)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
605 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
606 char *joyenv; /* Pointer to tested character */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
607 char tempnumber[5]; /* Temporary place to put numeric texts */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
608
1336
3692456e7b0f Use SDL_ prefixed versions of C library functions.
Sam Lantinga <slouken@libsdl.org>
parents: 1312
diff changeset
609 joyenv = SDL_getenv("SDL_OS2_JOYSTICK");
1190
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
610 if (joyenv == NULL) return 0;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
611 /* Joystick Environment is defined! */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
612 while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
613 /* If the string name starts with '... get if fully */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
614 if (*joyenv=='\'') joyenv+=joyGetData(++joyenv,joydata->name,'\'',sizeof(joydata->name));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
615 /* If not, get it until the next space */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
616 else if (*joyenv=='\"') joyenv+=joyGetData(++joyenv,joydata->name,'\"',sizeof(joydata->name));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
617 else joyenv+=joyGetData(joyenv,joydata->name,' ',sizeof(joydata->name));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
618 /* Now get the number of axes */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
619 while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
620 joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
621 joydata->axes = atoi(tempnumber);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
622 /* Now get the number of buttons */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
623 while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
624 joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
625 joydata->buttons = atoi(tempnumber);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
626 /* Now get the number of hats */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
627 while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
628 joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
629 joydata->hats = atoi(tempnumber);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
630 /* Now get the number of balls */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
631 while (*joyenv==' ' && *joyenv!=0) joyenv++; /* jump spaces... */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
632 joyenv+=joyGetData(joyenv,tempnumber,' ',sizeof(tempnumber));
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
633 joydata->balls = atoi(tempnumber);
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
634 return 1;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
635 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
636
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
637
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
638
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
639 /************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
640 /* Get a text from in the string starting in joyenv until it finds */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
641 /* the stopchar or maxchars is reached. The result is placed in name. */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
642 /************************************************************************/
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
643 int joyGetData(char *joyenv, char *name, char stopchar, size_t maxchars)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
644 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
645 char *nameptr; /* Pointer to the selected character */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
646 int chcnt=0; /* Count how many characters where copied */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
647
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
648 nameptr=name;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
649 while (*joyenv!=stopchar && *joyenv!=0)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
650 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
651 if (nameptr<(name+(maxchars-1)))
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
652 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
653 *nameptr = *joyenv; /* Only copy if smaller than maximum */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
654 nameptr++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
655 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
656 chcnt++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
657 joyenv++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
658 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
659 if (*joyenv==stopchar)
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
660 {
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
661 joyenv++; /* Jump stopchar */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
662 chcnt++;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
663 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
664 *nameptr = 0; /* Mark last byte */
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
665 return chcnt;
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
666 }
173c063d4f55 OS/2 port!
Ryan C. Gordon <icculus@icculus.org>
parents:
diff changeset
667
1635
92947e3a18db Make sure code is only compiled if the appropriate subsystem is enabled
Sam Lantinga <slouken@libsdl.org>
parents: 1442
diff changeset
668 #endif /* SDL_JOYSTICK_OS2 */