program quizcontrol; uses WinCrt, WinDos;
const
   LPT1D = $3bc;
   LPT1S = LPT1D+1;
var
   k: integer;
procedure stuurLamp(kandidaat: integer);
   begin
      if kandidaat=1 then
         if port[LPT1D] and $01 = $01 then
            port[LPT1D]:=$02
         else
            port[LPT1D]:=$01
      else
         if port[LPT1D] and $04 = $04 then
            port[LPT1D]:=$08
         else
            port[LPT1D]:=$04
   end;
procedure knipperEnWacht(kandidaat, wachttijd: integer);
   var
      s, t, teller, uur, min, h: word;
   begin
      writeln('Kandidaat ', kandidaat, ' mag nu antwoorden');
      getTime(uur, min, s, h);
      teller:=0;
      repeat
         stuurLamp(kandidaat);
         repeat
            getTime(uur, min, t, h)
         until (t<>s) or (port[LPT1S] and $20 = $20);
         s:=t;
         teller:=teller+1
      until (teller=wachttijd) or (port[LPT1S] and $20 = $20)
   end;
begin
   repeat
      port[LPT1D]:=$00;
      k:=0;
      writeln('Daar gaan we weer. Drukken maar...');
      repeat
         if port[LPT1S] and $08 = $08 then
            k:=1
         else
            if port[LPT1S] and $10 = $10 then
               k:=2
      until k<>0;
      writeln('Kandidaat ', k, ' heeft als eerste gedrukt!');
      knipperEnWacht(k, 10);
      if port[LPT1S] and $20 = $00 then
         if k=1 then
            knipperEnWacht(2, 5)
         else
            knipperEnWacht(1, 5)
   until port[LPT1S] and $40 = $40
end.