Documentation ¶
Overview ¶
Package libretro is a cgo binding for the libretro API.
Libretro is a simple but powerful development interface that allows for the easy creation of emulators, games and multimedia applications that can plug straight into any libretro-compatible frontend. This development interface is open to others so that they can run these pluggable emulator and game cores also in their own programs or devices.
Index ¶
- Constants
- func DlOpen(path string) (unsafe.Pointer, error)
- func GetPixelFormat(data unsafe.Pointer) uint32
- func SetBool(data unsafe.Pointer, val bool)
- func SetString(data unsafe.Pointer, val string)
- func SetUint(data unsafe.Pointer, val uint)
- type AudioCallback
- type Core
- func (core *Core) APIVersion() uint
- func (core *Core) BindLogCallback(data unsafe.Pointer, f logFunc)
- func (core *Core) BindPerfCallback(data unsafe.Pointer, f getTimeUsecFunc)
- func (core *Core) Deinit()
- func (core *Core) DlSym(name string) unsafe.Pointer
- func (core *Core) GetMemoryData(id uint32) unsafe.Pointer
- func (core *Core) GetMemorySize(id uint32) uint
- func (core *Core) GetSystemAVInfo() SystemAVInfo
- func (core *Core) GetSystemInfo() SystemInfo
- func (core *Core) Init()
- func (core *Core) LoadGame(gi GameInfo) bool
- func (core *Core) Reset()
- func (core *Core) Run()
- func (core *Core) Serialize(size uint) ([]byte, error)
- func (core *Core) SerializeSize() uint
- func (core *Core) SetAudioCallback(data unsafe.Pointer)
- func (core *Core) SetAudioSample(f audioSampleFunc)
- func (core *Core) SetAudioSampleBatch(f audioSampleBatchFunc)
- func (core *Core) SetControllerPortDevice(port uint, device uint32)
- func (core *Core) SetDiskControlCallback(data unsafe.Pointer)
- func (core *Core) SetEnvironment(f environmentFunc)
- func (core *Core) SetFrameTimeCallback(data unsafe.Pointer)
- func (core *Core) SetInputPoll(f inputPollFunc)
- func (core *Core) SetInputState(f inputStateFunc)
- func (core *Core) SetVideoRefresh(f videoRefreshFunc)
- func (core *Core) UnloadGame()
- func (core *Core) Unserialize(bytes []byte, size uint) error
- type CoreOptionDefinition
- func (cod *CoreOptionDefinition) Choices() []string
- func (cod *CoreOptionDefinition) DefaultValue() string
- func (cod *CoreOptionDefinition) Desc() string
- func (cod *CoreOptionDefinition) Info() string
- func (cod *CoreOptionDefinition) Key() string
- func (cod *CoreOptionDefinition) Values() []CoreOptionValue
- type CoreOptionValue
- type DiskControlCallback
- type FrameTimeCallback
- type GameGeometry
- type GameInfo
- type SystemAVInfo
- type SystemInfo
- type SystemTiming
- type Variable
Constants ¶
const ( PixelFormat0RGB1555 = uint32(C.RETRO_PIXEL_FORMAT_0RGB1555) PixelFormatXRGB8888 = uint32(C.RETRO_PIXEL_FORMAT_XRGB8888) PixelFormatRGB565 = uint32(C.RETRO_PIXEL_FORMAT_RGB565) )
The pixel format the core must use to render into data. This format could differ from the format used in SET_PIXEL_FORMAT. Set by frontend in GET_CURRENT_SOFTWARE_FRAMEBUFFER.
const ( // DeviceNone means that input is disabled. DeviceNone = uint32(C.RETRO_DEVICE_NONE) // DeviceJoypad represents the RetroPad. It is essentially a Super Nintendo // controller, but with additional L2/R2/L3/R3 buttons, similar to a // PS1 DualShock. DeviceJoypad = uint32(C.RETRO_DEVICE_JOYPAD) // DeviceMouse is a simple mouse, similar to Super Nintendo's mouse. // X and Y coordinates are reported relatively to last poll (poll callback). // It is up to the libretro implementation to keep track of where the mouse // pointer is supposed to be on the screen. // The frontend must make sure not to interfere with its own hardware // mouse pointer. DeviceMouse = uint32(C.RETRO_DEVICE_MOUSE) // DeviceKeyboard lets one poll for raw key pressed. // It is poll based, so input callback will return with the current // pressed state. // For event/text based keyboard input, see // RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK. DeviceKeyboard = uint32(C.RETRO_DEVICE_KEYBOARD) // DeviceLightgun X/Y coordinates are reported relatively to last poll, // similar to mouse. */ DeviceLightgun = uint32(C.RETRO_DEVICE_LIGHTGUN) // DeviceAnalog device is an extension to JOYPAD (RetroPad). // Similar to DualShock it adds two analog sticks. // This is treated as a separate device type as it returns values in the // full analog range of [-0x8000, 0x7fff]. Positive X axis is right. // Positive Y axis is down. // Only use ANALOG type when polling for analog values of the axes. DeviceAnalog = uint32(C.RETRO_DEVICE_ANALOG) )
Libretro's fundamental device abstractions.
Libretro's input system consists of some standardized device types, such as a joypad (with/without analog), mouse, keyboard, lightgun and a pointer.
The functionality of these devices are fixed, and individual cores map their own concept of a controller to libretro's abstractions. This makes it possible for frontends to map the abstract types to a real input device, and not having to worry about binding input correctly to arbitrary controller layouts.
const ( DeviceIDJoypadB = uint32(C.RETRO_DEVICE_ID_JOYPAD_B) DeviceIDJoypadY = uint32(C.RETRO_DEVICE_ID_JOYPAD_Y) DeviceIDJoypadSelect = uint32(C.RETRO_DEVICE_ID_JOYPAD_SELECT) DeviceIDJoypadStart = uint32(C.RETRO_DEVICE_ID_JOYPAD_START) DeviceIDJoypadUp = uint32(C.RETRO_DEVICE_ID_JOYPAD_UP) DeviceIDJoypadDown = uint32(C.RETRO_DEVICE_ID_JOYPAD_DOWN) DeviceIDJoypadLeft = uint32(C.RETRO_DEVICE_ID_JOYPAD_LEFT) DeviceIDJoypadRight = uint32(C.RETRO_DEVICE_ID_JOYPAD_RIGHT) DeviceIDJoypadA = uint32(C.RETRO_DEVICE_ID_JOYPAD_A) DeviceIDJoypadX = uint32(C.RETRO_DEVICE_ID_JOYPAD_X) DeviceIDJoypadL = uint32(C.RETRO_DEVICE_ID_JOYPAD_L) DeviceIDJoypadR = uint32(C.RETRO_DEVICE_ID_JOYPAD_R) DeviceIDJoypadL2 = uint32(C.RETRO_DEVICE_ID_JOYPAD_L2) DeviceIDJoypadR2 = uint32(C.RETRO_DEVICE_ID_JOYPAD_R2) DeviceIDJoypadL3 = uint32(C.RETRO_DEVICE_ID_JOYPAD_L3) DeviceIDJoypadR3 = uint32(C.RETRO_DEVICE_ID_JOYPAD_R3) )
Buttons for the RetroPad (JOYPAD). The placement of these is equivalent to placements on the Super Nintendo controller. L2/R2/L3/R3 buttons correspond to the PS1 DualShock.
const ( DeviceIndexAnalogLeft = uint32(C.RETRO_DEVICE_INDEX_ANALOG_LEFT) DeviceIndexAnalogRight = uint32(C.RETRO_DEVICE_INDEX_ANALOG_RIGHT) DeviceIndexAnalogButton = uint32(C.RETRO_DEVICE_INDEX_ANALOG_BUTTON) DeviceIDAnalogX = uint32(C.RETRO_DEVICE_ID_ANALOG_X) DeviceIDAnalogY = uint32(C.RETRO_DEVICE_ID_ANALOG_Y) )
Index / Id values for ANALOG device.
const ( EnvironmentSetRotation = uint32(C.RETRO_ENVIRONMENT_SET_ROTATION) EnvironmentGetOverscan = uint32(C.RETRO_ENVIRONMENT_GET_OVERSCAN) // Deprecated EnvironmentGetCanDupe = uint32(C.RETRO_ENVIRONMENT_GET_CAN_DUPE) EnvironmentSetMessage = uint32(C.RETRO_ENVIRONMENT_SET_MESSAGE) EnvironmentShutdown = uint32(C.RETRO_ENVIRONMENT_SHUTDOWN) EnvironmentSetPerformanceLevel = uint32(C.RETRO_ENVIRONMENT_SET_PERFORMANCE_LEVEL) EnvironmentGetSystemDirectory = uint32(C.RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY) EnvironmentSetPixelFormat = uint32(C.RETRO_ENVIRONMENT_SET_PIXEL_FORMAT) EnvironmentSetInputDescriptors = uint32(C.RETRO_ENVIRONMENT_SET_INPUT_DESCRIPTORS) EnvironmentSetKeyboardCallback = uint32(C.RETRO_ENVIRONMENT_SET_KEYBOARD_CALLBACK) EnvironmentSetDiskControlInterface = uint32(C.RETRO_ENVIRONMENT_SET_DISK_CONTROL_INTERFACE) EnvironmentSetHWRender = uint32(C.RETRO_ENVIRONMENT_SET_HW_RENDER) EnvironmentGetVariable = uint32(C.RETRO_ENVIRONMENT_GET_VARIABLE) EnvironmentSetVariables = uint32(C.RETRO_ENVIRONMENT_SET_VARIABLES) EnvironmentGetVariableUpdate = uint32(C.RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE) EnvironmentSetSupportNoGame = uint32(C.RETRO_ENVIRONMENT_SET_SUPPORT_NO_GAME) EnvironmentGetLibretroPath = uint32(C.RETRO_ENVIRONMENT_GET_LIBRETRO_PATH) EnvironmentSetFrameTimeCallback = uint32(C.RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK) EnvironmentSetAudioCallback = uint32(C.RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK) EnvironmentGetRumbleInterface = uint32(C.RETRO_ENVIRONMENT_GET_RUMBLE_INTERFACE) EnvironmentGetInputDeviceCapabilities = uint32(C.RETRO_ENVIRONMENT_GET_INPUT_DEVICE_CAPABILITIES) EnvironmentGetSensorInterface = uint32(C.RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE) EnvironmentGetCameraInterface = uint32(C.RETRO_ENVIRONMENT_GET_CAMERA_INTERFACE) EnvironmentGetLogInterface = uint32(C.RETRO_ENVIRONMENT_GET_LOG_INTERFACE) EnvironmentGetPerfInterface = uint32(C.RETRO_ENVIRONMENT_GET_PERF_INTERFACE) EnvironmentGetLocationInterface = uint32(C.RETRO_ENVIRONMENT_GET_LOCATION_INTERFACE) EnvironmentGetCoreAssetDirectory = uint32(C.RETRO_ENVIRONMENT_GET_CORE_ASSETS_DIRECTORY) EnvironmentGetSaveDirectory = uint32(C.RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY) EnvironmentSetSystemAVInfo = uint32(C.RETRO_ENVIRONMENT_SET_SYSTEM_AV_INFO) EnvironmentSetProcAddressCallback = uint32(C.RETRO_ENVIRONMENT_SET_PROC_ADDRESS_CALLBACK) EnvironmentSetSubsystemInfo = uint32(C.RETRO_ENVIRONMENT_SET_SUBSYSTEM_INFO) EnvironmentSetControllerInfo = uint32(C.RETRO_ENVIRONMENT_SET_CONTROLLER_INFO) EnvironmentSetMemoryMaps = uint32(C.RETRO_ENVIRONMENT_SET_MEMORY_MAPS) EnvironmentSetGeometry = uint32(C.RETRO_ENVIRONMENT_SET_GEOMETRY) EnvironmentGetUsername = uint32(C.RETRO_ENVIRONMENT_GET_USERNAME) EnvironmentGetLanguage = uint32(C.RETRO_ENVIRONMENT_GET_LANGUAGE) EnvironmentGetCurrentSoftwareFramebuffer = uint32(C.RETRO_ENVIRONMENT_GET_CURRENT_SOFTWARE_FRAMEBUFFER) EnvironmentGetHWRenderInterface = uint32(C.RETRO_ENVIRONMENT_GET_HW_RENDER_INTERFACE) EnvironmentSetSupportAchievements = uint32(C.RETRO_ENVIRONMENT_SET_SUPPORT_ACHIEVEMENTS) EnvironmentSetHWContextNegociationInterface = uint32(C.RETRO_ENVIRONMENT_SET_HW_RENDER_CONTEXT_NEGOTIATION_INTERFACE) EnvironmentSetSerializationQuirks = uint32(C.RETRO_ENVIRONMENT_SET_SERIALIZATION_QUIRKS) EnvironmentGetVFSInterface = uint32(C.RETRO_ENVIRONMENT_GET_VFS_INTERFACE) EnvironmentGetLEDInterface = uint32(C.RETRO_ENVIRONMENT_GET_LED_INTERFACE) EnvironmentGetAudioVideoEnable = uint32(C.RETRO_ENVIRONMENT_GET_AUDIO_VIDEO_ENABLE) EnvironmentGetMIDIInterface = uint32(C.RETRO_ENVIRONMENT_GET_MIDI_INTERFACE) EnvironmentGetFastforwarding = uint32(C.RETRO_ENVIRONMENT_GET_FASTFORWARDING) EnvironmentGetTargetRefreshRate = uint32(C.RETRO_ENVIRONMENT_GET_TARGET_REFRESH_RATE) EnvironmentGetInputBitmasks = uint32(C.RETRO_ENVIRONMENT_GET_INPUT_BITMASKS) EnvironmentGetCoreOptionsVersion = uint32(C.RETRO_ENVIRONMENT_GET_CORE_OPTIONS_VERSION) EnvironmentSetCoreOptions = uint32(C.RETRO_ENVIRONMENT_SET_CORE_OPTIONS) EnvironmentSetCoreOptionsIntl = uint32(C.RETRO_ENVIRONMENT_SET_CORE_OPTIONS_INTL) EnvironmentSetCoreOptionsDisplay = uint32(C.RETRO_ENVIRONMENT_SET_CORE_OPTIONS_DISPLAY) EnvironmentGetPrefferedHWRender = uint32(C.RETRO_ENVIRONMENT_GET_PREFERRED_HW_RENDER) EnvironmentGetDiskControlInterfaceVersion = uint32(C.RETRO_ENVIRONMENT_GET_DISK_CONTROL_INTERFACE_VERSION) EnvironmentGetDiskControlExtInterface = uint32(C.RETRO_ENVIRONMENT_SET_DISK_CONTROL_EXT_INTERFACE) )
Environment callback API. See libretro.h for details
const ( LogLevelDebug = uint32(C.RETRO_LOG_DEBUG) LogLevelInfo = uint32(C.RETRO_LOG_INFO) LogLevelWarn = uint32(C.RETRO_LOG_WARN) LogLevelError = uint32(C.RETRO_LOG_ERROR) LogLevelDummy = uint32(C.RETRO_LOG_DUMMY) )
Debug levels
const ( MemoryMask = uint32(C.RETRO_MEMORY_MASK) MemorySaveRAM = uint32(C.RETRO_MEMORY_SAVE_RAM) MemoryRTC = uint32(C.RETRO_MEMORY_RTC) MemorySystemRAM = uint32(C.RETRO_MEMORY_SYSTEM_RAM) MemoryVideoRAM = uint32(C.RETRO_MEMORY_VIDEO_RAM) )
Memory constants
const (
DeviceIDJoypadMask = uint32(C.RETRO_DEVICE_ID_JOYPAD_MASK)
)
Mask used to identify joypads
Variables ¶
This section is empty.
Functions ¶
func GetPixelFormat ¶
GetPixelFormat is an environment callback helper that returns the pixel format. Should be used in the case of EnvironmentSetPixelFormat
Types ¶
type AudioCallback ¶
type AudioCallback struct { Callback func() SetState func(bool) }
AudioCallback stores the audio callback itself and the SetState callback
type Core ¶
type Core struct { AudioCallback *AudioCallback FrameTimeCallback *FrameTimeCallback DiskControlCallback *DiskControlCallback // contains filtered or unexported fields }
Core is an instance of a dynalically loaded libretro core
func (*Core) APIVersion ¶
APIVersion returns the RETRO_API_VERSION. Used to validate ABI compatibility when the API is revised.
func (*Core) BindLogCallback ¶
BindLogCallback binds f to the log callback
func (*Core) BindPerfCallback ¶
BindPerfCallback binds f to the perf callback get_time_usec
func (*Core) Deinit ¶
func (core *Core) Deinit()
Deinit takes care of the library global deinitialization
func (*Core) GetMemoryData ¶ added in v0.2.0
GetMemoryData returns the size of a region of the memory. See memory constants.
func (*Core) GetMemorySize ¶ added in v0.2.0
GetMemorySize returns the size of a region of the memory. See memory constants.
func (*Core) GetSystemAVInfo ¶
func (core *Core) GetSystemAVInfo() SystemAVInfo
GetSystemAVInfo returns information about system audio/video timings and geometry. Can be called only after retro_load_game() has successfully completed. NOTE: The implementation of this function might not initialize every variable if needed. E.g. geom.aspect_ratio might not be initialized if core doesn't desire a particular aspect ratio.
func (*Core) GetSystemInfo ¶
func (core *Core) GetSystemInfo() SystemInfo
GetSystemInfo returns statically known system info. Pointers provided in *info must be statically allocated. Can be called at any time, even before retro_init().
func (*Core) Run ¶
func (core *Core) Run()
Run runs the game for one video frame. During retro_run(), input_poll callback must be called at least once. If a frame is not rendered for reasons where a game "dropped" a frame, this still counts as a frame, and retro_run() should explicitly dupe a frame if GET_CAN_DUPE returns true. In this case, the video callback can take a NULL argument for data.
func (*Core) SerializeSize ¶
SerializeSize returns the amount of data the implementation requires to serialize internal state (save states). Between calls to retro_load_game() and retro_unload_game(), the returned size is never allowed to be larger than a previous returned value, to ensure that the frontend can allocate a save state buffer once.
func (*Core) SetAudioCallback ¶ added in v0.2.6
SetAudioCallback is an environment callback helper to set the AudioCallback
func (*Core) SetAudioSample ¶
func (core *Core) SetAudioSample(f audioSampleFunc)
SetAudioSample sets the audio sample callback. Must be set before the first Run call
func (*Core) SetAudioSampleBatch ¶
func (core *Core) SetAudioSampleBatch(f audioSampleBatchFunc)
SetAudioSampleBatch sets the audio sample batch callback. Must be set before the first Run call
func (*Core) SetControllerPortDevice ¶ added in v0.2.9
SetControllerPortDevice sets the device type attached to a controller port
func (*Core) SetDiskControlCallback ¶ added in v0.14.0
SetDiskControlCallback sets an interface which frontend can use to eject and insert disk images
func (*Core) SetEnvironment ¶
func (core *Core) SetEnvironment(f environmentFunc)
SetEnvironment sets the environment callback. Must be called before Init
func (*Core) SetFrameTimeCallback ¶ added in v0.2.6
SetFrameTimeCallback is an environment callback helper to set the FrameTimeCallback
func (*Core) SetInputPoll ¶
func (core *Core) SetInputPoll(f inputPollFunc)
SetInputPoll sets the input poll callback. Must be set before the first Run call
func (*Core) SetInputState ¶
func (core *Core) SetInputState(f inputStateFunc)
SetInputState sets the input state callback. Must be set before the first Run call
func (*Core) SetVideoRefresh ¶
func (core *Core) SetVideoRefresh(f videoRefreshFunc)
SetVideoRefresh sets the video refresh callback. Must be set before the first Run call
type CoreOptionDefinition ¶ added in v0.12.3
type CoreOptionDefinition C.struct_retro_core_option_definition
CoreOptionDefinition represents a core option in the version 1 of the core options API
func GetCoreOptionDefinitions ¶ added in v0.12.3
func GetCoreOptionDefinitions(data unsafe.Pointer) []CoreOptionDefinition
GetCoreOptionDefinitions is an environment callback helper that returns the list of CoreOptionDefinition needed by a core
func GetCoreOptionsIntl ¶ added in v0.12.3
func GetCoreOptionsIntl(data unsafe.Pointer) []CoreOptionDefinition
GetCoreOptionsIntl is an environment callback helper that returns the list of CoreOptionsIntl needed by a core
func (*CoreOptionDefinition) Choices ¶ added in v0.12.3
func (cod *CoreOptionDefinition) Choices() []string
Choices returns the CoreOptionDefinition values as a string slice for compatibility with options v0
func (*CoreOptionDefinition) DefaultValue ¶ added in v0.12.3
func (cod *CoreOptionDefinition) DefaultValue() string
DefaultValue returns the default value of a CoreOptionDefinition as a string
func (*CoreOptionDefinition) Desc ¶ added in v0.12.3
func (cod *CoreOptionDefinition) Desc() string
Desc returns the name of a CoreOptionDefinition as a string
func (*CoreOptionDefinition) Info ¶ added in v0.12.3
func (cod *CoreOptionDefinition) Info() string
Info returns the detailed description of a CoreOptionDefinition as a string
func (*CoreOptionDefinition) Key ¶ added in v0.12.3
func (cod *CoreOptionDefinition) Key() string
Key returns the key of a CoreOptionDefinition as a string
func (*CoreOptionDefinition) Values ¶ added in v0.12.3
func (cod *CoreOptionDefinition) Values() []CoreOptionValue
Values returns the possible values of a CoreOptionDefinition as a string
type CoreOptionValue ¶ added in v0.12.3
type CoreOptionValue C.struct_retro_core_option_value
CoreOptionValue represents the value of a core option in the version 1 of the core options API
func (*CoreOptionValue) Label ¶ added in v0.12.3
func (cov *CoreOptionValue) Label() string
Label is the human readable value label of the CoreOptionValue. If NULL, value itself will be displayed by the frontend
func (*CoreOptionValue) Value ¶ added in v0.12.3
func (cov *CoreOptionValue) Value() string
Value is the expected option value
type DiskControlCallback ¶ added in v0.14.0
type DiskControlCallback struct { SetEjectState func(bool) GetEjectState func() bool GetImageIndex func() uint SetImageIndex func(uint) GetNumImages func() uint }
DiskControlCallback is an interface which frontend can use to eject and insert disk images
type FrameTimeCallback ¶
FrameTimeCallback stores the frame time callback itself and the reference time
type GameGeometry ¶
type GameGeometry struct { AspectRatio float64 BaseWidth int BaseHeight int MaxWidth int MaxHeight int }
GameGeometry represents the geometry of a game, with its aspect ratio, with and height
func GetGeometry ¶ added in v0.5.2
func GetGeometry(data unsafe.Pointer) GameGeometry
GetGeometry is an environment callback helper that returns the game geometry in EnvironmentSetGeometry.
type SystemAVInfo ¶
type SystemAVInfo struct { Geometry GameGeometry Timing SystemTiming }
SystemAVInfo stores informations about the emulated system audio and video
func GetSystemAVInfo ¶ added in v0.5.2
func GetSystemAVInfo(data unsafe.Pointer) SystemAVInfo
GetSystemAVInfo is an environment callback helper that returns the game geometry in EnvironmentSetGeometry.
type SystemInfo ¶
type SystemInfo struct { LibraryName string LibraryVersion string ValidExtensions string NeedFullpath bool BlockExtract bool }
SystemInfo stores informations about the emulated system
type SystemTiming ¶
SystemTiming stores informations about the timing of the emulated system
type Variable ¶
type Variable C.struct_retro_variable
Variable is a key value pair that represents a core option
func GetVariable ¶
GetVariable is an environment callback helper that returns a Variable
func GetVariables ¶
GetVariables is an environment callback helper that returns the list of Variable needed by a core
func (*Variable) DefaultValue ¶ added in v0.12.3
DefaultValue returns the default value of a Variable