.model tiny
.stack 10h

.code
jmp start

include tone.inc
DACQ	db	'DACQuarter 2.0 by NullSoft',10,13,'$'
DACHIT	db	'Hit any key for a quarter or ESC to exit...',10,13,'$'
THANKS	db	'Thanks for using DACQuarter 2.0!',10,13,'$'
OldInt	dw      0, 0
Playing	db      0
int_count dw	0
pMemory	dw      0
pMemoryEnd dw   0

NewInt proc far
	push	ax
	push	bx
	push	dx
        push    ds
        cli
        mov     dx, @code
        mov     ds, dx
	mov	dx,888
	cmp	Playing,0
	je	short @NotPlaying
	mov	bx, pMemory
	mov	al, byte ptr [bx]
	inc	pMemory
	cmp	bx, pMemoryEnd
	jl	short @StillPlaying
	mov	Playing, 0
@StillPlaying:
	jmp	short @OutByte
@NotPlaying:
	mov	al,128
@OutByte:
	out	dx,al
        sti
	mov	ax, int_count
	inc	int_count
	cmp	ax, 1221
	jne	short @NoOldHandler
	mov	int_count,0
	pushf	
	call	dword ptr OldInt
	jmp	short @IntDone
@NoOldHandler:
 	mov	 al, 20h
 	out	 20h, al
@IntDone:
        pop     ds
	pop	dx
	pop	bx
	pop	ax
	iret	
NewInt  endp

start:
        mov     dx, @code
        mov     ds, dx
        mov     ah, 09h
        mov     dx, offset DACQ
        int     21h
        mov     dx, offset DACHIT
        int     21h
         ;************** REV CLOCK BEGIN
        sub     ax, ax
        mov     ax, 3508h
        int     21h
	mov	word ptr OldInt+2,es
	mov	word ptr OldInt,bx
        mov     ax, 2508h
        mov     dx, offset NewInt 
        int     21h
	cli	
	mov     al, 36h
	out     043h, al
	mov     al, 54
	out     40h, al
	sub     ax, ax
	out     40h, al
	sti
         ;*************** REV CLOCK END
@While:
        mov     ah, 7
        int     21h
        cmp     al, 27
        je      short @EndLoop
	cmp     Playing, 0
	jne     short @While
        mov     bx, offset Quarter_Voc
	mov     pMemory, bx
        add     bx, 6548
        mov     pMemoryEnd, bx
	inc	Playing
        jmp     @While
@EndLoop:
         ; ************ Fix Clock Begin
	cli	
	mov	al, 36h
	out	43h, al
        sub     ax, ax
	out	40h, al
	out	40h, al
	sti
        push    ds
        mov     ax, 2508h
        mov     cx, word ptr OldInt+2 
        mov     dx, word ptr OldInt
        mov     ds, cx
        int     21h
        pop     ds

         ; ************ Fix Clock End
        mov     ah, 9
        mov     dx, offset THANKS
        int     21h
        mov     ax, 4C00h
        int     21h
	end
