comparison src/haptic/nds/SDL_syshaptic.c @ 2749:1c5f440a60fe

Initial work for NDS haptic support.
author Darren Alton <dalton@stevens.edu>
date Sat, 06 Sep 2008 00:10:16 +0000
parents
children e3affc66d963
comparison
equal deleted inserted replaced
2748:5668c3dfe7bc 2749:1c5f440a60fe
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 2008 Edgar Simo
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with this library; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
19 Sam Lantinga
20 slouken@libsdl.org
21 */
22 #include "SDL_config.h"
23
24 #ifdef SDL_HAPTIC_NDS
25
26 #include "SDL_haptic.h"
27 #include "../SDL_syshaptic.h"
28 #include "SDL_joystick.h"
29 #include <nds/arm9/rumble.h>
30 #include <nds/memory.h>
31
32 #define MAX_HAPTICS 1
33 /* right now only the ezf3in1 (and maybe official rumble pak) are supported
34 and there can only be one of those in at a time (in GBA slot.) */
35
36 SDL_Haptic *nds_haptic = NULL;
37
38 typedef struct
39 {
40 enum
41 { NONE, OFFICIAL, EZF3IN1 } type;
42 int pos;
43 } NDS_HapticData;
44
45
46
47 void NDS_EZF_OpenNorWrite()
48 {
49 GBA_BUS[0x0FF0000] = 0xD200;
50 GBA_BUS[0x0000000] = 0x1500;
51 GBA_BUS[0x0010000] = 0xD200;
52 GBA_BUS[0x0020000] = 0x1500;
53 GBA_BUS[0x0E20000] = 0x1500;
54 GBA_BUS[0x0FE0000] = 0x1500;
55 }
56
57
58 void NDS_EZF_CloseNorWrite()
59 {
60 GBA_BUS[0x0FF0000] = 0xD200;
61 GBA_BUS[0x0000000] = 0x1500;
62 GBA_BUS[0x0010000] = 0xD200;
63 GBA_BUS[0x0020000] = 0x1500;
64 GBA_BUS[0x0E20000] = 0xD200;
65 GBA_BUS[0x0FE0000] = 0x1500;
66 }
67
68 void NDS_EZF_ChipReset()
69 {
70 GBA_BUS[0x0000] = 0x00F0 ;
71 GBA_BUS[0x1000] = 0x00F0 ;
72 }
73 uint32 NDS_EZF_IsPresent()
74 {
75 vuint16 id1,id2;
76
77 NDS_EZF_OpenNorWrite();
78
79 GBA_BUS[0x0555] = 0x00AA;
80 GBA_BUS[0x02AA] = 0x0055;
81 GBA_BUS[0x0555] = 0x0090;
82 GBA_BUS[0x1555] = 0x00AA;
83 GBA_BUS[0x12AA] = 0x0055;
84 GBA_BUS[0x1555] = 0x0090;
85
86 id1 = GBA_BUS[0x0001];
87 id2 = GBA_BUS[0x1001];
88
89 if((id1!=0x227E)|| (id2!=0x227E)) {
90 NDS_EZF_CloseNorWrite();
91 return 0;
92 }
93
94 id1 = GBA_BUS[0x000E];
95 id2 = GBA_BUS[0x100E];
96
97 NDS_EZF_CloseNorWrite();
98
99 if(id1==0x2218 && id2==0x2218) {
100 return 1;
101 }
102
103 return 0;
104 }
105
106 void NDS_EZF_SetShake(u8 pos)
107 {
108 u16 data = ((pos%3)|0x00F0);
109
110 GBA_BUS[0x0FF0000] = 0xD200;
111 GBA_BUS[0x0000000] = 0x1500;
112 GBA_BUS[0x0010000] = 0xD200;
113 GBA_BUS[0x0020000] = 0x1500;
114 GBA_BUS[0x0F10000] = data;
115 GBA_BUS[0x0FE0000] = 0x1500;
116
117 GBA_BUS[0] = 0x0000; /* write any value for vibration. */
118 GBA_BUS[0] = 0x0002;
119 }
120
121 static int
122 SDL_SYS_LogicError(void)
123 {
124 SDL_SetError("Logic error: No haptic devices available.");
125 return 0;
126 }
127
128
129 int
130 SDL_SYS_HapticInit(void)
131 {
132 int ret = 0;
133 if(isRumbleInserted()) {
134 /* official rumble pak is present. */
135 ret = 1;
136 printf("debug: haptic present: nintendo\n");
137 } else if(NDS_EZF_IsPresent()) {
138 /* ezflash 3-in-1 pak is present. */
139 ret = 1;
140 printf("debug: haptic present: ezf3in1\n");
141 NDS_EZF_ChipReset();
142 } else {
143 printf("debug: no haptic found\n");
144 }
145
146 return ret;
147 }
148
149
150 const char *
151 SDL_SYS_HapticName(int index)
152 {
153 if(nds_haptic) {
154 switch(nds_haptic->hwdata->type) {
155 case OFFICIAL: return "Nintendo DS Rumble Pak";
156 case EZF3IN1: return "EZFlash 3-in-1 Rumble";
157 default: return NULL;
158 }
159 }
160 return NULL;
161 }
162
163
164 int
165 SDL_SYS_HapticOpen(SDL_Haptic * haptic)
166 {
167 if(!haptic) {
168 return -1;
169 }
170
171 haptic->hwdata = SDL_malloc(sizeof(NDS_HapticData));
172 if(!haptic->hwdata) {
173 SDL_OutOfMemory();
174 return -1;
175 }
176 nds_haptic = haptic;
177
178 haptic->supported = SDL_HAPTIC_CONSTANT;
179
180 /* determine what is here, if anything */
181 haptic->hwdata->type = NONE;
182 if(isRumbleInserted()) {
183 /* official rumble pak is present. */
184 haptic->hwdata->type = OFFICIAL;
185 } else if(NDS_EZF_IsPresent()) {
186 /* ezflash 3-in-1 pak is present. */
187 haptic->hwdata->type = EZF3IN1;
188 NDS_EZF_ChipReset();
189 } else {
190 /* no haptic present */
191 SDL_SYS_LogicError();
192 return -1;
193 }
194
195 return 0;
196 }
197
198
199 int
200 SDL_SYS_HapticMouse(void)
201 {
202 return -1;
203 }
204
205
206 int
207 SDL_SYS_JoystickIsHaptic(SDL_Joystick * joystick)
208 {
209 return 0;
210 }
211
212
213 int
214 SDL_SYS_HapticOpenFromJoystick(SDL_Haptic * haptic, SDL_Joystick * joystick)
215 {
216 /*SDL_SYS_LogicError();*/
217 return -1;
218 }
219
220
221 int
222 SDL_SYS_JoystickSameHaptic(SDL_Haptic * haptic, SDL_Joystick * joystick)
223 {
224 return 0;
225 }
226
227
228 void
229 SDL_SYS_HapticClose(SDL_Haptic * haptic)
230 {
231 return;
232 }
233
234
235 void
236 SDL_SYS_HapticQuit(void)
237 {
238 return;
239 }
240
241
242 int
243 SDL_SYS_HapticNewEffect(SDL_Haptic * haptic,
244 struct haptic_effect *effect, SDL_HapticEffect * base)
245 {
246 SDL_SYS_LogicError();
247 return -1;
248 }
249
250
251 int
252 SDL_SYS_HapticUpdateEffect(SDL_Haptic * haptic,
253 struct haptic_effect *effect,
254 SDL_HapticEffect * data)
255 {
256 SDL_SYS_LogicError();
257 return -1;
258 }
259
260
261 int
262 SDL_SYS_HapticRunEffect(SDL_Haptic * haptic, struct haptic_effect *effect,
263 Uint32 iterations)
264 {
265 SDL_SYS_LogicError();
266 return -1;
267 }
268
269
270 int
271 SDL_SYS_HapticStopEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
272 {
273 SDL_SYS_LogicError();
274 return -1;
275 }
276
277
278 void
279 SDL_SYS_HapticDestroyEffect(SDL_Haptic * haptic, struct haptic_effect *effect)
280 {
281 SDL_SYS_LogicError();
282 return;
283 }
284
285
286 int
287 SDL_SYS_HapticGetEffectStatus(SDL_Haptic * haptic,
288 struct haptic_effect *effect)
289 {
290 SDL_SYS_LogicError();
291 return -1;
292 }
293
294
295 int
296 SDL_SYS_HapticSetGain(SDL_Haptic * haptic, int gain)
297 {
298 SDL_SYS_LogicError();
299 return -1;
300 }
301
302
303 int
304 SDL_SYS_HapticSetAutocenter(SDL_Haptic * haptic, int autocenter)
305 {
306 SDL_SYS_LogicError();
307 return -1;
308 }
309
310 int
311 SDL_SYS_HapticPause(SDL_Haptic * haptic)
312 {
313 SDL_SYS_LogicError();
314 return -1;
315 }
316
317 int
318 SDL_SYS_HapticUnpause(SDL_Haptic * haptic)
319 {
320 SDL_SYS_LogicError();
321 return -1;
322 }
323
324 int
325 SDL_SYS_HapticStopAll(SDL_Haptic * haptic)
326 {
327 SDL_SYS_LogicError();
328 return -1;
329 }
330
331
332
333 #endif /* SDL_HAPTIC_NDS */
334 /* vi: set ts=4 sw=4 expandtab: */