Assembly Language Help (alang.hlp) (
Table of Contents;
Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software,
purely for historical purposes.
If you're looking for up-to-date documentation, particularly for programming,
you should not rely on the information found here, as it will be woefully
out of date.
Sound
◄Map► ◄Up► ◄Contents► ◄Index► ◄Back►
────────────────────────────────────────────────────────────────────────────
;* Sound - Sounds speaker with specified frequency and duration.
;*
;* Shows: Instructions - in out
;*
;* Params: Freq - Desired frequency of sound in Hertz
;* Duration - Desired duration in clocks, where
;* 18 clocks = approx 1 second
;*
;* Return: None
Sound PROC,
Freq:WORD, Duration:WORD
mov al, 0B6h ; Initialize channel 2 of
out 43h, al ; timer chip
mov dx, 12h ; Divide 1,193,182 Hertz
mov ax, 34DEh ; (clock frequency) by
div Freq ; desired frequency
; Result is timer clock count
out 42h, al ; Low byte of count to timer
mov al, ah
out 42h, al ; High byte of count to timer
in al, 61h ; Read value from port 61h
or al, 3 ; Set first two bits
out 61h, al ; Turn speaker on
; Pause, pass duration of delay
INVOKE Pause, Duration
in al, 61h ; Get port value
xor al, 3 ; Kill bits 0-1 to turn
out 61h, al ; speaker off
ret
Sound ENDP
-♦-