comparison src/joystick/dc/SDL_sysjoystick.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
52 * This function should set SDL_numjoysticks to the number of available 52 * This function should set SDL_numjoysticks to the number of available
53 * joysticks. Joystick 0 should be the system default joystick. 53 * joysticks. Joystick 0 should be the system default joystick.
54 * It should return 0, or -1 on an unrecoverable fatal error. 54 * It should return 0, or -1 on an unrecoverable fatal error.
55 */ 55 */
56 int 56 int
57 SDL_SYS_JoystickInit (void) 57 SDL_SYS_JoystickInit(void)
58 { 58 {
59 int numdevs; 59 int numdevs;
60 60
61 int p, u; 61 int p, u;
62 62
63 numdevs = 0; 63 numdevs = 0;
64 for (p = 0; p < MAPLE_PORT_COUNT; p++) { 64 for (p = 0; p < MAPLE_PORT_COUNT; p++) {
65 for (u = 0; u < MAPLE_UNIT_COUNT; u++) { 65 for (u = 0; u < MAPLE_UNIT_COUNT; u++) {
66 if (maple_device_func (p, u) & MAPLE_FUNC_CONTROLLER) { 66 if (maple_device_func(p, u) & MAPLE_FUNC_CONTROLLER) {
67 SYS_Joystick_addr[numdevs] = maple_addr (p, u); 67 SYS_Joystick_addr[numdevs] = maple_addr(p, u);
68 numdevs++; 68 numdevs++;
69 } 69 }
70 } 70 }
71 } 71 }
72 72
73 return (numdevs); 73 return (numdevs);
74 } 74 }
75 75
76 /* Function to get the device-dependent name of a joystick */ 76 /* Function to get the device-dependent name of a joystick */
77 const char * 77 const char *
78 SDL_SYS_JoystickName (int index) 78 SDL_SYS_JoystickName(int index)
79 { 79 {
80 maple_device_t *dev; 80 maple_device_t *dev;
81 if (maple_compat_resolve 81 if (maple_compat_resolve
82 (SYS_Joystick_addr[index], &dev, MAPLE_FUNC_CONTROLLER) != 0) 82 (SYS_Joystick_addr[index], &dev, MAPLE_FUNC_CONTROLLER) != 0)
83 return NULL; 83 return NULL;
88 The joystick to open is specified by the index field of the joystick. 88 The joystick to open is specified by the index field of the joystick.
89 This should fill the nbuttons and naxes fields of the joystick structure. 89 This should fill the nbuttons and naxes fields of the joystick structure.
90 It returns 0, or -1 if there is an error. 90 It returns 0, or -1 if there is an error.
91 */ 91 */
92 int 92 int
93 SDL_SYS_JoystickOpen (SDL_Joystick * joystick) 93 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
94 { 94 {
95 /* allocate memory for system specific hardware data */ 95 /* allocate memory for system specific hardware data */
96 joystick->hwdata = 96 joystick->hwdata =
97 (struct joystick_hwdata *) SDL_malloc (sizeof (*joystick->hwdata)); 97 (struct joystick_hwdata *) SDL_malloc(sizeof(*joystick->hwdata));
98 if (joystick->hwdata == NULL) { 98 if (joystick->hwdata == NULL) {
99 SDL_OutOfMemory (); 99 SDL_OutOfMemory();
100 return (-1); 100 return (-1);
101 } 101 }
102 SDL_memset (joystick->hwdata, 0, sizeof (*joystick->hwdata)); 102 SDL_memset(joystick->hwdata, 0, sizeof(*joystick->hwdata));
103 103
104 /* fill nbuttons, naxes, and nhats fields */ 104 /* fill nbuttons, naxes, and nhats fields */
105 joystick->nbuttons = MAX_BUTTONS; 105 joystick->nbuttons = MAX_BUTTONS;
106 joystick->naxes = MAX_AXES; 106 joystick->naxes = MAX_AXES;
107 joystick->nhats = MAX_HATS; 107 joystick->nhats = MAX_HATS;
114 * but instead should call SDL_PrivateJoystick*() to deliver events 114 * but instead should call SDL_PrivateJoystick*() to deliver events
115 * and update joystick device state. 115 * and update joystick device state.
116 */ 116 */
117 117
118 void 118 void
119 SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) 119 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
120 { 120 {
121 const int sdl_buttons[] = { 121 const int sdl_buttons[] = {
122 CONT_C, 122 CONT_C,
123 CONT_B, 123 CONT_B,
124 CONT_A, 124 CONT_A,
132 uint8 addr; 132 uint8 addr;
133 cont_cond_t cond, *prev_cond; 133 cont_cond_t cond, *prev_cond;
134 int buttons, prev_buttons, i, changed; 134 int buttons, prev_buttons, i, changed;
135 135
136 addr = SYS_Joystick_addr[joystick->index]; 136 addr = SYS_Joystick_addr[joystick->index];
137 if (cont_get_cond (addr, &cond) < 0) 137 if (cont_get_cond(addr, &cond) < 0)
138 return; 138 return;
139 139
140 buttons = cond.buttons; 140 buttons = cond.buttons;
141 prev_buttons = joystick->hwdata->prev_buttons; 141 prev_buttons = joystick->hwdata->prev_buttons;
142 changed = buttons ^ prev_buttons; 142 changed = buttons ^ prev_buttons;
150 hat |= SDL_HAT_DOWN; 150 hat |= SDL_HAT_DOWN;
151 if (buttons & CONT_DPAD_LEFT) 151 if (buttons & CONT_DPAD_LEFT)
152 hat |= SDL_HAT_LEFT; 152 hat |= SDL_HAT_LEFT;
153 if (buttons & CONT_DPAD_RIGHT) 153 if (buttons & CONT_DPAD_RIGHT)
154 hat |= SDL_HAT_RIGHT; 154 hat |= SDL_HAT_RIGHT;
155 SDL_PrivateJoystickHat (joystick, 0, hat); 155 SDL_PrivateJoystickHat(joystick, 0, hat);
156 } 156 }
157 if ((changed) & 157 if ((changed) &
158 (CONT_DPAD2_UP | CONT_DPAD2_DOWN | CONT_DPAD2_LEFT | 158 (CONT_DPAD2_UP | CONT_DPAD2_DOWN | CONT_DPAD2_LEFT |
159 CONT_DPAD2_RIGHT)) { 159 CONT_DPAD2_RIGHT)) {
160 int hat = SDL_HAT_CENTERED; 160 int hat = SDL_HAT_CENTERED;
164 hat |= SDL_HAT_DOWN; 164 hat |= SDL_HAT_DOWN;
165 if (buttons & CONT_DPAD2_LEFT) 165 if (buttons & CONT_DPAD2_LEFT)
166 hat |= SDL_HAT_LEFT; 166 hat |= SDL_HAT_LEFT;
167 if (buttons & CONT_DPAD2_RIGHT) 167 if (buttons & CONT_DPAD2_RIGHT)
168 hat |= SDL_HAT_RIGHT; 168 hat |= SDL_HAT_RIGHT;
169 SDL_PrivateJoystickHat (joystick, 1, hat); 169 SDL_PrivateJoystickHat(joystick, 1, hat);
170 } 170 }
171 171
172 for (i = 0; i < sizeof (sdl_buttons) / sizeof (sdl_buttons[0]); i++) { 172 for (i = 0; i < sizeof(sdl_buttons) / sizeof(sdl_buttons[0]); i++) {
173 if (changed & sdl_buttons[i]) { 173 if (changed & sdl_buttons[i]) {
174 SDL_PrivateJoystickButton (joystick, i, 174 SDL_PrivateJoystickButton(joystick, i,
175 (buttons & sdl_buttons[i]) ? 175 (buttons & sdl_buttons[i]) ?
176 SDL_PRESSED : SDL_RELEASED); 176 SDL_PRESSED : SDL_RELEASED);
177 } 177 }
178 } 178 }
179 179
180 prev_cond = &joystick->hwdata->prev_cond; 180 prev_cond = &joystick->hwdata->prev_cond;
181 if (cond.joyx != prev_cond->joyx) 181 if (cond.joyx != prev_cond->joyx)
182 SDL_PrivateJoystickAxis (joystick, 0, cond.joyx - 128); 182 SDL_PrivateJoystickAxis(joystick, 0, cond.joyx - 128);
183 if (cond.joyy != prev_cond->joyy) 183 if (cond.joyy != prev_cond->joyy)
184 SDL_PrivateJoystickAxis (joystick, 1, cond.joyy - 128); 184 SDL_PrivateJoystickAxis(joystick, 1, cond.joyy - 128);
185 if (cond.rtrig != prev_cond->rtrig) 185 if (cond.rtrig != prev_cond->rtrig)
186 SDL_PrivateJoystickAxis (joystick, 2, cond.rtrig); 186 SDL_PrivateJoystickAxis(joystick, 2, cond.rtrig);
187 if (cond.ltrig != prev_cond->ltrig) 187 if (cond.ltrig != prev_cond->ltrig)
188 SDL_PrivateJoystickAxis (joystick, 3, cond.ltrig); 188 SDL_PrivateJoystickAxis(joystick, 3, cond.ltrig);
189 if (cond.joy2x != prev_cond->joy2x) 189 if (cond.joy2x != prev_cond->joy2x)
190 SDL_PrivateJoystickAxis (joystick, 4, cond.joy2x - 128); 190 SDL_PrivateJoystickAxis(joystick, 4, cond.joy2x - 128);
191 if (cond.joy2y != prev_cond->joy2y) 191 if (cond.joy2y != prev_cond->joy2y)
192 SDL_PrivateJoystickAxis (joystick, 5, cond.joy2y - 128); 192 SDL_PrivateJoystickAxis(joystick, 5, cond.joy2y - 128);
193 193
194 joystick->hwdata->prev_buttons = buttons; 194 joystick->hwdata->prev_buttons = buttons;
195 joystick->hwdata->prev_cond = cond; 195 joystick->hwdata->prev_cond = cond;
196 } 196 }
197 197
198 /* Function to close a joystick after use */ 198 /* Function to close a joystick after use */
199 void 199 void
200 SDL_SYS_JoystickClose (SDL_Joystick * joystick) 200 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
201 { 201 {
202 if (joystick->hwdata != NULL) { 202 if (joystick->hwdata != NULL) {
203 /* free system specific hardware data */ 203 /* free system specific hardware data */
204 SDL_free (joystick->hwdata); 204 SDL_free(joystick->hwdata);
205 } 205 }
206 } 206 }
207 207
208 /* Function to perform any system-specific joystick related cleanup */ 208 /* Function to perform any system-specific joystick related cleanup */
209 void 209 void
210 SDL_SYS_JoystickQuit (void) 210 SDL_SYS_JoystickQuit(void)
211 { 211 {
212 return; 212 return;
213 } 213 }
214 214
215 #endif /* SDL_JOYSTICK_DC */ 215 #endif /* SDL_JOYSTICK_DC */