trs80m1: add initial joystick/input device support
authorAlan Cox <alan@linux.intel.com>
Fri, 6 Jul 2018 00:16:35 +0000 (01:16 +0100)
committerAlan Cox <alan@linux.intel.com>
Fri, 6 Jul 2018 00:16:35 +0000 (01:16 +0100)
Kernel/platform-trs80m1/Makefile
Kernel/platform-trs80m1/README
Kernel/platform-trs80m1/config.h
Kernel/platform-trs80m1/devinput.c [new file with mode: 0644]
Kernel/platform-trs80m1/devinput.h [new file with mode: 0644]
Kernel/platform-trs80m1/devtty.c
Kernel/platform-trs80m1/fuzix.lnk

index e878e47..bb2e99d 100644 (file)
@@ -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
index 482a624..b625507 100644 (file)
@@ -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
index e680de3..87a6b31 100644 (file)
 #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 (file)
index 0000000..36c85b6
--- /dev/null
@@ -0,0 +1,81 @@
+#include <kernel.h>
+#include <kdata.h>
+#include <input.h>
+#include <devgfx.h>
+#include <devinput.h>
+
+__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 (file)
index 0000000..5d79a9e
--- /dev/null
@@ -0,0 +1,4 @@
+
+extern void queue_input(uint8_t c);
+extern void poll_input(void);
+extern uint8_t vblank;
index ac27f23..81ff082 100644 (file)
@@ -5,6 +5,8 @@
 #include <tty.h>
 #include <vt.h>
 #include <devtty.h>
+#include <input.h>
+#include <devinput.h>
 #include <stdarg.h>
 
 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();
 }
index ccb011b..5129c12 100644 (file)
@@ -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