From 9ecd65467232071b18a7c6f782a22264046ebf45 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 22 Jul 2023 13:58:05 +0100 Subject: Joystick support --- src/control.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/control.c (limited to 'src/control.c') diff --git a/src/control.c b/src/control.c new file mode 100644 index 0000000..ee103f0 --- /dev/null +++ b/src/control.c @@ -0,0 +1,36 @@ +#include + +#include "keyb.h" +#include "joy.h" + +#include "control.h" + +static uint8_t joy = 0; + +void control_init() +{ + joy = joy_detect(); +} + +uint8_t control_read() +{ + uint8_t r = CTL_NONE; + + if (keys[KEY_UP]) + r |= CTL_UP; + if (keys[KEY_DOWN]) + r |= CTL_DOWN; + if (keys[KEY_LEFT]) + r |= CTL_LEFT; + if (keys[KEY_RIGHT]) + r |= CTL_RIGHT; + if (keys[KEY_Z]) + r |= CTL_FIRE1; + if (keys[KEY_X]) + r |= CTL_FIRE2; + + if (joy) + r |= joy_read(); + + return r; +} -- cgit v1.2.3