Program Test1_FstTimer;

uses
  Dos,
  RtcTime,
  HWSyst,
  Tick,
  FstTimer,
  NumToStr,
 {$ifdef Kit188}
  Crt2Mem, {obsluhy Video a Keyboard BIOSu pro komunikaci na KitXxx}
  ChnVirt,
  Chn188,  {komunikacni knihovna pro fyzicke rozhranni UART i8250}
  ChnCrt,  {komunikacni protokol pro prenos Video a Keyboard}
  CrtComSl,{komunikacni automat pro prenos Video a Keyboard}
 {$endif}
  Crt;

var
  Tm:tFstTimer;
  I :integer;
  Time:word;
  DT:DateTime;
  W,Sec100,Sec:word;

procedure WriteClock;
begin
  gotoxy(1,3);
  writeln('RtcTime=',TimeToStr(DT,'MM:SS'),
         ' FstTime=',IntToStr(Hi(Time),tpDec,2),':',IntToStr(Lo(Time),tpDec,2));
  writeln('(Fst)IRQCnt=',GetFastTime);
end;

Begin
 {$ifdef Kit188}
  if InitCrtCom('NAM=CRT MAS=SLAVE LSB=200 '+
                'NAM=188 BD=115200 PAR=E STO=1 LRB=500') <> res_Ok then RunError(10);
 {$endif}
  {InitTick;}
  ClrScr;
  writeln('Test jednotky FstTimer');
  writeln;
  write('Init.');
  GetTime(W,W,Sec,Sec100);
  W:=Sec100;
  repeat
    if (Sec100 mod 2 = 1)and
       (W<>Sec100) then
    begin
      write('.');
      W:=Sec100;
    end;
    Tm.SaveTime;
    GetTime(DT.Hour,DT.Min,DT.Sec,Sec100);
   {$ifdef Kit188}
    CrtComMake;
   {$endif}
  until DT.Sec<>Sec;
  Sec:=DT.Sec;
  Time:=(DT.Min shl 8) or DT.Sec;
  WriteClock;

  repeat
    for I:=1 to 100 do
    begin
      repeat
      until Tm.TstTime(10{ms});
      Tm.SaveTime;
      GetTime(DT.Hour,DT.Min,DT.Sec,W);
      if DT.Sec<>Sec then
      begin
        Sec:=DT.Sec;
        WriteClock;
      end;
      if keypressed then Exit;
     {$ifdef Kit188}
      CrtComMake;
     {$endif}
    end;
    Inc(Time);
    if Lo(Time)>59 then
      Time:=(Time+$100) and $FF00;
    WriteClock;
  until keypressed;
End.
