
PROCEDURE Stop_Watch;
VAR
   which,
   dummy,
   key_state, W_key,
   x, y : integer ;
   msg : Message_Buffer ;
BEGIN
   Total_Sec := 0;
   Hide_Mouse ;
   REPEAT             { wait for button up }
      which := Get_Event( E_Timer | E_Button, $0001, 0, 0,
               0, { time count of zero - quik return }
               false, 0, 0, 0, 0, false, 0, 0, 0, 0, { no rect's }
               msg, W_Key,   { what key }
               dummy, dummy, x, y, key_state ) ;
   UNTIL which>33;
   Paint_Color( 0 ) ;             { erase pm/am marker }
   Paint_Rect( 270,110,20,10 ) ;
   REPEAT
      { Get a left mouse button event. check for button push to stop clock }
      which := Get_Event( E_Timer | E_Button, $0001, 0, 0,
                          0, { time count of zero - quik return }
                          false, 0, 0, 0, 0, false, 0, 0, 0, 0, { no rect's }
                          msg, W_Key,   { what key }
                          dummy, dummy, x, y, key_state ) ;
      So_Far := Ticks ;
      Temp_Sec := So_Far - Start ; { how many seconds times 200 have past }
      Temp_Sec := Temp_Sec DIV 200 ;  { convert to seconds }
      Total_Sec := Original_Sec + Temp_Sec ;  { original time + time elapesed }
      { ** if greater than 19 hrs start counting over ** }
      IF Total_Sec > 68399 THEN
      BEGIN
         Start := Ticks;
         Original_Sec := 0 ;
         So_Far := Ticks ;
         Temp_Sec := So_Far - Start ; { how many seconds times 200 have past }
         Temp_Sec := Temp_Sec DIV 200 ;  { convert to seconds }
         Total_Sec := Original_Sec + Temp_Sec ; {original time + time elapesed}
      END;
           { now break down Total_Sec into hours, minutes and seconds }
      Hr := INT( Total_Sec DIV 3600 ) ;
      N := Hr ;
      Total_Sec := Total_Sec - N*3600 ;
      Min := INT( Total_Sec DIV 60 ) ;
      N := Min ;
      Total_Sec := Total_Sec - N*60 ;
      Sec := INT( Total_Sec ) ;
      Hr_10 := Hr DIV 10 ;
      Hr_1 :=  Hr MOD 10 ;
      IF Sec = 0 THEN
      BEGIN
         Sec_1 := 0;
         Sec_10 := 0;
      END
      ELSE BEGIN
         Sec_10 := Sec DIV 10 ;
         Sec_1 := Sec MOD 10 ;
      END;
      IF Min = 0 THEN
      BEGIN
         Min_1 := 0;
         Min_10 := 0;
      END
      ELSE BEGIN
         Min_10 := Min DIV 10 ;
         Min_1 := Min MOD 10 ;
      END;
                         { If digits have change Draw New Digit on the screen }
      IF Sec_1 <> Old_Sec_1 THEN
      BEGIN
         DX := 260 ;
         D_Digit( Sec_1 ) ;
      END;
      IF Sec_10 <> Old_Sec_10 THEN
      BEGIN
         DX := 212 ;
         D_Digit( Sec_10 ) ;
      END;
      IF Min_1 <> Old_Min_1 THEN
      BEGIN
         DX := 148 ;
         D_Digit( Min_1 ) ;
      END;
      IF Min_10 <> Old_Min_10 THEN
      BEGIN
         DX := 100 ;
         D_Digit( Min_10 ) ;
      END;
      IF Hr_1 <> Old_Hr_1 THEN
      BEGIN
         DX := 36 ;
         D_Digit( Hr_1 ) ;
      END;
      IF Hr_10 <> Old_Hr_10 THEN  D_Hr_10 ;
      Text_Color( 2 );
      Old_Hr_10:=Hr_10; Old_Hr_1:=Hr_1;
      Old_Min_10:=Min_10; Old_Min_1:=Min_1;
      Old_Sec_10:=Sec_10; Old_Sec_1:=Sec_1;
   UNTIL which<34;
   Show_Mouse ;
END;  { of Stop_Watch }

