aboutsummaryrefslogtreecommitdiff
path: root/src/control.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-07-22 13:58:05 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-07-22 13:58:22 +0100
commit9ecd65467232071b18a7c6f782a22264046ebf45 (patch)
tree1a6110a495069900ac70b53d9d2746152aab1202 /src/control.c
parentd6f7ac4c09ffb0717467790d9acc27df75e25b21 (diff)
downloadgold-mine-run-9ecd65467232071b18a7c6f782a22264046ebf45.tar.gz
gold-mine-run-9ecd65467232071b18a7c6f782a22264046ebf45.zip
Joystick support
Diffstat (limited to 'src/control.c')
-rw-r--r--src/control.c36
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;
+}