< -->

;musunt.asm - модуль к программе mymusic.exe
;Необходим для создания программок, проигрывающих музыку
;Не работает без включения в состав программы
.model tiny
.code
org 100h
.186
start:
	mov	ax, 351Ch
	int	21h
	mov	word ptr oldint1ch, bx
	mov	word ptr oldint1ch+2, es

	mov	dx, offset mushandler
	mov	ax, 251Ch
	int	21h

waithandler:
	xor	ah, ah
	int	16h
	cmp	al, 1Bh
	je	ifkeypressed
	cmp	word ptr flag, 1
	je	waithandler
comment #
	mov	cx, word ptr curtimecount
	test	cx, cx
	jnz	nonechanges

	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:
#

ifkeypressed:
	lds	dx, oldint1ch
	mov	ax, 251Ch
	int	21h
	call	nosound
	ret

mushandler	proc	near

	pushf
	pusha

	dec	cs:word ptr curtimecount

	popa
	popf
	iret

mushandler	endp

sound	proc	near
;dx = 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

oldint1ch	dd	?
curtimecount	dw	0
muslength	dw	0	;len

musdata:
end start

Назад