1
0
mirror of synced 2026-01-29 13:01:49 +00:00

11 Commits

9 changed files with 221 additions and 207 deletions

2
.gitignore vendored
View File

@@ -2,4 +2,6 @@
*~ *~
*.o *.o
*.exe *.exe
*.dsk
*.DSK
# the end # the end

View File

@@ -1,15 +1,39 @@
<B>tu58em</B> 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. <B>tu58em</B> 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.
<B>tu58em</B> 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. <B>tu58em</B> has been tested under Win2K, WinXPsp3, and Win7sp1. <B>tu58em</B> has compiled error free under Linux (Ubuntu 12.02LTS) but has not yet been rigorously tested in that environment. <B>tu58em</B> 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. <B>tu58em</B> 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 <B>tu58em</B> will support up to 8 drives per controller as DD0: to DD7: (altho this is easily changed in the source). <B>tu58em</B> 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. 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 <B>tu58em</B> will support up to 8 drives per controller as DD0: to DD7: (altho this is easily changed in the source). <B>tu58em</B> 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.
<B>tu58em</B> has been tested using both native RS232 serial COM ports and serial ports emulated thru USB serial adapters.
Note: <B>tu58em</B> is compiled using the CYGWIN serial interface library routines (ie, termios.h) and is the preferred version that should be used. <B>tu58ew</B> 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 <B>tu58ew</B> 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 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 termios appears not be be working correctly at all. 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
---------- -------------- ------------ --------------------------------------
Win/CYGWIN WINCOMM real comm PASS, BREAK detected
Win/CYGWIN WINCOMM USB ftdi PASS, BREAK detected
Win/CYGWIN WINCOMM USB prolific conditional PASS, BREAK not detected
---------- -------------- ------------ --------------------------------------
Win/CYGWIN termios real comm conditional PASS; BREAK not detected
Win/CYGWIN termios USB ftdi conditional PASS; BREAK not detected
Win/CYGWIN termios USB prolific conditional PASS; BREAK not detected
---------- -------------- ------------ --------------------------------------
Win/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
---------- -------------- ------------ --------------------------------------
Note:
(1) Win/CYGWIN = CYGWIN_NT-5.1 1.7.35(0.287/5/3) i686 Cygwin
(2) Linux = Ubuntu 12.04.5 LTS (GNU/Linux 3.2.0-124-generic) x86_64 GNU/Linux
```
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.
Configuring your serial card in the PDP-11 requires it be setup as 8-N-1 (8b data, no parity, one stop) AND that the serial interface card (example, a DL11-W in a UNIBUS system) be setup at the standard address of 776500 thru 776506. Also make sure that the card is enabled to send BREAK as that is an integral part of the TU58 serial protocol.
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 <B>tu58em.exe</B> executable as a command line program. 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 <B>tu58em.exe</B> executable as a command line program.
If the emulator is run with no options, it prints a usage screen: If the emulator is run with no options, it prints a usage screen:
@@ -18,7 +42,7 @@ If the emulator is run with no options, it prints a usage screen:
E:\DEC> tu58em E:\DEC> tu58em
ERROR: no units were specified ERROR: no units were specified
FATAL: illegal command line FATAL: illegal command line
tu58 tape emulator v1.4p tu58 tape emulator v2.0a
Usage: ./tu58em [-options] -[rwci] file1 ... -[rwci] file7 Usage: ./tu58em [-options] -[rwci] file1 ... -[rwci] file7
Options: -V | --version output version string Options: -V | --version output version string
-v | --verbose enable verbose output to terminal -v | --verbose enable verbose output to terminal
@@ -73,9 +97,10 @@ info: initialize RT-11 directory on 'rt11.dsk'
info: unit 0 r file 'boot.dsk' info: unit 0 r file 'boot.dsk'
info: unit 1 rwci file 'rt11.dsk' info: unit 1 rwci file 'rt11.dsk'
info: serial port 3 at 38400 baud 1 stop 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: R restart, S toggle send init, V toggle verbose, D toggle debug, Q quit
info: emulator started info: TU58 emulator started
info: <BREAK> seen
info: <INIT><INIT> seen, sending <CONT> info: <INIT><INIT> seen, sending <CONT>
info: read unit=0 sw=0x00 mod=0x00 blk=0x0000 cnt=0x0400 info: read unit=0 sw=0x00 mod=0x00 blk=0x0000 cnt=0x0400
info: read unit=0 sw=0x00 mod=0x00 blk=0x0006 cnt=0x0400 info: read unit=0 sw=0x00 mod=0x00 blk=0x0006 cnt=0x0400

View File

@@ -2,7 +2,7 @@
// tu58 - Emulate a TU58 over a serial line // tu58 - Emulate a TU58 over a serial line
// //
// Original (C) 1984 Dan Ts'o <Rockefeller Univ. Dept. of Neurobiology> // Original (C) 1984 Dan Ts'o <Rockefeller Univ. Dept. of Neurobiology>
// Update (C) 2005-2016 Donald N North <ak6dn_at_mindspring_dot_com> // Update (C) 2005-2017 Donald N North <ak6dn_at_mindspring_dot_com>
// //
// All rights reserved. // All rights reserved.
// //
@@ -80,10 +80,9 @@ typedef struct timespec timespec_t;
#define FILERT11INIT 4 // file should be init'ed as RT11 structure #define FILERT11INIT 4 // file should be init'ed as RT11 structure
#define FILEXXDPINIT 5 // file should be init'ed as XXDP structure #define FILEXXDPINIT 5 // file should be init'ed as XXDP structure
#define DEV_NYI -1 // not yet implemented #define DEV_NORMAL 0 // normal data byte
#define DEV_OK 0 // no error #define DEV_BREAK 1 // BREAK on line
#define DEV_BREAK 1 // BREAK on line #define DEV_ERROR 2 // ERROR on byte
#define DEV_ERROR 2 // ERROR on line
@@ -104,8 +103,7 @@ void devtxput (uint8_t);
int32_t devtxwrite (uint8_t *, int32_t); int32_t devtxwrite (uint8_t *, int32_t);
void devrxinit (void); void devrxinit (void);
int32_t devrxavail (void); int32_t devrxavail (void);
int32_t devrxerror (void); uint8_t devrxget (uint8_t *);
uint8_t devrxget (void);
void devinit (char *, int32_t, int32_t); void devinit (char *, int32_t, int32_t);
void devrestore (void); void devrestore (void);
void coninit (void); void coninit (void);

Binary file not shown.

2
file.c
View File

@@ -354,7 +354,7 @@ int32_t fileseek (int32_t unit,
{ {
if (fileunit(unit)) return -1; if (fileunit(unit)) return -1;
if (block*size+offset > lseek(file[unit].fd, 0, SEEK_END)) return -2; if (block*size+offset >= lseek(file[unit].fd, 0, SEEK_END)) return -2;
if (lseek(file[unit].fd, block*size+offset, SEEK_SET) < 0) return -3; if (lseek(file[unit].fd, block*size+offset, SEEK_SET) < 0) return -3;

10
main.c
View File

@@ -74,10 +74,16 @@
// - Added M. Blair's background mode option (no status). // - Added M. Blair's background mode option (no status).
// v1.4n - 06 Apr 2016 - donorth - Added capability for baud rates >230K, up to 3M // v1.4n - 06 Apr 2016 - donorth - Added capability for baud rates >230K, up to 3M
// v1.4o - 09 Jan 2017 - donorth - Removed baud rate 256000, it is nonstandard for unix. // v1.4o - 09 Jan 2017 - donorth - Removed baud rate 256000, it is nonstandard for unix.
// Changed serial setup to use cfsetispeed()/cfsetospeed(). // Changed serial setup to use cfsetispeed()/cfsetospeed()
// Added capability for 1 or 2 stop bits; default is 1 // Added capability for 1 or 2 stop bits; default is 1
// v1.4p - 05 May 2017 - donorth - Updated serial baud rate table with #ifdef detection // v1.4p - 05 May 2017 - donorth - Updated serial baud rate table with #ifdef detection
// Update clock_gettime() for MAC OSX support // 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.
// v2.0b - 03 Apr 2018 - donorth - Change iflags from PARMRK|IGNPAR to PARMRK|INPCK
// //
@@ -88,7 +94,7 @@
static char copyright[] = "(C) 2005-2017 Don North <ak6dn" "@" "mindspring.com>, " \ static char copyright[] = "(C) 2005-2017 Don North <ak6dn" "@" "mindspring.com>, " \
"(C) 1984 Dan Ts'o <Rockefeller University>"; "(C) 1984 Dan Ts'o <Rockefeller University>";
static char version[] = "tu58 tape emulator v1.4p"; static char version[] = "tu58 tape emulator v2.0b";
static char port[32] = "1"; // default port number (COM1, /dev/ttyS0) static char port[32] = "1"; // default port number (COM1, /dev/ttyS0)
static long speed = 9600; // default line speed static long speed = 9600; // default line speed

View File

@@ -2,50 +2,47 @@
# tu58em emulator makefile # tu58em emulator makefile
# #
ifeq ($(comm),mac) # get operating system name
# UNIX comms model, but on a Mac OPSYS = $(shell uname -s)
PROG = tu58em
COMM = -UWINCOMM -DMACOSX ifeq ($(OPSYS),Darwin)
else ifeq ($(comm),win) # mac: UNIX comms model, but on MACOSX
# WINDOWS comms model OPTIONS = -DMACOSX
PROG = tu58ew LFLAGS = -lpthread
COMM = -DWINCOMM BINDIR = /usr/local/bin
else # ifeq ($(comm),unix) else ifeq ($(OPSYS:CYGWIN%=CYGWIN),CYGWIN)
# UNIX comms model # win: WINDOWS comms model under CYGWIN (any version)
PROG = tu58em OPTIONS = -DCYGWIN -DWINCOMM
COMM = -UWINCOMM LFLAGS = -lpthread -lrt
BINDIR = /cygdrive/e/DEC/tools/exe
else ifeq ($(OPSYS),Linux)
# unix: UNIX comms model under LINUX, use PARMRK serial mode
OPTIONS = -DLINUX -DUSE_PARMRK
LFLAGS = -lpthread -lrt
BINDIR = /usr/local/bin
else # unknown environment
OPTIONS =
LFLAGS = -lpthread -lrt
BINDIR = /usr/local/bin
endif endif
# put your binary installation directory here... # default program name, redefine PROG=xxx on command line if wanted
BIN = /cygdrive/e/DEC/tools/exe PROG = tu58em
# compiler flags and libraries # compiler flags and libraries
CC = gcc CC = gcc
CFLAGS = -I. -O3 -Wall -c $(COMM) CFLAGS = -I. -O3 -Wall -c $(OPTIONS)
ifeq ($(comm),mac)
LFLAGS = -lpthread
else
LFLAGS = -lpthread -lrt
endif
$(PROG) : main.o tu58drive.o file.o serial.o $(PROG) : main.o tu58drive.o file.o serial.o
$(CC) -o $@ main.o tu58drive.o file.o serial.o $(LFLAGS) $(CC) -o $@ main.o tu58drive.o file.o serial.o $(LFLAGS)
all : config :
make --always comm=win @echo " OPSYS = \"$(OPSYS)\""
make clean @echo " PROG = \"$(PROG)\""
make --always comm=unix @echo " BINDIR = \"$(BINDIR)\""
make clean @echo " CC = \"$(CC)\""
@echo " CFLAGS = \"$(CFLAGS)\""
mac : @echo " LFLAGS = \"$(LFLAGS)\""
make --always comm=mac
make --clean
installall :
make --always comm=win install
make clean
make --always comm=unix install
make clean
clean : clean :
-rm -f *.o -rm -f *.o
@@ -57,7 +54,7 @@ purge : clean
-rm -f $(PROG) $(PROG).exe -rm -f $(PROG) $(PROG).exe
install : $(PROG) install : $(PROG)
[ -d $(BIN) ] && cp $< $(BIN) [ -d $(BINDIR) ] && cp $< $(BINDIR)
serial.o : serial.c common.h serial.o : serial.c common.h
$(CC) $(CFLAGS) serial.c $(CC) $(CFLAGS) serial.c

184
serial.c
View File

@@ -2,7 +2,7 @@
// tu58 - Emulate a TU58 over a serial line // tu58 - Emulate a TU58 over a serial line
// //
// Original (C) 1984 Dan Ts'o <Rockefeller Univ. Dept. of Neurobiology> // Original (C) 1984 Dan Ts'o <Rockefeller Univ. Dept. of Neurobiology>
// Update (C) 2005-2016 Donald N North <ak6dn_at_mindspring_dot_com> // Update (C) 2005-2017 Donald N North <ak6dn_at_mindspring_dot_com>
// //
// All rights reserved. // All rights reserved.
// //
@@ -56,21 +56,21 @@
#define IUCLC 0 // Not POSIX #define IUCLC 0 // Not POSIX
#define OLCUC 0 // Not POSIX #define OLCUC 0 // Not POSIX
#define CBAUD 0 // Not POSIX #define CBAUD 0 // Not POSIX
#endif #endif // MACOSX
#include <termios.h> #include <termios.h>
#define BUFSIZE 256 // size of serial line buffers (bytes, each way) #define BUFSIZE 256 // size of serial line buffers (bytes, each way)
// serial output buffer // serial output buffer
static uint8_t wbuf[BUFSIZE]; static uint8_t wbuf[BUFSIZE];
static uint8_t *wptr; static uint8_t *wptr;
static int32_t wcnt; static int32_t wcnt;
// serial input buffer // serial input buffer
static uint8_t rbuf[BUFSIZE]; static uint8_t rbuf[BUFSIZE];
static uint8_t *rptr; static uint8_t *rptr;
static int32_t rcnt; static int32_t rcnt;
#ifdef WINCOMM #ifdef WINCOMM
// serial device descriptor, default to nada // serial device descriptor, default to nada
@@ -78,6 +78,7 @@ static HANDLE hDevice = INVALID_HANDLE_VALUE;
// async line parameters // async line parameters
static DCB dcbSave; static DCB dcbSave;
static COMMTIMEOUTS ctoSave; static COMMTIMEOUTS ctoSave;
static uint8_t rxBreakSeen;
#else // !WINCOMM #else // !WINCOMM
// serial device descriptor, default to nada // serial device descriptor, default to nada
static int32_t device = -1; static int32_t device = -1;
@@ -197,6 +198,7 @@ void devrxinit (void)
#ifdef WINCOMM #ifdef WINCOMM
if (!PurgeComm(hDevice, PURGE_RXABORT|PURGE_RXCLEAR)) if (!PurgeComm(hDevice, PURGE_RXABORT|PURGE_RXCLEAR))
error("devrxinit(): error=%d", GetLastError()); error("devrxinit(): error=%d", GetLastError());
rxBreakSeen = 0;
#else // !WINCOMM #else // !WINCOMM
tcflush(device, TCIFLUSH); tcflush(device, TCIFLUSH);
#endif // !WINCOMM #endif // !WINCOMM
@@ -211,75 +213,26 @@ void devrxinit (void)
// //
// wait for an error on the serial line // return number of characters available, get more if receive buffer is empty
// 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
// //
int32_t devrxavail (void) int32_t devrxavail (void)
{ {
// get more characters if none available // get more characters if none available
if (rcnt <= 0) { if (rcnt <= 0) {
#ifdef WINCOMM #ifdef WINCOMM
OVERLAPPED ovlp = { 0 };
COMSTAT stat; COMSTAT stat;
DWORD acnt = 0; DWORD acnt = 0;
DWORD ncnt = 0;
DWORD sts = 0; DWORD sts = 0;
// clear state // clear state
if (!ClearCommError(hDevice, &sts, &stat)) if (!ClearCommError(hDevice, &sts, &stat))
error("devrxavail(): ClearCommError() failed"); error("devrxavail(): ClearCommError() failed");
if (debug && (sts || stat.cbInQue)) // do the read if something there, at most size of buffer
info("devrxavail(): status=0x%04X avail=%d", sts, stat.cbInQue); ncnt = stat.cbInQue > sizeof(rbuf) ? sizeof(rbuf) : stat.cbInQue;
// do the read if something there if (!ReadFile(hDevice, rbuf, ncnt, &acnt, NULL))
if (stat.cbInQue > 0) { error("devrxavail(): error=%d", GetLastError());
ovlp.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); // check for break
if (!ReadFile(hDevice, rbuf, sizeof(rbuf), &acnt, &ovlp)) { if (sts & CE_BREAK) rxBreakSeen = 1;
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);
}
// done // done
rcnt = acnt; rcnt = acnt;
#else // !WINCOMM #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 devtxwrite (uint8_t *buf,
int32_t cnt) int32_t cnt)
@@ -304,28 +257,16 @@ int32_t devtxwrite (uint8_t *buf,
// write characters if asked, return number written // write characters if asked, return number written
if (cnt > 0) { if (cnt > 0) {
#ifdef WINCOMM #ifdef WINCOMM
OVERLAPPED ovlp = { 0 };
COMSTAT stat; COMSTAT stat;
DWORD acnt = 0; DWORD acnt = 0;
DWORD sts = 0; DWORD sts = 0;
// clear state // clear state
if (!ClearCommError(hDevice, &sts, &stat)) if (!ClearCommError(hDevice, &sts, &stat))
error("devtxwrite(): ClearCommError() failed"); error("devtxwrite(): ClearCommError() failed");
if (debug && (sts || stat.cbOutQue))
info("devtxwrite(): status=0x%04X remain=%d", sts, stat.cbOutQue);
// do the write // do the write
ovlp.hEvent = CreateEvent(NULL, FALSE, FALSE, NULL); if (!WriteFile(hDevice, buf, cnt, &acnt, NULL))
if (!WriteFile(hDevice, buf, cnt, &acnt, &ovlp)) { error("devtxwrite(): error=%d", GetLastError());
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);
}
}
// done // done
CloseHandle(ovlp.hEvent);
return acnt; return acnt;
#else // !WINCOMM #else // !WINCOMM
return write(device, buf, cnt); return write(device, buf, cnt);
@@ -370,14 +311,71 @@ void devtxflush (void)
// //
// return char from rbuf, wait until some arrive // return char from rbuf, wait until some arrive
// //
uint8_t devrxget (void) uint8_t devrxget (uint8_t *flg)
{ {
// get more characters if none available uint8_t c;
while (devrxavail() <= 0) /*spin*/;
// count, return next character #ifdef USE_PARMRK
// get more bytes if none available
while (rcnt <= 0) { (void)devrxavail(); }
// at least one available
rcnt--; 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(); int32_t uid = getuid();
setreuid(euid, -1); setreuid(euid, -1);
if (sscanf(port, "%u", &n) == 1) sprintf(name, "\\\\.\\COM%d", n); else strcpy(name, port); 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, // open port in non-overlapped I/O mode
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_OVERLAPPED, NULL); 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); if (hDevice == INVALID_HANDLE_VALUE) fatal("no serial line [%s]", name);
// we own the port
setreuid(uid, euid); setreuid(uid, euid);
// get current line params, error if not a serial port // get current line params, error if not a serial port
@@ -580,10 +586,10 @@ void devinit (char *port,
// open serial port // open serial port
int32_t euid = geteuid(); int32_t euid = geteuid();
int32_t uid = getuid(); int32_t uid = getuid();
setreuid(euid, -1); if (setreuid(euid, -1)) fatal("setreuid(euid,-1) failed");
if (sscanf(port, "%u", &n) == 1) sprintf(name, "/dev/ttyS%u", n-1); else strcpy(name, port); if (sscanf(port, "%u", &n) == 1) sprintf(name, "/dev/ttyS%u", n-1); else strcpy(name, port);
if ((device = open(name, O_RDWR|O_NDELAY|O_NOCTTY)) < 0) fatal("no serial line [%s]", name); if ((device = open(name, O_RDWR|O_NDELAY|O_NOCTTY)) < 0) fatal("no serial line [%s]", name);
setreuid(uid, euid); if (setreuid(uid, euid)) fatal("setreuid(uid,euid) failed");
// get current line params, error if not a serial port // get current line params, error if not a serial port
if (tcgetattr(device, &lineSave)) fatal("not a serial device [%s]", name); if (tcgetattr(device, &lineSave)) fatal("not a serial device [%s]", name);
@@ -595,7 +601,11 @@ void devinit (char *port,
line.c_iflag &= ~( IGNBRK | BRKINT | IMAXBEL | INPCK | ISTRIP | line.c_iflag &= ~( IGNBRK | BRKINT | IMAXBEL | INPCK | ISTRIP |
INLCR | IGNCR | ICRNL | IXON | IXOFF | INLCR | IGNCR | ICRNL | IXON | IXOFF |
IUCLC | IXANY | PARMRK | IGNPAR ); IUCLC | IXANY | PARMRK | IGNPAR );
#ifdef USE_PARMRK
line.c_iflag |= ( PARMRK | INPCK );
#else // !USE_PARMRK
line.c_iflag |= ( 0 ); line.c_iflag |= ( 0 );
#endif // !USE_PARMRK
// output param // output param
line.c_oflag &= ~( OPOST | OLCUC | OCRNL | ONLCR | ONOCR | line.c_oflag &= ~( OPOST | OLCUC | OCRNL | ONLCR | ONOCR |

View File

@@ -2,7 +2,7 @@
// tu58 - Emulate a TU58 over a serial line // tu58 - Emulate a TU58 over a serial line
// //
// Original (C) 1984 Dan Ts'o <Rockefeller Univ. Dept. of Neurobiology> // Original (C) 1984 Dan Ts'o <Rockefeller Univ. Dept. of Neurobiology>
// Update (C) 2005-2016 Donald N North <ak6dn_at_mindspring_dot_com> // Update (C) 2005-2017 Donald N North <ak6dn_at_mindspring_dot_com>
// //
// All rights reserved. // All rights reserved.
// //
@@ -48,6 +48,7 @@
#include "common.h" #include "common.h"
#include <pthread.h> #include <pthread.h>
#include <setjmp.h>
#include "tu58.h" #include "tu58.h"
@@ -55,17 +56,13 @@
// clock_gettime() is not available under MACOSX // clock_gettime() is not available under MACOSX
#define CLOCK_REALTIME 1 #define CLOCK_REALTIME 1
#include <mach/mach_time.h> #include <mach/mach_time.h>
#include <mach/clock.h>
#include <mach/mach.h>
void clock_gettime (int dummy, struct timespec *t) { void clock_gettime (int dummy, struct timespec *t) {
uint64_t mt; uint64_t mt;
mt = mach_absolute_time(); mt = mach_absolute_time();
t->tv_sec = mt / 1000000000; t->tv_sec = mt / 1000000000;
t->tv_nsec = mt % 1000000000; t->tv_nsec = mt % 1000000000;
} }
#endif #endif // MACOSX
// delays for modeling device access // 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 doinit = 0; // set nonzero to indicate should send INITs continuously
static uint8_t runonce = 0; // set nonzero to indicate emulator has been run 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_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 // read of boot is not packetized, is just raw data
// //
@@ -150,7 +167,7 @@ static void bootio (void)
uint8_t buffer[TU_BOOT_LEN]; uint8_t buffer[TU_BOOT_LEN];
// check unit number for validity // check unit number for validity
unit = devrxget(); unit = rxget();
if (fileunit(unit)) { if (fileunit(unit)) {
error("bootio bad unit %d", unit); error("bootio bad unit %d", unit);
return; return;
@@ -240,7 +257,7 @@ static void wait4cont (uint8_t code)
// wait for a CONT to arrive, but only so long // wait for a CONT to arrive, but only so long
do { do {
c = devrxget(); c = rxget();
if (debug) info("wait4cont(): char=0x%02X", c); if (debug) info("wait4cont(): char=0x%02X", c);
} while (c != TUF_CONT && --maxchar >= 0); } while (c != TUF_CONT && --maxchar >= 0);
@@ -293,7 +310,7 @@ static int32_t getpacket (tu_packet *pkt)
uint16_t rcvchk, expchk; uint16_t rcvchk, expchk;
// get remaining packet bytes, incl two checksum bytes // get remaining packet bytes, incl two checksum bytes
while (--count >= 0) *ptr++ = devrxget(); while (--count >= 0) *ptr++ = rxget();
// get checksum bytes // get checksum bytes
rcvchk = (ptr[-1]<<8) | (ptr[-2]<<0); rcvchk = (ptr[-1]<<8) | (ptr[-2]<<0);
@@ -485,7 +502,7 @@ static void tuwrite (tu_cmdpkt *pk)
// loop until we see data flag // loop until we see data flag
do { do {
last = dk.flag; last = dk.flag;
dk.flag = devrxget(); dk.flag = rxget();
if (debug) info("flag=0x%02X last=0x%02X", dk.flag, last); if (debug) info("flag=0x%02X last=0x%02X", dk.flag, last);
if (last == TUF_INIT && dk.flag == TUF_INIT) { if (last == TUF_INIT && dk.flag == TUF_INIT) {
// two in a row is special // two in a row is special
@@ -507,7 +524,7 @@ static void tuwrite (tu_cmdpkt *pk)
} while (dk.flag != TUF_DATA); } while (dk.flag != TUF_DATA);
// byte following data flag is packet data length // byte following data flag is packet data length
dk.length = devrxget(); dk.length = rxget();
// get remainder of the data packet // get remainder of the data packet
if (getpacket((tu_packet *)&dk)) { if (getpacket((tu_packet *)&dk)) {
@@ -579,7 +596,7 @@ static void command (int8_t flag)
time_end.tv_nsec = 0; time_end.tv_nsec = 0;
pk.flag = flag; pk.flag = flag;
pk.length = devrxget(); pk.length = rxget();
// check control packet length ... if too long flush it // check control packet length ... if too long flush it
if (pk.length > sizeof(tu_cmdpkt)) { if (pk.length > sizeof(tu_cmdpkt)) {
@@ -731,11 +748,18 @@ static void* run (void* none)
doinit = !nosync; // start sending init flags? doinit = !nosync; // start sending init flags?
// say hello // say hello
info("emulator %sstarted", runonce++ ? "re" : ""); info("TU58 emulator %sstarted", runonce++ ? "re" : "");
// loop forever ... almost // loop forever ... almost
for (;;) { 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("<BREAK> seen");
// fall thru to main loop
}
// loop while no characters are available // loop while no characters are available
while (devrxavail() == 0) { while (devrxavail() == 0) {
// delays and printout only if not VAX // delays and printout only if not VAX
@@ -754,7 +778,7 @@ static void* run (void* none)
// process received characters // process received characters
last = flag; last = flag;
flag = devrxget(); flag = rxget();
if (debug) info("flag=0x%02X last=0x%02X", flag, last); if (debug) info("flag=0x%02X last=0x%02X", flag, last);
switch (flag) { switch (flag) {
@@ -820,48 +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;
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
return (void*)1;
default: // something else...
error("monitor(): unknown flag %d", sts);
break;
}
// bit of a delay, loop again
delay_ms(5);
}
return (void*)0;
}
// //
// start tu58 drive emulation // start tu58 drive emulation
// //
@@ -872,17 +854,13 @@ void tu58drive (void)
fatal("illegal BLOCKSIZE (%d) / TU_DATA_LEN (%d) ratio", BLOCKSIZE, TU_DATA_LEN); fatal("illegal BLOCKSIZE (%d) / TU_DATA_LEN (%d) ratio", BLOCKSIZE, TU_DATA_LEN);
// say hello // say hello
info("TU58 emulation start"); info("TU58 start");
info("R restart, S toggle send init, V toggle verbose, D toggle debug, Q quit"); info("R restart, S toggle send init, V toggle verbose, D toggle debug, Q quit");
// run the emulator // run the emulator
if (pthread_create(&th_run, NULL, run, NULL)) if (pthread_create(&th_run, NULL, run, NULL))
error("unable to create emulation thread"); 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 // loop on user input
for (;;) { for (;;) {
uint8_t c; uint8_t c;
@@ -914,8 +892,6 @@ void tu58drive (void)
error("unable to restart emulation thread"); error("unable to restart emulation thread");
} else if (c == 'Q') { } else if (c == 'Q') {
// kill the emulator and exit // kill the emulator and exit
if (pthread_cancel(th_monitor))
error("unable to cancel monitor thread");
if (pthread_cancel(th_run)) if (pthread_cancel(th_run))
error("unable to cancel emulation thread"); error("unable to cancel emulation thread");
break; break;
@@ -932,7 +908,7 @@ void tu58drive (void)
error("unable to join on emulation thread"); error("unable to join on emulation thread");
// all done // all done
info("TU58 emulation end"); info("TU58 end");
return; return;
} }