Debian Codegraph @

mednafen/pce_fast/input.cpp

raw symbols SCIP
1 /* Mednafen - Multi-system Emulator
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18 #include "pce.h"cxx . . $ `<file>/mednafen/pce_fast/pce.h`/
19 #include "input.h"cxx . . $ `<file>/mednafen/pce_fast/input.h`/
20 #include "huc.h"cxx . . $ `<file>/mednafen/pce_fast/huc.h`/
21 #include "../mednafen-endian.h"cxx . . $ `<file>/mednafen/mednafen-endian.h`/
22
23 static int InputTypescxx . . $ InputTypes.[5];
24 static uint8cxx . . $ uint8# *data_ptrcxx . . $ data_ptr.[5];
25
26 static bool AVPad6Whichcxx . . $ AVPad6Which.[5]; // Lower(8 buttons) or higher(4 buttons).
27 static bool AVPad6Enabledcxx . . $ AVPad6Enabled.[5];
28
29 uint16cxx . . $ uint16# pce_jp_datacxx . . $ pce_jp_data.[5];
30
31 static int64cxx . . $ int64# mouse_last_meowcxx . . $ mouse_last_meow.[5];
32
33 static int32cxx . . $ int32# mouse_xcxx . . $ mouse_x.[5], mouse_ycxx . . $ mouse_y.[5];
34 static uint16cxx . . $ uint16# mouse_relcxx . . $ mouse_rel.[5];
35
36 uint8cxx . . $ uint8# pce_mouse_buttoncxx . . $ pce_mouse_button.[5];
37 uint8cxx . . $ uint8# mouse_indexcxx . . $ mouse_index.[5];
38
39 static uint8cxx . . $ uint8# selcxx . . $ sel.;
40 static uint8cxx . . $ uint8# read_indexcxx . . $ read_index. = 0;
41
42 static void SyncSettingscxx . . $ SyncSettings(49f6e7a06ebc5aa8).(void);
43
44 void PCEINPUT_SettingChangedcxx . . $ PCEINPUT_SettingChanged(85c52e162fed56f9).(const char *name)
45 {
46 SyncSettingscxx . . $ SyncSettings(49f6e7a06ebc5aa8).();
47 }
48
49 void PCEINPUT_Initcxx . . $ PCEINPUT_Init(49f6e7a06ebc5aa8).(void)
50 {
51 SyncSettingscxx . . $ SyncSettings(49f6e7a06ebc5aa8).();
52 }
53
54 void PCEINPUT_SetInputcxx . . $ PCEINPUT_SetInput(d29b3d01ccfd77ca).(int port, const char *type, void *ptr)
55 {
56 assertcxx . . $ `<external>/4398592474888995393/assert.h:102:11`!(port < 5);
57
58 if(!strcasecmp(type, "gamepad"))
59 InputTypescxx . . $ InputTypes.[port] = 1;
60 else if(!strcasecmp(type, "mouse"))
61 InputTypescxx . . $ InputTypes.[port] = 2;
62 else
63 InputTypescxx . . $ InputTypes.[port] = 0;
64 data_ptrcxx . . $ data_ptr.[port] = (uint8cxx . . $ uint8# *)ptr;
65 }
66
67 void INPUT_Framecxx . . $ INPUT_Frame(49f6e7a06ebc5aa8).(void)
68 {
69 unsigned x;
70
71 for(x = 0; x < 5; x++)
72 {
73 if(InputTypescxx . . $ InputTypes.[x] == 1)
74 {
75 uint16cxx . . $ uint16# new_data = data_ptrcxx . . $ data_ptr.[x][0] | (data_ptrcxx . . $ data_ptr.[x][1] << 8);
76
77 if((new_data & 0x1000) && !(pce_jp_datacxx . . $ pce_jp_data.[x] & 0x1000))
78 {
79 AVPad6Enabledcxx . . $ AVPad6Enabled.[x] = !AVPad6Enabledcxx . . $ AVPad6Enabled.[x];
80 MDFN_DispMessagecxx . . $ MDFN_DispMessage(326aeb464d16410c).("%d-button mode selected for pad %d", AVPad6Enabledcxx . . $ AVPad6Enabled.[x] ? 6 : 2, x + 1);
81 }
82
83 pce_jp_datacxx . . $ pce_jp_data.[x] = new_data;
84 }
85 else if(InputTypescxx . . $ InputTypes.[x] == 2)
86 {
87 mouse_xcxx . . $ mouse_x.[x] += (int32cxx . . $ int32#)MDFN_de32lsb(data_ptrcxx . . $ data_ptr.[x] + 0);
88 mouse_ycxx . . $ mouse_y.[x] += (int32cxx . . $ int32#)MDFN_de32lsb(data_ptrcxx . . $ data_ptr.[x] + 4);
89 pce_mouse_buttoncxx . . $ pce_mouse_button.[x] = *(uint8cxx . . $ uint8# *)(data_ptrcxx . . $ data_ptr.[x] + 8);
90 }
91 }
92 }
93
94 void INPUT_FixTScxx . . $ INPUT_FixTS(49f6e7a06ebc5aa8).(void)
95 {
96 unsigned x;
97
98 for(x = 0; x < 5; x++)
99 {
100 if(InputTypescxx . . $ InputTypes.[x] == 2)
101 mouse_last_meowcxx . . $ mouse_last_meow.[x] -= HuCPUcxx . . $ HuCPU..timestampcxx . . $ __HuC6280#timestamp.;
102 }
103 }
104
105 static INLINEcxx . . $ `mednafen/mednafen-types.h:21:11`! bool CheckLMcxx . . $ CheckLM(83c267b20bac841a).(int n)
106 {
107 if((int64cxx . . $ int64#)HuCPUcxx . . $ HuCPU..timestampcxx . . $ __HuC6280#timestamp. - mouse_last_meowcxx . . $ mouse_last_meow.[n] > 10000)
108 {
109 mouse_last_meowcxx . . $ mouse_last_meow.[n] = HuCPUcxx . . $ HuCPU..timestampcxx . . $ __HuC6280#timestamp.;
110
111 int32cxx . . $ int32# rel_x = (int32cxx . . $ int32#)((0-mouse_xcxx . . $ mouse_x.[n]));
112 int32cxx . . $ int32# rel_y = (int32cxx . . $ int32#)((0-mouse_ycxx . . $ mouse_y.[n]));
113
114 if(rel_x < -127) rel_x = -127;
115 if(rel_x > 127) rel_x = 127;
116 if(rel_y < -127) rel_y = -127;
117 if(rel_y > 127) rel_y = 127;
118
119 mouse_relcxx . . $ mouse_rel.[n] = ((rel_x & 0xF0) >> 4) | ((rel_x & 0x0F) << 4);
120 mouse_relcxx . . $ mouse_rel.[n] |= (((rel_y & 0xF0) >> 4) | ((rel_y & 0x0F) << 4)) << 8;
121
122 mouse_xcxx . . $ mouse_x.[n] += (int32cxx . . $ int32#)(rel_x);
123 mouse_ycxx . . $ mouse_y.[n] += (int32cxx . . $ int32#)(rel_y);
124
125 return(1);
126 }
127 return(0);
128 }
129
130 uint8cxx . . $ uint8# INPUT_Readcxx . . $ INPUT_Read(32407b39b2dfce37).(unsigned int A)
131 {
132 uint8cxx . . $ uint8# ret = 0xF;
133 int tmp_ri = read_indexcxx . . $ read_index.;
134
135 if(tmp_ri > 4)
136 ret ^= 0xF;
137 else
138 {
139 if(!InputTypescxx . . $ InputTypes.[tmp_ri])
140 ret ^= 0xF;
141 else if(InputTypescxx . . $ InputTypes.[tmp_ri] == 2) // Mouse
142 {
143 if(selcxx . . $ sel. & 1)
144 {
145 CheckLMcxx . . $ CheckLM(83c267b20bac841a).(tmp_ri);
146 ret ^= 0xF;
147 ret ^= mouse_relcxx . . $ mouse_rel.[tmp_ri] & 0xF;
148
149 mouse_relcxx . . $ mouse_rel.[tmp_ri] >>= 4;
150 }
151 else
152 {
153 if(pce_mouse_buttoncxx . . $ pce_mouse_button.[tmp_ri] & 1)
154 ret ^= 0x3; //pce_mouse_button[tmp_ri];
155
156 if(pce_mouse_buttoncxx . . $ pce_mouse_button.[tmp_ri] & 0x2)
157 ret ^= 0x8;
158 }
159 }
160 else
161 {
162 if(InputTypescxx . . $ InputTypes.[tmp_ri] == 1) // Gamepad
163 {
164 if(AVPad6Whichcxx . . $ AVPad6Which.[tmp_ri] && AVPad6Enabledcxx . . $ AVPad6Enabled.[tmp_ri])
165 {
166 if(selcxx . . $ sel. & 1)
167 ret ^= 0x0F;
168 else
169 ret ^= (pce_jp_datacxx . . $ pce_jp_data.[tmp_ri] >> 8) & 0x0F;
170 }
171 else
172 {
173 if(selcxx . . $ sel. & 1)
174 ret ^= (pce_jp_datacxx . . $ pce_jp_data.[tmp_ri] >> 4) & 0x0F;
175 else
176 ret ^= pce_jp_datacxx . . $ pce_jp_data.[tmp_ri] & 0x0F;
177 }
178 if(!(selcxx . . $ sel. & 1))
179 AVPad6Whichcxx . . $ AVPad6Which.[tmp_ri] = !AVPad6Whichcxx . . $ AVPad6Which.[tmp_ri];
180 }
181 }
182 }
183
184 if(!PCE_IsCDcxx . . $ PCE_IsCD.)
185 ret |= 0x80; // Set when CDROM is not attached
186
187 //ret |= 0x40; // PC Engine if set, TG16 if clear. Let's leave it clear, PC Engine games don't seem to mind if it's clear, but TG16 games barf if it's set.
188
189 ret |= 0x30; // Always-set?
190
191 return(ret);
192 }
193
194 void INPUT_Writecxx . . $ INPUT_Write(cc289a6b3dfc48da).(unsigned int A, uint8cxx . . $ uint8# V)
195 {
196 if((V & 1) && !(selcxx . . $ sel. & 2) && (V & 2))
197 read_indexcxx . . $ read_index. = 0;
198 else if((V & 1) && !(selcxx . . $ sel. & 1))
199 {
200 if(read_indexcxx . . $ read_index. < 255)
201 read_indexcxx . . $ read_index.++;
202 }
203 selcxx . . $ sel. = V & 3;
204 }
205
206 int INPUT_StateActioncxx . . $ INPUT_StateAction(a45b884b8cf568d5).(StateMemcxx . . $ StateMem# *sm, int load, int data_only)
207 {
208 SFORMATcxx . . $ SFORMAT# StateRegs[] =
209 {
210 // 0.8.A fix:
211 SFARRAYBcxx . . $ `mednafen/state.h:76:9`!(AVPad6Enabled, 5),
212 SFARRAYBcxx . . $ `mednafen/state.h:76:9`!(AVPad6Which, 5),
213
214 SFVARNcxx . . $ `mednafen/state.h:69:9`!(mouse_last_meow[0], "mlm_0"),
215 SFVARNcxx . . $ `mednafen/state.h:69:9`!(mouse_last_meow[1], "mlm_1"),
216 SFVARNcxx . . $ `mednafen/state.h:69:9`!(mouse_last_meow[2], "mlm_2"),
217 SFVARNcxx . . $ `mednafen/state.h:69:9`!(mouse_last_meow[3], "mlm_3"),
218 SFVARNcxx . . $ `mednafen/state.h:69:9`!(mouse_last_meow[4], "mlm_4"),
219
220 SFARRAY32cxx . . $ `mednafen/state.h:82:9`!(mouse_x, 5),
221 SFARRAY32cxx . . $ `mednafen/state.h:82:9`!(mouse_y, 5),
222 SFARRAY16cxx . . $ `mednafen/state.h:79:9`!(mouse_rel, 5),
223 SFARRAYcxx . . $ `mednafen/state.h:73:9`!(pce_mouse_button, 5),
224 SFARRAYcxx . . $ `mednafen/state.h:73:9`!(mouse_index, 5),
225 // end 0.8.A fix
226
227 SFARRAY16cxx . . $ `mednafen/state.h:79:9`!(pce_jp_data, 5),
228 SFVARcxx . . $ `mednafen/state.h:70:9`!(sel),
229 SFVARcxx . . $ `mednafen/state.h:70:9`!(read_index),
230 SFENDcxx . . $ `mednafen/state.h:94:9`!
231 };
232 int ret = MDFNSS_StateActioncxx . . $ MDFNSS_StateAction(3f628545d3b0df83).(sm, load, data_only, StateRegs, "JOY");
233
234 return(ret);
235 }
236
237 // GamepadIDII and GamepadIDII_DSR must be EXACTLY the same except for the RUN+SELECT exclusion in the latter.
238 static const InputDeviceInputInfoStructcxx . . $ InputDeviceInputInfoStruct# GamepadIDIIcxx . . $ GamepadIDII.[] =
239 {
240 { "i", "I", 12, IDIT_BUTTON_CAN_RAPIDcxx . . $ IDIT_BUTTON_CAN_RAPID., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
241 { "ii", "II", 11, IDIT_BUTTON_CAN_RAPIDcxx . . $ IDIT_BUTTON_CAN_RAPID., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
242 { "select", "SELECT", 4, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
243 { "run", "RUN", 5, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
244 { "up", "UP ↑", 0, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "down" },
245 { "right", "RIGHT →", 3, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "left" },
246 { "down", "DOWN ↓", 1, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "up" },
247 { "left", "LEFT ←", 2, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "right" },
248 { "iii", "III", 10, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
249 { "iv", "IV", 7, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
250 { "v", "V", 8, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
251 { "vi", "VI", 9, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
252 { "mode_select", "2/6 Mode Select", 6, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
253 };
254 static const InputDeviceInputInfoStructcxx . . $ InputDeviceInputInfoStruct# GamepadIDII_DSRcxx . . $ GamepadIDII_DSR.[] =
255 {
256 { "i", "I", 12, IDIT_BUTTON_CAN_RAPIDcxx . . $ IDIT_BUTTON_CAN_RAPID., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
257 { "ii", "II", 11, IDIT_BUTTON_CAN_RAPIDcxx . . $ IDIT_BUTTON_CAN_RAPID., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
258 { "select", "SELECT", 4, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "run" },
259 { "run", "RUN", 5, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "select" },
260 { "up", "UP ↑", 0, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "down" },
261 { "right", "RIGHT →", 3, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "left" },
262 { "down", "DOWN ↓", 1, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "up" },
263 { "left", "LEFT ←", 2, IDIT_BUTTONcxx . . $ IDIT_BUTTON., "right" },
264 { "iii", "III", 10, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
265 { "iv", "IV", 7, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
266 { "v", "V", 8, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
267 { "vi", "VI", 9, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
268 { "mode_select", "2/6 Mode Select", 6, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
269 };
270
271 static const InputDeviceInputInfoStructcxx . . $ InputDeviceInputInfoStruct# MouseIDIIcxx . . $ MouseIDII.[] =
272 {
273 { "x_axis", "X Axis", -1, IDIT_X_AXIS_RELcxx . . $ IDIT_X_AXIS_REL. },
274 { "y_axis", "Y Axis", -1, IDIT_Y_AXIS_RELcxx . . $ IDIT_Y_AXIS_REL. },
275 { "left", "Left Button", 0, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
276 { "right", "Right Button", 1, IDIT_BUTTONcxx . . $ IDIT_BUTTON., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`! },
277 };
278
279 // If we add more devices to this array, REMEMBER TO UPDATE the hackish array indexing in the SyncSettings() function
280 // below.
281 static InputDeviceInfoStructcxx . . $ InputDeviceInfoStruct# InputDeviceInfocxx . . $ InputDeviceInfo.[] =
282 {
283 // None
284 {
285 "none",
286 "none",
287 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
288 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
289 0,
290 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!
291 },
292
293 // Gamepad
294 {
295 "gamepad",
296 "Gamepad",
297 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
298 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
299 sizeof(GamepadIDIIcxx . . $ GamepadIDII.) / sizeof(InputDeviceInputInfoStructcxx . . $ InputDeviceInputInfoStruct#),
300 GamepadIDIIcxx . . $ GamepadIDII.,
301 },
302
303 // Mouse
304 {
305 "mouse",
306 "Mouse",
307 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
308 NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!,
309 sizeof(MouseIDIIcxx . . $ MouseIDII.) / sizeof(InputDeviceInputInfoStructcxx . . $ InputDeviceInputInfoStruct#),
310 MouseIDIIcxx . . $ MouseIDII.,
311 },
312
313 };
314
315 static const InputPortInfoStructcxx . . $ InputPortInfoStruct# PortInfocxx . . $ PortInfo.[] =
316 {
317 { "port1", "Port 1", sizeof(InputDeviceInfocxx . . $ InputDeviceInfo.) / sizeof(InputDeviceInfoStructcxx . . $ InputDeviceInfoStruct#), InputDeviceInfocxx . . $ InputDeviceInfo., "gamepad" },
318 { "port2", "Port 2", sizeof(InputDeviceInfocxx . . $ InputDeviceInfo.) / sizeof(InputDeviceInfoStructcxx . . $ InputDeviceInfoStruct#), InputDeviceInfocxx . . $ InputDeviceInfo., "gamepad" },
319 { "port3", "Port 3", sizeof(InputDeviceInfocxx . . $ InputDeviceInfo.) / sizeof(InputDeviceInfoStructcxx . . $ InputDeviceInfoStruct#), InputDeviceInfocxx . . $ InputDeviceInfo., "gamepad" },
320 { "port4", "Port 4", sizeof(InputDeviceInfocxx . . $ InputDeviceInfo.) / sizeof(InputDeviceInfoStructcxx . . $ InputDeviceInfoStruct#), InputDeviceInfocxx . . $ InputDeviceInfo., "gamepad" },
321 { "port5", "Port 5", sizeof(InputDeviceInfocxx . . $ InputDeviceInfo.) / sizeof(InputDeviceInfoStructcxx . . $ InputDeviceInfoStruct#), InputDeviceInfocxx . . $ InputDeviceInfo., "gamepad" },
322 };
323
324 InputInfoStructcxx . . $ InputInfoStruct# PCEInputInfocxx . . $ PCEInputInfo. =
325 {
326 sizeof(PortInfocxx . . $ PortInfo.) / sizeof(InputPortInfoStructcxx . . $ InputPortInfoStruct#),
327 PortInfocxx . . $ PortInfo.
328 };
329
330 static void SyncSettingscxx . . $ SyncSettings(49f6e7a06ebc5aa8).(void)
331 {
332 MDFNGameInfocxx . . $ MDFNGameInfo.->mouse_sensitivitycxx . . $ $anonymous_type_643ef407c229d02_12#mouse_sensitivity. = MDFN_GetSettingFcxx . . $ MDFN_GetSettingF(9a18bdb0e56c1bc2).("pce_fast.mouse_sensitivity");
333 InputDeviceInfocxx . . $ InputDeviceInfo.[1].IDIIcxx . . $ $anonymous_type_643ef407c229d02_6#IDII. = MDFN_GetSettingBcxx . . $ MDFN_GetSettingB(c5f7da30cbc0f4e9).("pce_fast.disable_softreset") ? GamepadIDII_DSRcxx . . $ GamepadIDII_DSR. : GamepadIDIIcxx . . $ GamepadIDII.;
334 }