From: Alan Cox Date: Fri, 6 Jul 2018 00:16:35 +0000 (+0100) Subject: trs80m1: add initial joystick/input device support X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=c6955342a569b007db49d5a6e2525301224c1ba0;p=FUZIX.git trs80m1: add initial joystick/input device support --- diff --git a/Kernel/platform-trs80m1/Makefile b/Kernel/platform-trs80m1/Makefile index e878e477..bb2e99d2 100644 --- a/Kernel/platform-trs80m1/Makefile +++ b/Kernel/platform-trs80m1/Makefile @@ -1,6 +1,6 @@ CSRCS = devlpr.c devtty.c devfd.c devfd3.c devhd.c devgfx.c -CSRCS += devices.c main.c devstringy.c +CSRCS += devices.c main.c devstringy.c devinput.c DISCARD_CSRCS = discard.c devhd_discard.c ASRCS = trs80.s trs80-bank.s crt0.s vtsupport.s diff --git a/Kernel/platform-trs80m1/README b/Kernel/platform-trs80m1/README index 482a6240..b625507d 100644 --- a/Kernel/platform-trs80m1/README +++ b/Kernel/platform-trs80m1/README @@ -4,7 +4,7 @@ This port supports the following configurations currently TRS80 model I with Alpha SuperMem (or compatibles), 256K+ recommended Options: - Floppy Disk + Floppy Disk (somewhat basic support, no format tool yet) Hard Disk (Tandy compatible) Lower Case Kit (Optional, either Tandy or the simple mods) Percom Compatible Doubler @@ -14,10 +14,10 @@ This port supports the following configurations currently In Progress: Exatron stringy + Alpha Products Joystick HR1G Graphics Card Planned: Orchestra 80 sound card - Alpha Products Joystick TRS80 model III with Alpha SuperMem (or compatibles), 256K+ recommended Options: @@ -28,6 +28,7 @@ This port supports the following configurations currently In Progress: Micro Labs Graphyx Tandy Hi-Res Card + Alpha Products Joystick Planned: Orchestra 90 sound card Lo-tech IDE adapter diff --git a/Kernel/platform-trs80m1/config.h b/Kernel/platform-trs80m1/config.h index e680de37..87a6b310 100644 --- a/Kernel/platform-trs80m1/config.h +++ b/Kernel/platform-trs80m1/config.h @@ -16,10 +16,14 @@ #define CONFIG_VT_MULTI /* Banked memory set up */ #define CONFIG_BANK_FIXED - +/* Direct I/O support */ #define CONFIG_LARGE_IO_DIRECT +/* Raw input layer */ +#define CONFIG_INPUT +/* Full keycode level grabbing supported */ +#define CONFIG_INPUT_GRABMAX 3 -#define MAX_MAPS 16 +#define MAX_MAPS 16 /* 512K */ #define MAP_SIZE 0x8000 diff --git a/Kernel/platform-trs80m1/devinput.c b/Kernel/platform-trs80m1/devinput.c new file mode 100644 index 00000000..36c85b60 --- /dev/null +++ b/Kernel/platform-trs80m1/devinput.c @@ -0,0 +1,81 @@ +#include +#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; + } + + /* Clashes with Alpha joystick */ + if (has_hr1g) + return 0; + + 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 (has_hr1g) + return; + if (~stick != old_stick) + wakeup(&kqueue); +} diff --git a/Kernel/platform-trs80m1/devinput.h b/Kernel/platform-trs80m1/devinput.h new file mode 100644 index 00000000..5d79a9e0 --- /dev/null +++ b/Kernel/platform-trs80m1/devinput.h @@ -0,0 +1,4 @@ + +extern void queue_input(uint8_t c); +extern void poll_input(void); +extern uint8_t vblank; diff --git a/Kernel/platform-trs80m1/devtty.c b/Kernel/platform-trs80m1/devtty.c index ac27f231..81ff082f 100644 --- a/Kernel/platform-trs80m1/devtty.c +++ b/Kernel/platform-trs80m1/devtty.c @@ -5,6 +5,8 @@ #include #include #include +#include +#include #include static char tbuf1[TTYSIZ]; @@ -196,8 +198,13 @@ static void keyproc(void) int m = 1; for (n = 0; n < 8; n++) { if ((key & m) && (keymap[i] & m)) { - if (!(shiftmask[i] & m)) + if (!(shiftmask[i] & m)) { + if (keyboard_grab == 3) { + queue_input(KEYPRESS_UP); + queue_input(keyboard[i][n]); + } keysdown--; + } } if ((key & m) && !(keymap[i] & m)) { if (!(shiftmask[i] & m)) { @@ -269,14 +276,12 @@ static uint8_t kbd_timer; static void keydecode(void) { uint8_t c; + uint8_t m = 0; /* Convention for capslock or the mod */ - if (c == KEY_CAPSLOCK) { - capslock = 1 - capslock; - return; - } /* Only the model 3 has right shift (2) */ if (keymap[7] & 3) { /* shift (left/right) */ + m = KEYPRESS_SHIFT; c = shiftkeyboard[keybyte][keybit]; /* VT switcher */ if (c == KEY_LEFT || c == KEY_RIGHT) { @@ -291,9 +296,14 @@ static void keydecode(void) } else c = keyboard[keybyte][keybit]; + if (c == KEY_CAPSLOCK) { + capslock = 1 - capslock; + return; + } /* The keyboard lacks some rather important symbols so remap them with control (down arrow)*/ if ((keymap[6] | keymap[7]) & 16) { /* control */ + m |= KEYPRESS_CTRL; if (keymap[7] & 3) { /* shift */ if (c == '(') c = '{'; @@ -319,9 +329,29 @@ static void keydecode(void) else if (capslock && c >= 'a' && c <= 'z') c -= 'a' - 'A'; if (c) { -// kprintf("Typed %d:%c\n", c, c); - vt_inproc(inputtty + 1, c); - } + switch(keyboard_grab) { + case 0: + vt_inproc(inputtty + 1, c); + break; + case 1: + /* Proper rule needed FIXME */ + if (c <= 0x83) { + vt_inproc(inputtty + 1, c); + break; + } + /* Fall through */ + case 2: + queue_input(KEYPRESS_DOWN); + queue_input(c); + break; + case 3: + /* Queue an event giving the base key (unshifted) + and the state of shift/ctrl/alt */ + queue_input(KEYPRESS_DOWN | m); + queue_input(keyboard[keybyte][keybit]); + break; + } + } } /* Polled 40 times a second */ @@ -340,4 +370,5 @@ void kbd_interrupt(void) } if (vtq != vtbuf) vtflush(); + poll_input(); } diff --git a/Kernel/platform-trs80m1/fuzix.lnk b/Kernel/platform-trs80m1/fuzix.lnk index ccb011b8..5129c12d 100644 --- a/Kernel/platform-trs80m1/fuzix.lnk +++ b/Kernel/platform-trs80m1/fuzix.lnk @@ -46,8 +46,10 @@ swap.rel bankfixed.rel vt.rel devsys.rel +devinput.rel platform-trs80m1/devlpr.rel platform-trs80m1/devtty.rel platform-trs80m1/vtsupport.rel +platform-trs80m1/devinput.rel platform-trs80m1/discard.rel -e