program landscape;

uses crush13h,crt;

var land:array [0..24,0..24] of integer;
    f:text;
    x,y:integer;
    c:char;
    a:array [0..24] of integer;

begin
     assign (f,'land.dat');
     reset (f);

     for y:=0 to 24 do
         begin
              for x:=0 to 24 do
                  begin
                       read (f, land[x,y]);
                  end;
         end;

     close (f);

     video_mode ( $13);
     initvirt;
     repeat
      cls (0,vp[1]);
      for y:=0 to 24 do for x:=0 to 24 do putpixel ( x*10,y*5-land[x,y],land[x,y],vp[1]);
      move(mem[vp[1]:0],mem[vga:0],64000);
      waitvbl;
      if keypressed=true then
         begin
              c:=readkey;
              if c=#75 then
                 begin
                      for y:=0 to 24 do a[y]:=land[0,y];
                      for x:=0 to 24 do for y:=0 to 24 do land[x,y]:=land[x+1,y];
                      for y:=0 to 24 do land[24,y]:=a[y];
                 end;
              if c=#77 then
                 begin
                      for y:=0 to 24 do a[y]:=land[24,y];
                      for x:=24 downto 0 do for y:=24 downto 0 do land[x,y]:=land[x-1,y];
                      for y:=0 to 24 do land[0,y]:=a[y];
                 end;
              if c=#80 then
                 begin
                      for x:=0 to 24 do a[x]:=land[x,24];
                      for x:=24 downto 0 do for y:=24 downto 0 do land[x,y]:=land[x,y-1];
                      for x:=0 to 24 do land[x,0]:=a[x];
                 end;
              if c=#72 then
                 begin
                      for x:=0 to 24 do a[x]:=land[x,0];
                      for x:=0 to 24 do for y:=0 to 24 do land[x,y]:=land[x,y+1];
                      for x:=0 to 24 do land[x,24]:=a[x];
                 end;
         end;
     until c=#27;
     closevirt;
     video_mode ( 03);
end.