{***********************************************************************}
{									}
{ __MakeWin   Construct a new window record				}
{									}
{ function  __MakeWin(X1,Y1,X2,Y2,					}
{		      TopScan,BotScan,Fore,Back,			}
{		      BorType,BorFore,BorBack : byte): _WindowPtr;	}
{									}
{	      X1,Y1	Upper left corner of window, X1 is the column	}
{			number and Y1 is the row number.		}
{	      X2,Y2	Lower right corner of window, X2 is the column	}
{			number and Y2 is the row number.		}
{	      TopScan,BotScan						}
{			Cursor scan lines for the window cursor.	}
{	      Fore,Back Text attributes within the window.		}
{	      BorType	Border type (see __BoxScn). A value of 255	}
{			specifies no border.				}
{	      BorFore,BorBack						}
{			Border foreground and background attributes.	}
{									}
{ Description This function  constructs a new _Window record.		}
{	      The doubly linked list of _Window records describes all	}
{	      windows defined.	Three global _Window pointers aid in	}
{	      the maintenance and use of the list:  _WinRoot points	}
{	      to the first record in the list and is initialized to	}
{	      NIL by the procedure __InitWin.  WinLast_ points to	}
{	      the last _Window record in the list, and _WinCur points	}
{	      to the record of the window currently active (that is,	}
{	      last displayed with __DispWin function or made current	}
{	      with the __CurWin function).				}
{									}
{	      If the pointer to the root of the linked list of windows	}
{	      is NIL, it is set to point to the new record.  The	}
{	      pointer to the end of the list is altered to point to the }
{	      new record, and the previous records pointers are updated.}
{	      The cursor, border and window attributes are set to the	}
{	      values specified in the parameters. The function returns	}
{	      the pointer to the new window record.			}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc.  1987		}
{_______________________________________________________________________}

function  __MakeWin(X1,Y1,X2,Y2,
		    TopScan,BotScan,Fore,Back,
		    BorType,BorFore,BorBack : byte) : _WindowPtr;

  var
    NewWindowPtr : _WindowPtr;

  begin {__MakeWin}

    { First check that the parameters are meaningful, and alter them if }
    { they are not.							}

    if (X1 < 1) then
       X1 := 1
    else if (X1 > Pred(_CurColumns)) then  { Provide room for right	}
       X1 := Pred(_CurColumns); 	   { boundary.			}
    if (Y1 < 1) then
       Y1 := 1
    else if (Y1 > _CurRows) then
       Y1 := _CurRows;
    if (X2 < Succ(X1)) then
       X2 := Succ(X1)
    else if (X2 > _CurColumns) then
       X2 := _CurColumns;
    if (Y2 < Y1) then
       Y2 := Y1
    else if (Y2 > _CurRows) then
       Y2 := _CurRows;

    { Now we construct the new record and adjust all pointers.		}

    New(NewWindowPtr);
    with NewWindowPtr^ do
      begin
	if (_WinRoot = NIL) then       { This is the first window	}
	   begin		       { definition.			}
	     _WinUnder := NIL;
	     _WinCur   := NIL;	       { Since this is first record,	}
	     _WinRoot  := NewWindowPtr { initialize current pointer.	}
	   end
	else
	   begin
	     _WinUnder	       := WinLast_;
	     WinLast_^._WinTop := NewWindowPtr
	   end;
	WinLast_ := NewWindowPtr;
	_WinTop  := NIL;
	with _Dim do
	  begin
	    _XUpper := X1;
	    _YUpper := Y1;
	    _XLower := X2;
	    _YLower := Y2
	  end;
	_XCursor := 1;		       { Initially cursor at home	}
	_YCursor := 1;		       { position.			}
	_TopScan := TopScan;
	_BotScan := BotScan;
	_Fore	 := Fore;
	_Back	 := Back;
	with _Title do
	  _TitleStr := '';	       { Initialize as none requested.	}
	with _Border do 	       { If the dimensions do not pro-	}
	  if ( (X1 = 1) or	       { enough room for a border, set	}
	       (X2 = _CurColumns) or   { the border type to -1,i.e., no }
	       (Y1 = 1) or	       { border at all. 		}
	       (Y2 = _CurRows)) then
	     _BorType := _NOBORD_WIN
	  else
	     begin
	       _BorType := BorType;
	       _BorFore := BorFore;
	       _BorBack := BorBack
	     end;
	if (_Border._BorType = _NOBORD_WIN) then
	   _ImageSize := (X2 - X1 + 1) * (Y2 - Y1 + 1) * SizeOf(_ScnPos)
	else
	   _ImageSize := (X2 - X1 + 3) * (Y2 - Y1 + 3) * SizeOf(_ScnPos);
	_Image	:= NIL; 	       { The window is not active yet,	}
	_Active := FALSE	       { so no screen image is saved.	}
      end;  {with NewWindowPtr^}

    __MakeWin := NewWindowPtr

  end;	{__MakeWin}
