libretro

package
v0.2.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2019 License: GPL-3.0 Imports: 5 Imported by: 0

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

View Source
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.

View Source
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.

View Source
const (
	EnvironmentGetUsername          = uint32(C.RETRO_ENVIRONMENT_GET_USERNAME)
	EnvironmentGetLogInterface      = uint32(C.RETRO_ENVIRONMENT_GET_LOG_INTERFACE)
	EnvironmentGetCanDupe           = uint32(C.RETRO_ENVIRONMENT_GET_CAN_DUPE)
	EnvironmentSetPixelFormat       = uint32(C.RETRO_ENVIRONMENT_SET_PIXEL_FORMAT)
	EnvironmentGetSystemDirectory   = uint32(C.RETRO_ENVIRONMENT_GET_SYSTEM_DIRECTORY)
	EnvironmentGetSaveDirectory     = uint32(C.RETRO_ENVIRONMENT_GET_SAVE_DIRECTORY)
	EnvironmentShutdown             = uint32(C.RETRO_ENVIRONMENT_SHUTDOWN)
	EnvironmentGetVariable          = uint32(C.RETRO_ENVIRONMENT_GET_VARIABLE)
	EnvironmentSetVariables         = uint32(C.RETRO_ENVIRONMENT_SET_VARIABLES)
	EnvironmentGetVariableUpdate    = uint32(C.RETRO_ENVIRONMENT_GET_VARIABLE_UPDATE)
	EnvironmentGetPerfInterface     = uint32(C.RETRO_ENVIRONMENT_GET_PERF_INTERFACE)
	EnvironmentSetFrameTimeCallback = uint32(C.RETRO_ENVIRONMENT_SET_FRAME_TIME_CALLBACK)
	EnvironmentSetAudioCallback     = uint32(C.RETRO_ENVIRONMENT_SET_AUDIO_CALLBACK)
)

Environment callback API. See libretro.h for details

View Source
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

View Source
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

View Source
const DeviceJoypad = uint32(C.RETRO_DEVICE_JOYPAD)

DeviceJoypad represents the RetroPad. It is essentially a Super Nintendo controller, but with additional L2/R2/L3/R3 buttons, similar to a PS1 DualShock.

Variables

This section is empty.

Functions

func DlOpen

func DlOpen(path string) (unsafe.Pointer, error)

DlOpen opens a dynamic library

func GetPixelFormat

func GetPixelFormat(data unsafe.Pointer) uint32

GetPixelFormat is an environment callback helper that returns the pixel format. Should be used in the case of EnvironmentSetPixelFormat

func SetBool

func SetBool(data unsafe.Pointer, val bool)

SetBool is an environment callback helper to set a boolean

func SetString

func SetString(data unsafe.Pointer, val string)

SetString is an environment callback helper to set a string

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
	// contains filtered or unexported fields
}

Core is an instance of a dynalically loaded libretro core

func Load

func Load(sofile string) (*Core, error)

Load dynamically loads a libretro core at the given path and returns a Core instance

func (*Core) APIVersion

func (core *Core) APIVersion() uint

APIVersion returns the RETRO_API_VERSION. Used to validate ABI compatibility when the API is revised.

func (*Core) BindLogCallback

func (core *Core) BindLogCallback(data unsafe.Pointer, f logFunc)

BindLogCallback binds f to the log callback

func (*Core) BindPerfCallback

func (core *Core) BindPerfCallback(data unsafe.Pointer, f getTimeUsecFunc)

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) DlSym

func (core *Core) DlSym(name string) unsafe.Pointer

DlSym loads a symbol from a dynamic library

func (*Core) GetMemoryData added in v0.2.0

func (core *Core) GetMemoryData(id uint32) unsafe.Pointer

GetMemoryData returns the size of a region of the memory. See memory constants.

func (*Core) GetMemorySize added in v0.2.0

func (core *Core) GetMemorySize(id uint32) uint

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) Init

func (core *Core) Init()

Init takes care of the library global initialization

func (*Core) LoadGame

func (core *Core) LoadGame(gi GameInfo) bool

LoadGame loads a game

func (*Core) Reset

func (core *Core) Reset()

Reset resets the current game.

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) Serialize

func (core *Core) Serialize(size uint) ([]byte, error)

Serialize serializes internal state and returns the state as a byte slice.

func (*Core) SerializeSize

func (core *Core) SerializeSize() uint

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

func (core *Core) SetAudioCallback(data unsafe.Pointer)

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) 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

func (core *Core) SetFrameTimeCallback(data unsafe.Pointer)

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

func (*Core) UnloadGame

func (core *Core) UnloadGame()

UnloadGame unloads a currently loaded game

func (*Core) Unserialize

func (core *Core) Unserialize(bytes []byte, size uint) error

Unserialize unserializes internal state from a byte slice.

type FrameTimeCallback

type FrameTimeCallback struct {
	Callback  func(int64)
	Reference int64
}

FrameTimeCallback stores the frame time callback itself and the reference time

type GameGeometry

type GameGeometry struct {
	AspectRatio float64
	BaseWidth   int
	BaseHeight  int
}

GameGeometry represents the geometry of a game, with its aspect ratio, with and height

type GameInfo

type GameInfo struct {
	Path string
	Size int64
	Data unsafe.Pointer
}

GameInfo stores information about a ROM

func (*GameInfo) SetData

func (gi *GameInfo) SetData(bytes []byte)

SetData is a setter for the data of a GameInfo type

type SystemAVInfo

type SystemAVInfo struct {
	Geometry GameGeometry
	Timing   SystemTiming
}

SystemAVInfo stores informations about the emulated system audio and video

type SystemInfo

type SystemInfo struct {
	LibraryName     string
	LibraryVersion  string
	ValidExtensions string
	NeedFullpath    bool
	BlockExtract    bool
}

SystemInfo stores informations about the emulated system

type SystemTiming

type SystemTiming struct {
	FPS        float64
	SampleRate float64
}

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

func GetVariable(data unsafe.Pointer) *Variable

GetVariable is an environment callback helper that returns a Variable

func GetVariables

func GetVariables(data unsafe.Pointer) []Variable

GetVariables is an environment callback helper that returns the list of Variables needed by a core

func (*Variable) Choices

func (v *Variable) Choices() []string

Choices returns the list of possible choices for a given Variable

func (*Variable) Desc

func (v *Variable) Desc() string

Desc returns the description of a Variable as a string

func (*Variable) Key

func (v *Variable) Key() string

Key returns the key of a Variable as a string

func (*Variable) SetValue

func (v *Variable) SetValue(val string)

SetValue sets the value of a Variable

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL