(*----------------------------------------------------------------------*)
(*                  InitTerm --- Initialize PibTerm                     *)
(*----------------------------------------------------------------------*)

OVERLAY PROCEDURE InitTerm;

(*----------------------------------------------------------------------*)
(*                                                                      *)
(*     Procedure:  InitTerm                                             *)
(*                                                                      *)
(*     Purpose:    Initializes PibTerm                                  *)
(*                                                                      *)
(*     Calling Sequence:                                                *)
(*                                                                      *)
(*        InitTerm;                                                     *)
(*                                                                      *)
(*----------------------------------------------------------------------*)

VAR
   Done_Flag : BOOLEAN;
   F         : TEXT;

BEGIN (* InitTerm *)
                                   (* Get session start time   *)

   Session_Start_Time := TimeOfDay;
   Dialing_Start_Time := Session_Start_Time;

                                   (* Initialize critical error *)
                                   (* handler routine.          *)
   Int24ON;
                                   (* Initialize handler for    *)
                                   (* other errors.             *)

   ErrorPtr := OFS( Error_Handler );

                                   (* Clear screen             *)
   ClrScr;
                                   (* Select color/mono screen *)

   Get_Screen_Address( Actual_Screen );

                                   (* Assume text mode from    *)
                                   (* current system setting.  *)
   CASE Current_Video_Mode OF

      0, 2, 7       : Text_Mode := BW80;
      1, 3, 4, 5, 6 : Text_Mode := C80;

   END (* CASE *);

   TextMode( Text_Mode );
                                   (* Set colors as black and white *)

   Set_Global_Colors( White, Black );

   ForeGround_Color := White;
   BackGround_Color := Black;
   Menu_Text_Color  := White;
   Menu_Frame_Color := White;
                                   (* Set VT100 colors         *)

   VT100_ForeGround_Color := LightGray;
   VT100_BackGround_Color := Black;
   VT100_Underline_Color  := Blue;
   VT100_Bold_Color       := White;

                                   (* Set saved screen pointer *)
   Saved_Screen     := NIL;
                                   (* Silent mode OFF to start *)
   Silent_Mode      := FALSE;
                                   (* Local echo starts at OFF *)
   Local_Echo       := FALSE;
                                   (* Gossip mode starts at OFF *)
   Gossip_Mode_On   := FALSE;
                                   (* Host Mode starts at OFF *)
   Host_Mode        := FALSE;
                                   (* Phone number to dial     *)
   Phone_Number     := '';
                                   (* Last column not hit yet  *)
   Last_Column_Hit  := FALSE;
                                   (* Wrap long lines          *)
   Auto_Wrap_Mode   := TRUE;
                                   (* No blinking in effect    *)
   Blinking_On      := 0;
                                   (* No script file being used *)
   Script_File_Mode := FALSE;
                                   (* Set empty review buffer  *)
   Review_Head      := 0;
   Review_Tail      := 0;
   Review_Line      := '';
   Review_Buffer    := NIL;
                                   (* No WHEN string in use    *)
   Script_When_Text       := '';
   Script_When_Reply_Text := '';
   Script_When_Save       := '';
   When_Mode              := FALSE;
                                   (* No WAITSTRING in use     *)
   Script_Wait_Text       := '';
   Script_Wait_Reply_Text := '';
   Script_Wait_Save       := '';
   Script_Wait_Found      := FALSE;
   WaitString_Mode        := FALSE;
   Read_In_Script         := FALSE;
   Really_Wait_String     := FALSE;
   Script_Suspend_Time    := 0.0;
                                   (* No script to start *)
   Script_Buffer          := NIL;
   Script_Buffer_Size     := 0;

                                   (* Carrier not set high by default *)
   Modem_Carrier_High     := FALSE;

                                   (* Establish Communications *)

   IF NOT Set_Params( TRUE , FALSE ) THEN
      BEGIN
         WRITELN('*** Sorry, can''t initialize communications.');
         WRITELN('*** Program stops.');
         Halt;
      END;
                                   (* Give Program Notice *)

   WRITELN('PibTerm Version ', PibTerm_Version,' Ready.');
   WRITELN('Hit Alt-I for command list.');

                                   (* Initialize Modem         *)

   IF Modem_Init <> '' THEN
      BEGIN
         WRITELN('Modem initialization: ',Write_Ctrls( Modem_Init ) );
         Send_Modem_Command( Modem_Init );
         Async_Purge_Buffer;
      END;
                                   (* Pick up script file name if any, *)
                                   (* and convert to executable form.  *)
   IF ParamCount > 0 THEN
      BEGIN
         Script_File_Name := ParamStr( 1 );
         Process_Script;
      END
   ELSE                            (* Check if PIBTERM.SCR exists.     *)
      BEGIN
         ASSIGN( F , 'PIBTERM.SCR' );
            (*$I-*)
         RESET( F );
            (*$I+*)
         IF ( Int24Result = 0 ) THEN
            BEGIN
               CLOSE( F );
               Script_File_Name := 'PIBTERM.SCR';
               Process_Script;
            END;
      END;

END   (* InitTerm *);