libretro.drivers.environment.driver

Protocol definition for the retro_environment_t dispatcher.

See also

libretro.api.environment

The matching ctypes types and callback definitions.

Classes

EnvironmentDriver

Protocol for the dispatcher that handles libretro environment calls and AV callbacks.

class EnvironmentDriver[source]

Bases: Protocol

Protocol for the dispatcher that handles libretro environment calls and AV callbacks.

Acts as the single entry point libretro.py registers with the core via Core.set_environment(), Core.set_video_refresh(), etc.

See also

libretro.api.environment

The matching ctypes types and callback definitions.

abstractmethod environment(cmd, data)[source]

Dispatch an environment call from the core.

Implementations route cmd to the appropriate _<env_call_name> helper (e.g. _get_variable for RETRO_ENVIRONMENT_GET_VARIABLE) and return True if the call was handled successfully.

Parameters:
  • cmd (int) – The RETRO_ENVIRONMENT_* command identifier.

  • data (c_void_ptr) – Pointer to the command-specific data buffer, interpreted according to cmd.

Return type:

bool

Returns:

True if the call was handled, False if the command is unsupported or failed.

See also

retro_environment_t

The C function pointer type whose signature this method implements.

abstractmethod video_refresh(data, width, height, pitch)[source]

Receive one frame of video output from the core.

Parameters:
  • data (c_void_ptr) – Pointer to the frame buffer in the core’s current pixel format, or None if the core asked the frontend to duplicate the previous frame.

  • width (int) – Width of the frame in pixels.

  • height (int) – Height of the frame in pixels.

  • pitch (int) – Number of bytes per scanline in data.

See also

retro_video_refresh_t

The C function pointer type whose signature this method implements.

Return type:

None

abstractmethod audio_sample(left, right)[source]

Receive a single stereo audio sample from the core.

Parameters:
  • left (int) – The left-channel sample as a signed 16-bit integer.

  • right (int) – The right-channel sample as a signed 16-bit integer.

See also

retro_audio_sample_t

The C function pointer type whose signature this method implements.

Return type:

None

abstractmethod audio_sample_batch(data, frames)[source]

Receive a batch of interleaved stereo audio frames from the core.

Parameters:
  • data (LP_c_short) – Pointer to interleaved signed 16-bit stereo samples.

  • frames (int) – Number of stereo frames available in data.

Return type:

int

Returns:

The number of frames consumed.

See also

retro_audio_sample_batch_t

The C function pointer type whose signature this method implements.

abstractmethod input_poll()[source]

Poll input devices for new input state.

Called by the core once per frame before any input_state() queries.

See also

retro_input_poll_t

The C function pointer type whose signature this method implements.

Return type:

None

abstractmethod input_state(port, device, index, id)[source]

Return the current input state for a given device control.

Parameters:
  • port (Port (int)) – The input port being queried.

  • device (int) – The RETRO_DEVICE_* device class.

  • index (int) – The sub-device index (e.g. analog stick number).

  • id (int) – The button or axis identifier within the device class.

Return type:

int

Returns:

The control’s current state, encoded per libretro’s input conventions.

See also

retro_input_state_t

The C function pointer type whose signature this method implements.

static return_on_raise(default)[source]

Ctypes doesn’t propagate exceptions out of callbacks, so this is necessary to detect an error in a driver instead of just swallowing it with a warning.

Return type:

Callable[[Callable[[ParamSpec(P)], TypeVar(T)]], Callable[[ParamSpec(P)], TypeVar(T)]]

__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)