PROGRAM TURBOFIX (INPUT,OUTPUT,ROOTFILE);
{  ***************************************************************************
   -- Null the terminal control codes in the Turbo run-time library --
   All Ver. 2.0 Turbo Pascal programs send a Lowvideo and then a Highvideo
   sequence to the terminal when execution begins.  This is a problem when
   the object code is run on a terminal different from the one on which the
   program was compiled.  This program removes the control codes from the
   run-time library.
   (c) 1984 - Todd Merriman - Future Communications - Atlanta, Georgia.
   Published in the Public Domain for non-commercial use.
   Usage:
      A>TURBOFIX [filename] [.COM]
   If the extension .COM is not supplied on the command line, it is assumed
   by the program.  The Turbo 2.0 jump address at 100H is checked to be sure
   the .COM file is actually a Turbo program.
   ***************************************************************************
}
CONST
   NUMCHAR    = $FF;
   TERMLOC    = $53;                       { terminal name offset }
   LOWB       = $C2;
   HIB        = $C8;
   CLEAR      = $A2;
   HOME       = $A8;
   JUMP : ARRAY [0..2] OF BYTE = ($C3,$C9,$1F);   { Turbo 2.0 jump address }

TYPE
   STRING2    = STRING [2];
   STRING80   = STRING [80];

VAR
   I          : BYTE;
   ROOTNAME   : STRING [14];
   ROOTFILE   : FILE;
   BUFF       : ARRAY [0..NUMCHAR] OF BYTE;


FUNCTION CMDLINE: STRING80;
{  ***************************************************************************
   Get command from command line
   ***************************************************************************
}
CONST
   BUF = $80;

VAR
   I:INTEGER;
   ST:STRING80;

BEGIN { CMDLINE }

   ST:='';
   FOR I:= BUF+2 TO BUF + ORD (MEM [BUF]) DO
   BEGIN
      ST [0] := SUCC (ST [0]);
      ST [ORD (ST [0])] := CHR (MEM [I]);
   END;

   CMDLINE:=ST;

END; { CMDLINE }


{  ***************************************************************************
}
BEGIN { TURBOFIX }
   WRITELN ('----- TURBO PROGRAM ROOT REPAIR ----');
   WRITELN ('      by Future Communications');
   WRITELN;
   ROOTNAME := CMDLINE;
   IF LENGTH (ROOTNAME) > 0 THEN
   BEGIN
      IF POS ('.',ROOTNAME) = 0 THEN ROOTNAME := ROOTNAME + '.COM';
      ASSIGN (ROOTFILE,ROOTNAME);             { add default extension }
      {$I-}
      RESET (ROOTFILE);
      {$I+}
      IF IORESULT = 0 THEN
      BEGIN
         WRITELN ('> ',ROOTNAME);
         SEEK (ROOTFILE,0);
         BLOCKREAD (ROOTFILE,BUFF,2);
         IF (MEM [ADDR(BUFF) + 0] = JUMP [0]) AND   { check jump address }
            (MEM [ADDR(BUFF) + 1] = JUMP [1]) AND
            (MEM [ADDR(BUFF) + 2] = JUMP [2]) THEN
         BEGIN
            MEM [ADDR(BUFF) + LOWB] := 0;
            MEM [ADDR(BUFF) + HIB]  := 0;
            MEM [ADDR(BUFF) + TERMLOC] := 0;
            MEM [ADDR(BUFF) + CLEAR] := 0;
            MEM [ADDR(BUFF) + HOME] := 0;
            SEEK (ROOTFILE,0);
            WRITELN ('> Removing Terminal Control Codes');
            BLOCKWRITE (ROOTFILE,BUFF,2);
         END
         ELSE WRITELN (#7,'? Is not Turbo Ver. 2.0');
         CLOSE (ROOTFILE);
      END { IF IORESULT }
      ELSE WRITELN (#7,'? ',ROOTNAME,' does not exist');
   END { IF LENGTH }
   ELSE WRITELN (#7,'? No filename specified on command line');
   WRITELN ('> End <');
END. { TURBOFIX }

