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