Mercurial > sdl-ios-xcode
comparison src/joystick/nds/SDL_sysjoystick.c @ 2735:204be4fc2726
Final merge of Google Summer of Code 2008 work...
Port SDL 1.3 to the Nintendo DS
by Darren Alton, mentored by Sam Lantinga
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Wed, 27 Aug 2008 15:10:03 +0000 |
parents | |
children | 1c5f440a60fe |
comparison
equal
deleted
inserted
replaced
2734:dd25eabe441c | 2735:204be4fc2726 |
---|---|
1 /* | |
2 SDL - Simple DirectMedia Layer | |
3 Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga | |
4 | |
5 This library is free software; you can redistribute it and/or | |
6 modify it under the terms of the GNU Library General Public | |
7 License as published by the Free Software Foundation; either | |
8 version 2 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 Library General Public License for more details. | |
14 | |
15 You should have received a copy of the GNU Library General Public | |
16 License along with this library; if not, write to the Free | |
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 | |
19 Sam Lantinga | |
20 slouken@devolution.com | |
21 */ | |
22 | |
23 #include "SDL_config.h" | |
24 | |
25 #ifdef SDL_JOYSTICK_NDS | |
26 | |
27 /* This is the system specific header for the SDL joystick API */ | |
28 #include <nds.h> | |
29 #include <stdio.h> /* For the definition of NULL */ | |
30 | |
31 #include "SDL_error.h" | |
32 #include "SDL_events.h" | |
33 #include "SDL_joystick.h" | |
34 #include "SDL_sysjoystick.h" | |
35 #include "SDL_joystick_c.h" | |
36 | |
37 #include "../../video/nds/SDL_ndsevents_c.h" | |
38 | |
39 /* Function to scan the system for joysticks. | |
40 * This function should set SDL_numjoysticks to the number of available | |
41 * joysticks. Joystick 0 should be the system default joystick. | |
42 * It should return 0, or -1 on an unrecoverable fatal error. | |
43 */ | |
44 int | |
45 SDL_SYS_JoystickInit(void) | |
46 { | |
47 SDL_numjoysticks = 1; | |
48 | |
49 return (1); | |
50 } | |
51 | |
52 /* Function to get the device-dependent name of a joystick */ | |
53 const char * | |
54 SDL_SYS_JoystickName(int index) | |
55 { | |
56 if (!index) | |
57 return "NDS builtin joypad"; | |
58 SDL_SetError("No joystick available with that index"); | |
59 return (NULL); | |
60 } | |
61 | |
62 /* Function to open a joystick for use. | |
63 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. | |
65 It returns 0, or -1 if there is an error. | |
66 */ | |
67 int | |
68 SDL_SYS_JoystickOpen(SDL_Joystick * joystick) | |
69 { | |
70 joystick->nbuttons = 8; | |
71 joystick->nhats = 0; | |
72 joystick->nballs = 0; | |
73 joystick->naxes = 2; | |
74 return 0; | |
75 } | |
76 | |
77 | |
78 /* Function to update the state of a joystick - called as a device poll. | |
79 * This function shouldn't update the joystick structure directly, | |
80 * but instead should call SDL_PrivateJoystick*() to deliver events | |
81 * and update joystick device state. | |
82 */ | |
83 void | |
84 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick) | |
85 { | |
86 u32 keysd, keysu; | |
87 int magnitude = 16384; | |
88 | |
89 /*scanKeys(); */ | |
90 keysd = keysDown(); | |
91 keysu = keysUp(); | |
92 | |
93 if ((keysd & KEY_UP)) { | |
94 SDL_PrivateJoystickAxis(joystick, 1, -magnitude); | |
95 } | |
96 if ((keysd & KEY_DOWN)) { | |
97 SDL_PrivateJoystickAxis(joystick, 1, magnitude); | |
98 } | |
99 if ((keysd & KEY_LEFT)) { | |
100 SDL_PrivateJoystickAxis(joystick, 0, -magnitude); | |
101 } | |
102 if ((keysd & KEY_RIGHT)) { | |
103 SDL_PrivateJoystickAxis(joystick, 0, magnitude); | |
104 } | |
105 | |
106 if ((keysu & (KEY_UP | KEY_DOWN))) { | |
107 SDL_PrivateJoystickAxis(joystick, 1, 0); | |
108 } | |
109 | |
110 if ((keysu & (KEY_LEFT | KEY_RIGHT))) { | |
111 SDL_PrivateJoystickAxis(joystick, 0, 0); | |
112 } | |
113 | |
114 if ((keysd & KEY_A)) { | |
115 SDL_PrivateJoystickButton(joystick, 0, SDL_PRESSED); | |
116 } | |
117 | |
118 if ((keysd & KEY_B)) { | |
119 SDL_PrivateJoystickButton(joystick, 1, SDL_PRESSED); | |
120 } | |
121 | |
122 if ((keysd & KEY_X)) { | |
123 SDL_PrivateJoystickButton(joystick, 2, SDL_PRESSED); | |
124 } | |
125 | |
126 if ((keysd & KEY_Y)) { | |
127 SDL_PrivateJoystickButton(joystick, 3, SDL_PRESSED); | |
128 } | |
129 | |
130 if ((keysd & KEY_L)) { | |
131 SDL_PrivateJoystickButton(joystick, 4, SDL_PRESSED); | |
132 } | |
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 | |
142 if ((keysd & KEY_START)) { | |
143 SDL_PrivateJoystickButton(joystick, 7, SDL_PRESSED); | |
144 } | |
145 | |
146 if ((keysu & KEY_A)) { | |
147 SDL_PrivateJoystickButton(joystick, 0, SDL_RELEASED); | |
148 } | |
149 | |
150 if ((keysu & KEY_B)) { | |
151 SDL_PrivateJoystickButton(joystick, 1, SDL_RELEASED); | |
152 } | |
153 | |
154 if ((keysu & KEY_X)) { | |
155 SDL_PrivateJoystickButton(joystick, 2, SDL_RELEASED); | |
156 } | |
157 | |
158 if ((keysu & KEY_Y)) { | |
159 SDL_PrivateJoystickButton(joystick, 3, SDL_RELEASED); | |
160 } | |
161 | |
162 if ((keysu & KEY_L)) { | |
163 SDL_PrivateJoystickButton(joystick, 4, SDL_RELEASED); | |
164 } | |
165 | |
166 if ((keysu & KEY_R)) { | |
167 SDL_PrivateJoystickButton(joystick, 5, SDL_RELEASED); | |
168 } | |
169 | |
170 if ((keysu & KEY_SELECT)) { | |
171 SDL_PrivateJoystickButton(joystick, 6, SDL_RELEASED); | |
172 } | |
173 | |
174 if ((keysu & KEY_START)) { | |
175 SDL_PrivateJoystickButton(joystick, 7, SDL_RELEASED); | |
176 } | |
177 | |
178 } | |
179 | |
180 /* Function to close a joystick after use */ | |
181 void | |
182 SDL_SYS_JoystickClose(SDL_Joystick * joystick) | |
183 { | |
184 } | |
185 | |
186 /* Function to perform any system-specific joystick related cleanup */ | |
187 void | |
188 SDL_SYS_JoystickQuit(void) | |
189 { | |
190 } | |
191 | |
192 #endif /* SDL_JOYSTICK_NDS */ |