1 | /*------------------------------------------------------------------------------ |
---|
2 | $Id$ |
---|
3 | |
---|
4 | key input code -- provides slightly higher level input forming |
---|
5 | |
---|
6 | Copyright (C) 2005 |
---|
7 | Christian Auby (DesktopMan) |
---|
8 | Dave Murphy (WinterMute) |
---|
9 | |
---|
10 | This software is provided 'as-is', without any express or implied |
---|
11 | warranty. In no event will the authors be held liable for any |
---|
12 | damages arising from the use of this software. |
---|
13 | |
---|
14 | Permission is granted to anyone to use this software for any |
---|
15 | purpose, including commercial applications, and to alter it and |
---|
16 | redistribute it freely, subject to the following restrictions: |
---|
17 | |
---|
18 | 1. The origin of this software must not be misrepresented; you |
---|
19 | must not claim that you wrote the original software. If you use |
---|
20 | this software in a product, an acknowledgment in the product |
---|
21 | documentation would be appreciated but is not required. |
---|
22 | 2. Altered source versions must be plainly marked as such, and |
---|
23 | must not be misrepresented as being the original software. |
---|
24 | 3. This notice may not be removed or altered from any source |
---|
25 | distribution. |
---|
26 | |
---|
27 | $Log$ |
---|
28 | Revision 1.1 2008/04/16 18:37:32 joel |
---|
29 | 2008-04-16 Matthieu Bucchianeri <mbucchia@gmail.com> |
---|
30 | |
---|
31 | * ChangeLog, Makefile.am, README, bsp_specs, configure.ac, |
---|
32 | mk_libnds.sh, patch.libnds, preinstall.am, block/block.c, |
---|
33 | clock/clock.c, console/console.c, coproc/coproc.S, coproc/coproc.c, |
---|
34 | coproc/coproc.ld, dswifi/dswifi_license.txt, dswifi/makefile, |
---|
35 | dswifi/arm7/makefile, dswifi/arm7/source/wifi_arm7.c, |
---|
36 | dswifi/arm7/source/wifi_arm7.h, dswifi/arm9/makefile, |
---|
37 | dswifi/arm9/source/sgIP.c, dswifi/arm9/source/sgIP.h, |
---|
38 | dswifi/arm9/source/sgIP_ARP.c, dswifi/arm9/source/sgIP_ARP.h, |
---|
39 | dswifi/arm9/source/sgIP_Config.h, dswifi/arm9/source/sgIP_DHCP.c, |
---|
40 | dswifi/arm9/source/sgIP_DHCP.h, dswifi/arm9/source/sgIP_DNS.c, |
---|
41 | dswifi/arm9/source/sgIP_DNS.h, dswifi/arm9/source/sgIP_Hub.c, |
---|
42 | dswifi/arm9/source/sgIP_Hub.h, dswifi/arm9/source/sgIP_ICMP.c, |
---|
43 | dswifi/arm9/source/sgIP_ICMP.h, dswifi/arm9/source/sgIP_IP.c, |
---|
44 | dswifi/arm9/source/sgIP_IP.h, dswifi/arm9/source/sgIP_TCP.c, |
---|
45 | dswifi/arm9/source/sgIP_TCP.h, dswifi/arm9/source/sgIP_UDP.c, |
---|
46 | dswifi/arm9/source/sgIP_UDP.h, dswifi/arm9/source/sgIP_memblock.c, |
---|
47 | dswifi/arm9/source/sgIP_memblock.h, |
---|
48 | dswifi/arm9/source/sgIP_sockets.c, dswifi/arm9/source/sgIP_sockets.h, |
---|
49 | dswifi/arm9/source/wifi_arm9.c, dswifi/arm9/source/wifi_arm9.h, |
---|
50 | dswifi/common/source/dsregs.h, dswifi/common/source/spinlock.h, |
---|
51 | dswifi/common/source/spinlock.s, dswifi/common/source/wifi_shared.h, |
---|
52 | dswifi/include/dswifi7.h, dswifi/include/dswifi9.h, |
---|
53 | dswifi/include/dswifi_version.h, dswifi/include/netdb.h, |
---|
54 | dswifi/include/sgIP_errno.h, dswifi/include/netinet/in.h, fb/fb.c, |
---|
55 | fb/fb.h, include/bsp.h, include/my_ipc.h, include/tm27.h, |
---|
56 | include/types.h, include/sys/iosupport.h, irq/irq.c, irq/irq.h, |
---|
57 | libfat/gba/include/fat.h, libfat/include/fat.h, |
---|
58 | libfat/nds/include/fat.h, libfat/source/bit_ops.h, |
---|
59 | libfat/source/cache.c, libfat/source/cache.h, libfat/source/common.h, |
---|
60 | libfat/source/directory.c, libfat/source/directory.h, |
---|
61 | libfat/source/fatdir.c, libfat/source/fatdir.h, |
---|
62 | libfat/source/fatfile.c, libfat/source/fatfile.h, |
---|
63 | libfat/source/file_allocation_table.c, |
---|
64 | libfat/source/file_allocation_table.h, libfat/source/filetime.c, |
---|
65 | libfat/source/filetime.h, libfat/source/libfat.c, |
---|
66 | libfat/source/mem_allocate.h, libfat/source/partition.c, |
---|
67 | libfat/source/partition.h, libfat/source/disc_io/disc.c, |
---|
68 | libfat/source/disc_io/disc.h, libfat/source/disc_io/disc_io.h, |
---|
69 | libfat/source/disc_io/io_cf_common.c, |
---|
70 | libfat/source/disc_io/io_cf_common.h, |
---|
71 | libfat/source/disc_io/io_dldi.h, libfat/source/disc_io/io_dldi.s, |
---|
72 | libfat/source/disc_io/io_efa2.c, libfat/source/disc_io/io_efa2.h, |
---|
73 | libfat/source/disc_io/io_fcsr.c, libfat/source/disc_io/io_fcsr.h, |
---|
74 | libfat/source/disc_io/io_m3_common.c, |
---|
75 | libfat/source/disc_io/io_m3_common.h, |
---|
76 | libfat/source/disc_io/io_m3cf.c, libfat/source/disc_io/io_m3cf.h, |
---|
77 | libfat/source/disc_io/io_m3sd.c, libfat/source/disc_io/io_m3sd.h, |
---|
78 | libfat/source/disc_io/io_mpcf.c, libfat/source/disc_io/io_mpcf.h, |
---|
79 | libfat/source/disc_io/io_njsd.c, libfat/source/disc_io/io_njsd.h, |
---|
80 | libfat/source/disc_io/io_nmmc.c, libfat/source/disc_io/io_nmmc.h, |
---|
81 | libfat/source/disc_io/io_sc_common.c, |
---|
82 | libfat/source/disc_io/io_sc_common.h, |
---|
83 | libfat/source/disc_io/io_sccf.c, libfat/source/disc_io/io_sccf.h, |
---|
84 | libfat/source/disc_io/io_scsd.c, libfat/source/disc_io/io_scsd.h, |
---|
85 | libfat/source/disc_io/io_scsd_s.s, |
---|
86 | libfat/source/disc_io/io_sd_common.c, |
---|
87 | libfat/source/disc_io/io_sd_common.h, libnds/Makefile.arm7, |
---|
88 | libnds/Makefile.arm9, libnds/libnds_license.txt, |
---|
89 | libnds/basicARM7/source/defaultARM7.c, |
---|
90 | libnds/include/default_font_bin.h, libnds/include/gbfs.h, |
---|
91 | libnds/include/nds.h, libnds/include/nds/bios.h, |
---|
92 | libnds/include/nds/card.h, libnds/include/nds/dma.h, |
---|
93 | libnds/include/nds/interrupts.h, libnds/include/nds/ipc.h, |
---|
94 | libnds/include/nds/jtypes.h, libnds/include/nds/memory.h, |
---|
95 | libnds/include/nds/registers_alt.h, libnds/include/nds/reload.h, |
---|
96 | libnds/include/nds/system.h, libnds/include/nds/timers.h, |
---|
97 | libnds/include/nds/arm7/audio.h, libnds/include/nds/arm7/clock.h, |
---|
98 | libnds/include/nds/arm7/serial.h, libnds/include/nds/arm7/touch.h, |
---|
99 | libnds/include/nds/arm9/background.h, |
---|
100 | libnds/include/nds/arm9/boxtest.h, libnds/include/nds/arm9/cache.h, |
---|
101 | libnds/include/nds/arm9/console.h, |
---|
102 | libnds/include/nds/arm9/exceptions.h, |
---|
103 | libnds/include/nds/arm9/image.h, libnds/include/nds/arm9/input.h, |
---|
104 | libnds/include/nds/arm9/math.h, libnds/include/nds/arm9/ndsmotion.h, |
---|
105 | libnds/include/nds/arm9/pcx.h, libnds/include/nds/arm9/postest.h, |
---|
106 | libnds/include/nds/arm9/rumble.h, libnds/include/nds/arm9/sound.h, |
---|
107 | libnds/include/nds/arm9/sprite.h, libnds/include/nds/arm9/trig_lut.h, |
---|
108 | libnds/include/nds/arm9/video.h, libnds/include/nds/arm9/videoGL.h, |
---|
109 | libnds/source/arm7/audio.c, libnds/source/arm7/clock.c, |
---|
110 | libnds/source/arm7/microphone.c, libnds/source/arm7/spi.c, |
---|
111 | libnds/source/arm7/touch.c, libnds/source/arm7/userSettings.c, |
---|
112 | libnds/source/arm9/COS.bin, libnds/source/arm9/COS.s, |
---|
113 | libnds/source/arm9/SIN.bin, libnds/source/arm9/SIN.s, |
---|
114 | libnds/source/arm9/TAN.bin, libnds/source/arm9/TAN.s, |
---|
115 | libnds/source/arm9/boxtest.c, libnds/source/arm9/console.c, |
---|
116 | libnds/source/arm9/dcache.s, libnds/source/arm9/default_font.bin, |
---|
117 | libnds/source/arm9/default_font.s, |
---|
118 | libnds/source/arm9/exceptionHandler.S, |
---|
119 | libnds/source/arm9/exceptionHandler.s, |
---|
120 | libnds/source/arm9/exceptions.c, libnds/source/arm9/gurumeditation.c, |
---|
121 | libnds/source/arm9/icache.s, libnds/source/arm9/image.c, |
---|
122 | libnds/source/arm9/initSystem.c, libnds/source/arm9/keys.c, |
---|
123 | libnds/source/arm9/ndsmotion.c, libnds/source/arm9/pcx.c, |
---|
124 | libnds/source/arm9/rumble.c, libnds/source/arm9/sound.c, |
---|
125 | libnds/source/arm9/system.c, libnds/source/arm9/touch.c, |
---|
126 | libnds/source/arm9/video.c, libnds/source/arm9/videoGL.c, |
---|
127 | libnds/source/common/biosCalls.s, libnds/source/common/card.c, |
---|
128 | libnds/source/common/gbfs.c, |
---|
129 | libnds/source/common/interruptDispatcher.s, |
---|
130 | libnds/source/common/interrupts.c, rtc/rtc.c, sound/sound.c, |
---|
131 | sound/sound.h, start/start.S, startup/linkcmds, startup/start.c, |
---|
132 | timer/timer.c, tools/Makefile.am, tools/bin2s, tools/bin2s.c, |
---|
133 | tools/configure.ac, tools/runtest, |
---|
134 | tools/ndstool/include/arm7_sha1_homebrew.h, |
---|
135 | tools/ndstool/include/arm7_sha1_nintendo.h, |
---|
136 | tools/ndstool/include/banner.h, tools/ndstool/include/bigint.h, |
---|
137 | tools/ndstool/include/crc.h, tools/ndstool/include/default_icon.h, |
---|
138 | tools/ndstool/include/encryption.h, tools/ndstool/include/header.h, |
---|
139 | tools/ndstool/include/hook.h, tools/ndstool/include/little.h, |
---|
140 | tools/ndstool/include/loadme.h, tools/ndstool/include/logo.h, |
---|
141 | tools/ndstool/include/ndscreate.h, |
---|
142 | tools/ndstool/include/ndsextract.h, tools/ndstool/include/ndstool.h, |
---|
143 | tools/ndstool/include/ndstree.h, tools/ndstool/include/overlay.h, |
---|
144 | tools/ndstool/include/passme.h, tools/ndstool/include/passme_sram.h, |
---|
145 | tools/ndstool/include/passme_vhd1.h, |
---|
146 | tools/ndstool/include/passme_vhd2.h, tools/ndstool/include/raster.h, |
---|
147 | tools/ndstool/include/sha1.h, tools/ndstool/include/types.h, |
---|
148 | tools/ndstool/source/arm7_sha1_homebrew.c, |
---|
149 | tools/ndstool/source/arm7_sha1_nintendo.c, |
---|
150 | tools/ndstool/source/banner.cpp, tools/ndstool/source/bigint.cpp, |
---|
151 | tools/ndstool/source/compile_date.c, tools/ndstool/source/crc.cpp, |
---|
152 | tools/ndstool/source/default_icon.c, |
---|
153 | tools/ndstool/source/encryption.cpp, tools/ndstool/source/header.cpp, |
---|
154 | tools/ndstool/source/hook.cpp, tools/ndstool/source/loadme.c, |
---|
155 | tools/ndstool/source/logo.cpp, tools/ndstool/source/ndscodes.cpp, |
---|
156 | tools/ndstool/source/ndscreate.cpp, |
---|
157 | tools/ndstool/source/ndsextract.cpp, |
---|
158 | tools/ndstool/source/ndstool.cpp, tools/ndstool/source/ndstree.cpp, |
---|
159 | tools/ndstool/source/passme.cpp, tools/ndstool/source/passme_sram.c, |
---|
160 | tools/ndstool/source/raster.cpp, tools/ndstool/source/sha1.cpp, |
---|
161 | touchscreen/README.reco, touchscreen/parser.c, touchscreen/reco.c, |
---|
162 | touchscreen/reco.h, touchscreen/touchscreen.c, |
---|
163 | touchscreen/touchscreen.h, wifi/compat.c, wifi/compat.h, wifi/wifi.c: |
---|
164 | New files. |
---|
165 | |
---|
166 | Revision 1.15 2006/07/04 01:45:31 wntrmute |
---|
167 | remove unused variables |
---|
168 | |
---|
169 | Revision 1.14 2006/07/02 17:36:51 wntrmute |
---|
170 | remove unnecessary IPC reads |
---|
171 | |
---|
172 | Revision 1.13 2006/01/12 09:10:47 wntrmute |
---|
173 | Added key repeat as suggested by pepsiman |
---|
174 | |
---|
175 | Revision 1.12 2005/11/27 12:30:25 wntrmute |
---|
176 | reverted to correct hardware REGisters |
---|
177 | |
---|
178 | Revision 1.11 2005/11/27 07:48:45 joatski |
---|
179 | Renamed REG_KEYINPUT and REG_KEYCNT back to KEYS and KEYS_CR, as the alternatives are defined in registers_alt.h. |
---|
180 | Changed function returns to uint32 |
---|
181 | |
---|
182 | Revision 1.10 2005/11/03 23:38:49 wntrmute |
---|
183 | don't use enum for key function returns |
---|
184 | |
---|
185 | Revision 1.9 2005/10/13 16:30:11 dovoto |
---|
186 | Changed KEYPAD_BITS to a typedef enum, this resolved some issues with multiple redefinition of KEYPAD_BITS (although this error did not allways occur). |
---|
187 | |
---|
188 | Revision 1.8 2005/10/03 21:21:59 wntrmute |
---|
189 | use enum types |
---|
190 | |
---|
191 | Revision 1.7 2005/09/07 18:06:27 wntrmute |
---|
192 | use new register names |
---|
193 | |
---|
194 | Revision 1.6 2005/08/23 17:06:10 wntrmute |
---|
195 | converted all endings to unix |
---|
196 | |
---|
197 | Revision 1.5 2005/08/03 18:07:55 wntrmute |
---|
198 | don't use nds.h |
---|
199 | |
---|
200 | Revision 1.4 2005/07/25 02:31:07 wntrmute |
---|
201 | made local variables static |
---|
202 | added proper header to keys.h |
---|
203 | |
---|
204 | Revision 1.3 2005/07/25 02:19:01 desktopman |
---|
205 | Added support for KEY_LID in keys.c. |
---|
206 | Moved KEYS_CUR from header to source file. |
---|
207 | Changed from the custom abs() to stdlib.h's abs(). |
---|
208 | |
---|
209 | Revision 1.2 2005/07/14 08:00:57 wntrmute |
---|
210 | resynchronise with ndslib |
---|
211 | |
---|
212 | |
---|
213 | ------------------------------------------------------------------------------*/ |
---|
214 | |
---|
215 | #include <stdlib.h> |
---|
216 | |
---|
217 | #include <nds/ipc.h> |
---|
218 | #include <nds/system.h> |
---|
219 | #include <nds/arm9/input.h> |
---|
220 | |
---|
221 | //------------------------------------------------------------------------------ |
---|
222 | |
---|
223 | #define KEYS_CUR (( ((~REG_KEYINPUT)&0x3ff) | (((~IPC->buttons)&3)<<10) | (((~IPC->buttons)<<6) & (KEY_TOUCH|KEY_LID) ))^KEY_LID) |
---|
224 | |
---|
225 | static uint16 keys = 0; |
---|
226 | static uint16 keysold = 0; |
---|
227 | static uint16 keysrepeat = 0; |
---|
228 | |
---|
229 | static u8 delay = 60, repeat = 30, count = 60; |
---|
230 | |
---|
231 | //------------------------------------------------------------------------------ |
---|
232 | void scanKeys(void) { |
---|
233 | //------------------------------------------------------------------------------ |
---|
234 | keysold = keys; |
---|
235 | keys = KEYS_CUR; |
---|
236 | |
---|
237 | if ( delay != 0 ) { |
---|
238 | if ( keys != keysold ) { |
---|
239 | count = delay ; |
---|
240 | keysrepeat = keysDown() ; |
---|
241 | } |
---|
242 | count--; |
---|
243 | if ( count == 0 ) { |
---|
244 | count = repeat; |
---|
245 | keysrepeat = keys; |
---|
246 | } |
---|
247 | } |
---|
248 | } |
---|
249 | |
---|
250 | //------------------------------------------------------------------------------ |
---|
251 | uint32 keysHeld(void) { |
---|
252 | //------------------------------------------------------------------------------ |
---|
253 | return keys; |
---|
254 | } |
---|
255 | |
---|
256 | //------------------------------------------------------------------------------ |
---|
257 | uint32 keysDown(void) { |
---|
258 | //------------------------------------------------------------------------------ |
---|
259 | return (keys ^ keysold) & keys; |
---|
260 | } |
---|
261 | |
---|
262 | //------------------------------------------------------------------------------ |
---|
263 | uint32 keysDownRepeat(void) { |
---|
264 | //------------------------------------------------------------------------------ |
---|
265 | uint32 tmp = keysrepeat; |
---|
266 | |
---|
267 | keysrepeat = 0; |
---|
268 | |
---|
269 | return tmp; |
---|
270 | } |
---|
271 | |
---|
272 | //------------------------------------------------------------------------------ |
---|
273 | void keysSetRepeat( u8 setDelay, u8 setRepeat ) { |
---|
274 | //------------------------------------------------------------------------------ |
---|
275 | delay = setDelay ; |
---|
276 | repeat = setRepeat ; |
---|
277 | count = delay ; |
---|
278 | keysrepeat = 0 ; |
---|
279 | } |
---|
280 | |
---|
281 | //------------------------------------------------------------------------------ |
---|
282 | uint32 keysUp(void) { |
---|
283 | //------------------------------------------------------------------------------ |
---|
284 | return (keys ^ keysold) & (~keys); |
---|
285 | } |
---|