Wing Commander
Reconstructed Win32 source (1996)
Toggle main menu visibility
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 */
13
void
CalibrateJoystickInteractive
()
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;
29
if
(
nCurrentActiveInputDevice
== -1)
30
return
;
31
stDefaultTxtContext
.
alignment
= 2;
32
if
(
apTextFonts
[1] != 0)
33
fontLoaded = 1;
34
35
InitializeTextContextFromFont
(&
stDefaultTxtContext
, 1,
36
cViewportClearColour
, (
signed
char
)
cBlackColour
);
37
shown =
ShowModalTextPanel
(1,
38
"Turn AUTO FIRE off if present, press a button"
);
39
if
(shown != 0) {
40
DIBslamReal
();
41
WaitForJoystickButtonPress
();
42
WaitForJoystickButtonRelease
();
43
ReleaseModalTextPanel
();
44
}
45
46
shown =
ShowModalTextPanel
(1,
47
"Move stick to the UPPER LEFT, press a button"
);
48
if
(shown != 0) {
49
DIBslamReal
();
50
WaitForJoystickButtonPress
();
51
SampleJoystickDevice
(samples,
nCurrentActiveInputDevice
, 0x7fff);
52
calibration[0] =
nStickMinimumPositionX
=
53
samples[
nCurrentActiveInputDevice
].
x
;
54
calibration[1] =
nStickMinimumPositionY
=
55
samples[
nCurrentActiveInputDevice
].
y
;
56
WaitForJoystickButtonRelease
();
57
ReleaseModalTextPanel
();
58
}
59
60
shown =
ShowModalTextPanel
(1,
61
"Move stick to the LOWER RIGHT, press a button"
);
62
if
(shown != 0) {
63
DIBslamReal
();
64
WaitForJoystickButtonPress
();
65
SampleJoystickDevice
(samples,
nCurrentActiveInputDevice
, 0x7fff);
66
calibration[2] =
nStickMaxX
=
67
samples[
nCurrentActiveInputDevice
].
x
;
68
calibration[3] =
nStickMaxY
=
69
samples[
nCurrentActiveInputDevice
].
y
;
70
WaitForJoystickButtonRelease
();
71
ReleaseModalTextPanel
();
72
}
73
74
shown =
ShowModalTextPanel
(1,
75
"Center Joystick, press a button"
);
76
if
(shown != 0) {
77
DIBslamReal
();
78
WaitForJoystickButtonPress
();
79
SampleJoystickDevice
(samples,
nCurrentActiveInputDevice
, 0x7fff);
80
calibration[4] =
nJoystickCentreX
=
81
samples[
nCurrentActiveInputDevice
].
x
;
82
calibration[5] =
nJoystickCentreY
=
83
samples[
nCurrentActiveInputDevice
].
y
;
84
WaitForJoystickButtonRelease
();
85
ReleaseModalTextPanel
();
86
}
87
88
if
(fontLoaded == 0)
89
ReleaseTextFont
(1);
90
91
horizontalRange =
nJoystickHorizontalRangeValue
;
92
if
(horizontalRange == 0)
93
horizontalRange = 9;
94
verticalRange =
nJoystickVerticalRange
;
95
if
(verticalRange == 0)
96
verticalRange = 9;
97
leftScale =
98
(
nJoystickCentreX
-
nStickMinimumPositionX
) /
99
horizontalRange;
100
rightScale =
101
(
nStickMaxX
-
nJoystickCentreX
) /
102
horizontalRange;
103
upScale =
104
(
nJoystickCentreY
-
nStickMinimumPositionY
) /
105
verticalRange;
106
downScale =
107
(
nStickMaxY
-
nJoystickCentreY
) /
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;
128
nCurrentJoystickFailureValue
=
nStickMaxX
* 2;
129
130
if
(
nStickMaxX
<=
nStickMinimumPositionX
||
131
nStickMaxY
<=
nStickMinimumPositionY
) {
132
shown =
ShowModalTextPanel
(1,
133
"FAILED! Center Joystick, press a button"
);
134
if
(shown != 0) {
135
DIBslamReal
();
136
WaitForJoystickButtonPress
();
137
WaitForJoystickButtonRelease
();
138
LoadJoystickCalibrationFile
(8, 8, 1, 1);
139
ReleaseModalTextPanel
();
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 */
167
void
WaitForJoystickButtonRelease
(
void
)
168
{
169
do
{
170
SampleJoystickDevice
(
171
&
aInputDevSamples
[
172
nCurrentActiveInputDevice
],
173
nCurrentActiveInputDevice
, 0);
174
}
while
(
aInputDevSamples
[
175
nCurrentActiveInputDevice
].buttons != 0);
176
}
177
178
/* Function start: 0x410700 */
179
void
WaitForJoystickButtonPress
(
void
)
180
{
181
do
{
182
SampleJoystickDevice
(
183
&
aInputDevSamples
[
184
nCurrentActiveInputDevice
],
185
nCurrentActiveInputDevice
, 0);
186
}
while
(
aInputDevSamples
[
187
nCurrentActiveInputDevice
].buttons == 0);
188
}
aInputDevSamples
InputDeviceSample aInputDevSamples[2]
Definition
nav.c:78
nJoystickCentreY
int nJoystickCentreY
Definition
nav.c:75
stDefaultTxtContext
TextContext stDefaultTxtContext
Definition
targ.c:14
cBlackColour
unsigned char cBlackColour
Definition
init.c:12
nCurrentJoystickFailureValue
int nCurrentJoystickFailureValue
Definition
nav.c:77
nJoystickCentreX
int nJoystickCentreX
Definition
nav.c:76
nStickMaxX
int nStickMaxX
Definition
nav.c:65
cViewportClearColour
unsigned char cViewportClearColour
Definition
init.c:13
nJoystickDownScaleValue
int nJoystickDownScaleValue
Definition
nav.c:74
nStickMinimumPositionX
int nStickMinimumPositionX
Definition
nav.c:67
apTextFonts
unsigned char * apTextFonts[4]
Definition
pload.c:13
nJoystickRightScale
int nJoystickRightScale
Definition
nav.c:73
nCurrentJoystickLeftScale
int nCurrentJoystickLeftScale
Definition
nav.c:64
nJoystickHorizontalRangeValue
int nJoystickHorizontalRangeValue
Definition
nav.c:72
nStickMinimumPositionY
int nStickMinimumPositionY
Definition
nav.c:68
nJoystickUpScale
int nJoystickUpScale
Definition
nav.c:63
nCurrentActiveInputDevice
short nCurrentActiveInputDevice
Definition
nav.c:60
nStickMaxY
int nStickMaxY
Definition
nav.c:66
nJoystickVerticalRange
int nJoystickVerticalRange
Definition
nav.c:71
InputDeviceSample
Definition
wc1base.h:149
InputDeviceSample::x
int x
Definition
wc1base.h:150
InputDeviceSample::y
int y
Definition
wc1base.h:151
TextContext::alignment
unsigned char alignment
Definition
wc1base.h:244
wc1.h
Umbrella header for the game core.
InitializeTextContextFromFont
unsigned int InitializeTextContextFromFont(TextContext *context, short fontIndex, unsigned char colour, signed char background)
Definition
disk.c:192
CalibrateJoystickInteractive
void CalibrateJoystickInteractive()
Definition
joystick.c:13
WaitForJoystickButtonRelease
void WaitForJoystickButtonRelease(void)
Definition
joystick.c:167
DIBslamReal
void DIBslamReal(void)
Definition
dib.c:519
LoadJoystickCalibrationFile
void LoadJoystickCalibrationFile(short horizontalRange, short verticalRange, short horizontalDeadZone, short verticalDeadZone)
Definition
joycal.c:39
WaitForJoystickButtonPress
void WaitForJoystickButtonPress(void)
Definition
joystick.c:179
ReleaseModalTextPanel
void ReleaseModalTextPanel(void)
Definition
barracks.c:163
ReleaseTextFont
unsigned int ReleaseTextFont(short fontIndex)
Definition
disk.c:222
ShowModalTextPanel
short ShowModalTextPanel(short fontIndex, const char *format,...)
Definition
barracks.c:123
SampleJoystickDevice
int __stdcall SampleJoystickDevice(InputDeviceSample *samples, short joystick, unsigned short fallback)
Definition
mission.c:958
src
joystick.c
Generated by
1.18.0