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

interface

procedure scene_wirth;

implementation

uses global, math2, screen, resource, memory, palette, chunky;


var
Aantal, T1, start_time, old_time,elapsed_time:word;
qsub, qsub2, q, rand_value, speed, speed_pal:word;
n, stage, tip:byte;

procedure scene_wirth;
begin
Clear(0, 65535, vaddr2);
Clear(0, 65535, vaddr3);

LoadBinUnpack('wirth.bin',  {load->}vaddr,{-unpack->}vaddr3,  0);
Clear(0, 65535, vaddr);

LoadBin('mask_w.bin',  vaddr2,  0);
LoadBin('wirth.pal', seg_palitra,  ofs_palitra+palette2);
LoadBin('wirth2.pal', seg_palitra,  ofs_palitra+palette1);

init_pal2pal(seg_palitra,ofs_palitra);

mem2mem(seg_palitra,ofs_palitra+palette1, vaddr,0, 1536);


Midas_WaitVR;
setpalette_from_memW(palette2,seg_palitra,ofs_palitra);
palette_process[0]:=1;
speed_pal:=16;

tip:=1;
stage:=0;
Logo_mode:=0;
Logo_clear[0]:=0; Logo_Fill[0]:=0;


qsub2:=mtimer;

Aantal:=0; T1:=mTimer;
old_time:=mtimer;
start_time:=mtimer;

repeat
q:=mtimer-start_time;
elapsed_time:=(mtimer-old_time);
old_time:=mtimer;

if (elapsed_time>0) or (aantal=0) then begin

      MP^.GetInformation(@info);

      if (stage=0) and (music_pos(73,28)) then begin
          tip:=0;
          stage:=1;
          Logo_clear[0]:=0; Logo_Fill[0]:=0;
          LoadBin('mask_w.bin',  vaddr2,  0);
          qsub:=q;
      end;
      if (stage=1) and (music_pos(73,36)) then begin
          stage:=2;
          clear_palette2memW(palette2, seg_palitra, ofs_palitra);
          init_pal2pal(seg_palitra,ofs_palitra);
          palette_process[0]:=1;
          speed_pal:=3;
      end;

      speed:=abs(round(sin_((q-qsub)/55)*12)+1);
end;



if Vsync_mode=1 then Midas_WaitVR;{}


if stage<2 then
 if (mtimer-qsub2 > rand_value) then begin {blink effect}
      qsub2:=mtimer;
      rand_value:=random(3)*5+1;
      mem2mem(vaddr,0, seg_palitra,ofs_palitra+palette1, 1536);
      palette_process[0]:=1;
     end;


if palette_process[0]=1 then Pal2Pal_asm(palette_process[0], 0, 255, elapsed_time*speed_pal, seg_palitra,ofs_palitra);


Draw_Logo(Logo_fill[0], Logo_clear[0], tip{tip},
logo_mode, 1{fade size}, 2{cell_size},  0{color}, 0{pos}, 0{pos2},
4000 shr 2{size}, elapsed_time*speed, vaddr2{mask}, vaddr3{texture}, vga{output});{}


Inc(Aantal);
if FPS_Mode=1 then WriteFps(100, mtimer, T1, Aantal, vga);

until (esc_test) or ((stage=2) and (palette_process[0]=0));
end;


end.