
TITLE MUSIC -- A music of 'Mary had a little lamb'
;assemble with:masm music
;link with:link music+gensound
extrn gensound:far
stack segment para stack 'stack'
      db 64 dup('stack...')
stack ends
;--------------------------------------------------
dseg segment para 'data'
mus_freq dw 330,294,262,294,3 dup(330) ;bars 1 & 2
	 dw 3 dup(294),330,392,392     ;bars 3 & 4
	 dw 330,294,262,294,4 dup(330) ;bars 5 & 6
	 dw 294,294,330,294,262,-1     ;bars 7 & 8
mus_time dw 6 dup(25),50	       ;bars 1 & 2
	 dw 2 dup(25,25,50)	       ;bars 3 & 4
	 dw 12 dup(25),100	       ;bars 5 & 8
dseg ends
;--------------------------------------------------
cseg segment para 'code'
	assume cs:cseg, ss:stack, ds:dseg
music proc far
	push    ds            ;put return addr.
	sub     ax,ax	      ;  on stack
	push    ax
	mov     ax,dseg       ;initialize DS
	mov     ds,ax

	lea     si,mus_freq   ;puts the freq table
			      ; offset in SI
	lea	bp,ds:mus_time  ;puts the time table
			        ; offset in BP
freq:	mov	di,[si]	      ;read next frequency
	cmp	di,-1	      ;end of tone ?
	je	end_mus	      ;if so,exit
	mov	bx,ds:[bp]    ;otherwise,fetch the
			      ;   duration
	call	gensound      ;play the note 
	add	si,2	      ;update the table pointer
	add	bp,2
	jmp	freq	      ;go process next note
end_mus:
	ret		      ;return to DOS
music   endp
cseg    ends
;----------------------------------------------------
	end music
 