HLE: Merge HLE BIOS improvements from upstream
[pcsx_rearmed.git] / frontend / libretro.h
CommitLineData
6fbd15c8 1/* Copyright (C) 2010-2018 The RetroArch team
779692e4 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
38c2028e 23#ifndef LIBRETRO_H__
24#define LIBRETRO_H__
25
26#include <stdint.h>
27#include <stddef.h>
c19aba43 28#include <limits.h>
38c2028e 29
30#ifdef __cplusplus
31extern "C" {
eae1ae02
A
32#endif
33
34#ifndef __cplusplus
6fbd15c8 35#if defined(_MSC_VER) && _MSC_VER < 1800 && !defined(SN_TARGET_PS3)
eae1ae02
A
36/* Hack applied for MSVC when compiling in C89 mode
37 * as it isn't C99-compliant. */
38c2028e 38#define bool unsigned char
39#define true 1
40#define false 0
41#else
42#include <stdbool.h>
43#endif
44#endif
45
65a0505f
FJGG
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
6fbd15c8 80/* Used for checking API/ABI mismatches that can break libretro
eae1ae02
A
81 * implementations.
82 * It is not incremented for compatible changes to the API.
83 */
38c2028e 84#define RETRO_API_VERSION 1
85
eae1ae02
A
86/*
87 * Libretro's fundamental device abstractions.
88 *
89 * Libretro's input system consists of some standardized device types,
6fbd15c8 90 * such as a joypad (with/without analog), mouse, keyboard, lightgun
eae1ae02
A
91 * and a pointer.
92 *
6fbd15c8 93 * The functionality of these devices are fixed, and individual cores
eae1ae02 94 * map their own concept of a controller to libretro's abstractions.
6fbd15c8 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
eae1ae02
A
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. */
38c2028e 105#define RETRO_DEVICE_NONE 0
c19aba43 106
6fbd15c8 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
eae1ae02 109 * PS1 DualShock. */
38c2028e 110#define RETRO_DEVICE_JOYPAD 1
c19aba43 111
eae1ae02
A
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).
6fbd15c8 114 * It is up to the libretro implementation to keep track of where the mouse
eae1ae02 115 * pointer is supposed to be on the screen.
6fbd15c8 116 * The frontend must make sure not to interfere with its own hardware
eae1ae02
A
117 * mouse pointer.
118 */
38c2028e 119#define RETRO_DEVICE_MOUSE 2
c19aba43 120
eae1ae02 121/* KEYBOARD device lets one poll for raw key pressed.
6fbd15c8 122 * It is poll based, so input callback will return with the current
eae1ae02
A
123 * pressed state.
124 * For event/text based keyboard input, see
125 * RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
126 */
38c2028e 127#define RETRO_DEVICE_KEYBOARD 3
c19aba43 128
6fbd15c8 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 */
38c2028e 138#define RETRO_DEVICE_LIGHTGUN 4
c19aba43 139
eae1ae02 140/* The ANALOG device is an extension to JOYPAD (RetroPad).
6fbd15c8 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.
eae1ae02 148 */
38c2028e 149#define RETRO_DEVICE_ANALOG 5
150
eae1ae02 151/* Abstracts the concept of a pointing mechanism, e.g. touch.
6fbd15c8 152 * This allows libretro to query in absolute coordinates where on the
eae1ae02
A
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.
6fbd15c8 160 * The "screen" is here defined as area that is passed to the frontend and
eae1ae02
A
161 * later displayed on the monitor.
162 *
163 * The frontend is free to scale/resize this screen as it sees fit, however,
6fbd15c8 164 * (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the
eae1ae02
A
165 * game image, etc.
166 *
6fbd15c8 167 * To check if the pointer coordinates are valid (e.g. a touch display
eae1ae02
A
168 * actually being touched), PRESSED returns 1 or 0.
169 *
6fbd15c8 170 * If using a mouse on a desktop, PRESSED will usually correspond to the
eae1ae02
A
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 *
6fbd15c8 174 * For multi-touch, the index variable can be used to successively query
eae1ae02
A
175 * more presses.
176 * If index = 0 returns true for _PRESSED, coordinates can be extracted
6fbd15c8 177 * with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with
eae1ae02 178 * index = 1, and so on.
6fbd15c8 179 * Eventually _PRESSED will return false for an index. No further presses
eae1ae02 180 * are registered at this point. */
23ea11bd 181#define RETRO_DEVICE_POINTER 6
182
eae1ae02 183/* Buttons for the RetroPad (JOYPAD).
6fbd15c8 184 * The placement of these is equivalent to placements on the
eae1ae02 185 * Super Nintendo controller.
6fbd15c8 186 * L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
187 * Also used as id values for RETRO_DEVICE_INDEX_ANALOG_BUTTON */
38c2028e 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
6fbd15c8 205#define RETRO_DEVICE_ID_JOYPAD_MASK 256
206
eae1ae02 207/* Index / Id values for ANALOG device. */
6fbd15c8 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
38c2028e 213
eae1ae02 214/* Id values for MOUSE. */
65a0505f
FJGG
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
6fbd15c8 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*/
38c2028e 248
eae1ae02 249/* Id values for POINTER. */
23ea11bd 250#define RETRO_DEVICE_ID_POINTER_X 0
251#define RETRO_DEVICE_ID_POINTER_Y 1
252#define RETRO_DEVICE_ID_POINTER_PRESSED 2
6fbd15c8 253#define RETRO_DEVICE_ID_POINTER_COUNT 3
23ea11bd 254
eae1ae02 255/* Returned from retro_get_region(). */
38c2028e 256#define RETRO_REGION_NTSC 0
257#define RETRO_REGION_PAL 1
258
eae1ae02
A
259/* Id values for LANGUAGE */
260enum retro_language
261{
6fbd15c8 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,
eae1ae02
A
281 RETRO_LANGUAGE_LAST,
282
283 /* Ensure sizeof(enum) == sizeof(int) */
6fbd15c8 284 RETRO_LANGUAGE_DUMMY = INT_MAX
eae1ae02
A
285};
286
287/* Passed to retro_get_memory_data/size().
6fbd15c8 288 * If the memory type doesn't apply to the
eae1ae02
A
289 * implementation NULL/0 can be returned.
290 */
38c2028e 291#define RETRO_MEMORY_MASK 0xff
c19aba43 292
eae1ae02
A
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. */
38c2028e 298#define RETRO_MEMORY_SAVE_RAM 0
c19aba43 299
eae1ae02
A
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 */
38c2028e 303#define RETRO_MEMORY_RTC 1
c19aba43 304
eae1ae02 305/* System ram lets a frontend peek into a game systems main RAM. */
38c2028e 306#define RETRO_MEMORY_SYSTEM_RAM 2
c19aba43 307
eae1ae02 308/* Video ram lets a frontend peek into a game systems video RAM (VRAM). */
38c2028e 309#define RETRO_MEMORY_VIDEO_RAM 3
310
eae1ae02 311/* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */
c19aba43
TK
312enum 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,
6fbd15c8 386 RETROK_LEFTBRACE = 123,
387 RETROK_BAR = 124,
388 RETROK_RIGHTBRACE = 125,
389 RETROK_TILDE = 126,
c19aba43
TK
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,
6fbd15c8 460 RETROK_OEM_102 = 323,
c19aba43 461
23ea11bd 462 RETROK_LAST,
463
eae1ae02 464 RETROK_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
23ea11bd 465};
466
467enum 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
eae1ae02 480 RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */
c19aba43 481};
38c2028e 482
6fbd15c8 483/* If set, this call is not part of the public libretro API yet. It can
eae1ae02 484 * change or be removed at any time. */
e56b1300 485#define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000
eae1ae02 486/* Environment callback to be used internally in frontend. */
779692e4 487#define RETRO_ENVIRONMENT_PRIVATE 0x20000
23ea11bd 488
eae1ae02
A
489/* Environment commands. */
490#define RETRO_ENVIRONMENT_SET_ROTATION 1 /* const unsigned * --
491 * Sets screen rotation of graphics.
6fbd15c8 492 * Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180,
eae1ae02
A
493 * 270 degrees counter-clockwise respectively.
494 */
495#define RETRO_ENVIRONMENT_GET_OVERSCAN 2 /* bool * --
6fbd15c8 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,
eae1ae02
A
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
6fbd15c8 507 /* Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES),
eae1ae02
A
508 * and reserved to avoid possible ABI clash.
509 */
510
511#define RETRO_ENVIRONMENT_SET_MESSAGE 6 /* const struct retro_message * --
6fbd15c8 512 * Sets a message to be displayed in implementation-specific manner
eae1ae02 513 * for a certain amount of 'frames'.
6fbd15c8 514 * Should not be used for trivial messages, which should simply be
515 * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a
eae1ae02
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 */
38c2028e 523#define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8
eae1ae02
A
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 */
38c2028e 540#define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
eae1ae02
A
541 /* const char ** --
542 * Returns the "system" directory of the frontend.
6fbd15c8 543 * This directory can be used to store system specific
eae1ae02
A
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 *
6fbd15c8 549 * NOTE: Some cores used this folder also for "save" data such as
eae1ae02 550 * memory cards, etc, for lack of a better place to put it.
6fbd15c8 551 * This is now discouraged, and if possible, cores should try to
eae1ae02
A
552 * use the new GET_SAVE_DIRECTORY.
553 */
38c2028e 554#define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
eae1ae02
A
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).
6fbd15c8 559 * If the call returns false, the frontend does not support this pixel
eae1ae02
A
560 * format.
561 *
6fbd15c8 562 * This function should be called inside retro_load_game() or
eae1ae02
A
563 * retro_get_system_av_info().
564 */
c19aba43 565#define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11
eae1ae02
A
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.
6fbd15c8 569 * The array is terminated by retro_input_descriptor::description
eae1ae02 570 * being set to NULL.
6fbd15c8 571 * This function can be called at any time, but it is recommended
eae1ae02
A
572 * to call it as early as possible.
573 */
23ea11bd 574#define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12
eae1ae02
A
575 /* const struct retro_keyboard_callback * --
576 * Sets a callback function used to notify core about keyboard events.
577 */
23ea11bd 578#define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13
eae1ae02 579 /* const struct retro_disk_control_callback * --
6fbd15c8 580 * Sets an interface which frontend can use to eject and insert
eae1ae02 581 * disk images.
6fbd15c8 582 * This is used for games which consist of multiple images and
eae1ae02
A
583 * must be manually swapped out by the user (e.g. PSX).
584 */
779692e4 585#define RETRO_ENVIRONMENT_SET_HW_RENDER 14
eae1ae02 586 /* struct retro_hw_render_callback * --
6fbd15c8 587 * Sets an interface to let a libretro core render with
eae1ae02
A
588 * hardware acceleration.
589 * Should be called in retro_load_game().
6fbd15c8 590 * If successful, libretro cores will be able to render to a
eae1ae02 591 * frontend-provided framebuffer.
6fbd15c8 592 * The size of this framebuffer will be at least as large as
eae1ae02 593 * max_width/max_height provided in get_av_info().
6fbd15c8 594 * If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or
eae1ae02
A
595 * NULL to retro_video_refresh_t.
596 */
e56b1300 597#define RETRO_ENVIRONMENT_GET_VARIABLE 15
eae1ae02
A
598 /* struct retro_variable * --
599 * Interface to acquire user-defined information from environment
600 * that cannot feasibly be supported in a multi-system way.
6fbd15c8 601 * 'key' should be set to a key which has already been set by
eae1ae02
A
602 * SET_VARIABLES.
603 * 'data' will be set to a value or NULL.
604 */
e56b1300 605#define RETRO_ENVIRONMENT_SET_VARIABLES 16
eae1ae02
A
606 /* const struct retro_variable * --
607 * Allows an implementation to signal the environment
6fbd15c8 608 * which variables it might want to check for later using
eae1ae02 609 * GET_VARIABLE.
6fbd15c8 610 * This allows the frontend to present these variables to
eae1ae02 611 * a user dynamically.
6fbd15c8 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
eae1ae02 619 * terminated by a { NULL, NULL } element.
6fbd15c8 620 * retro_variable::key should be namespaced to not collide
621 * with other implementations' keys. E.g. A core called
eae1ae02 622 * 'foo' should use keys named as 'foo_option'.
6fbd15c8 623 * retro_variable::value should contain a human readable
624 * description of the key as well as a '|' delimited list
eae1ae02
A
625 * of expected values.
626 *
6fbd15c8 627 * The number of possible options should be very limited,
628 * i.e. it should be feasible to cycle through options
eae1ae02
A
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 *
6fbd15c8 636 * Text before first ';' is description. This ';' must be
637 * followed by a space, and followed by a list of possible
eae1ae02
A
638 * values split up with '|'.
639 *
6fbd15c8 640 * Only strings are operated on. The possible values will
eae1ae02
A
641 * generally be displayed and stored as-is by the frontend.
642 */
e56b1300 643#define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17
eae1ae02
A
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 */
6b5beb44 649#define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18
eae1ae02 650 /* const bool * --
6fbd15c8 651 * If true, the libretro implementation supports calls to
eae1ae02
A
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 */
779692e4 656#define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19
eae1ae02 657 /* const char ** --
6fbd15c8 658 * Retrieves the absolute path from where this libretro
eae1ae02 659 * implementation was loaded.
6fbd15c8 660 * NULL is returned if the libretro was loaded statically
661 * (i.e. linked statically to frontend), or if the path cannot be
eae1ae02 662 * determined.
6fbd15c8 663 * Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can
eae1ae02
A
664 * be loaded without ugly hacks.
665 */
6fbd15c8 666
667 /* Environment 20 was an obsolete version of SET_AUDIO_CALLBACK.
eae1ae02
A
668 * It was not used by any known core at the time,
669 * and was removed from the API. */
6fbd15c8 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 */
779692e4 679#define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22
eae1ae02 680 /* const struct retro_audio_callback * --
6fbd15c8 681 * Sets an interface which is used to notify a libretro core about audio
eae1ae02 682 * being available for writing.
6fbd15c8 683 * The callback can be called from any thread, so a core using this must
eae1ae02 684 * have a thread safe audio implementation.
6fbd15c8 685 * It is intended for games where audio and video are completely
eae1ae02 686 * asynchronous and audio can be generated on the fly.
6fbd15c8 687 * This interface is not recommended for use with emulators which have
eae1ae02
A
688 * highly synchronous audio.
689 *
6fbd15c8 690 * The callback only notifies about writability; the libretro core still
eae1ae02 691 * has to call the normal audio callbacks
6fbd15c8 692 * to write audio. The audio callbacks must be called from within the
eae1ae02
A
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 *
6fbd15c8 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
eae1ae02
A
700 * implement the "normal" audio interface.
701 *
6fbd15c8 702 * A libretro core using SET_AUDIO_CALLBACK should also make use of
eae1ae02
A
703 * SET_FRAME_TIME_CALLBACK.
704 */
779692e4 705#define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23
eae1ae02 706 /* struct retro_rumble_interface * --
6fbd15c8 707 * Gets an interface which is used by a libretro core to set
eae1ae02 708 * state of rumble motors in controllers.
6fbd15c8 709 * A strong and weak motor is supported, and they can be
eae1ae02
A
710 * controlled indepedently.
711 */
779692e4 712#define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24
eae1ae02 713 /* uint64_t * --
6fbd15c8 714 * Gets a bitmask telling which device type are expected to be
eae1ae02 715 * handled properly in a call to retro_input_state_t.
6fbd15c8 716 * Devices which are not handled or recognized always return
eae1ae02
A
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 */
779692e4 721#define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL)
eae1ae02
A
722 /* struct retro_sensor_interface * --
723 * Gets access to the sensor interface.
724 * The purpose of this interface is to allow
6fbd15c8 725 * setting state related to sensors such as polling rate,
eae1ae02 726 * enabling/disable it entirely, etc.
6fbd15c8 727 * Reading sensor state is done via the normal
eae1ae02
A
728 * input_state_callback API.
729 */
779692e4 730#define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL)
eae1ae02
A
731 /* struct retro_camera_callback * --
732 * Gets an interface to a video camera driver.
6fbd15c8 733 * A libretro core can use this interface to get access to a
eae1ae02 734 * video camera.
6fbd15c8 735 * New video frames are delivered in a callback in same
eae1ae02
A
736 * thread as retro_run().
737 *
738 * GET_CAMERA_INTERFACE should be called in retro_load_game().
739 *
6fbd15c8 740 * Depending on the camera implementation used, camera frames
eae1ae02
A
741 * will be delivered as a raw framebuffer,
742 * or as an OpenGL texture directly.
743 *
6fbd15c8 744 * The core has to tell the frontend here which types of
eae1ae02 745 * buffers can be handled properly.
6fbd15c8 746 * An OpenGL texture can only be handled when using a
eae1ae02 747 * libretro GL core (SET_HW_RENDER).
6fbd15c8 748 * It is recommended to use a libretro GL core when
eae1ae02
A
749 * using camera interface.
750 *
6fbd15c8 751 * The camera is not started automatically. The retrieved start/stop
eae1ae02
A
752 * functions must be used to explicitly
753 * start and stop the camera driver.
754 */
779692e4 755#define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27
eae1ae02 756 /* struct retro_log_callback * --
6fbd15c8 757 * Gets an interface for logging. This is useful for
eae1ae02 758 * logging in a cross-platform way
6fbd15c8 759 * as certain platforms cannot use stderr for logging.
eae1ae02
A
760 * It also allows the frontend to
761 * show logging information in a more suitable way.
6fbd15c8 762 * If this interface is not used, libretro cores should
eae1ae02
A
763 * log to stderr as desired.
764 */
779692e4 765#define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28
eae1ae02 766 /* struct retro_perf_callback * --
6fbd15c8 767 * Gets an interface for performance counters. This is useful
768 * for performance logging in a cross-platform way and for detecting
eae1ae02
A
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.
6fbd15c8 774 * The purpose of this interface is to be able to retrieve
eae1ae02
A
775 * location-based information from the host device,
776 * such as current latitude / longitude.
777 */
65a0505f
FJGG
778#define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30 /* Old name, kept for compatibility. */
779#define RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY 30
eae1ae02 780 /* const char ** --
65a0505f 781 * Returns the "core assets" directory of the frontend.
6fbd15c8 782 * This directory can be used to store specific assets that the
eae1ae02
A
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 ** --
6fbd15c8 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
eae1ae02
A
794 * cannot use the regular memory interface (retro_get_memory_data()).
795 *
6fbd15c8 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.
eae1ae02
A
803 */
804#define RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO 32
805 /* const struct retro_system_av_info * --
6fbd15c8 806 * Sets a new av_info structure. This can only be called from
eae1ae02 807 * within retro_run().
6fbd15c8 808 * This should *only* be used if the core is completely altering the
eae1ae02 809 * internal resolutions, aspect ratios, timings, sampling rate, etc.
6fbd15c8 810 * Calling this can require a full reinitialization of video/audio
eae1ae02
A
811 * drivers in the frontend,
812 *
6fbd15c8 813 * so it is important to call it very sparingly, and usually only with
eae1ae02 814 * the users explicit consent.
6fbd15c8 815 * An eventual driver reinitialize will happen so that video and
eae1ae02 816 * audio callbacks
6fbd15c8 817 * happening after this call within the same retro_run() call will
eae1ae02
A
818 * target the newly initialized driver.
819 *
6fbd15c8 820 * This callback makes it possible to support configurable resolutions
eae1ae02
A
821 * in games, which can be useful to
822 * avoid setting the "worst case" in max_width/max_height.
823 *
6fbd15c8 824 * ***HIGHLY RECOMMENDED*** Do not call this callback every time
eae1ae02 825 * resolution changes in an emulator core if it's
6fbd15c8 826 * expected to be a temporary change, for the reasons of possible
eae1ae02 827 * driver reinitialization.
6fbd15c8 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
eae1ae02
A
832 * of SET_SYSTEM_AV_INFO.
833 *
6fbd15c8 834 * If this returns false, the frontend does not acknowledge a
eae1ae02
A
835 * changed av_info struct.
836 */
837#define RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK 33
838 /* const struct retro_get_proc_address_interface * --
6fbd15c8 839 * Allows a libretro core to announce support for the
eae1ae02 840 * get_proc_address() interface.
6fbd15c8 841 * This interface allows for a standard way to extend libretro where
eae1ae02
A
842 * use of environment calls are too indirect,
843 * e.g. for cases where the frontend wants to call directly into the core.
844 *
6fbd15c8 845 * If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK
eae1ae02
A
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".
6fbd15c8 851 * A subsystem is a variant of a libretro core which supports
eae1ae02 852 * different kinds of games.
6fbd15c8 853 * The purpose of this is to support e.g. emulators which might
eae1ae02 854 * have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo.
6fbd15c8 855 * It can also be used to pick among subsystems in an explicit way
eae1ae02
A
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(),
6fbd15c8 859 * and this environment call allows a libretro core to expose which
eae1ae02 860 * subsystems are supported for use with retro_load_game_special().
6fbd15c8 861 * A core passes an array of retro_game_special_info which is terminated
eae1ae02
A
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 * --
6fbd15c8 869 * This environment call lets a libretro core tell the frontend
870 * which controller subclasses are recognized in calls to
eae1ae02
A
871 * retro_set_controller_port_device().
872 *
6fbd15c8 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.
eae1ae02 878 *
6fbd15c8 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.
eae1ae02 882 *
6fbd15c8 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,
eae1ae02
A
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 * --
6fbd15c8 907 * This environment call lets a libretro core tell the frontend
eae1ae02
A
908 * about the memory maps this core emulates.
909 * This can be used to implement, for example, cheats in a core-agnostic way.
910 *
6fbd15c8 911 * Should only be used by emulators; it doesn't make much sense for
eae1ae02 912 * anything else.
6fbd15c8 913 * It is recommended to expose all relevant pointers through
eae1ae02
A
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 * --
6fbd15c8 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
eae1ae02
A
922 * reinitialized.
923 * This can only be called from within retro_run().
924 *
6fbd15c8 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
eae1ae02
A
927 * useful for some emulators to change in run-time.
928 *
929 * max_width/max_height arguments are ignored and cannot be changed
6fbd15c8 930 * with this call as this could potentially require a reinitialization or a
eae1ae02
A
931 * non-constant time operation.
932 * If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required.
933 *
6fbd15c8 934 * A frontend must guarantee that this environment call completes in
eae1ae02
A
935 * constant time.
936 */
6fbd15c8 937#define RETRO_ENVIRONMENT_GET_USERNAME 38
eae1ae02
A
938 /* const char **
939 * Returns the specified username of the frontend, if specified by the user.
6fbd15c8 940 * This username can be used as a nickname for a core that has online facilities
eae1ae02
A
941 * or any other mode where personalization of the user is desirable.
942 * The returned value can be NULL.
6fbd15c8 943 * If this environ callback is used by a core that requires a valid username,
eae1ae02
A
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 */
65a0505f
FJGG
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 */
6fbd15c8 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/* VFS functionality */
1110
1111/* File paths:
1112 * File paths passed as parameters when using this API shall be well formed UNIX-style,
1113 * using "/" (unquoted forward slash) as directory separator regardless of the platform's native separator.
1114 * Paths shall also include at least one forward slash ("game.bin" is an invalid path, use "./game.bin" instead).
1115 * Other than the directory separator, cores shall not make assumptions about path format:
1116 * "C:/path/game.bin", "http://example.com/game.bin", "#game/game.bin", "./game.bin" (without quotes) are all valid paths.
1117 * Cores may replace the basename or remove path components from the end, and/or add new components;
1118 * however, cores shall not append "./", "../" or multiple consecutive forward slashes ("//") to paths they request to front end.
1119 * 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.
1120 * Frontends are encouraged, but not required, to support native file system paths (modulo replacing the directory separator, if applicable).
1121 * Cores are allowed to try using them, but must remain functional if the front rejects such requests.
1122 * Cores are encouraged to use the libretro-common filestream functions for file I/O,
1123 * as they seamlessly integrate with VFS, deal with directory separator replacement as appropriate
1124 * and provide platform-specific fallbacks in cases where front ends do not support VFS. */
1125
1126/* Opaque file handle
1127 * Introduced in VFS API v1 */
1128struct retro_vfs_file_handle;
1129
1130/* Opaque directory handle
1131 * Introduced in VFS API v3 */
1132struct retro_vfs_dir_handle;
1133
1134/* File open flags
1135 * Introduced in VFS API v1 */
1136#define RETRO_VFS_FILE_ACCESS_READ (1 << 0) /* Read only mode */
1137#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 */
1138#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*/
1139#define RETRO_VFS_FILE_ACCESS_UPDATE_EXISTING (1 << 2) /* Prevents discarding content of existing files opened for writing */
1140
1141/* These are only hints. The frontend may choose to ignore them. Other than RAM/CPU/etc use,
1142 and how they react to unlikely external interference (for example someone else writing to that file,
1143 or the file's server going down), behavior will not change. */
1144#define RETRO_VFS_FILE_ACCESS_HINT_NONE (0)
1145/* Indicate that the file will be accessed many times. The frontend should aggressively cache everything. */
1146#define RETRO_VFS_FILE_ACCESS_HINT_FREQUENT_ACCESS (1 << 0)
1147
1148/* Seek positions */
1149#define RETRO_VFS_SEEK_POSITION_START 0
1150#define RETRO_VFS_SEEK_POSITION_CURRENT 1
1151#define RETRO_VFS_SEEK_POSITION_END 2
1152
1153/* stat() result flags
1154 * Introduced in VFS API v3 */
1155#define RETRO_VFS_STAT_IS_VALID (1 << 0)
1156#define RETRO_VFS_STAT_IS_DIRECTORY (1 << 1)
1157#define RETRO_VFS_STAT_IS_CHARACTER_SPECIAL (1 << 2)
1158
1159/* Get path from opaque handle. Returns the exact same path passed to file_open when getting the handle
1160 * Introduced in VFS API v1 */
1161typedef const char *(RETRO_CALLCONV *retro_vfs_get_path_t)(struct retro_vfs_file_handle *stream);
1162
1163/* Open a file for reading or writing. If path points to a directory, this will
1164 * fail. Returns the opaque file handle, or NULL for error.
1165 * Introduced in VFS API v1 */
1166typedef struct retro_vfs_file_handle *(RETRO_CALLCONV *retro_vfs_open_t)(const char *path, unsigned mode, unsigned hints);
1167
1168/* Close the file and release its resources. Must be called if open_file returns non-NULL. Returns 0 on success, -1 on failure.
1169 * Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
1170 * Introduced in VFS API v1 */
1171typedef int (RETRO_CALLCONV *retro_vfs_close_t)(struct retro_vfs_file_handle *stream);
1172
1173/* Return the size of the file in bytes, or -1 for error.
1174 * Introduced in VFS API v1 */
1175typedef int64_t (RETRO_CALLCONV *retro_vfs_size_t)(struct retro_vfs_file_handle *stream);
1176
1177/* Truncate file to specified size. Returns 0 on success or -1 on error
1178 * Introduced in VFS API v2 */
1179typedef int64_t (RETRO_CALLCONV *retro_vfs_truncate_t)(struct retro_vfs_file_handle *stream, int64_t length);
1180
1181/* Get the current read / write position for the file. Returns -1 for error.
1182 * Introduced in VFS API v1 */
1183typedef int64_t (RETRO_CALLCONV *retro_vfs_tell_t)(struct retro_vfs_file_handle *stream);
1184
1185/* Set the current read/write position for the file. Returns the new position, -1 for error.
1186 * Introduced in VFS API v1 */
1187typedef int64_t (RETRO_CALLCONV *retro_vfs_seek_t)(struct retro_vfs_file_handle *stream, int64_t offset, int seek_position);
1188
1189/* Read data from a file. Returns the number of bytes read, or -1 for error.
1190 * Introduced in VFS API v1 */
1191typedef int64_t (RETRO_CALLCONV *retro_vfs_read_t)(struct retro_vfs_file_handle *stream, void *s, uint64_t len);
1192
1193/* Write data to a file. Returns the number of bytes written, or -1 for error.
1194 * Introduced in VFS API v1 */
1195typedef int64_t (RETRO_CALLCONV *retro_vfs_write_t)(struct retro_vfs_file_handle *stream, const void *s, uint64_t len);
1196
1197/* Flush pending writes to file, if using buffered IO. Returns 0 on sucess, or -1 on failure.
1198 * Introduced in VFS API v1 */
1199typedef int (RETRO_CALLCONV *retro_vfs_flush_t)(struct retro_vfs_file_handle *stream);
1200
1201/* Delete the specified file. Returns 0 on success, -1 on failure
1202 * Introduced in VFS API v1 */
1203typedef int (RETRO_CALLCONV *retro_vfs_remove_t)(const char *path);
1204
1205/* Rename the specified file. Returns 0 on success, -1 on failure
1206 * Introduced in VFS API v1 */
1207typedef int (RETRO_CALLCONV *retro_vfs_rename_t)(const char *old_path, const char *new_path);
1208
1209/* Stat the specified file. Retruns a bitmask of RETRO_VFS_STAT_* flags, none are set if path was not valid.
1210 * Additionally stores file size in given variable, unless NULL is given.
1211 * Introduced in VFS API v3 */
1212typedef int (RETRO_CALLCONV *retro_vfs_stat_t)(const char *path, int32_t *size);
1213
1214/* Create the specified directory. Returns 0 on success, -1 on unknown failure, -2 if already exists.
1215 * Introduced in VFS API v3 */
1216typedef int (RETRO_CALLCONV *retro_vfs_mkdir_t)(const char *dir);
1217
1218/* Open the specified directory for listing. Returns the opaque dir handle, or NULL for error.
1219 * Support for the include_hidden argument may vary depending on the platform.
1220 * Introduced in VFS API v3 */
1221typedef struct retro_vfs_dir_handle *(RETRO_CALLCONV *retro_vfs_opendir_t)(const char *dir, bool include_hidden);
1222
1223/* Read the directory entry at the current position, and move the read pointer to the next position.
1224 * Returns true on success, false if already on the last entry.
1225 * Introduced in VFS API v3 */
1226typedef bool (RETRO_CALLCONV *retro_vfs_readdir_t)(struct retro_vfs_dir_handle *dirstream);
1227
1228/* Get the name of the last entry read. Returns a string on success, or NULL for error.
1229 * The returned string pointer is valid until the next call to readdir or closedir.
1230 * Introduced in VFS API v3 */
1231typedef const char *(RETRO_CALLCONV *retro_vfs_dirent_get_name_t)(struct retro_vfs_dir_handle *dirstream);
1232
1233/* Check if the last entry read was a directory. Returns true if it was, false otherwise (or on error).
1234 * Introduced in VFS API v3 */
1235typedef bool (RETRO_CALLCONV *retro_vfs_dirent_is_dir_t)(struct retro_vfs_dir_handle *dirstream);
1236
1237/* Close the directory and release its resources. Must be called if opendir returns non-NULL. Returns 0 on success, -1 on failure.
1238 * Whether the call succeeds ot not, the handle passed as parameter becomes invalid and should no longer be used.
1239 * Introduced in VFS API v3 */
1240typedef int (RETRO_CALLCONV *retro_vfs_closedir_t)(struct retro_vfs_dir_handle *dirstream);
1241
1242struct retro_vfs_interface
1243{
1244 /* VFS API v1 */
1245 retro_vfs_get_path_t get_path;
1246 retro_vfs_open_t open;
1247 retro_vfs_close_t close;
1248 retro_vfs_size_t size;
1249 retro_vfs_tell_t tell;
1250 retro_vfs_seek_t seek;
1251 retro_vfs_read_t read;
1252 retro_vfs_write_t write;
1253 retro_vfs_flush_t flush;
1254 retro_vfs_remove_t remove;
1255 retro_vfs_rename_t rename;
1256 /* VFS API v2 */
1257 retro_vfs_truncate_t truncate;
1258 /* VFS API v3 */
1259 retro_vfs_stat_t stat;
1260 retro_vfs_mkdir_t mkdir;
1261 retro_vfs_opendir_t opendir;
1262 retro_vfs_readdir_t readdir;
1263 retro_vfs_dirent_get_name_t dirent_get_name;
1264 retro_vfs_dirent_is_dir_t dirent_is_dir;
1265 retro_vfs_closedir_t closedir;
1266};
1267
1268struct retro_vfs_interface_info
1269{
1270 /* Set by core: should this be higher than the version the front end supports,
1271 * front end will return false in the RETRO_ENVIRONMENT_GET_VFS_INTERFACE call
1272 * Introduced in VFS API v1 */
1273 uint32_t required_interface_version;
1274
1275 /* Frontend writes interface pointer here. The frontend also sets the actual
1276 * version, must be at least required_interface_version.
1277 * Introduced in VFS API v1 */
1278 struct retro_vfs_interface *iface;
1279};
65a0505f
FJGG
1280
1281enum retro_hw_render_interface_type
1282{
6fbd15c8 1283 RETRO_HW_RENDER_INTERFACE_VULKAN = 0,
1284 RETRO_HW_RENDER_INTERFACE_D3D9 = 1,
1285 RETRO_HW_RENDER_INTERFACE_D3D10 = 2,
1286 RETRO_HW_RENDER_INTERFACE_D3D11 = 3,
1287 RETRO_HW_RENDER_INTERFACE_D3D12 = 4,
1288 RETRO_HW_RENDER_INTERFACE_GSKIT_PS2 = 5,
1289 RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX
65a0505f
FJGG
1290};
1291
1292/* Base struct. All retro_hw_render_interface_* types
1293 * contain at least these fields. */
1294struct retro_hw_render_interface
1295{
1296 enum retro_hw_render_interface_type interface_type;
1297 unsigned interface_version;
1298};
eae1ae02 1299
6fbd15c8 1300typedef void (RETRO_CALLCONV *retro_set_led_state_t)(int led, int state);
1301struct retro_led_interface
1302{
1303 retro_set_led_state_t set_led_state;
1304};
1305
1306/* Retrieves the current state of the MIDI input.
1307 * Returns true if it's enabled, false otherwise. */
1308typedef bool (RETRO_CALLCONV *retro_midi_input_enabled_t)(void);
1309
1310/* Retrieves the current state of the MIDI output.
1311 * Returns true if it's enabled, false otherwise */
1312typedef bool (RETRO_CALLCONV *retro_midi_output_enabled_t)(void);
1313
1314/* Reads next byte from the input stream.
1315 * Returns true if byte is read, false otherwise. */
1316typedef bool (RETRO_CALLCONV *retro_midi_read_t)(uint8_t *byte);
1317
1318/* Writes byte to the output stream.
1319 * 'delta_time' is in microseconds and represent time elapsed since previous write.
1320 * Returns true if byte is written, false otherwise. */
1321typedef bool (RETRO_CALLCONV *retro_midi_write_t)(uint8_t byte, uint32_t delta_time);
1322
1323/* Flushes previously written data.
1324 * Returns true if successful, false otherwise. */
1325typedef bool (RETRO_CALLCONV *retro_midi_flush_t)(void);
1326
1327struct retro_midi_interface
1328{
1329 retro_midi_input_enabled_t input_enabled;
1330 retro_midi_output_enabled_t output_enabled;
1331 retro_midi_read_t read;
1332 retro_midi_write_t write;
1333 retro_midi_flush_t flush;
1334};
1335
1336enum retro_hw_render_context_negotiation_interface_type
1337{
1338 RETRO_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_VULKAN = 0,
1339 RETRO_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE_DUMMY = INT_MAX
1340};
1341
1342/* Base struct. All retro_hw_render_context_negotiation_interface_* types
1343 * contain at least these fields. */
1344struct retro_hw_render_context_negotiation_interface
1345{
1346 enum retro_hw_render_context_negotiation_interface_type interface_type;
1347 unsigned interface_version;
1348};
1349
1350/* Serialized state is incomplete in some way. Set if serialization is
1351 * usable in typical end-user cases but should not be relied upon to
1352 * implement frame-sensitive frontend features such as netplay or
1353 * rerecording. */
1354#define RETRO_SERIALIZATION_QUIRK_INCOMPLETE (1 << 0)
1355/* The core must spend some time initializing before serialization is
1356 * supported. retro_serialize() will initially fail; retro_unserialize()
1357 * and retro_serialize_size() may or may not work correctly either. */
1358#define RETRO_SERIALIZATION_QUIRK_MUST_INITIALIZE (1 << 1)
1359/* Serialization size may change within a session. */
1360#define RETRO_SERIALIZATION_QUIRK_CORE_VARIABLE_SIZE (1 << 2)
1361/* Set by the frontend to acknowledge that it supports variable-sized
1362 * states. */
1363#define RETRO_SERIALIZATION_QUIRK_FRONT_VARIABLE_SIZE (1 << 3)
1364/* Serialized state can only be loaded during the same session. */
1365#define RETRO_SERIALIZATION_QUIRK_SINGLE_SESSION (1 << 4)
1366/* Serialized state cannot be loaded on an architecture with a different
1367 * endianness from the one it was saved on. */
1368#define RETRO_SERIALIZATION_QUIRK_ENDIAN_DEPENDENT (1 << 5)
1369/* Serialized state cannot be loaded on a different platform from the one it
1370 * was saved on for reasons other than endianness, such as word size
1371 * dependence */
1372#define RETRO_SERIALIZATION_QUIRK_PLATFORM_DEPENDENT (1 << 6)
1373
1374#define RETRO_MEMDESC_CONST (1 << 0) /* The frontend will never change this memory area once retro_load_game has returned. */
1375#define RETRO_MEMDESC_BIGENDIAN (1 << 1) /* The memory area contains big endian data. Default is little endian. */
1376#define RETRO_MEMDESC_SYSTEM_RAM (1 << 2) /* The memory area is system RAM. This is main RAM of the gaming system. */
1377#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. */
1378#define RETRO_MEMDESC_VIDEO_RAM (1 << 4) /* The memory area is video RAM (VRAM) */
1379#define RETRO_MEMDESC_ALIGN_2 (1 << 16) /* All memory access in this area is aligned to their own size, or 2, whichever is smaller. */
1380#define RETRO_MEMDESC_ALIGN_4 (2 << 16)
1381#define RETRO_MEMDESC_ALIGN_8 (3 << 16)
1382#define RETRO_MEMDESC_MINSIZE_2 (1 << 24) /* All memory in this region is accessed at least 2 bytes at the time. */
1383#define RETRO_MEMDESC_MINSIZE_4 (2 << 24)
1384#define RETRO_MEMDESC_MINSIZE_8 (3 << 24)
eae1ae02
A
1385struct retro_memory_descriptor
1386{
1387 uint64_t flags;
1388
1389 /* Pointer to the start of the relevant ROM or RAM chip.
6fbd15c8 1390 * It's strongly recommended to use 'offset' if possible, rather than
eae1ae02
A
1391 * doing math on the pointer.
1392 *
6fbd15c8 1393 * If the same byte is mapped my multiple descriptors, their descriptors
eae1ae02 1394 * must have the same pointer.
6fbd15c8 1395 * If 'start' does not point to the first byte in the pointer, put the
eae1ae02
A
1396 * difference in 'offset' instead.
1397 *
6fbd15c8 1398 * May be NULL if there's nothing usable here (e.g. hardware registers and
eae1ae02
A
1399 * open bus). No flags should be set if the pointer is NULL.
1400 * It's recommended to minimize the number of descriptors if possible,
1401 * but not mandatory. */
1402 void *ptr;
1403 size_t offset;
1404
6fbd15c8 1405 /* This is the location in the emulated address space
eae1ae02
A
1406 * where the mapping starts. */
1407 size_t start;
1408
1409 /* Which bits must be same as in 'start' for this mapping to apply.
6fbd15c8 1410 * The first memory descriptor to claim a certain byte is the one
eae1ae02
A
1411 * that applies.
1412 * A bit which is set in 'start' must also be set in this.
6fbd15c8 1413 * Can be zero, in which case each byte is assumed mapped exactly once.
eae1ae02
A
1414 * In this case, 'len' must be a power of two. */
1415 size_t select;
1416
6fbd15c8 1417 /* If this is nonzero, the set bits are assumed not connected to the
eae1ae02
A
1418 * memory chip's address pins. */
1419 size_t disconnect;
1420
1421 /* This one tells the size of the current memory area.
6fbd15c8 1422 * If, after start+disconnect are applied, the address is higher than
eae1ae02
A
1423 * this, the highest bit of the address is cleared.
1424 *
1425 * If the address is still too high, the next highest bit is cleared.
6fbd15c8 1426 * Can be zero, in which case it's assumed to be infinite (as limited
eae1ae02
A
1427 * by 'select' and 'disconnect'). */
1428 size_t len;
1429
6fbd15c8 1430 /* To go from emulated address to physical address, the following
eae1ae02 1431 * order applies:
6fbd15c8 1432 * Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'. */
1433
1434 /* The address space name must consist of only a-zA-Z0-9_-,
eae1ae02 1435 * should be as short as feasible (maximum length is 8 plus the NUL),
6fbd15c8 1436 * and may not be any other address space plus one or more 0-9A-F
eae1ae02 1437 * at the end.
6fbd15c8 1438 * However, multiple memory descriptors for the same address space is
1439 * allowed, and the address space name can be empty. NULL is treated
eae1ae02
A
1440 * as empty.
1441 *
1442 * Address space names are case sensitive, but avoid lowercase if possible.
1443 * The same pointer may exist in multiple address spaces.
1444 *
1445 * Examples:
1446 * blank+blank - valid (multiple things may be mapped in the same namespace)
1447 * 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace)
1448 * 'A'+'B' - valid (neither is a prefix of each other)
1449 * 'S'+blank - valid ('S' is not in 0-9A-F)
1450 * 'a'+blank - valid ('a' is not in 0-9A-F)
1451 * 'a'+'A' - valid (neither is a prefix of each other)
1452 * 'AR'+blank - valid ('R' is not in 0-9A-F)
6fbd15c8 1453 * 'ARB'+blank - valid (the B can't be part of the address either, because
1454 * there is no namespace 'AR')
1455 * blank+'B' - not valid, because it's ambigous which address space B1234
1456 * would refer to.
1457 * The length can't be used for that purpose; the frontend may want
eae1ae02
A
1458 * to append arbitrary data to an address, without a separator. */
1459 const char *addrspace;
6fbd15c8 1460
1461 /* TODO: When finalizing this one, add a description field, which should be
1462 * "WRAM" or something roughly equally long. */
1463
1464 /* TODO: When finalizing this one, replace 'select' with 'limit', which tells
1465 * which bits can vary and still refer to the same address (limit = ~select).
1466 * TODO: limit? range? vary? something else? */
1467
1468 /* TODO: When finalizing this one, if 'len' is above what 'select' (or
1469 * 'limit') allows, it's bankswitched. Bankswitched data must have both 'len'
1470 * and 'select' != 0, and the mappings don't tell how the system switches the
1471 * banks. */
1472
1473 /* TODO: When finalizing this one, fix the 'len' bit removal order.
1474 * For len=0x1800, pointer 0x1C00 should go to 0x1400, not 0x0C00.
1475 * Algorithm: Take bits highest to lowest, but if it goes above len, clear
1476 * the most recent addition and continue on the next bit.
1477 * TODO: Can the above be optimized? Is "remove the lowest bit set in both
1478 * pointer and 'len'" equivalent? */
1479
1480 /* TODO: Some emulators (MAME?) emulate big endian systems by only accessing
1481 * the emulated memory in 32-bit chunks, native endian. But that's nothing
1482 * compared to Darek Mihocka <http://www.emulators.com/docs/nx07_vm101.htm>
1483 * (section Emulation 103 - Nearly Free Byte Reversal) - he flips the ENTIRE
1484 * RAM backwards! I'll want to represent both of those, via some flags.
1485 *
1486 * I suspect MAME either didn't think of that idea, or don't want the #ifdef.
1487 * Not sure which, nor do I really care. */
1488
1489 /* TODO: Some of those flags are unused and/or don't really make sense. Clean
1490 * them up. */
eae1ae02
A
1491};
1492
6fbd15c8 1493/* The frontend may use the largest value of 'start'+'select' in a
eae1ae02
A
1494 * certain namespace to infer the size of the address space.
1495 *
6fbd15c8 1496 * If the address space is larger than that, a mapping with .ptr=NULL
1497 * should be at the end of the array, with .select set to all ones for
eae1ae02
A
1498 * as long as the address space is big.
1499 *
1500 * Sample descriptors (minus .ptr, and RETRO_MEMFLAG_ on the flags):
1501 * SNES WRAM:
1502 * .start=0x7E0000, .len=0x20000
6fbd15c8 1503 * (Note that this must be mapped before the ROM in most cases; some of the
1504 * ROM mappers
eae1ae02
A
1505 * try to claim $7E0000, or at least $7E8000.)
1506 * SNES SPC700 RAM:
1507 * .addrspace="S", .len=0x10000
1508 * SNES WRAM mirrors:
1509 * .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000
1510 * .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000
1511 * SNES WRAM mirrors, alternate equivalent descriptor:
1512 * .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF
6fbd15c8 1513 * (Various similar constructions can be created by combining parts of
eae1ae02
A
1514 * the above two.)
1515 * SNES LoROM (512KB, mirrored a couple of times):
1516 * .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024
1517 * .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024
1518 * SNES HiROM (4MB):
1519 * .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024
1520 * .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024
1521 * SNES ExHiROM (8MB):
1522 * .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024
1523 * .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024
1524 * .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024
1525 * .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024
1526 * Clarify the size of the address space:
1527 * .ptr=NULL, .select=0xFFFFFF
1528 * .len can be implied by .select in many of them, but was included for clarity.
1529 */
1530
1531struct retro_memory_map
1532{
1533 const struct retro_memory_descriptor *descriptors;
1534 unsigned num_descriptors;
1535};
1536
1537struct retro_controller_description
1538{
6fbd15c8 1539 /* Human-readable description of the controller. Even if using a generic
1540 * input device type, this can be set to the particular device type the
eae1ae02
A
1541 * core uses. */
1542 const char *desc;
1543
6fbd15c8 1544 /* Device type passed to retro_set_controller_port_device(). If the device
1545 * type is a sub-class of a generic input device type, use the
eae1ae02
A
1546 * RETRO_DEVICE_SUBCLASS macro to create an ID.
1547 *
1548 * E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1). */
1549 unsigned id;
1550};
1551
1552struct retro_controller_info
1553{
1554 const struct retro_controller_description *types;
1555 unsigned num_types;
1556};
1557
1558struct retro_subsystem_memory_info
1559{
1560 /* The extension associated with a memory type, e.g. "psram". */
1561 const char *extension;
1562
6fbd15c8 1563 /* The memory type for retro_get_memory(). This should be at
1564 * least 0x100 to avoid conflict with standardized
eae1ae02
A
1565 * libretro memory types. */
1566 unsigned type;
1567};
1568
1569struct retro_subsystem_rom_info
1570{
1571 /* Describes what the content is (SGB BIOS, GB ROM, etc). */
1572 const char *desc;
1573
1574 /* Same definition as retro_get_system_info(). */
1575 const char *valid_extensions;
1576
1577 /* Same definition as retro_get_system_info(). */
1578 bool need_fullpath;
1579
1580 /* Same definition as retro_get_system_info(). */
1581 bool block_extract;
1582
6fbd15c8 1583 /* This is set if the content is required to load a game.
eae1ae02
A
1584 * If this is set to false, a zeroed-out retro_game_info can be passed. */
1585 bool required;
1586
6fbd15c8 1587 /* Content can have multiple associated persistent
eae1ae02
A
1588 * memory types (retro_get_memory()). */
1589 const struct retro_subsystem_memory_info *memory;
1590 unsigned num_memory;
1591};
1592
1593struct retro_subsystem_info
1594{
1595 /* Human-readable string of the subsystem type, e.g. "Super GameBoy" */
1596 const char *desc;
1597
1598 /* A computer friendly short string identifier for the subsystem type.
1599 * This name must be [a-z].
1600 * E.g. if desc is "Super GameBoy", this can be "sgb".
1601 * This identifier can be used for command-line interfaces, etc.
1602 */
1603 const char *ident;
1604
6fbd15c8 1605 /* Infos for each content file. The first entry is assumed to be the
eae1ae02 1606 * "most significant" content for frontend purposes.
6fbd15c8 1607 * E.g. with Super GameBoy, the first content should be the GameBoy ROM,
eae1ae02 1608 * as it is the most "significant" content to a user.
6fbd15c8 1609 * If a frontend creates new file paths based on the content used
eae1ae02
A
1610 * (e.g. savestates), it should use the path for the first ROM to do so. */
1611 const struct retro_subsystem_rom_info *roms;
1612
1613 /* Number of content files associated with a subsystem. */
1614 unsigned num_roms;
6fbd15c8 1615
eae1ae02
A
1616 /* The type passed to retro_load_game_special(). */
1617 unsigned id;
1618};
1619
6fbd15c8 1620typedef void (RETRO_CALLCONV *retro_proc_address_t)(void);
eae1ae02
A
1621
1622/* libretro API extension functions:
1623 * (None here so far).
1624 *
1625 * Get a symbol from a libretro core.
6fbd15c8 1626 * Cores should only return symbols which are actual
eae1ae02
A
1627 * extensions to the libretro API.
1628 *
6fbd15c8 1629 * Frontends should not use this to obtain symbols to standard
eae1ae02
A
1630 * libretro entry points (static linking or dlsym).
1631 *
6fbd15c8 1632 * The symbol name must be equal to the function name,
eae1ae02
A
1633 * e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo".
1634 * The returned function pointer must be cast to the corresponding type.
1635 */
6fbd15c8 1636typedef retro_proc_address_t (RETRO_CALLCONV *retro_get_proc_address_t)(const char *sym);
eae1ae02
A
1637
1638struct retro_get_proc_address_interface
1639{
1640 retro_get_proc_address_t get_proc_address;
1641};
779692e4 1642
1643enum retro_log_level
1644{
1645 RETRO_LOG_DEBUG = 0,
1646 RETRO_LOG_INFO,
1647 RETRO_LOG_WARN,
1648 RETRO_LOG_ERROR,
1649
1650 RETRO_LOG_DUMMY = INT_MAX
1651};
1652
eae1ae02 1653/* Logging function. Takes log level argument as well. */
6fbd15c8 1654typedef void (RETRO_CALLCONV *retro_log_printf_t)(enum retro_log_level level,
eae1ae02 1655 const char *fmt, ...);
779692e4 1656
1657struct retro_log_callback
1658{
1659 retro_log_printf_t log;
1660};
1661
eae1ae02
A
1662/* Performance related functions */
1663
1664/* ID values for SIMD CPU features */
779692e4 1665#define RETRO_SIMD_SSE (1 << 0)
1666#define RETRO_SIMD_SSE2 (1 << 1)
1667#define RETRO_SIMD_VMX (1 << 2)
1668#define RETRO_SIMD_VMX128 (1 << 3)
1669#define RETRO_SIMD_AVX (1 << 4)
1670#define RETRO_SIMD_NEON (1 << 5)
1671#define RETRO_SIMD_SSE3 (1 << 6)
1672#define RETRO_SIMD_SSSE3 (1 << 7)
eae1ae02
A
1673#define RETRO_SIMD_MMX (1 << 8)
1674#define RETRO_SIMD_MMXEXT (1 << 9)
1675#define RETRO_SIMD_SSE4 (1 << 10)
1676#define RETRO_SIMD_SSE42 (1 << 11)
1677#define RETRO_SIMD_AVX2 (1 << 12)
1678#define RETRO_SIMD_VFPU (1 << 13)
1679#define RETRO_SIMD_PS (1 << 14)
1680#define RETRO_SIMD_AES (1 << 15)
65a0505f
FJGG
1681#define RETRO_SIMD_VFPV3 (1 << 16)
1682#define RETRO_SIMD_VFPV4 (1 << 17)
1683#define RETRO_SIMD_POPCNT (1 << 18)
1684#define RETRO_SIMD_MOVBE (1 << 19)
6fbd15c8 1685#define RETRO_SIMD_CMOV (1 << 20)
1686#define RETRO_SIMD_ASIMD (1 << 21)
779692e4 1687
1688typedef uint64_t retro_perf_tick_t;
1689typedef int64_t retro_time_t;
1690
1691struct retro_perf_counter
1692{
1693 const char *ident;
1694 retro_perf_tick_t start;
1695 retro_perf_tick_t total;
1696 retro_perf_tick_t call_cnt;
1697
1698 bool registered;
1699};
1700
eae1ae02
A
1701/* Returns current time in microseconds.
1702 * Tries to use the most accurate timer available.
1703 */
6fbd15c8 1704typedef retro_time_t (RETRO_CALLCONV *retro_perf_get_time_usec_t)(void);
eae1ae02
A
1705
1706/* A simple counter. Usually nanoseconds, but can also be CPU cycles.
6fbd15c8 1707 * Can be used directly if desired (when creating a more sophisticated
eae1ae02
A
1708 * performance counter system).
1709 * */
6fbd15c8 1710typedef retro_perf_tick_t (RETRO_CALLCONV *retro_perf_get_counter_t)(void);
eae1ae02
A
1711
1712/* Returns a bit-mask of detected CPU features (RETRO_SIMD_*). */
6fbd15c8 1713typedef uint64_t (RETRO_CALLCONV *retro_get_cpu_features_t)(void);
eae1ae02
A
1714
1715/* Asks frontend to log and/or display the state of performance counters.
1716 * Performance counters can always be poked into manually as well.
1717 */
6fbd15c8 1718typedef void (RETRO_CALLCONV *retro_perf_log_t)(void);
eae1ae02
A
1719
1720/* Register a performance counter.
6fbd15c8 1721 * ident field must be set with a discrete value and other values in
eae1ae02 1722 * retro_perf_counter must be 0.
6fbd15c8 1723 * Registering can be called multiple times. To avoid calling to
eae1ae02 1724 * frontend redundantly, you can check registered field first. */
6fbd15c8 1725typedef void (RETRO_CALLCONV *retro_perf_register_t)(struct retro_perf_counter *counter);
eae1ae02
A
1726
1727/* Starts a registered counter. */
6fbd15c8 1728typedef void (RETRO_CALLCONV *retro_perf_start_t)(struct retro_perf_counter *counter);
eae1ae02
A
1729
1730/* Stops a registered counter. */
6fbd15c8 1731typedef void (RETRO_CALLCONV *retro_perf_stop_t)(struct retro_perf_counter *counter);
779692e4 1732
eae1ae02
A
1733/* For convenience it can be useful to wrap register, start and stop in macros.
1734 * E.g.:
1735 * #ifdef LOG_PERFORMANCE
1736 * #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
1737 * #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
1738 * #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
1739 * #else
1740 * ... Blank macros ...
1741 * #endif
1742 *
1743 * These can then be used mid-functions around code snippets.
1744 *
1745 * extern struct retro_perf_callback perf_cb; * Somewhere in the core.
1746 *
1747 * void do_some_heavy_work(void)
1748 * {
1749 * RETRO_PERFORMANCE_INIT(cb, work_1;
1750 * RETRO_PERFORMANCE_START(cb, work_1);
1751 * heavy_work_1();
1752 * RETRO_PERFORMANCE_STOP(cb, work_1);
1753 *
1754 * RETRO_PERFORMANCE_INIT(cb, work_2);
1755 * RETRO_PERFORMANCE_START(cb, work_2);
1756 * heavy_work_2();
1757 * RETRO_PERFORMANCE_STOP(cb, work_2);
1758 * }
1759 *
1760 * void retro_deinit(void)
1761 * {
1762 * perf_cb.perf_log(); * Log all perf counters here for example.
1763 * }
1764 */
779692e4 1765
1766struct retro_perf_callback
1767{
1768 retro_perf_get_time_usec_t get_time_usec;
1769 retro_get_cpu_features_t get_cpu_features;
1770
1771 retro_perf_get_counter_t get_perf_counter;
1772 retro_perf_register_t perf_register;
1773 retro_perf_start_t perf_start;
1774 retro_perf_stop_t perf_stop;
1775 retro_perf_log_t perf_log;
1776};
1777
eae1ae02
A
1778/* FIXME: Document the sensor API and work out behavior.
1779 * It will be marked as experimental until then.
1780 */
779692e4 1781enum retro_sensor_action
1782{
1783 RETRO_SENSOR_ACCELEROMETER_ENABLE = 0,
1784 RETRO_SENSOR_ACCELEROMETER_DISABLE,
1785
1786 RETRO_SENSOR_DUMMY = INT_MAX
1787};
1788
eae1ae02
A
1789/* Id values for SENSOR types. */
1790#define RETRO_SENSOR_ACCELEROMETER_X 0
1791#define RETRO_SENSOR_ACCELEROMETER_Y 1
1792#define RETRO_SENSOR_ACCELEROMETER_Z 2
1793
6fbd15c8 1794typedef bool (RETRO_CALLCONV *retro_set_sensor_state_t)(unsigned port,
eae1ae02
A
1795 enum retro_sensor_action action, unsigned rate);
1796
6fbd15c8 1797typedef float (RETRO_CALLCONV *retro_sensor_get_input_t)(unsigned port, unsigned id);
eae1ae02 1798
779692e4 1799struct retro_sensor_interface
1800{
1801 retro_set_sensor_state_t set_sensor_state;
eae1ae02 1802 retro_sensor_get_input_t get_sensor_input;
779692e4 1803};
779692e4 1804
1805enum retro_camera_buffer
1806{
1807 RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0,
1808 RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER,
1809
1810 RETRO_CAMERA_BUFFER_DUMMY = INT_MAX
1811};
1812
eae1ae02 1813/* Starts the camera driver. Can only be called in retro_run(). */
6fbd15c8 1814typedef bool (RETRO_CALLCONV *retro_camera_start_t)(void);
eae1ae02
A
1815
1816/* Stops the camera driver. Can only be called in retro_run(). */
6fbd15c8 1817typedef void (RETRO_CALLCONV *retro_camera_stop_t)(void);
eae1ae02 1818
6fbd15c8 1819/* Callback which signals when the camera driver is initialized
eae1ae02
A
1820 * and/or deinitialized.
1821 * retro_camera_start_t can be called in initialized callback.
1822 */
6fbd15c8 1823typedef void (RETRO_CALLCONV *retro_camera_lifetime_status_t)(void);
eae1ae02
A
1824
1825/* A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
1826 * Width, height and pitch are similar to retro_video_refresh_t.
1827 * First pixel is top-left origin.
1828 */
6fbd15c8 1829typedef void (RETRO_CALLCONV *retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer,
eae1ae02
A
1830 unsigned width, unsigned height, size_t pitch);
1831
1832/* A callback for when OpenGL textures are used.
1833 *
1834 * texture_id is a texture owned by camera driver.
6fbd15c8 1835 * Its state or content should be considered immutable, except for things like
eae1ae02
A
1836 * texture filtering and clamping.
1837 *
1838 * texture_target is the texture target for the GL texture.
6fbd15c8 1839 * These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly
eae1ae02
A
1840 * more depending on extensions.
1841 *
6fbd15c8 1842 * affine points to a packed 3x3 column-major matrix used to apply an affine
eae1ae02 1843 * transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
6fbd15c8 1844 * After transform, normalized texture coord (0, 0) should be bottom-left
eae1ae02
A
1845 * and (1, 1) should be top-right (or (width, height) for RECTANGLE).
1846 *
6fbd15c8 1847 * GL-specific typedefs are avoided here to avoid relying on gl.h in
eae1ae02
A
1848 * the API definition.
1849 */
6fbd15c8 1850typedef void (RETRO_CALLCONV *retro_camera_frame_opengl_texture_t)(unsigned texture_id,
eae1ae02
A
1851 unsigned texture_target, const float *affine);
1852
779692e4 1853struct retro_camera_callback
1854{
6fbd15c8 1855 /* Set by libretro core.
eae1ae02
A
1856 * Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER).
1857 */
6fbd15c8 1858 uint64_t caps;
779692e4 1859
6fbd15c8 1860 /* Desired resolution for camera. Is only used as a hint. */
1861 unsigned width;
779692e4 1862 unsigned height;
6fbd15c8 1863
1864 /* Set by frontend. */
1865 retro_camera_start_t start;
1866 retro_camera_stop_t stop;
eae1ae02
A
1867
1868 /* Set by libretro core if raw framebuffer callbacks will be used. */
1869 retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer;
6fbd15c8 1870
eae1ae02 1871 /* Set by libretro core if OpenGL texture callbacks will be used. */
6fbd15c8 1872 retro_camera_frame_opengl_texture_t frame_opengl_texture;
eae1ae02 1873
6fbd15c8 1874 /* Set by libretro core. Called after camera driver is initialized and
eae1ae02
A
1875 * ready to be started.
1876 * Can be NULL, in which this callback is not called.
1877 */
779692e4 1878 retro_camera_lifetime_status_t initialized;
1879
6fbd15c8 1880 /* Set by libretro core. Called right before camera driver is
eae1ae02
A
1881 * deinitialized.
1882 * Can be NULL, in which this callback is not called.
1883 */
779692e4 1884 retro_camera_lifetime_status_t deinitialized;
1885};
1886
6fbd15c8 1887/* Sets the interval of time and/or distance at which to update/poll
eae1ae02
A
1888 * location-based data.
1889 *
1890 * To ensure compatibility with all location-based implementations,
1891 * values for both interval_ms and interval_distance should be provided.
1892 *
1893 * interval_ms is the interval expressed in milliseconds.
1894 * interval_distance is the distance interval expressed in meters.
1895 */
6fbd15c8 1896typedef void (RETRO_CALLCONV *retro_location_set_interval_t)(unsigned interval_ms,
eae1ae02
A
1897 unsigned interval_distance);
1898
1899/* Start location services. The device will start listening for changes to the
6fbd15c8 1900 * current location at regular intervals (which are defined with
eae1ae02 1901 * retro_location_set_interval_t). */
6fbd15c8 1902typedef bool (RETRO_CALLCONV *retro_location_start_t)(void);
eae1ae02 1903
6fbd15c8 1904/* Stop location services. The device will stop listening for changes
eae1ae02 1905 * to the current location. */
6fbd15c8 1906typedef void (RETRO_CALLCONV *retro_location_stop_t)(void);
eae1ae02 1907
6fbd15c8 1908/* Get the position of the current location. Will set parameters to
eae1ae02 1909 * 0 if no new location update has happened since the last time. */
6fbd15c8 1910typedef bool (RETRO_CALLCONV *retro_location_get_position_t)(double *lat, double *lon,
eae1ae02
A
1911 double *horiz_accuracy, double *vert_accuracy);
1912
6fbd15c8 1913/* Callback which signals when the location driver is initialized
eae1ae02
A
1914 * and/or deinitialized.
1915 * retro_location_start_t can be called in initialized callback.
1916 */
6fbd15c8 1917typedef void (RETRO_CALLCONV *retro_location_lifetime_status_t)(void);
eae1ae02
A
1918
1919struct retro_location_callback
1920{
1921 retro_location_start_t start;
1922 retro_location_stop_t stop;
1923 retro_location_get_position_t get_position;
1924 retro_location_set_interval_t set_interval;
1925
1926 retro_location_lifetime_status_t initialized;
1927 retro_location_lifetime_status_t deinitialized;
1928};
1929
779692e4 1930enum retro_rumble_effect
1931{
1932 RETRO_RUMBLE_STRONG = 0,
1933 RETRO_RUMBLE_WEAK = 1,
1934
1935 RETRO_RUMBLE_DUMMY = INT_MAX
1936};
1937
6fbd15c8 1938/* Sets rumble state for joypad plugged in port 'port'.
eae1ae02
A
1939 * Rumble effects are controlled independently,
1940 * and setting e.g. strong rumble does not override weak rumble.
1941 * Strength has a range of [0, 0xffff].
1942 *
6fbd15c8 1943 * Returns true if rumble state request was honored.
eae1ae02 1944 * Calling this before first retro_run() is likely to return false. */
6fbd15c8 1945typedef bool (RETRO_CALLCONV *retro_set_rumble_state_t)(unsigned port,
eae1ae02
A
1946 enum retro_rumble_effect effect, uint16_t strength);
1947
779692e4 1948struct retro_rumble_interface
1949{
1950 retro_set_rumble_state_t set_rumble_state;
1951};
1952
eae1ae02 1953/* Notifies libretro that audio data should be written. */
6fbd15c8 1954typedef void (RETRO_CALLCONV *retro_audio_callback_t)(void);
779692e4 1955
6fbd15c8 1956/* True: Audio driver in frontend is active, and callback is
eae1ae02 1957 * expected to be called regularily.
6fbd15c8 1958 * False: Audio driver in frontend is paused or inactive.
1959 * Audio callback will not be called until set_state has been
eae1ae02
A
1960 * called with true.
1961 * Initial state is false (inactive).
1962 */
6fbd15c8 1963typedef void (RETRO_CALLCONV *retro_audio_set_state_callback_t)(bool enabled);
eae1ae02 1964
779692e4 1965struct retro_audio_callback
1966{
1967 retro_audio_callback_t callback;
1968 retro_audio_set_state_callback_t set_state;
1969};
1970
6fbd15c8 1971/* Notifies a libretro core of time spent since last invocation
eae1ae02
A
1972 * of retro_run() in microseconds.
1973 *
1974 * It will be called right before retro_run() every frame.
6fbd15c8 1975 * The frontend can tamper with timing to support cases like
eae1ae02
A
1976 * fast-forward, slow-motion and framestepping.
1977 *
1978 * In those scenarios the reference frame time value will be used. */
779692e4 1979typedef int64_t retro_usec_t;
6fbd15c8 1980typedef void (RETRO_CALLCONV *retro_frame_time_callback_t)(retro_usec_t usec);
779692e4 1981struct retro_frame_time_callback
1982{
1983 retro_frame_time_callback_t callback;
6fbd15c8 1984 /* Represents the time of one frame. It is computed as
1985 * 1000000 / fps, but the implementation will resolve the
eae1ae02
A
1986 * rounding to ensure that framestepping, etc is exact. */
1987 retro_usec_t reference;
779692e4 1988};
e56b1300 1989
eae1ae02
A
1990/* Pass this to retro_video_refresh_t if rendering to hardware.
1991 * Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
1992 * */
e56b1300 1993#define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)
1994
eae1ae02
A
1995/* Invalidates the current HW context.
1996 * Any GL state is lost, and must not be deinitialized explicitly.
1997 * If explicit deinitialization is desired by the libretro core,
1998 * it should implement context_destroy callback.
1999 * If called, all GPU resources must be reinitialized.
2000 * Usually called when frontend reinits video driver.
6fbd15c8 2001 * Also called first time video driver is initialized,
eae1ae02
A
2002 * allowing libretro core to initialize resources.
2003 */
6fbd15c8 2004typedef void (RETRO_CALLCONV *retro_hw_context_reset_t)(void);
eae1ae02
A
2005
2006/* Gets current framebuffer which is to be rendered to.
2007 * Could change every frame potentially.
2008 */
6fbd15c8 2009typedef uintptr_t (RETRO_CALLCONV *retro_hw_get_current_framebuffer_t)(void);
e56b1300 2010
eae1ae02 2011/* Get a symbol from HW context. */
6fbd15c8 2012typedef retro_proc_address_t (RETRO_CALLCONV *retro_hw_get_proc_address_t)(const char *sym);
e56b1300 2013
2014enum retro_hw_context_type
2015{
eae1ae02
A
2016 RETRO_HW_CONTEXT_NONE = 0,
2017 /* OpenGL 2.x. Driver can choose to use latest compatibility context. */
6fbd15c8 2018 RETRO_HW_CONTEXT_OPENGL = 1,
eae1ae02
A
2019 /* OpenGL ES 2.0. */
2020 RETRO_HW_CONTEXT_OPENGLES2 = 2,
2021 /* Modern desktop core GL context. Use version_major/
2022 * version_minor fields to set GL version. */
2023 RETRO_HW_CONTEXT_OPENGL_CORE = 3,
2024 /* OpenGL ES 3.0 */
2025 RETRO_HW_CONTEXT_OPENGLES3 = 4,
2026 /* OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3,
2027 * use the corresponding enums directly. */
2028 RETRO_HW_CONTEXT_OPENGLES_VERSION = 5,
e56b1300 2029
65a0505f
FJGG
2030 /* Vulkan, see RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE. */
2031 RETRO_HW_CONTEXT_VULKAN = 6,
2032
6fbd15c8 2033 /* Direct3D, set version_major to select the type of interface
2034 * returned by RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE */
2035 RETRO_HW_CONTEXT_DIRECT3D = 7,
2036
e56b1300 2037 RETRO_HW_CONTEXT_DUMMY = INT_MAX
2038};
23ea11bd 2039
e56b1300 2040struct retro_hw_render_callback
2041{
eae1ae02
A
2042 /* Which API to use. Set by libretro core. */
2043 enum retro_hw_context_type context_type;
2044
2045 /* Called when a context has been created or when it has been reset.
2046 * An OpenGL context is only valid after context_reset() has been called.
2047 *
6fbd15c8 2048 * When context_reset is called, OpenGL resources in the libretro
eae1ae02
A
2049 * implementation are guaranteed to be invalid.
2050 *
6fbd15c8 2051 * It is possible that context_reset is called multiple times during an
eae1ae02
A
2052 * application lifecycle.
2053 * If context_reset is called without any notification (context_destroy),
2054 * the OpenGL context was lost and resources should just be recreated
2055 * without any attempt to "free" old resources.
2056 */
2057 retro_hw_context_reset_t context_reset;
2058
65a0505f
FJGG
2059 /* Set by frontend.
2060 * TODO: This is rather obsolete. The frontend should not
2061 * be providing preallocated framebuffers. */
eae1ae02
A
2062 retro_hw_get_current_framebuffer_t get_current_framebuffer;
2063
6fbd15c8 2064 /* Set by frontend.
2065 * Can return all relevant functions, including glClear on Windows. */
eae1ae02
A
2066 retro_hw_get_proc_address_t get_proc_address;
2067
65a0505f
FJGG
2068 /* Set if render buffers should have depth component attached.
2069 * TODO: Obsolete. */
eae1ae02
A
2070 bool depth;
2071
65a0505f
FJGG
2072 /* Set if stencil buffers should be attached.
2073 * TODO: Obsolete. */
eae1ae02
A
2074 bool stencil;
2075
6fbd15c8 2076 /* If depth and stencil are true, a packed 24/8 buffer will be added.
eae1ae02
A
2077 * Only attaching stencil is invalid and will be ignored. */
2078
6fbd15c8 2079 /* Use conventional bottom-left origin convention. If false,
65a0505f
FJGG
2080 * standard libretro top-left origin semantics are used.
2081 * TODO: Move to GL specific interface. */
eae1ae02 2082 bool bottom_left_origin;
6fbd15c8 2083
eae1ae02
A
2084 /* Major version number for core GL context or GLES 3.1+. */
2085 unsigned version_major;
2086
2087 /* Minor version number for core GL context or GLES 3.1+. */
2088 unsigned version_minor;
2089
6fbd15c8 2090 /* If this is true, the frontend will go very far to avoid
eae1ae02 2091 * resetting context in scenarios like toggling fullscreen, etc.
65a0505f 2092 * TODO: Obsolete? Maybe frontend should just always assume this ...
eae1ae02
A
2093 */
2094 bool cache_context;
2095
6fbd15c8 2096 /* The reset callback might still be called in extreme situations
eae1ae02
A
2097 * such as if the context is lost beyond recovery.
2098 *
6fbd15c8 2099 * For optimal stability, set this to false, and allow context to be
eae1ae02
A
2100 * reset at any time.
2101 */
6fbd15c8 2102
2103 /* A callback to be called before the context is destroyed in a
eae1ae02
A
2104 * controlled way by the frontend. */
2105 retro_hw_context_reset_t context_destroy;
2106
2107 /* OpenGL resources can be deinitialized cleanly at this step.
6fbd15c8 2108 * context_destroy can be set to NULL, in which resources will
eae1ae02
A
2109 * just be destroyed without any notification.
2110 *
6fbd15c8 2111 * Even when context_destroy is non-NULL, it is possible that
eae1ae02 2112 * context_reset is called without any destroy notification.
6fbd15c8 2113 * This happens if context is lost by external factors (such as
eae1ae02
A
2114 * notified by GL_ARB_robustness).
2115 *
2116 * In this case, the context is assumed to be already dead,
6fbd15c8 2117 * and the libretro implementation must not try to free any OpenGL
eae1ae02
A
2118 * resources in the subsequent context_reset.
2119 */
2120
2121 /* Creates a debug context. */
2122 bool debug_context;
e56b1300 2123};
c19aba43 2124
6fbd15c8 2125/* Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK.
eae1ae02
A
2126 * Called by the frontend in response to keyboard events.
2127 * down is set if the key is being pressed, or false if it is being released.
2128 * keycode is the RETROK value of the char.
2129 * character is the text character of the pressed key. (UTF-32).
2130 * key_modifiers is a set of RETROKMOD values or'ed together.
2131 *
2132 * The pressed/keycode state can be indepedent of the character.
6fbd15c8 2133 * It is also possible that multiple characters are generated from a
eae1ae02
A
2134 * single keypress.
2135 * Keycode events should be treated separately from character events.
2136 * However, when possible, the frontend should try to synchronize these.
2137 * If only a character is posted, keycode should be RETROK_UNKNOWN.
2138 *
6fbd15c8 2139 * Similarily if only a keycode event is generated with no corresponding
eae1ae02
A
2140 * character, character should be 0.
2141 */
6fbd15c8 2142typedef void (RETRO_CALLCONV *retro_keyboard_event_t)(bool down, unsigned keycode,
eae1ae02 2143 uint32_t character, uint16_t key_modifiers);
23ea11bd 2144
2145struct retro_keyboard_callback
2146{
6b5beb44 2147 retro_keyboard_event_t callback;
23ea11bd 2148};
2149
eae1ae02 2150/* Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
6fbd15c8 2151 * Should be set for implementations which can swap out multiple disk
eae1ae02
A
2152 * images in runtime.
2153 *
2154 * If the implementation can do this automatically, it should strive to do so.
2155 * However, there are cases where the user must manually do so.
2156 *
6fbd15c8 2157 * Overview: To swap a disk image, eject the disk image with
eae1ae02 2158 * set_eject_state(true).
6fbd15c8 2159 * Set the disk index with set_image_index(index). Insert the disk again
eae1ae02
A
2160 * with set_eject_state(false).
2161 */
23ea11bd 2162
eae1ae02
A
2163/* If ejected is true, "ejects" the virtual disk tray.
2164 * When ejected, the disk image index can be set.
2165 */
6fbd15c8 2166typedef bool (RETRO_CALLCONV *retro_set_eject_state_t)(bool ejected);
eae1ae02
A
2167
2168/* Gets current eject state. The initial state is 'not ejected'. */
6fbd15c8 2169typedef bool (RETRO_CALLCONV *retro_get_eject_state_t)(void);
eae1ae02
A
2170
2171/* Gets current disk index. First disk is index 0.
2172 * If return value is >= get_num_images(), no disk is currently inserted.
2173 */
6fbd15c8 2174typedef unsigned (RETRO_CALLCONV *retro_get_image_index_t)(void);
eae1ae02
A
2175
2176/* Sets image index. Can only be called when disk is ejected.
6fbd15c8 2177 * The implementation supports setting "no disk" by using an
eae1ae02
A
2178 * index >= get_num_images().
2179 */
6fbd15c8 2180typedef bool (RETRO_CALLCONV *retro_set_image_index_t)(unsigned index);
eae1ae02
A
2181
2182/* Gets total number of images which are available to use. */
6fbd15c8 2183typedef unsigned (RETRO_CALLCONV *retro_get_num_images_t)(void);
eae1ae02 2184
23ea11bd 2185struct retro_game_info;
eae1ae02
A
2186
2187/* Replaces the disk image associated with index.
2188 * Arguments to pass in info have same requirements as retro_load_game().
2189 * Virtual disk tray must be ejected when calling this.
2190 *
6fbd15c8 2191 * Replacing a disk image with info = NULL will remove the disk image
eae1ae02
A
2192 * from the internal list.
2193 * As a result, calls to get_image_index() can change.
2194 *
6fbd15c8 2195 * E.g. replace_image_index(1, NULL), and previous get_image_index()
eae1ae02
A
2196 * returned 4 before.
2197 * Index 1 will be removed, and the new index is 3.
2198 */
6fbd15c8 2199typedef bool (RETRO_CALLCONV *retro_replace_image_index_t)(unsigned index,
eae1ae02
A
2200 const struct retro_game_info *info);
2201
2202/* Adds a new valid index (get_num_images()) to the internal disk list.
2203 * This will increment subsequent return values from get_num_images() by 1.
6fbd15c8 2204 * This image index cannot be used until a disk image has been set
eae1ae02 2205 * with replace_image_index. */
6fbd15c8 2206typedef bool (RETRO_CALLCONV *retro_add_image_index_t)(void);
23ea11bd 2207
2208struct retro_disk_control_callback
2209{
2210 retro_set_eject_state_t set_eject_state;
2211 retro_get_eject_state_t get_eject_state;
2212
2213 retro_get_image_index_t get_image_index;
2214 retro_set_image_index_t set_image_index;
2215 retro_get_num_images_t get_num_images;
2216
2217 retro_replace_image_index_t replace_image_index;
2218 retro_add_image_index_t add_image_index;
2219};
38c2028e 2220
2221enum retro_pixel_format
2222{
eae1ae02
A
2223 /* 0RGB1555, native endian.
2224 * 0 bit must be set to 0.
2225 * This pixel format is default for compatibility concerns only.
2226 * If a 15/16-bit pixel format is desired, consider using RGB565. */
c19aba43
TK
2227 RETRO_PIXEL_FORMAT_0RGB1555 = 0,
2228
eae1ae02
A
2229 /* XRGB8888, native endian.
2230 * X bits are ignored. */
c19aba43
TK
2231 RETRO_PIXEL_FORMAT_XRGB8888 = 1,
2232
eae1ae02
A
2233 /* RGB565, native endian.
2234 * This pixel format is the recommended format to use if a 15/16-bit
6fbd15c8 2235 * format is desired as it is the pixel format that is typically
eae1ae02
A
2236 * available on a wide range of low-power devices.
2237 *
2238 * It is also natively supported in APIs like OpenGL ES. */
c19aba43
TK
2239 RETRO_PIXEL_FORMAT_RGB565 = 2,
2240
eae1ae02 2241 /* Ensure sizeof() == sizeof(int). */
c19aba43 2242 RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX
38c2028e 2243};
2244
2245struct retro_message
2246{
eae1ae02
A
2247 const char *msg; /* Message to be displayed. */
2248 unsigned frames; /* Duration in frames of message. */
38c2028e 2249};
2250
eae1ae02
A
2251/* Describes how the libretro implementation maps a libretro input bind
2252 * to its internal input system through a human readable string.
2253 * This string can be used to better let a user configure input. */
c19aba43
TK
2254struct retro_input_descriptor
2255{
eae1ae02 2256 /* Associates given parameters with a description. */
c19aba43
TK
2257 unsigned port;
2258 unsigned device;
2259 unsigned index;
2260 unsigned id;
2261
eae1ae02
A
2262 /* Human readable description for parameters.
2263 * The pointer must remain valid until
2264 * retro_unload_game() is called. */
6fbd15c8 2265 const char *description;
c19aba43
TK
2266};
2267
38c2028e 2268struct retro_system_info
2269{
6fbd15c8 2270 /* All pointers are owned by libretro implementation, and pointers must
eae1ae02
A
2271 * remain valid until retro_deinit() is called. */
2272
6fbd15c8 2273 const char *library_name; /* Descriptive name of library. Should not
eae1ae02
A
2274 * contain any version numbers, etc. */
2275 const char *library_version; /* Descriptive version of core. */
2276
6fbd15c8 2277 const char *valid_extensions; /* A string listing probably content
2278 * extensions the core will be able to
eae1ae02
A
2279 * load, separated with pipe.
2280 * I.e. "bin|rom|iso".
6fbd15c8 2281 * Typically used for a GUI to filter
eae1ae02
A
2282 * out extensions. */
2283
6fbd15c8 2284 /* Libretro cores that need to have direct access to their content
2285 * files, including cores which use the path of the content files to
2286 * determine the paths of other files, should set need_fullpath to true.
2287 *
2288 * Cores should strive for setting need_fullpath to false,
2289 * as it allows the frontend to perform patching, etc.
eae1ae02 2290 *
6fbd15c8 2291 * If need_fullpath is true and retro_load_game() is called:
2292 * - retro_game_info::path is guaranteed to have a valid path
2293 * - retro_game_info::data and retro_game_info::size are invalid
eae1ae02 2294 *
6fbd15c8 2295 * If need_fullpath is false and retro_load_game() is called:
2296 * - retro_game_info::path may be NULL
2297 * - retro_game_info::data and retro_game_info::size are guaranteed
2298 * to be valid
2299 *
2300 * See also:
2301 * - RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY
2302 * - RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY
2303 */
2304 bool need_fullpath;
eae1ae02 2305
6fbd15c8 2306 /* If true, the frontend is not allowed to extract any archives before
eae1ae02 2307 * loading the real content.
6fbd15c8 2308 * Necessary for certain libretro implementations that load games
eae1ae02 2309 * from zipped archives. */
6fbd15c8 2310 bool block_extract;
38c2028e 2311};
2312
2313struct retro_game_geometry
2314{
eae1ae02
A
2315 unsigned base_width; /* Nominal video width of game. */
2316 unsigned base_height; /* Nominal video height of game. */
2317 unsigned max_width; /* Maximum possible width of game. */
2318 unsigned max_height; /* Maximum possible height of game. */
2319
2320 float aspect_ratio; /* Nominal aspect ratio of game. If
2321 * aspect_ratio is <= 0.0, an aspect ratio
2322 * of base_width / base_height is assumed.
2323 * A frontend could override this setting,
2324 * if desired. */
38c2028e 2325};
2326
2327struct retro_system_timing
2328{
eae1ae02
A
2329 double fps; /* FPS of video content. */
2330 double sample_rate; /* Sampling rate of audio. */
38c2028e 2331};
2332
2333struct retro_system_av_info
2334{
2335 struct retro_game_geometry geometry;
2336 struct retro_system_timing timing;
2337};
2338
2339struct retro_variable
2340{
eae1ae02 2341 /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.
6fbd15c8 2342 * If NULL, obtains the complete environment string if more
eae1ae02 2343 * complex parsing is necessary.
6fbd15c8 2344 * The environment string is formatted as key-value pairs
eae1ae02
A
2345 * delimited by semicolons as so:
2346 * "key1=value1;key2=value2;..."
2347 */
2348 const char *key;
6fbd15c8 2349
eae1ae02
A
2350 /* Value to be obtained. If key does not exist, it is set to NULL. */
2351 const char *value;
38c2028e 2352};
2353
2354struct retro_game_info
2355{
eae1ae02 2356 const char *path; /* Path to game, UTF-8 encoded.
6fbd15c8 2357 * Sometimes used as a reference for building other paths.
2358 * May be NULL if game was loaded from stdin or similar,
2359 * but in this case some cores will be unable to load `data`.
2360 * So, it is preferable to fabricate something here instead
2361 * of passing NULL, which will help more cores to succeed.
2362 * retro_system_info::need_fullpath requires
eae1ae02 2363 * that this path is valid. */
6fbd15c8 2364 const void *data; /* Memory buffer of loaded game. Will be NULL
eae1ae02
A
2365 * if need_fullpath was set. */
2366 size_t size; /* Size of memory buffer. */
2367 const char *meta; /* String of implementation specific meta-data. */
38c2028e 2368};
2369
65a0505f
FJGG
2370#define RETRO_MEMORY_ACCESS_WRITE (1 << 0)
2371 /* The core will write to the buffer provided by retro_framebuffer::data. */
2372#define RETRO_MEMORY_ACCESS_READ (1 << 1)
2373 /* The core will read from retro_framebuffer::data. */
2374#define RETRO_MEMORY_TYPE_CACHED (1 << 0)
2375 /* The memory in data is cached.
2376 * If not cached, random writes and/or reading from the buffer is expected to be very slow. */
2377struct retro_framebuffer
2378{
2379 void *data; /* The framebuffer which the core can render into.
2380 Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER.
2381 The initial contents of data are unspecified. */
2382 unsigned width; /* The framebuffer width used by the core. Set by core. */
2383 unsigned height; /* The framebuffer height used by the core. Set by core. */
2384 size_t pitch; /* The number of bytes between the beginning of a scanline,
2385 and beginning of the next scanline.
2386 Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */
2387 enum retro_pixel_format format; /* The pixel format the core must use to render into data.
2388 This format could differ from the format used in
2389 SET_PIXEL_FORMAT.
2390 Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */
2391
2392 unsigned access_flags; /* How the core will access the memory in the framebuffer.
2393 RETRO_MEMORY_ACCESS_* flags.
2394 Set by core. */
2395 unsigned memory_flags; /* Flags telling core how the memory has been mapped.
2396 RETRO_MEMORY_TYPE_* flags.
2397 Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */
2398};
2399
eae1ae02
A
2400/* Callbacks */
2401
6fbd15c8 2402/* Environment callback. Gives implementations a way of performing
eae1ae02 2403 * uncommon tasks. Extensible. */
6fbd15c8 2404typedef bool (RETRO_CALLCONV *retro_environment_t)(unsigned cmd, void *data);
38c2028e 2405
6fbd15c8 2406/* Render a frame. Pixel format is 15-bit 0RGB1555 native endian
eae1ae02
A
2407 * unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
2408 *
2409 * Width and height specify dimensions of buffer.
2410 * Pitch specifices length in bytes between two lines in buffer.
2411 *
6fbd15c8 2412 * For performance reasons, it is highly recommended to have a frame
eae1ae02 2413 * that is packed in memory, i.e. pitch == width * byte_per_pixel.
6fbd15c8 2414 * Certain graphic APIs, such as OpenGL ES, do not like textures
eae1ae02
A
2415 * that are not packed in memory.
2416 */
6fbd15c8 2417typedef void (RETRO_CALLCONV *retro_video_refresh_t)(const void *data, unsigned width,
eae1ae02 2418 unsigned height, size_t pitch);
38c2028e 2419
6fbd15c8 2420/* Renders a single audio frame. Should only be used if implementation
eae1ae02
A
2421 * generates a single sample at a time.
2422 * Format is signed 16-bit native endian.
2423 */
6fbd15c8 2424typedef void (RETRO_CALLCONV *retro_audio_sample_t)(int16_t left, int16_t right);
38c2028e 2425
eae1ae02
A
2426/* Renders multiple audio frames in one go.
2427 *
2428 * One frame is defined as a sample of left and right channels, interleaved.
2429 * I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
2430 * Only one of the audio callbacks must ever be used.
2431 */
6fbd15c8 2432typedef size_t (RETRO_CALLCONV *retro_audio_sample_batch_t)(const int16_t *data,
eae1ae02
A
2433 size_t frames);
2434
2435/* Polls input. */
6fbd15c8 2436typedef void (RETRO_CALLCONV *retro_input_poll_t)(void);
38c2028e 2437
6fbd15c8 2438/* Queries for input for player 'port'. device will be masked with
eae1ae02
A
2439 * RETRO_DEVICE_MASK.
2440 *
6fbd15c8 2441 * Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that
eae1ae02
A
2442 * have been set with retro_set_controller_port_device()
2443 * will still use the higher level RETRO_DEVICE_JOYPAD to request input.
2444 */
6fbd15c8 2445typedef int16_t (RETRO_CALLCONV *retro_input_state_t)(unsigned port, unsigned device,
eae1ae02
A
2446 unsigned index, unsigned id);
2447
6fbd15c8 2448/* Sets callbacks. retro_set_environment() is guaranteed to be called
eae1ae02
A
2449 * before retro_init().
2450 *
6fbd15c8 2451 * The rest of the set_* functions are guaranteed to have been called
eae1ae02 2452 * before the first call to retro_run() is made. */
65a0505f
FJGG
2453RETRO_API void retro_set_environment(retro_environment_t);
2454RETRO_API void retro_set_video_refresh(retro_video_refresh_t);
2455RETRO_API void retro_set_audio_sample(retro_audio_sample_t);
2456RETRO_API void retro_set_audio_sample_batch(retro_audio_sample_batch_t);
2457RETRO_API void retro_set_input_poll(retro_input_poll_t);
2458RETRO_API void retro_set_input_state(retro_input_state_t);
38c2028e 2459
eae1ae02 2460/* Library global initialization/deinitialization. */
65a0505f
FJGG
2461RETRO_API void retro_init(void);
2462RETRO_API void retro_deinit(void);
38c2028e 2463
eae1ae02
A
2464/* Must return RETRO_API_VERSION. Used to validate ABI compatibility
2465 * when the API is revised. */
65a0505f 2466RETRO_API unsigned retro_api_version(void);
38c2028e 2467
6fbd15c8 2468/* Gets statically known system info. Pointers provided in *info
eae1ae02
A
2469 * must be statically allocated.
2470 * Can be called at any time, even before retro_init(). */
65a0505f 2471RETRO_API void retro_get_system_info(struct retro_system_info *info);
38c2028e 2472
eae1ae02
A
2473/* Gets information about system audio/video timings and geometry.
2474 * Can be called only after retro_load_game() has successfully completed.
6fbd15c8 2475 * NOTE: The implementation of this function might not initialize every
eae1ae02 2476 * variable if needed.
6fbd15c8 2477 * E.g. geom.aspect_ratio might not be initialized if core doesn't
eae1ae02 2478 * desire a particular aspect ratio. */
65a0505f 2479RETRO_API void retro_get_system_av_info(struct retro_system_av_info *info);
38c2028e 2480
eae1ae02 2481/* Sets device to be used for player 'port'.
6fbd15c8 2482 * By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all
eae1ae02 2483 * available ports.
6fbd15c8 2484 * Setting a particular device type is not a guarantee that libretro cores
2485 * will only poll input based on that particular device type. It is only a
2486 * hint to the libretro core when a core cannot automatically detect the
2487 * appropriate input device type on its own. It is also relevant when a
2488 * core can change its behavior depending on device type.
2489 *
2490 * As part of the core's implementation of retro_set_controller_port_device,
2491 * the core should call RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS to notify the
2492 * frontend if the descriptions for any controls have changed as a
2493 * result of changing the device type.
2494 */
65a0505f 2495RETRO_API void retro_set_controller_port_device(unsigned port, unsigned device);
38c2028e 2496
eae1ae02 2497/* Resets the current game. */
65a0505f 2498RETRO_API void retro_reset(void);
38c2028e 2499
eae1ae02
A
2500/* Runs the game for one video frame.
2501 * During retro_run(), input_poll callback must be called at least once.
6fbd15c8 2502 *
eae1ae02 2503 * If a frame is not rendered for reasons where a game "dropped" a frame,
6fbd15c8 2504 * this still counts as a frame, and retro_run() should explicitly dupe
eae1ae02
A
2505 * a frame if GET_CAN_DUPE returns true.
2506 * In this case, the video callback can take a NULL argument for data.
2507 */
65a0505f 2508RETRO_API void retro_run(void);
38c2028e 2509
6fbd15c8 2510/* Returns the amount of data the implementation requires to serialize
eae1ae02 2511 * internal state (save states).
6fbd15c8 2512 * Between calls to retro_load_game() and retro_unload_game(), the
2513 * returned size is never allowed to be larger than a previous returned
eae1ae02
A
2514 * value, to ensure that the frontend can allocate a save state buffer once.
2515 */
65a0505f 2516RETRO_API size_t retro_serialize_size(void);
38c2028e 2517
eae1ae02
A
2518/* Serializes internal state. If failed, or size is lower than
2519 * retro_serialize_size(), it should return false, true otherwise. */
65a0505f
FJGG
2520RETRO_API bool retro_serialize(void *data, size_t size);
2521RETRO_API bool retro_unserialize(const void *data, size_t size);
38c2028e 2522
65a0505f
FJGG
2523RETRO_API void retro_cheat_reset(void);
2524RETRO_API void retro_cheat_set(unsigned index, bool enabled, const char *code);
38c2028e 2525
6fbd15c8 2526/* Loads a game.
2527 * Return true to indicate successful loading and false to indicate load failure.
2528 */
65a0505f 2529RETRO_API bool retro_load_game(const struct retro_game_info *game);
38c2028e 2530
eae1ae02
A
2531/* Loads a "special" kind of game. Should not be used,
2532 * except in extreme cases. */
65a0505f 2533RETRO_API bool retro_load_game_special(
38c2028e 2534 unsigned game_type,
2535 const struct retro_game_info *info, size_t num_info
2536);
2537
6fbd15c8 2538/* Unloads the currently loaded game. Called before retro_deinit(void). */
65a0505f 2539RETRO_API void retro_unload_game(void);
38c2028e 2540
eae1ae02 2541/* Gets region of game. */
65a0505f 2542RETRO_API unsigned retro_get_region(void);
38c2028e 2543
eae1ae02 2544/* Gets region of memory. */
65a0505f
FJGG
2545RETRO_API void *retro_get_memory_data(unsigned id);
2546RETRO_API size_t retro_get_memory_size(unsigned id);
38c2028e 2547
2548#ifdef __cplusplus
2549}
2550#endif
2551
2552#endif