{ FLIPPERM.PAS   - (c) Ansgar Scherp, Joachim Gelhaus
  All right reserved / vt'95

  MAIN MENU

  }

program FLIPPER_MAIN_MENU;
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';

const rahmen1:byte = 35;
      rahmen2:byte = 36;
      menucolor  :array[1..6] of byte=(95,96,97,98,99,100);
      playercolor:array[1..6] of byte=(101,102,103,104,105,106);
      Kreuz      :array[1..3] of byte=(35,36,107);

var auswahl:byte;
    ch:byte;
    ende:boolean;
    auswahlcolor,auswahlrichtung:byte;
    tables,highres,overscan,music:byte;
    minis:array[1..2] of pointer;
    miniseg:array[1..2] of word;
    I:word;
    player:byte;
    path:string;
    hilfsb:byte;
    params:string;
    code:integer;
{$I _NORMVGA.PAS}

procedure SET_PAL0;
begin
  port[$3c8] := 0;
  port[$3c9]:=pal[0,1]; port[$3c9]:=pal[0,2]; port[$3c9]:=pal[0,3];
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 DISPLAY_ANSI;
var f:file;
    buffer:array[1..4000] of byte;
    b:byte;
    z:word;
    mfm:word;
begin
  mfm:=filemode;
  filemode:=0;
  assign(f,'menu\menu.end');
  reset(f,1);
  blockread(f,buffer,4000,z);
  close(f);
  filemode:=mfm;
  for z:=1 to 4000 do mem[$b800:z-1]:=buffer[z];
end;

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

procedure Go_out_of_here;
begin
  for i:=1 to 2 do FreeMem(minis[i], 82*151);
  video_mode(3);
{STANDART-DOS-FONT}
 (* asm
  push ax
  push es
  push bp
  {}
  mov ax,1130h; mov bh,1; int 10h; {mov Fseg,es; mov Fofs,bp;}
  push es
  push bp
  {}
  mov ax,1100h
  mov bx,1000h
  mov cx,0100h
  mov dx,0000h
  pop es
  pop bp
  lea bp,[es:bp]
  int 10h
  {}
  pop bp
  pop es
  pop ax
  end;*)
  Display_ansi;
  gotoxy(1,16);
end;


procedure set_menu_color;
begin
  retrace;
  for i:=1 to 6 do set_rgb_color(menucolor[i],37,0,0);
  if highres=1 then set_rgb_color(kreuz[1],23,40,10)
               else set_rgb_color(kreuz[1],0,0,32);
  if overscan=1 then set_rgb_color(kreuz[2],23,40,10)
                else set_rgb_color(kreuz[2],0,0,32);
  if music=1 then set_rgb_color(kreuz[3],23,40,10)
             else set_rgb_color(kreuz[3],0,0,32);
  for i:=1 to 6 do set_rgb_color(playercolor[i],20,0,0);
  set_rgb_color(playercolor[player],37,0,0);
  if auswahl = 5 then set_rgb_color(playercolor[player],23,40,10);
end;

procedure load_mini(mininr:byte;fname:string);
var f:file;
    mfm:word;
begin
  mfm:=filemode;
  filemode:=0;
  assign(f,fname+'.MIN');
  reset(f,1);
  blockread(f,minis[mininr]^,filesize(f));
  close(f);
  filemode:=mfm;
end;

procedure init_alles;
begin

  getmem(minis[1],82*151);
  getmem(minis[2],82*151);
  miniseg[1]:=seg(minis[1]^);
  miniseg[2]:=seg(minis[2]^);
  load_mini(1,'MENU\MENU1');
  load_mini(2,'MENU\MENU2');
  ende:=false;
  video_mode($13);
  palette_black;
  load_palette('MENU\menu1');
  load_mini_palette('MENU\menu2');
  set_rgb_color(rahmen1,0,0,0);
  set_rgb_color(rahmen2,0,0,0);
  set_rgb_color(kreuz[1],0,0,32);
  set_rgb_color(kreuz[2],63,63,0);
  set_rgb_color(kreuz[3],63,63,0);
  SET_PAL0;
  load_vga('MENU\menu1');
  auswahl:=1;
  params:=paramstr(2);
  decode_paras;
{  tables:=0;
  highres:=0;
  music:=1;
  player:=1;
  overscan:=1;}
  auswahl:=1;
  params:=paramstr(2);
  decode_paras;
  set_menu_color;
  set_rgb_color(menucolor[auswahl],0,60,0);
  PutSprite(212,24,150,82,miniseg[tables]);
end;

procedure starte_flipper;
var paras:string;
begin
  for i:=1 to 2 do FreeMem(minis[i], 82*151);
  video_mode(3);

  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;
  halt(i);
end;

procedure display_help;
var ch:char;
begin
  video_mode($13);
  palette_black;
  load_palette('MENU\MENU3');
  load_vga('MENU\MENU3');
  repeat until keypressed;
  while keypressed do ch:=readkey;
  video_mode($13);
  palette_black;
  load_palette('MENU\menu1');
  load_mini_palette('MENU\MENU2');
  set_menu_color;
  set_rgb_color(menucolor[auswahl],0,60,0);
  SET_PAL0;
  load_vga('MENU\MENU1');
  i:=24;
  Scroll(212,24,212,27,i-24,82);
  putSprite(212,i,174-i,82,miniseg[tables]);

end;

begin
  CheckBreak := False;
  path:=paramstr(0);
  hilfsb:=0;
  while pos('\',copy(path,length(path)-hilfsb,1))=0 do inc(hilfsb);
  path:=(copy(path,1,length(path)-hilfsb-1));
  chDir(path);
  if (paramcount <> 2) or (paramstr(1) <> 'START') then
  begin halt(0); end;

  init_alles;
  repeat
    repeat
      set_menu_color;
      set_rgb_color(menucolor[auswahl],23,40,10);
      repeat until keypressed;
      ch:=ord(readkey);
      if ch=0 then begin
        ch:=ord(readkey);
        if ch=59 then display_help;
        if ch=80 then if auswahl<6 then inc(auswahl) else auswahl:=1;
        if ch=72 then if auswahl>1 then dec(auswahl) else auswahl:=6;
      end;
      if ch=27 then ende:=true;
    until (ch=13) or (ch=32) or (ende);
    if not ende then
    begin
      if auswahl=1 then
      begin
        tables:=tables xor 3;
        for i:=174 downto 24 do
        begin
          retrace;
          Scroll(212,24,212,27,i-24,82);
          putSprite(212,i,174-i,82,miniseg[tables]);
          dec(i,4);
          if i<24 then i:=24;
        end;
      end;
      if auswahl=2 then highres:=highres xor 1;
      if auswahl=3 then overscan:=overscan xor 1;
      if auswahl=4 then music:=music xor 1;
      if auswahl=5 then if player<6 then inc(player) else player:=1;
      if auswahl=6 then starte_flipper;
    end;
  until ende;
  go_out_of_here;
  halt(128);
end.


