X-Git-Url: http://cloudbase.mooo.com/gitweb/z180-stamp-cpm3.git/blobdiff_plain/ea5293bb6ce484bf1ec9ab70befe10c3a36a70c2..3ba537752998f2d8554cecee5d586fd1a70256b6:/cbios/misc.180 diff --git a/cbios/misc.180 b/cbios/misc.180 index 6e6e3ff..d39f632 100644 --- a/cbios/misc.180 +++ b/cbios/misc.180 @@ -1,91 +1,17 @@ - global add_hla - global ioiniml,ioini1l - global intinit - global bufinit + public intinit + public bufinit + public cpu_frq + public get_tmr - global fifolst + public fifolst - extrn ?pmsg - extrn msg.sm,hwl2phy + extrn div32_r,?pmsg + extrn msg.sm,msg.recv,hwl2phy include config.inc include z180reg.inc -;-------------------------------------------------------------- -; -; add a to hl -; -; return: -; hl = hl + a -; Flags undefined - - cseg ; (common. TODO: check for banked) - -add_hla: - add a,l - ld l,a - ret nc - inc h - ret - -;---------------------------------------------------------------------- - - ; output bytes to consecutive portaddresses - ; - ; hl: table with following structure: - ; db n, port1, val1, val2,... valn - ; db m, port1, val1, val2,... valm - ; ... - ; db 0 ; Terminate table - - - cseg ; (common for now) - -ioiniml: - push bc - xor a -ioml_lp: - ld b,(hl) - inc hl - cp b - jr z,ioml_e - - ld c,(hl) - inc hl - otimr - jr ioml_lp -ioml_e: - pop bc - ret - -;---------------------------------------------------------------------- - - ; output bytes to ports - ; - ; hl: tables of port,value pairs: - ; db n, port1,val1, port2,val2,... portn,valn - ; ... - ; db 0 ; Terminate table - - cseg ; (common for now) - -ioini1l: - push bc - jr io1_nxt -io1_lp: - ld c,(hl) ;port address - inc hl - otim - jr nz,io1_lp -io1_nxt: - ld b,(hl) ;count - inc hl - inc b - djnz io1_lp - - pop bc - ret ;---------------------------------------------------------------------- @@ -155,15 +81,88 @@ spi$msg: spi$nr: db '0' db 0 +;-------------------------------------------------------------------- +; +; Get/compute CPU clock +; +; return: +; hlde: CPU frequency (Hz) +; + + dseg + +cpu_frq: + ld hl,0 + ld d,h + ld e,l + call get_tmr + push de + push hl + +; delay ~8ms @ 18.432MHz --> 147456 clock cycles +; delay ~10ms @ 18.432MHz --> 184320 clock cycles +; + +; ld hl,8192 ; 147456/18 + ld hl,(10240-100)*5 ; 184320/18 + ld de,1 + or a +dly_lp: + sbc hl,de ; 10 + jr nz,dly_lp ; 6/8 -> 18 cycles + + pop hl + pop de + call get_tmr + + ld b,h + ld c,l + ld de,036EEh ;18432000/(2**16) * 50 + ld hl,08000h ;18432000%(2**16) * 50 + + ld a,b + or a + jr nz,cpuf_div + ld a,c + cp 2 + jr c,cpuf_done +cpuf_div: + call div32_r +cpuf_done: + ret + +;-------------------------------------------------------------------- + + dseg +get_tmr: + push de + push hl + ld hl,1*256 + 3 ; h = subcommand, l = command + push hl + ld hl,0 + add hl,sp + ld b,6 + call msg.sm + + dec sp + ld hl,0 + add hl,sp + ld b,7 ; max receive message len + call msg.recv + + pop bc + inc sp + pop hl + pop de + ret ;-------------------------------------------------------------------- - cseg + dseg fifolst: rept 4 dw 0 - db 0 endm ;-------------------------------------------------------------------- @@ -171,85 +170,46 @@ fifolst: dseg bufinit: - ld c,a + 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 - - 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 - -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 - ld (ix+o.mask),c ;reset "size" - 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 - -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 + ret z + + 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 - ;----------------------------------------------------------------------