{                         ****************************
                      ****   PC Spiel Pinball SOURCE  ****
                          ****************************

  FILE DESCRIPTION: This is the main program, from whom all is starting.

  Read the file readme. for further information.

}

{$M $4000,0,0 }

uses dos,crt;

const N1 = ' PCS-PINBALL  - Version 1.1 written by A.Scherp and J.Gelhaus ';
      N2 = ' (c)opyrights reserved by PC Spiel and vIRTUAL tECHNOLOGIES GbR';

var params:string;
    code:integer;
    music,highres,overscan,player,tables:byte;
    path:string;
    hilfsb:byte;

{$M $4000,0,0 }
Procedure Switch_Cursor(c:boolean);
var r: registers;
begin
 r.ax:=$0100;
 if c then r.cx:=$0506 else r.cx:=$2607;
 intr($10,r);
end;

function IntToStr(I: Longint): String;
var  S: string[11];
begin
  Str(I, S);
  IntToStr := S;
end;

procedure abort;
begin
  switch_cursor(true);
  clrscr;
  writeln('ASM-PINBALL is not able to run');
  halt(1);
end;

procedure decode_paras;
var i:byte;
begin
  val(params,i,code);
  if I and 64 = 64 then tables:=2   else tables:=1;
  if i and 32 = 32 then music:=1    else music:=0;
  if i and 16 = 16 then highres:=1  else highres:=0;
  if i and  8 =  8 then overscan:=1 else overscan:=0;
  player:=i and 7;
end;

procedure code_paras;
var i:byte;
begin
  i:=0;
  if tables  = 2 then i:=i or 64;
  if music   = 1 then i:=i or 32;
  if highres = 1 then i:=i or 16;
  if overscan= 1 then I:=i or  8;
  i:=I or player;
  params:=IntToStr(i);
end;

  var a : string;

begin
  CheckBreak := False;
  path:=paramstr(0);
  a := paramstr(1);
  for hilfsb := 1 to length(paramstr(1)) do
      a[hilfsb] := upcase(a[hilfsb]);
  hilfsb:=0;
  while pos('\',copy(path,length(path)-hilfsb,1))=0 do inc(hilfsb);
  path:=(copy(path,1,length(path)-hilfsb-1));
  if a <> '-NOINTRO' then begin
      swapvectors;
      Exec(path+'\INTRO.EXE',paramstr(1));
      swapvectors;
      if DosExitCode <> 100 then begin
           writeln('Intro konnte nicht geladen werden.');
           halt(0);
         end;
    end;
  highres:=0;
  music:=1;
  player:=1;
  tables:=2;
  overscan:=1;
  repeat
    code_paras;
    switch_cursor(false);
    swapvectors;
      Exec(path+'\FLIPPERM.EXE', 'START '+params);
    swapvectors;
    if doserror<>0 then abort;
    code:=DosExitCode;
    params:=IntToStr(Code);
    decode_paras;
    if player>0 then begin
      params:=inttostr(highres+overscan*2)+
              inttostr(music)+inttostr(player);
      switch_cursor(false);
      swapvectors;
        Exec(path+'\FlIpPer'+inttostr(tables)+'.EXE', params+' ');
      swapvectors;
      if doserror<>0 then abort;
    end;
  until player=0;
  switch_cursor(true);
end.