Mercurial > sdl-ios-xcode
comparison src/joystick/nds/SDL_sysjoystick.c @ 2673:24a6b3588eac gsoc2008_nds
Cleaned up and added joypad support from 1.2.9 NDS port. Also some minor video driver bugfixes.
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Thu, 19 Jun 2008 07:11:35 +0000 |
parents | c3e7c0698cbb |
children | 082cc3ffd7d8 |
comparison
equal
deleted
inserted
replaced
2672:74ac057679d5 | 2673:24a6b3588eac |
---|---|
23 #ifdef SAVE_RCSID | 23 #ifdef SAVE_RCSID |
24 static char rcsid = | 24 static char rcsid = |
25 "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $"; | 25 "@(#) $Id: SDL_sysjoystick.c,v 1.2 2001/04/26 16:50:17 hercules Exp $"; |
26 #endif | 26 #endif |
27 | 27 |
28 #include "SDL_config.h" | |
29 | |
30 #ifdef SDL_JOYSTICK_NDS | |
31 | |
28 /* This is the system specific header for the SDL joystick API */ | 32 /* This is the system specific header for the SDL joystick API */ |
29 #include <nds.h> | 33 #include <nds.h> |
30 //#include <nds/registers_alt.h> | 34 //#include <nds/registers_alt.h> |
31 #include <stdio.h> /* For the definition of NULL */ | 35 #include <stdio.h> /* For the definition of NULL */ |
32 | 36 |
33 #include "SDL_error.h" | 37 #include "SDL_error.h" |
38 #include "SDL_events.h" | |
34 #include "SDL_joystick.h" | 39 #include "SDL_joystick.h" |
35 #include "SDL_sysjoystick.h" | 40 #include "SDL_sysjoystick.h" |
36 #include "SDL_joystick_c.h" | 41 #include "SDL_joystick_c.h" |
37 | 42 |
38 #include "../../video/nds/SDL_ndsevents_c.h" | 43 #include "../../video/nds/SDL_ndsevents_c.h" |
44 */ | 49 */ |
45 int | 50 int |
46 SDL_SYS_JoystickInit(void) | 51 SDL_SYS_JoystickInit(void) |
47 { | 52 { |
48 SDL_numjoysticks = 1; | 53 SDL_numjoysticks = 1; |
49 | 54 /* keysInit();*/ |
50 //keysInit(); | 55 return (1); |
51 return (1); | |
52 } | 56 } |
53 | 57 |
54 /* Function to get the device-dependent name of a joystick */ | 58 /* Function to get the device-dependent name of a joystick */ |
55 const char * | 59 const char * |
56 SDL_SYS_JoystickName(int index) | 60 SDL_SYS_JoystickName(int index) |
80 /* Function to update the state of a joystick - called as a device poll. | 84 /* Function to update the state of a joystick - called as a device poll. |
81 * This function shouldn't update the joystick structure directly, | 85 * This function shouldn't update the joystick structure directly, |
82 * but instead should call SDL_PrivateJoystick*() to deliver events | 86 * but instead should call SDL_PrivateJoystick*() to deliver events |
83 * and update joystick device state. | 87 * and update joystick device state. |
84 */ | 88 */ |
85 int prevbutton = 0; | |
86 int prevkey = 0; | |
87 | |
88 int dc = NULL; | |
89 int ldc = 0; | |
90 u32 keysd, keysu = NULL; | |
91 void | 89 void |
92 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) | 90 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
93 { | 91 { |
94 | 92 u32 keysd, keysu; |
95 //dc=keysd; | 93 int magnitude = 16384; |
96 //if (dc != NULL) | 94 scanKeys(); |
97 //{ | 95 keysd = keysDown(); |
98 //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); | 96 keysu = keysUp(); |
99 //swiWaitForVBlank(); | |
100 //scanKeys(); | |
101 //keysd = keysDown(); | |
102 //keysu = keysUp(); | |
103 //ldc=keysd; | |
104 | |
105 //} | |
106 /*if (prevkey !=NULL && prevbutton !=NULL) | |
107 { | |
108 scanKeys(); | |
109 } | |
110 */ | |
111 | |
112 //scanKeys(); | |
113 keysd = keysDown(); | |
114 | |
115 keysu = keysUp(); | |
116 | |
117 | 97 |
118 short ax = 0, v = 0, h = 0; | |
119 if ((keysd & KEY_UP)) { | 98 if ((keysd & KEY_UP)) { |
120 ax = 1; | 99 SDL_PrivateJoystickAxis(joystick, 1, -magnitude); |
121 v = -10; | 100 } |
122 SDL_PrivateJoystickAxis(joystick, ax, v); | |
123 prevkey = KEY_UP; | |
124 } //fprintf(stderr,"KEY_UP\n");} | |
125 if ((keysd & KEY_DOWN)) { | 101 if ((keysd & KEY_DOWN)) { |
126 ax = 1; | 102 SDL_PrivateJoystickAxis(joystick, 1, magnitude); |
127 v = 10; | 103 } |
128 SDL_PrivateJoystickAxis(joystick, ax, v); | |
129 prevkey = KEY_DOWN; | |
130 } //fprintf(stderr,"KEY_DOWN\n");} | |
131 if ((keysd & KEY_LEFT)) { | 104 if ((keysd & KEY_LEFT)) { |
132 ax = 0; | 105 SDL_PrivateJoystickAxis(joystick, 0, -magnitude); |
133 h = -10; | 106 } |
134 SDL_PrivateJoystickAxis(joystick, ax, h); | |
135 prevkey = KEY_LEFT; | |
136 } //fprintf(stderr,"KEY_LEFT\n");} | |
137 if ((keysd & KEY_RIGHT)) { | 107 if ((keysd & KEY_RIGHT)) { |
138 ax = 0; | 108 SDL_PrivateJoystickAxis(joystick, 0, magnitude); |
139 h = 10; | |
140 SDL_PrivateJoystickAxis(joystick, ax, h); | |
141 prevkey = KEY_RIGHT; | |
142 } //fprintf(stderr,"KEY_RIGHT\n");} | |
143 | |
144 if ((keysu & KEY_UP)) { | |
145 ax = 1; | |
146 v = 0; | |
147 SDL_PrivateJoystickAxis(joystick, ax, v); | |
148 prevkey = NULL; | |
149 } //fprintf(stderr,"KEY_UP\n");} | |
150 if ((keysu & KEY_DOWN)) { | |
151 ax = 1; | |
152 v = 0; | |
153 SDL_PrivateJoystickAxis(joystick, ax, v); | |
154 prevkey = NULL; | |
155 } //fprintf(stderr,"KEY_DOWN\n");} | |
156 if ((keysu & KEY_LEFT)) { | |
157 ax = 0; | |
158 h = 0; | |
159 SDL_PrivateJoystickAxis(joystick, ax, h); | |
160 prevkey = NULL; | |
161 } //fprintf(stderr,"KEY_LEFT\n");} | |
162 if ((keysu & KEY_RIGHT)) { | |
163 ax = 0; | |
164 h = 0; | |
165 SDL_PrivateJoystickAxis(joystick, ax, h); | |
166 prevkey = NULL; | |
167 } //fprintf(stderr,"KEY_RIGHT\n");} | |
168 | |
169 if ((keysd & KEY_A)) { | |
170 SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); | |
171 prevbutton = KEY_A; | |
172 } | |
173 | |
174 if ((keysd & KEY_B)) { | |
175 SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED); | |
176 prevbutton = KEY_B; | |
177 } | |
178 | |
179 if ((keysd & KEY_X)) { | |
180 SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED); | |
181 prevbutton = KEY_X; | |
182 } | |
183 | |
184 if ((keysd & KEY_Y)) { | |
185 SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED); | |
186 prevbutton = KEY_Y; | |
187 } | |
188 | |
189 if ((keysd & KEY_SELECT)) { | |
190 SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED); | |
191 prevbutton = KEY_SELECT; | |
192 } | |
193 | |
194 if ((keysd & KEY_START)) { | |
195 SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED); | |
196 prevbutton = KEY_START; | |
197 } | |
198 | |
199 if ((keysd & KEY_L)) { | |
200 SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED); | |
201 prevbutton = KEY_L; | |
202 } | |
203 | |
204 if ((keysd & KEY_R)) { | |
205 SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED); | |
206 prevbutton = KEY_R; | |
207 } | |
208 | |
209 | |
210 if ((keysu & KEY_A)) { | |
211 SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); | |
212 prevbutton = NULL; | |
213 } | |
214 | |
215 if ((keysu & KEY_B)) { | |
216 SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED); | |
217 prevbutton = NULL; | |
218 } | |
219 | |
220 if ((keysu & KEY_X)) { | |
221 SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED); | |
222 prevbutton = NULL; | |
223 } | |
224 | |
225 if ((keysu & KEY_Y)) { | |
226 SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED); | |
227 prevbutton = NULL; | |
228 } | |
229 | |
230 if ((keysu & KEY_SELECT)) { | |
231 SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED); | |
232 prevbutton = NULL; | |
233 } | |
234 | |
235 if ((keysu & KEY_START)) { | |
236 SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED); | |
237 prevbutton = NULL; | |
238 } | |
239 | |
240 if ((keysu & KEY_L)) { | |
241 SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED); | |
242 prevbutton = NULL; | |
243 } | |
244 | |
245 if ((keysu & KEY_R)) { | |
246 SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED); | |
247 prevbutton = NULL; | |
248 } | 109 } |
249 | 110 |
111 if ((keysu & (KEY_UP|KEY_DOWN))) { | |
112 SDL_PrivateJoystickAxis(joystick, 1, 0); | |
113 } | |
114 if ((keysu & (KEY_LEFT|KEY_RIGHT))) { | |
115 SDL_PrivateJoystickAxis(joystick, 0, 0); | |
116 } | |
250 | 117 |
118 if ((keysd & KEY_A)) { | |
119 SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); | |
120 } | |
121 if ((keysd & KEY_B)) { | |
122 SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED); | |
123 } | |
124 if ((keysd & KEY_X)) { | |
125 SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED); | |
126 } | |
127 if ((keysd & KEY_Y)) { | |
128 SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED); | |
129 } | |
130 | |
131 if ((keysd & KEY_L)) { | |
132 SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED); | |
133 } | |
134 if ((keysd & KEY_R)) { | |
135 SDL_PrivateJoystickButton(joystick, 5, SDL_PRESSED); | |
136 } | |
137 | |
138 if ((keysd & KEY_SELECT)) { | |
139 SDL_PrivateJoystickButton(joystick, 6, SDL_PRESSED); | |
140 } | |
141 if ((keysd & KEY_START)) { | |
142 SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED); | |
143 } | |
144 | |
145 if ((keysu & KEY_A)) { | |
146 SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); | |
147 } | |
148 if ((keysu & KEY_B)) { | |
149 SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED); | |
150 } | |
151 if ((keysu & KEY_X)) { | |
152 SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED); | |
153 } | |
154 if ((keysu & KEY_Y)) { | |
155 SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED); | |
156 } | |
157 | |
158 if ((keysu & KEY_L)) { | |
159 SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED); | |
160 } | |
161 if ((keysu & KEY_R)) { | |
162 SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED); | |
163 } | |
164 | |
165 if ((keysu & KEY_SELECT)) { | |
166 SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED); | |
167 } | |
168 if ((keysu & KEY_START)) { | |
169 SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED); | |
170 } | |
251 } | 171 } |
252 | 172 |
253 /* Function to close a joystick after use */ | 173 /* Function to close a joystick after use */ |
254 void | 174 void |
255 SDL_SYS_JoystickClose(SDL_Joystick * joystick) | 175 SDL_SYS_JoystickClose(SDL_Joystick * joystick) |
259 /* Function to perform any system-specific joystick related cleanup */ | 179 /* Function to perform any system-specific joystick related cleanup */ |
260 void | 180 void |
261 SDL_SYS_JoystickQuit(void) | 181 SDL_SYS_JoystickQuit(void) |
262 { | 182 { |
263 } | 183 } |
184 #endif /* SDL_JOYSTICK_NDS */ | |
185 |