Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
joystick.c
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup shell
4 * @brief Interactive joystick calibration and button waits.
5 *
6 * Address range 4102b0-41073f.
7 */
8#include <sys/types.h>
9#include <crtdbg.h>
10#include "wc1.h"
11
12/* Function start: 0x4102B0 */
14{
15 InputDeviceSample samples[2];
16 short calibration[6];
17 short shown;
18 int file;
19 int failed;
20 int fontLoaded;
21 int leftScale;
22 int upScale;
23 int rightScale;
24 int downScale;
25 int horizontalRange;
26 int verticalRange;
27
28 fontLoaded = 0;
30 return;
32 if (apTextFonts[1] != 0)
33 fontLoaded = 1;
34
37 shown = ShowModalTextPanel(1,
38 "Turn AUTO FIRE off if present, press a button");
39 if (shown != 0) {
44 }
45
46 shown = ShowModalTextPanel(1,
47 "Move stick to the UPPER LEFT, press a button");
48 if (shown != 0) {
52 calibration[0] = nStickMinimumPositionX =
54 calibration[1] = nStickMinimumPositionY =
58 }
59
60 shown = ShowModalTextPanel(1,
61 "Move stick to the LOWER RIGHT, press a button");
62 if (shown != 0) {
66 calibration[2] = nStickMaxX =
68 calibration[3] = nStickMaxY =
72 }
73
74 shown = ShowModalTextPanel(1,
75 "Center Joystick, press a button");
76 if (shown != 0) {
80 calibration[4] = nJoystickCentreX =
82 calibration[5] = nJoystickCentreY =
86 }
87
88 if (fontLoaded == 0)
90
91 horizontalRange = nJoystickHorizontalRangeValue;
92 if (horizontalRange == 0)
93 horizontalRange = 9;
94 verticalRange = nJoystickVerticalRange;
95 if (verticalRange == 0)
96 verticalRange = 9;
97 leftScale =
99 horizontalRange;
100 rightScale =
102 horizontalRange;
103 upScale =
105 verticalRange;
106 downScale =
108 verticalRange;
109 if (leftScale == 0)
110 leftScale++;
111 if (upScale == 0)
112 upScale++;
113 if (rightScale == 0)
114 rightScale++;
115 if (downScale == 0)
116 downScale++;
117 nCurrentJoystickLeftScale = leftScale;
118 nJoystickUpScale = upScale;
119 nJoystickRightScale = rightScale;
120 nJoystickDownScaleValue = downScale;
121 nJoystickHorizontalRangeValue = horizontalRange;
122 nJoystickVerticalRange = verticalRange;
123
124 nStickMinimumPositionX = nJoystickCentreX - leftScale * horizontalRange;
125 nStickMinimumPositionY = nJoystickCentreY - upScale * verticalRange;
126 nStickMaxX = nJoystickCentreX + rightScale * horizontalRange;
127 nStickMaxY = nJoystickCentreY + downScale * verticalRange;
129
132 shown = ShowModalTextPanel(1,
133 "FAILED! Center Joystick, press a button");
134 if (shown != 0) {
135 DIBslamReal();
138 LoadJoystickCalibrationFile(8, 8, 1, 1);
140 }
141 _unlink("j.cal");
142 return;
143 }
144
145 file = _open("j.cal", 0x8301, 0x180);
146 if (file == -1)
147 return;
148 failed = _write(file, &nCurrentActiveInputDevice, 2) == -1;
149 if (failed == 0)
150 failed = _write(file, &calibration[0], 2) == -1;
151 if (failed == 0)
152 failed = _write(file, &calibration[1], 2) == -1;
153 if (failed == 0)
154 failed = _write(file, &calibration[2], 2) == -1;
155 if (failed == 0)
156 failed = _write(file, &calibration[3], 2) == -1;
157 if (failed == 0)
158 failed = _write(file, &calibration[4], 2) == -1;
159 if (failed == 0)
160 failed = _write(file, &calibration[5], 2) == -1;
161 _close(file);
162 if (failed != 0)
163 _unlink("j.cal");
164}
165
166/* Function start: 0x4106C0 */
177
178/* Function start: 0x410700 */
InputDeviceSample aInputDevSamples[2]
Definition nav.c:78
int nJoystickCentreY
Definition nav.c:75
TextContext stDefaultTxtContext
Definition targ.c:14
unsigned char cBlackColour
Definition init.c:12
int nCurrentJoystickFailureValue
Definition nav.c:77
int nJoystickCentreX
Definition nav.c:76
int nStickMaxX
Definition nav.c:65
unsigned char cViewportClearColour
Definition init.c:13
int nJoystickDownScaleValue
Definition nav.c:74
int nStickMinimumPositionX
Definition nav.c:67
unsigned char * apTextFonts[4]
Definition pload.c:13
int nJoystickRightScale
Definition nav.c:73
int nCurrentJoystickLeftScale
Definition nav.c:64
int nJoystickHorizontalRangeValue
Definition nav.c:72
int nStickMinimumPositionY
Definition nav.c:68
int nJoystickUpScale
Definition nav.c:63
short nCurrentActiveInputDevice
Definition nav.c:60
int nStickMaxY
Definition nav.c:66
int nJoystickVerticalRange
Definition nav.c:71
unsigned char alignment
Definition wc1base.h:244
Umbrella header for the game core.
unsigned int InitializeTextContextFromFont(TextContext *context, short fontIndex, unsigned char colour, signed char background)
Definition disk.c:192
void CalibrateJoystickInteractive()
Definition joystick.c:13
void WaitForJoystickButtonRelease(void)
Definition joystick.c:167
void DIBslamReal(void)
Definition dib.c:519
void LoadJoystickCalibrationFile(short horizontalRange, short verticalRange, short horizontalDeadZone, short verticalDeadZone)
Definition joycal.c:39
void WaitForJoystickButtonPress(void)
Definition joystick.c:179
void ReleaseModalTextPanel(void)
Definition barracks.c:163
unsigned int ReleaseTextFont(short fontIndex)
Definition disk.c:222
short ShowModalTextPanel(short fontIndex, const char *format,...)
Definition barracks.c:123
int __stdcall SampleJoystickDevice(InputDeviceSample *samples, short joystick, unsigned short fallback)
Definition mission.c:958