Debian Codegraph @

libretro_core_options.h

raw symbols SCIP
1 #ifndef LIBRETRO_CORE_OPTIONS_H__
2 #define LIBRETRO_CORE_OPTIONS_H__
3
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include <libretro.h>
8 #include <retro_inline.h>
9
10 #ifndef HAVE_NO_LANGEXTRA
11 #include "libretro_core_options_intl.h"
12 #endif
13
14 /*
15 ********************************
16 * VERSION: 2.0
17 ********************************
18 *
19 * - 2.0: Add support for core options v2 interface
20 * - 1.3: Move translations to libretro_core_options_intl.h
21 * - libretro_core_options_intl.h includes BOM and utf-8
22 * fix for MSVC 2010-2013
23 * - Added HAVE_NO_LANGEXTRA flag to disable translations
24 * on platforms/compilers without BOM support
25 * - 1.2: Use core options v1 interface when
26 * RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION is >= 1
27 * (previously required RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION == 1)
28 * - 1.1: Support generation of core options v0 retro_core_option_value
29 * arrays containing options with a single value
30 * - 1.0: First commit
31 */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*
38 ********************************
39 * Core Option Definitions
40 ********************************
41 */
42
43 /* RETRO_LANGUAGE_ENGLISH */
44
45 /* Default language:
46 * - All other languages must include the same keys and values
47 * - Will be used as a fallback in the event that frontend language
48 * is not available
49 * - Will be used as a fallback for any missing entries in
50 * frontend language definition */
51
52
53 struct retro_core_option_v2_category option_cats_us[] = {
54 { NULL, NULL, NULL },
55 };
56
57 struct retro_core_option_v2_definition option_defs_us[] = {
58 {
59 "wswan_rotate_display",
60 "Display Rotation",
61 NULL,
62 "Choose the orientation of the console screen. 'Portrait' can be used to achieve the correct layout of portrait oriented games on a conventional (landscape) display. 'Manual' enables rotation via the controller (default button: SELECT).",
63 NULL,
64 NULL,
65 {
66 { "manual", "Manual" },
67 { "landscape", "Landscape" },
68 { "portrait", "Portrait" },
69 { NULL, NULL },
70 },
71 "manual",
72 },
73 {
74 "wswan_rotate_keymap",
75 "Rotate Button Mappings",
76 NULL,
77 "Choose the preferred button mapping. 'Auto' adjusts button mapping to match the current display rotation.",
78 NULL,
79 NULL,
80 {
81 { "auto", "Auto" },
82 { "disabled", "Landscape" },
83 { "enabled", "Portrait" },
84 { NULL, NULL},
85 },
86 "auto",
87 },
88 {
89 "wswan_mono_palette",
90 "Color Palette",
91 NULL,
92 "Choose the colorization of WonderSwan (Mono) games. 'WS' palettes mimic the display of the original WonderSwan hardware.",
93 NULL,
94 NULL,
95 {
96 { "default", "Grayscale" },
97 { "wonderswan", "WS - WonderSwan" },
98 { "wondeswan_color", "WS - WonderSwan Color" },
99 { "swancrystal", "WS - SwanCrystal" },
100 { "gb_dmg", "Game Boy DMG" },
101 { "gb_pocket", "Game Boy Pocket" },
102 { "gb_light", "Game Boy Light" },
103 { "blossom_pink", "Blossom Pink" },
104 { "bubbles_blue", "Bubbles Blue" },
105 { "buttercup_green", "Buttercup Green" },
106 { "digivice", "Digivice" },
107 { "game_com", "Game.com" },
108 { "gameking", "GameKing" },
109 { "game_master", "Game Master" },
110 { "golden_wild", "Golden Wild" },
111 { "greenscale", "Greenscale" },
112 { "hokage_orange", "Hokage Orange" },
113 { "labo_fawn", "Labo Fawn" },
114 { "legendary_super_saiyan", "Legendary Super Saiyan" },
115 { "microvision", "Microvision" },
116 { "million_live_gold", "Million Live Gold" },
117 { "odyssey_gold", "Odyssey Gold" },
118 { "shiny_sky_blue", "Shiny Sky Blue" },
119 { "slime_blue", "Slime Blue" },
120 { "ti_83", "TI-83" },
121 { "travel_wood", "Travel Wood" },
122 { "virtual_boy", "Virtual Boy" },
123 { NULL, NULL },
124 },
125 "default"
126 },
127 {
128 "wswan_gfx_colors",
129 "Color Depth (Restart Required)",
130 NULL,
131 "24-bit is slower and not available on all platforms.",
132 NULL,
133 NULL,
134 {
135 { "16bit", "Thousands (16-bit)" },
136 { "24bit", "Millions (24-bit)" },
137 { NULL, NULL },
138 },
139 "16bit"
140 },
141 {
142 "wswan_frameskip",
143 "Frameskip",
144 NULL,
145 "Skip frames to avoid audio buffer under-run (crackling). Improves performance at the expense of visual smoothness. 'Auto' skips frames when advised by the frontend. 'Manual' utilizes the 'Frameskip Threshold (%)' setting.",
146 NULL,
147 NULL,
148 {
149 { "disabled", NULL },
150 { "auto", "Auto" },
151 { "manual", "Manual" },
152 { NULL, NULL },
153 },
154 "disabled"
155 },
156 {
157 "wswan_frameskip_threshold",
158 "Frameskip Threshold (%)",
159 NULL,
160 "When 'Frameskip' is set to 'Manual', this specifies the audio buffer occupancy threshold (percentage) below which frames will be skipped. Higher values reduce the risk of crackling by causing frames to be dropped more frequently.",
161 NULL,
162 NULL,
163 {
164 { "15", NULL },
165 { "18", NULL },
166 { "21", NULL },
167 { "24", NULL },
168 { "27", NULL },
169 { "30", NULL },
170 { "33", NULL },
171 { "36", NULL },
172 { "39", NULL },
173 { "42", NULL },
174 { "45", NULL },
175 { "48", NULL },
176 { "51", NULL },
177 { "54", NULL },
178 { "57", NULL },
179 { "60", NULL },
180 { NULL, NULL },
181 },
182 "33"
183 },
184 {
185 "wswan_60hz_mode",
186 "60Hz Mode",
187 NULL,
188 "Update the display at 60Hz instead of the native 75Hz WonderSwan refresh rate by dropping every fifth frame. Reduces video smoothness, but avoids screen tearing on displays that do not support native operation above 60Hz.",
189 NULL,
190 NULL,
191 {
192 { "disabled", NULL },
193 { "enabled", NULL },
194 { NULL, NULL },
195 },
196 "enabled",
197 },
198 {
199 "wswan_sound_sample_rate",
200 "Sound Output Sample Rate",
201 NULL,
202 "Higher values improve sound quality slightly at the expense of performance.",
203 NULL,
204 NULL,
205 {
206 { "11025", NULL },
207 { "22050", NULL },
208 { "44100", NULL },
209 { "48000", NULL },
210 { NULL, NULL },
211 },
212 "44100",
213 },
214 {
215 "wswan_sound_low_pass",
216 "Audio Filter",
217 NULL,
218 "Apply a low pass audio filter to 'soften' the sometimes harsh chiptunes produced by the WonderSwan.",
219 NULL,
220 NULL,
221 {
222 { "disabled", NULL },
223 { "enabled", NULL },
224 { NULL, NULL },
225 },
226 "disabled",
227 },
228 { NULL, NULL, NULL, NULL, NULL, NULL, {{0}}, NULL },
229 };
230
231 struct retro_core_options_v2 options_us = {
232 option_cats_us,
233 option_defs_us
234 };
235
236 /*
237 ********************************
238 * Language Mapping
239 ********************************
240 */
241
242 #ifndef HAVE_NO_LANGEXTRA
243 struct retro_core_options_v2 *options_intl[RETRO_LANGUAGE_LAST] = {
244 &options_us, /* RETRO_LANGUAGE_ENGLISH */
245 &options_ja, /* RETRO_LANGUAGE_JAPANESE */
246 &options_fr, /* RETRO_LANGUAGE_FRENCH */
247 &options_es, /* RETRO_LANGUAGE_SPANISH */
248 &options_de, /* RETRO_LANGUAGE_GERMAN */
249 &options_it, /* RETRO_LANGUAGE_ITALIAN */
250 &options_nl, /* RETRO_LANGUAGE_DUTCH */
251 &options_pt_br, /* RETRO_LANGUAGE_PORTUGUESE_BRAZIL */
252 &options_pt_pt, /* RETRO_LANGUAGE_PORTUGUESE_PORTUGAL */
253 &options_ru, /* RETRO_LANGUAGE_RUSSIAN */
254 &options_ko, /* RETRO_LANGUAGE_KOREAN */
255 &options_cht, /* RETRO_LANGUAGE_CHINESE_TRADITIONAL */
256 &options_chs, /* RETRO_LANGUAGE_CHINESE_SIMPLIFIED */
257 &options_eo, /* RETRO_LANGUAGE_ESPERANTO */
258 &options_pl, /* RETRO_LANGUAGE_POLISH */
259 &options_vn, /* RETRO_LANGUAGE_VIETNAMESE */
260 &options_ar, /* RETRO_LANGUAGE_ARABIC */
261 &options_el, /* RETRO_LANGUAGE_GREEK */
262 &options_tr, /* RETRO_LANGUAGE_TURKISH */
263 &options_sk, /* RETRO_LANGUAGE_SLOVAK */
264 &options_fa, /* RETRO_LANGUAGE_PERSIAN */
265 &options_he, /* RETRO_LANGUAGE_HEBREW */
266 &options_ast, /* RETRO_LANGUAGE_ASTURIAN */
267 &options_fi, /* RETRO_LANGUAGE_FINNISH */
268 &options_id, /* RETRO_LANGUAGE_INDONESIAN */
269 &options_sv, /* RETRO_LANGUAGE_SWEDISH */
270 &options_uk, /* RETRO_LANGUAGE_UKRAINIAN */
271 &options_cs, /* RETRO_LANGUAGE_CZECH */
272 &options_val, /* RETRO_LANGUAGE_CATALAN_VALENCIA */
273 &options_ca, /* RETRO_LANGUAGE_CATALAN */
274 &options_en, /* RETRO_LANGUAGE_BRITISH_ENGLISH */
275 &options_hu, /* RETRO_LANGUAGE_HUNGARIAN */
276 };
277 #endif
278
279 /*
280 ********************************
281 * Functions
282 ********************************
283 */
284
285 /* Handles configuration/setting of core options.
286 * Should be called as early as possible - ideally inside
287 * retro_set_environment(), and no later than retro_load_game()
288 * > We place the function body in the header to avoid the
289 * necessity of adding more .c files (i.e. want this to
290 * be as painless as possible for core devs)
291 */
292
293 static INLINE void libretro_set_core_options(retro_environment_t environ_cb,
294 bool *categories_supported)
295 {
296 unsigned version = 0;
297 #ifndef HAVE_NO_LANGEXTRA
298 unsigned language = 0;
299 #endif
300
301 if (!environ_cb || !categories_supported)
302 return;
303
304 *categories_supported = false;
305
306 if (!environ_cb(RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION, &version))
307 version = 0;
308
309 if (version >= 2)
310 {
311 #ifndef HAVE_NO_LANGEXTRA
312 struct retro_core_options_v2_intl core_options_intl;
313
314 core_options_intl.us = &options_us;
315 core_options_intl.local = NULL;
316
317 if (environ_cb(RETRO_ENVIRONMENT_GET_LANGUAGE, &language) &&
318 (language < RETRO_LANGUAGE_LAST) && (language != RETRO_LANGUAGE_ENGLISH))
319 core_options_intl.local = options_intl[language];
320
321 *categories_supported = environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2_INTL,
322 &core_options_intl);
323 #else
324 *categories_supported = environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_V2,
325 &options_us);
326 #endif
327 }
328 else
329 {
330 size_t i, j;
331 size_t option_index = 0;
332 size_t num_options = 0;
333 struct retro_core_option_definition
334 *option_v1_defs_us = NULL;
335 #ifndef HAVE_NO_LANGEXTRA
336 size_t num_options_intl = 0;
337 struct retro_core_option_v2_definition
338 *option_defs_intl = NULL;
339 struct retro_core_option_definition
340 *option_v1_defs_intl = NULL;
341 struct retro_core_options_intl
342 core_options_v1_intl;
343 #endif
344 struct retro_variable *variables = NULL;
345 char **values_buf = NULL;
346
347 /* Determine total number of options */
348 while (true)
349 {
350 if (option_defs_us[num_options].key)
351 num_options++;
352 else
353 break;
354 }
355
356 if (version >= 1)
357 {
358 /* Allocate US array */
359 option_v1_defs_us = (struct retro_core_option_definition *)
360 calloc(num_options + 1, sizeof(struct retro_core_option_definition));
361
362 /* Copy parameters from option_defs_us array */
363 for (i = 0; i < num_options; i++)
364 {
365 struct retro_core_option_v2_definition *option_def_us = &option_defs_us[i];
366 struct retro_core_option_value *option_values = option_def_us->values;
367 struct retro_core_option_definition *option_v1_def_us = &option_v1_defs_us[i];
368 struct retro_core_option_value *option_v1_values = option_v1_def_us->values;
369
370 option_v1_def_us->key = option_def_us->key;
371 option_v1_def_us->desc = option_def_us->desc;
372 option_v1_def_us->info = option_def_us->info;
373 option_v1_def_us->default_value = option_def_us->default_value;
374
375 /* Values must be copied individually... */
376 while (option_values->value)
377 {
378 option_v1_values->value = option_values->value;
379 option_v1_values->label = option_values->label;
380
381 option_values++;
382 option_v1_values++;
383 }
384 }
385
386 #ifndef HAVE_NO_LANGEXTRA
387 if (environ_cb(RETRO_ENVIRONMENT_GET_LANGUAGE, &language) &&
388 (language < RETRO_LANGUAGE_LAST) && (language != RETRO_LANGUAGE_ENGLISH) &&
389 options_intl[language])
390 option_defs_intl = options_intl[language]->definitions;
391
392 if (option_defs_intl)
393 {
394 /* Determine number of intl options */
395 while (true)
396 {
397 if (option_defs_intl[num_options_intl].key)
398 num_options_intl++;
399 else
400 break;
401 }
402
403 /* Allocate intl array */
404 option_v1_defs_intl = (struct retro_core_option_definition *)
405 calloc(num_options_intl + 1, sizeof(struct retro_core_option_definition));
406
407 /* Copy parameters from option_defs_intl array */
408 for (i = 0; i < num_options_intl; i++)
409 {
410 struct retro_core_option_v2_definition *option_def_intl = &option_defs_intl[i];
411 struct retro_core_option_value *option_values = option_def_intl->values;
412 struct retro_core_option_definition *option_v1_def_intl = &option_v1_defs_intl[i];
413 struct retro_core_option_value *option_v1_values = option_v1_def_intl->values;
414
415 option_v1_def_intl->key = option_def_intl->key;
416 option_v1_def_intl->desc = option_def_intl->desc;
417 option_v1_def_intl->info = option_def_intl->info;
418 option_v1_def_intl->default_value = option_def_intl->default_value;
419
420 /* Values must be copied individually... */
421 while (option_values->value)
422 {
423 option_v1_values->value = option_values->value;
424 option_v1_values->label = option_values->label;
425
426 option_values++;
427 option_v1_values++;
428 }
429 }
430 }
431
432 core_options_v1_intl.us = option_v1_defs_us;
433 core_options_v1_intl.local = option_v1_defs_intl;
434
435 environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL, &core_options_v1_intl);
436 #else
437 environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS, option_v1_defs_us);
438 #endif
439 }
440 else
441 {
442 /* Allocate arrays */
443 variables = (struct retro_variable *)calloc(num_options + 1,
444 sizeof(struct retro_variable));
445 values_buf = (char **)calloc(num_options, sizeof(char *));
446
447 if (!variables || !values_buf)
448 goto error;
449
450 /* Copy parameters from option_defs_us array */
451 for (i = 0; i < num_options; i++)
452 {
453 const char *key = option_defs_us[i].key;
454 const char *desc = option_defs_us[i].desc;
455 const char *default_value = option_defs_us[i].default_value;
456 struct retro_core_option_value *values = option_defs_us[i].values;
457 size_t buf_len = 3;
458 size_t default_index = 0;
459
460 values_buf[i] = NULL;
461
462 if (desc)
463 {
464 size_t num_values = 0;
465
466 /* Determine number of values */
467 while (true)
468 {
469 if (values[num_values].value)
470 {
471 /* Check if this is the default value */
472 if (default_value)
473 if (strcmp(values[num_values].value, default_value) == 0)
474 default_index = num_values;
475
476 buf_len += strlen(values[num_values].value);
477 num_values++;
478 }
479 else
480 break;
481 }
482
483 /* Build values string */
484 if (num_values > 0)
485 {
486 buf_len += num_values - 1;
487 buf_len += strlen(desc);
488
489 values_buf[i] = (char *)calloc(buf_len, sizeof(char));
490 if (!values_buf[i])
491 goto error;
492
493 strcpy(values_buf[i], desc);
494 strcat(values_buf[i], "; ");
495
496 /* Default value goes first */
497 strcat(values_buf[i], values[default_index].value);
498
499 /* Add remaining values */
500 for (j = 0; j < num_values; j++)
501 {
502 if (j != default_index)
503 {
504 strcat(values_buf[i], "|");
505 strcat(values_buf[i], values[j].value);
506 }
507 }
508 }
509 }
510
511 variables[option_index].key = key;
512 variables[option_index].value = values_buf[i];
513 option_index++;
514 }
515
516 /* Set variables */
517 environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables);
518 }
519
520 error:
521 /* Clean up */
522
523 if (option_v1_defs_us)
524 {
525 free(option_v1_defs_us);
526 option_v1_defs_us = NULL;
527 }
528
529 #ifndef HAVE_NO_LANGEXTRA
530 if (option_v1_defs_intl)
531 {
532 free(option_v1_defs_intl);
533 option_v1_defs_intl = NULL;
534 }
535 #endif
536
537 if (values_buf)
538 {
539 for (i = 0; i < num_options; i++)
540 {
541 if (values_buf[i])
542 {
543 free(values_buf[i]);
544 values_buf[i] = NULL;
545 }
546 }
547
548 free(values_buf);
549 values_buf = NULL;
550 }
551
552 if (variables)
553 {
554 free(variables);
555 variables = NULL;
556 }
557 }
558 }
559
560 #ifdef __cplusplus
561 }
562 #endif
563
564 #endif