Wing Commander II
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
joycal.c
Go to the documentation of this file.
1/*
2 * Joystick calibration file and calibrated reads.
3 *
4 * Retail object 0x423480-0x423C5F (link order; see docs/ORDER.md).
5 */
6#include "game.h"
7
8const int g_nJoystickUnavailableSample = -1; /* 0x0048e054 */
9
10signed char g_acExpectedGraphicsModes[5] = {
11 0x13, 0x0d, 4, 9, 7
12}; /* 0x00493078 */
13
14/* Function start: 0x423480 */
15short LoadJoystickCalibrationFile(short horizontalRange,
16 short verticalRange,
17 short horizontalDeadZone,
18 short verticalDeadZone)
19{
20 InputDeviceSample stickSamples[2];
21 unsigned short restX;
22 unsigned short restY;
23 unsigned short maxY;
24 unsigned short minY;
25 unsigned short minX;
26 int fileError;
27 unsigned short maxX;
28 int file;
29 short activeDevice;
30 unsigned short passes;
31
32 activeDevice = -1;
33 /* The DOS polling calibration's starting pass count; unused here. */
34 passes = 0x40;
35 fileError = 1;
36 if (horizontalRange == 0)
37 horizontalRange++;
38 if (verticalRange == 0)
39 verticalRange++;
43 if (stickSamples[0].x != g_nJoystickUnavailableSample &&
44 stickSamples[0].y != g_nJoystickUnavailableSample)
45 activeDevice = 0;
46 else if (stickSamples[1].x != g_nJoystickUnavailableSample &&
47 stickSamples[1].y != g_nJoystickUnavailableSample)
48 activeDevice = 1;
49
50 if (activeDevice != -1) {
51 file = _open("j.cal", 0x8000);
52 if (file != -1) {
53 fileError = _read(file, &activeDevice, 2) <= 0;
54 if (fileError == 0)
55 fileError = _read(file, &minX, 2) <= 0;
56 if (fileError == 0)
57 fileError = _read(file, &minY, 2) <= 0;
58 if (fileError == 0)
59 fileError = _read(file, &maxX, 2) <= 0;
60 if (fileError == 0)
61 fileError = _read(file, &maxY, 2) <= 0;
62 if (fileError == 0)
63 fileError = _read(file, &restX, 2) <= 0;
64 if (fileError == 0)
65 fileError = _read(file, &restY, 2) <= 0;
66 g_1_nJoystickCentreXNumber = (unsigned int)restX;
67 g_2_nJoystickCentreY = (unsigned int)restY;
68 _close(file);
69 if (fileError != 0)
70 _unlink("j.cal");
71 }
72
73 if (fileError != 0) {
74 GetJoystickDevCaps(activeDevice,
75 (short *)&minX,
76 (short *)&maxX,
77 (short *)&minY,
78 (short *)&maxY);
80 ((int)minX + (int)maxX) / 2;
82 ((int)minY + (int)maxY) / 2;
83 }
84
90 } else {
95 }
96 if (g_2_nJoystickCentreY > 10) {
101 } else {
106 }
107
110 (int)horizontalRange;
115 (int)verticalRange;
122 if (g_1_nJsRightScaleWord == 0)
126
129 horizontalRange * g_12_nControllerLeftScaleValue;
132 verticalRange * g_59_nJoystickUpScaleWord;
134 horizontalRange * g_12_nControllerLeftScaleValue +
137 verticalRange * g_59_nJoystickUpScaleWord +
139 g_nJoystickHorizDeadZone = horizontalDeadZone;
140 g_nControllerVerticalDeadZoneWord = verticalDeadZone;
141 }
142 g_8_nActiveInputDeviceWord = activeDevice;
143 return activeDevice;
144}
145
146/* Function start: 0x4238E9 */
148{
149 short normalizedX;
150 short normalizedY;
151 short inputDevice;
152
153 inputDevice = g_8_nActiveInputDeviceWord;
155 return 0;
157 &g_aInputDeviceSamplesList[inputDevice], inputDevice,
159 if (g_aInputDeviceSamplesList[inputDevice].x ==
161 g_aInputDeviceSamplesList[inputDevice].y ==
163 g_aInputDeviceSamplesList[inputDevice].x =
164 g_aInputDeviceSamplesList[inputDevice].y =
165 g_aInputDeviceSamplesList[inputDevice].buttons = 0;
167 return 0;
168 }
169
171 g_aInputDeviceSamplesList[inputDevice].x;
173 g_aInputDeviceSamplesList[inputDevice].y;
174 if (g_aInputDeviceSamplesList[inputDevice].x <
176 g_aInputDeviceSamplesList[inputDevice].x =
178 if (g_aInputDeviceSamplesList[inputDevice].x >
180 g_aInputDeviceSamplesList[inputDevice].x =
182 if (g_aInputDeviceSamplesList[inputDevice].y <
184 g_aInputDeviceSamplesList[inputDevice].y =
186 if (g_aInputDeviceSamplesList[inputDevice].y >
188 g_aInputDeviceSamplesList[inputDevice].y =
190
191 normalizedY = 0;
192 normalizedX = normalizedY;
193 if (g_aInputDeviceSamplesList[inputDevice].x <
195 normalizedX = (short)((g_1_nJoystickCentreXNumber -
196 g_aInputDeviceSamplesList[inputDevice].x) /
198 if (normalizedX <= g_nJoystickHorizDeadZone)
199 normalizedX = 0;
200 else if (normalizedX != 0)
201 normalizedX = (short)-normalizedX;
202 } else if (g_aInputDeviceSamplesList[inputDevice].x >
204 normalizedX = (short)((
205 g_aInputDeviceSamplesList[inputDevice].x -
208 if (normalizedX <= g_nJoystickHorizDeadZone)
209 normalizedX = 0;
210 }
211
212 if (g_aInputDeviceSamplesList[inputDevice].y <
214 normalizedY = (short)((g_2_nJoystickCentreY -
215 g_aInputDeviceSamplesList[inputDevice].y) /
217 if (normalizedY <= g_nControllerVerticalDeadZoneWord)
218 normalizedY = 0;
219 else if (normalizedY != 0)
220 normalizedY = (short)-normalizedY;
221 } else if (g_aInputDeviceSamplesList[inputDevice].y >
223 normalizedY = (short)((
224 g_aInputDeviceSamplesList[inputDevice].y -
227 if (normalizedY <= g_nControllerVerticalDeadZoneWord)
228 normalizedY = 0;
229 }
230 g_aInputDeviceSamplesList[inputDevice].x = (int)normalizedX;
231 g_aInputDeviceSamplesList[inputDevice].y = (int)normalizedY;
232 return 1;
233}
234
235/* Unreferenced driver names; WC1's joystick unit has the same pair. */
236static char g_szTMDriverName[] = "TM.DRV"; /* 0x00493080 */
237static char g_szSuperTMDriverName[] = "SUPERTM.DRV"; /* 0x00493088 */
238
239/* Linker commons defined here. LINK lays a unit's commons out by the
240 * identifiers' hash keys, so these spellings follow the original addresses. */
243int g_3_nJoystickRawX; /* 0x005d2ff8 */
244int g_nStickRawY; /* 0x005d2ffc */
246int g_7_nJoystickTuningTopY; /* 0x005d3004 */
247char g_nUnusedJoycalValue; /* 0x005d3008 */ /* never referenced */
248unsigned char *g_1_pCampaignDataBase; /* 0x005d300c */
short ReadCalibratedJoystick(void)
Definition joycal.c:147
short SampleBothJoysticks(InputDeviceSample *samples, unsigned int fallback)
Definition joystick.c:9
short LoadJoystickCalibrationFile(short horizontalRange, short verticalRange, short horizontalDeadZone, short verticalDeadZone)
Definition joycal.c:15
void SampleJoystickDevice(InputDeviceSample *samples, short joystick, unsigned int fallback)
Definition joystick.c:22
void GetJoystickDevCaps(short joystick, short *xMin, short *xMax, short *yMin, short *yMax)
Definition winmain.c:716
Shared Win32 declarations, types and library interfaces.
int g_nStickRawY
Definition joycal.c:244
int g_nControllerVerticalDeadZoneWord
Definition joystick.c:58
int g_12_nJoystickDownScaleWord
Definition joystick.c:70
int g_12_nControllerLeftScaleValue
Definition joystick.c:62
int g_4_nJoystickMaximumXValue
Definition joystick.c:63
int g_nJoystickCalibrationMinimumY
Definition joycal.c:241
int g_1_nJoystickCentreXNumber
Definition joystick.c:72
const int g_nJoystickUnavailableSample
Definition joycal.c:8
unsigned char * g_1_pCampaignDataBase
Definition joycal.c:248
signed char g_acExpectedGraphicsModes[5]
Definition joycal.c:10
int g_2_nJsMinimumY
Definition joystick.c:66
int g_2_nJoystickCalibrationMinimumXNumber
Definition joycal.c:242
int g_1_nJsRightScaleWord
Definition joystick.c:69
InputDeviceSample g_aInputDeviceSamplesList[2]
Definition joystick.c:75
int g_7_nJoystickTuningTopY
Definition joycal.c:246
int g_2_nJoystickCentreY
Definition joystick.c:71
int g_2_nControllerCalibrationMaximumX
Definition joycal.c:245
short g_8_nActiveInputDeviceWord
Definition joystick.c:57
int g_nJoystickHorizDeadZone
Definition joystick.c:59
int g_4_nControllerFailureValue
Definition joystick.c:73
int g_12_nJoystickMinimumXNumber
Definition joystick.c:65
int g_3_nJoystickRawX
Definition joycal.c:243
int g_59_nJoystickUpScaleWord
Definition joystick.c:61
int g_nJoystickMaximumY
Definition joystick.c:64
static char g_szSuperTMDriverName[]
Definition joycal.c:237
char g_nUnusedJoycalValue
Definition joycal.c:247
static char g_szTMDriverName[]
Definition joycal.c:236
unsigned int buttons
Definition game.h:224