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