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 ; Keep module name, edit number, and last revision date in memory.
27 family: db 'CPXCP.ASM (1) 3-DEC-2015$' ; First entry for V4.11
30 ; Assembly time message to let me know I'm building the right version.
33 .printx * Assembling Kermit-80 for AVR-CP/M *
37 SC16IS740_ADDR equ 90H ;SC16IS740 I2C address. (8bit, A0=VDD, A1=VDD)
40 ; Virtual I2C Interface
46 VI2C_BSIZ equ 66 ;largest message size including address byte (SLA)
48 ;----------------------------- ISC16IS740 UART -------------------------------
51 I2C_UART_RHR equ I2C_UART_PORT+00H ;R Receive Holding
52 I2C_UART_THR equ I2C_UART_PORT+00H ;W Transmit Holding
53 I2C_UART_IER equ I2C_UART_PORT+01H ;R/W Interrupt Enable
54 I2C_UART_FCR equ I2C_UART_PORT+02H ;W FIFO Control
55 TX_FIFO_RES equ 04H ; TX FIFO reset
56 RX_FIFO_RES equ 02H ; RX FIFO reset
57 FIFO_ENABLE equ 01H ; FIFO enable
59 I2C_UART_IIR equ I2C_UART_PORT+02H ;R Interrupt Identification
60 I2C_UART_LCR equ I2C_UART_PORT+03H ;R/W Line Control
61 DLAB equ 80H ; Devisor latch enable
62 WLS0 equ 01H ; Word Length Select Bit 0
63 WLS1 equ 02H ; Word Length Select Bit 1 for 8 bit word
64 STB equ 04H ; Stop bit count - 2 stop bits
66 I2C_UART_MCR equ I2C_UART_PORT+04H ;R/W Modem Control
67 RTS equ 02H ;RTS pin, 1 = active (low)
68 DTR equ 01H ;DTR pin (not on '740)
69 I2C_UART_LSR equ I2C_UART_PORT+05H ;R Line Status
70 TXE equ 40H ; THR and TSR empty
71 TXRDY equ 20H ; THR empty
72 RX_FE equ 08H ; Framig error
73 RX_PE equ 04H ; Parity error
74 RX_OE equ 02H ; Overrun error
75 RXRDY equ 01H ; Receved byte available
76 I2C_UART_MSR equ I2C_UART_PORT+06H ;R Modem Status
77 I2C_UART_SPR equ I2C_UART_PORT+07H ;R/W Scratchpad
78 I2C_UART_TCR equ I2C_UART_PORT+06H ;R/W Transmission Control
79 I2C_UART_TLR equ I2C_UART_PORT+07H ;R/W Trigger Level
80 I2C_UART_TXLVL equ I2C_UART_PORT+08H ;R Transmit FIFO Level
81 I2C_UART_RXLVL equ I2C_UART_PORT+09H ;R Receive FIFO Level
82 I2C_UART_EFCR equ I2C_UART_PORT+0FH ;R/W Extra Features
83 I2C_UART_DLL equ I2C_UART_PORT+00H ;R/W divisor latch LSB
84 I2C_UART_DLH equ I2C_UART_PORT+01H ;R/W divisor latch MSB
85 I2C_UART_EFR equ I2C_UART_PORT+02H ;R/W Enhanced Feature
86 I2C_UART_XON1 equ I2C_UART_PORT+04H ;R/W Xon1 word
87 I2C_UART_XON2 equ I2C_UART_PORT+05H ;R/W Xon2 word
88 I2C_UART_XOFF1 equ I2C_UART_PORT+06H ;R/W Xoff1 word
89 I2C_UART_XOFF2 equ I2C_UART_PORT+07H ;R/W Xoff2 word
93 z80 set TRUE ;This one emulates an Z80.
98 sysxin: ; continuation of system initialisation from sysinit
103 ld hl,6 ;set default baud rate
112 ; ld a,07H ;Enable and clear fifos
113 ; out (I2C_UART_FCR),a ;
115 ; out (I2C_UART_LCR),a ;
151 db 'UART crystal frequency: ','$'
152 mkftab <?,1.8432,3.6864,5.5296,7.3728,9.216,11.0592,12.9024,14.7456,16.5888,18.432,20.2752,22.1184,23.9616>
158 ; system-dependent KERMIT termination processing
159 ; If we've changed anything, this is our last chance to put it back.
165 ; system-dependent processing for start of CONNECT command
170 conmsg: ; Messages printed when entering transparent (CONNECT) mode:
175 ; syscls - system-dependent close routine
176 ; called when exiting transparent session.
184 ; sysinh - help for system-dependent special functions.
185 ; called in response to <escape>?, after listing all the
186 ; system-independent escape sequences.
193 ; Additional, system-dependent help for transparent mode
194 ; (two-character escape sequences)
196 db cr,lf,'B Transmit a BREAK (0.3s)'
197 db cr,lf,'L Transmit a LONG BREAK (1.8s)'
198 db '$' ; string terminator
202 ; sysint - system dependent special functions
203 ; called when transparent escape character has been typed;
204 ; the second character of the sequence is in A (and in B).
206 ; non-skip: sequence has been processed
207 ; skip: seqence was not recognized
210 and 5FH ; convert lower case to upper, for testing...
211 cp 'B' ; send break ?
212 jr z,sendbr ; then jump to send break routine
213 cp 'L' ; long break ?
214 jr z,longbr ; then jump to long break routine
215 jp rskp ; take skip return - command not recognised
221 ld e,180 ; time for long break is 1800 ms
225 ld e,25 ; time for break is 300 ms
229 set 6,a ; Break contol bit
232 ; Now, delay for duration of hangup or break
236 ; Time's up. Put transmitter back in normal state and return.
239 res 6,a ; Break contol bit
245 ; sysflt - system-dependent filter
246 ; called with character in E.
247 ; if this character should not be printed, return with A = zero.
248 ; preserves bc, de, hl.
249 ; note: <xon>,<xoff>,<del>, and <nul> are always discarded.
252 mov a,e ; get character for testing
256 ; mdmflt - modem filter
257 ; called with character to be sent to printer in E
258 ; with parity set as appropriate.
259 ; return with accumulator = 0 do do nothing,
260 ; <> 0 to send char in E.
262 mov a,e ; get character to test
266 ; prtflt - printer filter
267 ; called with character to be sent to printer in E
268 ; returns with a = 0 to do nothing
269 ; a <> 0 to print it.
271 ; this routine for those printer that automatically insert
272 ; a lf on cr, or cr for lf. Should this be shifted to
273 ; the system indep. stuff, in say 4.06?
276 mov a,e ; get character to test
278 IF FALSE ; strip out lf from printer stream
279 ani 7fh ; make sure it is parity less
280 cpi lf ; is it a line feed?
282 ; xra a ; yes, don't.
289 ; system-dependent processing for BYE command.
295 ; This is the system-dependent command to change the baud rate.
296 ; DE contains the two-byte value from the baud rate table; both
297 ; bytes of this value are also stored in 'speed'.
315 in a,(I2C_UART_MSR) ;Clear Modem Status Register
316 in a,(I2C_UART_LSR) ;Clear Line Status Register
317 in a,(I2C_UART_RHR) ;Clear Receiver Buffers
322 db (sysspd_tab_end - ($+1))/2
323 db I2C_UART_LCR, DLAB+03H ;Set devisor latch access bit
326 ds 1 ;1200 bit/s at 1.832 MHz
329 ds 1 ;Out to the MSB divisor port
330 db I2C_UART_LCR, 03H ;Disable Divisor Access Latch
331 db I2C_UART_FCR, 07H ;Clear and enable fifos
332 db I2C_UART_MCR, 00H ;Enable loopback
333 db I2C_UART_IER, 0 ;Set no interrupts
340 ; (Note that speed tables MUST be in alphabetical order for later
341 ; lookup procedures, and must begin with a value showing the total
342 ; number of entries. The speed help tables are just for us poor
345 ; db string length, string, divisor (2 bytes or 1 word, ab)
346 ; the data byte a is return in A and E, and b in D
347 ; only byte 'a' is the key for the table
349 spdtbl: db 15 ; Number of entries
381 sphtbl: db cr,lf,' 75 110 150 300 450 600 1200 2400'
382 db cr,lf,'4800 9600 19200 28800 38400 57600 115200$'
385 sphtbl: db cr,lf,' 110 300 600 2400 9600 28800 57600'
386 db cr,lf,' 75 150 450 1200 4800 19200 38400 115200$'
393 in a,(I2C_UART_MSR) ;Clear Modem Status Register
394 in a,(I2C_UART_LSR) ;Clear Line Status Register
395 in a,(I2C_UART_RHR) ;Clear Receiver Buffers
398 ld a,2 ;start write transaction
406 in a,(43H) ;lsb seconds
410 in a,(I2C_UART_RXLVL)
419 in a,(43H) ;lsb seconds
447 db (spt_tab_end - ($+1))/2
448 db I2C_UART_LCR, DLAB+03H ;Set devisor latch access bit
449 db I2C_UART_DLL, low 96 ;1200 bit/s at 1.832 MHz
450 db I2C_UART_DLH, high 96 ;Out to the MSB divisor port
451 db I2C_UART_LCR, 03H ;Disable Divisor Access Latch
452 db I2C_UART_FCR, 07H ;Clear and enable fifos
453 db I2C_UART_MCR, 10H ;Enable loopback
454 db I2C_UART_IER, 0 ;Set no interrupts
455 db VI2C_ADR+0, low outbuf
456 db VI2C_ADR+1, high outbuf
460 ;----------------------------------------------------------------------
461 ; output bytes to ports
463 ; hl: tables of port,value pairs:
464 ; db n ;number of pairs
465 ; db port1,val1, port2,val2,... portn,valn
467 ; db 0 ; Terminate table
474 ld c,(hl) ;port address
482 ; This is the system-dependent SET PORT command.
483 ; HL contains the argument from the command table.
488 prttbl EQU 0 ; SET PORT is not supported
492 ; selmdm - select modem port
493 ; selcon - select console port
494 ; selmdm is called before using inpmdm or outmdm;
495 ; selcon is called before using inpcon or outcon.
496 ; For iobyt systems, diddle the I/O byte to select console or comm port;
497 ; For the rest, does nothing.
498 ; preserves bc, de, hl.
511 ; Get character from console, or return zero.
512 ; result is returned in A. destroys bc, de, hl.
515 ld c,dconio ;Direct console I/O BDOS call.
522 ; Output character in E to the console.
523 ; destroys bc, de, hl
526 ld c,dconio ;Console output bdos call.
527 call bdos ;Output the char to the console.
532 ; outmdm - output a char from E to the modem.
533 ; the parity bit has been set as necessary.
534 ; returns nonskip; bc, de, hl preserved.
538 in a,(I2C_UART_LSR) ;Get the output done flag.
539 and TXRDY ;Is it set?
540 jr z,outmdm ;If not, loop until it is.
542 out (I2C_UART_THR),a ;Output it.
548 ld (hl),e ;return buffered char
555 jr nc,omflush_1 ;buffer full
578 in a,(I2C_UART_TXLVL)
588 ld a,2 ;start write transaction
612 ; get character from modem; return zero if none available.
613 ; for IOBYT systems, the modem port has already been selected.
614 ; destroys bc, de, hl.
618 in a,(I2C_UART_LSR) ;Get the port status into A.
619 and RXRDY ;See if the input ready bit is on.
620 ret z ;If not then return.
622 in a,(I2C_UART_MCR) ;debug
626 in a,(I2C_UART_RHR);If so, get the char.
633 jp m,imdrdi2c ;buffer empty
636 ld a,(hl) ;return buffered char
642 in a,(I2C_UART_RXLVL) ;get rx fifo count
644 ret z ;fifo is empty, return 0
647 inc a ;+ slave address
655 ld (hl),0 ;select subaddr 0 (RHR) for next read
656 ld a,3 ;write 1 byte (subaddr.), then read fifo
658 in a,(VI2C_CTRL) ;get i2c result
660 and 11h ;transfer completed?
662 in a,(VI2C_BLEN) ;get actual transfer count
664 sub 2 ;- (slave address + char to return now)
666 ld (inpcnt),a ;save new buffer count
680 ; flsmdm - flush comm line.
682 ; Currently, just gets characters until none are available.
685 call inpmdm ; Try to get a character
687 jnz flsmdm ; If so, try for another
688 ret ; Receiver is drained. Return.
692 ; lptstat - get the printer status. Return a=0 if ok, or 0ffh if not.
695 call bprtst ; get status
698 xra a ; assume it is ok.. this may not be necessary
702 ; outlpt - output character in E to printer
703 ; console is selected.
707 push d ; save DE in either case
708 call prtflt ; go through printer filter [30]
709 ana a ; if A = 0 do nothing,
710 jz outlp1 ; if a=0 do nothing
712 outlp1: pop d ; restore saved register pair
715 ; delchr - make delete look like a backspace. Unless delete is a printing
716 ; character, we just need to print a backspace. (we'll output clrspc
720 mvi e,bs ;get a backspace
723 ; erase the character at the current cursor position
726 mvi e,bs ;get a backspace
729 ; erase the current line
733 ; erase the whole screen, and go home. preserves b (but not c)
738 sysver: db 'AVR-CP/M'
761 LINK CPXVDU.ASM ; get terminal defs etc