1 #ifndef LIBRETRO_CORE_OPTIONS_H__
2 #define LIBRETRO_CORE_OPTIONS_H__
8 #include <retro_inline.h>
10 #ifndef HAVE_NO_LANGEXTRA
11 #include "libretro_core_options_intl.h"
15 ********************************
17 ********************************
19 * - 1.3: Move translations to libretro_core_options_intl.h
20 * - libretro_core_options_intl.h includes BOM and utf-8
21 * fix for MSVC 2010-2013
22 * - Added HAVE_NO_LANGEXTRA flag to disable translations
23 * on platforms/compilers without BOM support
24 * - 1.2: Use core options v1 interface when
25 * RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION is >= 1
26 * (previously required RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION == 1)
27 * - 1.1: Support generation of core options v0 retro_core_option_value
28 * arrays containing options with a single value
37 ********************************
38 * Core Option Definitions
39 ********************************
42 /* RETRO_LANGUAGE_ENGLISH */
45 * - All other languages must include the same keys and values
46 * - Will be used as a fallback in the event that frontend language
48 * - Will be used as a fallback for any missing entries in
49 * frontend language definition */
51 struct retro_core_option_definition option_defs_us[] = {
53 "mycore_region", /* key (option name) */
54 "Console Region", /* description (label) */
55 "Specify which region the system is from.", /* sublabel */
57 { "auto", "Auto" }, /* value_1, value_1_label */
58 { "ntsc-j", "Japan" }, /* value_2, value_2_label */
59 { "ntsc-u", "America" }, /* value_3, value_3_label */
60 { "pal", "Europe" }, /* value_4, value_4_label */
63 "auto" /* default_value */
68 "Set internal video scale factor.",
70 { "1x", NULL }, /* If value itself is human-readable (e.g. a number) */
71 { "2x", NULL }, /* and can displayed directly, the value_label should */
72 { "3x", NULL }, /* be set to NULL */
81 "Enable CPU overclock (unsafe).",
83 { "enabled", NULL }, /* If value is equal to 'enabled' or 'disabled', */
84 { "disabled", NULL }, /* value_label should be set to NULL */
89 { NULL, NULL, NULL, {{0}}, NULL },
93 ********************************
95 ********************************
98 #ifndef HAVE_NO_LANGEXTRA
99 struct retro_core_option_definition *option_defs_intl[RETRO_LANGUAGE_LAST] = {
100 option_defs_us, /* RETRO_LANGUAGE_ENGLISH */
101 NULL, /* RETRO_LANGUAGE_JAPANESE */
102 NULL, /* RETRO_LANGUAGE_FRENCH */
103 NULL, /* RETRO_LANGUAGE_SPANISH */
104 NULL, /* RETRO_LANGUAGE_GERMAN */
105 NULL, /* RETRO_LANGUAGE_ITALIAN */
106 NULL, /* RETRO_LANGUAGE_DUTCH */
107 NULL, /* RETRO_LANGUAGE_PORTUGUESE_BRAZIL */
108 NULL, /* RETRO_LANGUAGE_PORTUGUESE_PORTUGAL */
109 NULL, /* RETRO_LANGUAGE_RUSSIAN */
110 NULL, /* RETRO_LANGUAGE_KOREAN */
111 NULL, /* RETRO_LANGUAGE_CHINESE_TRADITIONAL */
112 NULL, /* RETRO_LANGUAGE_CHINESE_SIMPLIFIED */
113 NULL, /* RETRO_LANGUAGE_ESPERANTO */
114 NULL, /* RETRO_LANGUAGE_POLISH */
115 NULL, /* RETRO_LANGUAGE_VIETNAMESE */
116 NULL, /* RETRO_LANGUAGE_ARABIC */
117 NULL, /* RETRO_LANGUAGE_GREEK */
118 NULL, /* RETRO_LANGUAGE_TURKISH */
119 NULL, /* RETRO_LANGUAGE_SLOVAK */
120 NULL, /* RETRO_LANGUAGE_PERSIAN */
121 NULL, /* RETRO_LANGUAGE_HEBREW */
122 NULL, /* RETRO_LANGUAGE_ASTURIAN */
123 NULL, /* RETRO_LANGUAGE_FINNISH */
124 NULL, /* RETRO_LANGUAGE_INDONESIAN */
125 NULL, /* RETRO_LANGUAGE_SWEDISH */
126 NULL, /* RETRO_LANGUAGE_UKRAINIAN */
127 NULL, /* RETRO_LANGUAGE_CZECH */
133 ********************************
135 ********************************
138 /* Handles configuration/setting of core options.
139 * Should be called as early as possible - ideally inside
140 * retro_set_environment(), and no later than retro_load_game()
141 * > We place the function body in the header to avoid the
142 * necessity of adding more .c files (i.e. want this to
143 * be as painless as possible for core devs)
146 static INLINE void libretro_set_core_options(retro_environment_t environ_cb)
148 unsigned version = 0;
153 if (environ_cb(RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION, &version) && (version >= 1))
155 #ifndef HAVE_NO_LANGEXTRA
156 struct retro_core_options_intl core_options_intl;
157 unsigned language = 0;
159 core_options_intl.us = option_defs_us;
160 core_options_intl.local = NULL;
162 if (environ_cb(RETRO_ENVIRONMENT_GET_LANGUAGE, &language) &&
163 (language < RETRO_LANGUAGE_LAST) && (language != RETRO_LANGUAGE_ENGLISH))
164 core_options_intl.local = option_defs_intl[language];
166 environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL, &core_options_intl);
168 environ_cb(RETRO_ENVIRONMENT_SET_CORE_OPTIONS, &option_defs_us);
174 size_t num_options = 0;
175 struct retro_variable *variables = NULL;
176 char **values_buf = NULL;
178 /* Determine number of options */
181 if (!option_defs_us[num_options].key)
186 /* Allocate arrays */
187 variables = (struct retro_variable *)calloc(num_options + 1, sizeof(struct retro_variable));
188 values_buf = (char **)calloc(num_options, sizeof(char *));
190 if (!variables || !values_buf)
193 /* Copy parameters from option_defs_us array */
194 for (i = 0; i < num_options; i++)
196 const char *key = option_defs_us[i].key;
197 const char *desc = option_defs_us[i].desc;
198 const char *default_value = option_defs_us[i].default_value;
199 struct retro_core_option_value *values = option_defs_us[i].values;
201 size_t default_index = 0;
203 values_buf[i] = NULL;
207 size_t num_values = 0;
209 /* Determine number of values */
212 if (!values[num_values].value)
215 /* Check if this is the default value */
217 if (strcmp(values[num_values].value, default_value) == 0)
218 default_index = num_values;
220 buf_len += strlen(values[num_values].value);
224 /* Build values string */
229 buf_len += num_values - 1;
230 buf_len += strlen(desc);
232 values_buf[i] = (char *)calloc(buf_len, sizeof(char));
236 strcpy(values_buf[i], desc);
237 strcat(values_buf[i], "; ");
239 /* Default value goes first */
240 strcat(values_buf[i], values[default_index].value);
242 /* Add remaining values */
243 for (j = 0; j < num_values; j++)
245 if (j != default_index)
247 strcat(values_buf[i], "|");
248 strcat(values_buf[i], values[j].value);
254 variables[i].key = key;
255 variables[i].value = values_buf[i];
259 environ_cb(RETRO_ENVIRONMENT_SET_VARIABLES, variables);
266 for (i = 0; i < num_options; i++)
271 values_buf[i] = NULL;