4 ; KERMIT - (Celtic for "FREE")
6 ; This is the CP/M-80 implementation of the Columbia University
7 ; KERMIT file transfer protocol.
11 ; Copyright June 1981,1982,1983,1984,1985
14 ; Originally written by Bill Catchings of the Columbia University Center for
15 ; Computing Activities, 612 W. 115th St., New York, NY 10025.
17 ; Contributions by Frank da Cruz, Daphne Tzoar, Bernie Eiben,
18 ; Bruce Tanner, Nick Bush, Greg Small, Kimmo Laaksonen, Jeff Damens, and many
21 ; This file contains the system-dependent code and data for KERMIT
22 ; specific to the Heath/Zenith H89 and Z100, the Telcon Zorba,
23 ; and the OEM ScreenTyper. All but the latter use VT52 (or a
24 ; replica thereof) for screen output; the ScreenTyper uses the
25 ; same serial port chip as the H89 (an Intel 8250).
29 ; Edit 4, 31-Aug-1989 by Mike Freeman, 301 N.E. 107th Street; Vancouver wa
30 ; 98685 USA; Telephone (206)574-8221: Added Baud-rate Selection and
31 ; Break-sending ability for the Telcon Zorba portable.
33 ; edit 3, 22 July, 1987 by OBSchou to massage code to conform to new set
34 ; of overlay files (stripping out common code to CPXCOM.ASM)
36 ; edit 2 by OBSchou to add in old Kermit-80 V3.5 heath-8 code, formerly
37 ; in CPM directory. Entry from CP/M file:
39 ; This file contains an upgrade to the CPMBASE.M80 KERMIT
40 ; to allow setting and display of baud rates, a bug fix in
41 ; telnet, and an extension of the HELP to show GET (which works
42 ; in this release, on the H8). Look for the new symbol "h8quad"
43 ; (for the heath quad i/o board that it uses) in the conditionals.
44 ; Note that the Heath H8 is NOT the same machine as the H89. The H89
45 ; code does not run 'as is' on the H8, and does NOT initialize the
46 ; UART. Also there was a bug in the telnet section that is fixed
47 ; here, though I expect that it has already been found and fixed
48 ; by now - this is from the DECUS FALL 83 tape. The comments were
49 ; stripped out of this file to make it small enough for my H8 to
50 ; assemble, however, I have put the first section back in to make
51 ; it easier for you to identify. Thanks for a nice product to use
52 ; and work on. Major insertions are heavily commented, edit as needed.
54 ; This modification done by John Mealing, InteCom Inc, 601 Intecom Dr.,
55 ; Allen, TX 75002 (214)797-9141, x-2493, 5 Nov 84.
57 ; [OBSchou notes: This is the header, and the bugs in telnet are
58 ; unknown. telnet routine has been substantially changed anyway with
59 ; 4.08-4.09 revision. As for the major insertions: they probably went
60 ; with the 4.xx re-write. I am unable to test this version: can
61 ; anyone else do so??]
64 ; edit 01 5th Mar 1987 by M J Carter, Nottingham Uni [majoc]
65 ; Split off from CPXSYS.ASM, in order to install support for
66 ; the OEM ScreenTyper. I can't test anything other than the
67 ; ScreenTyper as I haven't the hardware. Any offers?
68 ; Thanks are due to Paul Bartlett of John Elmer
69 ; Electronics Ltd, who provided me with his modified sources
70 ; for (a slightly antiquated) CP/M 4.05 Kermit on which this
73 ; Keep module name, edit number, and last revision date in memory.
74 ;sysedt: db 'CPXSYS.ASM (35) 01-Dec-86 $'
75 ; [majoc 870305] Now in CPXFRK. I'll have to consult on this ...
79 ; Assembly time message to let me know I'm building the right version.
80 ; LASM generates an 'S' error along with the message, which is messy, but
81 ; better than trying to put everything inside a IF m80 OR mac80 conditional,
82 ; because LASM doesn't like nested IF's, either.
85 .printx * Assembling KERMIT-80 for the Heath/Zenith 89 *
89 .printx * Assembling KERMIT-80 for the Heath-8 with Quad IO board *
93 .printx * Assembling KERMIT-80 for the Heath/Zenith Z100 *
97 .printx * Assembling KERMIT-80 for the Telcon Zorba *
101 .printx * Assembling KERMIT-80 for the OEM ScreenTyper *
108 mnport EQU 330O ;Modem data port
112 mnport EQU 330O ;all port addresses can be set by user -
113 mnprts EQU mnport + 05 ; in octal cause heath wrote documents that
114 output EQU 20H ; way -- relative addressing on the UART
115 input EQU 01H ; registers, just to be nice
116 baudls EQU mnport ;ls baud divisor latch when DALB set
117 baudms EQU mnport + 1 ;ms baud divisor latch when DALB set
118 linctl EQU mnport + 3 ;line control register
119 modctl EQU mnport + 4 ;MODEM control register
120 dalbon EQU 80H ;enables speed selection
121 linset EQU 03H ;force hardware 8 bit, even parity
123 ; The line control register (linctl) is bit mapped as follows:
124 ; bit # function value
125 ; 0,1 select word size 00 -> 5 bit, 10 -> 7 bit
126 ; 01 -> 6 bit, 11 -> 8 bit
127 ; 2 select stop bits 0 -> 1 stop bit, 1 -> 1 1/2 for 5 bit,
128 ; 1 -> 2 for 6 bit words
129 ; 3 parity enable 0 -> no parity, 1 -> parity as set by 4
130 ; 4 Even parity select 0 -> Odd parity, 1 -> Even parity
131 ; 5 Stick parity 1 -> Parity of bit 4 is inverted
132 ; 6 Break control 1 -> output forced to spacing (break)
133 ; 7 DALB 1 -> access divisor latches to set baud rate
135 ; The value in linset is loaded into linctl when KERMIT comes up.
137 ms300 EQU 001O ;set for 300 baud as default
139 rtsoff EQU 20O ;direct control of modem lines
141 z80 EQU FALSE ;[2] or is it?
145 mnport EQU 8 ;Modem data port
149 ; Definitions for the 8250 ACE
151 acerbr EQU 0 ; ACE Receiver Buffer Register offset (R/O) (DLAB = 0)
152 acethr EQU 0 ; ACE Transmitter Holding Register offset (W/O)
153 acedll EQU 0 ; ACE Divisor Latch (Low) (DLAB = 1)
154 acedlh EQU 1 ; ACE Divisor Latch (High) (DLAB = 1)
155 aceier EQU 1 ; ACE Interrupt Enable Register (DLAB = 0)
156 aceiir EQU 2 ; ACE Interrupt Identification Register
157 acelcr EQU 3 ; ACE Line Control Register
158 acemcr EQU 4 ; ACE Modem Control Register
159 acelsr EQU 5 ; ACE Line Status Register offset
160 acemsr EQU 6 ; ACE Modem Status Register
162 ace8bw EQU 00000011b ; 8 bit words
163 acesb EQU 01000000b ; set break
164 acedla EQU 10000000b ; divisor latch access
165 acedtr EQU 00000001b ; data terminal ready
166 aceloo EQU 00010000b ; loopback mode
167 acedr EQU 00000001b ; data ready
168 acethe EQU 00100000b ; transmitter holding register empty
170 ;mnport EQU 330O ;Modem data port
171 ; [35a: majoc 870305] Shifted up above joint IF, to save nesting.
172 mnprts EQU mnport+acelsr ;Modem status port
173 output EQU acethe ;Transmitter empty
174 input EQU acedr ;Input data available
175 z80 EQU TRUE ;H89 uses the Z80
176 ENDIF;heath OR scntpr
179 mnport EQU 0ECH ;Modem data port
180 mnprts EQU 0EDH ;Modem status port
181 output EQU 01H ;Transmitter empty
182 input EQU 02H ;Input data available
183 z80 EQU FALSE ;[hh] this one's an 8085.
188 MNPORT EQU 20H ;Modem data port
189 MNPRTS EQU 21H ;Modem status port
190 OUTPUT EQU 01H ;Transmitter empty
191 INPUT EQU 02H ;Input data available
192 BRPORT EQU 00H ;8254-2 Baud Rate Generator Timer for Port A
193 COMMND EQU 03H ;8254-2 Timer Control Port
194 z80 EQU TRUE ;[MF]A real Z80
199 defesc EQU ']'-100O ;The default escape character.
202 IF heath OR h8quad OR z100 OR scntpr
203 defesc EQU '\'-100O ;The default is Control \ -- it's easier B.E.
204 ENDIF;heath OR h8quad OR z100 OR scntpr
206 ; Select initial setting for VT-52 emulation flag.
207 IF (heath OR h8quad OR z100 OR telcon)
208 vtval EQU 0 ; we don't need VT52 emulation
209 ENDIF;heath OR h8quad OR z100 OR telcon OR vt52 [OBS question - ok for h8quad?]
210 ; If none of the above, default to VT52-EMULATION ON.
212 vtval EQU 1 ; we do VT52 emulation
217 ; Family is the string used in VERSION to say which of several
218 ; smaller overlay files are used. These are (will be) derived from
219 ; the juge CPXSYS.ASM file, in which case we will never get here.
220 ; Just a Dollar, but put a sting in for a family of machines.
222 family: db 'CPXHEA.ASM (4) 31-Aug-1989$' ; Used for family versions....
225 sysxin: ; continuation of initialisation code
228 ; System dependent startup for H89 and OEM ScreenTyper
231 call mdmofl ; keep the line safe from garbage
233 ; First, tell Kermit the modem port's current speed
236 out mnport+acelcr ; access the ACE's divisor latch
237 in mnport+acedll ; get the low byte
239 in mnport+acedlh ; and the high byte
242 ; Now set up the port for Kermit
243 mvi a,ace8bw ; 8 data bits, 1 stop bit, no parity
246 ori acedtr ; raise DTR (just in case)
248 call mdmonl ; and put the ACE back on line
251 ; Take the ACE off line before modifying its state
253 in mnport+aceier ; save the ACE's interrupt state
256 out mnport+aceier ; and disable ACE interrupts
257 in mnport+acemcr ; now put the ACE in loopback mode
262 ; Put the ACE back on line
264 in mnport ; flush left-over garbage in the receive buffer
265 mvi a,7 ; wait about 2 300-baud character times
267 in mnport ; and flush more garbage
268 in mnport+acemcr ; take the ACE out of loopback mode
272 out mnport+aceier ; and restore the ACE's interrupt state
276 ENDIF;heath OR scntpr
279 h8init: lxi d,180h ; [2] set up for 300 baud
280 h8baud: mvi a,rtsoff ;disable modem for now
282 mvi a,dalbon ;set for UART speed programming
284 mov a,d ; [2] get ms bits for rate
286 mov a,e ; [2] get ls bits for rate
288 mvi a,linset ;force 8 bit, no parity and clear dalb
290 in mnport ;clear the recieve side
291 mvi a,rtson ;get ready
292 out modctl ;modem is on and ready to go
295 ret ; return from system-dependent routine
299 ; system-dependent termination processing
300 ; If we've changed anything, this is our last chance to put it back.
305 ; system-dependent processing for start of CONNECT command
310 conmsg: ; Messages printed when entering transparent (CONNECT) mode:
313 ; syscls - system-dependent close routine
314 ; called when exiting transparent session.
320 ; sysinh - help for system-dependent special functions.
321 ; called in response to <escape>?, after listing all the
322 ; system-independent escape sequences.
325 IF heath OR scntpr OR telcon;[4]
326 lxi d,inhlps ; we got options...
327 call prtstr ; print them.
328 ENDIF;heath OR scntpr OR telcon
333 ;additional, system-dependent help for transparent mode
334 ; (two-character escape sequences)
336 IF heath OR scntpr OR telcon;[4]
337 db cr,lf,'B Transmit a BREAK'
338 ENDIF;heath OR scntpr OR telcon
341 db cr,lf,'D Drop the line'
342 ENDIF;heath OR scntpr
344 db '$' ;[hh] table terminator
347 ; sysint - system dependent special functions
348 ; called when transparent escape character has been typed;
349 ; the second character of the sequence is in A (and in B).
351 ; non-skip: sequence has been processed
352 ; skip: sequence was not recognized
353 sysint: ani 137O ; convert lower case to upper, for testing...
357 jnz intc00 ; no: try next function character
359 mdmdrp: in mnport+acemcr ; (we also get here from sysbye)
361 out mnport+acemcr ; yes: drop DTR
362 mvi a,50 ; for half a second
366 out mnport+acemcr ; and then restore it
369 ENDIF;heath OR scntpr
371 IF heath OR scntpr OR telcon;[4]
372 cpi 'B' ; send break?
373 jz sendbr ; yes, go do it. return nonskip when through.
374 ENDIF;heath OR scntpr OR telcon
375 jmp rskp ; take skip return - command not recognized.
381 ; Send BREAK on H89 or ScreenTyper
383 sendbr: in mnport+acelcr
385 out mnport+acelcr ; set ACE break condition
387 call delay ; wait 300 milliseconds
390 out mnport+acelcr ; and clear ACE break condition
393 ENDIF;heath OR scntpr
397 ; Send break on Telcon Zorba
399 sendbr: mvi a,3fH ;DTR normal, break on
400 out mnprts ;Set break on
401 mvi a,30 ;Wait 300 ms
403 mvi a,37h ;DTR normal, tx, rx enabled
404 out mnprts ;Restore normal condition
411 ; sysflt - system-dependent filter
412 ; called with character in E.
413 ; if this character should not be printed, return with A = zero.
414 ; preserves bc, de, hl.
415 ; note: <xon>,<xoff>,<del>, and <nul> are always discarded.
417 mov a,e ; get character for testing
420 ; mdmflt - modem filter [30]
421 ; called with character to be sent to printer in E
422 ; with parity set as appropriate.
423 ; return with accumulator = 0 do do nothing,
424 ; <> 0 to send char in E.
426 mov a,e ;[30] get character to test
431 ; prtflt - printer filter [30]
432 ; called with character to be sent to printer in E
433 ; returns with a = 0 to do nothing
434 ; a <> 0 to print it.
436 ; this routine for those printer that automatically insert
437 ; a lf on cr, or cr for lf. Should this be shifted to
438 ; the system indep. stuff, in say 4.06?
440 mov a,e ; [30] get character to test
446 ; system-dependent processing for BYE command.
447 ; for apmmdm, heath, scntpr, and lobo, hang up the phone.
450 call mdmdrp ; Sleazy but effective
451 ENDIF;heath OR scntpr
455 ; This is the system-dependent command to change the baud rate.
456 ; DE contains the two-byte value from the baud rate table; this
457 ; value is also stored in 'speed'.
464 call mdmofl ; keep the line safe from garbage
467 out mnport+acelcr ; access the ACE's divisor latch
468 mov a,e ; low byte of speed is in E
469 out mnport+acedll ; set the low byte
470 mov a,d ; high byte of speed is in D
471 out mnport+acedlh ; set the high byte
474 out mnport+acelcr ; de-access the ACE's divisor latch
475 call mdmonl ; and put the ACE back on line
476 ENDIF;heath OR scntpr
478 IF h8quad ;[2][obs] A bit of guesswork this. Enter with date in de
479 call h8baud ; [2] routine is in initialisation bit
483 MVI A,36H ;Set square wave
485 MOV A,E ;Get LSB of Baud rate
486 OUT BRPORT ;Send to generator
487 MOV A,D ;Get msb of baud rate
488 OUT BRPORT ;Send to Baud rate generator
496 ; (Note that speed tables MUST be in alphabetical order for later
497 ; lookup procedures, and must begin with a value showing the total
498 ; number of entries. The speed help tables are just for us poor
501 ; db string length,string,divisor (2 identical bytes or 1 word)
506 ; Speed selection table for H89 (OK, so I got a little carried away...)
509 spdtbl: db 19 ; 19 entries
550 db ' 50 75 110 134.5 200 300 450 600 900 1200'
551 db cr,lf,' 1800 2400 3600 4800 7200 9600 19200 38400 56000$'
555 spdtbl: db 6 ;[2] 6 entries
556 db 3,'300$', 1,80h ; divisor for 300 baud
563 ; The strings to display the speed selected from the table above
565 sphtbl: db cr,lf,' 300 600 1200 2400 4800 9600$'
569 ; [35a: majoc 870305]
571 ; Speed selection table for ScreenTyper
574 spdtbl: db 14 ; 14 entries
583 db 5,'19200$' ; This was in PB's table, but not in the
584 dw 7H ; accompanying text string. Oversight?
614 sphtbl: db cr,lf,' 50 75 110 134.5 300 600 1200'
615 db cr,lf,' 1800 2400 3600 4800 7200 9600 (19200?)$'
620 ; Speed selection tables for the Telcon Zorba (I overdid it, also)
622 ; **NOTE** that when Kermit is first executed, the baud rate is
623 ; unknown to Kermit, having been set by CP/M upon cold-boot, SETUP.COM,
624 ; another communications program, etc. The easiest way to insure that
625 ; the baud rate is known upon Kermit start-up is to set it
628 spdtbl: db 20 ;[4]Number of entries (some of these
629 ;speeds are *weird* but the Zorba
630 ;supports them so I'll put them in
675 db ' 50 62.5 75 110 134.5 150 200 300 600 1200'
676 db cr,lf,' 1760 1800 2000 2400 3520 3600 4800 7200'
677 db cr,lf,' 9600 19200$'
681 ; The following conditionals were once a huge if not statement. There
682 ; wasn't enough room to add the lobo to the list, so it had to be broken
683 ; into 2, which you can't do with an if not. I redid it as two ifs and
684 ; applied them to those that wouldn't set baud. [Hal Hostetler]
686 spdtbl equ 0 ; SET BAUD not supported.
691 ; This is the system-dependent SET PORT command.
692 ; HL contains the argument from the command table.
696 prttbl equ 0 ; SET PORT is not supported
701 ; selmdm - select modem port
702 ; selcon - select console port
703 ; selmdm is called before using inpmdm or outmdm;
704 ; selcon is called before using inpcon or outcon.
705 ; For iobyt systems, diddle the I/O byte to select console or comm port;
706 ; For Decision I, switches Multi I/O board to console or modem serial
708 ; For the rest, does nothing.
709 ; preserves bc, de, hl.
716 ; Get character from console, or return zero.
717 ; result is returned in A. destroys bc, de, hl.
721 mvi c,dconio ;Direct console I/O BDOS call.
729 ; Output character in E to the console.
730 ; destroys bc, de, hl
734 mvi c,dconio ;Console output bdos call.
735 call bdos ;Output the char to the console.
740 ; outmdm - output a char from E to the modem.
741 ; the parity bit has been set as necessary.
742 ; returns nonskip; bc, de, hl preserved.
745 in mnprts ;Get the output done flag.
746 ani output ;Is it set?
747 jz outmdm ;If not, loop until it is.
749 out mnport ;Output it.
754 ;**** Note that we enter from outpkt with the I/O byte already set up for
755 ; output to go to the comm port
758 lda prtfun ;Get the output function
760 call bdos ;And output the character
768 ; get character from modem; return zero if none available.
769 ; for IOBYT systems, the modem port has already been selected.
770 ; destroys bc, de, hl.
772 IF NOT iobyt ;[2] this routine not in submitted file, so I guess
773 ; guess this is what it is supposed to do.
774 in mnprts ; input status port
775 ani input ; anything t read in?
777 in mnport ; else read in the data
778 ret ; return with character in A
779 ENDIF ; NOT iobyte [2]
782 ; flsmdm - flush comm line.
784 ; Currently, just gets characters until none are available.
786 flsmdm: call inpmdm ; Try to get a character
788 jnz flsmdm ; If so, try for another
789 ret ; Receiver is drained. Return.
792 ; lptstat - get the printer status. Return a=0ffh if ok, or 0 if not.
794 call bprtst ; assume it is ok.. this may not be necessary
798 ; outlpt - output character in E to printer
799 ; console is selected.
802 push d ; save DE in either case
803 call prtflt ; go through printer filter [30]
804 ana a ; if A = 0 do nothing,
805 jz outlp1 ; [30] if a=0 do nothing
809 call bdos ;Char to printer
811 outlp1: pop d ; restore saved register pair
815 ; Screen manipulation routines
816 ; csrpos - move to row B, column C
818 ; csrpos for terminals that use a leadin sequence followed
819 ; by (row + 31.) and (column + 31.)
821 csrpos: push b ; save coordinates
822 lxi d,curldn ; get cursor leadin sequence
823 call prtstr ; print it
824 pop h ; restore coordinates
826 adi (' '-1) ; space is row one
829 call outcon ; output row
832 adi (' '-1) ; space is column one
834 jmp outcon ; output it and return
837 ; delchr - make delete look like a backspace. Unless delete is a printing
838 ; character, we just need to print a backspace. (we'll output clrspc
840 ; For Kaypro and Vector General, delete puts a blotch on the screen.
841 ; For Apple and Osborne 1, delete moves but doesn't print.
843 mvi e,bs ;get a backspace
846 ; erase the character at the current cursor position
849 mvi e,bs ;get a backspace
852 ; erase the current line
856 ; erase the whole screen, and go home. preserves b (but not c)
861 sysver: db 'Telcon Zorba$'
865 sysver: db 'Heath/Zenith 89$'
869 sysver: db 'Heath H8 with quad I/O card$'
873 sysver: db 'Heath/Zenith Z-100 CP/M$'
877 ; [35a: majoc 870305]
878 sysver: db 'OEM ScreenTyper: 4MHz Z80 running OS/M$'
881 IF heath OR h8quad OR z100 OR telcon
882 outlin: db esc,'H',esc,'J',cr,lf,tab,tab,'$'
883 erascr: db esc,'H',esc,'J$' ;Clear screen and go home.
884 eralin: db cr,esc,'K$' ;Clear line.
885 curldn: db esc,'Y$' ;cursor leadin
886 ttab: ;Table start location.
887 ta: db esc,'A$',0 ;Cursor up.
888 tb: db esc,'B$',0 ;Cursor down.
889 tc: db esc,'C$',0 ;Cursor right.
890 td: db esc,'D$',0 ;Cursor left
891 te: db esc,'E$',0 ;Clear display
892 tf: db esc,'F$',0 ;Enter Graphics Mode
893 tg: db esc,'G$',0 ;Exit Graphics mode
894 th: db esc,'H$',0 ;Cursor home.
895 ti: db esc,'I$',0 ;Reverse linefeed.
896 tj: db esc,'J$',0 ;Clear to end of screen.
897 tk: db esc,'K$',0 ;Clear to end of line.
898 ENDIF;heath OR h8quad OR z100 OR telcon
901 IF scntpr ; [35a: majoc 870305]
902 outlin: db 1aH, cr, lf, '$'
903 erascr: db 1aH, '$' ;Clear screen and go home.
904 eralin: db cr,esc,'*$' ;Clear line.
905 curldn: db esc,'=$' ;cursor leadin
906 ttab: ;Table start location.
907 ta: db 1eH,'$',0,0 ;Cursor up.
908 tb: db 1fH,'$',0,0 ;Cursor down.
909 tc: db 1cH,'$',0,0 ;Cursor right.
910 td: db 1dH,'$',0,0 ;Cursor left
911 te: db 1aH,'$',0,0 ;Clear display
912 tf: db 0,0,0,0 ;(Can't)Enter Graphics Mode
913 tg: db 0,0,0,0 ;(Can't)Exit Graphics mode
914 th: db 15H,'$',0,0 ;Cursor home.
915 ti: db 1eH,'$',0,0 ;Reverse linefeed.
916 tj: db esc,'%$',0 ;Clear to end of screen.
917 tk: db esc,'*$',0 ;Clear to end of line.
920 ovlend EQU $ ; End of overlay
921 END ; Phew ... [majoc 870305]