Mercurial > repos > blastem
annotate bindings.c @ 2476:aaf7bb58ffca
Fix bug in Gen/MD serialize routine that could cause a use-after free in some cases
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 03 Mar 2024 13:47:59 -0800 |
parents | f8ce89498e11 |
children |
rev | line source |
---|---|
1587
ea687ca7d845
Fix missing include in bindings.c
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
1 #include <string.h> |
1783 | 2 #include <stdlib.h> |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "render.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "system.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "io.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "blastem.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "saves.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "util.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "genesis.h" |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
10 #include "sms.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include "menu.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #include "bindings.h" |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
13 #include "controller_info.h" |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 #ifndef DISABLE_NUKLEAR |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 #include "nuklear_ui/blastem_nuklear.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 #endif |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 enum { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 BIND_NONE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 BIND_UI, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 BIND_GAMEPAD, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 BIND_MOUSE |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 }; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 typedef enum { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 UI_DEBUG_MODE_INC, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 UI_ENTER_DEBUGGER, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 UI_SAVE_STATE, |
2162
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
29 UI_LOAD_STATE, |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 UI_SET_SPEED, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 UI_NEXT_SPEED, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 UI_PREV_SPEED, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 UI_RELEASE_MOUSE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 UI_TOGGLE_KEYBOARD_CAPTURE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 UI_TOGGLE_FULLSCREEN, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 UI_SOFT_RESET, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 UI_RELOAD, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 UI_SMS_PAUSE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 UI_SCREENSHOT, |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
40 UI_RECORD_VIDEO, |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
41 UI_VGM_LOG, |
2306
62f316b76e9a
Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents:
2304
diff
changeset
|
42 UI_MENU, |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
43 UI_EXIT, |
1634
e397766c3028
Added VRAM debug window
Michael Pavone <pavone@retrodev.com>
parents:
1631
diff
changeset
|
44 UI_PLANE_DEBUG, |
1638
f27142c48567
Initial stab at CRAM debug in a detached window
Michael Pavone <pavone@retrodev.com>
parents:
1634
diff
changeset
|
45 UI_VRAM_DEBUG, |
f27142c48567
Initial stab at CRAM debug in a detached window
Michael Pavone <pavone@retrodev.com>
parents:
1634
diff
changeset
|
46 UI_CRAM_DEBUG, |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
47 UI_COMPOSITE_DEBUG, |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
48 UI_OSCILLOSCOPE_DEBUG, |
2271
3ef80963c2a7
Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents:
2243
diff
changeset
|
49 UI_CD_GRAPHICS_DEBUG |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 } ui_action; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 uint8_t bind_type; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 uint8_t subtype_a; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 uint8_t subtype_b; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 } keybinding; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 keybinding bindings[4]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 uint8_t state; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 } joydpad; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 keybinding positive; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 keybinding negative; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 int16_t value; |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
67 int16_t deadzone; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 } joyaxis; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 keybinding *buttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 joydpad *dpads; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 joyaxis *axes; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 uint32_t num_buttons; //number of entries in the buttons array, not necessarily the number of buttons on the device |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 uint32_t num_dpads; //number of entries in the dpads array, not necessarily the number of dpads on the device |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 uint32_t num_axes; //number of entries in the axes array, not necessarily the number of dpads on the device |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 } joystick; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 keybinding buttons[MAX_MOUSE_BUTTONS]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 keybinding motion; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 } mousebinding; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 #define DEFAULT_JOYBUTTON_ALLOC 12 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 static keybinding *bindings[0x10000]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 static joystick joysticks[MAX_JOYSTICKS]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 static mousebinding mice[MAX_MICE]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 const uint8_t dpadbits[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 static void do_bind(keybinding *binding, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 binding->bind_type = bind_type; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 binding->subtype_a = subtype_a; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 binding->subtype_b = subtype_b; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 void bind_key(int keycode, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 int bucket = keycode >> 15 & 0xFFFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 if (!bindings[bucket]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 bindings[bucket] = malloc(sizeof(keybinding) * 0x8000); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 memset(bindings[bucket], 0, sizeof(keybinding) * 0x8000); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 int idx = keycode & 0x7FFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 do_bind(bindings[bucket] + idx, bind_type, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 void bind_button(int joystick, int button, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 if (!joysticks[joystick].buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 joysticks[joystick].num_buttons = button < DEFAULT_JOYBUTTON_ALLOC ? DEFAULT_JOYBUTTON_ALLOC : button + 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 joysticks[joystick].buttons = calloc(joysticks[joystick].num_buttons, sizeof(keybinding)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 } else if (joysticks[joystick].num_buttons <= button) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 uint32_t old_capacity = joysticks[joystick].num_buttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 joysticks[joystick].num_buttons *= 2; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 joysticks[joystick].buttons = realloc(joysticks[joystick].buttons, sizeof(keybinding) * joysticks[joystick].num_buttons); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 memset(joysticks[joystick].buttons + old_capacity, 0, joysticks[joystick].num_buttons - old_capacity); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 do_bind(joysticks[joystick].buttons + button, bind_type, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 void bind_dpad(int joystick, int dpad, int direction, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 if (!joysticks[joystick].dpads) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 //multiple D-pads/hats are not common, so don't allocate any extra space |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 joysticks[joystick].dpads = calloc(dpad+1, sizeof(joydpad)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 joysticks[joystick].num_dpads = dpad+1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 } else if (joysticks[joystick].num_dpads <= dpad) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 uint32_t old_capacity = joysticks[joystick].num_dpads; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 joysticks[joystick].num_dpads *= 2; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 joysticks[joystick].dpads = realloc(joysticks[joystick].dpads, sizeof(joydpad) * joysticks[joystick].num_dpads); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 memset(joysticks[joystick].dpads + old_capacity, 0, (joysticks[joystick].num_dpads - old_capacity) * sizeof(joydpad)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 for (int i = 0; i < 4; i ++) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 if (dpadbits[i] & direction) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 do_bind(joysticks[joystick].dpads[dpad].bindings + i, bind_type, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
148 void bind_axis(int joystick, int axis, int positive, int deadzone, uint8_t bind_type, uint8_t subtype_a, uint8_t subtype_b) |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 if (!joysticks[joystick].axes) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 //typical gamepad has 4 axes |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 joysticks[joystick].num_axes = axis+1 > 4 ? axis+1 : 4; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 joysticks[joystick].axes = calloc(joysticks[joystick].num_axes, sizeof(joyaxis)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 } else if (joysticks[joystick].num_axes <= axis) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 uint32_t old_capacity = joysticks[joystick].num_axes; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 joysticks[joystick].num_axes *= 2; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 joysticks[joystick].axes = realloc(joysticks[joystick].axes, sizeof(joyaxis) * joysticks[joystick].num_axes); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 memset(joysticks[joystick].axes + old_capacity, 0, (joysticks[joystick].num_axes - old_capacity) * sizeof(joyaxis)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 } |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
163 joysticks[joystick].axes[axis].deadzone = deadzone; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 if (positive) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 do_bind(&joysticks[joystick].axes[axis].positive, bind_type, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 do_bind(&joysticks[joystick].axes[axis].negative, bind_type, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 void reset_joystick_bindings(int joystick) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 if (joysticks[joystick].buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 for (int i = 0; i < joysticks[joystick].num_buttons; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 joysticks[joystick].buttons[i].bind_type = BIND_NONE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 if (joysticks[joystick].dpads) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 for (int i = 0; i < joysticks[joystick].num_dpads; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 for (int dir = 0; dir < 4; dir++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 joysticks[joystick].dpads[i].bindings[dir].bind_type = BIND_NONE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 if (joysticks[joystick].axes) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 for (int i = 0; i < joysticks[joystick].num_axes; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 joysticks[joystick].axes[i].positive.bind_type = BIND_NONE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 joysticks[joystick].axes[i].negative.bind_type = BIND_NONE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
200 static uint8_t content_binds_enabled = 1; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
201 void set_content_binding_state(uint8_t enabled) |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
202 { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
203 content_binds_enabled = enabled; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
204 } |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
205 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 void handle_binding_down(keybinding * binding) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 { |
2291
4de40b13b55f
Filter out "down" binds when content binds are disabled
Michael Pavone <pavone@retrodev.com>
parents:
2286
diff
changeset
|
208 if (!current_system || !content_binds_enabled) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 if (binding->bind_type == BIND_GAMEPAD && current_system && current_system->gamepad_down) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 current_system->gamepad_down(current_system, binding->subtype_a, binding->subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 else if (binding->bind_type == BIND_MOUSE && current_system && current_system->mouse_down) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 current_system->mouse_down(current_system, binding->subtype_a, binding->subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 static uint8_t keyboard_captured; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 void handle_keydown(int keycode, uint8_t scancode) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 int bucket = keycode >> 15 & 0xFFFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 int idx = keycode & 0x7FFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 if (binding && (!keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 handle_binding_down(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 } else if (keyboard_captured && current_system && current_system->keyboard_down) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 current_system->keyboard_down(current_system, scancode); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 void handle_joydown(int joystick, int button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 keybinding * binding = joysticks[joystick].buttons + button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 handle_binding_down(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 static uint8_t mouse_mode = MOUSE_NONE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 static uint8_t mouse_captured; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 void handle_mousedown(int mouse, int button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 if (mouse_mode == MOUSE_CAPTURE && !mouse_captured) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 mouse_captured = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 render_relative_mouse(1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 keybinding * binding = mice[mouse].buttons + button - 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 handle_binding_down(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 static int current_speed = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 static int num_speeds = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 static uint32_t * speeds = NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 static uint8_t mouse_captured; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 #ifdef _WIN32 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 #define localtime_r(a,b) localtime(a) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 #endif |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
269 char *get_content_config_path(char *config_path, char *config_template, char *default_name) |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
270 { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
271 char *base = tern_find_path(config, config_path, TVAL_PTR).ptrval; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
272 if (!base) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
273 base = "$HOME"; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
274 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
275 const system_media *media = current_media(); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
276 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
277 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
278 vars = tern_insert_ptr(vars, "USERDATA", (char *)get_userdata_dir()); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
279 vars = tern_insert_ptr(vars, "ROMNAME", media->name); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
280 vars = tern_insert_ptr(vars, "ROMDIR", media->dir); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
281 base = replace_vars(base, vars, 1); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
282 tern_free(vars); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
283 ensure_dir_exists(base); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
284 time_t now = time(NULL); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
285 struct tm local_store; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
286 char fname_part[256]; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
287 char *template = tern_find_path(config, config_template, TVAL_PTR).ptrval; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
288 if (template) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
289 vars = tern_insert_ptr(NULL, "ROMNAME", media->name); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
290 template = replace_vars(template, vars, 0); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
291 } else { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
292 template = strdup(default_name); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
293 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
294 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store)); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
295 char const *parts[] = {base, PATH_SEP, fname_part}; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
296 char *path = alloc_concat_m(3, parts); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
297 free(base); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
298 free(template); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
299 return path; |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
300 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
301 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 void handle_binding_up(keybinding * binding) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 { |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
304 uint8_t allow_content_binds = content_binds_enabled && current_system; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 switch(binding->bind_type) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 case BIND_GAMEPAD: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
308 if (allow_content_binds && current_system->gamepad_up) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 current_system->gamepad_up(current_system, binding->subtype_a, binding->subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 case BIND_MOUSE: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
313 if (allow_content_binds && current_system->mouse_up) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 current_system->mouse_up(current_system, binding->subtype_a, binding->subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 case BIND_UI: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 switch (binding->subtype_a) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 case UI_DEBUG_MODE_INC: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
321 if (allow_content_binds) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
322 current_system->inc_debug_mode(current_system); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
323 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 case UI_ENTER_DEBUGGER: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
326 if (allow_content_binds) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
327 current_system->enter_debugger = 1; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
328 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 case UI_SAVE_STATE: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
331 if (allow_content_binds) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
332 current_system->save_state = QUICK_SAVE_SLOT+1; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
333 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 break; |
2162
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
335 case UI_LOAD_STATE: |
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
336 if (allow_content_binds) { |
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
337 current_system->load_state(current_system, QUICK_SAVE_SLOT); |
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
338 } |
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
339 break; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 case UI_NEXT_SPEED: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
341 if (allow_content_binds) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
342 current_speed++; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
343 if (current_speed >= num_speeds) { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
344 current_speed = 0; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
345 } |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
346 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
347 current_system->set_speed_percent(current_system, speeds[current_speed]); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 case UI_PREV_SPEED: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
351 if (allow_content_binds) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
352 current_speed--; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
353 if (current_speed < 0) { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
354 current_speed = num_speeds - 1; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
355 } |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
356 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
357 current_system->set_speed_percent(current_system, speeds[current_speed]); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 case UI_SET_SPEED: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
361 if (allow_content_binds) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
362 if (binding->subtype_b < num_speeds) { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
363 current_speed = binding->subtype_b; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
364 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
365 current_system->set_speed_percent(current_system, speeds[current_speed]); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
366 } else { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
367 printf("Setting speed to %d\n", speeds[current_speed]); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
368 current_system->set_speed_percent(current_system, speeds[current_speed]); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
369 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 case UI_RELEASE_MOUSE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 if (mouse_captured) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 mouse_captured = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 render_relative_mouse(0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 case UI_TOGGLE_KEYBOARD_CAPTURE: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
379 if (allow_content_binds && current_system->has_keyboard) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 keyboard_captured = !keyboard_captured; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 case UI_TOGGLE_FULLSCREEN: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 render_toggle_fullscreen(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 case UI_SOFT_RESET: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
387 if (allow_content_binds) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
388 current_system->soft_reset(current_system); |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
389 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 case UI_RELOAD: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
392 if (allow_content_binds) { |
2409
f8ce89498e11
Fix some further fallout of ZIP reload fix
Michael Pavone <pavone@retrodev.com>
parents:
2317
diff
changeset
|
393 reload_media(); |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
394 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 case UI_SMS_PAUSE: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
397 if (allow_content_binds && current_system->gamepad_down) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 current_system->gamepad_down(current_system, GAMEPAD_MAIN_UNIT, MAIN_UNIT_PAUSE); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 break; |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
401 case UI_SCREENSHOT: |
1680
326d1a601fb9
Fixed crash bug that could occur in a narrow window of time when loading a ROM
Michael Pavone <pavone@retrodev.com>
parents:
1679
diff
changeset
|
402 if (allow_content_binds) { |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
403 char *path = get_content_config_path("ui\0screenshot_path\0", "ui\0screenshot_template\0", "blastem_%c.ppm"); |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
404 render_save_screenshot(path); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 break; |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
407 case UI_RECORD_VIDEO: |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
408 if (allow_content_binds) { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
409 if (render_saving_video()) { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
410 render_end_video(); |
2304
b3832f73444f
Save audio to a wave file when saving video to APNG
Michael Pavone <pavone@retrodev.com>
parents:
2295
diff
changeset
|
411 render_end_audio(); |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
412 } else { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
413 char *path = get_content_config_path("ui\0video_path\0", "ui\0video_template\0", "blastem_%c.apng"); |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
414 render_save_video(path); |
2304
b3832f73444f
Save audio to a wave file when saving video to APNG
Michael Pavone <pavone@retrodev.com>
parents:
2295
diff
changeset
|
415 path = get_content_config_path("ui\0audio_path\0", "ui\0audio_template\0", "blastem_%c.wav"); |
b3832f73444f
Save audio to a wave file when saving video to APNG
Michael Pavone <pavone@retrodev.com>
parents:
2295
diff
changeset
|
416 render_save_audio(path); |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
417 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
418 } |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
419 break; |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
420 case UI_VGM_LOG: |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
421 if (allow_content_binds && current_system->start_vgm_log) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
422 if (current_system->vgm_logging) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
423 current_system->stop_vgm_log(current_system); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
424 } else { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
425 char *path = get_content_config_path("ui\0vgm_path\0", "ui\0vgm_template\0", "blastem_%c.vgm"); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
426 current_system->start_vgm_log(current_system, path); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
427 free(path); |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
428 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
429 } |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
430 break; |
2306
62f316b76e9a
Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents:
2304
diff
changeset
|
431 case UI_MENU: |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 #ifndef DISABLE_NUKLEAR |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 if (is_nuklear_active()) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 show_pause_menu(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 #endif |
1980
81df9aa2de9b
Less hacky run on audio thread mode
Michael Pavone <pavone@retrodev.com>
parents:
1909
diff
changeset
|
437 system_request_exit(current_system, 1); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 if (current_system->type == SYSTEM_GENESIS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 genesis_context *gen = (genesis_context *)current_system; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 if (gen->extra) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 //TODO: More robust mechanism for detecting menu |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 menu_context *menu = gen->extra; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 menu->external_game_load = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 #ifndef DISABLE_NUKLEAR |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 #endif |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 break; |
2306
62f316b76e9a
Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents:
2304
diff
changeset
|
450 case UI_EXIT: |
62f316b76e9a
Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents:
2304
diff
changeset
|
451 exit(0); |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
452 case UI_PLANE_DEBUG: |
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
453 case UI_VRAM_DEBUG: |
1641
bc9bb4e5856f
Basic version of layer compositing debug view in a separate window
Michael Pavone <pavone@retrodev.com>
parents:
1638
diff
changeset
|
454 case UI_CRAM_DEBUG: |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
455 case UI_COMPOSITE_DEBUG: |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
456 case UI_OSCILLOSCOPE_DEBUG: |
2271
3ef80963c2a7
Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents:
2243
diff
changeset
|
457 case UI_CD_GRAPHICS_DEBUG: |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
458 if (allow_content_binds && current_system->toggle_debug_view) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
459 current_system->toggle_debug_view(current_system, binding->subtype_a - UI_PLANE_DEBUG + DEBUG_PLANE); |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
460 /* |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
461 vdp_context *vdp = NULL; |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
462 if (current_system->type == SYSTEM_GENESIS || current_system->type == SYSTEM_SEGACD) { |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
463 genesis_context *gen = (genesis_context *)current_system; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
464 vdp = gen->vdp; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
465 } else if (current_system->type == SYSTEM_SMS) { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
466 sms_context *sms = (sms_context *)current_system; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
467 vdp = sms->vdp; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
468 } |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
469 if (vdp) { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
470 uint8_t debug_type; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
471 switch(binding->subtype_a) |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
472 { |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
473 case UI_PLANE_DEBUG: debug_type = VDP_DEBUG_PLANE; break; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
474 case UI_VRAM_DEBUG: debug_type = VDP_DEBUG_VRAM; break; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
475 case UI_CRAM_DEBUG: debug_type = VDP_DEBUG_CRAM; break; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
476 case UI_COMPOSITE_DEBUG: debug_type = VDP_DEBUG_COMPOSITE; break; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
477 default: return; |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
478 } |
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
479 vdp_toggle_debug_view(vdp, debug_type); |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
480 }*/ |
1672
12d0c7c4ad80
Disable most bindings when UI is active
Michael Pavone <pavone@retrodev.com>
parents:
1643
diff
changeset
|
481 break; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
482 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 void handle_keyup(int keycode, uint8_t scancode) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 int bucket = keycode >> 15 & 0xFFFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 int idx = keycode & 0x7FFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 keybinding * binding = bindings[bucket] ? bindings[bucket] + idx : NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 if (binding && (!keyboard_captured || (binding->bind_type == BIND_UI && binding->subtype_a == UI_TOGGLE_KEYBOARD_CAPTURE))) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 handle_binding_up(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 } else if (keyboard_captured && current_system && current_system->keyboard_up) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 current_system->keyboard_up(current_system, scancode); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 void handle_joyup(int joystick, int button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 if (joystick >= MAX_JOYSTICKS || button >= joysticks[joystick].num_buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 keybinding * binding = joysticks[joystick].buttons + button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 handle_binding_up(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 void handle_joy_dpad(int joystick, int dpadnum, uint8_t value) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 if (joystick >= MAX_JOYSTICKS || dpadnum >= joysticks[joystick].num_dpads) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 joydpad * dpad = joysticks[joystick].dpads + dpadnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 uint8_t newdown = (value ^ dpad->state) & value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 uint8_t newup = ((~value) ^ (~dpad->state)) & (~value); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 dpad->state = value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 for (int i = 0; i < 4; i++) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 if (newdown & dpadbits[i]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 handle_binding_down(dpad->bindings + i); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 } else if(newup & dpadbits[i]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 handle_binding_up(dpad->bindings + i); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 void handle_joy_axis(int joystick, int axis, int16_t value) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 if (joystick >= MAX_JOYSTICKS || axis >= joysticks[joystick].num_axes) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 joyaxis *jaxis = joysticks[joystick].axes + axis; |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
533 int old_active = abs(jaxis->value) > jaxis->deadzone; |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
534 int new_active = abs(value) > jaxis->deadzone; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 int old_pos = jaxis->value > 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
536 int new_pos = value > 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 jaxis->value = value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
538 if (old_active && (!new_active || old_pos != new_pos)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
539 //previously activated direction is no longer active |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 handle_binding_up(old_pos ? &jaxis->positive : &jaxis->negative); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
541 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 if (new_active && (!old_active || old_pos != new_pos)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
543 //previously unactivated direction is now active |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 handle_binding_down(new_pos ? &jaxis->positive : &jaxis->negative); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
548 void handle_mouse_moved(int mouse, uint16_t x, uint16_t y, int16_t deltax, int16_t deltay) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
549 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
550 if (mouse >= MAX_MICE || !current_system) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
551 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
552 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 if (mice[mouse].motion.bind_type == BIND_MOUSE && mice[mouse].motion.subtype_b == PSEUDO_BUTTON_MOTION) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 uint8_t target_mouse = mice[mouse].motion.subtype_a; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
555 switch(mouse_mode) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
556 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
557 case MOUSE_NONE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
558 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
559 case MOUSE_ABSOLUTE: { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
560 if (current_system->mouse_motion_absolute) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
561 float scale_x = (render_emulated_width() * 2.0f) / ((float)render_width()); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
562 float scale_y = (render_emulated_height() * 2.0f) / ((float)render_height()); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
563 int32_t adj_x = x * scale_x + 2 * render_overscan_left() - 2 * BORDER_LEFT; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 int32_t adj_y = y * scale_y + 2 * render_overscan_top() - 4; |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
565 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
566 current_system->mouse_motion_absolute(current_system, target_mouse, adj_x, adj_y); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
567 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
568 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
569 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
570 case MOUSE_RELATIVE: { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
571 if (current_system->mouse_motion_relative) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
572 current_system->mouse_motion_relative(current_system, target_mouse, deltax, deltay); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
573 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
574 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
575 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
576 case MOUSE_CAPTURE: { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
577 if (mouse_captured && current_system->mouse_motion_relative) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
578 current_system->mouse_motion_relative(current_system, target_mouse, deltax, deltay); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
579 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
580 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
581 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
582 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
583 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 handle_binding_up(&mice[mouse].motion); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
585 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
586 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
587 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
588 void handle_mouseup(int mouse, int button) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
589 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
590 if (mouse >= MAX_MICE || button > MAX_MOUSE_BUTTONS || button <= 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
591 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
592 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
593 keybinding * binding = mice[mouse].buttons + button - 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 handle_binding_up(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
595 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 void bindings_release_capture(void) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 if (mouse_mode == MOUSE_RELATIVE || (mouse_mode == MOUSE_CAPTURE && mouse_captured)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 render_relative_mouse(0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 keyboard_captured = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 void bindings_reacquire_capture(void) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
606 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 if (mouse_mode == MOUSE_RELATIVE || (mouse_mode == MOUSE_CAPTURE && mouse_captured)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
608 render_relative_mouse(1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 |
2181
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
612 int parse_binding_target(int device_num, const char * target, tern_node * padbuttons, tern_node *mousebuttons, uint8_t * subtype_a, uint8_t * subtype_b) |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 const int gpadslen = strlen("gamepads."); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 const int mouselen = strlen("mouse."); |
1783 | 616 if (startswith(target, "gamepads.")) { |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
617 int padnum = target[gpadslen] == 'n' ? device_num + 1 : target[gpadslen] - '0'; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
618 if (padnum >= 1 && padnum <= 8) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
619 int button = tern_find_int(padbuttons, target + gpadslen + 1, 0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
620 if (button) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
621 *subtype_a = padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
622 *subtype_b = button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 return BIND_GAMEPAD; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
624 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 if (target[gpadslen+1]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 warning("Gamepad mapping string '%s' refers to an invalid button '%s'\n", target, target + gpadslen + 1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
627 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
628 warning("Gamepad mapping string '%s' has no button component\n", target); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
630 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
631 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
632 warning("Gamepad mapping string '%s' refers to an invalid gamepad number %c\n", target, target[gpadslen]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
633 } |
1783 | 634 } else if(startswith(target, "mouse.")) { |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
635 int mousenum = target[mouselen] == 'n' ? device_num + 1 : target[mouselen] - '0'; |
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
636 if (mousenum >= 1 && mousenum <= 8) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
637 int button = tern_find_int(mousebuttons, target + mouselen + 1, 0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 if (button) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
639 *subtype_a = mousenum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
640 *subtype_b = button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
641 return BIND_MOUSE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
643 if (target[mouselen+1]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 warning("Mouse mapping string '%s' refers to an invalid button '%s'\n", target, target + mouselen + 1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
645 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 warning("Mouse mapping string '%s' has no button component\n", target); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
650 warning("Gamepad mapping string '%s' refers to an invalid mouse number %c\n", target, target[mouselen]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
651 } |
1783 | 652 } else if(startswith(target, "ui.")) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 if (!strcmp(target + 3, "vdp_debug_mode")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
654 *subtype_a = UI_DEBUG_MODE_INC; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 } else if(!strcmp(target + 3, "vdp_debug_pal")) { |
1643
6909c5d0bbb5
Removed old VDP debug functionality
Michael Pavone <pavone@retrodev.com>
parents:
1641
diff
changeset
|
656 //legacy binding, ignore |
6909c5d0bbb5
Removed old VDP debug functionality
Michael Pavone <pavone@retrodev.com>
parents:
1641
diff
changeset
|
657 return 0; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
658 } else if(!strcmp(target + 3, "enter_debugger")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
659 *subtype_a = UI_ENTER_DEBUGGER; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
660 } else if(!strcmp(target + 3, "save_state")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 *subtype_a = UI_SAVE_STATE; |
2162
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
662 } else if(!strcmp(target + 3, "load_state")) { |
1270fe86eb89
Add Quick Load binding
Michael Pavone <pavone@retrodev.com>
parents:
2083
diff
changeset
|
663 *subtype_a = UI_LOAD_STATE; |
1783 | 664 } else if(startswith(target + 3, "set_speed.")) { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 *subtype_a = UI_SET_SPEED; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
666 *subtype_b = atoi(target + 3 + strlen("set_speed.")); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
667 } else if(!strcmp(target + 3, "next_speed")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
668 *subtype_a = UI_NEXT_SPEED; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
669 } else if(!strcmp(target + 3, "prev_speed")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
670 *subtype_a = UI_PREV_SPEED; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
671 } else if(!strcmp(target + 3, "release_mouse")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
672 *subtype_a = UI_RELEASE_MOUSE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 } else if(!strcmp(target + 3, "toggle_keyboard_captured")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
674 *subtype_a = UI_TOGGLE_KEYBOARD_CAPTURE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 } else if (!strcmp(target + 3, "toggle_fullscreen")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 *subtype_a = UI_TOGGLE_FULLSCREEN; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 } else if (!strcmp(target + 3, "soft_reset")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 *subtype_a = UI_SOFT_RESET; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
679 } else if (!strcmp(target + 3, "reload")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
680 *subtype_a = UI_RELOAD; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 } else if (!strcmp(target + 3, "sms_pause")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
682 *subtype_a = UI_SMS_PAUSE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
683 } else if (!strcmp(target + 3, "screenshot")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
684 *subtype_a = UI_SCREENSHOT; |
2295
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
685 } else if (!strcmp(target + 3, "record_video")) { |
eb45ad9d8a3f
WIP "video" recording in APNG format
Michael Pavone <pavone@retrodev.com>
parents:
2291
diff
changeset
|
686 *subtype_a = UI_RECORD_VIDEO; |
1909
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
687 } else if (!strcmp(target + 3, "vgm_log")) { |
508522f08e4d
Initial stab at VGM logging support
Michael Pavone <pavone@retrodev.com>
parents:
1850
diff
changeset
|
688 *subtype_a = UI_VGM_LOG; |
2306
62f316b76e9a
Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents:
2304
diff
changeset
|
689 } else if(!strcmp(target + 3, "menu")) { |
62f316b76e9a
Migrate ui.exit to ui.menu and create a new ui.exit for quitting
Michael Pavone <pavone@retrodev.com>
parents:
2304
diff
changeset
|
690 *subtype_a = UI_MENU; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 } else if(!strcmp(target + 3, "exit")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 *subtype_a = UI_EXIT; |
1631
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
693 } else if (!strcmp(target + 3, "plane_debug")) { |
c4ba3177b72d
WIP new VDP plane debug view and support for detached VDP debug views generally
Michael Pavone <pavone@retrodev.com>
parents:
1623
diff
changeset
|
694 *subtype_a = UI_PLANE_DEBUG; |
1634
e397766c3028
Added VRAM debug window
Michael Pavone <pavone@retrodev.com>
parents:
1631
diff
changeset
|
695 } else if (!strcmp(target + 3, "vram_debug")) { |
e397766c3028
Added VRAM debug window
Michael Pavone <pavone@retrodev.com>
parents:
1631
diff
changeset
|
696 *subtype_a = UI_VRAM_DEBUG; |
1638
f27142c48567
Initial stab at CRAM debug in a detached window
Michael Pavone <pavone@retrodev.com>
parents:
1634
diff
changeset
|
697 } else if (!strcmp(target + 3, "cram_debug")) { |
f27142c48567
Initial stab at CRAM debug in a detached window
Michael Pavone <pavone@retrodev.com>
parents:
1634
diff
changeset
|
698 *subtype_a = UI_CRAM_DEBUG; |
1641
bc9bb4e5856f
Basic version of layer compositing debug view in a separate window
Michael Pavone <pavone@retrodev.com>
parents:
1638
diff
changeset
|
699 } else if (!strcmp(target + 3, "compositing_debug")) { |
bc9bb4e5856f
Basic version of layer compositing debug view in a separate window
Michael Pavone <pavone@retrodev.com>
parents:
1638
diff
changeset
|
700 *subtype_a = UI_COMPOSITE_DEBUG; |
2243
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
701 } else if (!strcmp(target + 3, "oscilloscope")) { |
0d1d5dccdd28
Initial implementation of oscilloscope debug view
Michael Pavone <pavone@retrodev.com>
parents:
2181
diff
changeset
|
702 *subtype_a = UI_OSCILLOSCOPE_DEBUG; |
2271
3ef80963c2a7
Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents:
2243
diff
changeset
|
703 } else if (!strcmp(target + 3, "cd_graphics_debug")) { |
3ef80963c2a7
Fix stamp address mask and add WIP CD graphics debug view
Michael Pavone <pavone@retrodev.com>
parents:
2243
diff
changeset
|
704 *subtype_a = UI_CD_GRAPHICS_DEBUG; |
1638
f27142c48567
Initial stab at CRAM debug in a detached window
Michael Pavone <pavone@retrodev.com>
parents:
1634
diff
changeset
|
705 } else { |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
706 warning("Unreconized UI binding type %s\n", target); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 return 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 return BIND_UI; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
711 warning("Unrecognized binding type %s\n", target); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
712 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
713 return 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
714 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
715 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
716 void process_keys(tern_node * cur, tern_node * special, tern_node * padbuttons, tern_node *mousebuttons, char * prefix) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
717 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 char * curstr = NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
719 int len; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
720 if (!cur) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
721 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
722 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
723 char onec[2]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
724 if (prefix) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
725 len = strlen(prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
726 curstr = malloc(len + 2); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
727 memcpy(curstr, prefix, len); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
728 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
729 curstr = onec; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
730 len = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
731 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
732 curstr[len] = cur->el; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
733 curstr[len+1] = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
734 if (cur->el) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
735 process_keys(cur->straight.next, special, padbuttons, mousebuttons, curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
736 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
737 int keycode = tern_find_int(special, curstr, 0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 if (!keycode) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
739 keycode = curstr[0]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
740 if (curstr[1] != 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 warning("%s is not recognized as a key identifier, truncating to %c\n", curstr, curstr[0]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
744 char * target = cur->straight.value.ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
745 uint8_t subtype_a = 0, subtype_b = 0; |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
746 int bindtype = parse_binding_target(0, target, padbuttons, mousebuttons, &subtype_a, &subtype_b); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
747 bind_key(keycode, bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
748 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
749 process_keys(cur->left, special, padbuttons, mousebuttons, prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
750 process_keys(cur->right, special, padbuttons, mousebuttons, prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
751 if (curstr && len) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
752 free(curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
753 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
754 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
755 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
756 void process_speeds(tern_node * cur, char * prefix) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
757 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
758 char * curstr = NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
759 int len; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
760 if (!cur) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
761 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
762 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
763 char onec[2]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
764 if (prefix) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
765 len = strlen(prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 curstr = malloc(len + 2); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 memcpy(curstr, prefix, len); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 curstr = onec; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
770 len = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
771 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
772 curstr[len] = cur->el; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
773 curstr[len+1] = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
774 if (cur->el) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
775 process_speeds(cur->straight.next, curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
776 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
777 char *end; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
778 long speed_index = strtol(curstr, &end, 10); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
779 if (speed_index < 0 || end == curstr || *end) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
780 warning("%s is not a valid speed index", curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
781 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
782 if (speed_index >= num_speeds) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
783 speeds = realloc(speeds, sizeof(uint32_t) * (speed_index+1)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
784 for(; num_speeds < speed_index + 1; num_speeds++) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
785 speeds[num_speeds] = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
786 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
787 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
788 speeds[speed_index] = atoi(cur->straight.value.ptrval); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
789 if (speeds[speed_index] < 1) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
790 warning("%s is not a valid speed percentage, setting speed %d to 100", cur->straight.value.ptrval, speed_index); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
791 speeds[speed_index] = 100; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
792 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
793 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
794 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
795 process_speeds(cur->left, prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
796 process_speeds(cur->right, prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 if (curstr && len) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
798 free(curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
799 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
800 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
801 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
802 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
803 tern_node *padbuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
804 tern_node *mousebuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
805 int mouseidx; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 } pmb_state; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
807 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
808 void process_mouse_button(char *buttonstr, tern_val value, uint8_t valtype, void *data) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
810 pmb_state *state = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
811 int buttonnum = atoi(buttonstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 if (buttonnum < 1 || buttonnum > MAX_MOUSE_BUTTONS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
813 warning("Mouse button %s is out of the supported range of 1-8\n", buttonstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
815 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
816 if (valtype != TVAL_PTR) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
817 warning("Mouse button %s is not a scalar value!\n", buttonstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
818 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
819 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
820 buttonnum--; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
821 uint8_t subtype_a = 0, subtype_b = 0; |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
822 int bindtype = parse_binding_target(state->mouseidx, value.ptrval, state->padbuttons, state->mousebuttons, &subtype_a, &subtype_b); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
823 mice[state->mouseidx].buttons[buttonnum].bind_type = bindtype; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
824 mice[state->mouseidx].buttons[buttonnum].subtype_a = subtype_a; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
825 mice[state->mouseidx].buttons[buttonnum].subtype_b = subtype_b; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
826 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
827 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
828 void process_mouse(char *mousenum, tern_val value, uint8_t valtype, void *data) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
829 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
830 tern_node **buttonmaps = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
831 if (valtype != TVAL_NODE) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
832 warning("Binding for mouse %s is a scalar!\n", mousenum); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
833 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
834 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
835 tern_node *mousedef = value.ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
836 tern_node *padbuttons = buttonmaps[0]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
837 tern_node *mousebuttons = buttonmaps[1]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
838 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
839 int mouseidx = atoi(mousenum); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
840 if (mouseidx < 0 || mouseidx >= MAX_MICE) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
841 warning("Mouse numbers must be between 0 and %d, but %d is not\n", MAX_MICE, mouseidx); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
842 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
843 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
844 char *motion = tern_find_ptr(mousedef, "motion"); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
845 if (motion) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
846 uint8_t subtype_a = 0, subtype_b = 0; |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
847 int bindtype = parse_binding_target(mouseidx, motion, padbuttons, mousebuttons, &subtype_a, &subtype_b); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
848 mice[mouseidx].motion.bind_type = bindtype; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
849 mice[mouseidx].motion.subtype_a = subtype_a; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
850 mice[mouseidx].motion.subtype_b = subtype_b; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
851 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
852 tern_node *buttons = tern_find_path(mousedef, "buttons\0\0", TVAL_NODE).ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
853 if (buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
854 pmb_state state = {padbuttons, mousebuttons, mouseidx}; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
855 tern_foreach(buttons, process_mouse_button, &state); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
856 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
857 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
858 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
859 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
860 int padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
861 tern_node *padbuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
862 tern_node *mousebuttons; |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
863 int stick_deadzone; |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
864 int trigger_deadzone; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
865 } pad_button_state; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
866 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
867 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
868 static long map_warning_pad = -1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
869 void process_pad_button(char *key, tern_val val, uint8_t valtype, void *data) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
870 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
871 pad_button_state *state = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
872 int hostpadnum = state->padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
873 if (valtype != TVAL_PTR) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
874 warning("Pad button %s has a non-scalar value\n", key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
875 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
876 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
877 uint8_t subtype_a = 0, subtype_b = 0; |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
878 int bindtype = parse_binding_target(hostpadnum, val.ptrval, state->padbuttons, state->mousebuttons, &subtype_a, &subtype_b); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
879 char *end; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
880 long hostbutton = strtol(key, &end, 10); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
881 if (*end) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
882 //key is not a valid base 10 integer |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
883 hostbutton = render_translate_input_name(hostpadnum, key, 0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
884 if (hostbutton < 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
885 if (hostbutton == RENDER_INVALID_NAME) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
886 warning("%s is not a valid gamepad input name\n", key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
887 } else if (hostbutton == RENDER_NOT_MAPPED && hostpadnum != map_warning_pad) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1804
diff
changeset
|
888 debug_message("No SDL 2 mapping exists for input %s on gamepad %d\n", key, hostpadnum); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
889 map_warning_pad = hostpadnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
890 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
891 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
892 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
893 if (hostbutton & RENDER_DPAD_BIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
894 bind_dpad(hostpadnum, render_dpad_part(hostbutton), render_direction_part(hostbutton), bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
895 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
896 } else if (hostbutton & RENDER_AXIS_BIT) { |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
897 bind_axis(hostpadnum, render_axis_part(hostbutton), hostbutton & RENDER_AXIS_POS, state->trigger_deadzone, bindtype, subtype_a, subtype_b); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
898 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
899 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
900 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
901 bind_button(hostpadnum, hostbutton, bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
902 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
903 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
904 void process_pad_axis(char *key, tern_val val, uint8_t valtype, void *data) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
905 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
906 key = strdup(key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
907 pad_button_state *state = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
908 int hostpadnum = state->padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
909 if (valtype != TVAL_PTR) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
910 warning("Mapping for axis %s has a non-scalar value", key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
911 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
912 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
913 uint8_t subtype_a = 0, subtype_b = 0; |
1608
419a0a133b5c
Allow a gamepad mapping to apply to all controllers, controllers of a particular type (i.e.e 6-button PS4 controllers) or specific controllers (based on SDL2 GUID) in addition to the controller in a certain slot
Michael Pavone <pavone@retrodev.com>
parents:
1587
diff
changeset
|
914 int bindtype = parse_binding_target(hostpadnum, val.ptrval, state->padbuttons, state->mousebuttons, &subtype_a, &subtype_b); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
915 char *modifier = strchr(key, '.'); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
916 int positive = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
917 if (modifier) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
918 *modifier = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
919 modifier++; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
920 if (!strcmp("negative", modifier)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
921 positive = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
922 } else if(strcmp("positive", modifier)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
923 warning("Invalid axis modifier %s for axis %s on pad %d\n", modifier, key, hostpadnum); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
924 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
925 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
926 char *end; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
927 long axis = strtol(key, &end, 10); |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
928 int deadzone = state->stick_deadzone; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
929 if (*end) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
930 //key is not a valid base 10 integer |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
931 axis = render_translate_input_name(hostpadnum, key, 1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
932 if (axis < 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
933 if (axis == RENDER_INVALID_NAME) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
934 warning("%s is not a valid gamepad input name\n", key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
935 } else if (axis == RENDER_NOT_MAPPED && hostpadnum != map_warning_pad) { |
1839
78abbabfd58d
Get Android build working again and update for SDL 2.0.7 (last version to support older versions of Android)
Michael Pavone <pavone@retrodev.com>
parents:
1804
diff
changeset
|
936 debug_message("No SDL 2 mapping exists for input %s on gamepad %d\n", key, hostpadnum); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
937 map_warning_pad = hostpadnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
938 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
939 goto done; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
940 } |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
941 if (!strcmp("lefttrigger", key) || !strcmp("righttrigger", key) || !strcmp("l2", key) || !strcmp("r2", key)) { |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
942 deadzone = state->trigger_deadzone; |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
943 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
944 if (axis & RENDER_DPAD_BIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
945 bind_dpad(hostpadnum, render_dpad_part(axis), render_direction_part(axis), bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
946 goto done; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
947 } else if (axis & RENDER_AXIS_BIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
948 axis = render_axis_part(axis); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
949 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
950 bind_button(hostpadnum, axis, bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
951 goto done; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
952 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
953 } |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
954 bind_axis(hostpadnum, axis, positive, deadzone, bindtype, subtype_a, subtype_b); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
955 done: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
956 free(key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
957 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
958 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
959 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
960 static tern_node *get_pad_buttons() |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
961 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
962 static tern_node *padbuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
963 if (!padbuttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
964 padbuttons = tern_insert_int(NULL, ".up", DPAD_UP); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
965 padbuttons = tern_insert_int(padbuttons, ".down", DPAD_DOWN); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
966 padbuttons = tern_insert_int(padbuttons, ".left", DPAD_LEFT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
967 padbuttons = tern_insert_int(padbuttons, ".right", DPAD_RIGHT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
968 padbuttons = tern_insert_int(padbuttons, ".a", BUTTON_A); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
969 padbuttons = tern_insert_int(padbuttons, ".b", BUTTON_B); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
970 padbuttons = tern_insert_int(padbuttons, ".c", BUTTON_C); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
971 padbuttons = tern_insert_int(padbuttons, ".x", BUTTON_X); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
972 padbuttons = tern_insert_int(padbuttons, ".y", BUTTON_Y); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
973 padbuttons = tern_insert_int(padbuttons, ".z", BUTTON_Z); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
974 padbuttons = tern_insert_int(padbuttons, ".start", BUTTON_START); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
975 padbuttons = tern_insert_int(padbuttons, ".mode", BUTTON_MODE); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
976 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
977 return padbuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
978 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
979 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
980 static tern_node *get_mouse_buttons() |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
981 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
982 static tern_node *mousebuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
983 if (!mousebuttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
984 mousebuttons = tern_insert_int(NULL, ".left", MOUSE_LEFT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
985 mousebuttons = tern_insert_int(mousebuttons, ".middle", MOUSE_MIDDLE); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
986 mousebuttons = tern_insert_int(mousebuttons, ".right", MOUSE_RIGHT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
987 mousebuttons = tern_insert_int(mousebuttons, ".start", MOUSE_START); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
988 mousebuttons = tern_insert_int(mousebuttons, ".motion", PSEUDO_BUTTON_MOTION); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
989 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
990 return mousebuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
991 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
992 |
2181
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
993 uint8_t bind_up(const char *target) |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
994 { |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
995 keybinding bind; |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
996 bind.bind_type = parse_binding_target(0, target, get_pad_buttons(), get_mouse_buttons(), &bind.subtype_a, &bind.subtype_b); |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
997 if (!bind.bind_type) { |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
998 return 0; |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
999 } |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1000 handle_binding_up(&bind); |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1001 return 1; |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1002 } |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1003 |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1004 uint8_t bind_down(const char *target) |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1005 { |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1006 keybinding bind; |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1007 bind.bind_type = parse_binding_target(0, target, get_pad_buttons(), get_mouse_buttons(), &bind.subtype_a, &bind.subtype_b); |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1008 if (!bind.bind_type) { |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1009 return 0; |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1010 } |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1011 handle_binding_down(&bind); |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1012 return 1; |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1013 } |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1014 |
0c723b8b637c
Add bindup and binddown debugger commands
Michael Pavone <pavone@retrodev.com>
parents:
2162
diff
changeset
|
1015 |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1016 tern_node *get_binding_node_for_pad(int padnum, controller_info *info) |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1017 { |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1018 if (padnum > MAX_JOYSTICKS) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1019 return NULL; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1020 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1021 tern_node * pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval; |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1022 if (!pads) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1023 return NULL; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1024 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1025 char numstr[11]; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1026 sprintf(numstr, "%d", padnum); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1027 tern_node * pad = tern_find_node(pads, numstr); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1028 if (!pad) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1029 char *type_id = render_joystick_type_id(padnum); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1030 pad = tern_find_node(pads, type_id); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1031 free(type_id); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1032 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1033 if (!pad) { |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1034 char *key = make_controller_type_key(info); |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1035 pad = tern_find_node(pads, key); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1036 free(key); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1037 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1038 if (!pad) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1039 pad = tern_find_node(pads, "default"); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1040 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1041 return pad; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1042 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1043 |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1044 void handle_joy_added(int joystick) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1045 { |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1046 controller_info info = get_controller_info(joystick); |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1047 tern_node *pad = get_binding_node_for_pad(joystick, &info); |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1048 if (!pad) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1049 return; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1050 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1051 tern_node * dpad_node = tern_find_node(pad, "dpads"); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1052 if (dpad_node) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1053 for (int dpad = 0; dpad < 10; dpad++) |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1054 { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1055 char numstr[2] = {dpad + '0', 0}; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1056 tern_node * pad_dpad = tern_find_node(dpad_node, numstr); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1057 char * dirs[] = {"up", "down", "left", "right"}; |
1679
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1058 char *render_dirs[] = {"dpup", "dpdown", "dpleft", "dpright"}; |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1059 int dirnums[] = {RENDER_DPAD_UP, RENDER_DPAD_DOWN, RENDER_DPAD_LEFT, RENDER_DPAD_RIGHT}; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1060 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1061 char * target = tern_find_ptr(pad_dpad, dirs[dir]); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1062 if (target) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1063 uint8_t subtype_a = 0, subtype_b = 0; |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1064 int bindtype = parse_binding_target(joystick, target, get_pad_buttons(), get_mouse_buttons(), &subtype_a, &subtype_b); |
1679
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1065 int32_t hostbutton = dpad >0 ? -1 : render_translate_input_name(joystick, render_dirs[dir], 0); |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1066 if (hostbutton < 0) { |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1067 //assume this is a raw dpad mapping |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1068 bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b); |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1069 } else if (hostbutton & RENDER_DPAD_BIT) { |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1070 bind_dpad(joystick, render_dpad_part(hostbutton), render_direction_part(hostbutton), bindtype, subtype_a, subtype_b); |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1071 } else if (hostbutton & RENDER_AXIS_BIT) { |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1072 //SDL2 knows internally whether this should be a positive or negative binding, but doesn't expose that externally |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1073 //for now I'll just assume that any controller with axes for a d-pad has these mapped the "sane" way |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1074 bind_axis(joystick, render_axis_part(hostbutton), dir == 1 || dir == 3 ? 1 : 0, info.stick_deadzone, bindtype, subtype_a, subtype_b); |
1679
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1075 } else { |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1076 bind_button(joystick, hostbutton, bindtype, subtype_a, subtype_b); |
deaf31803b11
Add code to handle controllers that have their d-pads mapped as buttons or axes
Michael Pavone <pavone@retrodev.com>
parents:
1672
diff
changeset
|
1077 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1078 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1079 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1080 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1081 } |
2317
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1082 pad_button_state state = { |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1083 .padnum = joystick, |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1084 .padbuttons = get_pad_buttons(), |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1085 .mousebuttons = get_mouse_buttons(), |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1086 .stick_deadzone = info.stick_deadzone, |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1087 .trigger_deadzone = info.trigger_deadzone |
e836cf11783b
Make deadzones configurable and bump up the default value
Michael Pavone <pavone@retrodev.com>
parents:
2314
diff
changeset
|
1088 }; |
1623
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1089 tern_node *button_node = tern_find_node(pad, "buttons"); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1090 if (button_node) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1091 tern_foreach(button_node, process_pad_button, &state); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1092 } |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1093 tern_node *axes_node = tern_find_node(pad, "axes"); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1094 if (axes_node) { |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1095 tern_foreach(axes_node, process_pad_axis, &state); |
18a946ec74c8
Pull current controller config in binding UI from whatever the actual binding code would end up using
Michael Pavone <pavone@retrodev.com>
parents:
1608
diff
changeset
|
1096 } |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1097 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1098 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1099 //only handles keyboards and mice as gamepads are handled on hotplug events |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1100 void set_bindings(void) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1101 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1102 tern_node * special = tern_insert_int(NULL, "up", RENDERKEY_UP); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1103 special = tern_insert_int(special, "down", RENDERKEY_DOWN); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1104 special = tern_insert_int(special, "left", RENDERKEY_LEFT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1105 special = tern_insert_int(special, "right", RENDERKEY_RIGHT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1106 special = tern_insert_int(special, "enter", '\r'); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1107 special = tern_insert_int(special, "space", ' '); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1108 special = tern_insert_int(special, "tab", '\t'); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1109 special = tern_insert_int(special, "backspace", '\b'); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1110 special = tern_insert_int(special, "esc", RENDERKEY_ESC); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1111 special = tern_insert_int(special, "delete", RENDERKEY_DEL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1112 special = tern_insert_int(special, "lshift", RENDERKEY_LSHIFT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1113 special = tern_insert_int(special, "rshift", RENDERKEY_RSHIFT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1114 special = tern_insert_int(special, "lctrl", RENDERKEY_LCTRL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1115 special = tern_insert_int(special, "rctrl", RENDERKEY_RCTRL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1116 special = tern_insert_int(special, "lalt", RENDERKEY_LALT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1117 special = tern_insert_int(special, "ralt", RENDERKEY_RALT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1118 special = tern_insert_int(special, "home", RENDERKEY_HOME); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1119 special = tern_insert_int(special, "end", RENDERKEY_END); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1120 special = tern_insert_int(special, "pageup", RENDERKEY_PAGEUP); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1121 special = tern_insert_int(special, "pagedown", RENDERKEY_PAGEDOWN); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1122 special = tern_insert_int(special, "f1", RENDERKEY_F1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1123 special = tern_insert_int(special, "f2", RENDERKEY_F2); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1124 special = tern_insert_int(special, "f3", RENDERKEY_F3); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1125 special = tern_insert_int(special, "f4", RENDERKEY_F4); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1126 special = tern_insert_int(special, "f5", RENDERKEY_F5); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1127 special = tern_insert_int(special, "f6", RENDERKEY_F6); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1128 special = tern_insert_int(special, "f7", RENDERKEY_F7); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1129 special = tern_insert_int(special, "f8", RENDERKEY_F8); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1130 special = tern_insert_int(special, "f9", RENDERKEY_F9); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1131 special = tern_insert_int(special, "f10", RENDERKEY_F10); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1132 special = tern_insert_int(special, "f11", RENDERKEY_F11); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1133 special = tern_insert_int(special, "f12", RENDERKEY_F12); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1134 special = tern_insert_int(special, "select", RENDERKEY_SELECT); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1135 special = tern_insert_int(special, "play", RENDERKEY_PLAY); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1136 special = tern_insert_int(special, "search", RENDERKEY_SEARCH); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1137 special = tern_insert_int(special, "back", RENDERKEY_BACK); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1138 special = tern_insert_int(special, "np0", RENDERKEY_NP0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1139 special = tern_insert_int(special, "np1", RENDERKEY_NP1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1140 special = tern_insert_int(special, "np2", RENDERKEY_NP2); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1141 special = tern_insert_int(special, "np3", RENDERKEY_NP3); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1142 special = tern_insert_int(special, "np4", RENDERKEY_NP4); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1143 special = tern_insert_int(special, "np5", RENDERKEY_NP5); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1144 special = tern_insert_int(special, "np6", RENDERKEY_NP6); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1145 special = tern_insert_int(special, "np7", RENDERKEY_NP7); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1146 special = tern_insert_int(special, "np8", RENDERKEY_NP8); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1147 special = tern_insert_int(special, "np9", RENDERKEY_NP9); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1148 special = tern_insert_int(special, "np/", RENDERKEY_NP_DIV); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1149 special = tern_insert_int(special, "np*", RENDERKEY_NP_MUL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1150 special = tern_insert_int(special, "np-", RENDERKEY_NP_MIN); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1151 special = tern_insert_int(special, "np+", RENDERKEY_NP_PLUS); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1152 special = tern_insert_int(special, "npenter", RENDERKEY_NP_ENTER); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1153 special = tern_insert_int(special, "np.", RENDERKEY_NP_STOP); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1154 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1155 tern_node *padbuttons = get_pad_buttons(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1156 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1157 tern_node *mousebuttons = get_mouse_buttons(); |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1158 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1159 tern_node * keys = tern_find_path(config, "bindings\0keys\0", TVAL_NODE).ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1160 process_keys(keys, special, padbuttons, mousebuttons, NULL); |
1587
ea687ca7d845
Fix missing include in bindings.c
Michael Pavone <pavone@retrodev.com>
parents:
1583
diff
changeset
|
1161 tern_free(special); |
2083
372625dd9590
Persist BRAM to file. Load BIOS relative to blastem directory
Michael Pavone <pavone@retrodev.com>
parents:
1980
diff
changeset
|
1162 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1163 memset(mice, 0, sizeof(mice)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1164 tern_node * mice = tern_find_path(config, "bindings\0mice\0", TVAL_NODE).ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1165 if (mice) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1166 tern_node *buttonmaps[2] = {padbuttons, mousebuttons}; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1167 tern_foreach(mice, process_mouse, buttonmaps); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1168 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1169 tern_node * speed_nodes = tern_find_path(config, "clocks\0speeds\0", TVAL_NODE).ptrval; |
2314
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1170 free(speeds); |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1171 speeds = malloc(sizeof(uint32_t)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1172 speeds[0] = 100; |
2314
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1173 num_speeds = 1; |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1174 process_speeds(speed_nodes, NULL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1175 for (int i = 0; i < num_speeds; i++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1176 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1177 if (!speeds[i]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1178 warning("Speed index %d was not set to a valid percentage!", i); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1179 speeds[i] = 100; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1180 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1181 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1182 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1183 |
2314
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1184 void update_pad_bindings(void) |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1185 { |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1186 for (int i = 0; i < MAX_JOYSTICKS; i++) |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1187 { |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1188 if (joysticks[i].num_buttons || joysticks[i].num_axes || joysticks[i].num_dpads) { |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1189 reset_joystick_bindings(i); |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1190 handle_joy_added(i); |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1191 } |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1192 } |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1193 } |
59fd8aa352e2
Apply binding changes after a config change in UI
Michael Pavone <pavone@retrodev.com>
parents:
2306
diff
changeset
|
1194 |
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1195 void bindings_set_mouse_mode(uint8_t mode) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1196 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1197 mouse_mode = mode; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1198 if (mode == MOUSE_RELATIVE) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1199 render_relative_mouse(1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1200 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1201 } |