diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-07-22 13:58:05 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-07-22 13:58:22 +0100 |
commit | 9ecd65467232071b18a7c6f782a22264046ebf45 (patch) | |
tree | 1a6110a495069900ac70b53d9d2746152aab1202 /src/control.c | |
parent | d6f7ac4c09ffb0717467790d9acc27df75e25b21 (diff) | |
download | gold-mine-run-9ecd65467232071b18a7c6f782a22264046ebf45.tar.gz gold-mine-run-9ecd65467232071b18a7c6f782a22264046ebf45.zip |
Joystick support
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..ee103f0 --- /dev/null +++ b/src/control.c @@ -0,0 +1,36 @@ +#include <stdint.h> + +#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; +} |