1 /* Copyright (C) 2010-2020 The RetroArch team
2  *
3  * ---------------------------------------------------------------------------------------
4  * The following license statement only applies to this libretro API header (libretro.h).
5  * ---------------------------------------------------------------------------------------
6  *
7  * Permission is hereby granted, free of charge,
8  * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation the rights to
10  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11  * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16  * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19  * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 #ifndef LIBRETRO_H__
24 #define LIBRETRO_H__
25 
26 #include <stdint.h>
27 #include <stddef.h>
28 #include <limits.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 #ifndef __cplusplus
35 #if defined(_MSC_VER) && _MSC_VER < 1800 && !defined(SN_TARGET_PS3)
36 /* Hack applied for MSVC when compiling in C89 mode
37  * as it isn't C99-compliant. */
38 #define bool unsigned char
39 #define true 1
40 #define false 0
41 #else
42 #include <stdbool.h>
43 #endif
44 #endif
45 
46 #ifndef RETRO_CALLCONV
47 #  if defined(__GNUC__) && defined(__i386__) && !defined(__x86_64__)
48 #    define RETRO_CALLCONV __attribute__((cdecl))
49 #  elif defined(_MSC_VER) && defined(_M_X86) && !defined(_M_X64)
50 #    define RETRO_CALLCONV __cdecl
51 #  else
52 #    define RETRO_CALLCONV /* all other platforms only have one calling convention each */
53 #  endif
54 #endif
55 
56 #ifndef RETRO_API
57 #  if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
58 #    ifdef RETRO_IMPORT_SYMBOLS
59 #      ifdef __GNUC__
60 #        define RETRO_API RETRO_CALLCONV __attribute__((__dllimport__))
61 #      else
62 #        define RETRO_API RETRO_CALLCONV __declspec(dllimport)
63 #      endif
64 #    else
65 #      ifdef __GNUC__
66 #        define RETRO_API RETRO_CALLCONV __attribute__((__dllexport__))
67 #      else
68 #        define RETRO_API RETRO_CALLCONV __declspec(dllexport)
69 #      endif
70 #    endif
71 #  else
72 #      if defined(__GNUC__) && __GNUC__ >= 4
73 #        define RETRO_API RETRO_CALLCONV __attribute__((__visibility__("default")))
74 #      else
75 #        define RETRO_API RETRO_CALLCONV
76 #      endif
77 #  endif
78 #endif
79 
80 /* Used for checking API/ABI mismatches that can break libretro
81  * implementations.
82  * It is not incremented for compatible changes to the API.
83  */
84 #define RETRO_API_VERSION         1
85 
86 /*
87  * Libretro's fundamental device abstractions.
88  *
89  * Libretro's input system consists of some standardized device types,
90  * such as a joypad (with/without analog), mouse, keyboard, lightgun
91  * and a pointer.
92  *
93  * The functionality of these devices are fixed, and individual cores
94  * map their own concept of a controller to libretro's abstractions.
95  * This makes it possible for frontends to map the abstract types to a
96  * real input device, and not having to worry about binding input
97  * correctly to arbitrary controller layouts.
98  */
99 
100 #define RETRO_DEVICE_TYPE_SHIFT         8
101 #define RETRO_DEVICE_MASK               ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1)
102 #define RETRO_DEVICE_SUBCLASS(base, id) (((id + 1) << RETRO_DEVICE_TYPE_SHIFT) | base)
103 
104 /* Input disabled. */
105 #define RETRO_DEVICE_NONE         0
106 
107 /* The JOYPAD is called RetroPad. It is essentially a Super Nintendo
108  * controller, but with additional L2/R2/L3/R3 buttons, similar to a
109  * PS1 DualShock. */
110 #define RETRO_DEVICE_JOYPAD       1
111 
112 /* The mouse is a simple mouse, similar to Super Nintendo's mouse.
113  * X and Y coordinates are reported relatively to last poll (poll callback).
114  * It is up to the libretro implementation to keep track of where the mouse
115  * pointer is supposed to be on the screen.
116  * The frontend must make sure not to interfere with its own hardware
117  * mouse pointer.
118  */
119 #define RETRO_DEVICE_MOUSE        2
120 
121 /* KEYBOARD device lets one poll for raw key pressed.
122  * It is poll based, so input callback will return with the current
123  * pressed state.
124  * For event/text based keyboard input, see
125  * RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
126  */
127 #define RETRO_DEVICE_KEYBOARD     3
128 
129 /* LIGHTGUN device is similar to Guncon-2 for PlayStation 2.
130  * It reports X/Y coordinates in screen space (similar to the pointer)
131  * in the range [-0x8000, 0x7fff] in both axes, with zero being center and
132  * -0x8000 being out of bounds.
133  * As well as reporting on/off screen state. It features a trigger,
134  * start/select buttons, auxiliary action buttons and a
135  * directional pad. A forced off-screen shot can be requested for
136  * auto-reloading function in some games.
137  */
138 #define RETRO_DEVICE_LIGHTGUN     4
139 
140 /* The ANALOG device is an extension to JOYPAD (RetroPad).
141  * Similar to DualShock2 it adds two analog sticks and all buttons can
142  * be analog. This is treated as a separate device type as it returns
143  * axis values in the full analog range of [-0x7fff, 0x7fff],
144  * although some devices may return -0x8000.
145  * Positive X axis is right. Positive Y axis is down.
146  * Buttons are returned in the range [0, 0x7fff].
147  * Only use ANALOG type when polling for analog values.
148  */
149 #define RETRO_DEVICE_ANALOG       5
150 
151 /* Abstracts the concept of a pointing mechanism, e.g. touch.
152  * This allows libretro to query in absolute coordinates where on the
153  * screen a mouse (or something similar) is being placed.
154  * For a touch centric device, coordinates reported are the coordinates
155  * of the press.
156  *
157  * Coordinates in X and Y are reported as:
158  * [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen,
159  * and 0x7fff corresponds to the far right/bottom of the screen.
160  * The "screen" is here defined as area that is passed to the frontend and
161  * later displayed on the monitor.
162  *
163  * The frontend is free to scale/resize this screen as it sees fit, however,
164  * (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the
165  * game image, etc.
166  *
167  * To check if the pointer coordinates are valid (e.g. a touch display
168  * actually being touched), PRESSED returns 1 or 0.
169  *
170  * If using a mouse on a desktop, PRESSED will usually correspond to the
171  * left mouse button, but this is a frontend decision.
172  * PRESSED will only return 1 if the pointer is inside the game screen.
173  *
174  * For multi-touch, the index variable can be used to successively query
175  * more presses.
176  * If index = 0 returns true for _PRESSED, coordinates can be extracted
177  * with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with
178  * index = 1, and so on.
179  * Eventually _PRESSED will return false for an index. No further presses
180  * are registered at this point. */
181 #define RETRO_DEVICE_POINTER      6
182 
183 /* Buttons for the RetroPad (JOYPAD).
184  * The placement of these is equivalent to placements on the
185  * Super Nintendo controller.
186  * L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
187  * Also used as id values for RETRO_DEVICE_INDEX_ANALOG_BUTTON */
188 #define RETRO_DEVICE_ID_JOYPAD_B        0
189 #define RETRO_DEVICE_ID_JOYPAD_Y        1
190 #define RETRO_DEVICE_ID_JOYPAD_SELECT   2
191 #define RETRO_DEVICE_ID_JOYPAD_START    3
192 #define RETRO_DEVICE_ID_JOYPAD_UP       4
193 #define RETRO_DEVICE_ID_JOYPAD_DOWN     5
194 #define RETRO_DEVICE_ID_JOYPAD_LEFT     6
195 #define RETRO_DEVICE_ID_JOYPAD_RIGHT    7
196 #define RETRO_DEVICE_ID_JOYPAD_A        8
197 #define RETRO_DEVICE_ID_JOYPAD_X        9
198 #define RETRO_DEVICE_ID_JOYPAD_L       10
199 #define RETRO_DEVICE_ID_JOYPAD_R       11
200 #define RETRO_DEVICE_ID_JOYPAD_L2      12
201 #define RETRO_DEVICE_ID_JOYPAD_R2      13
202 #define RETRO_DEVICE_ID_JOYPAD_L3      14
203 #define RETRO_DEVICE_ID_JOYPAD_R3      15
204 
205 #define RETRO_DEVICE_ID_JOYPAD_MASK    256
206 
207 /* Index / Id values for ANALOG device. */
208 #define RETRO_DEVICE_INDEX_ANALOG_LEFT       0
209 #define RETRO_DEVICE_INDEX_ANALOG_RIGHT      1
210 #define RETRO_DEVICE_INDEX_ANALOG_BUTTON     2
211 #define RETRO_DEVICE_ID_ANALOG_X             0
212 #define RETRO_DEVICE_ID_ANALOG_Y             1
213 
214 /* Id values for MOUSE. */
215 #define RETRO_DEVICE_ID_MOUSE_X                0
216 #define RETRO_DEVICE_ID_MOUSE_Y                1
217 #define RETRO_DEVICE_ID_MOUSE_LEFT             2
218 #define RETRO_DEVICE_ID_MOUSE_RIGHT            3
219 #define RETRO_DEVICE_ID_MOUSE_WHEELUP          4
220 #define RETRO_DEVICE_ID_MOUSE_WHEELDOWN        5
221 #define RETRO_DEVICE_ID_MOUSE_MIDDLE           6
222 #define RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP    7
223 #define RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN  8
224 #define RETRO_DEVICE_ID_MOUSE_BUTTON_4         9
225 #define RETRO_DEVICE_ID_MOUSE_BUTTON_5         10
226 
227 /* Id values for LIGHTGUN. */
228 #define RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X        13 /*Absolute Position*/
229 #define RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y        14 /*Absolute*/
230 #define RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN    15 /*Status Check*/
231 #define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER          2
232 #define RETRO_DEVICE_ID_LIGHTGUN_RELOAD          16 /*Forced off-screen shot*/
233 #define RETRO_DEVICE_ID_LIGHTGUN_AUX_A            3
234 #define RETRO_DEVICE_ID_LIGHTGUN_AUX_B            4
235 #define RETRO_DEVICE_ID_LIGHTGUN_START            6
236 #define RETRO_DEVICE_ID_LIGHTGUN_SELECT           7
237 #define RETRO_DEVICE_ID_LIGHTGUN_AUX_C            8
238 #define RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP          9
239 #define RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN       10
240 #define RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT       11
241 #define RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT      12
242 /* deprecated */
243 #define RETRO_DEVICE_ID_LIGHTGUN_X                0 /*Relative Position*/
244 #define RETRO_DEVICE_ID_LIGHTGUN_Y                1 /*Relative*/
245 #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR           3 /*Use Aux:A*/
246 #define RETRO_DEVICE_ID_LIGHTGUN_TURBO            4 /*Use Aux:B*/
247 #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE            5 /*Use Start*/
248 
249 /* Id values for POINTER. */
250 #define RETRO_DEVICE_ID_POINTER_X         0
251 #define RETRO_DEVICE_ID_POINTER_Y         1
252 #define RETRO_DEVICE_ID_POINTER_PRESSED   2
253 #define RETRO_DEVICE_ID_POINTER_COUNT     3
254 
255 /* Returned from retro_get_region(). */
256 #define RETRO_REGION_NTSC  0
257 #define RETRO_REGION_PAL   1
258 
259 /* Id values for LANGUAGE */
260 enum retro_language
261 {
262    RETRO_LANGUAGE_ENGLISH             = 0,
263    RETRO_LANGUAGE_JAPANESE            = 1,
264    RETRO_LANGUAGE_FRENCH              = 2,
265    RETRO_LANGUAGE_SPANISH             = 3,
266    RETRO_LANGUAGE_GERMAN              = 4,
267    RETRO_LANGUAGE_ITALIAN             = 5,
268    RETRO_LANGUAGE_DUTCH               = 6,
269    RETRO_LANGUAGE_PORTUGUESE_BRAZIL   = 7,
270    RETRO_LANGUAGE_PORTUGUESE_PORTUGAL = 8,
271    RETRO_LANGUAGE_RUSSIAN             = 9,
272    RETRO_LANGUAGE_KOREAN              = 10,
273    RETRO_LANGUAGE_CHINESE_TRADITIONAL = 11,
274    RETRO_LANGUAGE_CHINESE_SIMPLIFIED  = 12,
275    RETRO_LANGUAGE_ESPERANTO           = 13,
276    RETRO_LANGUAGE_POLISH              = 14,
277    RETRO_LANGUAGE_VIETNAMESE          = 15,
278    RETRO_LANGUAGE_ARABIC              = 16,
279    RETRO_LANGUAGE_GREEK               = 17,
280    RETRO_LANGUAGE_TURKISH             = 18,
281    RETRO_LANGUAGE_SLOVAK              = 19,
282    RETRO_LANGUAGE_PERSIAN             = 20,
283    RETRO_LANGUAGE_HEBREW              = 21,
284    RETRO_LANGUAGE_ASTURIAN            = 22,
285    RETRO_LANGUAGE_LAST,
286 
287    /* Ensure sizeof(enum) == sizeof(int) */
288    RETRO_LANGUAGE_DUMMY          = INT_MAX
289 };
290 
291 /* Passed to retro_get_memory_data/size().
292  * If the memory type doesn't apply to the
293  * implementation NULL/0 can be returned.
294  */
295 #define RETRO_MEMORY_MASK        0xff
296 
297 /* Regular save RAM. This RAM is usually found on a game cartridge,
298  * backed up by a battery.
299  * If save game data is too complex for a single memory buffer,
300  * the SAVE_DIRECTORY (preferably) or SYSTEM_DIRECTORY environment
301  * callback can be used. */
302 #define RETRO_MEMORY_SAVE_RAM    0
303 
304 /* Some games have a built-in clock to keep track of time.
305  * This memory is usually just a couple of bytes to keep track of time.
306  */
307 #define RETRO_MEMORY_RTC         1
308 
309 /* System ram lets a frontend peek into a game systems main RAM. */
310 #define RETRO_MEMORY_SYSTEM_RAM  2
311 
312 /* Video ram lets a frontend peek into a game systems video RAM (VRAM). */
313 #define RETRO_MEMORY_VIDEO_RAM   3
314 
315 /* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */
316 enum retro_key
317 {
318    RETROK_UNKNOWN        = 0,
319    RETROK_FIRST          = 0,
320    RETROK_BACKSPACE      = 8,
321    RETROK_TAB            = 9,
322    RETROK_CLEAR          = 12,
323    RETROK_RETURN         = 13,
324    RETROK_PAUSE          = 19,
325    RETROK_ESCAPE         = 27,
326    RETROK_SPACE          = 32,
327    RETROK_EXCLAIM        = 33,
328    RETROK_QUOTEDBL       = 34,
329    RETROK_HASH           = 35,
330    RETROK_DOLLAR         = 36,
331    RETROK_AMPERSAND      = 38,
332    RETROK_QUOTE          = 39,
333    RETROK_LEFTPAREN      = 40,
334    RETROK_RIGHTPAREN     = 41,
335    RETROK_ASTERISK       = 42,
336    RETROK_PLUS           = 43,
337    RETROK_COMMA          = 44,
338    RETROK_MINUS          = 45,
339    RETROK_PERIOD         = 46,
340    RETROK_SLASH          = 47,
341    RETROK_0              = 48,
342    RETROK_1              = 49,
343    RETROK_2              = 50,
344    RETROK_3              = 51,
345    RETROK_4              = 52,
346    RETROK_5              = 53,
347    RETROK_6              = 54,
348    RETROK_7              = 55,
349    RETROK_8              = 56,
350    RETROK_9              = 57,
351    RETROK_COLON          = 58,
352    RETROK_SEMICOLON      = 59,
353    RETROK_LESS           = 60,
354    RETROK_EQUALS         = 61,
355    RETROK_GREATER        = 62,
356    RETROK_QUESTION       = 63,
357    RETROK_AT             = 64,
358    RETROK_LEFTBRACKET    = 91,
359    RETROK_BACKSLASH      = 92,
360    RETROK_RIGHTBRACKET   = 93,
361    RETROK_CARET          = 94,
362    RETROK_UNDERSCORE     = 95,
363    RETROK_BACKQUOTE      = 96,
364    RETROK_a              = 97,
365    RETROK_b              = 98,
366    RETROK_c              = 99,
367    RETROK_d              = 100,
368    RETROK_e              = 101,
369    RETROK_f              = 102,
370    RETROK_g              = 103,
371    RETROK_h              = 104,
372    RETROK_i              = 105,
373    RETROK_j              = 106,
374    RETROK_k              = 107,
375    RETROK_l              = 108,
376    RETROK_m              = 109,
377    RETROK_n              = 110,
378    RETROK_o              = 111,
379    RETROK_p              = 112,
380    RETROK_q              = 113,
381    RETROK_r              = 114,
382    RETROK_s              = 115,
383    RETROK_t              = 116,
384    RETROK_u              = 117,
385    RETROK_v              = 118,
386    RETROK_w              = 119,
387    RETROK_x              = 120,
388    RETROK_y              = 121,
389    RETROK_z              = 122,
390    RETROK_LEFTBRACE      = 123,
391    RETROK_BAR            = 124,
392    RETROK_RIGHTBRACE     = 125,
393    RETROK_TILDE          = 126,
394    RETROK_DELETE         = 127,
395 
396    RETROK_KP0            = 256,
397    RETROK_KP1            = 257,
398    RETROK_KP2            = 258,
399    RETROK_KP3            = 259,
400    RETROK_KP4            = 260,
401    RETROK_KP5            = 261,
402    RETROK_KP6            = 262,
403    RETROK_KP7            = 263,
404    RETROK_KP8            = 264,
405    RETROK_KP9            = 265,
406    RETROK_KP_PERIOD      = 266,
407    RETROK_KP_DIVIDE      = 267,
408    RETROK_KP_MULTIPLY    = 268,
409    RETROK_KP_MINUS       = 269,
410    RETROK_KP_PLUS        = 270,
411    RETROK_KP_ENTER       = 271,
412    RETROK_KP_EQUALS      = 272,
413 
414    RETROK_UP             = 273,
415    RETROK_DOWN           = 274,
416    RETROK_RIGHT          = 275,
417    RETROK_LEFT           = 276,
418    RETROK_INSERT         = 277,
419    RETROK_HOME           = 278,
420    RETROK_END            = 279,
421    RETROK_PAGEUP         = 280,
422    RETROK_PAGEDOWN       = 281,
423 
424    RETROK_F1             = 282,
425    RETROK_F2             = 283,
426    RETROK_F3             = 284,
427    RETROK_F4             = 285,
428    RETROK_F5             = 286,
429    RETROK_F6             = 287,
430    RETROK_F7             = 288,
431    RETROK_F8             = 289,
432    RETROK_F9             = 290,
433    RETROK_F10            = 291,
434    RETROK_F11            = 292,
435    RETROK_F12            = 293,
436    RETROK_F13            = 294,
437    RETROK_F14            = 295,
438    RETROK_F15            = 296,
439 
440    RETROK_NUMLOCK        = 300,
441    RETROK_CAPSLOCK       = 301,
442    RETROK_SCROLLOCK      = 302,
443    RETROK_RSHIFT         = 303,
444    RETROK_LSHIFT         = 304,
445    RETROK_RCTRL          = 305,
446    RETROK_LCTRL          = 306,
447    RETROK_RALT           = 307,
448    RETROK_LALT           = 308,
449    RETROK_RMETA          = 309,
450    RETROK_LMETA          = 310,
451    RETROK_LSUPER         = 311,
452    RETROK_RSUPER         = 312,
453    RETROK_MODE           = 313,
454    RETROK_COMPOSE        = 314,
455 
456    RETROK_HELP           = 315,
457    RETROK_PRINT          = 316,
458    RETROK_SYSREQ         = 317,
459    RETROK_BREAK          = 318,
460    RETROK_MENU           = 319,
461    RETROK_POWER          = 320,
462    RETROK_EURO           = 321,
463    RETROK_UNDO           = 322,
464    RETROK_OEM_102        = 323,
465 
466    RETROK_LAST,
467 
468    RETROK_DUMMY          = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
469 };
470 
471 enum retro_mod
472 {
473    RETROKMOD_NONE       = 0x0000,
474 
475    RETROKMOD_SHIFT      = 0x01,
476    RETROKMOD_CTRL       = 0x02,
477    RETROKMOD_ALT        = 0x04,
478    RETROKMOD_META       = 0x08,
479 
480    RETROKMOD_NUMLOCK    = 0x10,
481    RETROKMOD_CAPSLOCK   = 0x20,
482    RETROKMOD_SCROLLOCK  = 0x40,
483 
484    RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
485 };
486 
487 /* If set, this call is not part of the public libretro API yet. It can
488  * change or be removed at any time. */
489 #define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000
490 /* Environment callback to be used internally in frontend. */
491 #define RETRO_ENVIRONMENT_PRIVATE 0x20000
492 
493 /* Environment commands. */
494 #define RETRO_ENVIRONMENT_SET_ROTATION  1  /* const unsigned * --
495                                             * Sets screen rotation of graphics.
496                                             * Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180,
497                                             * 270 degrees counter-clockwise respectively.
498                                             */
499 #define RETRO_ENVIRONMENT_GET_OVERSCAN  2  /* bool * --
500                                             * NOTE: As of 2019 this callback is considered deprecated in favor of
501                                             * using core options to manage overscan in a more nuanced, core-specific way.
502                                             *
503                                             * Boolean value whether or not the implementation should use overscan,
504                                             * or crop away overscan.
505                                             */
506 #define RETRO_ENVIRONMENT_GET_CAN_DUPE  3  /* bool * --
507                                             * Boolean value whether or not frontend supports frame duping,
508                                             * passing NULL to video frame callback.
509                                             */
510 
511                                            /* Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES),
512                                             * and reserved to avoid possible ABI clash.
513                                             */
514 
515 #define RETRO_ENVIRONMENT_SET_MESSAGE   6  /* const struct retro_message * --
516                                             * Sets a message to be displayed in implementation-specific manner
517                                             * for a certain amount of 'frames'.
518                                             * Should not be used for trivial messages, which should simply be
519                                             * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a
520                                             * fallback, stderr).
521                                             */
522 #define RETRO_ENVIRONMENT_SHUTDOWN      7  /* N/A (NULL) --
523                                             * Requests the frontend to shutdown.
524                                             * Should only be used if game has a specific
525                                             * way to shutdown the game from a menu item or similar.
526                                             */
527 #define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8
528                                            /* const unsigned * --
529                                             * Gives a hint to the frontend how demanding this implementation
530                                             * is on a system. E.g. reporting a level of 2 means
531                                             * this implementation should run decently on all frontends
532                                             * of level 2 and up.
533                                             *
534                                             * It can be used by the frontend to potentially warn
535                                             * about too demanding implementations.
536                                             *
537                                             * The levels are "floating".
538                                             *
539                                             * This function can be called on a per-game basis,
540                                             * as certain games an implementation can play might be
541                                             * particularly demanding.
542                                             * If called, it should be called in retro_load_game().
543                                             */
544 #define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
545                                            /* const char ** --
546                                             * Returns the "system" directory of the frontend.
547                                             * This directory can be used to store system specific
548                                             * content such as BIOSes, configuration data, etc.
549                                             * The returned value can be NULL.
550                                             * If so, no such directory is defined,
551                                             * and it's up to the implementation to find a suitable directory.
552                                             *
553                                             * NOTE: Some cores used this folder also for "save" data such as
554                                             * memory cards, etc, for lack of a better place to put it.
555                                             * This is now discouraged, and if possible, cores should try to
556                                             * use the new GET_SAVE_DIRECTORY.
557                                             */
558 #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
559                                            /* const enum retro_pixel_format * --
560                                             * Sets the internal pixel format used by the implementation.
561                                             * The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555.
562                                             * This pixel format however, is deprecated (see enum retro_pixel_format).
563                                             * If the call returns false, the frontend does not support this pixel
564                                             * format.
565                                             *
566                                             * This function should be called inside retro_load_game() or
567                                             * retro_get_system_av_info().
568                                             */
569 #define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11
570                                            /* const struct retro_input_descriptor * --
571                                             * Sets an array of retro_input_descriptors.
572                                             * It is up to the frontend to present this in a usable way.
573                                             * The array is terminated by retro_input_descriptor::description
574                                             * being set to NULL.
575                                             * This function can be called at any time, but it is recommended
576                                             * to call it as early as possible.
577                                             */
578 #define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12
579                                            /* const struct retro_keyboard_callback * --
580                                             * Sets a callback function used to notify core about keyboard events.
581                                             */
582 #define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13
583                                            /* const struct retro_disk_control_callback * --
584                                             * Sets an interface which frontend can use to eject and insert
585                                             * disk images.
586                                             * This is used for games which consist of multiple images and
587                                             * must be manually swapped out by the user (e.g. PSX).
588                                             */
589 #define RETRO_ENVIRONMENT_SET_HW_RENDER 14
590                                            /* struct retro_hw_render_callback * --
591                                             * Sets an interface to let a libretro core render with
592                                             * hardware acceleration.
593                                             * Should be called in retro_load_game().
594                                             * If successful, libretro cores will be able to render to a
595                                             * frontend-provided framebuffer.
596                                             * The size of this framebuffer will be at least as large as
597                                             * max_width/max_height provided in get_av_info().
598                                             * If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or
599                                             * NULL to retro_video_refresh_t.
600                                             */
601 #define RETRO_ENVIRONMENT_GET_VARIABLE 15
602                                            /* struct retro_variable * --
603                                             * Interface to acquire user-defined information from environment
604                                             * that cannot feasibly be supported in a multi-system way.
605                                             * 'key' should be set to a key which has already been set by
606                                             * SET_VARIABLES.
607                                             * 'data' will be set to a value or NULL.
608                                             */
609 #define RETRO_ENVIRONMENT_SET_VARIABLES 16
610                                            /* const struct retro_variable * --
611                                             * Allows an implementation to signal the environment
612                                             * which variables it might want to check for later using
613                                             * GET_VARIABLE.
614                                             * This allows the frontend to present these variables to
615                                             * a user dynamically.
616                                             * This should be called the first time as early as
617                                             * possible (ideally in retro_set_environment).
618                                             * Afterward it may be called again for the core to communicate
619                                             * updated options to the frontend, but the number of core
620                                             * options must not change from the number in the initial call.
621                                             *
622                                             * 'data' points to an array of retro_variable structs
623                                             * terminated by a { NULL, NULL } element.
624                                             * retro_variable::key should be namespaced to not collide
625                                             * with other implementations' keys. E.g. A core called
626                                             * 'foo' should use keys named as 'foo_option'.
627                                             * retro_variable::value should contain a human readable
628                                             * description of the key as well as a '|' delimited list
629                                             * of expected values.
630                                             *
631                                             * The number of possible options should be very limited,
632                                             * i.e. it should be feasible to cycle through options
633                                             * without a keyboard.
634                                             *
635                                             * First entry should be treated as a default.
636                                             *
637                                             * Example entry:
638                                             * { "foo_option", "Speed hack coprocessor X; false|true" }
639                                             *
640                                             * Text before first ';' is description. This ';' must be
641                                             * followed by a space, and followed by a list of possible
642                                             * values split up with '|'.
643                                             *
644                                             * Only strings are operated on. The possible values will
645                                             * generally be displayed and stored as-is by the frontend.
646                                             */
647 #define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17
648                                            /* bool * --
649                                             * Result is set to true if some variables are updated by
650                                             * frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE.
651                                             * Variables should be queried with GET_VARIABLE.
652                                             */
653 #define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18
654                                            /* const bool * --
655                                             * If true, the libretro implementation supports calls to
656                                             * retro_load_game() with NULL as argument.
657                                             * Used by cores which can run without particular game data.
658                                             * This should be called within retro_set_environment() only.
659                                             */
660 #define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19
661                                            /* const char ** --
662                                             * Retrieves the absolute path from where this libretro
663                                             * implementation was loaded.
664                                             * NULL is returned if the libretro was loaded statically
665                                             * (i.e. linked statically to frontend), or if the path cannot be
666                                             * determined.
667                                             * Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can
668                                             * be loaded without ugly hacks.
669                                             */
670 
671                                            /* Environment 20 was an obsolete version of SET_AUDIO_CALLBACK.
672                                             * It was not used by any known core at the time,
673                                             * and was removed from the API. */
674 #define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21
675                                            /* const struct retro_frame_time_callback * --
676                                             * Lets the core know how much time has passed since last
677                                             * invocation of retro_run().
678                                             * The frontend can tamper with the timing to fake fast-forward,
679                                             * slow-motion, frame stepping, etc.
680                                             * In this case the delta time will use the reference value
681                                             * in frame_time_callback..
682                                             */
683 #define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22
684                                            /* const struct retro_audio_callback * --
685                                             * Sets an interface which is used to notify a libretro core about audio
686                                             * being available for writing.
687                                             * The callback can be called from any thread, so a core using this must
688                                             * have a thread safe audio implementation.
689                                             * It is intended for games where audio and video are completely
690                                             * asynchronous and audio can be generated on the fly.
691                                             * This interface is not recommended for use with emulators which have
692                                             * highly synchronous audio.
693                                             *
694                                             * The callback only notifies about writability; the libretro core still
695                                             * has to call the normal audio callbacks
696                                             * to write audio. The audio callbacks must be called from within the
697                                             * notification callback.
698                                             * The amount of audio data to write is up to the implementation.
699                                             * Generally, the audio callback will be called continously in a loop.
700                                             *
701                                             * Due to thread safety guarantees and lack of sync between audio and
702                                             * video, a frontend  can selectively disallow this interface based on
703                                             * internal configuration. A core using this interface must also
704                                             * implement the "normal" audio interface.
705                                             *
706                                             * A libretro core using SET_AUDIO_CALLBACK should also make use of
707                                             * SET_FRAME_TIME_CALLBACK.
708                                             */
709 #define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23
710                                            /* struct retro_rumble_interface * --
711                                             * Gets an interface which is used by a libretro core to set
712                                             * state of rumble motors in controllers.
713                                             * A strong and weak motor is supported, and they can be
714                                             * controlled indepedently.
715                                             */
716 #define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24
717                                            /* uint64_t * --
718                                             * Gets a bitmask telling which device type are expected to be
719                                             * handled properly in a call to retro_input_state_t.
720                                             * Devices which are not handled or recognized always return
721                                             * 0 in retro_input_state_t.
722                                             * Example bitmask: caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG).
723                                             * Should only be called in retro_run().
724                                             */
725 #define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL)
726                                            /* struct retro_sensor_interface * --
727                                             * Gets access to the sensor interface.
728                                             * The purpose of this interface is to allow
729                                             * setting state related to sensors such as polling rate,
730                                             * enabling/disable it entirely, etc.
731                                             * Reading sensor state is done via the normal
732                                             * input_state_callback API.
733                                             */
734 #define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL)
735                                            /* struct retro_camera_callback * --
736                                             * Gets an interface to a video camera driver.
737                                             * A libretro core can use this interface to get access to a
738                                             * video camera.
739                                             * New video frames are delivered in a callback in same
740                                             * thread as retro_run().
741                                             *
742                                             * GET_CAMERA_INTERFACE should be called in retro_load_game().
743                                             *
744                                             * Depending on the camera implementation used, camera frames
745                                             * will be delivered as a raw framebuffer,
746                                             * or as an OpenGL texture directly.
747                                             *
748                                             * The core has to tell the frontend here which types of
749                                             * buffers can be handled properly.
750                                             * An OpenGL texture can only be handled when using a
751                                             * libretro GL core (SET_HW_RENDER).
752                                             * It is recommended to use a libretro GL core when
753                                             * using camera interface.
754                                             *
755                                             * The camera is not started automatically. The retrieved start/stop
756                                             * functions must be used to explicitly
757                                             * start and stop the camera driver.
758                                             */
759 #define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27
760                                            /* struct retro_log_callback * --
761                                             * Gets an interface for logging. This is useful for
762                                             * logging in a cross-platform way
763                                             * as certain platforms cannot use stderr for logging.
764                                             * It also allows the frontend to
765                                             * show logging information in a more suitable way.
766                                             * If this interface is not used, libretro cores should
767                                             * log to stderr as desired.
768                                             */
769 #define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28
770                                            /* struct retro_perf_callback * --
771                                             * Gets an interface for performance counters. This is useful
772                                             * for performance logging in a cross-platform way and for detecting
773                                             * architecture-specific features, such as SIMD support.
774                                             */
775 #define RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE 29
776                                            /* struct retro_location_callback * --
777                                             * Gets access to the location interface.
778                                             * The purpose of this interface is to be able to retrieve
779                                             * location-based information from the host device,
780                                             * such as current latitude / longitude.
781                                             */
782 #define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30 /* Old name, kept for compatibility. */
783 #define RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY 30
784                                            /* const char ** --
785                                             * Returns the "core assets" directory of the frontend.
786                                             * This directory can be used to store specific assets that the
787                                             * core relies upon, such as art assets,
788                                             * input data, etc etc.
789                                             * The returned value can be NULL.
790                                             * If so, no such directory is defined,
791                                             * and it's up to the implementation to find a suitable directory.
792                                             */
793 #define RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY 31
794                                            /* const char ** --
795                                             * Returns the "save" directory of the frontend, unless there is no
796                                             * save directory available. The save directory should be used to
797                                             * store SRAM, memory cards, high scores, etc, if the libretro core
798                                             * cannot use the regular memory interface (retro_get_memory_data()).
799                                             *
800                                             * If the frontend cannot designate a save directory, it will return
801                                             * NULL to indicate that the core should attempt to operate without a
802                                             * save directory set.
803                                             *
804                                             * NOTE: early libretro cores used the system directory for save
805                                             * files. Cores that need to be backwards-compatible can still check
806                                             * GET_SYSTEM_DIRECTORY.
807                                             */
808 #define RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO 32
809                                            /* const struct retro_system_av_info * --
810                                             * Sets a new av_info structure. This can only be called from
811                                             * within retro_run().
812                                             * This should *only* be used if the core is completely altering the
813                                             * internal resolutions, aspect ratios, timings, sampling rate, etc.
814                                             * Calling this can require a full reinitialization of video/audio
815                                             * drivers in the frontend,
816                                             *
817                                             * so it is important to call it very sparingly, and usually only with
818                                             * the users explicit consent.
819                                             * An eventual driver reinitialize will happen so that video and
820                                             * audio callbacks
821                                             * happening after this call within the same retro_run() call will
822                                             * target the newly initialized driver.
823                                             *
824                                             * This callback makes it possible to support configurable resolutions
825                                             * in games, which can be useful to
826                                             * avoid setting the "worst case" in max_width/max_height.
827                                             *
828                                             * ***HIGHLY RECOMMENDED*** Do not call this callback every time
829                                             * resolution changes in an emulator core if it's
830                                             * expected to be a temporary change, for the reasons of possible
831                                             * driver reinitialization.
832                                             * This call is not a free pass for not trying to provide
833                                             * correct values in retro_get_system_av_info(). If you need to change
834                                             * things like aspect ratio or nominal width/height,
835                                             * use RETRO_ENVIRONMENT_SET_GEOMETRY, which is a softer variant
836                                             * of SET_SYSTEM_AV_INFO.
837                                             *
838                                             * If this returns false, the frontend does not acknowledge a
839                                             * changed av_info struct.
840                                             */
841 #define RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK 33
842                                            /* const struct retro_get_proc_address_interface * --
843                                             * Allows a libretro core to announce support for the
844                                             * get_proc_address() interface.
845                                             * This interface allows for a standard way to extend libretro where
846                                             * use of environment calls are too indirect,
847                                             * e.g. for cases where the frontend wants to call directly into the core.
848                                             *
849                                             * If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK
850                                             * **MUST** be called from within retro_set_environment().
851                                             */
852 #define RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO 34
853                                            /* const struct retro_subsystem_info * --
854                                             * This environment call introduces the concept of libretro "subsystems".
855                                             * A subsystem is a variant of a libretro core which supports
856                                             * different kinds of games.
857                                             * The purpose of this is to support e.g. emulators which might
858                                             * have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo.
859                                             * It can also be used to pick among subsystems in an explicit way
860                                             * if the libretro implementation is a multi-system emulator itself.
861                                             *
862                                             * Loading a game via a subsystem is done with retro_load_game_special(),
863                                             * and this environment call allows a libretro core to expose which
864                                             * subsystems are supported for use with retro_load_game_special().
865                                             * A core passes an array of retro_game_special_info which is terminated
866                                             * with a zeroed out retro_game_special_info struct.
867                                             *
868                                             * If a core wants to use this functionality, SET_SUBSYSTEM_INFO
869                                             * **MUST** be called from within retro_set_environment().
870                                             */
871 #define RETRO_ENVIRONMENT_SET_CONTROLLER_INFO 35
872                                            /* const struct retro_controller_info * --
873                                             * This environment call lets a libretro core tell the frontend
874                                             * which controller subclasses are recognized in calls to
875                                             * retro_set_controller_port_device().
876                                             *
877                                             * Some emulators such as Super Nintendo support multiple lightgun
878                                             * types which must be specifically selected from. It is therefore
879                                             * sometimes necessary for a frontend to be able to tell the core
880                                             * about a special kind of input device which is not specifcally
881                                             * provided by the Libretro API.
882                                             *
883                                             * In order for a frontend to understand the workings of those devices,
884                                             * they must be defined as a specialized subclass of the generic device
885                                             * types already defined in the libretro API.
886                                             *
887                                             * The core must pass an array of const struct retro_controller_info which
888                                             * is terminated with a blanked out struct. Each element of the
889                                             * retro_controller_info struct corresponds to the ascending port index
890                                             * that is passed to retro_set_controller_port_device() when that function
891                                             * is called to indicate to the core that the frontend has changed the
892                                             * active device subclass. SEE ALSO: retro_set_controller_port_device()
893                                             *
894                                             * The ascending input port indexes provided by the core in the struct
895                                             * are generally presented by frontends as ascending User # or Player #,
896                                             * such as Player 1, Player 2, Player 3, etc. Which device subclasses are
897                                             * supported can vary per input port.
898                                             *
899                                             * The first inner element of each entry in the retro_controller_info array
900                                             * is a retro_controller_description struct that specifies the names and
901                                             * codes of all device subclasses that are available for the corresponding
902                                             * User or Player, beginning with the generic Libretro device that the
903                                             * subclasses are derived from. The second inner element of each entry is the
904                                             * total number of subclasses that are listed in the retro_controller_description.
905                                             *
906                                             * NOTE: Even if special device types are set in the libretro core,
907                                             * libretro should only poll input based on the base input device types.
908                                             */
909 #define RETRO_ENVIRONMENT_SET_MEMORY_MAPS (36 | RETRO_ENVIRONMENT_EXPERIMENTAL)
910                                            /* const struct retro_memory_map * --
911                                             * This environment call lets a libretro core tell the frontend
912                                             * about the memory maps this core emulates.
913                                             * This can be used to implement, for example, cheats in a core-agnostic way.
914                                             *
915                                             * Should only be used by emulators; it doesn't make much sense for
916                                             * anything else.
917                                             * It is recommended to expose all relevant pointers through
918                                             * retro_get_memory_* as well.
919                                             *
920                                             * Can be called from retro_init and retro_load_game.
921                                             */
922 #define RETRO_ENVIRONMENT_SET_GEOMETRY 37
923                                            /* const struct retro_game_geometry * --
924                                             * This environment call is similar to SET_SYSTEM_AV_INFO for changing
925                                             * video parameters, but provides a guarantee that drivers will not be
926                                             * reinitialized.
927                                             * This can only be called from within retro_run().
928                                             *
929                                             * The purpose of this call is to allow a core to alter nominal
930                                             * width/heights as well as aspect ratios on-the-fly, which can be
931                                             * useful for some emulators to change in run-time.
932                                             *
933                                             * max_width/max_height arguments are ignored and cannot be changed
934                                             * with this call as this could potentially require a reinitialization or a
935                                             * non-constant time operation.
936                                             * If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required.
937                                             *
938                                             * A frontend must guarantee that this environment call completes in
939                                             * constant time.
940                                             */
941 #define RETRO_ENVIRONMENT_GET_USERNAME 38
942                                            /* const char **
943                                             * Returns the specified username of the frontend, if specified by the user.
944                                             * This username can be used as a nickname for a core that has online facilities
945                                             * or any other mode where personalization of the user is desirable.
946                                             * The returned value can be NULL.
947                                             * If this environ callback is used by a core that requires a valid username,
948                                             * a default username should be specified by the core.
949                                             */
950 #define RETRO_ENVIRONMENT_GET_LANGUAGE 39
951                                            /* unsigned * --
952                                             * Returns the specified language of the frontend, if specified by the user.
953                                             * It can be used by the core for localization purposes.
954                                             */
955 #define RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER (40 | RETRO_ENVIRONMENT_EXPERIMENTAL)
956                                            /* struct retro_framebuffer * --
957                                             * Returns a preallocated framebuffer which the core can use for rendering
958                                             * the frame into when not using SET_HW_RENDER.
959                                             * The framebuffer returned from this call must not be used
960                                             * after the current call to retro_run() returns.
961                                             *
962                                             * The goal of this call is to allow zero-copy behavior where a core
963                                             * can render directly into video memory, avoiding extra bandwidth cost by copying
964                                             * memory from core to video memory.
965                                             *
966                                             * If this call succeeds and the core renders into it,
967                                             * the framebuffer pointer and pitch can be passed to retro_video_refresh_t.
968                                             * If the buffer from GET_CURRENT_SOFTWARE_FRAMEBUFFER is to be used,
969                                             * the core must pass the exact
970                                             * same pointer as returned by GET_CURRENT_SOFTWARE_FRAMEBUFFER;
971                                             * i.e. passing a pointer which is offset from the
972                                             * buffer is undefined. The width, height and pitch parameters
973                                             * must also match exactly to the values obtained from GET_CURRENT_SOFTWARE_FRAMEBUFFER.
974                                             *
975                                             * It is possible for a frontend to return a different pixel format
976                                             * than the one used in SET_PIXEL_FORMAT. This can happen if the frontend
977                                             * needs to perform conversion.
978                                             *
979                                             * It is still valid for a core to render to a different buffer
980                                             * even if GET_CURRENT_SOFTWARE_FRAMEBUFFER succeeds.
981                                             *
982                                             * A frontend must make sure that the pointer obtained from this function is
983                                             * writeable (and readable).
984                                             */
985 #define RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE (41 | RETRO_ENVIRONMENT_EXPERIMENTAL)
986                                            /* const struct retro_hw_render_interface ** --
987                                             * Returns an API specific rendering interface for accessing API specific data.
988                                             * Not all HW rendering APIs support or need this.
989                                             * The contents of the returned pointer is specific to the rendering API
990                                             * being used. See the various headers like libretro_vulkan.h, etc.
991                                             *
992                                             * GET_HW_RENDER_INTERFACE cannot be called before context_reset has been called.
993                                             * Similarly, after context_destroyed callback returns,
994                                             * the contents of the HW_RENDER_INTERFACE are invalidated.
995                                             */
996 #define RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS (42 | RETRO_ENVIRONMENT_EXPERIMENTAL)
997                                            /* const bool * --
998                                             * If true, the libretro implementation supports achievements
999                                             * either via memory descriptors set with RETRO_ENVIRONMENT_SET_MEMORY_MAPS
1000                                             * or via retro_get_memory_data/retro_get_memory_size.
1001                                             *
1002                                             * This must be called before the first call to retro_run.
1003                                             */
1004 #define RETRO_ENVIRONMENT_SET_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE (43 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1005                                            /* const struct retro_hw_render_context_negotiation_interface * --
1006                                             * Sets an interface which lets the libretro core negotiate with frontend how a context is created.
1007                                             * The semantics of this interface depends on which API is used in SET_HW_RENDER earlier.
1008                                             * This interface will be used when the frontend is trying to create a HW rendering context,
1009                                             * so it will be used after SET_HW_RENDER, but before the context_reset callback.
1010                                             */
1011 #define RETRO_ENVIRONMENT_SET_SERIALIZATION_QUIRKS 44
1012                                            /* uint64_t * --
1013                                             * Sets quirk flags associated with serialization. The frontend will zero any flags it doesn't
1014                                             * recognize or support. Should be set in either retro_init or retro_load_game, but not both.
1015                                             */
1016 #define RETRO_ENVIRONMENT_SET_HW_SHARED_CONTEXT (44 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1017                                            /* N/A (null) * --
1018                                             * The frontend will try to use a 'shared' hardware context (mostly applicable
1019                                             * to OpenGL) when a hardware context is being set up.
1020                                             *
1021                                             * Returns true if the frontend supports shared hardware contexts and false
1022                                             * if the frontend does not support shared hardware contexts.
1023                                             *
1024                                             * This will do nothing on its own until SET_HW_RENDER env callbacks are
1025                                             * being used.
1026                                             */
1027 #define RETRO_ENVIRONMENT_GET_VFS_INTERFACE (45 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1028                                            /* struct retro_vfs_interface_info * --
1029                                             * Gets access to the VFS interface.
1030                                             * VFS presence needs to be queried prior to load_game or any
1031                                             * get_system/save/other_directory being called to let front end know
1032                                             * core supports VFS before it starts handing out paths.
1033                                             * It is recomended to do so in retro_set_environment
1034                                             */
1035 #define RETRO_ENVIRONMENT_GET_LED_INTERFACE (46 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1036                                            /* struct retro_led_interface * --
1037                                             * Gets an interface which is used by a libretro core to set
1038                                             * state of LEDs.
1039                                             */
1040 #define RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE (47 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1041                                            /* int * --
1042                                             * Tells the core if the frontend wants audio or video.
1043                                             * If disabled, the frontend will discard the audio or video,
1044                                             * so the core may decide to skip generating a frame or generating audio.
1045                                             * This is mainly used for increasing performance.
1046                                             * Bit 0 (value 1): Enable Video
1047                                             * Bit 1 (value 2): Enable Audio
1048                                             * Bit 2 (value 4): Use Fast Savestates.
1049                                             * Bit 3 (value 8): Hard Disable Audio
1050                                             * Other bits are reserved for future use and will default to zero.
1051                                             * If video is disabled:
1052                                             * * The frontend wants the core to not generate any video,
1053                                             *   including presenting frames via hardware acceleration.
1054                                             * * The frontend's video frame callback will do nothing.
1055                                             * * After running the frame, the video output of the next frame should be
1056                                             *   no different than if video was enabled, and saving and loading state
1057                                             *   should have no issues.
1058                                             * If audio is disabled:
1059                                             * * The frontend wants the core to not generate any audio.
1060                                             * * The frontend's audio callbacks will do nothing.
1061                                             * * After running the frame, the audio output of the next frame should be
1062                                             *   no different than if audio was enabled, and saving and loading state
1063                                             *   should have no issues.
1064                                             * Fast Savestates:
1065                                             * * Guaranteed to be created by the same binary that will load them.
1066                                             * * Will not be written to or read from the disk.
1067                                             * * Suggest that the core assumes loading state will succeed.
1068                                             * * Suggest that the core updates its memory buffers in-place if possible.
1069                                             * * Suggest that the core skips clearing memory.
1070                                             * * Suggest that the core skips resetting the system.
1071                                             * * Suggest that the core may skip validation steps.
1072                                             * Hard Disable Audio:
1073                                             * * Used for a secondary core when running ahead.
1074                                             * * Indicates that the frontend will never need audio from the core.
1075                                             * * Suggests that the core may stop synthesizing audio, but this should not
1076                                             *   compromise emulation accuracy.
1077                                             * * Audio output for the next frame does not matter, and the frontend will
1078                                             *   never need an accurate audio state in the future.
1079                                             * * State will never be saved when using Hard Disable Audio.
1080                                             */
1081 #define RETRO_ENVIRONMENT_GET_MIDI_INTERFACE (48 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1082                                            /* struct retro_midi_interface ** --
1083                                             * Returns a MIDI interface that can be used for raw data I/O.
1084                                             */
1085 
1086 #define RETRO_ENVIRONMENT_GET_FASTFORWARDING (49 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1087                                             /* bool * --
1088                                             * Boolean value that indicates whether or not the frontend is in
1089                                             * fastforwarding mode.
1090                                             */
1091 
1092 #define RETRO_ENVIRONMENT_GET_TARGET_REFRESH_RATE (50 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1093                                             /* float * --
1094                                             * Float value that lets us know what target refresh rate
1095                                             * is curently in use by the frontend.
1096                                             *
1097                                             * The core can use the returned value to set an ideal
1098                                             * refresh rate/framerate.
1099                                             */
1100 
1101 #define RETRO_ENVIRONMENT_GET_INPUT_BITMASKS (51 | RETRO_ENVIRONMENT_EXPERIMENTAL)
1102                                             /* bool * --
1103                                             * Boolean value that indicates whether or not the frontend supports
1104                                             * input bitmasks being returned by retro_input_state_t. The advantage
1105                                             * of this is that retro_input_state_t has to be only called once to
1106                                             * grab all button states instead of multiple times.
1107                                             *
1108                                             * If it returns true, you can pass RETRO_DEVICE_ID_JOYPAD_MASK as 'id'
1109                                             * to retro_input_state_t (make sure 'device' is set to RETRO_DEVICE_JOYPAD).
1110                                             * It will return a bitmask of all the digital buttons.
1111                                             */
1112 
1113 #define RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION 52
1114                                            /* unsigned * --
1115                                             * Unsigned value is the API version number of the core options
1116                                             * interface supported by the frontend. If callback return false,
1117                                             * API version is assumed to be 0.
1118                                             *
1119                                             * In legacy code, core options are set by passing an array of
1120                                             * retro_variable structs to RETRO_ENVIRONMENT_SET_VARIABLES.
1121                                             * This may be still be done regardless of the core options
1122                                             * interface version.
1123                                             *
1124                                             * If version is >= 1 however, core options may instead be set by
1125                                             * passing an array of retro_core_option_definition structs to
1126                                             * RETRO_ENVIRONMENT_SET_CORE_OPTIONS, or a 2D array of
1127                                             * retro_core_option_definition structs to RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL.
1128                                             * This allows the core to additionally set option sublabel information
1129                                             * and/or provide localisation support.
1130                                             */
1131 
1132 #define RETRO_ENVIRONMENT_SET_CORE_OPTIONS 53
1133                                            /* const struct retro_core_option_definition ** --
1134                                             * Allows an implementation to signal the environment
1135                                             * which variables it might want to check for later using
1136                                             * GET_VARIABLE.
1137                                             * This allows the frontend to present these variables to
1138                                             * a user dynamically.
1139                                             * This should only be called if RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION
1140                                             * returns an API version of >= 1.
1141                                             * This should be called instead of RETRO_ENVIRONMENT_SET_VARIABLES.
1142                                             * This should be called the first time as early as
1143                                             * possible (ideally in retro_set_environment).
1144                                             * Afterwards it may be called again for the core to communicate
1145                                             * updated options to the frontend, but the number of core
1146                                             * options must not change from the number in the initial call.
1147                                             *
1148                                             * 'data' points to an array of retro_core_option_definition structs
1149                                             * terminated by a { NULL, NULL, NULL, {{0}}, NULL } element.
1150                                             * retro_core_option_definition::key should be namespaced to not collide
1151                                             * with other implementations' keys. e.g. A core called
1152                                             * 'foo' should use keys named as 'foo_option'.
1153                                             * retro_core_option_definition::desc should contain a human readable
1154                                             * description of the key.
1155                                             * retro_core_option_definition::info should contain any additional human
1156                                             * readable information text that a typical user may need to
1157                                             * understand the functionality of the option.
1158                                             * retro_core_option_definition::values is an array of retro_core_option_value
1159                                             * structs terminated by a { NULL, NULL } element.
1160                                             * > retro_core_option_definition::values[index].value is an expected option
1161                                             *   value.
1162                                             * > retro_core_option_definition::values[index].label is a human readable
1163                                             *   label used when displaying the value on screen. If NULL,
1164                                             *   the value itself is used.
1165                                             * retro_core_option_definition::default_value is the default core option
1166                                             * setting. It must match one of the expected option values in the
1167                                             * retro_core_option_definition::values array. If it does not, or the
1168                                             * default value is NULL, the first entry in the
1169                                             * retro_core_option_definition::values array is treated as the default.
1170                                             *
1171                                             * The number of possible options should be very limited,
1172                                             * and must be less than RETRO_NUM_CORE_OPTION_VALUES_MAX.
1173                                             * i.e. it should be feasible to cycle through options
1174                                             * without a keyboard.
1175                                             *
1176                                             * Example entry:
1177                                             * {
1178                                             *     "foo_option",
1179                                             *     "Speed hack coprocessor X",
1180                                             *     "Provides increased performance at the expense of reduced accuracy",
1181                                             * 	  {
1182                                             *         { "false",    NULL },
1183                                             *         { "true",     NULL },
1184                                             *         { "unstable", "Turbo (Unstable)" },
1185                                             *         { NULL, NULL },
1186                                             *     },
1187                                             *     "false"
1188                                             * }
1189                                             *
1190                                             * Only strings are operated on. The possible values will
1191                                             * generally be displayed and stored as-is by the frontend.
1192                                             */
1193 
1194 #define RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL 54
1195                                            /* const struct retro_core_options_intl * --
1196                                             * Allows an implementation to signal the environment
1197                                             * which variables it might want to check for later using
1198                                             * GET_VARIABLE.
1199                                             * This allows the frontend to present these variables to
1200                                             * a user dynamically.
1201                                             * This should only be called if RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION
1202                                             * returns an API version of >= 1.
1203                                             * This should be called instead of RETRO_ENVIRONMENT_SET_VARIABLES.
1204                                             * This should be called the first time as early as
1205                                             * possible (ideally in retro_set_environment).
1206                                             * Afterwards it may be called again for the core to communicate
1207                                             * updated options to the frontend, but the number of core
1208                                             * options must not change from the number in the initial call.
1209                                             *
1210                                             * This is fundamentally the same as RETRO_ENVIRONMENT_SET_CORE_OPTIONS,
1211                                             * with the addition of localisation support. The description of the
1212                                             * RETRO_ENVIRONMENT_SET_CORE_OPTIONS callback should be consulted
1213                                             * for further details.
1214                                             *
1215                                             * 'data' points to a retro_core_options_intl struct.
1216                                             *
1217                                             * retro_core_options_intl::us is a pointer to an array of
1218                                             * retro_core_option_definition structs defining the US English
1219                                             * core options implementation. It must point to a valid array.
1220                                             *
1221                                             * retro_core_options_intl::local is a pointer to an array of
1222                                             * retro_core_option_definition structs defining core options for
1223                                             * the current frontend language. It may be NULL (in which case
1224                                             * retro_core_options_intl::us is used by the frontend). Any items
1225                                             * missing from this array will be read from retro_core_options_intl::us
1226                                             * instead.
1227                                             *
1228                                             * NOTE: Default core option values are always taken from the
1229                                             * retro_core_options_intl::us array. Any default values in
1230                                             * retro_core_options_intl::local array will be ignored.
1231                                             */
1232 
1233 #define RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY 55
1234                                            /* struct retro_core_option_display * --
1235                                             *
1236                                             * Allows an implementation to signal the environment to show
1237                                             * or hide a variable when displaying core options. This is
1238                                             * considered a *suggestion*. The frontend is free to ignore
1239                                             * this callback, and its implementation not considered mandatory.
1240                                             *
1241                                             * 'data' points to a retro_core_option_display struct
1242                                             *
1243                                             * retro_core_option_display::key is a variable identifier
1244                                             * which has already been set by SET_VARIABLES/SET_CORE_OPTIONS.
1245                                             *
1246                                             * retro_core_option_display::visible is a boolean, specifying
1247                                             * whether variable should be displayed
1248                                             *
1249                                             * Note that all core option variables will be set visible by
1250                                             * default when calling SET_VARIABLES/SET_CORE_OPTIONS.
1251                                             */
1252 
1253 #define RETRO_ENVIRONMENT_GET_PREFERRED_HW_RENDER 56
1254                                            /* unsigned * --
1255                                             *
1256                                             * Allows an implementation to ask frontend preferred hardware
1257                                             * context to use. Core should use this information to deal
1258                                             * with what specific context to request with SET_HW_RENDER.
1259                                             *
1260                                             * 'data' points to an unsigned variable
1261                                             */
1262 
1263 #define RETRO_ENVIRONMENT_GET_DISK_CONTROL_INTERFACE_VERSION 57
1264                                            /* unsigned * --
1265                                             * Unsigned value is the API version number of the disk control
1266                                             * interface supported by the frontend. If callback return false,
1267                                             * API version is assumed to be 0.
1268                                             *
1269                                             * In legacy code, the disk control interface is defined by passing
1270                                             * a struct of type retro_disk_control_callback to
1271                                             * RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
1272                                             * This may be still be done regardless of the disk control
1273                                             * interface version.
1274                                             *
1275                                             * If version is >= 1 however, the disk control interface may
1276                                             * instead be defined by passing a struct of type
1277                                             * retro_disk_control_ext_callback to
1278                                             * RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE.
1279                                             * This allows the core to provide additional information about
1280                                             * disk images to the frontend and/or enables extra
1281                                             * disk control functionality by the frontend.
1282                                             */
1283 
1284 #define RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE 58
1285                                            /* const struct retro_disk_control_ext_callback * --
1286                                             * Sets an interface which frontend can use to eject and insert
1287                                             * disk images, and also obtain information about individual
1288                                             * disk image files registered by the core.
1289                                             * This is used for games which consist of multiple images and
1290                                             * must be manually swapped out by the user (e.g. PSX, floppy disk
1291                                             * based systems).
1292                                             */
1293 
1294 #define RETRO_ENVIRONMENT_GET_MESSAGE_INTERFACE_VERSION 59
1295                                            /* unsigned * --
1296                                             * Unsigned value is the API version number of the message
1297                                             * interface supported by the frontend. If callback returns
1298                                             * false, API version is assumed to be 0.
1299                                             *
1300                                             * In legacy code, messages may be displayed in an
1301                                             * implementation-specific manner by passing a struct
1302                                             * of type retro_message to RETRO_ENVIRONMENT_SET_MESSAGE.
1303                                             * This may be still be done regardless of the message
1304                                             * interface version.
1305                                             *
1306                                             * If version is >= 1 however, messages may instead be
1307                                             * displayed by passing a struct of type retro_message_ext
1308                                             * to RETRO_ENVIRONMENT_SET_MESSAGE_EXT. This allows the
1309                                             * core to specify message logging level, priority and
1310                                             * destination (OSD, logging interface or both).
1311                                             */
1312 
1313 #define RETRO_ENVIRONMENT_SET_MESSAGE_EXT 60
1314                                            /* const struct retro_message_ext * --
1315                                             * Sets a message to be displayed in an implementation-specific
1316                                             * manner for a certain amount of 'frames'. Additionally allows
1317                                             * the core to specify message logging level, priority and
1318                                             * destination (OSD, logging interface or both).
1319                                             * Should not be used for trivial messages, which should simply be
1320                                             * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a
1321                                             * fallback, stderr).
1322                                             */
1323 
1324 /* VFS functionality */
1325 
1326 /* File paths:
1327  * File paths passed as parameters when using this API shall be well formed UNIX-style,
1328  * using "/" (unquoted forward slash) as directory separator regardless of the platform's native separator.
1329  * Paths shall also include at least one forward slash ("game.bin" is an invalid path, use "./game.bin" instead).
1330  * Other than the directory separator, cores shall not make assumptions about path format:
1331  * "C:/path/game.bin", "http://example.com/game.bin", "#game/game.bin", "./game.bin" (without quotes) are all valid paths.
1332  * Cores may replace the basename or remove path components from the end, and/or add new components;
1333  * however, cores shall not append "./", "../" or multiple consecutive forward slashes ("//") to paths they request to front end.
1334  * The frontend is encouraged to make such paths work as well as it can, but is allowed to give up if the core alters paths too much.
1335  * Frontends are encouraged, but not required, to support native file system paths (modulo replacing the directory separator, if applicable).
1336  * Cores are allowed to try using them, but must remain functional if the front rejects such requests.
1337  * Cores are encouraged to use the libretro-common filestream functions for file I/O,
1338  * as they seamlessly integrate with VFS, deal with directory separator replacement as appropriate
1339  * and provide platform-specific fallbacks in cases where front ends do not support VFS. */
1340 
1341 /* Opaque file handle
1342  * Introduced in VFS API v1 */
1343 struct retro_vfs_file_handle;
1344 
1345 /* Opaque directory handle
1346  * Introduced in VFS API v3 */
1347 struct retro_vfs_dir_handle;
1348 
1349 /* File open flags
1350  * Introduced in VFS API v1 */
1351 #define RETRO_VFS_FILE_ACCESS_READ            (1 << 0) /* Read only mode */
1352 #define RETRO_VFS_FILE_ACCESS_WRITE           (1 << 1) /* Write only mode, discard contents and overwrites existing file unless RETRO_VFS_FILE_ACCESS_UPDATE is also specified */
1353 #define RETRO_VFS_FILE_ACCESS_READ_WRITE      (RETRO_VFS_FILE_ACCESS_READ | RETRO_VFS_FILE_ACCESS_WRITE) /* Read-write mode, discard contents and overwrites existing file unless RETRO_VFS_FILE_ACCESS_UPDATE is also specified*/
1354 #define RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING (1 << 2) /* Prevents discarding content of existing files opened for writing */
1355 
1356 /* These are only hints. The frontend may choose to ignore them. Other than RAM/CPU/etc use,
1357    and how they react to unlikely external interference (for example someone else writing to that file,
1358    or the file's server going down), behavior will not change. */
1359 #define RETRO_VFS_FILE_ACCESS_HINT_NONE              (0)
1360 /* Indicate that the file will be accessed many times. The frontend should aggressively cache everything. */
1361 #define RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS   (1 << 0)
1362 
1363 /* Seek positions */
1364 #define RETRO_VFS_SEEK_POSITION_START    0
1365 #define RETRO_VFS_SEEK_POSITION_CURRENT  1
1366 #define RETRO_VFS_SEEK_POSITION_END      2
1367 
1368 /* stat() result flags
1369  * Introduced in VFS API v3 */
1370 #define RETRO_VFS_STAT_IS_VALID               (1 << 0)
1371 #define RETRO_VFS_STAT_IS_DIRECTORY           (1 << 1)
1372 #define RETRO_VFS_STAT_IS_CHARACTER_SPECIAL   (1 << 2)
1373 
1374 /* Get path from opaque handle. Returns the exact same path passed to file_open when getting the handle
1375  * Introduced in VFS API v1 */
1376 typedef const char *(RETRO_CALLCONV *retro_vfs_get_path_t)(struct retro_vfs_file_handle *stream);
1377 
1378 /* Open a file for reading or writing. If path points to a directory, this will
1379  * fail. Returns the opaque file handle, or NULL for error.
1380  * Introduced in VFS API v1 */
1381 typedef struct retro_vfs_file_handle *(RETRO_CALLCONV *retro_vfs_open_t)(const char *path, unsigned mode, unsigned hints);
1382 
1383 /* Close the file and release its resources. Must be called if open_file returns non-NULL. Returns 0 on success, -1 on failure.
1384  * Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
1385  * Introduced in VFS API v1 */
1386 typedef int (RETRO_CALLCONV *retro_vfs_close_t)(struct retro_vfs_file_handle *stream);
1387 
1388 /* Return the size of the file in bytes, or -1 for error.
1389  * Introduced in VFS API v1 */
1390 typedef int64_t (RETRO_CALLCONV *retro_vfs_size_t)(struct retro_vfs_file_handle *stream);
1391 
1392 /* Truncate file to specified size. Returns 0 on success or -1 on error
1393  * Introduced in VFS API v2 */
1394 typedef int64_t (RETRO_CALLCONV *retro_vfs_truncate_t)(struct retro_vfs_file_handle *stream, int64_t length);
1395 
1396 /* Get the current read / write position for the file. Returns -1 for error.
1397  * Introduced in VFS API v1 */
1398 typedef int64_t (RETRO_CALLCONV *retro_vfs_tell_t)(struct retro_vfs_file_handle *stream);
1399 
1400 /* Set the current read/write position for the file. Returns the new position, -1 for error.
1401  * Introduced in VFS API v1 */
1402 typedef int64_t (RETRO_CALLCONV *retro_vfs_seek_t)(struct retro_vfs_file_handle *stream, int64_t offset, int seek_position);
1403 
1404 /* Read data from a file. Returns the number of bytes read, or -1 for error.
1405  * Introduced in VFS API v1 */
1406 typedef int64_t (RETRO_CALLCONV *retro_vfs_read_t)(struct retro_vfs_file_handle *stream, void *s, uint64_t len);
1407 
1408 /* Write data to a file. Returns the number of bytes written, or -1 for error.
1409  * Introduced in VFS API v1 */
1410 typedef int64_t (RETRO_CALLCONV *retro_vfs_write_t)(struct retro_vfs_file_handle *stream, const void *s, uint64_t len);
1411 
1412 /* Flush pending writes to file, if using buffered IO. Returns 0 on sucess, or -1 on failure.
1413  * Introduced in VFS API v1 */
1414 typedef int (RETRO_CALLCONV *retro_vfs_flush_t)(struct retro_vfs_file_handle *stream);
1415 
1416 /* Delete the specified file. Returns 0 on success, -1 on failure
1417  * Introduced in VFS API v1 */
1418 typedef int (RETRO_CALLCONV *retro_vfs_remove_t)(const char *path);
1419 
1420 /* Rename the specified file. Returns 0 on success, -1 on failure
1421  * Introduced in VFS API v1 */
1422 typedef int (RETRO_CALLCONV *retro_vfs_rename_t)(const char *old_path, const char *new_path);
1423 
1424 /* Stat the specified file. Retruns a bitmask of RETRO_VFS_STAT_* flags, none are set if path was not valid.
1425  * Additionally stores file size in given variable, unless NULL is given.
1426  * Introduced in VFS API v3 */
1427 typedef int (RETRO_CALLCONV *retro_vfs_stat_t)(const char *path, int32_t *size);
1428 
1429 /* Create the specified directory. Returns 0 on success, -1 on unknown failure, -2 if already exists.
1430  * Introduced in VFS API v3 */
1431 typedef int (RETRO_CALLCONV *retro_vfs_mkdir_t)(const char *dir);
1432 
1433 /* Open the specified directory for listing. Returns the opaque dir handle, or NULL for error.
1434  * Support for the include_hidden argument may vary depending on the platform.
1435  * Introduced in VFS API v3 */
1436 typedef struct retro_vfs_dir_handle *(RETRO_CALLCONV *retro_vfs_opendir_t)(const char *dir, bool include_hidden);
1437 
1438 /* Read the directory entry at the current position, and move the read pointer to the next position.
1439  * Returns true on success, false if already on the last entry.
1440  * Introduced in VFS API v3 */
1441 typedef bool (RETRO_CALLCONV *retro_vfs_readdir_t)(struct retro_vfs_dir_handle *dirstream);
1442 
1443 /* Get the name of the last entry read. Returns a string on success, or NULL for error.
1444  * The returned string pointer is valid until the next call to readdir or closedir.
1445  * Introduced in VFS API v3 */
1446 typedef const char *(RETRO_CALLCONV *retro_vfs_dirent_get_name_t)(struct retro_vfs_dir_handle *dirstream);
1447 
1448 /* Check if the last entry read was a directory. Returns true if it was, false otherwise (or on error).
1449  * Introduced in VFS API v3 */
1450 typedef bool (RETRO_CALLCONV *retro_vfs_dirent_is_dir_t)(struct retro_vfs_dir_handle *dirstream);
1451 
1452 /* Close the directory and release its resources. Must be called if opendir returns non-NULL. Returns 0 on success, -1 on failure.
1453  * Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
1454  * Introduced in VFS API v3 */
1455 typedef int (RETRO_CALLCONV *retro_vfs_closedir_t)(struct retro_vfs_dir_handle *dirstream);
1456 
1457 struct retro_vfs_interface
1458 {
1459    /* VFS API v1 */
1460 	retro_vfs_get_path_t get_path;
1461 	retro_vfs_open_t open;
1462 	retro_vfs_close_t close;
1463 	retro_vfs_size_t size;
1464 	retro_vfs_tell_t tell;
1465 	retro_vfs_seek_t seek;
1466 	retro_vfs_read_t read;
1467 	retro_vfs_write_t write;
1468 	retro_vfs_flush_t flush;
1469 	retro_vfs_remove_t remove;
1470 	retro_vfs_rename_t rename;
1471    /* VFS API v2 */
1472    retro_vfs_truncate_t truncate;
1473    /* VFS API v3 */
1474    retro_vfs_stat_t stat;
1475    retro_vfs_mkdir_t mkdir;
1476    retro_vfs_opendir_t opendir;
1477    retro_vfs_readdir_t readdir;
1478    retro_vfs_dirent_get_name_t dirent_get_name;
1479    retro_vfs_dirent_is_dir_t dirent_is_dir;
1480    retro_vfs_closedir_t closedir;
1481 };
1482 
1483 struct retro_vfs_interface_info
1484 {
1485    /* Set by core: should this be higher than the version the front end supports,
1486     * front end will return false in the RETRO_ENVIRONMENT_GET_VFS_INTERFACE call
1487     * Introduced in VFS API v1 */
1488    uint32_t required_interface_version;
1489 
1490    /* Frontend writes interface pointer here. The frontend also sets the actual
1491     * version, must be at least required_interface_version.
1492     * Introduced in VFS API v1 */
1493    struct retro_vfs_interface *iface;
1494 };
1495 
1496 enum retro_hw_render_interface_type
1497 {
1498 	RETRO_HW_RENDER_INTERFACE_VULKAN = 0,
1499 	RETRO_HW_RENDER_INTERFACE_D3D9   = 1,
1500 	RETRO_HW_RENDER_INTERFACE_D3D10  = 2,
1501 	RETRO_HW_RENDER_INTERFACE_D3D11  = 3,
1502 	RETRO_HW_RENDER_INTERFACE_D3D12  = 4,
1503    RETRO_HW_RENDER_INTERFACE_GSKIT_PS2  = 5,
1504    RETRO_HW_RENDER_INTERFACE_DUMMY  = INT_MAX
1505 };
1506 
1507 /* Base struct. All retro_hw_render_interface_* types
1508  * contain at least these fields. */
1509 struct retro_hw_render_interface
1510 {
1511    enum retro_hw_render_interface_type interface_type;
1512    unsigned interface_version;
1513 };
1514 
1515 typedef void (RETRO_CALLCONV *retro_set_led_state_t)(int led, int state);
1516 struct retro_led_interface
1517 {
1518     retro_set_led_state_t set_led_state;
1519 };
1520 
1521 /* Retrieves the current state of the MIDI input.
1522  * Returns true if it's enabled, false otherwise. */
1523 typedef bool (RETRO_CALLCONV *retro_midi_input_enabled_t)(void);
1524 
1525 /* Retrieves the current state of the MIDI output.
1526  * Returns true if it's enabled, false otherwise */
1527 typedef bool (RETRO_CALLCONV *retro_midi_output_enabled_t)(void);
1528 
1529 /* Reads next byte from the input stream.
1530  * Returns true if byte is read, false otherwise. */
1531 typedef bool (RETRO_CALLCONV *retro_midi_read_t)(uint8_t *byte);
1532 
1533 /* Writes byte to the output stream.
1534  * 'delta_time' is in microseconds and represent time elapsed since previous write.
1535  * Returns true if byte is written, false otherwise. */
1536 typedef bool (RETRO_CALLCONV *retro_midi_write_t)(uint8_t byte, uint32_t delta_time);
1537 
1538 /* Flushes previously written data.
1539  * Returns true if successful, false otherwise. */
1540 typedef bool (RETRO_CALLCONV *retro_midi_flush_t)(void);
1541 
1542 struct retro_midi_interface
1543 {
1544    retro_midi_input_enabled_t input_enabled;
1545    retro_midi_output_enabled_t output_enabled;
1546    retro_midi_read_t read;
1547    retro_midi_write_t write;
1548    retro_midi_flush_t flush;
1549 };
1550 
1551 enum retro_hw_render_context_negotiation_interface_type
1552 {
1553    RETRO_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_VULKAN = 0,
1554    RETRO_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_DUMMY = INT_MAX
1555 };
1556 
1557 /* Base struct. All retro_hw_render_context_negotiation_interface_* types
1558  * contain at least these fields. */
1559 struct retro_hw_render_context_negotiation_interface
1560 {
1561    enum retro_hw_render_context_negotiation_interface_type interface_type;
1562    unsigned interface_version;
1563 };
1564 
1565 /* Serialized state is incomplete in some way. Set if serialization is
1566  * usable in typical end-user cases but should not be relied upon to
1567  * implement frame-sensitive frontend features such as netplay or
1568  * rerecording. */
1569 #define RETRO_SERIALIZATION_QUIRK_INCOMPLETE (1 << 0)
1570 /* The core must spend some time initializing before serialization is
1571  * supported. retro_serialize() will initially fail; retro_unserialize()
1572  * and retro_serialize_size() may or may not work correctly either. */
1573 #define RETRO_SERIALIZATION_QUIRK_MUST_INITIALIZE (1 << 1)
1574 /* Serialization size may change within a session. */
1575 #define RETRO_SERIALIZATION_QUIRK_CORE_VARIABLE_SIZE (1 << 2)
1576 /* Set by the frontend to acknowledge that it supports variable-sized
1577  * states. */
1578 #define RETRO_SERIALIZATION_QUIRK_FRONT_VARIABLE_SIZE (1 << 3)
1579 /* Serialized state can only be loaded during the same session. */
1580 #define RETRO_SERIALIZATION_QUIRK_SINGLE_SESSION (1 << 4)
1581 /* Serialized state cannot be loaded on an architecture with a different
1582  * endianness from the one it was saved on. */
1583 #define RETRO_SERIALIZATION_QUIRK_ENDIAN_DEPENDENT (1 << 5)
1584 /* Serialized state cannot be loaded on a different platform from the one it
1585  * was saved on for reasons other than endianness, such as word size
1586  * dependence */
1587 #define RETRO_SERIALIZATION_QUIRK_PLATFORM_DEPENDENT (1 << 6)
1588 
1589 #define RETRO_MEMDESC_CONST      (1 << 0)   /* The frontend will never change this memory area once retro_load_game has returned. */
1590 #define RETRO_MEMDESC_BIGENDIAN  (1 << 1)   /* The memory area contains big endian data. Default is little endian. */
1591 #define RETRO_MEMDESC_SYSTEM_RAM (1 << 2)   /* The memory area is system RAM.  This is main RAM of the gaming system. */
1592 #define RETRO_MEMDESC_SAVE_RAM   (1 << 3)   /* The memory area is save RAM. This RAM is usually found on a game cartridge, backed up by a battery. */
1593 #define RETRO_MEMDESC_VIDEO_RAM  (1 << 4)   /* The memory area is video RAM (VRAM) */
1594 #define RETRO_MEMDESC_ALIGN_2    (1 << 16)  /* All memory access in this area is aligned to their own size, or 2, whichever is smaller. */
1595 #define RETRO_MEMDESC_ALIGN_4    (2 << 16)
1596 #define RETRO_MEMDESC_ALIGN_8    (3 << 16)
1597 #define RETRO_MEMDESC_MINSIZE_2  (1 << 24)  /* All memory in this region is accessed at least 2 bytes at the time. */
1598 #define RETRO_MEMDESC_MINSIZE_4  (2 << 24)
1599 #define RETRO_MEMDESC_MINSIZE_8  (3 << 24)
1600 struct retro_memory_descriptor
1601 {
1602    uint64_t flags;
1603 
1604    /* Pointer to the start of the relevant ROM or RAM chip.
1605     * It's strongly recommended to use 'offset' if possible, rather than
1606     * doing math on the pointer.
1607     *
1608     * If the same byte is mapped my multiple descriptors, their descriptors
1609     * must have the same pointer.
1610     * If 'start' does not point to the first byte in the pointer, put the
1611     * difference in 'offset' instead.
1612     *
1613     * May be NULL if there's nothing usable here (e.g. hardware registers and
1614     * open bus). No flags should be set if the pointer is NULL.
1615     * It's recommended to minimize the number of descriptors if possible,
1616     * but not mandatory. */
1617    void *ptr;
1618    size_t offset;
1619 
1620    /* This is the location in the emulated address space
1621     * where the mapping starts. */
1622    size_t start;
1623 
1624    /* Which bits must be same as in 'start' for this mapping to apply.
1625     * The first memory descriptor to claim a certain byte is the one
1626     * that applies.
1627     * A bit which is set in 'start' must also be set in this.
1628     * Can be zero, in which case each byte is assumed mapped exactly once.
1629     * In this case, 'len' must be a power of two. */
1630    size_t select;
1631 
1632    /* If this is nonzero, the set bits are assumed not connected to the
1633     * memory chip's address pins. */
1634    size_t disconnect;
1635 
1636    /* This one tells the size of the current memory area.
1637     * If, after start+disconnect are applied, the address is higher than
1638     * this, the highest bit of the address is cleared.
1639     *
1640     * If the address is still too high, the next highest bit is cleared.
1641     * Can be zero, in which case it's assumed to be infinite (as limited
1642     * by 'select' and 'disconnect'). */
1643    size_t len;
1644 
1645    /* To go from emulated address to physical address, the following
1646     * order applies:
1647     * Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'. */
1648 
1649    /* The address space name must consist of only a-zA-Z0-9_-,
1650     * should be as short as feasible (maximum length is 8 plus the NUL),
1651     * and may not be any other address space plus one or more 0-9A-F
1652     * at the end.
1653     * However, multiple memory descriptors for the same address space is
1654     * allowed, and the address space name can be empty. NULL is treated
1655     * as empty.
1656     *
1657     * Address space names are case sensitive, but avoid lowercase if possible.
1658     * The same pointer may exist in multiple address spaces.
1659     *
1660     * Examples:
1661     * blank+blank - valid (multiple things may be mapped in the same namespace)
1662     * 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace)
1663     * 'A'+'B' - valid (neither is a prefix of each other)
1664     * 'S'+blank - valid ('S' is not in 0-9A-F)
1665     * 'a'+blank - valid ('a' is not in 0-9A-F)
1666     * 'a'+'A' - valid (neither is a prefix of each other)
1667     * 'AR'+blank - valid ('R' is not in 0-9A-F)
1668     * 'ARB'+blank - valid (the B can't be part of the address either, because
1669     *                      there is no namespace 'AR')
1670     * blank+'B' - not valid, because it's ambigous which address space B1234
1671     *             would refer to.
1672     * The length can't be used for that purpose; the frontend may want
1673     * to append arbitrary data to an address, without a separator. */
1674    const char *addrspace;
1675 
1676    /* TODO: When finalizing this one, add a description field, which should be
1677     * "WRAM" or something roughly equally long. */
1678 
1679    /* TODO: When finalizing this one, replace 'select' with 'limit', which tells
1680     * which bits can vary and still refer to the same address (limit = ~select).
1681     * TODO: limit? range? vary? something else? */
1682 
1683    /* TODO: When finalizing this one, if 'len' is above what 'select' (or
1684     * 'limit') allows, it's bankswitched. Bankswitched data must have both 'len'
1685     * and 'select' != 0, and the mappings don't tell how the system switches the
1686     * banks. */
1687 
1688    /* TODO: When finalizing this one, fix the 'len' bit removal order.
1689     * For len=0x1800, pointer 0x1C00 should go to 0x1400, not 0x0C00.
1690     * Algorithm: Take bits highest to lowest, but if it goes above len, clear
1691     * the most recent addition and continue on the next bit.
1692     * TODO: Can the above be optimized? Is "remove the lowest bit set in both
1693     * pointer and 'len'" equivalent? */
1694 
1695    /* TODO: Some emulators (MAME?) emulate big endian systems by only accessing
1696     * the emulated memory in 32-bit chunks, native endian. But that's nothing
1697     * compared to Darek Mihocka <http://www.emulators.com/docs/nx07_vm101.htm>
1698     * (section Emulation 103 - Nearly Free Byte Reversal) - he flips the ENTIRE
1699     * RAM backwards! I'll want to represent both of those, via some flags.
1700     *
1701     * I suspect MAME either didn't think of that idea, or don't want the #ifdef.
1702     * Not sure which, nor do I really care. */
1703 
1704    /* TODO: Some of those flags are unused and/or don't really make sense. Clean
1705     * them up. */
1706 };
1707 
1708 /* The frontend may use the largest value of 'start'+'select' in a
1709  * certain namespace to infer the size of the address space.
1710  *
1711  * If the address space is larger than that, a mapping with .ptr=NULL
1712  * should be at the end of the array, with .select set to all ones for
1713  * as long as the address space is big.
1714  *
1715  * Sample descriptors (minus .ptr, and RETRO_MEMFLAG_ on the flags):
1716  * SNES WRAM:
1717  * .start=0x7E0000, .len=0x20000
1718  * (Note that this must be mapped before the ROM in most cases; some of the
1719  * ROM mappers
1720  * try to claim $7E0000, or at least $7E8000.)
1721  * SNES SPC700 RAM:
1722  * .addrspace="S", .len=0x10000
1723  * SNES WRAM mirrors:
1724  * .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000
1725  * .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000
1726  * SNES WRAM mirrors, alternate equivalent descriptor:
1727  * .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF
1728  * (Various similar constructions can be created by combining parts of
1729  * the above two.)
1730  * SNES LoROM (512KB, mirrored a couple of times):
1731  * .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024
1732  * .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024
1733  * SNES HiROM (4MB):
1734  * .flags=CONST,                 .start=0x400000, .select=0x400000, .len=4*1024*1024
1735  * .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024
1736  * SNES ExHiROM (8MB):
1737  * .flags=CONST, .offset=0,                  .start=0xC00000, .select=0xC00000, .len=4*1024*1024
1738  * .flags=CONST, .offset=4*1024*1024,        .start=0x400000, .select=0xC00000, .len=4*1024*1024
1739  * .flags=CONST, .offset=0x8000,             .start=0x808000, .select=0xC08000, .len=4*1024*1024
1740  * .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024
1741  * Clarify the size of the address space:
1742  * .ptr=NULL, .select=0xFFFFFF
1743  * .len can be implied by .select in many of them, but was included for clarity.
1744  */
1745 
1746 struct retro_memory_map
1747 {
1748    const struct retro_memory_descriptor *descriptors;
1749    unsigned num_descriptors;
1750 };
1751 
1752 struct retro_controller_description
1753 {
1754    /* Human-readable description of the controller. Even if using a generic
1755     * input device type, this can be set to the particular device type the
1756     * core uses. */
1757    const char *desc;
1758 
1759    /* Device type passed to retro_set_controller_port_device(). If the device
1760     * type is a sub-class of a generic input device type, use the
1761     * RETRO_DEVICE_SUBCLASS macro to create an ID.
1762     *
1763     * E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1). */
1764    unsigned id;
1765 };
1766 
1767 struct retro_controller_info
1768 {
1769    const struct retro_controller_description *types;
1770    unsigned num_types;
1771 };
1772 
1773 struct retro_subsystem_memory_info
1774 {
1775    /* The extension associated with a memory type, e.g. "psram". */
1776    const char *extension;
1777 
1778    /* The memory type for retro_get_memory(). This should be at
1779     * least 0x100 to avoid conflict with standardized
1780     * libretro memory types. */
1781    unsigned type;
1782 };
1783 
1784 struct retro_subsystem_rom_info
1785 {
1786    /* Describes what the content is (SGB BIOS, GB ROM, etc). */
1787    const char *desc;
1788 
1789    /* Same definition as retro_get_system_info(). */
1790    const char *valid_extensions;
1791 
1792    /* Same definition as retro_get_system_info(). */
1793    bool need_fullpath;
1794 
1795    /* Same definition as retro_get_system_info(). */
1796    bool block_extract;
1797 
1798    /* This is set if the content is required to load a game.
1799     * If this is set to false, a zeroed-out retro_game_info can be passed. */
1800    bool required;
1801 
1802    /* Content can have multiple associated persistent
1803     * memory types (retro_get_memory()). */
1804    const struct retro_subsystem_memory_info *memory;
1805    unsigned num_memory;
1806 };
1807 
1808 struct retro_subsystem_info
1809 {
1810    /* Human-readable string of the subsystem type, e.g. "Super GameBoy" */
1811    const char *desc;
1812 
1813    /* A computer friendly short string identifier for the subsystem type.
1814     * This name must be [a-z].
1815     * E.g. if desc is "Super GameBoy", this can be "sgb".
1816     * This identifier can be used for command-line interfaces, etc.
1817     */
1818    const char *ident;
1819 
1820    /* Infos for each content file. The first entry is assumed to be the
1821     * "most significant" content for frontend purposes.
1822     * E.g. with Super GameBoy, the first content should be the GameBoy ROM,
1823     * as it is the most "significant" content to a user.
1824     * If a frontend creates new file paths based on the content used
1825     * (e.g. savestates), it should use the path for the first ROM to do so. */
1826    const struct retro_subsystem_rom_info *roms;
1827 
1828    /* Number of content files associated with a subsystem. */
1829    unsigned num_roms;
1830 
1831    /* The type passed to retro_load_game_special(). */
1832    unsigned id;
1833 };
1834 
1835 typedef void (RETRO_CALLCONV *retro_proc_address_t)(void);
1836 
1837 /* libretro API extension functions:
1838  * (None here so far).
1839  *
1840  * Get a symbol from a libretro core.
1841  * Cores should only return symbols which are actual
1842  * extensions to the libretro API.
1843  *
1844  * Frontends should not use this to obtain symbols to standard
1845  * libretro entry points (static linking or dlsym).
1846  *
1847  * The symbol name must be equal to the function name,
1848  * e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo".
1849  * The returned function pointer must be cast to the corresponding type.
1850  */
1851 typedef retro_proc_address_t (RETRO_CALLCONV *retro_get_proc_address_t)(const char *sym);
1852 
1853 struct retro_get_proc_address_interface
1854 {
1855    retro_get_proc_address_t get_proc_address;
1856 };
1857 
1858 enum retro_log_level
1859 {
1860    RETRO_LOG_DEBUG = 0,
1861    RETRO_LOG_INFO,
1862    RETRO_LOG_WARN,
1863    RETRO_LOG_ERROR,
1864 
1865    RETRO_LOG_DUMMY = INT_MAX
1866 };
1867 
1868 /* Logging function. Takes log level argument as well. */
1869 typedef void (RETRO_CALLCONV *retro_log_printf_t)(enum retro_log_level level,
1870       const char *fmt, ...);
1871 
1872 struct retro_log_callback
1873 {
1874    retro_log_printf_t log;
1875 };
1876 
1877 /* Performance related functions */
1878 
1879 /* ID values for SIMD CPU features */
1880 #define RETRO_SIMD_SSE      (1 << 0)
1881 #define RETRO_SIMD_SSE2     (1 << 1)
1882 #define RETRO_SIMD_VMX      (1 << 2)
1883 #define RETRO_SIMD_VMX128   (1 << 3)
1884 #define RETRO_SIMD_AVX      (1 << 4)
1885 #define RETRO_SIMD_NEON     (1 << 5)
1886 #define RETRO_SIMD_SSE3     (1 << 6)
1887 #define RETRO_SIMD_SSSE3    (1 << 7)
1888 #define RETRO_SIMD_MMX      (1 << 8)
1889 #define RETRO_SIMD_MMXEXT   (1 << 9)
1890 #define RETRO_SIMD_SSE4     (1 << 10)
1891 #define RETRO_SIMD_SSE42    (1 << 11)
1892 #define RETRO_SIMD_AVX2     (1 << 12)
1893 #define RETRO_SIMD_VFPU     (1 << 13)
1894 #define RETRO_SIMD_PS       (1 << 14)
1895 #define RETRO_SIMD_AES      (1 << 15)
1896 #define RETRO_SIMD_VFPV3    (1 << 16)
1897 #define RETRO_SIMD_VFPV4    (1 << 17)
1898 #define RETRO_SIMD_POPCNT   (1 << 18)
1899 #define RETRO_SIMD_MOVBE    (1 << 19)
1900 #define RETRO_SIMD_CMOV     (1 << 20)
1901 #define RETRO_SIMD_ASIMD    (1 << 21)
1902 
1903 typedef uint64_t retro_perf_tick_t;
1904 typedef int64_t retro_time_t;
1905 
1906 struct retro_perf_counter
1907 {
1908    const char *ident;
1909    retro_perf_tick_t start;
1910    retro_perf_tick_t total;
1911    retro_perf_tick_t call_cnt;
1912 
1913    bool registered;
1914 };
1915 
1916 /* Returns current time in microseconds.
1917  * Tries to use the most accurate timer available.
1918  */
1919 typedef retro_time_t (RETRO_CALLCONV *retro_perf_get_time_usec_t)(void);
1920 
1921 /* A simple counter. Usually nanoseconds, but can also be CPU cycles.
1922  * Can be used directly if desired (when creating a more sophisticated
1923  * performance counter system).
1924  * */
1925 typedef retro_perf_tick_t (RETRO_CALLCONV *retro_perf_get_counter_t)(void);
1926 
1927 /* Returns a bit-mask of detected CPU features (RETRO_SIMD_*). */
1928 typedef uint64_t (RETRO_CALLCONV *retro_get_cpu_features_t)(void);
1929 
1930 /* Asks frontend to log and/or display the state of performance counters.
1931  * Performance counters can always be poked into manually as well.
1932  */
1933 typedef void (RETRO_CALLCONV *retro_perf_log_t)(void);
1934 
1935 /* Register a performance counter.
1936  * ident field must be set with a discrete value and other values in
1937  * retro_perf_counter must be 0.
1938  * Registering can be called multiple times. To avoid calling to
1939  * frontend redundantly, you can check registered field first. */
1940 typedef void (RETRO_CALLCONV *retro_perf_register_t)(struct retro_perf_counter *counter);
1941 
1942 /* Starts a registered counter. */
1943 typedef void (RETRO_CALLCONV *retro_perf_start_t)(struct retro_perf_counter *counter);
1944 
1945 /* Stops a registered counter. */
1946 typedef void (RETRO_CALLCONV *retro_perf_stop_t)(struct retro_perf_counter *counter);
1947 
1948 /* For convenience it can be useful to wrap register, start and stop in macros.
1949  * E.g.:
1950  * #ifdef LOG_PERFORMANCE
1951  * #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
1952  * #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
1953  * #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
1954  * #else
1955  * ... Blank macros ...
1956  * #endif
1957  *
1958  * These can then be used mid-functions around code snippets.
1959  *
1960  * extern struct retro_perf_callback perf_cb;  * Somewhere in the core.
1961  *
1962  * void do_some_heavy_work(void)
1963  * {
1964  *    RETRO_PERFORMANCE_INIT(cb, work_1;
1965  *    RETRO_PERFORMANCE_START(cb, work_1);
1966  *    heavy_work_1();
1967  *    RETRO_PERFORMANCE_STOP(cb, work_1);
1968  *
1969  *    RETRO_PERFORMANCE_INIT(cb, work_2);
1970  *    RETRO_PERFORMANCE_START(cb, work_2);
1971  *    heavy_work_2();
1972  *    RETRO_PERFORMANCE_STOP(cb, work_2);
1973  * }
1974  *
1975  * void retro_deinit(void)
1976  * {
1977  *    perf_cb.perf_log();  * Log all perf counters here for example.
1978  * }
1979  */
1980 
1981 struct retro_perf_callback
1982 {
1983    retro_perf_get_time_usec_t    get_time_usec;
1984    retro_get_cpu_features_t      get_cpu_features;
1985 
1986    retro_perf_get_counter_t      get_perf_counter;
1987    retro_perf_register_t         perf_register;
1988    retro_perf_start_t            perf_start;
1989    retro_perf_stop_t             perf_stop;
1990    retro_perf_log_t              perf_log;
1991 };
1992 
1993 /* FIXME: Document the sensor API and work out behavior.
1994  * It will be marked as experimental until then.
1995  */
1996 enum retro_sensor_action
1997 {
1998    RETRO_SENSOR_ACCELEROMETER_ENABLE = 0,
1999    RETRO_SENSOR_ACCELEROMETER_DISABLE,
2000    RETRO_SENSOR_GYROSCOPE_ENABLE,
2001    RETRO_SENSOR_GYROSCOPE_DISABLE,
2002    RETRO_SENSOR_ILLUMINANCE_ENABLE,
2003    RETRO_SENSOR_ILLUMINANCE_DISABLE,
2004 
2005    RETRO_SENSOR_DUMMY = INT_MAX
2006 };
2007 
2008 /* Id values for SENSOR types. */
2009 #define RETRO_SENSOR_ACCELEROMETER_X 0
2010 #define RETRO_SENSOR_ACCELEROMETER_Y 1
2011 #define RETRO_SENSOR_ACCELEROMETER_Z 2
2012 #define RETRO_SENSOR_GYROSCOPE_X 3
2013 #define RETRO_SENSOR_GYROSCOPE_Y 4
2014 #define RETRO_SENSOR_GYROSCOPE_Z 5
2015 #define RETRO_SENSOR_ILLUMINANCE 6
2016 
2017 typedef bool (RETRO_CALLCONV *retro_set_sensor_state_t)(unsigned port,
2018       enum retro_sensor_action action, unsigned rate);
2019 
2020 typedef float (RETRO_CALLCONV *retro_sensor_get_input_t)(unsigned port, unsigned id);
2021 
2022 struct retro_sensor_interface
2023 {
2024    retro_set_sensor_state_t set_sensor_state;
2025    retro_sensor_get_input_t get_sensor_input;
2026 };
2027 
2028 enum retro_camera_buffer
2029 {
2030    RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0,
2031    RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER,
2032 
2033    RETRO_CAMERA_BUFFER_DUMMY = INT_MAX
2034 };
2035 
2036 /* Starts the camera driver. Can only be called in retro_run(). */
2037 typedef bool (RETRO_CALLCONV *retro_camera_start_t)(void);
2038 
2039 /* Stops the camera driver. Can only be called in retro_run(). */
2040 typedef void (RETRO_CALLCONV *retro_camera_stop_t)(void);
2041 
2042 /* Callback which signals when the camera driver is initialized
2043  * and/or deinitialized.
2044  * retro_camera_start_t can be called in initialized callback.
2045  */
2046 typedef void (RETRO_CALLCONV *retro_camera_lifetime_status_t)(void);
2047 
2048 /* A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
2049  * Width, height and pitch are similar to retro_video_refresh_t.
2050  * First pixel is top-left origin.
2051  */
2052 typedef void (RETRO_CALLCONV *retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer,
2053       unsigned width, unsigned height, size_t pitch);
2054 
2055 /* A callback for when OpenGL textures are used.
2056  *
2057  * texture_id is a texture owned by camera driver.
2058  * Its state or content should be considered immutable, except for things like
2059  * texture filtering and clamping.
2060  *
2061  * texture_target is the texture target for the GL texture.
2062  * These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly
2063  * more depending on extensions.
2064  *
2065  * affine points to a packed 3x3 column-major matrix used to apply an affine
2066  * transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
2067  * After transform, normalized texture coord (0, 0) should be bottom-left
2068  * and (1, 1) should be top-right (or (width, height) for RECTANGLE).
2069  *
2070  * GL-specific typedefs are avoided here to avoid relying on gl.h in
2071  * the API definition.
2072  */
2073 typedef void (RETRO_CALLCONV *retro_camera_frame_opengl_texture_t)(unsigned texture_id,
2074       unsigned texture_target, const float *affine);
2075 
2076 struct retro_camera_callback
2077 {
2078    /* Set by libretro core.
2079     * Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER).
2080     */
2081    uint64_t caps;
2082 
2083    /* Desired resolution for camera. Is only used as a hint. */
2084    unsigned width;
2085    unsigned height;
2086 
2087    /* Set by frontend. */
2088    retro_camera_start_t start;
2089    retro_camera_stop_t stop;
2090 
2091    /* Set by libretro core if raw framebuffer callbacks will be used. */
2092    retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer;
2093 
2094    /* Set by libretro core if OpenGL texture callbacks will be used. */
2095    retro_camera_frame_opengl_texture_t frame_opengl_texture;
2096 
2097    /* Set by libretro core. Called after camera driver is initialized and
2098     * ready to be started.
2099     * Can be NULL, in which this callback is not called.
2100     */
2101    retro_camera_lifetime_status_t initialized;
2102 
2103    /* Set by libretro core. Called right before camera driver is
2104     * deinitialized.
2105     * Can be NULL, in which this callback is not called.
2106     */
2107    retro_camera_lifetime_status_t deinitialized;
2108 };
2109 
2110 /* Sets the interval of time and/or distance at which to update/poll
2111  * location-based data.
2112  *
2113  * To ensure compatibility with all location-based implementations,
2114  * values for both interval_ms and interval_distance should be provided.
2115  *
2116  * interval_ms is the interval expressed in milliseconds.
2117  * interval_distance is the distance interval expressed in meters.
2118  */
2119 typedef void (RETRO_CALLCONV *retro_location_set_interval_t)(unsigned interval_ms,
2120       unsigned interval_distance);
2121 
2122 /* Start location services. The device will start listening for changes to the
2123  * current location at regular intervals (which are defined with
2124  * retro_location_set_interval_t). */
2125 typedef bool (RETRO_CALLCONV *retro_location_start_t)(void);
2126 
2127 /* Stop location services. The device will stop listening for changes
2128  * to the current location. */
2129 typedef void (RETRO_CALLCONV *retro_location_stop_t)(void);
2130 
2131 /* Get the position of the current location. Will set parameters to
2132  * 0 if no new  location update has happened since the last time. */
2133 typedef bool (RETRO_CALLCONV *retro_location_get_position_t)(double *lat, double *lon,
2134       double *horiz_accuracy, double *vert_accuracy);
2135 
2136 /* Callback which signals when the location driver is initialized
2137  * and/or deinitialized.
2138  * retro_location_start_t can be called in initialized callback.
2139  */
2140 typedef void (RETRO_CALLCONV *retro_location_lifetime_status_t)(void);
2141 
2142 struct retro_location_callback
2143 {
2144    retro_location_start_t         start;
2145    retro_location_stop_t          stop;
2146    retro_location_get_position_t  get_position;
2147    retro_location_set_interval_t  set_interval;
2148 
2149    retro_location_lifetime_status_t initialized;
2150    retro_location_lifetime_status_t deinitialized;
2151 };
2152 
2153 enum retro_rumble_effect
2154 {
2155    RETRO_RUMBLE_STRONG = 0,
2156    RETRO_RUMBLE_WEAK = 1,
2157 
2158    RETRO_RUMBLE_DUMMY = INT_MAX
2159 };
2160 
2161 /* Sets rumble state for joypad plugged in port 'port'.
2162  * Rumble effects are controlled independently,
2163  * and setting e.g. strong rumble does not override weak rumble.
2164  * Strength has a range of [0, 0xffff].
2165  *
2166  * Returns true if rumble state request was honored.
2167  * Calling this before first retro_run() is likely to return false. */
2168 typedef bool (RETRO_CALLCONV *retro_set_rumble_state_t)(unsigned port,
2169       enum retro_rumble_effect effect, uint16_t strength);
2170 
2171 struct retro_rumble_interface
2172 {
2173    retro_set_rumble_state_t set_rumble_state;
2174 };
2175 
2176 /* Notifies libretro that audio data should be written. */
2177 typedef void (RETRO_CALLCONV *retro_audio_callback_t)(void);
2178 
2179 /* True: Audio driver in frontend is active, and callback is
2180  * expected to be called regularily.
2181  * False: Audio driver in frontend is paused or inactive.
2182  * Audio callback will not be called until set_state has been
2183  * called with true.
2184  * Initial state is false (inactive).
2185  */
2186 typedef void (RETRO_CALLCONV *retro_audio_set_state_callback_t)(bool enabled);
2187 
2188 struct retro_audio_callback
2189 {
2190    retro_audio_callback_t callback;
2191    retro_audio_set_state_callback_t set_state;
2192 };
2193 
2194 /* Notifies a libretro core of time spent since last invocation
2195  * of retro_run() in microseconds.
2196  *
2197  * It will be called right before retro_run() every frame.
2198  * The frontend can tamper with timing to support cases like
2199  * fast-forward, slow-motion and framestepping.
2200  *
2201  * In those scenarios the reference frame time value will be used. */
2202 typedef int64_t retro_usec_t;
2203 typedef void (RETRO_CALLCONV *retro_frame_time_callback_t)(retro_usec_t usec);
2204 struct retro_frame_time_callback
2205 {
2206    retro_frame_time_callback_t callback;
2207    /* Represents the time of one frame. It is computed as
2208     * 1000000 / fps, but the implementation will resolve the
2209     * rounding to ensure that framestepping, etc is exact. */
2210    retro_usec_t reference;
2211 };
2212 
2213 /* Pass this to retro_video_refresh_t if rendering to hardware.
2214  * Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
2215  * */
2216 #define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)
2217 
2218 /* Invalidates the current HW context.
2219  * Any GL state is lost, and must not be deinitialized explicitly.
2220  * If explicit deinitialization is desired by the libretro core,
2221  * it should implement context_destroy callback.
2222  * If called, all GPU resources must be reinitialized.
2223  * Usually called when frontend reinits video driver.
2224  * Also called first time video driver is initialized,
2225  * allowing libretro core to initialize resources.
2226  */
2227 typedef void (RETRO_CALLCONV *retro_hw_context_reset_t)(void);
2228 
2229 /* Gets current framebuffer which is to be rendered to.
2230  * Could change every frame potentially.
2231  */
2232 typedef uintptr_t (RETRO_CALLCONV *retro_hw_get_current_framebuffer_t)(void);
2233 
2234 /* Get a symbol from HW context. */
2235 typedef retro_proc_address_t (RETRO_CALLCONV *retro_hw_get_proc_address_t)(const char *sym);
2236 
2237 enum retro_hw_context_type
2238 {
2239    RETRO_HW_CONTEXT_NONE             = 0,
2240    /* OpenGL 2.x. Driver can choose to use latest compatibility context. */
2241    RETRO_HW_CONTEXT_OPENGL           = 1,
2242    /* OpenGL ES 2.0. */
2243    RETRO_HW_CONTEXT_OPENGLES2        = 2,
2244    /* Modern desktop core GL context. Use version_major/
2245     * version_minor fields to set GL version. */
2246    RETRO_HW_CONTEXT_OPENGL_CORE      = 3,
2247    /* OpenGL ES 3.0 */
2248    RETRO_HW_CONTEXT_OPENGLES3        = 4,
2249    /* OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3,
2250     * use the corresponding enums directly. */
2251    RETRO_HW_CONTEXT_OPENGLES_VERSION = 5,
2252 
2253    /* Vulkan, see RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE. */
2254    RETRO_HW_CONTEXT_VULKAN           = 6,
2255 
2256    /* Direct3D, set version_major to select the type of interface
2257     * returned by RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE */
2258    RETRO_HW_CONTEXT_DIRECT3D         = 7,
2259 
2260    RETRO_HW_CONTEXT_DUMMY = INT_MAX
2261 };
2262 
2263 struct retro_hw_render_callback
2264 {
2265    /* Which API to use. Set by libretro core. */
2266    enum retro_hw_context_type context_type;
2267 
2268    /* Called when a context has been created or when it has been reset.
2269     * An OpenGL context is only valid after context_reset() has been called.
2270     *
2271     * When context_reset is called, OpenGL resources in the libretro
2272     * implementation are guaranteed to be invalid.
2273     *
2274     * It is possible that context_reset is called multiple times during an
2275     * application lifecycle.
2276     * If context_reset is called without any notification (context_destroy),
2277     * the OpenGL context was lost and resources should just be recreated
2278     * without any attempt to "free" old resources.
2279     */
2280    retro_hw_context_reset_t context_reset;
2281 
2282    /* Set by frontend.
2283     * TODO: This is rather obsolete. The frontend should not
2284     * be providing preallocated framebuffers. */
2285    retro_hw_get_current_framebuffer_t get_current_framebuffer;
2286 
2287    /* Set by frontend.
2288     * Can return all relevant functions, including glClear on Windows. */
2289    retro_hw_get_proc_address_t get_proc_address;
2290 
2291    /* Set if render buffers should have depth component attached.
2292     * TODO: Obsolete. */
2293    bool depth;
2294 
2295    /* Set if stencil buffers should be attached.
2296     * TODO: Obsolete. */
2297    bool stencil;
2298 
2299    /* If depth and stencil are true, a packed 24/8 buffer will be added.
2300     * Only attaching stencil is invalid and will be ignored. */
2301 
2302    /* Use conventional bottom-left origin convention. If false,
2303     * standard libretro top-left origin semantics are used.
2304     * TODO: Move to GL specific interface. */
2305    bool bottom_left_origin;
2306 
2307    /* Major version number for core GL context or GLES 3.1+. */
2308    unsigned version_major;
2309 
2310    /* Minor version number for core GL context or GLES 3.1+. */
2311    unsigned version_minor;
2312 
2313    /* If this is true, the frontend will go very far to avoid
2314     * resetting context in scenarios like toggling fullscreen, etc.
2315     * TODO: Obsolete? Maybe frontend should just always assume this ...
2316     */
2317    bool cache_context;
2318 
2319    /* The reset callback might still be called in extreme situations
2320     * such as if the context is lost beyond recovery.
2321     *
2322     * For optimal stability, set this to false, and allow context to be
2323     * reset at any time.
2324     */
2325 
2326    /* A callback to be called before the context is destroyed in a
2327     * controlled way by the frontend. */
2328    retro_hw_context_reset_t context_destroy;
2329 
2330    /* OpenGL resources can be deinitialized cleanly at this step.
2331     * context_destroy can be set to NULL, in which resources will
2332     * just be destroyed without any notification.
2333     *
2334     * Even when context_destroy is non-NULL, it is possible that
2335     * context_reset is called without any destroy notification.
2336     * This happens if context is lost by external factors (such as
2337     * notified by GL_ARB_robustness).
2338     *
2339     * In this case, the context is assumed to be already dead,
2340     * and the libretro implementation must not try to free any OpenGL
2341     * resources in the subsequent context_reset.
2342     */
2343 
2344    /* Creates a debug context. */
2345    bool debug_context;
2346 };
2347 
2348 /* Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
2349  * Called by the frontend in response to keyboard events.
2350  * down is set if the key is being pressed, or false if it is being released.
2351  * keycode is the RETROK value of the char.
2352  * character is the text character of the pressed key. (UTF-32).
2353  * key_modifiers is a set of RETROKMOD values or'ed together.
2354  *
2355  * The pressed/keycode state can be indepedent of the character.
2356  * It is also possible that multiple characters are generated from a
2357  * single keypress.
2358  * Keycode events should be treated separately from character events.
2359  * However, when possible, the frontend should try to synchronize these.
2360  * If only a character is posted, keycode should be RETROK_UNKNOWN.
2361  *
2362  * Similarily if only a keycode event is generated with no corresponding
2363  * character, character should be 0.
2364  */
2365 typedef void (RETRO_CALLCONV *retro_keyboard_event_t)(bool down, unsigned keycode,
2366       uint32_t character, uint16_t key_modifiers);
2367 
2368 struct retro_keyboard_callback
2369 {
2370    retro_keyboard_event_t callback;
2371 };
2372 
2373 /* Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE &
2374  * RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE.
2375  * Should be set for implementations which can swap out multiple disk
2376  * images in runtime.
2377  *
2378  * If the implementation can do this automatically, it should strive to do so.
2379  * However, there are cases where the user must manually do so.
2380  *
2381  * Overview: To swap a disk image, eject the disk image with
2382  * set_eject_state(true).
2383  * Set the disk index with set_image_index(index). Insert the disk again
2384  * with set_eject_state(false).
2385  */
2386 
2387 /* If ejected is true, "ejects" the virtual disk tray.
2388  * When ejected, the disk image index can be set.
2389  */
2390 typedef bool (RETRO_CALLCONV *retro_set_eject_state_t)(bool ejected);
2391 
2392 /* Gets current eject state. The initial state is 'not ejected'. */
2393 typedef bool (RETRO_CALLCONV *retro_get_eject_state_t)(void);
2394 
2395 /* Gets current disk index. First disk is index 0.
2396  * If return value is >= get_num_images(), no disk is currently inserted.
2397  */
2398 typedef unsigned (RETRO_CALLCONV *retro_get_image_index_t)(void);
2399 
2400 /* Sets image index. Can only be called when disk is ejected.
2401  * The implementation supports setting "no disk" by using an
2402  * index >= get_num_images().
2403  */
2404 typedef bool (RETRO_CALLCONV *retro_set_image_index_t)(unsigned index);
2405 
2406 /* Gets total number of images which are available to use. */
2407 typedef unsigned (RETRO_CALLCONV *retro_get_num_images_t)(void);
2408 
2409 struct retro_game_info;
2410 
2411 /* Replaces the disk image associated with index.
2412  * Arguments to pass in info have same requirements as retro_load_game().
2413  * Virtual disk tray must be ejected when calling this.
2414  *
2415  * Replacing a disk image with info = NULL will remove the disk image
2416  * from the internal list.
2417  * As a result, calls to get_image_index() can change.
2418  *
2419  * E.g. replace_image_index(1, NULL), and previous get_image_index()
2420  * returned 4 before.
2421  * Index 1 will be removed, and the new index is 3.
2422  */
2423 typedef bool (RETRO_CALLCONV *retro_replace_image_index_t)(unsigned index,
2424       const struct retro_game_info *info);
2425 
2426 /* Adds a new valid index (get_num_images()) to the internal disk list.
2427  * This will increment subsequent return values from get_num_images() by 1.
2428  * This image index cannot be used until a disk image has been set
2429  * with replace_image_index. */
2430 typedef bool (RETRO_CALLCONV *retro_add_image_index_t)(void);
2431 
2432 /* Sets initial image to insert in drive when calling
2433  * core_load_game().
2434  * Since we cannot pass the initial index when loading
2435  * content (this would require a major API change), this
2436  * is set by the frontend *before* calling the core's
2437  * retro_load_game()/retro_load_game_special() implementation.
2438  * A core should therefore cache the index/path values and handle
2439  * them inside retro_load_game()/retro_load_game_special().
2440  * - If 'index' is invalid (index >= get_num_images()), the
2441  *   core should ignore the set value and instead use 0
2442  * - 'path' is used purely for error checking - i.e. when
2443  *   content is loaded, the core should verify that the
2444  *   disk specified by 'index' has the specified file path.
2445  *   This is to guard against auto selecting the wrong image
2446  *   if (for example) the user should modify an existing M3U
2447  *   playlist. We have to let the core handle this because
2448  *   set_initial_image() must be called before loading content,
2449  *   i.e. the frontend cannot access image paths in advance
2450  *   and thus cannot perform the error check itself.
2451  *   If set path and content path do not match, the core should
2452  *   ignore the set 'index' value and instead use 0
2453  * Returns 'false' if index or 'path' are invalid, or core
2454  * does not support this functionality
2455  */
2456 typedef bool (RETRO_CALLCONV *retro_set_initial_image_t)(unsigned index, const char *path);
2457 
2458 /* Fetches the path of the specified disk image file.
2459  * Returns 'false' if index is invalid (index >= get_num_images())
2460  * or path is otherwise unavailable.
2461  */
2462 typedef bool (RETRO_CALLCONV *retro_get_image_path_t)(unsigned index, char *path, size_t len);
2463 
2464 /* Fetches a core-provided 'label' for the specified disk
2465  * image file. In the simplest case this may be a file name
2466  * (without extension), but for cores with more complex
2467  * content requirements information may be provided to
2468  * facilitate user disk swapping - for example, a core
2469  * running floppy-disk-based content may uniquely label
2470  * save disks, data disks, level disks, etc. with names
2471  * corresponding to in-game disk change prompts (so the
2472  * frontend can provide better user guidance than a 'dumb'
2473  * disk index value).
2474  * Returns 'false' if index is invalid (index >= get_num_images())
2475  * or label is otherwise unavailable.
2476  */
2477 typedef bool (RETRO_CALLCONV *retro_get_image_label_t)(unsigned index, char *label, size_t len);
2478 
2479 struct retro_disk_control_callback
2480 {
2481    retro_set_eject_state_t set_eject_state;
2482    retro_get_eject_state_t get_eject_state;
2483 
2484    retro_get_image_index_t get_image_index;
2485    retro_set_image_index_t set_image_index;
2486    retro_get_num_images_t  get_num_images;
2487 
2488    retro_replace_image_index_t replace_image_index;
2489    retro_add_image_index_t add_image_index;
2490 };
2491 
2492 struct retro_disk_control_ext_callback
2493 {
2494    retro_set_eject_state_t set_eject_state;
2495    retro_get_eject_state_t get_eject_state;
2496 
2497    retro_get_image_index_t get_image_index;
2498    retro_set_image_index_t set_image_index;
2499    retro_get_num_images_t  get_num_images;
2500 
2501    retro_replace_image_index_t replace_image_index;
2502    retro_add_image_index_t add_image_index;
2503 
2504    /* NOTE: Frontend will only attempt to record/restore
2505     * last used disk index if both set_initial_image()
2506     * and get_image_path() are implemented */
2507    retro_set_initial_image_t set_initial_image; /* Optional - may be NULL */
2508 
2509    retro_get_image_path_t get_image_path;       /* Optional - may be NULL */
2510    retro_get_image_label_t get_image_label;     /* Optional - may be NULL */
2511 };
2512 
2513 enum retro_pixel_format
2514 {
2515    /* 0RGB1555, native endian.
2516     * 0 bit must be set to 0.
2517     * This pixel format is default for compatibility concerns only.
2518     * If a 15/16-bit pixel format is desired, consider using RGB565. */
2519    RETRO_PIXEL_FORMAT_0RGB1555 = 0,
2520 
2521    /* XRGB8888, native endian.
2522     * X bits are ignored. */
2523    RETRO_PIXEL_FORMAT_XRGB8888 = 1,
2524 
2525    /* RGB565, native endian.
2526     * This pixel format is the recommended format to use if a 15/16-bit
2527     * format is desired as it is the pixel format that is typically
2528     * available on a wide range of low-power devices.
2529     *
2530     * It is also natively supported in APIs like OpenGL ES. */
2531    RETRO_PIXEL_FORMAT_RGB565   = 2,
2532 
2533    /* Ensure sizeof() == sizeof(int). */
2534    RETRO_PIXEL_FORMAT_UNKNOWN  = INT_MAX
2535 };
2536 
2537 struct retro_message
2538 {
2539    const char *msg;        /* Message to be displayed. */
2540    unsigned    frames;     /* Duration in frames of message. */
2541 };
2542 
2543 enum retro_message_target
2544 {
2545    RETRO_MESSAGE_TARGET_ALL = 0,
2546    RETRO_MESSAGE_TARGET_OSD,
2547    RETRO_MESSAGE_TARGET_LOG
2548 };
2549 
2550 enum retro_message_type
2551 {
2552    RETRO_MESSAGE_TYPE_NOTIFICATION = 0,
2553    RETRO_MESSAGE_TYPE_NOTIFICATION_ALT,
2554    RETRO_MESSAGE_TYPE_STATUS,
2555    RETRO_MESSAGE_TYPE_PROGRESS
2556 };
2557 
2558 struct retro_message_ext
2559 {
2560    /* Message string to be displayed/logged */
2561    const char *msg;
2562    /* Duration (in ms) of message when targeting the OSD */
2563    unsigned duration;
2564    /* Message priority when targeting the OSD
2565     * > When multiple concurrent messages are sent to
2566     *   the frontend and the frontend does not have the
2567     *   capacity to display them all, messages with the
2568     *   *highest* priority value should be shown
2569     * > There is no upper limit to a message priority
2570     *   value (within the bounds of the unsigned data type)
2571     * > In the reference frontend (RetroArch), the same
2572     *   priority values are used for frontend-generated
2573     *   notifications, which are typically assigned values
2574     *   between 0 and 3 depending upon importance */
2575    unsigned priority;
2576    /* Message logging level (info, warn, error, etc.) */
2577    enum retro_log_level level;
2578    /* Message destination: OSD, logging interface or both */
2579    enum retro_message_target target;
2580    /* Message 'type' when targeting the OSD
2581     * > RETRO_MESSAGE_TYPE_NOTIFICATION: Specifies that a
2582     *   message should be handled in identical fashion to
2583     *   a standard frontend-generated notification
2584     * > RETRO_MESSAGE_TYPE_NOTIFICATION_ALT: Specifies that
2585     *   message is a notification that requires user attention
2586     *   or action, but that it should be displayed in a manner
2587     *   that differs from standard frontend-generated notifications.
2588     *   This would typically correspond to messages that should be
2589     *   displayed immediately (independently from any internal
2590     *   frontend message queue), and/or which should be visually
2591     *   distinguishable from frontend-generated notifications.
2592     *   For example, a core may wish to inform the user of
2593     *   information related to a disk-change event. It is
2594     *   expected that the frontend itself may provide a
2595     *   notification in this case; if the core sends a
2596     *   message of type RETRO_MESSAGE_TYPE_NOTIFICATION, an
2597     *   uncomfortable 'double-notification' may occur. A message
2598     *   of RETRO_MESSAGE_TYPE_NOTIFICATION_ALT should therefore
2599     *   be presented such that visual conflict with regular
2600     *   notifications does not occur
2601     * > RETRO_MESSAGE_TYPE_STATUS: Indicates that message
2602     *   is not a standard notification. This typically
2603     *   corresponds to 'status' indicators, such as a core's
2604     *   internal FPS, which are intended to be displayed
2605     *   either permanently while a core is running, or in
2606     *   a manner that does not suggest user attention or action
2607     *   is required. 'Status' type messages should therefore be
2608     *   displayed in a different on-screen location and in a manner
2609     *   easily distinguishable from both standard frontend-generated
2610     *   notifications and messages of type RETRO_MESSAGE_TYPE_NOTIFICATION_ALT
2611     * > RETRO_MESSAGE_TYPE_PROGRESS: Indicates that message reports
2612     *   the progress of an internal core task. For example, in cases
2613     *   where a core itself handles the loading of content from a file,
2614     *   this may correspond to the percentage of the file that has been
2615     *   read. Alternatively, an audio/video playback core may use a
2616     *   message of type RETRO_MESSAGE_TYPE_PROGRESS to display the current
2617     *   playback position as a percentage of the runtime. 'Progress' type
2618     *   messages should therefore be displayed as a literal progress bar,
2619     *   where:
2620     *   - 'retro_message_ext.msg' is the progress bar title/label
2621     *   - 'retro_message_ext.progress' determines the length of
2622     *     the progress bar
2623     * NOTE: Message type is a *hint*, and may be ignored
2624     * by the frontend. If a frontend lacks support for
2625     * displaying messages via alternate means than standard
2626     * frontend-generated notifications, it will treat *all*
2627     * messages as having the type RETRO_MESSAGE_TYPE_NOTIFICATION */
2628    enum retro_message_type type;
2629    /* Task progress when targeting the OSD and message is
2630     * of type RETRO_MESSAGE_TYPE_PROGRESS
2631     * > -1:    Unmetered/indeterminate
2632     * > 0-100: Current progress percentage
2633     * NOTE: Since message type is a hint, a frontend may ignore
2634     * progress values. Where relevant, a core should therefore
2635     * include progress percentage within the message string,
2636     * such that the message intent remains clear when displayed
2637     * as a standard frontend-generated notification */
2638    int8_t progress;
2639 };
2640 
2641 /* Describes how the libretro implementation maps a libretro input bind
2642  * to its internal input system through a human readable string.
2643  * This string can be used to better let a user configure input. */
2644 struct retro_input_descriptor
2645 {
2646    /* Associates given parameters with a description. */
2647    unsigned port;
2648    unsigned device;
2649    unsigned index;
2650    unsigned id;
2651 
2652    /* Human readable description for parameters.
2653     * The pointer must remain valid until
2654     * retro_unload_game() is called. */
2655    const char *description;
2656 };
2657 
2658 struct retro_system_info
2659 {
2660    /* All pointers are owned by libretro implementation, and pointers must
2661     * remain valid until retro_deinit() is called. */
2662 
2663    const char *library_name;      /* Descriptive name of library. Should not
2664                                    * contain any version numbers, etc. */
2665    const char *library_version;   /* Descriptive version of core. */
2666 
2667    const char *valid_extensions;  /* A string listing probably content
2668                                    * extensions the core will be able to
2669                                    * load, separated with pipe.
2670                                    * I.e. "bin|rom|iso".
2671                                    * Typically used for a GUI to filter
2672                                    * out extensions. */
2673 
2674    /* Libretro cores that need to have direct access to their content
2675     * files, including cores which use the path of the content files to
2676     * determine the paths of other files, should set need_fullpath to true.
2677     *
2678     * Cores should strive for setting need_fullpath to false,
2679     * as it allows the frontend to perform patching, etc.
2680     *
2681     * If need_fullpath is true and retro_load_game() is called:
2682     *    - retro_game_info::path is guaranteed to have a valid path
2683     *    - retro_game_info::data and retro_game_info::size are invalid
2684     *
2685     * If need_fullpath is false and retro_load_game() is called:
2686     *    - retro_game_info::path may be NULL
2687     *    - retro_game_info::data and retro_game_info::size are guaranteed
2688     *      to be valid
2689     *
2690     * See also:
2691     *    - RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY
2692     *    - RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY
2693     */
2694    bool        need_fullpath;
2695 
2696    /* If true, the frontend is not allowed to extract any archives before
2697     * loading the real content.
2698     * Necessary for certain libretro implementations that load games
2699     * from zipped archives. */
2700    bool        block_extract;
2701 };
2702 
2703 struct retro_game_geometry
2704 {
2705    unsigned base_width;    /* Nominal video width of game. */
2706    unsigned base_height;   /* Nominal video height of game. */
2707    unsigned max_width;     /* Maximum possible width of game. */
2708    unsigned max_height;    /* Maximum possible height of game. */
2709 
2710    float    aspect_ratio;  /* Nominal aspect ratio of game. If
2711                             * aspect_ratio is <= 0.0, an aspect ratio
2712                             * of base_width / base_height is assumed.
2713                             * A frontend could override this setting,
2714                             * if desired. */
2715 };
2716 
2717 struct retro_system_timing
2718 {
2719    double fps;             /* FPS of video content. */
2720    double sample_rate;     /* Sampling rate of audio. */
2721 };
2722 
2723 struct retro_system_av_info
2724 {
2725    struct retro_game_geometry geometry;
2726    struct retro_system_timing timing;
2727 };
2728 
2729 struct retro_variable
2730 {
2731    /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.
2732     * If NULL, obtains the complete environment string if more
2733     * complex parsing is necessary.
2734     * The environment string is formatted as key-value pairs
2735     * delimited by semicolons as so:
2736     * "key1=value1;key2=value2;..."
2737     */
2738    const char *key;
2739 
2740    /* Value to be obtained. If key does not exist, it is set to NULL. */
2741    const char *value;
2742 };
2743 
2744 struct retro_core_option_display
2745 {
2746    /* Variable to configure in RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY */
2747    const char *key;
2748 
2749    /* Specifies whether variable should be displayed
2750     * when presenting core options to the user */
2751    bool visible;
2752 };
2753 
2754 /* Maximum number of values permitted for a core option
2755  * > Note: We have to set a maximum value due the limitations
2756  *   of the C language - i.e. it is not possible to create an
2757  *   array of structs each containing a variable sized array,
2758  *   so the retro_core_option_definition values array must
2759  *   have a fixed size. The size limit of 128 is a balancing
2760  *   act - it needs to be large enough to support all 'sane'
2761  *   core options, but setting it too large may impact low memory
2762  *   platforms. In practise, if a core option has more than
2763  *   128 values then the implementation is likely flawed.
2764  *   To quote the above API reference:
2765  *      "The number of possible options should be very limited
2766  *       i.e. it should be feasible to cycle through options
2767  *       without a keyboard."
2768  */
2769 #define RETRO_NUM_CORE_OPTION_VALUES_MAX 128
2770 
2771 struct retro_core_option_value
2772 {
2773    /* Expected option value */
2774    const char *value;
2775 
2776    /* Human-readable value label. If NULL, value itself
2777     * will be displayed by the frontend */
2778    const char *label;
2779 };
2780 
2781 struct retro_core_option_definition
2782 {
2783    /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE. */
2784    const char *key;
2785 
2786    /* Human-readable core option description (used as menu label) */
2787    const char *desc;
2788 
2789    /* Human-readable core option information (used as menu sublabel) */
2790    const char *info;
2791 
2792    /* Array of retro_core_option_value structs, terminated by NULL */
2793    struct retro_core_option_value values[RETRO_NUM_CORE_OPTION_VALUES_MAX];
2794 
2795    /* Default core option value. Must match one of the values
2796     * in the retro_core_option_value array, otherwise will be
2797     * ignored */
2798    const char *default_value;
2799 };
2800 
2801 struct retro_core_options_intl
2802 {
2803    /* Pointer to an array of retro_core_option_definition structs
2804     * - US English implementation
2805     * - Must point to a valid array */
2806    struct retro_core_option_definition *us;
2807 
2808    /* Pointer to an array of retro_core_option_definition structs
2809     * - Implementation for current frontend language
2810     * - May be NULL */
2811    struct retro_core_option_definition *local;
2812 };
2813 
2814 struct retro_game_info
2815 {
2816    const char *path;       /* Path to game, UTF-8 encoded.
2817                             * Sometimes used as a reference for building other paths.
2818                             * May be NULL if game was loaded from stdin or similar,
2819                             * but in this case some cores will be unable to load `data`.
2820                             * So, it is preferable to fabricate something here instead
2821                             * of passing NULL, which will help more cores to succeed.
2822                             * retro_system_info::need_fullpath requires
2823                             * that this path is valid. */
2824    const void *data;       /* Memory buffer of loaded game. Will be NULL
2825                             * if need_fullpath was set. */
2826    size_t      size;       /* Size of memory buffer. */
2827    const char *meta;       /* String of implementation specific meta-data. */
2828 };
2829 
2830 #define RETRO_MEMORY_ACCESS_WRITE (1 << 0)
2831    /* The core will write to the buffer provided by retro_framebuffer::data. */
2832 #define RETRO_MEMORY_ACCESS_READ (1 << 1)
2833    /* The core will read from retro_framebuffer::data. */
2834 #define RETRO_MEMORY_TYPE_CACHED (1 << 0)
2835    /* The memory in data is cached.
2836     * If not cached, random writes and/or reading from the buffer is expected to be very slow. */
2837 struct retro_framebuffer
2838 {
2839    void *data;                      /* The framebuffer which the core can render into.
2840                                        Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER.
2841                                        The initial contents of data are unspecified. */
2842    unsigned width;                  /* The framebuffer width used by the core. Set by core. */
2843    unsigned height;                 /* The framebuffer height used by the core. Set by core. */
2844    size_t pitch;                    /* The number of bytes between the beginning of a scanline,
2845                                        and beginning of the next scanline.
2846                                        Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */
2847    enum retro_pixel_format format;  /* The pixel format the core must use to render into data.
2848                                        This format could differ from the format used in
2849                                        SET_PIXEL_FORMAT.
2850                                        Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */
2851 
2852    unsigned access_flags;           /* How the core will access the memory in the framebuffer.
2853                                        RETRO_MEMORY_ACCESS_* flags.
2854                                        Set by core. */
2855    unsigned memory_flags;           /* Flags telling core how the memory has been mapped.
2856                                        RETRO_MEMORY_TYPE_* flags.
2857                                        Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */
2858 };
2859 
2860 /* Callbacks */
2861 
2862 /* Environment callback. Gives implementations a way of performing
2863  * uncommon tasks. Extensible. */
2864 typedef bool (RETRO_CALLCONV *retro_environment_t)(unsigned cmd, void *data);
2865 
2866 /* Render a frame. Pixel format is 15-bit 0RGB1555 native endian
2867  * unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
2868  *
2869  * Width and height specify dimensions of buffer.
2870  * Pitch specifices length in bytes between two lines in buffer.
2871  *
2872  * For performance reasons, it is highly recommended to have a frame
2873  * that is packed in memory, i.e. pitch == width * byte_per_pixel.
2874  * Certain graphic APIs, such as OpenGL ES, do not like textures
2875  * that are not packed in memory.
2876  */
2877 typedef void (RETRO_CALLCONV *retro_video_refresh_t)(const void *data, unsigned width,
2878       unsigned height, size_t pitch);
2879 
2880 /* Renders a single audio frame. Should only be used if implementation
2881  * generates a single sample at a time.
2882  * Format is signed 16-bit native endian.
2883  */
2884 typedef void (RETRO_CALLCONV *retro_audio_sample_t)(int16_t left, int16_t right);
2885 
2886 /* Renders multiple audio frames in one go.
2887  *
2888  * One frame is defined as a sample of left and right channels, interleaved.
2889  * I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
2890  * Only one of the audio callbacks must ever be used.
2891  */
2892 typedef size_t (RETRO_CALLCONV *retro_audio_sample_batch_t)(const int16_t *data,
2893       size_t frames);
2894 
2895 /* Polls input. */
2896 typedef void (RETRO_CALLCONV *retro_input_poll_t)(void);
2897 
2898 /* Queries for input for player 'port'. device will be masked with
2899  * RETRO_DEVICE_MASK.
2900  *
2901  * Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that
2902  * have been set with retro_set_controller_port_device()
2903  * will still use the higher level RETRO_DEVICE_JOYPAD to request input.
2904  */
2905 typedef int16_t (RETRO_CALLCONV *retro_input_state_t)(unsigned port, unsigned device,
2906       unsigned index, unsigned id);
2907 
2908 /* Sets callbacks. retro_set_environment() is guaranteed to be called
2909  * before retro_init().
2910  *
2911  * The rest of the set_* functions are guaranteed to have been called
2912  * before the first call to retro_run() is made. */
2913 RETRO_API void retro_set_environment(retro_environment_t);
2914 RETRO_API void retro_set_video_refresh(retro_video_refresh_t);
2915 RETRO_API void retro_set_audio_sample(retro_audio_sample_t);
2916 RETRO_API void retro_set_audio_sample_batch(retro_audio_sample_batch_t);
2917 RETRO_API void retro_set_input_poll(retro_input_poll_t);
2918 RETRO_API void retro_set_input_state(retro_input_state_t);
2919 
2920 /* Library global initialization/deinitialization. */
2921 RETRO_API void retro_init(void);
2922 RETRO_API void retro_deinit(void);
2923 
2924 /* Must return RETRO_API_VERSION. Used to validate ABI compatibility
2925  * when the API is revised. */
2926 RETRO_API unsigned retro_api_version(void);
2927 
2928 /* Gets statically known system info. Pointers provided in *info
2929  * must be statically allocated.
2930  * Can be called at any time, even before retro_init(). */
2931 RETRO_API void retro_get_system_info(struct retro_system_info *info);
2932 
2933 /* Gets information about system audio/video timings and geometry.
2934  * Can be called only after retro_load_game() has successfully completed.
2935  * NOTE: The implementation of this function might not initialize every
2936  * variable if needed.
2937  * E.g. geom.aspect_ratio might not be initialized if core doesn't
2938  * desire a particular aspect ratio. */
2939 RETRO_API void retro_get_system_av_info(struct retro_system_av_info *info);
2940 
2941 /* Sets device to be used for player 'port'.
2942  * By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all
2943  * available ports.
2944  * Setting a particular device type is not a guarantee that libretro cores
2945  * will only poll input based on that particular device type. It is only a
2946  * hint to the libretro core when a core cannot automatically detect the
2947  * appropriate input device type on its own. It is also relevant when a
2948  * core can change its behavior depending on device type.
2949  *
2950  * As part of the core's implementation of retro_set_controller_port_device,
2951  * the core should call RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS to notify the
2952  * frontend if the descriptions for any controls have changed as a
2953  * result of changing the device type.
2954  */
2955 RETRO_API void retro_set_controller_port_device(unsigned port, unsigned device);
2956 
2957 /* Resets the current game. */
2958 RETRO_API void retro_reset(void);
2959 
2960 /* Runs the game for one video frame.
2961  * During retro_run(), input_poll callback must be called at least once.
2962  *
2963  * If a frame is not rendered for reasons where a game "dropped" a frame,
2964  * this still counts as a frame, and retro_run() should explicitly dupe
2965  * a frame if GET_CAN_DUPE returns true.
2966  * In this case, the video callback can take a NULL argument for data.
2967  */
2968 RETRO_API void retro_run(void);
2969 
2970 /* Returns the amount of data the implementation requires to serialize
2971  * internal state (save states).
2972  * Between calls to retro_load_game() and retro_unload_game(), the
2973  * returned size is never allowed to be larger than a previous returned
2974  * value, to ensure that the frontend can allocate a save state buffer once.
2975  */
2976 RETRO_API size_t retro_serialize_size(void);
2977 
2978 /* Serializes internal state. If failed, or size is lower than
2979  * retro_serialize_size(), it should return false, true otherwise. */
2980 RETRO_API bool retro_serialize(void *data, size_t size);
2981 RETRO_API bool retro_unserialize(const void *data, size_t size);
2982 
2983 RETRO_API void retro_cheat_reset(void);
2984 RETRO_API void retro_cheat_set(unsigned index, bool enabled, const char *code);
2985 
2986 /* Loads a game.
2987  * Return true to indicate successful loading and false to indicate load failure.
2988  */
2989 RETRO_API bool retro_load_game(const struct retro_game_info *game);
2990 
2991 /* Loads a "special" kind of game. Should not be used,
2992  * except in extreme cases. */
2993 RETRO_API bool retro_load_game_special(
2994   unsigned game_type,
2995   const struct retro_game_info *info, size_t num_info
2996 );
2997 
2998 /* Unloads the currently loaded game. Called before retro_deinit(void). */
2999 RETRO_API void retro_unload_game(void);
3000 
3001 /* Gets region of game. */
3002 RETRO_API unsigned retro_get_region(void);
3003 
3004 /* Gets region of memory. */
3005 RETRO_API void *retro_get_memory_data(unsigned id);
3006 RETRO_API size_t retro_get_memory_size(unsigned id);
3007 
3008 #ifdef __cplusplus
3009 }
3010 #endif
3011 
3012 #endif
3013