KallistiOS git master
Independent SDK for the Sega Dreamcast
Loading...
Searching...
No Matches
Querying Inputs

API used to query for input state. More...

Modules

 Inputs
 Collection of all status masks for checking input.
 

Data Structures

struct  cont_state_t
 Controller state structure. More...
 

Macros

#define CONT_RESET_BUTTONS   (CONT_A | CONT_B | CONT_X | CONT_Y | CONT_START)
 Controller buttons for standard reset action.
 

Typedefs

typedef void(* cont_btn_callback_t) (uint8_t addr, uint32_t btns)
 Controller automatic callback type.
 

Functions

void cont_btn_callback (uint8_t addr, uint32_t btns, cont_btn_callback_t cb)
 Set an automatic button press callback.
 

Detailed Description

API used to query for input state.

The following API is used to check for a controller's input state.

You can grab a controller's state structure, containing the state of all of its inputs by using:

cont_state_t *state = (cont_state_t *)maple_dev_status(device);

Next you can check for the state of a particular button with:

if(state->a)                // Check via bitfield
    printf("Pressed A".);

or

if(state->buttons & CONT_A) // Check via applying bitmask
    printf("Pressed A.")

Macro Definition Documentation

◆ CONT_RESET_BUTTONS

#define CONT_RESET_BUTTONS   (CONT_A | CONT_B | CONT_X | CONT_Y | CONT_START)

Controller buttons for standard reset action.

Convenience macro providing the standard button combination used as a reset mechanism by most retail games.

Typedef Documentation

◆ cont_btn_callback_t

typedef void(* cont_btn_callback_t) (uint8_t addr, uint32_t btns)

Controller automatic callback type.

Functions of this type can be set with cont_btn_callback() to respond automatically to the specified set of buttons being pressed. This can be used, for instance, to implement the standard A+B+X+Y+Start method of ending the program running.

Warning
Your callback will be invoked within a context with interrupts disabled. See cont_btn_callback for more information.
Parameters
addrMaple BUS address to poll for the button mask on, or 0 for all ports.
btnsMask of all buttons which should be pressed to trigger the callback.
See also
cont_btn_callback

Function Documentation

◆ cont_btn_callback()

void cont_btn_callback ( uint8_t  addr,
uint32_t  btns,
cont_btn_callback_t  cb 
)

Set an automatic button press callback.

This function sets a callback function to be called when the specified controller has the set of buttons given pressed.

Note
The callback gets invoked for the given maple port; however, providing an address of '0' will cause it to be invoked for any port with a device pressing the given buttons. Since you are passed back the address of this device, You are free to implement your own filtering logic within your callback.
Warning
The provided callback function is invoked within a context which has interrupts disabled. This means that you should not do any sort of complex processing or make any API calls which depend on interrupts to complete, such as Maple or ethernet processing whichy rely on packet transmission, any sleeping or threading calls, blocking on any sort of file I/O, etc. This mechanism is typically used to quickly terminate the application and should be used with caution.
Parameters
addrThe controller to listen on (or 0 for all ports). This value can be obtained by using maple_addr().
btnsThe buttons bitmask to match.
cbThe callback to call when the buttons are pressed.