Mercurial > sdl-ios-xcode
comparison src/joystick/nds/SDL_sysjoystick.c @ 2671:c3e7c0698cbb gsoc2008_nds
some changes to the dummy driver for debug purposes that should be reverted.
most importantly, commenting out a check for an env. var.
author | Darren Alton <dalton@stevens.edu> |
---|---|
date | Thu, 12 Jun 2008 02:38:49 +0000 |
parents | 6e4669f4db49 |
children | 24a6b3588eac |
comparison
equal
deleted
inserted
replaced
2670:6e4669f4db49 | 2671:c3e7c0698cbb |
---|---|
20 slouken@devolution.com | 20 slouken@devolution.com |
21 */ | 21 */ |
22 | 22 |
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 /* This is the system specific header for the SDL joystick API */ | 28 /* This is the system specific header for the SDL joystick API */ |
29 #include <nds.h> | 29 #include <nds.h> |
30 //#include <nds/registers_alt.h> | 30 //#include <nds/registers_alt.h> |
31 #include <stdio.h> /* For the definition of NULL */ | 31 #include <stdio.h> /* For the definition of NULL */ |
32 | 32 |
33 #include "SDL_error.h" | 33 #include "SDL_error.h" |
34 #include "SDL_joystick.h" | 34 #include "SDL_joystick.h" |
35 #include "SDL_sysjoystick.h" | 35 #include "SDL_sysjoystick.h" |
36 #include "SDL_joystick_c.h" | 36 #include "SDL_joystick_c.h" |
40 /* Function to scan the system for joysticks. | 40 /* Function to scan the system for joysticks. |
41 * This function should set SDL_numjoysticks to the number of available | 41 * This function should set SDL_numjoysticks to the number of available |
42 * joysticks. Joystick 0 should be the system default joystick. | 42 * joysticks. Joystick 0 should be the system default joystick. |
43 * It should return 0, or -1 on an unrecoverable fatal error. | 43 * It should return 0, or -1 on an unrecoverable fatal error. |
44 */ | 44 */ |
45 int SDL_SYS_JoystickInit(void) | 45 int |
46 { | 46 SDL_SYS_JoystickInit(void) |
47 SDL_numjoysticks = 1; | 47 { |
48 //keysInit(); | 48 SDL_numjoysticks = 1; |
49 | 49 |
50 return(1); | 50 //keysInit(); |
51 return (1); | |
51 } | 52 } |
52 | 53 |
53 /* Function to get the device-dependent name of a joystick */ | 54 /* Function to get the device-dependent name of a joystick */ |
54 const char *SDL_SYS_JoystickName(int index) | 55 const char * |
55 { | 56 SDL_SYS_JoystickName(int index) |
56 if(!index) | 57 { |
57 return "NDS builtin joypad"; | 58 if (!index) |
58 SDL_SetError("No joystick available with that index"); | 59 return "NDS builtin joypad"; |
59 return (NULL); | 60 SDL_SetError("No joystick available with that index"); |
61 return (NULL); | |
60 } | 62 } |
61 | 63 |
62 /* Function to open a joystick for use. | 64 /* Function to open a joystick for use. |
63 The joystick to open is specified by the index field of the joystick. | 65 The joystick to open is specified by the index field of the joystick. |
64 This should fill the nbuttons and naxes fields of the joystick structure. | 66 This should fill the nbuttons and naxes fields of the joystick structure. |
65 It returns 0, or -1 if there is an error. | 67 It returns 0, or -1 if there is an error. |
66 */ | 68 */ |
67 int SDL_SYS_JoystickOpen(SDL_Joystick *joystick) | 69 int |
68 { | 70 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) |
69 joystick->nbuttons=8; | 71 { |
70 joystick->nhats=0; | 72 joystick->nbuttons = 8; |
71 joystick->nballs=0; | 73 joystick->nhats = 0; |
72 joystick->naxes=2; | 74 joystick->nballs = 0; |
73 return 0; | 75 joystick->naxes = 2; |
76 return 0; | |
74 } | 77 } |
75 | 78 |
76 | 79 |
77 /* Function to update the state of a joystick - called as a device poll. | 80 /* Function to update the state of a joystick - called as a device poll. |
78 * This function shouldn't update the joystick structure directly, | 81 * This function shouldn't update the joystick structure directly, |
79 * but instead should call SDL_PrivateJoystick*() to deliver events | 82 * but instead should call SDL_PrivateJoystick*() to deliver events |
80 * and update joystick device state. | 83 * and update joystick device state. |
81 */ | 84 */ |
82 | 85 int prevbutton = 0; |
83 int prevbutton=0; | 86 int prevkey = 0; |
84 int prevkey=0; | 87 |
85 | 88 int dc = NULL; |
86 int dc=NULL;int ldc=0; | 89 int ldc = 0; |
87 u32 keysd,keysu=NULL; | 90 u32 keysd, keysu = NULL; |
88 void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick) | 91 void |
89 { | 92 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) |
90 //dc=keysd; | 93 { |
91 //if (dc != NULL) | 94 |
92 //{ | 95 //dc=keysd; |
93 //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); | 96 //if (dc != NULL) |
94 //swiWaitForVBlank(); | 97 //{ |
95 //scanKeys(); | 98 //fprintf(stderr,"heartbeat= %d\n",REG_VCOUNT); |
96 //keysd = keysDown(); | 99 //swiWaitForVBlank(); |
97 //keysu = keysUp(); | 100 //scanKeys(); |
98 //ldc=keysd; | 101 //keysd = keysDown(); |
99 | 102 //keysu = keysUp(); |
100 //} | 103 //ldc=keysd; |
101 /*if (prevkey !=NULL && prevbutton !=NULL) | 104 |
102 { | 105 //} |
103 scanKeys(); | 106 /*if (prevkey !=NULL && prevbutton !=NULL) |
104 } | 107 { |
105 */ | 108 scanKeys(); |
106 | 109 } |
107 //scanKeys(); | 110 */ |
108 keysd = keysDown(); | 111 |
109 keysu = keysUp(); | 112 //scanKeys(); |
110 | 113 keysd = keysDown(); |
111 | 114 |
112 short ax=0,v=0,h=0; | 115 keysu = keysUp(); |
113 if((keysd&KEY_UP)) {ax=1;v=-10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_UP;}//fprintf(stderr,"KEY_UP\n");} | 116 |
114 if((keysd&KEY_DOWN)) {ax=1;v=10;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=KEY_DOWN;}//fprintf(stderr,"KEY_DOWN\n");} | 117 |
115 if((keysd&KEY_LEFT)) {ax=0;h=-10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_LEFT;}//fprintf(stderr,"KEY_LEFT\n");} | 118 short ax = 0, v = 0, h = 0; |
116 if((keysd&KEY_RIGHT)) {ax=0;h=10;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=KEY_RIGHT;}//fprintf(stderr,"KEY_RIGHT\n");} | 119 if ((keysd & KEY_UP)) { |
117 | 120 ax = 1; |
118 if((keysu&KEY_UP)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_UP\n");} | 121 v = -10; |
119 if((keysu&KEY_DOWN)) {ax=1;v=0;SDL_PrivateJoystickAxis(joystick,ax,v);prevkey=NULL;}//fprintf(stderr,"KEY_DOWN\n");} | 122 SDL_PrivateJoystickAxis(joystick, ax, v); |
120 if((keysu&KEY_LEFT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_LEFT\n");} | 123 prevkey = KEY_UP; |
121 if((keysu&KEY_RIGHT)) {ax=0;h=0;SDL_PrivateJoystickAxis(joystick,ax,h);prevkey=NULL;}//fprintf(stderr,"KEY_RIGHT\n");} | 124 } //fprintf(stderr,"KEY_UP\n");} |
122 | 125 if ((keysd & KEY_DOWN)) { |
123 if((keysd&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_PRESSED);prevbutton=KEY_A;} | 126 ax = 1; |
124 if((keysd&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_PRESSED);prevbutton=KEY_B;} | 127 v = 10; |
125 if((keysd&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_PRESSED);prevbutton=KEY_X;} | 128 SDL_PrivateJoystickAxis(joystick, ax, v); |
126 if((keysd&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_PRESSED);prevbutton=KEY_Y;} | 129 prevkey = KEY_DOWN; |
127 if((keysd&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_PRESSED);prevbutton=KEY_SELECT;} | 130 } //fprintf(stderr,"KEY_DOWN\n");} |
128 if((keysd&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_PRESSED);prevbutton=KEY_START;} | 131 if ((keysd & KEY_LEFT)) { |
129 if((keysd&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_PRESSED);prevbutton=KEY_L;} | 132 ax = 0; |
130 if((keysd&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_PRESSED);prevbutton=KEY_R;} | 133 h = -10; |
131 | 134 SDL_PrivateJoystickAxis(joystick, ax, h); |
132 if((keysu&KEY_A)) {SDL_PrivateJoystickButton(joystick,0,SDL_RELEASED);prevbutton=NULL;} | 135 prevkey = KEY_LEFT; |
133 if((keysu&KEY_B)) {SDL_PrivateJoystickButton(joystick,1,SDL_RELEASED);prevbutton=NULL;} | 136 } //fprintf(stderr,"KEY_LEFT\n");} |
134 if((keysu&KEY_X)) {SDL_PrivateJoystickButton(joystick,2,SDL_RELEASED);prevbutton=NULL;} | 137 if ((keysd & KEY_RIGHT)) { |
135 if((keysu&KEY_Y)) {SDL_PrivateJoystickButton(joystick,3,SDL_RELEASED);prevbutton=NULL;} | 138 ax = 0; |
136 if((keysu&KEY_SELECT)) {SDL_PrivateJoystickButton(joystick,6,SDL_RELEASED);prevbutton=NULL;} | 139 h = 10; |
137 if((keysu&KEY_START)) {SDL_PrivateJoystickButton(joystick,7,SDL_RELEASED);prevbutton=NULL;} | 140 SDL_PrivateJoystickAxis(joystick, ax, h); |
138 if((keysu&KEY_L)) {SDL_PrivateJoystickButton(joystick,4,SDL_RELEASED);prevbutton=NULL;} | 141 prevkey = KEY_RIGHT; |
139 if((keysu&KEY_R)) {SDL_PrivateJoystickButton(joystick,5,SDL_RELEASED);prevbutton=NULL;} | 142 } //fprintf(stderr,"KEY_RIGHT\n");} |
140 | 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 } | |
141 | 249 |
142 | 250 |
143 } | 251 } |
144 | 252 |
145 /* Function to close a joystick after use */ | 253 /* Function to close a joystick after use */ |
146 void SDL_SYS_JoystickClose(SDL_Joystick *joystick) | 254 void |
255 SDL_SYS_JoystickClose(SDL_Joystick * joystick) | |
147 { | 256 { |
148 } | 257 } |
149 | 258 |
150 /* Function to perform any system-specific joystick related cleanup */ | 259 /* Function to perform any system-specific joystick related cleanup */ |
151 void SDL_SYS_JoystickQuit(void) | 260 void |
152 { | 261 SDL_SYS_JoystickQuit(void) |
153 } | 262 { |
154 | 263 } |