program waveblur;

uses crush13h,crt;

var c:char;
    x,y:integer;
    count1,add1:integer;


var aaa,ccc,ccc2,counter:integer;
    cccc: array [0..9] of integer;

begin
     video_mode ( $13);
     initvirt;

     loadpcx ('wave.pcx',vp[2]);
     loadpcx ('image50_.pcx',vp[1]);

     count1:=0;
     add1:=1;

     repeat

      count1:=count1+add1;
      if count1>255 then add1:=-1;
      if count1<0 then add1:=1;

{      move(mem[vp[1]:0],mem[vga:0],64000);}

        for x:=1 to 318 do for y:=1 to 198 do
         begin
          cccc[0]:=mem[vp[2]:x+y*320];
          cccc[1]:=mem[vp[1]:(x+1)+(y+1)*320];
          cccc[2]:=mem[vp[1]:(x)+(y+1)*320];
          cccc[3]:=mem[vp[1]:(x-1)+(y+1)*320];
          cccc[4]:=mem[vp[1]:(x+1)+(y)*320];
          cccc[5]:=mem[vp[1]:(x)+(y)*320];
          cccc[6]:=mem[vp[1]:(x-1)+(y)*320];
          cccc[7]:=mem[vp[1]:(x+1)+(y-1)*320];
          cccc[8]:=mem[vp[1]:(x)+(y-1)*320];
          cccc[9]:=mem[vp[1]:(x-1)+(y-1)*320];

          if cccc[0]<count1-50 then
           begin
                  ccc2:=0;
                  for aaa:=1 to 9 do ccc2:=ccc2+cccc[aaa];
                  ccc:=trunc(ccc2 div 9);
           end;

          if cccc[0]<count1 then if cccc[0]>count1-50 then
             ccc:=((cccc[2]+cccc[4]+cccc[5]+cccc[6]+cccc[8]) div 5);

          if cccc[0]<count1+50 then if cccc[0]>count1 then
             ccc:=(((cccc[2]+cccc[4]+cccc[6]+cccc[8]) div 4) + cccc[5]) div 2;

          if cccc[0]>count1+50 then
             ccc:=0;

          mem[vga:x+y*320]:=ccc;
         end;

      if keypressed=true then c:=readkey;
     until c=#27;

     closevirt;
     video_mode ( 03);
end.