![]() |
libdragon
|
Joypad abstraction interface. More...
Files | |
file | joypad.c |
Joypad Subsystem. | |
file | joypad_accessory.c |
Joypad accessory helpers. | |
file | joypad_accessory.h |
Joypad accessory helpers. | |
file | joypad_internal.h |
Joypad internal. | |
file | joypad.h |
Joypad Subsystem. | |
Data Structures | |
struct | joypad_accessory_io_t |
Joypad Accessory I/O operation state. More... | |
struct | joypad_transfer_pak_io_t |
Joypad N64 Transfer Pak I/O operation state. More... | |
struct | joypad_accessory_t |
Joypad accessory structure. More... | |
struct | joypad_gcn_origin_t |
Joypad GameCube controller origins structure. More... | |
struct | joypad_device_cold_t |
"Cold" (non-volatile) Joypad device structure. More... | |
struct | joypad_device_hot_t |
"Hot" (interrupt-driven) Joypad device structure. More... | |
union | joypad_buttons_t |
Joypad Buttons. More... | |
struct | joypad_inputs_t |
Joypad Inputs Unified State Structure. More... | |
Macros | |
#define | JOYPAD_IDENTIFY_INTERVAL_TICKS TICKS_PER_SECOND |
Number of ticks between Joybus identify commands. | |
#define | ASSERT_JOYPAD_INITIALIZED() assertf(joypad_init_refcount > 0, "joypad_init() was not called") |
Convenience macro to ensure Joypad subsystem is initialized. | |
#define | BB_HACK_FLAGS_SWAP_PORT1 ((*(uint32_t *)0x8000038c) & 3) |
BBPlayer "Hack Flags" register value. | |
#define | JOYPAD_ACCESSORY_RETRY_LIMIT 2 |
Number of times to retry accessory commands. | |
#define | joypad_accessory_state_is_detecting(state) |
Is Joypad accessory currently in detection state? | |
#define | joypad_accessory_state_is_transfer_enabling(state) |
Is Joypad accessory currently in Transfer Pak enabling state? | |
#define | joypad_accessory_state_is_transfer_loading(state) |
Is Joypad accessory currently in Transfer Pak loading state? | |
#define | joypad_accessory_state_is_transfer_storing(state) |
Is Joypad accessory currently in Transfer Pak storing state? | |
#define | JOYPAD_CONTROLLER_PAK_BANK_SWITCH_ADDRESS 0x8000 |
Controller pak address to perform bank switching. | |
#define | ASSERT_JOYPAD_PORT_VALID(port) assert((port) >= 0 && (port) < JOYPAD_PORT_COUNT) |
Convenience macro to validate a Joypad port number. | |
#define | JOYPAD_GCN_ORIGIN_INIT ((joypad_gcn_origin_t){ 127, 127, 127, 127, 0, 0 }) |
Initial state for GameCube controller origins. | |
#define | CLAMP_ANALOG_STICK(value) CLAMP((int)(value), -127, 127) |
Ensure value is in range of an analog stick axis. | |
#define | CLAMP_ANALOG_TRIGGER(value) CLAMP((int)(value), 0, 255) |
Ensure value is in range of an analog trigger. | |
#define | JOYPAD_PORT_COUNT 4 |
Count of Joypad ports. | |
#define | JOYPAD_PORT_FOREACH(iterator_token) |
Convenience macro to iterate through all Joypad ports. | |
Typedefs | |
typedef void(* | joypad_accessory_io_callback_t) (joypad_accessory_error_t error, void *ctx) |
Callback function signature for joypad_accessory_xfer_async. | |
Enumerations | |
enum | joypad_accessory_state_t { JOYPAD_ACCESSORY_STATE_IDLE = 0 , JOYPAD_ACCESSORY_STATE_DETECT_INIT , JOYPAD_ACCESSORY_STATE_DETECT_CPAK_BANK_WRITE , JOYPAD_ACCESSORY_STATE_DETECT_CPAK_LABEL_BACKUP , JOYPAD_ACCESSORY_STATE_DETECT_CPAK_LABEL_WRITE , JOYPAD_ACCESSORY_STATE_DETECT_CPAK_LABEL_READ , JOYPAD_ACCESSORY_STATE_DETECT_CPAK_LABEL_RESTORE , JOYPAD_ACCESSORY_STATE_DETECT_RUMBLE_PROBE_WRITE , JOYPAD_ACCESSORY_STATE_DETECT_RUMBLE_PROBE_READ , JOYPAD_ACCESSORY_STATE_DETECT_TRANSFER_PROBE_ON , JOYPAD_ACCESSORY_STATE_DETECT_TRANSFER_PROBE_READ , JOYPAD_ACCESSORY_STATE_DETECT_TRANSFER_PROBE_OFF , JOYPAD_ACCESSORY_STATE_DETECT_SNAP_PROBE_WRITE , JOYPAD_ACCESSORY_STATE_DETECT_SNAP_PROBE_READ , JOYPAD_ACCESSORY_STATE_READ , JOYPAD_ACCESSORY_STATE_WRITE , JOYPAD_ACCESSORY_STATE_RUMBLE_WRITE , JOYPAD_ACCESSORY_STATE_TRANSFER_ENABLE_PROBE_WRITE , JOYPAD_ACCESSORY_STATE_TRANSFER_ENABLE_PROBE_WAIT , JOYPAD_ACCESSORY_STATE_TRANSFER_ENABLE_STATUS_WRITE , JOYPAD_ACCESSORY_STATE_TRANSFER_ENABLE_STATUS_WAIT , JOYPAD_ACCESSORY_STATE_TRANSFER_ENABLE_STATUS_READ , JOYPAD_ACCESSORY_STATE_TRANSFER_LOAD_STATUS_READ , JOYPAD_ACCESSORY_STATE_TRANSFER_LOAD_BANK_WRITE , JOYPAD_ACCESSORY_STATE_TRANSFER_LOAD_DATA_READ , JOYPAD_ACCESSORY_STATE_TRANSFER_STORE_STATUS_READ , JOYPAD_ACCESSORY_STATE_TRANSFER_STORE_BANK_WRITE , JOYPAD_ACCESSORY_STATE_TRANSFER_STORE_DATA_WRITE } |
Joypad accessory states enumeration. | |
enum | joypad_accessory_error_t { JOYPAD_ACCESSORY_ERROR_PENDING = -1 , JOYPAD_ACCESSORY_ERROR_NONE = 0 , JOYPAD_ACCESSORY_ERROR_ABSENT , JOYPAD_ACCESSORY_ERROR_CHECKSUM , JOYPAD_ACCESSORY_ERROR_TRANSFER_PAK_STATUS_CHANGE , JOYPAD_ACCESSORY_ERROR_UNKNOWN } |
Joypad accessory error codes. More... | |
enum | joypad_accessory_xfer_t { JOYPAD_ACCESSORY_XFER_READ , JOYPAD_ACCESSORY_XFER_WRITE } |
Type of transfer performed by joypad_accessory_xfer_async. More... | |
enum | joypad_rumble_method_t { JOYPAD_RUMBLE_METHOD_NONE = 0 , JOYPAD_RUMBLE_METHOD_N64_RUMBLE_PAK , JOYPAD_RUMBLE_METHOD_GCN_CONTROLLER } |
Joypad rumble methods enumeration. More... | |
enum | joypad_port_t { JOYPAD_PORT_1 = 0 , JOYPAD_PORT_2 = 1 , JOYPAD_PORT_3 = 2 , JOYPAD_PORT_4 = 3 } |
Joypad Port Numbers. More... | |
enum | joypad_style_t { JOYPAD_STYLE_NONE = 0 , JOYPAD_STYLE_N64 , JOYPAD_STYLE_GCN , JOYPAD_STYLE_MOUSE } |
Joypad Styles enumeration. More... | |
enum | joypad_accessory_type_t { JOYPAD_ACCESSORY_TYPE_NONE = 0 , JOYPAD_ACCESSORY_TYPE_UNKNOWN , JOYPAD_ACCESSORY_TYPE_CONTROLLER_PAK , JOYPAD_ACCESSORY_TYPE_RUMBLE_PAK , JOYPAD_ACCESSORY_TYPE_TRANSFER_PAK , JOYPAD_ACCESSORY_TYPE_BIO_SENSOR , JOYPAD_ACCESSORY_TYPE_SNAP_STATION } |
Joypad Accessories enumeration. More... | |
enum | joypad_axis_t { JOYPAD_AXIS_STICK_X = offsetof(joypad_inputs_t, stick_x) , JOYPAD_AXIS_STICK_Y = offsetof(joypad_inputs_t, stick_y) , JOYPAD_AXIS_CSTICK_X = offsetof(joypad_inputs_t, cstick_x) , JOYPAD_AXIS_CSTICK_Y = offsetof(joypad_inputs_t, cstick_y) , JOYPAD_AXIS_ANALOG_L = offsetof(joypad_inputs_t, analog_l) , JOYPAD_AXIS_ANALOG_R = offsetof(joypad_inputs_t, analog_r) } |
Joypad Axis enumeration values. More... | |
enum | joypad_2d_t { JOYPAD_2D_STICK = (1 << 0) , JOYPAD_2D_DPAD = (1 << 1) , JOYPAD_2D_C = (1 << 2) , JOYPAD_2D_LH = (JOYPAD_2D_STICK | JOYPAD_2D_DPAD) , JOYPAD_2D_RH = (JOYPAD_2D_STICK | JOYPAD_2D_C) , JOYPAD_2D_ANY = (JOYPAD_2D_STICK | JOYPAD_2D_DPAD | JOYPAD_2D_C) } |
Joypad 2D axes enumeration. More... | |
enum | joypad_8way_t { JOYPAD_8WAY_NONE = -1 , JOYPAD_8WAY_RIGHT = 0 , JOYPAD_8WAY_UP_RIGHT = 1 , JOYPAD_8WAY_UP = 2 , JOYPAD_8WAY_UP_LEFT = 3 , JOYPAD_8WAY_LEFT = 4 , JOYPAD_8WAY_DOWN_LEFT = 5 , JOYPAD_8WAY_DOWN = 6 , JOYPAD_8WAY_DOWN_RIGHT = 7 } |
Joypad 8-way directional enumeration. More... | |
Functions | |
joypad_inputs_t | joypad_read_n64_inputs (joypad_port_t port) |
Read the inputs from a Nintendo 64 controller synchronously. | |
void | joypad_init (void) |
Initialize the Joypad subsystem. | |
void | joypad_close (void) |
Close the Joypad subsystem. | |
void | joypad_poll (void) |
Fetch the current Joypad input state. | |
bool | joypad_is_connected (joypad_port_t port) |
Whether a Joybus device is plugged in to a Joypad port. | |
joybus_identifier_t | joypad_get_identifier (joypad_port_t port) |
Get the Joybus device identifier for a Joypad port. | |
joypad_style_t | joypad_get_style (joypad_port_t port) |
Get the Joypad style for a Joypad port. | |
joypad_accessory_type_t | joypad_get_accessory_type (joypad_port_t port) |
Get the Joypad accessory type for a Joypad port. | |
int | joypad_get_accessory_state (joypad_port_t port) |
Get the Joypad accessory state for a Joypad port. | |
int | joypad_get_accessory_error (joypad_port_t port) |
Get the Joypad accessory error for a Joypad port. | |
uint8_t | joypad_get_transfer_pak_status (joypad_port_t port) |
Get the Transfer Pak status byte for a Joypad port. | |
bool | joypad_get_rumble_supported (joypad_port_t port) |
Is rumble supported for a Joypad port? | |
bool | joypad_get_rumble_active (joypad_port_t port) |
Is rumble active for a Joypad port? | |
void | joypad_set_rumble_active (joypad_port_t port, bool active) |
Activate or deactivate rumble on a Joypad port. | |
joypad_inputs_t | joypad_get_inputs (joypad_port_t port) |
Get the current Joypad inputs state for a Joypad port. | |
joypad_buttons_t | joypad_get_buttons (joypad_port_t port) |
Get the current Joypad buttons state for a Joypad port. | |
joypad_buttons_t | joypad_get_buttons_pressed (joypad_port_t port) |
Get the Joypad buttons that were pressed since the last time Joypads were read for a Joypad port. | |
joypad_buttons_t | joypad_get_buttons_released (joypad_port_t port) |
Get the Joypad buttons that were released since the last time Joypads were read for a Joypad port. | |
joypad_buttons_t | joypad_get_buttons_held (joypad_port_t port) |
Get the Joypad buttons that are held down since the last time Joypads were read for a Joypad port. | |
int | joypad_get_axis_pressed (joypad_port_t port, joypad_axis_t axis) |
Get the direction of a "press" of an axis on a Joypad port. | |
int | joypad_get_axis_released (joypad_port_t port, joypad_axis_t axis) |
Get the direction of a "release" of an axis on a Joypad port. | |
int | joypad_get_axis_held (joypad_port_t port, joypad_axis_t axis) |
Get the direction that an axis is held on a Joypad port. | |
joypad_8way_t | joypad_get_direction (joypad_port_t port, joypad_2d_t axes) |
Get the 8-way direction for a Joypad port's directional axes. | |
void | joypad_accessory_reset (joypad_port_t port) |
Reset the accessory state for a Joypad port. | |
void | joypad_transfer_pak_wait_timer_init (joypad_port_t port) |
Initialize the Transfer Pak wait timer if necessary. | |
void | joypad_accessory_detect_async (joypad_port_t port) |
Detect which accessory is inserted in an N64 controller. | |
void | joypad_rumble_pak_toggle_async (joypad_port_t port, bool active) |
Turn the Rumble Pak motor on or off for a Joypad port. | |
void | joypad_accessory_xfer_async (joypad_port_t port, joypad_accessory_xfer_t xfer, uint16_t start_addr, void *dst, size_t len, joypad_accessory_io_callback_t callback, void *ctx) |
Read or write data from a Joypad accessory asynchronously. | |
joypad_accessory_error_t | joypad_accessory_xfer (joypad_port_t port, joypad_accessory_xfer_t xfer, uint16_t start_addr, void *dst, size_t len) |
Read or write data from a joypad accessory. | |
joypad_accessory_error_t | joypad_controller_pak_set_bank (joypad_port_t port, uint8_t bank) |
Select the active bank for a Controller Pak. | |
void | joypad_transfer_pak_enable_async (joypad_port_t port, bool enabled) |
Enable or disable the Transfer Pak for a Joypad port. | |
void | joypad_transfer_pak_load_async (joypad_port_t port, uint16_t cart_addr, void *dst, size_t len) |
Load data from the GB cartridge inserted in a Transfer Pak. | |
void | joypad_transfer_pak_store_async (joypad_port_t port, uint16_t cart_addr, void *src, size_t len) |
Store data on the GB cartridge inserted in a Transfer Pak. | |
Variables | |
volatile joybus_identifier_t | joypad_identifiers_hot [JOYPAD_PORT_COUNT] |
Joypad identifiers for each port. | |
volatile joypad_device_hot_t | joypad_devices_hot [JOYPAD_PORT_COUNT] |
Joypad "hot" devices for each port. | |
volatile joypad_gcn_origin_t | joypad_origins_hot [JOYPAD_PORT_COUNT] |
Joypad origins for each port. | |
volatile joypad_accessory_t | joypad_accessories_hot [JOYPAD_PORT_COUNT] |
Joypad accessories for each port. | |
"Hot" (interrupt-driven) global state | |
volatile joybus_identifier_t | joypad_identifiers_hot [JOYPAD_PORT_COUNT] = {0} |
Joypad identifiers for each port. | |
volatile joypad_device_hot_t | joypad_devices_hot [JOYPAD_PORT_COUNT] = {0} |
Joypad "hot" devices for each port. | |
volatile joypad_gcn_origin_t | joypad_origins_hot [JOYPAD_PORT_COUNT] = {0} |
Joypad origins for each port. | |
volatile joypad_accessory_t | joypad_accessories_hot [JOYPAD_PORT_COUNT] = {0} |
Joypad accessories for each port. | |
Joypad abstraction interface.
The Joypad subsystem is in charge of communication with the controller ports and provides a common interface to support a variety of input devices:
To use a Joypad, the developer must first call joypad_init. Once initialized, The Joypad subsystem will automatically identify and read all connected input devices once per frame.
To refer to individual ports, use the joypad_port_t enumeration values. To iterate across all ports, use the JOYPAD_PORT_FOREACH macro.
To read the controllers, first call joypad_poll once per frame to process the input data. joypad_get_style will return which "style" of device is connected to a port (joypad_style_t). joypad_get_inputs will return the buttons and analog input state for a given controller port.
Developers can determine whether the input device is capable of rumble by calling joypad_get_rumble_supported and then starting/stopping the rumble motor by calling joypad_set_rumble_active.
The Joypad subsystem will automatically detect which accessory is connected to Nintendo 64 controllers. Call joypad_get_accessory_type to determine which accessory was detected.
For advanced use-cases, a developer can determine exactly which type of input device is connected by calling joypad_get_identifier, which will return the 16-bit device identifier value from the Joybus "Info" response.
To read digital button state for a Joypad device:
To read 8-way directional state for a Joypad device:
To read analog directions as digital inputs for a Joypad device:
struct joypad_accessory_io_t |
Joypad Accessory I/O operation state.
Data Fields | ||
---|---|---|
uint8_t * | start | |
uint8_t * | end | |
uint8_t * | cursor | |
uint16_t | cart_addr | |
joypad_accessory_io_callback_t | callback | |
void * | ctx |
struct joypad_transfer_pak_io_t |
struct joypad_accessory_t |
Joypad accessory structure.
Data Fields | ||
---|---|---|
uint8_t | status | |
joypad_accessory_type_t | type | |
joypad_accessory_state_t | state | |
joypad_accessory_error_t | error | |
unsigned | retries | |
uint8_t | cpak_label_backup[JOYBUS_ACCESSORY_DATA_SIZE] | |
joypad_accessory_io_t | io | |
timer_link_t * | transfer_pak_wait_timer | |
joybus_transfer_pak_status_t | transfer_pak_status | |
joypad_transfer_pak_io_t | transfer_pak_io |
struct joypad_gcn_origin_t |
struct joypad_device_cold_t |
"Cold" (non-volatile) Joypad device structure.
Data Fields | ||
---|---|---|
joybus_identifier_t | identifier | Joybus device type identifier. |
joypad_style_t | style | Joypad style. |
joypad_inputs_t | current | Joypad inputs for current frame. |
joypad_inputs_t | previous | Joypad inputs for previous frame. |
struct joypad_device_hot_t |
"Hot" (interrupt-driven) Joypad device structure.
Data Fields | ||
---|---|---|
joypad_style_t | style | Joypad style. |
joypad_rumble_method_t | rumble_method | Joypad rumble method. |
bool | rumble_active | Is the Joypad currently rumbling? |
union joypad_buttons_t |
Joypad Buttons.
struct joypad_inputs_t |
Joypad Inputs Unified State Structure.
Data Fields | ||
---|---|---|
joypad_buttons_t | btn | Structure containing digital button inputs state. |
int8_t | stick_x |
Position of the analog joystick X axis. (-127, +127) On OEM N64 controllers with analog sticks in good condition, the range of this axis is roughly (-85, +85). On well-worn N64 controllers, the range may be as low as (-60, +60). On real GameCube controllers, the range is roughly (-100, +100). On startup, an N64 controller will report its current stick position as (0, 0). To reset the origin on an N64 controller, hold the L & R shoulder buttons and the start button for several seconds with the analog stick in a neutral position. For GameCube controllers, this value will be relative to its origin. The Joypad subsystem will automatically read the origins of GameCube controllers and account for them when resolving the analog inputs. To reset the origin on a GameCube controller, hold the X & Y buttons and the start button for several seconds with the analog inputs in neutral positions. |
int8_t | stick_y |
Position of the analog joystick Y axis. (-127, +127) On OEM N64 controllers with analog sticks in good condition, the range of this axis is roughly (-85, +85). On well-worn N64 controllers, the range may be as low as (-60, +60). On real GameCube controllers, the range is roughly (-100, +100). On startup, an N64 controller will report its current stick position as (0, 0). To reset the origin on an N64 controller, hold the L & R shoulder buttons and the start button for several seconds with the analog stick in a neutral position. For GameCube controllers, this value will be relative to its origin. The Joypad subsystem will automatically read the origins of GameCube controllers and account for them when resolving the analog inputs. To reset the origin on a GameCube controller, hold the X & Y buttons and the start button for several seconds with the analog inputs in neutral positions. |
int8_t | cstick_x |
Position of the analog "C-Stick" X axis. (-127, +127) On real controllers, the range of this axis is roughly (-76, +76). For N64 controllers, this value will be emulated based on the digital C-Left and C-Right button values (-76=C-Left, +76=C-Right). For GameCube controllers, this value will be relative to its origin. The Joypad subsystem will automatically read the origins of GameCube controllers and account for them when resolving the analog inputs. To reset the origin on a GameCube controller, hold the X & Y buttons and the start button for several seconds with the analog inputs in neutral positions. |
int8_t | cstick_y |
Position of the analog "C-Stick" Y axis. (-127, +127) On real controllers, the range of this axis is roughly (-76, +76). For N64 controllers, this value will be emulated based on the digital C-Up and C-Down button values (-76=C-Down, +76=C-Up). For GameCube controllers, this value will be relative to its origin. The Joypad subsystem will automatically read the origins of GameCube controllers and account for them when resolving the analog inputs. To reset the origin on a GameCube controller, hold the X & Y buttons and the start button for several seconds with the analog inputs in neutral positions. |
uint8_t | analog_l |
Position of the analog L trigger. (0, 255) This value will be close to zero when no pressure is applied, and close to 200 when full pressure is applied. For N64 controllers, this value will be emulated based on the digital L trigger button value (0=unpressed, 200=pressed). For GameCube controllers, this value will be relative to its origin. The Joypad subsystem will automatically read the origins of GameCube controllers and account for them when resolving the analog inputs. To reset the origin on a GameCube controller, hold the X & Y buttons and the start button for several seconds with the analog inputs in neutral positions. |
uint8_t | analog_r |
Position of the analog R trigger. (0, 255) This value will be close to zero when no pressure is applied, and close to 200 when full pressure is applied. For N64 controllers, this value will be emulated based on the digital R trigger button value (0=unpressed, 200=pressed). For GameCube controllers, this value will be relative to its origin. The Joypad subsystem will automatically read the origins of GameCube controllers and account for them when resolving the analog inputs. To reset the origin on a GameCube controller, hold the X & Y buttons and the start button for several seconds with the analog inputs in neutral positions. |
#define JOYPAD_IDENTIFY_INTERVAL_TICKS TICKS_PER_SECOND |
Number of ticks between Joybus identify commands.
During VI interrupt, the Joypad subsystem will periodically re-identify the connected devices to check if the identifier has changed or if any accessories have been connected/disconnected.
#define BB_HACK_FLAGS_SWAP_PORT1 ((*(uint32_t *)0x8000038c) & 3) |
BBPlayer "Hack Flags" register value.
The only known purpose of this register is to hold the iQue menu configuration setting for swapping the first controller with another port.
The value of the register is the controller to swap with (0-indexed).
#define joypad_accessory_state_is_detecting | ( | state | ) |
Is Joypad accessory currently in detection state?
#define joypad_accessory_state_is_transfer_enabling | ( | state | ) |
Is Joypad accessory currently in Transfer Pak enabling state?
#define joypad_accessory_state_is_transfer_loading | ( | state | ) |
Is Joypad accessory currently in Transfer Pak loading state?
#define joypad_accessory_state_is_transfer_storing | ( | state | ) |
Is Joypad accessory currently in Transfer Pak storing state?
#define JOYPAD_PORT_FOREACH | ( | iterator_token | ) |
Convenience macro to iterate through all Joypad ports.
Joypad accessory error codes.
Type of transfer performed by joypad_accessory_xfer_async.
Enumerator | |
---|---|
JOYPAD_ACCESSORY_XFER_READ | Read operation. |
JOYPAD_ACCESSORY_XFER_WRITE | Write operation. |
enum joypad_port_t |
enum joypad_style_t |
Joypad Styles enumeration.
Joypad Accessories enumeration.
enum joypad_axis_t |
Joypad Axis enumeration values.
These values are used to index into the joypad_inputs_t structure.
enum joypad_2d_t |
Joypad 2D axes enumeration.
These values are used to select one or more 2D input axes.
enum joypad_8way_t |
Joypad 8-way directional enumeration.
joypad_inputs_t joypad_read_n64_inputs | ( | joypad_port_t | port | ) |
Read the inputs from a Nintendo 64 controller synchronously.
This function is intended for use in situations where interrupts may be disabled or where joypad_init may not have been called.
port | Joypad port (joypad_port_t) to read from. |
void joypad_init | ( | void | ) |
Initialize the Joypad subsystem.
Starts reading Joypads during VI interrupt.
void joypad_close | ( | void | ) |
Close the Joypad subsystem.
Stops reading Joypads during VI interrupt.
void joypad_poll | ( | void | ) |
Fetch the current Joypad input state.
This function must be called once per frame, or any time after the Joypads have been read. After calling this function, you can read the Joypad state using the following functions:
This function is very fast. In fact, joypads are read in background asynchronously under interrupt, so this function just synchronizes the internal state.
bool joypad_is_connected | ( | joypad_port_t | port | ) |
Whether a Joybus device is plugged in to a Joypad port.
port | Joypad port number (joypad_port_t) |
true | A Joybus device is connected to the Joypad port. |
false | Nothing is connected to the Joypad port. |
joybus_identifier_t joypad_get_identifier | ( | joypad_port_t | port | ) |
Get the Joybus device identifier for a Joypad port.
port | Joypad port number (joypad_port_t) |
joypad_style_t joypad_get_style | ( | joypad_port_t | port | ) |
Get the Joypad style for a Joypad port.
port | Joypad port number (joypad_port_t) |
joypad_accessory_type_t joypad_get_accessory_type | ( | joypad_port_t | port | ) |
Get the Joypad accessory type for a Joypad port.
port | Joypad port number (joypad_port_t) |
int joypad_get_accessory_state | ( | joypad_port_t | port | ) |
Get the Joypad accessory state for a Joypad port.
port | Joypad port number (joypad_port_t) |
int joypad_get_accessory_error | ( | joypad_port_t | port | ) |
Get the Joypad accessory error for a Joypad port.
port | Joypad port number (joypad_port_t) |
uint8_t joypad_get_transfer_pak_status | ( | joypad_port_t | port | ) |
Get the Transfer Pak status byte for a Joypad port.
port | Joypad port number (joypad_port_t) |
bool joypad_get_rumble_supported | ( | joypad_port_t | port | ) |
Is rumble supported for a Joypad port?
port | Joypad port number (joypad_port_t) |
bool joypad_get_rumble_active | ( | joypad_port_t | port | ) |
Is rumble active for a Joypad port?
port | Joypad port number (joypad_port_t) |
void joypad_set_rumble_active | ( | joypad_port_t | port, |
bool | active | ||
) |
Activate or deactivate rumble on a Joypad port.
port | Joypad port number (joypad_port_t) |
active | Whether rumble should be active |
joypad_inputs_t joypad_get_inputs | ( | joypad_port_t | port | ) |
Get the current Joypad inputs state for a Joypad port.
port | Joypad port number (joypad_port_t) |
joypad_buttons_t joypad_get_buttons | ( | joypad_port_t | port | ) |
Get the current Joypad buttons state for a Joypad port.
port | Joypad port number (joypad_port_t) |
joypad_buttons_t joypad_get_buttons_pressed | ( | joypad_port_t | port | ) |
Get the Joypad buttons that were pressed since the last time Joypads were read for a Joypad port.
port | Joypad port number (joypad_port_t) |
joypad_buttons_t joypad_get_buttons_released | ( | joypad_port_t | port | ) |
Get the Joypad buttons that were released since the last time Joypads were read for a Joypad port.
port | Joypad port number (joypad_port_t) |
joypad_buttons_t joypad_get_buttons_held | ( | joypad_port_t | port | ) |
Get the Joypad buttons that are held down since the last time Joypads were read for a Joypad port.
port | Joypad port number (joypad_port_t) |
int joypad_get_axis_pressed | ( | joypad_port_t | port, |
joypad_axis_t | axis | ||
) |
Get the direction of a "press" of an axis on a Joypad port.
port | Joypad port number (joypad_port_t) |
axis | Joypad axis enumeration value (joypad_axis_t) |
+1 | Axis is pressed in the positive direction |
-1 | Axis is pressed in the negative direction |
0 | Axis is not pressed |
int joypad_get_axis_released | ( | joypad_port_t | port, |
joypad_axis_t | axis | ||
) |
Get the direction of a "release" of an axis on a Joypad port.
port | Joypad port number (joypad_port_t) |
axis | Joypad axis enumeration value (joypad_axis_t) |
+1 | Axis was released in the positive direction |
-1 | Axis was released in the negative direction |
0 | Axis is not released |
int joypad_get_axis_held | ( | joypad_port_t | port, |
joypad_axis_t | axis | ||
) |
Get the direction that an axis is held on a Joypad port.
port | Joypad port number (joypad_port_t) |
axis | Joypad axis enumeration value (joypad_axis_t) |
+1 | Axis is being held in the positive direction |
-1 | Axis is being held in the negative direction |
0 | Axis is not being held |
joypad_8way_t joypad_get_direction | ( | joypad_port_t | port, |
joypad_2d_t | axes | ||
) |
Get the 8-way direction for a Joypad port's directional axes.
port | Joypad port number (joypad_port_t) |
axes | 2D axes enumeration value (joypad_2d_t) |
void joypad_accessory_reset | ( | joypad_port_t | port | ) |
Reset the accessory state for a Joypad port.
port | Joypad port number (joypad_port_t) |
void joypad_transfer_pak_wait_timer_init | ( | joypad_port_t | port | ) |
Initialize the Transfer Pak wait timer if necessary.
port | Joypad port number (joypad_port_t) |
void joypad_accessory_detect_async | ( | joypad_port_t | port | ) |
Detect which accessory is inserted in an N64 controller.
port | Joypad port to detect the accessory on (joypad_port_t) |
void joypad_rumble_pak_toggle_async | ( | joypad_port_t | port, |
bool | active | ||
) |
Turn the Rumble Pak motor on or off for a Joypad port.
port | Joypad port number (joypad_port_t) |
active | Whether the motor should be on (true) or off (false) |
void joypad_accessory_xfer_async | ( | joypad_port_t | port, |
joypad_accessory_xfer_t | xfer, | ||
uint16_t | start_addr, | ||
void * | dst, | ||
size_t | len, | ||
joypad_accessory_io_callback_t | callback, | ||
void * | ctx | ||
) |
Read or write data from a Joypad accessory asynchronously.
This function can perform a bulk transfer of data from a Joypad accessory. A bulk transfer can read or write any number of bytes from any starting address in the accessory, including misaligned addresses.
It builds upon the lower level primitives joybus_accessory_read and joybus_accessory_write, which are limited to 32-byte, aligned data blocks. To perform misaligned writes, this function will perform read-modify-write operations on the accessory when needed.
This function can operate on any Joypad accessory.
The joybus protocol for accessories includes a builtin checksum to detect corruptions on the wire (that can indeed happen during normal operation). This function will automatically retry the transfer in case of a checksum error (up to some hardcoded number of times) and then eventually fail with a JOYPAD_ACCESSORY_ERROR_CHECKSUM error. If you get this error, it might be useless to try again and you can just assume the connection to the accessory is electrically faulty.
port | Joypad port number (joypad_port_t) |
xfer | Transfer direction ( JOYPAD_ACCESSORY_XFER_READ or JOYPAD_ACCESSORY_XFER_WRITE) |
start_addr | Starting address in the accessory to read from, or write to. There is no alignment requirement for this address. |
dst | Destination buffer to read accessory data into. |
len | Number of bytes to read. Any number of bytes can be read. |
callback | Callback function to call when the read operation completes. |
ctx | Opaque pointer to pass to the callback function. |
joypad_accessory_error_t joypad_accessory_xfer | ( | joypad_port_t | port, |
joypad_accessory_xfer_t | xfer, | ||
uint16_t | start_addr, | ||
void * | dst, | ||
size_t | len | ||
) |
Read or write data from a joypad accessory.
This is the blocking version of joypad_accessory_xfer_async. Like the asynchronous version, this function can read or write any number of bytes from any starting address in the accessory.
This builds upon the lower level primitives joybus_accessory_read and joybus_accessory_write, which are limited to 32-byte, aligned data blocks.
port | Joypad port number (joypad_port_t) |
xfer | Transfer direction (JOYPAD_ACCESSORY_XFER_READ or JOYPAD_ACCESSORY_XFER_WRITE) |
start_addr | Starting address in the accessory to read from. There is no alignment requirement for this address. |
dst | Destination buffer to read accessory data into. |
len | Number of bytes to read. Any number of bytes can be read. |
joypad_accessory_error_t joypad_controller_pak_set_bank | ( | joypad_port_t | port, |
uint8_t | bank | ||
) |
Select the active bank for a Controller Pak.
Most controller paks (including all first-party ones) have a single bank of 32 KiB of storage. However, some third-party controller paks have multiple banks, and require an explicit bank switch operation to access data beyond the first 32 KiB.
Generic transfer functions for accessories like joypad_accessory_xfer_async will only access the active bank.
There is no way to probe the number of banks in a Controller Pak at the hardware level. In situation where probing is necessary (eg: formatting functions), write tests can be performed to determine the number of banks.
port | Joypad port number (joypad_port_t) |
bank | Bank number to switch to. |
void joypad_transfer_pak_enable_async | ( | joypad_port_t | port, |
bool | enabled | ||
) |
Enable or disable the Transfer Pak for a Joypad port.
port | Joypad port number (joypad_port_t) |
enabled | Whether the Transfer Pak should be enabled (true) or disabled (false) |
void joypad_transfer_pak_load_async | ( | joypad_port_t | port, |
uint16_t | cart_addr, | ||
void * | dst, | ||
size_t | len | ||
) |
Load data from the GB cartridge inserted in a Transfer Pak.
port | Joypad port number (joypad_port_t) | |
cart_addr | Starting address in the GB cartridge to load from. | |
[out] | dst | Destination buffer to load cartridge data into. |
len | Number of bytes to load (must be a multiple of 32). |
void joypad_transfer_pak_store_async | ( | joypad_port_t | port, |
uint16_t | cart_addr, | ||
void * | src, | ||
size_t | len | ||
) |
Store data on the GB cartridge inserted in a Transfer Pak.
port | Joypad port number (joypad_port_t) | |
cart_addr | Starting address in the GB cartridge to store into. | |
[in] | src | Source buffer of data to store on GB cartridge. |
len | Number of bytes to store (must be a multiple of 32). |