program sample;
uses crt,secread;
type   Str8 = string[8];
       Str10 = string[10];
       str80 = string[80];

var temp,temp2 : string[4];
    dummy : integer;
    dfile : text;
    fname : string[15];
    secbase  : word;             (* base address of SEC-PC *)
    axis        : word;
    keyv  : char;
    i : integer;
    error : boolean;
    Ch : char;
    copy : word;
    x,y,z : longint;
    stat  : byte;

(* -------------------------------------- *)
procedure ZeroCtrs;
begin
   port[secbase] := 0;
end;
(* --------------------------------------*)


(* --------------------------------------*)
(* --------------------------------------*)


(* --------------------------------------*)

procedure MakeWindow(x1,y1,width,height:word);
var x,y,x2,y2 : integer;
begin
  x2 := x1 + width;
  y2 := y1 + height;

  window(1,1,80,25);
  { TOP }
  gotoxy(x1,y1);
  write(chr(213));
  for x := x1 +1 to x2-1 do write(chr(205));
  write(chr(184));
  { SIDES }
  for y := y1+1  to y2-1 do
    begin
      gotoxy(x1,y);
      write(chr(179),' ':x2-x1-1,chr(179));
    end;
  { BOTTOM }
  gotoxy(x1,y2);
  write(chr(212));
  for x := x1+1 to x2-1 do write(chr(205));
  write(chr(190));
  { make it the current window }
  window(x1+1,y1+1,x2-1,y2-1);
  gotoxy(1,1);
end;


(* --------------------------------------*)


(* --------------------------------------*)
procedure SetUpWindows;
begin
   MakeWindow(1,2,79,23);
   MakeWindow(7,12,16,2);      (* window 1 *)
   MakeWindow(32,12,16,2);
   MakeWindow(58,12,16,2);
   Window(1,1,80,25);
   gotoxy(13,12);  Write(#181,' X ',#198);
   gotoxy(38,12);  Write(#181,' Y ',#198);
   gotoxy(64,12);  Write(#181,' Z ',#198);

   gotoxy(21,1);   Write(#181,'Fischer Computer Systems SEC-PC demo.',#198);

end;
(* --------------------------------------*)

(* --------------------------------------*)
procedure PrintFkeys;
begin
   window(11,25,80,25);
   write('ESC-Exit                                            F2-Zero ');
   window(1,1,80,25);
end;
(* --------------------------------------*)


(* --------------------------------------*)
(* --------------------------------------*)
(* --------------------------------------*)






(* *************************************************************** *)
begin
   clrscr;
   secbase := $330;    (* base address of SEC-PC board *)
   TextColor(LightGray);
   SetUpWindows;
   PrintFKeys;
   (* top of loop *)
   repeat
      repeat
         copy := 1;   (* this makes the copy function enabled for next read *)
         x := ReadCtr(secbase,copy,1);
         copy := 0;   (* we've already copied so just read values now *)
         y := ReadCtr(secbase,copy,2);
         z := ReadCtr(secbase,copy,3);
         gotoxy(9,13);   write(x:10);
         gotoxy(35,13);  write(y:10);
         gotoxy(61,13);  write(z:10);

         (* check for error *)
         port[secbase+3] := 0;   (* set board to status *)
         stat := port[secbase] and $40;
         if stat > 0 then error := true else error := false;

         if error then       (* if sec-pc finds error then *)
         begin
            gotoxy(7,22);
            Write('ERROR in counter!    ',^G);
            Window(1,1,80,25);
            TextColor(143);
            gotoxy(7,23);   Write('Hit F2 to clear counters and continue.');
            TextColor(15);
            repeat
               Ch := ReadKey;
               if Ch = #0 then
                  Ch := ReadKey;
            until Ch = #60;
            if Ch = #60 then ZeroCtrs;
            gotoxy(7,22);   Write('                                           ');
            gotoxy(7,23);   Write('                                           ');

            dummy:= port[secbase+3];   (* clear flag *)
            error := false;
         end;
      until keypressed;           (* reads counters until key pressed *)

      keyv := readkey;
      if keyv = #0 then           (* if extended code then *)
      begin
         keyv := readkey;
         case keyv of
         #60   :       (* F2 *)
            begin
               ZeroCtrs;
            end;
         end;   (* end case to select function key *)
      end;   (* end if extended code key *)
   until keyv = #27;
   ClrScr;
end.

