diff --git a/README.md b/README.md
index 3328d84..8e6a19c 100644
--- a/README.md
+++ b/README.md
@@ -1,15 +1,36 @@
-tu58em is a software emulation of a DECtapeII TU-58 block addressable cartridge tape drive. It requires only a standard Windows PC as a host with an RS232 serial port to connect to the target system.
+tu58em is a software emulation of a DECtapeII TU-58 block addressable cartridge tape drive. It requires only a standard Windows PC as a host with a (real or USB) RS232 serial comm port to connect to the target system.
-tu58em was originally based on the 1984 Dan Ts'o tu58 program, but has been almost completely rewritten to make it compile error free, improve the program flow, and add new functionality. It has been compiled within the CYGWIN environment, and will run either within a CYGWIN window or an MSDOS command window with the associated cygwin1.dll helper file. tu58em has been tested under Win2K, WinXPsp3, and Win7sp1. tu58em has compiled error free under Linux (Ubuntu 12.02LTS) but has not yet been rigorously tested in that environment.
+tu58em was originally based on the 1984 Dan Ts'o tu58 program, but has been almost completely rewritten to make it compile error free, improve the program flow, and add new functionality. It has been compiled within the CYGWIN environment, and will run either within a CYGWIN window or an MSDOS command window with the associated cygwin1.dll helper file. tu58em has been tested under WinXPsp3, Win7sp1(64b), and Linux (Ubuntu 12.02LTS).
Each emulated .dsk image file is exactly 256KB (512 blocks of 512 bytes) of data and is a byte-for-byte image of the data on a TU-58 cartridge tape. As currently configured tu58em will support up to 8 drives per controller as DD0: to DD7: (altho this is easily changed in the source). tu58em will support disk image files as large as the TU58 protocol allows (ie, 32MB, or 64K 512B blocks); however most standard DEC operating system drivers restrict TU58 drives to 256KB each. The DEC driver must be patched to allow for larger than 256KB disk images.
-tu58em has been tested using both native RS232 serial COM ports and serial ports emulated thru USB serial adapters.
-
-Note: tu58em is compiled using the CYGWIN serial interface library routines (ie, termios.h) and is the preferred version that should be used. tu58ew bypasses the CYGWIN serial interface layer and makes direct Windows serial comm routine calls. This version was done early on because of deficiencies in the CYGWIN serial library. However, the required features are now present so in reality tu58ew should be considered deprecated.
-
As of v1.4m Mark Blair's updates for VAX mode operation (for VAX-730 microcode boot support) and background mode are integrated.
+As of v2.0a the serial support routines have been rewritten to, under Linux, use termios.h PARMRK mode to allow detecting BREAK inline within the rx byte stream, and respond correctly (ie, abort current command in process and return to init loop). PARMRK mode in CYGWIN appears not be be working correctly; a BREAK just gets turned into a NULL byte. Windows communication mode (-DWINCOMM) is preferred for CYGWIN, as BREAK is detected correctly. MACOS support of PARMRK mode is unknown. The makefile is setup to detect the operating system type and define the compilation options correctly.
+
+The following configurations have been tested:
+```
+System Mode Port Status
+------------ -------------- ------------ --------------------------------------
+WinXP/CYGWIN WINCOMM real comm PASS, BREAK detected
+WinXP/CYGWIN WINCOMM USB ftdi PASS, BREAK detected
+WinXP/CYGWIN WINCOMM USB prolific conditional PASS, BREAK not detected
+------------ -------------- ------------ --------------------------------------
+WinXP/CYGWIN termios real comm conditional PASS; BREAK not detected
+WinXP/CYGWIN termios USB ftdi conditional PASS; BREAK not detected
+WinXP/CYGWIN termios USB prolific conditional PASS; BREAK not detected
+------------ -------------- ------------ --------------------------------------
+WinXP/CYGWIN termios+PARMRK any FAIL, does not work at all
+------------ -------------- ------------ --------------------------------------
+Linux* termios+PARMRK real comm PASS, BREAK detected
+Linux* termios+PARMRK USB ftdi PASS, BREAK detected
+Linux* termios+PARMRK USB prolific conditional PASS; BREAK not detected
+------------ -------------- ------------ --------------------------------------
+
+*Linux == "Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-124-generic x86_64)"
+```
+So it appears that the drivers for real comm ports handle BREAK correctly, as does the driver for the USB ftdi adapter, on both WinXP and Linux. The USB prolific adapter hardware and/or driver do not handle a BREAK, altho all data transfers operate correctly.
+
A cygwin folder with a precompiled 32b cygwin executable (tu58em.exe) is included for those without cygwin environment access. Under Windows, just open a standard CMD.EXE window, change to the cygwin folder, and run the tu58em.exe executable as a command line program.
If the emulator is run with no options, it prints a usage screen:
@@ -18,7 +39,7 @@ If the emulator is run with no options, it prints a usage screen:
E:\DEC> tu58em
ERROR: no units were specified
FATAL: illegal command line
- tu58 tape emulator v1.4q
+ tu58 tape emulator v2.0a
Usage: ./tu58em [-options] -[rwci] file1 ... -[rwci] file7
Options: -V | --version output version string
-v | --verbose enable verbose output to terminal
@@ -73,9 +94,10 @@ info: initialize RT-11 directory on 'rt11.dsk'
info: unit 0 r file 'boot.dsk'
info: unit 1 rwci file 'rt11.dsk'
info: serial port 3 at 38400 baud 1 stop
-info: TU58 emulation start
+info: TU58 start
info: R restart, S toggle send init, V toggle verbose, D toggle debug, Q quit
-info: emulator started
+info: TU58 emulator started
+info: seen
info: seen, sending
info: read unit=0 sw=0x00 mod=0x00 blk=0x0000 cnt=0x0400
info: read unit=0 sw=0x00 mod=0x00 blk=0x0006 cnt=0x0400
diff --git a/common.h b/common.h
index 631a6fc..b62457b 100644
--- a/common.h
+++ b/common.h
@@ -2,7 +2,7 @@
// tu58 - Emulate a TU58 over a serial line
//
// Original (C) 1984 Dan Ts'o
-// Update (C) 2005-2016 Donald N North
+// Update (C) 2005-2017 Donald N North
//
// All rights reserved.
//
@@ -80,10 +80,9 @@ typedef struct timespec timespec_t;
#define FILERT11INIT 4 // file should be init'ed as RT11 structure
#define FILEXXDPINIT 5 // file should be init'ed as XXDP structure
-#define DEV_NYI -1 // not yet implemented
-#define DEV_OK 0 // no error
-#define DEV_BREAK 1 // BREAK on line
-#define DEV_ERROR 2 // ERROR on line
+#define DEV_NORMAL 0 // normal data byte
+#define DEV_BREAK 1 // BREAK on line
+#define DEV_ERROR 2 // ERROR on byte
@@ -104,8 +103,7 @@ void devtxput (uint8_t);
int32_t devtxwrite (uint8_t *, int32_t);
void devrxinit (void);
int32_t devrxavail (void);
-int32_t devrxerror (void);
-uint8_t devrxget (void);
+uint8_t devrxget (uint8_t *);
void devinit (char *, int32_t, int32_t);
void devrestore (void);
void coninit (void);
diff --git a/cygwin/tu58em.exe b/cygwin/tu58em.exe
index 6a7949f..5c49a52 100644
Binary files a/cygwin/tu58em.exe and b/cygwin/tu58em.exe differ
diff --git a/main.c b/main.c
index 113a689..fadb11a 100644
--- a/main.c
+++ b/main.c
@@ -79,6 +79,10 @@
// v1.4p - 05 May 2017 - donorth - Updated serial baud rate table with #ifdef detection
// Update clock_gettime() for MAC OSX support
// v1.4q - 16 May 2017 - donorth - Fixed error in fileseek() routine (should fail at EOF)
+// v2.0a - 19 May 2017 - donorth - Rewrite of serial.c to support PARMRK mode on linux
+// so that BREAKs are handled correctly via setjmp/longjmp
+// Update tu58drive.c to intercept rx byte read routine to
+// detect input line BREAK and process as required.
//
@@ -89,7 +93,7 @@
static char copyright[] = "(C) 2005-2017 Don North , " \
"(C) 1984 Dan Ts'o ";
-static char version[] = "tu58 tape emulator v1.4q";
+static char version[] = "tu58 tape emulator v2.0a";
static char port[32] = "1"; // default port number (COM1, /dev/ttyS0)
static long speed = 9600; // default line speed
diff --git a/makefile b/makefile
index 6c7b934..071e312 100644
--- a/makefile
+++ b/makefile
@@ -2,50 +2,46 @@
# tu58em emulator makefile
#
-ifeq ($(comm),mac)
-# UNIX comms model, but on a Mac
-PROG = tu58em
-COMM = -UWINCOMM -DMACOSX
-else ifeq ($(comm),win)
-# WINDOWS comms model
-PROG = tu58ew
-COMM = -DWINCOMM
-else # ifeq ($(comm),unix)
-# UNIX comms model
-PROG = tu58em
-COMM = -UWINCOMM
+# get operating system name
+OPSYS = $(shell uname -s)
+
+ifeq ($(OPSYS),Darwin)
+# mac: UNIX comms model, but on MACOSX
+OPTIONS = -DMACOSX
+LFLAGS = -lpthread
+else ifeq ($(OPSYS:CYGWIN%=CYGWIN),CYGWIN)
+# win: WINDOWS comms model under CYGWIN (any version)
+OPTIONS = -DCYGWIN -DWINCOMM
+LFLAGS = -lpthread -lrt
+else ifeq ($(OPSYS),Linux)
+# unix: UNIX comms model under LINUX, use PARMRK serial mode
+OPTIONS = -DLINUX -DUSE_PARMRK
+LFLAGS = -lpthread -lrt
+else # unknown environment
+OPTIONS =
+LFLAGS = -lpthread -lrt
endif
+# default program name, redefine PROG=xxx on command line if wanted
+PROG = tu58em
+
# put your binary installation directory here...
-BIN = /cygdrive/e/DEC/tools/exe
+BINDIR = /cygdrive/e/DEC/tools/exe
# compiler flags and libraries
CC = gcc
-CFLAGS = -I. -O3 -Wall -c $(COMM)
-ifeq ($(comm),mac)
-LFLAGS = -lpthread
-else
-LFLAGS = -lpthread -lrt
-endif
+CFLAGS = -I. -O3 -Wall -c $(OPTIONS)
$(PROG) : main.o tu58drive.o file.o serial.o
$(CC) -o $@ main.o tu58drive.o file.o serial.o $(LFLAGS)
-all :
- make --always comm=win
- make clean
- make --always comm=unix
- make clean
-
-mac :
- make --always comm=mac
- make --clean
-
-installall :
- make --always comm=win install
- make clean
- make --always comm=unix install
- make clean
+config :
+ @echo " OPSYS = \"$(OPSYS)\""
+ @echo " PROG = \"$(PROG)\""
+ @echo " BINDIR = \"$(BINDIR)\""
+ @echo " CC = \"$(CC)\""
+ @echo " CFLAGS = \"$(CFLAGS)\""
+ @echo " LFLAGS = \"$(LFLAGS)\""
clean :
-rm -f *.o
@@ -57,7 +53,7 @@ purge : clean
-rm -f $(PROG) $(PROG).exe
install : $(PROG)
- [ -d $(BIN) ] && cp $< $(BIN)
+ [ -d $(BINDIR) ] && cp $< $(BINDIR)
serial.o : serial.c common.h
$(CC) $(CFLAGS) serial.c
diff --git a/serial.c b/serial.c
index 7b9b414..5230874 100644
--- a/serial.c
+++ b/serial.c
@@ -2,7 +2,7 @@
// tu58 - Emulate a TU58 over a serial line
//
// Original (C) 1984 Dan Ts'o
-// Update (C) 2005-2016 Donald N North
+// Update (C) 2005-2017 Donald N North
//
// All rights reserved.
//
@@ -56,21 +56,21 @@
#define IUCLC 0 // Not POSIX
#define OLCUC 0 // Not POSIX
#define CBAUD 0 // Not POSIX
-#endif
+#endif // MACOSX
#include
#define BUFSIZE 256 // size of serial line buffers (bytes, each way)
// serial output buffer
-static uint8_t wbuf[BUFSIZE];
+static uint8_t wbuf[BUFSIZE];
static uint8_t *wptr;
-static int32_t wcnt;
+static int32_t wcnt;
// serial input buffer
-static uint8_t rbuf[BUFSIZE];
+static uint8_t rbuf[BUFSIZE];
static uint8_t *rptr;
-static int32_t rcnt;
+static int32_t rcnt;
#ifdef WINCOMM
// serial device descriptor, default to nada
@@ -78,6 +78,7 @@ static HANDLE hDevice = INVALID_HANDLE_VALUE;
// async line parameters
static DCB dcbSave;
static COMMTIMEOUTS ctoSave;
+static uint8_t rxBreakSeen;
#else // !WINCOMM
// serial device descriptor, default to nada
static int32_t device = -1;
@@ -197,6 +198,7 @@ void devrxinit (void)
#ifdef WINCOMM
if (!PurgeComm(hDevice, PURGE_RXABORT|PURGE_RXCLEAR))
error("devrxinit(): error=%d", GetLastError());
+ rxBreakSeen = 0;
#else // !WINCOMM
tcflush(device, TCIFLUSH);
#endif // !WINCOMM
@@ -211,75 +213,26 @@ void devrxinit (void)
//
-// wait for an error on the serial line
-// return NYI, OK, BREAK, ERROR flag
-//
-int32_t devrxerror (void)
-{
-#ifdef WINCOMM
- // enable BREAK and ERROR events
- OVERLAPPED ovlp = { 0 };
- DWORD sts = 0;
- if (!SetCommMask(hDevice, EV_BREAK|EV_ERR)) {
- DWORD err = GetLastError();
- if (err != ERROR_OPERATION_ABORTED)
- error("devrxerror(): SetCommMask() failed, error=%d", err);
- }
- // do the status check
- ovlp.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (!WaitCommEvent(hDevice, &sts, &ovlp)) {
- DWORD err = GetLastError();
- if (err == ERROR_IO_PENDING) {
- if (WaitForSingleObject(ovlp.hEvent, INFINITE) == WAIT_OBJECT_0)
- GetOverlappedResult(hDevice, &ovlp, &sts, FALSE);
- } else {
- if (err != ERROR_OPERATION_ABORTED)
- error("devrxerror(): WaitCommEvent() failed, error=%d", err);
- }
- }
- // done
- CloseHandle(ovlp.hEvent);
- // indicate either a break or some other error or OK
- return (sts & (CE_BREAK|CE_FRAME)) ? DEV_BREAK : (sts ? DEV_ERROR : DEV_OK);
-#else // !WINCOMM
- // not implemented
- return DEV_NYI;
-#endif // !WINCOMM
-}
-
-
-
-//
-// return number of characters available
+// return number of characters available, get more if receive buffer is empty
//
int32_t devrxavail (void)
{
// get more characters if none available
if (rcnt <= 0) {
#ifdef WINCOMM
- OVERLAPPED ovlp = { 0 };
COMSTAT stat;
DWORD acnt = 0;
+ DWORD ncnt = 0;
DWORD sts = 0;
// clear state
if (!ClearCommError(hDevice, &sts, &stat))
error("devrxavail(): ClearCommError() failed");
- if (debug && (sts || stat.cbInQue))
- info("devrxavail(): status=0x%04X avail=%d", sts, stat.cbInQue);
- // do the read if something there
- if (stat.cbInQue > 0) {
- ovlp.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (!ReadFile(hDevice, rbuf, sizeof(rbuf), &acnt, &ovlp)) {
- DWORD err = GetLastError();
- if (err == ERROR_IO_PENDING) {
- if (WaitForSingleObject(ovlp.hEvent, INFINITE) == WAIT_OBJECT_0)
- GetOverlappedResult(hDevice, &ovlp, &acnt, FALSE);
- } else {
- error("devrxavail(): error=%d", err);
- }
- }
- CloseHandle(ovlp.hEvent);
- }
+ // do the read if something there, at most size of buffer
+ ncnt = stat.cbInQue > sizeof(rbuf) ? sizeof(rbuf) : stat.cbInQue;
+ if (!ReadFile(hDevice, rbuf, ncnt, &acnt, NULL))
+ error("devrxavail(): error=%d", GetLastError());
+ // check for break
+ if (sts & CE_BREAK) rxBreakSeen = 1;
// done
rcnt = acnt;
#else // !WINCOMM
@@ -296,7 +249,7 @@ int32_t devrxavail (void)
//
-// write characters direct to device
+// write characters direct to device from transmit buffer
//
int32_t devtxwrite (uint8_t *buf,
int32_t cnt)
@@ -304,28 +257,16 @@ int32_t devtxwrite (uint8_t *buf,
// write characters if asked, return number written
if (cnt > 0) {
#ifdef WINCOMM
- OVERLAPPED ovlp = { 0 };
COMSTAT stat;
DWORD acnt = 0;
DWORD sts = 0;
// clear state
if (!ClearCommError(hDevice, &sts, &stat))
error("devtxwrite(): ClearCommError() failed");
- if (debug && (sts || stat.cbOutQue))
- info("devtxwrite(): status=0x%04X remain=%d", sts, stat.cbOutQue);
// do the write
- ovlp.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
- if (!WriteFile(hDevice, buf, cnt, &acnt, &ovlp)) {
- DWORD err = GetLastError();
- if (err == ERROR_IO_PENDING) {
- if (WaitForSingleObject(ovlp.hEvent, INFINITE) == WAIT_OBJECT_0)
- GetOverlappedResult(hDevice, &ovlp, &acnt, FALSE);
- } else {
- error("devtxwrite(): error=%d", err);
- }
- }
+ if (!WriteFile(hDevice, buf, cnt, &acnt, NULL))
+ error("devtxwrite(): error=%d", GetLastError());
// done
- CloseHandle(ovlp.hEvent);
return acnt;
#else // !WINCOMM
return write(device, buf, cnt);
@@ -370,14 +311,71 @@ void devtxflush (void)
//
// return char from rbuf, wait until some arrive
//
-uint8_t devrxget (void)
+uint8_t devrxget (uint8_t *flg)
{
- // get more characters if none available
- while (devrxavail() <= 0) /*spin*/;
+ uint8_t c;
- // count, return next character
+#ifdef USE_PARMRK
+ // get more bytes if none available
+ while (rcnt <= 0) { (void)devrxavail(); }
+ // at least one available
rcnt--;
- return *rptr++;
+ // check if escaped or normal
+ if ((c = *rptr++) == 0377) {
+ // escape byte seen
+ while (rcnt <= 0) { (void)devrxavail(); }
+ // at least one available
+ rcnt--;
+ // check if escape or not
+ if ((c = *rptr++) == 0377) {
+ // 377,377 seen; return 377
+ *flg = DEV_NORMAL;
+ return c;
+ } else {
+ // non-escape byte seen, so get one more byte
+ while (rcnt <= 0) { (void)devrxavail(); }
+ // at least one available
+ rcnt--;
+ // check if NULL
+ if ((c = *rptr++) == 0000) {
+ // 377,000,000 seen; signals a BREAK, return 000 byte
+ *flg = DEV_BREAK;
+ return c;
+ } else {
+ // 377,000,NNN seen; signals byte NNN parity/framing error
+ *flg = DEV_ERROR;
+ return c;
+ }
+ }
+ } else {
+ // return normal data byte
+ *flg = DEV_NORMAL;
+ return c;
+ }
+#else // !USE_PARMRK
+ // get more characters if none available
+ while (rcnt <= 0) { (void)devrxavail(); }
+ // at least one available
+ rcnt--;
+ // get data byte
+ c = *rptr++;
+#ifdef WINCOMM
+ // check if this byte should be flagged as a BREAK
+ // for lack of a better algorithm, we flag the first
+ // ZERO byte after the rxBreakSeen flag is set as BREAK
+ if (c == 000 && rxBreakSeen) {
+ *flg = DEV_BREAK;
+ rxBreakSeen = 0;
+ } else {
+ *flg = DEV_NORMAL;
+ }
+#else // !WINCOMM
+ // return normal data byte
+ *flg = DEV_NORMAL;
+#endif // !WINCOMM
+ // return data byte
+ return c;
+#endif // !USE_PARMRK
}
@@ -521,9 +519,17 @@ void devinit (char *port,
int32_t uid = getuid();
setreuid(euid, -1);
if (sscanf(port, "%u", &n) == 1) sprintf(name, "\\\\.\\COM%d", n); else strcpy(name, port);
- hDevice = CreateFile(name, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, NULL);
+ // open port in non-overlapped I/O mode
+ hDevice = CreateFile(name,
+ GENERIC_READ | GENERIC_WRITE,
+ 0,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
if (hDevice == INVALID_HANDLE_VALUE) fatal("no serial line [%s]", name);
+
+ // we own the port
setreuid(uid, euid);
// get current line params, error if not a serial port
@@ -595,7 +601,11 @@ void devinit (char *port,
line.c_iflag &= ~( IGNBRK | BRKINT | IMAXBEL | INPCK | ISTRIP |
INLCR | IGNCR | ICRNL | IXON | IXOFF |
IUCLC | IXANY | PARMRK | IGNPAR );
+#ifdef USE_PARMRK
+ line.c_iflag |= ( PARMRK | IGNPAR );
+#else // !USE_PARMRK
line.c_iflag |= ( 0 );
+#endif // !USE_PARMRK
// output param
line.c_oflag &= ~( OPOST | OLCUC | OCRNL | ONLCR | ONOCR |
diff --git a/tu58drive.c b/tu58drive.c
index 2cfee57..e67b7e4 100644
--- a/tu58drive.c
+++ b/tu58drive.c
@@ -2,7 +2,7 @@
// tu58 - Emulate a TU58 over a serial line
//
// Original (C) 1984 Dan Ts'o
-// Update (C) 2005-2016 Donald N North
+// Update (C) 2005-2017 Donald N North
//
// All rights reserved.
//
@@ -48,6 +48,7 @@
#include "common.h"
#include
+#include
#include "tu58.h"
@@ -55,17 +56,13 @@
// clock_gettime() is not available under MACOSX
#define CLOCK_REALTIME 1
#include
-#include
-#include
-
void clock_gettime (int dummy, struct timespec *t) {
uint64_t mt;
mt = mach_absolute_time();
t->tv_sec = mt / 1000000000;
t->tv_nsec = mt % 1000000000;
}
-#endif
-
+#endif // MACOSX
// delays for modeling device access
@@ -92,7 +89,7 @@ uint8_t mrsp = 0; // set nonzero to indicate MRSP mode is active
static uint8_t doinit = 0; // set nonzero to indicate should send INITs continuously
static uint8_t runonce = 0; // set nonzero to indicate emulator has been run
static pthread_t th_run; // emulator thread id
-static pthread_t th_monitor; // monitor thread id
+static jmp_buf rx_break_env; // longjmp state for when a BREAK is detected on rx
@@ -140,6 +137,26 @@ static void reinit (void)
+//
+// read a byte from the host, process BREAK if seen
+//
+static uint8_t rxget (void)
+{
+ uint8_t state;
+ uint8_t c;
+
+ // get a byte and state flag
+ c = devrxget(&state);
+
+ // seen a BREAK on the rx line, so abort this packet
+ if (state == DEV_BREAK) longjmp(rx_break_env, c);
+
+ // return the byte
+ return c;
+}
+
+
+
//
// read of boot is not packetized, is just raw data
//
@@ -150,7 +167,7 @@ static void bootio (void)
uint8_t buffer[TU_BOOT_LEN];
// check unit number for validity
- unit = devrxget();
+ unit = rxget();
if (fileunit(unit)) {
error("bootio bad unit %d", unit);
return;
@@ -240,7 +257,7 @@ static void wait4cont (uint8_t code)
// wait for a CONT to arrive, but only so long
do {
- c = devrxget();
+ c = rxget();
if (debug) info("wait4cont(): char=0x%02X", c);
} while (c != TUF_CONT && --maxchar >= 0);
@@ -293,7 +310,7 @@ static int32_t getpacket (tu_packet *pkt)
uint16_t rcvchk, expchk;
// get remaining packet bytes, incl two checksum bytes
- while (--count >= 0) *ptr++ = devrxget();
+ while (--count >= 0) *ptr++ = rxget();
// get checksum bytes
rcvchk = (ptr[-1]<<8) | (ptr[-2]<<0);
@@ -485,7 +502,7 @@ static void tuwrite (tu_cmdpkt *pk)
// loop until we see data flag
do {
last = dk.flag;
- dk.flag = devrxget();
+ dk.flag = rxget();
if (debug) info("flag=0x%02X last=0x%02X", dk.flag, last);
if (last == TUF_INIT && dk.flag == TUF_INIT) {
// two in a row is special
@@ -507,7 +524,7 @@ static void tuwrite (tu_cmdpkt *pk)
} while (dk.flag != TUF_DATA);
// byte following data flag is packet data length
- dk.length = devrxget();
+ dk.length = rxget();
// get remainder of the data packet
if (getpacket((tu_packet *)&dk)) {
@@ -579,7 +596,7 @@ static void command (int8_t flag)
time_end.tv_nsec = 0;
pk.flag = flag;
- pk.length = devrxget();
+ pk.length = rxget();
// check control packet length ... if too long flush it
if (pk.length > sizeof(tu_cmdpkt)) {
@@ -736,6 +753,13 @@ static void* run (void* none)
// loop forever ... almost
for (;;) {
+ // setup for when a BREAK is detected
+ if (setjmp(rx_break_env)) {
+ // return here when we get a BREAK on the rx input
+ if (debug) info(" seen");
+ // fall thru to main loop
+ }
+
// loop while no characters are available
while (devrxavail() == 0) {
// delays and printout only if not VAX
@@ -754,7 +778,7 @@ static void* run (void* none)
// process received characters
last = flag;
- flag = devrxget();
+ flag = rxget();
if (debug) info("flag=0x%02X last=0x%02X", flag, last);
switch (flag) {
@@ -820,51 +844,6 @@ static void* run (void* none)
-//
-// monitor for break/error on line, restart emulator if seen
-//
-static void* monitor (void* none)
-{
- int32_t sts;
-
- info("TU58 monitor started");
-
- for (;;) {
-
- // check for any error
- switch (sts = devrxerror()) {
- case DEV_ERROR: // error
- case DEV_BREAK: // break
- // kill and restart the emulator
- if (verbose) info("BREAK detected");
-#ifdef THIS_DOES_NOT_YET_WORK_RELIABLY
- if (pthread_cancel(th_run))
- error("unable to cancel emulation thread");
- if (pthread_join(th_run, NULL))
- error("unable to join on emulation thread");
- if (pthread_create(&th_run, NULL, run, NULL))
- error("unable to restart emulation thread");
-#endif // THIS_DOES_NOT_YET_WORK_RELIABLY
- break;
- case DEV_OK: // OK
- break;
- case DEV_NYI: // not yet implemented
- delay_ms(200);
- break;
- default: // something else...
- error("monitor(): unknown flag %d", sts);
- break;
- }
- // bit of a delay, loop again
- delay_ms(50);
-
- }
-
- return (void*)0;
-}
-
-
-
//
// start tu58 drive emulation
//
@@ -875,17 +854,13 @@ void tu58drive (void)
fatal("illegal BLOCKSIZE (%d) / TU_DATA_LEN (%d) ratio", BLOCKSIZE, TU_DATA_LEN);
// say hello
- info("emulation start");
+ info("TU58 start");
info("R restart, S toggle send init, V toggle verbose, D toggle debug, Q quit");
// run the emulator
if (pthread_create(&th_run, NULL, run, NULL))
error("unable to create emulation thread");
- // run the monitor
- if (pthread_create(&th_monitor, NULL, monitor, NULL))
- error("unable to create monitor thread");
-
// loop on user input
for (;;) {
uint8_t c;
@@ -917,8 +892,6 @@ void tu58drive (void)
error("unable to restart emulation thread");
} else if (c == 'Q') {
// kill the emulator and exit
- if (pthread_cancel(th_monitor))
- error("unable to cancel monitor thread");
if (pthread_cancel(th_run))
error("unable to cancel emulation thread");
break;
@@ -935,7 +908,7 @@ void tu58drive (void)
error("unable to join on emulation thread");
// all done
- info("TU58 emulation end");
+ info("TU58 end");
return;
}