comparison src/joystick/riscos/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
51 * This function should set SDL_numjoysticks to the number of available 51 * This function should set SDL_numjoysticks to the number of available
52 * joysticks. Joystick 0 should be the system default joystick. 52 * joysticks. Joystick 0 should be the system default joystick.
53 * It should return number of joysticks, or -1 on an unrecoverable fatal error. 53 * It should return number of joysticks, or -1 on an unrecoverable fatal error.
54 */ 54 */
55 int 55 int
56 SDL_SYS_JoystickInit (void) 56 SDL_SYS_JoystickInit(void)
57 { 57 {
58 _kernel_swi_regs regs; 58 _kernel_swi_regs regs;
59 59
60 /* Try to read joystick 0 */ 60 /* Try to read joystick 0 */
61 regs.r[0] = 0; 61 regs.r[0] = 0;
62 if (_kernel_swi (JOYSTICK_READ, &regs, &regs) == NULL) { 62 if (_kernel_swi(JOYSTICK_READ, &regs, &regs) == NULL) {
63 /* Switch works so assume we've got a joystick */ 63 /* Switch works so assume we've got a joystick */
64 return 1; 64 return 1;
65 } 65 }
66 /* Switch fails so it looks like there's no joystick here */ 66 /* Switch fails so it looks like there's no joystick here */
67 67
68 return (0); 68 return (0);
69 } 69 }
70 70
71 /* Function to get the device-dependent name of a joystick */ 71 /* Function to get the device-dependent name of a joystick */
72 const char * 72 const char *
73 SDL_SYS_JoystickName (int index) 73 SDL_SYS_JoystickName(int index)
74 { 74 {
75 if (index == 0) { 75 if (index == 0) {
76 return "RISC OS Joystick 0"; 76 return "RISC OS Joystick 0";
77 } 77 }
78 78
79 SDL_SetError ("No joystick available with that index"); 79 SDL_SetError("No joystick available with that index");
80 return (NULL); 80 return (NULL);
81 } 81 }
82 82
83 /* Function to open a joystick for use. 83 /* Function to open a joystick for use.
84 The joystick to open is specified by the index field of the joystick. 84 The joystick to open is specified by the index field of the joystick.
85 This should fill the nbuttons and naxes fields of the joystick structure. 85 This should fill the nbuttons and naxes fields of the joystick structure.
86 It returns 0, or -1 if there is an error. 86 It returns 0, or -1 if there is an error.
87 */ 87 */
88 int 88 int
89 SDL_SYS_JoystickOpen (SDL_Joystick * joystick) 89 SDL_SYS_JoystickOpen(SDL_Joystick * joystick)
90 { 90 {
91 _kernel_swi_regs regs; 91 _kernel_swi_regs regs;
92 92
93 if (!(joystick->hwdata = SDL_malloc (sizeof (struct joystick_hwdata)))) 93 if (!(joystick->hwdata = SDL_malloc(sizeof(struct joystick_hwdata))))
94 return -1; 94 return -1;
95 95
96 regs.r[0] = joystick->index; 96 regs.r[0] = joystick->index;
97 97
98 /* Don't know how to get exact count of buttons so assume max of 4 for now */ 98 /* Don't know how to get exact count of buttons so assume max of 4 for now */
111 * This function shouldn't update the joystick structure directly, 111 * This function shouldn't update the joystick structure directly,
112 * but instead should call SDL_PrivateJoystick*() to deliver events 112 * but instead should call SDL_PrivateJoystick*() to deliver events
113 * and update joystick device state. 113 * and update joystick device state.
114 */ 114 */
115 void 115 void
116 SDL_SYS_JoystickUpdate (SDL_Joystick * joystick) 116 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
117 { 117 {
118 _kernel_swi_regs regs; 118 _kernel_swi_regs regs;
119 regs.r[0] = joystick->index; 119 regs.r[0] = joystick->index;
120 120
121 if (_kernel_swi (JOYSTICK_READ, &regs, &regs) == NULL) { 121 if (_kernel_swi(JOYSTICK_READ, &regs, &regs) == NULL) {
122 int newstate = regs.r[0]; 122 int newstate = regs.r[0];
123 int oldstate = joystick->hwdata->joystate; 123 int oldstate = joystick->hwdata->joystate;
124 if (newstate != oldstate) { 124 if (newstate != oldstate) {
125 if ((newstate & 0xFF) != (oldstate & 0xFF)) { 125 if ((newstate & 0xFF) != (oldstate & 0xFF)) {
126 int y = regs.r[0] & 0xFF; 126 int y = regs.r[0] & 0xFF;
127 /* Convert to signed values */ 127 /* Convert to signed values */
128 if (y >= 128) 128 if (y >= 128)
129 y -= 256; 129 y -= 256;
130 SDL_PrivateJoystickAxis (joystick, 1, -y * 256); /* Up and down opposite to result in SDL */ 130 SDL_PrivateJoystickAxis(joystick, 1, -y * 256); /* Up and down opposite to result in SDL */
131 } 131 }
132 if ((newstate & 0xFF00) != (oldstate & 0xFF00)) { 132 if ((newstate & 0xFF00) != (oldstate & 0xFF00)) {
133 int x = (regs.r[0] & 0xFF00) >> 8; 133 int x = (regs.r[0] & 0xFF00) >> 8;
134 if (x >= 128) 134 if (x >= 128)
135 x -= 256; 135 x -= 256;
136 SDL_PrivateJoystickAxis (joystick, 0, x * 256); 136 SDL_PrivateJoystickAxis(joystick, 0, x * 256);
137 } 137 }
138 138
139 if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) { 139 if ((newstate & 0xFF0000) != (oldstate & 0xFF0000)) {
140 int buttons = (regs.r[0] & 0xFF0000) >> 16; 140 int buttons = (regs.r[0] & 0xFF0000) >> 16;
141 int oldbuttons = (oldstate & 0xFF0000) >> 16; 141 int oldbuttons = (oldstate & 0xFF0000) >> 16;
142 int i; 142 int i;
143 for (i = 0; i < joystick->nbuttons; i++) { 143 for (i = 0; i < joystick->nbuttons; i++) {
144 if ((buttons & (1 << i)) != (oldbuttons & (1 << i))) { 144 if ((buttons & (1 << i)) != (oldbuttons & (1 << i))) {
145 if (buttons & (1 << i)) 145 if (buttons & (1 << i))
146 SDL_PrivateJoystickButton (joystick, i, 146 SDL_PrivateJoystickButton(joystick, i,
147 SDL_PRESSED); 147 SDL_PRESSED);
148 else 148 else
149 SDL_PrivateJoystickButton (joystick, i, 149 SDL_PrivateJoystickButton(joystick, i,
150 SDL_RELEASED); 150 SDL_RELEASED);
151 } 151 }
152 } 152 }
153 } 153 }
154 joystick->hwdata->joystate = newstate; 154 joystick->hwdata->joystate = newstate;
155 } 155 }
158 return; 158 return;
159 } 159 }
160 160
161 /* Function to close a joystick after use */ 161 /* Function to close a joystick after use */
162 void 162 void
163 SDL_SYS_JoystickClose (SDL_Joystick * joystick) 163 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
164 { 164 {
165 if (joystick->hwdata) 165 if (joystick->hwdata)
166 SDL_free (joystick->hwdata); 166 SDL_free(joystick->hwdata);
167 return; 167 return;
168 } 168 }
169 169
170 /* Function to perform any system-specific joystick related cleanup */ 170 /* Function to perform any system-specific joystick related cleanup */
171 void 171 void
172 SDL_SYS_JoystickQuit (void) 172 SDL_SYS_JoystickQuit(void)
173 { 173 {
174 SDL_numjoysticks = 0; 174 SDL_numjoysticks = 0;
175 175
176 return; 176 return;
177 } 177 }