先声明一下,这也是从DFW中看到抄下来的,具体贴子也没记下来。
const
cnst_BEEP_LOW_FREQ=40;
cnst_BEEP_HIGH_FREQ=5000;
function _GetPort(address:word):word;
var
bValue: byte;
begin
asm
mov dx, address
in al, dx
mov bValue, al
end;
Result := bValue;
end; { _GetPort }
procedure _SetPort(address, Value:Word);
var
bValue: byte;
begin
bValue := Trunc(Value and 255);
asm
mov dx, address
mov al, bValue
out dx, al
end;
end; { _SetPort }
procedure StartBeep(Freq : Word);
var
B: Byte;
begin
if (Freq >= cnst_BEEP_LOW_FREQ) and (Freq <= cnst_BEEP_HIGH_FREQ) then
begin
Freq := Word(1193181 div LongInt(Freq));
B := Byte(_GetPort($61));
if (B and 3) = 0 then
begin
_SetPort($61, Word(B or 3));
_SetPort($43, $B6);
end;
_SetPort($42, Freq);
_SetPort($42, Freq shr 8);
end;
end; { StartBeep }
procedure StopBeep;
var
Value: Word;
begin
Value := _GetPort($61) and $FC;
_SetPort($61, Value);
end; { StopBeep }