From 1c7e396322093876bd5405aa6c2beed7c04608ec Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 6 Nov 2015 19:13:42 +0100 Subject: [PATCH] Add TCGETA, TCSETA --- cbios/Makefile | 2 +- cbios/ascii.180 | 424 ++++++++++++++++++++++++++++++++++++++++----- cbios/bioskrnl.180 | 19 +- cbios/chario.180 | 19 +- cbios/config.inc | 46 +++++ cbios/ioctl.inc | 11 +- cbios/mm.180 | 123 ++++++++++++- cbios/utils.180 | 6 +- 8 files changed, 575 insertions(+), 75 deletions(-) diff --git a/cbios/Makefile b/cbios/Makefile index fafba28..6d01dec 100644 --- a/cbios/Makefile +++ b/cbios/Makefile @@ -7,7 +7,7 @@ SRC += sdio.180 cfio.180 SRC += scb.180 ALLSRC := $(SRC) ldrbios.180 -INC := config.inc z180reg.inc z180.lib +INC := config.inc z180reg.inc z180.lib ioctl.inc OBJ := $(SRC:.180=.rel) diff --git a/cbios/ascii.180 b/cbios/ascii.180 index cb48550..2581bf5 100644 --- a/cbios/ascii.180 +++ b/cbios/ascii.180 @@ -4,19 +4,22 @@ 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 +31,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 +56,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 +73,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 +123,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 +626,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 diff --git a/cbios/bioskrnl.180 b/cbios/bioskrnl.180 index 2a63494..0bb3ecc 100644 --- a/cbios/bioskrnl.180 +++ b/cbios/bioskrnl.180 @@ -44,6 +44,7 @@ ccp equ 0100h ; Console Command Processor gets loaded extrn ?ci,?co,?cist,?cost ; each take device in extrn ?cinit ; (re)initialize device in + extrn ioctl extrn @ctbl ; physical character device table ; disk communication data items @@ -63,7 +64,9 @@ ccp equ 0100h ; Console Command Processor gets loaded extrn ?time ; signal time operation - include modebaud.inc ; define mode bits + extrn ijphl ; vectored call + + maclib modebaud.inc ; define mode bits ; External names for BIOS entry points @@ -119,9 +122,10 @@ ccp equ 0100h ; Console Command Processor gets loaded ?stbnk: jp setbnk ; select different bank for disk I/O DMA operations ?xmov: jp ?xmove ; set source and destination banks for one operation + jp 0 ; reserved for system implementor jp 0 ; reserved for future expansion jp 0 ; reserved for future expansion - jp 0 ; reserved for future expansion +?ioctl jp ioctl ; ; BOOT @@ -167,7 +171,7 @@ d$init$loop: ld (@ADRV),bc ; save absolute and relative drive code ld l,(ix-4) ld h,(ix-3) ; get init pointer - call ipchl ; call init routine + call ijphl ; call init routine pop hl ; recover @drv pointer d$init$next: pop bc ; recover counter and drive # @@ -423,12 +427,6 @@ ci$rdy: ;------------------------------------------------------------------------------- ; Utility Subroutines - -ipchl: ; vectored CALL point - jp (hl) - - - ; BNKSEL ; Bank Select. Select CPU bank for further execution. @@ -480,8 +478,7 @@ seldsk: inc hl ld h,(hl) ld l,a - call ipchl ; call LOGIN -notfirst: + call ijphl ; call LOGIN ld hl,(@xdph) ; recover DPH pointer ret diff --git a/cbios/chario.180 b/cbios/chario.180 index 3451262..c29271d 100644 --- a/cbios/chario.180 +++ b/cbios/chario.180 @@ -4,15 +4,15 @@ - public ?cinit,?ci,?co,?cist,?cost + public ?cinit,ioctl,?ci,?co,?cist,?cost public @ctbl extrn ff_dev extrn as0_dev,as1_dev extrn _b0call - include config.inc - include z180reg.inc + maclib z180reg.inc + maclib config.inc include modebaud.inc ; define mode bits and baud equates @@ -42,7 +42,7 @@ O_COF equ -10 O_COSTF equ -8 O_CIF equ -6 O_CISTF equ -4 -O_INITF equ -2 +O_IOCTLF equ -2 dseg xctbl: @@ -71,14 +71,15 @@ null_dev: cseg ?cinit: ; init devices - b0call _cinit + ld b,c + ld c,0 ; +ioctl: + b0call _ioctl ret dseg -_cinit: - ld b,c - ld hl,O_INITF - ld c,0 ; +_ioctl: + ld hl,O_IOCTLF jr vector_io ;-------------------------------------------------------------- diff --git a/cbios/config.inc b/cbios/config.inc index fe31e57..9034624 100644 --- a/cbios/config.inc +++ b/cbios/config.inc @@ -218,3 +218,49 @@ b0call macro address call _b0call dw address endm + +;----------------------------------------------------- +; shift accu right logical n bits + +srlan macro n + if n > 7 or n < 0 + xor a + exitm + endif + + if n > 4 + rept 8-n + rlca + endm + and (1 << (8-n)) - 1 + exitm + endif + + if n > 2 + rept n + rrca + endm + and (1 << (8-n)) - 1 + exitm + endif + + rept n + srl a + endm + endm + +;----------------------------------------------------- +; convert bit mask to bit number + +m2b macro name,mask + local n + n defl mask + name defl 0 + rept 8 + n defl n/2 + if n = 0 + exitm + endif + name defl name+1 + endm + endm diff --git a/cbios/ioctl.inc b/cbios/ioctl.inc index d3a7b7b..8d1f303 100644 --- a/cbios/ioctl.inc +++ b/cbios/ioctl.inc @@ -26,7 +26,7 @@ TIOCGSOFTCAR equ 11h ;Get the status of the CLOCAL flag in the c_cflag field TIOCSSOFTCAR equ 12h ;Set the CLOCAL flag when *argp is nonzero, and clear it otherwise. -; iflag bits (0) +; iflags bits (0) b2m IGNBRK, 0 ;Ignore BREAK condition on input. b2m BRKINT, 1 b2m INPCK, 2 ;Enable input parity checking. @@ -34,7 +34,7 @@ TIOCSSOFTCAR equ 12h ;Set the CLOCAL flag when *argp is nonzero, and clear it b2m PARMRK, 4 ;Prefix a character with a parity error or framing error with FFH 00H. b2m ISTRIP, 5 ;Strip off eighth bit. b2m PARODD, 6 ;If set, then parity for input and output is odd. -; fflag bits (1) +; fflags bits (1) b2m IXON, 0 ;Enable XON/XOFF flow control on output. b2m IXANY, 1 ;Typing any character will restart stopped output. b2m IXOFF, 2 ;Enable XON/XOFF flow control on input. @@ -44,7 +44,7 @@ TIOCSSOFTCAR equ 12h ;Set the CLOCAL flag when *argp is nonzero, and clear it b2m CREAD, 6 ;Enable receiver. -; control mode flags (2) +; cflags (2) M_CBAUD equ 01Fh ;Baud speed mask B0 equ 000h ;hang up B50 equ 011h @@ -70,8 +70,9 @@ M_CBAUD equ 01Fh ;Baud speed mask B192000 equ 016h B288000 equ 017h M_CSIZE equ 020h ;Character size mask. - CS7 equ 000h ; - CS8 equ 020h ; + M_CS7 equ 000h ; + M_CS8 equ 020h ; + CS8 equ 5 ; b2m CSTOPB, 6 ;Set two stop bits, rather than one. b2m PARENB, 7 ;Enable parity generation on output and parity checking for input. diff --git a/cbios/mm.180 b/cbios/mm.180 index 9f90e03..9df0471 100644 --- a/cbios/mm.180 +++ b/cbios/mm.180 @@ -5,9 +5,15 @@ public mmuinit public bnk2log,bnk2phy,hwl2phy,phy2log public isv_sw + public b_ld_a,b_ld_hl,b_st_a,b_st_hl - include config.inc - include z180reg.inc + + extrn @cbnk + extrn ijphl + + + maclib z180reg.inc + maclib config.inc ;---------------------------------------------------------------------- @@ -353,7 +359,7 @@ isv_sw: ; ld d,(hl) ; ex de,hl ; push bc ; - call jphl ; + call ijphl ; pop bc ; pop hl ; @@ -365,15 +371,122 @@ isv_sw: ; pop hl ; ei ; ret ; -jphl: - jp (hl) ; ds 24 istack: + dseg + +;-------------------------------------------------------------------- +; Load byte/word from user ram +; +; de: src address in users bank +; return +; a: value (byte) +; hl: value (word) + +b_ld_a: + push hl + or a ; clear carry == byte store + jr $+3 +b_ld_hl: + scf ; set carry == word store + push af ; save flag + push hl ; make space on stack + + ld a,(@cbnk) + ld b,a ; b = src bank + + ld hl,0 + ld a,l + ld c,l ; c = dst bank (0) + add hl,sp ; hl = dst + adc a,1 ; a = count + ex de,hl + call dma_move + ex de,hl + pop hl + pop af + ret c + ld a,l + pop hl + ret + +;-------------------------------------------------------------------- +; Store byte/word to user ram +; +; de: dst address in users bank +; a: value (byte) +; hl: value (word) + +b_st_a: + push hl + ld l,a + or a ; clear carry == byte store + jr $+3 +b_st_hl: + scf ; set carry == word store + push af ; save flag + push hl ; put value on stack + + ld a,(@cbnk) ; + ld c,a ; c = dst bank + ld a,0 + ld l,a + ld h,a + ld b,a ; b = src bank (0) + add hl,sp ; hl = src + adc a,1 ; a = count + + call dma_move + + pop hl ; restore value + pop af ; carry + ret c + pop hl + ret + +;-------------------------------------------------------------------- +; +; hl: src +; de: dst +; b: src bank +; c: dst bank +; a: count + +dma_move: + out0 (bcr0l),a ; setup DMA count + xor a + out0 (bcr0h),a + + push hl + ld a,b + call bnk2phy + out0 (sar0l),l ; setup DMA src address + out0 (sar0h),h + out0 (sar0b),a + + ld l,e + ld h,d + ld a,c + call bnk2phy + out0 (dar0l),l ; setup DMA dst address + out0 (dar0h),h + out0 (dar0b),a + + ld a,M_MMOD ; DMA burst mode + out0 (dmode),a + ld a,M_DE0+M_NDWE1 ; enable DMA0 + out0 (dstat),a ; move ... + pop hl + ret + + ;==================================================================== + cseg + if 0 ;-------------------------------------------------------------------- diff --git a/cbios/utils.180 b/cbios/utils.180 index a84d217..1fdb6ca 100644 --- a/cbios/utils.180 +++ b/cbios/utils.180 @@ -1,4 +1,3 @@ -==== BASE ==== title 'general utility routines' ; i/o port init routines @@ -85,12 +84,17 @@ io1_nxt: pop bc ret + + cseg + ;-------------------------------------------------------------------- ; vectored CALL point ijphl: jp (hl) + dseg + ;-------------------------------------------------------------------- ; add a to hl ; -- 2.39.2