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
25 ;edit 4, 7-Jan-1991 by MF. Added code to support the Ampro Little Board.
26 ; The code was contributed by Jay S. Rouman; 913 North Drive;
27 ; Mt. Pleasant, MI 48858 (voice (517)773-7887).
28 ; edit 3, 23 July by OBSchou to massage file to suit CPXCOM.ASM
30 ; edit 2 23 May 1987 by C.J.MILES@UMRCC.
31 ; Reorganised file to be similar in structure to that
32 ; of the Amstrad sys-dep file. Added hangup in clear
33 ; screen options in CONNECT mode.
35 ; edit 1 10 May 1987 by Chris Miles (C.J.MILES@UMRCC)
36 ; Removed Kaypro, Xerox and Big Board from CPXSYS.ASM
37 ; and grouped them into this file as CPXBBI.ASM.
41 ; Original code broken off and modified by:
44 ; 344, Claremont Road,
53 ; *** MAIN CODE START ***
56 ; Keep module name, edit number, and last revision date in memory.
58 sysedt: db 'CPXSYS.ASM (35) 01-Dec-86$'
59 family: db 'CPXBBI.ASM (4) 7-Jan-1991$'
62 ; Assembly time message announcing which version we're building
65 .printx * Assembling Kaypro II KERMIT-80 *
69 .printx * Assembling Xerox 820 KERMIT-80 *
73 .printx * Assembling BigBoard II KERMIT-80 *
77 .printx * Assembling Ampro Little Board KERMIT-80 *
80 z80 EQU TRUE ; They all use Z80s
83 defesc EQU ']'-100O ;The default escape character for Xerox
87 defesc EQU '\'-100O ;The default escape character for Kaypro
90 ; If one of the above, default to VT52-EMULATION ON.
97 ; Specific machine hardware information
100 mnport equ 04h ; Modem data port
101 mnprts equ 06h ; Modem status port
102 output equ 04h ; Transmit buffer empty
103 input equ 01h ; Receive data available
104 baudrt equ 00h ; Baud rate port for channel A
109 mnport equ 80h ; Modem data port (SIO channel A)
110 mnprts equ 81h ; Modem status port
111 output equ 04h ; Transmit buffer empty
112 input equ 01h ; Receive data available
113 baudrt equ 89h ; Baud rate port for channel A
117 mnport equ 88h ; Modem data port (SIO channel B)
118 mnprts equ 8Ch ; Modem status port
119 output equ 04h ; Transmit buffer empty
120 input equ 01h ; Receive data available
121 baudrt equ 50h ; Baud rate port for channel B
125 sysxin: ;continuation of system initialisation code
126 lxi d,siotbl ; Load the address of the status able
127 mvi c,siolen ; Length of status table
128 siolup: ; Loop back here for each command byte
129 ldax d ; Load the first byte into A
130 inx d ; Index the pointer
131 out mnprts ; Send it to the status port
132 dcr c ; Decrement the byte counter
133 jnz siolup ; Jump back for more commands
134 ret ; return from system-dependent routine
136 ; List of commands to set up SIO channel A for asynchronous operation.
138 siotbl: DB 18H ; Channel reset
139 DB 18H ; another, in case register 0 wasn't selected
140 DB 04H ; Select register 4
141 DB 44H ; 1 stop bit, clock*16
142 DB 01H ; Select register 1
143 DB 00H ; No interrupts enabled
144 DB 03H ; Select register 3
145 DB 0C1H ; Rx enable, 8 bit Rx character
146 DB 05H ; Select register 5
147 DB 0EAH ; Tx enable, 8 bit Tx character,
149 siolen equ $-siotbl ; length of command list
153 ; sysexit - System-dependent termination processing
154 ; if we've changed anything, this is our last
155 ; chance to put it back.
161 ; syscon - System-dependent processing for start
162 ; of CONNECT command.
169 conmsg: ; Messages printed when entering transparent (CONNECT) mode:
172 ; syscls - system-dependent close routine
173 ; called when exiting transparent session.
178 ; sysinh - help for system-dependent special functions.
179 ; called in response to <escape>?, after listing
180 ; all the system-independent escape sequences.
183 lxi d,inhlps ; we got options...
184 call prtstr ; print them.
188 ; additional, system-dependent help for transparent mode
189 ; (two-character escape sequences)
191 db cr,lf,'B Transmit a BREAK'
192 db cr,lf,'H Hangup using DTR'
193 db cr,lf,'W Wipe screen clear'
196 ; sysint - system dependent special functions
197 ; called when transparent escape character has been typed;
198 ; the second character of the sequence is in A (and in B).
200 ; non-skip: sequence has been processed
201 ; skip : sequence was not recognized
203 sysint: ani 137O ; convert lower case to upper, for testing...
204 cpi 'B' ; send break ?
205 jz sendbr ; then jump to send break routine
207 jz hangup ; then jump to hangup routine
208 cpi 'W' ; clear screen ?
209 jz clrtop ; then jump to clear screen routine
210 jmp rskp ; take skip return - command not recognized.
213 ; Hangup and Break routines
216 mvi d,0ah ; set up hangup bit mask
217 mvi e,255 ; time for hangup is 2 1/2 secs
218 jmp setbit ; skip Tx empty test
221 mvi d,9ah ; set up break bit mask
222 mvi e,30 ; time for break is 300 ms
224 sndbr1: mvi a,1 ; select Read Register 1
226 in mnprts ; read the contents
227 ani 1 ; test "all done" flag
228 jz sndbr1 ; loop until it's nonzero.
230 ; Next, set the break or DTR bit on the SIO
233 mvi a,5 ; select Write Register 5
235 mvi a,6ah ; Tx enable, 8 bit Tx character,
236 ora d ; OR with appropriate bit mask
239 ; Now, delay for duration of hangup or break
240 mov a,e ; delay count
243 ; Time's up. Put transmitter back in normal state and return.
244 mvi a,5 ; select Write Register 5
246 mvi a,0eah ; Tx enable, 8 bit Tx character,
250 ; sysflt - system-dependent filter
251 ; called with character in E.
252 ; if this character should not be printed, return with A = zero.
253 ; preserves bc, de, hl.
254 ; note: <xon>,<xoff>,<del>, and <nul> are always discarded.
257 mov a,e ; get character for testing
261 ; sysbye - system-dependent processing for BYE command.
266 ; This is the system-dependent command to change the baud rate.
267 ; DE contains the two-byte value from the baud rate table; this
268 ; value is also stored in 'speed'.
272 ; Set the speed for bigboard II
274 di ; don't let anything between the data bytes
275 mvi a,01000111b ; get the command byte (load time constant)
276 out baudrt ; output it to CTC
277 mov a,e ; Get the parsed value.
278 out baudrt ; Tell the baud rate generator.
279 ei ; end of critical section
284 ; Set the speed for bigboard I
286 mov a,e ; get the parsed value
287 out baudrt ; Tell the baud rate generator.
291 ; set the speed for the Ampro Little Board
293 mvi e,3fh ; offset to port b ctc 3f hex bytes
295 mvi a,47h ; counter mode,ctc reset,value follows
296 mov m,a ; store value
297 lda speed+1 ; get ctc divisor
298 inx h ; location of ctc divisor
299 mov m,a ; store new divisor
301 ; set up wr4 clock divisor according to mspeed
303 mvi e,50h ; offset to dart wr4
305 mvi a,3fh ; mask for wr4 clock bits
306 ana m ; mask off bits
307 mov m,a ; and save to wr4
308 lda speed ; get clock flag
309 ora a ; set flags, zero = 300 bps
310 mvi a,80h ; x32 clock bit
311 jz lbps ; setup wr4 for 300 bps x32 clock
313 ; set up wr4 value for 1200 bps x16 clock 'hl' has wr4 loc
315 hbps: mvi a,40h ; x16 clock
317 ; setup wr4 value for 300 bps x32 clock 'hl' has wr4 loc
319 lbps: ora m ; set clock bits saving parity
320 mov m,a ; store new clock divisor to wr4 value
322 ; initialize sio/dart
325 push h ; set up for return
326 mvi e,36h ; offset to ioinit
328 pchl ; we pushed return address
332 ; return bios location in 'hl' called with offset in 'e'
335 lhld 1 ; get bios location
344 ; (Note that speed tables MUST be in alphabetical order for later
345 ; lookup procedures, and must begin with a value showing the total
346 ; number of entries. The speed help tables are just for us poor
349 ; db string length,string,divisor (2 identical bytes or 1 word)
353 spdtbl: db 10h ;16 entries
354 db 03h,'110$', 02h,02h
355 db 04h,'1200$', 07h,07h
356 db 05h,'134.5$', 03h,03h
357 db 03h,'150$', 04h,04h
358 db 04h,'1800$', 08h,08h
359 db 05h,'19200$', 0fh,0fh
360 db 04h,'2000$', 09h,09h
361 db 04h,'2400$', 0ah,0ah
362 db 03h,'300$', 05h,05h
363 db 04h,'3600$', 0bh,0bh
364 db 04h,'4800$', 0ch,0ch
365 db 02h,'50$', 00h,00h
366 db 03h,'600$', 06h,06h
367 db 04h,'7200$', 0dh,0dh
368 db 02h,'75$', 01h,01h
369 db 04h,'9600$', 0eh,0eh
371 sphtbl: db cr,lf,' 50 75 110 134.5 150 300 600 1200'
372 db cr,lf,' 1800 2000 2400 3600 4800 7200 9600 19200$'
376 spdtbl: db 8 ; 8 entries
377 db 04h,'1200$', 20h,20h
378 db 05h,'19200$', 02h,02h
379 db 04h,'2400$', 10h,10h
380 db 03h,'300$', 80h,80h
381 db 05h,'38400$', 01h,01h
382 db 04h,'4800$', 08h,08h
383 db 03h,'600$', 40h,40h
384 db 04h,'9600$', 04h,04h
386 sphtbl: db cr,lf,' 300 600 1200 2400 4800 9600 19200 38400$'
391 spdtbl: db 6 ; 6 entries
392 db 04h,'1200$', 1,104
399 sphtbl: db cr,lf,' 300 600 1200 2400 4800 9600$'
402 ; This is the system-dependent SET PORT command.
403 ; HL contains the argument from the command table.
409 prttbl equ 0 ; SET PORT is not supported
413 ; selmdm - select modem port
414 ; selcon - select console port
415 ; selmdm is called before using inpmdm or outmdm;
416 ; selcon is called before using inpcon or outcon.
417 ; preserves BC, DE, HL.
423 ; Get character from console, or return zero.
424 ; result is returned in A. destroys bc, de, hl.
427 mvi c,dconio ;Direct console I/O BDOS call.
433 ; Output character in E to the console.
434 ; destroys bc, de, hl
438 mvi c,dconio ;Console output bdos call.
439 call bdos ;Output the char to the console.
444 ; outmdm - output a char from E to the modem.
445 ; the parity bit has been set as necessary.
446 ; returns nonskip; bc, de, hl preserved.
448 in mnprts ;Get the output done flag.
449 ani output ;Is it set?
450 jz outmdm ;If not, loop until it is.
452 out mnport ;Output it.
457 ; get character from modem; return zero if none available.
458 ; destroys bc, de, hl.
460 in mnprts ;Get the port status into A.
461 ani input ;See if the input ready bit is on.
462 rz ;If not then return.
463 in mnport ;If so, get the char.
465 ret ; return with character in A
469 ; flsmdm - flush comm line.
471 ; Currently, just gets characters until none are available.
473 flsmdm: call inpmdm ; Try to get a character
475 jnz flsmdm ; If so, try for another
476 ret ; Receiver is drained. Return.
478 ; lptstat - get the printer status. Return a=0ffh if ok, or 0 if not.
480 xra a ; assume it is ok.. this may not be necessary
484 ; outlpt - output character in E to printer
485 ; console is selected.
488 push d ; save DE in either case
489 ana a ; if A = 0 do nothing,
490 jz outlp1 ; [30] if a=0 do nothing
492 call bdos ;Char to printer
493 outlp1: pop d ; restore saved register pair
498 ; Screen manipulation routines
499 ; csrpos - move to row B, column C
501 ; csrpos for terminals that use a leadin sequence followed
502 ; by (row + 31.) and (column + 31.)
504 IF NOT (bbII OR ampro) ;[obs I think ]
505 csrpos: push b ; save coordinates
506 lxi d,curldn ; get cursor leadin sequence
507 call prtstr ; print it
508 pop h ; restore coordinates
510 adi (' '-1) ; space is row one
513 call outcon ; output row
516 adi (' '-1) ; space is column one
518 jmp outcon ; output it and return
519 ENDIF ; NOT bbII OR ampro
522 ; delchr - make delete look like a backspace. Unless delete is a
523 ; printing character, we just need to print a backspace
524 ; (we'll output clrsp afterwards)
534 mvi e,bs ;get a backspace
538 ; erase the character at the current cursor position
541 mvi e,bs ;get a backspace
544 ; erase the current line
548 ; erase the whole screen, and go home. preserves b (but not c)
552 ; If its a BigBoard or Ampro, we need a terminal, so link to CPXVDU.ASM
554 sysver: db 'Big Board II$'
558 sysver: db 'Ampro Little Board$'
561 IF (bbII AND lasm) ; we need a terminal as well
563 ENDIF ;(bbII AND lasm)
565 IF (ampro AND lasm) ; we need a terminal as well
567 ENDIF ;(ampro AND lasm)
569 ;If here, we are Kaypro or Xerox 820, or if from M80, we should skip
570 ; a few lines if Bigboard.
574 ttytyp: db 'Kaypro II$'
575 outlin: db subt,cr,lf,tab,tab,'$'
576 erascr: db subt,'$' ;Clear screen and home.
577 eralin: db cr,18H,'$' ;Clear line.
578 curldn: db esc,'=$' ;Cursor lead-in
579 delstr: db bs,' ',bs,bs,'$' ; adjust for echoing delete character
580 ttab: ;Table start location.
581 ta: db 0BH,'$',0,0 ;Cursor up.
582 tb: db 0AH,'$',0,0 ;Cursor down.
583 tc: db 0CH,'$',0,0 ;Cursor right.
584 td: db bs,'$',0,0 ;Cursor left
585 te: db subt,'$',0,0 ;Clear display
586 tf: db esc,'G$',0 ; Enter Graphics Mode (select Greek)
587 tg: db esc,'A$',0 ; Exit Graphics mode (select ASCII)
588 th: db 1EH,'$',0,0 ; Cursor home. [UTK016]
589 ti: db esc,'E','$',0 ; Reverse linefeed. (insert line)
590 tj: db 'W'-100O,'$',0,0 ; Clear to end of screen.
591 tk: db 'X'-100O,'$',0,0 ; Clear to end of line.
597 sysver: db 'Xerox 820$'
598 outlin: db subt,cr,lf,tab,tab,'$'
599 erascr: db subt,'$' ;Clear screen and home.
600 eralin: db cr,18H,'$' ;Clear line.
601 curldn: db esc,'=$' ;Cursor lead-in
602 delstr: db bs,' ',bs,bs,'$' ; adjust for echoing delete character
603 ttab: ;Table start location.
604 ta: db 0BH,'$',0,0 ;Cursor up.
605 tb: db 0AH,'$',0,0 ;Cursor down.
606 tc: db 0CH,'$',0,0 ;Cursor right.
607 td: db bs,'$',0,0 ;Cursor left
608 te: db subt,'$',0,0 ;Clear display
609 tf: db '$',0,0,0 ; Enter Graphics Mode (can't)
610 tg: db '$',0,0,0 ; Exit Graphics mode (can't)
611 th: db 1EH,'$',0,0 ; Cursor home. [UTK016]
612 ti: db 0BH,'$',0,0 ; Reverse linefeed. (cursor up)
613 tj: db 11H,'$',0,0 ; Clear to end of screen.
614 tk: db 18H,'$',0,0 ; Clear to end of line.
616 ovlend equ $ ; End of overlay