From 40df51aed30ddcd710c7356f8098516c27088392 Mon Sep 17 00:00:00 2001 From: Leo C Date: Fri, 5 Jun 2015 08:49:18 +0200 Subject: [PATCH] change message buffer initialization. cleanup --- cbios/bioskrnl.180 | 16 +----- cbios/boot.180 | 58 ++++++++------------ cbios/conbuf.180 | 129 +++++++++++++++++---------------------------- cbios/misc.180 | 97 +++++++++++----------------------- cbios/mm.180 | 27 ++++++++-- cbios/msgbuf.180 | 30 ++++++++--- cbios/utils.180 | 2 +- 7 files changed, 147 insertions(+), 212 deletions(-) diff --git a/cbios/bioskrnl.180 b/cbios/bioskrnl.180 index f2cfde8..04f4159 100644 --- a/cbios/bioskrnl.180 +++ b/cbios/bioskrnl.180 @@ -156,27 +156,13 @@ d$init$loop: or d jr z,d$init$next ; if null, no drive push hl ; save @drv pointer - if 0 - ex de,hl ; XDPH address in - dec hl - dec hl - ld b,(hl) ; get relative drive code - ld (@ADRV),bc ; save absolute and relative drive code - dec hl ; point to init pointer - ld d,(hl) - dec hl - ld e,(hl) ; get init pointer - ex de,hl - call ipchl ; call init routine - else push de - pop ix + pop ix ; XDPH address in ld b,(ix-2) 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 - endif pop hl ; recover @drv pointer d$init$next: pop bc ; recover counter and drive # diff --git a/cbios/boot.180 b/cbios/boot.180 index 5256539..c0ecc11 100644 --- a/cbios/boot.180 +++ b/cbios/boot.180 @@ -17,10 +17,18 @@ include z180reg.inc -bdos equ 5 - ccpsize equ 0c80h + ; CP/M BDOS Function Interfaces + +resetdsk equ 13 +open equ 15 +read equ 20 +setdma equ 26 +setmulti equ 44 +bdos equ 5 + + if banked tpa$bank equ 1 else @@ -89,21 +97,26 @@ hwini_skip: ?ldccp: ; First time, load the A:CCP.COM file into TPA - call resetdsk + ld c,resetdsk + call bdos xor a ld (ccp$fcb+15),a ; zero extent ld hl,0 ld (fcb$nr),hl ; start at beginning of file ld de,ccp$fcb - call open ; open file containing CCP + ld c,open ; open file containing CCP + call bdos inc a jp z,no$ccp ; error if no file... ld de,0100h - call setdma ; start of TPA + ld c,setdma ; start of TPA + call bdos ld de,128 - call setmulti ; allow up to 16k bytes + ld c,setmulti ; allow up to 16k bytes + call bdos ld de,ccp$fcb - call read ; load the thing + ld c,read ; load the thing + call bdos ; read records ; now, ; copy CCP to bank 0 for reloading ld hl,0100h @@ -119,11 +132,8 @@ ld$1: call ?bnksl ; select extra bank pop af ld (hl),a ; save the byte - inc hl - dec bc ; bump pointer, drop count - ld a,b - or c ; test for done - jp nz,ld$1 + cpi ; bump pointer, drop count + jp pe,ld$1 pop af call ?bnksl ; restore original bank ret @@ -153,30 +163,6 @@ rl$1: ret - ; CP/M BDOS Function Interfaces - -resetdsk: - ld c,13 - jp bdos ; reset disk system - -open: - ld c,15 - jp bdos ; open file control block - -setdma: - ld c,26 - jp bdos ; set data transfer address - -setmulti: - ld c,44 - jp bdos ; set record count - -read: - ld c,20 - jp bdos ; read records - - - ccp$fcb:db 1,'CCP ','COM',0,0,0,0 ds 16 fcb$nr: db 0,0,0 diff --git a/cbios/conbuf.180 b/cbios/conbuf.180 index 7275643..64d42dc 100644 --- a/cbios/conbuf.180 +++ b/cbios/conbuf.180 @@ -17,8 +17,8 @@ mkbuf ci.fifo_id, ci.fifo, ci.fifo_len mkbuf co.fifo_id, co.fifo, co.fifo_len -ici equ ci.fifo_id * 3 -ico equ co.fifo_id * 3 +ici equ ci.fifo_id * 2 +ico equ co.fifo_id * 2 ;-------------------------------------------------------------- @@ -37,6 +37,8 @@ ff.init: jp bufinit ;-------------------------------------------------------------- +; Input status +; buffer is empty, if output index and input index are the same cseg ff.ist: @@ -52,41 +54,40 @@ buf.empty: ret +;-------------------------------------------------------------- +; Output status +; buffer is full, if output index is one behind input index + ff.in: push ix ld ix,(fifolst+ici) ; buf.get: - ld a,(ix+o.out_idx) ; + push ix + pop hl + ld c,(ix+o.out_idx) ; + ld b,0 + add hl,bc + ld a,c bg.wait: cp (ix+o.in_idx) ; jr z,bg.wait - - push hl ; - push ix - pop hl - add a,l - ld l,a - jr nc,bg.nc - inc h -bg.nc: - ld l,(hl) - - ld a,(ix+o.out_idx) ; + ld b,(hl) + ld a,c ; inc a and (ix+o.mask) ld (ix+o.out_idx),a - - ld a,l - pop hl + ld a,b pop ix ret ;-------------------------------------------------------------- +; Output status +; buffer is full, if output index is one behind input index ff.ost: push ix - ld ix,(fifolst+ico) ; + ld ix,(fifolst+ico) ; buf.full: ld a,(ix+o.in_idx) ; @@ -99,70 +100,36 @@ buf.full: ret - if 1 -ff.out: - push ix ;15 - ld ix,(fifolst+ico) ; - -buf.put: - push hl ;11 - push bc ;11 - push ix ;15 - pop hl ;10 - ld a,c ;4 - ld c,(ix+o.in_idx) ;19 - ld b,0 ;7 - add hl,bc ;11 - ld (hl),a ;7 - ld b,a ;4 - - ld a,c ;4 - inc a ;4 - and (ix+o.mask) ;19 -bp.wait: - cp (ix+o.out_idx) ;19 - jr z,bp.wait ;12/7 - ld (ix+o.in_idx),a ;19 - - out (AVRINT6),a ;11 - ld a,b ;4 - pop bc ;10 - pop hl ;10 - pop ix ;14 - ret ;10 - - else +;-------------------------------------------------------------- +; put character in c in buffer +; destroys hl, bc +; returns output char in a ff.out: - push ix ;15 - ld ix,co.fifo ;14 - + push ix ; + ld ix,(fifolst+ico) ; buf.put: - push hl ;11 - push ix ;15 - pop hl ;10 - ld a,(ix+o.in_idx) ;19 - add a,l ;4 - ld l,a ;4 - jr nc,bp.1 ;12/7 - inc l ;4 - ld (hl),c ;7 - ld a,(ix+o.in_idx) ;19 - inc a ;4 - and (ix+o.mask) ;19 -bp.wait: - cp (ix+o.out_idx) ;19 - jr z,bp.wait ;12/7 - ld (ix+o.in_idx),a ;19 - - out (AVRINT6),a ;11 - ld a,c ;4 - pop hl ;10 - pop ix ;14 - ret ;10 | - - endif - -;-------------------------------------------------------------- + push ix ; + pop hl ; get buffer start address + + ld a,c ; + ld c,(ix+o.in_idx) ; add input index + ld b,0 ; + add hl,bc ; + ld (hl),a ; one place is allways free + ld b,a ; + + ld a,c ; bump input index + inc a ; + and (ix+o.mask) ; +bp.wait: ; do + cp (ix+o.out_idx) ; + jr z,bp.wait ; while new input idx == ouput idx + ld (ix+o.in_idx),a ; + + out (AVRINT6),a ; tell monitor + ld a,b ; + pop ix ; + ret ; end diff --git a/cbios/misc.180 b/cbios/misc.180 index b3e486d..ccb608e 100644 --- a/cbios/misc.180 +++ b/cbios/misc.180 @@ -1,9 +1,10 @@ - global intinit - global bufinit - global cpu_frq + public intinit + public bufinit + public cpu_frq + public get_tmr - global fifolst + public fifolst extrn div32_r,?pmsg extrn msg.sm,msg.recv,hwl2phy @@ -94,7 +95,7 @@ cpu_frq: ld hl,0 ld d,h ld e,l - call get_timer + call get_tmr push de push hl @@ -112,7 +113,7 @@ dly_lp: pop hl pop de - call get_timer + call get_tmr ld b,h ld c,l @@ -132,10 +133,11 @@ cpuf_done: ;-------------------------------------------------------------------- -get_timer: + dseg +get_tmr: push de push hl - ld hl,1*256 + 3 ; d = subcommand, e = command + ld hl,1*256 + 3 ; h = subcommand, l = command push hl ld hl,0 add hl,sp @@ -161,7 +163,6 @@ get_timer: fifolst: rept 4 dw 0 - db 0 endm ;-------------------------------------------------------------------- @@ -169,85 +170,47 @@ fifolst: dseg bufinit: + ld (ix+o.in_idx),0 ;reset pointers (empty fifo) + ld (ix+o.out_idx),0 ld a,(ix+o.id) - cp 4 - jr nc,bfi_doit2 - ld hl,fifolst ld e,a ld d,0 add hl,de add hl,de - add hl,de - - if 0 - ld e,(hl) - inc hl - ld d,(hl) - dec hl - ld a,e - or d - jr z,bfi_doit - -; TODO: address translation - push de - pop ix - ret - endif - -bfi_doit: push ix pop de -; TODO: address translation + cp 4 + jr nc,bfi_skip + ld (hl),e inc hl ld (hl),d - ld a,(ix+o.id) - or a - jr nz,bfi_doit2 - ld hl,fifolst - ld (040h),hl - ld (040h+2),a - -bfi_doit2: - ld (ix+o.in_idx),0 ;reset pointers - ld (ix+o.out_idx),0 - - push ix ;get phys. address of fifo - pop hl - call hwl2phy +bfi_skip: ex de,hl + call hwl2phy ;get phys. address of fifo ld c,a ld a,(ix+o.id) ;fifo id or a ;test if fifo 0 - jr nz,bfi_1 - - out (AVRINT5),a - ret + ret z bfi_1: - ld hl,bfi_msg_end - ld (hl),c - dec hl - ld (hl),d - dec hl - ld (hl),e - dec hl - ld (hl),a - dec hl - ld b,bfi_msg_len + ld b,a + push bc ;c: bank-addr, b: ignored + push hl ;address + ld c,0 + push bc ;c: function, b:subf + ld b,5 + ld h,c + ld l,c + add hl,sp call msg.sm + pop hl + pop hl + pop hl ret -bfi_msg: - db 0 ;function: 0 - db 0 ;subfunc: gets overwritten with buf id - dw 0 ;physical - db 0 ; address -bfi_msg_len equ $ - bfi_msg -bfi_msg_end equ $ - 1 - ;---------------------------------------------------------------------- diff --git a/cbios/mm.180 b/cbios/mm.180 index eb4135b..9d1e256 100644 --- a/cbios/mm.180 +++ b/cbios/mm.180 @@ -148,10 +148,26 @@ hl2p_x: public _b0call _b0call: + push af + in0 a,(bbr) + jr nz,b0c_doit + pop af + ex (sp),hl ;16 + push de + ld e,(hl) + inc hl + ld d,(hl) + inc hl + ld (b0c_fast_go),de + pop de + ex (sp),hl ;16 +b0c_fast_go equ $+1 + jp 0 + +b0c_doit: ld (b0_save_hl),hl ld (b0_save_de),de - push af pop hl ld (b0_save_af),hl @@ -181,12 +197,13 @@ _b0call: ld sp,bs$stack ; push hl ;save user stack pointer - in0 h,(cbar) ; + + in0 h,(bbr) ; push hl ; ld hl,b0c_ret push hl - ld a,SYS$CBAR ; - out0 (cbar),a ; + xor a + out0 (bbr),a ; ex de,hl ;ptr ld e,(hl) ;get 'function address' inc hl ; @@ -203,7 +220,7 @@ b0c_ret: ld (b0_save_hl),hl pop hl ; - out0 (cbar),h ; + out0 (bbr),h ; pop hl ; ld sp,hl ; ld hl,(b0_save_hl) diff --git a/cbios/msgbuf.180 b/cbios/msgbuf.180 index a5dfa49..12d4861 100644 --- a/cbios/msgbuf.180 +++ b/cbios/msgbuf.180 @@ -7,7 +7,7 @@ ; global msg.sout global msg.sm,msg.recv - extrn bufinit + extrn bufinit,hwl2phy extrn fifolst include config.inc @@ -20,15 +20,15 @@ mkbuf 0,mtx.fifo,mtx.fifo_len mkbuf 1,mrx.fifo,mrx.fifo_len -;txfifo_addr equ fifolst + (0*3) -;rxfifo_addr equ fifolst + (1*3) +;txfifo_addr equ fifolst + (0*2) +;rxfifo_addr equ fifolst + (1*2) -itx equ 0*3 -irx equ 1*3 +itx equ 0*2 +irx equ 1*2 ;-------------------------------------------------------------- ; -; Init mssage fifos +; Init message fifos ; dseg @@ -38,18 +38,34 @@ msginit: jr nz,msgi_1 ld hl,(040h) +;TODO: physical to logical address translation ld a,l or h jr z,msgi_1 ld de,fifolst - ld bc,4*3 + ld bc,4*2 ldir ret msgi_1: + ld a,(043h) +;TODO: value should be 0 ld ix,mtx.fifo call bufinit + + ld hl,fifolst + call hwl2phy + ld (040h),hl + ld (040h+2),a + ld a,0ffh + ld (043h),a + out (AVRINT5),a +wait: + ld a,(043h) + or a + jr nz,wait + ld ix,mrx.fifo jp bufinit diff --git a/cbios/utils.180 b/cbios/utils.180 index f682d44..8157aba 100644 --- a/cbios/utils.180 +++ b/cbios/utils.180 @@ -112,7 +112,7 @@ div32_r: add hl,bc ;low x + y/2 pop bc jr nc,div_r1 - inc hl + inc de div_r1: ;fall thru -- 2.39.2