]> cloudbase.mooo.com Git - kermit-80.git/blob - cpxac.asm
Bugfix in outmdm (output buffer flush)
[kermit-80.git] / cpxac.asm
1 IF NOT lasm
2 .printx * CPXAC.ASM *
3 ENDIF ;NOT lasm
4 IF lasm
5 .printx Error: Z80 macro assembler (i.e. M80) required
6 END
7 ENDIF ;lasm
8 ; KERMIT - (Celtic for "FREE")
9 ;
10 ; This is the CP/M-80 implementation of the Columbia University
11 ; KERMIT file transfer protocol.
12 ;
13 ; Version 4.0
14 ;
15 ; Copyright June 1981,1982,1983,1984,1985
16 ; Columbia University
17 ;
18 ; Originally written by Bill Catchings of the Columbia University Center for
19 ; Computing Activities, 612 W. 115th St., New York, NY 10025.
20 ;
21 ; Contributions by Frank da Cruz, Daphne Tzoar, Bernie Eiben,
22 ; Bruce Tanner, Nick Bush, Greg Small, Kimmo Laaksonen, Jeff Damens, and many
23 ; others.
24 ;
25 ;
26 ;
27
28 ;
29 ; Keep module name, edit number, and last revision date in memory.
30 ;
31 family: db 'CPXCA.ASM (1) 3-DEC-2015$' ; First entry for V4.11
32
33 ;
34 ; Assembly time message to let me know I'm building the right version.
35 ;
36
37 .printx * Assembling Kermit-80 for AVR-CP/M *
38
39
40
41 SC16IS740_ADDR equ 90H ;SC16IS740 I2C address. (8bit, A0=VDD, A1=VDD)
42 OUTSIZE equ 64
43
44 VERSION_MIN equ 0304H ;Minimum AVR-CP/M firmware version required
45
46 ; Virtual I2C Interface
47
48 VI2C_STAT equ 05h
49 VI2C_CTRL equ 05h
50 VI2C_BLEN equ 06h
51 VI2C_ADR equ 07h
52 VI2C_BSIZ equ 66 ;largest message size including address byte (SLA)
53
54 ;----------------------------- ISC16IS740 UART -------------------------------
55 I2C_UART_PORT equ 50H
56
57 I2C_UART_RHR equ I2C_UART_PORT+00H ;R Receive Holding
58 I2C_UART_THR equ I2C_UART_PORT+00H ;W Transmit Holding
59 I2C_UART_IER equ I2C_UART_PORT+01H ;R/W Interrupt Enable
60 I2C_UART_FCR equ I2C_UART_PORT+02H ;W FIFO Control
61 TX_FIFO_RES equ 04H ; TX FIFO reset
62 RX_FIFO_RES equ 02H ; RX FIFO reset
63 FIFO_ENABLE equ 01H ; FIFO enable
64
65 I2C_UART_IIR equ I2C_UART_PORT+02H ;R Interrupt Identification
66 I2C_UART_LCR equ I2C_UART_PORT+03H ;R/W Line Control
67 DLAB equ 80H ; Devisor latch enable
68 WLS0 equ 01H ; Word Length Select Bit 0
69 WLS1 equ 02H ; Word Length Select Bit 1 for 8 bit word
70 STB equ 04H ; Stop bit count - 2 stop bits
71
72 I2C_UART_MCR equ I2C_UART_PORT+04H ;R/W Modem Control
73 RTS equ 02H ;RTS pin, 1 = active (low)
74 DTR equ 01H ;DTR pin (not on '740)
75 I2C_UART_LSR equ I2C_UART_PORT+05H ;R Line Status
76 TXE equ 40H ; THR and TSR empty
77 TXRDY equ 20H ; THR empty
78 RX_FE equ 08H ; Framig error
79 RX_PE equ 04H ; Parity error
80 RX_OE equ 02H ; Overrun error
81 RXRDY equ 01H ; Receved byte available
82 I2C_UART_MSR equ I2C_UART_PORT+06H ;R Modem Status
83 I2C_UART_SPR equ I2C_UART_PORT+07H ;R/W Scratchpad
84 I2C_UART_TCR equ I2C_UART_PORT+06H ;R/W Transmission Control
85 I2C_UART_TLR equ I2C_UART_PORT+07H ;R/W Trigger Level
86 I2C_UART_TXLVL equ I2C_UART_PORT+08H ;R Transmit FIFO Level
87 I2C_UART_RXLVL equ I2C_UART_PORT+09H ;R Receive FIFO Level
88 I2C_UART_EFCR equ I2C_UART_PORT+0FH ;R/W Extra Features
89 I2C_UART_DLL equ I2C_UART_PORT+00H ;R/W divisor latch LSB
90 I2C_UART_DLH equ I2C_UART_PORT+01H ;R/W divisor latch MSB
91 I2C_UART_EFR equ I2C_UART_PORT+02H ;R/W Enhanced Feature
92 I2C_UART_XON1 equ I2C_UART_PORT+04H ;R/W Xon1 word
93 I2C_UART_XON2 equ I2C_UART_PORT+05H ;R/W Xon2 word
94 I2C_UART_XOFF1 equ I2C_UART_PORT+06H ;R/W Xoff1 word
95 I2C_UART_XOFF2 equ I2C_UART_PORT+07H ;R/W Xoff2 word
96
97
98 z80 set TRUE ;This one emulates an Z80.
99
100 .z80
101 ;----------------------------------------------------------------------
102 ; Macros
103 ;----------------------------------------------------------------------
104
105 ; make a message table
106 ; usage:
107 ; label: mkmsgtab <msg0,msg1,msg2,...>
108
109 mkm_tab macro x
110 n?msg defl 0
111 irp y,<x>
112 n?msg defl n?msg+1
113 endm
114 db n?msg
115 irp y,<x>
116 db '&y','$'
117 endm
118 endm
119
120 ; make a message table
121 ; usage:
122 ; label: mkmsgtab <msg0,msg1,msg2,...>
123
124 mkms_tab macro x
125 n?msg defl 0
126 irp y,<x>
127 n?msg defl n?msg+1
128 endm
129 db n?msg
130 irp y,<x>
131 ifnb <y>
132 db y,'$'
133 else
134 db '$'
135 endif
136 endm
137 endm
138
139 ;----------------------------------------------------------------------
140 ; Messages
141 ;----------------------------------------------------------------------
142
143 umsg_tab:
144 ; 0 1 2 3 4 5
145 mkms_tab <'UART',,' not', ' detected',', crystal frequency: ','!'>
146
147 fmsg_tab:
148 mkm_tab <?,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>
149 fdim_msg:
150 db ' MHz.',cr,lf,'$'
151 fw_msg:
152 db 'AVR firmware to old, at least version 3.4 neded.','$'
153 exit_msg:
154 db cr,lf,'Exiting!',cr,lf,'$'
155
156 ;----------------------------------------------------------------------
157 ; Utilities
158 ;----------------------------------------------------------------------
159
160 ; Print message from table
161 ;
162 ; hl: message table address
163 ; first byte is number of table entries
164 ; a: number of message to print (0 based, index in table)
165 ;
166 ; If index is out of range, print message #0
167
168 pdecoded:
169 push bc
170 push de
171 push hl
172 ld bc,0
173 cp (hl) ; number of messages in table
174 jr c,pdc_1
175 ld a,c
176 pdc_1:
177 inc hl
178 ld e,a
179 ld a,'$'
180 inc e
181 jr pdc_2
182 pdc_nxt_str:
183 cpir
184 pdc_2:
185 dec e
186 jr nz,pdc_nxt_str
187 ex de,hl
188 call prtstr
189 pop hl
190 pop de
191 pop bc
192 ret
193
194 ;----------------------------------------------------------------------
195 ; output bytes to ports
196 ;
197 ; hl: tables of port,value pairs:
198 ; db n ;number of pairs
199 ; db port1,val1, port2,val2,... portn,valn
200 ; ...
201 ; db 0 ; Terminate table
202
203 ioinil:
204 push bc
205 ld b,(hl) ;count
206 inc hl
207 io1_lp:
208 ld c,(hl) ;port address
209 inc hl
210 outi
211 jr nz,io1_lp
212 pop bc
213 ret
214
215 ;----------------------------------------------------------------------
216
217 vi2c_setup_chk:
218 ld hl,chkbuf
219 vi2c_setup:
220 out (VI2C_BLEN),a
221 ld a,h
222 out (VI2C_ADR+1),a
223 ld a,l
224 out (VI2C_ADR+0),a
225 ret
226
227 ;----------------------------------------------------------------------
228
229 prspeedmsg:
230 ld hl,fmsg_tab
231 call pdecoded
232 ld de,fdim_msg
233 call prtstr
234 ret
235
236 ;----------------------------------------------------------------------
237 ;
238 ;----------------------------------------------------------------------
239
240 fw_check:
241 ld bc,000CH ;
242 out (c),b ;write 0 to version port
243 in a,(c)
244 cp 1 ;result should be 0
245 ret nc ;exit (a != 0) if it wasn't
246 inc b
247 out (c),b
248 in h,(c) ;get MAJOR
249 inc b
250 out (c),b
251 in l,(c) ;get MINOR
252 ld de,VERSION_MIN
253 xor a ;clear carry
254 sbc hl,de
255 sbc a,a ;z if hl >= VERSION_MIN
256 ret
257
258 ;----------------------------------------------------------------------
259
260 uart_check:
261 ld a,3 ;2 byte + SLA
262 call vi2c_setup_chk
263 ld a,2 ;write cmd
264 out (VI2C_CTRL),a
265 uc_0:
266 in a,(VI2C_CTRL) ;do: get i2c result
267 bit 7,a ;
268 jr nz,uc_0 ;while busy
269 cp 0FH
270 jr nz,uc_err ;error in transaction
271 in a,(VI2C_BLEN)
272 cp 3
273 jr nz,uc_err
274
275 inc hl
276 inc hl
277 in a,(I2C_UART_SPR)
278 cp (hl)
279 jr nz,uc_err
280 ld (hl),42H
281 ld a,2
282 out (VI2C_CTRL),a
283 in a,(I2C_UART_SPR)
284 cp (hl)
285 jr nz,uc_err
286 xor a
287 jr uc_1
288 uc_err:
289 ld a,1
290 uc_1:
291 ld c,a
292 ld hl,umsg_tab
293 xor a
294 call pdecoded
295 ld a,1
296 add a,c
297 call pdecoded
298 ld a,3
299 call pdecoded
300 ld a,4
301 add a,c
302 call pdecoded
303 ld a,c
304 or a
305 ret
306
307 ;----------------------------------------------------------------------
308
309 chkbuf:
310 db SC16IS740_ADDR
311 db (I2C_UART_SPR - I2C_UART_PORT) shl 3 ;address of scratch pad register
312 db 5AH
313
314 ;----------------------------------------------------------------------
315
316 speedtest:
317 ld hl,spt_tab ;init UART in loop back mode
318 call ioinil ; and fill tx fifo with 60 chars
319
320 in a,(I2C_UART_MSR) ;Clear Modem Status Register
321 in a,(I2C_UART_LSR) ;Clear Line Status Register
322 in a,(I2C_UART_RHR) ;Clear Receiver Buffers
323 in a,(I2C_UART_RHR)
324
325 ld a,2 ;start write transaction
326 out (VI2C_CTRL),a
327
328 ; get time stamp
329 in a,(41H) ;lsb ms
330 ld e,a
331 in a,(42H) ;msb ms
332 ld d,a
333 in a,(43H) ;lsb seconds
334 ld c,a
335
336 spt_1:
337 in a,(I2C_UART_RXLVL) ;wait till all 60 char in rx fifo
338 cp 60
339 jr nz,spt_1
340
341 ; get 2nd time stamp
342 in a,(41H) ;lsb ms
343 ld l,a
344 in a,(42H) ;msb ms
345 ld h,a
346 in a,(43H) ;lsb seconds
347 sub c ;seconds diff
348 jr z,spt_3
349 ld bc,1000
350 spt_2: ;convert s to ms
351 add hl,bc
352 dec a
353 jr nz,spt_2
354 spt_3:
355 sbc hl,de ;hl = elapsed time (ms) for 60 chars
356 ld d,h
357 ld e,l
358 inc hl
359 srl h
360 rr l
361 ld bc,500
362 add hl,bc
363
364 xor a ;clear carry
365 spt_4:
366 inc a
367 sbc hl,de
368 jr nc,spt_4
369 dec a
370 ret
371
372 spt_tab:
373 db (spt_tab_end - ($+1))/2
374 db I2C_UART_LCR, DLAB+03H ;Set devisor latch access bit
375 db I2C_UART_DLL, low 96 ;1200 bit/s at 1.832 MHz
376 db I2C_UART_DLH, high 96 ;Out to the MSB divisor port
377 db I2C_UART_LCR, 03H ;Disable Divisor Access Latch
378 db I2C_UART_FCR, 07H ;Clear and enable fifos
379 db I2C_UART_MCR, 10H ;Enable loopback
380 db I2C_UART_IER, 0 ;Set no interrupts
381 db VI2C_ADR+0, low outbuf
382 db VI2C_ADR+1, high outbuf
383 db VI2C_BLEN, 60+2
384 spt_tab_end:
385
386 ;----------------------------------------------------------------------
387 ;
388 ;----------------------------------------------------------------------
389
390 sysxin: ; continuation of system initialisation from sysinit
391
392 call fw_check
393 jr nz,si_exit_f
394 call uart_check
395 jr nz,si_exit
396 call speedtest
397 ld (clk_div),a
398 call prspeedmsg
399
400 ld hl,6 ;set default baud rate
401 ld (speed),hl
402 ex de,hl
403 call sysspd
404
405 ld a,RTS+DTR
406 out (I2C_UART_MCR),a
407 ret
408
409 si_exit_f:
410 ld de,fw_msg
411 call prtstr
412 si_exit:
413 ld de,exit_msg
414 call prtstr
415 jp 0
416
417
418 ; ld a,07H ;Enable and clear fifos
419 ; out (I2C_UART_FCR),a ;
420 ; ld a,03H ;8N1
421 ; out (I2C_UART_LCR),a ;
422
423
424 ;
425 ; system-dependent KERMIT termination processing
426 ; If we've changed anything, this is our last chance to put it back.
427 ;
428 sysexit:
429 ret
430
431 ;
432 ; system-dependent processing for start of CONNECT command
433 ;
434 syscon:
435 ret
436
437 conmsg: ; Messages printed when entering transparent (CONNECT) mode:
438
439 db '$'
440
441 ;
442 ; syscls - system-dependent close routine
443 ; called when exiting transparent session.
444 ;
445 syscls:
446 ret
447
448 .8080
449
450 ;
451 ; sysinh - help for system-dependent special functions.
452 ; called in response to <escape>?, after listing all the
453 ; system-independent escape sequences.
454 ;
455 sysinh:
456 lxi d, inhlps
457 call prtstr
458 ret
459
460 ; Additional, system-dependent help for transparent mode
461 ; (two-character escape sequences)
462 inhlps:
463 db cr,lf,'B Transmit a BREAK (0.3s)'
464 db cr,lf,'L Transmit a LONG BREAK (1.8s)'
465 db '$' ; string terminator
466
467 .z80
468 ;
469 ; sysint - system dependent special functions
470 ; called when transparent escape character has been typed;
471 ; the second character of the sequence is in A (and in B).
472 ; returns:
473 ; non-skip: sequence has been processed
474 ; skip: seqence was not recognized
475 ;
476 sysint:
477 and 5FH ; convert lower case to upper, for testing...
478 cp 'B' ; send break ?
479 jr z,sendbr ; then jump to send break routine
480 cp 'L' ; long break ?
481 jr z,longbr ; then jump to long break routine
482 jp rskp ; take skip return - command not recognised
483
484 ;
485 ; Break routines
486 ;
487 longbr:
488 ld e,180 ; time for long break is 1800 ms
489 jr setbit
490
491 sendbr:
492 ld e,25 ; time for break is 300 ms
493
494 setbit:
495 in a,(I2C_UART_LCR)
496 set 6,a ; Break contol bit
497 out (I2C_UART_LCR),a
498 ;
499 ; Now, delay for duration of hangup or break
500 ld a,e ; delay count
501 call delay
502 ;
503 ; Time's up. Put transmitter back in normal state and return.
504
505 in a,(I2C_UART_LCR)
506 res 6,a ; Break contol bit
507 out (I2C_UART_LCR),a
508 ret ; done.
509
510 .8080
511 ;
512 ; sysflt - system-dependent filter
513 ; called with character in E.
514 ; if this character should not be printed, return with A = zero.
515 ; preserves bc, de, hl.
516 ; note: <xon>,<xoff>,<del>, and <nul> are always discarded.
517 ;
518 sysflt:
519 mov a,e ; get character for testing
520 ret
521
522 ;
523 ; mdmflt - modem filter
524 ; called with character to be sent to printer in E
525 ; with parity set as appropriate.
526 ; return with accumulator = 0 do do nothing,
527 ; <> 0 to send char in E.
528 mdmflt:
529 mov a,e ; get character to test
530 ret
531
532 ;
533 ; prtflt - printer filter
534 ; called with character to be sent to printer in E
535 ; returns with a = 0 to do nothing
536 ; a <> 0 to print it.
537 ;
538 ; this routine for those printer that automatically insert
539 ; a lf on cr, or cr for lf. Should this be shifted to
540 ; the system indep. stuff, in say 4.06?
541 ;
542 prtflt:
543 mov a,e ; get character to test
544
545 IF FALSE ; strip out lf from printer stream
546 ani 7fh ; make sure it is parity less
547 cpi lf ; is it a line feed?
548 rnz ; no, print it
549 ; xra a ; yes, don't.
550
551 ENDIF
552
553 ret
554
555 ;
556 ; system-dependent processing for BYE command.
557 ;
558 sysbye:
559 ret
560
561 ;
562 ; This is the system-dependent command to change the baud rate.
563 ; DE contains the two-byte value from the baud rate table; both
564 ; bytes of this value are also stored in 'speed'.
565 ;
566 .z80
567 sysspd:
568 ld hl,0
569 ld a,(clk_div)
570 ld b,a
571 sysspd_1:
572 add hl,de
573 djnz sysspd_1
574 ld a,l
575 ld (sysspd_dll),a
576 ld a,h
577 ld (sysspd_dlh),a
578
579 ld hl,sysspd_tab
580 call ioinil
581
582 in a,(I2C_UART_MSR) ;Clear Modem Status Register
583 in a,(I2C_UART_LSR) ;Clear Line Status Register
584 in a,(I2C_UART_RHR) ;Clear Receiver Buffers
585 in a,(I2C_UART_RHR)
586 ret
587
588 sysspd_tab:
589 db (sysspd_tab_end - ($+1))/2
590 db I2C_UART_LCR, DLAB+03H ;Set devisor latch access bit
591 db I2C_UART_DLL
592 sysspd_dll:
593 ds 1 ;1200 bit/s at 1.832 MHz
594 db I2C_UART_DLH
595 sysspd_dlh:
596 ds 1 ;Out to the MSB divisor port
597 db I2C_UART_LCR, 03H ;Disable Divisor Access Latch
598 db I2C_UART_FCR, 07H ;Clear and enable fifos
599 db I2C_UART_MCR, 00H ;Enable loopback
600 db I2C_UART_IER, 0 ;Set no interrupts
601 sysspd_tab_end:
602
603
604
605 ;
606 ; Speed tables
607 ; (Note that speed tables MUST be in alphabetical order for later
608 ; lookup procedures, and must begin with a value showing the total
609 ; number of entries. The speed help tables are just for us poor
610 ; humans.
611 ;
612 ; db string length, string, divisor (2 bytes or 1 word, ab)
613 ; the data byte a is return in A and E, and b in D
614 ; only byte 'a' is the key for the table
615
616 spdtbl: db 15 ; Number of entries
617 db 3,'110$'
618 dw 1047
619 db 6,'115200$'
620 dw 1
621 db 4,'1200$'
622 dw 96
623 db 3,'150$'
624 dw 768
625 db 5,'19200$'
626 dw 6
627 db 4,'2400$'
628 dw 48
629 db 5,'28800$'
630 dw 5
631 db 3,'300$'
632 dw 384
633 db 5,'38400$'
634 dw 3
635 db 3,'450$'
636 dw 256
637 db 4,'4800$'
638 dw 24
639 db 5,'57600$'
640 dw 2
641 db 3,'600$'
642 dw 192
643 db 2,'75$'
644 dw 1536
645 db 4,'9600$'
646 dw 12
647 IF 0
648 sphtbl: db cr,lf,' 75 110 150 300 450 600 1200 2400'
649 db cr,lf,'4800 9600 19200 28800 38400 57600 115200$'
650 ENDIF
651
652 sphtbl: db cr,lf,' 110 300 600 2400 9600 28800 57600'
653 db cr,lf,' 75 150 450 1200 4800 19200 38400 115200$'
654
655
656 ;
657 ; This is the system-dependent SET PORT command.
658 ; HL contains the argument from the command table.
659 ;
660 sysprt:
661 ret
662
663 prttbl EQU 0 ; SET PORT is not supported
664 prhtbl EQU 0
665
666 ;
667 ; selmdm - select modem port
668 ; selcon - select console port
669 ; selmdm is called before using inpmdm or outmdm;
670 ; selcon is called before using inpcon or outcon.
671 ; For iobyt systems, diddle the I/O byte to select console or comm port;
672 ; For the rest, does nothing.
673 ; preserves bc, de, hl.
674 ;
675 selmdm:
676 ret
677
678 selcon:
679 jr omflush
680
681 ;
682 ; Get character from console, or return zero.
683 ; result is returned in A. destroys bc, de, hl.
684 ;
685 inpcon:
686 ld c,dconio ;Direct console I/O BDOS call.
687 ld e,0FFH ;Input.
688 call BDOS
689
690 ret
691
692 ;
693 ; Output character in E to the console.
694 ; destroys bc, de, hl
695 ;
696 outcon:
697 ld c,dconio ;Console output bdos call.
698 call bdos ;Output the char to the console.
699
700 ret
701
702 ;
703 ; outmdm - output a char from E to the modem.
704 ; the parity bit has been set as necessary.
705 ; returns nonskip; bc, de, hl preserved.
706 ;
707 outmdm:
708 push hl
709 ld hl,(outptr)
710 ld (hl),e ;save char in buffer
711 inc hl
712 ld (outptr),hl
713 ld a,(outcnt)
714 inc a
715 ld (outcnt),a
716 cp OUTSIZE
717 jr nc,omflush_1 ;buffer full
718 pop hl
719 ret
720
721 omflush:
722 ld a,(outcnt)
723 or a
724 ret z
725
726 scf
727 push hl
728 omflush_1:
729 push bc
730 ld c,a ;outcnt
731 ld b,a
732 jr c,$+4
733 ld b,1
734 ld hl,outbuf
735 ld a,h
736 out (VI2C_ADR+1),a
737 ld a,l
738 out (VI2C_ADR+0),a
739 omf_0:
740 in a,(I2C_UART_TXLVL)
741 cp b
742 jr c,omf_0
743 cp c
744 jr nc,omf_2
745 ld c,a
746 omf_2:
747 ld a,c
748 add a,2
749 out (VI2C_BLEN),a
750 ld a,2 ;start write transaction
751 out (VI2C_CTRL),a
752
753 ld hl,outbuf+2 ;buffer start
754 ld a,(outcnt)
755 sub c ;buffer now empty?
756 ld (outcnt),a
757 jr z,omfex
758
759 push de ;no, shift remaining chars down
760 ld d,h ;dest = buffer start
761 ld e,l
762 ld b,0
763 add hl,bc ;src = buffer start + num chars last transmitted
764 ld c,a
765 ldir
766 ex de,hl
767 pop de
768 omfex:
769 ld (outptr),hl
770 pop bc
771 pop hl
772 ret
773
774 ;
775 ; get character from modem; return zero if none available.
776 ; for IOBYT systems, the modem port has already been selected.
777 ; destroys bc, de, hl.
778 ;
779 inpmdm:
780 ld a,(inpcnt) ;any buffered chars?
781 dec a
782 jp m,imdrdi2c ;no, buffer empty
783 ld (inpcnt),a ;save updated buffer counter
784 ld hl,(inpptr)
785 ld a,(hl) ;return buffered char
786 inc hl
787 ld (inpptr),hl ;save buffer pointer
788 ret
789
790 imdrdi2c:
791 in a,(I2C_UART_RXLVL) ;get rx fifo count
792 or a
793 ret z ;fifo is empty, return 0
794
795 ; prepare fifo read
796 inc a ;+ slave address
797 ld hl,inbuf
798 call vi2c_setup
799 inc hl
800 ld (hl),0 ;select subaddr 0 (RHR) for next read
801 ld a,3 ;write 1 byte (subaddr.), then read fifo
802 out (VI2C_CTRL),a
803 in a,(VI2C_CTRL) ;get i2c result
804 xor 01h
805 and 11h ;transfer completed?
806 jr nz,imrdex
807 in a,(VI2C_BLEN) ;get actual transfer count
808
809 sub 2 ;- (slave address + char to return now)
810 jr c,imrdex
811 ld (inpcnt),a ;save new buffer count
812 ld a,(hl)
813 inc hl
814 ld (inpptr),hl ;save buffer pointer
815 ret
816
817 imrdex:
818 xor a
819 ret
820
821 .8080
822 ;
823 ; flsmdm - flush comm line.
824 ; Modem is selected.
825 ; Currently, just gets characters until none are available.
826 ;
827 flsmdm:
828 call inpmdm ; Try to get a character
829 ora a ; Got one?
830 jnz flsmdm ; If so, try for another
831 ret ; Receiver is drained. Return.
832
833
834 ;
835 ; lptstat - get the printer status. Return a=0 if ok, or 0ffh if not.
836 lptstat:
837 IF iobyte ;[33]
838 call bprtst ; get status
839 ENDIF ;iobyte[33]
840 IF NOT iobyte ;[33]
841 xra a ; assume it is ok.. this may not be necessary
842 ENDIF ;iobyte [33]
843 ret
844 ;
845 ; outlpt - output character in E to printer
846 ; console is selected.
847 ; preserves de.
848 ;
849 outlpt:
850 push d ; save DE in either case
851 call prtflt ; go through printer filter [30]
852 ana a ; if A = 0 do nothing,
853 jz outlp1 ; if a=0 do nothing
854
855 outlp1: pop d ; restore saved register pair
856 ret
857
858 ; delchr - make delete look like a backspace. Unless delete is a printing
859 ; character, we just need to print a backspace. (we'll output clrspc
860 ; afterwards)
861 delchr:
862
863 mvi e,bs ;get a backspace
864 jmp outcon
865
866 ; erase the character at the current cursor position
867 clrspc: mvi e,' '
868 call outcon
869 mvi e,bs ;get a backspace
870 jmp outcon
871
872 ; erase the current line
873 clrlin: lxi d,eralin
874 jmp prtstr
875
876 ; erase the whole screen, and go home. preserves b (but not c)
877 clrtop: lxi d,erascr
878 jmp prtstr
879
880 ;----------------------------------------------------------------------
881
882 sysver: db 'AVR-CP/M'
883 db '$'
884
885 ;----------------------------------------------------------------------
886
887 clk_div:
888 db 1 ;default div
889
890 inpptr: dw 0
891 inpcnt: db 0
892 inbuf:
893 db SC16IS740_ADDR
894 ds VI2C_BSIZ-1
895
896
897 outptr: dw outbuf+2
898 outcnt: db 0
899 outbuf:
900 db SC16IS740_ADDR
901 db 0 ;RHR subaddress
902 ds OUTSIZE
903
904 ;----------------------------------------------------------------------
905
906 IF lasm
907 LINK CPXVDU.ASM ; get terminal defs etc
908 ENDIF ;lasm