
program testtmap;
uses crt,gfx3,tmap2,m3d52;
var l1,ode:integer;
    l2:word;
    ok:boolean;
    rndmatrix:pointer;


Procedure SetUpVirtual;
   { This sets up the memory needed for the virtual screen }
BEGIN
  GetMem (VirScr,64000);
  vaddr := seg (virscr^);
    GetMem (VirScr2,64000);
  vaddr2 := seg (virscr2^);
   GetMem (VirScr3,64000);
  vaddr3 := seg (virscr3^);
END;

{컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴컴}
Procedure ShutDown;
   { This frees the memory used by the virtual screen }
BEGIN
  FreeMem (VirScr,64000);
  freemem(virscr2,64000);
    freemem(virscr3,64000);
END;


Procedure MotionClear(Var D; Step : Byte); Assembler;
Asm
  Les  di,D
  Mov  bl,Step
  Mov  cx,64000
 @Looper:
  Mov al,es:[di]
  Sub al,bl
  Jns @SkipZero
  Mov al,0
 @SkipZero:
  Mov es:[di],al
  Inc di
  Dec  cx
  Jnz @Looper
End;


{$i tflip}

begin
  setupvirtual;
  setmcga;
  Getmem (RndMatrix,4100);
SetupRNDMatrix (seg(RndMatrix^),8);
                              { ^ -> max value}

  tsetup('room.euv');
  setup('sphere.euv');

 {lpcx('remap2.pcx',vaddr3);}


 {half palete for the room and half for the mirror}
  tset1map('remap3.pcx',2,vaddr);

     for l1:=1 to 128 do
       getpal(l1*2,palar[l1,1],palar[l1,2],palar[l1,3]);

{  setuprefpal;}
   lpcx('remap3.pcx',vaddr3);
   for l2:=1 to 63999 do {reduce colors    }
      mem[vaddr3:l2]:=(mem[vaddr3:l2] div 2)+128;

     for l1:=1 to 128 do
       getpal(l1*2,palar[l1+128,1],palar[l1+128,2],palar[l1+128,3]);
   for l1:=1 to 255 do pal(l1,palar[l1,1],palar[l1,2],palar[l1,3]);


  l1:=0;
  tzoff:=-50;
  zoff:=-550;
  td:=0.5;
  d:=2;
  cls(vaddr2,0);
  ambient:=20;
  con:=64;
  RANDOMIZE;
  ode:=l1;
  ad1:=0;
  ad2:=20;
  ad3:=30;
  ok:=false;
  repeat

    l1:=(l1+3) mod (360);

    trotatepoints2(l1,l1,0);
    tshowtext(vaddr);

    rotatepoints2(l1,l1,0);
    showpolys(100,vaddr2);

    phongit(vaddr2,vaddr3);
{    flip(vaddr2
    ,sega000);}

{NOISE4(VADDR2);}
{    asmfade(virscr);}

{    flip(vaddr2,SEGA000);}
{     for l2:=1 to 63999 do begin
       if mem[vaddr2:l2]>0 then mem[sega000:l2]:=mem[vaddr2:l2]
       else mem[sega000:l2]:=mem[vaddr:l2];
     end;}
     trndflip16 (vaddr2,vaddr,seg(rndmatrix^),random($ff));
     flip32(vaddr2,sega000);
     {     if zoff>=-300 then ok:=true;
     if (zoff>-700) and (ok) then begin
       zoff:=zoff-5;
       if tzoff>-50 then  tzoff:=tzoff+ 1;
     end;}



        cls32(vaddr2,0);
  until keypressed;
  tshutmap;
  tshut;
  shut;
  shutdown;
end.

