{---------------------------------------------------------------------------}
procedure Init_ball_values;
begin
  {ballx := 300; bally := 160;
  ballspeed_y:=-80; ballspeed_x:=2; kraft := 250;}
  ballx := 300; bally := 500+20;
  get_ground_auto;
  draw_ball_auto;
  bx_old := 300; by_old := 500+20;
  ballspeed_y := 0;
  ballspeed_x := 0;
  kraft := 0;
  play(snd8);
end;

procedure Init_All;
var y : byte; ch:char; t : word;
    param : string;
begin
  param := paramstr(1);
  OldFileMode := FileMode;
  FileMode := 0;
  ch := param[1];
  case ch of
    '0' : begin overscan := false; highres := false; end;
    '1' : begin overscan := false; highres := true; end;
    '2' : begin overscan := true; highres := false; end;
    '3' : begin overscan := true; highres := true; end;
    else halt(2);
  end;
  VideoMode := ch;
  ch := param[2];
  case ch of
     '1' : UseSound:=yes;
     '0' : UseSound:=no;
    else halt(2);
  end;
  ch := param[3];
  case ch of
    '1','2','3','4','5','6' : begin
        MaxPlayer := ord(ch)-48;
        writeln(Maxplayer);
      end;
    else halt(2);
  end;

  getfont;
  nosound;
  init_random;
  OldHeapSize := memavail;
  mark(OldHeapLimit);
  getmem(tableground1,320*200);
  getmem(tableground2,320*200);
  getmem(tableground3,320*200);
  getmem(led_display,80*24*2);
  getmem(arm_links,ArmBreiteLinks*ArmHoeheLinks*5);
  getmem(arm_rechts,ArmBreiteRechts*ArmHoeheRechts*5);
  getmem(arm_links_msk,ArmBreiteLinks*ArmHoeheLinks*5);
  getmem(arm_rechts_msk,ArmBreiteRechts*ArmHoeheRechts*5);
  getmem(ball,256);
  getmem(ground,256);
  getmem(ball_sprite,256);
  getmem(underground,1024);
  getmem(tableground,9368);
  getmem(feder,480);
  ledseg:=seg(Led_display^);
  armlinksseg:=seg(arm_links^);
  armrechtsseg:=seg(arm_rechts^);
  armlinks_mskseg:=seg(arm_links_msk^);
  armrechts_mskseg:=seg(arm_rechts_msk^);
  ballseg:=seg(ball^);
  groundseg:=seg(ground^);
  ballspriteseg:=seg(ball_Sprite^);
  undergroundseg:=seg(underground^);
  tablegroundseg:=seg(tableground^);
  federseg:=seg(Feder^);
  led_hoehe:=24; led_color_1:=129; led_color_2:=130; led_funktion:=0;
  {twix-mode 320x400 }
  vga320x400Overscan; {setlinecomp(400-46);}

  load_table_tab;
  load_table_gro;
  load_feder;
  FederY:=400+205;
  FederHoehe:=40;
  Set_Feder;
  bally := 50;
  calc_page_pos_of_ballpos;
  init_colors;

       load_mini_palette('gfx\feder'+tnr+'.mpa');
  load_arm_links;
  load_arm_rechts;
  load_arm_links_msk;
  load_arm_rechts_msk;
  load_ball;

  arm_links_old_status:=2;
  arm_rechts_old_status:=2;
  arm_links_status:=1;
  arm_rechts_status:=1;
  for y:=0 to 255 do mem[groundseg:y]:=0;
  ballx:=50; bally:=260; get_ground_auto; bx_old:=50; by_old:=260;
  if UseSound then init_soundkit;
  {show led}
  LED_anzeige_1;
  {normal position}
  Case VideoMode of
    '2' : NormalPos := 400-led_hoehe*2+7;
    '0' : NormalPos := 400-led_hoehe*2+7;
    '3' : NormalPos := 400-led_hoehe+3;
    '1' : NormalPos := 400-led_hoehe+3;
  end;
  CurrentPos := 400;
  bende := false;
  Actplayer := 1;
  for t := 1 to 6 do begin
      Balls[t] := 1;
      Score[t] := 0;
    end;
  ruetteln := 0;
  {**********}
  draw_arm_links; draw_arm_rechts;
  if HighRes then
      for bally := 50 to 350 do begin
           retrace; calc_page_pos_of_ballpos;
         end
     else for bally := 50 to 560 do begin
              retrace; calc_page_pos_of_ballpos;
            end;
  init_ball_values;
end;

procedure Close_all;
begin
  nosound;
  Release(OldHeapLimit);
  video_mode(3);
  if OldHeapSize <> memavail then begin
      writeln('Achtung Heapmanipulationen waren nicht erfolgreich!');
      readkey;
    end;
  FileMode := OldFileMode;
end;
{---------------------------------------------------------------------------}
