aboutsummaryrefslogtreecommitdiff
path: root/src/joy.c
diff options
context:
space:
mode:
authorJuan J. Martinez <jjm@usebox.net>2023-08-12 13:19:31 +0100
committerJuan J. Martinez <jjm@usebox.net>2023-08-12 13:19:31 +0100
commitac70ede342a9074c1896b62729440e88cbfe1c87 (patch)
tree59f3306f7f2c2ed5842142312e5b5a0361720f2b /src/joy.c
parent3e1c7be361aff6803393b010bbb68bd7b2480ddb (diff)
downloadgold-mine-run-ac70ede342a9074c1896b62729440e88cbfe1c87.tar.gz
gold-mine-run-ac70ede342a9074c1896b62729440e88cbfe1c87.zip
Reads must be signed, also potential issue reading buttons
Diffstat (limited to 'src/joy.c')
-rw-r--r--src/joy.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/joy.c b/src/joy.c
index 4910f16..31c8982 100644
--- a/src/joy.c
+++ b/src/joy.c
@@ -18,9 +18,9 @@
#define TIMEOUT 16000
-static uint16_t j_up, j_down, j_left, j_right;
+static int16_t j_up, j_down, j_left, j_right;
-static uint16_t read_axis(uint8_t axis)
+static int16_t read_axis(uint8_t axis)
{
uint16_t i;
@@ -34,7 +34,7 @@ static uint16_t read_axis(uint8_t axis)
return i;
}
-static uint8_t calibrate(uint16_t *v, uint16_t *h)
+static uint8_t calibrate(int16_t *v, int16_t *h)
{
while (1)
{
@@ -48,6 +48,7 @@ static uint8_t calibrate(uint16_t *v, uint16_t *h)
*v = read_axis(AXISY);
*h = read_axis(AXISX);
+ outportb(PORT, 0xff);
if (!(inportb(PORT) & BUTTON1))
{
while (!(inportb(PORT) & BUTTON1))
@@ -66,7 +67,7 @@ uint8_t joy_detect()
printf("Joystick detected!\n");
- uint16_t cx, cy;
+ int16_t cx, cy;
printf("Please center the joystick and press BUTTON 1 (ESC to abort)\n");
if (!calibrate(&cy, &cx))
return 0;
@@ -103,8 +104,9 @@ uint8_t joy_read()
{
uint8_t r = CTL_NONE;
uint8_t b;
- uint16_t v;
+ int16_t v;
+ outportb(PORT, 0xff);
b = inportb(PORT);
if (!(b & BUTTON1))
r |= CTL_FIRE1;