
;--------------------------------------------------
dseg	segment
	count	dw   0
	sec	dw   0
	min	dw   0
	hours	dw   0
dseg	ends
;--------------------------------------------------
cseg	segment
main 	proc	far
	assume	cs:cseg, ds:dseg, es:dseg
start:	push	ds
	sub	ax,ax
	push	ax
	mov	ax,dseg
	mov	ds,ax

	mov	al,1ch		;save old interrupt
	mov	ah,35h		;  vector in stack
	int	21h
	push	es
	push	bx

	push	ds
	mov	dx,offset clint	;set new interrupt
	mov	ax,seg clint	;  vector
	mov	ds,ax
	mov	al,1ch
	mov	ah,25h
	int	21h
	pop	ds

	in	al,21h
	and	al,0feh
	out	21h,al	   ;set interrupt mask bit
	sti

	mov	cx,10000  	;main program
mainp:	mov	ax,1000
again:	dec	ax
	jne	again
	loop	mainp

	pop	dx
	pop	ds
	mov	al,1ch		;restore old
	mov	ah,25h		;  interrupt
	int	21h		;   vector
	ret
main	endp
;--------------------------------------------------
clint	proc   near
	push	ds
	push	bx
	mov 	bx,seg count
	mov	ds,bx
	lea	bx,count
	inc	word ptr [bx]
	cmp	word ptr [bx],18
	jne	exit
	call	inctest
adj:	cmp	hours,12
	jle	timeok
	sub	hours,12
timeok:	mov	ax,sec
	and	ax,0007
	cmp	ax,5
	jne	exit
	mov	dl,07h		;the bell ring
	mov	ah,2
	int	21h
exit:	mov	al,20h
	out	20h,al
	pop	bx
	pop	ds
	iret			;interrupt return
clint	endp
;--------------------------------------------------
inctest	proc near
	mov	word ptr [bx],0
	add	bx,2
	inc	word ptr [bx]
	cmp	word ptr [bx],60
	jne	return
	call	inctest		;adjust time
return:	ret
inctest	endp
;--------------------------------------------------
cseg	ends
	end	start
