From eba664771a2add6f8a9d4c5201a54672c825f051 Mon Sep 17 00:00:00 2001 From: Bruce Mitchener Date: Wed, 27 Jan 2021 00:42:17 +0700 Subject: [PATCH] Fix tty.c to compile. (#180) This removes a bit of the debug info printing, but other than that, is pretty close to what it was before. We also now build it in both the make and cmake build systems. --- CMakeLists.txt | 2 +- bin/makefile-tail | 1 + inc/tty.h | 19 +--- src/tty.c | 226 +++++++++++++++++++--------------------------- 4 files changed, 101 insertions(+), 147 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 94ec704..baebe48 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,7 +107,6 @@ SET(BAD_SRCS src/rawrs232c.c src/rs232c.c src/truecolor.c - src/tty.c src/vesainit.c src/vgainit.c ) @@ -195,6 +194,7 @@ SET(MAIKO_SRCS src/sxhash.c src/testtool.c src/timer.c + src/tty.c src/typeof.c src/ubf1.c src/ubf2.c diff --git a/bin/makefile-tail b/bin/makefile-tail index 37bab8e..a3f2cd4 100644 --- a/bin/makefile-tail +++ b/bin/makefile-tail @@ -127,6 +127,7 @@ DEVICES = $(OBJECTDIR)dspsubrs.o \ $(OBJECTDIR)keyevent.o \ $(OBJECTDIR)kbdsubrs.o \ $(OBJECTDIR)ether.o \ + $(OBJECTDIR)tty.o \ $(OBJECTDIR)initkbd.o TESTFILES = $(OBJECTDIR)dbgtool.o \ diff --git a/inc/tty.h b/inc/tty.h index 8226e9b..acf5d4a 100644 --- a/inc/tty.h +++ b/inc/tty.h @@ -11,16 +11,8 @@ /* */ /************************************************************************/ -#include -#include -#include -#include "lispemul.h" -#include "adr68k.h" - -#include "lispmap.h" - /* - TTY Command + TTY Command */ #define TTY_GET_STATUS 33280>>8 @@ -55,9 +47,9 @@ typedef struct { DLword notify_mask; } DLTTY_OUT_CSB; -typedef struct { - unsigned state : 1; - unsigned nil1 : 7; +typedef struct { + unsigned state : 1; + unsigned nil1 : 7; unsigned success : 1; unsigned break_detected : 1; unsigned framing_error : 1; @@ -72,8 +64,5 @@ typedef struct { unsigned rx_ready : 1; unsigned tx_ready : 1; } DLTTY_IN_CSB; - -extern DLword *Lisp_world; - #endif /* TTY_H */ diff --git a/src/tty.c b/src/tty.c index 444c5f5..5147176 100644 --- a/src/tty.c +++ b/src/tty.c @@ -9,7 +9,18 @@ #include "version.h" -#include +#include +#include +#include +#include +#include + +#include "lispemul.h" +#include "lispmap.h" +#include "adr68k.h" +#include "lsptypes.h" +#include "lspglob.h" +#include "commondefs.h" #include "tty.h" DLTTY_OUT_COMMAND *DLTTYPortCmd; @@ -19,33 +30,33 @@ DLTTY_OUT_CSB *DLTTYOut; char *TTY_Dev; int TTY_Fd = -1; extern fd_set LispReadFds; -struct sgttyb TTY_Mode; - -void tty_init() { -#ifdef TRACE - printf("TRACE: tty_init()\n"); -#endif +void tty_init(void) +{ TTY_Dev = "/dev/ttyb"; /* Modify device name */ TTY_Fd = (-1); DLTTYPortCmd = (DLTTY_OUT_COMMAND *)Addr68k_from_LADDR(IOPAGE_OFFSET + 20); DLTTYIn = (DLTTY_IN_CSB *)Addr68k_from_LADDR(IOPAGE_OFFSET + 36); DLTTYOut = (DLTTY_OUT_CSB *)Addr68k_from_LADDR(IOPAGE_OFFSET + 34); -} /* tty_init end */ +} -void tty_open() { - int stat; - -#ifdef TRACE - printf("TRACE: tty_open()\n"); -#endif +void tty_open(void) +{ + struct termios options; if (TTY_Fd < 0) { if ((TTY_Fd = open(TTY_Dev, O_RDWR)) >= 0) { - stat = ioctl(TTY_Fd, TIOCGETP, &TTY_Mode); - TTY_Mode.sg_flags = RAW; - stat = ioctl(TTY_Fd, TIOCSETP, &TTY_Mode); + tcgetattr(TTY_Fd, &options); + options.c_iflag &= ~(IMAXBEL|IXOFF|INPCK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IGNPAR); + options.c_iflag |= IGNBRK; + options.c_oflag &= ~OPOST; + options.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|NOFLSH|TOSTOP|PENDIN); + options.c_cflag &= ~(CSIZE|PARENB); + options.c_cflag |= CS8|CREAD; + options.c_cc[VMIN] = 1; + options.c_cc[VTIME] = 0; + tcsetattr(TTY_Fd, TCSANOW, &options); FD_SET(TTY_Fd, &LispReadFds); #ifdef TTYINT @@ -56,84 +67,97 @@ void tty_open() { error("TTY: tty_open"); } } -} /* tty_open end */ - -void tty_close() { - int stat; - -#ifdef TRACE - printf("TRACE: tty_close()\n"); -#endif +} +void tty_close(void) +{ if (TTY_Fd >= 0) { FD_CLR(TTY_Fd, &LispReadFds); - stat = close(TTY_Fd); + close(TTY_Fd); #ifdef TTYINT int_io_close(TTY_Fd); #endif TTY_Fd = (-1); } -} /* tty_close end */ +} -void TTY_get() { +void tty_get(void) +{ char indata[256]; - int count; - -#ifdef TRACE - printf("TRACE: tty_get()\n"); -#endif if ((TTY_Fd >= 0) && !DLTTYIn->state) { DLTTYIn->in_data = '\0'; /* Clear Previous Data */ - if ((count = read(TTY_Fd, indata, 1)) == 1) { + if (read(TTY_Fd, indata, 1) == 1) { DLTTYIn->in_data = indata[0]; DLTTYIn->state = 1; } else { error("TTY: tty_get"); } } -} /* TTY_get end */ +} -void tty_put() { - int count; +void tty_put(void) +{ char c; -#ifdef TRACE - printf("TRACE: tty_put()\n"); -#endif - if (TTY_Fd >= 0) { c = DLTTYPortCmd->outdata; - if ((count = write(TTY_Fd, &c, 1)) != 1) { error("TTY: tty_put()"); } + if (write(TTY_Fd, &c, 1) != 1) { error("TTY: tty_put()"); } } -} /* tty_put end */ +} -void tty_breakon() { - int stat; +speed_t tty_baudtosymbol(short aBaud) +{ + if (aBaud == 0) return (B50); + if (aBaud == 1) return (B75); + if (aBaud == 2) return (B110); + if (aBaud == 3) return (B134); + if (aBaud == 4) return (B150); + if (aBaud == 5) return (B300); + if (aBaud == 6) return (B600); + if (aBaud == 7) return (B1200); + if (aBaud == 10) return (B2400); + if (aBaud == 12) return (B4800); + if (aBaud == 14) return (B9600); + if (aBaud == 15) return (EXTA); + return (-1); +} -#ifdef TRACE - printf("TRACE: tty_breakon()\n"); -#endif +void tty_setbaudrate(void) +{ + speed_t baudrate; - if (TTY_Fd >= 0) { stat = ioctl(TTY_Fd, TIOCSBRK, 0); } -} /* tty_breakon end */ + if (TTY_Fd >= 0) { + if ((baudrate = tty_baudtosymbol(DLTTYOut->line_speed)) != -1) { + struct termios options; + tcgetattr(TTY_Fd, &options); + cfsetispeed(&options, baudrate); + cfsetospeed(&options, baudrate); + tcsetattr(TTY_Fd, TCSANOW, &options); + } else { + error("TTY: tty_setbaudrate"); + } + } +} -void tty_breakoff() { - int stat; +void tty_setparam(void) +{ + if (DLTTYPortCmd->outdata & SET_BAUD_RATE) tty_setbaudrate(); +} -#ifdef TRACE - printf("TRACE: tty_breakoff()\n"); -#endif +void tty_breakon(void) +{ + if (TTY_Fd >= 0) { ioctl(TTY_Fd, TIOCSBRK, 0); } +} - if (TTY_Fd >= 0) { stat = ioctl(TTY_Fd, TIOCCBRK, 0); } -} /* tty_breakoff end */ - -void TTY_cmd() { -#ifdef TRACE - printf("TRACE: tty_cmd()\n"); -#endif +void tty_breakoff(void) +{ + if (TTY_Fd >= 0) { ioctl(TTY_Fd, TIOCCBRK, 0); } +} +void tty_cmd(void) +{ if (DLTTYPortCmd->command >= PUT_CHAR) { if (DLTTYPortCmd->command == PUT_CHAR) tty_put(); @@ -152,83 +176,23 @@ void TTY_cmd() { DLTTYPortCmd->command &= ~PUT_CHAR; } -} /* TTY_cmd end */ +} -void tty_setparam() { -#ifdef TRACE - printf("TRACE: tty_setpram()\n"); -#endif - - if (DLTTYPortCmd->outdata & SET_BAUD_RATE) tty_setbaudrate(); - -} /* tty_setpram end */ - -void tty_setbaudrate() { - char baudrate; - int stat; - -#ifdef TRACE - printf("TRACE: tty_setbaudrete()\n"); -#endif - - if (TTY_Fd >= 0) { - if ((baudrate = tty_baudtosymbol(DLTTYOut->line_speed)) != -1) { - TTY_Mode.sg_ispeed = baudrate; - TTY_Mode.sg_ospeed = baudrate; - stat = ioctl(TTY_Fd, TIOCSETP, &TTY_Mode); - } else { - error("TTY: tty_setbaudrate"); - } - } -} /* tty_setbaudrate end */ - -int tty_baudtosymbol(short aBaud) +void tty_debug(const char *name) { -#ifdef TRACE - printf("TRACE: tty_baudtosymbol(%x)\n", aBaud); -#endif - - if (aBaud == 0) return (B50); - if (aBaud == 1) return (B75); - if (aBaud == 2) return (B110); - if (aBaud == 3) return (B134); - if (aBaud == 4) return (B150); - if (aBaud == 5) return (B300); - if (aBaud == 6) return (B600); - if (aBaud == 7) return (B1200); - if (aBaud == 10) return (B2400); - if (aBaud == 12) return (B4800); - if (aBaud == 14) return (B9600); - if (aBaud == 15) return (EXTA); - return (-1); - -} /* tty_baudtosymbol */ - -void tty_debug(char *name) -{ - int stat; - struct sgttyb mode; - printf("DEBUG: %s\n", name); printf("DEBUG: \t\tTTY_Dev = \"%s\"\n", TTY_Dev); printf("DEBUG: \t\tTTY_Fd = %d\n", TTY_Fd); if (TTY_Fd >= 0) { - stat = ioctl(TTY_Fd, TIOCGETP, &mode); - printf("DEBUG: \t\tTTY_Mode.sg_ispeed = %#x\n", mode.sg_ispeed); - printf("DEBUG: \t\tTTY_Mode.sg_ospeed = %#x\n", mode.sg_ospeed); - printf("DEBUG: \t\tTTY_Mode.sg_erase = %#x\n", mode.sg_erase); - printf("DEBUG: \t\tTTY_Mode.sg_kill = %#x\n", mode.sg_kill); - printf("DEBUG: \t\tTTY_Mode.sg_flags = %#x\n", mode.sg_flags); + struct termios attr; + tcgetattr(TTY_Fd, &attr); + printf("DEBUG: \t\tTTY_Mode.sg_ispeed = %#x\n", (unsigned int)cfgetispeed(&attr)); + printf("DEBUG: \t\tTTY_Mode.sg_ospeed = %#x\n", (unsigned int)cfgetospeed(&attr)); } printf("DEBUG:\n"); printf("DEBUG: \t\tSymbol Address Contents\n"); - printf("DEBUG: \t\tIOPAGE %#x\n", Addr68k_from_LADDR(IOPAGE_OFFSET)); - printf("DEBUG: \t\tDLTTYPortCmd %#x %#x\n", DLTTYPortCmd, *(DLword *)DLTTYPortCmd); - printf("DEBUG: \t\tDLTTYOut %#x %#x\n", DLTTYOut, *(DLword *)DLTTYOut); - printf("DEBUG: \t\t %#x\n", *(DLword *)(DLTTYOut + 1)); - printf("DEBUG: \t\tDLTTYIn %#x %#x\n", DLTTYIn, *(DLword *)DLTTYIn); - printf("DEBUG: \t\t %#x\n", *(DLword *)(DLTTYIn + 1)); - -} /* tty_debug end */ + printf("DEBUG: \t\tIOPAGE %p\n", Addr68k_from_LADDR(IOPAGE_OFFSET)); + /* In the future, we could print out the various fields of DLTTYOut, DLTTYIn, and DLTTYPortCmd */ +}