{***********************************************************************}
{									}
{ __RetDvScn  Return the current video setting				}
{									}
{ function  __RetDvScn(var Mode,Cols,Rows,				}
{			   ActivePage,DisplayPage : byte) : byte;	}
{									}
{	      Mode	  The returned screen mode.  See __NewDvScn for }
{			  a description of the screen modes.		}
{	      Cols	  The number of columns on the screen		}
{	      Rows	  The number of rows on the screen		}
{	      ActivePage  The current page which is active		}
{	      DisplayPage The current display page			}
{									}
{ Description __RetDvScn returns the video mode information by making a }
{	      call to BIOS video routines, first subfunction $1B, and	}
{	      if that isn't supported to subfunction $0F.  The function }
{	      value returned is either _MONO (1) or _COLOR (2), depend- }
{	      ing on the screen mode and current video adapter in use.	}
{	      __RetDvScn initializes the following globally defined	}
{	      (in the unit Unit_Scn) variables: 			}
{									}
{	      _MaxDisplayPage	       Maximum display page number	}
{	      _CurActivePage	       Current video active page	}
{	      _CurColumns	       Current number of screen cols	}
{	      _CurRows		       Current number of screen rows	}
{	      _CurMode		       Current display mode		}
{	      _CurDevice	       _MONO or _COLOR			}
{	      _CurMonitor	       _MonoMonitor, _ColorMonitor, etc.}
{	      _ScnLoc		       Address of video adapter memory	}
{									}
{	      __RetDvScn also sets MaxScanLine_, (global to Unit_Scn's	}
{	      implementation section only).				}
{									}
{	      __RetDvScn can be used to initialize these variables	}
{	      rather than using __NewDvScn if you do not want to reset	}
{	      the video adapter.  In particular, if you do not want	}
{	      to clear the screen and reposition the cursor,		}
{	      __RetDvScn should be called rather than  __NewDvScn.	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

function  __RetDvScn(var Mode,Cols,Rows,
			 ActivePage,DisplayPage : byte) : byte;

  var
    Reg 	: registers;
    VBuf	: VParmBlock_;
    Int1BWorked : boolean;
    CharHeight	: word;

  begin {__RetDvScn}

    { First try new video BIOS call introduced with PS/2 machines and	}
    { video adapters.  If that function is unavailable, use $0F.	}

    if (__VInfoScn(VBuf)) then	       { Call BIOS and return pointer	}
       begin
	 Int1BWorked := TRUE;
	 CharHeight  := VBuf.VCharHeight_;
	 ActivePage  := VBuf.VActPage_;
	 Cols	     := VBuf.VCols_;
	 Rows	     := VBuf.VRows_;
	 Mode	     := VBuf.VMode_
       end
    else
       with Reg do
	 begin			       { Call BIOS, return video state. }
	   Int1BWorked := FALSE;
	   AX := $0F00;
	   Intr(_VIDEO,Reg);
	   Mode       := AL;
	   Cols       := AH;
	   ActivePage := BH
	 end;

    if (Mode = 7) then		       { Monochrome text mode	       }
       begin
	 _CurDevice := _MONO;
	 _ScnLoc    := Ptr($B000,$0000)
       end
    else if (Mode < 13) then	       { Color text or graphics mode	}
       begin
	 _CurDevice := _COLOR;
	 _ScnLoc    := Ptr($B000,$8000)
       end
    else			       { EGA/VGA graphics mode		}
       begin
	 if (Mode = 15) then
	    _CurDevice := _MONO
	 else
	    _CurDevice := _COLOR;
	 _ScnLoc := Ptr($A000,$0000)
       end;

    { Now determine Monitor attached to adapter 			}

    if ((_CurDevice = _HercAdapter) or (_CurDevice = _MonoAdapter)) then
       begin
	 _CurMonitor := _MonoMonitor;
	 CharHeight  := 14
       end
    else if (_CurDevice = _ColorAdapter) then
       begin
	 _CurMonitor := _ColorMonitor;
	 CharHeight  := 8
       end
    else if (_CurDevice = _EgaAdapter) then
       _CurMonitor := EgaMonitor_      { Initialized in __EquipScn	}
				       { CharHeight set below		}
    else if ((_CurDevice = _VgaAdapter) or
				       (_CurDevice = _McgaAdapter)) then
       _CurMonitor := AnalogMonitor_   { Initialized in __EquipScn	}
				       { CharHeight set above		}
    else
       _CurMonitor := _NoMonitor;

    if (Int1BWorked = FALSE) then
       begin
	 if (_EgaAdapter = _CurDevice) then { Have an EGA, so check for }
	    with Reg do 	       { number of rows by calling BIOS }
	      begin		       { VIDEO function $11, subfunc-	}
		AX := $1130;	       { tion $30.  Number of rows is	}
		BX := 0;	       { returned in DL.		}
		Intr(_VIDEO,Reg);
		Rows := DL + 1;
		case Rows of
		  25 : CharHeight := 14;
		  43 : CharHeight := 8
		end
	      end
	 else
	    Rows := 25;
       end; { Int1BWorked = FALSE }

    { Next assign _MaxDisplayPage (the first page is number 0). 	}

    case Mode of
      4..6,8..10,17..19:
	    _MaxDisplayPage := 0;
      0,1:
	    if (Rows = 50) then
	       _MaxDisplayPage := 6
	    else
	       _MaxDisplayPage := 7;
      2,3,7:
	    begin
	      if (_CurDevice = _MONO) then
		 _MaxDisplayPage := 0
	      else
		 _MaxDisplayPage := 3;
	      if (_CurDevice = _VgaAdapter) then
		 case Rows of
		   25	 : _MaxDisplayPage := 7;
		   43,50 : _MaxDisplayPage := 3
		 end;
	      if (_CurDevice = _EgaAdapter) then
		 begin
		   if (EgaMemory_ > 64) then
		      _MaxDisplayPage := 7
		   else
		      _MaxDisplayPage := 3;
		   if (Rows = 43) then
		      _MaxDisplayPage := _MaxDisplayPage div 2
		 end
	    end;
      13:
	    begin		       { Eight pages by default for	}
	      _MaxDisplayPage := 7;    { "fat" EGA and VGA.		}
	      if (_EgaAdapter = _CurDevice) then
		 if (EgaMemory_ = 64) then
		   _MaxDisplayPage := 1
		 else if (EgaMemory_ = 128) then
		   _MaxDisplayPage := 3;
	    end;
      14:			       { Four pages by default for	}
	    begin		       { "fat" EGA and VGA.		}
	      _MaxDisplayPage := 3;
	      if (_EgaAdapter = _CurDevice) then
		 if (EgaMemory_ = 64) then
		    _MaxDisplayPage := 0
		 else if (EgaMemory_ = 128) then
		    _MaxDisplayPage := 1
	    end;
      15..16:
	    begin		       { Two pages by default for	}
	      _MaxDisplayPage := 1;    { "fat" EGA and VGA.		}
	      if (_EgaAdapter = _CurDevice) then
		 if (EgaMemory_ = 64) then
		    _MaxDisplayPage := 0;
	    end;

    end; {case Mode}

    DisplayPage    := _CurDisplayPage; { Initialized at startup.	}
    _CurMode	   := Mode;	       { Initialize global variables	}
    _CurRows	   := Rows;
    _CurColumns    := Cols;
    _CurActivePage := ActivePage;
    MaxScanLine_   := CharHeight - 1;

    __RetDvScn	   := _CurDevice

  end;	{__RetDvScn}
