Lines Matching refs:joystick

96 	SDL_Joystick *joystick;  in SDL_JoystickOpen()  local
107 joystick = SDL_joysticks[i]; in SDL_JoystickOpen()
108 ++joystick->ref_count; in SDL_JoystickOpen()
109 return(joystick); in SDL_JoystickOpen()
114 joystick = (SDL_Joystick *)SDL_malloc((sizeof *joystick)); in SDL_JoystickOpen()
115 if ( !joystick ) { in SDL_JoystickOpen()
120 SDL_memset(joystick, 0, (sizeof *joystick)); in SDL_JoystickOpen()
121 joystick->index = device_index; in SDL_JoystickOpen()
122 if ( SDL_SYS_JoystickOpen(joystick) < 0 ) { in SDL_JoystickOpen()
123 SDL_free(joystick); in SDL_JoystickOpen()
127 if ( joystick->naxes > 0 ) { in SDL_JoystickOpen()
128 joystick->axes = (Sint16 *)SDL_malloc in SDL_JoystickOpen()
129 (joystick->naxes*sizeof(Sint16)); in SDL_JoystickOpen()
131 if ( joystick->nhats > 0 ) { in SDL_JoystickOpen()
132 joystick->hats = (Uint8 *)SDL_malloc in SDL_JoystickOpen()
133 (joystick->nhats*sizeof(Uint8)); in SDL_JoystickOpen()
135 if ( joystick->nballs > 0 ) { in SDL_JoystickOpen()
136 joystick->balls = (struct balldelta *)SDL_malloc in SDL_JoystickOpen()
137 (joystick->nballs*sizeof(*joystick->balls)); in SDL_JoystickOpen()
139 if ( joystick->nbuttons > 0 ) { in SDL_JoystickOpen()
140 joystick->buttons = (Uint8 *)SDL_malloc in SDL_JoystickOpen()
141 (joystick->nbuttons*sizeof(Uint8)); in SDL_JoystickOpen()
143 if ( ((joystick->naxes > 0) && !joystick->axes) in SDL_JoystickOpen()
144 || ((joystick->nhats > 0) && !joystick->hats) in SDL_JoystickOpen()
145 || ((joystick->nballs > 0) && !joystick->balls) in SDL_JoystickOpen()
146 || ((joystick->nbuttons > 0) && !joystick->buttons)) { in SDL_JoystickOpen()
148 SDL_JoystickClose(joystick); in SDL_JoystickOpen()
152 if ( joystick->axes ) { in SDL_JoystickOpen()
153 SDL_memset(joystick->axes, 0, in SDL_JoystickOpen()
154 joystick->naxes*sizeof(Sint16)); in SDL_JoystickOpen()
156 if ( joystick->hats ) { in SDL_JoystickOpen()
157 SDL_memset(joystick->hats, 0, in SDL_JoystickOpen()
158 joystick->nhats*sizeof(Uint8)); in SDL_JoystickOpen()
160 if ( joystick->balls ) { in SDL_JoystickOpen()
161 SDL_memset(joystick->balls, 0, in SDL_JoystickOpen()
162 joystick->nballs*sizeof(*joystick->balls)); in SDL_JoystickOpen()
164 if ( joystick->buttons ) { in SDL_JoystickOpen()
165 SDL_memset(joystick->buttons, 0, in SDL_JoystickOpen()
166 joystick->nbuttons*sizeof(Uint8)); in SDL_JoystickOpen()
170 ++joystick->ref_count; in SDL_JoystickOpen()
174 SDL_joysticks[i] = joystick; in SDL_JoystickOpen()
177 return(joystick); in SDL_JoystickOpen()
197 static int ValidJoystick(SDL_Joystick **joystick) in ValidJoystick() argument
201 if ( *joystick == NULL ) { in ValidJoystick()
202 *joystick = default_joystick; in ValidJoystick()
204 if ( *joystick == NULL ) { in ValidJoystick()
216 int SDL_JoystickIndex(SDL_Joystick *joystick) in SDL_JoystickIndex() argument
218 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickIndex()
221 return(joystick->index); in SDL_JoystickIndex()
227 int SDL_JoystickNumAxes(SDL_Joystick *joystick) in SDL_JoystickNumAxes() argument
229 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickNumAxes()
232 return(joystick->naxes); in SDL_JoystickNumAxes()
238 int SDL_JoystickNumHats(SDL_Joystick *joystick) in SDL_JoystickNumHats() argument
240 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickNumHats()
243 return(joystick->nhats); in SDL_JoystickNumHats()
249 int SDL_JoystickNumBalls(SDL_Joystick *joystick) in SDL_JoystickNumBalls() argument
251 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickNumBalls()
254 return(joystick->nballs); in SDL_JoystickNumBalls()
260 int SDL_JoystickNumButtons(SDL_Joystick *joystick) in SDL_JoystickNumButtons() argument
262 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickNumButtons()
265 return(joystick->nbuttons); in SDL_JoystickNumButtons()
271 Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis) in SDL_JoystickGetAxis() argument
275 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickGetAxis()
278 if ( axis < joystick->naxes ) { in SDL_JoystickGetAxis()
279 state = joystick->axes[axis]; in SDL_JoystickGetAxis()
281 SDL_SetError("Joystick only has %d axes", joystick->naxes); in SDL_JoystickGetAxis()
290 Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat) in SDL_JoystickGetHat() argument
294 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickGetHat()
297 if ( hat < joystick->nhats ) { in SDL_JoystickGetHat()
298 state = joystick->hats[hat]; in SDL_JoystickGetHat()
300 SDL_SetError("Joystick only has %d hats", joystick->nhats); in SDL_JoystickGetHat()
309 int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy) in SDL_JoystickGetBall() argument
313 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickGetBall()
318 if ( ball < joystick->nballs ) { in SDL_JoystickGetBall()
320 *dx = joystick->balls[ball].dx; in SDL_JoystickGetBall()
323 *dy = joystick->balls[ball].dy; in SDL_JoystickGetBall()
325 joystick->balls[ball].dx = 0; in SDL_JoystickGetBall()
326 joystick->balls[ball].dy = 0; in SDL_JoystickGetBall()
328 SDL_SetError("Joystick only has %d balls", joystick->nballs); in SDL_JoystickGetBall()
337 Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button) in SDL_JoystickGetButton() argument
341 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickGetButton()
344 if ( button < joystick->nbuttons ) { in SDL_JoystickGetButton()
345 state = joystick->buttons[button]; in SDL_JoystickGetButton()
347 SDL_SetError("Joystick only has %d buttons",joystick->nbuttons); in SDL_JoystickGetButton()
356 void SDL_JoystickClose(SDL_Joystick *joystick) in SDL_JoystickClose() argument
360 if ( ! ValidJoystick(&joystick) ) { in SDL_JoystickClose()
365 if ( --joystick->ref_count > 0 ) { in SDL_JoystickClose()
372 if ( joystick == default_joystick ) { in SDL_JoystickClose()
375 SDL_SYS_JoystickClose(joystick); in SDL_JoystickClose()
379 if ( joystick == SDL_joysticks[i] ) { in SDL_JoystickClose()
381 (SDL_numjoysticks-i)*sizeof(joystick)); in SDL_JoystickClose()
390 if ( joystick->axes ) { in SDL_JoystickClose()
391 SDL_free(joystick->axes); in SDL_JoystickClose()
393 if ( joystick->hats ) { in SDL_JoystickClose()
394 SDL_free(joystick->hats); in SDL_JoystickClose()
396 if ( joystick->balls ) { in SDL_JoystickClose()
397 SDL_free(joystick->balls); in SDL_JoystickClose()
399 if ( joystick->buttons ) { in SDL_JoystickClose()
400 SDL_free(joystick->buttons); in SDL_JoystickClose()
402 SDL_free(joystick); in SDL_JoystickClose()
423 int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value) in SDL_PrivateJoystickAxis() argument
428 joystick->axes[axis] = value; in SDL_PrivateJoystickAxis()
436 event.jaxis.which = joystick->index; in SDL_PrivateJoystickAxis()
448 int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value) in SDL_PrivateJoystickHat() argument
453 joystick->hats[hat] = value; in SDL_PrivateJoystickHat()
461 event.jhat.which = joystick->index; in SDL_PrivateJoystickHat()
473 int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball, in SDL_PrivateJoystickBall() argument
479 joystick->balls[ball].dx += xrel; in SDL_PrivateJoystickBall()
480 joystick->balls[ball].dy += yrel; in SDL_PrivateJoystickBall()
488 event.jball.which = joystick->index; in SDL_PrivateJoystickBall()
501 int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state) in SDL_PrivateJoystickButton() argument
521 joystick->buttons[button] = state; in SDL_PrivateJoystickButton()
527 event.jbutton.which = joystick->index; in SDL_PrivateJoystickButton()