program interlacemode;

uses crush13h,crt;

var c:char;
    a,x,y:integer;
    count:integer;

procedure copypage_l(y1:integer;from:word;y2:integer;too:word);
var a:integer;
begin
     for a:=y2 to y2+200 do
         begin
              if a>-1 then if a<200 then move(mem[from:320*(a-y2)],mem[too:320*a],320);
         end;
end;

procedure interlace(from1,from2:word;y2:integer;too:word);
var a:integer;
begin
     for a:=y2 to y2+200 do
         begin
              if a>-1 then if a<200 then
               if a mod 2 = 0 then move(mem[from1:320*(a-y2)],mem[too:320*a],320)
               else move(mem[from2:320*(a-y2)],mem[too:320*a],320);
         end;
end;

procedure interlace_2(from:word;y2:integer;too:word);
var a:integer;
begin
     for a:=y2 to y2+200 do
         begin
              if a>-1 then if a<200 then
               if a mod 2 = 0 then move(mem[from:320*(a-y2)],mem[too:320*a],320);
         end;
end;

procedure interlace_3(from:word;y2:integer;too:word);
var a:integer;
begin
     for a:=y2 to y2+200 do
         begin
              if a>-1 then if a<200 then
               if a mod 2 <> 0 then move(mem[from:320*(a-y2)],mem[too:320*a],320);
         end;
end;


begin
     video_mode ( $13);
     initvirt;

     cls (0,vp[1]);
     cls (0,vp[2]);
     loadpcx ('c:\ps\neopaint\pcx\claw2.pcx',vp[1]);

     {loadpcx ('c:\ps\neopaint\pcx\moia95.pcx',vp[2]);}
     count:=200;

     repeat

     count:=count+1;
     if count>200 then count:=-200;

     waitvbl;

     {if count mod 2 = 0 then copypage_l(0,vp[1],count,vga) else
     copypage_l(0,vp[2],count,vga);}

     interlace_3 (vp[1],count,vga);
     interlace_2 (vp[1],count *(-1),vga);


     if count>-1 then if count<200 then for x:=0 to 319 do putpixel (x,count,0,vga);
     if count>-200 then if count<0 then for x:=0 to 319 do putpixel (x,count+200,0,vga);

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

     closevirt;
     video_mode ( 03);
end.