53#define SDL_LIBRETRO_MAJOR_VERSION 0
61#define SDL_LIBRETRO_MINOR_VERSION 1
69#define SDL_LIBRETRO_MICRO_VERSION 0
74#define SDL_LIBRETRO_VERSION SDL_VERSIONNUM(SDL_LIBRETRO_MAJOR_VERSION, SDL_LIBRETRO_MINOR_VERSION, SDL_LIBRETRO_MICRO_VERSION)
79#define SDL_LIBRETRO_VERSION_ATLEAST(X, Y, Z) (SDL_LIBRETRO_VERSION >= SDL_VERSIONNUM(X, Y, Z))
255#define SDL_EVENT_LIBRETRO (SDL_EVENT_USER + 0x1000)
261#define SDL_EVENT_LIBRETRO_LAST (SDL_EVENT_LIBRETRO | 0xFFF)
282#define SDL_EVENT_LIBRETRO_ENVIRONMENT(cmd) (SDL_EVENT_LIBRETRO | ((cmd) & 0x3FF) | (((cmd) >> 6) & 0xC00))
290#define SDL_EVENT_LIBRETRO_ENVIRONMENT_LAST (SDL_EVENT_LIBRETRO | 0xBFF)
298#define SDL_LIBRETRO_ENVIRONMENT_COMMAND(type) ((((type) - SDL_EVENT_LIBRETRO) & 0x3FF) | ((((type) - SDL_EVENT_LIBRETRO) & 0xC00) << 6))
300#define SDL_EVENT_LIBRETRO_CORE_LOADED (SDL_EVENT_LIBRETRO | 0xF00)
301#define SDL_EVENT_LIBRETRO_GAME_LOADED (SDL_EVENT_LIBRETRO | 0xF01)
302#define SDL_EVENT_LIBRETRO_MENU_OPENED (SDL_EVENT_LIBRETRO | 0xF02)
303#define SDL_EVENT_LIBRETRO_MENU_CLOSED (SDL_EVENT_LIBRETRO | 0xF03)
304#define SDL_EVENT_LIBRETRO_CORE_UNLOADED (SDL_EVENT_LIBRETRO | 0xF04)
305#define SDL_EVENT_LIBRETRO_GAME_UNLOADED (SDL_EVENT_LIBRETRO | 0xF05)
306#define SDL_EVENT_LIBRETRO_SHUTDOWN (SDL_EVENT_LIBRETRO | 0xF06)
307#define SDL_EVENT_LIBRETRO_GEOMETRY_CHANGED (SDL_EVENT_LIBRETRO | 0xF07)
332bool SDL_Libretro_GetMemoryMapDescriptor(
const SDL_Libretro* lr,
unsigned index, Uint64* flags,
void** ptr,
size_t* offset,
size_t* start,
size_t* select,
size_t* disconnect,
size_t* len,
const char** addrspace);
531#ifdef SDL_LIBRETRO_IMPLEMENTATION
532#ifndef SDL_LIBRETRO_IMPLEMENTATION_ONCE
537#define SDL_LIBRETRO_IMPLEMENTATION_ONCE
539#ifndef SDL_LIBRETRO_NO_INI_IMPLEMENTATION
540#define SDL_INI_IMPLEMENTATION
544#ifndef SDL_LIBRETRO_MAX_PATH
549#define SDL_LIBRETRO_MAX_PATH 4096
555#define SDL_LIBRETRO_AUDIO_SINGLE_SAMPLE_BUFFER_SIZE 512
561#define SDL_LIBRETRO_OSD_INITIAL_CAPACITY 4
563#ifndef SDL_LIBRETRO_MAX_USERS
571#define SDL_LIBRETRO_MAX_USERS 4
582#define SDL_LIBRETRO_MAX_JOYPAD_BUTTONS 16
590static const char* SDL_Libretro_JoypadButtonNames[SDL_LIBRETRO_MAX_JOYPAD_BUTTONS] = {
591 "B",
"Y",
"Select",
"Start",
"Up",
"Down",
"Left",
"Right",
592 "A",
"X",
"L",
"R",
"L2",
"R2",
"L3",
"R3",
603 "None",
"Left",
"Right",
615typedef struct SDL_Libretro_CoreInfo {
617 char* supported_extensions;
620 bool supports_no_game;
622} SDL_Libretro_CoreInfo;
628typedef struct SDL_LibretroOsdEntry {
632 enum retro_message_type type;
634} SDL_LibretroOsdEntry;
640typedef struct SDL_LibretroCoreSymbols {
641 SDL_SharedObject* handle;
642 void (*retro_init)(void);
643 void (*retro_deinit)(void);
644 unsigned (*retro_api_version)(void);
645 void (*retro_set_environment)(retro_environment_t);
646 void (*retro_set_video_refresh)(retro_video_refresh_t);
647 void (*retro_set_audio_sample)(retro_audio_sample_t);
648 void (*retro_set_audio_sample_batch)(retro_audio_sample_batch_t);
649 void (*retro_set_input_poll)(retro_input_poll_t);
650 void (*retro_set_input_state)(retro_input_state_t);
651 void (*retro_get_system_info)(
struct retro_system_info*);
652 void (*retro_get_system_av_info)(
struct retro_system_av_info*);
653 void (*retro_set_controller_port_device)(
unsigned port,
unsigned device);
654 void (*retro_reset)(void);
655 void (*retro_run)(void);
656 size_t (*retro_serialize_size)(void);
657 bool (*retro_serialize)(
void*, size_t);
658 bool (*retro_unserialize)(
const void*, size_t);
659 void (*retro_cheat_reset)(void);
660 void (*retro_cheat_set)(
unsigned index,
bool enabled,
const char* code);
661 bool (*retro_load_game)(
const struct retro_game_info*);
662 bool (*retro_load_game_special)(unsigned,
const struct retro_game_info*, size_t);
663 void (*retro_unload_game)(void);
664 unsigned (*retro_get_region)(void);
665 void* (*retro_get_memory_data)(unsigned);
666 size_t (*retro_get_memory_size)(unsigned);
667} SDL_LibretroCoreSymbols;
675typedef struct SDL_LibretroMicrophone {
676 SDL_AudioStream* stream;
680} SDL_LibretroMicrophone;
686typedef struct SDL_LibretroDiskImage {
690} SDL_LibretroDiskImage;
696typedef struct SDL_LibretroCoreData {
697 SDL_LibretroCoreSymbols symbols;
702 double speedAccumulator;
704 unsigned width, height;
708 char corePath[SDL_LIBRETRO_MAX_PATH];
709 char libraryName[128];
710 char libraryVersion[128];
711 char validExtensions[128];
717 enum retro_pixel_format pixelFormat;
718 unsigned performanceLevel;
719 uint64_t serializationQuirks;
720 enum retro_savestate_context savestateContext;
724 SDL_Texture* texture;
725 SDL_FRect renderDstRect;
726 bool videoReinitPending;
732 void* softwareFramebufferPixels;
735 SDL_AudioStream* audioStream;
736 int audioQueueThresholdBytes;
737 unsigned minimumAudioLatencyMs;
738 int16_t singleSampleBuffer[SDL_LIBRETRO_AUDIO_SINGLE_SAMPLE_BUFFER_SIZE * 2];
739 size_t singleSampleCount;
740 int audioDropWarnCount;
741 bool audioReinitPending;
742 struct retro_audio_callback audio_callback;
743 struct retro_audio_buffer_status_callback audio_buffer_status;
746 float inputMouseX, inputMouseY;
747 float inputMotionAccumX, inputMotionAccumY;
748 float inputMotionX, inputMotionY;
749 float inputWheelAccumX, inputWheelAccumY;
750 float inputWheelX, inputWheelY;
753 retro_keyboard_event_t keyboard_event;
756 struct retro_frame_time_callback runloop_frame_time;
757 Uint64 runloop_frame_time_last;
760 struct retro_fastforwarding_override fastforwardOverride;
761 bool fastforwardOverrideActive;
765 unsigned optionCount;
766 unsigned optionCapacity;
767 bool optionsDirtyCore;
768 bool optionsDirtyApp;
770 retro_core_options_update_display_callback_t optionsUpdateDisplayCallback;
772 unsigned optionCategoriesCount;
773 unsigned optionCategoriesCapacity;
776 struct retro_input_descriptor* inputDescriptors;
777 unsigned inputDescriptorsCount;
780 struct retro_controller_info* controllerInfo;
781 unsigned controllerInfoCount;
784 char contentPath[SDL_LIBRETRO_MAX_PATH];
785 char contentName[SDL_LIBRETRO_MAX_PATH];
786 char contentDir[SDL_LIBRETRO_MAX_PATH];
788 char contentTempPath[SDL_LIBRETRO_MAX_PATH];
789 char contentTempDir[SDL_LIBRETRO_MAX_PATH];
791 struct retro_game_info_ext gameInfoExt;
792 struct retro_game_info_ext* gameInfoExtArray;
793 unsigned gameInfoExtCount;
796 struct retro_system_content_info_override* contentInfoOverrides;
797 unsigned contentInfoOverrideCount;
800 struct retro_subsystem_info* subsystems;
801 unsigned subsystemCount;
814 SDL_LibretroMicrophone* microphone;
817 struct retro_disk_control_ext_callback disk_control;
818 SDL_LibretroDiskImage* diskImages;
819 unsigned diskImageCount;
822 struct retro_memory_descriptor* memoryMapDescriptors;
823 unsigned memoryMapDescriptorCount;
831 struct retro_perf_counter* perfCounters[64];
832 unsigned perfCounterCount;
833 retro_perf_tick_t gameTimeNSEC;
834} SDL_LibretroCoreData;
840typedef struct SDL_LibretroRewindDelta {
844} SDL_LibretroRewindDelta;
856 unsigned audioLatencyMs;
858 SDL_ScaleMode scaleMode;
859 SDL_Scancode keyboardPlayer1[SDL_LIBRETRO_MAX_JOYPAD_BUTTONS];
864 char coreDirectory[SDL_LIBRETRO_MAX_PATH];
865 char saveDirectory[SDL_LIBRETRO_MAX_PATH];
866 char systemDirectory[SDL_LIBRETRO_MAX_PATH];
867 char coreAssetsDirectory[SDL_LIBRETRO_MAX_PATH];
868 char playlistDirectory[SDL_LIBRETRO_MAX_PATH];
869 char fileBrowserStartDirectory[SDL_LIBRETRO_MAX_PATH];
874 SDL_Renderer* renderer;
878 enum retro_log_level logLevel;
881 SDL_LibretroOsdEntry* osdQueue;
883 int osdQueueCapacity;
886 struct retro_vfs_interface vfs_interface;
889 unsigned char* rewindReference;
890 unsigned char* rewindScratch;
891 unsigned char* rewindEncodeScratch;
892 SDL_LibretroRewindDelta* rewindEntries;
893 size_t rewindSlotSize;
895 size_t rewindMaxBytes;
896 unsigned rewindCapacity;
898 unsigned rewindCount;
899 unsigned rewindCaptureInterval;
900 unsigned rewindFrameCounter;
902 bool rewindHasReference;
907 unsigned gamepadCount;
909 SDL_LibretroCoreData core;
910 unsigned coreGeneration;
917 SDL_Libretro_CoreInfo* coreLibrary;
918 unsigned coreLibraryCount;
922#if defined(SDL_LIBRETRO_ENABLE_PHYSFS) && !defined(SDL_LIBRETRO_DISABLE_PHYSFS)
924 char physfsMountSource[SDL_LIBRETRO_MAX_PATH];
942static bool SDL_Libretro_InitVideo(SDL_Libretro* lr);
943static void SDL_Libretro_CloseVideo(SDL_Libretro* lr);
944static void SDL_Libretro_VideoRefresh(
const void* data,
unsigned width,
unsigned height,
size_t pitch);
945static void SDL_Libretro_ReleaseSoftwareFramebuffer(SDL_Libretro* lr);
947static void SDL_Libretro_AudioSample(int16_t left, int16_t right);
948static size_t SDL_Libretro_AudioSampleBatch(
const int16_t* data,
size_t frames);
949static void SDL_Libretro_FlushSingleSamples(SDL_Libretro* lr);
950static void SDL_Libretro_UpdateDRC(SDL_Libretro* lr,
float speed);
951static unsigned SDL_Libretro_UpdateAudioThreshold(SDL_Libretro* lr);
952static void SDL_Libretro_ReportAudioBufferStatus(SDL_Libretro* lr);
954static bool SDL_Libretro_InitAudio(SDL_Libretro* lr);
955static void SDL_Libretro_CloseAudio(SDL_Libretro* lr);
956static void SDL_Libretro_InputPoll(
void);
957static int16_t SDL_Libretro_InputState(
unsigned port,
unsigned device,
unsigned index,
unsigned id);
958static bool SDL_Libretro_RewindStep(SDL_Libretro* lr);
959static void SDL_Libretro_OsdPush(SDL_Libretro* lr,
const char* msg,
double durationSec,
unsigned priority,
enum retro_message_type type, int8_t progress);
960static void SDL_Libretro_FreeMessages(SDL_Libretro* lr);
961static bool SDL_Libretro_EnvironmentCallback(
unsigned cmd,
void* data);
962static void SDL_Libretro_PushEvent(SDL_Libretro* lr, Uint32 type,
void* data);
963static bool SDL_Libretro_PushEnvEvent(SDL_Libretro* lr,
unsigned cmd,
void* data);
964static void SDL_Libretro_ClearRewind(SDL_Libretro* lr);
966static SDL_Scancode SDL_Libretro_RetroKeyToScancode(
unsigned key);
967static unsigned SDL_Libretro_ScancodeToRetroKey(SDL_Scancode scancode);
968static uint16_t SDL_Libretro_KeymodToRetroMod(SDL_Keymod mod);
969static SDL_GamepadButton SDL_Libretro_RetroJoypadToGamepadButton(
const SDL_Libretro* lr,
unsigned port,
unsigned button);
973static bool SDL_Libretro_SetSensorState(
unsigned port,
enum retro_sensor_action action,
unsigned rate);
974static float SDL_Libretro_GetSensorInput(
unsigned port,
unsigned id);
975static void SDL_Libretro_CloseSensors(SDL_Libretro* lr);
979static retro_microphone_t* SDL_Libretro_MicOpen(
const retro_microphone_params_t* params);
980static void SDL_Libretro_MicClose(retro_microphone_t* microphone);
981static bool SDL_Libretro_MicGetParams(
const retro_microphone_t* microphone, retro_microphone_params_t* params);
982static bool SDL_Libretro_MicSetState(retro_microphone_t* microphone,
bool state);
983static bool SDL_Libretro_MicGetState(
const retro_microphone_t* microphone);
984static int SDL_Libretro_MicRead(retro_microphone_t* microphone, int16_t* samples,
size_t num_samples);
985static void SDL_Libretro_CloseMicrophone(SDL_Libretro* lr);
989#ifdef SDL_LIBRETRO_ENABLE_REWIND_DELTA
990static size_t SDL_Libretro_RewindEncodeDelta(
const unsigned char* cur,
const unsigned char* ref,
size_t len,
unsigned char* out,
size_t outCap);
991static bool SDL_Libretro_RewindDecodeDelta(
const unsigned char* delta,
size_t deltaLen,
unsigned char* state,
size_t stateLen);
993static void SDL_Libretro_RewindCapture(SDL_Libretro* lr);
994static bool SDL_Libretro_RewindStepState(SDL_Libretro* lr);
995static void SDL_Libretro_RewindFreeEntry(SDL_Libretro* lr, SDL_LibretroRewindDelta* entry);
996static void SDL_Libretro_RewindEvictToBudget(SDL_Libretro* lr);
997static void SDL_Libretro_RewindFree(SDL_Libretro* lr);
999static bool SDL_Libretro_ExtensionInList(
const char* ext,
const char* pipeList);
1001static void SDL_Libretro_InitCoreOption(SDL_Libretro* lr,
const char* key,
const char* defaultValue,
const char* desc,
const struct retro_core_option_value* values,
unsigned valuesMax,
const char* info,
const char* categoryKey);
1002static void SDL_Libretro_InitCoreOptionCategory(SDL_Libretro* lr,
const char* key,
const char* desc,
const char* info);
1003static void SDL_Libretro_FreeCoreOptions(SDL_Libretro* lr);
1005static void SDL_Libretro_FreeMemoryMap(SDL_Libretro* lr);
1006static void SDL_Libretro_FreeContentInfoOverrides(SDL_Libretro* lr);
1007static void SDL_Libretro_FreeSubsystems(SDL_Libretro* lr);
1008static void SDL_Libretro_FreeInputDescriptors(SDL_Libretro* lr);
1009static void SDL_Libretro_FreeControllerInfo(SDL_Libretro* lr);
1010static const struct retro_subsystem_info* SDL_Libretro_GetSubsystemById(
const SDL_Libretro* lr,
unsigned subsystemId);
1011static const struct retro_subsystem_info* SDL_Libretro_GetSubsystemByName(
const SDL_Libretro* lr,
const char* name);
1015static bool SDL_Libretro_GetPrefDirectory(
char* dst,
size_t dstSize);
1016static void SDL_Libretro_FreeDiskImages(SDL_Libretro* lr);
1017static const char* SDL_Libretro_GetExtension(
const char* path);
1018static bool SDL_Libretro_ContentNeedsFullpath(
const SDL_Libretro* lr,
const char* ext);
1019static bool SDL_Libretro_SpillToTempFile(SDL_Libretro* lr, SDL_IOStream* src,
const char* path,
bool closeio,
char* tempPath,
size_t tempPathSize);
1020static bool SDL_Libretro_GetTempDirectory(SDL_Libretro* lr,
char* dir,
size_t dirSize);
1021static void SDL_Libretro_RemoveTree(
const char* path);
1025static void SDL_Libretro_FreeCoreLibrary(SDL_Libretro* lr);
1029static bool SDL_Libretro_LoadCoreConfig(SDL_Libretro* lr);
1030static bool SDL_Libretro_SaveCoreConfig(SDL_Libretro* lr);
1031static const char* SDL_Libretro_GetSavedCoreOption(
const SDL_Libretro* lr,
const char* key);
1032static bool SDL_Libretro_CloseConfig(SDL_Libretro* lr);
1036static void SDL_Libretro_PhysFS_ClearMount(SDL_Libretro* lr);
#define SDL_LIBRETRO_MAX_USERS
The number of controller ports (gamepads) the frontend tracks.
SDL_libretro - audio subsystem.
SDL_libretro config saving/loading.
SDL_libretro - core lifecycle implementation.
SDL_libretro environment callback dispatch.
SDL_libretro - on-screen display message queue.
SDL_libretro - core options management.
SDL_libretro - zip loading with PhysFS.
SDL_libretro - save states, core memory (SRAM/RTC/...), and rewind.
SDL_libretro - SDL3 Virtual File System interface for libretro.
SDL_libretro - Video System.
void SDL_Libretro_SetMessage(SDL_Libretro *lr, const char *msg, double duration)
Add a message to be displayed within the libretro context.
bool SDL_Libretro_SaveState_IO(SDL_Libretro *lr, SDL_IOStream *dst, bool closeio)
Save the current libretro state to the given SDL_IOStream.
bool SDL_Libretro_IsMenuOpen(const SDL_LibretroMenu *menu)
Checks whether the menu is currently shown.
bool SDL_Libretro_CycleOptionValue(SDL_Libretro *lr, const char *key, int direction)
Advance a core option to the next (+1) or previous (-1) value.
bool SDL_Libretro_Render(SDL_Libretro *lr, SDL_Renderer *renderer, const SDL_FRect *dstRect)
Render the libretro context in the given renderer.
bool SDL_Libretro_IsCoreReady(const SDL_Libretro *lr)
Indicates whether a core is loaded.
bool SDL_Libretro_SetCoreAssetsDirectory(SDL_Libretro *lr, const char *path)
Sets where cores look for their assets, reported through RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY.
bool SDL_Libretro_SetSystemDirectory(SDL_Libretro *lr, const char *path)
Sets where cores look for system files (BIOS, firmware, etc).
struct SDL_LibretroMenu SDL_LibretroMenu
An in-app menu built on nuklear_console.
size_t SDL_Libretro_GetSavePath(const SDL_Libretro *lr, const char *extension, char *dst, size_t dstSize)
Build a path in the save directory for the currently loaded content.
bool SDL_Libretro_SetCoreDirectory(SDL_Libretro *lr, const char *path)
Sets the associated libretro core directory, where the default set of cores will be loaded from.
void SDL_Libretro_SetRewindMemoryLimit(SDL_Libretro *lr, size_t maxBytes)
Set the maximum number of bytes of encoded delta history to retain.
bool SDL_Libretro_UpdateOptionVisibility(SDL_Libretro *lr)
Ask the core to refresh which of its options should be displayed.
void(* SDL_LibretroMenuCallback)(SDL_LibretroMenu *menu, void *userdata)
A callback for menu entries added by the application.
bool SDL_Libretro_SaveSRAM(SDL_Libretro *lr, const char *file)
Saves the current SRAM to the given file.
const char * SDL_Libretro_GetUsername(SDL_Libretro *lr)
Get the username reported to cores.
SDL_ScaleMode SDL_Libretro_GetScaleMode(const SDL_Libretro *lr)
Gets the texture scale mode used when the libretro frame is scaled.
SDL_LibretroFitMode SDL_Libretro_GetFitMode(const SDL_Libretro *lr)
Gets how the frame is fit into the destination rectangle when rendered.
bool SDL_Libretro_SetCheat(SDL_Libretro *lr, unsigned index, bool enabled, const char *code)
Set a cheat code either enabled or disabled within the libretro context.
bool SDL_Libretro_SaveScreenshot(const SDL_Libretro *lr, const char *path)
Saves a PNG screenshot of the current frame.
SDL_Surface * SDL_Libretro_CreateSurface(const SDL_Libretro *lr)
Creates a new surface from the current libretro context.
const char * SDL_Libretro_GetContentExtension(const SDL_Libretro *lr)
Get the extension of the loaded content, as it appears in the path.
unsigned SDL_Libretro_GetInputDescriptorCount(const SDL_Libretro *lr)
Retrieve the number of input descriptors provided by a Libretro core.
int SDL_Libretro_GetRotation(const SDL_Libretro *lr)
Gets the screen rotation requested by the core.
bool SDL_Libretro_GetMessageByIndex(SDL_Libretro *lr, int index, const char **msg, int *progress, int *type)
Retrieves all message details for the given message index.
bool SDL_Libretro_GetSRAMAutoSave(const SDL_Libretro *lr)
Check whether SRAM is loaded and saved along with the game.
void SDL_Libretro_UpdateMenu(SDL_LibretroMenu *menu)
Processes input and lays out the menu for this frame.
void SDL_Libretro_UnloadCore(SDL_Libretro *lr)
Unloads the actively loaded core.
bool SDL_Libretro_AddDiskImage(SDL_Libretro *lr, const char *path)
Appends a new disk image from a file path.
int SDL_Libretro_GetMessageProgress(SDL_Libretro *lr)
Gets the progress of the message returned by SDL_Libretro_GetMessage().
bool SDL_Libretro_GetMemoryMapDescriptor(const SDL_Libretro *lr, unsigned index, Uint64 *flags, void **ptr, size_t *offset, size_t *start, size_t *select, size_t *disconnect, size_t *len, const char **addrspace)
Retrieve one memory-map descriptor by index.
bool SDL_Libretro_EjectDisk(SDL_Libretro *lr)
Ejects the disk tray, allowing the disk image to be changed.
bool SDL_Libretro_LoadGameSpecial(SDL_Libretro *lr, const char *subsystem, const char **paths, unsigned numPaths)
Loads multi-ROM subsystem content (e.g.
void SDL_Libretro_SetLogLevel(SDL_Libretro *lr, SDL_LogPriority level)
Sets the threshold for logs to be posted.
double SDL_Libretro_GetSampleRate(const SDL_Libretro *lr)
Get the audio sample rate the loaded core outputs at.
SDL_LibretroFitMode
When rendering the libretro context, determine how to display within the destination.
bool SDL_Libretro_SetPortDevice(SDL_Libretro *lr, unsigned port, unsigned device)
Assign a device type to a controller port.
bool SDL_Libretro_LoadSRAM(SDL_Libretro *lr, const char *file)
Loads the SRAM from the given file.
bool SDL_Libretro_Reset(SDL_Libretro *lr)
Resets the loaded game, like pressing the console's reset button.
size_t SDL_Libretro_GetFileName(char *dst, size_t dstSize, const char *path, bool withExtension)
Copy the file name portion of a path into a caller-provided buffer.
void SDL_Libretro_ResetCheats(SDL_Libretro *lr)
Clears all cheats that were set on the core.
bool SDL_Libretro_AreOptionsDirty(SDL_Libretro *lr)
Retrieves whether the options have been changed since the last time they were checked.
bool SDL_Libretro_PhysFS_LoadGame(SDL_Libretro *lr, const char *gamePath)
Archive-aware replacement for SDL_Libretro_LoadGame().
void * SDL_Libretro_GetMemoryData(const SDL_Libretro *lr, unsigned memoryType, size_t *size)
Get a pointer to a core memory region and its size.
const char * SDL_Libretro_GetGameName(const SDL_Libretro *lr)
Retrieve the human-readable name of the loaded game.
unsigned SDL_Libretro_GetPortDevice(const SDL_Libretro *lr, unsigned port)
Get the device type assigned to a controller port.
int SDL_Libretro_GetVersion(void)
Get the version of SDL_libretro the implementation was compiled with.
void * SDL_Libretro_GetMenuUserData(const SDL_LibretroMenu *menu)
Gets the data attached with SDL_Libretro_SetMenuUserData().
const SDL_LibretroCategory * SDL_Libretro_GetCategoryByIndex(const SDL_Libretro *lr, unsigned index)
Retrieve an option category by index.
SDL_LibretroMenuStyle
Color themes for the menu.
bool SDL_Libretro_SetRewindEnabled(SDL_Libretro *lr, bool enabled, unsigned bufferFrames, unsigned captureInterval)
Enable or disable the rewind system.
const char * SDL_Libretro_GetCoreVersion(const SDL_Libretro *lr)
Retrieves the version of the libretro core that's actively loaded.
void SDL_Libretro_RenderMenu(SDL_LibretroMenu *menu)
Draws the menu laid out by SDL_Libretro_UpdateMenu() to the renderer.
const SDL_LibretroCategory * SDL_Libretro_GetCategory(const SDL_Libretro *lr, const char *key)
Retrieve an option category by key.
bool SDL_Libretro_SetRewindMemoryDuration(SDL_Libretro *lr, double seconds)
Set the rewind memory budget by target duration instead of raw bytes.
unsigned SDL_Libretro_GetPerformanceLevel(const SDL_Libretro *lr)
Get the performance level the core requested via SET_PERFORMANCE_LEVEL.
void SDL_Libretro_DestroyMenu(SDL_LibretroMenu *menu)
Destroys a menu created with SDL_Libretro_CreateMenu().
void SDL_Libretro_Update(SDL_Libretro *lr)
Runs the loaded game; call it once per frame of the application's loop.
bool SDL_Libretro_GetInputDescriptor(const SDL_Libretro *lr, unsigned index, unsigned *port, unsigned *device, unsigned *id, const char **description)
Retrieve an input descriptor by index.
size_t SDL_Libretro_GetRewindMemoryUsage(const SDL_Libretro *lr)
Get the approximate memory currently held by the rewind buffer, in bytes.
const char * SDL_Libretro_GetValidExtensions(const SDL_Libretro *lr)
Gets the default set of valid extensions associated with the core, seperated by a "|".
void SDL_Libretro_SetMenuOpen(SDL_LibretroMenu *menu, bool open)
Opens or closes the menu.
unsigned SDL_Libretro_GetCategoryCount(const SDL_Libretro *lr)
Get the number of option categories registered by the core.
bool SDL_Libretro_InitConfig(SDL_Libretro *lr, const char *org, const char *app)
Sets up the config file to be the default path, accoring to the organization and app name.
bool SDL_Libretro_SaveSRAM_IO(SDL_Libretro *lr, SDL_IOStream *dst, bool closeio)
Write the core's battery-backed save RAM to a stream.
bool SDL_Libretro_InitConfigFile(SDL_Libretro *lr, const char *file)
Initializes the config system based on the given file.
unsigned SDL_Libretro_GetMemoryMapCount(const SDL_Libretro *lr)
Get the number of memory-map descriptors the core has published.
bool SDL_Libretro_PhysFS_Init(SDL_Libretro *lr)
Initialize PhysFS and route the libretro VFS through it.
bool SDL_Libretro_AddMenuCheckbox(SDL_LibretroMenu *menu, const char *label, bool *value, SDL_LibretroMenuCallback callback, void *userdata)
Adds a checkbox to the main menu, just above Quit.
bool SDL_Libretro_LoadGame_IO(SDL_Libretro *lr, SDL_IOStream *src, const char *path, bool closeio)
Loads a game from an SDL_IOStream.
bool SDL_Libretro_SetInitialDisk(SDL_Libretro *lr, unsigned index, const char *path)
Sets the disk image to insert once content is loaded.
bool SDL_Libretro_GetBlockExtract(const SDL_Libretro *lr)
Retrieves whether the core expects archives to be loaded directly.
bool SDL_Libretro_LoadSRAM_IO(SDL_Libretro *lr, SDL_IOStream *src, bool closeio)
Load the core's battery-backed save RAM from a stream.
int SDL_Libretro_GetMessageType(SDL_Libretro *lr)
Gets the type of the message returned by SDL_Libretro_GetMessage().
unsigned SDL_Libretro_GetDiskIndex(const SDL_Libretro *lr)
Returns the index of the currently inserted disk image.
bool SDL_Libretro_SetDiskIndex(SDL_Libretro *lr, unsigned index)
Sets the disk image index to insert into the emulated drive.
const char * SDL_Libretro_GetMessage(SDL_Libretro *lr)
Gets the most relevant libretro message to display from the queue.
void SDL_Libretro_SetVFS(SDL_Libretro *lr, void *vfs)
Set the Virtual File System the core uses for file access.
double SDL_Libretro_GetFPS(const SDL_Libretro *lr)
Gets the frame rate the core expects to run at.
const char * SDL_Libretro_GetOptionValueLabel(SDL_Libretro *lr, const char *key)
Get the human-readable label for a core option's current value.
SDL_LogPriority SDL_Libretro_GetLogLevel(const SDL_Libretro *lr)
Retrieve the threshold for logs that will be posted.
float SDL_Libretro_GetSpeed(const SDL_Libretro *lr)
Get how fast the game runs, as a multiple of its normal speed.
void SDL_Libretro_PhysFS_Quit(SDL_Libretro *lr)
Tear down PhysFS, unmounting any active archive and restoring the plain SDL VFS on the given context.
bool SDL_Libretro_LoadState(SDL_Libretro *lr, const char *file)
Loads the libretro state from the given file.
bool SDL_Libretro_SetFitMode(SDL_Libretro *lr, SDL_LibretroFitMode mode)
Sets how the frame is fit into the destination rectangle when rendered.
enum retro_savestate_context SDL_Libretro_GetSavestateContext(const SDL_Libretro *lr)
Get the savestate context reported to cores through RETRO_ENVIRONMENT_GET_SAVESTATE_CONTEXT.
bool SDL_Libretro_AddDiskImage_IO(SDL_Libretro *lr, SDL_IOStream *src, const char *path, bool closeio)
Appends a new disk image from an SDL_IOStream.
const SDL_LibretroOption * SDL_Libretro_GetOptionByIndex(const SDL_Libretro *lr, unsigned index)
Retrieve a core option by its registration index.
unsigned SDL_Libretro_GetMessageCount(SDL_Libretro *lr)
Gets the number of messages currently in the queue.
void SDL_Libretro_SetVolume(SDL_Libretro *lr, float volume)
Set the audio volume when playing sounds.
size_t SDL_Libretro_GetStateSize(const SDL_Libretro *lr)
Retrieves the size of serialized states.
bool SDL_Libretro_SaveMemory(SDL_Libretro *lr, unsigned memoryType, const char *file)
Write a core memory region to a file.
const char * SDL_Libretro_GetCoreAssetsDirectory(SDL_Libretro *lr)
Get the core assets directory.
bool SDL_Libretro_LoadState_IO(SDL_Libretro *lr, SDL_IOStream *src, bool closeio)
Load a libretro state from the given SDL_IOStream.
const char * SDL_Libretro_GetOptionValue(SDL_Libretro *lr, const char *key)
Get a core option's current value.
struct SDL_Libretro SDL_Libretro
A libretro frontend context: one loaded core, its game, and the settings that carry across cores.
bool SDL_Libretro_GetDiskLabel(const SDL_Libretro *lr, unsigned index, char *label, size_t len)
Retrieves the human-readable label of a disk image.
bool SDL_Libretro_LoadGame(SDL_Libretro *lr, const char *gamePath)
Loads a game at the given path.
float SDL_Libretro_GetAspectRatio(const SDL_Libretro *lr)
Gets the aspect ratio for the libretro context.
SDL_Renderer * SDL_Libretro_GetRenderer(const SDL_Libretro *lr)
Get the renderer the context draws into.
void SDL_Libretro_SetSRAMAutoSave(SDL_Libretro *lr, bool enabled)
Load and save the core's battery-backed save RAM along with the game.
bool SDL_Libretro_ShouldQuit(const SDL_Libretro *lr)
Indicates whether or not the core has requested to shutdown.
bool SDL_Libretro_LoadMemory_IO(SDL_Libretro *lr, unsigned memoryType, SDL_IOStream *src, bool closeio)
Load a core memory region from a stream.
SDL_Libretro * SDL_Libretro_GetMenuLibretro(const SDL_LibretroMenu *menu)
Gets the libretro context the menu was created for.
bool SDL_Libretro_ResetOption(SDL_Libretro *lr, const char *key)
Reset a core option to its default value.
void SDL_Libretro_SetGamepadMapping(SDL_Libretro *lr, unsigned port, int retroButton, SDL_GamepadButton button)
Maps an SDL gamepad button to a RETRO_DEVICE_ID_JOYPAD_* button on the given controller port.
void SDL_Libretro_SetAudioLatency(SDL_Libretro *lr, unsigned latencyMs)
Set the desired minimum audio latency for the audio stream.
float SDL_Libretro_GetVolume(const SDL_Libretro *lr)
Get the audio volume.
void SDL_Libretro_Destroy(SDL_Libretro *lr)
Destroys the given libretro context.
bool SDL_Libretro_LoadMemory(SDL_Libretro *lr, unsigned memoryType, const char *file)
Load a core memory region from a file.
bool SDL_Libretro_OpenMenuPath(SDL_LibretroMenu *menu, const char *path)
Opens the menu and navigates to a page by its slash-separated label path, e.g.
void SDL_Libretro_SetMousePort(SDL_Libretro *lr, unsigned port)
Selects the one controller port that the mouse drives.
SDL_Libretro * SDL_Libretro_Create(void)
Creates a new libretro context.
bool SDL_Libretro_SetMenuStyle(SDL_LibretroMenu *menu, SDL_LibretroMenuStyle style)
Applies a color theme to the menu.
SDL_LibretroMenu * SDL_Libretro_CreateMenu(SDL_Libretro *lr)
Creates the in-app menu for a libretro context.
bool SDL_Libretro_GetRewindEnabled(const SDL_Libretro *lr)
Check whether the rewind system is enabled (independent of current direction).
const char * SDL_Libretro_GetSystemDirectory(SDL_Libretro *lr)
Get the system directory.
void SDL_Libretro_UnloadGame(SDL_Libretro *lr)
Unloads the actively loaded game.
bool SDL_Libretro_SetOptionValue(SDL_Libretro *lr, const char *key, const char *value)
Set a core option's value; fails if the value isn't one the core declared.
void SDL_Libretro_ResetAllOptions(SDL_Libretro *lr)
Reset every core option to its default value.
SDL_LibretroAnalogToDigital SDL_Libretro_GetAnalogToDigital(const SDL_Libretro *lr, unsigned port)
Get the analog stick that also registers D-Pad presses on a controller port.
bool SDL_Libretro_SetSaveDirectory(SDL_Libretro *lr, const char *path)
Sets where content will be saved.
unsigned SDL_Libretro_GetDiskCount(const SDL_Libretro *lr)
Returns the number of disk images available to the loaded core.
bool SDL_Libretro_SaveState(SDL_Libretro *lr, const char *file)
Saves the current libretro state to a file.
size_t SDL_Libretro_GetRewindMemoryLimit(const SDL_Libretro *lr)
Get the current rewind memory budget in bytes (0 if unbounded).
void SDL_Libretro_GetSize(const SDL_Libretro *lr, int *w, int *h)
Gets the width and height of the core's current video frame.
bool SDL_Libretro_LoadGameSpecialById(SDL_Libretro *lr, unsigned subsystemId, const char **paths, unsigned numPaths)
Load multi-ROM subsystem content by its numeric subsystem id.
bool SDL_Libretro_SetMemoryData(SDL_Libretro *lr, unsigned memoryType, const void *data, size_t size)
Overwrite a core memory region with caller-provided bytes.
double SDL_Libretro_GetRewindRemaining(const SDL_Libretro *lr)
Calculates the amount of rewind time remaining in the buffer.
int SDL_Libretro_GetLanguage(const SDL_Libretro *lr)
Get the language reported to cores through RETRO_ENVIRONMENT_GET_LANGUAGE.
unsigned SDL_Libretro_GetOptionCount(const SDL_Libretro *lr)
Get the number of core options that have been set.
void SDL_Libretro_SetMenuUserData(SDL_LibretroMenu *menu, void *userData)
Attaches generic application data to the menu.
bool SDL_Libretro_IsGameReady(const SDL_Libretro *lr)
Indicates whether a game is loaded and running.
bool SDL_Libretro_InsertDisk(SDL_Libretro *lr)
Closes the disk tray after a disk change.
bool SDL_Libretro_LoadCore(SDL_Libretro *lr, const char *core)
Loads a libretro core.
bool SDL_Libretro_SetUsername(SDL_Libretro *lr, const char *username)
Sets the username reported to cores through RETRO_ENVIRONMENT_GET_USERNAME.
bool SDL_Libretro_AddMenuButton(SDL_LibretroMenu *menu, const char *label, SDL_LibretroMenuCallback callback, void *userdata)
Adds a button to the main menu, just above Quit.
void SDL_Libretro_SetVirtualButton(SDL_Libretro *lr, unsigned port, int button, bool pressed)
Press or release a joypad button from code, such as from an on-screen touch control.
void * SDL_Libretro_GetMapAddress(const SDL_Libretro *lr, size_t address, size_t *regionRemaining)
Translate an emulated (guest) address to a live host pointer via the memory map.
bool SDL_Libretro_SetRenderer(SDL_Libretro *lr, SDL_Renderer *renderer)
Set the renderer the libretro context draws into.
bool SDL_Libretro_IsGameRequired(const SDL_Libretro *lr)
Indicates whether the loaded core needs content to run.
SDL_LibretroMenuStyle SDL_Libretro_GetMenuStyle(const SDL_LibretroMenu *menu)
Gets the menu's active color theme.
void SDL_Libretro_HandleEvent(SDL_Libretro *lr, const SDL_Event *event)
Call this function within the SDL_PollEvent() loop to ensure libretro knows of important events.
void SDL_Libretro_MenuScreenshotClicked(SDL_LibretroMenu *menu, void *userdata)
A ready-made menu callback that saves a PNG screenshot of the current frame, reporting the result in ...
SDL_Texture * SDL_Libretro_GetTexture(const SDL_Libretro *lr)
Get the streaming texture that holds the core's most recent video frame.
bool SDL_Libretro_SetScaleMode(SDL_Libretro *lr, SDL_ScaleMode mode)
Sets the texture scale mode used when the libretro frame is scaled.
unsigned SDL_Libretro_GetAudioLatency(const SDL_Libretro *lr)
Get the minimum audio latency for the audio stream.
void SDL_Libretro_SetAnalogToDigital(SDL_Libretro *lr, unsigned port, SDL_LibretroAnalogToDigital stick)
Selects which analog stick, if any, also registers D-Pad presses on the given controller port,...
const char * SDL_Libretro_GetCoreDirectory(SDL_Libretro *lr)
Get the core directory.
const char * SDL_Libretro_GetSaveDirectory(SDL_Libretro *lr)
Get the save directory.
bool SDL_Libretro_HandleMenuEvent(SDL_LibretroMenu *menu, const SDL_Event *event)
Routes an event to the menu; call this for every event, before SDL_Libretro_HandleEvent().
void SDL_Libretro_SetSavestateContext(SDL_Libretro *lr, enum retro_savestate_context context)
Sets the savestate context reported to cores through RETRO_ENVIRONMENT_GET_SAVESTATE_CONTEXT.
void SDL_Libretro_ToggleMenu(SDL_LibretroMenu *menu)
Opens the menu when it is closed, or closes it when it is open.
bool SDL_Libretro_IsFastforwardOverrideActive(const SDL_Libretro *lr)
Indicates whether the core is forcing fast-forward through RETRO_ENVIRONMENT_SET_FASTFORWARDING_OVERR...
bool SDL_Libretro_SaveMemory_IO(SDL_Libretro *lr, unsigned memoryType, SDL_IOStream *dst, bool closeio)
Write a core memory region to a stream.
SDL_LibretroAnalogToDigital
Which analog stick, if any, also registers D-Pad presses for a controller port.
unsigned SDL_Libretro_GetMousePort(const SDL_Libretro *lr)
Get the controller port that the mouse drives.
const SDL_LibretroOption * SDL_Libretro_GetOption(const SDL_Libretro *lr, const char *key)
Retrieve details about a given core option.
void SDL_Libretro_SetLanguage(SDL_Libretro *lr, int language)
Override the language reported to cores through RETRO_ENVIRONMENT_GET_LANGUAGE.
const char * SDL_Libretro_GetCoreName(const SDL_Libretro *lr)
Retrieve the name of the libretro core that's actively loaded.
void SDL_Libretro_SetKeyboardMapping(SDL_Libretro *lr, int retroButton, SDL_Scancode scancode)
Maps a keyboard key to a RETRO_DEVICE_ID_JOYPAD_* button for Player 1 (controller port 0).
void SDL_Libretro_SetSpeed(SDL_Libretro *lr, float speed)
Sets how fast the game runs, as a multiple of its normal speed.
@ SDL_LIBRETRO_FIT_STRETCH
Ignore the aspect ratio, and stretch the image to match the destination rectangle.
@ SDL_LIBRETRO_FIT_FIRST
The default fit mode to fit within the destination.
@ SDL_LIBRETRO_FIT_INTEGER
Keep the same aspect ratio, while keeping integer scaling within the confines of the destination.
@ SDL_LIBRETRO_FIT_COUNT
The number of possible fit modes.
@ SDL_LIBRETRO_FIT_ASPECT
Keep the same aspect ratio, and fit within the confines of the destination.
@ SDL_LIBRETRO_MENU_STYLE_CATPPUCCIN_LATTE
Catppuccin Latte, the light Catppuccin flavor.
@ SDL_LIBRETRO_MENU_STYLE_CATPPUCCIN_FRAPPE
Catppuccin Frappe, a muted dark Catppuccin flavor.
@ SDL_LIBRETRO_MENU_STYLE_COUNT
The number of menu styles.
@ SDL_LIBRETRO_MENU_STYLE_DARK
Nuklear's built-in default dark style.
@ SDL_LIBRETRO_MENU_STYLE_DRACULA
The Dracula dark theme.
@ SDL_LIBRETRO_MENU_STYLE_CATPPUCCIN_MOCHA
Catppuccin Mocha, the darkest Catppuccin flavor.
@ SDL_LIBRETRO_MENU_STYLE_CATPPUCCIN_MACCHIATO
Catppuccin Macchiato, a dark Catppuccin flavor between Frappe and Mocha.
@ SDL_LIBRETRO_ANALOG_TO_DIGITAL_NONE
Only the D-Pad drives the retro joypad's directions.
@ SDL_LIBRETRO_ANALOG_TO_DIGITAL_RIGHT
The right analog stick also registers D-Pad presses.
@ SDL_LIBRETRO_ANALOG_TO_DIGITAL_LEFT
The left analog stick also registers D-Pad presses.
@ SDL_LIBRETRO_ANALOG_TO_DIGITAL_COUNT
The number of possible modes.
A group of related core options.
const char * key
Unique identifier referenced by SDL_LibretroOption::category.
const char * desc
Human-readable name.
const char * info
Description / help text; may be empty.
A core option and its current state.
bool visible
Whether the frontend should display it.
SDL_LibretroOptionValue * values
The selectable values; dynamically allocated.
unsigned valuesCapacity
Allocated capacity of the values array.
const char * desc
Human-readable name.
const char * value
The current value.
const char * category
Key of the category it belongs to; empty if none.
unsigned valuesCount
The number of populated entries in values.
const char * key
Unique identifier the core queries.
const char * defaultValue
The default value.
const char * info
Description / help text; may be empty.
One selectable value for a core option.
const char * value
The value the core stores.
const char * label
Human-readable name; may be NULL, in which case display value itself.