Havde det lige liggende
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;
function GetPort(address: Word): Word;
var
bValue: Byte;
begin
asm
mov dx, address
in al, dx
mov bValue, al
end;
GetPort := bValue;
end;
procedure Sound(aFreq, aDelay: Integer) ;
procedure DoSound(Freq: Word) ;
var
B: Byte;
begin
if Freq > 18 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;
procedure Delay(MSecs: Integer) ;
var
FirstTickCount: LongInt;
begin
FirstTickCount := GetTickCount;
repeat
Sleep(1) ;
//or use Application.ProcessMessages instead of Sleep
until ((GetTickCount - FirstTickCount) >= Longint(MSecs)) ;
end;
begin
if Win32Platform = VER_PLATFORM_WIN32_NT then
begin
Windows.Beep(aFreq, aDelay) ;
end
else
begin
DoSound(aFreq) ;
Delay(aDelay) ;
end;
end;
procedure NoSound;
var
Value: Word;
begin
if not (Win32Platform = VER_PLATFORM_WIN32_NT) then
begin
Value := GetPort($61) and $FC;
SetPort($61, Value) ;
end;
end;
eksempel
procedure TForm1.Button1Click(Sender: TObject);
begin
Sound(1000, 500);
end;
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GED d- s: a--- C++ U? P L+ E? W++ N? o? K- w
O? M? V? PS PE? Y? PGP++ t 5? X+ R tv+ b+ DI? D+
G e-- h! !r y--
------END GEEK CODE BLOCK------
Failure is not an option, it\\'s included with the software. - Murphys Law
[Redigeret d. 06/12-05 13:24:18 af Jonas (Decko)]