2 ; Interrupt drivers for ASCI0 and ASCI1
7 extrn ff_empty,ff_get,ff_full,ff_put
8 extrn ff_puth,ff_cnt,ff_gech
10 extrn isv_sw,ijphl,add_hla,div32_r
21 m2b mbxon_bit,mb$xon$xoff
23 ;-----------------------------------------------------
33 db 0 ;absolute device #
36 db M_CREAD+M_CRTS_IFLOW+M_CCTS_OFLOW ;fflags
50 oint.iflags equ as0_dev+o.iflags-s0.inbuf
51 oint.fflags equ as0_dev+o.fflags-s0.inbuf
52 oint.stat equ as0_dev+o.stat-s0.inbuf
53 mkbuf s0.rx_id, s0.inbuf, s0.rx_len
54 mkbuf s0.tx_id, s0.outbuf,s0.tx_len
63 db 0 ;absolute device #
66 db M_CREAD+M_IXOFF ;fflags
71 mkbuf s1.rx_id, s1.inbuf, s1.rx_len
72 mkbuf s1.tx_id, s1.outbuf,s1.tx_len
80 dw func_tcinit ;(00h) CP/M 3 DEVINI function
81 dw func_tcgeta ;(01h) Get the current serial port settings.
82 dw func_tcseta ;(02h) Set the current serial port settings.
83 dw func_tcsetaw ;(03h) Allow the output buffer to drain
84 dw func_tcsetaf ;(04h) Allow the output buffer to drain, discard pending input
85 dw func_tcsbrk ;(05h) Sending a break (250ms .. 500ms)
86 dw func_tcsbrkp ;(06h) arg is timeinterval in 0.1sec
87 dw func_tiocsbrk ;(07h) Turn break on
88 dw func_tioccbrk ;(08h) Turn break off
89 dw func_tcxonc ;(09h) Software flow control (TCOOFF, TCOON, TCIOFF, TCION)
90 dw func_tcflsh ;(0Ah) Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH)
91 dw func_fionread ;(0Bh) Get the number of bytes in the input buffer.
92 dw func_tiocoutq ;(0Ch) Get the number of bytes in the output buffer.
93 dw func_tiocmget ;(0Dh) get the status of modem bits.
94 dw func_tiocmbis ;(0Eh) set the indicated modem bits.
95 dw func_tiocmbic ;(0Fh) clear the indicated modem bits.
96 dw func_tiocmset ;(10h) set the status of modem bits.
97 dw func_tiocgsoftcar ;(11h) Get the status of the CLOCAL flag in the c_cflag field
98 dw func_tiocssoftcar ;(12h) Set the CLOCAL flag when *argp is nonzero, and clear it otherwise.
100 IOCTL_MAX equ ($-ioctl_ftab)/2
104 ;--------------------------------------------------------------
108 ; de: ioctl arg pointer
109 ; hl: ptr to driver local data
140 ;--------------------------------------------------------------
141 ; CP/M 3 DEVINI function
142 ; Init Serial I/O for input and output (ASCI 0/1)
148 ld c,asext0 ;Enable baud rate generator
149 ld a,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS +M_BREAKEN
150 bit CCTS_OFLOW,(ix+o.fflags)
160 ld a,(hl) ;get baudrate index
166 ld a,M_MPBT ;No MP Mode, X16
167 bit PARODD,(ix+o.iflags)
178 or a,M_RE+M_TE+M_RTS0+M_EFR ;Rx/Tx enable
184 ld hl,rtxisvjmp0 ;rx/tx int vector
185 ld (ivtab + IV$ASCI0),hl ;
191 ld hl,rtxisvjmp1 ;rx/tx int vector
192 ld (ivtab + IV$ASCI1),hl ;
202 ;--------------------------------------------------------------
215 ;--------------------------------------------------------------
216 ; Get the current serial port settings.
233 ld a,(hl) ;get baudrate index
245 ;--------------------------------------------------------------
246 ; Set the current serial port settings.
268 ld (hl),a ;set baudrate index
277 ;--------------------------------------------------------------
278 ; Allow the output buffer to drain
282 ;--------------------------------------------------------------
283 ; Allow the output buffer to drain, discard pending input
287 ;--------------------------------------------------------------
288 ; Sending a break (250ms .. 500ms)
292 ;--------------------------------------------------------------
293 ; arg is timeinterval in 0.1sec
297 ;--------------------------------------------------------------
302 ;--------------------------------------------------------------
307 ;--------------------------------------------------------------
308 ; Software flow control (TCOOFF, TCOON, TCIOFF, TCION)
312 ;--------------------------------------------------------------
313 ; Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH)
317 ;--------------------------------------------------------------
318 ; Get the number of bytes in the input buffer.
322 ;--------------------------------------------------------------
323 ; Get the number of bytes in the output buffer.
327 ;--------------------------------------------------------------
328 ; get the status of modem bits.
332 ;--------------------------------------------------------------
333 ; set the indicated modem bits.
337 ;--------------------------------------------------------------
338 ; clear the indicated modem bits.
342 ;--------------------------------------------------------------
343 ; set the status of modem bits.
347 ;--------------------------------------------------------------
348 ; Get the status of the CLOCAL flag in the c_cflag field
352 ;--------------------------------------------------------------
353 ; Set the CLOCAL flag when *argp is nonzero, and clear it otherwise.
360 ;--------------------------------------------------------------
370 ;--------------------------------------------------------------
373 ld c,stat0 ;Disable rx/tx interrupts
377 ld c,cntla0 ;Disable receiver and transmitter
378 ld a,M_RTS0+M_EFR ;RTS/CKA1
381 ;--------------------------------------------------------------
387 and ~M_RTS0 ;Activate RTS
395 ;--------------------------------------------------------------
396 ; output to asci0/1 register
398 ; c: register address
412 ;--------------------------------------------------------------
413 ; output 16 bit value to asci0/1 register
415 ; c: register address
432 ;--------------------------------------------------------------
464 ; factor index baudrate orig. cp/m
465 dw 19200/150 ; 0 19200 -
466 dw 28800/150 ; 1 28800 50
467 dw 38400/150 ; 2 38400 75
468 dw 57600/150 ; 3 57600 110
469 dw 11520/15 ; 4 115200 134.5
480 dw 19200/150 ;15 19200
483 ;--------------------------------------------------------------
488 db 1,stat0,0 ;Disable rx/tx interrupts
489 ;Enable baud rate generator
490 db 1,asext0,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS
492 init_br_off equ $ - initab0
494 db 1,cntlb0,M_MPBT ;No MP Mode, X16
495 db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
499 db 1,stat1,0 ;Disable rx/tx ints, disable CTS1
500 db 1,asext1,M_BRGMOD ;Enable baud rate generator
501 db 2,astc1l,low 3, high 3
502 db 1,cntlb1,M_MPBT ;No MP Mode, X16
503 db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
507 ;--------------------------------------------------------------
517 ;--------------------------------------------------------------
526 ;--------------------------------------------------------------
527 ; Get an input character
553 ld a,b ;remaining chrs in buffer
554 cp s0.rx_len/4 ; < 32?
555 jr nc,a0i_2 ; no, just get char
556 ld b,(ix+oint.fflags) ; yes, enable RTS if needed
557 bit CRTS_IFLOW,b ; yes, enable RTS if needed
558 jr z,a0i_1 ; no needed
561 and ~M_RTS0 ;assert RTS
562 or M_EFR ;don't reset error flags
566 bit IXOFF,b ; XON/XOFF on input?
569 set TDC1,(ix+oint.stat) ;
579 ;--------------------------------------------------------------
580 ; Get an input character
586 ld a,b ; remaining chars in buffer
587 cp s0.rx_len/4 ; == 25% full?
588 jr nz,a1i_2 ; no, just get char
589 bit IXOFF,(ix+oint.fflags) ; XON/XOFF on input?
592 set TDC1,(ix+oint.stat) ;
598 ld a,c ; get back the char
602 ;--------------------------------------------------------------
612 ;--------------------------------------------------------------
622 ;--------------------------------------------------------------
623 ; put character in c in buffer
625 ; returns output char in a
639 ;--------------------------------------------------------------
640 ; put character in c in buffer
642 ; returns output char in a
657 ;--------------------------------------------------------------
668 ;--------------------------------------------------------------
669 ; ASCI 0/1 Transmit/Receive interupt routines
677 ld d,(ix+oint.fflags)
679 in0 e,(stat&dev) ;get asci status
680 jp p,txi&dev ;RDRF == Bit 7
685 in0 a,(asext&dev) ;get break status
687 or e ;merge to other error flags
690 in0 a,(cntla&dev) ;reset all error flags
694 ld c,(ix+o.in_idx) ;input buffer pointer
699 in0 b,(rdr&dev) ;get char
700 ;todo: break detection
701 ;todo: parity, framing, overrun error
709 ld a,c ;increment buffer in pointer
716 jr z,rxtxi&dev&_lp1 ;skip if buffer is full
718 ld (ix+o.in_idx),c ;input buffer pointer
726 if dev=0 ; only channel 0 has rts line
730 in0 a,(cntla&dev) ;reset all error flags
731 or M_RTS0+M_EFR ;RTS inactive
739 set TDC3,(ix+oint.stat)
750 ld a,(ix+oint.stat) ;check if xon/xoff should be sent
752 jr z,txi&dev&_char ; no
754 ld l,DC3 ;prepare for xoff
755 bit TDC1,a ;request for xon (also) set?
760 and ~(M_TDC1+M_TDC3) ;reset request flags
761 ld (ix+oint.stat),a ;
765 ld hl,s&dev&.outbuf+o.in_idx ;[in]
770 jr z,txi&dev&_empty ;
777 ld a,(s&dev&.outbuf+o.mask) ;
779 ld (s&dev&.outbuf+o.out_idx),a ;
784 res TIE,e ;disable tx-int
785 out0 (stat&dev),e ; 5
793 ;--------------------------------------------------------------
794 ; ASCI 0 Transmit/Receive interupt routines
799 ;--------------------------------------------------------------
800 ; ASCI 1 Transmit/Receive interupt routines