{***********************************************************************}
{									}
{ __GotoWin   Position the cursor in the current window 		}
{									}
{ procedure __GotoWin(X,Y : byte);					}
{									}
{	      X 	The row and column where the cursor is posi-	}
{	      Y 	tioned on the current display page.  The	}
{			position is set relative to the current 	}
{			window.  The rows (Y) are numbered 1 to 25, 43	}
{			or 50, and the columns are numbered 1 to 40 or	}
{			80. Y is the row number, and X is the column	}
{			number. 					}
{									}
{ Description This procedure sets the cursor to the position specified	}
{	      by Y and X.  __GotoWin differs from the Turbo Pascal	}
{	      intrinsic function GotoXY in that this procedure alters	}
{	      the cursor position on the current display page.	GotoXY	}
{	      only accesses page 0.  Note, however, that the current	}
{	      display page must equal the active page for the cursor	}
{	      to physically move.  Like GotoXY, movement is relative to }
{	      the current window (_CurWindow) .  Finally, the values	}
{	      of X and Y are forced to be reasonable values: if X is	}
{	      greater than the right edge of the window, the value is	}
{	      wrapped around to the left edge, and the row number	}
{	      increases.  If the resulting row number is greater than	}
{	      the bottom of the window, the row number wraps around to	}
{	      the top.							}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

procedure __GotoWin(X,Y : byte);

  var
    XOff,YOff	 : byte;
    Width,Height : byte;
    ExtraRows	 : byte;

  begin {__GotoWin}

    { First force the row and column values in the current window.	}

    with _CurWindow do
      begin
	XOff   := _XUpper - 1;
	YOff   := _YUpper - 1;
	Width  := _XLower - XOff;	     { Number of legal columns	}
	Height := _YLower - YOff;	     { Number of legal rows	}
      end;
    if (X < 1) then
       X := 1
    else if (X > Width) then
       begin
	 ExtraRows := (X - 1) div Width;
	 X	   := X - (ExtraRows * Width);
	 Y	   := Y + ExtraRows
       end;
    if (Y < 1) then
       Y := 1
    else if (Y > Height) then
       Y := ((Y - 1) mod Height) + 1;

    __GotoScn(X + XOff,Y + YOff)

  end;	{__GotoWin}
