{***********************************************************************}
{									}
{ __ChgDvScn  Change the video device to color or monochrome		}
{									}
{ procedure __ChgDvScn(Device : byte; var ErrorCode : word);		}
{									}
{	      Device	The video adapter to select, the legal values	}
{			are _MONO (1) for the monochrome device, and	}
{			_COLOR (2) for the color device.		}
{	      ErrorCode The returned error status code: 		}
{			0 - Device successfully switched or no change	}
{			    needed.					}
{			1 - Invalid device request			}
{			2 - Requested device is not available.		}
{									}
{ Description This function selects a video adapter for future use	}
{	      without resetting it.  __ChgDvScn makes sure the		}
{	      desired device is present, alters the BIOS equipment	}
{	      flag, saves the current video state variables and re-	}
{	      stores the previous ones if they are available.  If the	}
{	      requested is the current one, or the device is un-	}
{	      available, no action is taken.  Note:  the VGA adapter	}
{	      can produce both monochrome and color modes on a single	}
{	      monitor, so it can become alternately the _MONO and	}
{	      _COLOR device.  Use __NewDvScn to switch _VgaAdapter from }
{	      _MONO to _COLOR when using a VGA with a single monitor.	}
{									}
{ Version     4.00 (C)Copyright Blaise Computing Inc. 1987		}
{_______________________________________________________________________}

procedure __ChgDvScn(Device : byte; var ErrorCode : word);

  var
    EquipFlag	: word absolute _BIOSSEG:$0010;     {Equipment flag	}
    VideoSet	: word; 	       { Video portion of Equipment flag}
    ErrCode	: word;
    Mode	: byte;
    Rows,Cols	: byte;
    APage,DPage : byte;

  begin {__ChgDvScn}

    if ((Device <> _COLOR) and (Device <>_MONO)) then
       begin			       { Illegal request		}
	 ErrorCode := 1;
	 Exit
       end
    else if (Device = _CurDevice) then
       begin			       { Nothing to do here.		}
	 ErrorCode := 0;
	 Exit
       end;

    if (((Device = _COLOR) and (AvailColorModes_ = [])) or
	((Device = _MONO)  and (AvailMonoModes_ = []))	or
	((_CurDevice = _VgaAdapter) and (not DualDisplay_))) then
       begin
	 ErrorCode := 2;	       { Hardware not available 	}
	 Exit
       end;

    { Now actually switch the devices by altering the equipment flag.	}
    { If the video attributes have been saved, restore them, and save	}
    { the attributes of the current device.				}

    if (Device = _MONO) then
       begin
	 SaveVideo(_COLOR);
	 EquipFlag := (EquipFlag and $FFCF) or $0030;
	 if (StateSaved_[_MONO]) then
	    RestoreVideo(_MONO)        { Restore previous state 	}
	 else
	    __NewDvScn(7,25,ErrCode)   { Use the default settings	}
       end
    else
       begin
	 SaveVideo(_MONO);
	 EquipFlag := (EquipFlag and $FFCF) or $0020;
	 if (StateSaved_[_COLOR]) then
	    RestoreVideo(_COLOR)       { Restore previous state 	}
	 else
	    __NewDvScn(3,25,ErrCode)   { Use the default settings	}
       end;

    { Finally, now call __RetDvScn to return the new screen mode.	}
    { __RetDvScn also sets variables exported from Unit_Scn.		}

    Device    := __RetDvScn(Mode,Rows,Cols,APage,DPage);
    ErrorCode := 0

  end;	{__ChgDvScn}
