1 |
|
/* |
2 |
|
* C64_Be.h - Put the pieces together, Be specific stuff |
3 |
|
* |
4 |
< |
* Frodo (C) 1994-1997,2002 Christian Bauer |
4 |
> |
* Frodo (C) 1994-1997,2002-2003 Christian Bauer |
5 |
|
* |
6 |
|
* This program is free software; you can redistribute it and/or modify |
7 |
|
* it under the terms of the GNU General Public License as published by |
20 |
|
|
21 |
|
#include <KernelKit.h> |
22 |
|
#include <device/Joystick.h> |
23 |
+ |
#include <device/DigitalPort.h> |
24 |
|
|
25 |
|
#undef PROFILING |
26 |
|
|
31 |
|
|
32 |
|
void C64::c64_ctor1(void) |
33 |
|
{ |
34 |
< |
joy[0] = new BJoystick(); |
35 |
< |
joy[1] = new BJoystick(); |
34 |
> |
joy[0] = joy[1] = NULL; |
35 |
> |
joy_geek_port[0] = joy_geek_port[1] = false; |
36 |
|
} |
37 |
|
|
38 |
|
void C64::c64_ctor2(void) |
58 |
|
{ |
59 |
|
delete_sem(pause_sem); |
60 |
|
delete_sem(sound_sync_sem); |
60 |
– |
|
61 |
– |
delete joy[0]; |
62 |
– |
delete joy[1]; |
61 |
|
} |
62 |
|
|
63 |
|
|
222 |
|
* joystick preferences |
223 |
|
*/ |
224 |
|
|
225 |
< |
void C64::open_close_joysticks(bool oldjoy1, bool oldjoy2, bool newjoy1, bool newjoy2) |
225 |
> |
void C64::open_close_joystick(int port, int oldjoy, int newjoy) |
226 |
|
{ |
227 |
< |
if (oldjoy1 != newjoy1) { |
227 |
> |
if (oldjoy != newjoy) { |
228 |
|
joy_minx = joy_miny = 32767; // Reset calibration |
229 |
|
joy_maxx = joy_maxy = 0; |
230 |
< |
if (newjoy1) |
231 |
< |
joy[0]->Open("joystick2"); |
232 |
< |
else |
233 |
< |
joy[0]->Close(); |
230 |
> |
if (joy[port]) { |
231 |
> |
if (joy_geek_port[port]) { |
232 |
> |
((BDigitalPort *)joy[port])->Close(); |
233 |
> |
delete (BDigitalPort *)joy[port]; |
234 |
> |
} else { |
235 |
> |
((BJoystick *)joy[port])->Close(); |
236 |
> |
delete (BJoystick *)joy[port]; |
237 |
> |
} |
238 |
> |
joy[port] = NULL; |
239 |
> |
} |
240 |
> |
switch (newjoy) { |
241 |
> |
case 1: |
242 |
> |
joy[port] = new BJoystick; |
243 |
> |
((BJoystick *)joy[port])->Open("joystick1"); |
244 |
> |
joy_geek_port[port] = false; |
245 |
> |
break; |
246 |
> |
case 2: |
247 |
> |
joy[port] = new BJoystick; |
248 |
> |
((BJoystick *)joy[port])->Open("joystick2"); |
249 |
> |
joy_geek_port[port] = false; |
250 |
> |
break; |
251 |
> |
case 3: |
252 |
> |
joy[port] = new BDigitalPort; |
253 |
> |
((BDigitalPort *)joy[port])->Open("DigitalA"); |
254 |
> |
joy_geek_port[port] = true; |
255 |
> |
break; |
256 |
> |
case 4: |
257 |
> |
joy[port] = new BDigitalPort; |
258 |
> |
((BDigitalPort *)joy[port])->Open("DigitalB"); |
259 |
> |
joy_geek_port[port] = true; |
260 |
> |
break; |
261 |
> |
} |
262 |
|
} |
263 |
+ |
} |
264 |
|
|
265 |
< |
if (oldjoy2 != newjoy2) { |
266 |
< |
joy_minx = joy_miny = 32767; // Reset calibration |
267 |
< |
joy_maxx = joy_maxy = 0; |
268 |
< |
if (newjoy2) |
242 |
< |
joy[1]->Open("joystick1"); |
243 |
< |
else |
244 |
< |
joy[1]->Close(); |
245 |
< |
} |
265 |
> |
void C64::open_close_joysticks(int oldjoy1, int oldjoy2, int newjoy1, int newjoy2) |
266 |
> |
{ |
267 |
> |
open_close_joystick(0, oldjoy1, newjoy1); |
268 |
> |
open_close_joystick(1, oldjoy2, newjoy2); |
269 |
|
} |
270 |
|
|
271 |
|
|
277 |
|
{ |
278 |
|
uint8 j = 0xff; |
279 |
|
|
280 |
< |
if (joy[port]->Update() != B_ERROR) { |
281 |
< |
if (joy[port]->horizontal > joy_maxx) |
282 |
< |
joy_maxx = joy[port]->horizontal; |
283 |
< |
if (joy[port]->horizontal < joy_minx) |
284 |
< |
joy_minx = joy[port]->horizontal; |
285 |
< |
if (joy[port]->vertical > joy_maxy) |
286 |
< |
joy_maxy = joy[port]->vertical; |
287 |
< |
if (joy[port]->vertical < joy_miny) |
288 |
< |
joy_miny = joy[port]->vertical; |
289 |
< |
|
290 |
< |
if (!joy[port]->button1) |
291 |
< |
j &= 0xef; // Button |
292 |
< |
|
293 |
< |
if (joy_maxx-joy_minx < 100 || joy_maxy-joy_miny < 100) |
294 |
< |
return j; |
295 |
< |
|
296 |
< |
if (joy[port]->horizontal < (joy_minx + (joy_maxx-joy_minx)/3)) |
297 |
< |
j &= 0xf7; // Right |
298 |
< |
else if (joy[port]->horizontal > (joy_minx + 2*(joy_maxx-joy_minx)/3)) |
299 |
< |
j &= 0xfb; // Left |
300 |
< |
|
301 |
< |
if (joy[port]->vertical < (joy_miny + (joy_maxy-joy_miny)/3)) |
302 |
< |
j &= 0xfd; // Down |
303 |
< |
else if (joy[port]->vertical > (joy_miny + 2*(joy_maxy-joy_miny)/3)) |
304 |
< |
j &= 0xfe; // Up |
280 |
> |
if (joy[port] == NULL) |
281 |
> |
return j; |
282 |
> |
|
283 |
> |
if (joy_geek_port[port]) { |
284 |
> |
|
285 |
> |
// GeekPort |
286 |
> |
uint8 val; |
287 |
> |
if (((BDigitalPort *)joy[port])->Read(&val) == 1) |
288 |
> |
j = val | 0xe0; |
289 |
> |
|
290 |
> |
} else { |
291 |
> |
|
292 |
> |
// Joystick port |
293 |
> |
BJoystick *p = (BJoystick *)joy[port]; |
294 |
> |
if (p->Update() != B_ERROR) { |
295 |
> |
if (p->horizontal > joy_maxx) |
296 |
> |
joy_maxx = p->horizontal; |
297 |
> |
if (p->horizontal < joy_minx) |
298 |
> |
joy_minx = p->horizontal; |
299 |
> |
if (p->vertical > joy_maxy) |
300 |
> |
joy_maxy = p->vertical; |
301 |
> |
if (p->vertical < joy_miny) |
302 |
> |
joy_miny = p->vertical; |
303 |
> |
|
304 |
> |
if (!p->button1) |
305 |
> |
j &= 0xef; // Button |
306 |
> |
|
307 |
> |
if (joy_maxx-joy_minx < 100 || joy_maxy-joy_miny < 100) |
308 |
> |
return j; |
309 |
> |
|
310 |
> |
if (p->horizontal < (joy_minx + (joy_maxx-joy_minx)/3)) |
311 |
> |
j &= 0xf7; // Right |
312 |
> |
else if (p->horizontal > (joy_minx + 2*(joy_maxx-joy_minx)/3)) |
313 |
> |
j &= 0xfb; // Left |
314 |
> |
|
315 |
> |
if (p->vertical < (joy_miny + (joy_maxy-joy_miny)/3)) |
316 |
> |
j &= 0xfd; // Down |
317 |
> |
else if (p->vertical > (joy_miny + 2*(joy_maxy-joy_miny)/3)) |
318 |
> |
j &= 0xfe; // Up |
319 |
> |
} |
320 |
|
} |
321 |
|
return j; |
322 |
|
} |