From 3fb254b65aa52a5d95e79bd99ad3c7d1b42db876 Mon Sep 17 00:00:00 2001 From: Alan Cox Date: Sun, 25 Nov 2018 20:07:19 +0000 Subject: [PATCH] zxdiv: turn on input layer and joystick/mouse logic --- Kernel/platform-zxdiv/Makefile | 2 +- Kernel/platform-zxdiv/config.h | 3 +++ Kernel/platform-zxdiv/devtty.c | 47 +++++++++++++++++++++++++++++---- Kernel/platform-zxdiv/devtty.h | 2 ++ Kernel/platform-zxdiv/fuzix.lnk | 2 ++ Kernel/platform-zxdiv/main.c | 7 ++++- 6 files changed, 56 insertions(+), 7 deletions(-) diff --git a/Kernel/platform-zxdiv/Makefile b/Kernel/platform-zxdiv/Makefile index 0bbb5739..aab649d7 100644 --- a/Kernel/platform-zxdiv/Makefile +++ b/Kernel/platform-zxdiv/Makefile @@ -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 diff --git a/Kernel/platform-zxdiv/config.h b/Kernel/platform-zxdiv/config.h index 590155e3..974575a0 100644 --- a/Kernel/platform-zxdiv/config.h +++ b/Kernel/platform-zxdiv/config.h @@ -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 */ diff --git a/Kernel/platform-zxdiv/devtty.c b/Kernel/platform-zxdiv/devtty.c index bce0705a..d72d24fc 100644 --- a/Kernel/platform-zxdiv/devtty.c +++ b/Kernel/platform-zxdiv/devtty.c @@ -7,6 +7,8 @@ #include #include #include +#include +#include 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; diff --git a/Kernel/platform-zxdiv/devtty.h b/Kernel/platform-zxdiv/devtty.h index 49ea085b..a8d5c6a2 100644 --- a/Kernel/platform-zxdiv/devtty.h +++ b/Kernel/platform-zxdiv/devtty.h @@ -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 diff --git a/Kernel/platform-zxdiv/fuzix.lnk b/Kernel/platform-zxdiv/fuzix.lnk index 033bc64f..aa5f62af 100644 --- a/Kernel/platform-zxdiv/fuzix.lnk +++ b/Kernel/platform-zxdiv/fuzix.lnk @@ -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 diff --git a/Kernel/platform-zxdiv/main.c b/Kernel/platform-zxdiv/main.c index e2529e66..2d283e18 100644 --- a/Kernel/platform-zxdiv/main.c +++ b/Kernel/platform-zxdiv/main.c @@ -3,6 +3,7 @@ #include #include #include +#include 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); } /* -- 2.34.1