KallistiOS  2.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
controller.h
Go to the documentation of this file.
1 /* KallistiOS 2.0.0
2 
3  dc/maple/controller.h
4  (C)2000-2002 Jordan DeLong, Dan Potter
5 
6  Thanks to Marcus Comstedt for information on the controller.
7 */
8 
9 /** \file dc/maple/controller.h
10  \brief Definitions for using the controller device.
11 
12  This file contains the definitions needed to access the Maple controller
13  device. Obviously, this corresponds to the MAPLE_FUNC_CONTROLLER function
14  code.
15 
16  \author Jordan DeLong
17  \author Dan Potter
18 */
19 
20 #ifndef __DC_MAPLE_CONTROLLER_H
21 #define __DC_MAPLE_CONTROLLER_H
22 
23 #include <sys/cdefs.h>
24 __BEGIN_DECLS
25 
26 #include <arch/types.h>
27 
28 /** \defgroup controller_buttons Controller button codes
29 
30  This is the set of all buttons that are valid for a maple bus controller
31  device. The names should make it obvious what the button is.
32 
33  @{
34 */
35 #define CONT_C (1<<0)
36 #define CONT_B (1<<1)
37 #define CONT_A (1<<2)
38 #define CONT_START (1<<3)
39 #define CONT_DPAD_UP (1<<4)
40 #define CONT_DPAD_DOWN (1<<5)
41 #define CONT_DPAD_LEFT (1<<6)
42 #define CONT_DPAD_RIGHT (1<<7)
43 #define CONT_Z (1<<8)
44 #define CONT_Y (1<<9)
45 #define CONT_X (1<<10)
46 #define CONT_D (1<<11)
47 #define CONT_DPAD2_UP (1<<12)
48 #define CONT_DPAD2_DOWN (1<<13)
49 #define CONT_DPAD2_LEFT (1<<14)
50 #define CONT_DPAD2_RIGHT (1<<15)
51 /* @} */
52 
53 /* Raw controller condition structure */
54 typedef struct {
55  uint16 buttons; /* buttons bitfield */
56  uint8 rtrig; /* right trigger */
57  uint8 ltrig; /* left trigger */
58  uint8 joyx; /* joystick X */
59  uint8 joyy; /* joystick Y */
60  uint8 joy2x; /* second joystick X */
61  uint8 joy2y; /* second joystick Y */
62 } cont_cond_t;
63 
64 /* Our more civilized structure. Note that there are some fairly
65  significant differences in value interpretations here between
66  this struct and the old one:
67 
68  - "buttons" is zero based: a 1-bit means the button is PRESSED.
69  - "joyx", "joyy", "joy2x", and "joy2y" are all zero based: zero
70  means they are in the center, negative values are up/left,
71  and positive values are down/right.
72 
73  Note also that this is the struct you will get back if you call
74  maple_dev_status(), NOT a cont_cond_t. However, cont_get_cond() will
75  return the old compatible struct for now. */
76 
77 /** \brief Controller status structure.
78 
79  This structure contains information about the status of the controller
80  device and can be fetched with maple_dev_status().
81 
82  A 1 bit in the buttons bitfield indicates that a button is pressed, and the
83  joyx, joyy, joy2x, joy2 values are all 0 based (0 is centered).
84 
85  \headerfile dc/maple/controller.h
86 */
87 typedef struct {
88  /** \brief Buttons bitfield.
89  \see controller_buttons
90  */
92 
93  /** \brief Left trigger value. */
94  int ltrig;
95 
96  /** \brief Right trigger value. */
97  int rtrig;
98 
99  /** \brief Main joystick x-axis value. */
100  int joyx;
101 
102  /** \brief Main joystick y-axis value. */
103  int joyy;
104 
105  /** \brief Secondary joystick x-axis value (if applicable). */
106  int joy2x;
107 
108  /** \brief Secondary joystick y-axis value (if applicable). */
109  int joy2y;
110 } cont_state_t;
111 
112 /* \cond */
113 /* Init / Shutdown */
114 int cont_init();
115 void cont_shutdown();
116 /* \endcond */
117 
118 /** \brief Controller automatic callback type.
119 
120  Functions of this type can be set with cont_btn_callback() to respond
121  automatically to the specified set of buttons being pressed. This can be
122  used, for instance, to implement the standard A+B+X+Y+Start method of ending
123  the program running.
124 */
125 typedef void (*cont_btn_callback_t)(uint8 addr, uint32 btns);
126 
127 /** \brief Set an automatic button press callback.
128 
129  This function sets a callback function to be called when the specified
130  controller has the set of buttons given pressed.
131 
132  \param addr The controller to listen on. This value can be
133  obtained by using maple_addr().
134  \param btns The buttons bitmask to match.
135  \param cb The callback to call when the buttons are pressed.
136 */
138 
139 /** \defgroup controller_caps Controller capability bits.
140 
141  These bits will be set in the function_data for the controller's deviceinfo
142  if the controller supports the corresponding feature.
143 
144  @{
145 */
146 #define CONT_CAPABILITY_C (1<<0)
147 #define CONT_CAPABILITY_B (1<<1)
148 #define CONT_CAPABILITY_A (1<<2)
149 #define CONT_CAPABILITY_START (1<<3)
150 #define CONT_CAPABILITY_DPAD_UP (1<<4)
151 #define CONT_CAPABILITY_DPAD_DOWN (1<<5)
152 #define CONT_CAPABILITY_DPAD_LEFT (1<<6)
153 #define CONT_CAPABILITY_DPAD_RIGHT (1<<7)
154 #define CONT_CAPABILITY_Z (1<<8)
155 #define CONT_CAPABILITY_Y (1<<9)
156 #define CONT_CAPABILITY_X (1<<10)
157 #define CONT_CAPABILITY_D (1<<11)
158 #define CONT_CAPABILITY_DPAD2_UP (1<<12)
159 #define CONT_CAPABILITY_DPAD2_DOWN (1<<13)
160 #define CONT_CAPABILITY_DPAD2_LEFT (1<<14)
161 #define CONT_CAPABILITY_DPAD2_RIGHT (1<<15)
162 #define CONT_CAPABILITY_RTRIG (1<<16)
163 #define CONT_CAPABILITY_LTRIG (1<<17)
164 #define CONT_CAPABILITY_ANALOG_X (1<<18)
165 #define CONT_CAPABILITY_ANALOG_Y (1<<19)
166 #define CONT_CAPABILITY_ANALOG2_X (1<<20)
167 #define CONT_CAPABILITY_ANALOG2_Y (1<<21)
168 /** @} */
169 
170 __END_DECLS
171 
172 #endif /* __DC_MAPLE_CONTROLLER_H */
173