summaryrefslogtreecommitdiff
path: root/source/input.hpp
diff options
context:
space:
mode:
authorDaniel Hader <[email protected]>2026-08-23 20:25:36 -0500
committerDaniel Hader <[email protected]>2026-08-23 20:25:36 -0500
commit0532e04a9e273f2a9033a28cdbce1030a91c5bb4 (patch)
tree6e07d6bffeb834e01ff4cc18ec620ee265da8505 /source/input.hpp
initial commit working tile demo
Diffstat (limited to 'source/input.hpp')
-rw-r--r--source/input.hpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/source/input.hpp b/source/input.hpp
new file mode 100644
index 0000000..2a2a3a2
--- /dev/null
+++ b/source/input.hpp
@@ -0,0 +1,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; }