Here is the code which emulates the Beep function in VB to make the above program work in Windows 98 as well.
It uses win95io.dll port I/O library from
which is available for download at ftp://ftp.softcircuits.com/tools/win95io.zip
The size of this tiny DLL is only 4KB but it does a great job. Before running this code download and extract this file to Windows\System directory.
___
[tt]
' "Annie's Song"
' by John Denver
'for Windows 95/98/Me.
Option Explicit
Private Declare Sub vbOut Lib "Win95io.dll" (ByVal nPort As Integer, ByVal nData As Integer)
Private Declare Function vbInp Lib "Win95io.dll" (ByVal nPort As Integer) As Integer
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Form_Load()
Dim Note As Long
Dim Frequencies As String, Durations As String
Dim Frequency As Long, Duration As Long
Frequencies = "iiihfihfffhidadddfhihfffhihiiihfihffihfdadddfhihffhiki"
Durations = "aabbbfjaabbbbnaabbbfjaabcapaabbbfjaabbbbnaabbbfjaabcap"
Const E4 = 329.6276
For Note = 1 To Len(Frequencies)
Frequency = E4 * 2 ^ ((Asc(Mid$(Frequencies, Note, 1)) - 96) / 12)
Duration = (Asc(Mid$(Durations, Note, 1)) - 96) * 200 - 10
Beep Frequency, Duration
Sleep 10
DoEvents
Next
Unload Me
End Sub
Sub Beep(Frequency As Long, Duration As Long)
'This procedure emulates the Beep API.
'It uses Win95io.dll for port I/O.
'Ports 66 and 67 control the onboard PIT.
'PIT base address = 40H = 64. (Range: 40H - 43H)
'Address of command register of PIT = 67.
'Address of Timer #2 = 66
'Timer #2 is the last timer of the PIT and is
'internally connected to the PC speaker.
'Port 97 controls the speaker connected to the PPI chip.
'Divide clock frequency by sound frequency to get the
'number of clock pulses the timer must produce.
'The timer is clocked by a frequency of 1193180 Hz derived
'from the crystal.
Dim Pulses As Long, LoByte As Integer, HiByte As Integer
Pulses = 1193180 / Frequency
'Split this value in two bytes (hi and lo).
'These bytes will be sent one-by-one to the PIT.
LoByte = Pulses Mod 256
HiByte = Pulses \ 256
'Now program the timer 2 in mode 3. (Square wave generator)
'The Command Word is determined as follows.
' 1 0 | 1 1 | 0 1 1 | 0
'Timer #2 | Lo-byte then Hi-byte serially | Mode 3(Square Wave gen.) | Binary data
'Thus the command word is 10110110b = B6h = 182.
'Send this command word to PIT command
'register located at address #67.
vbOut 67, &HB6 'B6h = 10110110b
'Now send count to the timer #2 by sending
'the lo and hi bytes to the timer serially.
vbOut 66, LoByte 'Send LoByte.
vbOut 66, HiByte 'Send HiByte.
'At this moment the timer has started sending square wave
'pulses at the required audio frequency to the PPI chip.
'Now turn on the speaker by setting the bits 0 and 1 of PPI chip.
'Port Address = 97. (61h)
Dim X As Integer
X = vbInp(97) 'Read byte value from the PPI.
X = X Or &H3 'Set the lower 2 bits.
vbOut 97, X 'Send the modified byte.
'wait for the required duration.
Sleep Duration
'Now turn the speaker off by masking the lower 2 bits.
X = vbInp(97) 'Read byte value from the PPI.
X = X And &HFC 'Mask the lower 2 bits. (&HFC= 11111100B)
vbOut 97, X 'Send the modified byte.
End Sub[/tt]