forked from JBontes/Life32
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTickTime.pas
166 lines (140 loc) · 3.03 KB
/
TickTime.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
unit TickTime;
interface
uses SysUtils;
type
TTijd = record
case integer of
1: (Totaal: Comp);
2: (Lo, Hi: Longint);
3: (Lom, Dummy, Him, Dummy2: word);
end;
TTickTimer = class(TObject)
protected
function GetStartTime: TTijd;
function GetEndTime: TTijd;
function GetTimePast: TTijd;
function GetStartMilliTime: integer;
function GetEndMilliTime: integer;
function GetMilliTimePast: integer;
public
procedure ClearTime;
procedure StartNow;
procedure StopNow;
property StartTime: TTijd read GetStartTime;
property EndTime: TTijd read GetEndTime;
property TimePast: TTijd read GetTimePast;
property StartMilliTime: integer read GetStartMilliTime;
property EndMilliTime: integer read GetEndMilliTime;
property MilliTimePast: integer read GetMilliTimePast;
end;
function CompToStr(const A: Comp): string;
function IsIntelInstalled: boolean;
implementation
uses
Windows;
var
Start, Eind: TTijd;
TicksPerMilliSec: integer;
function CompToStr(const A: Comp): string;
begin
//Str(A:20:0,Result);
//Result:= Trim(Result);
Result:= IntToStr(Int64((@A)^));
end;
function IsIntelInstalled: boolean;
begin
{$ifdef win32}
result:= true;
try
asm
db 00FH
db 031H
end; {asm}
except result:= false
end; {try}
{$else}
result:= false;
{$endif}
end;
function GetTicksPerMilli: integer;
var
TickTimer: TTickTimer;
MilliStart: integer;
MilliEnd: integer;
TicksPast: TTijd;
begin
TickTimer:= TTickTimer.Create;
MilliStart:= GetTickCount;
TickTimer.StartNow;
repeat
MilliEnd:= GetTickCount
until MilliEnd - MilliStart > 20; //time 20 milliseconds or more.
TicksPast:= TickTimer.TimePast;
MilliEnd:= MilliEnd - MilliStart;
Result:= Round(TicksPast.Totaal / MilliEnd);
end;
procedure TTickTimer.StartNow;
asm
DB 00FH
DB 031H
{$ifdef win32}
MOV Start.Lo,EAX
MOV Start.Hi,EDX
{$else}
DB 066H; MOV Start.LOM,AX
DB 066H; MOV Start.Him,DX
{$endif}
end; {asm}
procedure TTickTimer.StopNow;
asm
DB 00FH
DB 031H
{$ifdef win32}
MOV Eind.Lo,EAX
MOV Eind.Hi,EDX
{$else}
DB 066H; MOV Eind.LOM,AX
DB 066H; MOV Eind.Him,DX
{$endif}
end; {asm}
function TTickTimer.GetStartTime: TTijd;
begin
StartNow;
Result:= Start;
end;
function TTickTimer.GetEndTime: TTijd;
begin
StopNow;
Result:= Eind;
end;
function TTickTimer.GetTimePast: TTijd;
begin
StopNow;
Result.Totaal:= Eind.Totaal - Start.Totaal;
end;
function TTickTimer.GetStartMilliTime: integer;
begin
Result:= Round(StartTime.Totaal / TicksPerMilliSec);
end;
function TTickTimer.GetEndMilliTime: integer;
begin
Result:= Round(Eind.Totaal / TicksPerMilliSec);
end;
function TTickTimer.GetMilliTimePast: integer;
begin
Result:= Round(TimePast.Totaal / TicksPerMilliSec);
end;
procedure ClearIt;
begin
Start.Hi:= 0;
Start.Lo:= 0;
Eind:= Start;
end;
procedure TTickTimer.ClearTime;
begin
ClearIt;
end;
initialization
ClearIt;
if IsIntelInstalled then TicksPerMilliSec:= GetTicksPerMilli;
end.