From 722d5509178fa5bdaa488fbbd9196f21377f8775 Mon Sep 17 00:00:00 2001 From: Ben Bridle Date: Mon, 18 Nov 2024 14:57:19 +1300 Subject: Initial commit --- arm9/source/devices/input.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 arm9/source/devices/input.c (limited to 'arm9/source/devices/input.c') 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 +#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; + } + } +} -- cgit v1.2.3-70-g09d2