Mercurial > repos > blastem
annotate io.c @ 1207:9d6f155732ed
Basic support for mapping an analog axis to functionality
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 26 Jan 2017 23:49:13 -0800 |
parents | a6ae693974e0 |
children | 95f5253e75c7 |
rev | line source |
---|---|
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
1 /* |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
2 Copyright 2013 Michael Pavone |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
3 This file is part of BlastEm. |
467
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
4 BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text. |
140af5509ce7
Added copyright notice to source files and added GPL license text in COPYING
Mike Pavone <pavone@retrodev.com>
parents:
451
diff
changeset
|
5 */ |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
6 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
7 #include <unistd.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
8 #include <fcntl.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
9 #include <sys/socket.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
10 #include <sys/un.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
11 #include <sys/types.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
12 #include <sys/stat.h> |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
13 #include <errno.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
14 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
15 #include <string.h> |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
16 #include <stdlib.h> |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
17 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 #include "io.h" |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 #include "blastem.h" |
1103
22e87b739ad6
WIP split of ROM loading/argument parsing from Genesis emulation code. Compiles and doesn't crash, but nothing works. Still a few too many globals as well.
Michael Pavone <pavone@retrodev.com>
parents:
1077
diff
changeset
|
20 #include "genesis.h" |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 #include "render.h" |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
22 #include "util.h" |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
24 #define CYCLE_NEVER 0xFFFFFFFF |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
25 #define MIN_POLL_INTERVAL 6840 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
26 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
27 const char * device_type_names[] = { |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
28 "SMS gamepad", |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
29 "3-button gamepad", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
30 "6-button gamepad", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
31 "Mega Mouse", |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
32 "Saturn Keyboard", |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
33 "Menacer", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
34 "Justifier", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
35 "Sega multi-tap", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
36 "EA 4-way Play cable A", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
37 "EA 4-way Play cable B", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
38 "Sega Parallel Transfer Board", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
39 "Generic Device", |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
40 "None" |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
41 }; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
42 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 enum { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 BIND_NONE, |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
45 BIND_UI, |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 BIND_GAMEPAD1, |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 BIND_GAMEPAD2, |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
48 BIND_GAMEPAD3, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
49 BIND_GAMEPAD4, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
50 BIND_GAMEPAD5, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
51 BIND_GAMEPAD6, |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
52 BIND_GAMEPAD7, |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
53 BIND_GAMEPAD8, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
54 BIND_MOUSE1, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
55 BIND_MOUSE2, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
56 BIND_MOUSE3, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
57 BIND_MOUSE4, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
58 BIND_MOUSE5, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
59 BIND_MOUSE6, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
60 BIND_MOUSE7, |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
61 BIND_MOUSE8 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 }; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 typedef enum { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 UI_DEBUG_MODE_INC, |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 UI_DEBUG_PAL_INC, |
444
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
437
diff
changeset
|
67 UI_ENTER_DEBUGGER, |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
68 UI_SAVE_STATE, |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
69 UI_SET_SPEED, |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
70 UI_NEXT_SPEED, |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
71 UI_PREV_SPEED, |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
72 UI_RELEASE_MOUSE, |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1197
diff
changeset
|
73 UI_TOGGLE_FULLSCREEN, |
444
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
437
diff
changeset
|
74 UI_EXIT |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 } ui_action; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
77 typedef enum { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
78 MOUSE_ABSOLUTE, //really only useful for menu ROM |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
79 MOUSE_RELATIVE, //for full screen |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
80 MOUSE_CAPTURE //for windowed mode |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
81 } mouse_modes; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
82 |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
83 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 typedef struct { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
85 io_port *port; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 uint8_t bind_type; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 uint8_t subtype_a; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 uint8_t subtype_b; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 uint8_t value; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 } keybinding; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 typedef struct { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 keybinding bindings[4]; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 uint8_t state; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } joydpad; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
97 typedef struct { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
98 keybinding positive; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
99 keybinding negative; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
100 int16_t value; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
101 } joyaxis; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
102 |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
103 typedef struct { |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
104 keybinding *buttons; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
105 joydpad *dpads; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
106 joyaxis *axes; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
107 uint32_t num_buttons; //number of entries in the buttons array, not necessarily the number of buttons on the device |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
108 uint32_t num_dpads; //number of entries in the dpads array, not necessarily the number of dpads on the device |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
109 uint32_t num_axes; //number of entries in the axes array, not necessarily the number of dpads on the device |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
110 } joystick; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
111 |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
112 typedef struct { |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
113 io_port *motion_port; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
114 keybinding buttons[MAX_MOUSE_BUTTONS]; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
115 uint8_t bind_type; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
116 } mousebinding; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
117 |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
118 #define DEFAULT_JOYBUTTON_ALLOC 12 |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
119 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
120 static sega_io *current_io; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
121 static keybinding *bindings[0x10000]; |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
122 static joystick joysticks[MAX_JOYSTICKS]; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
123 static mousebinding mice[MAX_MICE]; |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
124 static io_port *keyboard_port; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
127 static void do_bind(keybinding *binding, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
128 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
129 binding->bind_type = bind_type; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
130 binding->subtype_a = subtype_a; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
131 binding->subtype_b = subtype_b; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
132 binding->value = value; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
133 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
134 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
137 int bucket = keycode >> 15 & 0xFFFF; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 if (!bindings[bucket]) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
139 bindings[bucket] = malloc(sizeof(keybinding) * 0x8000); |
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
140 memset(bindings[bucket], 0, sizeof(keybinding) * 0x8000); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 } |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
142 int idx = keycode & 0x7FFF; |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
143 do_bind(bindings[bucket] + idx, bind_type, subtype_a, subtype_b, value); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 void bind_button(int joystick, int button, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 if (joystick >= MAX_JOYSTICKS) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 } |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
151 if (!joysticks[joystick].buttons) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
152 joysticks[joystick].num_buttons = button < DEFAULT_JOYBUTTON_ALLOC ? DEFAULT_JOYBUTTON_ALLOC : button + 1; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
153 joysticks[joystick].buttons = calloc(joysticks[joystick].num_buttons, sizeof(keybinding)); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
154 } else if (joysticks[joystick].num_buttons <= button) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
155 uint32_t old_capacity = joysticks[joystick].num_buttons; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
156 joysticks[joystick].num_buttons *= 2; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
157 joysticks[joystick].buttons = realloc(joysticks[joystick].buttons, sizeof(keybinding) * joysticks[joystick].num_buttons); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
158 memset(joysticks[joystick].buttons + old_capacity, 0, joysticks[joystick].num_buttons - old_capacity); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
160 do_bind(joysticks[joystick].buttons + button, bind_type, subtype_a, subtype_b, value); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 void bind_dpad(int joystick, int dpad, int direction, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 if (joystick >= MAX_JOYSTICKS) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
168 if (!joysticks[joystick].dpads) { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
169 //multiple D-pads/hats are not common, so don't allocate any extra space |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
170 joysticks[joystick].dpads = calloc(dpad+1, sizeof(joydpad)); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
171 joysticks[joystick].num_dpads = dpad+1; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
172 } else if (joysticks[joystick].num_dpads <= dpad) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
173 uint32_t old_capacity = joysticks[joystick].num_dpads; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
174 joysticks[joystick].num_dpads *= 2; |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
175 joysticks[joystick].dpads = realloc(joysticks[joystick].dpads, sizeof(joydpad) * joysticks[joystick].num_dpads); |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
176 memset(joysticks[joystick].dpads + old_capacity, 0, (joysticks[joystick].num_dpads - old_capacity) * sizeof(joydpad)); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 for (int i = 0; i < 4; i ++) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 if (dpadbits[i] & direction) { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
180 do_bind(joysticks[joystick].dpads[dpad].bindings + i, bind_type, subtype_a, subtype_b, value); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 break; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
186 void bind_axis(int joystick, int axis, int positive, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b, uint8_t value) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
187 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
188 if (joystick >= MAX_JOYSTICKS) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
189 return; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
190 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
191 if (!joysticks[joystick].axes) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
192 //typical gamepad has 4 axes |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
193 joysticks[joystick].num_axes = axis+1 > 4 ? axis+1 : 4; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
194 joysticks[joystick].axes = calloc(joysticks[joystick].num_axes, sizeof(joyaxis)); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
195 } else if (joysticks[joystick].num_axes <= axis) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
196 uint32_t old_capacity = joysticks[joystick].num_axes; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
197 joysticks[joystick].num_axes *= 2; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
198 joysticks[joystick].axes = realloc(joysticks[joystick].axes, sizeof(joyaxis) * joysticks[joystick].num_axes); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
199 memset(joysticks[joystick].axes + old_capacity, 0, (joysticks[joystick].num_axes - old_capacity) * sizeof(joyaxis)); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
200 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
201 if (positive) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
202 do_bind(&joysticks[joystick].axes[axis].positive, bind_type, subtype_a, subtype_b, value); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
203 } else { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
204 do_bind(&joysticks[joystick].axes[axis].negative, bind_type, subtype_a, subtype_b, value); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
205 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
206 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
207 |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
208 void reset_joystick_bindings(int joystick) |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
209 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
210 if (joystick >= MAX_JOYSTICKS) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
211 return; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
212 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
213 if (joysticks[joystick].buttons) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
214 for (int i = 0; i < joysticks[joystick].num_buttons; i++) |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
215 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
216 joysticks[joystick].buttons[i].bind_type = BIND_NONE; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
217 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
218 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
219 if (joysticks[joystick].dpads) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
220 for (int i = 0; i < joysticks[joystick].num_dpads; i++) |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
221 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
222 for (int dir = 0; dir < 4; dir++) |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
223 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
224 joysticks[joystick].dpads[i].bindings[dir].bind_type = BIND_NONE; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
225 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
226 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
227 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
228 if (joysticks[joystick].axes) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
229 for (int i = 0; i < joysticks[joystick].num_axes; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
230 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
231 joysticks[joystick].axes[i].positive.bind_type = BIND_NONE; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
232 joysticks[joystick].axes[i].negative.bind_type = BIND_NONE; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
233 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
234 } |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
235 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
236 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 #define GAMEPAD_BUTTON(PRI_SLOT, SEC_SLOT, VALUE) (PRI_SLOT << 12 | SEC_SLOT << 8 | VALUE) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 #define DPAD_UP GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x01) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 #define BUTTON_Z GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x01) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 #define DPAD_DOWN GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_TH1, 0x02) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 #define BUTTON_Y GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x02) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 #define DPAD_LEFT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x04) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 #define BUTTON_X GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x04) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 #define DPAD_RIGHT GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x08) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 #define BUTTON_MODE GAMEPAD_BUTTON(GAMEPAD_EXTRA, GAMEPAD_NONE, 0x08) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 #define BUTTON_A GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x10) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 #define BUTTON_B GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x10) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 #define BUTTON_START GAMEPAD_BUTTON(GAMEPAD_TH0, GAMEPAD_NONE, 0x20) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 #define BUTTON_C GAMEPAD_BUTTON(GAMEPAD_TH1, GAMEPAD_NONE, 0x20) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
252 #define PSEUDO_BUTTON_MOTION 0xFFFF |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
253 #define MOUSE_LEFT 1 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
254 #define MOUSE_RIGHT 2 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
255 #define MOUSE_MIDDLE 4 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
256 #define MOUSE_START 8 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
257 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 void bind_gamepad(int keycode, int gamepadnum, int button) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 { |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
260 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
261 if (gamepadnum < 1 || gamepadnum > 8) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 bind_key(keycode, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 void bind_button_gamepad(int joystick, int joybutton, int gamepadnum, int padbutton) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
270 if (gamepadnum < 1 || gamepadnum > 8) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 bind_button(joystick, joybutton, bind_type, padbutton >> 12, padbutton >> 8 & 0xF, padbutton & 0xFF); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 void bind_dpad_gamepad(int joystick, int dpad, uint8_t direction, int gamepadnum, int button) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
279 if (gamepadnum < 1 || gamepadnum > 8) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 bind_dpad(joystick, dpad, direction, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
286 void bind_axis_gamepad(int joystick, int axis, uint8_t positive, int gamepadnum, int button) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
287 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
288 if (gamepadnum < 1 || gamepadnum > 8) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
289 return; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
290 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
291 uint8_t bind_type = gamepadnum - 1 + BIND_GAMEPAD1; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
292 bind_axis(joystick, axis, positive, bind_type, button >> 12, button >> 8 & 0xF, button & 0xFF); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
293 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
294 |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
295 void bind_ui(int keycode, ui_action action, uint8_t param) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 { |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
297 bind_key(keycode, BIND_UI, action, 0, param); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 |
493
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
300 void bind_button_ui(int joystick, int joybutton, ui_action action, uint8_t param) |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
301 { |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
302 bind_button(joystick, joybutton, BIND_UI, action, 0, param); |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
303 } |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
304 |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
305 void bind_dpad_ui(int joystick, int dpad, uint8_t direction, ui_action action, uint8_t param) |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
306 { |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
307 bind_dpad(joystick, dpad, direction, BIND_UI, action, 0, param); |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
308 } |
36c080ece4ed
Add support for UI bindings on gamepad buttons and dpads
Mike Pavone <pavone@retrodev.com>
parents:
483
diff
changeset
|
309 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
310 void bind_axis_ui(int joystick, int axis, uint8_t positive, ui_action action, uint8_t param) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
311 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
312 bind_axis(joystick, axis, positive, BIND_UI, action, 0, param); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
313 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
314 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 void handle_binding_down(keybinding * binding) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 { |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
317 if (binding->bind_type >= BIND_GAMEPAD1 && binding->bind_type <= BIND_GAMEPAD8) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
319 if (binding->subtype_a <= GAMEPAD_EXTRA && binding->port) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
320 binding->port->input[binding->subtype_a] |= binding->value; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
322 if (binding->subtype_b <= GAMEPAD_EXTRA && binding->port) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
323 binding->port->input[binding->subtype_b] |= binding->value; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
326 else if (binding->bind_type >= BIND_MOUSE1 && binding->bind_type <= BIND_MOUSE8) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
327 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
328 if (binding->port) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
329 binding->port->input[0] |= binding->value; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
330 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
331 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
334 void store_key_event(uint16_t code) |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
335 { |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
336 if (keyboard_port && keyboard_port->device.keyboard.write_pos != keyboard_port->device.keyboard.read_pos) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
337 //there's room in the buffer, record this event |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
338 keyboard_port->device.keyboard.events[keyboard_port->device.keyboard.write_pos] = code; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
339 if (keyboard_port->device.keyboard.read_pos == 0xFF) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
340 //ring buffer was empty, update read_pos to indicate there is now data |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
341 keyboard_port->device.keyboard.read_pos = keyboard_port->device.keyboard.write_pos; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
342 } |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
343 keyboard_port->device.keyboard.write_pos = (keyboard_port->device.keyboard.write_pos + 1) & 7; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
344 } |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
345 } |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
346 |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
347 void handle_keydown(int keycode, uint8_t scancode) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
349 int bucket = keycode >> 15 & 0xFFFF; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 if (!bindings[bucket]) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 } |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
353 int idx = keycode & 0x7FFF; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 keybinding * binding = bindings[bucket] + idx; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 handle_binding_down(binding); |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
356 store_key_event(scancode); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 void handle_joydown(int joystick, int button) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 { |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
361 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 } |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
364 keybinding * binding = joysticks[joystick].buttons + button; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 handle_binding_down(binding); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
368 void handle_mousedown(int mouse, int button) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
369 { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
370 if (current_io->mouse_mode == MOUSE_CAPTURE && !current_io->mouse_captured) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
371 current_io->mouse_captured = 1; |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
372 render_relative_mouse(1); |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
373 return; |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
374 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
375 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
376 return; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
377 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
378 keybinding * binding = mice[mouse].buttons + button - 1; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
379 handle_binding_down(binding); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
380 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
381 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 uint8_t ui_debug_mode = 0; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 uint8_t ui_debug_pal = 0; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
385 int current_speed = 0; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
386 int num_speeds = 1; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
387 uint32_t * speeds = NULL; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
388 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 void handle_binding_up(keybinding * binding) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 switch(binding->bind_type) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 case BIND_GAMEPAD1: |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 case BIND_GAMEPAD2: |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
395 case BIND_GAMEPAD3: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
396 case BIND_GAMEPAD4: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
397 case BIND_GAMEPAD5: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
398 case BIND_GAMEPAD6: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
399 case BIND_GAMEPAD7: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
400 case BIND_GAMEPAD8: |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
401 if (binding->subtype_a <= GAMEPAD_EXTRA && binding->port) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
402 binding->port->input[binding->subtype_a] &= ~binding->value; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
404 if (binding->subtype_b <= GAMEPAD_EXTRA && binding->port) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
405 binding->port->input[binding->subtype_b] &= ~binding->value; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 break; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
408 case BIND_MOUSE1: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
409 case BIND_MOUSE2: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
410 case BIND_MOUSE3: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
411 case BIND_MOUSE4: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
412 case BIND_MOUSE5: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
413 case BIND_MOUSE6: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
414 case BIND_MOUSE7: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
415 case BIND_MOUSE8: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
416 if (binding->port) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
417 binding->port->input[0] &= ~binding->value; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
418 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
419 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 case BIND_UI: |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 switch (binding->subtype_a) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 case UI_DEBUG_MODE_INC: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
424 current_system->inc_debug_mode(current_system); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 break; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 case UI_DEBUG_PAL_INC: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
427 current_system->inc_debug_pal(current_system); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 break; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 case UI_ENTER_DEBUGGER: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
430 current_system->enter_debugger = 1; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 break; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
432 case UI_SAVE_STATE: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
433 current_system->save_state = QUICK_SAVE_SLOT+1; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
434 break; |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
435 case UI_NEXT_SPEED: |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
436 current_speed++; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
437 if (current_speed >= num_speeds) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
438 current_speed = 0; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
439 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
440 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
441 current_system->set_speed_percent(current_system, speeds[current_speed]); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
442 break; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
443 case UI_PREV_SPEED: |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
444 current_speed--; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
445 if (current_speed < 0) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
446 current_speed = num_speeds - 1; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
447 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
448 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
449 current_system->set_speed_percent(current_system, speeds[current_speed]); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
450 break; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
451 case UI_SET_SPEED: |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
452 if (binding->value < num_speeds) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
453 current_speed = binding->value; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
454 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
455 current_system->set_speed_percent(current_system, speeds[current_speed]); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
456 } else { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
457 printf("Setting speed to %d\n", speeds[current_speed]); |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
458 current_system->set_speed_percent(current_system, speeds[current_speed]); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
459 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
460 break; |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
461 case UI_RELEASE_MOUSE: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
462 if (current_io->mouse_captured) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
463 current_io->mouse_captured = 0; |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
464 render_relative_mouse(0); |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
465 } |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
466 break; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1197
diff
changeset
|
467 case UI_TOGGLE_FULLSCREEN: |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1197
diff
changeset
|
468 render_toggle_fullscreen(); |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1197
diff
changeset
|
469 break; |
444
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
437
diff
changeset
|
470 case UI_EXIT: |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
471 current_system->request_exit(current_system); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
472 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 break; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
478 void handle_keyup(int keycode, uint8_t scancode) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
480 int bucket = keycode >> 15 & 0xFFFF; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 if (!bindings[bucket]) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 } |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
484 int idx = keycode & 0x7FFF; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 keybinding * binding = bindings[bucket] + idx; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 handle_binding_up(binding); |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
487 store_key_event(0x100 | scancode); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 void handle_joyup(int joystick, int button) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 { |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
492 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 } |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
495 keybinding * binding = joysticks[joystick].buttons + button; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 handle_binding_up(binding); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value) |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 { |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
501 if (joystick >= MAX_JOYSTICKS || dpadnum >= joysticks[joystick].num_dpads) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 return; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 } |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
504 joydpad * dpad = joysticks[joystick].dpads + dpadnum; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 uint8_t newdown = (value ^ dpad->state) & value; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 uint8_t newup = ((~value) ^ (~dpad->state)) & (~value); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 dpad->state = value; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 for (int i = 0; i < 4; i++) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 if (newdown & dpadbits[i]) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 handle_binding_down(dpad->bindings + i); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 } else if(newup & dpadbits[i]) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 handle_binding_up(dpad->bindings + i); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
517 #define JOY_AXIS_THRESHOLD 2000 |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
518 |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
519 void handle_joy_axis(int joystick, int axis, int16_t value) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
520 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
521 if (joystick >= MAX_JOYSTICKS || axis >= joysticks[joystick].num_axes) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
522 return; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
523 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
524 joyaxis *jaxis = joysticks[joystick].axes + axis; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
525 int old_active = abs(jaxis->value) > JOY_AXIS_THRESHOLD; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
526 int new_active = abs(value) > JOY_AXIS_THRESHOLD; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
527 int old_pos = jaxis->value > 0; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
528 int new_pos = value > 0; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
529 jaxis->value = value; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
530 if (old_active && (!new_active || old_pos != new_pos)) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
531 //previously activated direction is no longer active |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
532 handle_binding_up(old_pos ? &jaxis->positive : &jaxis->negative); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
533 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
534 if (new_active && (!old_active || old_pos != new_pos)) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
535 //previously unactivated direction is now active |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
536 handle_binding_down(new_pos ? &jaxis->positive : &jaxis->negative); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
537 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
538 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
539 |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
540 void handle_mouseup(int mouse, int button) |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
541 { |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
542 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
543 return; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
544 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
545 keybinding * binding = mice[mouse].buttons + button - 1; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
546 handle_binding_up(binding); |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
547 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
548 |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
549 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay) |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
550 { |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
551 if (mouse >= MAX_MICE || !mice[mouse].motion_port) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
552 return; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
553 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
554 switch(current_io->mouse_mode) |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
555 { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
556 case MOUSE_ABSOLUTE: { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
557 float scale_x = 640.0 / ((float)render_width()); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
558 float scale_y = 480.0 / ((float)render_height()); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
559 float scale = scale_x > scale_y ? scale_y : scale_x; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
560 mice[mouse].motion_port->device.mouse.cur_x = x * scale_x; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
561 mice[mouse].motion_port->device.mouse.cur_y = y * scale_y; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
562 break; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
563 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
564 case MOUSE_RELATIVE: { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
565 mice[mouse].motion_port->device.mouse.cur_x += deltax; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
566 mice[mouse].motion_port->device.mouse.cur_y += deltay; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
567 break; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
568 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
569 case MOUSE_CAPTURE: { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
570 if (current_io->mouse_captured) { |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
571 mice[mouse].motion_port->device.mouse.cur_x += deltax; |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
572 mice[mouse].motion_port->device.mouse.cur_y += deltay; |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
573 } |
1197
9bc78bd89567
Minor cleanup to handle_mouse_moved
Michael Pavone <pavone@retrodev.com>
parents:
1194
diff
changeset
|
574 break; |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
575 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
576 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
577 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
578 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
579 int parse_binding_target(char * target, tern_node * padbuttons, tern_node *mousebuttons, int * ui_out, int * padnum_out, int * padbutton_out) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
580 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
581 const int gpadslen = strlen("gamepads."); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
582 const int mouselen = strlen("mouse."); |
796
41f73c76b978
Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
771
diff
changeset
|
583 if (!strncmp(target, "gamepads.", gpadslen)) { |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
584 if (target[gpadslen] >= '1' && target[gpadslen] <= '8') { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
585 int padnum = target[gpadslen] - '0'; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
586 int button = tern_find_int(padbuttons, target + gpadslen + 1, 0); |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
587 if (button) { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
588 *padnum_out = padnum; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
589 *padbutton_out = button; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
590 return BIND_GAMEPAD1; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
591 } else { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
592 if (target[gpadslen+1]) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
593 warning("Gamepad mapping string '%s' refers to an invalid button '%s'\n", target, target + gpadslen + 1); |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
594 } else { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
595 warning("Gamepad mapping string '%s' has no button component\n", target); |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
596 } |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
597 } |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
598 } else { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
599 warning("Gamepad mapping string '%s' refers to an invalid gamepad number %c\n", target, target[gpadslen]); |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
600 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
601 } else if(!strncmp(target, "mouse.", mouselen)) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
602 if (target[mouselen] >= '1' && target[mouselen] <= '8') { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
603 int mousenum = target[mouselen] - '0'; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
604 int button = tern_find_int(mousebuttons, target + mouselen + 1, 0); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
605 if (button) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
606 *padnum_out = mousenum; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
607 *padbutton_out = button; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
608 return BIND_MOUSE1; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
609 } else { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
610 if (target[mouselen+1]) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
611 warning("Mouse mapping string '%s' refers to an invalid button '%s'\n", target, target + mouselen + 1); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
612 } else { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
613 warning("Mouse mapping string '%s' has no button component\n", target); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
614 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
615 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
616 } else { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
617 warning("Gamepad mapping string '%s' refers to an invalid mouse number %c\n", target, target[mouselen]); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
618 } |
796
41f73c76b978
Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
771
diff
changeset
|
619 } else if(!strncmp(target, "ui.", strlen("ui."))) { |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
620 *padbutton_out = 0; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
621 if (!strcmp(target + 3, "vdp_debug_mode")) { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
622 *ui_out = UI_DEBUG_MODE_INC; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
623 } else if(!strcmp(target + 3, "vdp_debug_pal")) { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
624 *ui_out = UI_DEBUG_PAL_INC; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
625 } else if(!strcmp(target + 3, "enter_debugger")) { |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
626 *ui_out = UI_ENTER_DEBUGGER; |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
627 } else if(!strcmp(target + 3, "save_state")) { |
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
628 *ui_out = UI_SAVE_STATE; |
796
41f73c76b978
Fix some memory issues
=?UTF-8?q?Higor=20Eur=C3=ADpedes?= <heuripedes@gmail.com>
parents:
771
diff
changeset
|
629 } else if(!strncmp(target + 3, "set_speed.", strlen("set_speed."))) { |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
630 *ui_out = UI_SET_SPEED; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
631 *padbutton_out = atoi(target + 3 + strlen("set_speed.")); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
632 } else if(!strcmp(target + 3, "next_speed")) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
633 *ui_out = UI_NEXT_SPEED; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
634 } else if(!strcmp(target + 3, "prev_speed")) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
635 *ui_out = UI_PREV_SPEED; |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
636 } else if(!strcmp(target + 3, "release_mouse")) { |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
637 *ui_out = UI_RELEASE_MOUSE; |
1202
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1197
diff
changeset
|
638 } else if (!strcmp(target + 3, "toggle_fullscreen")) { |
a6ae693974e0
Allow toggling full screen mode at runtime. Allow resizing the window in windowed mode. Allow specifying the aspect ratio in the config file.
Michael Pavone <pavone@retrodev.com>
parents:
1197
diff
changeset
|
639 *ui_out = UI_TOGGLE_FULLSCREEN; |
444
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
437
diff
changeset
|
640 } else if(!strcmp(target + 3, "exit")) { |
cc754a309ead
Add fullscreen support and add a keybinding for exiting the emulator
Mike Pavone <pavone@retrodev.com>
parents:
437
diff
changeset
|
641 *ui_out = UI_EXIT; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
642 } else { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
643 warning("Unreconized UI binding type %s\n", target); |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
644 return 0; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
645 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
646 return BIND_UI; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
647 } else { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
648 warning("Unrecognized binding type %s\n", target); |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
649 } |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
650 return 0; |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
651 } |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
652 |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
653 void process_keys(tern_node * cur, tern_node * special, tern_node * padbuttons, tern_node *mousebuttons, char * prefix) |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
654 { |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
655 char * curstr = NULL; |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
656 int len; |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
657 if (!cur) { |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
658 return; |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
659 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
660 char onec[2]; |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
661 if (prefix) { |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
662 len = strlen(prefix); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
663 curstr = malloc(len + 2); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
664 memcpy(curstr, prefix, len); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
665 } else { |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
666 curstr = onec; |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
667 len = 0; |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
668 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
669 curstr[len] = cur->el; |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
670 curstr[len+1] = 0; |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
671 if (cur->el) { |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
672 process_keys(cur->straight.next, special, padbuttons, mousebuttons, curstr); |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
673 } else { |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
674 int keycode = tern_find_int(special, curstr, 0); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
675 if (!keycode) { |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
676 keycode = curstr[0]; |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
677 if (curstr[1] != 0) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
678 warning("%s is not recognized as a key identifier, truncating to %c\n", curstr, curstr[0]); |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
679 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
680 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
681 char * target = cur->straight.value.ptrval; |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
682 int ui_func, padnum, button; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
683 int bindtype = parse_binding_target(target, padbuttons, mousebuttons, &ui_func, &padnum, &button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
684 if (bindtype == BIND_GAMEPAD1) { |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
685 bind_gamepad(keycode, padnum, button); |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
686 } else if(bindtype == BIND_UI) { |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
687 bind_ui(keycode, ui_func, button); |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
688 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
689 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
690 process_keys(cur->left, special, padbuttons, mousebuttons, prefix); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
691 process_keys(cur->right, special, padbuttons, mousebuttons, prefix); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
692 if (curstr && len) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
693 free(curstr); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
694 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
695 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
696 |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
697 void process_speeds(tern_node * cur, char * prefix) |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
698 { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
699 char * curstr = NULL; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
700 int len; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
701 if (!cur) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
702 return; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
703 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
704 char onec[2]; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
705 if (prefix) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
706 len = strlen(prefix); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
707 curstr = malloc(len + 2); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
708 memcpy(curstr, prefix, len); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
709 } else { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
710 curstr = onec; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
711 len = 0; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
712 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
713 curstr[len] = cur->el; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
714 curstr[len+1] = 0; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
715 if (cur->el) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
716 process_speeds(cur->straight.next, curstr); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
717 } else { |
1005
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
718 char *end; |
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
719 long speed_index = strtol(curstr, &end, 10); |
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
720 if (speed_index < 0 || end == curstr || *end) { |
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
721 warning("%s is not a valid speed index", curstr); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
722 } else { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
723 if (speed_index >= num_speeds) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
724 speeds = realloc(speeds, sizeof(uint32_t) * (speed_index+1)); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
725 for(; num_speeds < speed_index + 1; num_speeds++) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
726 speeds[num_speeds] = 0; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
727 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
728 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
729 speeds[speed_index] = atoi(cur->straight.value.ptrval); |
1005
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
730 if (speeds[speed_index] < 1) { |
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
731 warning("%s is not a valid speed percentage, setting speed %d to 100", cur->straight.value.ptrval, speed_index); |
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
732 speeds[speed_index] = 100; |
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
733 } |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
734 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
735 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
736 process_speeds(cur->left, prefix); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
737 process_speeds(cur->right, prefix); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
738 if (curstr && len) { |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
739 free(curstr); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
740 } |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
741 } |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
742 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
743 void process_device(char * device_type, io_port * port) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
744 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
745 port->device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
746 if (!device_type) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
747 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
748 return; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
749 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
750 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
751 const int gamepad_len = strlen("gamepad"); |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
752 const int mouse_len = strlen("mouse"); |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
753 if (!strncmp(device_type, "gamepad", gamepad_len)) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
754 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
755 if ( |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
756 (device_type[gamepad_len] != '3' && device_type[gamepad_len] != '6' && device_type[gamepad_len] != '2') |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
757 || device_type[gamepad_len+1] != '.' || device_type[gamepad_len+2] < '1' |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
758 || device_type[gamepad_len+2] > '8' || device_type[gamepad_len+3] != 0 |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
759 ) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
760 warning("%s is not a valid gamepad type\n", device_type); |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
761 } else if (device_type[gamepad_len] == '3') { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
762 port->device_type = IO_GAMEPAD3; |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
763 } else if (device_type[gamepad_len] == '2') { |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
764 port->device_type = IO_GAMEPAD2; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
765 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
766 port->device_type = IO_GAMEPAD6; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
767 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
768 port->device.pad.gamepad_num = device_type[gamepad_len+2] - '1'; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
769 } else if(!strncmp(device_type, "mouse", mouse_len)) { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
770 port->device_type = IO_MOUSE; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
771 port->device.mouse.mouse_num = device_type[mouse_len+1] - '1'; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
772 port->device.mouse.last_read_x = 0; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
773 port->device.mouse.last_read_y = 0; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
774 port->device.mouse.cur_x = 0; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
775 port->device.mouse.cur_y = 0; |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
776 port->device.mouse.latched_x = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
777 port->device.mouse.latched_y = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
778 port->device.mouse.ready_cycle = CYCLE_NEVER; |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
779 port->device.mouse.tr_counter = 0; |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
780 } else if(!strcmp(device_type, "saturn keyboard")) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
781 port->device_type = IO_SATURN_KEYBOARD; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
782 port->device.keyboard.read_pos = 0xFF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
783 port->device.keyboard.write_pos = 0; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
784 } else if(!strcmp(device_type, "sega_parallel")) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
785 port->device_type = IO_SEGA_PARALLEL; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
786 port->device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
787 port->device.stream.listen_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
788 } else if(!strcmp(device_type, "generic")) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
789 port->device_type = IO_GENERIC; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
790 port->device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
791 port->device.stream.listen_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
792 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
793 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
794 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
795 char * io_name(int i) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
796 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
797 switch (i) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
798 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
799 case 0: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
800 return "1"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
801 case 1: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
802 return "2"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
803 case 2: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
804 return "EXT"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
805 default: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
806 return "invalid"; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
807 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
808 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
809 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
810 static char * sockfile_name; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
811 static void cleanup_sockfile() |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
812 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
813 unlink(sockfile_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
814 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
815 |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
816 void setup_io_devices(tern_node * config, rom_info *rom, sega_io *io) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
817 { |
1116
fe8c79f82c22
More cleanup in preparation for SMS/Mark III support
Michael Pavone <pavone@retrodev.com>
parents:
1111
diff
changeset
|
818 current_io = io; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
819 io_port * ports = current_io->ports; |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
820 tern_node *io_nodes = tern_get_node(tern_find_path(config, "io\0devices\0")); |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
821 char * io_1 = rom->port1_override ? rom->port1_override : tern_find_ptr(io_nodes, "1"); |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
822 char * io_2 = rom->port2_override ? rom->port2_override : tern_find_ptr(io_nodes, "2"); |
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
823 char * io_ext = rom->ext_override ? rom->ext_override : tern_find_ptr(io_nodes, "ext"); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
824 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
825 process_device(io_1, ports); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
826 process_device(io_2, ports+1); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
827 process_device(io_ext, ports+2); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
828 |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
829 if (render_fullscreen()) { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
830 current_io->mouse_mode = MOUSE_RELATIVE; |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
831 render_relative_mouse(1); |
916
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
832 } else { |
20c464dbae8f
Finished implementation of mouse capture mode
Michael Pavone <pavone@retrodev.com>
parents:
915
diff
changeset
|
833 if (rom->mouse_mode && !strcmp(rom->mouse_mode, "absolute")) { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
834 current_io->mouse_mode = MOUSE_ABSOLUTE; |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
835 } else { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
836 current_io->mouse_mode = MOUSE_CAPTURE; |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
837 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
838 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
839 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
840 for (int i = 0; i < 3; i++) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
841 { |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
842 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
843 if (ports[i].device_type == IO_SEGA_PARALLEL) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
844 { |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
845 char *pipe_name = tern_find_path(config, "io\0parallel_pipe\0").ptrval; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
846 if (!pipe_name) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
847 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
848 warning("IO port %s is configured to use the sega parallel board, but no paralell_pipe is set!\n", io_name(i)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
849 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
850 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
851 printf("IO port: %s connected to device '%s' with pipe name: %s\n", io_name(i), device_type_names[ports[i].device_type], pipe_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
852 if (!strcmp("stdin", pipe_name)) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
853 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
854 ports[i].device.stream.data_fd = STDIN_FILENO; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
855 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
856 if (mkfifo(pipe_name, 0666) && errno != EEXIST) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
857 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
858 warning("Failed to create fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
859 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
860 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
861 ports[i].device.stream.data_fd = open(pipe_name, O_NONBLOCK | O_RDONLY); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
862 if (ports[i].device.stream.data_fd == -1) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
863 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
864 warning("Failed to open fifo %s for Sega parallel board emulation: %d %s\n", pipe_name, errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
865 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
866 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
867 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
868 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
869 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
870 } else if (ports[i].device_type == IO_GENERIC) { |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
871 char *sock_name = tern_find_path(config, "io\0socket\0").ptrval; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
872 if (!sock_name) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
873 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
874 warning("IO port %s is configured to use generic IO, but no socket is set!\n", io_name(i)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
875 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
876 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
877 printf("IO port: %s connected to device '%s' with socket name: %s\n", io_name(i), device_type_names[ports[i].device_type], sock_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
878 ports[i].device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
879 ports[i].device.stream.listen_fd = socket(AF_UNIX, SOCK_STREAM, 0); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
880 size_t pathlen = strlen(sock_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
881 size_t addrlen = offsetof(struct sockaddr_un, sun_path) + pathlen + 1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
882 struct sockaddr_un *saddr = malloc(addrlen); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
883 saddr->sun_family = AF_UNIX; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
884 memcpy(saddr->sun_path, sock_name, pathlen+1); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
885 if (bind(ports[i].device.stream.listen_fd, (struct sockaddr *)saddr, addrlen)) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
886 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
887 warning("Failed to bind socket for IO Port %s to path %s: %d %s\n", io_name(i), sock_name, errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
888 goto cleanup_sock; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
889 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
890 if (listen(ports[i].device.stream.listen_fd, 1)) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
891 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
892 warning("Failed to listen on socket for IO Port %s: %d %s\n", io_name(i), errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
893 goto cleanup_sockfile; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
894 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
895 sockfile_name = sock_name; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
896 atexit(cleanup_sockfile); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
897 continue; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
898 cleanup_sockfile: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
899 unlink(sock_name); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
900 cleanup_sock: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
901 close(ports[i].device.stream.listen_fd); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
902 ports[i].device_type = IO_NONE; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
903 } |
883
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
796
diff
changeset
|
904 } else |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
905 #endif |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
906 if (ports[i].device_type == IO_GAMEPAD3 || ports[i].device_type == IO_GAMEPAD6 || ports[i].device_type == IO_GAMEPAD2) { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
907 printf("IO port %s connected to gamepad #%d with type '%s'\n", io_name(i), ports[i].device.pad.gamepad_num + 1, device_type_names[ports[i].device_type]); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
908 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
909 printf("IO port %s connected to device '%s'\n", io_name(i), device_type_names[ports[i].device_type]); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
910 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
911 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
912 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
913 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
914 void map_bindings(io_port *ports, keybinding *bindings, int numbindings) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
915 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
916 for (int i = 0; i < numbindings; i++) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
917 { |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
918 if (bindings[i].bind_type >= BIND_GAMEPAD1 && bindings[i].bind_type <= BIND_GAMEPAD8) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
919 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
920 int num = bindings[i].bind_type - BIND_GAMEPAD1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
921 for (int j = 0; j < 3; j++) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
922 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
923 if ((ports[j].device_type == IO_GAMEPAD3 |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
924 || ports[j].device_type == IO_GAMEPAD6 |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
925 || ports[j].device_type == IO_GAMEPAD2) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
926 && ports[j].device.pad.gamepad_num == num |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
927 ) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
928 { |
886
fb1f11fd0692
Clear out IO port input state when setting bindings. This fixes a bug where pressing start in the menu after returning to it only worked on the second try.
Michael Pavone <pavone@retrodev.com>
parents:
884
diff
changeset
|
929 memset(ports[j].input, 0, sizeof(ports[j].input)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
930 bindings[i].port = ports + j; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
931 break; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
932 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
933 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
934 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
935 else if (bindings[i].bind_type >= BIND_MOUSE1 && bindings[i].bind_type <= BIND_MOUSE8) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
936 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
937 int num = bindings[i].bind_type - BIND_MOUSE1; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
938 for (int j = 0; j < 3; j++) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
939 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
940 if (ports[j].device_type == IO_MOUSE && ports[j].device.mouse.mouse_num == num) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
941 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
942 memset(ports[j].input, 0, sizeof(ports[j].input)); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
943 bindings[i].port = ports + j; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
944 break; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
945 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
946 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
947 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
948 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
949 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
950 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
951 typedef struct { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
952 tern_node *padbuttons; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
953 tern_node *mousebuttons; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
954 int mouseidx; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
955 } pmb_state; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
956 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
957 void process_mouse_button(char *buttonstr, tern_val value, void *data) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
958 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
959 pmb_state *state = data; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
960 int buttonnum = atoi(buttonstr); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
961 if (buttonnum < 1 || buttonnum > MAX_MOUSE_BUTTONS) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
962 warning("Mouse button %s is out of the supported range of 1-8\n", buttonstr); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
963 return; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
964 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
965 buttonnum--; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
966 int ui_func, devicenum, button; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
967 int bindtype = parse_binding_target(value.ptrval, state->padbuttons, state->mousebuttons, &ui_func, &devicenum, &button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
968 switch (bindtype) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
969 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
970 case BIND_UI: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
971 mice[state->mouseidx].buttons[buttonnum].subtype_a = ui_func; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
972 break; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
973 case BIND_GAMEPAD1: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
974 mice[state->mouseidx].buttons[buttonnum].subtype_a = button >> 12; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
975 mice[state->mouseidx].buttons[buttonnum].subtype_b = button >> 8 & 0xF; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
976 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
977 break; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
978 case BIND_MOUSE1: |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
979 mice[state->mouseidx].buttons[buttonnum].value = button & 0xFF; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
980 break; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
981 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
982 if (bindtype != BIND_UI) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
983 bindtype += devicenum-1; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
984 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
985 mice[state->mouseidx].buttons[buttonnum].bind_type = bindtype; |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
986 |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
987 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
988 |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
989 void process_mouse(char *mousenum, tern_val value, void *data) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
990 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
991 tern_node **buttonmaps = data; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
992 tern_node *mousedef = tern_get_node(value); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
993 tern_node *padbuttons = buttonmaps[0]; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
994 tern_node *mousebuttons = buttonmaps[1]; |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
995 |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
996 if (!mousedef) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
997 warning("Binding for mouse %s is a scalar!\n", mousenum); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
998 return; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
999 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1000 int mouseidx = atoi(mousenum); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1001 if (mouseidx < 0 || mouseidx >= MAX_MICE) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1002 warning("Mouse numbers must be between 0 and %d, but %d is not\n", MAX_MICE, mouseidx); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1003 return; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1004 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1005 char *motion = tern_find_ptr(mousedef, "motion"); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1006 if (motion) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1007 int ui_func,devicenum,button; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1008 int bindtype = parse_binding_target(motion, padbuttons, mousebuttons, &ui_func, &devicenum, &button); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1009 if (bindtype != BIND_UI) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1010 bindtype += devicenum-1; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1011 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1012 if (button == PSEUDO_BUTTON_MOTION) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1013 mice[mouseidx].bind_type = bindtype; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1014 } else { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1015 warning("Mouse motion can't be bound to target %s\n", motion); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1016 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1017 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1018 tern_node *buttons = tern_get_node(tern_find_path(mousedef, "buttons\0\0")); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1019 if (buttons) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1020 pmb_state state = {padbuttons, mousebuttons, mouseidx}; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1021 tern_foreach(buttons, process_mouse_button, &state); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1022 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1023 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1024 |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1025 typedef struct { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1026 int padnum; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1027 tern_node *padbuttons; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1028 tern_node *mousebuttons; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1029 } pad_button_state; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1030 |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1031 void process_pad_button(char *key, tern_val val, void *data) |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1032 { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1033 pad_button_state *state = data; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1034 int hostpadnum = state->padnum; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1035 int ui_func, padnum, button; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1036 int bindtype = parse_binding_target(val.ptrval, state->padbuttons, state->mousebuttons, &ui_func, &padnum, &button); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1037 char *end; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1038 long hostbutton = strtol(key, &end, 10); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1039 if (*end) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1040 //key is not a valid base 10 integer |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1041 hostbutton = render_translate_input_name(hostpadnum, key, 0); |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1042 if (hostbutton < 0) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1043 if (hostbutton == RENDER_INVALID_NAME) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1044 warning("%s is not a valid gamepad input name\n", key); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1045 } else if (hostbutton == RENDER_NOT_MAPPED) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1046 warning("No mapping exists for input %s on gamepad %d\n", key, hostpadnum); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1047 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1048 return; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1049 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1050 if (hostbutton & RENDER_DPAD_BIT) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1051 if (bindtype == BIND_GAMEPAD1) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1052 bind_dpad_gamepad(hostpadnum, render_dpad_part(hostbutton), render_direction_part(hostbutton), padnum, button); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1053 } else { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1054 bind_dpad_ui(hostpadnum, render_dpad_part(hostbutton), render_direction_part(hostbutton), ui_func, button); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1055 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1056 return; |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1057 } else if (hostbutton & RENDER_AXIS_BIT) { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1058 if (bindtype == BIND_GAMEPAD1) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1059 bind_axis_gamepad(hostpadnum, render_axis_part(hostbutton), 1, padnum, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1060 } else { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1061 bind_axis_ui(hostpadnum, render_axis_part(hostbutton), 1, padnum, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1062 } |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1063 return; |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1064 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1065 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1066 if (bindtype == BIND_GAMEPAD1) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1067 bind_button_gamepad(hostpadnum, hostbutton, padnum, button); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1068 } else if (bindtype == BIND_UI) { |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1069 bind_button_ui(hostpadnum, hostbutton, ui_func, button); |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1070 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1071 } |
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1072 |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1073 void process_pad_axis(char *key, tern_val val, void *data) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1074 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1075 key = strdup(key); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1076 pad_button_state *state = data; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1077 int hostpadnum = state->padnum; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1078 int ui_func, padnum, button; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1079 int bindtype = parse_binding_target(val.ptrval, state->padbuttons, state->mousebuttons, &ui_func, &padnum, &button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1080 char *modifier = strchr(key, '.'); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1081 int positive = 1; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1082 if (modifier) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1083 *modifier = 0; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1084 modifier++; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1085 if (!strcmp("negative", modifier)) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1086 positive = 0; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1087 } else if(strcmp("positive", modifier)) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1088 warning("Invalid axis modifier %s for axis %s on pad %d\n", modifier, key, hostpadnum); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1089 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1090 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1091 char *end; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1092 long axis = strtol(key, &end, 10); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1093 if (*end) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1094 //key is not a valid base 10 integer |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1095 axis = render_translate_input_name(hostpadnum, key, 1); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1096 if (axis < 0) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1097 if (axis == RENDER_INVALID_NAME) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1098 warning("%s is not a valid gamepad input name\n", key); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1099 } else if (axis == RENDER_NOT_MAPPED) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1100 warning("No mapping exists for input %s on gamepad %d\n", key, hostpadnum); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1101 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1102 goto done; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1103 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1104 if (axis & RENDER_DPAD_BIT) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1105 if (bindtype == BIND_GAMEPAD1) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1106 bind_dpad_gamepad(hostpadnum, render_dpad_part(axis), render_direction_part(axis), padnum, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1107 } else { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1108 bind_dpad_ui(hostpadnum, render_dpad_part(axis), render_direction_part(axis), ui_func, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1109 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1110 goto done; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1111 } else if (axis & RENDER_AXIS_BIT) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1112 axis = render_axis_part(axis); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1113 } else { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1114 if (bindtype == BIND_GAMEPAD1) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1115 bind_button_gamepad(hostpadnum, axis, padnum, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1116 } else if (bindtype == BIND_UI) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1117 bind_button_ui(hostpadnum, axis, ui_func, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1118 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1119 goto done; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1120 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1121 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1122 if (bindtype == BIND_GAMEPAD1) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1123 bind_axis_gamepad(hostpadnum, axis, positive, padnum, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1124 } else { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1125 bind_axis_ui(hostpadnum, axis, positive, ui_func, button); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1126 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1127 done: |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1128 free(key); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1129 return; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1130 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1131 |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1132 static tern_node *get_pad_buttons() |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1133 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1134 static tern_node *padbuttons; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1135 if (!padbuttons) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1136 padbuttons = tern_insert_int(NULL, ".up", DPAD_UP); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1137 padbuttons = tern_insert_int(padbuttons, ".down", DPAD_DOWN); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1138 padbuttons = tern_insert_int(padbuttons, ".left", DPAD_LEFT); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1139 padbuttons = tern_insert_int(padbuttons, ".right", DPAD_RIGHT); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1140 padbuttons = tern_insert_int(padbuttons, ".a", BUTTON_A); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1141 padbuttons = tern_insert_int(padbuttons, ".b", BUTTON_B); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1142 padbuttons = tern_insert_int(padbuttons, ".c", BUTTON_C); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1143 padbuttons = tern_insert_int(padbuttons, ".x", BUTTON_X); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1144 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1145 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1146 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1147 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1148 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1149 return padbuttons; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1150 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1151 |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1152 static tern_node *get_mouse_buttons() |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1153 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1154 static tern_node *mousebuttons; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1155 if (!mousebuttons) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1156 mousebuttons = tern_insert_int(NULL, ".left", MOUSE_LEFT); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1157 mousebuttons = tern_insert_int(mousebuttons, ".middle", MOUSE_MIDDLE); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1158 mousebuttons = tern_insert_int(mousebuttons, ".right", MOUSE_RIGHT); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1159 mousebuttons = tern_insert_int(mousebuttons, ".start", MOUSE_START); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1160 mousebuttons = tern_insert_int(mousebuttons, ".motion", PSEUDO_BUTTON_MOTION); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1161 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1162 return mousebuttons; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1163 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1164 |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1165 void handle_joy_added(int joystick) |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1166 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1167 if (joystick > MAX_JOYSTICKS) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1168 return; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1169 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1170 tern_node * pads = tern_get_node(tern_find_path(config, "bindings\0pads\0")); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1171 if (pads) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1172 char numstr[11]; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1173 sprintf(numstr, "%d", joystick); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1174 tern_node * pad = tern_find_ptr(pads, numstr); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1175 if (pad) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1176 tern_node * dpad_node = tern_find_ptr(pad, "dpads"); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1177 if (dpad_node) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1178 for (int dpad = 0; dpad < 10; dpad++) |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1179 { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1180 numstr[0] = dpad + '0'; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1181 numstr[1] = 0; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1182 tern_node * pad_dpad = tern_find_ptr(dpad_node, numstr); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1183 char * dirs[] = {"up", "down", "left", "right"}; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1184 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1185 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1186 char * target = tern_find_ptr(pad_dpad, dirs[dir]); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1187 if (target) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1188 int ui_func, padnum, button; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1189 int bindtype = parse_binding_target(target, get_pad_buttons(), get_mouse_buttons(), &ui_func, &padnum, &button); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1190 if (bindtype == BIND_GAMEPAD1) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1191 bind_dpad_gamepad(joystick, dpad, dirnums[dir], padnum, button); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1192 } else if (bindtype == BIND_UI) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1193 bind_dpad_ui(joystick, dpad, dirnums[dir], ui_func, button); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1194 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1195 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1196 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1197 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1198 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1199 tern_node *button_node = tern_find_ptr(pad, "buttons"); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1200 if (button_node) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1201 pad_button_state state = { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1202 .padnum = joystick, |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1203 .padbuttons = get_pad_buttons(), |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1204 .mousebuttons = get_mouse_buttons() |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1205 }; |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1206 tern_foreach(button_node, process_pad_button, &state); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1207 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1208 tern_node *axes_node = tern_find_ptr(pad, "axes"); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1209 if (axes_node) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1210 pad_button_state state = { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1211 .padnum = joystick, |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1212 .padbuttons = get_pad_buttons(), |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1213 .mousebuttons = get_mouse_buttons() |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1214 }; |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1215 tern_foreach(axes_node, process_pad_axis, &state); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1216 } |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1217 if (current_io) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1218 if (joysticks[joystick].buttons) { |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1219 map_bindings(current_io->ports, joysticks[joystick].buttons, joysticks[joystick].num_buttons); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1220 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1221 if (joysticks[joystick].dpads) |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1222 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1223 for (uint32_t i = 0; i < joysticks[joystick].num_dpads; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1224 { |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1225 map_bindings(current_io->ports, joysticks[joystick].dpads[i].bindings, 4); |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1226 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1227 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1228 if (joysticks[joystick].axes) { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1229 for (uint32_t i = 0; i < joysticks[joystick].num_axes; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1230 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1231 map_bindings(current_io->ports, &joysticks[joystick].axes[i].positive, 1); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1232 map_bindings(current_io->ports, &joysticks[joystick].axes[i].negative, 1); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1233 } |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1234 } |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1235 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1236 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1237 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1238 |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1239 } |
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1240 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1241 void set_keybindings(sega_io *io) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1242 { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1243 static uint8_t already_done; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1244 if (already_done) { |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1245 map_all_bindings(io); |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1246 return; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1247 } |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1248 already_done = 1; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1249 io_port *ports = io->ports; |
431
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
1250 tern_node * special = tern_insert_int(NULL, "up", RENDERKEY_UP); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
1251 special = tern_insert_int(special, "down", RENDERKEY_DOWN); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
1252 special = tern_insert_int(special, "left", RENDERKEY_LEFT); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
1253 special = tern_insert_int(special, "right", RENDERKEY_RIGHT); |
440efd7d27a9
Read key bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
421
diff
changeset
|
1254 special = tern_insert_int(special, "enter", '\r'); |
1035
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1255 special = tern_insert_int(special, "space", ' '); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1256 special = tern_insert_int(special, "tab", '\t'); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1257 special = tern_insert_int(special, "backspace", '\b'); |
504
7b0df1aaf384
Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents:
493
diff
changeset
|
1258 special = tern_insert_int(special, "esc", RENDERKEY_ESC); |
1035
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1259 special = tern_insert_int(special, "delete", RENDERKEY_DEL); |
504
7b0df1aaf384
Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents:
493
diff
changeset
|
1260 special = tern_insert_int(special, "lshift", RENDERKEY_LSHIFT); |
7b0df1aaf384
Add support for left and right shift keys
Mike Pavone <pavone@retrodev.com>
parents:
493
diff
changeset
|
1261 special = tern_insert_int(special, "rshift", RENDERKEY_RSHIFT); |
1035
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1262 special = tern_insert_int(special, "lctrl", RENDERKEY_LCTRL); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1263 special = tern_insert_int(special, "rctrl", RENDERKEY_RCTRL); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1264 special = tern_insert_int(special, "lalt", RENDERKEY_LALT); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1265 special = tern_insert_int(special, "ralt", RENDERKEY_RALT); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1266 special = tern_insert_int(special, "home", RENDERKEY_HOME); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1267 special = tern_insert_int(special, "end", RENDERKEY_END); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1268 special = tern_insert_int(special, "pageup", RENDERKEY_PAGEUP); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1269 special = tern_insert_int(special, "pagedown", RENDERKEY_PAGEDOWN); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1270 special = tern_insert_int(special, "f1", RENDERKEY_F1); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1271 special = tern_insert_int(special, "f2", RENDERKEY_F2); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1272 special = tern_insert_int(special, "f3", RENDERKEY_F3); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1273 special = tern_insert_int(special, "f4", RENDERKEY_F4); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1274 special = tern_insert_int(special, "f5", RENDERKEY_F5); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1275 special = tern_insert_int(special, "f6", RENDERKEY_F6); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1276 special = tern_insert_int(special, "f7", RENDERKEY_F7); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1277 special = tern_insert_int(special, "f8", RENDERKEY_F8); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1278 special = tern_insert_int(special, "f9", RENDERKEY_F9); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1279 special = tern_insert_int(special, "f10", RENDERKEY_F10); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1280 special = tern_insert_int(special, "f11", RENDERKEY_F11); |
284d905ca582
Added support for binding a bunch more "special" keys
Michael Pavone <pavone@retrodev.com>
parents:
1028
diff
changeset
|
1281 special = tern_insert_int(special, "f12", RENDERKEY_F12); |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1282 special = tern_insert_int(special, "select", RENDERKEY_SELECT); |
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1283 special = tern_insert_int(special, "play", RENDERKEY_PLAY); |
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1284 special = tern_insert_int(special, "search", RENDERKEY_SEARCH); |
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1285 special = tern_insert_int(special, "back", RENDERKEY_BACK); |
451
b7c3b2d22858
Added support for saving savestates. Added gst savestate format test harness
Mike Pavone <pavone@retrodev.com>
parents:
444
diff
changeset
|
1286 |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1287 tern_node *padbuttons = get_pad_buttons(); |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
1288 |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1289 tern_node *mousebuttons = get_mouse_buttons(); |
1187
6a4503fad67e
Initial support for using SDL2 game controller mapping functionality
Michael Pavone <pavone@retrodev.com>
parents:
1146
diff
changeset
|
1290 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1291 tern_node * keys = tern_get_node(tern_find_path(config, "bindings\0keys\0")); |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1292 process_keys(keys, special, padbuttons, mousebuttons, NULL); |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1293 char numstr[] = "00"; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1294 tern_node * pads = tern_get_node(tern_find_path(config, "bindings\0pads\0")); |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1295 if (pads) { |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
1296 for (int i = 0; i < MAX_JOYSTICKS; i++) |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1297 { |
883
9f149f0e98b7
It is now possible to switch back and forth between the menu ROM and the game
Michael Pavone <pavone@retrodev.com>
parents:
796
diff
changeset
|
1298 |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1299 if (i < 10) { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1300 numstr[0] = i + '0'; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1301 numstr[1] = 0; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1302 } else { |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1303 numstr[0] = i/10 + '0'; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1304 numstr[1] = i%10 + '0'; |
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1305 } |
1194
1ad0ec7e3939
Make gamepad "semantic" mapping play nice with hotplug support
Michael Pavone <pavone@retrodev.com>
parents:
1187
diff
changeset
|
1306 |
432
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
1307 } |
18cde14e8c10
Read joystick bindings from config file
Mike Pavone <pavone@retrodev.com>
parents:
431
diff
changeset
|
1308 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1309 memset(mice, 0, sizeof(mice)); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1310 tern_node * mice = tern_get_node(tern_find_path(config, "bindings\0mice\0")); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1311 if (mice) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1312 tern_node *buttonmaps[2] = {padbuttons, mousebuttons}; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1313 tern_foreach(mice, process_mouse, buttonmaps); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1314 } |
766
1b2f8280ba81
WIP changes to support reading cart memory map from ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
745
diff
changeset
|
1315 tern_node * speed_nodes = tern_get_node(tern_find_path(config, "clocks\0speeds\0")); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1316 speeds = malloc(sizeof(uint32_t)); |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1317 speeds[0] = 100; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1318 process_speeds(speed_nodes, NULL); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1319 for (int i = 0; i < num_speeds; i++) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1320 { |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1321 if (!speeds[i]) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1322 warning("Speed index %d was not set to a valid percentage!", i); |
483
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1323 speeds[i] = 100; |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1324 } |
3e1573fa22cf
Implement turbo/slow motion feature that overclocks or underclocks the entire system at the push of a button
Mike Pavone <pavone@retrodev.com>
parents:
467
diff
changeset
|
1325 } |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1326 map_all_bindings(io); |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
1327 } |
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
1328 |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1329 void map_all_bindings(sega_io *io) |
884
252dfd29831d
Selecting a second game from the menu now works
Michael Pavone <pavone@retrodev.com>
parents:
883
diff
changeset
|
1330 { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1331 current_io = io; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1332 io_port *ports = io->ports; |
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1333 |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1334 for (int bucket = 0; bucket < 0x10000; bucket++) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1335 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1336 if (bindings[bucket]) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1337 { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1338 map_bindings(ports, bindings[bucket], 0x8000); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1339 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1340 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1341 for (int stick = 0; stick < MAX_JOYSTICKS; stick++) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1342 { |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
1343 if (joysticks[stick].buttons) { |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
1344 map_bindings(ports, joysticks[stick].buttons, joysticks[stick].num_buttons); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
1345 } |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
1346 if (joysticks[stick].dpads) |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1347 { |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1348 for (uint32_t i = 0; i < joysticks[stick].num_dpads; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1349 { |
937
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
1350 map_bindings(ports, joysticks[stick].dpads[i].bindings, 4); |
9364dad5561a
Added reasonable handling of joystick hotplug
Michael Pavone <pavone@retrodev.com>
parents:
916
diff
changeset
|
1351 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1352 } |
1207
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1353 for (uint32_t i = 0; i < joysticks[stick].num_axes; i++) |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1354 { |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1355 map_bindings(current_io->ports, &joysticks[stick].axes[i].positive, 1); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1356 map_bindings(current_io->ports, &joysticks[stick].axes[i].negative, 1); |
9d6f155732ed
Basic support for mapping an analog axis to functionality
Michael Pavone <pavone@retrodev.com>
parents:
1202
diff
changeset
|
1357 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1358 } |
907
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1359 for (int mouse = 0; mouse < MAX_MICE; mouse++) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1360 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1361 if (mice[mouse].bind_type >= BIND_MOUSE1 && mice[mouse].bind_type <= BIND_MOUSE8) { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1362 int num = mice[mouse].bind_type - BIND_MOUSE1; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1363 for (int j = 0; j < 3; j++) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1364 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1365 if (ports[j].device_type == IO_MOUSE && ports[j].device.mouse.mouse_num == num) |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1366 { |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1367 memset(ports[j].input, 0, sizeof(ports[j].input)); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1368 mice[mouse].motion_port = ports + j; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1369 break; |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1370 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1371 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1372 } |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1373 map_bindings(ports, mice[mouse].buttons, MAX_MOUSE_BUTTONS); |
b5d35222047e
Mega mouse support is mostly done
Michael Pavone <pavone@retrodev.com>
parents:
903
diff
changeset
|
1374 } |
1026
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1375 keyboard_port = NULL; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1376 for (int i = 0; i < 3; i++) |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1377 { |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1378 if (ports[i].device_type == IO_SATURN_KEYBOARD) { |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1379 keyboard_port = ports + i; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1380 break; |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1381 } |
7267bc1ab547
Fix bug in 68K movep.l when the destination is a register mapped to a host register
Michael Pavone <pavone@retrodev.com>
parents:
1005
diff
changeset
|
1382 } |
1005
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
1383 //not really related to the intention of this function, but the best place to do this currently |
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
1384 if (speeds[0] != 100) { |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1385 current_system->set_speed_percent(current_system, speeds[0]); |
1005
580a806aef6a
Allow overriding speed 0. May be useful for people that want to use vsync
Michael Pavone <pavone@retrodev.com>
parents:
971
diff
changeset
|
1386 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1387 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1388 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1389 #define TH 0x40 |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1390 #define TR 0x20 |
694
7497334bb548
Adjust TH timeout value to take into account the move to master clock cycles
Michael Pavone <pavone@retrodev.com>
parents:
645
diff
changeset
|
1391 #define TH_TIMEOUT 56000 |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1392 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1393 void mouse_check_ready(io_port *port, uint32_t current_cycle) |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1394 { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1395 if (current_cycle >= port->device.mouse.ready_cycle) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1396 port->device.mouse.tr_counter++; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1397 port->device.mouse.ready_cycle = CYCLE_NEVER; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1398 if (port->device.mouse.tr_counter == 3) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1399 port->device.mouse.latched_x = port->device.mouse.cur_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1400 port->device.mouse.latched_y = port->device.mouse.cur_y; |
1111
2eb54e24914e
Mostly working changes to allow support for multiple emulated system types in main blastem program
Michael Pavone <pavone@retrodev.com>
parents:
1103
diff
changeset
|
1401 if (current_io->mouse_mode == MOUSE_ABSOLUTE) { |
915
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1402 //avoid overflow in absolute mode |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1403 int deltax = port->device.mouse.latched_x - port->device.mouse.last_read_x; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1404 if (abs(deltax) > 255) { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1405 port->device.mouse.latched_x = port->device.mouse.last_read_x + (deltax > 0 ? 255 : -255); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1406 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1407 int deltay = port->device.mouse.latched_y - port->device.mouse.last_read_y; |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1408 if (abs(deltay) > 255) { |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1409 port->device.mouse.latched_y = port->device.mouse.last_read_y + (deltay > 0 ? 255 : -255); |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1410 } |
9e882eca717e
Initial support for relative mouse mode and skeleton of support for capture mode. Avoid mouse position overflow in absolute mode. Allow absolute mode to be set by ROM DB.
Michael Pavone <pavone@retrodev.com>
parents:
914
diff
changeset
|
1411 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1412 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1413 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1414 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1415 |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1416 uint32_t last_poll_cycle; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1417 void io_adjust_cycles(io_port * port, uint32_t current_cycle, uint32_t deduction) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1418 { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1419 /*uint8_t control = pad->control | 0x80; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1420 uint8_t th = control & pad->output; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1421 if (pad->input[GAMEPAD_TH0] || pad->input[GAMEPAD_TH1]) { |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1422 printf("adjust_cycles | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, pad->input[GAMEPAD_TH0], pad->input[GAMEPAD_TH1], pad->th_counter,pad->timeout_cycle, current_cycle); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1423 }*/ |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1424 if (port->device_type == IO_GAMEPAD6) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1425 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1426 if (current_cycle >= port->device.pad.timeout_cycle) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1427 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1428 port->device.pad.th_counter = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1429 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1430 port->device.pad.timeout_cycle -= deduction; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1431 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1432 } else if (port->device_type == IO_MOUSE) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1433 mouse_check_ready(port, current_cycle); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1434 if (port->device.mouse.ready_cycle != CYCLE_NEVER) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1435 port->device.mouse.ready_cycle -= deduction; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1436 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1437 } |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1438 if (last_poll_cycle >= deduction) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1439 last_poll_cycle -= deduction; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1440 } else { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1441 last_poll_cycle = 0; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1442 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1443 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1444 |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1445 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1446 static void wait_for_connection(io_port * port) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1447 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1448 if (port->device.stream.data_fd == -1) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1449 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1450 puts("Waiting for socket connection..."); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1451 port->device.stream.data_fd = accept(port->device.stream.listen_fd, NULL, NULL); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1452 fcntl(port->device.stream.data_fd, F_SETFL, O_NONBLOCK | O_RDWR); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1453 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1454 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1455 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1456 static void service_pipe(io_port * port) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1457 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1458 uint8_t value; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1459 int numRead = read(port->device.stream.data_fd, &value, sizeof(value)); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1460 if (numRead > 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1461 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1462 port->input[IO_TH0] = (value & 0xF) | 0x10; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1463 port->input[IO_TH1] = (value >> 4) | 0x10; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1464 } else if(numRead == -1 && errno != EAGAIN && errno != EWOULDBLOCK) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1465 warning("Error reading pipe for IO port: %d %s\n", errno, strerror(errno)); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1466 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1467 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1468 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1469 static void service_socket(io_port *port) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1470 { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1471 uint8_t buf[32]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1472 uint8_t blocking = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1473 int numRead = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1474 while (numRead <= 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1475 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1476 numRead = recv(port->device.stream.data_fd, buf, sizeof(buf), 0); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1477 if (numRead > 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1478 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1479 port->input[IO_TH0] = buf[numRead-1]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1480 if (port->input[IO_STATE] == IO_READ_PENDING) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1481 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1482 port->input[IO_STATE] = IO_READ; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1483 if (blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1484 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1485 //pending read satisfied, back to non-blocking mode |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1486 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1487 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1488 } else if (port->input[IO_STATE] == IO_WRITTEN) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1489 port->input[IO_STATE] = IO_READ; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1490 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1491 } else if (numRead == 0) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1492 port->device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1493 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1494 } else if (errno != EAGAIN && errno != EWOULDBLOCK) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1495 warning("Error reading from socket for IO port: %d %s\n", errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1496 close(port->device.stream.data_fd); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1497 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1498 } else if (port->input[IO_STATE] == IO_READ_PENDING) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1499 //clear the nonblocking flag so the next read will block |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1500 if (!blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1501 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1502 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1503 blocking = 1; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1504 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1505 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1506 //no new data, but that's ok |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1507 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1508 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1509 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1510 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1511 if (port->input[IO_STATE] == IO_WRITE_PENDING) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1512 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1513 uint8_t value = port->output & port->control; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1514 int written = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1515 blocking = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1516 while (written <= 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1517 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1518 send(port->device.stream.data_fd, &value, sizeof(value), 0); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1519 if (written > 0) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1520 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1521 port->input[IO_STATE] = IO_WRITTEN; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1522 if (blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1523 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1524 //pending write satisfied, back to non-blocking mode |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1525 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR | O_NONBLOCK); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1526 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1527 } else if (written == 0) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1528 port->device.stream.data_fd = -1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1529 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1530 } else if (errno != EAGAIN && errno != EWOULDBLOCK) { |
903
0e5f9d6135be
Make nexus player remote useable as a controller for games that only require a dpad + start + c. Use warning() instead of fprintf(stder,...) in io.c
Michael Pavone <pavone@retrodev.com>
parents:
897
diff
changeset
|
1531 warning("Error writing to socket for IO port: %d %s\n", errno, strerror(errno)); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1532 close(port->device.stream.data_fd); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1533 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1534 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1535 //clear the nonblocking flag so the next write will block |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1536 if (!blocking) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1537 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1538 fcntl(port->device.stream.data_fd, F_SETFL, O_RDWR); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1539 blocking = 1; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1540 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1541 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1542 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1543 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1544 } |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1545 #endif |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1546 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1547 const int mouse_delays[] = {112*7, 120*7, 96*7, 132*7, 104*7, 96*7, 112*7, 96*7}; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1548 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1549 void io_data_write(io_port * port, uint8_t value, uint32_t current_cycle) |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1550 { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1551 uint8_t old_output = (port->control & port->output) | (~port->control & 0xFF); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1552 uint8_t output = (port->control & value) | (~port->control & 0xFF); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1553 switch (port->device_type) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1554 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1555 case IO_GAMEPAD6: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1556 //check if TH has changed |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1557 if ((old_output & TH) ^ (output & TH)) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1558 if (current_cycle >= port->device.pad.timeout_cycle) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1559 port->device.pad.th_counter = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1560 } |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1561 if ((output & TH)) { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1562 port->device.pad.th_counter++; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1563 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1564 port->device.pad.timeout_cycle = current_cycle + TH_TIMEOUT; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1565 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1566 break; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1567 case IO_MOUSE: |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1568 mouse_check_ready(port, current_cycle); |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1569 if (output & TH) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1570 //request is over or mouse is being reset |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1571 if (port->device.mouse.tr_counter) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1572 //request is over |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1573 port->device.mouse.last_read_x = port->device.mouse.latched_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1574 port->device.mouse.last_read_y = port->device.mouse.latched_y; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1575 } |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1576 port->device.mouse.tr_counter = 0; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1577 port->device.mouse.ready_cycle = CYCLE_NEVER; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1578 } else { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1579 if ((output & TR) != (old_output & TR)) { |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1580 int delay_index = port->device.mouse.tr_counter >= sizeof(mouse_delays) ? sizeof(mouse_delays)-1 : port->device.mouse.tr_counter; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1581 port->device.mouse.ready_cycle = current_cycle + mouse_delays[delay_index]; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1582 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1583 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1584 break; |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1585 case IO_SATURN_KEYBOARD: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1586 if (output & TH) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1587 //request is over |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1588 if (port->device.keyboard.tr_counter >= 10 && port->device.keyboard.read_pos != 0xFF) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1589 //remove scan code from buffer |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1590 port->device.keyboard.read_pos++; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1591 port->device.keyboard.read_pos &= 7; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1592 if (port->device.keyboard.read_pos == port->device.keyboard.write_pos) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1593 port->device.keyboard.read_pos = 0xFF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1594 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1595 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1596 port->device.keyboard.tr_counter = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1597 } else { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1598 if ((output & TR) != (old_output & TR)) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1599 port->device.keyboard.tr_counter++; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1600 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1601 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1602 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1603 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1604 case IO_GENERIC: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1605 wait_for_connection(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1606 port->input[IO_STATE] = IO_WRITE_PENDING; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1607 service_socket(port); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1608 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1609 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1610 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1611 port->output = value; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1612 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1613 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1614 |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1615 uint8_t io_data_read(io_port * port, uint32_t current_cycle) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1616 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1617 uint8_t control = port->control | 0x80; |
911
73732ae76fa8
IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents:
910
diff
changeset
|
1618 uint8_t output = (control & port->output) | (~control & 0xFF); |
73732ae76fa8
IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents:
910
diff
changeset
|
1619 uint8_t th = output & 0x40; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1620 uint8_t input; |
1077
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1621 if (current_cycle - last_poll_cycle > MIN_POLL_INTERVAL) { |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1622 process_events(); |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1623 last_poll_cycle = current_cycle; |
1a66d5165ea7
Cleanup the separation of render backend and VDP code in preparation for having extra debug windows. Make determination of H40/H32 based on number of lines in each mode.
Michael Pavone <pavone@retrodev.com>
parents:
1035
diff
changeset
|
1624 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1625 switch (port->device_type) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1626 { |
1146
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
1627 case IO_GAMEPAD2: |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
1628 input = ~port->input[GAMEPAD_TH1]; |
3e24de8d8073
Add support for SMS controllers
Michael Pavone <pavone@retrodev.com>
parents:
1144
diff
changeset
|
1629 break; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1630 case IO_GAMEPAD3: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1631 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1632 input = port->input[th ? GAMEPAD_TH1 : GAMEPAD_TH0]; |
888
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
1633 if (!th) { |
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
1634 input |= 0xC; |
bc127fa1f800
Fix Mega Drive peripheral ID for 3-button pad
Michael Pavone <pavone@retrodev.com>
parents:
886
diff
changeset
|
1635 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1636 //controller output is logically inverted |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1637 input = ~input; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1638 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1639 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1640 case IO_GAMEPAD6: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1641 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1642 if (current_cycle >= port->device.pad.timeout_cycle) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1643 port->device.pad.th_counter = 0; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1644 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1645 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1646 printf("io_data_read | control: %X, TH: %X, GAMEPAD_TH0: %X, GAMEPAD_TH1: %X, TH Counter: %d, Timeout: %d, Cycle: %d\n", control, th, port->input[GAMEPAD_TH0], port->input[GAMEPAD_TH1], port->th_counter,port->timeout_cycle, context->current_cycle); |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1647 }*/ |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1648 if (th) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1649 if (port->device.pad.th_counter == 3) { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1650 input = port->input[GAMEPAD_EXTRA]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1651 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1652 input = port->input[GAMEPAD_TH1]; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1653 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1654 } else { |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1655 if (port->device.pad.th_counter == 2) { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1656 input = port->input[GAMEPAD_TH0] | 0xF; |
1144
be3df2d8530a
Increment TH counter on low to high transitions rather than high to low transitions for six button controllers. Fixes Charles MacDonald's SMS six button controller demo
Michael Pavone <pavone@retrodev.com>
parents:
1116
diff
changeset
|
1657 } else if(port->device.pad.th_counter == 3) { |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1658 input = port->input[GAMEPAD_TH0] & 0x30; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1659 } else { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1660 input = port->input[GAMEPAD_TH0] | 0xC; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1661 } |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1662 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1663 //controller output is logically inverted |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1664 input = ~input; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1665 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1666 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1667 case IO_MOUSE: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1668 { |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1669 mouse_check_ready(port, current_cycle); |
911
73732ae76fa8
IO port pins should read as high from the perspective of a device when they are set as inputs
Michael Pavone <pavone@retrodev.com>
parents:
910
diff
changeset
|
1670 uint8_t tr = output & TR; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1671 if (th) { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1672 if (tr) { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1673 input = 0x10; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1674 } else { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1675 input = 0; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1676 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1677 } else { |
913
a5a51465f8b0
Allow IO device config to be overriden by ROM DB
Michael Pavone <pavone@retrodev.com>
parents:
912
diff
changeset
|
1678 |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1679 int16_t delta_x = port->device.mouse.latched_x - port->device.mouse.last_read_x; |
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1680 int16_t delta_y = port->device.mouse.last_read_y - port->device.mouse.latched_y; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1681 switch (port->device.mouse.tr_counter) |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1682 { |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1683 case 0: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1684 input = 0xB; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1685 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1686 case 1: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1687 case 2: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1688 input = 0xF; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1689 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1690 case 3: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1691 input = 0; |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1692 if (delta_y > 255 || delta_y < -255) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1693 input |= 8; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1694 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1695 if (delta_x > 255 || delta_x < -255) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1696 input |= 4; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1697 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1698 if (delta_y < 0) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1699 input |= 2; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1700 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1701 if (delta_x < 0) { |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1702 input |= 1; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1703 } |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1704 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1705 case 4: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1706 input = port->input[0]; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1707 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1708 case 5: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1709 input = delta_x >> 4 & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1710 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1711 case 6: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1712 input = delta_x & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1713 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1714 case 7: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1715 input = delta_y >> 4 & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1716 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1717 case 8: |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1718 default: |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1719 input = delta_y & 0xF; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1720 break; |
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1721 } |
912
599e2861f484
Rough emulation of mouse response delays when TR is toggled. Latch current mouse value rather than delta. Some other IO cleanup/fixes
Michael Pavone <pavone@retrodev.com>
parents:
911
diff
changeset
|
1722 input |= ((port->device.mouse.tr_counter & 1) == 0) << 4; |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1723 } |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1724 break; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1725 } |
1028
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1726 case IO_SATURN_KEYBOARD: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1727 { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1728 if (th) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1729 input = 0x11; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1730 } else { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1731 uint8_t tr = output & TR; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1732 uint16_t code = port->device.keyboard.read_pos == 0xFF ? 0 |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1733 : port->device.keyboard.events[port->device.keyboard.read_pos]; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1734 switch (port->device.keyboard.tr_counter) |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1735 { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1736 case 0: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1737 input = 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1738 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1739 case 1: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1740 //Saturn peripheral ID |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1741 input = 3; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1742 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1743 case 2: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1744 //data size |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1745 input = 4; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1746 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1747 case 3: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1748 //d-pad |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1749 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1750 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1751 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1752 case 4: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1753 //Start ABC |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1754 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1755 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1756 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1757 case 5: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1758 //R XYZ |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1759 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1760 input = 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1761 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1762 case 6: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1763 //L and KBID |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1764 //TODO: set L based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1765 input = 0x8; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1766 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1767 case 7: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1768 //Capslock, Numlock, Scrolllock |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1769 //TODO: set these based on keyboard state |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1770 input = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1771 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1772 case 8: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1773 input = 6; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1774 if (code & 0x100) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1775 //break |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1776 input |= 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1777 } else if (code) { |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1778 input |= 8; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1779 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1780 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1781 case 9: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1782 input = code >> 4 & 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1783 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1784 case 10: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1785 input = code & 0xF; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1786 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1787 case 11: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1788 input = 0; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1789 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1790 default: |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1791 input = 1; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1792 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1793 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1794 input |= ((port->device.keyboard.tr_counter & 1) == 0) << 4; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1795 } |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1796 break; |
56b1748a8473
Initial stab at Saturn keyboard support
Michael Pavone <pavone@retrodev.com>
parents:
1026
diff
changeset
|
1797 } |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1798 #ifndef _WIN32 |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1799 case IO_SEGA_PARALLEL: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1800 if (!th) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1801 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1802 service_pipe(port); |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1803 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1804 input = port->input[th ? IO_TH1 : IO_TH0]; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1805 break; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1806 case IO_GENERIC: |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1807 if (port->input[IO_TH0] & 0x80 && port->input[IO_STATE] == IO_WRITTEN) |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1808 { |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1809 //device requested a blocking read after writes |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1810 port->input[IO_STATE] = IO_READ_PENDING; |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1811 } |
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1812 service_socket(port); |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1813 input = port->input[IO_TH0]; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1814 break; |
745
daa31ee7d8cd
Get windows build compiling again post-merge
Michael Pavone <pavone@retrodev.com>
parents:
722
diff
changeset
|
1815 #endif |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1816 default: |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1817 input = 0xFF; |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1818 break; |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1819 } |
897
b9564fb88a5a
WIP support for mega mouse
Michael Pavone <pavone@retrodev.com>
parents:
888
diff
changeset
|
1820 uint8_t value = (input & (~control)) | (port->output & control); |
645
d77c79cec800
Initial support for configurable IO, custom IO and sega transfer board emulation
Michael Pavone <pavone@retrodev.com>
parents:
504
diff
changeset
|
1821 /*if (port->input[GAMEPAD_TH0] || port->input[GAMEPAD_TH1]) { |
421
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1822 printf ("value: %X\n", value); |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1823 }*/ |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1824 return value; |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1825 } |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1826 |
d0cacb4ade0b
Move IO code to a separate file and do a tiny bit of refactoring
Mike Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1827 |