< -->

;musunit.asm - модуль к программе mymusic.exe
;Необходим для создания программок, проигрывающих музыку
;Не работает без включения в состав программы
.model tiny
.code
org 100h
.186
start:

waithandler:
	call	mushandler
	mov	ah, 86h
	xor	cx, cx
	mov	dx, 02260h
	int	15h
	mov	ah, 1
	int	16h
	jnz	ifkeypressed
	cmp	word ptr flag, 1
	je	waithandler

ifkeypressed:
	call	nosound
	ret

mushandler	proc	near

	mov	cx, word ptr curtimecount
	test	cx, cx
	jnz	nonechanges

	call	nosound

	mov	word ptr bx, muslength
	test	bx, bx
	jnz	nextnota

	mov	word ptr flag, 0
	jmp	short	nonechanges

nextnota:
	dec	bx
	mov	word ptr muslength, bx
	shl	bx, 2
	mov	cx, word ptr musdata[bx]
	mov	bx, word ptr musdata[bx+2]
	test	cx, cx
	jz	movnret
	test	bx, bx
	jnz	makemus
	call	nosound
makemus:
	call	sound

nonechanges:
	dec	cx
movnret:
	mov	word ptr curtimecount, cx
	ret
mushandler	endp

sound	proc	near
;bx = frq

	mov	ax, 34DDh
	mov	dx, 12h
	cmp	dx, bx
	jnb	exitsound
	div	bx
	mov	bx, ax
	in	al, 61h
	test	al, 3
	jnz	makesound
	or	al, 3
	out	61h, al
	mov	al, 0B6h
	out	43h, al
makesound:
	mov	al, bl
	out	42h, al
	mov	al, bh
	out	42h, al
exitsound:
	ret
sound	endp

nosound	proc	near
	in	al, 61h
	and	al, 0FCh
	out	61h, al
	ret
nosound	endp

flag		dw	1
curtimecount	dw	0
muslength	dw	0	;len

musdata:
end start

Назад