From 0532e04a9e273f2a9033a28cdbce1030a91c5bb4 Mon Sep 17 00:00:00 2001 From: Daniel Hader Date: Sun, 23 Aug 2026 20:25:36 -0500 Subject: initial commit working tile demo --- source/input.hpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 source/input.hpp (limited to 'source/input.hpp') 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(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; } -- cgit v1.2.3