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 | ------------------------------------------------------------------------------*/ |
---|
28 | |
---|
29 | #include <stdlib.h> |
---|
30 | |
---|
31 | #include <nds/ipc.h> |
---|
32 | #include <nds/system.h> |
---|
33 | #include <nds/arm9/input.h> |
---|
34 | |
---|
35 | //------------------------------------------------------------------------------ |
---|
36 | |
---|
37 | #define KEYS_CUR (( ((~REG_KEYINPUT)&0x3ff) | (((~IPC->buttons)&3)<<10) | (((~IPC->buttons)<<6) & (KEY_TOUCH|KEY_LID) ))^KEY_LID) |
---|
38 | |
---|
39 | static uint16 keys = 0; |
---|
40 | static uint16 keysold = 0; |
---|
41 | static uint16 keysrepeat = 0; |
---|
42 | |
---|
43 | static u8 delay = 60, repeat = 30, count = 60; |
---|
44 | |
---|
45 | //------------------------------------------------------------------------------ |
---|
46 | void scanKeys(void) { |
---|
47 | //------------------------------------------------------------------------------ |
---|
48 | keysold = keys; |
---|
49 | keys = KEYS_CUR; |
---|
50 | |
---|
51 | if ( delay != 0 ) { |
---|
52 | if ( keys != keysold ) { |
---|
53 | count = delay ; |
---|
54 | keysrepeat = keysDown() ; |
---|
55 | } |
---|
56 | count--; |
---|
57 | if ( count == 0 ) { |
---|
58 | count = repeat; |
---|
59 | keysrepeat = keys; |
---|
60 | } |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | //------------------------------------------------------------------------------ |
---|
65 | uint32 keysHeld(void) { |
---|
66 | //------------------------------------------------------------------------------ |
---|
67 | return keys; |
---|
68 | } |
---|
69 | |
---|
70 | //------------------------------------------------------------------------------ |
---|
71 | uint32 keysDown(void) { |
---|
72 | //------------------------------------------------------------------------------ |
---|
73 | return (keys ^ keysold) & keys; |
---|
74 | } |
---|
75 | |
---|
76 | //------------------------------------------------------------------------------ |
---|
77 | uint32 keysDownRepeat(void) { |
---|
78 | //------------------------------------------------------------------------------ |
---|
79 | uint32 tmp = keysrepeat; |
---|
80 | |
---|
81 | keysrepeat = 0; |
---|
82 | |
---|
83 | return tmp; |
---|
84 | } |
---|
85 | |
---|
86 | //------------------------------------------------------------------------------ |
---|
87 | void keysSetRepeat( u8 setDelay, u8 setRepeat ) { |
---|
88 | //------------------------------------------------------------------------------ |
---|
89 | delay = setDelay ; |
---|
90 | repeat = setRepeat ; |
---|
91 | count = delay ; |
---|
92 | keysrepeat = 0 ; |
---|
93 | } |
---|
94 | |
---|
95 | //------------------------------------------------------------------------------ |
---|
96 | uint32 keysUp(void) { |
---|
97 | //------------------------------------------------------------------------------ |
---|
98 | return (keys ^ keysold) & (~keys); |
---|
99 | } |
---|