diff options
author | Ben Bridle <ben@derelict.engineering> | 2024-11-18 14:57:19 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2024-11-18 14:57:19 +1300 |
commit | 722d5509178fa5bdaa488fbbd9196f21377f8775 (patch) | |
tree | 112b39cd80cb8e074d9e71d1def4d8de33c9eefa /arm9/source/devices/input.c | |
download | bedrock-nds-722d5509178fa5bdaa488fbbd9196f21377f8775.zip |
Initial commit
Diffstat (limited to 'arm9/source/devices/input.c')
-rw-r--r-- | arm9/source/devices/input.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/arm9/source/devices/input.c b/arm9/source/devices/input.c new file mode 100644 index 0000000..a39f448 --- /dev/null +++ b/arm9/source/devices/input.c @@ -0,0 +1,59 @@ +#include <nds.h> +#include "../bang.h" +#include "input.h" + +// Read gamepad state into an input device. +void inp_read_gamepad(InputDevice *inp) { + u32 held = keysHeld(); + u8 gamepad = ( + TEST(held, KEY_UP) << 7 + | TEST(held, KEY_DOWN) << 6 + | TEST(held, KEY_LEFT) << 5 + | TEST(held, KEY_RIGHT) << 4 + | TEST(held, KEY_A) << 3 + | TEST(held, KEY_B) << 2 + | TEST(held, KEY_X) << 1 + | TEST(held, KEY_Y) << 0 + ); + if (gamepad != inp->gamepad) { + inp->wake = TRUE; + inp->gamepad = gamepad; + } +} + +// Read navigation state into an input device. +void inp_read_navigation(InputDevice *inp) { + u32 held = keysHeld(); + u8 navigation = ( + TEST(held, KEY_UP) << 7 + | TEST(held, KEY_DOWN) << 6 + | TEST(held, KEY_LEFT) << 5 + | TEST(held, KEY_RIGHT) << 4 + | TEST(held, KEY_A) << 3 + | TEST(held, KEY_B) << 2 + | TEST(held, KEY_R) << 1 + | TEST(held, KEY_L) << 0 + ); + if (navigation != inp->navigation) { + inp->wake = TRUE; + inp->navigation = navigation; + } +} + +// Read touchscreen state into an input device. +void inp_read_touch(InputDevice *inp) { + bool pointer = TEST(keysHeld(), KEY_TOUCH); + if (pointer != inp->pointer) { + inp->wake = TRUE; + inp->pointer = pointer; + } + if (pointer) { + touchPosition pos; + touchRead(&pos); + if (pos.px != inp->x || pos.py != inp->y) { + inp->wake = TRUE; + inp->x = pos.px; + inp->y = pos.py; + } + } +} |