	page	,132
; Z s
;	"Sleep" for s seconds.  If s omitted, take five.
;
cseg	segment	public 'code'
	assume	cs:cseg,ds:cseg

	org	80h
len	db	?		; length
	db	?		; initial space if len>0
param	db	?		; first digit

	org	100h
Z	proc	far
	mov	cl,len
	cmp	cl,0
	jz	until		; parameter omitted; use default
	xor	ax,ax		; ax will be param in binary
	xor	bh,bh
	xor	ch,ch
	dec	cl		; cx = number of digits
	mov	dl,10
	lea	si,param	; point to first digit

next:	mul	dl		; push seen digits left one place
	mov	bl,[si]
	and	bl,0FFh-'0'
	add	ax,bx		; add this digit to running sum
	inc	si		; point to next digit
	loop	next
	mov	wait,ax		; save # secs to zzz

until:	mov	ah,2Ch		; get time
	int	21h		; ch,cl= h,m; dh,dl= s,c
	mov	athm,cx
	mov	ats,dh

	xor	dx,dx		; prepare for divide
	mov	ax,wait
	mov	bl,ats
	add	ax,bx
	mov	cx,60
	div	cx		; ax= mins; dx= secs
	mov	ats,dl

	xor	dx,dx
	mov	bl,atm
	add	ax,bx
	div	cx		; ax= hrs; dx= mins
	mov	atm,dl

	xor	dx,dx
	mov	bl,ath
	add	ax,bx
	mov	cx,24
	div	cx		; ax= days; dx= hrs
	mov	ath,dl		; save hrs; discard days

check:	mov	ah,2Ch		; get time
	int	21h		; ch,cl= h,m; dh,dl= s,c
	cmp	cx,athm
	jne	check
	cmp	dh,ats
	jl	check
	int	20h		; exit

	even
wait	dw	5		; how many seconds to wait
athm	dw	?
	org	$-2
atm	db	?		; minutes
ath	db	?		; hours
atc	db	?		; hundredths
ats	db	?		; seconds
Z	endp
cseg	ends
	end	Z
