Unit PCSPK;
Interface
Uses Classes, WinProcs, Forms;
type TPCSpeaker = class (TComponent) private {Private declarations} procedure NoSound; procedure Sound (Freq: Word); procedure SetPort (address, value: Word); function GetPort (address: Word): Word; protected {Protected declarations} public { PUBLIC DECLArations}}: Procedure Play; Procedure Stop; PROCEDURE STOP; Published {Published Declarations}
PROCEDURE register;
IMPLEMentation
Procedure tpcspeaker.nosound; var wvalue: word; begin wvalue: = getport ($ 61); wvalue: = wvalue and $ fc; setPort ($ 61, wvalue);
Procedure tpcspeaker.sound (freq: word); var B: Word; Begin IF FREQ> 18 THEN BEGIN FREQ: = WORD (1193181 Div Longint (FREQ));
B: = GetPort ($ 61);
IF (b and 3) = 0 THEN BEGIN SETPORT ($ 61, B OR 3); SetPort ($ 43, $ B6); END;
SetPort ($ 42, FREQ); SetPort ($ 42, (Freq SHR 8)); End;
procedure TPCSpeaker.Delay (MSecs: Integer); var FirstTickCount: LongInt; begin FirstTickCount: = GetTickCount; repeat Application.ProcessMessages; {allowing access to other controls, etc.} until ((GetTickCount-FirstTickCount)> = LongInt (MSecs)) ;
Procedure tpcspeaker.play (freq: word; msecs: integer); Begin Sound (FREQ); DELAY (MSECS); Nosound; End;
Procedure tpcspeaker.stop; begin nosound;
Procedure tpcspeaker.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 TPCSpeaker.GetPort (address: Word): Word; var bValue: Byte; begin asm mov DX, address in AL, DX mov bValue, AL end; result: = bValue; end; procedure Register; begin RegisterComponents ( 'SongWS', [TPCSPEAKER]);
End.