ScummVM API documentation
libretro-mapper.h
1 /* Copyright (C) 2023 Giovanni Cascione <ing.cascione@gmail.com>
2  *
3  * This program is free software: you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation, either version 3 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #ifndef LIBRETRO_MAPPER_H
19 #define LIBRETRO_MAPPER_H
20 
21 #include <libretro.h>
22 #include "common/keyboard.h"
23 
24 #define RETRO_DEVICE_KEY_STATUS 0
25 #define RETRO_DEVICE_KEY_PREV_STATUS 1
26 #define RETRO_DEVICE_KEY_CHANGED 2
27 
28 #define RETRO_DEVICE_ID_JOYPAD_ANALOG 16
29 
30 #define RETRO_DEVICE_ID_JOYPAD_LR 16
31 #define RETRO_DEVICE_ID_JOYPAD_LL 17
32 #define RETRO_DEVICE_ID_JOYPAD_LD 18
33 #define RETRO_DEVICE_ID_JOYPAD_LU 19
34 #define RETRO_DEVICE_ID_JOYPAD_RR 20
35 #define RETRO_DEVICE_ID_JOYPAD_RL 21
36 #define RETRO_DEVICE_ID_JOYPAD_RD 22
37 #define RETRO_DEVICE_ID_JOYPAD_RU 23
38 
39 #define RETRO_DEVICE_ID_JOYPAD_LAST 24
40 
41 #define RETROKE_VKBD -1
42 #define RETROKE_LEFT -2
43 #define RETROKE_UP -3
44 #define RETROKE_DOWN -4
45 #define RETROKE_RIGHT -5
46 #define RETROKE_LEFT_BUTTON -6
47 #define RETROKE_RIGHT_BUTTON -7
48 #define RETROKE_FINE_CONTROL -8
49 #define RETROKE_SCUMMVM_GUI -9
50 #define RETROKE_SHIFT_MOD -10
51 #define RETROKE_CTRL_MOD -11
52 #define RETROKE_ALT_MOD -12
53 
54 /* libretro.cpp functions */
55 extern retro_input_state_t retro_input_cb;
56 extern int retro_setting_get_analog_deadzone(void);
57 extern bool retro_get_input_bitmask_supported(void);
58 
59 struct retro_keymap {
60  int retro_id;
61  int scummvm_id;
62  const char *value;
63 };
64 
65 static const struct retro_keymap retro_keys[] = {
66  {0, 0, "---"},
67  {RETROKE_VKBD, 0, "RETROKE_VKBD"},
68  {RETROKE_LEFT, 0, "RETROKE_LEFT"},
69  {RETROKE_UP, 0, "RETROKE_UP"},
70  {RETROKE_DOWN, 0, "RETROKE_DOWN"},
71  {RETROKE_RIGHT, 0, "RETROKE_RIGHT"},
72  {RETROKE_LEFT_BUTTON, 0, "RETROKE_LEFT_BUTTON"},
73  {RETROKE_RIGHT_BUTTON, 0, "RETROKE_RIGHT_BUTTON"},
74  {RETROKE_FINE_CONTROL, 0, "RETROKE_FINE_CONTROL"},
75  {RETROKE_SCUMMVM_GUI, 0, "RETROKE_SCUMMVM_GUI"},
76  {RETROKE_SHIFT_MOD, 0, "RETROKE_SHIFT_MOD"},
77  {RETROKE_CTRL_MOD, 0, "RETROKE_CTRL_MOD"},
78  {RETROKE_ALT_MOD, 0, "RETROKE_ALT_MOD"},
79  {RETROK_BACKSPACE, Common::KEYCODE_BACKSPACE, "RETROK_BACKSPACE"},
80  {RETROK_TAB, Common::KEYCODE_TAB, "RETROK_TAB"},
81  {RETROK_CLEAR, Common::KEYCODE_CLEAR, "RETROK_CLEAR"},
82  {RETROK_RETURN, Common::KEYCODE_RETURN, "RETROK_RETURN"},
83  {RETROK_PAUSE, Common::KEYCODE_PAUSE, "RETROK_PAUSE"},
84  {RETROK_ESCAPE, Common::KEYCODE_ESCAPE, "RETROK_ESCAPE"},
85  {RETROK_SPACE, Common::KEYCODE_SPACE, "RETROK_SPACE"},
86  {RETROK_EXCLAIM, Common::KEYCODE_EXCLAIM, "RETROK_EXCLAIM"},
87  {RETROK_QUOTEDBL, Common::KEYCODE_QUOTEDBL, "RETROK_QUOTEDBL"},
88  {RETROK_HASH, Common::KEYCODE_HASH, "RETROK_HASH"},
89  {RETROK_DOLLAR, Common::KEYCODE_DOLLAR, "RETROK_DOLLAR"},
90  {RETROK_AMPERSAND, Common::KEYCODE_AMPERSAND, "RETROK_AMPERSAND"},
91  {RETROK_QUOTE, Common::KEYCODE_QUOTE, "RETROK_QUOTE"},
92  {RETROK_LEFTPAREN, Common::KEYCODE_LEFTPAREN, "RETROK_LEFTPAREN"},
93  {RETROK_RIGHTPAREN, Common::KEYCODE_RIGHTPAREN, "RETROK_RIGHTPAREN"},
94  {RETROK_ASTERISK, Common::KEYCODE_ASTERISK, "RETROK_ASTERISK"},
95  {RETROK_PLUS, Common::KEYCODE_PLUS, "RETROK_PLUS"},
96  {RETROK_COMMA, Common::KEYCODE_COMMA, "RETROK_COMMA"},
97  {RETROK_MINUS, Common::KEYCODE_MINUS, "RETROK_MINUS"},
98  {RETROK_PERIOD, Common::KEYCODE_PERIOD, "RETROK_PERIOD"},
99  {RETROK_SLASH, Common::KEYCODE_SLASH, "RETROK_SLASH"},
100  {RETROK_0, Common::KEYCODE_0, "RETROK_0"},
101  {RETROK_1, Common::KEYCODE_1, "RETROK_1"},
102  {RETROK_2, Common::KEYCODE_2, "RETROK_2"},
103  {RETROK_3, Common::KEYCODE_3, "RETROK_3"},
104  {RETROK_4, Common::KEYCODE_4, "RETROK_4"},
105  {RETROK_5, Common::KEYCODE_5, "RETROK_5"},
106  {RETROK_6, Common::KEYCODE_6, "RETROK_6"},
107  {RETROK_7, Common::KEYCODE_7, "RETROK_7"},
108  {RETROK_8, Common::KEYCODE_8, "RETROK_8"},
109  {RETROK_9, Common::KEYCODE_9, "RETROK_9"},
110  {RETROK_COLON, Common::KEYCODE_COLON, "RETROK_COLON"},
111  {RETROK_SEMICOLON, Common::KEYCODE_SEMICOLON, "RETROK_SEMICOLON"},
112  {RETROK_LESS, Common::KEYCODE_LESS, "RETROK_LESS"},
113  {RETROK_EQUALS, Common::KEYCODE_EQUALS, "RETROK_EQUALS"},
114  {RETROK_GREATER, Common::KEYCODE_GREATER, "RETROK_GREATER"},
115  {RETROK_QUESTION, Common::KEYCODE_QUESTION, "RETROK_QUESTION"},
116  {RETROK_AT, Common::KEYCODE_AT, "RETROK_AT"},
117  {RETROK_LEFTBRACKET, Common::KEYCODE_LEFTBRACKET, "RETROK_LEFTBRACKET"},
118  {RETROK_BACKSLASH, Common::KEYCODE_BACKSLASH, "RETROK_BACKSLASH"},
119  {RETROK_RIGHTBRACKET, Common::KEYCODE_RIGHTBRACKET, "RETROK_RIGHTBRACKET"},
120  {RETROK_CARET, Common::KEYCODE_CARET, "RETROK_CARET"},
121  {RETROK_UNDERSCORE, Common::KEYCODE_UNDERSCORE, "RETROK_UNDERSCORE"},
122  {RETROK_BACKQUOTE, Common::KEYCODE_BACKQUOTE, "RETROK_BACKQUOTE"},
123  {RETROK_a, Common::KEYCODE_a, "RETROK_a"},
124  {RETROK_b, Common::KEYCODE_b, "RETROK_b"},
125  {RETROK_c, Common::KEYCODE_c, "RETROK_c"},
126  {RETROK_d, Common::KEYCODE_d, "RETROK_d"},
127  {RETROK_e, Common::KEYCODE_e, "RETROK_e"},
128  {RETROK_f, Common::KEYCODE_f, "RETROK_f"},
129  {RETROK_g, Common::KEYCODE_g, "RETROK_g"},
130  {RETROK_h, Common::KEYCODE_h, "RETROK_h"},
131  {RETROK_i, Common::KEYCODE_i, "RETROK_i"},
132  {RETROK_j, Common::KEYCODE_j, "RETROK_j"},
133  {RETROK_k, Common::KEYCODE_k, "RETROK_k"},
134  {RETROK_l, Common::KEYCODE_l, "RETROK_l"},
135  {RETROK_m, Common::KEYCODE_m, "RETROK_m"},
136  {RETROK_n, Common::KEYCODE_n, "RETROK_n"},
137  {RETROK_o, Common::KEYCODE_o, "RETROK_o"},
138  {RETROK_p, Common::KEYCODE_p, "RETROK_p"},
139  {RETROK_q, Common::KEYCODE_q, "RETROK_q"},
140  {RETROK_r, Common::KEYCODE_r, "RETROK_r"},
141  {RETROK_s, Common::KEYCODE_s, "RETROK_s"},
142  {RETROK_t, Common::KEYCODE_t, "RETROK_t"},
143  {RETROK_u, Common::KEYCODE_u, "RETROK_u"},
144  {RETROK_v, Common::KEYCODE_v, "RETROK_v"},
145  {RETROK_w, Common::KEYCODE_w, "RETROK_w"},
146  {RETROK_x, Common::KEYCODE_x, "RETROK_x"},
147  {RETROK_y, Common::KEYCODE_y, "RETROK_y"},
148  {RETROK_z, Common::KEYCODE_z, "RETROK_z"},
149  {RETROK_KP0, Common::KEYCODE_KP0, "RETROK_KP0"},
150  {RETROK_KP1, Common::KEYCODE_KP1, "RETROK_KP1"},
151  {RETROK_KP2, Common::KEYCODE_KP2, "RETROK_KP2"},
152  {RETROK_KP3, Common::KEYCODE_KP3, "RETROK_KP3"},
153  {RETROK_KP4, Common::KEYCODE_KP4, "RETROK_KP4"},
154  {RETROK_KP5, Common::KEYCODE_KP5, "RETROK_KP5"},
155  {RETROK_KP6, Common::KEYCODE_KP6, "RETROK_KP6"},
156  {RETROK_KP7, Common::KEYCODE_KP7, "RETROK_KP7"},
157  {RETROK_KP8, Common::KEYCODE_KP8, "RETROK_KP8"},
158  {RETROK_KP9, Common::KEYCODE_KP9, "RETROK_KP9"},
159  {RETROK_KP_PERIOD, Common::KEYCODE_KP_PERIOD, "RETROK_KP_PERIOD"},
160  {RETROK_KP_DIVIDE, Common::KEYCODE_KP_DIVIDE, "RETROK_KP_DIVIDE"},
161  {RETROK_KP_MULTIPLY, Common::KEYCODE_KP_MULTIPLY, "RETROK_KP_MULTIPLY"},
162  {RETROK_KP_MINUS, Common::KEYCODE_KP_MINUS, "RETROK_KP_MINUS"},
163  {RETROK_KP_PLUS, Common::KEYCODE_KP_PLUS, "RETROK_KP_PLUS"},
164  {RETROK_KP_ENTER, Common::KEYCODE_KP_ENTER, "RETROK_KP_ENTER"},
165  {RETROK_KP_EQUALS, Common::KEYCODE_KP_EQUALS, "RETROK_KP_EQUALS"},
166  {RETROK_UP, Common::KEYCODE_UP, "RETROK_UP"},
167  {RETROK_DOWN, Common::KEYCODE_DOWN, "RETROK_DOWN"},
168  {RETROK_LEFT, Common::KEYCODE_LEFT, "RETROK_LEFT"},
169  {RETROK_RIGHT, Common::KEYCODE_RIGHT, "RETROK_RIGHT"},
170  {RETROK_INSERT, Common::KEYCODE_INSERT, "RETROK_INSERT"},
171  {RETROK_DELETE, Common::KEYCODE_DELETE, "RETROK_DELETE"},
172  {RETROK_HOME, Common::KEYCODE_HOME, "RETROK_HOME"},
173  {RETROK_END, Common::KEYCODE_END, "RETROK_END"},
174  {RETROK_PAGEUP, Common::KEYCODE_PAGEUP, "RETROK_PAGEUP"},
175  {RETROK_PAGEDOWN, Common::KEYCODE_PAGEDOWN, "RETROK_PAGEDOWN"},
176  {RETROK_F1, Common::KEYCODE_F1, "RETROK_F1"},
177  {RETROK_F2, Common::KEYCODE_F2, "RETROK_F2"},
178  {RETROK_F3, Common::KEYCODE_F3, "RETROK_F3"},
179  {RETROK_F4, Common::KEYCODE_F4, "RETROK_F4"},
180  {RETROK_F5, Common::KEYCODE_F5, "RETROK_F5"},
181  {RETROK_F6, Common::KEYCODE_F6, "RETROK_F6"},
182  {RETROK_F7, Common::KEYCODE_F7, "RETROK_F7"},
183  {RETROK_F8, Common::KEYCODE_F8, "RETROK_F8"},
184  {RETROK_F9, Common::KEYCODE_F9, "RETROK_F9"},
185  {RETROK_F10, Common::KEYCODE_F10, "RETROK_F10"},
186  {RETROK_F11, Common::KEYCODE_F11, "RETROK_F11"},
187  {RETROK_F12, Common::KEYCODE_F12, "RETROK_F12"},
188  {RETROK_F13, Common::KEYCODE_F13, "RETROK_F13"},
189  {RETROK_F14, Common::KEYCODE_F14, "RETROK_F14"},
190  {RETROK_F15, Common::KEYCODE_F15, "RETROK_F15"},
191  {RETROK_NUMLOCK, Common::KEYCODE_NUMLOCK, "RETROK_NUMLOCK"},
192  {RETROK_CAPSLOCK, Common::KEYCODE_CAPSLOCK, "RETROK_CAPSLOCK"},
193  {RETROK_SCROLLOCK, Common::KEYCODE_SCROLLOCK, "RETROK_SCROLLOCK"},
194  {RETROK_LSHIFT, Common::KEYCODE_LSHIFT, "RETROK_LSHIFT"},
195  {RETROK_RSHIFT, Common::KEYCODE_RSHIFT, "RETROK_RSHIFT"},
196  {RETROK_LCTRL, Common::KEYCODE_LCTRL, "RETROK_LCTRL"},
197  {RETROK_RCTRL, Common::KEYCODE_RCTRL, "RETROK_RCTRL"},
198  {RETROK_LALT, Common::KEYCODE_LALT, "RETROK_LALT"},
199  {RETROK_RALT, Common::KEYCODE_RALT, "RETROK_RALT"},
200  {RETROK_LMETA, Common::KEYCODE_LMETA, "RETROK_LMETA"},
201  {RETROK_RMETA, Common::KEYCODE_RMETA, "RETROK_RMETA"},
202  {RETROK_LSUPER, Common::KEYCODE_LSUPER, "RETROK_LSUPER"},
203  {RETROK_RSUPER, Common::KEYCODE_RSUPER, "RETROK_RSUPER"},
204  {RETROK_MODE, Common::KEYCODE_MODE, "RETROK_MODE"},
205  {RETROK_COMPOSE, Common::KEYCODE_COMPOSE, "RETROK_COMPOSE"},
206  {RETROK_HELP, Common::KEYCODE_HELP, "RETROK_HELP"},
207  {RETROK_PRINT, Common::KEYCODE_PRINT, "RETROK_PRINT"},
208  {RETROK_SYSREQ, Common::KEYCODE_SYSREQ, "RETROK_SYSREQ"},
209  {RETROK_BREAK, Common::KEYCODE_BREAK, "RETROK_BREAK"},
210  {RETROK_MENU, Common::KEYCODE_MENU, "RETROK_MENU"},
211  {RETROK_POWER, Common::KEYCODE_POWER, "RETROK_POWER"},
212  {RETROK_EURO, Common::KEYCODE_EURO, "RETROK_EURO"},
213  {RETROK_UNDO, Common::KEYCODE_UNDO, "RETROK_UNDO"},
214  {RETROK_LAST, 0, ""}
215 };
216 
217 const struct retro_controller_description retro_controller_list[] = {
218  {"None", RETRO_DEVICE_NONE},
219  {"Automatic", RETRO_DEVICE_JOYPAD},
220  {NULL, 0}
221 };
222 
223 const struct retro_controller_info retro_controller_lists[] = {
224  {retro_controller_list, sizeof(retro_controller_list) / sizeof(retro_controller_list[0])},
225  {NULL, 0}
226 };
227 
228 static struct retro_input_descriptor retro_input_desc[] = {
229  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_UP, "Up"},
230  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_DOWN, "Down"},
231  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_LEFT, "Left"},
232  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_RIGHT, "Right"},
233  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_B, "B / Fire / Red"},
234  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_A, "A / 2nd fire / Blue"},
235  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_Y, "Y / Green"},
236  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_X, "X / Yellow"},
237  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_SELECT, "Select"},
238  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_START, "Start / Play"},
239  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L, "L / Rewind"},
240  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R, "R / Forward"},
241  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L2, "L2"},
242  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R2, "R2"},
243  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_L3, "L3"},
244  {0, RETRO_DEVICE_JOYPAD, 0, RETRO_DEVICE_ID_JOYPAD_R3, "R3"},
245  {0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_X, "Left Analog X"},
246  {0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_LEFT, RETRO_DEVICE_ID_ANALOG_Y, "Left Analog Y"},
247  {0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_X, "Right Analog X"},
248  {0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y"},
249  {0}
250 };
251 
252 void mapper_poll_device(void);
253 bool mapper_set_device_keys(unsigned int retro_device_id, const char *retro_key_value);
254 uint8 mapper_get_device_key_status(unsigned int retro_device_id);
255 int16 mapper_get_device_key_value(unsigned int retro_device_id);
256 int16 mapper_get_device_key_retro_id(unsigned int retro_device_id);
257 int16 mapper_get_device_key_scummvm_id(unsigned int retro_device_id);
258 int8 mapper_get_mapper_key_index(int16 key_retro_id, uint8 start_index = 0);
259 uint8 mapper_get_mapper_key_status(int16 key_retro_id);
260 int16 mapper_get_mapper_key_value(int16 key_retro_id);
261 
262 #endif // LIBRETRO_MAPPER_H
Definition: libretro-mapper.h:59