{컴컴컴컴컴컴컴컴커}
{ june'97 by Cazz �}
{컴컴컴컴컴컴컴컴켸}
{$A+,B-,D-,E-,F-,G+,I-,L-,N-,O-,P-,Q-,R-,S-,T-,V-,X+}
{$M 2048,0,655360}
unit part4;

     interface

procedure dopart4;

     implementation

uses vga256,pcx,keyboard,misc,timer,midas;

const      width:array[0..41] of byte=(
15,11,16,14,15,14,14,14,14,14,7,9,8,10,7,13,15,15,13,16,13,12,17,17,8,13,
16,12,20,17,19,15,18,15,12,13,15,15,22,19,14,15);

const      message:string='                    AS YOU CAN SEE THERE ARE NO '+
           'GFX ARTISTS                                                    ';

var  scr,r:pointer;
     a,b:integer;
     palet:palette;
     _siin,_coos:array[0..511] of integer;
     c:byte;
     cnnn:word;
     offs:array[0..41] of word;
     myfont:pointer;
     textbuf:pointer;
     chrcnt:byte;    { counts width in char }
     chrpos:byte;    { counts pos in string }
     ll,lc,rid,angle:word;
     notext:boolean;

procedure uhhuu(p:longint;q:longint;s:word);
var       _dx,dy,dxd:longint;
          u1,v1:longint;
          y,x:longint;
          off:word;
          txtoff:word;
begin
  dy:=65536 div (200-p);
  dxd:=p shl 10 div (200-p);
  u1:=-p shl 10;
  v1:=q shl 8;
  off:=p*320;
  s:=byte(s)*1024;
  asm
      mov di,off
      mov ax,vidseg
      mov es,ax
  end;
  for y:=p to 199 do
    begin
      _dx:=(256-u1 shr 7) shl 8 div 320;
      asm
        mov bx,word ptr u1
        mov cx,word ptr v1
        add bx,s
        mov dx,word ptr _dx
        push ds
        lds si,r

        push bp

            mov bp,160
@innerloop2:
            mov cl,bh
            mov si,cx
            add bx,dx
            mov cl,bh
            mov al,ds:[si]
            mov si,cx
            add bx,dx
            mov cl,bh
            mov ah,ds:[si]
            mov es:[di],ax
            add di,2

            dec bp
            jnz @innerloop2

        pop bp

        pop ds
      end;
      u1:=u1+dxd;
      v1:=v1+dy;
    end;
end;

procedure uhhuu2(p:longint;q:longint;s:word);
var       _dx,dy,dxd:longint;
          u1,v1:longint;
          y,x:longint;
          off:word;
          txtoff:word;
begin
  dy:=65536 div p;
  dxd:=-p shl 10 div p;
  u1:=0;
  v1:=q shl 8;
  off:=0;
  s:=byte(s)*1024;
  asm
      mov di,off
      mov ax,vidseg
      mov es,ax
  end;
  for y:=0 to p-1 do
    begin
      _dx:=((256-u1 shr 7) shl 8 div 320);
      asm
        mov bx,word ptr u1
        add bx,s
        mov cx,word ptr v1
        mov dx,word ptr _dx
        push ds
        lds si,r

        push bp

            mov bp,160
@innerloop2:
            mov cl,bh
            mov si,cx
            add bx,dx
            mov cl,bh
            mov al,ds:[si]
            mov si,cx
            add bx,dx
            mov cl,bh
            mov ah,ds:[si]
            mov es:[di],ax
            add di,2

            dec bp
            jnz @innerloop2

        pop bp

        pop ds
      end;
      u1:=u1+dxd;
      v1:=v1+dy;
    end;
end;

procedure uhhuu3(q:longint;s:word);
var       _dx,dy,dxd:longint;
          u1,v1:longint;
          y,x:longint;
          off:word;
          txtoff:word;
begin
  dy:=655;
  dxd:=1024;
  u1:=-102400;
  v1:=q shl 8;
  off:=32000;
  s:=byte(s)*1024;
  asm
      mov di,off
      mov ax,vidseg
      mov es,ax
  end;
  for y:=100 to 199 do
    begin
      _dx:=(256-u1 shr 7) shl 8 div 320;
      asm
        mov bx,word ptr u1
        mov cx,word ptr v1
        add bx,s
        mov dx,word ptr _dx
        push ds
        lds si,r

        push bp

            mov bp,160
@innerloop2:
            mov cl,bh
            mov si,cx
            add bx,dx
            mov cl,bh
            mov al,ds:[si]
            mov si,cx
            add bx,dx
            mov cl,bh
            mov ah,ds:[si]
            mov es:[di],ax
            add di,2

            dec bp
            jnz @innerloop2

        pop bp

        pop ds
      end;
      u1:=u1+dxd;
      v1:=v1+dy;
    end;
{ duplicate }
  asm
    push ds
    mov ax,vidseg
    mov ds,ax
    mov es,ax
    mov si,32000
    mov di,31680
    mov bx,100
@next:
    mov cx,80
    db 66h; rep movsw
    sub di,640
    dec bx
    jnz @next
    pop ds
  end;
end;

procedure textscan;
var       l:byte;
          off,bo:word;
          d,l_in_f:byte;
begin
  if chrpos>length(message) then exit;
{ make it scroll }
  ll:=(cnnn div 2-ll);
  if (ll>1) and (chrpos>1) then begin notext:=true; exit end;
  asm
    push es
    push ds
    les di,textbuf
    lds si,textbuf
    inc si
    db 66h; mov cx,320*19/4-1
    dw 0; db 66h; rep movsw
    pop ds
    pop es
  end;
  l_in_f:=255;
  if (message[chrpos]<='9') and (message[chrpos]>='0') then
    l_in_f:=ord(message[chrpos])-48
  else if (message[chrpos]<='Z') and (message[chrpos]>='A') then
    l_in_f:=ord(message[chrpos])-65+16;
  if l_in_f<>255 then
    begin
{ next scanline }
      off:=offs[l_in_f]+chrcnt*19;
      bo:=ofs(textbuf^)+319;
      for d:=0 to 18 do
        begin
          mem[seg(textbuf^):bo]:=mem[seg(myfont^):off]+192;
          inc(off);
          inc(bo,320);
        end;
      inc(chrcnt,ll);
      if chrcnt>=width[l_in_f] then
        begin
          inc(chrpos);
          chrcnt:=0;
        end;
    end
  else
    begin
      bo:=ofs(textbuf^)+319;
      for d:=0 to 18 do
        begin
          mem[seg(textbuf^):bo]:=192;
          inc(off);
          inc(bo,320);
        end;
      inc(chrcnt,ll);
      if chrcnt>=10 then
        begin
          inc(chrpos);
          chrcnt:=0;
        end;
    end;
  asm
    push es
    push ds
    lds si,textbuf
    mov ax,0a000h
    mov es,ax
    mov di,90*320
    mov cx,320*19
@nextone:
    mov al,ds:[si]
    cmp al,192
    jz @no
    mov es:[di],al
@no:
    inc si
    inc di
    dec cx
    jnz @nextone
    pop ds
    pop es
  end;
  ll:=cnnn div 2;
end;

procedure rotozoomer(x0,y0,xx,xy,yx,yy:longint;src,dest:pointer);
external; {$L roto.obj}
procedure rotozoomer2(x0,y0,xx,xy,yx,yy:longint;src,dest:pointer);
external; {$L roto2.obj}

procedure pre1;far;
begin
  if rid<4 then angle:=angle+2;
  if angle>511 then
    begin
      angle:=0;
      if rid<4 then rid:=rid+1;
    end;
end;

procedure pre2;far;
begin
  inc(cnnn,2);
  dec(c,2);
end;

procedure pre3;far;
begin
  dec(cnnn,4);
  dec(c,2);
end;

procedure init;
var       cnt:integer;
begin
  for cnt:=0 to 511 do
    begin
      _siin[cnt]:=round(sin(cnt*pi/256)*256);
      _coos[cnt]:=round(cos(cnt*pi/256)*256);
    end;
  getmem(r,65535);
  fillchar(palet,768,0);
  initpalette(palet);
  load_pcx_datafile(7,256,seg(r^),ofs(r^),true);

  getmem(scr,65535);
  clear(0,seg(scr^));
  vidseg:=$a000;
  clear(0,vidseg);
{ load&init font }
  getmem(myfont,index[9,2]);
  loaddata(myfont,9);
  offs[0]:=ofs(myfont^);
  for a:=1 to 41 do
    offs[a]:=offs[a-1]+width[a-1]*19;
  getmem(textbuf,320*19);
  fillchar(textbuf^,320*19,192);
  chrpos:=1;
  chrcnt:=0;
  initkey;
end;

procedure dopart4;
var     frame:longint;
        xmid,ymid:longint;
        txmid,tymid:longint;
        zoomx,zoomy:longint;
        zoomxd,zoomyd:longint;
        curx,cury:longint;
        an:byte;
        zoom:real;
begin
  init;
  frame:=0;
{ int 1 }
  errnr:=tmrSyncScr(scrsync,@pre1,@immVR,nil);
  if errnr<>0 then midaserror(errnr);
  repeat
    if (frame<=128) and (frame mod 2=0) then
      begin
        for a:=0 to 255 do
          begin
            if palet[a,1]<pal[a,1] then inc(palet[a,1]);
            if palet[a,2]<pal[a,2] then inc(palet[a,2]);
            if palet[a,3]<pal[a,3] then inc(palet[a,3]);
          end;
        initpalette(palet);
      end;

    zoom:=exp(sin(angle*pi/256));
    zoomx:=round(_coos[angle]/zoom);
    zoomy:=round(_siin[angle]/zoom);
    zoomxd:=-_siin[angle];
    zoomyd:=_coos[angle];
    curx:=_siin[angle];
    cury:=-_coos[angle];

    rotozoomer(curx,cury,zoomx,zoomy,zoomxd,zoomyd,r,vidram);
    lfrm:=frm;
    repeat until frm>lfrm;
    inc(frame);
    if key[1] then begin over:=true; break; end;
  until (rid=4);
  if not over then
  repeat
    if zoomx<205 then inc(zoomx);
    if zoomx>205 then dec(zoomx);
    if zoomyd<329 then inc(zoomyd);
    if zoomyd>329 then dec(zoomyd);
    rotozoomer2(0,0,zoomx,0,0,zoomyd,r,vidram);
    if (zoomx=205) and (zoomyd=329) then break;
    if key[1] then begin over:=true; break; end;
  until false;
  cnnn:=0;
  c:=0;
{ int 2}
  vidseg:=seg(scr^);
  errnr:=tmrSyncScr(scrsync,@pre2,@immVR,nil);
  if errnr<>0 then midaserror(errnr);
  if not over then
  for a:=1 to 50 do
    begin
      lfrm:=frm;
      repeat until frm>lfrm;
      uhhuu(a*2,0,cnnn);
      uhhuu2(a*2,0,cnnn);
      page(scr,vidram);
      if key[1] then begin over:=true; break; end;
    end;
  c:=0;
  a:=0;
  notext:=false;
  if not over then
  repeat
    lfrm:=frm;
    repeat until frm>lfrm;
    uhhuu3(c,cnnn);
    page(scr,vidram);
    if not notext then textscan;
    if key[1] then begin over:=true; break; end;
    if notext then inc(a);
  until (chrpos>length(message)) or (notext and (a>500));
{ int 3}
  errnr:=tmrSyncScr(scrsync,@pre3,@immVR,nil);
  if errnr<>0 then midaserror(errnr);
  if not over then
  for b:=1 to 300 do
    begin
      lfrm:=frm;
      repeat until frm>lfrm;
      uhhuu3(-c,cnnn);
      page(scr,vidram);
      if key[1] then begin over:=true; break; end;
    end;
  if not over then
  for b:=0 to 63 do
    begin
      for a:=0 to 255 do
        begin
          if pal[a,1]>0 then dec(pal[a,1]);
          if pal[a,2]>0 then dec(pal[a,2]);
          if pal[a,3]>0 then dec(pal[a,3]);
        end;
      initpalette(pal);
      lfrm:=frm;
      repeat until frm>lfrm;
      uhhuu3(-c,cnnn);
      page(scr,vidram);
      if key[1] then begin over:=true; break; end;
    end;
  disabkey;
  freemem(textbuf,320*19);
  freemem(myfont,index[9,2]);
  freemem(scr,65535);
  freemem(r,65535);
end;

end.