uses crt;
var x,y:Integer;								{counter and mouse coordinates}

Procedure magn_asm(zx,zy:Integer);external;
{draws the magnifying glass effect}
Procedure ReadGif;external;
{reads a 320x200x256 Gif image from "GifName"}
Procedure Setpal;external;
{sets the palette of the Gif image}

{$l magn.obj}
{$l gif}


type tbuffer=Array[0..199,0..319] of Byte;
{structure of image buffer 320x200}
Var buffer,backgnd:^tbuffer;    {Pointer to buffer and background}
  errorno:word;           	{Error message}
  gifname:String;               {Name, extended by #0}
  Circle_Start:Array[0..48] of Integer;	{Description of circle shape}
  Circle_End:Array[0..48] of Integer;

Procedure Prep_Circle;
{loads the Circle array}
var b:Word;
Begin
	For y:=0 to 48 do Begin								{calculate 49 rows}
  	b:=Trunc(Sqrt(Sqr(24)-Sqr(y-24)));   {Width= Sqrt(r^2-y^2)}
  	Circle_Start[y]:=24-b;               {Beginning of a row}
    Circle_End[y]:=49-Circle_Start[y];       {End of a row}
  End;
End;

Procedure Show_Buffer;		{displays buffer on screen}
Begin
	Move(Buffer^,Ptr($a000,0)^,64000);
End;

begin
  getmem(backgnd,64000);	{Get memory for background}
  getmem(buffer,64000);         {Get memory for image buffer}
  asm mov ax,13h; int 10h End;  {Set graphic mode 13h}
  asm mov ax,0; int 33h End;    {Reset mouse driver}

  GifName:='magn.gif'+#0;	{Define name of image}
  ReadGif;                      {Read Gif image}
  move(buffer^,backgnd^,64000); {save as background}
  SetPal;                       {Set palette}
  Prep_Circle;

  repeat
    asm
      mov ax,0003h              {Function 03h: read absolute coordinates}
      int 33h                   {Get mouse coordinates}
      mov x,cx                  {save in variables}
      mov y,dx
    End;
        if y>200-49 Then y:=200-50;{check variables}
  	if x>320-49 Then x:=320-50;
    move(backgnd^,buffer^,64000); {Background to buffer}
    magn_asm(x,y);             {Draw magnifying glass}
    Show_Buffer;               {and put on screen}
  Until KeyPressed;            {until key pressed}
  TextMode(3);                 {Set text mode}
End.
