www.pudn.com > DelayProcs.rar > DelayProcs.pas
unit DelayProcs;
{Delphi 3.0}
{biblioteka procedur czasowych}
{by NopSoft}
{użyłem rozwiązań z programatora Willem}
interface
procedure initdelay; {inicjuje zmienne procedur delay}
procedure ticksdelay(ticks:longint); {ticks}
function ticks2us(us:longint):longint; {us -> ticks}
procedure usdelay(us:longint); {microseconds}
procedure msdelay(ms:longint); {milliseconds}
{zamiast msdelay można użyć Sleep(ms) lub SleepEx(ms,flag),
ale mają one pewne ograniczenia - patrz pomoc (np. ALT+TAB)}
{Sleep(long)}
{SleepEx(long,boolean):long}
implementation
{{
#define TICKS(us) ((unsigned) (1.193182*(us)+1)) /* us to ticks */
LARGE_INTEGER PerformanceFrequency;
void __fastcall ms_delay(int ticks)
{
// Dos version Returns after roughly ticks*0.8381 microseconds
// we convert figures used for Dos version to no of cycles.
// Currently set so 1,000,000 = 1 second
LARGE_INTEGER Count,EndCount;
QueryPerformanceCounter(&Count);
EndCount.QuadPart = Count.QuadPart + (ticks * PerformanceFrequency.QuadPart * 0.0000008381);
while (Count.QuadPart < EndCount.QuadPart) QueryPerformanceCounter(&Count);
}
{{
void __fastcall TfrmEprom::FormCreate(TObject *Sender)
{
// Get performance details for timing
QueryPerformanceFrequency(&PerformanceFrequency);
// Port Access DLL's for Windows 95 and NT
DLPortIO->DriverPath=ExtractFileDir(ParamStr(0));
DLPortIO->OpenDriver();
if (!DLPortIO->ActiveHW)
MessageDlg("Could not open the DriverLINX driver.",mtError, TMsgDlgButtons() << mbOK, 0);
[...]
}{}
uses
Windows;
type
large_integer = TLargeInteger; {dword + longint or longint + longint}
var
PerformanceFrequency:large_integer;
procedure initdelay;
begin
{Get performance details for timing}
QueryPerformanceFrequency(PerformanceFrequency);
end;
procedure ticksdelay;
{
Dos version Returns after roughly ticks*0.8381 microseconds
we convert figures used for Dos version to no of cycles.
Currently set so 1,000,000 = 1 second
}
var
Count,EndCount:large_integer;
begin
QueryPerformanceCounter(Count);
EndCount.QuadPart := int( {round doesn't work :( -too high numbers...}
Count.QuadPart
+ (ticks * PerformanceFrequency.QuadPart * 0.0000008381{0.8381us})
);
{ EndCount.QuadPart :=
Count.QuadPart
+ ((ticks * 8381 * PerformanceFrequency.QuadPart) div 10000000000/0.8381us/);}
while (Count.QuadPart < EndCount.QuadPart) do
QueryPerformanceCounter(Count);
end;
function ticks2us;
{us to ticks}
begin
ticks2us:=round(1.193182 * us + 1);
end;
procedure usdelay;
var
Count,EndCount:large_integer;
begin
QueryPerformanceCounter(Count);
EndCount.QuadPart := int(
Count.QuadPart
+ (us * PerformanceFrequency.QuadPart * 0.000001{us})
);
{ EndCount.QuadPart :=
Count.QuadPart
+ ((us * PerformanceFrequency.QuadPart) div 1000000/us/)}
while (Count.QuadPart < EndCount.QuadPart) do
QueryPerformanceCounter(Count);
end;
procedure msdelay;
var
Count,EndCount:large_integer;
begin
QueryPerformanceCounter(Count);
EndCount.QuadPart := int(
Count.QuadPart
+ (ms * PerformanceFrequency.QuadPart * 0.001{ms})
);
{ EndCount.QuadPart :=
Count.QuadPart
+ ((ms * PerformanceFrequency.QuadPart) div 1000/ms/)}
while (Count.QuadPart < EndCount.QuadPart) do
QueryPerformanceCounter(Count);
{
or use:
Sleep(ms);
}
end;
end.