(iOS) Work around clang crash when compiling libpcsxcor/new_dynarec/pcsxmem.c.
[pcsx_rearmed.git] / frontend / libretro.h
CommitLineData
c40ab498 1/* Copyright (C) 2010-2013 The RetroArch team
2 *
3 * ---------------------------------------------------------------------------------------
4 * The following license statement only applies to this libretro API header (libretro.h).
5 * ---------------------------------------------------------------------------------------
6 *
7 * Permission is hereby granted, free of charge,
8 * to any person obtaining a copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation the rights to
10 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
11 * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
16 * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
19 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 */
22
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
c19aba43 30// Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant.
38c2028e 31#ifdef __cplusplus
32extern "C" {
33#else
c19aba43 34#if defined(_MSC_VER) && !defined(SN_TARGET_PS3) && !defined(__cplusplus)
38c2028e 35#define bool unsigned char
36#define true 1
37#define false 0
38#else
39#include <stdbool.h>
40#endif
41#endif
42
c19aba43 43// Used for checking API/ABI mismatches that can break libretro implementations.
23ea11bd 44// It is not incremented for compatible changes to the API.
38c2028e 45#define RETRO_API_VERSION 1
46
c19aba43 47// Libretro's fundamental device abstractions.
38c2028e 48#define RETRO_DEVICE_MASK 0xff
49#define RETRO_DEVICE_NONE 0
c19aba43
TK
50
51// The JOYPAD is called RetroPad. It is essentially a Super Nintendo controller,
52// but with additional L2/R2/L3/R3 buttons, similar to a PS1 DualShock.
38c2028e 53#define RETRO_DEVICE_JOYPAD 1
c19aba43
TK
54
55// The mouse is a simple mouse, similar to Super Nintendo's mouse.
56// X and Y coordinates are reported relatively to last poll (poll callback).
57// It is up to the libretro implementation to keep track of where the mouse pointer is supposed to be on the screen.
58// The frontend must make sure not to interfere with its own hardware mouse pointer.
38c2028e 59#define RETRO_DEVICE_MOUSE 2
c19aba43
TK
60
61// KEYBOARD device lets one poll for raw key pressed.
62// It is poll based, so input callback will return with the current pressed state.
38c2028e 63#define RETRO_DEVICE_KEYBOARD 3
c19aba43
TK
64
65// Lightgun X/Y coordinates are reported relatively to last poll, similar to mouse.
38c2028e 66#define RETRO_DEVICE_LIGHTGUN 4
c19aba43
TK
67
68// The ANALOG device is an extension to JOYPAD (RetroPad).
69// Similar to DualShock it adds two analog sticks.
70// This is treated as a separate device type as it returns values in the full analog range
71// of [-0x8000, 0x7fff]. Positive X axis is right. Positive Y axis is down.
72// Only use ANALOG type when polling for analog values of the axes.
38c2028e 73#define RETRO_DEVICE_ANALOG 5
74
23ea11bd 75// Abstracts the concept of a pointing mechanism, e.g. touch.
76// This allows libretro to query in absolute coordinates where on the screen a mouse (or something similar) is being placed.
77// For a touch centric device, coordinates reported are the coordinates of the press.
78//
79// Coordinates in X and Y are reported as:
80// [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen,
81// and 0x7fff corresponds to the far right/bottom of the screen.
82// The "screen" is here defined as area that is passed to the frontend and later displayed on the monitor.
83// The frontend is free to scale/resize this screen as it sees fit, however,
84// (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the game image, etc.
85//
86// To check if the pointer coordinates are valid (e.g. a touch display actually being touched),
87// PRESSED returns 1 or 0.
88// If using a mouse, PRESSED will usually correspond to the left mouse button.
89// PRESSED will only return 1 if the pointer is inside the game screen.
90//
91// For multi-touch, the index variable can be used to successively query more presses.
92// If index = 0 returns true for _PRESSED, coordinates can be extracted
93// with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with index = 1, and so on.
94// Eventually _PRESSED will return false for an index. No further presses are registered at this point.
95#define RETRO_DEVICE_POINTER 6
96
c40ab498 97// FIXME: Document this.
98#define RETRO_DEVICE_SENSOR_ACCELEROMETER 7
99
c19aba43
TK
100// These device types are specializations of the base types above.
101// They should only be used in retro_set_controller_type() to inform libretro implementations
102// about use of a very specific device type.
103//
104// In input state callback, however, only the base type should be used in the 'device' field.
38c2028e 105#define RETRO_DEVICE_JOYPAD_MULTITAP ((1 << 8) | RETRO_DEVICE_JOYPAD)
106#define RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE ((1 << 8) | RETRO_DEVICE_LIGHTGUN)
107#define RETRO_DEVICE_LIGHTGUN_JUSTIFIER ((2 << 8) | RETRO_DEVICE_LIGHTGUN)
108#define RETRO_DEVICE_LIGHTGUN_JUSTIFIERS ((3 << 8) | RETRO_DEVICE_LIGHTGUN)
109
c19aba43
TK
110// Buttons for the RetroPad (JOYPAD).
111// The placement of these is equivalent to placements on the Super Nintendo controller.
112// L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
38c2028e 113#define RETRO_DEVICE_ID_JOYPAD_B 0
114#define RETRO_DEVICE_ID_JOYPAD_Y 1
115#define RETRO_DEVICE_ID_JOYPAD_SELECT 2
116#define RETRO_DEVICE_ID_JOYPAD_START 3
117#define RETRO_DEVICE_ID_JOYPAD_UP 4
118#define RETRO_DEVICE_ID_JOYPAD_DOWN 5
119#define RETRO_DEVICE_ID_JOYPAD_LEFT 6
120#define RETRO_DEVICE_ID_JOYPAD_RIGHT 7
121#define RETRO_DEVICE_ID_JOYPAD_A 8
122#define RETRO_DEVICE_ID_JOYPAD_X 9
123#define RETRO_DEVICE_ID_JOYPAD_L 10
124#define RETRO_DEVICE_ID_JOYPAD_R 11
125#define RETRO_DEVICE_ID_JOYPAD_L2 12
126#define RETRO_DEVICE_ID_JOYPAD_R2 13
127#define RETRO_DEVICE_ID_JOYPAD_L3 14
128#define RETRO_DEVICE_ID_JOYPAD_R3 15
129
c19aba43 130// Index / Id values for ANALOG device.
38c2028e 131#define RETRO_DEVICE_INDEX_ANALOG_LEFT 0
132#define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1
133#define RETRO_DEVICE_ID_ANALOG_X 0
134#define RETRO_DEVICE_ID_ANALOG_Y 1
135
c19aba43 136// Id values for MOUSE.
38c2028e 137#define RETRO_DEVICE_ID_MOUSE_X 0
138#define RETRO_DEVICE_ID_MOUSE_Y 1
139#define RETRO_DEVICE_ID_MOUSE_LEFT 2
140#define RETRO_DEVICE_ID_MOUSE_RIGHT 3
141
c19aba43 142// Id values for LIGHTGUN types.
38c2028e 143#define RETRO_DEVICE_ID_LIGHTGUN_X 0
144#define RETRO_DEVICE_ID_LIGHTGUN_Y 1
145#define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2
146#define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3
147#define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4
148#define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5
149#define RETRO_DEVICE_ID_LIGHTGUN_START 6
150
23ea11bd 151// Id values for POINTER.
152#define RETRO_DEVICE_ID_POINTER_X 0
153#define RETRO_DEVICE_ID_POINTER_Y 1
154#define RETRO_DEVICE_ID_POINTER_PRESSED 2
155
c40ab498 156// Id values for SENSOR types.
157#define RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X 0
158#define RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y 1
159#define RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z 2
160
c19aba43 161// Returned from retro_get_region().
38c2028e 162#define RETRO_REGION_NTSC 0
163#define RETRO_REGION_PAL 1
164
c19aba43
TK
165// Passed to retro_get_memory_data/size().
166// If the memory type doesn't apply to the implementation NULL/0 can be returned.
38c2028e 167#define RETRO_MEMORY_MASK 0xff
c19aba43
TK
168
169// Regular save ram. This ram is usually found on a game cartridge, backed up by a battery.
170// If save game data is too complex for a single memory buffer,
171// the SYSTEM_DIRECTORY environment callback can be used.
38c2028e 172#define RETRO_MEMORY_SAVE_RAM 0
c19aba43
TK
173
174// Some games have a built-in clock to keep track of time.
175// This memory is usually just a couple of bytes to keep track of time.
38c2028e 176#define RETRO_MEMORY_RTC 1
c19aba43
TK
177
178// System ram lets a frontend peek into a game systems main RAM.
38c2028e 179#define RETRO_MEMORY_SYSTEM_RAM 2
c19aba43
TK
180
181// Video ram lets a frontend peek into a game systems video RAM (VRAM).
38c2028e 182#define RETRO_MEMORY_VIDEO_RAM 3
183
c19aba43 184// Special memory types.
38c2028e 185#define RETRO_MEMORY_SNES_BSX_RAM ((1 << 8) | RETRO_MEMORY_SAVE_RAM)
186#define RETRO_MEMORY_SNES_BSX_PRAM ((2 << 8) | RETRO_MEMORY_SAVE_RAM)
187#define RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM ((3 << 8) | RETRO_MEMORY_SAVE_RAM)
188#define RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM ((4 << 8) | RETRO_MEMORY_SAVE_RAM)
189#define RETRO_MEMORY_SNES_GAME_BOY_RAM ((5 << 8) | RETRO_MEMORY_SAVE_RAM)
190#define RETRO_MEMORY_SNES_GAME_BOY_RTC ((6 << 8) | RETRO_MEMORY_RTC)
191
c19aba43
TK
192// Special game types passed into retro_load_game_special().
193// Only used when multiple ROMs are required.
38c2028e 194#define RETRO_GAME_TYPE_BSX 0x101
195#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102
196#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103
197#define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104
198
c19aba43
TK
199// Keysyms used for ID in input state callback when polling RETRO_KEYBOARD.
200enum retro_key
201{
202 RETROK_UNKNOWN = 0,
203 RETROK_FIRST = 0,
204 RETROK_BACKSPACE = 8,
205 RETROK_TAB = 9,
206 RETROK_CLEAR = 12,
207 RETROK_RETURN = 13,
208 RETROK_PAUSE = 19,
209 RETROK_ESCAPE = 27,
210 RETROK_SPACE = 32,
211 RETROK_EXCLAIM = 33,
212 RETROK_QUOTEDBL = 34,
213 RETROK_HASH = 35,
214 RETROK_DOLLAR = 36,
215 RETROK_AMPERSAND = 38,
216 RETROK_QUOTE = 39,
217 RETROK_LEFTPAREN = 40,
218 RETROK_RIGHTPAREN = 41,
219 RETROK_ASTERISK = 42,
220 RETROK_PLUS = 43,
221 RETROK_COMMA = 44,
222 RETROK_MINUS = 45,
223 RETROK_PERIOD = 46,
224 RETROK_SLASH = 47,
225 RETROK_0 = 48,
226 RETROK_1 = 49,
227 RETROK_2 = 50,
228 RETROK_3 = 51,
229 RETROK_4 = 52,
230 RETROK_5 = 53,
231 RETROK_6 = 54,
232 RETROK_7 = 55,
233 RETROK_8 = 56,
234 RETROK_9 = 57,
235 RETROK_COLON = 58,
236 RETROK_SEMICOLON = 59,
237 RETROK_LESS = 60,
238 RETROK_EQUALS = 61,
239 RETROK_GREATER = 62,
240 RETROK_QUESTION = 63,
241 RETROK_AT = 64,
242 RETROK_LEFTBRACKET = 91,
243 RETROK_BACKSLASH = 92,
244 RETROK_RIGHTBRACKET = 93,
245 RETROK_CARET = 94,
246 RETROK_UNDERSCORE = 95,
247 RETROK_BACKQUOTE = 96,
248 RETROK_a = 97,
249 RETROK_b = 98,
250 RETROK_c = 99,
251 RETROK_d = 100,
252 RETROK_e = 101,
253 RETROK_f = 102,
254 RETROK_g = 103,
255 RETROK_h = 104,
256 RETROK_i = 105,
257 RETROK_j = 106,
258 RETROK_k = 107,
259 RETROK_l = 108,
260 RETROK_m = 109,
261 RETROK_n = 110,
262 RETROK_o = 111,
263 RETROK_p = 112,
264 RETROK_q = 113,
265 RETROK_r = 114,
266 RETROK_s = 115,
267 RETROK_t = 116,
268 RETROK_u = 117,
269 RETROK_v = 118,
270 RETROK_w = 119,
271 RETROK_x = 120,
272 RETROK_y = 121,
273 RETROK_z = 122,
274 RETROK_DELETE = 127,
275
276 RETROK_KP0 = 256,
277 RETROK_KP1 = 257,
278 RETROK_KP2 = 258,
279 RETROK_KP3 = 259,
280 RETROK_KP4 = 260,
281 RETROK_KP5 = 261,
282 RETROK_KP6 = 262,
283 RETROK_KP7 = 263,
284 RETROK_KP8 = 264,
285 RETROK_KP9 = 265,
286 RETROK_KP_PERIOD = 266,
287 RETROK_KP_DIVIDE = 267,
288 RETROK_KP_MULTIPLY = 268,
289 RETROK_KP_MINUS = 269,
290 RETROK_KP_PLUS = 270,
291 RETROK_KP_ENTER = 271,
292 RETROK_KP_EQUALS = 272,
293
294 RETROK_UP = 273,
295 RETROK_DOWN = 274,
296 RETROK_RIGHT = 275,
297 RETROK_LEFT = 276,
298 RETROK_INSERT = 277,
299 RETROK_HOME = 278,
300 RETROK_END = 279,
301 RETROK_PAGEUP = 280,
302 RETROK_PAGEDOWN = 281,
303
304 RETROK_F1 = 282,
305 RETROK_F2 = 283,
306 RETROK_F3 = 284,
307 RETROK_F4 = 285,
308 RETROK_F5 = 286,
309 RETROK_F6 = 287,
310 RETROK_F7 = 288,
311 RETROK_F8 = 289,
312 RETROK_F9 = 290,
313 RETROK_F10 = 291,
314 RETROK_F11 = 292,
315 RETROK_F12 = 293,
316 RETROK_F13 = 294,
317 RETROK_F14 = 295,
318 RETROK_F15 = 296,
319
320 RETROK_NUMLOCK = 300,
321 RETROK_CAPSLOCK = 301,
322 RETROK_SCROLLOCK = 302,
323 RETROK_RSHIFT = 303,
324 RETROK_LSHIFT = 304,
325 RETROK_RCTRL = 305,
326 RETROK_LCTRL = 306,
327 RETROK_RALT = 307,
328 RETROK_LALT = 308,
329 RETROK_RMETA = 309,
330 RETROK_LMETA = 310,
331 RETROK_LSUPER = 311,
332 RETROK_RSUPER = 312,
333 RETROK_MODE = 313,
334 RETROK_COMPOSE = 314,
335
336 RETROK_HELP = 315,
337 RETROK_PRINT = 316,
338 RETROK_SYSREQ = 317,
339 RETROK_BREAK = 318,
340 RETROK_MENU = 319,
341 RETROK_POWER = 320,
342 RETROK_EURO = 321,
343 RETROK_UNDO = 322,
344
23ea11bd 345 RETROK_LAST,
346
347 RETROK_DUMMY = INT_MAX // Ensure sizeof(enum) == sizeof(int)
348};
349
350enum retro_mod
351{
352 RETROKMOD_NONE = 0x0000,
353
354 RETROKMOD_SHIFT = 0x01,
355 RETROKMOD_CTRL = 0x02,
356 RETROKMOD_ALT = 0x04,
357 RETROKMOD_META = 0x08,
358
359 RETROKMOD_NUMLOCK = 0x10,
360 RETROKMOD_CAPSLOCK = 0x20,
361 RETROKMOD_SCROLLOCK = 0x40,
362
363 RETROKMOD_DUMMY = INT_MAX // Ensure sizeof(enum) == sizeof(int)
c19aba43 364};
38c2028e 365
72f68e8c 366// If set, this call is not part of the public libretro API yet. It can change or be removed at any time.
367#define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000
c40ab498 368// Environment callback to be used internally in frontend.
369#define RETRO_ENVIRONMENT_PRIVATE 0x20000
23ea11bd 370
38c2028e 371// Environment commands.
372#define RETRO_ENVIRONMENT_SET_ROTATION 1 // const unsigned * --
373 // Sets screen rotation of graphics.
374 // Is only implemented if rotation can be accelerated by hardware.
375 // Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180, 270 degrees
376 // counter-clockwise respectively.
377 //
378#define RETRO_ENVIRONMENT_GET_OVERSCAN 2 // bool * --
379 // Boolean value whether or not the implementation should use overscan, or crop away overscan.
380 //
381#define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 // bool * --
c19aba43 382 // Boolean value whether or not frontend supports frame duping,
38c2028e 383 // passing NULL to video frame callback.
384 //
72f68e8c 385// Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES), and reserved to avoid possible ABI clash.
38c2028e 386#define RETRO_ENVIRONMENT_SET_MESSAGE 6 // const struct retro_message * --
387 // Sets a message to be displayed in implementation-specific manner for a certain amount of 'frames'.
388 // Should not be used for trivial messages, which should simply be logged to stderr.
389#define RETRO_ENVIRONMENT_SHUTDOWN 7 // N/A (NULL) --
390 // Requests the frontend to shutdown.
391 // Should only be used if game has a specific
392 // way to shutdown the game from a menu item or similar.
393 //
394#define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8
395 // const unsigned * --
396 // Gives a hint to the frontend how demanding this implementation
397 // is on a system. E.g. reporting a level of 2 means
398 // this implementation should run decently on all frontends
399 // of level 2 and up.
400 //
401 // It can be used by the frontend to potentially warn
402 // about too demanding implementations.
23ea11bd 403 //
38c2028e 404 // The levels are "floating", but roughly defined as:
c19aba43
TK
405 // 0: Low-powered embedded devices such as Raspberry Pi
406 // 1: 6th generation consoles, such as Wii/Xbox 1, and phones, tablets, etc.
407 // 2: 7th generation consoles, such as PS3/360, with sub-par CPUs.
38c2028e 408 // 3: Modern desktop/laptops with reasonably powerful CPUs.
409 // 4: High-end desktops with very powerful CPUs.
410 //
411 // This function can be called on a per-game basis,
412 // as certain games an implementation can play might be
413 // particularily demanding.
414 // If called, it should be called in retro_load_game().
415 //
416#define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
417 // const char ** --
418 // Returns the "system" directory of the frontend.
419 // This directory can be used to store system specific ROMs such as BIOSes, configuration data, etc.
420 // The returned value can be NULL.
421 // If so, no such directory is defined,
422 // and it's up to the implementation to find a suitable directory.
423 //
424#define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
425 // const enum retro_pixel_format * --
426 // Sets the internal pixel format used by the implementation.
c19aba43
TK
427 // The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555.
428 // This pixel format however, is deprecated (see enum retro_pixel_format).
38c2028e 429 // If the call returns false, the frontend does not support this pixel format.
430 // This function should be called inside retro_load_game() or retro_get_system_av_info().
c19aba43
TK
431 //
432#define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11
433 // const struct retro_input_descriptor * --
434 // Sets an array of retro_input_descriptors.
435 // It is up to the frontend to present this in a usable way.
436 // The array is terminated by retro_input_descriptor::description being set to NULL.
437 // This function can be called at any time, but it is recommended to call it as early as possible.
23ea11bd 438#define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12
439 // const struct retro_keyboard_callback * --
440 // Sets a callback function used to notify core about keyboard events.
441 //
442#define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13
443 // const struct retro_disk_control_callback * --
444 // Sets an interface which frontend can use to eject and insert disk images.
445 // This is used for games which consist of multiple images and must be manually
446 // swapped out by the user (e.g. PSX).
c40ab498 447#define RETRO_ENVIRONMENT_SET_HW_RENDER 14
72f68e8c 448 // struct retro_hw_render_callback * --
72f68e8c 449 // Sets an interface to let a libretro core render with hardware acceleration.
450 // Should be called in retro_load_game().
451 // If successful, libretro cores will be able to render to a frontend-provided framebuffer.
452 // The size of this framebuffer will be at least as large as max_width/max_height provided in get_av_info().
453 // If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or NULL to retro_video_refresh_t.
454#define RETRO_ENVIRONMENT_GET_VARIABLE 15
455 // struct retro_variable * --
c40ab498 456 // Interface to acquire user-defined information from environment
72f68e8c 457 // that cannot feasibly be supported in a multi-system way.
458 // 'key' should be set to a key which has already been set by SET_VARIABLES.
459 // 'data' will be set to a value or NULL.
460 //
461#define RETRO_ENVIRONMENT_SET_VARIABLES 16
462 // const struct retro_variable * --
463 // Allows an implementation to signal the environment
464 // which variables it might want to check for later using GET_VARIABLE.
465 // This allows the frontend to present these variables to a user dynamically.
466 // This should be called as early as possible (ideally in retro_set_environment).
467 //
468 // 'data' points to an array of retro_variable structs terminated by a { NULL, NULL } element.
469 // retro_variable::key should be namespaced to not collide with other implementations' keys. E.g. A core called 'foo' should use keys named as 'foo_option'.
470 // retro_variable::value should contain a human readable description of the key as well as a '|' delimited list of expected values.
471 // The number of possible options should be very limited, i.e. it should be feasible to cycle through options without a keyboard.
472 // First entry should be treated as a default.
473 //
474 // Example entry:
475 // { "foo_option", "Speed hack coprocessor X; false|true" }
476 //
477 // Text before first ';' is description. This ';' must be followed by a space, and followed by a list of possible values split up with '|'.
478 // Only strings are operated on. The possible values will generally be displayed and stored as-is by the frontend.
479 //
480#define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17
481 // bool * --
482 // Result is set to true if some variables are updated by
483 // frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE.
484 // Variables should be queried with GET_VARIABLE.
e268a47e 485 //
486#define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18
487 // const bool * --
488 // If true, the libretro implementation supports calls to retro_load_game() with NULL as argument.
489 // Used by cores which can run without particular game data.
490 // This should be called within retro_set_environment() only.
c40ab498 491 //
492#define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19
493 // const char ** --
494 // Retrieves the absolute path from where this libretro implementation was loaded.
495 // NULL is returned if the libretro was loaded statically (i.e. linked statically to frontend), or if the path cannot be determined.
496 // Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can be loaded without ugly hacks.
497 //
498 //
499// Environment 20 was an obsolete version of SET_AUDIO_CALLBACK. It was not used by any known core at the time,
500// and was removed from the API.
501#define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22
502 // const struct retro_audio_callback * --
503 // Sets an interface which is used to notify a libretro core about audio being available for writing.
504 // The callback can be called from any thread, so a core using this must have a thread safe audio implementation.
505 // It is intended for games where audio and video are completely asynchronous and audio can be generated on the fly.
506 // This interface is not recommended for use with emulators which have highly synchronous audio.
507 //
508 // The callback only notifies about writability; the libretro core still has to call the normal audio callbacks
509 // to write audio. The audio callbacks must be called from within the notification callback.
510 // The amount of audio data to write is up to the implementation.
511 // Generally, the audio callback will be called continously in a loop.
512 //
513 // Due to thread safety guarantees and lack of sync between audio and video, a frontend
514 // can selectively disallow this interface based on internal configuration. A core using
515 // this interface must also implement the "normal" audio interface.
516 //
517 // A libretro core using SET_AUDIO_CALLBACK should also make use of SET_FRAME_TIME_CALLBACK.
518#define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21
519 // const struct retro_frame_time_callback * --
520 // Lets the core know how much time has passed since last invocation of retro_run().
521 // The frontend can tamper with the timing to fake fast-forward, slow-motion, frame stepping, etc.
522 // In this case the delta time will use the reference value in frame_time_callback..
523 //
524#define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23
525 // struct retro_rumble_interface * --
526 // Gets an interface which is used by a libretro core to set state of rumble motors in controllers.
527 // A strong and weak motor is supported, and they can be controlled indepedently.
528 //
529#define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24
530 // uint64_t * --
531 // Gets a bitmask telling which device type are expected to be handled properly in a call to retro_input_state_t.
532 // Devices which are not handled or recognized always return 0 in retro_input_state_t.
533 // Example bitmask: caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG).
534 // Should only be called in retro_run().
535 //
536#define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL)
537 // struct retro_sensor_interface * --
538 // Gets access to the sensor interface.
539 // The purpose of this interface is to allow
540 // setting state related to sensors such as polling rate, enabling/disable it entirely, etc.
541 // Reading sensor state is done via the normal input_state_callback API.
542 //
543#define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL)
544 // struct retro_camera_callback * --
545 // Gets an interface to a video camera driver.
546 // A libretro core can use this interface to get access to a video camera.
547 // New video frames are delivered in a callback in same thread as retro_run().
548 //
549 // GET_CAMERA_INTERFACE should be called in retro_load_game().
550 //
551 // Depending on the camera implementation used, camera frames will be delivered as a raw framebuffer,
552 // or as an OpenGL texture directly.
553 //
554 // The core has to tell the frontend here which types of buffers can be handled properly.
555 // An OpenGL texture can only be handled when using a libretro GL core (SET_HW_RENDER).
556 // It is recommended to use a libretro GL core when using camera interface.
557 //
558 // The camera is not started automatically. The retrieved start/stop functions must be used to explicitly
559 // start and stop the camera driver.
560 //
561#define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27
562 // struct retro_log_callback * --
563 // Gets an interface for logging. This is useful for logging in a cross-platform way
564 // as certain platforms cannot use use stderr for logging. It also allows the frontend to
565 // show logging information in a more suitable way.
566 // If this interface is not used, libretro cores should log to stderr as desired.
567#define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28
568 // struct retro_perf_callback * --
569 // Gets an interface for performance counters. This is useful for performance logging in a
570 // cross-platform way and for detecting architecture-specific features, such as SIMD support.
571
572enum retro_log_level
573{
574 RETRO_LOG_DEBUG = 0,
575 RETRO_LOG_INFO,
576 RETRO_LOG_WARN,
577 RETRO_LOG_ERROR,
578
579 RETRO_LOG_DUMMY = INT_MAX
580};
581
582// Logging function. Takes log level argument as well.
583typedef void (*retro_log_printf_t)(enum retro_log_level level, const char *fmt, ...);
584
585struct retro_log_callback
586{
587 retro_log_printf_t log;
588};
589
590// Performance related functions
591//
592// ID values for SIMD CPU features
593#define RETRO_SIMD_SSE (1 << 0)
594#define RETRO_SIMD_SSE2 (1 << 1)
595#define RETRO_SIMD_VMX (1 << 2)
596#define RETRO_SIMD_VMX128 (1 << 3)
597#define RETRO_SIMD_AVX (1 << 4)
598#define RETRO_SIMD_NEON (1 << 5)
599#define RETRO_SIMD_SSE3 (1 << 6)
600#define RETRO_SIMD_SSSE3 (1 << 7)
601
602typedef uint64_t retro_perf_tick_t;
603typedef int64_t retro_time_t;
604
605struct retro_perf_counter
606{
607 const char *ident;
608 retro_perf_tick_t start;
609 retro_perf_tick_t total;
610 retro_perf_tick_t call_cnt;
611
612 bool registered;
613};
614
615// Returns current time in microseconds. Tries to use the most accurate timer available.
616typedef retro_time_t (*retro_perf_get_time_usec_t)(void);
617// A simple counter. Usually nanoseconds, but can also be CPU cycles.
618// Can be used directly if desired (when creating a more sophisticated performance counter system).
619typedef retro_perf_tick_t (*retro_perf_get_counter_t)(void);
620// Returns a bit-mask of detected CPU features (RETRO_SIMD_*).
621typedef uint64_t (*retro_get_cpu_features_t)(void);
622// Asks frontend to log and/or display the state of performance counters.
623// Performance counters can always be poked into manually as well.
624typedef void (*retro_perf_log_t)(void);
625// Register a performance counter.
626// ident field must be set with a discrete value and other values in retro_perf_counter must be 0.
627// Registering can be called multiple times. To avoid calling to frontend redundantly, you can check registered field first.
628typedef void (*retro_perf_register_t)(struct retro_perf_counter *counter);
629// Starts and stops a registered counter.
630typedef void (*retro_perf_start_t)(struct retro_perf_counter *counter);
631typedef void (*retro_perf_stop_t)(struct retro_perf_counter *counter);
632
633// For convenience it can be useful to wrap register, start and stop in macros.
634// E.g.:
635// #ifdef LOG_PERFORMANCE
636// #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
637// #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
638// #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
639// #else
640// ... Blank macros ...
641// #endif
642// These can then be used mid-functions around code snippets.
643//
644// extern struct retro_perf_callback perf_cb; // Somewhere in the core.
645//
646// void do_some_heavy_work(void)
647// {
648// RETRO_PERFORMANCE_INIT(cb, work_1);
649// RETRO_PERFORMANCE_START(cb, work_1);
650// heavy_work_1();
651// RETRO_PERFORMANCE_STOP(cb, work_1);
652//
653// RETRO_PERFORMANCE_INIT(cb, work_2);
654// RETRO_PERFORMANCE_START(cb, work_2);
655// heavy_work_2();
656// RETRO_PERFORMANCE_STOP(cb, work_2);
657// }
658//
659// void retro_deinit(void)
660// {
661// perf_cb.perf_log(); // Log all perf counters here for example.
662// }
663
664struct retro_perf_callback
665{
666 retro_perf_get_time_usec_t get_time_usec;
667 retro_get_cpu_features_t get_cpu_features;
668
669 retro_perf_get_counter_t get_perf_counter;
670 retro_perf_register_t perf_register;
671 retro_perf_start_t perf_start;
672 retro_perf_stop_t perf_stop;
673 retro_perf_log_t perf_log;
674};
675
676// FIXME: Document the sensor API and work out behavior.
677// It will be marked as experimental until then.
678enum retro_sensor_action
679{
680 RETRO_SENSOR_ACCELEROMETER_ENABLE = 0,
681 RETRO_SENSOR_ACCELEROMETER_DISABLE,
682
683 RETRO_SENSOR_DUMMY = INT_MAX
684};
685
686typedef bool (*retro_set_sensor_state_t)(unsigned port, enum retro_sensor_action action, unsigned rate);
687struct retro_sensor_interface
688{
689 retro_set_sensor_state_t set_sensor_state;
690};
691////
692
693enum retro_camera_buffer
694{
695 RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0,
696 RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER,
697
698 RETRO_CAMERA_BUFFER_DUMMY = INT_MAX
699};
700
701// Starts the camera driver. Can only be called in retro_run().
702typedef bool (*retro_camera_start_t)(void);
703// Stops the camera driver. Can only be called in retro_run().
704typedef void (*retro_camera_stop_t)(void);
705// Callback which signals when the camera driver is initialized and/or deinitialized.
706// retro_camera_start_t can be called in initialized callback.
707typedef void (*retro_camera_lifetime_status_t)(void);
708// A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
709// Width, height and pitch are similar to retro_video_refresh_t.
710// First pixel is top-left origin.
711typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer, unsigned width, unsigned height, size_t pitch);
712// A callback for when OpenGL textures are used.
713//
714// texture_id is a texture owned by camera driver.
715// Its state or content should be considered immutable, except for things like texture filtering and clamping.
716//
717// texture_target is the texture target for the GL texture.
718// These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly more depending on extensions.
719//
720// affine points to a packed 3x3 column-major matrix used to apply an affine transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
721// After transform, normalized texture coord (0, 0) should be bottom-left and (1, 1) should be top-right (or (width, height) for RECTANGLE).
722//
723// GL-specific typedefs are avoided here to avoid relying on gl.h in the API definition.
724typedef void (*retro_camera_frame_opengl_texture_t)(unsigned texture_id, unsigned texture_target, const float *affine);
725struct retro_camera_callback
726{
727 uint64_t caps; // Set by libretro core. Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER).
728
729 unsigned width; // Desired resolution for camera. Is only used as a hint.
730 unsigned height;
731 retro_camera_start_t start; // Set by frontend.
732 retro_camera_stop_t stop; // Set by frontend.
733
734 retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer; // Set by libretro core if raw framebuffer callbacks will be used.
735 retro_camera_frame_opengl_texture_t frame_opengl_texture; // Set by libretro core if OpenGL texture callbacks will be used.
736
737 // Set by libretro core. Called after camera driver is initialized and ready to be started.
738 // Can be NULL, in which this callback is not called.
739 retro_camera_lifetime_status_t initialized;
740
741 // Set by libretro core. Called right before camera driver is deinitialized.
742 // Can be NULL, in which this callback is not called.
743 retro_camera_lifetime_status_t deinitialized;
744};
745
746enum retro_rumble_effect
747{
748 RETRO_RUMBLE_STRONG = 0,
749 RETRO_RUMBLE_WEAK = 1,
750
751 RETRO_RUMBLE_DUMMY = INT_MAX
752};
753
754// Sets rumble state for joypad plugged in port 'port'. Rumble effects are controlled independently,
755// and setting e.g. strong rumble does not override weak rumble.
756// Strength has a range of [0, 0xffff].
757//
758// Returns true if rumble state request was honored. Calling this before first retro_run() is likely to return false.
759typedef bool (*retro_set_rumble_state_t)(unsigned port, enum retro_rumble_effect effect, uint16_t strength);
760struct retro_rumble_interface
761{
762 retro_set_rumble_state_t set_rumble_state;
763};
764
765// Notifies libretro that audio data should be written.
766typedef void (*retro_audio_callback_t)(void);
767
768// True: Audio driver in frontend is active, and callback is expected to be called regularily.
769// False: Audio driver in frontend is paused or inactive. Audio callback will not be called until set_state has been called with true.
770// Initial state is false (inactive).
771typedef void (*retro_audio_set_state_callback_t)(bool enabled);
772struct retro_audio_callback
773{
774 retro_audio_callback_t callback;
775 retro_audio_set_state_callback_t set_state;
776};
777
778// Notifies a libretro core of time spent since last invocation of retro_run() in microseconds.
779// It will be called right before retro_run() every frame.
780// The frontend can tamper with timing to support cases like fast-forward, slow-motion and framestepping.
781// In those scenarios the reference frame time value will be used.
782typedef int64_t retro_usec_t;
783typedef void (*retro_frame_time_callback_t)(retro_usec_t usec);
784struct retro_frame_time_callback
785{
786 retro_frame_time_callback_t callback;
787 retro_usec_t reference; // Represents the time of one frame. It is computed as 1000000 / fps, but the implementation will resolve the rounding to ensure that framestepping, etc is exact.
788};
72f68e8c 789
790// Pass this to retro_video_refresh_t if rendering to hardware.
791// Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
792#define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)
793
794// Invalidates the current HW context.
c40ab498 795// Any GL state is lost, and must not be deinitialized explicitly. If explicit deinitialization is desired by the libretro core,
796// it should implement context_destroy callback.
72f68e8c 797// If called, all GPU resources must be reinitialized.
798// Usually called when frontend reinits video driver.
799// Also called first time video driver is initialized, allowing libretro core to init resources.
800typedef void (*retro_hw_context_reset_t)(void);
801// Gets current framebuffer which is to be rendered to. Could change every frame potentially.
802typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void);
803
804// Get a symbol from HW context.
805typedef void (*retro_proc_address_t)(void);
806typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym);
807
808enum retro_hw_context_type
809{
810 RETRO_HW_CONTEXT_NONE = 0,
c40ab498 811 RETRO_HW_CONTEXT_OPENGL, // OpenGL 2.x. Latest version available before 3.x+. Driver can choose to use latest compatibility context.
72f68e8c 812 RETRO_HW_CONTEXT_OPENGLES2, // GLES 2.0
c40ab498 813 RETRO_HW_CONTEXT_OPENGL_CORE, // Modern desktop core GL context. Use major/minor fields to set GL version.
814 RETRO_HW_CONTEXT_OPENGLES3, // GLES 3.0
72f68e8c 815
816 RETRO_HW_CONTEXT_DUMMY = INT_MAX
817};
23ea11bd 818
72f68e8c 819struct retro_hw_render_callback
820{
821 enum retro_hw_context_type context_type; // Which API to use. Set by libretro core.
c40ab498 822 retro_hw_context_reset_t context_reset; // Called when a context has been created or when it has been reset.
72f68e8c 823 retro_hw_get_current_framebuffer_t get_current_framebuffer; // Set by frontend.
824 retro_hw_get_proc_address_t get_proc_address; // Set by frontend.
825 bool depth; // Set if render buffers should have depth component attached.
c40ab498 826 bool stencil; // Set if stencil buffers should be attached.
827 // If depth and stencil are true, a packed 24/8 buffer will be added. Only attaching stencil is invalid and will be ignored.
828 bool bottom_left_origin; // Use conventional bottom-left origin convention. Is false, standard libretro top-left origin semantics are used.
829 unsigned version_major; // Major version number for core GL context.
830 unsigned version_minor; // Minor version number for core GL context.
831
832 bool cache_context; // If this is true, the frontend will go very far to avoid resetting context in scenarios like toggling fullscreen, etc.
833 // The reset callback might still be called in extreme situations such as if the context is lost beyond recovery.
834 // For optimal stability, set this to false, and allow context to be reset at any time.
835 retro_hw_context_reset_t context_destroy; // A callback to be called before the context is destroyed. Resources can be deinitialized at this step. This can be set to NULL, in which resources will just be destroyed without any notification.
836 bool debug_context; // Creates a debug context.
72f68e8c 837};
c19aba43 838
23ea11bd 839// Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. Called by the frontend in response to keyboard events.
840// down is set if the key is being pressed, or false if it is being released.
841// keycode is the RETROK value of the char.
842// character is the text character of the pressed key. (UTF-32).
843// key_modifiers is a set of RETROKMOD values or'ed together.
c40ab498 844//
845// The pressed/keycode state can be indepedent of the character.
846// It is also possible that multiple characters are generated from a single keypress.
847// Keycode events should be treated separately from character events.
848// However, when possible, the frontend should try to synchronize these.
849// If only a character is posted, keycode should be RETROK_UNKNOWN.
850// Similarily if only a keycode event is generated with no corresponding character, character should be 0.
23ea11bd 851typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
852
853struct retro_keyboard_callback
854{
e268a47e 855 retro_keyboard_event_t callback;
23ea11bd 856};
857
858// Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
859// Should be set for implementations which can swap out multiple disk images in runtime.
860// If the implementation can do this automatically, it should strive to do so.
861// However, there are cases where the user must manually do so.
862//
863// Overview: To swap a disk image, eject the disk image with set_eject_state(true).
864// Set the disk index with set_image_index(index). Insert the disk again with set_eject_state(false).
865
866// If ejected is true, "ejects" the virtual disk tray.
867// When ejected, the disk image index can be set.
868typedef bool (*retro_set_eject_state_t)(bool ejected);
869// Gets current eject state. The initial state is 'not ejected'.
870typedef bool (*retro_get_eject_state_t)(void);
871// Gets current disk index. First disk is index 0.
872// If return value is >= get_num_images(), no disk is currently inserted.
873typedef unsigned (*retro_get_image_index_t)(void);
874// Sets image index. Can only be called when disk is ejected.
875// The implementation supports setting "no disk" by using an index >= get_num_images().
876typedef bool (*retro_set_image_index_t)(unsigned index);
877// Gets total number of images which are available to use.
878typedef unsigned (*retro_get_num_images_t)(void);
879//
880// Replaces the disk image associated with index.
881// Arguments to pass in info have same requirements as retro_load_game().
882// Virtual disk tray must be ejected when calling this.
883// Replacing a disk image with info = NULL will remove the disk image from the internal list.
884// As a result, calls to get_image_index() can change.
885//
886// E.g. replace_image_index(1, NULL), and previous get_image_index() returned 4 before.
887// Index 1 will be removed, and the new index is 3.
888struct retro_game_info;
889typedef bool (*retro_replace_image_index_t)(unsigned index, const struct retro_game_info *info);
890// Adds a new valid index (get_num_images()) to the internal disk list.
891// This will increment subsequent return values from get_num_images() by 1.
892// This image index cannot be used until a disk image has been set with replace_image_index.
893typedef bool (*retro_add_image_index_t)(void);
894
895struct retro_disk_control_callback
896{
897 retro_set_eject_state_t set_eject_state;
898 retro_get_eject_state_t get_eject_state;
899
900 retro_get_image_index_t get_image_index;
901 retro_set_image_index_t set_image_index;
902 retro_get_num_images_t get_num_images;
903
904 retro_replace_image_index_t replace_image_index;
905 retro_add_image_index_t add_image_index;
906};
38c2028e 907
908enum retro_pixel_format
909{
c19aba43
TK
910 // 0RGB1555, native endian. 0 bit must be set to 0.
911 // This pixel format is default for compatibility concerns only.
912 // If a 15/16-bit pixel format is desired, consider using RGB565.
913 RETRO_PIXEL_FORMAT_0RGB1555 = 0,
914
915 // XRGB8888, native endian. X bits are ignored.
916 RETRO_PIXEL_FORMAT_XRGB8888 = 1,
917
918 // RGB565, native endian. This pixel format is the recommended format to use if a 15/16-bit format is desired
919 // as it is the pixel format that is typically available on a wide range of low-power devices.
920 // It is also natively supported in APIs like OpenGL ES.
921 RETRO_PIXEL_FORMAT_RGB565 = 2,
922
923 // Ensure sizeof() == sizeof(int).
924 RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX
38c2028e 925};
926
927struct retro_message
928{
929 const char *msg; // Message to be displayed.
930 unsigned frames; // Duration in frames of message.
931};
932
c19aba43
TK
933// Describes how the libretro implementation maps a libretro input bind
934// to its internal input system through a human readable string.
935// This string can be used to better let a user configure input.
936struct retro_input_descriptor
937{
938 // Associates given parameters with a description.
939 unsigned port;
940 unsigned device;
941 unsigned index;
942 unsigned id;
943
944 const char *description; // Human readable description for parameters.
945 // The pointer must remain valid until retro_unload_game() is called.
946};
947
38c2028e 948struct retro_system_info
949{
c19aba43
TK
950 // All pointers are owned by libretro implementation, and pointers must remain valid until retro_deinit() is called.
951
38c2028e 952 const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc.
953 const char *library_version; // Descriptive version of core.
954
955 const char *valid_extensions; // A string listing probably rom extensions the core will be able to load, separated with pipe.
956 // I.e. "bin|rom|iso".
957 // Typically used for a GUI to filter out extensions.
958
959 bool need_fullpath; // If true, retro_load_game() is guaranteed to provide a valid pathname in retro_game_info::path.
960 // ::data and ::size are both invalid.
961 // If false, ::data and ::size are guaranteed to be valid, but ::path might not be valid.
962 // This is typically set to true for libretro implementations that must load from file.
963 // Implementations should strive for setting this to false, as it allows the frontend to perform patching, etc.
964
965 bool block_extract; // If true, the frontend is not allowed to extract any archives before loading the real ROM.
966 // Necessary for certain libretro implementations that load games from zipped archives.
967};
968
969struct retro_game_geometry
970{
971 unsigned base_width; // Nominal video width of game.
972 unsigned base_height; // Nominal video height of game.
973 unsigned max_width; // Maximum possible width of game.
974 unsigned max_height; // Maximum possible height of game.
975
976 float aspect_ratio; // Nominal aspect ratio of game. If aspect_ratio is <= 0.0,
977 // an aspect ratio of base_width / base_height is assumed.
978 // A frontend could override this setting if desired.
979};
980
981struct retro_system_timing
982{
983 double fps; // FPS of video content.
984 double sample_rate; // Sampling rate of audio.
985};
986
987struct retro_system_av_info
988{
989 struct retro_game_geometry geometry;
990 struct retro_system_timing timing;
991};
992
993struct retro_variable
994{
995 const char *key; // Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.
996 // If NULL, obtains the complete environment string if more complex parsing is necessary.
997 // The environment string is formatted as key-value pairs delimited by semicolons as so:
998 // "key1=value1;key2=value2;..."
999 const char *value; // Value to be obtained. If key does not exist, it is set to NULL.
1000};
1001
1002struct retro_game_info
1003{
1004 const char *path; // Path to game, UTF-8 encoded. Usually used as a reference.
1005 // May be NULL if rom was loaded from stdin or similar.
1006 // retro_system_info::need_fullpath guaranteed that this path is valid.
1007 const void *data; // Memory buffer of loaded game. Will be NULL if need_fullpath was set.
1008 size_t size; // Size of memory buffer.
1009 const char *meta; // String of implementation specific meta-data.
1010};
1011
1012// Callbacks
1013//
1014// Environment callback. Gives implementations a way of performing uncommon tasks. Extensible.
1015typedef bool (*retro_environment_t)(unsigned cmd, void *data);
1016
1017// Render a frame. Pixel format is 15-bit 0RGB1555 native endian unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
1018// Width and height specify dimensions of buffer.
1019// Pitch specifices length in bytes between two lines in buffer.
c19aba43
TK
1020// For performance reasons, it is highly recommended to have a frame that is packed in memory, i.e. pitch == width * byte_per_pixel.
1021// Certain graphic APIs, such as OpenGL ES, do not like textures that are not packed in memory.
38c2028e 1022typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch);
1023
1024// Renders a single audio frame. Should only be used if implementation generates a single sample at a time.
1025// Format is signed 16-bit native endian.
1026typedef void (*retro_audio_sample_t)(int16_t left, int16_t right);
1027// Renders multiple audio frames in one go. One frame is defined as a sample of left and right channels, interleaved.
1028// I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
1029// Only one of the audio callbacks must ever be used.
1030typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, size_t frames);
1031
1032// Polls input.
1033typedef void (*retro_input_poll_t)(void);
1034// Queries for input for player 'port'. device will be masked with RETRO_DEVICE_MASK.
1035// Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that have been set with retro_set_controller_port_device()
1036// will still use the higher level RETRO_DEVICE_JOYPAD to request input.
1037typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, unsigned index, unsigned id);
1038
1039// Sets callbacks. retro_set_environment() is guaranteed to be called before retro_init().
1040// The rest of the set_* functions are guaranteed to have been called before the first call to retro_run() is made.
1041void retro_set_environment(retro_environment_t);
1042void retro_set_video_refresh(retro_video_refresh_t);
1043void retro_set_audio_sample(retro_audio_sample_t);
1044void retro_set_audio_sample_batch(retro_audio_sample_batch_t);
1045void retro_set_input_poll(retro_input_poll_t);
1046void retro_set_input_state(retro_input_state_t);
1047
1048// Library global initialization/deinitialization.
1049void retro_init(void);
1050void retro_deinit(void);
1051
1052// Must return RETRO_API_VERSION. Used to validate ABI compatibility when the API is revised.
1053unsigned retro_api_version(void);
1054
1055// Gets statically known system info. Pointers provided in *info must be statically allocated.
1056// Can be called at any time, even before retro_init().
1057void retro_get_system_info(struct retro_system_info *info);
1058
1059// Gets information about system audio/video timings and geometry.
1060// Can be called only after retro_load_game() has successfully completed.
c19aba43
TK
1061// NOTE: The implementation of this function might not initialize every variable if needed.
1062// E.g. geom.aspect_ratio might not be initialized if core doesn't desire a particular aspect ratio.
38c2028e 1063void retro_get_system_av_info(struct retro_system_av_info *info);
1064
1065// Sets device to be used for player 'port'.
1066void retro_set_controller_port_device(unsigned port, unsigned device);
1067
1068// Resets the current game.
1069void retro_reset(void);
1070
1071// Runs the game for one video frame.
1072// During retro_run(), input_poll callback must be called at least once.
1073//
1074// If a frame is not rendered for reasons where a game "dropped" a frame,
1075// this still counts as a frame, and retro_run() should explicitly dupe a frame if GET_CAN_DUPE returns true.
1076// In this case, the video callback can take a NULL argument for data.
1077void retro_run(void);
1078
1079// Returns the amount of data the implementation requires to serialize internal state (save states).
1080// Beetween calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned value, to
1081// ensure that the frontend can allocate a save state buffer once.
1082size_t retro_serialize_size(void);
1083
1084// Serializes internal state. If failed, or size is lower than retro_serialize_size(), it should return false, true otherwise.
1085bool retro_serialize(void *data, size_t size);
1086bool retro_unserialize(const void *data, size_t size);
1087
1088void retro_cheat_reset(void);
1089void retro_cheat_set(unsigned index, bool enabled, const char *code);
1090
1091// Loads a game.
1092bool retro_load_game(const struct retro_game_info *game);
1093
1094// Loads a "special" kind of game. Should not be used except in extreme cases.
1095bool retro_load_game_special(
1096 unsigned game_type,
1097 const struct retro_game_info *info, size_t num_info
1098);
1099
1100// Unloads a currently loaded game.
1101void retro_unload_game(void);
1102
1103// Gets region of game.
1104unsigned retro_get_region(void);
1105
1106// Gets region of memory.
1107void *retro_get_memory_data(unsigned id);
1108size_t retro_get_memory_size(unsigned id);
1109
1110#ifdef __cplusplus
1111}
1112#endif
1113
1114#endif