#ifndef LIBRETRO_H__1#define LIBRETRO_H__23#include <stdint.h>4#include <stddef.h>5#include <limits.h>67// Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant.8#ifdef __cplusplus9extern "C" {10#else11#if defined(_MSC_VER) && !defined(SN_TARGET_PS3) && !defined(__cplusplus)12#define bool unsigned char13#define true 114#define false 015#else16#include <stdbool.h>17#endif18#endif1920// Used for checking API/ABI mismatches that can break libretro implementations.21// It is not incremented for compatible changes to the API.22#define RETRO_API_VERSION 12324// Libretro's fundamental device abstractions.25#define RETRO_DEVICE_MASK 0xff26#define RETRO_DEVICE_NONE 02728// The JOYPAD is called RetroPad. It is essentially a Super Nintendo controller,29// but with additional L2/R2/L3/R3 buttons, similar to a PS1 DualShock.30#define RETRO_DEVICE_JOYPAD 13132// The mouse is a simple mouse, similar to Super Nintendo's mouse.33// X and Y coordinates are reported relatively to last poll (poll callback).34// It is up to the libretro implementation to keep track of where the mouse pointer is supposed to be on the screen.35// The frontend must make sure not to interfere with its own hardware mouse pointer.36#define RETRO_DEVICE_MOUSE 23738// KEYBOARD device lets one poll for raw key pressed.39// It is poll based, so input callback will return with the current pressed state.40#define RETRO_DEVICE_KEYBOARD 34142// Lightgun X/Y coordinates are reported relatively to last poll, similar to mouse.43#define RETRO_DEVICE_LIGHTGUN 44445// The ANALOG device is an extension to JOYPAD (RetroPad).46// Similar to DualShock it adds two analog sticks.47// This is treated as a separate device type as it returns values in the full analog range48// of [-0x8000, 0x7fff]. Positive X axis is right. Positive Y axis is down.49// Only use ANALOG type when polling for analog values of the axes.50#define RETRO_DEVICE_ANALOG 55152// Abstracts the concept of a pointing mechanism, e.g. touch.53// This allows libretro to query in absolute coordinates where on the screen a mouse (or something similar) is being placed.54// For a touch centric device, coordinates reported are the coordinates of the press.55//56// Coordinates in X and Y are reported as:57// [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen,58// and 0x7fff corresponds to the far right/bottom of the screen.59// The "screen" is here defined as area that is passed to the frontend and later displayed on the monitor.60// The frontend is free to scale/resize this screen as it sees fit, however,61// (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the game image, etc.62//63// To check if the pointer coordinates are valid (e.g. a touch display actually being touched),64// PRESSED returns 1 or 0.65// If using a mouse, PRESSED will usually correspond to the left mouse button.66// PRESSED will only return 1 if the pointer is inside the game screen.67//68// For multi-touch, the index variable can be used to successively query more presses.69// If index = 0 returns true for _PRESSED, coordinates can be extracted70// with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with index = 1, and so on.71// Eventually _PRESSED will return false for an index. No further presses are registered at this point.72#define RETRO_DEVICE_POINTER 67374// These device types are specializations of the base types above.75// They should only be used in retro_set_controller_type() to inform libretro implementations76// about use of a very specific device type.77//78// In input state callback, however, only the base type should be used in the 'device' field.79#define RETRO_DEVICE_JOYPAD_MULTITAP ((1 << 8) | RETRO_DEVICE_JOYPAD)80#define RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE ((1 << 8) | RETRO_DEVICE_LIGHTGUN)81#define RETRO_DEVICE_LIGHTGUN_JUSTIFIER ((2 << 8) | RETRO_DEVICE_LIGHTGUN)82#define RETRO_DEVICE_LIGHTGUN_JUSTIFIERS ((3 << 8) | RETRO_DEVICE_LIGHTGUN)8384// Buttons for the RetroPad (JOYPAD).85// The placement of these is equivalent to placements on the Super Nintendo controller.86// L2/R2/L3/R3 buttons correspond to the PS1 DualShock.87#define RETRO_DEVICE_ID_JOYPAD_B 088#define RETRO_DEVICE_ID_JOYPAD_Y 189#define RETRO_DEVICE_ID_JOYPAD_SELECT 290#define RETRO_DEVICE_ID_JOYPAD_START 391#define RETRO_DEVICE_ID_JOYPAD_UP 492#define RETRO_DEVICE_ID_JOYPAD_DOWN 593#define RETRO_DEVICE_ID_JOYPAD_LEFT 694#define RETRO_DEVICE_ID_JOYPAD_RIGHT 795#define RETRO_DEVICE_ID_JOYPAD_A 896#define RETRO_DEVICE_ID_JOYPAD_X 997#define RETRO_DEVICE_ID_JOYPAD_L 1098#define RETRO_DEVICE_ID_JOYPAD_R 1199#define RETRO_DEVICE_ID_JOYPAD_L2 12100#define RETRO_DEVICE_ID_JOYPAD_R2 13101#define RETRO_DEVICE_ID_JOYPAD_L3 14102#define RETRO_DEVICE_ID_JOYPAD_R3 15103104// Index / Id values for ANALOG device.105#define RETRO_DEVICE_INDEX_ANALOG_LEFT 0106#define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1107#define RETRO_DEVICE_ID_ANALOG_X 0108#define RETRO_DEVICE_ID_ANALOG_Y 1109110// Id values for MOUSE.111#define RETRO_DEVICE_ID_MOUSE_X 0112#define RETRO_DEVICE_ID_MOUSE_Y 1113#define RETRO_DEVICE_ID_MOUSE_LEFT 2114#define RETRO_DEVICE_ID_MOUSE_RIGHT 3115116// Id values for LIGHTGUN types.117#define RETRO_DEVICE_ID_LIGHTGUN_X 0118#define RETRO_DEVICE_ID_LIGHTGUN_Y 1119#define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2120#define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3121#define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4122#define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5123#define RETRO_DEVICE_ID_LIGHTGUN_START 6124125// Id values for POINTER.126#define RETRO_DEVICE_ID_POINTER_X 0127#define RETRO_DEVICE_ID_POINTER_Y 1128#define RETRO_DEVICE_ID_POINTER_PRESSED 2129130// Returned from retro_get_region().131#define RETRO_REGION_NTSC 0132#define RETRO_REGION_PAL 1133134// Passed to retro_get_memory_data/size().135// If the memory type doesn't apply to the implementation NULL/0 can be returned.136#define RETRO_MEMORY_MASK 0xff137138// Regular save ram. This ram is usually found on a game cartridge, backed up by a battery.139// If save game data is too complex for a single memory buffer,140// the SYSTEM_DIRECTORY environment callback can be used.141#define RETRO_MEMORY_SAVE_RAM 0142143// Some games have a built-in clock to keep track of time.144// This memory is usually just a couple of bytes to keep track of time.145#define RETRO_MEMORY_RTC 1146147// System ram lets a frontend peek into a game systems main RAM.148#define RETRO_MEMORY_SYSTEM_RAM 2149150// Video ram lets a frontend peek into a game systems video RAM (VRAM).151#define RETRO_MEMORY_VIDEO_RAM 3152153// Special memory types.154#define RETRO_MEMORY_SNES_BSX_RAM ((1 << 8) | RETRO_MEMORY_SAVE_RAM)155#define RETRO_MEMORY_SNES_BSX_PRAM ((2 << 8) | RETRO_MEMORY_SAVE_RAM)156#define RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM ((3 << 8) | RETRO_MEMORY_SAVE_RAM)157#define RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM ((4 << 8) | RETRO_MEMORY_SAVE_RAM)158#define RETRO_MEMORY_SNES_GAME_BOY_RAM ((5 << 8) | RETRO_MEMORY_SAVE_RAM)159#define RETRO_MEMORY_SNES_GAME_BOY_RTC ((6 << 8) | RETRO_MEMORY_RTC)160161// Special game types passed into retro_load_game_special().162// Only used when multiple ROMs are required.163#define RETRO_GAME_TYPE_BSX 0x101164#define RETRO_GAME_TYPE_BSX_SLOTTED 0x102165#define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103166#define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104167168// Keysyms used for ID in input state callback when polling RETRO_KEYBOARD.169enum retro_key170{171RETROK_UNKNOWN = 0,172RETROK_FIRST = 0,173RETROK_BACKSPACE = 8,174RETROK_TAB = 9,175RETROK_CLEAR = 12,176RETROK_RETURN = 13,177RETROK_PAUSE = 19,178RETROK_ESCAPE = 27,179RETROK_SPACE = 32,180RETROK_EXCLAIM = 33,181RETROK_QUOTEDBL = 34,182RETROK_HASH = 35,183RETROK_DOLLAR = 36,184RETROK_AMPERSAND = 38,185RETROK_QUOTE = 39,186RETROK_LEFTPAREN = 40,187RETROK_RIGHTPAREN = 41,188RETROK_ASTERISK = 42,189RETROK_PLUS = 43,190RETROK_COMMA = 44,191RETROK_MINUS = 45,192RETROK_PERIOD = 46,193RETROK_SLASH = 47,194RETROK_0 = 48,195RETROK_1 = 49,196RETROK_2 = 50,197RETROK_3 = 51,198RETROK_4 = 52,199RETROK_5 = 53,200RETROK_6 = 54,201RETROK_7 = 55,202RETROK_8 = 56,203RETROK_9 = 57,204RETROK_COLON = 58,205RETROK_SEMICOLON = 59,206RETROK_LESS = 60,207RETROK_EQUALS = 61,208RETROK_GREATER = 62,209RETROK_QUESTION = 63,210RETROK_AT = 64,211RETROK_LEFTBRACKET = 91,212RETROK_BACKSLASH = 92,213RETROK_RIGHTBRACKET = 93,214RETROK_CARET = 94,215RETROK_UNDERSCORE = 95,216RETROK_BACKQUOTE = 96,217RETROK_a = 97,218RETROK_b = 98,219RETROK_c = 99,220RETROK_d = 100,221RETROK_e = 101,222RETROK_f = 102,223RETROK_g = 103,224RETROK_h = 104,225RETROK_i = 105,226RETROK_j = 106,227RETROK_k = 107,228RETROK_l = 108,229RETROK_m = 109,230RETROK_n = 110,231RETROK_o = 111,232RETROK_p = 112,233RETROK_q = 113,234RETROK_r = 114,235RETROK_s = 115,236RETROK_t = 116,237RETROK_u = 117,238RETROK_v = 118,239RETROK_w = 119,240RETROK_x = 120,241RETROK_y = 121,242RETROK_z = 122,243RETROK_DELETE = 127,244245RETROK_KP0 = 256,246RETROK_KP1 = 257,247RETROK_KP2 = 258,248RETROK_KP3 = 259,249RETROK_KP4 = 260,250RETROK_KP5 = 261,251RETROK_KP6 = 262,252RETROK_KP7 = 263,253RETROK_KP8 = 264,254RETROK_KP9 = 265,255RETROK_KP_PERIOD = 266,256RETROK_KP_DIVIDE = 267,257RETROK_KP_MULTIPLY = 268,258RETROK_KP_MINUS = 269,259RETROK_KP_PLUS = 270,260RETROK_KP_ENTER = 271,261RETROK_KP_EQUALS = 272,262263RETROK_UP = 273,264RETROK_DOWN = 274,265RETROK_RIGHT = 275,266RETROK_LEFT = 276,267RETROK_INSERT = 277,268RETROK_HOME = 278,269RETROK_END = 279,270RETROK_PAGEUP = 280,271RETROK_PAGEDOWN = 281,272273RETROK_F1 = 282,274RETROK_F2 = 283,275RETROK_F3 = 284,276RETROK_F4 = 285,277RETROK_F5 = 286,278RETROK_F6 = 287,279RETROK_F7 = 288,280RETROK_F8 = 289,281RETROK_F9 = 290,282RETROK_F10 = 291,283RETROK_F11 = 292,284RETROK_F12 = 293,285RETROK_F13 = 294,286RETROK_F14 = 295,287RETROK_F15 = 296,288289RETROK_NUMLOCK = 300,290RETROK_CAPSLOCK = 301,291RETROK_SCROLLOCK = 302,292RETROK_RSHIFT = 303,293RETROK_LSHIFT = 304,294RETROK_RCTRL = 305,295RETROK_LCTRL = 306,296RETROK_RALT = 307,297RETROK_LALT = 308,298RETROK_RMETA = 309,299RETROK_LMETA = 310,300RETROK_LSUPER = 311,301RETROK_RSUPER = 312,302RETROK_MODE = 313,303RETROK_COMPOSE = 314,304305RETROK_HELP = 315,306RETROK_PRINT = 316,307RETROK_SYSREQ = 317,308RETROK_BREAK = 318,309RETROK_MENU = 319,310RETROK_POWER = 320,311RETROK_EURO = 321,312RETROK_UNDO = 322,313314RETROK_LAST,315316RETROK_DUMMY = INT_MAX // Ensure sizeof(enum) == sizeof(int)317};318319enum retro_mod320{321RETROKMOD_NONE = 0x0000,322323RETROKMOD_SHIFT = 0x01,324RETROKMOD_CTRL = 0x02,325RETROKMOD_ALT = 0x04,326RETROKMOD_META = 0x08,327328RETROKMOD_NUMLOCK = 0x10,329RETROKMOD_CAPSLOCK = 0x20,330RETROKMOD_SCROLLOCK = 0x40,331332RETROKMOD_DUMMY = INT_MAX // Ensure sizeof(enum) == sizeof(int)333};334335// If set, this call is not part of the public libretro API yet. It can change or be removed at any time.336#define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000337338// Environment commands.339#define RETRO_ENVIRONMENT_SET_ROTATION 1 // const unsigned * --340// Sets screen rotation of graphics.341// Is only implemented if rotation can be accelerated by hardware.342// Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180, 270 degrees343// counter-clockwise respectively.344//345#define RETRO_ENVIRONMENT_GET_OVERSCAN 2 // bool * --346// Boolean value whether or not the implementation should use overscan, or crop away overscan.347//348#define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 // bool * --349// Boolean value whether or not frontend supports frame duping,350// passing NULL to video frame callback.351//352// Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES), and reserved to avoid possible ABI clash.353#define RETRO_ENVIRONMENT_SET_MESSAGE 6 // const struct retro_message * --354// Sets a message to be displayed in implementation-specific manner for a certain amount of 'frames'.355// Should not be used for trivial messages, which should simply be logged to stderr.356#define RETRO_ENVIRONMENT_SHUTDOWN 7 // N/A (NULL) --357// Requests the frontend to shutdown.358// Should only be used if game has a specific359// way to shutdown the game from a menu item or similar.360//361#define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8362// const unsigned * --363// Gives a hint to the frontend how demanding this implementation364// is on a system. E.g. reporting a level of 2 means365// this implementation should run decently on all frontends366// of level 2 and up.367//368// It can be used by the frontend to potentially warn369// about too demanding implementations.370//371// The levels are "floating", but roughly defined as:372// 0: Low-powered embedded devices such as Raspberry Pi373// 1: 6th generation consoles, such as Wii/Xbox 1, and phones, tablets, etc.374// 2: 7th generation consoles, such as PS3/360, with sub-par CPUs.375// 3: Modern desktop/laptops with reasonably powerful CPUs.376// 4: High-end desktops with very powerful CPUs.377//378// This function can be called on a per-game basis,379// as certain games an implementation can play might be380// particularily demanding.381// If called, it should be called in retro_load_game().382//383#define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9384// const char ** --385// Returns the "system" directory of the frontend.386// This directory can be used to store system specific ROMs such as BIOSes, configuration data, etc.387// The returned value can be NULL.388// If so, no such directory is defined,389// and it's up to the implementation to find a suitable directory.390//391#define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10392// const enum retro_pixel_format * --393// Sets the internal pixel format used by the implementation.394// The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555.395// This pixel format however, is deprecated (see enum retro_pixel_format).396// If the call returns false, the frontend does not support this pixel format.397// This function should be called inside retro_load_game() or retro_get_system_av_info().398//399#define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11400// const struct retro_input_descriptor * --401// Sets an array of retro_input_descriptors.402// It is up to the frontend to present this in a usable way.403// The array is terminated by retro_input_descriptor::description being set to NULL.404// This function can be called at any time, but it is recommended to call it as early as possible.405#define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12406// const struct retro_keyboard_callback * --407// Sets a callback function used to notify core about keyboard events.408//409#define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13410// const struct retro_disk_control_callback * --411// Sets an interface which frontend can use to eject and insert disk images.412// This is used for games which consist of multiple images and must be manually413// swapped out by the user (e.g. PSX).414#define RETRO_ENVIRONMENT_SET_HW_RENDER (14 | RETRO_ENVIRONMENT_EXPERIMENTAL)415// struct retro_hw_render_callback * --416// NOTE: This call is currently very experimental, and should not be considered part of the public API.417// The interface could be changed or removed at any time.418// Sets an interface to let a libretro core render with hardware acceleration.419// Should be called in retro_load_game().420// If successful, libretro cores will be able to render to a frontend-provided framebuffer.421// The size of this framebuffer will be at least as large as max_width/max_height provided in get_av_info().422// If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or NULL to retro_video_refresh_t.423#define RETRO_ENVIRONMENT_GET_VARIABLE 15424// struct retro_variable * --425// Interface to aquire user-defined information from environment426// that cannot feasibly be supported in a multi-system way.427// 'key' should be set to a key which has already been set by SET_VARIABLES.428// 'data' will be set to a value or NULL.429//430#define RETRO_ENVIRONMENT_SET_VARIABLES 16431// const struct retro_variable * --432// Allows an implementation to signal the environment433// which variables it might want to check for later using GET_VARIABLE.434// This allows the frontend to present these variables to a user dynamically.435// This should be called as early as possible (ideally in retro_set_environment).436//437// 'data' points to an array of retro_variable structs terminated by a { NULL, NULL } element.438// 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'.439// retro_variable::value should contain a human readable description of the key as well as a '|' delimited list of expected values.440// The number of possible options should be very limited, i.e. it should be feasible to cycle through options without a keyboard.441// First entry should be treated as a default.442//443// Example entry:444// { "foo_option", "Speed hack coprocessor X; false|true" }445//446// Text before first ';' is description. This ';' must be followed by a space, and followed by a list of possible values split up with '|'.447// Only strings are operated on. The possible values will generally be displayed and stored as-is by the frontend.448//449#define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17450// bool * --451// Result is set to true if some variables are updated by452// frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE.453// Variables should be queried with GET_VARIABLE.454455// Pass this to retro_video_refresh_t if rendering to hardware.456// Passing NULL to retro_video_refresh_t is still a frame dupe as normal.457#define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)458459// Invalidates the current HW context.460// If called, all GPU resources must be reinitialized.461// Usually called when frontend reinits video driver.462// Also called first time video driver is initialized, allowing libretro core to init resources.463typedef void (*retro_hw_context_reset_t)(void);464// Gets current framebuffer which is to be rendered to. Could change every frame potentially.465typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void);466467// Get a symbol from HW context.468typedef void (*retro_proc_address_t)(void);469typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym);470471enum retro_hw_context_type472{473RETRO_HW_CONTEXT_NONE = 0,474RETRO_HW_CONTEXT_OPENGL, // OpenGL 2.x. Latest version available before 3.x+.475RETRO_HW_CONTEXT_OPENGLES2, // GLES 2.0476477RETRO_HW_CONTEXT_DUMMY = INT_MAX478};479480struct retro_hw_render_callback481{482enum retro_hw_context_type context_type; // Which API to use. Set by libretro core.483retro_hw_context_reset_t context_reset; // Set by libretro core.484retro_hw_get_current_framebuffer_t get_current_framebuffer; // Set by frontend.485retro_hw_get_proc_address_t get_proc_address; // Set by frontend.486bool depth; // Set if render buffers should have depth component attached.487};488489// Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. Called by the frontend in response to keyboard events.490// down is set if the key is being pressed, or false if it is being released.491// keycode is the RETROK value of the char.492// character is the text character of the pressed key. (UTF-32).493// key_modifiers is a set of RETROKMOD values or'ed together.494typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);495496struct retro_keyboard_callback497{498retro_keyboard_event_t callback;499};500501// Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.502// Should be set for implementations which can swap out multiple disk images in runtime.503// If the implementation can do this automatically, it should strive to do so.504// However, there are cases where the user must manually do so.505//506// Overview: To swap a disk image, eject the disk image with set_eject_state(true).507// Set the disk index with set_image_index(index). Insert the disk again with set_eject_state(false).508509// If ejected is true, "ejects" the virtual disk tray.510// When ejected, the disk image index can be set.511typedef bool (*retro_set_eject_state_t)(bool ejected);512// Gets current eject state. The initial state is 'not ejected'.513typedef bool (*retro_get_eject_state_t)(void);514// Gets current disk index. First disk is index 0.515// If return value is >= get_num_images(), no disk is currently inserted.516typedef unsigned (*retro_get_image_index_t)(void);517// Sets image index. Can only be called when disk is ejected.518// The implementation supports setting "no disk" by using an index >= get_num_images().519typedef bool (*retro_set_image_index_t)(unsigned index);520// Gets total number of images which are available to use.521typedef unsigned (*retro_get_num_images_t)(void);522//523// Replaces the disk image associated with index.524// Arguments to pass in info have same requirements as retro_load_game().525// Virtual disk tray must be ejected when calling this.526// Replacing a disk image with info = NULL will remove the disk image from the internal list.527// As a result, calls to get_image_index() can change.528//529// E.g. replace_image_index(1, NULL), and previous get_image_index() returned 4 before.530// Index 1 will be removed, and the new index is 3.531struct retro_game_info;532typedef bool (*retro_replace_image_index_t)(unsigned index, const struct retro_game_info *info);533// Adds a new valid index (get_num_images()) to the internal disk list.534// This will increment subsequent return values from get_num_images() by 1.535// This image index cannot be used until a disk image has been set with replace_image_index.536typedef bool (*retro_add_image_index_t)(void);537538struct retro_disk_control_callback539{540retro_set_eject_state_t set_eject_state;541retro_get_eject_state_t get_eject_state;542543retro_get_image_index_t get_image_index;544retro_set_image_index_t set_image_index;545retro_get_num_images_t get_num_images;546547retro_replace_image_index_t replace_image_index;548retro_add_image_index_t add_image_index;549};550551enum retro_pixel_format552{553// 0RGB1555, native endian. 0 bit must be set to 0.554// This pixel format is default for compatibility concerns only.555// If a 15/16-bit pixel format is desired, consider using RGB565.556RETRO_PIXEL_FORMAT_0RGB1555 = 0,557558// XRGB8888, native endian. X bits are ignored.559RETRO_PIXEL_FORMAT_XRGB8888 = 1,560561// RGB565, native endian. This pixel format is the recommended format to use if a 15/16-bit format is desired562// as it is the pixel format that is typically available on a wide range of low-power devices.563// It is also natively supported in APIs like OpenGL ES.564RETRO_PIXEL_FORMAT_RGB565 = 2,565566// Ensure sizeof() == sizeof(int).567RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX568};569570struct retro_message571{572const char *msg; // Message to be displayed.573unsigned frames; // Duration in frames of message.574};575576// Describes how the libretro implementation maps a libretro input bind577// to its internal input system through a human readable string.578// This string can be used to better let a user configure input.579struct retro_input_descriptor580{581// Associates given parameters with a description.582unsigned port;583unsigned device;584unsigned index;585unsigned id;586587const char *description; // Human readable description for parameters.588// The pointer must remain valid until retro_unload_game() is called.589};590591struct retro_system_info592{593// All pointers are owned by libretro implementation, and pointers must remain valid until retro_deinit() is called.594595const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc.596const char *library_version; // Descriptive version of core.597598const char *valid_extensions; // A string listing probably rom extensions the core will be able to load, separated with pipe.599// I.e. "bin|rom|iso".600// Typically used for a GUI to filter out extensions.601602bool need_fullpath; // If true, retro_load_game() is guaranteed to provide a valid pathname in retro_game_info::path.603// ::data and ::size are both invalid.604// If false, ::data and ::size are guaranteed to be valid, but ::path might not be valid.605// This is typically set to true for libretro implementations that must load from file.606// Implementations should strive for setting this to false, as it allows the frontend to perform patching, etc.607608bool block_extract; // If true, the frontend is not allowed to extract any archives before loading the real ROM.609// Necessary for certain libretro implementations that load games from zipped archives.610};611612struct retro_game_geometry613{614unsigned base_width; // Nominal video width of game.615unsigned base_height; // Nominal video height of game.616unsigned max_width; // Maximum possible width of game.617unsigned max_height; // Maximum possible height of game.618619float aspect_ratio; // Nominal aspect ratio of game. If aspect_ratio is <= 0.0,620// an aspect ratio of base_width / base_height is assumed.621// A frontend could override this setting if desired.622};623624struct retro_system_timing625{626double fps; // FPS of video content.627double sample_rate; // Sampling rate of audio.628};629630struct retro_system_av_info631{632struct retro_game_geometry geometry;633struct retro_system_timing timing;634};635636struct retro_variable637{638const char *key; // Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.639// If NULL, obtains the complete environment string if more complex parsing is necessary.640// The environment string is formatted as key-value pairs delimited by semicolons as so:641// "key1=value1;key2=value2;..."642const char *value; // Value to be obtained. If key does not exist, it is set to NULL.643};644645struct retro_game_info646{647const char *path; // Path to game, UTF-8 encoded. Usually used as a reference.648// May be NULL if rom was loaded from stdin or similar.649// retro_system_info::need_fullpath guaranteed that this path is valid.650const void *data; // Memory buffer of loaded game. Will be NULL if need_fullpath was set.651size_t size; // Size of memory buffer.652const char *meta; // String of implementation specific meta-data.653};654655// Callbacks656//657// Environment callback. Gives implementations a way of performing uncommon tasks. Extensible.658typedef bool (*retro_environment_t)(unsigned cmd, void *data);659660// Render a frame. Pixel format is 15-bit 0RGB1555 native endian unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).661// Width and height specify dimensions of buffer.662// Pitch specifices length in bytes between two lines in buffer.663// For performance reasons, it is highly recommended to have a frame that is packed in memory, i.e. pitch == width * byte_per_pixel.664// Certain graphic APIs, such as OpenGL ES, do not like textures that are not packed in memory.665typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch);666667// Renders a single audio frame. Should only be used if implementation generates a single sample at a time.668// Format is signed 16-bit native endian.669typedef void (*retro_audio_sample_t)(int16_t left, int16_t right);670// Renders multiple audio frames in one go. One frame is defined as a sample of left and right channels, interleaved.671// I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.672// Only one of the audio callbacks must ever be used.673typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, size_t frames);674675// Polls input.676typedef void (*retro_input_poll_t)(void);677// Queries for input for player 'port'. device will be masked with RETRO_DEVICE_MASK.678// Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that have been set with retro_set_controller_port_device()679// will still use the higher level RETRO_DEVICE_JOYPAD to request input.680typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, unsigned index, unsigned id);681682// Sets callbacks. retro_set_environment() is guaranteed to be called before retro_init().683// The rest of the set_* functions are guaranteed to have been called before the first call to retro_run() is made.684void retro_set_environment(retro_environment_t);685void retro_set_video_refresh(retro_video_refresh_t);686void retro_set_audio_sample(retro_audio_sample_t);687void retro_set_audio_sample_batch(retro_audio_sample_batch_t);688void retro_set_input_poll(retro_input_poll_t);689void retro_set_input_state(retro_input_state_t);690691// Library global initialization/deinitialization.692void retro_init(void);693void retro_deinit(void);694695// Must return RETRO_API_VERSION. Used to validate ABI compatibility when the API is revised.696unsigned retro_api_version(void);697698// Gets statically known system info. Pointers provided in *info must be statically allocated.699// Can be called at any time, even before retro_init().700void retro_get_system_info(struct retro_system_info *info);701702// Gets information about system audio/video timings and geometry.703// Can be called only after retro_load_game() has successfully completed.704// NOTE: The implementation of this function might not initialize every variable if needed.705// E.g. geom.aspect_ratio might not be initialized if core doesn't desire a particular aspect ratio.706void retro_get_system_av_info(struct retro_system_av_info *info);707708// Sets device to be used for player 'port'.709void retro_set_controller_port_device(unsigned port, unsigned device);710711// Resets the current game.712void retro_reset(void);713714// Runs the game for one video frame.715// During retro_run(), input_poll callback must be called at least once.716//717// If a frame is not rendered for reasons where a game "dropped" a frame,718// this still counts as a frame, and retro_run() should explicitly dupe a frame if GET_CAN_DUPE returns true.719// In this case, the video callback can take a NULL argument for data.720void retro_run(void);721722// Returns the amount of data the implementation requires to serialize internal state (save states).723// Beetween calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned value, to724// ensure that the frontend can allocate a save state buffer once.725size_t retro_serialize_size(void);726727// Serializes internal state. If failed, or size is lower than retro_serialize_size(), it should return false, true otherwise.728bool retro_serialize(void *data, size_t size);729bool retro_unserialize(const void *data, size_t size);730731void retro_cheat_reset(void);732void retro_cheat_set(unsigned index, bool enabled, const char *code);733734// Loads a game.735bool retro_load_game(const struct retro_game_info *game);736737// Loads a "special" kind of game. Should not be used except in extreme cases.738bool retro_load_game_special(739unsigned game_type,740const struct retro_game_info *info, size_t num_info741);742743// Unloads a currently loaded game.744void retro_unload_game(void);745746// Gets region of game.747unsigned retro_get_region(void);748749// Gets region of memory.750void *retro_get_memory_data(unsigned id);751size_t retro_get_memory_size(unsigned id);752753#ifdef __cplusplus754}755#endif756757#endif758759760