以前帮朋友在网上找到的:<br>(只是部分代码)<br><br>{---------------------------------_GetPort--------------------------------------}<br>function _GetPort(address:word):word;<br>var<br> bValue: byte;<br>begin<br> asm<br> mov dx, address<br> in al, dx<br> mov bValue, al<br> end;<br> Result := bValue;<br>end; { _GetPort }<br><br><br>{----------------------------------_SetPort--------------------------------------}<br>procedure _SetPort(address, Value:Word);<br>var<br> bValue: byte;<br>begin<br> bValue := Trunc(Value and 255);<br> asm<br> mov dx, address<br> mov al, bValue<br> out dx, al<br> end;<br>end; { _SetPort }<br><br><br>{----------------------------------StartBeep--------------------------------------}<br>procedure StartBeep(Freq : Word);<br>var<br> B: Byte;<br>begin<br> if (Freq >= LOW_FREQ) and (Freq <= HIGH_FREQ)<br> then<br> begin<br> Freq := Word(1193181 div LongInt(Freq));<br> B := Byte(_GetPort($61));<br> if (B and 3) = 0<br> then<br> begin<br> _SetPort($61, Word(B or 3));<br> _SetPort($43, $B6);<br> end;<br> _SetPort($42, Freq);<br> _SetPort($42, Freq shr 8);<br> end;<br>end; { StartBeep }<br><br><br><br>{------------------------------StopBeep----------------------------------------}<br>procedure StopBeep;<br>var<br> Value: Word;<br>begin<br> Value := _GetPort($61) and $FC;<br> _SetPort($61, Value);<br>end; { StopBeep }<br><br><br>用法:<br> StartBeep(Tone); // Tone为频率<br> StartTime:=GetTickCount;<br> while ( (GetTickCount - StartTime) < LongInt(MSecs) ) do //MSecs为响声长度(毫秒)<br> Application.ProcessMessages;<br> StopBeep;<br><br>*我自己没试过