Debian Codegraph @

src/joystick.c

raw symbols SCIP
1 /*
2 * OpenTyrian: A modern cross-platform port of Tyrian
3 * Copyright (C) 2007-2009 The OpenTyrian Development Team
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 */
19 #include "joystick.h"cxx . . $ `<file>/src/joystick.h`/
20
21 #include "config.h"cxx . . $ `<file>/src/config.h`/
22 #include "config_file.h"cxx . . $ `<file>/src/config_file.h`/
23 #include "file.h"cxx . . $ `<file>/src/file.h`/
24 #include "keyboard.h"cxx . . $ `<file>/src/keyboard.h`/
25 #include "nortsong.h"cxx . . $ `<file>/src/nortsong.h`/
26 #include "opentyr.h"cxx . . $ `<file>/src/opentyr.h`/
27 #include "params.h"cxx . . $ `<file>/src/params.h`/
28 #include "varz.h"cxx . . $ `<file>/src/varz.h`/
29 #include "video.h"cxx . . $ `<file>/src/video.h`/
30
31 #include <assert.h>
32 #include <ctype.h>
33 #include <string.h>
34
35 int joystick_axis_thresholdcxx . . $ joystick_axis_threshold(9b79fb6aee4c0440).(int j, int value);
36 int check_assignedcxx . . $ check_assigned(5cb5d6b3b02190c9).(SDL_Joystickcxx . . $ SDL_Joystick# *joystick_handle, const Joystick_assignmentcxx . . $ Joystick_assignment# assignment[2]);
37
38 const char *assignment_to_codecxx . . $ assignment_to_code(6d7bebc2f642d6a3).(const Joystick_assignmentcxx . . $ Joystick_assignment# *assignment);
39 void code_to_assignmentcxx . . $ code_to_assignment(6e1410cc8d6d3471).(Joystick_assignmentcxx . . $ Joystick_assignment# *assignment, const char *buffer);
40
41 int joystick_repeat_delaycxx . . $ joystick_repeat_delay. = 300; // milliseconds, repeat delay for buttons
42 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! joydowncxx . . $ joydown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; // any joystick buttons down, updated by poll_joysticks()
43 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ignore_joystickcxx . . $ ignore_joystick. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
44
45 int joystickscxx . . $ joysticks. = 0;
46 Joystickcxx . . $ Joystick# *joystickcxx . . $ joystick. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
47
48 static const int joystick_analog_maxcxx . . $ joystick_analog_max. = 32767;
49
50 // eliminates axis movement below the threshold
51 int joystick_axis_thresholdcxx . . $ joystick_axis_threshold(9b79fb6aee4c0440).(int j, int value)
52 {
53 assertcxx . . $ `/usr/include/assert.h:50:10`!(j < joysticks);
54
55 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! negative = value < 0;
56 if (negative)
57 value = -value;
58
59 if (value <= joystickcxx . . $ joystick.[j].thresholdcxx . . $ $anonymous_type_abd17893024d7112_2#threshold. * 1000)
60 return 0;
61
62 value -= joystickcxx . . $ joystick.[j].thresholdcxx . . $ $anonymous_type_abd17893024d7112_2#threshold. * 1000;
63
64 return negative ? -value : value;
65 }
66
67 // converts joystick axis to sane Tyrian-usable value (based on sensitivity)
68 int joystick_axis_reducecxx . . $ joystick_axis_reduce(9b79fb6aee4c0440).(int j, int value)
69 {
70 assertcxx . . $ `/usr/include/assert.h:50:10`!(j < joysticks);
71
72 value = joystick_axis_thresholdcxx . . $ joystick_axis_threshold(9b79fb6aee4c0440).(j, value);
73
74 if (value == 0)
75 return 0;
76
77 return value / (3000 - 200 * joystickcxx . . $ joystick.[j].sensitivitycxx . . $ $anonymous_type_abd17893024d7112_2#sensitivity.);
78 }
79
80 // converts analog joystick axes to an angle
81 // returns false if axes are centered (there is no angle)
82 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! joystick_analog_anglecxx . . $ joystick_analog_angle(e7043f53b8864a02).(int j, float *angle)
83 {
84 assertcxx . . $ `/usr/include/assert.h:50:10`!(j < joysticks);
85
86 float x = joystick_axis_thresholdcxx . . $ joystick_axis_threshold(9b79fb6aee4c0440).(j, joystickcxx . . $ joystick.[j].xcxx . . $ $anonymous_type_abd17893024d7112_2#x.), y = joystick_axis_thresholdcxx . . $ joystick_axis_threshold(9b79fb6aee4c0440).(j, joystickcxx . . $ joystick.[j].ycxx . . $ $anonymous_type_abd17893024d7112_2#y.);
87
88 if (x != 0)
89 {
90 *angle += atanfcxx . . $ atanf(fbcf3211dfe1bfd1).(-y / x);
91 *angle += (x < 0) ? -M_PI_2cxx . . $ `<external>/11263917310783833665/math.h:1122:10`! : M_PI_2cxx . . $ `<external>/11263917310783833665/math.h:1122:10`!;
92 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
93 }
94 else if (y != 0)
95 {
96 *angle += y < 0 ? M_PIcxx . . $ `<external>/11263917310783833665/math.h:1121:10`! : 0;
97 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
98 }
99
100 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
101 }
102
103 /* gives back value 0..joystick_analog_max indicating that one of the assigned
104 * buttons has been pressed or that one of the assigned axes/hats has been moved
105 * in the assigned direction
106 */
107 int check_assignedcxx . . $ check_assigned(5cb5d6b3b02190c9).(SDL_Joystickcxx . . $ SDL_Joystick# *joystick_handle, const Joystick_assignmentcxx . . $ Joystick_assignment# assignment[2])
108 {
109 int result = 0;
110
111 for (int i = 0; i < 2; i++)
112 {
113 int temp = 0;
114
115 switch (assignment[i].typecxx . . $ $anonymous_type_abd17893024d7112_1#type.)
116 {
117 case NONEcxx . . $ NONE.:
118 continue;
119
120 case AXIScxx . . $ AXIS.:
121 temp = SDL_JoystickGetAxiscxx . . $ SDL_JoystickGetAxis(f217c576919a4e9b).(joystick_handle, assignment[i].numcxx . . $ $anonymous_type_abd17893024d7112_1#num.);
122
123 if (assignment[i].negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis.)
124 temp = -temp;
125 break;
126
127 case BUTTONcxx . . $ BUTTON.:
128 temp = SDL_JoystickGetButtoncxx . . $ SDL_JoystickGetButton(cd1bab72d9aa38cc).(joystick_handle, assignment[i].numcxx . . $ $anonymous_type_abd17893024d7112_1#num.) == 1 ? joystick_analog_maxcxx . . $ joystick_analog_max. : 0;
129 break;
130
131 case HATcxx . . $ HAT.:
132 temp = SDL_JoystickGetHatcxx . . $ SDL_JoystickGetHat(cd1bab72d9aa38cc).(joystick_handle, assignment[i].numcxx . . $ $anonymous_type_abd17893024d7112_1#num.);
133
134 if (assignment[i].x_axiscxx . . $ $anonymous_type_abd17893024d7112_1#x_axis.)
135 temp &= SDL_HAT_LEFTcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:885:9`! | SDL_HAT_RIGHTcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:883:9`!;
136 else
137 temp &= SDL_HAT_UPcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:882:9`! | SDL_HAT_DOWNcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:884:9`!;
138
139 if (assignment[i].negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis.)
140 temp &= SDL_HAT_LEFTcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:885:9`! | SDL_HAT_UPcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:882:9`!;
141 else
142 temp &= SDL_HAT_RIGHTcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:883:9`! | SDL_HAT_DOWNcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:884:9`!;
143
144 temp = temp ? joystick_analog_maxcxx . . $ joystick_analog_max. : 0;
145 break;
146 }
147
148 if (temp > result)
149 result = temp;
150 }
151
152 return result;
153 }
154
155 // updates joystick state
156 void poll_joystickcxx . . $ poll_joystick(d4f767463ce0a6b3).(int j)
157 {
158 assertcxx . . $ `/usr/include/assert.h:50:10`!(j < joysticks);
159
160 if (joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
161 return;
162
163 SDL_JoystickUpdatecxx . . $ SDL_JoystickUpdate(49f6e7a06ebc5aa8).();
164
165 // indicates that a direction/action was pressed since last poll
166 joystickcxx . . $ joystick.[j].input_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#input_pressed. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
167
168 // indicates that an direction/action has been held long enough to fake a repeat press
169 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! repeat = joystickcxx . . $ joystick.[j].joystick_delaycxx . . $ $anonymous_type_abd17893024d7112_2#joystick_delay. < SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).();
170
171 // update direction state
172 for (uintcxx . . $ uint# d = 0; d < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].direction); d++)
173 {
174 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! old = joystickcxx . . $ joystick.[j].directioncxx . . $ $anonymous_type_abd17893024d7112_2#direction.[d];
175
176 joystickcxx . . $ joystick.[j].analog_directioncxx . . $ $anonymous_type_abd17893024d7112_2#analog_direction.[d] = check_assignedcxx . . $ check_assigned(5cb5d6b3b02190c9).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[d]);
177 joystickcxx . . $ joystick.[j].directioncxx . . $ $anonymous_type_abd17893024d7112_2#direction.[d] = joystickcxx . . $ joystick.[j].analog_directioncxx . . $ $anonymous_type_abd17893024d7112_2#analog_direction.[d] > (joystick_analog_maxcxx . . $ joystick_analog_max. / 2);
178 joydowncxx . . $ joydown. |= joystickcxx . . $ joystick.[j].directioncxx . . $ $anonymous_type_abd17893024d7112_2#direction.[d];
179
180 joystickcxx . . $ joystick.[j].direction_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#direction_pressed.[d] = joystickcxx . . $ joystick.[j].directioncxx . . $ $anonymous_type_abd17893024d7112_2#direction.[d] && (!old || repeat);
181 joystickcxx . . $ joystick.[j].input_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#input_pressed. |= joystickcxx . . $ joystick.[j].direction_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#direction_pressed.[d];
182 }
183
184 joystickcxx . . $ joystick.[j].xcxx . . $ $anonymous_type_abd17893024d7112_2#x. = -joystickcxx . . $ joystick.[j].analog_directioncxx . . $ $anonymous_type_abd17893024d7112_2#analog_direction.[3] + joystickcxx . . $ joystick.[j].analog_directioncxx . . $ $anonymous_type_abd17893024d7112_2#analog_direction.[1];
185 joystickcxx . . $ joystick.[j].ycxx . . $ $anonymous_type_abd17893024d7112_2#y. = -joystickcxx . . $ joystick.[j].analog_directioncxx . . $ $anonymous_type_abd17893024d7112_2#analog_direction.[0] + joystickcxx . . $ joystick.[j].analog_directioncxx . . $ $anonymous_type_abd17893024d7112_2#analog_direction.[2];
186
187 // update action state
188 for (uintcxx . . $ uint# d = 0; d < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].action); d++)
189 {
190 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! old = joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[d];
191
192 joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[d] = check_assignedcxx . . $ check_assigned(5cb5d6b3b02190c9).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[d + COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].direction)]) > (joystick_analog_maxcxx . . $ joystick_analog_max. / 2);
193 joydowncxx . . $ joydown. |= joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[d];
194
195 joystickcxx . . $ joystick.[j].action_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#action_pressed.[d] = joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[d] && (!old || repeat);
196 joystickcxx . . $ joystick.[j].input_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#input_pressed. |= joystickcxx . . $ joystick.[j].action_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#action_pressed.[d];
197 }
198
199 joystickcxx . . $ joystick.[j].confirmcxx . . $ $anonymous_type_abd17893024d7112_2#confirm. = joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[0] || joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[4];
200 joystickcxx . . $ joystick.[j].cancelcxx . . $ $anonymous_type_abd17893024d7112_2#cancel. = joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[1] || joystickcxx . . $ joystick.[j].actioncxx . . $ $anonymous_type_abd17893024d7112_2#action.[5];
201
202 // if new input, reset press-repeat delay
203 if (joystickcxx . . $ joystick.[j].input_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#input_pressed.)
204 joystickcxx . . $ joystick.[j].joystick_delaycxx . . $ $anonymous_type_abd17893024d7112_2#joystick_delay. = SDL_GetTickscxx . . $ SDL_GetTicks(db52760e79bf9054).() + joystick_repeat_delaycxx . . $ joystick_repeat_delay.;
205 }
206
207 // updates all joystick states
208 void poll_joystickscxx . . $ poll_joysticks(49f6e7a06ebc5aa8).(void)
209 {
210 joydowncxx . . $ joydown. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
211
212 for (int j = 0; j < joystickscxx . . $ joysticks.; j++)
213 poll_joystickcxx . . $ poll_joystick(d4f767463ce0a6b3).(j);
214 }
215
216 // sends SDL KEYDOWN and KEYUP events for a key
217 void push_keycxx . . $ push_key(decbd40bd4dd73ad).(SDL_Scancodecxx . . $ SDL_Scancode# key)
218 {
219 SDL_Eventcxx . . $ SDL_Event# e;
220
221 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&e.keycxx . . $ SDL_Event#key..keysymcxx . . $ SDL_KeyboardEvent#keysym., 0, sizeof(e.keycxx . . $ SDL_Event#key..keysymcxx . . $ SDL_KeyboardEvent#keysym.));
222
223 e.keycxx . . $ SDL_Event#key..keysymcxx . . $ SDL_KeyboardEvent#keysym..scancodecxx . . $ SDL_Keysym#scancode. = key;
224 e.keycxx . . $ SDL_Event#key..statecxx . . $ SDL_KeyboardEvent#state. = SDL_RELEASEDcxx . . $ `<external>/12778062723415653681/SDL_events.h:49:9`!;
225
226 e.typecxx . . $ SDL_Event#type. = SDL_KEYDOWNcxx . . $ SDL_KEYDOWN.;
227 SDL_PushEventcxx . . $ SDL_PushEvent(c228975526fb3e93).(&e);
228
229 e.typecxx . . $ SDL_Event#type. = SDL_KEYUPcxx . . $ SDL_KEYUP.;
230 SDL_PushEventcxx . . $ SDL_PushEvent(c228975526fb3e93).(&e);
231 }
232
233 // helps us be lazy by pretending joysticks are a keyboard (useful for menus)
234 void push_joysticks_as_keyboardcxx . . $ push_joysticks_as_keyboard(49f6e7a06ebc5aa8).(void)
235 {
236 const SDL_Scancodecxx . . $ SDL_Scancode# confirm = SDL_SCANCODE_RETURNcxx . . $ SDL_SCANCODE_RETURN., cancel = SDL_SCANCODE_ESCAPEcxx . . $ SDL_SCANCODE_ESCAPE.;
237 const SDL_Scancodecxx . . $ SDL_Scancode# direction[4] = { SDL_SCANCODE_UPcxx . . $ SDL_SCANCODE_UP., SDL_SCANCODE_RIGHTcxx . . $ SDL_SCANCODE_RIGHT., SDL_SCANCODE_DOWNcxx . . $ SDL_SCANCODE_DOWN., SDL_SCANCODE_LEFTcxx . . $ SDL_SCANCODE_LEFT. };
238
239 poll_joystickscxx . . $ poll_joysticks(49f6e7a06ebc5aa8).();
240
241 for (int j = 0; j < joystickscxx . . $ joysticks.; j++)
242 {
243 if (!joystickcxx . . $ joystick.[j].input_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#input_pressed.)
244 continue;
245
246 if (joystickcxx . . $ joystick.[j].confirmcxx . . $ $anonymous_type_abd17893024d7112_2#confirm.)
247 push_keycxx . . $ push_key(decbd40bd4dd73ad).(confirm);
248 if (joystickcxx . . $ joystick.[j].cancelcxx . . $ $anonymous_type_abd17893024d7112_2#cancel.)
249 push_keycxx . . $ push_key(decbd40bd4dd73ad).(cancel);
250
251 for (uintcxx . . $ uint# d = 0; d < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].direction_pressed); d++)
252 {
253 if (joystickcxx . . $ joystick.[j].direction_pressedcxx . . $ $anonymous_type_abd17893024d7112_2#direction_pressed.[d])
254 push_keycxx . . $ push_key(decbd40bd4dd73ad).(direction[d]);
255 }
256 }
257 }
258
259 // initializes SDL joystick system and loads assignments for joysticks found
260 void init_joystickscxx . . $ init_joysticks(49f6e7a06ebc5aa8).(void)
261 {
262 if (ignore_joystickcxx . . $ ignore_joystick.)
263 return;
264
265 if (SDL_InitSubSystemcxx . . $ SDL_InitSubSystem(4c679297bf94b9eb).(SDL_INIT_JOYSTICKcxx . . $ `<external>/13597568925221565411/SDL.h:86:9`!))
266 {
267 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "warning: failed to initialize joystick system: %s\n", SDL_GetErrorcxx . . $ SDL_GetError(33a1f659e94feb42).());
268 ignore_joystickcxx . . $ ignore_joystick. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
269 return;
270 }
271
272 SDL_JoystickEventStatecxx . . $ SDL_JoystickEventState(7864480464b09eea).(SDL_IGNOREcxx . . $ `<external>/12778062723415653681/SDL_events.h:1141:9`!);
273
274 joystickscxx . . $ joysticks. = SDL_NumJoystickscxx . . $ SDL_NumJoysticks(b126dc7c1de90089).();
275 joystickcxx . . $ joystick. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(joystickscxx . . $ joysticks. * sizeof(*joystickcxx . . $ joystick.));
276
277 for (int j = 0; j < joystickscxx . . $ joysticks.; j++)
278 {
279 memsetcxx . . $ memset(d1de1e4fb215f1c6).(&joystickcxx . . $ joystick.[j], 0, sizeof(*joystickcxx . . $ joystick.));
280
281 joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle. = SDL_JoystickOpencxx . . $ SDL_JoystickOpen(e74792c1862f2ced).(j);
282 if (joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
283 {
284 printfcxx . . $ printf(581fddd72a8db8fc).("joystick detected: %s ", SDL_JoystickNamecxx . . $ SDL_JoystickName(7b1cc1d0d4a60d0b).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.));
285 printfcxx . . $ printf(581fddd72a8db8fc).("(%d axes, %d buttons, %d hats)\n",
286 SDL_JoystickNumAxescxx . . $ SDL_JoystickNumAxes(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.),
287 SDL_JoystickNumButtonscxx . . $ SDL_JoystickNumButtons(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.),
288 SDL_JoystickNumHatscxx . . $ SDL_JoystickNumHats(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.));
289
290 if (!load_joystick_assignmentscxx . . $ load_joystick_assignments(930ab16aa94885a3).(&opentyrian_configcxx . . $ opentyrian_config., j))
291 reset_joystick_assignmentscxx . . $ reset_joystick_assignments(d4f767463ce0a6b3).(j);
292 }
293 }
294
295 if (joystickscxx . . $ joysticks. == 0)
296 printfcxx . . $ printf(581fddd72a8db8fc).("no joysticks detected\n");
297 }
298
299 // deinitializes SDL joystick system and saves joystick assignments
300 void deinit_joystickscxx . . $ deinit_joysticks(49f6e7a06ebc5aa8).(void)
301 {
302 if (ignore_joystickcxx . . $ ignore_joystick.)
303 return;
304
305 for (int j = 0; j < joystickscxx . . $ joysticks.; j++)
306 {
307 if (joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
308 {
309 save_joystick_assignmentscxx . . $ save_joystick_assignments(930ab16aa94885a3).(&opentyrian_configcxx . . $ opentyrian_config., j);
310 SDL_JoystickClosecxx . . $ SDL_JoystickClose(23c180a5db1ea4aa).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.);
311 }
312 }
313
314 freecxx . . $ free(5d22bdacc48458e8).(joystickcxx . . $ joystick.);
315
316 SDL_QuitSubSystemcxx . . $ SDL_QuitSubSystem(cb2f890c2fdad230).(SDL_INIT_JOYSTICKcxx . . $ `<external>/13597568925221565411/SDL.h:86:9`!);
317 }
318
319 void reset_joystick_assignmentscxx . . $ reset_joystick_assignments(d4f767463ce0a6b3).(int j)
320 {
321 assertcxx . . $ `/usr/include/assert.h:50:10`!(j < joysticks);
322
323 // defaults: first 2 axes, first hat, first 6 buttons
324 for (uintcxx . . $ uint# a = 0; a < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].assignment); a++)
325 {
326 // clear assignments
327 for (uintcxx . . $ uint# i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].assignment[a]); i++)
328 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][i].typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = NONEcxx . . $ NONE.;
329
330 if (a < 4)
331 {
332 if (SDL_JoystickNumAxescxx . . $ SDL_JoystickNumAxes(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.) >= 2)
333 {
334 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][0].typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = AXIScxx . . $ AXIS.;
335 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][0].numcxx . . $ $anonymous_type_abd17893024d7112_1#num. = (a + 1) % 2;
336 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][0].negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. = (a == 0 || a == 3);
337 }
338
339 if (SDL_JoystickNumHatscxx . . $ SDL_JoystickNumHats(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.) >= 1)
340 {
341 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][1].typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = HATcxx . . $ HAT.;
342 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][1].numcxx . . $ $anonymous_type_abd17893024d7112_1#num. = 0;
343 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][1].x_axiscxx . . $ $anonymous_type_abd17893024d7112_1#x_axis. = (a == 1 || a == 3);
344 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][1].negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. = (a == 0 || a == 3);
345 }
346 }
347 else
348 {
349 if (a - 4 < (unsigned)SDL_JoystickNumButtonscxx . . $ SDL_JoystickNumButtons(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.))
350 {
351 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][0].typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = BUTTONcxx . . $ BUTTON.;
352 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][0].numcxx . . $ $anonymous_type_abd17893024d7112_1#num. = a - 4;
353 }
354 }
355 }
356
357 joystickcxx . . $ joystick.[j].analogcxx . . $ $anonymous_type_abd17893024d7112_2#analog. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
358 joystickcxx . . $ joystick.[j].sensitivitycxx . . $ $anonymous_type_abd17893024d7112_2#sensitivity. = 5;
359 joystickcxx . . $ joystick.[j].thresholdcxx . . $ $anonymous_type_abd17893024d7112_2#threshold. = 5;
360 }
361
362 static const char* const assignment_namescxx . . $ assignment_names.[] =
363 {
364 "up",
365 "right",
366 "down",
367 "left",
368 "fire",
369 "change fire",
370 "left sidekick",
371 "right sidekick",
372 "menu",
373 "pause",
374 };
375
376 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! load_joystick_assignmentscxx . . $ load_joystick_assignments(930ab16aa94885a3).(Configcxx . . $ Config# *config, int j)
377 {
378 ConfigSectioncxx . . $ ConfigSection# *section = config_find_sectioncxx . . $ config_find_section(9d60c5d7489db765).(config, "joystick", SDL_JoystickNamecxx . . $ SDL_JoystickName(7b1cc1d0d4a60d0b).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.));
379 if (section == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
380 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
381
382 if (!config_get_bool_optioncxx . . $ config_get_bool_option(fe7db5902bd636d8).(section, "analog", &joystickcxx . . $ joystick.[j].analogcxx . . $ $anonymous_type_abd17893024d7112_2#analog.))
383 joystickcxx . . $ joystick.[j].analogcxx . . $ $anonymous_type_abd17893024d7112_2#analog. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
384
385 joystickcxx . . $ joystick.[j].sensitivitycxx . . $ $anonymous_type_abd17893024d7112_2#sensitivity. = config_get_or_set_int_optioncxx . . $ config_get_or_set_int_option(bd9cb9e767e253ec).(section, "sensitivity", 5);
386
387 joystickcxx . . $ joystick.[j].thresholdcxx . . $ $anonymous_type_abd17893024d7112_2#threshold. = config_get_or_set_int_optioncxx . . $ config_get_or_set_int_option(bd9cb9e767e253ec).(section, "threshold", 5);
388
389 for (size_t a = 0; a < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(assignment_names); ++a)
390 {
391 for (unsigned int i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].assignment[a]); ++i)
392 joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][i].typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = NONEcxx . . $ NONE.;
393
394 ConfigOptioncxx . . $ ConfigOption# *option = config_get_optioncxx . . $ config_get_option(5d3990c1f9186589).(section, assignment_namescxx . . $ assignment_names.[a]);
395 if (option == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
396 continue;
397
398 foreach_option_i_valuecxx . . $ `src/config_file.h:574:9`!(i, value, option)
399 {
400 if (i >= COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].assignment[a]))
401 break;
402
403 code_to_assignmentcxx . . $ code_to_assignment(6e1410cc8d6d3471).(&joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][i], value);
404 }
405 }
406
407 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
408 }
409
410 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! save_joystick_assignmentscxx . . $ save_joystick_assignments(930ab16aa94885a3).(Configcxx . . $ Config# *config, int j)
411 {
412 ConfigSectioncxx . . $ ConfigSection# *section = config_find_or_add_sectioncxx . . $ config_find_or_add_section(9d60c5d7489db765).(config, "joystick", SDL_JoystickNamecxx . . $ SDL_JoystickName(7b1cc1d0d4a60d0b).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.));
413 if (section == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
414 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); // out of memory
415
416 config_set_bool_optioncxx . . $ config_set_bool_option(f5dd347f13677d31).(section, "analog", joystickcxx . . $ joystick.[j].analogcxx . . $ $anonymous_type_abd17893024d7112_2#analog., NO_YEScxx . . $ NO_YES.);
417
418 config_set_int_optioncxx . . $ config_set_int_option(3efcdbae08d7b398).(section, "sensitivity", joystickcxx . . $ joystick.[j].sensitivitycxx . . $ $anonymous_type_abd17893024d7112_2#sensitivity.);
419
420 config_set_int_optioncxx . . $ config_set_int_option(3efcdbae08d7b398).(section, "threshold", joystickcxx . . $ joystick.[j].thresholdcxx . . $ $anonymous_type_abd17893024d7112_2#threshold.);
421
422 for (size_t a = 0; a < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(assignment_names); ++a)
423 {
424 ConfigOptioncxx . . $ ConfigOption# *option = config_set_optioncxx . . $ config_set_option(a828e1840e46298e).(section, assignment_namescxx . . $ assignment_names.[a], NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
425 if (option == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
426 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); // out of memory
427
428 option = config_set_valuecxx . . $ config_set_value(933b7be54a5eb800).(option, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
429 if (option == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
430 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); // out of memory
431
432 for (size_t i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(joystick[j].assignment[a]); ++i)
433 {
434 if (joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][i].typecxx . . $ $anonymous_type_abd17893024d7112_1#type. == NONEcxx . . $ NONE.)
435 continue;
436
437 option = config_add_valuecxx . . $ config_add_value(933b7be54a5eb800).(option, assignment_to_codecxx . . $ assignment_to_code(6d7bebc2f642d6a3).(&joystickcxx . . $ joystick.[j].assignmentcxx . . $ $anonymous_type_abd17893024d7112_2#assignment.[a][i]));
438 if (option == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)
439 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); // out of memory
440 }
441 }
442
443 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
444 }
445
446 // fills buffer with comma separated list of assigned joystick functions
447 void joystick_assignments_to_stringcxx . . $ joystick_assignments_to_string(20ca3e504103fe2).(char *buffer, size_t buffer_len, const Joystick_assignmentcxx . . $ Joystick_assignment# *assignments)
448 {
449 strncpycxx . . $ strncpy(255158a415b673b0).(buffer, "", buffer_len);
450
451 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! comma = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
452 for (uintcxx . . $ uint# i = 0; i < COUNTOFcxx . . $ `src/opentyr.h:27:9`!(*joystick->assignment); ++i)
453 {
454 if (assignments[i].typecxx . . $ $anonymous_type_abd17893024d7112_1#type. == NONEcxx . . $ NONE.)
455 continue;
456
457 size_t len = snprintfcxx . . $ snprintf(ea502d73e74c754c).(buffer, buffer_len, "%s%s",
458 comma ? ", " : "",
459 assignment_to_codecxx . . $ assignment_to_code(6d7bebc2f642d6a3).(&assignments[i]));
460 buffer += len;
461 buffer_len -= len;
462
463 comma = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
464 }
465 }
466
467 // reverse of assignment_to_code()
468 void code_to_assignmentcxx . . $ code_to_assignment(6e1410cc8d6d3471).(Joystick_assignmentcxx . . $ Joystick_assignment# *assignment, const char *buffer)
469 {
470 memsetcxx . . $ memset(d1de1e4fb215f1c6).(assignment, 0, sizeof(*assignment));
471
472 char axis = 0, direction = 0;
473
474 if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(buffer, " AX %d%c", &assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num., &direction) == 2)
475 assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = AXIScxx . . $ AXIS.;
476 else if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(buffer, " BTN %d", &assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num.) == 1)
477 assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = BUTTONcxx . . $ BUTTON.;
478 else if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(buffer, " H %d%c%c", &assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num., &axis, &direction) == 3)
479 assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = HATcxx . . $ HAT.;
480
481 if (assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. == 0)
482 assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = NONEcxx . . $ NONE.;
483 else
484 --assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num.;
485
486 assignment->x_axiscxx . . $ $anonymous_type_abd17893024d7112_1#x_axis. = (touppercxx . . $ `<external>/17904084882347303253/ctype.h:221:11`!(axis) == 'X');
487 assignment->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. = (touppercxx . . $ `<external>/17904084882347303253/ctype.h:221:11`!(direction) == '-');
488 }
489
490 /* gives the short (6 or less characters) identifier for a joystick assignment
491 *
492 * two of these per direction/action is all that can fit on the joystick config screen,
493 * assuming two digits for the axis/button/hat number
494 */
495 const char *assignment_to_codecxx . . $ assignment_to_code(6d7bebc2f642d6a3).(const Joystick_assignmentcxx . . $ Joystick_assignment# *assignment)
496 {
497 static char name[7];
498
499 switch (assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type.)
500 {
501 case NONEcxx . . $ NONE.:
502 strcpycxx . . $ strcpy(b7b3a83273496486).(name, "");
503 break;
504
505 case AXIScxx . . $ AXIS.:
506 snprintfcxx . . $ snprintf(ea502d73e74c754c).(name, sizeof(name), "AX %d%c",
507 assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. + 1,
508 assignment->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. ? '-' : '+');
509 break;
510
511 case BUTTONcxx . . $ BUTTON.:
512 snprintfcxx . . $ snprintf(ea502d73e74c754c).(name, sizeof(name), "BTN %d",
513 assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. + 1);
514 break;
515
516 case HATcxx . . $ HAT.:
517 snprintfcxx . . $ snprintf(ea502d73e74c754c).(name, sizeof(name), "H %d%c%c",
518 assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. + 1,
519 assignment->x_axiscxx . . $ $anonymous_type_abd17893024d7112_1#x_axis. ? 'X' : 'Y',
520 assignment->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. ? '-' : '+');
521 break;
522 }
523
524 return name;
525 }
526
527 // captures joystick input for configuring assignments
528 // returns false if non-joystick input was detected
529 // TODO: input from joystick other than the one being configured probably should not be ignored
530 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! detect_joystick_assignmentcxx . . $ detect_joystick_assignment(8994ef2eb854becc).(int j, Joystick_assignmentcxx . . $ Joystick_assignment# *assignment)
531 {
532 // get initial joystick state to compare against to see if anything was pressed
533
534 const int axes = SDL_JoystickNumAxescxx . . $ SDL_JoystickNumAxes(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.);
535 Sint16cxx . . $ Sint16# *axis = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(axes * sizeof(*axis));
536 for (int i = 0; i < axes; i++)
537 axis[i] = SDL_JoystickGetAxiscxx . . $ SDL_JoystickGetAxis(f217c576919a4e9b).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., i);
538
539 const int buttons = SDL_JoystickNumButtonscxx . . $ SDL_JoystickNumButtons(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.);
540 Uint8cxx . . $ Uint8# *button = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(buttons * sizeof(*button));
541 for (int i = 0; i < buttons; i++)
542 button[i] = SDL_JoystickGetButtoncxx . . $ SDL_JoystickGetButton(cd1bab72d9aa38cc).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., i);
543
544 const int hats = SDL_JoystickNumHatscxx . . $ SDL_JoystickNumHats(15e1a858cc05ed36).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle.);
545 Uint8cxx . . $ Uint8# *hat = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(hats * sizeof(*hat));
546 for (int i = 0; i < hats; i++)
547 hat[i] = SDL_JoystickGetHatcxx . . $ SDL_JoystickGetHat(cd1bab72d9aa38cc).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., i);
548
549 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! detected = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
550
551 do
552 {
553 setDelaycxx . . $ setDelay(d4f767463ce0a6b3).(1);
554
555 SDL_JoystickUpdatecxx . . $ SDL_JoystickUpdate(49f6e7a06ebc5aa8).();
556
557 for (int i = 0; i < axes; ++i)
558 {
559 Sint16cxx . . $ Sint16# temp = SDL_JoystickGetAxiscxx . . $ SDL_JoystickGetAxis(f217c576919a4e9b).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., i);
560
561 if (abscxx . . $ abs(7864480464b09eea).(temp - axis[i]) > joystick_analog_maxcxx . . $ joystick_analog_max. * 2 / 3)
562 {
563 assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = AXIScxx . . $ AXIS.;
564 assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. = i;
565 assignment->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. = temp < axis[i];
566 detected = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
567 break;
568 }
569 }
570
571 for (int i = 0; i < buttons; ++i)
572 {
573 Uint8cxx . . $ Uint8# new_button = SDL_JoystickGetButtoncxx . . $ SDL_JoystickGetButton(cd1bab72d9aa38cc).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., i),
574 changed = button[i] ^ new_button;
575
576 if (!changed)
577 continue;
578
579 if (new_button == 0) // button was released
580 {
581 button[i] = new_button;
582 }
583 else // button was pressed
584 {
585 assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = BUTTONcxx . . $ BUTTON.;
586 assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. = i;
587 detected = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
588 break;
589 }
590 }
591
592 for (int i = 0; i < hats; ++i)
593 {
594 Uint8cxx . . $ Uint8# new_hat = SDL_JoystickGetHatcxx . . $ SDL_JoystickGetHat(cd1bab72d9aa38cc).(joystickcxx . . $ joystick.[j].handlecxx . . $ $anonymous_type_abd17893024d7112_2#handle., i),
595 changed = hat[i] ^ new_hat;
596
597 if (!changed)
598 continue;
599
600 if ((new_hat & changed) == SDL_HAT_CENTEREDcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:881:9`!) // hat was centered
601 {
602 hat[i] = new_hat;
603 }
604 else
605 {
606 assignment->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. = HATcxx . . $ HAT.;
607 assignment->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. = i;
608 assignment->x_axiscxx . . $ $anonymous_type_abd17893024d7112_1#x_axis. = changed & (SDL_HAT_LEFTcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:885:9`! | SDL_HAT_RIGHTcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:883:9`!);
609 assignment->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. = changed & (SDL_HAT_LEFTcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:885:9`! | SDL_HAT_UPcxx . . $ `<external>/17049259561641565683/SDL_joystick.h:882:9`!);
610 detected = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
611 }
612 }
613
614 service_SDL_eventscxx . . $ service_SDL_events(b45ddcbc8423892c).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!);
615 JE_showVGAcxx . . $ JE_showVGA(49f6e7a06ebc5aa8).();
616
617 wait_delaycxx . . $ wait_delay(49f6e7a06ebc5aa8).();
618 } while (!detected && !newkeycxx . . $ newkey. && !newmousecxx . . $ newmouse.);
619
620 freecxx . . $ free(5d22bdacc48458e8).(axis);
621 freecxx . . $ free(5d22bdacc48458e8).(button);
622 freecxx . . $ free(5d22bdacc48458e8).(hat);
623
624 return detected;
625 }
626
627 // compares relevant parts of joystick assignments for equality
628 boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! joystick_assignment_cmpcxx . . $ joystick_assignment_cmp(168eefc3be700665).(const Joystick_assignmentcxx . . $ Joystick_assignment# *a, const Joystick_assignmentcxx . . $ Joystick_assignment# *b)
629 {
630 if (a->typecxx . . $ $anonymous_type_abd17893024d7112_1#type. == b->typecxx . . $ $anonymous_type_abd17893024d7112_1#type.)
631 {
632 switch (a->typecxx . . $ $anonymous_type_abd17893024d7112_1#type.)
633 {
634 case NONEcxx . . $ NONE.:
635 return truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!;
636 case AXIScxx . . $ AXIS.:
637 return (a->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. == b->numcxx . . $ $anonymous_type_abd17893024d7112_1#num.) &&
638 (a->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. == b->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis.);
639 case BUTTONcxx . . $ BUTTON.:
640 return (a->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. == b->numcxx . . $ $anonymous_type_abd17893024d7112_1#num.);
641 case HATcxx . . $ HAT.:
642 return (a->numcxx . . $ $anonymous_type_abd17893024d7112_1#num. == b->numcxx . . $ $anonymous_type_abd17893024d7112_1#num.) &&
643 (a->x_axiscxx . . $ $anonymous_type_abd17893024d7112_1#x_axis. == b->x_axiscxx . . $ $anonymous_type_abd17893024d7112_1#x_axis.) &&
644 (a->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis. == b->negative_axiscxx . . $ $anonymous_type_abd17893024d7112_1#negative_axis.);
645 }
646 }
647
648 return falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!;
649 }