From ac70ede342a9074c1896b62729440e88cbfe1c87 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sat, 12 Aug 2023 13:19:31 +0100 Subject: Reads must be signed, also potential issue reading buttons --- src/joy.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/joy.c') 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; -- cgit v1.2.3