libdragon
controller.h
Go to the documentation of this file.
1
6#ifndef __LIBDRAGON_CONTROLLER_H
7#define __LIBDRAGON_CONTROLLER_H
8
9#include <stdint.h>
10
23#define CONTROLLER_1_INSERTED 0xF000
25#define CONTROLLER_2_INSERTED 0x0F00
27#define CONTROLLER_3_INSERTED 0x00F0
29#define CONTROLLER_4_INSERTED 0x000F
38#define ACCESSORY_NONE 0
40#define ACCESSORY_MEMPAK 1
42#define ACCESSORY_RUMBLEPAK 2
44#define ACCESSORY_VRU 3
46#define ACCESSORY_TRANSFERPAK 4
54#define ERROR_NONE 0x0
56#define ERROR_BAD_COMMAND 0x1
58#define ERROR_NOT_PRESENT 0x2
66typedef struct SI_condat
67{
69 unsigned : 16;
71 unsigned err : 2;
73 unsigned : 14;
74
75 union
76 {
77 struct
78 {
80 unsigned int data : 32;
81 };
82 struct
83 {
85 unsigned A : 1;
87 unsigned B : 1;
89 unsigned Z : 1;
91 unsigned start : 1;
93 unsigned up : 1;
95 unsigned down : 1;
97 unsigned left : 1;
99 unsigned right : 1;
101 unsigned : 2;
103 unsigned L : 1;
105 unsigned R : 1;
107 unsigned C_up : 1;
109 unsigned C_down : 1;
111 unsigned C_left : 1;
113 unsigned C_right : 1;
115 signed x : 8;
117 signed y : 8;
118 };
119 };
120} _SI_condat;
121
127typedef struct SI_condat_gc
128{
129 union
130 {
131 struct
132 {
134 uint64_t data;
135 };
136 struct
137 {
138 unsigned err : 2;
139 unsigned origin_unchecked : 1;
140 unsigned start : 1;
141 unsigned y : 1;
142 unsigned x : 1;
143 unsigned b : 1;
144 unsigned a : 1;
145 unsigned unused2 : 1;
146 unsigned l : 1;
147 unsigned r : 1;
148 unsigned z : 1;
149 unsigned up : 1;
150 unsigned down : 1;
151 unsigned right : 1;
152 unsigned left : 1;
153 unsigned stick_x : 8;
154 unsigned stick_y : 8;
155
156 unsigned cstick_x : 8;
157 unsigned cstick_y : 8;
158 unsigned analog_l : 8;
159 unsigned analog_r : 8;
160 };
161 };
163
170 struct SI_condat_gc data;
171 uint8_t deadzone0;
172 uint8_t deadzone1;
173};
174
181typedef struct controller_data
182{
184 struct SI_condat c[4];
186 struct SI_condat_gc gc[4];
188
190typedef struct controller_origin_data
191{
193 struct SI_origdat_gc gc[4];
195
196#ifdef __cplusplus
197extern "C" {
198#endif
199
200void controller_init( void );
201void controller_read( struct controller_data * data );
202void controller_read_gc( struct controller_data * data, const uint8_t rumble[4] );
203void controller_read_gc_origin( struct controller_origin_data * data);
204int get_controllers_present( void );
205int get_accessories_present( struct controller_data * data );
206void controller_scan( void );
207struct controller_data get_keys_down( void );
208struct controller_data get_keys_up( void );
209struct controller_data get_keys_held( void );
210struct controller_data get_keys_pressed( void );
211int get_dpad_direction( int controller );
212int read_mempak_address( int controller, uint16_t address, uint8_t *data );
213int write_mempak_address( int controller, uint16_t address, uint8_t *data );
214int identify_accessory( int controller );
215void rumble_start( int controller );
216void rumble_stop( int controller );
217void execute_raw_command( int controller, int command, int bytesout, int bytesin, unsigned char *out, unsigned char *in );
218
219#ifdef __cplusplus
220}
221#endif
222 /* controller */
224
225#endif
unsigned err
Status of the last command.
Definition: controller.h:71
void controller_scan(void)
Fetch the current controller state.
Definition: controller.c:240
struct controller_data get_keys_held(void)
Get keys that were held since the last inspection.
Definition: controller.c:304
void controller_read_gc_origin(struct controller_origin_data *outdata)
Read the controller origin status for all controllers, GC version.
Definition: controller.c:204
int write_mempak_address(int controller, uint16_t address, uint8_t *data)
Write a chunk of data to a mempak.
Definition: controller.c:711
void rumble_start(int controller)
Turn rumble on for a particular controller.
Definition: controller.c:862
void controller_read(struct controller_data *output)
Read the controller button status for all controllers.
Definition: controller.c:130
int get_accessories_present(struct controller_data *out)
Return a bitmask specifying which controllers have recognized accessories.
Definition: controller.c:519
struct controller_data get_keys_pressed(void)
Get keys that are currently pressed, regardless of previous state.
Definition: controller.c:326
int identify_accessory(int controller)
Identify the accessory connected to a controller.
Definition: controller.c:806
void execute_raw_command(int controller, int command, int bytesout, int bytesin, unsigned char *out, unsigned char *in)
Execute a raw PIF command.
Definition: controller.c:407
void rumble_stop(int controller)
Turn rumble off for a particular controller.
Definition: controller.c:879
struct controller_data get_keys_down(void)
Get keys that were pressed since the last inspection.
Definition: controller.c:259
int get_dpad_direction(int controller)
Return the DPAD calculated direction.
Definition: controller.c:343
struct controller_data get_keys_up(void)
Get keys that were released since the last inspection.
Definition: controller.c:281
void controller_init(void)
Initialize the controller subsystem.
Definition: controller.c:109
void controller_read_gc(struct controller_data *outdata, const uint8_t rumble[4])
Read the controller button status for all controllers, GC version.
Definition: controller.c:158
int get_controllers_present(void)
Return a bitmask representing which controllers are present.
Definition: controller.c:437
int read_mempak_address(int controller, uint16_t address, uint8_t *data)
Read a chunk of data from a mempak.
Definition: controller.c:637
SI GameCube controller origin data for all controller ports.
Definition: controller.h:191
SI controller data for all controller ports.
Definition: controller.h:182
SI GameCube controller origin data.
Definition: controller.h:169
SI Nintendo 64 controller data.
Definition: controller.h:67
SI GameCube controller data.
Definition: controller.h:128