
TITLE GENSOUND -- The speaker beeper
;Produces a tone of a specified frequency
;  and duration public gensound
public gensound
cseg segment para 'code'
	 assume cs:cseg
gensound proc far
	push	ax	  ;save registers
	push	bx
	push	cx
	push	dx
	push	di
	mov	al,0b6h	  ;write timer mode reg.
	out	43h,al
	mov	dx,12h	  ;timer divisor
	mov	ax,533h*896  ; 533h * 896 / freq
	div	di
	out	42h,al	  ;write timer2 count low byte
	mov	al,ah
	out	42h,al	  ;write timer2 count hight byte
	in	al,61h	  ;get current port setting
	mov	ah,al	  ;and save it in AH
	or	al,3	  ;turn speaker on
	out	61h,al
wait1:	mov	cx,2801	  ;wait for specified interval
delay:	loop	delay
	dec	bx
	jnz	wait1
	mov	al,ah	  ;recover value of port
	out	61h,al
	pop	di	  ;restore the registers
	pop	dx
	pop	cx
	pop	bx
	pop	ax
	ret		  ;exit
gensound endp
cseg	 ends
	 end
