{$CALLING OLDFPCCALL}
uses Lacrt;

Function FromTimer:dword;assembler;{$IFDEF NEWFPC}nostackframe;{$ENDIF}
asm
mov eax,fs:[$400+$6c]
end;


Function TimerTicksFrom(last,d:dword):boolean;assembler;{$IFDEF NEWFPC}nostackframe;{$ENDIF}
{Similar like "if FromTimer>last+d then true" but solves problem with}
{Timer wrapping on MaxDword value}
{DESTROYS: NONE (only return value into EAX)}
asm
push ecx
push ebx

call FromTimer     {FromTimer je ted v EAX}
mov ecx,eax        {a ted v ECX}

xor eax,eax

mov ebx,last       {Minula hodnota timeru je ted v EBX}


cmp ecx,ebx
jb @interval_uplynul  {osetri wrapping - nedodrzi vsak interval}

add ebx,d          {EBX:=Last+D}
cmp ecx,ebx
jb @je_mensi

@interval_uplynul:
inc eax

@je_mensi:

pop ebx
pop ecx
end;


var zt:dword;
     b:boolean;
     a:byte;

begin
zt:=FromTimer;
a:=0;
repeat
TimerDelay(5);
b:=TimerTicksFrom(zt,20);
if B then
   begin
   inc(a);
   zt:=FromTimer;
   end
   else begin
   a:=a;
   end;
writeln(b);
until a>=2;

readln;
end.