'===========================================================================
' Subject: PC SPEAKER FREQUENCY               Date: Unknown Date           
'  Author: James Vahn                         Code: QB, QBasic, PDS        
'  Origin: FidoNet QUIK_BAS Echo            Packet: SOUND.ABC
'===========================================================================
'This shows how to make specific frequencies through the PC
'speaker.  How high a note can you hear?  :-)
 
'Speaker.bas - James Vahn 1:30854/20@fidonet
'Shows the use of PC hardware to generate sound.
'
        Old = INP(&H61)     ' 8255 PPI chip. Save the original.
        OUT &H43, 182       ' 8253 Timer chip. 10110110b Channel 2, mode 3
        Port = INP(&H61)    ' get the 8255 port contents.
        OUT &H61, Port OR 3 ' enable the speaker and use channel 2.
 
INPUT "Desired Frequency in Hz"; Hz
Divisor = 1193180 / Hz
LSB = Divisor MOD 256
MSB = Divisor \ 256
 
OUT &H42, LSB
OUT &H42, MSB
 
PRINT "Press any to stop"
WHILE INKEY$ = "": WEND
OUT &H61, Old  ' turn it off.
