	page	,132
	title	Batch file Beep

;------------------------------------------------------------------------
;
;  Beep      -	Bill Gibson - 1987
;		Lathrup Village, Mi 48076
;
;   Ver. 1.01 -  sound using ASCII character 7		    -	02/26/87
;	 1.02 -  using the 8253 timer chip directly	    -	02/26/87
;	 1.03 -  now a siren (a mod of v1.02)		    -	02/28/87
; *	 1.04 -  another siren (mod of v1.03)		    -	02/28/87
;
;  For Public Domain Use.  Not for Sale or Hire.
;------------------------------------------------------------------------
COMMENT *
	   As requested by Viggo Jensen.

   Beep utility - sounds alarm until any key is pressed.

		  Obviously, best use of this small utility is at
		  the end of a batch file.  Could be used to replace
		  the DOS "pause" command.
*
;------------------------------------------------------------------------
code		SEGMENT BYTE PUBLIC 'code'
ASSUME		CS:code,DS:code,SS:code

		ORG	100h

Beep		PROC	FAR

start:
		MOV	DX,OFFSET msg1	;intro greeting
		MOV	AH,9
		INT	21h
noise:
		CALL	Sound_Up	;sound the horn - up scale
		CALL	Sound_Down	;		- down scale
exit:
		MOV	AH,4Ch
		INT	21h

;------------------------------------------------------------------------
; Work Area - constants,equates,messages
;------------------------------------------------------------------------
cr		EQU	0Dh		;carriage return
lf		EQU	0Ah		;line feed
esc		EQU	01Bh		;escape char

msg1		DB	cr,lf,'Beeping - press any key to quit...','$'

;--------------------------------------------------------------------------
; Sub-Routines: Declare each Proc PUBLIC for use with MapSym & SymDeb v4.0
;--------------------------------------------------------------------------
		PUBLIC	Sound_Up
Sound_Up	PROC	NEAR
s1:
		MOV	BX,0800h	;set 1/pitch - lowest possible tone
		MOV	AL,0B6h 	;"switch" to
		OUT	43h,AL		;initalize the speaker timer
s2:
		MOV	AX,BX		;OUT instruction can only handle the
		OUT	42h,AL		;least significant byte (LSB) from
		MOV	AL,AH		;the AX register  (AL)
		OUT	42h,AL
		IN	AL,61h		;grab speaker port
		OR	AL,3		;turn on speaker
		OUT	61h,AL
		DEC	BX		;increase the pitch
		CMP	BX,0350h	;predefined upper tone limit
		JZ	sdown		;change to whatever suits you
sinput:
		PUSH	AX
		PUSH	BX
		MOV	AH,0Bh		;check standard input device
		INT	21h
		OR	AL,AL		;any character waiting ?
		POP	BX
		POP	AX
		JZ	s2		;go do new tone
soff:
		CALL	Sound_Off
sdown:
		RET
Sound_Up	ENDP

;--------------
		PUBLIC	Sound_Down
Sound_Down	PROC	NEAR
d1:
		MOV	BX,0300h	;set 1/pitch - highest possible tone
		MOV	AL,0B6h 	;"switch" to
		OUT	43h,AL		;initalize the speaker timer
d2:
		MOV	AX,BX		;OUT instruction can only handle the
		OUT	42h,AL		;least significant byte (LSB) from
		MOV	AL,AH		;the AX register  (AL)
		OUT	42h,AL
		IN	AL,61h		;grab speaker port
		OR	AL,3		;turn on speaker
		OUT	61h,AL
		INC	BX		;decrease the pitch
		CMP	BX,0700h	;predefined lower tone limit
		JZ	ddown
dinput:
		PUSH	AX
		PUSH	BX
		MOV	AH,0Bh		;check standard input device
		INT	21h
		OR	AL,AL		;any character waiting ?
		POP	BX
		POP	AX
		JZ	d2		;go do new tone
doff:
		CALL	Sound_Off
ddown:
		JMP	noise		;start this cycle all over
Sound_Down	ENDP

;--------------
		PUBLIC	Sound_Off
Sound_Off	PROC	NEAR
		IN	AL,61h		;grab speaker port
		XOR	AL,3		;turn off speaker
		OUT	61h,AL
		JMP	Exit
Sound_Off	ENDP

;--------------

Beep		ENDP
code		ENDS
		END	Beep
