(*===========================================================================*)
(*                             TCell                                         *)
(*===========================================================================*)
(*                                                                           *)
(*              This is the main program                                     *) 
(*                                                                           *)
(*===========================================================================*)
(*                                                                           *)
(*              Original : Writen by David Siebert                           *)
(*                         02-may-88                                         *)
(*===========================================================================*)
(*                                                                           *)
(*             Modified  : 03-may-88 David Siebert                           *)
(*                         looked for the bug                                *)
(*                         05-may-88 David Siebert                           *)
(*                         quite working on the program                      *)
(*                         07-may-88 David Siebert                           *)
(*                         looked at Virusx I don't like                     *)
(*                         the way it worked no one but                      *)
(*                         the DOS should write the                          *)
(*                         Bootblock. There is a limit                       *)
(*                         to what a program should do.                      *)
(*                         01-jun-88 David Siebert                           *)
(*                         Auto Checks Disk                                  *)
(*                         04-jun-88 David Siebert                           *)
(*                           Checks for Boot Bandit Virus                    *)
(*===========================================================================*)

MODULE TCell;
FROM MyStartupCode IMPORT StartUp,CloseUp;
FROM SYSTEM IMPORT NULL,ADR,BYTE,ADDRESS;
FROM Libraries IMPORT OpenLibrary,CloseLibrary;
FROM Intuition IMPORT NewWindow,WindowPtr,Window,IDCMPFlagSet,WindowFlags,
WindowFlagSet,ScreenFlags,ScreenFlagSet,IntuitionName,IntuitionBase,
IntuiMessagePtr,IDCMPFlags,IntuitionText;
FROM Ports IMPORT WaitPort,GetMsg,ReplyMsg,MessagePtr;
FROM Strings IMPORT String;
FROM Windows IMPORT OpenWindow,CloseWindow;
FROM Text IMPORT ClearScreen;
FROM NVK IMPORT Change,Di; 
FROM VK IMPORT VCheck,TDD; 
FROM Requesters IMPORT AutoRequest;
FROM GraphicsLibrary IMPORT Jam1;
FROM DOSCodeLoader IMPORT Execute;
FROM DOSFiles IMPORT FileHandle,Open,Close,ModeNewFile,Write;
FROM ASCII IMPORT CharIsPrintable;

(* $S-,$T-,$A+ *)
VAR
  MyData : TDD;
  DriveName:ARRAY [0..3] OF String;
  DriveString:ARRAY[0..3] OF String;
  Qtemp:IDCMPFlagSet;
  s1,
  s2,
  s3,
  s4,
  s5,
  s6,
  TITLE   :String;
  Nwind   :NewWindow;
  MyWindow:WindowPtr;
  actt,
  Act     :BOOLEAN;
  MyClass :IDCMPFlagSet;
  MyMsg   :IntuiMessagePtr;
  TString1,
  TString2,
  TString3,
  TString4:IntuitionText;
  a,
  Drive   :LONGCARD;
  i       :INTEGER;
  q       :FileHandle;
  NC      :CHAR;
  nq      :LONGINT;

PROCEDURE InForm(Drive:INTEGER);
VAR 
   i : INTEGER;

BEGIN
   q:=FileHandle(NULL);
   TString1.IText:=ADR(s4);
   TString2.IText:=ADR(s5);
   TString3.IText:=ADR(s6);
   TString4.IText:=ADR(DriveString[Drive]);
   IF AutoRequest(MyWindow,ADR(TString1),ADR(TString2),
      ADR(TString3),Qtemp,Qtemp,250,65) THEN
      q:=Open("CON:0/0/640/200/BootBlock",ModeNewFile);
      FOR i:=1 TO 512 DO
         IF CharIsPrintable(MyData[i]) THEN nq:=Write(q,ADR(MyData[i]),1);
         ELSE
            nq:=Write(q,ADR(NC),1);
         END; 
      END;(* END FOR *)
   END; (* end if *)
   TString1.IText:=ADR(s1);
   TString2.IText:=ADR(s2);
   TString3.IText:=ADR(s3);
   Act:=AutoRequest(MyWindow,ADR(TString1),ADR(TString2),
                    ADR(TString3),Qtemp,Qtemp,270,65);
   Close(q);
   IF Act THEN
      q:=Open("NIL:",ModeNewFile); 
      (* this is in my opinion is the way it initalize a bootblock *)
      (* in a operating system friendly way. *)
      IF Execute(DriveName[Drive],q,q) THEN
      END; (* end if *)
      Close(q);
   END; (*end if*)
END InForm;

BEGIN
(* initalize a lot of data that is one thing that c does a lot better *)
  StartUp;
  NC:=".";
  DriveName[0]:="c:Install DF0:";
  DriveName[1]:="c:Install DF1:";
  DriveName[2]:="c:Install DF2:";
  DriveName[3]:="c:Install DF3:";
  DriveString[0]:=" On Drive DF0:";
  DriveString[1]:=" On Drive DF1:";
  DriveString[2]:=" On Drive DF2:";
  DriveString[3]:=" On Drive DF3:";
  Qtemp:=IDCMPFlagSet{};
  TITLE:="TCell";
  s1:=" Non Stanadard Boot Block";
  s2:=" INSTALL";
  s3:=" DON'T INSTALL";
  s4:=" Show Boot Block ?";
  s5:=" Show";
  s6:=" DontShow";
  WITH TString1 DO
     FrontPen := BYTE(0);
     BackPen  := BYTE(1);
     DrawMode :=BYTE(Jam1);
     LeftEdge :=3;
     TopEdge  :=5;
     ITextFont :=NULL;
     NextText :=ADR(TString4);
  END; (* TString1 *)
WITH TString2 DO
     FrontPen := BYTE(0);
     BackPen  := BYTE(1);
     DrawMode :=BYTE(Jam1);
     LeftEdge :=3;
     TopEdge  :=3;
     ITextFont :=NULL;
     NextText :=NULL;
  END; (* TString2 *)
  WITH TString3 DO
     FrontPen := BYTE(0);
     BackPen  := BYTE(1);
     DrawMode :=BYTE(Jam1);
     LeftEdge :=3;
     TopEdge  :=3;
     ITextFont :=NULL;
     NextText :=NULL;
  END; (* TString3 *)
  WITH TString4 DO
     FrontPen := BYTE(0);
     BackPen  := BYTE(1);
     DrawMode :=BYTE(Jam1);
     LeftEdge :=3;
     TopEdge  :=14;
     ITextFont :=NULL;
     NextText :=NULL;
  END; (* TString4 *)
  WITH Nwind DO
     LeftEdge  :=0;
     TopEdge   :=0;
     Width     :=128;
     Height    :=10;
     DetailPen :=BYTE(0);
     BlockPen  :=BYTE(1);
     IDCMPFlags :=IDCMPFlagSet{DiskInserted,CloseWindowFlag};
     Flags     :=WindowFlagSet{WindowDepth,GimmeZeroZero,WBenchWindow,
      WindowDrag,WindowClose,Borderless};
     FirstGadget :=NULL;
     CheckMark :=NULL;
     Title :=ADR(TITLE);
     Screen :=NULL;
     BitMap :=NULL;
     MinWidth:=20;
     MinHeight :=20;
     MaxWidth:=600;
     MaxHeight :=200;
     Type:=ScreenFlagSet{WBenchScreen};     
  END; (*With*)
(* here is the real program *)
  FOR Drive:=0 TO 3 DO
     IF Di[i].IsHere THEN
        IF VCheck(Drive,MyData) THEN
        (* set up the auto requester *)
           InForm(INTEGER(Drive));         
        END; (* end if *)
     END; (* end if *)
  END; (* end for *)
  MyClass:=IDCMPFlagSet{};
  MyWindow:=OpenWindow(Nwind);
  IF MyWindow <> NULL THEN
    REPEAT
       MyMsg:=ADDRESS(WaitPort(MyWindow^.UserPort));
       MyMsg:=ADDRESS(GetMsg(MyWindow^.UserPort));
       MyClass:=MyMsg^.Class;
       ReplyMsg(ADDRESS(MyMsg));
       IF (MyClass = IDCMPFlagSet{DiskInserted}) THEN
           (* the code in the module that the procdure Change is from is *)
           (* some of the worst I have written. and would not have been even*)
           (* been nessasary if Intuition had done the smart thing and *)
           (* returned the drive number of the drive that had been changed*)
           (* in the code field *)
            Drive:=Change();
           IF VCheck(Drive,MyData) THEN
             (* set up the auto requester *)
              InForm(INTEGER(Drive));         
           END; (* end if *)
       END; (* end if *)
    UNTIL (MyClass = IDCMPFlagSet{CloseWindowFlag});
    CloseWindow(MyWindow);
 END; (*IF *)
CloseUp;
END TCell.
