> Anybody got something similar stashed away in their archives?
Maybe this will work for you?
Roger
;
; ***************************************
; **** SOFTIM: Z80 SOFTWARE TIMER ****
; **** WRITTEN BY: DAN TERPSTRA ****
; ***** CHEMISTRY DEPARTMENT *****
; ** FLORIDA STATE UNIVERSITY **
; *****************************
;
; The execution time of this routine is given by:
; T = (N+2)*40
; where T is the time in t-states, and N is the 3 byte
; (positive integer) delay quantity obtained from memory
; locations LODELA, HIDELA. To calculate the time in
; seconds, multiply the number of t-states by the time of
; one clock cycle (e.g. 4 MHz = 250 ns/cycle). This
; timing assumes memory that operates with no wait
; states. The minimum time of execution for a 4 MHz Z80
; is 30 usec for N = 1 (including the CALL and RET
; sequence), increasing in steps of 10 usec to a maximum
; of over 160 sec. N = 0 is undefined, and N =
; FFFFFF(HEX) is the maximum time period. There is NO
; software jitter in this timing loop.
;
;
;main:
; ld hl,(lodela) ;low order count word
; ld a,(hidela) ;high order count byte
; call softim ;time it
; ...continue with program...
; ret
;
; SOFTIM SUBROUTINE
;
; entry conditions:
; a, hl = 24 bit positive count
; exit conditions:
; a = b = hl = 0
; modifies:
; a, b, hl
;
softim: inc a ;at least one pass
ld b,a ;through outer loop
ld a,0 ;dummy instructions
jp softm2 ;to kill time
softm1: jr softm2 ;delay 16 T states
softm2: nop
softm3: dec hl ;decrement low order
ld a,l
or h ;hl = 0?
jp nz,softm1 ;no, look again
dec b ;b = zero?
jr nz,softm3 ;no, repeat outer loop
ret ;yes, return
;
; storage locations for 24-bit time delay word
;lodela: ds 2 ;low order 16 bits
;hidela: ds 1 ;high order 8 bits
;