libretro.core¶
Thin ctypes wrapper around a libretro core’s exported retro_* functions.
See also
libretro.apiThe Python equivalents of the C types passed across this boundary.
libretro.sessionThe high-level harness that orchestrates calls into a
Core.
Classes
A thin wrapper around a libretro core that can be used to call its public interface. |
|
An interface for a libretro core. |
- class CoreInterface[source]¶
Bases:
ProtocolAn interface for a libretro core.
- abstractmethod set_environment(env)[source]¶
Call the core’s
retro_set_environmentfunction with the given callback.- Return type:
- abstractmethod set_video_refresh(video)[source]¶
Call the core’s
retro_set_video_refreshfunction with the given callback.- Return type:
- abstractmethod set_audio_sample(audio)[source]¶
Call the core’s
retro_set_audio_samplefunction with the given callback.- Return type:
- abstractmethod set_audio_sample_batch(audio)[source]¶
Call the core’s
retro_set_audio_sample_batchfunction with the given callback.- Return type:
- abstractmethod set_input_poll(poll)[source]¶
Call the core’s
retro_set_input_pollfunction with the given callback.- Return type:
- abstractmethod set_input_state(state)[source]¶
Call the core’s
retro_set_input_statefunction with the given callback.- Return type:
- abstractmethod api_version()[source]¶
Call the core’s
retro_api_versionfunction and return the result.- Return type:
- abstractmethod get_system_info()[source]¶
Call the core’s
retro_get_system_infofunction and return the result.- Return type:
- abstractmethod get_system_av_info()[source]¶
Call the core’s
retro_get_system_av_infofunction and return the result.- Return type:
- abstractmethod set_controller_port_device(port, device)[source]¶
Call the core’s
retro_set_controller_port_devicefunction with the given arguments.- Return type:
- abstractmethod run()[source]¶
Call the core’s
retro_runfunction to advance the core by one frame.- Return type:
- abstractmethod serialize_size()[source]¶
Call the core’s
retro_serialize_sizefunction and return the result.- Return type:
- abstractmethod serialize(data)[source]¶
Call the core’s
retro_serializefunction with the given mutable buffer.- Return type:
- abstractmethod unserialize(data)[source]¶
Call the core’s
retro_unserializefunction with the given buffer.- Return type:
- abstractmethod cheat_set(index, enabled, code)[source]¶
Call the core’s
retro_cheat_setfunction with the given arguments.- Return type:
- abstractmethod load_game(game)[source]¶
Call the core’s
retro_load_gamefunction with the given game info.- Return type:
- abstractmethod load_game_special(game_type, info)[source]¶
Call the core’s
retro_load_game_specialfunction with the given arguments.- Return type:
- abstractmethod get_region()[source]¶
Call the core’s
retro_get_regionfunction and return the result.
- abstractmethod get_memory_data(id)[source]¶
Call the core’s
retro_get_memory_datafunction for the given memory region.- Return type:
- abstractmethod get_memory_size(id)[source]¶
Call the core’s
retro_get_memory_sizefunction for the given memory region.- Return type:
- get_memory(id)[source]¶
Get a writable
memoryviewof the memory region given byid.Convenience wrapper around
get_memory_data()andget_memory_size().- Parameters:
id (
int) – The ID of the memory region to access.- Return type:
- Returns:
A writable
memoryviewof the given region, orNoneifretro_get_memory_datareturnedNULL.
- __init__(*args, **kwargs)¶
- classmethod __new__(*args, **kwargs)¶
- class Core[source]¶
Bases:
CoreInterfaceA thin wrapper around a libretro core that can be used to call its public interface.
Does not manage the underlying core’s life cycle, i.e.
retro_*methods are not called implicitly unless otherwise noted; that’s left toSessionor some custom abstraction layer.- __init__(core)[source]¶
Create a new
Coreinstance.- Parameters:
core (
CDLL|PathLike[str] |PathLike[bytes] |str) –The core to wrap. Can be one of the following:
A
strorPathLikerepresenting the path to the core’s shared library.A
CDLLrepresenting the core’s shared library.
- Raises:
ValueError – If the core does not define all the required functions (i.e. the
retro_*function that each method corresponds to).TypeError – If
coreis not one of the above-mentioned types.
- set_environment(env)[source]¶
Call the core’s
retro_set_environmentfunction with the given callback.
- set_video_refresh(video)[source]¶
Call the core’s
retro_set_video_refreshfunction with the given callback.
- set_audio_sample(audio)[source]¶
Call the core’s
retro_set_audio_samplefunction with the given callback.
- set_audio_sample_batch(audio)[source]¶
Call the core’s
retro_set_audio_sample_batchfunction with the given callback.
- set_input_poll(poll)[source]¶
Call the core’s
retro_set_input_pollfunction with the given callback.
- set_input_state(state)[source]¶
Call the core’s
retro_set_input_statefunction with the given callback.
- init()[source]¶
Call the core’s
retro_initfunction.- Note:
This method does not check if the core has already been initialized. Additionally, this method is not implicitly called by
__init__.
- deinit()[source]¶
Call the core’s
retro_deinitfunction.- Note:
This method does not validate that the core has been initialized. Additionally, it is not implicitly called upon deletion.
- api_version()[source]¶
Call the core’s
retro_api_versionfunction.- Return type:
- Returns:
The integer returned by the core’s implementation of
retro_api_version.- Warning:
This method does not validate the returned version number.
- get_system_info()[source]¶
Call the core’s
retro_get_system_infofunction.- Return type:
- Returns:
A
retro_system_infoinstance containing information about the core. All strings are copied and may be accessed even after unloading the core.
- get_system_av_info()[source]¶
Call the core’s
retro_get_system_av_infofunction.- Return type:
- Returns:
A
retro_system_av_infoinstance containing information about the core’s audiovisual capabilities. It may be accessed even after unloading the core.
- set_controller_port_device(port, device)[source]¶
Call the core’s
retro_set_controller_port_devicefunction with the given arguments.
- reset()[source]¶
Call the core’s
retro_resetfunction.- Warning:
Does not check if the core is in a state where it can be reset.
- run()[source]¶
Call the core’s
retro_runfunction.- Warning:
Does not check if the core is in a state where it can be run.
- serialize_size()[source]¶
Call the core’s
retro_serialize_sizefunction.- Return type:
- Returns:
The length of the buffer needed to serialize the core’s state, in bytes. If zero, the core does not support serialization.
- serialize(data)[source]¶
Call the core’s
retro_serializefunction with the given mutable buffer.Fills
datawith whatever serialized state the core returns.- Parameters:
data (
bytearray|memoryview[int] |Buffer) – Abytearray, mutablememoryview, orBufferimplementation that core’s serialized state will be saved to.- Return type:
- Returns:
Trueif the core successfully serialized its state,Falseotherwise.- Raises:
TypeError – If
datais not one of the aforementioned types.ValueError – If
datais a read-onlymemoryvieworBuffer.
- Note:
The buffer must be at least as large as the last value returned by
serialize_size, or else the serialized data will be incomplete.
- unserialize(data)[source]¶
Call the core’s
retro_unserializefunction with the given buffer.Restores the core’s state from the serialized data in
data.
- cheat_set(index, enabled, code)[source]¶
Call the core’s
retro_cheat_setfunction with the given arguments.- Parameters:
- Raises:
TypeError – If any parameter’s value is inconsistent with its documented type.
ValueError – If
codedoes not contain a null terminator (i.e. the value 0).
- load_game(game)[source]¶
Call the core’s
retro_load_gamefunction with the given game info.- Parameters:
game (
retro_game_info|None) – Aretro_game_infoinstance orNone.- Return type:
- Returns:
Trueif the core successfully loadedgame,Falseotherwise.- Raises:
TypeError – If
gameis not aretro_game_infoorNone.- Warning:
This method does not validate any preconditions documented in libretro.h, e.g. it’s possible to pass
Noneeven if the core doesn’t support no-content mode.
- load_game_special(game_type, info)[source]¶
Call the core’s
retro_load_game_specialfunction with the given arguments.- Parameters:
game_type (
int|retro_subsystem_info) – The subsystem type to activate. May be passed as anintor aretro_subsystem_infoinstance.info (
Sequence[retro_game_info] |Array[retro_game_info]) – ASequenceorctypes.Arrayofretro_game_infoinstances.
- Return type:
- Returns:
Trueif the core successfully loaded the game,Falseif not.- Raises:
TypeError – If any parameter’s value is inconsistent with its documented type.
- Warning:
This method does not validate any preconditions documented in libretro.h, e.g. it’s possible to use this method even if the core doesn’t define subsystems.
- unload_game()[source]¶
Call the core’s
retro_unload_gamefunction.- Warning:
Does not check if the preconditions for
retro_unload_gameare met, e.g. it doesn’t check if a game is currently loaded.
- get_memory_data(id)[source]¶
Call the core’s
retro_get_memory_datafunction for the given memory region.
- get_memory_size(id)[source]¶
Call the core’s
retro_get_memory_sizefunction for the given memory region.
- property path¶
The path to the core’s shared library.
- classmethod __new__(*args, **kwargs)¶
- get_memory(id)¶
Get a writable
memoryviewof the memory region given byid.Convenience wrapper around
get_memory_data()andget_memory_size().- Parameters:
id (
int) – The ID of the memory region to access.- Return type:
- Returns:
A writable
memoryviewof the given region, orNoneifretro_get_memory_datareturnedNULL.