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

interface

procedure init_credits;
procedure scene_credits;

implementation

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

const
pattern64: array[0..8*8-1] of byte =
( 0,48,12,60, 3,51,15,63,
  32,16,44,28,35,19,47,31,
  8,56, 4,52,11,59, 7,55,
  40,24,36,20,43,27,39,23,
  2,50,14,62, 1,49,13,61,
  34,18,46,30,33,17,45,29,
  10,58, 6,54, 9,57, 5,53,
  42,26,38,22,41,25,37,21);

type
  rgb = record
  r,g,b : byte;
  end;

var
Aantal, T1, start_time, old_time, elapsed_time:word;
y,x1,x2,y1,y2:integer;
pos, dd, xx,yy1,yy2:integer;
f, q_, sub_q, vdi, vbp, q, mapseg, n, height,vsi, offs,p,m:word;
glitch_num, glitch_on, c, hei_p, monster_pal, speed_pal, start_pal,end_pal, stage, regim,r,g,b, blink, h, blink_num:byte;
qq:single;
bg_color, logo1_size,logo2_size,logo1,logo2, bitl,manwe, soundtrack, codegfx:word;
jump_on:array[0..2] of integer;
p_col, bg_color_bitl, bg_color_bitl2, bg_color_manwe, bg_color_manwe2:rgb;
glitch:word;

s:string;

procedure blur(where:word);assembler;
asm
mov es, where
mov si, 640 *60
dec si
mov dx, 100 -60
@y:
mov cx, 160
@x:
mov al, es:[si]
add al, es:[si+3]
add al, es:[si+321]
add al, es:[si+320*2+1]
shr al, 2

mov ah, al
mov es:[si+1], al
mov es:[si+3], al
mov es:[si+321], ax {; mov es:[si+322],al}

add si, 2
dec cx
jnz @x
add si, 320
dec dx
jnz @y
end;

procedure shift(where:word);assembler;
asm
mov es, where
mov di, 640  *60
mov dx, 100  -60
@y:
   mov cx, 160
   @x:
     mov al, es:[di+640]
     mov ah, al
     mov es:[di-1], al
     mov es:[di], ax     {;mov es:[di+1], al}
     mov es:[di+320], al
     add di, 2
   dec cx
   jnz @x
add di, 320
dec dx
jnz @y
end;

procedure random_dots_bottom(seek, where:word);assembler;
asm
mov es, where
xor di, di

{in ax, 40h  {seek}
mov ax, seek
test ax, ax
jnz @j
   inc ax
@j:

mov cx, 160
@x:{for x:=0 to 159 do begin}

mov bx, ax   {col:=random(63);}
shl ax, 3
xor bx, ax
mov ax, bx
sar ax, 7
xor bx, ax
mov ax, bx
shl ax, 2
xor bx, ax
mov ax, bx
and bl, 63

mov bh, bl
mov es:[di+320*198], bx   {mem[vaddr:n+320*198]:=col;}
{mov es:[di+320*198+1], al {mem[vaddr:n+320*198+1]:=col;}
mov es:[di+320*199], bx   {mem[vaddr:n+320*199]:=col;}
{mov es:[di+320*199+1], al {mem[vaddr:n+320*199+1]:=col;}
add di, 2 {inc(n,2);}
dec cx
jns @x{end;}
end;



procedure main_draw(bgcolor:word);
var n, bgcolor_:word;
begin
q_:=q*10;

{--------------------------top dither part--------------------------}
if yy2>0 then
for y:=0 to yy2-1 do begin

   if glitch_on>0 then glitch:=(y and 8) shl 8 else glitch:=0;

   if f=0 then n:=word(glitch+integer(memw[vaddr2:64000 +( (q_ -y shr 1) and 511) shl 1]) div 3  +(128)+q shl 10)
   else n:=word(glitch+integer(memw[vaddr2:64000 +( (q_ shr 1 -y) and 511) shl 1]) shl 8  +q shl 8 + 32);

   if y<100 then begin mapseg:=vaddr2; offs:=0; end else
     begin mapseg:=vaddr3; offs:=100; end;

   dd:=yy2-y; {height gradient for dither}
   if dd<0 then dd:=0;
   if dd>64 then dd:=64;

   if y<200 then
   asm
   push 0a000h
   pop es
   mov ax, vaddr
   db $8e,$e0 {mov fs, ax}
   mov ax, y

   mov dx, ax
   and dx, 7
   shl dx, 3

   mov dh, byte ptr dd

   mov bx, n
   mov cs:[offset @n1+3], bx
   mov cs:[offset @n2+3], bx
   mov bx, bgcolor
   mov cs:[offset @bg_color+1], bx
   jmp @clear_prefetch; @clear_prefetch:

   mov bx, offs
   push ds
   push bp
   mov ds, mapseg
   imul di, ax, 320
   sub ax, bx
   imul bp, ax, 640
   mov cx, 320
   @x:{for x:=0 to 319 do begin}
      @bg_color: mov ax, 2727h

      {bayer:= pattern[(x and 7)+(y and 7)*8];}
      mov bx, cx
      and bx, 7
      add bl, dl
      mov bx, ds:[bx+65535-64]

      db $66; mov si, ds:[bp]

      cmp bl, dh
      jbe @skip1
         @n1: db $64; mov al, [si+1234h]
      @skip1:

      cmp bh, dh
      jbe @skip2
         db $66; shr si, 16
         @n2: db $64; mov ah, [si+1234h]
      @skip2:

      mov es:[di], ax {mem[vga:y*320+x]:=mem[tuntexseg:word(m)];}

      add di, 2
      add bp, 4
   sub cx, 2
   jnz @x
   pop bp
   pop ds
   end;
end;


{--------------------------main part-----------------------------}
y2:=199-yy1;

if yy2<100 then vbp:=yy2*640 else vbp:=(yy2-100)*640;
vdi:=yy2*320;

if (y2>=0) and (yy2<200) then
for y:=yy2 to y2 do begin

   if glitch_on>0 then glitch:=((y and 8) shl 8) else glitch:=0;

   if f=0 then n:=word(glitch+integer(memw[vaddr2:64000 +( (q_ -y shr 1) and 511) shl 1]) div 3  +(128)+q shl 10)
   else n:=word(glitch+integer(memw[vaddr2:64000 +( (q_ shr 1 -y) and 511) shl 1]) shl 8  +q shl 8 +32);

   if vbp>=64000 then vbp:=0;

   if y<100 then mapseg:=vaddr2 else mapseg:=vaddr3;
   asm
   push 0a000h
   pop es
   mov ax, vaddr
   db $8e,$e0 {mov fs, ax}
   mov si, n
   mov dx, vbp
   mov di, vdi
   push ds
   push bp
   mov ds, mapseg
   mov bp, dx
   mov cx, 80/4
   @x:{for x:=0 to 319 do begin}
      {m:=memw[vaddr2:(y*320+x) shl 1]+n}
      db $66; mov bx, ds:[bp+4]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; shl ax, 16
      db $66; mov bx, ds:[bp]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; mov es:[di], ax

      db $66; mov bx, ds:[bp+4 +8]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; shl ax, 16
      db $66; mov bx, ds:[bp   +8]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; mov es:[di       +4], ax

      db $66; mov bx, ds:[bp+4 +16]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; shl ax, 16
      db $66; mov bx, ds:[bp   +16]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; mov es:[di       +8], ax

      db $66; mov bx, ds:[bp+4 +24]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; shl ax, 16
      db $66; mov bx, ds:[bp   +24]
      db $64; mov al, [si+bx]
      db $66; shr bx, 16
      db $64; mov ah, [si+bx]
      db $66; mov es:[di       +12], ax

      add di, 4*4
      add bp, 8*4
   dec cx
   jnz @x
   pop bp
   pop ds
   end;

vbp:=vbp+640;
vdi:=vdi+320;

end;


{--------------------------bottom dither part--------------------------}
if yy1>199 then y1:=yy1-200 else y1:=0;

y2:=y2+1;
if y2<0 then y2:=0;

if y2<200 then
for y:=y2 to 199 do begin

   if glitch_on>0 then begin
      glitch:=(y and 8) shl 8;
      if (-q shl 1 +y) and 8>0 then bgcolor_:=$0303 else bgcolor_:=bgcolor;
      end
   else
      begin
      glitch:=0;
      bgcolor_:=bgcolor;
      end;

   if f=0 then n:=word(glitch+integer(memw[vaddr2:64000 +( (q_ -y shr 1) and 511) shl 1]) div 3  +(128)+q shl 10)
   else n:=word(glitch+integer(memw[vaddr2:64000 +( (q_ shr 1 -y) and 511) shl 1]) shl 8  +q shl 8  +32);

   if y<100 then begin mapseg:=vaddr2; offs:=0; end else
     begin mapseg:=vaddr3; offs:=100; end;

   dd:=y - y2 + y1; {height gradient for dither}
   if dd>63 then dd:=63;

   asm
   push 0a000h
   pop es
   mov ax, vaddr
   db $8e,$e0 {mov fs, ax}
   mov ax, y

   mov dx, ax
   and dx, 7
   shl dx, 3

   mov dh, byte ptr dd

   mov bx, n
   mov cs:[offset @n1+3], bx
   mov cs:[offset @n2+3], bx
   mov bx, bgcolor_
   mov cs:[offset @bg_color+1], bx
   jmp @clear_prefetch; @clear_prefetch:

   mov bx, offs
   push ds
   push bp
   mov ds, mapseg
   imul di, ax, 320
   sub ax, bx
   imul bp, ax, 640
   mov cx, 320
   @x:{for x:=0 to 319 do begin}
      @bg_color: mov ax, 2727h
      {bayer:= pattern[(x and 7)+(y and 7)*8];}
      mov bx, cx
      and bx, 7
      add bl, dl
      mov bx, ds:[bx+65535-64]

      db $66; mov si, ds:[bp]

      cmp bl, dh
      jbe @skip1
         @n1: db $64; mov al, [si+1234h]
      @skip1:

      cmp bh, dh
      jbe @skip2
         db $66; shr si, 16
         @n2: db $64; mov ah, [si+1234h]
      @skip2:

      mov es:[di], ax {mem[vga:y*320+x]:=mem[tuntexseg:word(m)];}

      add di, 2
      add bp, 4
   sub cx, 2
   jnz @x
   pop bp
   pop ds
   end;
end;
{------------------------------------------------------------------}

end;


procedure init_credits;
begin

{custom segments for logo's data}
bitl:=vaddr3+4000;      {148 byte}
codegfx:=bitl+10;       {360 byte}
manwe:=codegfx+23;      {268 byte}
soundtrack:=manwe+17;   {508 byte}
LoadBin('bitl2.bin',    bitl,  0);
LoadBin('codegfx.bin',  codegfx,  0);
LoadBin('manwe2.bin',   manwe,  0);
LoadBin('soundtrk.bin', soundtrack,  0);

for n:=0 to 63 do mem[vaddr3:n +65535-64]:=pattern64[n];
for n:=0 to 63 do mem[vaddr2:n +65535-64]:=pattern64[n];
for n:=0 to 511 do memw[vaddr2:n shl 1 +64000]:=integer(round(sin_(6.283185307/512 *n)*128));{}


end;



function jump1(var jump_this:integer; d, speed:single):single;
var jump:single;
begin
  jump:= sin((q-jump_this)/speed)*d;
  if jump<0 then begin jump_this:=0; jump:=0;end;
  jump1:=jump;
end;



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

LoadBinUnpack('fanta1.bin',  {load->}vaddr2,{-unpack->}vaddr,  0);
LoadBin('fanta1.pal', seg_palitra,  ofs_palitra+palette2);
setonecolor2memw(254, 50,50,50,  palette2, seg_palitra, ofs_palitra);

LoadBin('cred2_1.bin', vaddr2, 0);
LoadBin('cred3_1.bin', vaddr3, 0);

init_credits;

bg_color_bitl.r :=9;  bg_color_bitl.g:=11; bg_color_bitl.b:=14;
bg_color_bitl2.r:=4;  bg_color_bitl2.g:=12; bg_color_bitl2.b:=22;

bg_color_manwe.r:= 8; bg_color_manwe.g :=8;  bg_color_manwe.b :=13;
bg_color_manwe2.r:=14; bg_color_manwe2.g:=8;  bg_color_manwe2.b:=16;




for n:=1 to 254 do setonecolor2memW(n,50,50,50, palette1, seg_palitra,ofs_palitra);
init_pal2pal(seg_palitra,ofs_palitra);
palette_process[0]:=1;
palette_process[1]:=1;

Midas_WaitVR;
Clear(1, 64000, vga);
setpalette_from_memW(palette1,seg_palitra,ofs_palitra);



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

hei_p:=8;
monster_pal:=0;
blink_num:=0;
glitch_num:=0;
jump_on[0]:=0; jump_on[1]:=0; jump_on[2]:=0;
speed_pal:=5;
start_pal:=0;
end_pal:=64;
bg_color:=$fefe;
regim:=0;
glitch_on:=0;
stage:=0;
f:=0;


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) then begin
   qq:=q/50;
   yy2:=round(cos(qq)*132+132);
   yy1:=0;
   if (monster_pal=0) and (info^.pos>19) and (info^.row > 45) then
         begin
           if (glitch_num=0) then begin inc(glitch_num); jump_on[2]:=q; end;
          {
           LoadBin('mostr3.pal', seg_palitra,  ofs_palitra+palette2);}
           setonecolor2memw(254, bg_color_bitl.r,bg_color_bitl.g,bg_color_bitl.b,  palette2, seg_palitra, ofs_palitra);
           setonecolor2memw(254, bg_color_bitl.r,bg_color_bitl.g,bg_color_bitl.b,  palette1, seg_palitra, ofs_palitra);
           setonecolor(254, bg_color_bitl.r,bg_color_bitl.g,bg_color_bitl.b);

           {init_pal2pal(seg_palitra,ofs_palitra);
           palette_process[0]:=1; palette_process[1]:=1;}
           speed_pal:=16;
           monster_pal:=1;
         end;


   if (sin(qq)<0) then stage:=1;
end;

if (stage=1) then if {q>200} (info^.pos > 20) and (info^.row > 6) then begin stage:=2; sub_q:=q; end;

if (stage=2) then begin
   qq:=(q-sub_q)/40;
   yy2:=0;
   yy1:=round(-cos(qq)*132+132);
   if (sin(qq) < 0) then stage:=3;
end;

if (stage=3) then begin {bitl screen init}
   r:=bg_color_bitl.r; g:=bg_color_bitl.g; b:=bg_color_bitl.b;

   LoadBinUnpack('bitl3.bin',  {load->}vaddr,{-unpack->}vaddr2,  0);
   LoadBin('bitl3.pal',  seg_palitra,  ofs_palitra+palette1);
   setonecolor2memw(254,r,g,b,  palette1, seg_palitra, ofs_palitra);
   for n:=64 to 64+16+16 do setonecolor2memw(n,r,g,b,  palette1, seg_palitra, ofs_palitra);

   clear(0, 65535, vaddr);
   setpalette_from_memW(palette1,seg_palitra,ofs_palitra);
   Midas_WaitVR;

   FlipScreen(vaddr2, vga);
   for n:=1 to 63 do setonecolor2memw(n,23,43,53,  palette2, seg_palitra, ofs_palitra);
   for n:=64 to 64+16 do       setonecolor2memw(n,1,1,1,   palette2, seg_palitra, ofs_palitra);
   for n:=(65+16) to (65+16+16) do
        setonecolor2memw(n, bg_color_bitl2.r,bg_color_bitl2.g,bg_color_bitl2.b,  palette2, seg_palitra, ofs_palitra);


   init_pal2pal(seg_palitra,ofs_palitra);
   start_pal:=1; end_pal:=64+16+16; speed_pal:=2;
   palette_process[0]:=0;

   logo1:=bitl;    Logo1_size:=148;
   logo2:=codegfx; Logo2_size:=360;

   q:=mtimer-start_time; sub_q:=q;
   elapsed_time:=0;
   old_time:=mtimer;

   stage:=4; regim:=1;
end;


if (stage=4) and (q-sub_q>160) then begin palette_process[0]:=1; stage:=5; end;


if (stage=5) then if q-sub_q>280 then begin
   for n:=1 to 254 do
       setonecolor2memw(n,bg_color_bitl2.r,bg_color_bitl2.g,bg_color_bitl2.b,  palette2, seg_palitra, ofs_palitra);
   init_pal2pal(seg_palitra,ofs_palitra);
   palette_process[0]:=1;
   start_pal:=1; end_pal:=64+16+16; speed_pal:=5;
   stage:=6; q:=mtimer-start_time; sub_q:=q;
   end;


if (stage=6) then if palette_process[0]=0 then begin

   LoadBinUnpack('fanta2.bin',  {load->}vaddr2,{-unpack->}vaddr,  0);
   LoadBin('fanta2.pal', seg_palitra,  ofs_palitra+palette1);

   LoadBin('cred2_2.bin', vaddr2, 0);
   LoadBin('cred3_2.bin', vaddr3, 0);

   f:=1;

   setonecolor2memw(254,bg_color_bitl2.r,bg_color_bitl2.g,bg_color_bitl2.b,  palette1, seg_palitra, ofs_palitra);
   Midas_WaitVR;
   setpalette_from_memW(palette1,seg_palitra,ofs_palitra);
   Clear(254, 64000, vga);
   regim:=0; stage:=7; q:=mtimer-start_time; sub_q:=q;
end;

if (stage=7) then begin
   qq:=(q-sub_q)/50;
   yy1:=round(cos(qq)*132+132);
   yy2:=0;
   if (sin(qq)<0) then stage:=8;

   if (info^.pos > 22) then begin
       if (info^.row > 44) and (glitch_num=1) then begin inc(glitch_num); jump_on[2]:=q; end;
       if (info^.row > 52) and (glitch_num=2) then begin inc(glitch_num); jump_on[2]:=q; end;
       end;

   if (monster_pal=1) and (info^.pos > 23) and (info^.row > 0) then
         begin
{           LoadBin('monscont.pal', seg_palitra,  ofs_palitra+palette2);}
{           setonecolor2memw(254,bg_color_bitl2.r,bg_color_bitl2.g,bg_color_bitl2.b,  palette2, seg_palitra, ofs_palitra);
           init_pal2pal(seg_palitra,ofs_palitra);
           palette_process[0]:=1; palette_process[1]:=1;
           speed_pal:=128;}
           monster_pal:=2;
         end;
end;

if (stage=8) then begin
    if {q-sub_q>200} (info^.pos > 23) and (info^.row > 30) then
                     begin
                     stage:=9; sub_q:=q;
                     end;

    if (monster_pal=2) and (info^.pos > 23) and (info^.row > 6) then
         begin
           {LoadBin('fanta2.pal', seg_palitra,  ofs_palitra+palette2);}
           setonecolor2memw(254,bg_color_manwe.r,bg_color_manwe.g,bg_color_manwe.b,  palette2, seg_palitra, ofs_palitra);
           setonecolor2memw(254,bg_color_manwe.r,bg_color_manwe.g,bg_color_manwe.b,  palette1, seg_palitra, ofs_palitra);
           setonecolor(254,bg_color_manwe.r,bg_color_manwe.g,bg_color_manwe.b);

{           init_pal2pal(seg_palitra,ofs_palitra);
           palette_process[0]:=1; palette_process[1]:=1;}
           speed_pal:=16;
           monster_pal:=3;
         end;
end;

if (stage=9) then begin
   bg_color:=$fefe;
   qq:=(q-sub_q)/50;
   yy1:=0;
   yy2:=round(-cos(qq)*133+133);
   if (sin(qq) < 0) then stage:=10;
end;

if (stage=10) then begin {manwe screen init}
   r:=bg_color_manwe.r; g:=bg_color_manwe.g; b:=bg_color_manwe.b;
   {clear(0, 65535, vaddr);}

   clear(254, 64000, vga);

   LoadBinUnpack('manwe3.bin',  {load->}vaddr,{-unpack->}vaddr2,  0);
   LoadBin('manwe3.pal',  seg_palitra,  ofs_palitra+palette1);

   setonecolor2memw(254,r,g,b,  palette1, seg_palitra, ofs_palitra);
   for n:=64 to 64+16+16 do setonecolor2memw(n,r,g,b,  palette1, seg_palitra, ofs_palitra);

   clear(0, 65535, vaddr);
   setpalette_from_memW(palette1,seg_palitra,ofs_palitra);
   Midas_WaitVR;

   FlipScreen(vaddr2, vga);
   for n:=1 to 63 do setonecolor2memw(n,53,23,43,  palette2, seg_palitra, ofs_palitra);
   for n:=64 to 64+16 do       setonecolor2memw(n,1,1,1,   palette2, seg_palitra, ofs_palitra);
   for n:=(65+16) to (65+16+16) do
        setonecolor2memw(n, bg_color_manwe2.r,bg_color_manwe2.g,bg_color_manwe2.b,  palette2, seg_palitra, ofs_palitra);

   init_pal2pal(seg_palitra,ofs_palitra);
   start_pal:=1; end_pal:=64+16+16; speed_pal:=2;
   palette_process[0]:=0;

   Logo1:=manwe;      Logo1_size:=268;
   logo2:=soundtrack; Logo2_size:=508;
   Logo_clear[0]:=0; Logo_Fill[0]:=0;
   Logo_clear[1]:=0; Logo_Fill[1]:=0;

   q:=mtimer-start_time; sub_q:=q; elapsed_time:=0; old_time:=mtimer;

   stage:=11; regim:=1;
end;


if (stage=11) and (q-sub_q>260) then begin palette_process[0]:=1; stage:=12; end;


if (stage=12) then if q-sub_q>360 then begin
   for n:=1 to 254 do
       setonecolor2memw(n,bg_color_manwe2.r,bg_color_manwe2.g,bg_color_manwe2.b,  palette2, seg_palitra, ofs_palitra);
   init_pal2pal(seg_palitra,ofs_palitra);
   palette_process[0]:=1;
   start_pal:=1; end_pal:=64+16+16; speed_pal:=5;
   stage:=13; q:=mtimer-start_time; sub_q:=q;
end;

if (stage=13) then
   if (palette_process[0]=0) then
      begin
        stage:=14;
        regim:=255;
      end;
end;{----------------------------------------------------------------------}






if (regim=0) then begin
          if Vsync_mode=1 then Midas_WaitVR;{}

          if Aantal and 1 = 0 then begin
             if palette_process[0]=1 then
             Pal2Pal_asm(palette_process[0], 0, 127, elapsed_time*speed_pal, seg_palitra,ofs_palitra);
             end
          else begin
             if palette_process[1]=1 then
             Pal2Pal_asm(palette_process[1], 128, 255, elapsed_time*speed_pal, seg_palitra,ofs_palitra);
             end;

          if (jump_on[2]>0) then glitch_on:=round(jump1(jump_on[2], 3, 5));

          Main_Draw(bg_color); {effect draw}
          end

else
if (regim=1) then begin      {credits draw}

          if (stage=4) or (stage=5) or (stage=11) or (stage=12) then begin
             if (info^.row > 44) and (info^.row<52) then if (blink_num=0) then begin hei_p:=8;inc(blink_num);jump_on[0]:=q;end;
             if (info^.row > 52) then if (blink_num=1) then begin hei_p:=8; inc(blink_num); jump_on[1]:=q; end;
             if (info^.row > 31) then if (blink_num=2) then begin hei_p:=2; inc(blink_num); jump_on[0]:=q; end;
             if (info^.row > 47) then if (blink_num=3) then begin hei_p:=8; inc(blink_num); jump_on[1]:=q;   end;
             if (info^.row > 0) and (info^.row<16) then if (blink_num=4) then begin hei_p:=2; blink_num:=0; jump_on[1]:=q;end;

          end;

          if (jump_on[0]>0) then blink:=round(jump1(jump_on[0], 3, 5));
          if (jump_on[1]>0) then blink:=round(jump1(jump_on[1], 3, 10));

          random_dots_bottom(aantal, vaddr);{}
          Blur(vaddr);{}
          Shift(vaddr);{}

          Midas_WaitVR;

          if (palette_process[0]=1) then
              Pal2Pal_asm(palette_process[0], start_pal, end_pal, speed_pal*elapsed_time, seg_palitra, ofs_palitra)
          else
          begin {poloski na bordure}

                for n:=0 to 15 do begin
                   c:=65+ (n+q) and 15;
                   readonecolor_from_memW(c, p_col.r,p_col.g,p_col.b, palette1,  seg_palitra, ofs_palitra);
                   if (n and hei_p = 0) then h:=blink else h:=0;
                   setonecolor(c, p_col.r, p_col.g+h, p_col.b+h);
                end;
          end;

          for n:=0 to 15 do begin {poloski na fone}
             c:=(65+16)+ (n+q) and 15;
             readonecolor_from_memW(c, p_col.r,p_col.g,p_col.b, palette1,  seg_palitra, ofs_palitra);
             if (n and hei_p = 0) then h:=blink else h:=0;
             setonecolor(c, p_col.r, p_col.g+h, p_col.b+h);
          end;

          pos:=30+320*56; {source buffer offset}

          Draw_Logo(Logo_fill[0], Logo_clear[0], 1{tip},
          logo_mode, 10{fade size}, 2{cell_size},  0{color}, 0{pos}, pos{pos2},
          logo1_size shr 2{size}, elapsed_time,   logo1{mask}, vaddr{texture}, vga{output});{}

          if (Logo_fill[0]>=logo1_size shr 2) then
          Draw_Logo(Logo_fill[1], Logo_clear[1], 1{tip},
          logo_mode, 5{fade size}, 1{cell_size},  0{color}, 0{pos}, pos{pos2},
          logo2_size shr 2{size}, elapsed_time,   logo2{mask}, vaddr{texture}, vga{output});{}

end;




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

{str(end_pal, s);
DrawString_6x6(s, 2, 15, 63, seg_font6x6_d,ofs_font6x6_d, vga);{}


until (esc_test) or (stage=14) or ((info^.pos > 26) and (info^.row > 16));


end;


end.