blob: 2a2a3a27f2b3e7a04745fe0c7a273b24cefe26de (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#include "types.hpp"
typedef u16 KeyFlags;
enum Key : KeyFlags {
A = 0x0001,
B = 0x0002,
Select = 0x0004,
Start = 0x0008,
Right = 0x0010,
Left = 0x0020,
Up = 0x0040,
Down = 0x0080,
R = 0x0100,
L = 0x0200,
};
constexpr KeyFlags KEY_MASK = 0x03FF;
volatile KeyFlags* const REG_KEYINPUT = reinterpret_cast<volatile KeyFlags*>(0x04000130);
static inline KeyFlags &keyflags_curr() {
static KeyFlags keybits_curr = 0;
return keybits_curr;
}
static inline KeyFlags &keyflags_prev() {
static KeyFlags keybits_prev = 0;
return keybits_prev;
}
static inline void keyflags_poll() {
KeyFlags &prev = keyflags_prev();
KeyFlags &curr = keyflags_curr();
prev = curr;
curr = ~*REG_KEYINPUT & KEY_MASK;
}
static inline bool key_is_down(Key key) { return keyflags_curr() & key; }
static inline bool key_is_up(Key key) { return ~keyflags_curr() & key; }
static inline bool key_was_down(Key key) { return keyflags_prev() & key; }
static inline bool key_was_up(Key key) { return ~keyflags_prev() & key; }
|