| 1 | /* Copyright (C) 2010-2016 The RetroArch team |
| 2 | * |
| 3 | * --------------------------------------------------------------------------------------- |
| 4 | * The following license statement only applies to this libretro API header (libretro.h). |
| 5 | * --------------------------------------------------------------------------------------- |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, |
| 8 | * to any person obtaining a copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation the rights to |
| 10 | * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, |
| 11 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 16 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 18 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 19 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 21 | */ |
| 22 | |
| 23 | #ifndef LIBRETRO_H__ |
| 24 | #define LIBRETRO_H__ |
| 25 | |
| 26 | #include <stdint.h> |
| 27 | #include <stddef.h> |
| 28 | #include <limits.h> |
| 29 | |
| 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | #ifndef __cplusplus |
| 35 | #if defined(_MSC_VER) && !defined(SN_TARGET_PS3) |
| 36 | /* Hack applied for MSVC when compiling in C89 mode |
| 37 | * as it isn't C99-compliant. */ |
| 38 | #define bool unsigned char |
| 39 | #define true 1 |
| 40 | #define false 0 |
| 41 | #else |
| 42 | #include <stdbool.h> |
| 43 | #endif |
| 44 | #endif |
| 45 | |
| 46 | #ifndef RETRO_CALLCONV |
| 47 | # if defined(__GNUC__) && defined(__i386__) && !defined(__x86_64__) |
| 48 | # define RETRO_CALLCONV __attribute__((cdecl)) |
| 49 | # elif defined(_MSC_VER) && defined(_M_X86) && !defined(_M_X64) |
| 50 | # define RETRO_CALLCONV __cdecl |
| 51 | # else |
| 52 | # define RETRO_CALLCONV /* all other platforms only have one calling convention each */ |
| 53 | # endif |
| 54 | #endif |
| 55 | |
| 56 | #ifndef RETRO_API |
| 57 | # if defined(_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__) |
| 58 | # ifdef RETRO_IMPORT_SYMBOLS |
| 59 | # ifdef __GNUC__ |
| 60 | # define RETRO_API RETRO_CALLCONV __attribute__((__dllimport__)) |
| 61 | # else |
| 62 | # define RETRO_API RETRO_CALLCONV __declspec(dllimport) |
| 63 | # endif |
| 64 | # else |
| 65 | # ifdef __GNUC__ |
| 66 | # define RETRO_API RETRO_CALLCONV __attribute__((__dllexport__)) |
| 67 | # else |
| 68 | # define RETRO_API RETRO_CALLCONV __declspec(dllexport) |
| 69 | # endif |
| 70 | # endif |
| 71 | # else |
| 72 | # if defined(__GNUC__) && __GNUC__ >= 4 && !defined(__CELLOS_LV2__) |
| 73 | # define RETRO_API RETRO_CALLCONV __attribute__((__visibility__("default"))) |
| 74 | # else |
| 75 | # define RETRO_API RETRO_CALLCONV |
| 76 | # endif |
| 77 | # endif |
| 78 | #endif |
| 79 | |
| 80 | /* Used for checking API/ABI mismatches that can break libretro |
| 81 | * implementations. |
| 82 | * It is not incremented for compatible changes to the API. |
| 83 | */ |
| 84 | #define RETRO_API_VERSION 1 |
| 85 | |
| 86 | /* |
| 87 | * Libretro's fundamental device abstractions. |
| 88 | * |
| 89 | * Libretro's input system consists of some standardized device types, |
| 90 | * such as a joypad (with/without analog), mouse, keyboard, lightgun |
| 91 | * and a pointer. |
| 92 | * |
| 93 | * The functionality of these devices are fixed, and individual cores |
| 94 | * map their own concept of a controller to libretro's abstractions. |
| 95 | * This makes it possible for frontends to map the abstract types to a |
| 96 | * real input device, and not having to worry about binding input |
| 97 | * correctly to arbitrary controller layouts. |
| 98 | */ |
| 99 | |
| 100 | #define RETRO_DEVICE_TYPE_SHIFT 8 |
| 101 | #define RETRO_DEVICE_MASK ((1 << RETRO_DEVICE_TYPE_SHIFT) - 1) |
| 102 | #define RETRO_DEVICE_SUBCLASS(base, id) (((id + 1) << RETRO_DEVICE_TYPE_SHIFT) | base) |
| 103 | |
| 104 | /* Input disabled. */ |
| 105 | #define RETRO_DEVICE_NONE 0 |
| 106 | |
| 107 | /* The JOYPAD is called RetroPad. It is essentially a Super Nintendo |
| 108 | * controller, but with additional L2/R2/L3/R3 buttons, similar to a |
| 109 | * PS1 DualShock. */ |
| 110 | #define RETRO_DEVICE_JOYPAD 1 |
| 111 | |
| 112 | /* The mouse is a simple mouse, similar to Super Nintendo's mouse. |
| 113 | * X and Y coordinates are reported relatively to last poll (poll callback). |
| 114 | * It is up to the libretro implementation to keep track of where the mouse |
| 115 | * pointer is supposed to be on the screen. |
| 116 | * The frontend must make sure not to interfere with its own hardware |
| 117 | * mouse pointer. |
| 118 | */ |
| 119 | #define RETRO_DEVICE_MOUSE 2 |
| 120 | |
| 121 | /* KEYBOARD device lets one poll for raw key pressed. |
| 122 | * It is poll based, so input callback will return with the current |
| 123 | * pressed state. |
| 124 | * For event/text based keyboard input, see |
| 125 | * RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. |
| 126 | */ |
| 127 | #define RETRO_DEVICE_KEYBOARD 3 |
| 128 | |
| 129 | /* Lightgun X/Y coordinates are reported relatively to last poll, |
| 130 | * similar to mouse. */ |
| 131 | #define RETRO_DEVICE_LIGHTGUN 4 |
| 132 | |
| 133 | /* The ANALOG device is an extension to JOYPAD (RetroPad). |
| 134 | * Similar to DualShock it adds two analog sticks. |
| 135 | * This is treated as a separate device type as it returns values in the |
| 136 | * full analog range of [-0x8000, 0x7fff]. Positive X axis is right. |
| 137 | * Positive Y axis is down. |
| 138 | * Only use ANALOG type when polling for analog values of the axes. |
| 139 | */ |
| 140 | #define RETRO_DEVICE_ANALOG 5 |
| 141 | |
| 142 | /* Abstracts the concept of a pointing mechanism, e.g. touch. |
| 143 | * This allows libretro to query in absolute coordinates where on the |
| 144 | * screen a mouse (or something similar) is being placed. |
| 145 | * For a touch centric device, coordinates reported are the coordinates |
| 146 | * of the press. |
| 147 | * |
| 148 | * Coordinates in X and Y are reported as: |
| 149 | * [-0x7fff, 0x7fff]: -0x7fff corresponds to the far left/top of the screen, |
| 150 | * and 0x7fff corresponds to the far right/bottom of the screen. |
| 151 | * The "screen" is here defined as area that is passed to the frontend and |
| 152 | * later displayed on the monitor. |
| 153 | * |
| 154 | * The frontend is free to scale/resize this screen as it sees fit, however, |
| 155 | * (X, Y) = (-0x7fff, -0x7fff) will correspond to the top-left pixel of the |
| 156 | * game image, etc. |
| 157 | * |
| 158 | * To check if the pointer coordinates are valid (e.g. a touch display |
| 159 | * actually being touched), PRESSED returns 1 or 0. |
| 160 | * |
| 161 | * If using a mouse on a desktop, PRESSED will usually correspond to the |
| 162 | * left mouse button, but this is a frontend decision. |
| 163 | * PRESSED will only return 1 if the pointer is inside the game screen. |
| 164 | * |
| 165 | * For multi-touch, the index variable can be used to successively query |
| 166 | * more presses. |
| 167 | * If index = 0 returns true for _PRESSED, coordinates can be extracted |
| 168 | * with _X, _Y for index = 0. One can then query _PRESSED, _X, _Y with |
| 169 | * index = 1, and so on. |
| 170 | * Eventually _PRESSED will return false for an index. No further presses |
| 171 | * are registered at this point. */ |
| 172 | #define RETRO_DEVICE_POINTER 6 |
| 173 | |
| 174 | /* Buttons for the RetroPad (JOYPAD). |
| 175 | * The placement of these is equivalent to placements on the |
| 176 | * Super Nintendo controller. |
| 177 | * L2/R2/L3/R3 buttons correspond to the PS1 DualShock. */ |
| 178 | #define RETRO_DEVICE_ID_JOYPAD_B 0 |
| 179 | #define RETRO_DEVICE_ID_JOYPAD_Y 1 |
| 180 | #define RETRO_DEVICE_ID_JOYPAD_SELECT 2 |
| 181 | #define RETRO_DEVICE_ID_JOYPAD_START 3 |
| 182 | #define RETRO_DEVICE_ID_JOYPAD_UP 4 |
| 183 | #define RETRO_DEVICE_ID_JOYPAD_DOWN 5 |
| 184 | #define RETRO_DEVICE_ID_JOYPAD_LEFT 6 |
| 185 | #define RETRO_DEVICE_ID_JOYPAD_RIGHT 7 |
| 186 | #define RETRO_DEVICE_ID_JOYPAD_A 8 |
| 187 | #define RETRO_DEVICE_ID_JOYPAD_X 9 |
| 188 | #define RETRO_DEVICE_ID_JOYPAD_L 10 |
| 189 | #define RETRO_DEVICE_ID_JOYPAD_R 11 |
| 190 | #define RETRO_DEVICE_ID_JOYPAD_L2 12 |
| 191 | #define RETRO_DEVICE_ID_JOYPAD_R2 13 |
| 192 | #define RETRO_DEVICE_ID_JOYPAD_L3 14 |
| 193 | #define RETRO_DEVICE_ID_JOYPAD_R3 15 |
| 194 | |
| 195 | /* Index / Id values for ANALOG device. */ |
| 196 | #define RETRO_DEVICE_INDEX_ANALOG_LEFT 0 |
| 197 | #define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1 |
| 198 | #define RETRO_DEVICE_INDEX_ANALOG_BUTTON 2 |
| 199 | #define RETRO_DEVICE_ID_ANALOG_X 0 |
| 200 | #define RETRO_DEVICE_ID_ANALOG_Y 1 |
| 201 | |
| 202 | /* Id values for MOUSE. */ |
| 203 | #define RETRO_DEVICE_ID_MOUSE_X 0 |
| 204 | #define RETRO_DEVICE_ID_MOUSE_Y 1 |
| 205 | #define RETRO_DEVICE_ID_MOUSE_LEFT 2 |
| 206 | #define RETRO_DEVICE_ID_MOUSE_RIGHT 3 |
| 207 | #define RETRO_DEVICE_ID_MOUSE_WHEELUP 4 |
| 208 | #define RETRO_DEVICE_ID_MOUSE_WHEELDOWN 5 |
| 209 | #define RETRO_DEVICE_ID_MOUSE_MIDDLE 6 |
| 210 | #define RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP 7 |
| 211 | #define RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN 8 |
| 212 | |
| 213 | /* Id values for LIGHTGUN types. */ |
| 214 | #define RETRO_DEVICE_ID_LIGHTGUN_X 0 |
| 215 | #define RETRO_DEVICE_ID_LIGHTGUN_Y 1 |
| 216 | #define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2 |
| 217 | #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3 |
| 218 | #define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4 |
| 219 | #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5 |
| 220 | #define RETRO_DEVICE_ID_LIGHTGUN_START 6 |
| 221 | |
| 222 | /* Id values for POINTER. */ |
| 223 | #define RETRO_DEVICE_ID_POINTER_X 0 |
| 224 | #define RETRO_DEVICE_ID_POINTER_Y 1 |
| 225 | #define RETRO_DEVICE_ID_POINTER_PRESSED 2 |
| 226 | |
| 227 | /* Returned from retro_get_region(). */ |
| 228 | #define RETRO_REGION_NTSC 0 |
| 229 | #define RETRO_REGION_PAL 1 |
| 230 | |
| 231 | /* Id values for LANGUAGE */ |
| 232 | enum retro_language |
| 233 | { |
| 234 | RETRO_LANGUAGE_ENGLISH = 0, |
| 235 | RETRO_LANGUAGE_JAPANESE = 1, |
| 236 | RETRO_LANGUAGE_FRENCH = 2, |
| 237 | RETRO_LANGUAGE_SPANISH = 3, |
| 238 | RETRO_LANGUAGE_GERMAN = 4, |
| 239 | RETRO_LANGUAGE_ITALIAN = 5, |
| 240 | RETRO_LANGUAGE_DUTCH = 6, |
| 241 | RETRO_LANGUAGE_PORTUGUESE = 7, |
| 242 | RETRO_LANGUAGE_RUSSIAN = 8, |
| 243 | RETRO_LANGUAGE_KOREAN = 9, |
| 244 | RETRO_LANGUAGE_CHINESE_TRADITIONAL = 10, |
| 245 | RETRO_LANGUAGE_CHINESE_SIMPLIFIED = 11, |
| 246 | RETRO_LANGUAGE_ESPERANTO = 12, |
| 247 | RETRO_LANGUAGE_POLISH = 13, |
| 248 | RETRO_LANGUAGE_LAST, |
| 249 | |
| 250 | /* Ensure sizeof(enum) == sizeof(int) */ |
| 251 | RETRO_LANGUAGE_DUMMY = INT_MAX |
| 252 | }; |
| 253 | |
| 254 | /* Passed to retro_get_memory_data/size(). |
| 255 | * If the memory type doesn't apply to the |
| 256 | * implementation NULL/0 can be returned. |
| 257 | */ |
| 258 | #define RETRO_MEMORY_MASK 0xff |
| 259 | |
| 260 | /* Regular save RAM. This RAM is usually found on a game cartridge, |
| 261 | * backed up by a battery. |
| 262 | * If save game data is too complex for a single memory buffer, |
| 263 | * the SAVE_DIRECTORY (preferably) or SYSTEM_DIRECTORY environment |
| 264 | * callback can be used. */ |
| 265 | #define RETRO_MEMORY_SAVE_RAM 0 |
| 266 | |
| 267 | /* Some games have a built-in clock to keep track of time. |
| 268 | * This memory is usually just a couple of bytes to keep track of time. |
| 269 | */ |
| 270 | #define RETRO_MEMORY_RTC 1 |
| 271 | |
| 272 | /* System ram lets a frontend peek into a game systems main RAM. */ |
| 273 | #define RETRO_MEMORY_SYSTEM_RAM 2 |
| 274 | |
| 275 | /* Video ram lets a frontend peek into a game systems video RAM (VRAM). */ |
| 276 | #define RETRO_MEMORY_VIDEO_RAM 3 |
| 277 | |
| 278 | /* Keysyms used for ID in input state callback when polling RETRO_KEYBOARD. */ |
| 279 | enum retro_key |
| 280 | { |
| 281 | RETROK_UNKNOWN = 0, |
| 282 | RETROK_FIRST = 0, |
| 283 | RETROK_BACKSPACE = 8, |
| 284 | RETROK_TAB = 9, |
| 285 | RETROK_CLEAR = 12, |
| 286 | RETROK_RETURN = 13, |
| 287 | RETROK_PAUSE = 19, |
| 288 | RETROK_ESCAPE = 27, |
| 289 | RETROK_SPACE = 32, |
| 290 | RETROK_EXCLAIM = 33, |
| 291 | RETROK_QUOTEDBL = 34, |
| 292 | RETROK_HASH = 35, |
| 293 | RETROK_DOLLAR = 36, |
| 294 | RETROK_AMPERSAND = 38, |
| 295 | RETROK_QUOTE = 39, |
| 296 | RETROK_LEFTPAREN = 40, |
| 297 | RETROK_RIGHTPAREN = 41, |
| 298 | RETROK_ASTERISK = 42, |
| 299 | RETROK_PLUS = 43, |
| 300 | RETROK_COMMA = 44, |
| 301 | RETROK_MINUS = 45, |
| 302 | RETROK_PERIOD = 46, |
| 303 | RETROK_SLASH = 47, |
| 304 | RETROK_0 = 48, |
| 305 | RETROK_1 = 49, |
| 306 | RETROK_2 = 50, |
| 307 | RETROK_3 = 51, |
| 308 | RETROK_4 = 52, |
| 309 | RETROK_5 = 53, |
| 310 | RETROK_6 = 54, |
| 311 | RETROK_7 = 55, |
| 312 | RETROK_8 = 56, |
| 313 | RETROK_9 = 57, |
| 314 | RETROK_COLON = 58, |
| 315 | RETROK_SEMICOLON = 59, |
| 316 | RETROK_LESS = 60, |
| 317 | RETROK_EQUALS = 61, |
| 318 | RETROK_GREATER = 62, |
| 319 | RETROK_QUESTION = 63, |
| 320 | RETROK_AT = 64, |
| 321 | RETROK_LEFTBRACKET = 91, |
| 322 | RETROK_BACKSLASH = 92, |
| 323 | RETROK_RIGHTBRACKET = 93, |
| 324 | RETROK_CARET = 94, |
| 325 | RETROK_UNDERSCORE = 95, |
| 326 | RETROK_BACKQUOTE = 96, |
| 327 | RETROK_a = 97, |
| 328 | RETROK_b = 98, |
| 329 | RETROK_c = 99, |
| 330 | RETROK_d = 100, |
| 331 | RETROK_e = 101, |
| 332 | RETROK_f = 102, |
| 333 | RETROK_g = 103, |
| 334 | RETROK_h = 104, |
| 335 | RETROK_i = 105, |
| 336 | RETROK_j = 106, |
| 337 | RETROK_k = 107, |
| 338 | RETROK_l = 108, |
| 339 | RETROK_m = 109, |
| 340 | RETROK_n = 110, |
| 341 | RETROK_o = 111, |
| 342 | RETROK_p = 112, |
| 343 | RETROK_q = 113, |
| 344 | RETROK_r = 114, |
| 345 | RETROK_s = 115, |
| 346 | RETROK_t = 116, |
| 347 | RETROK_u = 117, |
| 348 | RETROK_v = 118, |
| 349 | RETROK_w = 119, |
| 350 | RETROK_x = 120, |
| 351 | RETROK_y = 121, |
| 352 | RETROK_z = 122, |
| 353 | RETROK_DELETE = 127, |
| 354 | |
| 355 | RETROK_KP0 = 256, |
| 356 | RETROK_KP1 = 257, |
| 357 | RETROK_KP2 = 258, |
| 358 | RETROK_KP3 = 259, |
| 359 | RETROK_KP4 = 260, |
| 360 | RETROK_KP5 = 261, |
| 361 | RETROK_KP6 = 262, |
| 362 | RETROK_KP7 = 263, |
| 363 | RETROK_KP8 = 264, |
| 364 | RETROK_KP9 = 265, |
| 365 | RETROK_KP_PERIOD = 266, |
| 366 | RETROK_KP_DIVIDE = 267, |
| 367 | RETROK_KP_MULTIPLY = 268, |
| 368 | RETROK_KP_MINUS = 269, |
| 369 | RETROK_KP_PLUS = 270, |
| 370 | RETROK_KP_ENTER = 271, |
| 371 | RETROK_KP_EQUALS = 272, |
| 372 | |
| 373 | RETROK_UP = 273, |
| 374 | RETROK_DOWN = 274, |
| 375 | RETROK_RIGHT = 275, |
| 376 | RETROK_LEFT = 276, |
| 377 | RETROK_INSERT = 277, |
| 378 | RETROK_HOME = 278, |
| 379 | RETROK_END = 279, |
| 380 | RETROK_PAGEUP = 280, |
| 381 | RETROK_PAGEDOWN = 281, |
| 382 | |
| 383 | RETROK_F1 = 282, |
| 384 | RETROK_F2 = 283, |
| 385 | RETROK_F3 = 284, |
| 386 | RETROK_F4 = 285, |
| 387 | RETROK_F5 = 286, |
| 388 | RETROK_F6 = 287, |
| 389 | RETROK_F7 = 288, |
| 390 | RETROK_F8 = 289, |
| 391 | RETROK_F9 = 290, |
| 392 | RETROK_F10 = 291, |
| 393 | RETROK_F11 = 292, |
| 394 | RETROK_F12 = 293, |
| 395 | RETROK_F13 = 294, |
| 396 | RETROK_F14 = 295, |
| 397 | RETROK_F15 = 296, |
| 398 | |
| 399 | RETROK_NUMLOCK = 300, |
| 400 | RETROK_CAPSLOCK = 301, |
| 401 | RETROK_SCROLLOCK = 302, |
| 402 | RETROK_RSHIFT = 303, |
| 403 | RETROK_LSHIFT = 304, |
| 404 | RETROK_RCTRL = 305, |
| 405 | RETROK_LCTRL = 306, |
| 406 | RETROK_RALT = 307, |
| 407 | RETROK_LALT = 308, |
| 408 | RETROK_RMETA = 309, |
| 409 | RETROK_LMETA = 310, |
| 410 | RETROK_LSUPER = 311, |
| 411 | RETROK_RSUPER = 312, |
| 412 | RETROK_MODE = 313, |
| 413 | RETROK_COMPOSE = 314, |
| 414 | |
| 415 | RETROK_HELP = 315, |
| 416 | RETROK_PRINT = 316, |
| 417 | RETROK_SYSREQ = 317, |
| 418 | RETROK_BREAK = 318, |
| 419 | RETROK_MENU = 319, |
| 420 | RETROK_POWER = 320, |
| 421 | RETROK_EURO = 321, |
| 422 | RETROK_UNDO = 322, |
| 423 | |
| 424 | RETROK_LAST, |
| 425 | |
| 426 | RETROK_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */ |
| 427 | }; |
| 428 | |
| 429 | enum retro_mod |
| 430 | { |
| 431 | RETROKMOD_NONE = 0x0000, |
| 432 | |
| 433 | RETROKMOD_SHIFT = 0x01, |
| 434 | RETROKMOD_CTRL = 0x02, |
| 435 | RETROKMOD_ALT = 0x04, |
| 436 | RETROKMOD_META = 0x08, |
| 437 | |
| 438 | RETROKMOD_NUMLOCK = 0x10, |
| 439 | RETROKMOD_CAPSLOCK = 0x20, |
| 440 | RETROKMOD_SCROLLOCK = 0x40, |
| 441 | |
| 442 | RETROKMOD_DUMMY = INT_MAX /* Ensure sizeof(enum) == sizeof(int) */ |
| 443 | }; |
| 444 | |
| 445 | /* If set, this call is not part of the public libretro API yet. It can |
| 446 | * change or be removed at any time. */ |
| 447 | #define RETRO_ENVIRONMENT_EXPERIMENTAL 0x10000 |
| 448 | /* Environment callback to be used internally in frontend. */ |
| 449 | #define RETRO_ENVIRONMENT_PRIVATE 0x20000 |
| 450 | |
| 451 | /* Environment commands. */ |
| 452 | #define RETRO_ENVIRONMENT_SET_ROTATION 1 /* const unsigned * -- |
| 453 | * Sets screen rotation of graphics. |
| 454 | * Is only implemented if rotation can be accelerated by hardware. |
| 455 | * Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180, |
| 456 | * 270 degrees counter-clockwise respectively. |
| 457 | */ |
| 458 | #define RETRO_ENVIRONMENT_GET_OVERSCAN 2 /* bool * -- |
| 459 | * Boolean value whether or not the implementation should use overscan, |
| 460 | * or crop away overscan. |
| 461 | */ |
| 462 | #define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 /* bool * -- |
| 463 | * Boolean value whether or not frontend supports frame duping, |
| 464 | * passing NULL to video frame callback. |
| 465 | */ |
| 466 | |
| 467 | /* Environ 4, 5 are no longer supported (GET_VARIABLE / SET_VARIABLES), |
| 468 | * and reserved to avoid possible ABI clash. |
| 469 | */ |
| 470 | |
| 471 | #define RETRO_ENVIRONMENT_SET_MESSAGE 6 /* const struct retro_message * -- |
| 472 | * Sets a message to be displayed in implementation-specific manner |
| 473 | * for a certain amount of 'frames'. |
| 474 | * Should not be used for trivial messages, which should simply be |
| 475 | * logged via RETRO_ENVIRONMENT_GET_LOG_INTERFACE (or as a |
| 476 | * fallback, stderr). |
| 477 | */ |
| 478 | #define RETRO_ENVIRONMENT_SHUTDOWN 7 /* N/A (NULL) -- |
| 479 | * Requests the frontend to shutdown. |
| 480 | * Should only be used if game has a specific |
| 481 | * way to shutdown the game from a menu item or similar. |
| 482 | */ |
| 483 | #define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8 |
| 484 | /* const unsigned * -- |
| 485 | * Gives a hint to the frontend how demanding this implementation |
| 486 | * is on a system. E.g. reporting a level of 2 means |
| 487 | * this implementation should run decently on all frontends |
| 488 | * of level 2 and up. |
| 489 | * |
| 490 | * It can be used by the frontend to potentially warn |
| 491 | * about too demanding implementations. |
| 492 | * |
| 493 | * The levels are "floating". |
| 494 | * |
| 495 | * This function can be called on a per-game basis, |
| 496 | * as certain games an implementation can play might be |
| 497 | * particularly demanding. |
| 498 | * If called, it should be called in retro_load_game(). |
| 499 | */ |
| 500 | #define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9 |
| 501 | /* const char ** -- |
| 502 | * Returns the "system" directory of the frontend. |
| 503 | * This directory can be used to store system specific |
| 504 | * content such as BIOSes, configuration data, etc. |
| 505 | * The returned value can be NULL. |
| 506 | * If so, no such directory is defined, |
| 507 | * and it's up to the implementation to find a suitable directory. |
| 508 | * |
| 509 | * NOTE: Some cores used this folder also for "save" data such as |
| 510 | * memory cards, etc, for lack of a better place to put it. |
| 511 | * This is now discouraged, and if possible, cores should try to |
| 512 | * use the new GET_SAVE_DIRECTORY. |
| 513 | */ |
| 514 | #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10 |
| 515 | /* const enum retro_pixel_format * -- |
| 516 | * Sets the internal pixel format used by the implementation. |
| 517 | * The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555. |
| 518 | * This pixel format however, is deprecated (see enum retro_pixel_format). |
| 519 | * If the call returns false, the frontend does not support this pixel |
| 520 | * format. |
| 521 | * |
| 522 | * This function should be called inside retro_load_game() or |
| 523 | * retro_get_system_av_info(). |
| 524 | */ |
| 525 | #define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11 |
| 526 | /* const struct retro_input_descriptor * -- |
| 527 | * Sets an array of retro_input_descriptors. |
| 528 | * It is up to the frontend to present this in a usable way. |
| 529 | * The array is terminated by retro_input_descriptor::description |
| 530 | * being set to NULL. |
| 531 | * This function can be called at any time, but it is recommended |
| 532 | * to call it as early as possible. |
| 533 | */ |
| 534 | #define RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK 12 |
| 535 | /* const struct retro_keyboard_callback * -- |
| 536 | * Sets a callback function used to notify core about keyboard events. |
| 537 | */ |
| 538 | #define RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE 13 |
| 539 | /* const struct retro_disk_control_callback * -- |
| 540 | * Sets an interface which frontend can use to eject and insert |
| 541 | * disk images. |
| 542 | * This is used for games which consist of multiple images and |
| 543 | * must be manually swapped out by the user (e.g. PSX). |
| 544 | */ |
| 545 | #define RETRO_ENVIRONMENT_SET_HW_RENDER 14 |
| 546 | /* struct retro_hw_render_callback * -- |
| 547 | * Sets an interface to let a libretro core render with |
| 548 | * hardware acceleration. |
| 549 | * Should be called in retro_load_game(). |
| 550 | * If successful, libretro cores will be able to render to a |
| 551 | * frontend-provided framebuffer. |
| 552 | * The size of this framebuffer will be at least as large as |
| 553 | * max_width/max_height provided in get_av_info(). |
| 554 | * If HW rendering is used, pass only RETRO_HW_FRAME_BUFFER_VALID or |
| 555 | * NULL to retro_video_refresh_t. |
| 556 | */ |
| 557 | #define RETRO_ENVIRONMENT_GET_VARIABLE 15 |
| 558 | /* struct retro_variable * -- |
| 559 | * Interface to acquire user-defined information from environment |
| 560 | * that cannot feasibly be supported in a multi-system way. |
| 561 | * 'key' should be set to a key which has already been set by |
| 562 | * SET_VARIABLES. |
| 563 | * 'data' will be set to a value or NULL. |
| 564 | */ |
| 565 | #define RETRO_ENVIRONMENT_SET_VARIABLES 16 |
| 566 | /* const struct retro_variable * -- |
| 567 | * Allows an implementation to signal the environment |
| 568 | * which variables it might want to check for later using |
| 569 | * GET_VARIABLE. |
| 570 | * This allows the frontend to present these variables to |
| 571 | * a user dynamically. |
| 572 | * This should be called as early as possible (ideally in |
| 573 | * retro_set_environment). |
| 574 | * |
| 575 | * 'data' points to an array of retro_variable structs |
| 576 | * terminated by a { NULL, NULL } element. |
| 577 | * retro_variable::key should be namespaced to not collide |
| 578 | * with other implementations' keys. E.g. A core called |
| 579 | * 'foo' should use keys named as 'foo_option'. |
| 580 | * retro_variable::value should contain a human readable |
| 581 | * description of the key as well as a '|' delimited list |
| 582 | * of expected values. |
| 583 | * |
| 584 | * The number of possible options should be very limited, |
| 585 | * i.e. it should be feasible to cycle through options |
| 586 | * without a keyboard. |
| 587 | * |
| 588 | * First entry should be treated as a default. |
| 589 | * |
| 590 | * Example entry: |
| 591 | * { "foo_option", "Speed hack coprocessor X; false|true" } |
| 592 | * |
| 593 | * Text before first ';' is description. This ';' must be |
| 594 | * followed by a space, and followed by a list of possible |
| 595 | * values split up with '|'. |
| 596 | * |
| 597 | * Only strings are operated on. The possible values will |
| 598 | * generally be displayed and stored as-is by the frontend. |
| 599 | */ |
| 600 | #define RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE 17 |
| 601 | /* bool * -- |
| 602 | * Result is set to true if some variables are updated by |
| 603 | * frontend since last call to RETRO_ENVIRONMENT_GET_VARIABLE. |
| 604 | * Variables should be queried with GET_VARIABLE. |
| 605 | */ |
| 606 | #define RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME 18 |
| 607 | /* const bool * -- |
| 608 | * If true, the libretro implementation supports calls to |
| 609 | * retro_load_game() with NULL as argument. |
| 610 | * Used by cores which can run without particular game data. |
| 611 | * This should be called within retro_set_environment() only. |
| 612 | */ |
| 613 | #define RETRO_ENVIRONMENT_GET_LIBRETRO_PATH 19 |
| 614 | /* const char ** -- |
| 615 | * Retrieves the absolute path from where this libretro |
| 616 | * implementation was loaded. |
| 617 | * NULL is returned if the libretro was loaded statically |
| 618 | * (i.e. linked statically to frontend), or if the path cannot be |
| 619 | * determined. |
| 620 | * Mostly useful in cooperation with SET_SUPPORT_NO_GAME as assets can |
| 621 | * be loaded without ugly hacks. |
| 622 | */ |
| 623 | |
| 624 | /* Environment 20 was an obsolete version of SET_AUDIO_CALLBACK. |
| 625 | * It was not used by any known core at the time, |
| 626 | * and was removed from the API. */ |
| 627 | #define RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK 22 |
| 628 | /* const struct retro_audio_callback * -- |
| 629 | * Sets an interface which is used to notify a libretro core about audio |
| 630 | * being available for writing. |
| 631 | * The callback can be called from any thread, so a core using this must |
| 632 | * have a thread safe audio implementation. |
| 633 | * It is intended for games where audio and video are completely |
| 634 | * asynchronous and audio can be generated on the fly. |
| 635 | * This interface is not recommended for use with emulators which have |
| 636 | * highly synchronous audio. |
| 637 | * |
| 638 | * The callback only notifies about writability; the libretro core still |
| 639 | * has to call the normal audio callbacks |
| 640 | * to write audio. The audio callbacks must be called from within the |
| 641 | * notification callback. |
| 642 | * The amount of audio data to write is up to the implementation. |
| 643 | * Generally, the audio callback will be called continously in a loop. |
| 644 | * |
| 645 | * Due to thread safety guarantees and lack of sync between audio and |
| 646 | * video, a frontend can selectively disallow this interface based on |
| 647 | * internal configuration. A core using this interface must also |
| 648 | * implement the "normal" audio interface. |
| 649 | * |
| 650 | * A libretro core using SET_AUDIO_CALLBACK should also make use of |
| 651 | * SET_FRAME_TIME_CALLBACK. |
| 652 | */ |
| 653 | #define RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK 21 |
| 654 | /* const struct retro_frame_time_callback * -- |
| 655 | * Lets the core know how much time has passed since last |
| 656 | * invocation of retro_run(). |
| 657 | * The frontend can tamper with the timing to fake fast-forward, |
| 658 | * slow-motion, frame stepping, etc. |
| 659 | * In this case the delta time will use the reference value |
| 660 | * in frame_time_callback.. |
| 661 | */ |
| 662 | #define RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE 23 |
| 663 | /* struct retro_rumble_interface * -- |
| 664 | * Gets an interface which is used by a libretro core to set |
| 665 | * state of rumble motors in controllers. |
| 666 | * A strong and weak motor is supported, and they can be |
| 667 | * controlled indepedently. |
| 668 | */ |
| 669 | #define RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES 24 |
| 670 | /* uint64_t * -- |
| 671 | * Gets a bitmask telling which device type are expected to be |
| 672 | * handled properly in a call to retro_input_state_t. |
| 673 | * Devices which are not handled or recognized always return |
| 674 | * 0 in retro_input_state_t. |
| 675 | * Example bitmask: caps = (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG). |
| 676 | * Should only be called in retro_run(). |
| 677 | */ |
| 678 | #define RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE (25 | RETRO_ENVIRONMENT_EXPERIMENTAL) |
| 679 | /* struct retro_sensor_interface * -- |
| 680 | * Gets access to the sensor interface. |
| 681 | * The purpose of this interface is to allow |
| 682 | * setting state related to sensors such as polling rate, |
| 683 | * enabling/disable it entirely, etc. |
| 684 | * Reading sensor state is done via the normal |
| 685 | * input_state_callback API. |
| 686 | */ |
| 687 | #define RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE (26 | RETRO_ENVIRONMENT_EXPERIMENTAL) |
| 688 | /* struct retro_camera_callback * -- |
| 689 | * Gets an interface to a video camera driver. |
| 690 | * A libretro core can use this interface to get access to a |
| 691 | * video camera. |
| 692 | * New video frames are delivered in a callback in same |
| 693 | * thread as retro_run(). |
| 694 | * |
| 695 | * GET_CAMERA_INTERFACE should be called in retro_load_game(). |
| 696 | * |
| 697 | * Depending on the camera implementation used, camera frames |
| 698 | * will be delivered as a raw framebuffer, |
| 699 | * or as an OpenGL texture directly. |
| 700 | * |
| 701 | * The core has to tell the frontend here which types of |
| 702 | * buffers can be handled properly. |
| 703 | * An OpenGL texture can only be handled when using a |
| 704 | * libretro GL core (SET_HW_RENDER). |
| 705 | * It is recommended to use a libretro GL core when |
| 706 | * using camera interface. |
| 707 | * |
| 708 | * The camera is not started automatically. The retrieved start/stop |
| 709 | * functions must be used to explicitly |
| 710 | * start and stop the camera driver. |
| 711 | */ |
| 712 | #define RETRO_ENVIRONMENT_GET_LOG_INTERFACE 27 |
| 713 | /* struct retro_log_callback * -- |
| 714 | * Gets an interface for logging. This is useful for |
| 715 | * logging in a cross-platform way |
| 716 | * as certain platforms cannot use use stderr for logging. |
| 717 | * It also allows the frontend to |
| 718 | * show logging information in a more suitable way. |
| 719 | * If this interface is not used, libretro cores should |
| 720 | * log to stderr as desired. |
| 721 | */ |
| 722 | #define RETRO_ENVIRONMENT_GET_PERF_INTERFACE 28 |
| 723 | /* struct retro_perf_callback * -- |
| 724 | * Gets an interface for performance counters. This is useful |
| 725 | * for performance logging in a cross-platform way and for detecting |
| 726 | * architecture-specific features, such as SIMD support. |
| 727 | */ |
| 728 | #define RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE 29 |
| 729 | /* struct retro_location_callback * -- |
| 730 | * Gets access to the location interface. |
| 731 | * The purpose of this interface is to be able to retrieve |
| 732 | * location-based information from the host device, |
| 733 | * such as current latitude / longitude. |
| 734 | */ |
| 735 | #define RETRO_ENVIRONMENT_GET_CONTENT_DIRECTORY 30 /* Old name, kept for compatibility. */ |
| 736 | #define RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY 30 |
| 737 | /* const char ** -- |
| 738 | * Returns the "core assets" directory of the frontend. |
| 739 | * This directory can be used to store specific assets that the |
| 740 | * core relies upon, such as art assets, |
| 741 | * input data, etc etc. |
| 742 | * The returned value can be NULL. |
| 743 | * If so, no such directory is defined, |
| 744 | * and it's up to the implementation to find a suitable directory. |
| 745 | */ |
| 746 | #define RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY 31 |
| 747 | /* const char ** -- |
| 748 | * Returns the "save" directory of the frontend. |
| 749 | * This directory can be used to store SRAM, memory cards, |
| 750 | * high scores, etc, if the libretro core |
| 751 | * cannot use the regular memory interface (retro_get_memory_data()). |
| 752 | * |
| 753 | * NOTE: libretro cores used to check GET_SYSTEM_DIRECTORY for |
| 754 | * similar things before. |
| 755 | * They should still check GET_SYSTEM_DIRECTORY if they want to |
| 756 | * be backwards compatible. |
| 757 | * The path here can be NULL. It should only be non-NULL if the |
| 758 | * frontend user has set a specific save path. |
| 759 | */ |
| 760 | #define RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO 32 |
| 761 | /* const struct retro_system_av_info * -- |
| 762 | * Sets a new av_info structure. This can only be called from |
| 763 | * within retro_run(). |
| 764 | * This should *only* be used if the core is completely altering the |
| 765 | * internal resolutions, aspect ratios, timings, sampling rate, etc. |
| 766 | * Calling this can require a full reinitialization of video/audio |
| 767 | * drivers in the frontend, |
| 768 | * |
| 769 | * so it is important to call it very sparingly, and usually only with |
| 770 | * the users explicit consent. |
| 771 | * An eventual driver reinitialize will happen so that video and |
| 772 | * audio callbacks |
| 773 | * happening after this call within the same retro_run() call will |
| 774 | * target the newly initialized driver. |
| 775 | * |
| 776 | * This callback makes it possible to support configurable resolutions |
| 777 | * in games, which can be useful to |
| 778 | * avoid setting the "worst case" in max_width/max_height. |
| 779 | * |
| 780 | * ***HIGHLY RECOMMENDED*** Do not call this callback every time |
| 781 | * resolution changes in an emulator core if it's |
| 782 | * expected to be a temporary change, for the reasons of possible |
| 783 | * driver reinitialization. |
| 784 | * This call is not a free pass for not trying to provide |
| 785 | * correct values in retro_get_system_av_info(). If you need to change |
| 786 | * things like aspect ratio or nominal width/height, |
| 787 | * use RETRO_ENVIRONMENT_SET_GEOMETRY, which is a softer variant |
| 788 | * of SET_SYSTEM_AV_INFO. |
| 789 | * |
| 790 | * If this returns false, the frontend does not acknowledge a |
| 791 | * changed av_info struct. |
| 792 | */ |
| 793 | #define RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK 33 |
| 794 | /* const struct retro_get_proc_address_interface * -- |
| 795 | * Allows a libretro core to announce support for the |
| 796 | * get_proc_address() interface. |
| 797 | * This interface allows for a standard way to extend libretro where |
| 798 | * use of environment calls are too indirect, |
| 799 | * e.g. for cases where the frontend wants to call directly into the core. |
| 800 | * |
| 801 | * If a core wants to expose this interface, SET_PROC_ADDRESS_CALLBACK |
| 802 | * **MUST** be called from within retro_set_environment(). |
| 803 | */ |
| 804 | #define RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO 34 |
| 805 | /* const struct retro_subsystem_info * -- |
| 806 | * This environment call introduces the concept of libretro "subsystems". |
| 807 | * A subsystem is a variant of a libretro core which supports |
| 808 | * different kinds of games. |
| 809 | * The purpose of this is to support e.g. emulators which might |
| 810 | * have special needs, e.g. Super Nintendo's Super GameBoy, Sufami Turbo. |
| 811 | * It can also be used to pick among subsystems in an explicit way |
| 812 | * if the libretro implementation is a multi-system emulator itself. |
| 813 | * |
| 814 | * Loading a game via a subsystem is done with retro_load_game_special(), |
| 815 | * and this environment call allows a libretro core to expose which |
| 816 | * subsystems are supported for use with retro_load_game_special(). |
| 817 | * A core passes an array of retro_game_special_info which is terminated |
| 818 | * with a zeroed out retro_game_special_info struct. |
| 819 | * |
| 820 | * If a core wants to use this functionality, SET_SUBSYSTEM_INFO |
| 821 | * **MUST** be called from within retro_set_environment(). |
| 822 | */ |
| 823 | #define RETRO_ENVIRONMENT_SET_CONTROLLER_INFO 35 |
| 824 | /* const struct retro_controller_info * -- |
| 825 | * This environment call lets a libretro core tell the frontend |
| 826 | * which controller types are recognized in calls to |
| 827 | * retro_set_controller_port_device(). |
| 828 | * |
| 829 | * Some emulators such as Super Nintendo |
| 830 | * support multiple lightgun types which must be specifically |
| 831 | * selected from. |
| 832 | * It is therefore sometimes necessary for a frontend to be able |
| 833 | * to tell the core about a special kind of input device which is |
| 834 | * not covered by the libretro input API. |
| 835 | * |
| 836 | * In order for a frontend to understand the workings of an input device, |
| 837 | * it must be a specialized type |
| 838 | * of the generic device types already defined in the libretro API. |
| 839 | * |
| 840 | * Which devices are supported can vary per input port. |
| 841 | * The core must pass an array of const struct retro_controller_info which |
| 842 | * is terminated with a blanked out struct. Each element of the struct |
| 843 | * corresponds to an ascending port index to |
| 844 | * retro_set_controller_port_device(). |
| 845 | * Even if special device types are set in the libretro core, |
| 846 | * libretro should only poll input based on the base input device types. |
| 847 | */ |
| 848 | #define RETRO_ENVIRONMENT_SET_MEMORY_MAPS (36 | RETRO_ENVIRONMENT_EXPERIMENTAL) |
| 849 | /* const struct retro_memory_map * -- |
| 850 | * This environment call lets a libretro core tell the frontend |
| 851 | * about the memory maps this core emulates. |
| 852 | * This can be used to implement, for example, cheats in a core-agnostic way. |
| 853 | * |
| 854 | * Should only be used by emulators; it doesn't make much sense for |
| 855 | * anything else. |
| 856 | * It is recommended to expose all relevant pointers through |
| 857 | * retro_get_memory_* as well. |
| 858 | * |
| 859 | * Can be called from retro_init and retro_load_game. |
| 860 | */ |
| 861 | #define RETRO_ENVIRONMENT_SET_GEOMETRY 37 |
| 862 | /* const struct retro_game_geometry * -- |
| 863 | * This environment call is similar to SET_SYSTEM_AV_INFO for changing |
| 864 | * video parameters, but provides a guarantee that drivers will not be |
| 865 | * reinitialized. |
| 866 | * This can only be called from within retro_run(). |
| 867 | * |
| 868 | * The purpose of this call is to allow a core to alter nominal |
| 869 | * width/heights as well as aspect ratios on-the-fly, which can be |
| 870 | * useful for some emulators to change in run-time. |
| 871 | * |
| 872 | * max_width/max_height arguments are ignored and cannot be changed |
| 873 | * with this call as this could potentially require a reinitialization or a |
| 874 | * non-constant time operation. |
| 875 | * If max_width/max_height are to be changed, SET_SYSTEM_AV_INFO is required. |
| 876 | * |
| 877 | * A frontend must guarantee that this environment call completes in |
| 878 | * constant time. |
| 879 | */ |
| 880 | #define RETRO_ENVIRONMENT_GET_USERNAME 38 |
| 881 | /* const char ** |
| 882 | * Returns the specified username of the frontend, if specified by the user. |
| 883 | * This username can be used as a nickname for a core that has online facilities |
| 884 | * or any other mode where personalization of the user is desirable. |
| 885 | * The returned value can be NULL. |
| 886 | * If this environ callback is used by a core that requires a valid username, |
| 887 | * a default username should be specified by the core. |
| 888 | */ |
| 889 | #define RETRO_ENVIRONMENT_GET_LANGUAGE 39 |
| 890 | /* unsigned * -- |
| 891 | * Returns the specified language of the frontend, if specified by the user. |
| 892 | * It can be used by the core for localization purposes. |
| 893 | */ |
| 894 | #define RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER (40 | RETRO_ENVIRONMENT_EXPERIMENTAL) |
| 895 | /* struct retro_framebuffer * -- |
| 896 | * Returns a preallocated framebuffer which the core can use for rendering |
| 897 | * the frame into when not using SET_HW_RENDER. |
| 898 | * The framebuffer returned from this call must not be used |
| 899 | * after the current call to retro_run() returns. |
| 900 | * |
| 901 | * The goal of this call is to allow zero-copy behavior where a core |
| 902 | * can render directly into video memory, avoiding extra bandwidth cost by copying |
| 903 | * memory from core to video memory. |
| 904 | * |
| 905 | * If this call succeeds and the core renders into it, |
| 906 | * the framebuffer pointer and pitch can be passed to retro_video_refresh_t. |
| 907 | * If the buffer from GET_CURRENT_SOFTWARE_FRAMEBUFFER is to be used, |
| 908 | * the core must pass the exact |
| 909 | * same pointer as returned by GET_CURRENT_SOFTWARE_FRAMEBUFFER; |
| 910 | * i.e. passing a pointer which is offset from the |
| 911 | * buffer is undefined. The width, height and pitch parameters |
| 912 | * must also match exactly to the values obtained from GET_CURRENT_SOFTWARE_FRAMEBUFFER. |
| 913 | * |
| 914 | * It is possible for a frontend to return a different pixel format |
| 915 | * than the one used in SET_PIXEL_FORMAT. This can happen if the frontend |
| 916 | * needs to perform conversion. |
| 917 | * |
| 918 | * It is still valid for a core to render to a different buffer |
| 919 | * even if GET_CURRENT_SOFTWARE_FRAMEBUFFER succeeds. |
| 920 | * |
| 921 | * A frontend must make sure that the pointer obtained from this function is |
| 922 | * writeable (and readable). |
| 923 | */ |
| 924 | |
| 925 | enum retro_hw_render_interface_type |
| 926 | { |
| 927 | RETRO_HW_RENDER_INTERFACE_VULKAN = 0, |
| 928 | RETRO_HW_RENDER_INTERFACE_DUMMY = INT_MAX |
| 929 | }; |
| 930 | |
| 931 | /* Base struct. All retro_hw_render_interface_* types |
| 932 | * contain at least these fields. */ |
| 933 | struct retro_hw_render_interface |
| 934 | { |
| 935 | enum retro_hw_render_interface_type interface_type; |
| 936 | unsigned interface_version; |
| 937 | }; |
| 938 | #define RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE (41 | RETRO_ENVIRONMENT_EXPERIMENTAL) |
| 939 | /* const struct retro_hw_render_interface ** -- |
| 940 | * Returns an API specific rendering interface for accessing API specific data. |
| 941 | * Not all HW rendering APIs support or need this. |
| 942 | * The contents of the returned pointer is specific to the rendering API |
| 943 | * being used. See the various headers like libretro_vulkan.h, etc. |
| 944 | * |
| 945 | * GET_HW_RENDER_INTERFACE cannot be called before context_reset has been called. |
| 946 | * Similarly, after context_destroyed callback returns, |
| 947 | * the contents of the HW_RENDER_INTERFACE are invalidated. |
| 948 | */ |
| 949 | |
| 950 | #define RETRO_MEMDESC_CONST (1 << 0) /* The frontend will never change this memory area once retro_load_game has returned. */ |
| 951 | #define RETRO_MEMDESC_BIGENDIAN (1 << 1) /* The memory area contains big endian data. Default is little endian. */ |
| 952 | #define RETRO_MEMDESC_ALIGN_2 (1 << 16) /* All memory access in this area is aligned to their own size, or 2, whichever is smaller. */ |
| 953 | #define RETRO_MEMDESC_ALIGN_4 (2 << 16) |
| 954 | #define RETRO_MEMDESC_ALIGN_8 (3 << 16) |
| 955 | #define RETRO_MEMDESC_MINSIZE_2 (1 << 24) /* All memory in this region is accessed at least 2 bytes at the time. */ |
| 956 | #define RETRO_MEMDESC_MINSIZE_4 (2 << 24) |
| 957 | #define RETRO_MEMDESC_MINSIZE_8 (3 << 24) |
| 958 | struct retro_memory_descriptor |
| 959 | { |
| 960 | uint64_t flags; |
| 961 | |
| 962 | /* Pointer to the start of the relevant ROM or RAM chip. |
| 963 | * It's strongly recommended to use 'offset' if possible, rather than |
| 964 | * doing math on the pointer. |
| 965 | * |
| 966 | * If the same byte is mapped my multiple descriptors, their descriptors |
| 967 | * must have the same pointer. |
| 968 | * If 'start' does not point to the first byte in the pointer, put the |
| 969 | * difference in 'offset' instead. |
| 970 | * |
| 971 | * May be NULL if there's nothing usable here (e.g. hardware registers and |
| 972 | * open bus). No flags should be set if the pointer is NULL. |
| 973 | * It's recommended to minimize the number of descriptors if possible, |
| 974 | * but not mandatory. */ |
| 975 | void *ptr; |
| 976 | size_t offset; |
| 977 | |
| 978 | /* This is the location in the emulated address space |
| 979 | * where the mapping starts. */ |
| 980 | size_t start; |
| 981 | |
| 982 | /* Which bits must be same as in 'start' for this mapping to apply. |
| 983 | * The first memory descriptor to claim a certain byte is the one |
| 984 | * that applies. |
| 985 | * A bit which is set in 'start' must also be set in this. |
| 986 | * Can be zero, in which case each byte is assumed mapped exactly once. |
| 987 | * In this case, 'len' must be a power of two. */ |
| 988 | size_t select; |
| 989 | |
| 990 | /* If this is nonzero, the set bits are assumed not connected to the |
| 991 | * memory chip's address pins. */ |
| 992 | size_t disconnect; |
| 993 | |
| 994 | /* This one tells the size of the current memory area. |
| 995 | * If, after start+disconnect are applied, the address is higher than |
| 996 | * this, the highest bit of the address is cleared. |
| 997 | * |
| 998 | * If the address is still too high, the next highest bit is cleared. |
| 999 | * Can be zero, in which case it's assumed to be infinite (as limited |
| 1000 | * by 'select' and 'disconnect'). */ |
| 1001 | size_t len; |
| 1002 | |
| 1003 | /* To go from emulated address to physical address, the following |
| 1004 | * order applies: |
| 1005 | * Subtract 'start', pick off 'disconnect', apply 'len', add 'offset'. |
| 1006 | * |
| 1007 | * The address space name must consist of only a-zA-Z0-9_-, |
| 1008 | * should be as short as feasible (maximum length is 8 plus the NUL), |
| 1009 | * and may not be any other address space plus one or more 0-9A-F |
| 1010 | * at the end. |
| 1011 | * However, multiple memory descriptors for the same address space is |
| 1012 | * allowed, and the address space name can be empty. NULL is treated |
| 1013 | * as empty. |
| 1014 | * |
| 1015 | * Address space names are case sensitive, but avoid lowercase if possible. |
| 1016 | * The same pointer may exist in multiple address spaces. |
| 1017 | * |
| 1018 | * Examples: |
| 1019 | * blank+blank - valid (multiple things may be mapped in the same namespace) |
| 1020 | * 'Sp'+'Sp' - valid (multiple things may be mapped in the same namespace) |
| 1021 | * 'A'+'B' - valid (neither is a prefix of each other) |
| 1022 | * 'S'+blank - valid ('S' is not in 0-9A-F) |
| 1023 | * 'a'+blank - valid ('a' is not in 0-9A-F) |
| 1024 | * 'a'+'A' - valid (neither is a prefix of each other) |
| 1025 | * 'AR'+blank - valid ('R' is not in 0-9A-F) |
| 1026 | * 'ARB'+blank - valid (the B can't be part of the address either, because |
| 1027 | * there is no namespace 'AR') |
| 1028 | * blank+'B' - not valid, because it's ambigous which address space B1234 |
| 1029 | * would refer to. |
| 1030 | * The length can't be used for that purpose; the frontend may want |
| 1031 | * to append arbitrary data to an address, without a separator. */ |
| 1032 | const char *addrspace; |
| 1033 | }; |
| 1034 | |
| 1035 | /* The frontend may use the largest value of 'start'+'select' in a |
| 1036 | * certain namespace to infer the size of the address space. |
| 1037 | * |
| 1038 | * If the address space is larger than that, a mapping with .ptr=NULL |
| 1039 | * should be at the end of the array, with .select set to all ones for |
| 1040 | * as long as the address space is big. |
| 1041 | * |
| 1042 | * Sample descriptors (minus .ptr, and RETRO_MEMFLAG_ on the flags): |
| 1043 | * SNES WRAM: |
| 1044 | * .start=0x7E0000, .len=0x20000 |
| 1045 | * (Note that this must be mapped before the ROM in most cases; some of the |
| 1046 | * ROM mappers |
| 1047 | * try to claim $7E0000, or at least $7E8000.) |
| 1048 | * SNES SPC700 RAM: |
| 1049 | * .addrspace="S", .len=0x10000 |
| 1050 | * SNES WRAM mirrors: |
| 1051 | * .flags=MIRROR, .start=0x000000, .select=0xC0E000, .len=0x2000 |
| 1052 | * .flags=MIRROR, .start=0x800000, .select=0xC0E000, .len=0x2000 |
| 1053 | * SNES WRAM mirrors, alternate equivalent descriptor: |
| 1054 | * .flags=MIRROR, .select=0x40E000, .disconnect=~0x1FFF |
| 1055 | * (Various similar constructions can be created by combining parts of |
| 1056 | * the above two.) |
| 1057 | * SNES LoROM (512KB, mirrored a couple of times): |
| 1058 | * .flags=CONST, .start=0x008000, .select=0x408000, .disconnect=0x8000, .len=512*1024 |
| 1059 | * .flags=CONST, .start=0x400000, .select=0x400000, .disconnect=0x8000, .len=512*1024 |
| 1060 | * SNES HiROM (4MB): |
| 1061 | * .flags=CONST, .start=0x400000, .select=0x400000, .len=4*1024*1024 |
| 1062 | * .flags=CONST, .offset=0x8000, .start=0x008000, .select=0x408000, .len=4*1024*1024 |
| 1063 | * SNES ExHiROM (8MB): |
| 1064 | * .flags=CONST, .offset=0, .start=0xC00000, .select=0xC00000, .len=4*1024*1024 |
| 1065 | * .flags=CONST, .offset=4*1024*1024, .start=0x400000, .select=0xC00000, .len=4*1024*1024 |
| 1066 | * .flags=CONST, .offset=0x8000, .start=0x808000, .select=0xC08000, .len=4*1024*1024 |
| 1067 | * .flags=CONST, .offset=4*1024*1024+0x8000, .start=0x008000, .select=0xC08000, .len=4*1024*1024 |
| 1068 | * Clarify the size of the address space: |
| 1069 | * .ptr=NULL, .select=0xFFFFFF |
| 1070 | * .len can be implied by .select in many of them, but was included for clarity. |
| 1071 | */ |
| 1072 | |
| 1073 | struct retro_memory_map |
| 1074 | { |
| 1075 | const struct retro_memory_descriptor *descriptors; |
| 1076 | unsigned num_descriptors; |
| 1077 | }; |
| 1078 | |
| 1079 | struct retro_controller_description |
| 1080 | { |
| 1081 | /* Human-readable description of the controller. Even if using a generic |
| 1082 | * input device type, this can be set to the particular device type the |
| 1083 | * core uses. */ |
| 1084 | const char *desc; |
| 1085 | |
| 1086 | /* Device type passed to retro_set_controller_port_device(). If the device |
| 1087 | * type is a sub-class of a generic input device type, use the |
| 1088 | * RETRO_DEVICE_SUBCLASS macro to create an ID. |
| 1089 | * |
| 1090 | * E.g. RETRO_DEVICE_SUBCLASS(RETRO_DEVICE_JOYPAD, 1). */ |
| 1091 | unsigned id; |
| 1092 | }; |
| 1093 | |
| 1094 | struct retro_controller_info |
| 1095 | { |
| 1096 | const struct retro_controller_description *types; |
| 1097 | unsigned num_types; |
| 1098 | }; |
| 1099 | |
| 1100 | struct retro_subsystem_memory_info |
| 1101 | { |
| 1102 | /* The extension associated with a memory type, e.g. "psram". */ |
| 1103 | const char *extension; |
| 1104 | |
| 1105 | /* The memory type for retro_get_memory(). This should be at |
| 1106 | * least 0x100 to avoid conflict with standardized |
| 1107 | * libretro memory types. */ |
| 1108 | unsigned type; |
| 1109 | }; |
| 1110 | |
| 1111 | struct retro_subsystem_rom_info |
| 1112 | { |
| 1113 | /* Describes what the content is (SGB BIOS, GB ROM, etc). */ |
| 1114 | const char *desc; |
| 1115 | |
| 1116 | /* Same definition as retro_get_system_info(). */ |
| 1117 | const char *valid_extensions; |
| 1118 | |
| 1119 | /* Same definition as retro_get_system_info(). */ |
| 1120 | bool need_fullpath; |
| 1121 | |
| 1122 | /* Same definition as retro_get_system_info(). */ |
| 1123 | bool block_extract; |
| 1124 | |
| 1125 | /* This is set if the content is required to load a game. |
| 1126 | * If this is set to false, a zeroed-out retro_game_info can be passed. */ |
| 1127 | bool required; |
| 1128 | |
| 1129 | /* Content can have multiple associated persistent |
| 1130 | * memory types (retro_get_memory()). */ |
| 1131 | const struct retro_subsystem_memory_info *memory; |
| 1132 | unsigned num_memory; |
| 1133 | }; |
| 1134 | |
| 1135 | struct retro_subsystem_info |
| 1136 | { |
| 1137 | /* Human-readable string of the subsystem type, e.g. "Super GameBoy" */ |
| 1138 | const char *desc; |
| 1139 | |
| 1140 | /* A computer friendly short string identifier for the subsystem type. |
| 1141 | * This name must be [a-z]. |
| 1142 | * E.g. if desc is "Super GameBoy", this can be "sgb". |
| 1143 | * This identifier can be used for command-line interfaces, etc. |
| 1144 | */ |
| 1145 | const char *ident; |
| 1146 | |
| 1147 | /* Infos for each content file. The first entry is assumed to be the |
| 1148 | * "most significant" content for frontend purposes. |
| 1149 | * E.g. with Super GameBoy, the first content should be the GameBoy ROM, |
| 1150 | * as it is the most "significant" content to a user. |
| 1151 | * If a frontend creates new file paths based on the content used |
| 1152 | * (e.g. savestates), it should use the path for the first ROM to do so. */ |
| 1153 | const struct retro_subsystem_rom_info *roms; |
| 1154 | |
| 1155 | /* Number of content files associated with a subsystem. */ |
| 1156 | unsigned num_roms; |
| 1157 | |
| 1158 | /* The type passed to retro_load_game_special(). */ |
| 1159 | unsigned id; |
| 1160 | }; |
| 1161 | |
| 1162 | typedef void (*retro_proc_address_t)(void); |
| 1163 | |
| 1164 | /* libretro API extension functions: |
| 1165 | * (None here so far). |
| 1166 | * |
| 1167 | * Get a symbol from a libretro core. |
| 1168 | * Cores should only return symbols which are actual |
| 1169 | * extensions to the libretro API. |
| 1170 | * |
| 1171 | * Frontends should not use this to obtain symbols to standard |
| 1172 | * libretro entry points (static linking or dlsym). |
| 1173 | * |
| 1174 | * The symbol name must be equal to the function name, |
| 1175 | * e.g. if void retro_foo(void); exists, the symbol must be called "retro_foo". |
| 1176 | * The returned function pointer must be cast to the corresponding type. |
| 1177 | */ |
| 1178 | typedef retro_proc_address_t (*retro_get_proc_address_t)(const char *sym); |
| 1179 | |
| 1180 | struct retro_get_proc_address_interface |
| 1181 | { |
| 1182 | retro_get_proc_address_t get_proc_address; |
| 1183 | }; |
| 1184 | |
| 1185 | enum retro_log_level |
| 1186 | { |
| 1187 | RETRO_LOG_DEBUG = 0, |
| 1188 | RETRO_LOG_INFO, |
| 1189 | RETRO_LOG_WARN, |
| 1190 | RETRO_LOG_ERROR, |
| 1191 | |
| 1192 | RETRO_LOG_DUMMY = INT_MAX |
| 1193 | }; |
| 1194 | |
| 1195 | /* Logging function. Takes log level argument as well. */ |
| 1196 | typedef void (*retro_log_printf_t)(enum retro_log_level level, |
| 1197 | const char *fmt, ...); |
| 1198 | |
| 1199 | struct retro_log_callback |
| 1200 | { |
| 1201 | retro_log_printf_t log; |
| 1202 | }; |
| 1203 | |
| 1204 | /* Performance related functions */ |
| 1205 | |
| 1206 | /* ID values for SIMD CPU features */ |
| 1207 | #define RETRO_SIMD_SSE (1 << 0) |
| 1208 | #define RETRO_SIMD_SSE2 (1 << 1) |
| 1209 | #define RETRO_SIMD_VMX (1 << 2) |
| 1210 | #define RETRO_SIMD_VMX128 (1 << 3) |
| 1211 | #define RETRO_SIMD_AVX (1 << 4) |
| 1212 | #define RETRO_SIMD_NEON (1 << 5) |
| 1213 | #define RETRO_SIMD_SSE3 (1 << 6) |
| 1214 | #define RETRO_SIMD_SSSE3 (1 << 7) |
| 1215 | #define RETRO_SIMD_MMX (1 << 8) |
| 1216 | #define RETRO_SIMD_MMXEXT (1 << 9) |
| 1217 | #define RETRO_SIMD_SSE4 (1 << 10) |
| 1218 | #define RETRO_SIMD_SSE42 (1 << 11) |
| 1219 | #define RETRO_SIMD_AVX2 (1 << 12) |
| 1220 | #define RETRO_SIMD_VFPU (1 << 13) |
| 1221 | #define RETRO_SIMD_PS (1 << 14) |
| 1222 | #define RETRO_SIMD_AES (1 << 15) |
| 1223 | #define RETRO_SIMD_VFPV3 (1 << 16) |
| 1224 | #define RETRO_SIMD_VFPV4 (1 << 17) |
| 1225 | #define RETRO_SIMD_POPCNT (1 << 18) |
| 1226 | #define RETRO_SIMD_MOVBE (1 << 19) |
| 1227 | |
| 1228 | typedef uint64_t retro_perf_tick_t; |
| 1229 | typedef int64_t retro_time_t; |
| 1230 | |
| 1231 | struct retro_perf_counter |
| 1232 | { |
| 1233 | const char *ident; |
| 1234 | retro_perf_tick_t start; |
| 1235 | retro_perf_tick_t total; |
| 1236 | retro_perf_tick_t call_cnt; |
| 1237 | |
| 1238 | bool registered; |
| 1239 | }; |
| 1240 | |
| 1241 | /* Returns current time in microseconds. |
| 1242 | * Tries to use the most accurate timer available. |
| 1243 | */ |
| 1244 | typedef retro_time_t (*retro_perf_get_time_usec_t)(void); |
| 1245 | |
| 1246 | /* A simple counter. Usually nanoseconds, but can also be CPU cycles. |
| 1247 | * Can be used directly if desired (when creating a more sophisticated |
| 1248 | * performance counter system). |
| 1249 | * */ |
| 1250 | typedef retro_perf_tick_t (*retro_perf_get_counter_t)(void); |
| 1251 | |
| 1252 | /* Returns a bit-mask of detected CPU features (RETRO_SIMD_*). */ |
| 1253 | typedef uint64_t (*retro_get_cpu_features_t)(void); |
| 1254 | |
| 1255 | /* Asks frontend to log and/or display the state of performance counters. |
| 1256 | * Performance counters can always be poked into manually as well. |
| 1257 | */ |
| 1258 | typedef void (*retro_perf_log_t)(void); |
| 1259 | |
| 1260 | /* Register a performance counter. |
| 1261 | * ident field must be set with a discrete value and other values in |
| 1262 | * retro_perf_counter must be 0. |
| 1263 | * Registering can be called multiple times. To avoid calling to |
| 1264 | * frontend redundantly, you can check registered field first. */ |
| 1265 | typedef void (*retro_perf_register_t)(struct retro_perf_counter *counter); |
| 1266 | |
| 1267 | /* Starts a registered counter. */ |
| 1268 | typedef void (*retro_perf_start_t)(struct retro_perf_counter *counter); |
| 1269 | |
| 1270 | /* Stops a registered counter. */ |
| 1271 | typedef void (*retro_perf_stop_t)(struct retro_perf_counter *counter); |
| 1272 | |
| 1273 | /* For convenience it can be useful to wrap register, start and stop in macros. |
| 1274 | * E.g.: |
| 1275 | * #ifdef LOG_PERFORMANCE |
| 1276 | * #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name)) |
| 1277 | * #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name)) |
| 1278 | * #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name)) |
| 1279 | * #else |
| 1280 | * ... Blank macros ... |
| 1281 | * #endif |
| 1282 | * |
| 1283 | * These can then be used mid-functions around code snippets. |
| 1284 | * |
| 1285 | * extern struct retro_perf_callback perf_cb; * Somewhere in the core. |
| 1286 | * |
| 1287 | * void do_some_heavy_work(void) |
| 1288 | * { |
| 1289 | * RETRO_PERFORMANCE_INIT(cb, work_1; |
| 1290 | * RETRO_PERFORMANCE_START(cb, work_1); |
| 1291 | * heavy_work_1(); |
| 1292 | * RETRO_PERFORMANCE_STOP(cb, work_1); |
| 1293 | * |
| 1294 | * RETRO_PERFORMANCE_INIT(cb, work_2); |
| 1295 | * RETRO_PERFORMANCE_START(cb, work_2); |
| 1296 | * heavy_work_2(); |
| 1297 | * RETRO_PERFORMANCE_STOP(cb, work_2); |
| 1298 | * } |
| 1299 | * |
| 1300 | * void retro_deinit(void) |
| 1301 | * { |
| 1302 | * perf_cb.perf_log(); * Log all perf counters here for example. |
| 1303 | * } |
| 1304 | */ |
| 1305 | |
| 1306 | struct retro_perf_callback |
| 1307 | { |
| 1308 | retro_perf_get_time_usec_t get_time_usec; |
| 1309 | retro_get_cpu_features_t get_cpu_features; |
| 1310 | |
| 1311 | retro_perf_get_counter_t get_perf_counter; |
| 1312 | retro_perf_register_t perf_register; |
| 1313 | retro_perf_start_t perf_start; |
| 1314 | retro_perf_stop_t perf_stop; |
| 1315 | retro_perf_log_t perf_log; |
| 1316 | }; |
| 1317 | |
| 1318 | /* FIXME: Document the sensor API and work out behavior. |
| 1319 | * It will be marked as experimental until then. |
| 1320 | */ |
| 1321 | enum retro_sensor_action |
| 1322 | { |
| 1323 | RETRO_SENSOR_ACCELEROMETER_ENABLE = 0, |
| 1324 | RETRO_SENSOR_ACCELEROMETER_DISABLE, |
| 1325 | |
| 1326 | RETRO_SENSOR_DUMMY = INT_MAX |
| 1327 | }; |
| 1328 | |
| 1329 | /* Id values for SENSOR types. */ |
| 1330 | #define RETRO_SENSOR_ACCELEROMETER_X 0 |
| 1331 | #define RETRO_SENSOR_ACCELEROMETER_Y 1 |
| 1332 | #define RETRO_SENSOR_ACCELEROMETER_Z 2 |
| 1333 | |
| 1334 | typedef bool (*retro_set_sensor_state_t)(unsigned port, |
| 1335 | enum retro_sensor_action action, unsigned rate); |
| 1336 | |
| 1337 | typedef float (*retro_sensor_get_input_t)(unsigned port, unsigned id); |
| 1338 | |
| 1339 | struct retro_sensor_interface |
| 1340 | { |
| 1341 | retro_set_sensor_state_t set_sensor_state; |
| 1342 | retro_sensor_get_input_t get_sensor_input; |
| 1343 | }; |
| 1344 | |
| 1345 | enum retro_camera_buffer |
| 1346 | { |
| 1347 | RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0, |
| 1348 | RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER, |
| 1349 | |
| 1350 | RETRO_CAMERA_BUFFER_DUMMY = INT_MAX |
| 1351 | }; |
| 1352 | |
| 1353 | /* Starts the camera driver. Can only be called in retro_run(). */ |
| 1354 | typedef bool (*retro_camera_start_t)(void); |
| 1355 | |
| 1356 | /* Stops the camera driver. Can only be called in retro_run(). */ |
| 1357 | typedef void (*retro_camera_stop_t)(void); |
| 1358 | |
| 1359 | /* Callback which signals when the camera driver is initialized |
| 1360 | * and/or deinitialized. |
| 1361 | * retro_camera_start_t can be called in initialized callback. |
| 1362 | */ |
| 1363 | typedef void (*retro_camera_lifetime_status_t)(void); |
| 1364 | |
| 1365 | /* A callback for raw framebuffer data. buffer points to an XRGB8888 buffer. |
| 1366 | * Width, height and pitch are similar to retro_video_refresh_t. |
| 1367 | * First pixel is top-left origin. |
| 1368 | */ |
| 1369 | typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer, |
| 1370 | unsigned width, unsigned height, size_t pitch); |
| 1371 | |
| 1372 | /* A callback for when OpenGL textures are used. |
| 1373 | * |
| 1374 | * texture_id is a texture owned by camera driver. |
| 1375 | * Its state or content should be considered immutable, except for things like |
| 1376 | * texture filtering and clamping. |
| 1377 | * |
| 1378 | * texture_target is the texture target for the GL texture. |
| 1379 | * These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly |
| 1380 | * more depending on extensions. |
| 1381 | * |
| 1382 | * affine points to a packed 3x3 column-major matrix used to apply an affine |
| 1383 | * transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0)) |
| 1384 | * After transform, normalized texture coord (0, 0) should be bottom-left |
| 1385 | * and (1, 1) should be top-right (or (width, height) for RECTANGLE). |
| 1386 | * |
| 1387 | * GL-specific typedefs are avoided here to avoid relying on gl.h in |
| 1388 | * the API definition. |
| 1389 | */ |
| 1390 | typedef void (*retro_camera_frame_opengl_texture_t)(unsigned texture_id, |
| 1391 | unsigned texture_target, const float *affine); |
| 1392 | |
| 1393 | struct retro_camera_callback |
| 1394 | { |
| 1395 | /* Set by libretro core. |
| 1396 | * Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER). |
| 1397 | */ |
| 1398 | uint64_t caps; |
| 1399 | |
| 1400 | unsigned width; /* Desired resolution for camera. Is only used as a hint. */ |
| 1401 | unsigned height; |
| 1402 | retro_camera_start_t start; /* Set by frontend. */ |
| 1403 | retro_camera_stop_t stop; /* Set by frontend. */ |
| 1404 | |
| 1405 | /* Set by libretro core if raw framebuffer callbacks will be used. */ |
| 1406 | retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer; |
| 1407 | /* Set by libretro core if OpenGL texture callbacks will be used. */ |
| 1408 | retro_camera_frame_opengl_texture_t frame_opengl_texture; |
| 1409 | |
| 1410 | /* Set by libretro core. Called after camera driver is initialized and |
| 1411 | * ready to be started. |
| 1412 | * Can be NULL, in which this callback is not called. |
| 1413 | */ |
| 1414 | retro_camera_lifetime_status_t initialized; |
| 1415 | |
| 1416 | /* Set by libretro core. Called right before camera driver is |
| 1417 | * deinitialized. |
| 1418 | * Can be NULL, in which this callback is not called. |
| 1419 | */ |
| 1420 | retro_camera_lifetime_status_t deinitialized; |
| 1421 | }; |
| 1422 | |
| 1423 | /* Sets the interval of time and/or distance at which to update/poll |
| 1424 | * location-based data. |
| 1425 | * |
| 1426 | * To ensure compatibility with all location-based implementations, |
| 1427 | * values for both interval_ms and interval_distance should be provided. |
| 1428 | * |
| 1429 | * interval_ms is the interval expressed in milliseconds. |
| 1430 | * interval_distance is the distance interval expressed in meters. |
| 1431 | */ |
| 1432 | typedef void (*retro_location_set_interval_t)(unsigned interval_ms, |
| 1433 | unsigned interval_distance); |
| 1434 | |
| 1435 | /* Start location services. The device will start listening for changes to the |
| 1436 | * current location at regular intervals (which are defined with |
| 1437 | * retro_location_set_interval_t). */ |
| 1438 | typedef bool (*retro_location_start_t)(void); |
| 1439 | |
| 1440 | /* Stop location services. The device will stop listening for changes |
| 1441 | * to the current location. */ |
| 1442 | typedef void (*retro_location_stop_t)(void); |
| 1443 | |
| 1444 | /* Get the position of the current location. Will set parameters to |
| 1445 | * 0 if no new location update has happened since the last time. */ |
| 1446 | typedef bool (*retro_location_get_position_t)(double *lat, double *lon, |
| 1447 | double *horiz_accuracy, double *vert_accuracy); |
| 1448 | |
| 1449 | /* Callback which signals when the location driver is initialized |
| 1450 | * and/or deinitialized. |
| 1451 | * retro_location_start_t can be called in initialized callback. |
| 1452 | */ |
| 1453 | typedef void (*retro_location_lifetime_status_t)(void); |
| 1454 | |
| 1455 | struct retro_location_callback |
| 1456 | { |
| 1457 | retro_location_start_t start; |
| 1458 | retro_location_stop_t stop; |
| 1459 | retro_location_get_position_t get_position; |
| 1460 | retro_location_set_interval_t set_interval; |
| 1461 | |
| 1462 | retro_location_lifetime_status_t initialized; |
| 1463 | retro_location_lifetime_status_t deinitialized; |
| 1464 | }; |
| 1465 | |
| 1466 | enum retro_rumble_effect |
| 1467 | { |
| 1468 | RETRO_RUMBLE_STRONG = 0, |
| 1469 | RETRO_RUMBLE_WEAK = 1, |
| 1470 | |
| 1471 | RETRO_RUMBLE_DUMMY = INT_MAX |
| 1472 | }; |
| 1473 | |
| 1474 | /* Sets rumble state for joypad plugged in port 'port'. |
| 1475 | * Rumble effects are controlled independently, |
| 1476 | * and setting e.g. strong rumble does not override weak rumble. |
| 1477 | * Strength has a range of [0, 0xffff]. |
| 1478 | * |
| 1479 | * Returns true if rumble state request was honored. |
| 1480 | * Calling this before first retro_run() is likely to return false. */ |
| 1481 | typedef bool (*retro_set_rumble_state_t)(unsigned port, |
| 1482 | enum retro_rumble_effect effect, uint16_t strength); |
| 1483 | |
| 1484 | struct retro_rumble_interface |
| 1485 | { |
| 1486 | retro_set_rumble_state_t set_rumble_state; |
| 1487 | }; |
| 1488 | |
| 1489 | /* Notifies libretro that audio data should be written. */ |
| 1490 | typedef void (*retro_audio_callback_t)(void); |
| 1491 | |
| 1492 | /* True: Audio driver in frontend is active, and callback is |
| 1493 | * expected to be called regularily. |
| 1494 | * False: Audio driver in frontend is paused or inactive. |
| 1495 | * Audio callback will not be called until set_state has been |
| 1496 | * called with true. |
| 1497 | * Initial state is false (inactive). |
| 1498 | */ |
| 1499 | typedef void (*retro_audio_set_state_callback_t)(bool enabled); |
| 1500 | |
| 1501 | struct retro_audio_callback |
| 1502 | { |
| 1503 | retro_audio_callback_t callback; |
| 1504 | retro_audio_set_state_callback_t set_state; |
| 1505 | }; |
| 1506 | |
| 1507 | /* Notifies a libretro core of time spent since last invocation |
| 1508 | * of retro_run() in microseconds. |
| 1509 | * |
| 1510 | * It will be called right before retro_run() every frame. |
| 1511 | * The frontend can tamper with timing to support cases like |
| 1512 | * fast-forward, slow-motion and framestepping. |
| 1513 | * |
| 1514 | * In those scenarios the reference frame time value will be used. */ |
| 1515 | typedef int64_t retro_usec_t; |
| 1516 | typedef void (*retro_frame_time_callback_t)(retro_usec_t usec); |
| 1517 | struct retro_frame_time_callback |
| 1518 | { |
| 1519 | retro_frame_time_callback_t callback; |
| 1520 | /* Represents the time of one frame. It is computed as |
| 1521 | * 1000000 / fps, but the implementation will resolve the |
| 1522 | * rounding to ensure that framestepping, etc is exact. */ |
| 1523 | retro_usec_t reference; |
| 1524 | }; |
| 1525 | |
| 1526 | /* Pass this to retro_video_refresh_t if rendering to hardware. |
| 1527 | * Passing NULL to retro_video_refresh_t is still a frame dupe as normal. |
| 1528 | * */ |
| 1529 | #define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1) |
| 1530 | |
| 1531 | /* Invalidates the current HW context. |
| 1532 | * Any GL state is lost, and must not be deinitialized explicitly. |
| 1533 | * If explicit deinitialization is desired by the libretro core, |
| 1534 | * it should implement context_destroy callback. |
| 1535 | * If called, all GPU resources must be reinitialized. |
| 1536 | * Usually called when frontend reinits video driver. |
| 1537 | * Also called first time video driver is initialized, |
| 1538 | * allowing libretro core to initialize resources. |
| 1539 | */ |
| 1540 | typedef void (*retro_hw_context_reset_t)(void); |
| 1541 | |
| 1542 | /* Gets current framebuffer which is to be rendered to. |
| 1543 | * Could change every frame potentially. |
| 1544 | */ |
| 1545 | typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void); |
| 1546 | |
| 1547 | /* Get a symbol from HW context. */ |
| 1548 | typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym); |
| 1549 | |
| 1550 | enum retro_hw_context_type |
| 1551 | { |
| 1552 | RETRO_HW_CONTEXT_NONE = 0, |
| 1553 | /* OpenGL 2.x. Driver can choose to use latest compatibility context. */ |
| 1554 | RETRO_HW_CONTEXT_OPENGL = 1, |
| 1555 | /* OpenGL ES 2.0. */ |
| 1556 | RETRO_HW_CONTEXT_OPENGLES2 = 2, |
| 1557 | /* Modern desktop core GL context. Use version_major/ |
| 1558 | * version_minor fields to set GL version. */ |
| 1559 | RETRO_HW_CONTEXT_OPENGL_CORE = 3, |
| 1560 | /* OpenGL ES 3.0 */ |
| 1561 | RETRO_HW_CONTEXT_OPENGLES3 = 4, |
| 1562 | /* OpenGL ES 3.1+. Set version_major/version_minor. For GLES2 and GLES3, |
| 1563 | * use the corresponding enums directly. */ |
| 1564 | RETRO_HW_CONTEXT_OPENGLES_VERSION = 5, |
| 1565 | |
| 1566 | /* Vulkan, see RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE. */ |
| 1567 | RETRO_HW_CONTEXT_VULKAN = 6, |
| 1568 | |
| 1569 | RETRO_HW_CONTEXT_DUMMY = INT_MAX |
| 1570 | }; |
| 1571 | |
| 1572 | struct retro_hw_render_callback |
| 1573 | { |
| 1574 | /* Which API to use. Set by libretro core. */ |
| 1575 | enum retro_hw_context_type context_type; |
| 1576 | |
| 1577 | /* Called when a context has been created or when it has been reset. |
| 1578 | * An OpenGL context is only valid after context_reset() has been called. |
| 1579 | * |
| 1580 | * When context_reset is called, OpenGL resources in the libretro |
| 1581 | * implementation are guaranteed to be invalid. |
| 1582 | * |
| 1583 | * It is possible that context_reset is called multiple times during an |
| 1584 | * application lifecycle. |
| 1585 | * If context_reset is called without any notification (context_destroy), |
| 1586 | * the OpenGL context was lost and resources should just be recreated |
| 1587 | * without any attempt to "free" old resources. |
| 1588 | */ |
| 1589 | retro_hw_context_reset_t context_reset; |
| 1590 | |
| 1591 | /* Set by frontend. |
| 1592 | * TODO: This is rather obsolete. The frontend should not |
| 1593 | * be providing preallocated framebuffers. */ |
| 1594 | retro_hw_get_current_framebuffer_t get_current_framebuffer; |
| 1595 | |
| 1596 | /* Set by frontend. */ |
| 1597 | retro_hw_get_proc_address_t get_proc_address; |
| 1598 | |
| 1599 | /* Set if render buffers should have depth component attached. |
| 1600 | * TODO: Obsolete. */ |
| 1601 | bool depth; |
| 1602 | |
| 1603 | /* Set if stencil buffers should be attached. |
| 1604 | * TODO: Obsolete. */ |
| 1605 | bool stencil; |
| 1606 | |
| 1607 | /* If depth and stencil are true, a packed 24/8 buffer will be added. |
| 1608 | * Only attaching stencil is invalid and will be ignored. */ |
| 1609 | |
| 1610 | /* Use conventional bottom-left origin convention. If false, |
| 1611 | * standard libretro top-left origin semantics are used. |
| 1612 | * TODO: Move to GL specific interface. */ |
| 1613 | bool bottom_left_origin; |
| 1614 | |
| 1615 | /* Major version number for core GL context or GLES 3.1+. */ |
| 1616 | unsigned version_major; |
| 1617 | |
| 1618 | /* Minor version number for core GL context or GLES 3.1+. */ |
| 1619 | unsigned version_minor; |
| 1620 | |
| 1621 | /* If this is true, the frontend will go very far to avoid |
| 1622 | * resetting context in scenarios like toggling fullscreen, etc. |
| 1623 | * TODO: Obsolete? Maybe frontend should just always assume this ... |
| 1624 | */ |
| 1625 | bool cache_context; |
| 1626 | |
| 1627 | /* The reset callback might still be called in extreme situations |
| 1628 | * such as if the context is lost beyond recovery. |
| 1629 | * |
| 1630 | * For optimal stability, set this to false, and allow context to be |
| 1631 | * reset at any time. |
| 1632 | */ |
| 1633 | |
| 1634 | /* A callback to be called before the context is destroyed in a |
| 1635 | * controlled way by the frontend. */ |
| 1636 | retro_hw_context_reset_t context_destroy; |
| 1637 | |
| 1638 | /* OpenGL resources can be deinitialized cleanly at this step. |
| 1639 | * context_destroy can be set to NULL, in which resources will |
| 1640 | * just be destroyed without any notification. |
| 1641 | * |
| 1642 | * Even when context_destroy is non-NULL, it is possible that |
| 1643 | * context_reset is called without any destroy notification. |
| 1644 | * This happens if context is lost by external factors (such as |
| 1645 | * notified by GL_ARB_robustness). |
| 1646 | * |
| 1647 | * In this case, the context is assumed to be already dead, |
| 1648 | * and the libretro implementation must not try to free any OpenGL |
| 1649 | * resources in the subsequent context_reset. |
| 1650 | */ |
| 1651 | |
| 1652 | /* Creates a debug context. */ |
| 1653 | bool debug_context; |
| 1654 | }; |
| 1655 | |
| 1656 | /* Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. |
| 1657 | * Called by the frontend in response to keyboard events. |
| 1658 | * down is set if the key is being pressed, or false if it is being released. |
| 1659 | * keycode is the RETROK value of the char. |
| 1660 | * character is the text character of the pressed key. (UTF-32). |
| 1661 | * key_modifiers is a set of RETROKMOD values or'ed together. |
| 1662 | * |
| 1663 | * The pressed/keycode state can be indepedent of the character. |
| 1664 | * It is also possible that multiple characters are generated from a |
| 1665 | * single keypress. |
| 1666 | * Keycode events should be treated separately from character events. |
| 1667 | * However, when possible, the frontend should try to synchronize these. |
| 1668 | * If only a character is posted, keycode should be RETROK_UNKNOWN. |
| 1669 | * |
| 1670 | * Similarily if only a keycode event is generated with no corresponding |
| 1671 | * character, character should be 0. |
| 1672 | */ |
| 1673 | typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, |
| 1674 | uint32_t character, uint16_t key_modifiers); |
| 1675 | |
| 1676 | struct retro_keyboard_callback |
| 1677 | { |
| 1678 | retro_keyboard_event_t callback; |
| 1679 | }; |
| 1680 | |
| 1681 | /* Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE. |
| 1682 | * Should be set for implementations which can swap out multiple disk |
| 1683 | * images in runtime. |
| 1684 | * |
| 1685 | * If the implementation can do this automatically, it should strive to do so. |
| 1686 | * However, there are cases where the user must manually do so. |
| 1687 | * |
| 1688 | * Overview: To swap a disk image, eject the disk image with |
| 1689 | * set_eject_state(true). |
| 1690 | * Set the disk index with set_image_index(index). Insert the disk again |
| 1691 | * with set_eject_state(false). |
| 1692 | */ |
| 1693 | |
| 1694 | /* If ejected is true, "ejects" the virtual disk tray. |
| 1695 | * When ejected, the disk image index can be set. |
| 1696 | */ |
| 1697 | typedef bool (*retro_set_eject_state_t)(bool ejected); |
| 1698 | |
| 1699 | /* Gets current eject state. The initial state is 'not ejected'. */ |
| 1700 | typedef bool (*retro_get_eject_state_t)(void); |
| 1701 | |
| 1702 | /* Gets current disk index. First disk is index 0. |
| 1703 | * If return value is >= get_num_images(), no disk is currently inserted. |
| 1704 | */ |
| 1705 | typedef unsigned (*retro_get_image_index_t)(void); |
| 1706 | |
| 1707 | /* Sets image index. Can only be called when disk is ejected. |
| 1708 | * The implementation supports setting "no disk" by using an |
| 1709 | * index >= get_num_images(). |
| 1710 | */ |
| 1711 | typedef bool (*retro_set_image_index_t)(unsigned index); |
| 1712 | |
| 1713 | /* Gets total number of images which are available to use. */ |
| 1714 | typedef unsigned (*retro_get_num_images_t)(void); |
| 1715 | |
| 1716 | struct retro_game_info; |
| 1717 | |
| 1718 | /* Replaces the disk image associated with index. |
| 1719 | * Arguments to pass in info have same requirements as retro_load_game(). |
| 1720 | * Virtual disk tray must be ejected when calling this. |
| 1721 | * |
| 1722 | * Replacing a disk image with info = NULL will remove the disk image |
| 1723 | * from the internal list. |
| 1724 | * As a result, calls to get_image_index() can change. |
| 1725 | * |
| 1726 | * E.g. replace_image_index(1, NULL), and previous get_image_index() |
| 1727 | * returned 4 before. |
| 1728 | * Index 1 will be removed, and the new index is 3. |
| 1729 | */ |
| 1730 | typedef bool (*retro_replace_image_index_t)(unsigned index, |
| 1731 | const struct retro_game_info *info); |
| 1732 | |
| 1733 | /* Adds a new valid index (get_num_images()) to the internal disk list. |
| 1734 | * This will increment subsequent return values from get_num_images() by 1. |
| 1735 | * This image index cannot be used until a disk image has been set |
| 1736 | * with replace_image_index. */ |
| 1737 | typedef bool (*retro_add_image_index_t)(void); |
| 1738 | |
| 1739 | struct retro_disk_control_callback |
| 1740 | { |
| 1741 | retro_set_eject_state_t set_eject_state; |
| 1742 | retro_get_eject_state_t get_eject_state; |
| 1743 | |
| 1744 | retro_get_image_index_t get_image_index; |
| 1745 | retro_set_image_index_t set_image_index; |
| 1746 | retro_get_num_images_t get_num_images; |
| 1747 | |
| 1748 | retro_replace_image_index_t replace_image_index; |
| 1749 | retro_add_image_index_t add_image_index; |
| 1750 | }; |
| 1751 | |
| 1752 | enum retro_pixel_format |
| 1753 | { |
| 1754 | /* 0RGB1555, native endian. |
| 1755 | * 0 bit must be set to 0. |
| 1756 | * This pixel format is default for compatibility concerns only. |
| 1757 | * If a 15/16-bit pixel format is desired, consider using RGB565. */ |
| 1758 | RETRO_PIXEL_FORMAT_0RGB1555 = 0, |
| 1759 | |
| 1760 | /* XRGB8888, native endian. |
| 1761 | * X bits are ignored. */ |
| 1762 | RETRO_PIXEL_FORMAT_XRGB8888 = 1, |
| 1763 | |
| 1764 | /* RGB565, native endian. |
| 1765 | * This pixel format is the recommended format to use if a 15/16-bit |
| 1766 | * format is desired as it is the pixel format that is typically |
| 1767 | * available on a wide range of low-power devices. |
| 1768 | * |
| 1769 | * It is also natively supported in APIs like OpenGL ES. */ |
| 1770 | RETRO_PIXEL_FORMAT_RGB565 = 2, |
| 1771 | |
| 1772 | /* Ensure sizeof() == sizeof(int). */ |
| 1773 | RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX |
| 1774 | }; |
| 1775 | |
| 1776 | struct retro_message |
| 1777 | { |
| 1778 | const char *msg; /* Message to be displayed. */ |
| 1779 | unsigned frames; /* Duration in frames of message. */ |
| 1780 | }; |
| 1781 | |
| 1782 | /* Describes how the libretro implementation maps a libretro input bind |
| 1783 | * to its internal input system through a human readable string. |
| 1784 | * This string can be used to better let a user configure input. */ |
| 1785 | struct retro_input_descriptor |
| 1786 | { |
| 1787 | /* Associates given parameters with a description. */ |
| 1788 | unsigned port; |
| 1789 | unsigned device; |
| 1790 | unsigned index; |
| 1791 | unsigned id; |
| 1792 | |
| 1793 | /* Human readable description for parameters. |
| 1794 | * The pointer must remain valid until |
| 1795 | * retro_unload_game() is called. */ |
| 1796 | const char *description; |
| 1797 | }; |
| 1798 | |
| 1799 | struct retro_system_info |
| 1800 | { |
| 1801 | /* All pointers are owned by libretro implementation, and pointers must |
| 1802 | * remain valid until retro_deinit() is called. */ |
| 1803 | |
| 1804 | const char *library_name; /* Descriptive name of library. Should not |
| 1805 | * contain any version numbers, etc. */ |
| 1806 | const char *library_version; /* Descriptive version of core. */ |
| 1807 | |
| 1808 | const char *valid_extensions; /* A string listing probably content |
| 1809 | * extensions the core will be able to |
| 1810 | * load, separated with pipe. |
| 1811 | * I.e. "bin|rom|iso". |
| 1812 | * Typically used for a GUI to filter |
| 1813 | * out extensions. */ |
| 1814 | |
| 1815 | /* If true, retro_load_game() is guaranteed to provide a valid pathname |
| 1816 | * in retro_game_info::path. |
| 1817 | * ::data and ::size are both invalid. |
| 1818 | * |
| 1819 | * If false, ::data and ::size are guaranteed to be valid, but ::path |
| 1820 | * might not be valid. |
| 1821 | * |
| 1822 | * This is typically set to true for libretro implementations that must |
| 1823 | * load from file. |
| 1824 | * Implementations should strive for setting this to false, as it allows |
| 1825 | * the frontend to perform patching, etc. */ |
| 1826 | bool need_fullpath; |
| 1827 | |
| 1828 | /* If true, the frontend is not allowed to extract any archives before |
| 1829 | * loading the real content. |
| 1830 | * Necessary for certain libretro implementations that load games |
| 1831 | * from zipped archives. */ |
| 1832 | bool block_extract; |
| 1833 | }; |
| 1834 | |
| 1835 | struct retro_game_geometry |
| 1836 | { |
| 1837 | unsigned base_width; /* Nominal video width of game. */ |
| 1838 | unsigned base_height; /* Nominal video height of game. */ |
| 1839 | unsigned max_width; /* Maximum possible width of game. */ |
| 1840 | unsigned max_height; /* Maximum possible height of game. */ |
| 1841 | |
| 1842 | float aspect_ratio; /* Nominal aspect ratio of game. If |
| 1843 | * aspect_ratio is <= 0.0, an aspect ratio |
| 1844 | * of base_width / base_height is assumed. |
| 1845 | * A frontend could override this setting, |
| 1846 | * if desired. */ |
| 1847 | }; |
| 1848 | |
| 1849 | struct retro_system_timing |
| 1850 | { |
| 1851 | double fps; /* FPS of video content. */ |
| 1852 | double sample_rate; /* Sampling rate of audio. */ |
| 1853 | }; |
| 1854 | |
| 1855 | struct retro_system_av_info |
| 1856 | { |
| 1857 | struct retro_game_geometry geometry; |
| 1858 | struct retro_system_timing timing; |
| 1859 | }; |
| 1860 | |
| 1861 | struct retro_variable |
| 1862 | { |
| 1863 | /* Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE. |
| 1864 | * If NULL, obtains the complete environment string if more |
| 1865 | * complex parsing is necessary. |
| 1866 | * The environment string is formatted as key-value pairs |
| 1867 | * delimited by semicolons as so: |
| 1868 | * "key1=value1;key2=value2;..." |
| 1869 | */ |
| 1870 | const char *key; |
| 1871 | |
| 1872 | /* Value to be obtained. If key does not exist, it is set to NULL. */ |
| 1873 | const char *value; |
| 1874 | }; |
| 1875 | |
| 1876 | struct retro_game_info |
| 1877 | { |
| 1878 | const char *path; /* Path to game, UTF-8 encoded. |
| 1879 | * Usually used as a reference. |
| 1880 | * May be NULL if rom was loaded from stdin |
| 1881 | * or similar. |
| 1882 | * retro_system_info::need_fullpath guaranteed |
| 1883 | * that this path is valid. */ |
| 1884 | const void *data; /* Memory buffer of loaded game. Will be NULL |
| 1885 | * if need_fullpath was set. */ |
| 1886 | size_t size; /* Size of memory buffer. */ |
| 1887 | const char *meta; /* String of implementation specific meta-data. */ |
| 1888 | }; |
| 1889 | |
| 1890 | #define RETRO_MEMORY_ACCESS_WRITE (1 << 0) |
| 1891 | /* The core will write to the buffer provided by retro_framebuffer::data. */ |
| 1892 | #define RETRO_MEMORY_ACCESS_READ (1 << 1) |
| 1893 | /* The core will read from retro_framebuffer::data. */ |
| 1894 | #define RETRO_MEMORY_TYPE_CACHED (1 << 0) |
| 1895 | /* The memory in data is cached. |
| 1896 | * If not cached, random writes and/or reading from the buffer is expected to be very slow. */ |
| 1897 | struct retro_framebuffer |
| 1898 | { |
| 1899 | void *data; /* The framebuffer which the core can render into. |
| 1900 | Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. |
| 1901 | The initial contents of data are unspecified. */ |
| 1902 | unsigned width; /* The framebuffer width used by the core. Set by core. */ |
| 1903 | unsigned height; /* The framebuffer height used by the core. Set by core. */ |
| 1904 | size_t pitch; /* The number of bytes between the beginning of a scanline, |
| 1905 | and beginning of the next scanline. |
| 1906 | Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */ |
| 1907 | enum retro_pixel_format format; /* The pixel format the core must use to render into data. |
| 1908 | This format could differ from the format used in |
| 1909 | SET_PIXEL_FORMAT. |
| 1910 | Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */ |
| 1911 | |
| 1912 | unsigned access_flags; /* How the core will access the memory in the framebuffer. |
| 1913 | RETRO_MEMORY_ACCESS_* flags. |
| 1914 | Set by core. */ |
| 1915 | unsigned memory_flags; /* Flags telling core how the memory has been mapped. |
| 1916 | RETRO_MEMORY_TYPE_* flags. |
| 1917 | Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER. */ |
| 1918 | }; |
| 1919 | |
| 1920 | /* Callbacks */ |
| 1921 | |
| 1922 | /* Environment callback. Gives implementations a way of performing |
| 1923 | * uncommon tasks. Extensible. */ |
| 1924 | typedef bool (*retro_environment_t)(unsigned cmd, void *data); |
| 1925 | |
| 1926 | /* Render a frame. Pixel format is 15-bit 0RGB1555 native endian |
| 1927 | * unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT). |
| 1928 | * |
| 1929 | * Width and height specify dimensions of buffer. |
| 1930 | * Pitch specifices length in bytes between two lines in buffer. |
| 1931 | * |
| 1932 | * For performance reasons, it is highly recommended to have a frame |
| 1933 | * that is packed in memory, i.e. pitch == width * byte_per_pixel. |
| 1934 | * Certain graphic APIs, such as OpenGL ES, do not like textures |
| 1935 | * that are not packed in memory. |
| 1936 | */ |
| 1937 | typedef void (*retro_video_refresh_t)(const void *data, unsigned width, |
| 1938 | unsigned height, size_t pitch); |
| 1939 | |
| 1940 | /* Renders a single audio frame. Should only be used if implementation |
| 1941 | * generates a single sample at a time. |
| 1942 | * Format is signed 16-bit native endian. |
| 1943 | */ |
| 1944 | typedef void (*retro_audio_sample_t)(int16_t left, int16_t right); |
| 1945 | |
| 1946 | /* Renders multiple audio frames in one go. |
| 1947 | * |
| 1948 | * One frame is defined as a sample of left and right channels, interleaved. |
| 1949 | * I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames. |
| 1950 | * Only one of the audio callbacks must ever be used. |
| 1951 | */ |
| 1952 | typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, |
| 1953 | size_t frames); |
| 1954 | |
| 1955 | /* Polls input. */ |
| 1956 | typedef void (*retro_input_poll_t)(void); |
| 1957 | |
| 1958 | /* Queries for input for player 'port'. device will be masked with |
| 1959 | * RETRO_DEVICE_MASK. |
| 1960 | * |
| 1961 | * Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that |
| 1962 | * have been set with retro_set_controller_port_device() |
| 1963 | * will still use the higher level RETRO_DEVICE_JOYPAD to request input. |
| 1964 | */ |
| 1965 | typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, |
| 1966 | unsigned index, unsigned id); |
| 1967 | |
| 1968 | /* Sets callbacks. retro_set_environment() is guaranteed to be called |
| 1969 | * before retro_init(). |
| 1970 | * |
| 1971 | * The rest of the set_* functions are guaranteed to have been called |
| 1972 | * before the first call to retro_run() is made. */ |
| 1973 | RETRO_API void retro_set_environment(retro_environment_t); |
| 1974 | RETRO_API void retro_set_video_refresh(retro_video_refresh_t); |
| 1975 | RETRO_API void retro_set_audio_sample(retro_audio_sample_t); |
| 1976 | RETRO_API void retro_set_audio_sample_batch(retro_audio_sample_batch_t); |
| 1977 | RETRO_API void retro_set_input_poll(retro_input_poll_t); |
| 1978 | RETRO_API void retro_set_input_state(retro_input_state_t); |
| 1979 | |
| 1980 | /* Library global initialization/deinitialization. */ |
| 1981 | RETRO_API void retro_init(void); |
| 1982 | RETRO_API void retro_deinit(void); |
| 1983 | |
| 1984 | /* Must return RETRO_API_VERSION. Used to validate ABI compatibility |
| 1985 | * when the API is revised. */ |
| 1986 | RETRO_API unsigned retro_api_version(void); |
| 1987 | |
| 1988 | /* Gets statically known system info. Pointers provided in *info |
| 1989 | * must be statically allocated. |
| 1990 | * Can be called at any time, even before retro_init(). */ |
| 1991 | RETRO_API void retro_get_system_info(struct retro_system_info *info); |
| 1992 | |
| 1993 | /* Gets information about system audio/video timings and geometry. |
| 1994 | * Can be called only after retro_load_game() has successfully completed. |
| 1995 | * NOTE: The implementation of this function might not initialize every |
| 1996 | * variable if needed. |
| 1997 | * E.g. geom.aspect_ratio might not be initialized if core doesn't |
| 1998 | * desire a particular aspect ratio. */ |
| 1999 | RETRO_API void retro_get_system_av_info(struct retro_system_av_info *info); |
| 2000 | |
| 2001 | /* Sets device to be used for player 'port'. |
| 2002 | * By default, RETRO_DEVICE_JOYPAD is assumed to be plugged into all |
| 2003 | * available ports. |
| 2004 | * Setting a particular device type is not a guarantee that libretro cores |
| 2005 | * will only poll input based on that particular device type. It is only a |
| 2006 | * hint to the libretro core when a core cannot automatically detect the |
| 2007 | * appropriate input device type on its own. It is also relevant when a |
| 2008 | * core can change its behavior depending on device type. */ |
| 2009 | RETRO_API void retro_set_controller_port_device(unsigned port, unsigned device); |
| 2010 | |
| 2011 | /* Resets the current game. */ |
| 2012 | RETRO_API void retro_reset(void); |
| 2013 | |
| 2014 | /* Runs the game for one video frame. |
| 2015 | * During retro_run(), input_poll callback must be called at least once. |
| 2016 | * |
| 2017 | * If a frame is not rendered for reasons where a game "dropped" a frame, |
| 2018 | * this still counts as a frame, and retro_run() should explicitly dupe |
| 2019 | * a frame if GET_CAN_DUPE returns true. |
| 2020 | * In this case, the video callback can take a NULL argument for data. |
| 2021 | */ |
| 2022 | RETRO_API void retro_run(void); |
| 2023 | |
| 2024 | /* Returns the amount of data the implementation requires to serialize |
| 2025 | * internal state (save states). |
| 2026 | * Between calls to retro_load_game() and retro_unload_game(), the |
| 2027 | * returned size is never allowed to be larger than a previous returned |
| 2028 | * value, to ensure that the frontend can allocate a save state buffer once. |
| 2029 | */ |
| 2030 | RETRO_API size_t retro_serialize_size(void); |
| 2031 | |
| 2032 | /* Serializes internal state. If failed, or size is lower than |
| 2033 | * retro_serialize_size(), it should return false, true otherwise. */ |
| 2034 | RETRO_API bool retro_serialize(void *data, size_t size); |
| 2035 | RETRO_API bool retro_unserialize(const void *data, size_t size); |
| 2036 | |
| 2037 | RETRO_API void retro_cheat_reset(void); |
| 2038 | RETRO_API void retro_cheat_set(unsigned index, bool enabled, const char *code); |
| 2039 | |
| 2040 | /* Loads a game. */ |
| 2041 | RETRO_API bool retro_load_game(const struct retro_game_info *game); |
| 2042 | |
| 2043 | /* Loads a "special" kind of game. Should not be used, |
| 2044 | * except in extreme cases. */ |
| 2045 | RETRO_API bool retro_load_game_special( |
| 2046 | unsigned game_type, |
| 2047 | const struct retro_game_info *info, size_t num_info |
| 2048 | ); |
| 2049 | |
| 2050 | /* Unloads a currently loaded game. */ |
| 2051 | RETRO_API void retro_unload_game(void); |
| 2052 | |
| 2053 | /* Gets region of game. */ |
| 2054 | RETRO_API unsigned retro_get_region(void); |
| 2055 | |
| 2056 | /* Gets region of memory. */ |
| 2057 | RETRO_API void *retro_get_memory_data(unsigned id); |
| 2058 | RETRO_API size_t retro_get_memory_size(unsigned id); |
| 2059 | |
| 2060 | #ifdef __cplusplus |
| 2061 | } |
| 2062 | #endif |
| 2063 | |
| 2064 | #endif |