diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-08-28 15:16:12 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-08-28 15:30:25 +0100 |
commit | e35cff6d299a07d9b34f303717083a9299a37e82 (patch) | |
tree | 7204099ad4978dfc67e04bc11df29d0f366af851 /src/control.c | |
download | uboxlib-dos-e35cff6d299a07d9b34f303717083a9299a37e82.tar.gz uboxlib-dos-e35cff6d299a07d9b34f303717083a9299a37e82.zip |
Initial import
Diffstat (limited to 'src/control.c')
-rw-r--r-- | src/control.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/control.c b/src/control.c new file mode 100644 index 0000000..440ede7 --- /dev/null +++ b/src/control.c @@ -0,0 +1,36 @@ +#include <stdint.h> + +#include "ubox_keyb.h" +#include "ubox_joy.h" + +#include "ubox_control.h" + +static uint8_t joy = 0; + +void ubox_control_init() +{ + joy = ubox_joy_detect(); +} + +uint8_t ubox_control_read() +{ + uint8_t r = UBOX_CTL_NONE; + + if (ubox_keys[UBOX_KEY_UP]) + r |= UBOX_CTL_UP; + if (ubox_keys[UBOX_KEY_DOWN]) + r |= UBOX_CTL_DOWN; + if (ubox_keys[UBOX_KEY_LEFT]) + r |= UBOX_CTL_LEFT; + if (ubox_keys[UBOX_KEY_RIGHT]) + r |= UBOX_CTL_RIGHT; + if (ubox_keys[UBOX_KEY_Z]) + r |= UBOX_CTL_FIRE1; + if (ubox_keys[UBOX_KEY_X]) + r |= UBOX_CTL_FIRE2; + + if (joy) + r |= ubox_joy_read(); + + return r; +} |