Uses Crt,Gfx3;

Var I:Word;

VAR Virscr2 : VirtPtr;                     { Our first Virtual screen }
    Vaddr2  : word;                        { The segment of our virtual screen}
   Virscr3 : VirtPtr;                     { Our first Virtual screen }
    Vaddr3  : word;                        { The segment of our virtual screen}
    Cx,Cy:Array[0..320] of Word;

Procedure ASmooth(Where:Word);assembler;
Var M:Word;
Asm
 Mov Es,Where
 Xor Di,Di
 Xor Ah,ah
 Xor bh,bh
 Xor Ch,Ch
 Xor Dh,Dh
 @MainLoop:
  Inc Di
  Dec Di
  Mov Al,Es:[Di]
  Add Di,2
  Mov Bl,Es:[Di]
  Add Di,320
  Mov Cl,Es:[Di]
  Sub Di,2
  Mov Dl,Es:[Di]
  Sub Di,319
  Mov M,Ax
  Add M,Bx
  Add M,Cx
  Add M,Dx
  Shr M,2
  Mov Ax,M
  Cmp Al,2
  Jl  @donot
  Sub Al,2
  @Donot:
  Mov Es:[Di],Al
  Xor Ah,Ah

  Cmp Di,63678
 Jne @MainLoop
End;



Procedure Scale;
Var X,Y:Integer;
    O,Co:Word;
    Temp:Byte;
Begin
 For Y:=0 to 199 do
  Begin
   o:=Y*320;
   Co:=Cy[y]*320;
   For X:=0 To 319 Do
    Begin
     Temp:=Mem[Vaddr:Co+Cx[X]];
     Mem[Vaddr2:O+x]:=Temp+Mem[Vaddr3:Co+Cx[X]+Temp];
    End;
  End;
End;

Procedure GetPallete(Fil:String;Where:Word);
Var TCol:Byte;
    Pale:Array[1..3,0..255] of Byte;
Begin
 LPcx(Fil,Where);
 For TCol:=0 to 160 do
   GetPal(Getpixel(160-TCol,100,Where),Pale[1,TCol],Pale[2,TCol],Pale[3,TCol]);
 For TCol:=0 to 160 do
  Pal(TCol,Pale[1,160-TCol],Pale[2,160-TCol],Pale[3,160-TCol]);
End;




Begin
 SetMCGA;
 SetUpVirtual;
 GetMem (VirScr2,64000);
 vaddr2 := seg (virscr2^);
 GetMem (VirScr3,64256);
 vaddr3 := seg (virscr3^);
 For i:=0 to 64255 do Mem[Vaddr3:i]:=Random(7);
 For I:=0 to 320 do
  Begin
   Cx[i]:=Round(23.7+0.85*i);
   Cy[i]:=Round(14+0.85*i);
  End;
  If ParamCount<>0 Then
   Begin
    If ParamStr(1)='2' Then GetPallete('Amumap3.pcx',vaddr)
     Else Lpcx('Amumap5.pcx',vaddr);
   End
    Else
      For i:=0 to 255 do Pal(i,i shr 3,i shr 2,i shr 3);
 Pal(255,0,0,0);
 Cls32(Vaddr,0);
 Cls32(Vaddr2,0);

 Repeat
  Scale;
  Flip32(Vaddr2,Vaddr);
  Flip32(Vaddr2,Sega000);
  ASmooth(Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);

  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);
  Putpixel(155+Random(20),90+Random(20),255,Vaddr);

  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
  Putpixel(150+Random(20),90+Random(20),(255),Vaddr);
 Until Keypressed;
 FreeMem (VirScr2,64000);
 FreeMem (VirScr3,64256);
 ShutDown;
 SetText;
End.