#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; }