Program Spaghetti;

uses crt,lines;

const
    time=1000;
    maxx=319;

var
   x,y,z,x1,y1,z1,n,m,my,a,b,hop,i   : integer;
   yminalt,ymaxalt                   : integer;
   q,w,e,afram,gafram,g1             : integer;
   ee,segg,off,count                 : integer;
   hnit                              : array[1..820,1..3] of integer;
   hnit1                             : array[1..820,1..3] of integer;
   cosg,sing                         : array[1..362] of integer;
   mynd                              : array[1..870,1..3] of integer;
   hopp                              : array[1..100] of integer;
   pall,pall1                        : array[1..900] of byte;
   r                                 : real;
   p,back                            : pointer;
   lin                               : longint;


procedure plot(x,y:integer; c:byte );
begin
     if (y<ymaxalt) and (y>yminalt) then mem[$a000:x+y*320]:=c;
end;
procedure inpall;
begin
     for n:=0 to 300 do
         if pall1[n]<pall[n] then inc(pall1[n]);
end;

procedure setpallet(sem,offf:integer);
begin
     for n:=7 to 55 do
         begin
              port[$3c8]:=n;
              port[$3c9]:=mem[sem:offf+n*3-3];
              port[$3c9]:=mem[sem:offf+n*3-2];
              port[$3c9]:=mem[sem:offf+n*3-1];
         end;
end;

procedure utscreen;
begin
     for n:=0 to maxx do
         begin
              plot(n,count-time,0);
              plot(n,count-time+1,2);
         end;
     for n:=0 to maxx do
         begin
              plot(n,200-(count-time),0);
              plot(n,200-(count-time)-1,2);
         end;
     yminalt:=count-time;
     ymaxalt:=200-yminalt;
end;

begin
     yminalt:=0;
     ymaxalt:=200;
     for n:=1 to 362 do
         begin
              cosg[n]:=round(100*cos(n*pi/180));
              sing[n]:=round(100*sin(n*pi/180));
         end;
     m:=20;
     for n:=1 to m do
          begin
               hnit[n,1]:=70*cosg[n*9] div 100;
               hnit[n,2]:=70*sing[n*9] div 100;
               hnit[n,3]:=1;
          end;
     asm
        mov ax,13h
        int 10h
     end;
     
     z1:=0;
     my:=0;
  repeat
     z1:=z1+10;
     for n:=1 to m do
         begin
              hnit1[n,2]:=hnit[n,2]*cosg[z1] div 100 - hnit[n,3]*sing[z1] div 100;
              hnit1[n,1]:=hnit[n,1];
              hnit1[n,3]:=hnit[n,2]*sing[z1] div 100 + hnit[n,3]*cosg[z1] div 100;
         end;
     for n:=1 to m do
         begin
              inc(my);
              for y1:=1 to 3 do
                  mynd[my,y1]:=hnit1[n,y1];
         end;
  until z1=360;

     for n:=-25 to 25 do                      { hopp formula }
         hopp[n+25]:=n*n div 10;

     for n:=0 to 75 do                         { palletta }
         pall[n]:=round(n*63/75);
      for n:=76 to 149 do
         pall[n]:=63-round((n-76)*63/75);
      for n:=150 to 300 do
          pall[n]:=pall[n-150+1];
      for n:=0 to 100 do
          pall[n*3+2]:=0;
      for n:=0 to 320 do
          pall1[n]:=0;
      segg:=seg(pall1);
      off:=ofs(pall1);
      asm
        mov ax,1012h
        mov bx,7
        mov cx,49
        mov dx,segg
        mov es,dx
        mov dx,off
        int 10h
     end;
     y:=140;
     i:=1;
     for m:=0 to 100 do
         begin
              y:=y+1;
              for n:=m to maxx do
                  begin
                       if i=50 then
                          begin
                               if x=4 then x:=15 else x:=4;
                               i:=1;
                          end;
                       inc(i);
                       plot(n,y,i+5);
                  end;
         end;

     for m:=0 to 1 do
         for n:=0 to 319 do
             plot(n,1+m*198,2);
     getmem(back,64000);
     for lin:=0 to 64000 do
         mem[seg(back^):lin]:=mem[$a000:lin];
     
      z1:=0;
      m:=20*36;
      afram:=170;
      hop:=0;
      g1:=1;
      r:=1;
      ee:=2;
      count:=0;
  repeat
      if count >150 then
         if count < 150+2*64 then
           if count mod 2=0 then inpall;
      inc(count);
      off:=off+15;
      setpallet(segg,off);
      z1:=z1+2;
      inc(hop);
      r:=r+1.3;
      g1:=round(r);
      afram:=afram+ee;
      for n:=1 to m do
          begin
               q:=(mynd[n,1]*cosg[z1] -mynd[n,2]*sing[z1]) div 100;
               e:=mynd[n,3];
               w:=(mynd[n,1]*sing[z1] + mynd[n,2]*cosg[z1]) div 100;
               hnit1[n,1]:=afram+(q*cosg[g1] + e*sing[g1]) div 100;
               hnit1[n,2]:=w+hopp[hop]+50;
               hnit1[n,3]:=(-q*sing[g1]  + e*cosg[g1]) div 100;
          end;
      sinc;
      for n:=1 to m do
          begin
               if hnit[n,3] > 0 then
               plot (hnit[n,1],hnit[n,2],mem[seg(back^):hnit[n,1]+hnit[n,2]*320]);
               if hnit1[n,3] > 0 then
               plot (hnit1[n,1],hnit1[n,2],97);
          end;
          for a:=1 to m do
              for b:=1 to 3 do
                  hnit[a,b]:=hnit1[a,b];
              if afram>320-80 then ee:=-round(random*6);
              if afram<100 then ee:=round(Random*6);
              if z1=360 then z1:=0;
              if hop=50 then hop:=1;
              if r>360 then r:=1;
              if afram=320+70 then afram:=-70;
              if off>=ofs(pall1)+150 then off:=ofs(pall1);
              if count>time then utscreen;
  until count=time+160;
     asm
        mov ax,3
        int 10h
     end;
     port[$3c8]:=7;
     port[$3c9]:=35;
     port[$3c9]:=0;
     port[$3c9]:=62;
     write(' HALi                                            address: skapti@rvik.ismennt.is');
end.
