+// Returns current time in microseconds. Tries to use the most accurate timer available.
+typedef retro_time_t (*retro_perf_get_time_usec_t)(void);
+// A simple counter. Usually nanoseconds, but can also be CPU cycles.
+// Can be used directly if desired (when creating a more sophisticated performance counter system).
+typedef retro_perf_tick_t (*retro_perf_get_counter_t)(void);
+// Returns a bit-mask of detected CPU features (RETRO_SIMD_*).
+typedef uint64_t (*retro_get_cpu_features_t)(void);
+// Asks frontend to log and/or display the state of performance counters.
+// Performance counters can always be poked into manually as well.
+typedef void (*retro_perf_log_t)(void);
+// Register a performance counter.
+// ident field must be set with a discrete value and other values in retro_perf_counter must be 0.
+// Registering can be called multiple times. To avoid calling to frontend redundantly, you can check registered field first.
+typedef void (*retro_perf_register_t)(struct retro_perf_counter *counter);
+// Starts and stops a registered counter.
+typedef void (*retro_perf_start_t)(struct retro_perf_counter *counter);
+typedef void (*retro_perf_stop_t)(struct retro_perf_counter *counter);
+
+// For convenience it can be useful to wrap register, start and stop in macros.
+// E.g.:
+// #ifdef LOG_PERFORMANCE
+// #define RETRO_PERFORMANCE_INIT(perf_cb, name) static struct retro_perf_counter name = {#name}; if (!name.registered) perf_cb.perf_register(&(name))
+// #define RETRO_PERFORMANCE_START(perf_cb, name) perf_cb.perf_start(&(name))
+// #define RETRO_PERFORMANCE_STOP(perf_cb, name) perf_cb.perf_stop(&(name))
+// #else
+// ... Blank macros ...
+// #endif
+// These can then be used mid-functions around code snippets.
+//
+// extern struct retro_perf_callback perf_cb; // Somewhere in the core.
+//
+// void do_some_heavy_work(void)
+// {
+// RETRO_PERFORMANCE_INIT(cb, work_1);
+// RETRO_PERFORMANCE_START(cb, work_1);
+// heavy_work_1();
+// RETRO_PERFORMANCE_STOP(cb, work_1);
+//
+// RETRO_PERFORMANCE_INIT(cb, work_2);
+// RETRO_PERFORMANCE_START(cb, work_2);
+// heavy_work_2();
+// RETRO_PERFORMANCE_STOP(cb, work_2);
+// }
+//
+// void retro_deinit(void)
+// {
+// perf_cb.perf_log(); // Log all perf counters here for example.
+// }
+
+struct retro_perf_callback
+{
+ retro_perf_get_time_usec_t get_time_usec;
+ retro_get_cpu_features_t get_cpu_features;
+
+ retro_perf_get_counter_t get_perf_counter;
+ retro_perf_register_t perf_register;
+ retro_perf_start_t perf_start;
+ retro_perf_stop_t perf_stop;
+ retro_perf_log_t perf_log;
+};
+
+// FIXME: Document the sensor API and work out behavior.
+// It will be marked as experimental until then.
+enum retro_sensor_action
+{
+ RETRO_SENSOR_ACCELEROMETER_ENABLE = 0,
+ RETRO_SENSOR_ACCELEROMETER_DISABLE,
+
+ RETRO_SENSOR_DUMMY = INT_MAX
+};
+
+typedef bool (*retro_set_sensor_state_t)(unsigned port, enum retro_sensor_action action, unsigned rate);
+struct retro_sensor_interface
+{
+ retro_set_sensor_state_t set_sensor_state;
+};
+////
+
+enum retro_camera_buffer
+{
+ RETRO_CAMERA_BUFFER_OPENGL_TEXTURE = 0,
+ RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER,
+
+ RETRO_CAMERA_BUFFER_DUMMY = INT_MAX
+};
+
+// Starts the camera driver. Can only be called in retro_run().
+typedef bool (*retro_camera_start_t)(void);
+// Stops the camera driver. Can only be called in retro_run().
+typedef void (*retro_camera_stop_t)(void);
+// Callback which signals when the camera driver is initialized and/or deinitialized.
+// retro_camera_start_t can be called in initialized callback.
+typedef void (*retro_camera_lifetime_status_t)(void);
+// A callback for raw framebuffer data. buffer points to an XRGB8888 buffer.
+// Width, height and pitch are similar to retro_video_refresh_t.
+// First pixel is top-left origin.
+typedef void (*retro_camera_frame_raw_framebuffer_t)(const uint32_t *buffer, unsigned width, unsigned height, size_t pitch);
+// A callback for when OpenGL textures are used.
+//
+// texture_id is a texture owned by camera driver.
+// Its state or content should be considered immutable, except for things like texture filtering and clamping.
+//
+// texture_target is the texture target for the GL texture.
+// These can include e.g. GL_TEXTURE_2D, GL_TEXTURE_RECTANGLE, and possibly more depending on extensions.
+//
+// affine points to a packed 3x3 column-major matrix used to apply an affine transform to texture coordinates. (affine_matrix * vec3(coord_x, coord_y, 1.0))
+// After transform, normalized texture coord (0, 0) should be bottom-left and (1, 1) should be top-right (or (width, height) for RECTANGLE).
+//
+// GL-specific typedefs are avoided here to avoid relying on gl.h in the API definition.
+typedef void (*retro_camera_frame_opengl_texture_t)(unsigned texture_id, unsigned texture_target, const float *affine);
+struct retro_camera_callback
+{
+ uint64_t caps; // Set by libretro core. Example bitmask: caps = (1 << RETRO_CAMERA_BUFFER_OPENGL_TEXTURE) | (1 << RETRO_CAMERA_BUFFER_RAW_FRAMEBUFFER).
+
+ unsigned width; // Desired resolution for camera. Is only used as a hint.
+ unsigned height;
+ retro_camera_start_t start; // Set by frontend.
+ retro_camera_stop_t stop; // Set by frontend.
+
+ retro_camera_frame_raw_framebuffer_t frame_raw_framebuffer; // Set by libretro core if raw framebuffer callbacks will be used.
+ retro_camera_frame_opengl_texture_t frame_opengl_texture; // Set by libretro core if OpenGL texture callbacks will be used.
+
+ // Set by libretro core. Called after camera driver is initialized and ready to be started.
+ // Can be NULL, in which this callback is not called.
+ retro_camera_lifetime_status_t initialized;
+
+ // Set by libretro core. Called right before camera driver is deinitialized.
+ // Can be NULL, in which this callback is not called.
+ retro_camera_lifetime_status_t deinitialized;
+};
+
+enum retro_rumble_effect
+{
+ RETRO_RUMBLE_STRONG = 0,
+ RETRO_RUMBLE_WEAK = 1,
+
+ RETRO_RUMBLE_DUMMY = INT_MAX
+};
+
+// Sets rumble state for joypad plugged in port 'port'. Rumble effects are controlled independently,
+// and setting e.g. strong rumble does not override weak rumble.
+// Strength has a range of [0, 0xffff].
+//
+// Returns true if rumble state request was honored. Calling this before first retro_run() is likely to return false.
+typedef bool (*retro_set_rumble_state_t)(unsigned port, enum retro_rumble_effect effect, uint16_t strength);
+struct retro_rumble_interface
+{
+ retro_set_rumble_state_t set_rumble_state;
+};
+
+// Notifies libretro that audio data should be written.
+typedef void (*retro_audio_callback_t)(void);
+
+// True: Audio driver in frontend is active, and callback is expected to be called regularily.
+// False: Audio driver in frontend is paused or inactive. Audio callback will not be called until set_state has been called with true.
+// Initial state is false (inactive).
+typedef void (*retro_audio_set_state_callback_t)(bool enabled);
+struct retro_audio_callback
+{
+ retro_audio_callback_t callback;
+ retro_audio_set_state_callback_t set_state;
+};
+
+// Notifies a libretro core of time spent since last invocation of retro_run() in microseconds.
+// It will be called right before retro_run() every frame.
+// The frontend can tamper with timing to support cases like fast-forward, slow-motion and framestepping.
+// In those scenarios the reference frame time value will be used.
+typedef int64_t retro_usec_t;
+typedef void (*retro_frame_time_callback_t)(retro_usec_t usec);
+struct retro_frame_time_callback
+{
+ retro_frame_time_callback_t callback;
+ retro_usec_t reference; // Represents the time of one frame. It is computed as 1000000 / fps, but the implementation will resolve the rounding to ensure that framestepping, etc is exact.
+};
+
+// Pass this to retro_video_refresh_t if rendering to hardware.
+// Passing NULL to retro_video_refresh_t is still a frame dupe as normal.
+#define RETRO_HW_FRAME_BUFFER_VALID ((void*)-1)
+
+// Invalidates the current HW context.
+// Any GL state is lost, and must not be deinitialized explicitly. If explicit deinitialization is desired by the libretro core,
+// it should implement context_destroy callback.
+// If called, all GPU resources must be reinitialized.
+// Usually called when frontend reinits video driver.
+// Also called first time video driver is initialized, allowing libretro core to init resources.
+typedef void (*retro_hw_context_reset_t)(void);
+// Gets current framebuffer which is to be rendered to. Could change every frame potentially.
+typedef uintptr_t (*retro_hw_get_current_framebuffer_t)(void);
+
+// Get a symbol from HW context.
+typedef void (*retro_proc_address_t)(void);
+typedef retro_proc_address_t (*retro_hw_get_proc_address_t)(const char *sym);
+
+enum retro_hw_context_type
+{
+ RETRO_HW_CONTEXT_NONE = 0,
+ RETRO_HW_CONTEXT_OPENGL, // OpenGL 2.x. Latest version available before 3.x+. Driver can choose to use latest compatibility context.
+ RETRO_HW_CONTEXT_OPENGLES2, // GLES 2.0
+ RETRO_HW_CONTEXT_OPENGL_CORE, // Modern desktop core GL context. Use major/minor fields to set GL version.
+ RETRO_HW_CONTEXT_OPENGLES3, // GLES 3.0
+
+ RETRO_HW_CONTEXT_DUMMY = INT_MAX
+};
+
+struct retro_hw_render_callback
+{
+ enum retro_hw_context_type context_type; // Which API to use. Set by libretro core.
+ retro_hw_context_reset_t context_reset; // Called when a context has been created or when it has been reset.
+ retro_hw_get_current_framebuffer_t get_current_framebuffer; // Set by frontend.
+ retro_hw_get_proc_address_t get_proc_address; // Set by frontend.
+ bool depth; // Set if render buffers should have depth component attached.
+ bool stencil; // Set if stencil buffers should be attached.
+ // If depth and stencil are true, a packed 24/8 buffer will be added. Only attaching stencil is invalid and will be ignored.
+ bool bottom_left_origin; // Use conventional bottom-left origin convention. Is false, standard libretro top-left origin semantics are used.
+ unsigned version_major; // Major version number for core GL context.
+ unsigned version_minor; // Minor version number for core GL context.
+
+ bool cache_context; // If this is true, the frontend will go very far to avoid resetting context in scenarios like toggling fullscreen, etc.
+ // The reset callback might still be called in extreme situations such as if the context is lost beyond recovery.
+ // For optimal stability, set this to false, and allow context to be reset at any time.
+ retro_hw_context_reset_t context_destroy; // A callback to be called before the context is destroyed. Resources can be deinitialized at this step. This can be set to NULL, in which resources will just be destroyed without any notification.
+ bool debug_context; // Creates a debug context.
+};
+
+// Callback type passed in RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. Called by the frontend in response to keyboard events.
+// down is set if the key is being pressed, or false if it is being released.
+// keycode is the RETROK value of the char.
+// character is the text character of the pressed key. (UTF-32).
+// key_modifiers is a set of RETROKMOD values or'ed together.
+//
+// The pressed/keycode state can be indepedent of the character.
+// It is also possible that multiple characters are generated from a single keypress.
+// Keycode events should be treated separately from character events.
+// However, when possible, the frontend should try to synchronize these.
+// If only a character is posted, keycode should be RETROK_UNKNOWN.
+// Similarily if only a keycode event is generated with no corresponding character, character should be 0.
+typedef void (*retro_keyboard_event_t)(bool down, unsigned keycode, uint32_t character, uint16_t key_modifiers);
+
+struct retro_keyboard_callback
+{
+ retro_keyboard_event_t callback;
+};
+
+// Callbacks for RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE.
+// Should be set for implementations which can swap out multiple disk images in runtime.
+// If the implementation can do this automatically, it should strive to do so.
+// However, there are cases where the user must manually do so.
+//
+// Overview: To swap a disk image, eject the disk image with set_eject_state(true).
+// Set the disk index with set_image_index(index). Insert the disk again with set_eject_state(false).
+
+// If ejected is true, "ejects" the virtual disk tray.
+// When ejected, the disk image index can be set.
+typedef bool (*retro_set_eject_state_t)(bool ejected);
+// Gets current eject state. The initial state is 'not ejected'.
+typedef bool (*retro_get_eject_state_t)(void);
+// Gets current disk index. First disk is index 0.
+// If return value is >= get_num_images(), no disk is currently inserted.
+typedef unsigned (*retro_get_image_index_t)(void);
+// Sets image index. Can only be called when disk is ejected.
+// The implementation supports setting "no disk" by using an index >= get_num_images().
+typedef bool (*retro_set_image_index_t)(unsigned index);
+// Gets total number of images which are available to use.
+typedef unsigned (*retro_get_num_images_t)(void);
+//
+// Replaces the disk image associated with index.
+// Arguments to pass in info have same requirements as retro_load_game().
+// Virtual disk tray must be ejected when calling this.
+// Replacing a disk image with info = NULL will remove the disk image from the internal list.
+// As a result, calls to get_image_index() can change.
+//
+// E.g. replace_image_index(1, NULL), and previous get_image_index() returned 4 before.
+// Index 1 will be removed, and the new index is 3.
+struct retro_game_info;
+typedef bool (*retro_replace_image_index_t)(unsigned index, const struct retro_game_info *info);
+// Adds a new valid index (get_num_images()) to the internal disk list.
+// This will increment subsequent return values from get_num_images() by 1.
+// This image index cannot be used until a disk image has been set with replace_image_index.
+typedef bool (*retro_add_image_index_t)(void);
+
+struct retro_disk_control_callback
+{
+ retro_set_eject_state_t set_eject_state;
+ retro_get_eject_state_t get_eject_state;
+
+ retro_get_image_index_t get_image_index;
+ retro_set_image_index_t set_image_index;
+ retro_get_num_images_t get_num_images;
+
+ retro_replace_image_index_t replace_image_index;
+ retro_add_image_index_t add_image_index;
+};