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
46 oint.iflags equ as0_dev+o.iflags-s0.inbuf
47 oint.fflags equ as0_dev+o.fflags-s0.inbuf
48 mkbuf s0.rx_id, s0.inbuf, s0.rx_len
49 mkbuf s0.tx_id, s0.outbuf,s0.tx_len
58 db 0 ;absolute device #
61 db M_CREAD+M_IXOFF ;fflags
66 mkbuf s1.rx_id, s1.inbuf, s1.rx_len
67 mkbuf s1.tx_id, s1.outbuf,s1.tx_len
75 dw func_tcinit ;(00h) CP/M 3 DEVINI function
76 dw func_tcgeta ;(01h) Get the current serial port settings.
77 dw func_tcseta ;(02h) Set the current serial port settings.
78 dw func_tcsetaw ;(03h) Allow the output buffer to drain
79 dw func_tcsetaf ;(04h) Allow the output buffer to drain, discard pending input
80 dw func_tcsbrk ;(05h) Sending a break (250ms .. 500ms)
81 dw func_tcsbrkp ;(06h) arg is timeinterval in 0.1sec
82 dw func_tiocsbrk ;(07h) Turn break on
83 dw func_tioccbrk ;(08h) Turn break off
84 dw func_tcxonc ;(09h) Software flow control (TCOOFF, TCOON, TCIOFF, TCION)
85 dw func_tcflsh ;(0Ah) Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH)
86 dw func_fionread ;(0Bh) Get the number of bytes in the input buffer.
87 dw func_tiocoutq ;(0Ch) Get the number of bytes in the output buffer.
88 dw func_tiocmget ;(0Dh) get the status of modem bits.
89 dw func_tiocmbis ;(0Eh) set the indicated modem bits.
90 dw func_tiocmbic ;(0Fh) clear the indicated modem bits.
91 dw func_tiocmset ;(10h) set the status of modem bits.
92 dw func_tiocgsoftcar ;(11h) Get the status of the CLOCAL flag in the c_cflag field
93 dw func_tiocssoftcar ;(12h) Set the CLOCAL flag when *argp is nonzero, and clear it otherwise.
95 IOCTL_MAX equ ($-ioctl_ftab)/2
99 ;--------------------------------------------------------------
103 ; de: ioctl arg pointer
104 ; hl: ptr to driver local data
135 ;--------------------------------------------------------------
136 ; CP/M 3 DEVINI function
137 ; Init Serial I/O for input and output (ASCI 0/1)
143 ld c,asext0 ;Enable baud rate generator
144 ld a,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS +M_BREAKEN
145 bit CCTS_OFLOW,(ix+o.fflags)
155 ld a,(hl) ;get baudrate index
161 ld a,M_MPBT ;No MP Mode, X16
162 bit PARODD,(ix+o.iflags)
173 or a,M_RE+M_TE+M_RTS0+M_EFR ;Rx/Tx enable
179 ld hl,rtxisvjmp0 ;rx/tx int vector
180 ld (ivtab + IV$ASCI0),hl ;
186 ld hl,rtxisvjmp1 ;rx/tx int vector
187 ld (ivtab + IV$ASCI1),hl ;
197 ;--------------------------------------------------------------
210 ;--------------------------------------------------------------
211 ; Get the current serial port settings.
228 ld a,(hl) ;get baudrate index
240 ;--------------------------------------------------------------
241 ; Set the current serial port settings.
263 ld (hl),a ;set baudrate index
272 ;--------------------------------------------------------------
273 ; Allow the output buffer to drain
277 ;--------------------------------------------------------------
278 ; Allow the output buffer to drain, discard pending input
282 ;--------------------------------------------------------------
283 ; Sending a break (250ms .. 500ms)
287 ;--------------------------------------------------------------
288 ; arg is timeinterval in 0.1sec
292 ;--------------------------------------------------------------
297 ;--------------------------------------------------------------
302 ;--------------------------------------------------------------
303 ; Software flow control (TCOOFF, TCOON, TCIOFF, TCION)
307 ;--------------------------------------------------------------
308 ; Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH)
312 ;--------------------------------------------------------------
313 ; Get the number of bytes in the input buffer.
317 ;--------------------------------------------------------------
318 ; Get the number of bytes in the output buffer.
322 ;--------------------------------------------------------------
323 ; get the status of modem bits.
327 ;--------------------------------------------------------------
328 ; set the indicated modem bits.
332 ;--------------------------------------------------------------
333 ; clear the indicated modem bits.
337 ;--------------------------------------------------------------
338 ; set the status of modem bits.
342 ;--------------------------------------------------------------
343 ; Get the status of the CLOCAL flag in the c_cflag field
347 ;--------------------------------------------------------------
348 ; Set the CLOCAL flag when *argp is nonzero, and clear it otherwise.
355 ;--------------------------------------------------------------
365 ;--------------------------------------------------------------
368 ld c,stat0 ;Disable rx/tx interrupts
372 ld c,cntla0 ;Disable receiver and transmitter
373 ld a,M_RTS0+M_EFR ;RTS/CKA1
376 ;--------------------------------------------------------------
382 and ~M_RTS0 ;Activate RTS
390 ;--------------------------------------------------------------
391 ; output to asci0/1 register
393 ; c: register address
407 ;--------------------------------------------------------------
408 ; output 16 bit value to asci0/1 register
410 ; c: register address
427 ;--------------------------------------------------------------
459 ; factor index baudrate orig. cp/m
460 dw 19200/150 ; 0 19200 -
461 dw 28800/150 ; 1 28800 50
462 dw 38400/150 ; 2 38400 75
463 dw 57600/150 ; 3 57600 110
464 dw 11520/15 ; 4 115200 134.5
475 dw 19200/150 ;15 19200
478 ;--------------------------------------------------------------
483 db 1,stat0,0 ;Disable rx/tx interrupts
484 ;Enable baud rate generator
485 db 1,asext0,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS
487 init_br_off equ $ - initab0
489 db 1,cntlb0,M_MPBT ;No MP Mode, X16
490 db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
494 db 1,stat1,0 ;Disable rx/tx ints, disable CTS1
495 db 1,asext1,M_BRGMOD ;Enable baud rate generator
496 db 2,astc1l,low 3, high 3
497 db 1,cntlb1,M_MPBT ;No MP Mode, X16
498 db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
502 ;--------------------------------------------------------------
512 ;--------------------------------------------------------------
521 ;--------------------------------------------------------------
522 ; Get an input character
548 ld a,b ;remaining chrs in buffer
549 cp s0.rx_len/4 ; < 32?
550 jr nc,a0i_1 ; no, just get char
551 bit CRTS_IFLOW,(ix+oint.fflags) ; yes, enable RTS if needed
552 jr z,a0i_1 ; no needed
555 and ~M_RTS0 ;assert RTS
556 or M_EFR ;don't reset error flags
564 ;--------------------------------------------------------------
565 ; Get an input character
571 ld a,b ; remaining chars in buffer
572 cp s0.rx_len/4 ; == 25% full?
573 jr nz,a1i_2 ; no, just get char
574 bit IXOFF,(ix+oint.fflags) ; XON/XOFF on input?
577 a1i_1: in0 a,(stat1) ; status reg ASCI1
578 bit TDRE,a ; Transmitter Data Reg. empty?
579 jr z,a1i_1 ; no, wait
581 out0 (tdr1),a ; send out
584 ld a,c ; get back the char
588 ;--------------------------------------------------------------
598 ;--------------------------------------------------------------
608 ;--------------------------------------------------------------
609 ; put character in c in buffer
611 ; returns output char in a
625 ;--------------------------------------------------------------
626 ; put character in c in buffer
628 ; returns output char in a
643 ;--------------------------------------------------------------
654 ;--------------------------------------------------------------
655 ; ASCI 0/1 Transmit/Receive interupt routines
659 local rxi_2,rxi_3,rxi_4
665 in0 a,(stat&dev) ;receive flag set?
666 jp p,txi&dev ;RDRF == Bit 7
667 and M_OVRN+M_PERR+M_FE
679 ld c,(ix+o.in_idx) ;input buffer pointer
684 in0 a,(rdr&dev) ;get char
686 ;todo: break detection
687 ;todo: parity, framing overrun error
689 ld e,(ix+oint.fflags)
693 ld a,c ;increment buffer in pointer
700 jr z,rxtxi&dev&_lp1 ;skip if buffer is full
702 ld (ix+o.in_idx),c ;input buffer pointer
715 set RTS0,d ;RTS inactive
723 rxi_3: in0 a,(stat&dev) ; status reg ASCI1
724 bit TDRE,a ; Transmitter Data Reg. empty?
725 jr z,rxi_3 ; no, wait
727 out0 (tdr&dev),a ; send out
733 ; jr z,rxtxi&dev&_lp1
746 ld hl,s&dev&.outbuf+o.in_idx ;[in]
751 jr z,txi&dev&_empty ;
758 ld a,(s&dev&.outbuf+o.mask) ;
760 ld (s&dev&.outbuf+o.out_idx),a ;
765 res TIE,e ;disable tx-int
766 out0 (stat&dev),e ; 5
774 ;--------------------------------------------------------------
775 ; ASCI 0 Transmit/Receive interupt routines
780 ;--------------------------------------------------------------
781 ; ASCI 1 Transmit/Receive interupt routines