Mercurial > repos > blastem
comparison controller_info.c @ 1779:3a8c4ee68568
Added raw fbdev/evdev/ALSA render backend
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 10 Mar 2019 21:30:09 -0700 |
parents | 84ef1eb2c96a |
children | a4cae960fd08 |
comparison
equal
deleted
inserted
replaced
1767:8a29c250f352 | 1779:3a8c4ee68568 |
---|---|
1 #include <string.h> | 1 #include <string.h> |
2 #include <stdlib.h> | |
3 #ifndef USE_FBDEV | |
2 #include "render_sdl.h" | 4 #include "render_sdl.h" |
5 #endif | |
3 #include "controller_info.h" | 6 #include "controller_info.h" |
4 #include "config.h" | 7 #include "config.h" |
5 #include "util.h" | 8 #include "util.h" |
6 | 9 |
7 typedef struct { | 10 typedef struct { |
68 } | 71 } |
69 } | 72 } |
70 | 73 |
71 controller_info get_controller_info(int joystick) | 74 controller_info get_controller_info(int joystick) |
72 { | 75 { |
76 #ifndef USE_FBDEV | |
73 load_ctype_config(); | 77 load_ctype_config(); |
74 char guid_string[33]; | 78 char guid_string[33]; |
75 SDL_Joystick *stick = render_get_joystick(joystick); | 79 SDL_Joystick *stick = render_get_joystick(joystick); |
76 SDL_GameController *control = render_get_controller(joystick); | 80 SDL_GameController *control = render_get_controller(joystick); |
77 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string)); | 81 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(stick), guid_string, sizeof(guid_string)); |
146 controller_info res = heuristics[i].info; | 150 controller_info res = heuristics[i].info; |
147 res.name = name; | 151 res.name = name; |
148 return res; | 152 return res; |
149 } | 153 } |
150 } | 154 } |
155 #else | |
156 const char *name = "Unknown"; | |
157 #endif | |
151 //default to a 360 | 158 //default to a 360 |
152 return (controller_info){ | 159 return (controller_info){ |
153 .type = TYPE_GENERIC_MAPPING, | 160 .type = TYPE_GENERIC_MAPPING, |
154 .subtype = SUBTYPE_UNKNOWN, | 161 .subtype = SUBTYPE_UNKNOWN, |
155 .variant = VARIANT_NORMAL, | 162 .variant = VARIANT_NORMAL, |
157 }; | 164 }; |
158 } | 165 } |
159 | 166 |
160 static void mappings_iter(char *key, tern_val val, uint8_t valtype, void *data) | 167 static void mappings_iter(char *key, tern_val val, uint8_t valtype, void *data) |
161 { | 168 { |
169 #ifndef USE_FBDEV | |
162 if (valtype != TVAL_NODE) { | 170 if (valtype != TVAL_NODE) { |
163 return; | 171 return; |
164 } | 172 } |
165 char *mapping = tern_find_ptr(val.ptrval, "mapping"); | 173 char *mapping = tern_find_ptr(val.ptrval, "mapping"); |
166 if (mapping) { | 174 if (mapping) { |
167 const char *parts[] = {key, ",", mapping}; | 175 const char *parts[] = {key, ",", mapping}; |
168 char * full = alloc_concat_m(3, parts); | 176 char * full = alloc_concat_m(3, parts); |
169 SDL_GameControllerAddMapping(full); | 177 SDL_GameControllerAddMapping(full); |
170 free(full); | 178 free(full); |
171 } | 179 } |
180 #endif | |
172 } | 181 } |
173 | 182 |
174 void controller_add_mappings(void) | 183 void controller_add_mappings(void) |
175 { | 184 { |
176 load_ctype_config(); | 185 load_ctype_config(); |
179 } | 188 } |
180 } | 189 } |
181 | 190 |
182 void save_controller_info(int joystick, controller_info *info) | 191 void save_controller_info(int joystick, controller_info *info) |
183 { | 192 { |
193 #ifndef USE_FBDEV | |
184 char guid_string[33]; | 194 char guid_string[33]; |
185 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); | 195 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
186 tern_node *existing = tern_find_node(info_config, guid_string); | 196 tern_node *existing = tern_find_node(info_config, guid_string); |
187 existing = tern_insert_ptr(existing, "subtype", (void *)subtype_names[info->subtype]); | 197 existing = tern_insert_ptr(existing, "subtype", (void *)subtype_names[info->subtype]); |
188 existing = tern_insert_ptr(existing, "variant", (void *)variant_names[info->variant]); | 198 existing = tern_insert_ptr(existing, "variant", (void *)variant_names[info->variant]); |
189 info_config = tern_insert_node(info_config, guid_string, existing); | 199 info_config = tern_insert_node(info_config, guid_string, existing); |
190 persist_config_at(info_config, "controller_types.cfg"); | 200 persist_config_at(info_config, "controller_types.cfg"); |
191 | 201 #endif |
192 } | 202 } |
193 | 203 |
194 void save_controller_mapping(int joystick, char *mapping_string) | 204 void save_controller_mapping(int joystick, char *mapping_string) |
195 { | 205 { |
206 #ifndef USE_FBDEV | |
196 char guid_string[33]; | 207 char guid_string[33]; |
197 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); | 208 SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(render_get_joystick(joystick)), guid_string, sizeof(guid_string)); |
198 tern_node *existing = tern_find_node(info_config, guid_string); | 209 tern_node *existing = tern_find_node(info_config, guid_string); |
199 existing = tern_insert_ptr(existing, "mapping", mapping_string); | 210 existing = tern_insert_ptr(existing, "mapping", mapping_string); |
200 info_config = tern_insert_node(info_config, guid_string, existing); | 211 info_config = tern_insert_node(info_config, guid_string, existing); |
201 persist_config_at(info_config, "controller_types.cfg"); | 212 persist_config_at(info_config, "controller_types.cfg"); |
213 #endif | |
202 } | 214 } |
203 | 215 |
204 char const *labels_xbox[] = { | 216 char const *labels_xbox[] = { |
205 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" | 217 "A", "B", "X", "Y", "Back", NULL, "Start", "Click", "Click", "White", "Black", "LT", "RT" |
206 }; | 218 }; |
253 } | 265 } |
254 } | 266 } |
255 | 267 |
256 const char *get_button_label(controller_info *info, int button) | 268 const char *get_button_label(controller_info *info, int button) |
257 { | 269 { |
270 #ifndef USE_FBDEV | |
258 if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { | 271 if (button >= SDL_CONTROLLER_BUTTON_DPAD_UP) { |
259 static char const * dirs[] = {"Up", "Down", "Left", "Right"}; | 272 static char const * dirs[] = {"Up", "Down", "Left", "Right"}; |
260 return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP]; | 273 return dirs[button - SDL_CONTROLLER_BUTTON_DPAD_UP]; |
261 } | 274 } |
275 #endif | |
262 return label_source(info)[button]; | 276 return label_source(info)[button]; |
263 } | 277 } |
264 | 278 |
265 static char const *axis_labels[] = { | 279 static char const *axis_labels[] = { |
266 "Left X", "Left Y", "Right X", "Right Y" | 280 "Left X", "Left Y", "Right X", "Right Y" |
267 }; | 281 }; |
268 const char *get_axis_label(controller_info *info, int axis) | 282 const char *get_axis_label(controller_info *info, int axis) |
269 { | 283 { |
284 #ifndef USE_FBDEV | |
270 if (axis < SDL_CONTROLLER_AXIS_TRIGGERLEFT) { | 285 if (axis < SDL_CONTROLLER_AXIS_TRIGGERLEFT) { |
271 return axis_labels[axis]; | 286 return axis_labels[axis]; |
272 } else { | 287 } else { |
273 return label_source(info)[axis - SDL_CONTROLLER_AXIS_TRIGGERLEFT + SDL_CONTROLLER_BUTTON_RIGHTSHOULDER + 1]; | 288 return label_source(info)[axis - SDL_CONTROLLER_AXIS_TRIGGERLEFT + SDL_CONTROLLER_BUTTON_RIGHTSHOULDER + 1]; |
274 } | 289 } |
290 #else | |
291 return NULL; | |
292 #endif | |
275 } | 293 } |
276 | 294 |
277 char *make_controller_type_key(controller_info *info) | 295 char *make_controller_type_key(controller_info *info) |
278 { | 296 { |
279 const char *subtype; | 297 const char *subtype; |
314 char *prefix; | 332 char *prefix; |
315 if (info->variant == VARIANT_NORMAL) { | 333 if (info->variant == VARIANT_NORMAL) { |
316 prefix = "Normal "; | 334 prefix = "Normal "; |
317 } else { | 335 } else { |
318 static const char *parts[] = {"6 button (", NULL, "/", NULL, ") "}; | 336 static const char *parts[] = {"6 button (", NULL, "/", NULL, ") "}; |
337 #ifdef USE_FBDEV | |
338 parts[1] = parts[3] = "??"; | |
339 #else | |
319 if (info->variant == VARIANT_6B_BUMPERS) { | 340 if (info->variant == VARIANT_6B_BUMPERS) { |
320 parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); | 341 parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER); |
321 parts[3] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); | 342 parts[3] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
322 } else { | 343 } else { |
323 parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); | 344 parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER); |
324 parts[3] = get_axis_label(info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT); | 345 parts[3] = get_axis_label(info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT); |
325 } | 346 } |
347 #endif | |
326 prefix = alloc_concat_m(5, parts); | 348 prefix = alloc_concat_m(5, parts); |
327 } | 349 } |
328 char *ret = alloc_concat(prefix, base); | 350 char *ret = alloc_concat(prefix, base); |
329 if (info->variant != VARIANT_NORMAL) { | 351 if (info->variant != VARIANT_NORMAL) { |
330 free(prefix); | 352 free(prefix); |