home *** CD-ROM | disk | FTP | other *** search
- page 58,132
- ;
- ; sound.asm
- ; contains: gsound()
- ;
- ;
- include model.h
- include prologue.h
- name sound
- pseg sound
-
- ;==>-- void gsound(frequency,duration)
- ;
- ;; ARGUMENTS:
- ; (int) freq - Frequency in Hertz
- ; (int) duration - Duration in 1/18.2 sec. intervals
- ;
- ;; DESCRIPTION:
- ; Generates sound, equivalent to SOUND command in basic.
- ; sound(440,9) = Middle C, for about 1/2 second.
- ;
- ;; AUTHOR:
- ; Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
- ;
- ; MODIFICATIONS:
- ; "" Wed 11-Jan-1989 10:53:53
- ; Renamed from sound()
- ;;;
- bios_loc equ 40h
-
- cproc gsound
- push ds
- mov cx,@ab[bp] ;get freq
- cmp cx,0 ;if zero,
- je snd1 ;just delay in here..
- mov dx,12h
- mov ax,34dch
- div cx ;calculate freq parameter
- push ax
- call spkron
- pop ax
- snd1: mov cx,@ab+2[bp] ;get duration
- cmp cx,0 ;if 0, turn off spkr
- je snd3 ;and exit.
- mov ax,bios_loc ;segment for timer location
- mov ds,ax
- mov si,06ch ;offset
- mov ax,[si] ;get timer tic to start
- snd2: cmp ax,[si] ;wait til timer increments
- je snd2
- inc ax
- loop snd2 ;loop for CX ticks of timer
- snd3: push cx ;counter = 0 either from countdown of
- ;snd2 loop or parameter
- in al,61h ;8255 port B
- and al,11111100b ;turn off speaker
- out 61h,al
- pop cx
- sndx: pop ds
- cproce
-
-
- ;==>-- void spkron(divisor)
- ; unsigned divisor; data to put in the timer.
- ;
- ; This function is only called from sound()
- ;
- spkron proc near
- push bp
- mov bp,sp
- mov al,10110110b
- out 43h,al
- mov ax,[bp+4]
- cmp ax,0 ; if zero, just exit
- jz spkronx
- out 42h,al ; else output low order part to port
- jmp short fpf0 ; to satisfy the AT circuitry
- fpf0: xchg ah,al
- out 42h,al ; hi order part
- jmp short fpf1 ; to satisfy the AT circuitry
- fpf1: nop
- in al,61h ; get current port data
- jmp short fpf2 ; to satisfy the AT circuitry
- fpf2: or al,3 ; turn on 2 lo order bits for speaker
- out 61h,al ; under control of timer port.
- spkronx:
- pop bp
- ret
- spkron endp
- endps
- end
-