From: Alan Cox Date: Fri, 6 Jul 2018 23:40:36 +0000 (+0100) Subject: trs80: introduce new files for input device handling X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=f5074b59709d7d772043016546b88b25c295c65c;p=FUZIX.git trs80: introduce new files for input device handling --- diff --git a/Kernel/platform-trs80/devinput.c b/Kernel/platform-trs80/devinput.c new file mode 100644 index 00000000..3e22a8d9 --- /dev/null +++ b/Kernel/platform-trs80/devinput.c @@ -0,0 +1,74 @@ +#include +#include +#include +#include + +__sfr __at 0x00 stick; +uint8_t old_stick; + +static char buf[32]; +static struct s_queue kqueue = { + buf, buf, buf, sizeof(buf), 0, sizeof(buf) / 2 +}; + +/* Queue a character to the input device */ +void queue_input(uint8_t c) +{ + insq(&kqueue, c); + wakeup(&kqueue); +} + +int platform_input_read(uint8_t *slot) +{ + uint8_t r, k; + if (remq(&kqueue, &r)) { + remq(&kqueue, &k); + *slot++ = KEYPRESS_CODE | r; + *slot++ = k; + return 2; + } + + r = ~stick; + if (r == old_stick) + return 0; + + old_stick = r; + + k = 0; + /* Legacy joystick encoding U|D = FIRE */ + if ((r & 3) == 3) { + r &= ~3; + r |= 16; + } + if (r & 1) + k = STICK_DIGITAL_U; + if (r & 2) + k |= STICK_DIGITAL_D; + if (r & 4) + k |= STICK_DIGITAL_L; + if (r & 8) + k |= STICK_DIGITAL_R; + if (r & 16) + k |= BUTTON(0); + *slot++ = STICK_DIGITAL; + *slot++ = k; + return 2; +} + +void platform_input_wait(void) +{ + psleep(&kqueue); /* We wake this on timers so it works for sticks */ +} + +int platform_input_write(uint8_t flag) +{ + flag; + udata.u_error = EINVAL; + return -1; +} + +void poll_input(void) +{ + if (~stick != old_stick) + wakeup(&kqueue); +} diff --git a/Kernel/platform-trs80/devinput.h b/Kernel/platform-trs80/devinput.h new file mode 100644 index 00000000..5d79a9e0 --- /dev/null +++ b/Kernel/platform-trs80/devinput.h @@ -0,0 +1,4 @@ + +extern void queue_input(uint8_t c); +extern void poll_input(void); +extern uint8_t vblank;