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
51 oint.iflags equ as0_dev+o.iflags-s0.inbuf
52 oint.fflags equ as0_dev+o.fflags-s0.inbuf
53 oint.stat equ as0_dev+o.stat-s0.inbuf
54 mkbuf s0.rx_id, s0.inbuf, s0.rx_len
55 mkbuf s0.tx_id, s0.outbuf,s0.tx_len
64 db 0 ;absolute device #
67 db M_CREAD+M_IXOFF ;fflags
72 mkbuf s1.rx_id, s1.inbuf, s1.rx_len
73 mkbuf s1.tx_id, s1.outbuf,s1.tx_len
81 dw func_tcinit ;(00h) CP/M 3 DEVINI function
82 dw func_tcgeta ;(01h) Get the current serial port settings.
83 dw func_tcseta ;(02h) Set the current serial port settings.
84 dw func_tcsetaw ;(03h) Allow the output buffer to drain
85 dw func_tcsetaf ;(04h) Allow the output buffer to drain, discard pending input
86 dw func_tcsbrk ;(05h) Sending a break (250ms .. 500ms)
87 dw func_tcsbrkp ;(06h) arg is timeinterval in 0.1sec
88 dw func_tiocsbrk ;(07h) Turn break on
89 dw func_tioccbrk ;(08h) Turn break off
90 dw func_tcxonc ;(09h) Software flow control (TCOOFF, TCOON, TCIOFF, TCION)
91 dw func_tcflsh ;(0Ah) Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH)
92 dw func_fionread ;(0Bh) Get the number of bytes in the input buffer.
93 dw func_tiocoutq ;(0Ch) Get the number of bytes in the output buffer.
94 dw func_tiocmget ;(0Dh) get the status of modem bits.
95 dw func_tiocmbis ;(0Eh) set the indicated modem bits.
96 dw func_tiocmbic ;(0Fh) clear the indicated modem bits.
97 dw func_tiocmset ;(10h) set the status of modem bits.
98 dw func_tiocgsoftcar ;(11h) Get the status of the CLOCAL flag in the c_cflag field
99 dw func_tiocssoftcar ;(12h) Set the CLOCAL flag when *argp is nonzero, and clear it otherwise.
101 IOCTL_MAX equ ($-ioctl_ftab)/2
105 ;--------------------------------------------------------------
109 ; de: ioctl arg pointer
110 ; hl: ptr to driver local data
141 ;--------------------------------------------------------------
142 ; CP/M 3 DEVINI function
143 ; Init Serial I/O for input and output (ASCI 0/1)
149 ld c,asext0 ;Enable baud rate generator
150 ld a,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS +M_BREAKEN
151 bit CCTS_OFLOW,(ix+o.fflags)
161 ld a,(hl) ;get baudrate index
167 ld a,M_MPBT ;No MP Mode, X16
168 bit PARODD,(ix+o.iflags)
179 or a,M_RE+M_TE+M_RTS0+M_EFR ;Rx/Tx enable
185 ld hl,rtxisvjmp0 ;rx/tx int vector
186 ld (ivtab + IV$ASCI0),hl ;
192 ld hl,rtxisvjmp1 ;rx/tx int vector
193 ld (ivtab + IV$ASCI1),hl ;
203 ;--------------------------------------------------------------
216 ;--------------------------------------------------------------
217 ; Get the current serial port settings.
234 ld a,(hl) ;get baudrate index
246 ;--------------------------------------------------------------
247 ; Set the current serial port settings.
269 ld (hl),a ;set baudrate index
278 ;--------------------------------------------------------------
279 ; Allow the output buffer to drain
283 ;--------------------------------------------------------------
284 ; Allow the output buffer to drain, discard pending input
288 ;--------------------------------------------------------------
289 ; Sending a break (250ms .. 500ms)
293 ;--------------------------------------------------------------
294 ; arg is timeinterval in 0.1sec
298 ;--------------------------------------------------------------
303 ;--------------------------------------------------------------
308 ;--------------------------------------------------------------
309 ; Software flow control (TCOOFF, TCOON, TCIOFF, TCION)
313 ;--------------------------------------------------------------
314 ; Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH)
318 ;--------------------------------------------------------------
319 ; Get the number of bytes in the input buffer.
323 ;--------------------------------------------------------------
324 ; Get the number of bytes in the output buffer.
328 ;--------------------------------------------------------------
329 ; get the status of modem bits.
333 ;--------------------------------------------------------------
334 ; set the indicated modem bits.
338 ;--------------------------------------------------------------
339 ; clear the indicated modem bits.
343 ;--------------------------------------------------------------
344 ; set the status of modem bits.
348 ;--------------------------------------------------------------
349 ; Get the status of the CLOCAL flag in the c_cflag field
353 ;--------------------------------------------------------------
354 ; Set the CLOCAL flag when *argp is nonzero, and clear it otherwise.
361 ;--------------------------------------------------------------
371 ;--------------------------------------------------------------
374 ld c,stat0 ;Disable rx/tx interrupts
378 ld c,cntla0 ;Disable receiver and transmitter
379 ld a,M_RTS0+M_EFR ;RTS/CKA1
382 ;--------------------------------------------------------------
388 and ~M_RTS0 ;Activate RTS
396 ;--------------------------------------------------------------
397 ; output to asci0/1 register
399 ; c: register address
413 ;--------------------------------------------------------------
414 ; output 16 bit value to asci0/1 register
416 ; c: register address
433 ;--------------------------------------------------------------
465 ; factor index baudrate orig. cp/m
466 dw 19200/150 ; 0 19200 -
467 dw 28800/150 ; 1 28800 50
468 dw 38400/150 ; 2 38400 75
469 dw 57600/150 ; 3 57600 110
470 dw 11520/15 ; 4 115200 134.5
481 dw 19200/150 ;15 19200
484 ;--------------------------------------------------------------
489 db 1,stat0,0 ;Disable rx/tx interrupts
490 ;Enable baud rate generator
491 db 1,asext0,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS
493 init_br_off equ $ - initab0
495 db 1,cntlb0,M_MPBT ;No MP Mode, X16
496 db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
500 db 1,stat1,0 ;Disable rx/tx ints, disable CTS1
501 db 1,asext1,M_BRGMOD ;Enable baud rate generator
502 db 2,astc1l,low 3, high 3
503 db 1,cntlb1,M_MPBT ;No MP Mode, X16
504 db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1
508 ;--------------------------------------------------------------
518 ;--------------------------------------------------------------
527 ;--------------------------------------------------------------
528 ; Get an input character
554 ld a,b ;remaining chrs in buffer
555 cp s0.rx_len/4 ; < 32?
556 jr nc,a0i_2 ; no, just get char
557 ld b,(ix+oint.fflags) ; yes, enable RTS if needed
558 bit CRTS_IFLOW,b ; yes, enable RTS if needed
559 jr z,a0i_1 ; no needed
562 and ~M_RTS0 ;assert RTS
563 or M_EFR ;don't reset error flags
567 bit IXOFF,b ; XON/XOFF on input?
570 set TDC1,(ix+oint.stat) ;
580 ;--------------------------------------------------------------
581 ; Get an input character
587 ld a,b ; remaining chars in buffer
588 cp s0.rx_len/4 ; == 25% full?
589 jr nz,a1i_2 ; no, just get char
590 bit IXOFF,(ix+oint.fflags) ; XON/XOFF on input?
593 set TDC1,(ix+oint.stat) ;
599 ld a,c ; get back the char
603 ;--------------------------------------------------------------
613 ;--------------------------------------------------------------
623 ;--------------------------------------------------------------
624 ; put character in c in buffer
632 ld a,(as0_dev+o.stat) ;Transmitter stopped?
642 ;--------------------------------------------------------------
643 ; put character in c in buffer
651 ld a,(as1_dev+o.stat) ;Transmitter stopped?
662 ;--------------------------------------------------------------
673 ;--------------------------------------------------------------
674 ; ASCI 0/1 Transmit/Receive interupt routines
680 ld d,(ix+oint.fflags)
682 in0 e,(stat&dev) ;get asci status
683 jp p,txi&dev ;RDRF == Bit 7
688 in0 a,(asext&dev) ;get break status
690 or e ;merge to other error flags
693 in0 a,(cntla&dev) ;reset all error flags
697 ld c,(ix+o.in_idx) ;get input index
699 ld hl,s&dev&.inbuf ; + base = input buffer pointer
702 in0 b,(rdr&dev) ;get char
703 ;todo: break detection
704 ;todo: parity, framing, overrun error
712 set TOFF,(ix+oint.stat) ;Stop transmitter
718 res TOFF,(ix+oint.stat) ;Enable transmitter
723 res TOFF,(ix+oint.stat) ;Enable transmitter
726 ld a,c ;increment input index
732 sub (ix+o.out_idx) ;number of free places in buffer
733 jr z,rxtxi&dev&_lp1 ;buffer full?
735 ld (ix+o.in_idx),c ; no, update input index
737 cp s&dev&.tx_len*3/4 ;buffer now 75% full?
740 if dev=0 ;only channel 0 has rts line
744 or M_RTS0+M_EFR ;RTS inactive
752 set TDC3,(ix+oint.stat)
764 ld a,(ix+oint.stat) ;check whether xon/xoff should be sent
766 jr z,txi&dev&_char ; no
768 ld l,DC3 ;prepare for xoff
769 bit TDC1,a ;request for xon (also) set?
774 and ~(M_TDC1+M_TDC3) ;reset request flags
775 ld (ix+oint.stat),a ;
779 bit TOFF,(ix+oint.stat)
780 jr nz,txi&dev&_empty ;
782 ld hl,s&dev&.outbuf+o.in_idx ;[in]
787 jr z,txi&dev&_empty ;
794 ld a,(s&dev&.outbuf+o.mask);
796 ld (s&dev&.outbuf+o.out_idx),a ;
801 res TIE,e ;disable tx-int
810 ;--------------------------------------------------------------
811 ; ASCI 0 Transmit/Receive interupt routines
816 ;--------------------------------------------------------------
817 ; ASCI 1 Transmit/Receive interupt routines