zxdiv: turn on input layer and joystick/mouse logic
authorAlan Cox <alan@linux.intel.com>
Sun, 25 Nov 2018 20:07:19 +0000 (20:07 +0000)
committerAlan Cox <alan@linux.intel.com>
Sun, 25 Nov 2018 20:07:19 +0000 (20:07 +0000)
Kernel/platform-zxdiv/Makefile
Kernel/platform-zxdiv/config.h
Kernel/platform-zxdiv/devtty.c
Kernel/platform-zxdiv/devtty.h
Kernel/platform-zxdiv/fuzix.lnk
Kernel/platform-zxdiv/main.c

index 0bbb573..aab649d 100644 (file)
@@ -1,4 +1,4 @@
-CSRCS = devtty.c devices.c main.c bank128.c divide.c divmmc.c
+CSRCS = devtty.c devices.c main.c bank128.c divide.c divmmc.c devinput.c
 CDSRCS = discard.c
 DSRCS = ../dev/devide.c ../dev/devsd.c ../dev/blkdev.c
 DDSRCS = ../dev/devide_discard.c ../dev/devsd_discard.c ../dev/mbr.c
index 590155e..974575a 100644 (file)
@@ -16,6 +16,9 @@
 /* CP/M emulation */
 #undef CONFIG_CPM_EMU
 
+/* Input layer support */
+#define CONFIG_INPUT
+#define CONFIG_INPUT_GRABMAX   3
 /* Video terminal, not a serial tty */
 #define CONFIG_VT
 /* Keyboard contains non-ascii symbols */
index bce0705..d72d24f 100644 (file)
@@ -7,6 +7,8 @@
 #include <vt.h>
 #include <tty.h>
 #include <graphics.h>
+#include <input.h>
+#include <devinput.h>
 
 char tbuf1[TTYSIZ];
 
@@ -111,7 +113,7 @@ void tty_data_consumed(uint8_t minor)
 
 void update_keyboard(void)
 {
-       /* We need this assembler code because SDCC __sfr cannot handle 16-bit addresses. And because it is much faster, of course  */
+       /* We need this assembler code because it is much faster, of course  */
        /* TODO: make it naked? */
        __asm
                ld hl,#_keybuf
@@ -145,8 +147,13 @@ void tty_pollirq(void)
                        uint8_t m = 0x10;
                        for (n = 4; n >= 0; 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)) {
@@ -177,16 +184,18 @@ static uint8_t cursor[4] = { KEY_LEFT, KEY_DOWN, KEY_UP, KEY_RIGHT };
 
 static void keydecode(void)
 {
+       uint8_t m = 0;
        uint8_t c;
 
        uint8_t ss = keymap[0] & 0x02;  /* SYMBOL SHIFT */
        uint8_t cs = keymap[7] & 0x01;  /* CAPS SHIFT */
 
-       if (ss) {
+       if (ss && !cs) {
+               m = KEYPRESS_SHIFT;
                c = shiftkeyboard[keybyte][keybit];
        } else {
                c = keyboard[keybyte][keybit];
-               if (cs) {
+               if (cs && !ss) {
                        if (c >= 'a' && c <= 'z')
                                c -= 'a' - 'A';
                        else if (c == '0')      /* CS + 0 is backspace) */
@@ -197,7 +206,33 @@ static void keydecode(void)
                                c = cursor[c - '5'];
                }
        }
-       tty_inproc(1, c);
+       if (ss & cs) {
+               m |= KEYPRESS_CTRL;
+               c &= 31;
+       }
+       if (c) {
+               switch (keyboard_grab) {
+               case 0:
+                       vt_inproc(1, c);
+                       break;
+               case 1:
+                       if (!input_match_meta(c)) {
+                               vt_inproc(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;
+               }
+       }
 }
 
 
@@ -243,7 +278,9 @@ int gfx_ioctl(uint8_t minor, uarg_t arg, char *ptr)
                return 0;
        case GFXIOC_WAITVB:
                /* Our system clock is vblank */
+               timer_wait++;
                psleep(&timer_interrupt);
+               timer_wait--;
                chksigs();
                if (udata.u_cursig) {
                        udata.u_error = EINTR;
index 49ea085..a8d5c6a 100644 (file)
@@ -10,6 +10,8 @@ extern uint8_t keymap[8];
 extern uint8_t keyboard[8][5];
 extern uint8_t shiftkeyboard[8][5];
 
+extern uint8_t timer_wait;
+
 extern int gfx_ioctl(uint8_t minor, uarg_t arg, char *ptr);
 
 #endif
index 033bc64..aa5f62a 100644 (file)
@@ -45,6 +45,7 @@ mm.rel
 platform-zxdiv/bank128.rel
 swap.rel
 devsys.rel
+devinput.rel
 platform-zxdiv/devtty.rel
 platform-zxdiv/devide.rel
 platform-zxdiv/devide_discard.rel
@@ -54,4 +55,5 @@ platform-zxdiv/divide.rel
 platform-zxdiv/divmmc.rel
 platform-zxdiv/mbr.rel
 platform-zxdiv/blkdev.rel
+platform-zxdiv/devinput.rel
 -e
index e2529e6..2d283e1 100644 (file)
@@ -3,6 +3,7 @@
 #include <kdata.h>
 #include <printf.h>
 #include <devtty.h>
+#include <devinput.h>
 
 uint16_t ramtop = PROGTOP;
 uint16_t swap_dev = 0xFFFF;
@@ -17,11 +18,15 @@ void platform_idle(void)
   __endasm;
 }
 
+uint8_t timer_wait;
+
 void platform_interrupt(void)
 {
  tty_pollirq();
  timer_interrupt();
- wakeup(&timer_interrupt);
+ poll_input();
+ if (timer_wait)
+  wakeup(&timer_interrupt);
 }
 
 /*