Mercurial > repos > blastem
annotate bindings.c @ 1585:15116d4fdf40
Fix cycle counts for BCD instructions, RESET, and MOVE from SR
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 18 May 2018 19:00:10 -0700 |
parents | 430dd12e4010 |
children | ea687ca7d845 |
rev | line source |
---|---|
1583
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 #include "render.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 #include "system.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 #include "io.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "blastem.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 #include "saves.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 #include "util.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 #include "genesis.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 #include "menu.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 #include "bindings.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 #ifndef DISABLE_NUKLEAR |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 #include "nuklear_ui/blastem_nuklear.h" |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 #endif |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 enum { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 BIND_NONE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 BIND_UI, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 BIND_GAMEPAD, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 BIND_MOUSE |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 }; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 typedef enum { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 UI_DEBUG_MODE_INC, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 UI_DEBUG_PAL_INC, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 UI_ENTER_DEBUGGER, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 UI_SAVE_STATE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 UI_SET_SPEED, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 UI_NEXT_SPEED, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 UI_PREV_SPEED, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 UI_RELEASE_MOUSE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 UI_TOGGLE_KEYBOARD_CAPTURE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 UI_TOGGLE_FULLSCREEN, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 UI_SOFT_RESET, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 UI_RELOAD, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 UI_SMS_PAUSE, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 UI_SCREENSHOT, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 UI_EXIT |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 } ui_action; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 uint8_t bind_type; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 uint8_t subtype_a; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 uint8_t subtype_b; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 } keybinding; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 keybinding bindings[4]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 uint8_t state; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 } joydpad; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 keybinding positive; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 keybinding negative; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 int16_t value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 } joyaxis; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 keybinding *buttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 joydpad *dpads; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 joyaxis *axes; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 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
|
61 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
|
62 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
|
63 } joystick; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 keybinding buttons[MAX_MOUSE_BUTTONS]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 keybinding motion; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 } mousebinding; |
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 #define DEFAULT_JOYBUTTON_ALLOC 12 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 static keybinding *bindings[0x10000]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 static joystick joysticks[MAX_JOYSTICKS]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 static mousebinding mice[MAX_MICE]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 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
|
75 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 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
|
77 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 binding->bind_type = bind_type; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 binding->subtype_a = subtype_a; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 binding->subtype_b = subtype_b; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 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
|
84 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 int bucket = keycode >> 15 & 0xFFFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 if (!bindings[bucket]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 bindings[bucket] = malloc(sizeof(keybinding) * 0x8000); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 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
|
89 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 int idx = keycode & 0x7FFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 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
|
92 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 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
|
95 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 return; |
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 if (!joysticks[joystick].buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 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
|
101 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
|
102 } 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
|
103 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
|
104 joysticks[joystick].num_buttons *= 2; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 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
|
106 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
|
107 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 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
|
109 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 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
|
112 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 if (!joysticks[joystick].dpads) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 //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
|
118 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
|
119 joysticks[joystick].num_dpads = dpad+1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 } 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
|
121 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
|
122 joysticks[joystick].num_dpads *= 2; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 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
|
124 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
|
125 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 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
|
127 if (dpadbits[i] & direction) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 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
|
129 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 void bind_axis(int joystick, int axis, int positive, 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
|
135 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 if (!joysticks[joystick].axes) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 //typical gamepad has 4 axes |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 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
|
142 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
|
143 } 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
|
144 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
|
145 joysticks[joystick].num_axes *= 2; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 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
|
147 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
|
148 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 if (positive) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 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
|
151 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 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
|
153 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 void reset_joystick_bindings(int joystick) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 if (joystick >= MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 if (joysticks[joystick].buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 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
|
163 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 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
|
165 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 if (joysticks[joystick].dpads) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 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
|
169 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 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
|
171 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 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
|
173 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 } |
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].axes) { |
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_axes; 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].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
|
180 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
|
181 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 } |
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 void handle_binding_down(keybinding * binding) |
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 if (!current_system) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 return; |
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 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
|
191 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 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
|
193 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 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
|
195 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 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
|
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 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 static uint8_t keyboard_captured; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 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
|
202 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 int bucket = keycode >> 15 & 0xFFFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 int idx = keycode & 0x7FFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 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
|
206 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
|
207 handle_binding_down(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 } 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
|
209 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
|
210 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 } |
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 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
|
214 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 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
|
216 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 keybinding * binding = joysticks[joystick].buttons + button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 handle_binding_down(binding); |
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 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 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
|
223 static uint8_t mouse_captured; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 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
|
225 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 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
|
227 mouse_captured = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 render_relative_mouse(1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 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
|
232 return; |
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 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
|
235 handle_binding_down(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 static uint8_t ui_debug_mode = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 static uint8_t ui_debug_pal = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 static int current_speed = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 static int num_speeds = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 static uint32_t * speeds = NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 static uint8_t mouse_captured; |
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 #ifdef _WIN32 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 #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
|
249 #endif |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 void handle_binding_up(keybinding * binding) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 switch(binding->bind_type) |
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 case BIND_GAMEPAD: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 if (current_system && current_system->gamepad_up) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 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
|
258 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 case BIND_MOUSE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 if (current_system && current_system->mouse_up) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 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
|
263 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 case BIND_UI: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 switch (binding->subtype_a) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 case UI_DEBUG_MODE_INC: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 current_system->inc_debug_mode(current_system); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 case UI_DEBUG_PAL_INC: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 current_system->inc_debug_pal(current_system); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 case UI_ENTER_DEBUGGER: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 current_system->enter_debugger = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 case UI_SAVE_STATE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 current_system->save_state = QUICK_SAVE_SLOT+1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 case UI_NEXT_SPEED: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 current_speed++; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 if (current_speed >= num_speeds) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 current_speed = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 current_system->set_speed_percent(current_system, speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 case UI_PREV_SPEED: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 current_speed--; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 if (current_speed < 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 current_speed = num_speeds - 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 current_system->set_speed_percent(current_system, speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 case UI_SET_SPEED: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 if (binding->subtype_b < num_speeds) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 current_speed = binding->subtype_b; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 printf("Setting speed to %d: %d\n", current_speed, speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 current_system->set_speed_percent(current_system, speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 printf("Setting speed to %d\n", speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 current_system->set_speed_percent(current_system, speeds[current_speed]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 case UI_RELEASE_MOUSE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 if (mouse_captured) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 mouse_captured = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 render_relative_mouse(0); |
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 UI_TOGGLE_KEYBOARD_CAPTURE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 if (current_system && current_system->has_keyboard) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 keyboard_captured = !keyboard_captured; |
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 UI_TOGGLE_FULLSCREEN: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 render_toggle_fullscreen(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 case UI_SOFT_RESET: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 current_system->soft_reset(current_system); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 case UI_RELOAD: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 reload_media(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 case UI_SMS_PAUSE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 if (current_system && current_system->gamepad_down) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 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
|
329 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 case UI_SCREENSHOT: { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 char *screenshot_base = tern_find_path(config, "ui\0screenshot_path\0", TVAL_PTR).ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 if (!screenshot_base) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 screenshot_base = "$HOME"; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 tern_node *vars = tern_insert_ptr(NULL, "HOME", get_home_dir()); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 vars = tern_insert_ptr(vars, "EXEDIR", get_exe_dir()); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 screenshot_base = replace_vars(screenshot_base, vars, 1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 tern_free(vars); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 time_t now = time(NULL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 struct tm local_store; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 char fname_part[256]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 char *template = tern_find_path(config, "ui\0screenshot_template\0", TVAL_PTR).ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 if (!template) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 template = "blastem_%c.ppm"; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
346 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 strftime(fname_part, sizeof(fname_part), template, localtime_r(&now, &local_store)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 char const *parts[] = {screenshot_base, PATH_SEP, fname_part}; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 char *path = alloc_concat_m(3, parts); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 free(screenshot_base); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 render_save_screenshot(path); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 case UI_EXIT: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 #ifndef DISABLE_NUKLEAR |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 if (is_nuklear_active()) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 show_pause_menu(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 #endif |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 current_system->request_exit(current_system); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 if (current_system->type == SYSTEM_GENESIS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 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
|
363 if (gen->extra) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 //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
|
365 menu_context *menu = gen->extra; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 menu->external_game_load = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 #ifndef DISABLE_NUKLEAR |
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 #endif |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 } |
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 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 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
|
379 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 int bucket = keycode >> 15 & 0xFFFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 int idx = keycode & 0x7FFF; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 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
|
383 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
|
384 handle_binding_up(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 } 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
|
386 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
|
387 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 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
|
391 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 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
|
393 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 keybinding * binding = joysticks[joystick].buttons + button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 handle_binding_up(binding); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 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
|
400 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 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
|
402 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 joydpad * dpad = joysticks[joystick].dpads + dpadnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 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
|
406 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
|
407 dpad->state = value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 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
|
409 if (newdown & dpadbits[i]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 handle_binding_down(dpad->bindings + i); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 } else if(newup & dpadbits[i]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 handle_binding_up(dpad->bindings + i); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 #define JOY_AXIS_THRESHOLD 2000 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 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
|
420 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 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
|
422 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 joyaxis *jaxis = joysticks[joystick].axes + axis; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 int old_active = abs(jaxis->value) > JOY_AXIS_THRESHOLD; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 int new_active = abs(value) > JOY_AXIS_THRESHOLD; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 int old_pos = jaxis->value > 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 int new_pos = value > 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 jaxis->value = value; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 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
|
431 //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
|
432 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
|
433 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 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
|
435 //previously unactivated direction is now active |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 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
|
437 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 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
|
441 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 if (mouse >= MAX_MICE || !current_system) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 return; |
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 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
|
446 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
|
447 switch(mouse_mode) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 case MOUSE_NONE: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 case MOUSE_ABSOLUTE: { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 if (current_system->mouse_motion_absolute) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 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
|
454 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
|
455 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
|
456 int32_t adj_y = y * scale_y + 2 * render_overscan_top() - 4; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 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
|
459 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 case MOUSE_RELATIVE: { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 if (current_system->mouse_motion_relative) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 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
|
465 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 case MOUSE_CAPTURE: { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 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
|
470 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
|
471 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 break; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 handle_binding_up(&mice[mouse].motion); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 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
|
481 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 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
|
483 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 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
|
486 handle_binding_up(binding); |
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 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 void bindings_release_capture(void) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 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
|
492 render_relative_mouse(0); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 keyboard_captured = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 void bindings_reacquire_capture(void) |
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 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
|
500 render_relative_mouse(1); |
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 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 int parse_binding_target(char * target, tern_node * padbuttons, tern_node *mousebuttons, 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
|
505 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 const int gpadslen = strlen("gamepads."); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 const int mouselen = strlen("mouse."); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 if (!strncmp(target, "gamepads.", gpadslen)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 if (target[gpadslen] >= '1' && target[gpadslen] <= '8') { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 int padnum = target[gpadslen] - '0'; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 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
|
512 if (button) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 *subtype_a = padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 *subtype_b = button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 return BIND_GAMEPAD; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 if (target[gpadslen+1]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 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
|
519 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 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
|
521 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 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
|
525 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 } else if(!strncmp(target, "mouse.", mouselen)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 if (target[mouselen] >= '1' && target[mouselen] <= '8') { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 int mousenum = target[mouselen] - '0'; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 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
|
530 if (button) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 *subtype_a = mousenum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 *subtype_b = button; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
533 return BIND_MOUSE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
534 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 if (target[mouselen+1]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
536 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
|
537 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
538 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
|
539 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
541 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 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
|
543 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 } else if(!strncmp(target, "ui.", strlen("ui."))) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 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
|
546 *subtype_a = UI_DEBUG_MODE_INC; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 } else if(!strcmp(target + 3, "vdp_debug_pal")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
548 *subtype_a = UI_DEBUG_PAL_INC; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
549 } 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
|
550 *subtype_a = UI_ENTER_DEBUGGER; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
551 } 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
|
552 *subtype_a = UI_SAVE_STATE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 } else if(!strncmp(target + 3, "set_speed.", strlen("set_speed."))) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 *subtype_a = UI_SET_SPEED; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
555 *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
|
556 } 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
|
557 *subtype_a = UI_NEXT_SPEED; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
558 } 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
|
559 *subtype_a = UI_PREV_SPEED; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
560 } 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
|
561 *subtype_a = UI_RELEASE_MOUSE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
562 } 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
|
563 *subtype_a = UI_TOGGLE_KEYBOARD_CAPTURE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 } 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
|
565 *subtype_a = UI_TOGGLE_FULLSCREEN; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
566 } 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
|
567 *subtype_a = UI_SOFT_RESET; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
568 } else if (!strcmp(target + 3, "reload")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
569 *subtype_a = UI_RELOAD; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
570 } 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
|
571 *subtype_a = UI_SMS_PAUSE; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
572 } else if (!strcmp(target + 3, "screenshot")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
573 *subtype_a = UI_SCREENSHOT; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
574 } else if(!strcmp(target + 3, "exit")) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
575 *subtype_a = UI_EXIT; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
576 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
577 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
|
578 return 0; |
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 return BIND_UI; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
581 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
582 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
|
583 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 return 0; |
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 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
|
588 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
589 char * curstr = NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
590 int len; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
591 if (!cur) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
592 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
593 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 char onec[2]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
595 if (prefix) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 len = strlen(prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 curstr = malloc(len + 2); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 memcpy(curstr, prefix, len); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 curstr = onec; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 len = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 curstr[len] = cur->el; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 curstr[len+1] = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 if (cur->el) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
606 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
|
607 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
608 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
|
609 if (!keycode) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 keycode = curstr[0]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 if (curstr[1] != 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 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
|
613 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 char * target = cur->straight.value.ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
616 uint8_t subtype_a = 0, subtype_b = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 int bindtype = parse_binding_target(target, padbuttons, mousebuttons, &subtype_a, &subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 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
|
619 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
620 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
|
621 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
|
622 if (curstr && len) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 free(curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
624 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
627 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
|
628 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 char * curstr = NULL; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
630 int len; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
631 if (!cur) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
632 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
633 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
634 char onec[2]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
635 if (prefix) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
636 len = strlen(prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
637 curstr = malloc(len + 2); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 memcpy(curstr, prefix, len); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
639 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
640 curstr = onec; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
641 len = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
643 curstr[len] = cur->el; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 curstr[len+1] = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
645 if (cur->el) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 process_speeds(cur->straight.next, curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 char *end; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 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
|
650 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
|
651 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
|
652 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 if (speed_index >= num_speeds) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
654 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
|
655 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
|
656 speeds[num_speeds] = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
657 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
658 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
659 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
|
660 if (speeds[speed_index] < 1) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 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
|
662 speeds[speed_index] = 100; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
663 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
666 process_speeds(cur->left, prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
667 process_speeds(cur->right, prefix); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
668 if (curstr && len) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
669 free(curstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
670 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
671 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
672 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
674 tern_node *padbuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 tern_node *mousebuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 int mouseidx; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 } pmb_state; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
679 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
|
680 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 pmb_state *state = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
682 int buttonnum = atoi(buttonstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
683 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
|
684 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
|
685 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 if (valtype != TVAL_PTR) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
688 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
|
689 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
690 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 buttonnum--; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 uint8_t subtype_a = 0, subtype_b = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 int bindtype = parse_binding_target(value.ptrval, state->padbuttons, state->mousebuttons, &subtype_a, &subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
694 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
|
695 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
|
696 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
|
697 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
698 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 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
|
700 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
701 tern_node **buttonmaps = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
702 if (valtype != TVAL_NODE) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
703 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
|
704 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
705 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
706 tern_node *mousedef = value.ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 tern_node *padbuttons = buttonmaps[0]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 tern_node *mousebuttons = buttonmaps[1]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 int mouseidx = atoi(mousenum); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
711 if (mouseidx < 0 || mouseidx >= MAX_MICE) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
712 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
|
713 return; |
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 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
|
716 if (motion) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
717 uint8_t subtype_a = 0, subtype_b = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 int bindtype = parse_binding_target(motion, padbuttons, mousebuttons, &subtype_a, &subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
719 mice[mouseidx].motion.bind_type = bindtype; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
720 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
|
721 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
|
722 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
723 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
|
724 if (buttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
725 pmb_state state = {padbuttons, mousebuttons, mouseidx}; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
726 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
|
727 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
728 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
729 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
730 typedef struct { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
731 int padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
732 tern_node *padbuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
733 tern_node *mousebuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
734 } pad_button_state; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
735 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
736 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
737 static long map_warning_pad = -1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 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
|
739 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
740 pad_button_state *state = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 int hostpadnum = state->padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 if (valtype != TVAL_PTR) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 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
|
744 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
745 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
746 uint8_t subtype_a = 0, subtype_b = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
747 int bindtype = parse_binding_target(val.ptrval, state->padbuttons, state->mousebuttons, &subtype_a, &subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
748 char *end; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
749 long hostbutton = strtol(key, &end, 10); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
750 if (*end) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
751 //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
|
752 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
|
753 if (hostbutton < 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
754 if (hostbutton == RENDER_INVALID_NAME) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
755 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
|
756 } else if (hostbutton == RENDER_NOT_MAPPED && hostpadnum != map_warning_pad) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
757 warning("No SDL 2 mapping exists for input %s on gamepad %d\n", key, hostpadnum); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
758 map_warning_pad = hostpadnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
759 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
760 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
761 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
762 if (hostbutton & RENDER_DPAD_BIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
763 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
|
764 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
765 } else if (hostbutton & RENDER_AXIS_BIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 bind_axis(hostpadnum, render_axis_part(hostbutton), 1, bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
770 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
|
771 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
772 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
773 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
|
774 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
775 key = strdup(key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
776 pad_button_state *state = data; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
777 int hostpadnum = state->padnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
778 if (valtype != TVAL_PTR) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
779 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
|
780 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
781 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
782 uint8_t subtype_a = 0, subtype_b = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
783 int bindtype = parse_binding_target(val.ptrval, state->padbuttons, state->mousebuttons, &subtype_a, &subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
784 char *modifier = strchr(key, '.'); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
785 int positive = 1; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
786 if (modifier) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
787 *modifier = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
788 modifier++; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
789 if (!strcmp("negative", modifier)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
790 positive = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
791 } else if(strcmp("positive", modifier)) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
792 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
|
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 char *end; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
796 long axis = strtol(key, &end, 10); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 if (*end) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
798 //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
|
799 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
|
800 if (axis < 0) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
801 if (axis == RENDER_INVALID_NAME) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
802 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
|
803 } else if (axis == RENDER_NOT_MAPPED && hostpadnum != map_warning_pad) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
804 warning("No SDL 2 mapping exists for input %s on gamepad %d\n", key, hostpadnum); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
805 map_warning_pad = hostpadnum; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
807 goto done; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
808 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 if (axis & RENDER_DPAD_BIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
810 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
|
811 goto done; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 } else if (axis & RENDER_AXIS_BIT) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
813 axis = render_axis_part(axis); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 } else { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
815 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
|
816 goto done; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
817 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
818 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
819 bind_axis(hostpadnum, axis, positive, bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
820 done: |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
821 free(key); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
822 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
823 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
824 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
825 static tern_node *get_pad_buttons() |
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 static tern_node *padbuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
828 if (!padbuttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
829 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
|
830 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
|
831 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
|
832 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
|
833 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
|
834 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
|
835 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
|
836 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
|
837 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
|
838 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
|
839 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
|
840 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
|
841 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
842 return padbuttons; |
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 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
845 static tern_node *get_mouse_buttons() |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
846 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
847 static tern_node *mousebuttons; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
848 if (!mousebuttons) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
849 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
|
850 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
|
851 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
|
852 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
|
853 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
|
854 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
855 return mousebuttons; |
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 void handle_joy_added(int joystick) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
859 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
860 if (joystick > MAX_JOYSTICKS) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
861 return; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
862 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
863 tern_node * pads = tern_find_path(config, "bindings\0pads\0", TVAL_NODE).ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
864 if (pads) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
865 char numstr[11]; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
866 sprintf(numstr, "%d", joystick); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
867 tern_node * pad = tern_find_node(pads, numstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
868 if (pad) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
869 tern_node * dpad_node = tern_find_node(pad, "dpads"); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
870 if (dpad_node) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
871 for (int dpad = 0; dpad < 10; dpad++) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
872 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
873 numstr[0] = dpad + '0'; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
874 numstr[1] = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
875 tern_node * pad_dpad = tern_find_node(dpad_node, numstr); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
876 char * dirs[] = {"up", "down", "left", "right"}; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
877 //TODO: Support controllers that have d-pads implemented as analog axes or buttons |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
878 int dirnums[] = {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
|
879 for (int dir = 0; dir < sizeof(dirs)/sizeof(dirs[0]); dir++) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
880 char * target = tern_find_ptr(pad_dpad, dirs[dir]); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
881 if (target) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
882 uint8_t subtype_a = 0, subtype_b = 0; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
883 int bindtype = parse_binding_target(target, get_pad_buttons(), get_mouse_buttons(), &subtype_a, &subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
884 bind_dpad(joystick, dpad, dirnums[dir], bindtype, subtype_a, subtype_b); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
885 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
886 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
887 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
888 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
889 tern_node *button_node = tern_find_node(pad, "buttons"); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
890 if (button_node) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
891 pad_button_state state = { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
892 .padnum = joystick, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
893 .padbuttons = get_pad_buttons(), |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
894 .mousebuttons = get_mouse_buttons() |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
895 }; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
896 tern_foreach(button_node, process_pad_button, &state); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
897 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
898 tern_node *axes_node = tern_find_node(pad, "axes"); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
899 if (axes_node) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
900 pad_button_state state = { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
901 .padnum = joystick, |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
902 .padbuttons = get_pad_buttons(), |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
903 .mousebuttons = get_mouse_buttons() |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
904 }; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
905 tern_foreach(axes_node, process_pad_axis, &state); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
906 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
907 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
908 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
909 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
910 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
911 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
912 //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
|
913 void set_bindings(void) |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
914 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
915 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
|
916 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
|
917 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
|
918 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
|
919 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
|
920 special = tern_insert_int(special, "space", ' '); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
921 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
|
922 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
|
923 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
|
924 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
|
925 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 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
|
935 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 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
|
941 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
|
942 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
|
943 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
|
944 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
|
945 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
|
946 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
|
947 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
|
948 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
|
949 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
|
950 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
|
951 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
|
952 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
|
953 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
|
954 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
|
955 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
|
956 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
|
957 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
|
958 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
|
959 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
|
960 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
|
961 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
|
962 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
|
963 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
|
964 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
|
965 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
|
966 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
|
967 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
968 tern_node *padbuttons = get_pad_buttons(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
969 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
970 tern_node *mousebuttons = get_mouse_buttons(); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
971 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
972 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
|
973 process_keys(keys, special, padbuttons, mousebuttons, NULL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
974 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
975 memset(mice, 0, sizeof(mice)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
976 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
|
977 if (mice) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
978 tern_node *buttonmaps[2] = {padbuttons, mousebuttons}; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
979 tern_foreach(mice, process_mouse, buttonmaps); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
980 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
981 tern_node * speed_nodes = tern_find_path(config, "clocks\0speeds\0", TVAL_NODE).ptrval; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
982 speeds = malloc(sizeof(uint32_t)); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
983 speeds[0] = 100; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
984 process_speeds(speed_nodes, NULL); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
985 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
|
986 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
987 if (!speeds[i]) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
988 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
|
989 speeds[i] = 100; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
990 } |
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 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
993 |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
994 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
|
995 { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
996 mouse_mode = mode; |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
997 if (mode == MOUSE_RELATIVE) { |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
998 render_relative_mouse(1); |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
999 } |
430dd12e4010
Refactor to split device bindings from IO emulation code
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1000 } |