[net.micro.trs-80] TERMCAP the story unfolds

johnw@reed.UUCP (John Windberg) (09/18/85)

From tektronix!tekred!ronbe Tue Sep 17 18:23:48 1985
From: tektronix!tekred!ronbe
Message-Id: <8509180123.AA08967@reed.UUCP>
To: tektronix!reed!johnw
Fcc: inbox
Received: from tekred.uucp by tektronix ; 17 Sep 85 18:02:56 PDT
Date: Tuesday, 17 Sep 85 17:06:53 PDT
Subject: TERMCAP
Status: R




There has been some confusion lately about termcaps and
different terminal emulators.  For this reason I'm posting
the termcap I use with my TRSTERM program, and giving an
explanation of each entry.  The following may be included as
part of your .login file:
--------------------------------------------------------------
if ($term == 'dialup') then
	echo 'trs80' > ~/.termset
	setenv TERM trs80
	setenv TERMCAP 'trs80|trs-80:\
	:am:bs:bw:cd=\037:ce=\036:cl=\034\037:co#64:\
	:do=^Z:ho=\034:is=\034\037:kd=\n:kl=\b:kr=\t:\
	:ku=[:li#16:ll=\034\033:nd=^Y:sr=\022:up=\E'
#	if this stuff is in /etc/termcap
#	tset -s -Q -m':?trs80' > ~/.termset
#	source ~/.termset
else
# put a '?' here -----\/ for question
	tset -s -Q -m':vt100v' > ~/.termset
	source ~/.termset
endif
--------------------------------------------------------------
Now a brief description of each entry:

am means the terminal has automatic margins.  This means that
if the cursor is at the end of the line and the host computer
sends a space (or any other printable character), the cursor
will move to the first of the next line rather than sitting at
the end of the same line.

bs means the terminal can backspace with a cntl-H.  This is
standard on most terminals except some printers.

bw means backspace wraps from column 0 to the last column of
the previous line.  Similar to am, but running in reverse.

cd=\037 tells UNIX what to send to erase to the end of the
display.  \037 is octal for 1F hex.  See page 228 of the
Operation and BASIC Language Manual for standard definitions.
It shows the effect of 1FH as "Erase to end of display".

ce=\036 tells UNIX what to send to erase to the end of the
current line.  The BASIC manual says "Erase to end of line" for
1EH.

cl=\034\037 tells UNIX how to clear the screen.  \034 (1CH)
moves the cursor to the upper left corner of the screen and
\037 (1FH) erases to the end of the display.

co#64 tells UNIX that there are 64 columns on the screen.

do=^Z tells UNIX what to send to move the cursor down one line.
This is 1AH.

ho=\034 tells UNIX how to home the cursor.  1CH moves the
cursor to the upper left corner of the screen.

is=\034\037 is the initialization string.  Same as the cl
entry, it just clears the screen.  This will happen only if
tset is used.

kd=\n tells UNIX what the terminal will send for a down-arrow
key.  \n is shorthand for \012 or 0AH, which is what the
down-arrow key on the TRS-80 keyboard sends.

kl=\b tells UNIX what the terminal will send for a left-arrow
key.  \b is shorthand for \010 or 08H, which is what the
backspace key on the TRS-80 keyboard sends.

kr=\t tells UNIX what the terminal will send for a right-arrow
key.  \t is shorthand for \011 or 09H, which is what the tab
key on the TRS-80 keyboard sends.  This lets the tab key move
the cursor right in vi, but also allowing it to function as a
tab key in insert move and at other times.

ku=[ tells UNIX what the terminal will send for an up-arrow
key.  [ or \133 or 5BH is what the up-arrow key on the TRS-80
keyboard sends.

li#16 tells UNIX that there are 16 lines on the screen.

ll=\034\033 tell UNIX how to move the cursor to the bottom
left-hand corner of the screen.  \034 (1CH) moves the cursor
to the upper left-hand corner, and \033 (1BH) moves the cursor
up one line, wrapping to the bottom.

nd=^Y tells UNIX how to send a non-destructive space (move the
cursor right).  ^Y is shorthand for \031 or 19H which will move
the cursor right on the TRS-80.

sr=\022 tells UNIX how to reverse scroll the screen.  /022 or
12H normally has no effect on the TRS-80, but TRSTERM handles
this character and scrolls the screen backwards.

up=\E tells UNIX how to move the cursor up one line.  \E is
shorthand for escape, or \033 or 1BH.  This character moves the
cursor up on the TRS-80.

	The problem with using a TRS-80 as a terminal emulator
for UNIX is the fact that Radio Shack handles a couple of
control characters differently than the rest of the world.
Typically, a terminal receiving a linefeed (\012 or 0AH) will
move the cursor straight down one line.  The same terminal
receiving a carriage return (\015 or 0DH) will move the cursor
to the beginning of the SAME line.  TRS-80's treat these two
characters equally, and move the cursor to the beginning of the
NEXT line, erasing that next line.  Anyone who has tried to
write a terminal emulation program with an associated termcap
for a TRS-80 can testify to the fact that this causes problems.

	There are routines in the TRS-80 ROM that display
characters on the screen.  People familiar with Z80 programming
will recognize the VDCHAR routine at 0033H as the entry point
for these routines.  While the computer is scrolling the screen
(an operation that takes a 'long' time, relatively speaking),
or displaying any other character using these routines in ROM,
interrupts are disabled, and nothing else can happen until the
operation is finished.  For this reason, terminal emulators
that use these routines will probably lose characters at 1200
baud or more.  This is because characters come in from the
RS-232C at a high rate, and are lost while the computer is
busy displaying things on the screen.  Even if the programmer
causes the incoming characters to cause interrupts, those
interrupts will not occur since the VDCHAR routine disables
interrupts while it does its stuff.

	Another problem is the fact that the VDCHAR routine
ignores tab characters (\011 or 09H).  The programmer must
synthesize these without using the VDCHAR routines.

	Also, the TRS-80 has no built-in bell.  A solution
could be to send bell characters (\007 or 07H) to the printer
if there is a printer attached that can produce sound.  Another
solution would be to create a routine for a video bell which
would do something on the display that would catch the
operator's eye.

	Another problem is the fact that the TRS-80 keyboard is
limited.  That is, there is no tilda, braces, brackets,
carat, pipe, backslash, backquote, or underline that are often
very important for UNIX.

--------------------------------------------------------------

Okay, enough problems.  Let's talk solutions.

	The first thing I did in TRSTERM is to write my own
VDCHAR routines.  Since the ROM routines do lots of checking for
things like double-wide screen and alternate character sets
that I didn't want to use, I figured if I left that junk out I
would be able to speed things up.  Also, I wanted the tab,
carriage return, linefeed, and bell to be handled normally
along with all the other characters.

	My goal was to use my 1200 baud modem without losing
characters.  With the new VDCHAR routines done, the screen
handlers worked faster, but I still lost characters when the
screen was scrolling.  If I received more than 2 or 3
linefeeds, the following characters were missed.

	The earliest versions of TRSTERM included a way to send
all the characters that UNIX needed (the tilda, pipe, etc.).
Since I was still losing characters, I went to an interrupt
scheme.  Each incoming character caused an interrupt, and the
interrupt handler read the character and placed it into a
circular buffer.  The background (non-interrupt) routines
checked for characters from the circular buffer rather than
from the RS-232C.  This way, the computer could be busy
scrolling the screen, and get an interrupt in the middle.
The character would be saved away for use when the background
routines were ready for it, and the scrolling would continue.
Eureka!  1200 baud works!  I later found that I can go up to
4800 baud without losing characters.  The program will even
function up to 19200 baud as long as there are not more than 10
or so consecutive linefeeds.  I ended up using a 200 character
circular buffer.  Making this buffer larger would decrease the
number of lost characters at higher baud rates.

	If characters are lost, the reverse video question mark
is displayed in the upper right hand corner of the screen.
This should not happen below 9600 baud.  My VDCHAR routine does
NOT disable interrupts.

	In the first versions, I sent bell characters to the
printer.  This is forced.  In other words, if there is no
printer attached, or the printer is off-line, no harm done.
I later added a video bell that causes a cursor to streak
across the screen in addition to the printer bell.

	Special characters are sent by pressing CLEAR, then
another character.  For example, to send a carat (^), you
would press CLEAR, then the UP-ARROW.  To send a control-C, you
would press CLEAR, then C.  (Escape is sent by pressing SHIFT
and UP-ARROW together.)

	I wanted more.  I wanted to be able to upload and
download from the TRS-80's disk to UNIX.  I also wanted to be
able to print things as they came in from the host.  Since the
printer is notoriously slow, I added a second, much larger,
circular buffer.  This buffer uses all available RAM.
Characters coming in from the RS-232C could be put into the
buffer.  The BREAK key would turn this buffering capability on
and off.  I added a command menu which could be accessed by
pressing CLEAR twice.  Selections would include:

Download a disk file.  Read a file from disk, sending each
character to UNIX.  Since UNIX buffers incoming characters, I
thought I could send like crazy.  Not so.  I was overdriving
UNIX.  Since the program works in full duplex (host echos)
mode, the solution was to send a line up to and including the
carriage return, then wait for the carriage return to echo
before sending the next line.

Write the buffer to disk.  If buffering (BREAK) was on,
characters were being stored in the big buffer.  If not being
used for printing, I wanted to create a file on the disk with
the data in the circular buffer.

Clear the buffer.  To lose everything that was in the big
circular buffer.  Not to affect whether buffering was on or
off.

Printer on/off.  To use the big buffer as a printer spooler.
If on, the printer would be printing while I was doing other
things.  The printer is slow, and was usually quite a bit
behind whatever I was doing.  The background routines check
the circular buffer and if there are characters in it and the
printer is on and ready, a character was sent to the printer.
This resulted in the printer running as fast as it could while
not effecting anything else.

XMODEM.  Ward Christensen developed a useful file transfer
protocol and I incorporated in into TRSTERM for error-checking
ability in both sending and receiving.  Our UNIX system has a
version of XMODEM, so I use that more than download and writing
the buffer.  This is real helpful when you get a bad phone
line.

Quit.  A way to exit the program and return to DOS.  Exiting
the program should not drop the line, so you can do DOS
operations and then return to TRSTERM without having to re-dial
and log in again.

	I have a weird password.  It's hard to type, but you'd
never guess it.  I also have an auto-dial modem.  So I added an
auto-login feature.  You can create a file with lines
specifying what to send and what to wait for.  Mine looks like
this:
--------------------------------------------------------------
S^E$
RHELLO:I'M READY$*
S2$
R$$$
S$
RDIALING...$
RANSWER TONE$
RON LINE$
Rlogin: 
Sronbe$
RPassword:
Sthinkitellu?$
--------------------------------------------------------------
	Lines beginning with S are sent, and lines beginning
with R are received (waited for).  Dollar signs represent
carriage returns.  The first line sends a control-E followed by
a carriage return to get the modem's attention.  Then a
dialogue goes on with the modem until I'm on-line with the
computer.  Then the dialogue continues with the computer until
I'm logged on.  I store the above file as LOGIN/BLD on the
TRS-80 disk.  To use it, I type "TERM LOGIN/BLD" at the DOS
READY prompt.

	Somebody told me they wanted a way to send a break
signal, so I included that, too.  Press CLEAR, then BREAK.
Hold down BREAK for as long as you want the signal to be sent.

	The program hasn't undergone any changes in the last
month or so, so I think it's in it's final form.  As I've
written before, it's not for sale, but it's free to anybody
that wants it.  All I ask is that the copyright notice remains
intact.  If you have a way to download, call my bulletin board
at (503) 923-0580 and get TERM/SRC or TERM/CMD (XMODEM only).
If not, I'll be happy to send you a copy on disk.  I've already
mailed out quite a few.  You provide the disk.  If you go this
route, you'll also get a bunch of other stuff on the disk.
Mailing address is below.

	Hope this rather long posting has helped somebody
understand termcaps and the problems associated with using
TRS-80's for terminal emulation.  I'm 100% behind the guy who
still has a Model I or Model III while all the new 16- and
32-bit PCs are coming out.  I would also hope that any bugs
found in any of my programs (heaven forbid!) would be reported
to me.

			Happy hacking,
			Ron Bemis


Ron Bemis 659 SW 29th St Redmond, OR  97756
(503) 923-4460 (work) (503) 923-0580 (BBS)
...tektronix!tekred!ronbe