{ $DEFINE ANALOGIZE}
// Ce logiciel est un logiciel libre, distribue sous licence GNU
//   Copyright (C) H. LESOURD, 1994
{ $DEFINE S0}
{$IFDEF S0}
Program S0;
{$ELSE}
Program CompTest;
{$ENDIF}

Uses
    Crt,
    Errorify,
    Symbolize,
    Lexify,
    Writify,
    Digitizify,
    Assemblify,
    Expressify,
    Addressify,
    Compilify
              ;

Var
   Res : TypedAddress;
   I : Integer;
   L : LongInt;
   S : String;
   B : BoxPtr;
Begin
{$IFDEF S0}
  WaitOnError:=False;
  Case ParamCount Of
    1: Begin
         FT:=COM;
         S:=ParamStr(1);
       End;
    2: Begin
         S:=ParamStr(2);
         If S[1]='/' Then
           Case S[2] Of
             'C','c': FT:=COM;
             'B','b': FT:=BOOT;
             'O','o': FT:=OBJ;
             Else
               Error('C,O,B expected for FicType');
           End
         Else
           Error('"S0 FName (/FicType)" expected');

         S:=ParamStr(1);
       End;
    Else
      Error('"S0 FName (/FicType)" expected');
  End;
{$ELSE}
  S:='DIRBUG';
  FT:=OBJ;
  ClrScr;
{$ENDIF}
  StartLexify(Concat(S,'.S'));

  Case FT Of
    COM,BOOT:
         Begin
           NextWord;
           B:=DigitizeBody;
         End;
    OBJ: B:=DigitizePackage;
    Else
      Error('Bad FT');
  End;

{ COUILLE : Ca passe avec Digitize(0), alors ke le fic commence par VAR !!! }

  More:=True;
  Lisp:=True;
  NbCarriages:=1;
{$IFNDEF S0}
{$IFDEF ANALOGIZE}
  SetColorMode;
  If FT=OBJ Then AnalogizePackage(B) Else AnalogizeBody(B);
  TextAttr:=7;
  Writeln;
{$ENDIF}
{$ENDIF}
  EndLexify;
  For I:=AX To rSS Do RegFree[I]:=False;
  Init;
  StartAssemblify(S);
  NewLabel(EnterLab);
  Case FT Of
    COM:
      Begin
      { JMP +&H0C }
        PokeW($0CEB);
      { MOV BX,CS }
        PokeW($CB8C);
      { ADD BX,10 }
        PokeW($C383);
        PokeB($10);
      { POP CX }
        PokeB($59);
      { MOV CX,&H0011 }
        PokeB($B9);
        PokeW($0011);
      { PUSH BX }
        PokeB($53);
      { PUSH CX }
        PokeB($51);
      { RETF }
        PokeB($CB);
      { CALL -&H0E }
        PokeB($E8);
        PokeW($FFF1);
        Assemble(JMP,EnterLab,NullAddr);
      End;
    BOOT:
      Begin
      { JUMP 1E; NOP }
        PokeW($1CEB);
        PokeB($90);
      { CopyRight }
        PokeB(Ord('B'));
        PokeB(Ord('O'));
        PokeB(Ord('S'));
        PokeB(Ord(' '));
        PokeB(Ord('v'));
        PokeB(Ord('1'));
        PokeB(Ord('.'));
        PokeB(Ord('0'));
      { #Byte/Sect }
        PokeW($0200);
      { #Sect/Clus }
        PokeB($01);
      { #BootSection }
        PokeW($0001);
      { #FATs }
        PokeB($02);
      { #RootDir }
        PokeW($00E0);
      { #Sect }
        PokeW($0B40);
      { Suppt Descr }
        PokeB($F0);
      { #Sect/FAT }
        PokeW($0009);
      { #Sect/Track }
        PokeW($0012);
      { #Heads }
        PokeW($0002);
      { #ZOB }
        PokeW($0000);
      { JMP 07C0:0023 }
        PokeB($EA);
        PokeW($0023);
        PokeW($07C0);
      { JMP Start }
        Assemble(JMP,EnterLab,NullAddr);
      End;
  End;
  Case FT Of
    OBJ: CompilePackage(B);
    Else
      Begin
        CompileBody(B);
      End;
  End;
  EndAssemblify;
{$IFNDEF S0}
  WaitingForAKey;
{$ENDIF}
End.
