8 // Hack applied for MSVC when compiling in C89 mode as it isn't C99 compliant.
12 #if defined(_MSC_VER) && !defined(SN_TARGET_PS3) && !defined(__cplusplus)
13 #define bool unsigned char
21 // Used for checking API/ABI mismatches that can break libretro implementations.
22 // It is not incremented for compatible changes.
23 #define RETRO_API_VERSION 1
25 // Libretro's fundamental device abstractions.
26 #define RETRO_DEVICE_MASK 0xff
27 #define RETRO_DEVICE_NONE 0
29 // The JOYPAD is called RetroPad. It is essentially a Super Nintendo controller,
30 // but with additional L2/R2/L3/R3 buttons, similar to a PS1 DualShock.
31 #define RETRO_DEVICE_JOYPAD 1
33 // The mouse is a simple mouse, similar to Super Nintendo's mouse.
34 // X and Y coordinates are reported relatively to last poll (poll callback).
35 // It is up to the libretro implementation to keep track of where the mouse pointer is supposed to be on the screen.
36 // The frontend must make sure not to interfere with its own hardware mouse pointer.
37 #define RETRO_DEVICE_MOUSE 2
39 // KEYBOARD device lets one poll for raw key pressed.
40 // It is poll based, so input callback will return with the current pressed state.
41 #define RETRO_DEVICE_KEYBOARD 3
43 // Lightgun X/Y coordinates are reported relatively to last poll, similar to mouse.
44 #define RETRO_DEVICE_LIGHTGUN 4
46 // The ANALOG device is an extension to JOYPAD (RetroPad).
47 // Similar to DualShock it adds two analog sticks.
48 // This is treated as a separate device type as it returns values in the full analog range
49 // of [-0x8000, 0x7fff]. Positive X axis is right. Positive Y axis is down.
50 // Only use ANALOG type when polling for analog values of the axes.
51 #define RETRO_DEVICE_ANALOG 5
53 // These device types are specializations of the base types above.
54 // They should only be used in retro_set_controller_type() to inform libretro implementations
55 // about use of a very specific device type.
57 // In input state callback, however, only the base type should be used in the 'device' field.
58 #define RETRO_DEVICE_JOYPAD_MULTITAP ((1 << 8) | RETRO_DEVICE_JOYPAD)
59 #define RETRO_DEVICE_LIGHTGUN_SUPER_SCOPE ((1 << 8) | RETRO_DEVICE_LIGHTGUN)
60 #define RETRO_DEVICE_LIGHTGUN_JUSTIFIER ((2 << 8) | RETRO_DEVICE_LIGHTGUN)
61 #define RETRO_DEVICE_LIGHTGUN_JUSTIFIERS ((3 << 8) | RETRO_DEVICE_LIGHTGUN)
63 // Buttons for the RetroPad (JOYPAD).
64 // The placement of these is equivalent to placements on the Super Nintendo controller.
65 // L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
66 #define RETRO_DEVICE_ID_JOYPAD_B 0
67 #define RETRO_DEVICE_ID_JOYPAD_Y 1
68 #define RETRO_DEVICE_ID_JOYPAD_SELECT 2
69 #define RETRO_DEVICE_ID_JOYPAD_START 3
70 #define RETRO_DEVICE_ID_JOYPAD_UP 4
71 #define RETRO_DEVICE_ID_JOYPAD_DOWN 5
72 #define RETRO_DEVICE_ID_JOYPAD_LEFT 6
73 #define RETRO_DEVICE_ID_JOYPAD_RIGHT 7
74 #define RETRO_DEVICE_ID_JOYPAD_A 8
75 #define RETRO_DEVICE_ID_JOYPAD_X 9
76 #define RETRO_DEVICE_ID_JOYPAD_L 10
77 #define RETRO_DEVICE_ID_JOYPAD_R 11
78 #define RETRO_DEVICE_ID_JOYPAD_L2 12
79 #define RETRO_DEVICE_ID_JOYPAD_R2 13
80 #define RETRO_DEVICE_ID_JOYPAD_L3 14
81 #define RETRO_DEVICE_ID_JOYPAD_R3 15
83 // Index / Id values for ANALOG device.
84 #define RETRO_DEVICE_INDEX_ANALOG_LEFT 0
85 #define RETRO_DEVICE_INDEX_ANALOG_RIGHT 1
86 #define RETRO_DEVICE_ID_ANALOG_X 0
87 #define RETRO_DEVICE_ID_ANALOG_Y 1
89 // Id values for MOUSE.
90 #define RETRO_DEVICE_ID_MOUSE_X 0
91 #define RETRO_DEVICE_ID_MOUSE_Y 1
92 #define RETRO_DEVICE_ID_MOUSE_LEFT 2
93 #define RETRO_DEVICE_ID_MOUSE_RIGHT 3
95 // Id values for LIGHTGUN types.
96 #define RETRO_DEVICE_ID_LIGHTGUN_X 0
97 #define RETRO_DEVICE_ID_LIGHTGUN_Y 1
98 #define RETRO_DEVICE_ID_LIGHTGUN_TRIGGER 2
99 #define RETRO_DEVICE_ID_LIGHTGUN_CURSOR 3
100 #define RETRO_DEVICE_ID_LIGHTGUN_TURBO 4
101 #define RETRO_DEVICE_ID_LIGHTGUN_PAUSE 5
102 #define RETRO_DEVICE_ID_LIGHTGUN_START 6
104 // Returned from retro_get_region().
105 #define RETRO_REGION_NTSC 0
106 #define RETRO_REGION_PAL 1
108 // Passed to retro_get_memory_data/size().
109 // If the memory type doesn't apply to the implementation NULL/0 can be returned.
110 #define RETRO_MEMORY_MASK 0xff
112 // Regular save ram. This ram is usually found on a game cartridge, backed up by a battery.
113 // If save game data is too complex for a single memory buffer,
114 // the SYSTEM_DIRECTORY environment callback can be used.
115 #define RETRO_MEMORY_SAVE_RAM 0
117 // Some games have a built-in clock to keep track of time.
118 // This memory is usually just a couple of bytes to keep track of time.
119 #define RETRO_MEMORY_RTC 1
121 // System ram lets a frontend peek into a game systems main RAM.
122 #define RETRO_MEMORY_SYSTEM_RAM 2
124 // Video ram lets a frontend peek into a game systems video RAM (VRAM).
125 #define RETRO_MEMORY_VIDEO_RAM 3
127 // Special memory types.
128 #define RETRO_MEMORY_SNES_BSX_RAM ((1 << 8) | RETRO_MEMORY_SAVE_RAM)
129 #define RETRO_MEMORY_SNES_BSX_PRAM ((2 << 8) | RETRO_MEMORY_SAVE_RAM)
130 #define RETRO_MEMORY_SNES_SUFAMI_TURBO_A_RAM ((3 << 8) | RETRO_MEMORY_SAVE_RAM)
131 #define RETRO_MEMORY_SNES_SUFAMI_TURBO_B_RAM ((4 << 8) | RETRO_MEMORY_SAVE_RAM)
132 #define RETRO_MEMORY_SNES_GAME_BOY_RAM ((5 << 8) | RETRO_MEMORY_SAVE_RAM)
133 #define RETRO_MEMORY_SNES_GAME_BOY_RTC ((6 << 8) | RETRO_MEMORY_RTC)
135 // Special game types passed into retro_load_game_special().
136 // Only used when multiple ROMs are required.
137 #define RETRO_GAME_TYPE_BSX 0x101
138 #define RETRO_GAME_TYPE_BSX_SLOTTED 0x102
139 #define RETRO_GAME_TYPE_SUFAMI_TURBO 0x103
140 #define RETRO_GAME_TYPE_SUPER_GAME_BOY 0x104
142 // Keysyms used for ID in input state callback when polling RETRO_KEYBOARD.
147 RETROK_BACKSPACE = 8,
155 RETROK_QUOTEDBL = 34,
158 RETROK_AMPERSAND = 38,
160 RETROK_LEFTPAREN = 40,
161 RETROK_RIGHTPAREN = 41,
162 RETROK_ASTERISK = 42,
179 RETROK_SEMICOLON = 59,
183 RETROK_QUESTION = 63,
185 RETROK_LEFTBRACKET = 91,
186 RETROK_BACKSLASH = 92,
187 RETROK_RIGHTBRACKET = 93,
189 RETROK_UNDERSCORE = 95,
190 RETROK_BACKQUOTE = 96,
229 RETROK_KP_PERIOD = 266,
230 RETROK_KP_DIVIDE = 267,
231 RETROK_KP_MULTIPLY = 268,
232 RETROK_KP_MINUS = 269,
233 RETROK_KP_PLUS = 270,
234 RETROK_KP_ENTER = 271,
235 RETROK_KP_EQUALS = 272,
245 RETROK_PAGEDOWN = 281,
263 RETROK_NUMLOCK = 300,
264 RETROK_CAPSLOCK = 301,
265 RETROK_SCROLLOCK = 302,
277 RETROK_COMPOSE = 314,
291 // Environment commands.
292 #define RETRO_ENVIRONMENT_SET_ROTATION 1 // const unsigned * --
293 // Sets screen rotation of graphics.
294 // Is only implemented if rotation can be accelerated by hardware.
295 // Valid values are 0, 1, 2, 3, which rotates screen by 0, 90, 180, 270 degrees
296 // counter-clockwise respectively.
298 #define RETRO_ENVIRONMENT_GET_OVERSCAN 2 // bool * --
299 // Boolean value whether or not the implementation should use overscan, or crop away overscan.
301 #define RETRO_ENVIRONMENT_GET_CAN_DUPE 3 // bool * --
302 // Boolean value whether or not frontend supports frame duping,
303 // passing NULL to video frame callback.
305 #define RETRO_ENVIRONMENT_GET_VARIABLE 4 // struct retro_variable * --
306 // Interface to aquire user-defined information from environment
307 // that cannot feasibly be supported in a multi-system way.
308 // Mostly used for obscure,
309 // specific features that the user can tap into when neseccary.
311 #define RETRO_ENVIRONMENT_SET_VARIABLES 5 // const struct retro_variable * --
312 // Allows an implementation to signal the environment
313 // which variables it might want to check for later using GET_VARIABLE.
314 // 'data' points to an array of retro_variable structs terminated by a { NULL, NULL } element.
315 // retro_variable::value should contain a human readable description of the key.
317 #define RETRO_ENVIRONMENT_SET_MESSAGE 6 // const struct retro_message * --
318 // Sets a message to be displayed in implementation-specific manner for a certain amount of 'frames'.
319 // Should not be used for trivial messages, which should simply be logged to stderr.
320 #define RETRO_ENVIRONMENT_SHUTDOWN 7 // N/A (NULL) --
321 // Requests the frontend to shutdown.
322 // Should only be used if game has a specific
323 // way to shutdown the game from a menu item or similar.
325 #define RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL 8
326 // const unsigned * --
327 // Gives a hint to the frontend how demanding this implementation
328 // is on a system. E.g. reporting a level of 2 means
329 // this implementation should run decently on all frontends
330 // of level 2 and up.
332 // It can be used by the frontend to potentially warn
333 // about too demanding implementations.
335 // The levels are "floating", but roughly defined as:
336 // 0: Low-powered embedded devices such as Raspberry Pi
337 // 1: 6th generation consoles, such as Wii/Xbox 1, and phones, tablets, etc.
338 // 2: 7th generation consoles, such as PS3/360, with sub-par CPUs.
339 // 3: Modern desktop/laptops with reasonably powerful CPUs.
340 // 4: High-end desktops with very powerful CPUs.
342 // This function can be called on a per-game basis,
343 // as certain games an implementation can play might be
344 // particularily demanding.
345 // If called, it should be called in retro_load_game().
347 #define RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY 9
349 // Returns the "system" directory of the frontend.
350 // This directory can be used to store system specific ROMs such as BIOSes, configuration data, etc.
351 // The returned value can be NULL.
352 // If so, no such directory is defined,
353 // and it's up to the implementation to find a suitable directory.
355 #define RETRO_ENVIRONMENT_SET_PIXEL_FORMAT 10
356 // const enum retro_pixel_format * --
357 // Sets the internal pixel format used by the implementation.
358 // The default pixel format is RETRO_PIXEL_FORMAT_0RGB1555.
359 // This pixel format however, is deprecated (see enum retro_pixel_format).
360 // If the call returns false, the frontend does not support this pixel format.
361 // This function should be called inside retro_load_game() or retro_get_system_av_info().
363 #define RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS 11
364 // const struct retro_input_descriptor * --
365 // Sets an array of retro_input_descriptors.
366 // It is up to the frontend to present this in a usable way.
367 // The array is terminated by retro_input_descriptor::description being set to NULL.
368 // This function can be called at any time, but it is recommended to call it as early as possible.
371 enum retro_pixel_format
373 // 0RGB1555, native endian. 0 bit must be set to 0.
374 // This pixel format is default for compatibility concerns only.
375 // If a 15/16-bit pixel format is desired, consider using RGB565.
376 RETRO_PIXEL_FORMAT_0RGB1555 = 0,
378 // XRGB8888, native endian. X bits are ignored.
379 RETRO_PIXEL_FORMAT_XRGB8888 = 1,
381 // RGB565, native endian. This pixel format is the recommended format to use if a 15/16-bit format is desired
382 // as it is the pixel format that is typically available on a wide range of low-power devices.
383 // It is also natively supported in APIs like OpenGL ES.
384 RETRO_PIXEL_FORMAT_RGB565 = 2,
386 // Ensure sizeof() == sizeof(int).
387 RETRO_PIXEL_FORMAT_UNKNOWN = INT_MAX
392 const char *msg; // Message to be displayed.
393 unsigned frames; // Duration in frames of message.
396 // Describes how the libretro implementation maps a libretro input bind
397 // to its internal input system through a human readable string.
398 // This string can be used to better let a user configure input.
399 struct retro_input_descriptor
401 // Associates given parameters with a description.
407 const char *description; // Human readable description for parameters.
408 // The pointer must remain valid until retro_unload_game() is called.
411 struct retro_system_info
413 // All pointers are owned by libretro implementation, and pointers must remain valid until retro_deinit() is called.
415 const char *library_name; // Descriptive name of library. Should not contain any version numbers, etc.
416 const char *library_version; // Descriptive version of core.
418 const char *valid_extensions; // A string listing probably rom extensions the core will be able to load, separated with pipe.
419 // I.e. "bin|rom|iso".
420 // Typically used for a GUI to filter out extensions.
422 bool need_fullpath; // If true, retro_load_game() is guaranteed to provide a valid pathname in retro_game_info::path.
423 // ::data and ::size are both invalid.
424 // If false, ::data and ::size are guaranteed to be valid, but ::path might not be valid.
425 // This is typically set to true for libretro implementations that must load from file.
426 // Implementations should strive for setting this to false, as it allows the frontend to perform patching, etc.
428 bool block_extract; // If true, the frontend is not allowed to extract any archives before loading the real ROM.
429 // Necessary for certain libretro implementations that load games from zipped archives.
432 struct retro_game_geometry
434 unsigned base_width; // Nominal video width of game.
435 unsigned base_height; // Nominal video height of game.
436 unsigned max_width; // Maximum possible width of game.
437 unsigned max_height; // Maximum possible height of game.
439 float aspect_ratio; // Nominal aspect ratio of game. If aspect_ratio is <= 0.0,
440 // an aspect ratio of base_width / base_height is assumed.
441 // A frontend could override this setting if desired.
444 struct retro_system_timing
446 double fps; // FPS of video content.
447 double sample_rate; // Sampling rate of audio.
450 struct retro_system_av_info
452 struct retro_game_geometry geometry;
453 struct retro_system_timing timing;
456 struct retro_variable
458 const char *key; // Variable to query in RETRO_ENVIRONMENT_GET_VARIABLE.
459 // If NULL, obtains the complete environment string if more complex parsing is necessary.
460 // The environment string is formatted as key-value pairs delimited by semicolons as so:
461 // "key1=value1;key2=value2;..."
462 const char *value; // Value to be obtained. If key does not exist, it is set to NULL.
465 struct retro_game_info
467 const char *path; // Path to game, UTF-8 encoded. Usually used as a reference.
468 // May be NULL if rom was loaded from stdin or similar.
469 // retro_system_info::need_fullpath guaranteed that this path is valid.
470 const void *data; // Memory buffer of loaded game. Will be NULL if need_fullpath was set.
471 size_t size; // Size of memory buffer.
472 const char *meta; // String of implementation specific meta-data.
477 // Environment callback. Gives implementations a way of performing uncommon tasks. Extensible.
478 typedef bool (*retro_environment_t)(unsigned cmd, void *data);
480 // Render a frame. Pixel format is 15-bit 0RGB1555 native endian unless changed (see RETRO_ENVIRONMENT_SET_PIXEL_FORMAT).
481 // Width and height specify dimensions of buffer.
482 // Pitch specifices length in bytes between two lines in buffer.
483 // For performance reasons, it is highly recommended to have a frame that is packed in memory, i.e. pitch == width * byte_per_pixel.
484 // Certain graphic APIs, such as OpenGL ES, do not like textures that are not packed in memory.
485 typedef void (*retro_video_refresh_t)(const void *data, unsigned width, unsigned height, size_t pitch);
487 // Renders a single audio frame. Should only be used if implementation generates a single sample at a time.
488 // Format is signed 16-bit native endian.
489 typedef void (*retro_audio_sample_t)(int16_t left, int16_t right);
490 // Renders multiple audio frames in one go. One frame is defined as a sample of left and right channels, interleaved.
491 // I.e. int16_t buf[4] = { l, r, l, r }; would be 2 frames.
492 // Only one of the audio callbacks must ever be used.
493 typedef size_t (*retro_audio_sample_batch_t)(const int16_t *data, size_t frames);
496 typedef void (*retro_input_poll_t)(void);
497 // Queries for input for player 'port'. device will be masked with RETRO_DEVICE_MASK.
498 // Specialization of devices such as RETRO_DEVICE_JOYPAD_MULTITAP that have been set with retro_set_controller_port_device()
499 // will still use the higher level RETRO_DEVICE_JOYPAD to request input.
500 typedef int16_t (*retro_input_state_t)(unsigned port, unsigned device, unsigned index, unsigned id);
502 // Sets callbacks. retro_set_environment() is guaranteed to be called before retro_init().
503 // The rest of the set_* functions are guaranteed to have been called before the first call to retro_run() is made.
504 void retro_set_environment(retro_environment_t);
505 void retro_set_video_refresh(retro_video_refresh_t);
506 void retro_set_audio_sample(retro_audio_sample_t);
507 void retro_set_audio_sample_batch(retro_audio_sample_batch_t);
508 void retro_set_input_poll(retro_input_poll_t);
509 void retro_set_input_state(retro_input_state_t);
511 // Library global initialization/deinitialization.
512 void retro_init(void);
513 void retro_deinit(void);
515 // Must return RETRO_API_VERSION. Used to validate ABI compatibility when the API is revised.
516 unsigned retro_api_version(void);
518 // Gets statically known system info. Pointers provided in *info must be statically allocated.
519 // Can be called at any time, even before retro_init().
520 void retro_get_system_info(struct retro_system_info *info);
522 // Gets information about system audio/video timings and geometry.
523 // Can be called only after retro_load_game() has successfully completed.
524 // NOTE: The implementation of this function might not initialize every variable if needed.
525 // E.g. geom.aspect_ratio might not be initialized if core doesn't desire a particular aspect ratio.
526 void retro_get_system_av_info(struct retro_system_av_info *info);
528 // Sets device to be used for player 'port'.
529 void retro_set_controller_port_device(unsigned port, unsigned device);
531 // Resets the current game.
532 void retro_reset(void);
534 // Runs the game for one video frame.
535 // During retro_run(), input_poll callback must be called at least once.
537 // If a frame is not rendered for reasons where a game "dropped" a frame,
538 // this still counts as a frame, and retro_run() should explicitly dupe a frame if GET_CAN_DUPE returns true.
539 // In this case, the video callback can take a NULL argument for data.
540 void retro_run(void);
542 // Returns the amount of data the implementation requires to serialize internal state (save states).
543 // Beetween calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned value, to
544 // ensure that the frontend can allocate a save state buffer once.
545 size_t retro_serialize_size(void);
547 // Serializes internal state. If failed, or size is lower than retro_serialize_size(), it should return false, true otherwise.
548 bool retro_serialize(void *data, size_t size);
549 bool retro_unserialize(const void *data, size_t size);
551 void retro_cheat_reset(void);
552 void retro_cheat_set(unsigned index, bool enabled, const char *code);
555 bool retro_load_game(const struct retro_game_info *game);
557 // Loads a "special" kind of game. Should not be used except in extreme cases.
558 bool retro_load_game_special(
560 const struct retro_game_info *info, size_t num_info
563 // Unloads a currently loaded game.
564 void retro_unload_game(void);
566 // Gets region of game.
567 unsigned retro_get_region(void);
569 // Gets region of memory.
570 void *retro_get_memory_data(unsigned id);
571 size_t retro_get_memory_size(unsigned id);