{$N+,A+,G+,F+,D-,E-,L-,R-,S-,Q-,Y-}
unit loadscr1;

interface

procedure loadscreen_open;
procedure loadscreen_close;


implementation
uses global, screen, memory, palette;

var
r,g,b:byte;
aantal, x,y:word;
h,s1,s2,s3:single;


procedure loadscreen_open;
begin

clear_palette2memW(palette1, seg_palitra, ofs_palitra);

setonecolor2memW(16,32,32,42, palette2, seg_palitra,ofs_palitra);{}

{reset gradient of progressbar}
for x:=255-31 to 255 do setonecolor2memW(x,0,0,0, palette2, seg_palitra,ofs_palitra);{}

init_pal2pal(seg_palitra, ofs_palitra);
palette_process[0]:=1;

WaitVR;
for x:=0 to 255 do setonecolor(x,0,0,0);
FlipScreen(vaddr,VGA);{}

repeat {fade in}
WaitVR;
if palette_process[0]=1 then  Pal2Pal_asm(palette_process[0], 0, 255, 2, seg_palitra, ofs_palitra);
until palette_process[0]=0;

readonecolor(16, r,g,b);
end;


procedure fallblock(x1,y1, x2,y2:word; s:single; where:word);
var vcx,vdi,vsi:word;
begin
   vcx:=(x2-x1) shr 2 +1;
   for y:=y2 downto round(y1+s) do
     begin
          vdi:=y*320 + x1;
          vsi:=round(y-s)*320 + x1;
          asm
          mov ax, where
          mov es, ax
          db $8E,$E0 {mov fs, ax}
          mov si, vsi
          mov di, vdi
          mov cx, vcx {for x:=0 to (235-80) shr 2 do}
          db $64; db $66; rep movsw {meml[vaddr:(x shl 2+80)+y*320]:=meml[vaddr:(x shl 2+80)+round(y-s1)*320];}
          end;
     end;
end;


procedure loadscreen_close;
var vsi,vdi:word;
begin

{for y:=26 to 77 do for x:=80 to 235 do mem[vaddr:x+y*320]:=mem[vaddr:x+y*320]+4;
for y:=81 to 121 do for x:=80 to 235 do mem[vaddr:x+y*320]:=mem[vaddr:x+y*320]+4;
for y:=125 to 167 do for x:=80 to 235 do mem[vaddr:x+y*320]:=mem[vaddr:x+y*320]+4;}

s1:=0;s2:=0;s3:=0;
Aantal:=0;

repeat

if aantal<36 then begin
   s1:=s1+0.08;
   fallblock(80, 25, 235, 77, s1, vaddr);
end;

if (aantal>25) and (aantal<56) then begin
   s2:=s2+0.09;
   fallblock(80, 80, 235, 121, s2, vaddr);{}
end;

if (aantal>48) and (aantal<80) then begin
   s3:=s3+0.09;
   fallblock(80, 124, 235, 167, s3, vaddr);{}

end;

WaitVR;{}
FlipScreen(vaddr,VGA);{}
Inc(Aantal);
until (aantal>84) ;

for y:=26 to 167 do for x:=80 to 235 do mem[vga:x+y*320]:=16;


end;


end.