X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp-cpm3.git/blobdiff_plain/6dd88c258326e3bc0538c15b3b7fe3e04874ab99..7c72cfe363cdc89093e62ddcd47fc2e1df98e5cf:/cbios/ascii.180?ds=inline diff --git a/cbios/ascii.180 b/cbios/ascii.180 index cb48550..0ee942d 100644 --- a/cbios/ascii.180 +++ b/cbios/ascii.180 @@ -1,22 +1,24 @@ - page 200 ; Interrupt drivers for ASCI0 and ASCI1 global as0_dev,as1_dev - extrn as_init + extrn @ctbl,f_cpu extrn ff_empty,ff_get,ff_full,ff_put extrn ff_puth,ff_cnt,ff_gech extrn bufinit - extrn isv_sw,ijphl,add_hla + extrn isv_sw,ijphl,add_hla,div32_r + extrn b_st_a,b_ld_a - include config.inc - include ioctl.inc - include z180reg.inc + maclib z180reg.inc + maclib config.inc + maclib ioctl.inc + maclib modebaud.inc + m2b mbxon_bit,mb$xon$xoff ;----------------------------------------------------- @@ -28,16 +30,24 @@ dw asci0_ista dw asci_ioctl as0_dev: - db 0 - db 0 - db 0 - db 0 - db 0 + db 0 ;absolute device # + db 0 ;relative device + db 0 ;iflags + db 0 ;fflags + db M_CS8 ;cflags o.absdev equ 0 o.reldev equ 1 -o.cflags equ 2 -o.iflags equ 3 -o.fflags equ 4 +o.iflags equ 2 +o.fflags equ 3 +o.cflags equ 4 + + db 0 + db 0 +oint.iflags equ as0_dev+o.iflags-s0.inbuf +oint.fflags equ as0_dev+o.fflags-s0.inbuf + mkbuf s0.rx_id, s0.inbuf, s0.rx_len + mkbuf s0.tx_id, s0.outbuf,s0.tx_len + dw asci1_out dw asci1_osta @@ -45,20 +55,14 @@ o.fflags equ 4 dw asci1_ista dw asci_ioctl as1_dev: - db 0 - db 1 - db 0 - db 0 - db 0 + db 0 ;absolute device # + db 1 ;relative device + db 0 ;iflags + db 0 ;fflags + db M_CS8 ;cflags - - -o.in_flags equ $-s0.inbuf db 0 -o.in_flow equ $-s0.inbuf db 0 - mkbuf s0.rx_id, s0.inbuf, s0.rx_len - mkbuf s0.tx_id, s0.outbuf,s0.tx_len mkbuf s1.rx_id, s1.inbuf, s1.rx_len mkbuf s1.tx_id, s1.outbuf,s1.tx_len @@ -68,10 +72,30 @@ o.in_flow equ $-s0.inbuf ioctl_ftab: - dw cinit + dw func_tcinit ;(00h) CP/M 3 DEVINI function + dw func_tcgeta ;(01h) Get the current serial port settings. + dw func_tcseta ;(02h) Set the current serial port settings. + dw func_tcsetaw ;(03h) Allow the output buffer to drain + dw func_tcsetaf ;(04h) Allow the output buffer to drain, discard pending input + dw func_tcsbrk ;(05h) Sending a break (250ms .. 500ms) + dw func_tcsbrkp ;(06h) arg is timeinterval in 0.1sec + dw func_tiocsbrk ;(07h) Turn break on + dw func_tioccbrk ;(08h) Turn break off + dw func_tcxonc ;(09h) Software flow control (TCOOFF, TCOON, TCIOFF, TCION) + dw func_tcflsh ;(0Ah) Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH) + dw func_fionread ;(0Bh) Get the number of bytes in the input buffer. + dw func_tiocoutq ;(0Ch) Get the number of bytes in the output buffer. + dw func_tiocmget ;(0Dh) get the status of modem bits. + dw func_tiocmbis ;(0Eh) set the indicated modem bits. + dw func_tiocmbic ;(0Fh) clear the indicated modem bits. + dw func_tiocmset ;(10h) set the status of modem bits. + dw func_tiocgsoftcar ;(11h) Get the status of the CLOCAL flag in the c_cflag field + dw func_tiocssoftcar ;(12h) Set the CLOCAL flag when *argp is nonzero, and clear it otherwise. + IOCTL_MAX equ ($-ioctl_ftab)/2 dw nofunc + ;-------------------------------------------------------------- ; ; b: device number @@ -98,45 +122,358 @@ asci_ioctl: call ijphl pop ix nofunc: + or a ret - ;-------------------------------------------------------------- +; CP/M 3 DEVINI function ; Init Serial I/O for input and output (ASCI 0/1) -cinit: - ld a,stat0 - add a,(ix+o.reldev) - ld c,a - ld b,0 - push bc - xor a ; - out (c),a ;Disable rx/tx interrupts +func_tcinit: + call asci_stop + +init_st: + ld c,asext0 ;Enable baud rate generator + ld a,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS +M_BREAKEN + bit CCTS_OFLOW,(ix+o.fflags) + jr nz,$+4 + or M_CTS0DIS + call out_asci_reg - ld c,(ix+o.reldev) ld b,(ix+o.absdev) - call as_init + ld c,8 ; + mlt bc ; + ld hl,@ctbl+7 ; + add hl,bc ; + ld a,(hl) ;get baudrate index + call as_br_div + ld c,astc0l + ld a,l + call out_asci_reg + inc c + ld a,h + call out_asci_reg + + + ld c,cntlb0 + ld a,M_MPBT ;No MP Mode, X16 + bit PARODD,(ix+o.iflags) + jr z,$+4 + or M_PEO + call out_asci_reg + + ld c,cntla0 + ld a,(ix+o.cflags) + srlan CS8 + ld hl,mod_tab + call add_hla + ld a,(hl) + or a,M_RE+M_TE+M_RTS0+M_EFR ;Rx/Tx enable + call out_asci_reg + + push ix bit 0,(ix+o.reldev) jr nz,init_1 ld hl,rtxisvjmp0 ;rx/tx int vector ld (ivtab + IV$ASCI0),hl ; - ld ix,s0.inbuf - call bufinit ld ix,s0.outbuf + call bufinit + ld ix,s0.inbuf jr init_2 init_1: ld hl,rtxisvjmp1 ;rx/tx int vector ld (ivtab + IV$ASCI1),hl ; - ld ix,s1.inbuf - call bufinit ld ix,s1.outbuf + call bufinit + ld ix,s1.inbuf init_2: call bufinit - pop bc + pop ix + call asci_start + ret + +;-------------------------------------------------------------- + +mod_tab: + db 000B ; 7N1 + db 100B ; 8N1 + db 001B ; 7N2 + db 101B ; 8N2 + db 010B ; 7P1 + db 110B ; 8P1 + db 011B ; 7P2 + db 111B ; 8P2 + + +;-------------------------------------------------------------- +; Get the current serial port settings. + +func_tcgeta: + ld a,d + or e + ld a,0ffh + jr z,fgeta_e + + ld a,(ix+o.iflags) + call b_st_a + inc de + ld a,(ix+o.fflags) + call b_st_a + inc de + + ld b,(ix+o.absdev) + ld c,8 ; + mlt bc ; + ld hl,@ctbl+7 ; + add hl,bc ; + ld a,(hl) ;get baudrate index + and M_CBAUD + ld b,a + ld a,(ix+o.cflags) + and ~M_CBAUD + or b + call b_st_a + dec de + dec de + xor a +fgeta_e: + ret + + +;-------------------------------------------------------------- +; Set the current serial port settings. + +func_tcseta: + ld a,d + or e + ld a,0ffh + jr z,fseta_e + + call asci_stop + + call b_ld_a + ld (ix+o.iflags),a + inc de + call b_ld_a + ld (ix+o.fflags),a + inc de + + ld b,(ix+o.absdev) + ld c,8 ; + mlt bc ; + ld hl,@ctbl+7 ; + add hl,bc ; + call b_ld_a + ld (ix+o.cflags),a + and M_CBAUD + ld (hl),a ;set baudrate index + dec de + dec de + push de + call init_st + pop de + xor a +fseta_e: + ret + + +;-------------------------------------------------------------- +; Allow the output buffer to drain + +func_tcsetaw: + +;-------------------------------------------------------------- +; Allow the output buffer to drain, discard pending input + +func_tcsetaf: + +;-------------------------------------------------------------- +; Sending a break (250ms .. 500ms) + +func_tcsbrk: + +;-------------------------------------------------------------- +; arg is timeinterval in 0.1sec + +func_tcsbrkp: + +;-------------------------------------------------------------- +; Turn break on + +func_tiocsbrk: + +;-------------------------------------------------------------- +; Turn break off + +func_tioccbrk: + +;-------------------------------------------------------------- +; Software flow control (TCOOFF, TCOON, TCIOFF, TCION) + +func_tcxonc: + +;-------------------------------------------------------------- +; Flush input/output buffer (TCIFLUSH, TCOFLUSH, TCIOFLUSH) + +func_tcflsh: + +;-------------------------------------------------------------- +; Get the number of bytes in the input buffer. + +func_fionread: + +;-------------------------------------------------------------- +; Get the number of bytes in the output buffer. + +func_tiocoutq: + +;-------------------------------------------------------------- +; get the status of modem bits. + +func_tiocmget: + +;-------------------------------------------------------------- +; set the indicated modem bits. + +func_tiocmbis: + +;-------------------------------------------------------------- +; clear the indicated modem bits. + +func_tiocmbic: + +;-------------------------------------------------------------- +; set the status of modem bits. + +func_tiocmset: + +;-------------------------------------------------------------- +; Get the status of the CLOCAL flag in the c_cflag field + +func_tiocgsoftcar: + +;-------------------------------------------------------------- +; Set the CLOCAL flag when *argp is nonzero, and clear it otherwise. + +func_tiocssoftcar: + + or 0ffh + ret + +;-------------------------------------------------------------- + +asci_stop: + ld c,stat0 ;Disable rx/tx interrupts + xor a ; + call out_asci_reg + + ld c,cntla0 ;Disable receiver and transmitter + ld a,M_RTS0+M_EFR ;RTS/CKA1 + jr out_asci_reg + +;-------------------------------------------------------------- + +asci_start: + ld c,stat0 ; ld a,M_RIE - out (c),a ;Enable rx interrupts + jr out_asci_reg + +;-------------------------------------------------------------- +; output to asci0/1 register +; +; c: register address +; a: value +; + +out_asci_reg: + push bc + ld b,a + ld a,c + cp astc0l ;astc0/1 are 16 bit + jr c,$+5 + add a,(ix+o.reldev) + add a,(ix+o.reldev) + ld c,a + ld a,b + ld b,0 + out (c),a + pop bc ret +;-------------------------------------------------------------- +; baud rate divider +; +; a: index +; return +; hl: divider + +as_br_div: + push de + push bc + and 0fh + add a,a ;get factor + ld hl,bd150_tab + call add_hla + ld c,(hl) + inc hl + ld b,(hl) + ld hl,(f_cpu) + ld de,(f_cpu+2) + call div32_r + ld bc,32*150 + call div32_r + ld de,2 + or a + sbc hl,de + pop bc + pop de + ret nc + ld hl,0 + ret + +bd150_tab: +; factor index baudrate orig. cp/m + dw 19200/150 ; 0 19200 - + dw 28800/150 ; 1 28800 50 + dw 38400/150 ; 2 38400 75 + dw 57600/150 ; 3 57600 110 + dw 11520/15 ; 4 115200 134.5 + dw 150/150 ; 5 150 + dw 300/150 ; 6 300 + dw 600/150 ; 7 600 + dw 1200/150 ; 8 1200 + dw 1800/150 ; 9 1800 + dw 2400/150 ;10 2400 + dw 3600/150 ;11 3600 + dw 4800/150 ;12 4800 + dw 7200/150 ;13 7200 + dw 9600/150 ;14 9600 + dw 19200/150 ;15 19200 + + +;-------------------------------------------------------------- + + if 0 + +initab0: + db 1,stat0,0 ;Disable rx/tx interrupts + ;Enable baud rate generator + db 1,asext0,M_BRGMOD+M_DCD0DIS ; +M_CTS0DIS + db 2,astc0l +init_br_off equ $ - initab0 + dw 28 + db 1,cntlb0,M_MPBT ;No MP Mode, X16 + db 1,cntla0,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1 + db 0 + +initab1: + db 1,stat1,0 ;Disable rx/tx ints, disable CTS1 + db 1,asext1,M_BRGMOD ;Enable baud rate generator + db 2,astc1l,low 3, high 3 + db 1,cntlb1,M_MPBT ;No MP Mode, X16 + db 1,cntla1,M_RE+M_TE+M_MOD2 ;Rx/Tx enable, 8N1 + db 0 + endif ;-------------------------------------------------------------- @@ -288,7 +625,7 @@ rxtxi0_lp1: ;todo: parity, framing overrun error - ld e,(ix+o.in_flow) + ld e,(ix+oint.fflags) bit IXON,e jr z,rxtxi0_2