mirror of https://github.com/lianthony/NT4.0
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
6057 lines
170 KiB
6057 lines
170 KiB
/*++
|
|
|
|
Copyright (c) 1992 Microsoft Corporation
|
|
|
|
Module Name:
|
|
|
|
v7.c
|
|
|
|
Abstract:
|
|
|
|
This is the miniport driver for the V7 cards.
|
|
|
|
Environment:
|
|
|
|
kernel mode only
|
|
|
|
Notes:
|
|
|
|
Revision History:
|
|
|
|
--*/
|
|
|
|
#include "dderror.h"
|
|
#include "devioctl.h"
|
|
#include "miniport.h"
|
|
|
|
#include "ntddvdeo.h"
|
|
#include "video.h"
|
|
#include "v7.h"
|
|
|
|
// NOTE: should be a variable
|
|
#define POINTER_BANK 1
|
|
|
|
|
|
//
|
|
// Function declarations
|
|
//
|
|
// Functions that start with 'VGA' are entry points for the OS port driver.
|
|
//
|
|
|
|
VP_STATUS
|
|
VgaFindAdapter(
|
|
PVOID HwDeviceExtension,
|
|
PVOID HwContext,
|
|
PWSTR ArgumentString,
|
|
PVIDEO_PORT_CONFIG_INFO ConfigInfo,
|
|
PUCHAR Again
|
|
);
|
|
|
|
BOOLEAN
|
|
VgaInitialize(
|
|
PVOID HwDeviceExtension
|
|
);
|
|
|
|
BOOLEAN
|
|
VgaStartIO(
|
|
PVOID HwDeviceExtension,
|
|
PVIDEO_REQUEST_PACKET RequestPacket
|
|
);
|
|
|
|
//
|
|
// Private function prototypes.
|
|
//
|
|
|
|
VP_STATUS
|
|
VgaQueryAvailableModes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_MODE_INFORMATION ModeInformation,
|
|
ULONG ModeInformationSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaQueryNumberOfAvailableModes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_NUM_MODES NumModes,
|
|
ULONG NumModesSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaQueryCurrentMode(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_MODE_INFORMATION ModeInformation,
|
|
ULONG ModeInformationSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSetMode(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_MODE Mode,
|
|
ULONG ModeSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaLoadAndSetFont(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_LOAD_FONT_INFORMATION FontInformation,
|
|
ULONG FontInformationSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaQueryCursorPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_POSITION CursorPosition,
|
|
ULONG CursorPositionSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSetCursorPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_POSITION CursorPosition,
|
|
ULONG CursorPositionSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaQueryCursorAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
|
ULONG CursorAttributesSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSetCursorAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
|
ULONG CursorAttributesSize
|
|
);
|
|
|
|
BOOLEAN
|
|
VgaIsPresent(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
);
|
|
|
|
VOID
|
|
V7EnablePointer(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
);
|
|
|
|
VOID
|
|
V7DisablePointer(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
);
|
|
|
|
BOOLEAN
|
|
V7IsPresent(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
);
|
|
|
|
VOID
|
|
VgaInterpretCmdStream(
|
|
PVOID HwDeviceExtension,
|
|
PUSHORT pusCmdStream
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSetPaletteReg(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_PALETTE_DATA PaletteBuffer,
|
|
ULONG PaletteBufferSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSetColorLookup(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CLUT ClutBuffer,
|
|
ULONG ClutBufferSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaRestoreHardwareState(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_HARDWARE_STATE HardwareState,
|
|
ULONG HardwareStateSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSaveHardwareState(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_HARDWARE_STATE HardwareState,
|
|
ULONG HardwareStateSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaGetBankSelectCode(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_BANK_SELECT BankSelect,
|
|
ULONG BankSelectSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaQueryPointerCapabilities(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_CAPABILITIES PointerCaps,
|
|
ULONG PointerCapsSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSetPointerPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_POSITION pPointerPosition,
|
|
ULONG PointerPositionSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaQueryPointerPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_POSITION pPointerPosition,
|
|
ULONG PointerPositionSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaSetPointerAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_ATTRIBUTES pVideoPointerAttributes,
|
|
ULONG PointerAttributesSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VP_STATUS
|
|
VgaQueryPointerAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_ATTRIBUTES pVideoPointerAttributes,
|
|
ULONG PointerAttributesSize,
|
|
PULONG OutputSize
|
|
);
|
|
|
|
VOID
|
|
vBankMap_1RW(
|
|
LONG iBankRead,
|
|
LONG iBankWrite,
|
|
PVOID pvContext
|
|
);
|
|
|
|
VOID
|
|
vBankMap_2RW(
|
|
LONG iBankRead,
|
|
LONG iBankWrite,
|
|
PVOID pvContext
|
|
);
|
|
|
|
#if defined(ALLOC_PRAGMA)
|
|
#pragma alloc_text(PAGE,DriverEntry)
|
|
#pragma alloc_text(PAGE,VgaFindAdapter)
|
|
#pragma alloc_text(PAGE,VgaInitialize)
|
|
#pragma alloc_text(PAGE,VgaStartIO)
|
|
#pragma alloc_text(PAGE,VgaLoadAndSetFont)
|
|
#pragma alloc_text(PAGE,VgaQueryCursorPosition)
|
|
#pragma alloc_text(PAGE,VgaSetCursorPosition)
|
|
#pragma alloc_text(PAGE,VgaQueryCursorAttributes)
|
|
#pragma alloc_text(PAGE,VgaSetCursorAttributes)
|
|
#pragma alloc_text(PAGE,VgaIsPresent)
|
|
#pragma alloc_text(PAGE,V7EnablePointer)
|
|
#pragma alloc_text(PAGE,V7DisablePointer)
|
|
#pragma alloc_text(PAGE,V7IsPresent)
|
|
#pragma alloc_text(PAGE,VgaSetPaletteReg)
|
|
#pragma alloc_text(PAGE,VgaSetColorLookup)
|
|
#pragma alloc_text(PAGE,VgaRestoreHardwareState)
|
|
#pragma alloc_text(PAGE,VgaSaveHardwareState)
|
|
#pragma alloc_text(PAGE,VgaGetBankSelectCode)
|
|
#pragma alloc_text(PAGE,VgaQueryPointerCapabilities)
|
|
#pragma alloc_text(PAGE,VgaSetPointerPosition)
|
|
#pragma alloc_text(PAGE,VgaQueryPointerPosition)
|
|
#pragma alloc_text(PAGE,VgaSetPointerAttributes)
|
|
#pragma alloc_text(PAGE,VgaQueryPointerAttributes)
|
|
#pragma alloc_text(PAGE,VgaValidatorUcharEntry)
|
|
#pragma alloc_text(PAGE,VgaValidatorUshortEntry)
|
|
#pragma alloc_text(PAGE,VgaValidatorUlongEntry)
|
|
#endif
|
|
|
|
//
|
|
// exported from modeset.c
|
|
//
|
|
|
|
VOID
|
|
VgaSizeMemory(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
);
|
|
|
|
VOID
|
|
VgaValidateModes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
);
|
|
|
|
|
|
|
|
ULONG
|
|
DriverEntry(
|
|
PVOID Context1,
|
|
PVOID Context2
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Installable driver initialization entry point.
|
|
This entry point is called directly by the I/O system.
|
|
|
|
Arguments:
|
|
|
|
Context1 - First context value passed by the operating system. This is
|
|
the value with which the miniport driver calls VideoPortInitialize().
|
|
|
|
Context2 - Second context value passed by the operating system. This is
|
|
the value with which the miniport driver calls VideoPortInitialize().
|
|
|
|
Return Value:
|
|
|
|
Status from VideoPortInitialize()
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
VIDEO_HW_INITIALIZATION_DATA hwInitData;
|
|
ULONG status;
|
|
ULONG initializationStatus;
|
|
|
|
//
|
|
// Zero out structure.
|
|
//
|
|
|
|
VideoPortZeroMemory(&hwInitData, sizeof(VIDEO_HW_INITIALIZATION_DATA));
|
|
|
|
//
|
|
// Specify sizes of structure and extension.
|
|
//
|
|
|
|
hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);
|
|
|
|
//
|
|
// Set entry points.
|
|
//
|
|
|
|
hwInitData.HwFindAdapter = VgaFindAdapter;
|
|
hwInitData.HwInitialize = VgaInitialize;
|
|
hwInitData.HwInterrupt = NULL;
|
|
hwInitData.HwStartIO = VgaStartIO;
|
|
|
|
//
|
|
// Determine the size we require for the device extension.
|
|
//
|
|
|
|
hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);
|
|
|
|
//
|
|
// Always start with parameters for device0 in this case.
|
|
// We can leave it like this since we know we will only ever find one
|
|
// VGA type adapter in a machine.
|
|
//
|
|
|
|
// hwInitData.StartingDeviceNumber = 0;
|
|
|
|
//
|
|
// Once all the relevant information has been stored, call the video
|
|
// port driver to do the initialization.
|
|
// For this device we will repeat this call three times, for ISA, EISA
|
|
// and MCA.
|
|
// We will return the minimum of all return values.
|
|
//
|
|
|
|
hwInitData.AdapterInterfaceType = Isa;
|
|
|
|
initializationStatus = VideoPortInitialize(Context1,
|
|
Context2,
|
|
&hwInitData,
|
|
NULL);
|
|
|
|
hwInitData.AdapterInterfaceType = Eisa;
|
|
|
|
status = VideoPortInitialize(Context1,
|
|
Context2,
|
|
&hwInitData,
|
|
NULL);
|
|
|
|
if (initializationStatus > status) {
|
|
initializationStatus = status;
|
|
}
|
|
|
|
hwInitData.AdapterInterfaceType = MicroChannel;
|
|
|
|
status = VideoPortInitialize(Context1,
|
|
Context2,
|
|
&hwInitData,
|
|
NULL);
|
|
|
|
if (initializationStatus > status) {
|
|
initializationStatus = status;
|
|
}
|
|
|
|
return initializationStatus;
|
|
|
|
} // end DriverEntry()
|
|
|
|
VP_STATUS
|
|
VgaFindAdapter(
|
|
PVOID HwDeviceExtension,
|
|
PVOID HwContext,
|
|
PWSTR ArgumentString,
|
|
PVIDEO_PORT_CONFIG_INFO ConfigInfo,
|
|
PUCHAR Again
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine is called to determine if the adapter for this driver
|
|
is present in the system.
|
|
If it is present, the function fills out some information describing
|
|
the adapter.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Supplies the miniport driver's adapter storage. This
|
|
storage is initialized to zero before this call.
|
|
|
|
HwContext - Supplies the context value which was passed to
|
|
VideoPortInitialize().
|
|
|
|
ArgumentString - Suuplies a NULL terminated ASCII string. This string
|
|
originates from the user.
|
|
|
|
ConfigInfo - Returns the configuration information structure which is
|
|
filled by the miniport driver. This structure is initialized with
|
|
any knwon configuration information (such as SystemIoBusNumber) by
|
|
the port driver. Where possible, drivers should have one set of
|
|
defaults which do not require any supplied configuration information.
|
|
|
|
Again - Indicates if the miniport driver wants the port driver to call
|
|
its VIDEO_HW_FIND_ADAPTER function again with a new device extension
|
|
and the same config info. This is used by the miniport drivers which
|
|
can search for several adapters on a bus.
|
|
|
|
Return Value:
|
|
|
|
This routine must return:
|
|
|
|
NO_ERROR - Indicates a host adapter was found and the
|
|
configuration information was successfully determined.
|
|
|
|
ERROR_INVALID_PARAMETER - Indicates an adapter was found but there was an
|
|
error obtaining the configuration information. If possible an error
|
|
should be logged.
|
|
|
|
ERROR_DEV_NOT_EXIST - Indicates no host adapter was found for the
|
|
supplied configuration information.
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
|
|
VP_STATUS status;
|
|
PHYSICAL_ADDRESS physicalAddress;
|
|
|
|
//
|
|
// Make sure the size of the structure is at least as large as what we
|
|
// are expecting (check version of the config info structure).
|
|
//
|
|
|
|
if (ConfigInfo->Length < sizeof(VIDEO_PORT_CONFIG_INFO)) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// No interrupt information is necessary.
|
|
//
|
|
|
|
//
|
|
// Check to see if there is a hardware resource conflict.
|
|
//
|
|
|
|
status = VideoPortVerifyAccessRanges(HwDeviceExtension,
|
|
NUM_VGA_ACCESS_RANGES,
|
|
VgaAccessRange);
|
|
|
|
if (status != NO_ERROR) {
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
//
|
|
// Get logical IO port addresses.
|
|
//
|
|
|
|
if ( (hwDeviceExtension->IOAddress =
|
|
VideoPortGetDeviceBase(hwDeviceExtension,
|
|
VgaAccessRange->RangeStart,
|
|
VGA_MAX_IO_PORT - VGA_BASE_IO_PORT + 1,
|
|
TRUE)) == NULL) {
|
|
|
|
VideoDebugPrint((2, "VgaFindAdapter - Fail to get io address\n"));
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Determine whether a VGA is present.
|
|
//
|
|
if (!VgaIsPresent(hwDeviceExtension)) {
|
|
|
|
return ERROR_DEV_NOT_EXIST;
|
|
|
|
}
|
|
|
|
//
|
|
// Pass a pointer to the emulator range we are using.
|
|
//
|
|
|
|
ConfigInfo->NumEmulatorAccessEntries = VGA_NUM_EMULATOR_ACCESS_ENTRIES;
|
|
ConfigInfo->EmulatorAccessEntries = VgaEmulatorAccessEntries;
|
|
ConfigInfo->EmulatorAccessEntriesContext = (ULONG) hwDeviceExtension;
|
|
|
|
ConfigInfo->VdmPhysicalVideoMemoryAddress.LowPart = MEM_VGA;
|
|
ConfigInfo->VdmPhysicalVideoMemoryAddress.HighPart = 0x00000000;
|
|
ConfigInfo->VdmPhysicalVideoMemoryLength = MEM_VGA_SIZE;
|
|
|
|
//
|
|
// Minimum size of the buffer required to store the hardware state
|
|
// information returned by IOCTL_VIDEO_SAVE_HARDWARE_STATE.
|
|
//
|
|
|
|
ConfigInfo->HardwareStateSize = VGA_TOTAL_STATE_SIZE;
|
|
|
|
//
|
|
// Video memory information
|
|
//
|
|
|
|
hwDeviceExtension->PhysicalVideoMemoryBase.HighPart = 0x00000000;
|
|
hwDeviceExtension->PhysicalVideoMemoryBase.LowPart = MEM_VGA;
|
|
hwDeviceExtension->PhysicalVideoMemoryLength = MEM_VGA_SIZE;
|
|
|
|
//
|
|
// Map the video memory into the system virtual address space so we can
|
|
// clear it out and use it for save and restore.
|
|
//
|
|
|
|
if ( (hwDeviceExtension->VideoMemoryAddress =
|
|
VideoPortGetDeviceBase(hwDeviceExtension,
|
|
hwDeviceExtension->PhysicalVideoMemoryBase,
|
|
hwDeviceExtension->PhysicalVideoMemoryLength,
|
|
FALSE)) == NULL) {
|
|
|
|
VideoDebugPrint((1, "VgaFindAdapter - Fail to get memory address\n"));
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Map the regen of memory where Fonts can be found or loaded from.
|
|
// Note that this is also used for identifying the adapter, below, so
|
|
// it cannot be removed even if font loading from the ROM is eliminated.
|
|
//
|
|
|
|
physicalAddress.LowPart = ROM_BASE;
|
|
physicalAddress.HighPart = 0x00000000;
|
|
|
|
if ( (hwDeviceExtension->ROMBaseAddress =
|
|
VideoPortGetDeviceBase(hwDeviceExtension,
|
|
physicalAddress,
|
|
ROM_LENGTH,
|
|
FALSE)) == NULL) {
|
|
|
|
VideoDebugPrint((2, "VgaFindAdapter - Fail to get font address\n"));
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Determine whether a supported V7 adapter is present, and if so, what
|
|
// kind.
|
|
//
|
|
|
|
if (!V7IsPresent(hwDeviceExtension)) {
|
|
|
|
return ERROR_DEV_NOT_EXIST;
|
|
|
|
}
|
|
|
|
//
|
|
// Indicate we do not wish to be called again for another initialization.
|
|
//
|
|
|
|
*Again = 0;
|
|
|
|
//
|
|
// Indicate a successful completion status.
|
|
//
|
|
|
|
return NO_ERROR;
|
|
|
|
} // VgaFindAdapter()
|
|
|
|
BOOLEAN
|
|
VgaInitialize(
|
|
PVOID HwDeviceExtension
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine does one time initialization of the device.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's adapter information.
|
|
|
|
Return Value:
|
|
|
|
None.
|
|
|
|
--*/
|
|
|
|
{
|
|
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
|
|
|
|
//
|
|
// ***************************
|
|
// ***** IMPORTANT NOTE ******
|
|
// ***************************
|
|
//
|
|
// We do the memory size detection and calculate valid modes here
|
|
// because we need to do an int10 for that.
|
|
// An int 10 is only possible when being called by the display driver,
|
|
// (more precisely in the context of the caller)
|
|
// and must therefore be done in the Initialize routine.
|
|
//
|
|
|
|
VgaSizeMemory(HwDeviceExtension);
|
|
|
|
//
|
|
// Write amount of memory to registry
|
|
//
|
|
|
|
VideoPortSetRegistryParameters(hwDeviceExtension,
|
|
L"HardwareInformation.MemorySize",
|
|
&hwDeviceExtension->AdapterMemorySize,
|
|
sizeof(ULONG));
|
|
|
|
VgaValidateModes(HwDeviceExtension);
|
|
|
|
//
|
|
// set up the default cursor position and type.
|
|
//
|
|
|
|
hwDeviceExtension->CursorPosition.Column = 0;
|
|
hwDeviceExtension->CursorPosition.Row = 0;
|
|
hwDeviceExtension->CursorTopScanLine = 0;
|
|
hwDeviceExtension->CursorBottomScanLine = 31;
|
|
hwDeviceExtension->CursorEnable = TRUE;
|
|
|
|
return TRUE;
|
|
|
|
} // VgaInitialize()
|
|
|
|
BOOLEAN
|
|
VgaStartIO(
|
|
PVOID HwDeviceExtension,
|
|
PVIDEO_REQUEST_PACKET RequestPacket
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine is the main execution routine for the miniport driver. It
|
|
acceptss a Video Request Packet, performs the request, and then returns
|
|
with the appropriate status.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's adapter information.
|
|
|
|
RequestPacket - Pointer to the video request packet. This structure
|
|
contains all the parameters passed to the VideoIoControl function.
|
|
|
|
Return Value:
|
|
|
|
This routine will return error codes from the various support routines
|
|
and will also return ERROR_INSUFFICIENT_BUFFER for incorrectly sized
|
|
buffers and ERROR_INVALID_FUNCTION for unsupported functions.
|
|
|
|
--*/
|
|
|
|
{
|
|
PHW_DEVICE_EXTENSION hwDeviceExtension = HwDeviceExtension;
|
|
VP_STATUS status;
|
|
VIDEO_MODE videoMode;
|
|
PVIDEO_MEMORY_INFORMATION memoryInformation;
|
|
ULONG inIoSpace;
|
|
|
|
PVIDEO_SHARE_MEMORY pShareMemory;
|
|
PVIDEO_SHARE_MEMORY_INFORMATION pShareMemoryInformation;
|
|
PHYSICAL_ADDRESS shareAddress;
|
|
PVOID virtualAddress;
|
|
ULONG sharedViewSize;
|
|
ULONG ulBankSize;
|
|
|
|
VOID (*pfnBank)(LONG,LONG,PVOID);
|
|
|
|
//
|
|
// Switch on the IoContolCode in the RequestPacket. It indicates which
|
|
// function must be performed by the driver.
|
|
//
|
|
|
|
switch (RequestPacket->IoControlCode) {
|
|
|
|
|
|
case IOCTL_VIDEO_SHARE_VIDEO_MEMORY:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - ShareVideoMemory\n"));
|
|
|
|
if ( (RequestPacket->OutputBufferLength < sizeof(VIDEO_SHARE_MEMORY_INFORMATION)) ||
|
|
(RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) ) {
|
|
|
|
status = ERROR_INSUFFICIENT_BUFFER;
|
|
VideoDebugPrint((0, "VgaStartIO - ShareVideoMemory - ERROR_INSUFFICIENT_BUFFER\n"));
|
|
break;
|
|
|
|
}
|
|
|
|
pShareMemory = RequestPacket->InputBuffer;
|
|
|
|
if ( (pShareMemory->ViewOffset > hwDeviceExtension->AdapterMemorySize) ||
|
|
((pShareMemory->ViewOffset + pShareMemory->ViewSize) >
|
|
hwDeviceExtension->AdapterMemorySize) ) {
|
|
|
|
status = ERROR_INVALID_PARAMETER;
|
|
VideoDebugPrint((0, "VgaStartIO - ShareVideoMemory - ERROR_INVALID_PARAMETER\n"));
|
|
break;
|
|
|
|
}
|
|
|
|
RequestPacket->StatusBlock->Information =
|
|
sizeof(VIDEO_SHARE_MEMORY_INFORMATION);
|
|
|
|
//
|
|
// Beware: the input buffer and the output buffer are the same
|
|
// buffer, and therefore data should not be copied from one to the
|
|
// other
|
|
//
|
|
|
|
virtualAddress = pShareMemory->ProcessHandle;
|
|
sharedViewSize = pShareMemory->ViewSize;
|
|
|
|
inIoSpace = 0;
|
|
|
|
//
|
|
// NOTE: we are ignoring ViewOffset
|
|
//
|
|
|
|
shareAddress.QuadPart =
|
|
hwDeviceExtension->PhysicalFrameBase.QuadPart;
|
|
|
|
switch(hwDeviceExtension->CurrentMode->banktype) {
|
|
|
|
case VideoBanked1RW:
|
|
|
|
ulBankSize = 0x10000; // 64K bank granularity
|
|
pfnBank = vBankMap_1RW;
|
|
break;
|
|
|
|
case VideoBanked2RW:
|
|
|
|
ulBankSize = 0x1000; // 4K bank granularity
|
|
pfnBank = vBankMap_2RW;
|
|
break;
|
|
|
|
default:
|
|
|
|
VideoDebugPrint((0, "IOCTL_VIDEO_SHARE_VIDEO_MEMORY - Unsupported bank type\n"));
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
status = VideoPortMapBankedMemory(hwDeviceExtension,
|
|
shareAddress,
|
|
&sharedViewSize,
|
|
&inIoSpace,
|
|
&virtualAddress,
|
|
ulBankSize, // bank size
|
|
TRUE, // we don't have separate read/write
|
|
pfnBank,
|
|
(PVOID)hwDeviceExtension);
|
|
|
|
pShareMemoryInformation = RequestPacket->OutputBuffer;
|
|
|
|
pShareMemoryInformation->SharedViewOffset = pShareMemory->ViewOffset;
|
|
pShareMemoryInformation->VirtualAddress = virtualAddress;
|
|
pShareMemoryInformation->SharedViewSize = sharedViewSize;
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_UNSHARE_VIDEO_MEMORY:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - UnshareVideoMemory\n"));
|
|
|
|
if (RequestPacket->InputBufferLength < sizeof(VIDEO_SHARE_MEMORY)) {
|
|
|
|
status = ERROR_INSUFFICIENT_BUFFER;
|
|
break;
|
|
|
|
}
|
|
|
|
pShareMemory = RequestPacket->InputBuffer;
|
|
|
|
status = VideoPortUnmapMemory(hwDeviceExtension,
|
|
pShareMemory->RequestedVirtualAddress,
|
|
pShareMemory->ProcessHandle);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_MAP_VIDEO_MEMORY:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - MapVideoMemory\n"));
|
|
|
|
if ( (RequestPacket->OutputBufferLength <
|
|
(RequestPacket->StatusBlock->Information =
|
|
sizeof(VIDEO_MEMORY_INFORMATION))) ||
|
|
(RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) ) {
|
|
|
|
status = ERROR_INSUFFICIENT_BUFFER;
|
|
}
|
|
|
|
memoryInformation = RequestPacket->OutputBuffer;
|
|
|
|
memoryInformation->VideoRamBase = ((PVIDEO_MEMORY)
|
|
(RequestPacket->InputBuffer))->RequestedVirtualAddress;
|
|
|
|
memoryInformation->VideoRamLength =
|
|
hwDeviceExtension->PhysicalVideoMemoryLength;
|
|
|
|
inIoSpace = 0;
|
|
|
|
status = VideoPortMapMemory(hwDeviceExtension,
|
|
hwDeviceExtension->PhysicalVideoMemoryBase,
|
|
&(memoryInformation->VideoRamLength),
|
|
&inIoSpace,
|
|
&(memoryInformation->VideoRamBase));
|
|
|
|
memoryInformation->FrameBufferBase =
|
|
((PUCHAR) (memoryInformation->VideoRamBase)) +
|
|
(hwDeviceExtension->PhysicalFrameBase.LowPart -
|
|
hwDeviceExtension->PhysicalVideoMemoryBase.LowPart);
|
|
|
|
memoryInformation->FrameBufferLength =
|
|
hwDeviceExtension->PhysicalFrameLength;
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_UNMAP_VIDEO_MEMORY:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - UnMapVideoMemory\n"));
|
|
|
|
if (RequestPacket->InputBufferLength < sizeof(VIDEO_MEMORY)) {
|
|
|
|
status = ERROR_INSUFFICIENT_BUFFER;
|
|
}
|
|
|
|
status = VideoPortUnmapMemory(hwDeviceExtension,
|
|
((PVIDEO_MEMORY)
|
|
(RequestPacket->InputBuffer))->
|
|
RequestedVirtualAddress,
|
|
0);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_QUERY_AVAIL_MODES:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - QueryAvailableModes\n"));
|
|
|
|
status = VgaQueryAvailableModes(HwDeviceExtension,
|
|
(PVIDEO_MODE_INFORMATION)
|
|
RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_QUERY_NUM_AVAIL_MODES:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - QueryNumAvailableModes\n"));
|
|
|
|
status = VgaQueryNumberOfAvailableModes(HwDeviceExtension,
|
|
(PVIDEO_NUM_MODES)
|
|
RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_QUERY_CURRENT_MODE:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - QueryCurrentMode\n"));
|
|
|
|
status = VgaQueryCurrentMode(HwDeviceExtension,
|
|
(PVIDEO_MODE_INFORMATION) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_SET_CURRENT_MODE:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - SetCurrentModes\n"));
|
|
|
|
status = VgaSetMode(HwDeviceExtension,
|
|
(PVIDEO_MODE) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_RESET_DEVICE:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - Reset Device\n"));
|
|
|
|
videoMode.RequestedMode = DEFAULT_MODE;
|
|
|
|
status = VgaSetMode(HwDeviceExtension,
|
|
(PVIDEO_MODE) &videoMode,
|
|
sizeof(videoMode));
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_LOAD_AND_SET_FONT:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - LoadAndSetFont\n"));
|
|
|
|
status = VgaLoadAndSetFont(HwDeviceExtension,
|
|
(PVIDEO_LOAD_FONT_INFORMATION) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_QUERY_CURSOR_POSITION:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - QueryCursorPosition\n"));
|
|
|
|
status = VgaQueryCursorPosition(HwDeviceExtension,
|
|
(PVIDEO_CURSOR_POSITION) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_SET_CURSOR_POSITION:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - SetCursorPosition\n"));
|
|
|
|
status = VgaSetCursorPosition(HwDeviceExtension,
|
|
(PVIDEO_CURSOR_POSITION)
|
|
RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_QUERY_CURSOR_ATTR:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - QueryCursorAttributes\n"));
|
|
|
|
status = VgaQueryCursorAttributes(HwDeviceExtension,
|
|
(PVIDEO_CURSOR_ATTRIBUTES) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_SET_CURSOR_ATTR:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - SetCursorAttributes\n"));
|
|
|
|
status = VgaSetCursorAttributes(HwDeviceExtension,
|
|
(PVIDEO_CURSOR_ATTRIBUTES) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_SET_PALETTE_REGISTERS:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - SetPaletteRegs\n"));
|
|
|
|
status = VgaSetPaletteReg(HwDeviceExtension,
|
|
(PVIDEO_PALETTE_DATA) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_SET_COLOR_REGISTERS:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - SetColorRegs\n"));
|
|
|
|
status = VgaSetColorLookup(HwDeviceExtension,
|
|
(PVIDEO_CLUT) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_ENABLE_VDM:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - EnableVDM\n"));
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 0;
|
|
hwDeviceExtension->SequencerAddressValue = 0;
|
|
|
|
hwDeviceExtension->CurrentNumVdmAccessRanges =
|
|
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE;
|
|
hwDeviceExtension->CurrentVdmAccessRange =
|
|
MinimalVgaValidatorAccessRange;
|
|
|
|
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
|
hwDeviceExtension->CurrentNumVdmAccessRanges,
|
|
hwDeviceExtension->CurrentVdmAccessRange);
|
|
|
|
status = NO_ERROR;
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_RESTORE_HARDWARE_STATE:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - RestoreHardwareState\n"));
|
|
|
|
status = VgaRestoreHardwareState(HwDeviceExtension,
|
|
(PVIDEO_HARDWARE_STATE) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength);
|
|
|
|
break;
|
|
|
|
|
|
case IOCTL_VIDEO_SAVE_HARDWARE_STATE:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - SaveHardwareState\n"));
|
|
|
|
status = VgaSaveHardwareState(HwDeviceExtension,
|
|
(PVIDEO_HARDWARE_STATE) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
|
|
break;
|
|
|
|
case IOCTL_VIDEO_GET_BANK_SELECT_CODE:
|
|
|
|
VideoDebugPrint((2, "VgaStartIO - GetBankSelectCode\n"));
|
|
|
|
status = VgaGetBankSelectCode(HwDeviceExtension,
|
|
(PVIDEO_BANK_SELECT) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
|
|
break;
|
|
|
|
//
|
|
// There is a monochrome hardware cursor.
|
|
//
|
|
|
|
case IOCTL_VIDEO_QUERY_POINTER_CAPABILITIES:
|
|
|
|
VideoDebugPrint((2, "V7 - QueryPointerCapabilities\n"));
|
|
|
|
status = VgaQueryPointerCapabilities(HwDeviceExtension,
|
|
(PVIDEO_POINTER_CAPABILITIES) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
break;
|
|
|
|
case IOCTL_VIDEO_ENABLE_POINTER:
|
|
|
|
V7EnablePointer(HwDeviceExtension);
|
|
|
|
hwDeviceExtension->videoPointerAttributes.Enable = 1;
|
|
|
|
status = NO_ERROR;
|
|
|
|
break;
|
|
|
|
case IOCTL_VIDEO_DISABLE_POINTER:
|
|
|
|
V7DisablePointer(HwDeviceExtension);
|
|
|
|
hwDeviceExtension->videoPointerAttributes.Enable = 0;
|
|
|
|
status = NO_ERROR;
|
|
|
|
break;
|
|
|
|
case IOCTL_VIDEO_SET_POINTER_ATTR:
|
|
|
|
status = VgaSetPointerAttributes(HwDeviceExtension,
|
|
(PVIDEO_POINTER_ATTRIBUTES) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
break;
|
|
|
|
case IOCTL_VIDEO_QUERY_POINTER_ATTR:
|
|
|
|
status = VgaQueryPointerAttributes(HwDeviceExtension,
|
|
(PVIDEO_POINTER_ATTRIBUTES) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
break;
|
|
|
|
case IOCTL_VIDEO_SET_POINTER_POSITION:
|
|
|
|
status = VgaSetPointerPosition(HwDeviceExtension,
|
|
(PVIDEO_POINTER_POSITION) RequestPacket->InputBuffer,
|
|
RequestPacket->InputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
break;
|
|
|
|
case IOCTL_VIDEO_QUERY_POINTER_POSITION:
|
|
|
|
status = VgaQueryPointerPosition(HwDeviceExtension,
|
|
(PVIDEO_POINTER_POSITION) RequestPacket->OutputBuffer,
|
|
RequestPacket->OutputBufferLength,
|
|
&RequestPacket->StatusBlock->Information);
|
|
break;
|
|
|
|
//
|
|
// If we get here, an invalid IoControlCode was specified.
|
|
//
|
|
|
|
default:
|
|
|
|
VideoDebugPrint((1, "Fell through vga startIO routine - invalid command\n"));
|
|
|
|
RequestPacket->StatusBlock->Information = 0;
|
|
status = ERROR_INVALID_FUNCTION;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
RequestPacket->StatusBlock->Status = status;
|
|
|
|
return TRUE;
|
|
|
|
} // VgaStartIO()
|
|
|
|
//
|
|
// private routines
|
|
//
|
|
|
|
VP_STATUS
|
|
VgaLoadAndSetFont(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_LOAD_FONT_INFORMATION FontInformation,
|
|
ULONG FontInformationSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Takes a buffer containing a user-defined font and loads it into the
|
|
VGA soft font memory and programs the VGA to the appropriate character
|
|
cell size.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
FontInformation - Pointer to the structure containing the information
|
|
about the loadable ROM font to be set.
|
|
|
|
FontInformationSize - Length of the input buffer supplied by the user.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
|
|
|
|
ERROR_INVALID_PARAMETER - invalid video mode
|
|
|
|
--*/
|
|
|
|
{
|
|
PUCHAR destination;
|
|
PUCHAR source;
|
|
USHORT width;
|
|
ULONG i;
|
|
|
|
//
|
|
// check if a mode has been set
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode == NULL) {
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
|
|
|
//
|
|
// Text mode only; If we are in a graphics mode, return an error
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check if the size of the data in the input buffer is large enough
|
|
// and that it contains all the data.
|
|
//
|
|
|
|
if ( (FontInformationSize < sizeof(VIDEO_LOAD_FONT_INFORMATION)) ||
|
|
(FontInformationSize < sizeof(VIDEO_LOAD_FONT_INFORMATION) +
|
|
sizeof(UCHAR) * (FontInformation->FontSize - 1)) ) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check for the width and height of the font
|
|
//
|
|
|
|
if ( ((FontInformation->WidthInPixels != 8) &&
|
|
(FontInformation->WidthInPixels != 9)) ||
|
|
(FontInformation->HeightInPixels > 32) ) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check the size of the font buffer is the right size for the size
|
|
// font being passed down.
|
|
//
|
|
|
|
if (FontInformation->FontSize < FontInformation->HeightInPixels * 256 *
|
|
sizeof(UCHAR) ) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Since the font parameters are valid, store the parameters in the
|
|
// device extension and load the font.
|
|
//
|
|
|
|
HwDeviceExtension->FontPelRows = FontInformation->HeightInPixels;
|
|
HwDeviceExtension->FontPelColumns = FontInformation->WidthInPixels;
|
|
|
|
HwDeviceExtension->CurrentMode->row =
|
|
HwDeviceExtension->CurrentMode->vres / FontInformation->HeightInPixels;
|
|
|
|
width =
|
|
HwDeviceExtension->CurrentMode->hres / HwDeviceExtension->FontPelColumns;
|
|
|
|
if (width < (USHORT)HwDeviceExtension->CurrentMode->col) {
|
|
|
|
HwDeviceExtension->CurrentMode->col = width;
|
|
|
|
}
|
|
|
|
source = &(FontInformation->Font[0]);
|
|
|
|
//
|
|
// Set up the destination and source pointers for the font
|
|
//
|
|
|
|
destination = (PUCHAR)HwDeviceExtension->VideoMemoryAddress;
|
|
|
|
//
|
|
// Map font buffer at A0000
|
|
//
|
|
|
|
VgaInterpretCmdStream(HwDeviceExtension, EnableA000Data);
|
|
|
|
//
|
|
// Move the font to its destination
|
|
//
|
|
|
|
for (i = 1; i <= 256; i++) {
|
|
|
|
VideoPortWriteRegisterBufferUchar(destination,
|
|
source,
|
|
FontInformation->HeightInPixels);
|
|
|
|
destination += 32;
|
|
source += FontInformation->HeightInPixels;
|
|
|
|
}
|
|
|
|
VgaInterpretCmdStream(HwDeviceExtension, DisableA000Color);
|
|
|
|
//
|
|
// Restore to a text mode.
|
|
//
|
|
|
|
//
|
|
// Set Height of font.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, 0x9);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR,
|
|
(UCHAR)(FontInformation->HeightInPixels - 1));
|
|
|
|
//
|
|
// Set Width of font.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, 0x12);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR,
|
|
(UCHAR)(((USHORT)FontInformation->HeightInPixels *
|
|
(USHORT)HwDeviceExtension->CurrentMode->row) - 1));
|
|
|
|
i = HwDeviceExtension->CurrentMode->vres /
|
|
HwDeviceExtension->CurrentMode->row;
|
|
|
|
//
|
|
// Set Cursor End
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, 0xb);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR, (UCHAR)--i);
|
|
|
|
//
|
|
// Set Cursor Statr
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, 0xa);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR, (UCHAR)--i);
|
|
|
|
return NO_ERROR;
|
|
|
|
} //end VgaLoadAndSetFont()
|
|
|
|
VP_STATUS
|
|
VgaQueryCursorPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_POSITION CursorPosition,
|
|
ULONG CursorPositionSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine returns the row and column of the cursor.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
CursorPosition - Pointer to the output buffer supplied by the user. This
|
|
is where the cursor position is stored.
|
|
|
|
CursorPositionSize - Length of the output buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a buffer in which to return the actual size of
|
|
the data in the buffer. If the buffer was not large enough, this
|
|
contains the minimum required buffer size.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
ERROR_INVALID_PARAMETER - invalid video mode
|
|
|
|
--*/
|
|
|
|
{
|
|
//
|
|
// check if a mode has been set
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode == NULL) {
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
|
|
|
//
|
|
// Text mode only; If we are in a graphics mode, return an error
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
|
|
|
*OutputSize = 0;
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// If the buffer passed in is not large enough return an
|
|
// appropriate error code.
|
|
//
|
|
|
|
if (CursorPositionSize < (*OutputSize = sizeof(VIDEO_CURSOR_POSITION)) ) {
|
|
|
|
*OutputSize = 0;
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Store the postition of the cursor into the buffer.
|
|
//
|
|
|
|
CursorPosition->Column = HwDeviceExtension->CursorPosition.Column;
|
|
CursorPosition->Row = HwDeviceExtension->CursorPosition.Row;
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaQueryCursorPosition()
|
|
|
|
VP_STATUS
|
|
VgaSetCursorPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_POSITION CursorPosition,
|
|
ULONG CursorPositionSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine verifies that the requested cursor position is within
|
|
the row and column bounds of the current mode and font. If valid, then
|
|
it sets the row and column of the cursor.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
CursorPosition - Pointer to the structure containing the cursor position.
|
|
|
|
CursorPositionSize - Length of the input buffer supplied by the user.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data
|
|
|
|
ERROR_INVALID_PARAMETER - invalid video mode
|
|
|
|
--*/
|
|
|
|
{
|
|
USHORT position;
|
|
|
|
//
|
|
// check if a mode has been set
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode == NULL) {
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
|
|
|
//
|
|
// Text mode only; If we are in a graphics mode, return an error
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check if the size of the data in the input buffer is large enough.
|
|
//
|
|
|
|
if (CursorPositionSize < sizeof(VIDEO_CURSOR_POSITION)) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check if the new values for the cursor positions are in the valid
|
|
// bounds for the screen.
|
|
//
|
|
|
|
if ((CursorPosition->Column >= HwDeviceExtension->CurrentMode->col) ||
|
|
(CursorPosition->Row >= HwDeviceExtension->CurrentMode->row)) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Store these new values in the device extension so we can use them in
|
|
// a QUERY.
|
|
//
|
|
|
|
HwDeviceExtension->CursorPosition.Column = CursorPosition->Column;
|
|
HwDeviceExtension->CursorPosition.Row = CursorPosition->Row;
|
|
|
|
//
|
|
// Calculate the position on the screen at which the cursor must be
|
|
// be displayed
|
|
//
|
|
|
|
position = (USHORT) (HwDeviceExtension->CurrentMode->col *
|
|
CursorPosition->Row + CursorPosition->Column);
|
|
|
|
|
|
//
|
|
// Address Cursor Location Low Register in CRT Controller Registers
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, IND_CURSOR_LOW_LOC);
|
|
|
|
//
|
|
// Set Cursor Location Low Register
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR, (UCHAR) (position & 0x00FF));
|
|
|
|
//
|
|
// Address Cursor Location High Register in CRT Controller Registers
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, IND_CURSOR_HIGH_LOC);
|
|
|
|
//
|
|
// Set Cursor Location High Register
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR, (UCHAR) (position >> 8));
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaSetCursorPosition()
|
|
|
|
VP_STATUS
|
|
VgaQueryCursorAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
|
ULONG CursorAttributesSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine returns information about the height and visibility of the
|
|
cursor.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
CursorAttributes - Pointer to the output buffer supplied by the user.
|
|
This is where the cursor type is stored.
|
|
|
|
CursorAttributesSize - Length of the output buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a buffer in which to return the actual size of
|
|
the data in the buffer. If the buffer was not large enough, this
|
|
contains the minimum required buffer size.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
ERROR_INVALID_PARAMETER - invalid video mode
|
|
|
|
--*/
|
|
|
|
{
|
|
//
|
|
// check if a mode has been set
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode == NULL) {
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
|
|
|
//
|
|
// Text mode only; If we are in a graphics mode, return an error
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
|
|
|
*OutputSize = 0;
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Find out the size of the data to be put in the the buffer and return
|
|
// that in the status information (whether or not the information is
|
|
// there). If the buffer passed in is not large enough return an
|
|
// appropriate error code.
|
|
//
|
|
|
|
if (CursorAttributesSize < (*OutputSize =
|
|
sizeof(VIDEO_CURSOR_ATTRIBUTES)) ) {
|
|
|
|
*OutputSize = 0;
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Store the cursor information into the buffer.
|
|
//
|
|
|
|
CursorAttributes->Height = (USHORT) HwDeviceExtension->CursorTopScanLine;
|
|
CursorAttributes->Width = (USHORT) HwDeviceExtension->CursorBottomScanLine;
|
|
CursorAttributes->Enable = HwDeviceExtension->CursorEnable;
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaQueryCursorAttributes()
|
|
|
|
VP_STATUS
|
|
VgaSetCursorAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CURSOR_ATTRIBUTES CursorAttributes,
|
|
ULONG CursorAttributesSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine verifies that the requested cursor height is within the
|
|
bounds of the character cell. If valid, then it sets the new
|
|
visibility and height of the cursor.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
CursorType - Pointer to the structure containing the cursor information.
|
|
|
|
CursorTypeSize - Length of the input buffer supplied by the user.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data
|
|
|
|
ERROR_INVALID_PARAMETER - invalid video mode
|
|
|
|
--*/
|
|
|
|
{
|
|
UCHAR cursorLine;
|
|
|
|
//
|
|
// check if a mode has been set
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode == NULL) {
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
|
|
|
//
|
|
// Text mode only; If we are in a graphics mode, return an error
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode->fbType & VIDEO_MODE_GRAPHICS) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check if the size of the data in the input buffer is large enough.
|
|
//
|
|
|
|
if (CursorAttributesSize < sizeof(VIDEO_CURSOR_ATTRIBUTES)) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check if the new values for the cursor type are in the valid range.
|
|
//
|
|
|
|
if ((CursorAttributes->Height >= HwDeviceExtension->FontPelRows) ||
|
|
(CursorAttributes->Width > 31)) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Store the cursor information in the device extension so we can use
|
|
// them in a QUERY.
|
|
//
|
|
|
|
HwDeviceExtension->CursorTopScanLine = (UCHAR) CursorAttributes->Height;
|
|
HwDeviceExtension->CursorBottomScanLine = (UCHAR) CursorAttributes->Width;
|
|
HwDeviceExtension->CursorEnable = CursorAttributes->Enable;
|
|
|
|
//
|
|
// Address Cursor Start Register in CRT Controller Registers
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR,
|
|
IND_CURSOR_START);
|
|
|
|
//
|
|
// Set Cursor Start Register by writting to CRTCtl Data Register
|
|
// Preserve the high three bits of this register.
|
|
//
|
|
// Only the Five low bits are used for the cursor height.
|
|
// Bit 5 is cursor enable, bit 6 and 7 preserved.
|
|
//
|
|
|
|
cursorLine = (UCHAR) CursorAttributes->Height & 0x1F;
|
|
|
|
cursorLine |= VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR) & 0xC0;
|
|
|
|
if (!CursorAttributes->Enable) {
|
|
|
|
cursorLine |= 0x20; // Flip cursor off bit
|
|
|
|
}
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + CRTC_DATA_PORT_COLOR,
|
|
cursorLine);
|
|
|
|
//
|
|
// Address Cursor End Register in CRT Controller Registers
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR,
|
|
IND_CURSOR_END);
|
|
|
|
//
|
|
// Set Cursor End Register. Preserve the high three bits of this
|
|
// register.
|
|
//
|
|
|
|
cursorLine = (UCHAR)
|
|
(CursorAttributes->Width < (USHORT) (HwDeviceExtension->FontPelRows - 1)) ?
|
|
CursorAttributes->Width : (HwDeviceExtension->FontPelRows - 1);
|
|
|
|
cursorLine &= 0x1f;
|
|
|
|
cursorLine |= VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR) & 0xE0;
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + CRTC_DATA_PORT_COLOR,
|
|
cursorLine);
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaSetCursorAttributes()
|
|
|
|
BOOLEAN
|
|
VgaIsPresent(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine returns TRUE if a VGA is present. Determining whether a VGA
|
|
is present is a two-step process. First, this routine walks bits through
|
|
the Bit Mask register, to establish that there are readable indexed
|
|
registers (EGAs normally don't have readable registers, and other adapters
|
|
are unlikely to have indexed registers). This test is done first because
|
|
it's a non-destructive EGA rejection test (correctly rejects EGAs, but
|
|
doesn't potentially mess up the screen or the accessibility of display
|
|
memory). Normally, this would be an adequate test, but some EGAs have
|
|
readable registers, so next, we check for the existence of the Chain4 bit
|
|
in the Memory Mode register; this bit doesn't exist in EGAs. It's
|
|
conceivable that there are EGAs with readable registers and a register bit
|
|
where Chain4 is stored, although I don't know of any; if a better test yet
|
|
is needed, memory could be written to in Chain4 mode, and then examined
|
|
plane by plane in non-Chain4 mode to make sure the Chain4 bit did what it's
|
|
supposed to do. However, the current test should be adequate to eliminate
|
|
just about all EGAs, and 100% of everything else.
|
|
|
|
If this function fails to find a VGA, it attempts to undo any damage it
|
|
may have inadvertently done while testing. The underlying assumption for
|
|
the damage control is that if there's any non-VGA adapter at the tested
|
|
ports, it's an EGA or an enhanced EGA, because: a) I don't know of any
|
|
other adapters that use 3C4/5 or 3CE/F, and b), if there are other
|
|
adapters, I certainly don't know how to restore their original states. So
|
|
all error recovery is oriented toward putting an EGA back in a writable
|
|
state, so that error messages are visible. The EGA's state on entry is
|
|
assumed to be text mode, so the Memory Mode register is restored to the
|
|
default state for text mode.
|
|
|
|
If a VGA is found, the VGA is returned to its original state after
|
|
testing is finished.
|
|
|
|
Arguments:
|
|
|
|
None.
|
|
s
|
|
Return Value:
|
|
|
|
TRUE if a VGA is present, FALSE if not.
|
|
|
|
--*/
|
|
|
|
{
|
|
UCHAR originalGCAddr;
|
|
UCHAR originalSCAddr;
|
|
UCHAR originalBitMask;
|
|
UCHAR originalReadMap;
|
|
UCHAR originalMemoryMode;
|
|
UCHAR testMask;
|
|
BOOLEAN returnStatus;
|
|
|
|
//
|
|
// Remember the original state of the Graphics Controller Address register.
|
|
//
|
|
|
|
originalGCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT);
|
|
|
|
//
|
|
// Write the Read Map register with a known state so we can verify
|
|
// that it isn't changed after we fool with the Bit Mask. This ensures
|
|
// that we're dealing with indexed registers, since both the Read Map and
|
|
// the Bit Mask are addressed at GRAPH_DATA_PORT.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
|
|
|
//
|
|
// If we can't read back the Graphics Address register setting we just
|
|
// performed, it's not readable and this isn't a VGA.
|
|
//
|
|
|
|
if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT) & GRAPH_ADDR_MASK) != IND_READ_MAP) {
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
//
|
|
// Set the Read Map register to a known state.
|
|
//
|
|
|
|
originalReadMap = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, READ_MAP_TEST_SETTING);
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT) != READ_MAP_TEST_SETTING) {
|
|
|
|
//
|
|
// The Read Map setting we just performed can't be read back; not a
|
|
// VGA. Restore the default Read Map state.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
//
|
|
// Remember the original setting of the Bit Mask register.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_BIT_MASK);
|
|
if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT) & GRAPH_ADDR_MASK) != IND_BIT_MASK) {
|
|
|
|
//
|
|
// The Graphics Address register setting we just made can't be read
|
|
// back; not a VGA. Restore the default Read Map state.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
originalBitMask = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT);
|
|
|
|
//
|
|
// Set up the initial test mask we'll write to and read from the Bit Mask.
|
|
//
|
|
|
|
testMask = 0xBB;
|
|
|
|
do {
|
|
|
|
//
|
|
// Write the test mask to the Bit Mask.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, testMask);
|
|
|
|
//
|
|
// Make sure the Bit Mask remembered the value.
|
|
//
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT) != testMask) {
|
|
|
|
//
|
|
// The Bit Mask is not properly writable and readable; not a VGA.
|
|
// Restore the Bit Mask and Read Map to their default states.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, BIT_MASK_DEFAULT);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
//
|
|
// Cycle the mask for next time.
|
|
//
|
|
|
|
testMask >>= 1;
|
|
|
|
} while (testMask != 0);
|
|
|
|
//
|
|
// There's something readable at GRAPH_DATA_PORT; now switch back and
|
|
// make sure that the Read Map register hasn't changed, to verify that
|
|
// we're dealing with indexed registers.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT) != READ_MAP_TEST_SETTING) {
|
|
|
|
//
|
|
// The Read Map is not properly writable and readable; not a VGA.
|
|
// Restore the Bit Mask and Read Map to their default states, in case
|
|
// this is an EGA, so subsequent writes to the screen aren't garbled.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, READ_MAP_DEFAULT);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_BIT_MASK);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, BIT_MASK_DEFAULT);
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
//
|
|
// We've pretty surely verified the existence of the Bit Mask register.
|
|
// Put the Graphics Controller back to the original state.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, originalReadMap);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_BIT_MASK);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, originalBitMask);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, originalGCAddr);
|
|
|
|
//
|
|
// Now, check for the existence of the Chain4 bit.
|
|
//
|
|
|
|
//
|
|
// Remember the original states of the Sequencer Address and Memory Mode
|
|
// registers.
|
|
//
|
|
|
|
originalSCAddr = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
|
if ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT) & SEQ_ADDR_MASK) != IND_MEMORY_MODE) {
|
|
|
|
//
|
|
// Couldn't read back the Sequencer Address register setting we just
|
|
// performed.
|
|
//
|
|
|
|
return FALSE;
|
|
}
|
|
originalMemoryMode = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT);
|
|
|
|
//
|
|
// Toggle the Chain4 bit and read back the result. This must be done during
|
|
// sync reset, since we're changing the chaining state.
|
|
//
|
|
|
|
//
|
|
// Begin sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Toggle the Chain4 bit.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT, (UCHAR)(originalMemoryMode ^ CHAIN4_MASK));
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT) != (UCHAR) (originalMemoryMode ^ CHAIN4_MASK)) {
|
|
|
|
//
|
|
// Chain4 bit not there; not a VGA.
|
|
// Set text mode default for Memory Mode register.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT, MEMORY_MODE_TEXT_DEFAULT);
|
|
//
|
|
// End sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
|
|
|
returnStatus = FALSE;
|
|
|
|
} else {
|
|
|
|
//
|
|
// It's a VGA.
|
|
//
|
|
|
|
//
|
|
// Restore the original Memory Mode setting.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT, originalMemoryMode);
|
|
|
|
//
|
|
// End sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT)(IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Restore the original Sequencer Address setting.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, originalSCAddr);
|
|
|
|
returnStatus = TRUE;
|
|
}
|
|
|
|
return returnStatus;
|
|
|
|
} // VgaIsPresent()
|
|
|
|
VP_STATUS
|
|
VgaSetPaletteReg(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_PALETTE_DATA PaletteBuffer,
|
|
ULONG PaletteBufferSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine sets a specified portion of the EGA (not DAC) palette
|
|
registers.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
PaletteBuffer - Pointer to the structure containing the palette data.
|
|
|
|
PaletteBufferSize - Length of the input buffer supplied by the user.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
|
|
|
|
ERROR_INVALID_PARAMETER - invalid palette size.
|
|
|
|
--*/
|
|
|
|
{
|
|
USHORT i;
|
|
|
|
//
|
|
// Check if the size of the data in the input buffer is large enough.
|
|
//
|
|
|
|
if ((PaletteBufferSize) < (sizeof(VIDEO_PALETTE_DATA)) ||
|
|
(PaletteBufferSize < (sizeof(VIDEO_PALETTE_DATA) +
|
|
(sizeof(USHORT) * (PaletteBuffer->NumEntries -1)) ))) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check to see if the parameters are valid.
|
|
//
|
|
|
|
if ( (PaletteBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER ) ||
|
|
(PaletteBuffer->NumEntries == 0) ||
|
|
(PaletteBuffer->FirstEntry + PaletteBuffer->NumEntries >
|
|
VIDEO_MAX_PALETTE_REGISTER + 1 ) ) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Reset ATC to index mode
|
|
//
|
|
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_INITIALIZE_PORT_COLOR);
|
|
|
|
//
|
|
// Blast out our palette values.
|
|
//
|
|
|
|
for (i = 0; i < PaletteBuffer->NumEntries; i++) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
|
|
(UCHAR)(i+PaletteBuffer->FirstEntry));
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_DATA_WRITE_PORT,
|
|
(UCHAR)PaletteBuffer->Colors[i]);
|
|
}
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + ATT_ADDRESS_PORT,
|
|
VIDEO_ENABLE);
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaSetPaletteReg()
|
|
|
|
|
|
VP_STATUS
|
|
VgaSetColorLookup(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_CLUT ClutBuffer,
|
|
ULONG ClutBufferSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine sets a specified portion of the DAC color lookup table
|
|
settings.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
ClutBufferSize - Length of the input buffer supplied by the user.
|
|
|
|
ClutBuffer - Pointer to the structure containing the color lookup table.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough for input data.
|
|
|
|
ERROR_INVALID_PARAMETER - invalid clut size.
|
|
|
|
--*/
|
|
|
|
{
|
|
USHORT i;
|
|
|
|
//
|
|
// Check if the size of the data in the input buffer is large enough.
|
|
//
|
|
|
|
if ( (ClutBufferSize < sizeof(VIDEO_CLUT) - sizeof(ULONG)) ||
|
|
(ClutBufferSize < sizeof(VIDEO_CLUT) +
|
|
(sizeof(ULONG) * (ClutBuffer->NumEntries - 1)) ) ) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Check to see if the parameters are valid.
|
|
//
|
|
|
|
if ( (ClutBuffer->NumEntries == 0) ||
|
|
(ClutBuffer->FirstEntry > VIDEO_MAX_COLOR_REGISTER) ||
|
|
(ClutBuffer->FirstEntry + ClutBuffer->NumEntries >
|
|
VIDEO_MAX_COLOR_REGISTER + 1) ) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Set CLUT registers directly on the hardware
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT,
|
|
(UCHAR) ClutBuffer->FirstEntry);
|
|
|
|
for (i = 0; i < ClutBuffer->NumEntries; i++) {
|
|
|
|
VideoPortWritePortBufferUchar((PUCHAR)HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT,
|
|
&(ClutBuffer->LookupTable[i].RgbArray.Red),
|
|
0x03);
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaSetColorLookup()
|
|
|
|
VP_STATUS
|
|
VgaRestoreHardwareState(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_HARDWARE_STATE HardwareState,
|
|
ULONG HardwareStateSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Restores all registers and memory of the VGA.
|
|
|
|
Note: HardwareState points to the actual buffer from which the state
|
|
is to be restored. This buffer will always be big enough (we specified
|
|
the required size at DriverEntry).
|
|
|
|
Note: The offset in the hardware state header from which each general
|
|
register is restored is the offset of the write address of that register
|
|
from the base I/O address of the VGA.
|
|
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
HardwareState - Pointer to a structure from which the saved state is to be
|
|
restored (actually only info about and a pointer to the actual save
|
|
buffer).
|
|
|
|
HardwareStateSize - Length of the input buffer supplied by the user.
|
|
(Actually only the size of the HardwareState structure, not the
|
|
buffer it points to from which the state is actually restored. The
|
|
pointed-to buffer is assumed to be big enough.)
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - restore performed successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough to provide data
|
|
|
|
--*/
|
|
|
|
{
|
|
PVIDEO_HARDWARE_STATE_HEADER hardwareStateHeader;
|
|
ULONG i;
|
|
UCHAR dummy;
|
|
PUCHAR pScreen;
|
|
PUCHAR pucLatch;
|
|
PULONG pulBuffer;
|
|
PUCHAR port;
|
|
PUCHAR portValue;
|
|
PUCHAR portValueDAC;
|
|
ULONG bIsColor;
|
|
|
|
//
|
|
// Check if the size of the data in the input buffer is large enough.
|
|
//
|
|
|
|
if ((HardwareStateSize < sizeof(VIDEO_HARDWARE_STATE)) ||
|
|
(HardwareState->StateLength < VGA_TOTAL_STATE_SIZE)) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Point to the buffer where the restore data is actually stored.
|
|
//
|
|
|
|
hardwareStateHeader = HardwareState->StateHeader;
|
|
|
|
//
|
|
// Make sure the offset are in the structure ...
|
|
//
|
|
|
|
if ((hardwareStateHeader->BasicSequencerOffset + VGA_NUM_SEQUENCER_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->BasicCrtContOffset + VGA_NUM_CRTC_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->BasicGraphContOffset + VGA_NUM_GRAPH_CONT_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->BasicAttribContOffset + VGA_NUM_ATTRIB_CONT_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->BasicDacOffset + (3 * VGA_NUM_DAC_ENTRIES) >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->BasicLatchesOffset + 4 >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->ExtendedSequencerOffset + EXT_NUM_SEQUENCER_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->ExtendedCrtContOffset + EXT_NUM_CRTC_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->ExtendedGraphContOffset + EXT_NUM_GRAPH_CONT_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->ExtendedAttribContOffset + EXT_NUM_ATTRIB_CONT_PORTS >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->ExtendedDacOffset + (4 * EXT_NUM_DAC_ENTRIES) >
|
|
HardwareState->StateLength) ||
|
|
|
|
//
|
|
// Only check the validator state offset if there is unemulated data.
|
|
//
|
|
|
|
((hardwareStateHeader->VGAStateFlags & VIDEO_STATE_UNEMULATED_VGA_STATE) &&
|
|
(hardwareStateHeader->ExtendedValidatorStateOffset + VGA_VALIDATOR_AREA_SIZE >
|
|
HardwareState->StateLength)) ||
|
|
|
|
(hardwareStateHeader->ExtendedMiscDataOffset + VGA_MISC_DATA_AREA_OFFSET >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->Plane1Offset + hardwareStateHeader->PlaneLength >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->Plane2Offset + hardwareStateHeader->PlaneLength >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->Plane3Offset + hardwareStateHeader->PlaneLength >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->Plane4Offset + hardwareStateHeader->PlaneLength >
|
|
HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->DIBOffset +
|
|
hardwareStateHeader->DIBBitsPerPixel / 8 *
|
|
hardwareStateHeader->DIBXResolution *
|
|
hardwareStateHeader->DIBYResolution > HardwareState->StateLength) ||
|
|
|
|
(hardwareStateHeader->DIBXlatOffset + hardwareStateHeader->DIBXlatLength >
|
|
HardwareState->StateLength)) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Turn off the screen to avoid flickering. The screen will turn back on
|
|
// when we restore the DAC state at the end of this routine.
|
|
//
|
|
// Wait for the leading edge of vertical sync, to blank the screen cleanly.
|
|
//
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
MISC_OUTPUT_REG_READ_PORT) & 0x01) {
|
|
port = INPUT_STATUS_1_COLOR + HwDeviceExtension->IOAddress;
|
|
} else {
|
|
port = INPUT_STATUS_1_MONO + HwDeviceExtension->IOAddress;
|
|
}
|
|
|
|
// while (VideoPortReadPortUchar(port) & 0x08)
|
|
// ; // wait for not vertical sync
|
|
|
|
// while (!(VideoPortReadPortUchar(port) & 0x08))
|
|
// ; // wait for vertical sync
|
|
|
|
//
|
|
// Set DAC register 0 to display black.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT, 0);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
|
|
//
|
|
// Set the DAC mask register to force DAC register 0 to display all the
|
|
// time (this is the register we just set to display black). From now on,
|
|
// nothing but black will show up on the screen.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_PIXEL_MASK_PORT, 0);
|
|
|
|
|
|
//
|
|
// Restore the latches and the contents of display memory.
|
|
//
|
|
// Set up the VGA's hardware to allow us to copy to each plane in turn.
|
|
//
|
|
// Begin sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Turn off Chain mode and map display memory at A0000 for 64K.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_GRAPH_MISC);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, (UCHAR) ((VideoPortReadPortUchar(
|
|
HwDeviceExtension->IOAddress + GRAPH_DATA_PORT) & 0xF1) | 0x04));
|
|
|
|
//
|
|
// Turn off Chain4 mode and odd/even.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT,
|
|
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT) & 0xF3) | 0x04));
|
|
|
|
//
|
|
// End sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Set the write mode to 0, the read mode to 0, and turn off odd/even.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_GRAPH_MODE);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT,
|
|
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT) & 0xE4) | 0x00));
|
|
|
|
//
|
|
// Set the Bit Mask to 0xFF to allow all CPU bits through.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT), (USHORT) (IND_BIT_MASK + (0xFF << 8)));
|
|
|
|
//
|
|
// Set the Data Rotation and Logical Function fields to 0 to allow CPU
|
|
// data through unmodified.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT), (USHORT) (IND_DATA_ROTATE + (0 << 8)));
|
|
|
|
//
|
|
// Set Set/Reset Enable to 0 to select CPU data for all planes.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT), (USHORT) (IND_SET_RESET_ENABLE + (0 << 8)));
|
|
|
|
//
|
|
// Point the Sequencer Index to the Map Mask register.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, IND_MAP_MASK);
|
|
|
|
//
|
|
// Restore the latches.
|
|
//
|
|
// Point to the saved data for the first latch.
|
|
//
|
|
|
|
pucLatch = ((PUCHAR) (hardwareStateHeader)) +
|
|
hardwareStateHeader->BasicLatchesOffset;
|
|
|
|
//
|
|
// Point to first byte of display memory.
|
|
//
|
|
|
|
pScreen = (PUCHAR) HwDeviceExtension->VideoMemoryAddress;
|
|
|
|
//
|
|
// Write the contents to be restored to each of the four latches in turn.
|
|
//
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
//
|
|
// Set the Map Mask to select the plane we want to restore next.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT, (UCHAR)(1<<i));
|
|
|
|
//
|
|
// Write this plane's latch.
|
|
//
|
|
|
|
VideoPortWriteRegisterUchar(pScreen, *pucLatch++);
|
|
|
|
}
|
|
|
|
//
|
|
// Read the latched data into the latches, and the latches are set.
|
|
//
|
|
|
|
dummy = VideoPortReadRegisterUchar(pScreen);
|
|
|
|
|
|
//
|
|
// Point to the offset of the saved data for the first plane.
|
|
//
|
|
|
|
pulBuffer = &(hardwareStateHeader->Plane1Offset);
|
|
|
|
//
|
|
// Restore each of the four planes in turn.
|
|
//
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
//
|
|
// Set the Map Mask to select the plane we want to restore next.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT, (UCHAR)(1<<i));
|
|
|
|
//
|
|
// Restore this plane from the buffer.
|
|
//
|
|
|
|
VideoPortMoveMemory((PUCHAR) HwDeviceExtension->VideoMemoryAddress,
|
|
((PUCHAR) (hardwareStateHeader)) + *pulBuffer,
|
|
hardwareStateHeader->PlaneLength);
|
|
|
|
pulBuffer++;
|
|
|
|
}
|
|
|
|
//
|
|
// If we have some unemulated data, put it back into the buffer
|
|
//
|
|
|
|
if (hardwareStateHeader->VGAStateFlags & VIDEO_STATE_UNEMULATED_VGA_STATE) {
|
|
|
|
if (!hardwareStateHeader->ExtendedValidatorStateOffset) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
//
|
|
// Get the right offset in the struct and save all the data associated
|
|
// with the trapped validator data.
|
|
//
|
|
|
|
VideoPortMoveMemory(&(HwDeviceExtension->TrappedValidatorCount),
|
|
((PUCHAR) (hardwareStateHeader)) +
|
|
hardwareStateHeader->ExtendedValidatorStateOffset,
|
|
VGA_VALIDATOR_AREA_SIZE);
|
|
|
|
//
|
|
// Check to see if this is an appropriate access range.
|
|
// We are trapping - so we must have the trapping access range enabled.
|
|
//
|
|
|
|
if (((HwDeviceExtension->CurrentVdmAccessRange != FullVgaValidatorAccessRange) ||
|
|
(HwDeviceExtension->CurrentNumVdmAccessRanges != NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE)) &&
|
|
((HwDeviceExtension->CurrentVdmAccessRange != MinimalVgaValidatorAccessRange) ||
|
|
(HwDeviceExtension->CurrentNumVdmAccessRanges != NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE))) {
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
}
|
|
|
|
VideoPortSetTrappedEmulatorPorts(HwDeviceExtension,
|
|
HwDeviceExtension->CurrentNumVdmAccessRanges,
|
|
HwDeviceExtension->CurrentVdmAccessRange);
|
|
|
|
}
|
|
|
|
//
|
|
// Set the critical registers (clock and timing states) during sync reset.
|
|
//
|
|
// Begin sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
|
|
(START_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Restore the Miscellaneous Output register.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
MISC_OUTPUT_REG_WRITE_PORT,
|
|
(UCHAR) (hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] & 0xF7));
|
|
|
|
//
|
|
// Restore all Sequencer registers except the Sync Reset register, which
|
|
// is always not in reset (except when we send out a batched sync reset
|
|
// register set, but that can't be interrupted, so we know we're never in
|
|
// sync reset at save/restore time).
|
|
//
|
|
|
|
portValue = ((PUCHAR) hardwareStateHeader) +
|
|
hardwareStateHeader->BasicSequencerOffset + 1;
|
|
|
|
for (i = 1; i < VGA_NUM_SEQUENCER_PORTS; i++) {
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT), (USHORT) (i + ((*portValue++) << 8)) );
|
|
|
|
}
|
|
|
|
//
|
|
// Restore the Graphics Controller Miscellaneous register, which contains
|
|
// the Chain bit.
|
|
//
|
|
|
|
portValue = ((PUCHAR) hardwareStateHeader) +
|
|
hardwareStateHeader->BasicGraphContOffset + IND_GRAPH_MISC;
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT), (USHORT)(IND_GRAPH_MISC + (*portValue << 8)));
|
|
|
|
//
|
|
// End sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT), (USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Figure out if color/mono switchable registers are at 3BX or 3DX.
|
|
// At the same time, save the state of the Miscellaneous Output register
|
|
// which is read from 3CC but written at 3C2.
|
|
//
|
|
|
|
if (hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] & 0x01) {
|
|
bIsColor = TRUE;
|
|
} else {
|
|
bIsColor = FALSE;
|
|
}
|
|
|
|
|
|
//
|
|
// Restore the CRT Controller indexed registers.
|
|
//
|
|
// Unlock CRTC registers 0-7.
|
|
//
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader +
|
|
hardwareStateHeader->BasicCrtContOffset;
|
|
|
|
if (bIsColor) {
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR), (USHORT) (IND_CRTC_PROTECT +
|
|
(((*(portValue + IND_CRTC_PROTECT)) & 0x7F) << 8)));
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO), (USHORT) (IND_CRTC_PROTECT +
|
|
(((*(portValue + IND_CRTC_PROTECT)) & 0x7F) << 8)));
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Now restore the CRTC registers.
|
|
//
|
|
|
|
for (i = 0; i < VGA_NUM_CRTC_PORTS; i++) {
|
|
|
|
if (bIsColor) {
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR),
|
|
(USHORT) (i + ((*portValue++) << 8)));
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO),
|
|
(USHORT) (i + ((*portValue++) << 8)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Restore the Graphics Controller indexed registers.
|
|
//
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader +
|
|
hardwareStateHeader->BasicGraphContOffset;
|
|
|
|
for (i = 0; i < VGA_NUM_GRAPH_CONT_PORTS; i++) {
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT), (USHORT) (i + ((*portValue++) << 8)));
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Restore the Attribute Controller indexed registers.
|
|
//
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader +
|
|
hardwareStateHeader->BasicAttribContOffset;
|
|
|
|
//
|
|
// Reset the AC index/data toggle, then blast out all the register
|
|
// settings.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
INPUT_STATUS_1_COLOR);
|
|
} else {
|
|
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
INPUT_STATUS_1_MONO);
|
|
}
|
|
|
|
for (i = 0; i < VGA_NUM_ATTRIB_CONT_PORTS; i++) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_ADDRESS_PORT, (UCHAR)i);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_DATA_WRITE_PORT, *portValue++);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Restore DAC registers 1 through 255. We'll do register 0, the DAC Mask,
|
|
// and the index registers later.
|
|
//
|
|
// Wait for the leading edge of vertical sync, so we can read out the DAC
|
|
// registers without causing sparkles on the screen.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_COLOR;
|
|
} else {
|
|
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_MONO;
|
|
}
|
|
|
|
// while (VideoPortReadPortUchar(port) & 0x08)
|
|
// ; // wait for not vertical sync
|
|
|
|
// while (!(VideoPortReadPortUchar(port) & 0x08))
|
|
// ; // wait for vertical sync
|
|
|
|
//
|
|
// Set the Write Index to one, to write to DAC register 1 first (we'll do
|
|
// register 0 later), then read out the 255 DAC registers other than
|
|
// register 0. Each successive three writes set Red, Green, and Blue
|
|
// components for that register, then the index autoincrements.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT, 1);
|
|
VideoPortWritePortBufferUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, (PUCHAR) hardwareStateHeader +
|
|
hardwareStateHeader->BasicDacOffset + 3,
|
|
(VGA_NUM_DAC_ENTRIES - 1) * 3);
|
|
|
|
|
|
//
|
|
// Extended registers are not supported in this driver.
|
|
//
|
|
|
|
|
|
//
|
|
// Restore the Feature Control register.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
FEAT_CTRL_WRITE_PORT_COLOR,
|
|
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_COLOR]);
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
FEAT_CTRL_WRITE_PORT_MONO,
|
|
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_MONO]);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Restore the Sequencer Index.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT,
|
|
hardwareStateHeader->PortValue[SEQ_ADDRESS_PORT]);
|
|
|
|
//
|
|
// Restore the CRT Controller Index.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR,
|
|
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_COLOR]);
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO,
|
|
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_MONO]);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Restore the Graphics Controller Index.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT,
|
|
hardwareStateHeader->PortValue[GRAPH_ADDRESS_PORT]);
|
|
|
|
|
|
//
|
|
// Restore the Attribute Controller Index and index/data toggle state.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_COLOR;
|
|
} else {
|
|
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_MONO;
|
|
}
|
|
|
|
VideoPortReadPortUchar(port); // reset the toggle to Index state
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_ADDRESS_PORT, // restore the AC Index
|
|
hardwareStateHeader->PortValue[ATT_ADDRESS_PORT]);
|
|
|
|
//
|
|
// If the toggle should be in Data state, we're all set. If it should be in
|
|
// Index state, reset it to that condition.
|
|
//
|
|
|
|
if (hardwareStateHeader->AttribIndexDataState == 0) {
|
|
|
|
//
|
|
// Reset the toggle to Index state.
|
|
//
|
|
|
|
VideoPortReadPortUchar(port);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Restore DAC register 0 and the DAC Mask, to unblank the screen.
|
|
//
|
|
|
|
portValueDAC = (PUCHAR) hardwareStateHeader +
|
|
hardwareStateHeader->BasicDacOffset;
|
|
|
|
//
|
|
// Restore the DAC Mask register.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_PIXEL_MASK_PORT,
|
|
hardwareStateHeader->PortValue[DAC_PIXEL_MASK_PORT]);
|
|
|
|
//
|
|
// Restore DAC register 0.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT, 0);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, *portValueDAC++);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, *portValueDAC++);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, *portValueDAC++);
|
|
|
|
|
|
//
|
|
// Restore the read/write state and the current index of the DAC.
|
|
//
|
|
// See whether the Read or Write Index was written to most recently.
|
|
// (The upper nibble stored at DAC_STATE_PORT is the # of reads/writes
|
|
// for the current index.)
|
|
//
|
|
|
|
if ((hardwareStateHeader->PortValue[DAC_STATE_PORT] & 0x0F) == 3) {
|
|
|
|
//
|
|
// The DAC Read Index was written to last. Restore the DAC by setting
|
|
// up to read from the saved index - 1, because the way the Read
|
|
// Index works is that it autoincrements after reading, so you actually
|
|
// end up reading the data for the index you read at the DAC Write
|
|
// Mask register - 1.
|
|
//
|
|
// Set the Read Index to the index we read, minus 1, accounting for
|
|
// wrap from 255 back to 0. The DAC hardware immediately reads this
|
|
// register into a temporary buffer, then adds 1 to the index.
|
|
//
|
|
|
|
if (hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] == 0) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_READ_PORT, 255);
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_READ_PORT, (UCHAR)
|
|
(hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] -
|
|
1));
|
|
|
|
}
|
|
|
|
//
|
|
// Now read the hardware however many times are required to get to
|
|
// the partial read state we saved.
|
|
//
|
|
|
|
for (i = hardwareStateHeader->PortValue[DAC_STATE_PORT] >> 4;
|
|
i > 0; i--) {
|
|
|
|
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
// The DAC Write Index was written to last. Set the Write Index to the
|
|
// index value we read out of the DAC. Then, if a partial write
|
|
// (partway through an RGB triplet) was in place, write the partial
|
|
// values, which we obtained by writing them to the current DAC
|
|
// register. This DAC register will be wrong until the write is
|
|
// completed, but at least the values will be right once the write is
|
|
// finished, and most importantly we won't have messed up the sequence
|
|
// of RGB writes (which can be as long as 768 in a row).
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT,
|
|
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]);
|
|
|
|
//
|
|
// Now write to the hardware however many times are required to get to
|
|
// the partial write state we saved (if any).
|
|
//
|
|
// Point to the saved value for the DAC register that was in the
|
|
// process of being written to; we wrote the partial value out, so now
|
|
// we can restore it.
|
|
//
|
|
|
|
portValueDAC = (PUCHAR) hardwareStateHeader +
|
|
hardwareStateHeader->BasicDacOffset +
|
|
(hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] * 3);
|
|
|
|
for (i = hardwareStateHeader->PortValue[DAC_STATE_PORT] >> 4;
|
|
i > 0; i--) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, *portValueDAC++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaRestoreHardwareState()
|
|
|
|
VP_STATUS
|
|
VgaSaveHardwareState(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_HARDWARE_STATE HardwareState,
|
|
ULONG HardwareStateSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Saves all registers and memory of the VGA.
|
|
|
|
Note: HardwareState points to the actual buffer in which the state
|
|
is saved. This buffer will always be big enough (we specified
|
|
the required size at DriverEntry).
|
|
|
|
Note: This routine leaves registers in any state it cares to, except
|
|
that it will not mess with any of the CRT or Sequencer parameters that
|
|
might make the monitor unhappy. It leaves the screen blanked by setting
|
|
the DAC Mask and DAC register 0 to all zero values. The next video
|
|
operation we expect after this is a mode set to take us back to Win32.
|
|
|
|
Note: The offset in the hardware state header in which each general
|
|
register is saved is the offset of the write address of that register from
|
|
the base I/O address of the VGA.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
HardwareState - Pointer to a structure in which the saved state will be
|
|
returned (actually only info about and a pointer to the actual save
|
|
buffer).
|
|
|
|
HardwareStateSize - Length of the output buffer supplied by the user.
|
|
(Actually only the size of the HardwareState structure, not the
|
|
buffer it points to where the state is actually saved. The pointed-
|
|
to buffer is assumed to be big enough.)
|
|
|
|
OutputSize - Pointer to a buffer in which to return the actual size of
|
|
the data returned in the buffer.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
--*/
|
|
|
|
{
|
|
PVIDEO_HARDWARE_STATE_HEADER hardwareStateHeader;
|
|
PUCHAR port;
|
|
PUCHAR pScreen;
|
|
PUCHAR portValue;
|
|
PUCHAR portValueDAC;
|
|
PUCHAR bufferPointer;
|
|
ULONG i;
|
|
UCHAR dummy, originalACIndex, originalACData;
|
|
UCHAR ucCRTC03;
|
|
ULONG bIsColor;
|
|
|
|
|
|
//
|
|
// See if the buffer is big enough to hold the hardware state structure.
|
|
// (This is only the HardwareState structure itself, not the buffer it
|
|
// points to.)
|
|
//
|
|
|
|
if (HardwareStateSize < sizeof(VIDEO_HARDWARE_STATE) ) {
|
|
|
|
*OutputSize = 0; // nothing returned
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Amount of data we're going to return in the output buffer.
|
|
// (The VIDEO_HARDWARE_STATE in the output buffer points to the actual
|
|
// buffer in which the state is stored, which is assumed to be large
|
|
// enough.)
|
|
//
|
|
|
|
*OutputSize = sizeof(VIDEO_HARDWARE_STATE);
|
|
|
|
//
|
|
// Indicate the size of the full state save info.
|
|
//
|
|
|
|
HardwareState->StateLength = VGA_TOTAL_STATE_SIZE;
|
|
|
|
//
|
|
// hardwareStateHeader is a structure of offsets at the start of the
|
|
// actual save area that indicates the locations in which various VGA
|
|
// register and memory components are saved.
|
|
//
|
|
|
|
hardwareStateHeader = HardwareState->StateHeader;
|
|
|
|
//
|
|
// Zero out the structure.
|
|
//
|
|
|
|
VideoPortZeroMemory(hardwareStateHeader, sizeof(VIDEO_HARDWARE_STATE_HEADER));
|
|
|
|
//
|
|
// Set the Length field, which is basically a version ID.
|
|
//
|
|
|
|
hardwareStateHeader->Length = sizeof(VIDEO_HARDWARE_STATE_HEADER);
|
|
|
|
//
|
|
// Set the basic register offsets properly.
|
|
//
|
|
|
|
hardwareStateHeader->BasicSequencerOffset = VGA_BASIC_SEQUENCER_OFFSET;
|
|
hardwareStateHeader->BasicCrtContOffset = VGA_BASIC_CRTC_OFFSET;
|
|
hardwareStateHeader->BasicGraphContOffset = VGA_BASIC_GRAPH_CONT_OFFSET;
|
|
hardwareStateHeader->BasicAttribContOffset = VGA_BASIC_ATTRIB_CONT_OFFSET;
|
|
hardwareStateHeader->BasicDacOffset = VGA_BASIC_DAC_OFFSET;
|
|
hardwareStateHeader->BasicLatchesOffset = VGA_BASIC_LATCHES_OFFSET;
|
|
|
|
//
|
|
// Figure out if color/mono switchable registers are at 3BX or 3DX.
|
|
// At the same time, save the state of the Miscellaneous Output register
|
|
// which is read from 3CC but written at 3C2.
|
|
//
|
|
|
|
if ((hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
MISC_OUTPUT_REG_READ_PORT))
|
|
& 0x01) {
|
|
bIsColor = TRUE;
|
|
} else {
|
|
bIsColor = FALSE;
|
|
}
|
|
|
|
//
|
|
// Force the video subsystem enable state to enabled.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
VIDEO_SUBSYSTEM_ENABLE_PORT, 1);
|
|
|
|
//
|
|
// Save the DAC state first, so we can set the DAC to blank the screen
|
|
// so nothing after this shows up at all.
|
|
//
|
|
// Save the DAC Mask register.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[DAC_PIXEL_MASK_PORT] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_PIXEL_MASK_PORT);
|
|
|
|
//
|
|
// Save the DAC Index register. Note that there is actually only one DAC
|
|
// Index register, which functions as either the Read Index or the Write
|
|
// Index as needed.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT);
|
|
|
|
//
|
|
// Save the DAC read/write state. We determine if the DAC has been written
|
|
// to or read from at the current index 0, 1, or 2 times (the application
|
|
// is in the middle of reading or writing a DAC register triplet if the
|
|
// count is 1 or 2), and save enough info so we can restore things
|
|
// properly. The only hole is if the application writes to the Write Index,
|
|
// then reads from instead of writes to the Data register, or vice-versa,
|
|
// or if they do a partial read write, then never finish it.
|
|
// This is fairly ridiculous behavior, however, and anyway there's nothing
|
|
// we can do about it.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[DAC_STATE_PORT] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_STATE_PORT);
|
|
|
|
if (hardwareStateHeader->PortValue[DAC_STATE_PORT] == 3) {
|
|
|
|
//
|
|
// The DAC Read Index was written to last. Figure out how many reads
|
|
// have been done from the current index. We'll restart this on restore
|
|
// by setting the Read Index to the current index - 1 (the read index
|
|
// is one greater than the index being read), then doing the proper
|
|
// number of reads.
|
|
//
|
|
// Read the Data register once, and see if the index changes.
|
|
//
|
|
|
|
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT);
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT) !=
|
|
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
|
|
|
//
|
|
// The DAC Index changed, so two reads had already been done from
|
|
// the current index. Store the count "2" in the upper nibble of
|
|
// the read/write state field.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x20;
|
|
|
|
} else {
|
|
|
|
//
|
|
// Read the Data register again, and see if the index changes.
|
|
//
|
|
|
|
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT);
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT) !=
|
|
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
|
|
|
//
|
|
// The DAC Index changed, so one read had already been done
|
|
// from the current index. Store the count "1" in the upper
|
|
// nibble of the read/write state field.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x10;
|
|
}
|
|
|
|
//
|
|
// If neither 2 nor 1 reads had been done from the current index,
|
|
// then 0 reads were done, and we're all set, since the upper
|
|
// nibble of the read/write state field is already 0.
|
|
//
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
//
|
|
// The DAC Write Index was written to last. Figure out how many writes
|
|
// have been done to the current index. We'll restart this on restore
|
|
// by setting the Write Index to the proper index, then doing the
|
|
// proper number of writes. When we do the DAC register save, we'll
|
|
// read out the value that gets written (if there was a partial write
|
|
// in progress), so we can restore the proper data later. This will
|
|
// cause this current DAC location to be briefly wrong in the 1- and
|
|
// 2-bytes-written case (until the app finishes the write), but that's
|
|
// better than having the wrong DAC values written for good.
|
|
//
|
|
// Write the Data register once, and see if the index changes.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT) !=
|
|
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
|
|
|
//
|
|
// The DAC Index changed, so two writes had already been done to
|
|
// the current index. Store the count "2" in the upper nibble of
|
|
// the read/write state field.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x20;
|
|
|
|
} else {
|
|
|
|
//
|
|
// Write the Data register again, and see if the index changes.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT) !=
|
|
hardwareStateHeader->PortValue[DAC_ADDRESS_WRITE_PORT]) {
|
|
|
|
//
|
|
// The DAC Index changed, so one write had already been done
|
|
// to the current index. Store the count "1" in the upper
|
|
// nibble of the read/write state field.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[DAC_STATE_PORT] |= 0x10;
|
|
}
|
|
|
|
//
|
|
// If neither 2 nor 1 writes had been done to the current index,
|
|
// then 0 writes were done, and we're all set.
|
|
//
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Now, read out the 256 18-bit DAC palette registers (256 RGB triplets),
|
|
// and blank the screen.
|
|
//
|
|
|
|
portValueDAC = (PUCHAR) hardwareStateHeader + VGA_BASIC_DAC_OFFSET;
|
|
|
|
//
|
|
// Read out DAC register 0, so we can set it to black.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_READ_PORT, 0);
|
|
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT);
|
|
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT);
|
|
*portValueDAC++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT);
|
|
|
|
//
|
|
// Set DAC register 0 to display black.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_WRITE_PORT, 0);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, 0);
|
|
|
|
//
|
|
// Set the DAC mask register to force DAC register 0 to display all the
|
|
// time (this is the register we just set to display black). From now on,
|
|
// nothing but black will show up on the screen.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_PIXEL_MASK_PORT, 0);
|
|
|
|
//
|
|
// Wait until we've gotten the Attribute Controller toggle state to save
|
|
// the rest of the DAC registers, so we can wait for vertical sync.
|
|
//
|
|
|
|
|
|
//
|
|
// Read out the Attribute Controller Index state, and deduce the Index/Data
|
|
// toggle state at the same time.
|
|
//
|
|
// Save the state of the Attribute Controller, both Index and Data,
|
|
// so we can test in which state the toggle currently is.
|
|
//
|
|
|
|
originalACIndex = hardwareStateHeader->PortValue[ATT_ADDRESS_PORT] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_ADDRESS_PORT);
|
|
originalACData = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_DATA_READ_PORT);
|
|
|
|
//
|
|
// Sequencer Index.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[SEQ_ADDRESS_PORT] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT);
|
|
|
|
//
|
|
// Begin sync reset, just in case this is an SVGA and the currently
|
|
// indexed Attribute Controller register controls clocking stuff (a
|
|
// normal VGA won't require this).
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Now, write a different Index setting to the Attribute Controller, and
|
|
// see if the Index changes.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_ADDRESS_PORT, (UCHAR) (originalACIndex ^ 0x10));
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_ADDRESS_PORT) == originalACIndex) {
|
|
|
|
//
|
|
// The Index didn't change, so the toggle was in the Data state.
|
|
//
|
|
|
|
hardwareStateHeader->AttribIndexDataState = 1;
|
|
|
|
//
|
|
// Restore the original Data state; we just corrupted it, and we need
|
|
// to read it out later; also, it may glitch the screen if not
|
|
// corrected. The toggle is already in the Index state.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_ADDRESS_PORT, originalACIndex);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_DATA_WRITE_PORT, originalACData);
|
|
|
|
} else {
|
|
|
|
//
|
|
// The Index did change, so the toggle was in the Index state.
|
|
// No need to restore anything, because the Data register didn't
|
|
// change, and we've already read out the Index register.
|
|
//
|
|
|
|
hardwareStateHeader->AttribIndexDataState = 0;
|
|
|
|
}
|
|
|
|
//
|
|
// End sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
|
|
|
|
|
//
|
|
// Save the rest of the DAC registers.
|
|
//
|
|
// Wait for the leading edge of vertical sync, so we can read out the DAC
|
|
// registers without causing sparkles on the screen.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_COLOR;
|
|
} else {
|
|
port = HwDeviceExtension->IOAddress + INPUT_STATUS_1_MONO;
|
|
}
|
|
|
|
// while (VideoPortReadPortUchar(port) & 0x08)
|
|
// ; // wait for not vertical sync
|
|
|
|
// while (!(VideoPortReadPortUchar(port) & 0x08))
|
|
// ; // wait for vertical sync
|
|
|
|
//
|
|
// Set the Read Index to one, to read DAC register 1 first (we already read
|
|
// register 0), then read out the other 255 DAC registers. Each successive
|
|
// three reads get Red, Green, and Blue components for that register, then
|
|
// the index autoincrements.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
DAC_ADDRESS_READ_PORT, 1);
|
|
|
|
VideoPortReadPortBufferUchar((PUCHAR) HwDeviceExtension->IOAddress +
|
|
DAC_DATA_REG_PORT, portValueDAC, (VGA_NUM_DAC_ENTRIES - 1) * 3);
|
|
|
|
|
|
//
|
|
// The Feature Control register is read from 3CA but written at 3BA/3DA.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
|
|
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_COLOR] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
FEAT_CTRL_READ_PORT);
|
|
|
|
} else {
|
|
|
|
hardwareStateHeader->PortValue[FEAT_CTRL_WRITE_PORT_MONO] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
FEAT_CTRL_READ_PORT);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
// CRT Controller Index.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
|
|
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_COLOR] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR);
|
|
|
|
} else {
|
|
|
|
hardwareStateHeader->PortValue[CRTC_ADDRESS_PORT_MONO] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Graphics Controller Index.
|
|
//
|
|
|
|
hardwareStateHeader->PortValue[GRAPH_ADDRESS_PORT] =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT);
|
|
|
|
|
|
//
|
|
// Sequencer indexed registers.
|
|
//
|
|
|
|
portValue = ((PUCHAR) hardwareStateHeader) + VGA_BASIC_SEQUENCER_OFFSET;
|
|
|
|
for (i = 0; i < VGA_NUM_SEQUENCER_PORTS; i++) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, (UCHAR)i);
|
|
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// CRT Controller indexed registers.
|
|
//
|
|
|
|
//
|
|
// Remember the state of CRTC register 3, then force bit 7
|
|
// to 1 so we will read back the Vertical Retrace start and
|
|
// end registers rather than the light pen info.
|
|
//
|
|
|
|
if (bIsColor) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, 3);
|
|
ucCRTC03 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR, (UCHAR) (ucCRTC03 | 0x80));
|
|
} else {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO, 3);
|
|
ucCRTC03 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_MONO);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_MONO, (UCHAR) (ucCRTC03 | 0x80));
|
|
}
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_CRTC_OFFSET;
|
|
|
|
for (i = 0; i < VGA_NUM_CRTC_PORTS; i++) {
|
|
|
|
if (bIsColor) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, (UCHAR)i);
|
|
*portValue++ =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR);
|
|
} else {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO, (UCHAR)i);
|
|
*portValue++ =
|
|
VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_MONO);
|
|
}
|
|
|
|
}
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_CRTC_OFFSET;
|
|
portValue[3] = ucCRTC03;
|
|
|
|
|
|
//
|
|
// Graphics Controller indexed registers.
|
|
//
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_GRAPH_CONT_OFFSET;
|
|
|
|
for (i = 0; i < VGA_NUM_GRAPH_CONT_PORTS; i++) {
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, (UCHAR)i);
|
|
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT);
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Attribute Controller indexed registers.
|
|
//
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_ATTRIB_CONT_OFFSET;
|
|
|
|
//
|
|
// For each indexed AC register, reset the flip-flop for reading the
|
|
// attribute register, then write the desired index to the AC Index,
|
|
// then read the value of the indexed register from the AC Data register.
|
|
//
|
|
|
|
for (i = 0; i < VGA_NUM_ATTRIB_CONT_PORTS; i++) {
|
|
|
|
if (bIsColor) {
|
|
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
INPUT_STATUS_1_COLOR);
|
|
} else {
|
|
dummy = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
INPUT_STATUS_1_MONO);
|
|
}
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_ADDRESS_PORT, (UCHAR)i);
|
|
*portValue++ = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
ATT_DATA_READ_PORT);
|
|
|
|
}
|
|
|
|
//
|
|
// Save the latches. This destroys one byte of display memory in each
|
|
// plane, which is unfortunate but unavoidable. Chips that provide
|
|
// a way to read back the latches can avoid this problem.
|
|
//
|
|
// Set up the VGA's hardware so we can write the latches, then read them
|
|
// back.
|
|
//
|
|
|
|
//
|
|
// Begin sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Set the Miscellaneous register to make sure we can access video RAM.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
MISC_OUTPUT_REG_WRITE_PORT, (UCHAR)(
|
|
hardwareStateHeader->PortValue[MISC_OUTPUT_REG_WRITE_PORT] |
|
|
0x02));
|
|
|
|
//
|
|
// Turn off Chain mode and map display memory at A0000 for 64K.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_GRAPH_MISC);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT,
|
|
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT) & 0xF1) | 0x04));
|
|
|
|
//
|
|
// Turn off Chain4 mode and odd/even.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, IND_MEMORY_MODE);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT,
|
|
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT) & 0xF3) | 0x04));
|
|
|
|
//
|
|
// End sync reset.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET + (END_SYNC_RESET_VALUE << 8)));
|
|
|
|
//
|
|
// Set the Map Mask to write to all planes.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT), (USHORT) (IND_MAP_MASK + (0x0F << 8)));
|
|
|
|
//
|
|
// Set the write mode to 0, the read mode to 0, and turn off odd/even.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_GRAPH_MODE);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT,
|
|
(UCHAR) ((VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT) & 0xE4) | 0x01));
|
|
|
|
//
|
|
// Point to the last byte of display memory.
|
|
//
|
|
|
|
pScreen = (PUCHAR) HwDeviceExtension->VideoMemoryAddress +
|
|
VGA_PLANE_SIZE - 1;
|
|
|
|
//
|
|
// Write the latches to the last byte of display memory.
|
|
//
|
|
|
|
VideoPortWriteRegisterUchar(pScreen, 0);
|
|
|
|
//
|
|
// Cycle through the four planes, reading the latch data from each plane.
|
|
//
|
|
|
|
//
|
|
// Point the Graphics Controller Index to the Read Map register.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
|
|
|
portValue = (PUCHAR) hardwareStateHeader + VGA_BASIC_LATCHES_OFFSET;
|
|
|
|
for (i=0; i<4; i++) {
|
|
|
|
//
|
|
// Set the Read Map for the current plane.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, (UCHAR)i);
|
|
|
|
//
|
|
// Read the latched data we've written to memory.
|
|
//
|
|
|
|
*portValue++ = VideoPortReadRegisterUchar(pScreen);
|
|
|
|
}
|
|
|
|
//
|
|
// Set the VDM flags
|
|
// We are a standard VGA, and then check if we have unemulated state.
|
|
//
|
|
|
|
hardwareStateHeader->VGAStateFlags = 0;
|
|
|
|
if (HwDeviceExtension->TrappedValidatorCount) {
|
|
|
|
hardwareStateHeader->VGAStateFlags |= VIDEO_STATE_UNEMULATED_VGA_STATE;
|
|
|
|
//
|
|
// Save the VDM Emulator data
|
|
// No need to save the state of the seuencer port register for our
|
|
// emulated data since it may change when we come back. It will be
|
|
// recomputed.
|
|
//
|
|
|
|
hardwareStateHeader->ExtendedValidatorStateOffset = VGA_VALIDATOR_OFFSET;
|
|
|
|
VideoPortMoveMemory(((PUCHAR) (hardwareStateHeader)) +
|
|
hardwareStateHeader->ExtendedValidatorStateOffset,
|
|
&(HwDeviceExtension->TrappedValidatorCount),
|
|
VGA_VALIDATOR_AREA_SIZE);
|
|
|
|
} else {
|
|
|
|
hardwareStateHeader->ExtendedValidatorStateOffset = 0;
|
|
|
|
}
|
|
|
|
//
|
|
// Set the size of each plane.
|
|
//
|
|
|
|
hardwareStateHeader->PlaneLength = VGA_PLANE_SIZE;
|
|
|
|
//
|
|
// Store all the offsets for the planes in the structure.
|
|
//
|
|
|
|
hardwareStateHeader->Plane1Offset = VGA_PLANE_0_OFFSET;
|
|
hardwareStateHeader->Plane2Offset = VGA_PLANE_1_OFFSET;
|
|
hardwareStateHeader->Plane3Offset = VGA_PLANE_2_OFFSET;
|
|
hardwareStateHeader->Plane4Offset = VGA_PLANE_3_OFFSET;
|
|
|
|
//
|
|
// Now copy the contents of video VRAM into the buffer.
|
|
//
|
|
// The VGA hardware is already set up so that video memory is readable;
|
|
// we already turned off Chain mode, mapped in at A0000, turned off Chain4,
|
|
// turned off odd/even, and set read mode 0 when we saved the latches.
|
|
//
|
|
// Point the Graphics Controller Index to the Read Map register.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_ADDRESS_PORT, IND_READ_MAP);
|
|
|
|
//
|
|
// Point to the save area for the first plane.
|
|
//
|
|
|
|
bufferPointer = ((PUCHAR) (hardwareStateHeader)) +
|
|
hardwareStateHeader->Plane1Offset;
|
|
|
|
//
|
|
// Save the four planes consecutively.
|
|
//
|
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
//
|
|
// Set the Read Map to select the plane we want to save next.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
GRAPH_DATA_PORT, (UCHAR)i);
|
|
|
|
//
|
|
// Copy this plane into the buffer.
|
|
//
|
|
|
|
VideoPortMoveMemory(bufferPointer,
|
|
(PUCHAR) HwDeviceExtension->VideoMemoryAddress,
|
|
VGA_PLANE_SIZE);
|
|
//
|
|
// Point to the next plane's save area.
|
|
//
|
|
|
|
bufferPointer += VGA_PLANE_SIZE;
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaSaveHardwareState()
|
|
|
|
VP_STATUS
|
|
VgaGetBankSelectCode(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_BANK_SELECT BankSelect,
|
|
ULONG BankSelectSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Returns information needed in order for caller to implement bank
|
|
management.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
BankSelectMode - Pointer to a VIDEO_MODE structure in which is
|
|
passed the mode for which bank select data is to be returned (input
|
|
buffer).
|
|
|
|
BankSelectModeSize - Length of the input buffer supplied by the user.
|
|
|
|
BankSelect - Pointer to a VIDEO_BANK_SELECT structure in which the bank
|
|
select data will be returned (output buffer).
|
|
|
|
BankSelectSize - Length of the output buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a variable in which to return the actual size of
|
|
the data returned in the output buffer.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_MORE_DATA - output buffer not large enough to hold all info (but
|
|
Size is returned, so caller can tell how large a buffer to allocate)
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
ERROR_INVALID_PARAMETER - invalid video mode selection
|
|
|
|
--*/
|
|
|
|
{
|
|
ULONG codeSize;
|
|
ULONG codePlanarSize;
|
|
PUCHAR pCodeDest;
|
|
PUCHAR pCodeBank;
|
|
PUCHAR pCodePlanarBank;
|
|
|
|
ULONG AdapterType = HwDeviceExtension->AdapterType;
|
|
PVIDEOMODE pMode = HwDeviceExtension->CurrentMode;
|
|
|
|
//
|
|
// check if a mode has been set
|
|
//
|
|
|
|
if (HwDeviceExtension->CurrentMode == NULL) {
|
|
|
|
return ERROR_INVALID_FUNCTION;
|
|
|
|
}
|
|
|
|
//
|
|
// The minimum passed buffer size is a VIDEO_BANK_SELECT
|
|
// structure, so that we can return the required size; we can't do
|
|
// anything if we don't have at least that much buffer.
|
|
//
|
|
|
|
if (BankSelectSize < sizeof(VIDEO_BANK_SELECT)) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Determine the banking type, and set whether any banking is actually
|
|
// supported in this mode.
|
|
//
|
|
|
|
BankSelect->BankingFlags = 0;
|
|
codeSize = 0;
|
|
codePlanarSize = 0;
|
|
pCodeBank = NULL;
|
|
|
|
switch(pMode->banktype) {
|
|
|
|
case NoBanking:
|
|
|
|
BankSelect->BankingType = VideoNotBanked;
|
|
BankSelect->Granularity = 0;
|
|
|
|
break;
|
|
|
|
case NormalBanking:
|
|
|
|
//
|
|
// The Vram supports independent 64K read and write banks in
|
|
// 16 color mode
|
|
//
|
|
|
|
BankSelect->BankingType = VideoBanked1R1W;
|
|
BankSelect->Granularity = 0x10000; // 64K bank start adjustment
|
|
|
|
pCodeBank = &BankSwitchStart;
|
|
codeSize = ((ULONG)&BankSwitchEnd) - ((ULONG)&BankSwitchStart);
|
|
|
|
break;
|
|
|
|
case PlanarHCBanking:
|
|
|
|
BankSelect->BankingFlags = PLANAR_HC; // planar mode supported
|
|
BankSelect->PlanarHCBankingType = pMode->VideoPlanarBank[AdapterType];
|
|
|
|
switch(BankSelect->PlanarHCBankingType) {
|
|
|
|
case VideoBanked2RW:
|
|
|
|
BankSelect->PlanarHCGranularity = 0x8000;
|
|
// 32K bank granularity
|
|
pCodePlanarBank = &PlanarHCBankSwitchStart256_2RW;
|
|
codePlanarSize = ((ULONG)&PlanarHCBankSwitchEnd256_2RW) -
|
|
((ULONG)&PlanarHCBankSwitchStart256_2RW);
|
|
|
|
break;
|
|
|
|
case VideoBanked1R1W:
|
|
|
|
BankSelect->PlanarHCGranularity = 0x10000;
|
|
// 64K bank granularity
|
|
pCodePlanarBank = &PlanarHCBankSwitchStart256;
|
|
codePlanarSize = ((ULONG)&PlanarHCBankSwitchEnd256) -
|
|
((ULONG)&PlanarHCBankSwitchStart256);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
VideoDebugPrint((1, "Unsupported planar bank type\n"));
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
//
|
|
// Fall through to Normal256Banking...
|
|
//
|
|
|
|
case Normal256Banking:
|
|
|
|
BankSelect->BankingType = pMode->VideoBank[AdapterType];
|
|
|
|
switch(BankSelect->BankingType) {
|
|
|
|
case VideoBanked1RW:
|
|
|
|
BankSelect->Granularity = 0x10000; // 64K bank granularity
|
|
pCodeBank = &BankSwitchStart256;
|
|
codeSize = ((ULONG)&BankSwitchEnd256) -
|
|
((ULONG)&BankSwitchStart256);
|
|
|
|
break;
|
|
|
|
case VideoBanked2RW:
|
|
|
|
BankSelect->Granularity = 0x1000; // 4K bank granularity
|
|
pCodeBank = &BankSwitchStart256_2RW;
|
|
codeSize = ((ULONG)&BankSwitchEnd256_2RW) -
|
|
((ULONG)&BankSwitchStart256_2RW);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
VideoDebugPrint((1, "Unsupported bank type\n"));
|
|
return ERROR_INVALID_PARAMETER;
|
|
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
//
|
|
// Size of banking info.
|
|
//
|
|
|
|
BankSelect->Size = sizeof(VIDEO_BANK_SELECT) + codeSize;
|
|
|
|
if (BankSelect->BankingFlags & PLANAR_HC) {
|
|
|
|
BankSelect->Size += codePlanarSize +
|
|
(((ULONG)&EnablePlanarHCEnd) - ((ULONG)&EnablePlanarHCStart)) +
|
|
(((ULONG)&DisablePlanarHCEnd) - ((ULONG)&DisablePlanarHCStart));
|
|
|
|
}
|
|
|
|
//
|
|
// This serves an a ID for the version of the structure we're using.
|
|
//
|
|
|
|
BankSelect->Length = sizeof(VIDEO_BANK_SELECT);
|
|
|
|
//
|
|
// If the buffer isn't big enough to hold all info, just return
|
|
// ERROR_MORE_DATA; Size is already set.
|
|
//
|
|
|
|
if (BankSelectSize < BankSelect->Size ) {
|
|
|
|
//
|
|
// We're returning only the VIDEO_BANK_SELECT structure.
|
|
//
|
|
|
|
*OutputSize = sizeof(VIDEO_BANK_SELECT);
|
|
return ERROR_MORE_DATA;
|
|
}
|
|
|
|
//
|
|
// There's room enough for everything, so fill in all fields in
|
|
// VIDEO_BANK_SELECT. (All fields are always returned; the caller can
|
|
// just choose to ignore them, based on BankingFlags and BankingType.)
|
|
//
|
|
|
|
BankSelect->BitmapWidthInBytes = pMode->wbytes;
|
|
BankSelect->BitmapSize = pMode->sbytes;
|
|
|
|
//
|
|
// Copy all banking code into the output buffer.
|
|
//
|
|
|
|
pCodeDest = (PUCHAR)BankSelect + sizeof(VIDEO_BANK_SELECT);
|
|
|
|
if (pCodeBank != NULL) {
|
|
|
|
BankSelect->CodeOffset = pCodeDest - (PUCHAR)BankSelect;
|
|
VideoPortMoveMemory(pCodeDest, pCodeBank, codeSize);
|
|
pCodeDest += codeSize;
|
|
}
|
|
|
|
if (BankSelect->BankingFlags & PLANAR_HC) {
|
|
|
|
//
|
|
// Copy appropriate high-color planar Bank Switch code:
|
|
//
|
|
|
|
BankSelect->PlanarHCBankCodeOffset = pCodeDest - (PUCHAR)BankSelect;
|
|
VideoPortMoveMemory(pCodeDest, pCodePlanarBank, codePlanarSize);
|
|
pCodeDest += codePlanarSize;
|
|
|
|
//
|
|
// Copy high-color planar bank mode Enable code:
|
|
//
|
|
|
|
BankSelect->PlanarHCEnableCodeOffset = pCodeDest - (PUCHAR)BankSelect;
|
|
|
|
VideoPortMoveMemory(pCodeDest,
|
|
&EnablePlanarHCStart,
|
|
((ULONG)&EnablePlanarHCEnd) -
|
|
((ULONG)&EnablePlanarHCStart));
|
|
|
|
pCodeDest += ((ULONG)&EnablePlanarHCEnd) -
|
|
((ULONG)&EnablePlanarHCStart);
|
|
|
|
//
|
|
// Copy high-color planar bank mode Disable code:
|
|
//
|
|
|
|
BankSelect->PlanarHCDisableCodeOffset = pCodeDest - (PUCHAR)BankSelect;
|
|
|
|
VideoPortMoveMemory(pCodeDest,
|
|
&DisablePlanarHCStart,
|
|
((ULONG)&DisablePlanarHCEnd) -
|
|
((ULONG)&DisablePlanarHCStart));
|
|
|
|
}
|
|
|
|
//
|
|
// Number of bytes we're returning is the full banking info size.
|
|
//
|
|
|
|
*OutputSize = BankSelect->Size;
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaGetBankSelectCode()
|
|
|
|
VP_STATUS
|
|
VgaValidatorUcharEntry(
|
|
ULONG Context,
|
|
ULONG Port,
|
|
UCHAR AccessMode,
|
|
PUCHAR Data
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Entry point into the validator for byte I/O operations.
|
|
|
|
The entry point will be called whenever a byte operation was performed
|
|
by a DOS application on one of the specified Video ports. The kernel
|
|
emulator will forward these requests.
|
|
|
|
Arguments:
|
|
|
|
Context - Context value that is passed to each call made to the validator
|
|
function. This is the value the miniport driver specified in the
|
|
MiniportConfigInfo->EmulatorAccessEntriesContext.
|
|
|
|
Port - Port on which the operation is to be performed.
|
|
|
|
AccessMode - Determines if it is a read or write operation.
|
|
|
|
Data - Pointer to a variable containing the data to be written or a
|
|
variable into which the read data should be stored.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR.
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
|
|
ULONG endEmulation;
|
|
UCHAR temp;
|
|
|
|
Port -= VGA_BASE_IO_PORT;
|
|
|
|
if (hwDeviceExtension->TrappedValidatorCount) {
|
|
|
|
//
|
|
// If we are processing a WRITE instruction, then store it in the
|
|
// playback buffer. If the buffer is full, then play it back right
|
|
// away, end sync reset and reinitialize the buffer with a sync
|
|
// reset instruction.
|
|
//
|
|
// If we have a READ, we must flush the buffer (which has the side
|
|
// effect of starting SyncReset), perform the read operation, stop
|
|
// sync reset, and put back a sync reset instruction in the buffer
|
|
// so we can go on appropriately
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
|
|
|
//
|
|
// Make sure Bit 3 of the Miscellaneous register is always 0.
|
|
// If it is 1 it could select a non-existent clock, and kill the
|
|
// system
|
|
//
|
|
|
|
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
|
|
|
*Data &= 0xF7;
|
|
|
|
}
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Port = Port;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].AccessType = VGA_VALIDATOR_UCHAR_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Data = *Data;
|
|
|
|
hwDeviceExtension->TrappedValidatorCount++;
|
|
|
|
//
|
|
// Check to see if this instruction was ending sync reset.
|
|
// If it did, we must flush the buffer and reset the trapped
|
|
// IO ports to the minimal set.
|
|
//
|
|
|
|
if ( (Port == SEQ_DATA_PORT) &&
|
|
((*Data & END_SYNC_RESET_VALUE) == END_SYNC_RESET_VALUE) &&
|
|
(hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
|
|
|
|
endEmulation = 1;
|
|
|
|
} else {
|
|
|
|
//
|
|
// If we are accessing the seq address port, keep track of the
|
|
// data value
|
|
//
|
|
|
|
if (Port == SEQ_ADDRESS_PORT) {
|
|
|
|
hwDeviceExtension->SequencerAddressValue = *Data;
|
|
|
|
}
|
|
|
|
//
|
|
// If the buffer is not full, then just return right away.
|
|
//
|
|
|
|
if (hwDeviceExtension->TrappedValidatorCount <
|
|
VGA_MAX_VALIDATOR_DATA - 1) {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
endEmulation = 0;
|
|
}
|
|
}
|
|
|
|
//
|
|
// We are either in a READ path or a WRITE path that caused a
|
|
// a full buffer. So flush the buffer either way.
|
|
//
|
|
// To do this put an END_SYNC_RESET at the end since we want to make
|
|
// the buffer is ended sync reset ended.
|
|
//
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8));
|
|
|
|
hwDeviceExtension->TrappedValidatorCount++;
|
|
|
|
VideoPortSynchronizeExecution(hwDeviceExtension,
|
|
VpHighPriority,
|
|
(PMINIPORT_SYNCHRONIZE_ROUTINE)
|
|
VgaPlaybackValidatorData,
|
|
hwDeviceExtension);
|
|
|
|
//
|
|
// Write back the real value of the sequencer address port.
|
|
//
|
|
|
|
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT,
|
|
(UCHAR) hwDeviceExtension->SequencerAddressValue);
|
|
|
|
//
|
|
// If we are in a READ path, read the data
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_READ_ACCESS) {
|
|
|
|
*Data = VideoPortReadPortUchar(hwDeviceExtension->IOAddress + Port);
|
|
|
|
endEmulation = 0;
|
|
|
|
}
|
|
|
|
//
|
|
// If we are ending emulation, reset trapping to the minimal amount
|
|
// and exit.
|
|
//
|
|
|
|
if (endEmulation) {
|
|
|
|
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
|
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
|
|
MinimalVgaValidatorAccessRange);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
//
|
|
// For both cases, put back a START_SYNC_RESET in the buffer.
|
|
//
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 1;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
|
VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Data =
|
|
(ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
|
|
|
|
} else {
|
|
|
|
//
|
|
// Nothing trapped.
|
|
// Lets check is the IO is trying to do something that would require
|
|
// us to stop trapping
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
|
|
|
//
|
|
// Make sure Bit 3 of the Miscelaneous register is always 0.
|
|
// If it is 1 it could select a non-existant clock, and kill the
|
|
// system
|
|
//
|
|
|
|
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
|
|
|
temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT);
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET +
|
|
(START_SYNC_RESET_VALUE << 8)));
|
|
|
|
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + Port,
|
|
(UCHAR) (*Data & 0xF7) );
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8)));
|
|
|
|
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT,
|
|
temp);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
//
|
|
// If we get an access to the sequencer register, start trapping.
|
|
//
|
|
|
|
if ( (Port == SEQ_DATA_PORT) &&
|
|
((*Data & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
|
|
(VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT) == IND_SYNC_RESET)) {
|
|
|
|
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
|
NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
|
|
FullVgaValidatorAccessRange);
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 1;
|
|
hwDeviceExtension->TrappedValidatorData[0].Port = Port;
|
|
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
|
VGA_VALIDATOR_UCHAR_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
|
|
|
|
//
|
|
// Start keeping track of the state of the sequencer port.
|
|
//
|
|
|
|
hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + Port,
|
|
*Data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*Data = VideoPortReadPortUchar(hwDeviceExtension->IOAddress + Port);
|
|
|
|
}
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaValidatorUcharEntry()
|
|
|
|
VP_STATUS
|
|
VgaValidatorUshortEntry(
|
|
ULONG Context,
|
|
ULONG Port,
|
|
UCHAR AccessMode,
|
|
PUSHORT Data
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Entry point into the validator for word I/O operations.
|
|
|
|
The entry point will be called whenever a byte operation was performed
|
|
by a DOS application on one of the specified Video ports. The kernel
|
|
emulator will forward these requests.
|
|
|
|
Arguments:
|
|
|
|
Context - Context value that is passed to each call made to the validator
|
|
function. This is the value the miniport driver specified in the
|
|
MiniportConfigInfo->EmulatorAccessEntriesContext.
|
|
|
|
Port - Port on which the operation is to be performed.
|
|
|
|
AccessMode - Determines if it is a read or write operation.
|
|
|
|
Data - Pointer to a variable containing the data to be written or a
|
|
variable into which the read data should be stored.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR.
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
|
|
ULONG endEmulation;
|
|
UCHAR temp;
|
|
|
|
Port -= VGA_BASE_IO_PORT;
|
|
|
|
if (hwDeviceExtension->TrappedValidatorCount) {
|
|
|
|
//
|
|
// If we are processing a WRITE instruction, then store it in the
|
|
// playback buffer. If the buffer is full, then play it back right
|
|
// away, end sync reset and reinitialize the buffer with a sync
|
|
// reset instruction.
|
|
//
|
|
// If we have a READ, we must flush the buffer (which has the side
|
|
// effect of starting SyncReset), perform the read operation, stop
|
|
// sync reset, and put back a sync reset instruction in the buffer
|
|
// so we can go on appropriately
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
|
|
|
//
|
|
// Make sure Bit 3 of the Miscellaneous register is always 0.
|
|
// If it is 1 it could select a non-existent clock, and kill the
|
|
// system
|
|
//
|
|
|
|
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
|
|
|
*Data &= 0xFFF7;
|
|
|
|
}
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Port = Port;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Data = *Data;
|
|
|
|
hwDeviceExtension->TrappedValidatorCount++;
|
|
|
|
//
|
|
// Check to see if this instruction was ending sync reset.
|
|
// If it did, we must flush the buffer and reset the trapped
|
|
// IO ports to the minimal set.
|
|
//
|
|
|
|
if (Port == SEQ_ADDRESS_PORT) {
|
|
|
|
//
|
|
// If we are accessing the seq address port, keep track of its
|
|
// value
|
|
//
|
|
|
|
hwDeviceExtension->SequencerAddressValue = (*Data & 0xFF);
|
|
|
|
}
|
|
|
|
if ((Port == SEQ_ADDRESS_PORT) &&
|
|
( ((*Data >> 8) & END_SYNC_RESET_VALUE) ==
|
|
END_SYNC_RESET_VALUE) &&
|
|
(hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
|
|
|
|
endEmulation = 1;
|
|
|
|
} else {
|
|
|
|
//
|
|
// If the buffer is not full, then just return right away.
|
|
//
|
|
|
|
if (hwDeviceExtension->TrappedValidatorCount <
|
|
VGA_MAX_VALIDATOR_DATA - 1) {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
endEmulation = 0;
|
|
}
|
|
}
|
|
|
|
//
|
|
// We are either in a READ path or a WRITE path that caused a
|
|
// a full buffer. So flush the buffer either way.
|
|
//
|
|
// To do this put an END_SYNC_RESET at the end since we want to make
|
|
// the buffer is ended sync reset ended.
|
|
//
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8));
|
|
|
|
hwDeviceExtension->TrappedValidatorCount++;
|
|
|
|
VideoPortSynchronizeExecution(hwDeviceExtension,
|
|
VpHighPriority,
|
|
(PMINIPORT_SYNCHRONIZE_ROUTINE)
|
|
VgaPlaybackValidatorData,
|
|
hwDeviceExtension);
|
|
|
|
//
|
|
// Write back the real value of the sequencer address port.
|
|
//
|
|
|
|
VideoPortWritePortUchar((PUCHAR) (hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(UCHAR) hwDeviceExtension->SequencerAddressValue);
|
|
|
|
//
|
|
// If we are in a READ path, read the data
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_READ_ACCESS) {
|
|
|
|
*Data = VideoPortReadPortUshort((PUSHORT)(hwDeviceExtension->IOAddress
|
|
+ Port));
|
|
|
|
endEmulation = 0;
|
|
|
|
}
|
|
|
|
//
|
|
// If we are ending emulation, reset trapping to the minimal amount
|
|
// and exit.
|
|
//
|
|
|
|
if (endEmulation) {
|
|
|
|
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
|
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
|
|
MinimalVgaValidatorAccessRange);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
//
|
|
// For both cases, put back a START_SYNC_RESET in the buffer.
|
|
//
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 1;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
|
VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Data =
|
|
(ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
|
|
|
|
} else {
|
|
|
|
//
|
|
// Nothing trapped.
|
|
// Lets check is the IO is trying to do something that would require
|
|
// us to stop trapping
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
|
|
|
//
|
|
// Make sure Bit 3 of the Miscelaneous register is always 0.
|
|
// If it is 1 it could select a non-existant clock, and kill the
|
|
// system
|
|
//
|
|
|
|
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
|
|
|
temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT);
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET +
|
|
(START_SYNC_RESET_VALUE << 8)));
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
|
(ULONG)Port),
|
|
(USHORT) (*Data & 0xFFF7) );
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8)));
|
|
|
|
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
|
temp);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
if ( (Port == SEQ_ADDRESS_PORT) &&
|
|
(((*Data>> 8) & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
|
|
((*Data & 0xFF) == IND_SYNC_RESET)) {
|
|
|
|
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
|
NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
|
|
FullVgaValidatorAccessRange);
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 1;
|
|
hwDeviceExtension->TrappedValidatorData[0].Port = Port;
|
|
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
|
VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
|
|
|
|
//
|
|
// Start keeping track of the state of the sequencer port.
|
|
//
|
|
|
|
hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUshort((PUSHORT)(hwDeviceExtension->IOAddress +
|
|
Port),
|
|
*Data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*Data = VideoPortReadPortUshort((PUSHORT)(hwDeviceExtension->IOAddress +
|
|
Port));
|
|
|
|
}
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaValidatorUshortEntry()
|
|
|
|
VP_STATUS
|
|
VgaValidatorUlongEntry(
|
|
ULONG Context,
|
|
ULONG Port,
|
|
UCHAR AccessMode,
|
|
PULONG Data
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Entry point into the validator for dword I/O operations.
|
|
|
|
The entry point will be called whenever a byte operation was performed
|
|
by a DOS application on one of the specified Video ports. The kernel
|
|
emulator will forward these requests.
|
|
|
|
Arguments:
|
|
|
|
Context - Context value that is passed to each call made to the validator
|
|
function. This is the value the miniport driver specified in the
|
|
MiniportConfigInfo->EmulatorAccessEntriesContext.
|
|
|
|
Port - Port on which the operation is to be performed.
|
|
|
|
AccessMode - Determines if it is a read or write operation.
|
|
|
|
Data - Pointer to a variable containing the data to be written or a
|
|
variable into which the read data should be stored.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR.
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
PHW_DEVICE_EXTENSION hwDeviceExtension = (PHW_DEVICE_EXTENSION) Context;
|
|
ULONG endEmulation;
|
|
UCHAR temp;
|
|
|
|
Port -= VGA_BASE_IO_PORT;
|
|
|
|
if (hwDeviceExtension->TrappedValidatorCount) {
|
|
|
|
//
|
|
// If we are processing a WRITE instruction, then store it in the
|
|
// playback buffer. If the buffer is full, then play it back right
|
|
// away, end sync reset and reinitialize the buffer with a sync
|
|
// reset instruction.
|
|
//
|
|
// If we have a READ, we must flush the buffer (which has the side
|
|
// effect of starting SyncReset), perform the read operation, stop
|
|
// sync reset, and put back a sync reset instruction in the buffer
|
|
// so we can go on appropriately
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
|
|
|
//
|
|
// Make sure Bit 3 of the Miscellaneous register is always 0.
|
|
// If it is 1 it could select a non-existent clock, and kill the
|
|
// system
|
|
//
|
|
|
|
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
|
|
|
*Data &= 0xFFFFFFF7;
|
|
|
|
}
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Port = Port;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].AccessType = VGA_VALIDATOR_ULONG_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Data = *Data;
|
|
|
|
hwDeviceExtension->TrappedValidatorCount++;
|
|
|
|
//
|
|
// Check to see if this instruction was ending sync reset.
|
|
// If it did, we must flush the buffer and reset the trapped
|
|
// IO ports to the minimal set.
|
|
//
|
|
|
|
if (Port == SEQ_ADDRESS_PORT) {
|
|
|
|
//
|
|
// If we are accessing the seq address port, keep track of its
|
|
// value
|
|
//
|
|
|
|
hwDeviceExtension->SequencerAddressValue = (*Data & 0xFF);
|
|
|
|
}
|
|
|
|
if ((Port == SEQ_ADDRESS_PORT) &&
|
|
( ((*Data >> 8) & END_SYNC_RESET_VALUE) ==
|
|
END_SYNC_RESET_VALUE) &&
|
|
(hwDeviceExtension->SequencerAddressValue == IND_SYNC_RESET)) {
|
|
|
|
endEmulation = 1;
|
|
|
|
} else {
|
|
|
|
//
|
|
// If the buffer is not full, then just return right away.
|
|
//
|
|
|
|
if (hwDeviceExtension->TrappedValidatorCount <
|
|
VGA_MAX_VALIDATOR_DATA - 1) {
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
endEmulation = 0;
|
|
}
|
|
}
|
|
|
|
//
|
|
// We are either in a READ path or a WRITE path that caused a
|
|
// a full buffer. So flush the buffer either way.
|
|
//
|
|
// To do this put an END_SYNC_RESET at the end since we want to make
|
|
// the buffer is ended sync reset ended.
|
|
//
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Port = SEQ_ADDRESS_PORT;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].AccessType = VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[hwDeviceExtension->
|
|
TrappedValidatorCount].Data = (USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8));
|
|
|
|
hwDeviceExtension->TrappedValidatorCount++;
|
|
|
|
VideoPortSynchronizeExecution(hwDeviceExtension,
|
|
VpHighPriority,
|
|
(PMINIPORT_SYNCHRONIZE_ROUTINE)
|
|
VgaPlaybackValidatorData,
|
|
hwDeviceExtension);
|
|
|
|
//
|
|
// Write back the real value of the sequencer address port.
|
|
//
|
|
|
|
VideoPortWritePortUchar(hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT,
|
|
(UCHAR) hwDeviceExtension->SequencerAddressValue);
|
|
|
|
//
|
|
// If we are in a READ path, read the data
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_READ_ACCESS) {
|
|
|
|
*Data = VideoPortReadPortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
|
Port));
|
|
|
|
endEmulation = 0;
|
|
|
|
}
|
|
|
|
//
|
|
// If we are ending emulation, reset trapping to the minimal amount
|
|
// and exit.
|
|
//
|
|
|
|
if (endEmulation) {
|
|
|
|
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
|
NUM_MINIMAL_VGA_VALIDATOR_ACCESS_RANGE,
|
|
MinimalVgaValidatorAccessRange);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
//
|
|
// For both cases, put back a START_SYNC_RESET in the buffer.
|
|
//
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 1;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Port = SEQ_ADDRESS_PORT;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
|
VGA_VALIDATOR_USHORT_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Data =
|
|
(ULONG) (IND_SYNC_RESET + (START_SYNC_RESET_VALUE << 8));
|
|
|
|
} else {
|
|
|
|
//
|
|
// Nothing trapped.
|
|
// Lets check is the IO is trying to do something that would require
|
|
// us to stop trapping
|
|
//
|
|
|
|
if (AccessMode & EMULATOR_WRITE_ACCESS) {
|
|
|
|
//
|
|
// Make sure Bit 3 of the Miscelaneous register is always 0.
|
|
// If it is 1 it could select a non-existant clock, and kill the
|
|
// system
|
|
//
|
|
|
|
if (Port == MISC_OUTPUT_REG_WRITE_PORT) {
|
|
|
|
temp = VideoPortReadPortUchar(hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT);
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET +
|
|
(START_SYNC_RESET_VALUE << 8)));
|
|
|
|
VideoPortWritePortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
|
Port),
|
|
(ULONG) (*Data & 0xFFFFFFF7) );
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (hwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),
|
|
(USHORT) (IND_SYNC_RESET +
|
|
(END_SYNC_RESET_VALUE << 8)));
|
|
|
|
VideoPortWritePortUchar(hwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
|
temp);
|
|
|
|
return NO_ERROR;
|
|
|
|
}
|
|
|
|
if ( (Port == SEQ_ADDRESS_PORT) &&
|
|
(((*Data>> 8) & END_SYNC_RESET_VALUE) != END_SYNC_RESET_VALUE) &&
|
|
((*Data & 0xFF) == IND_SYNC_RESET)) {
|
|
|
|
VideoPortSetTrappedEmulatorPorts(hwDeviceExtension,
|
|
NUM_FULL_VGA_VALIDATOR_ACCESS_RANGE,
|
|
FullVgaValidatorAccessRange);
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 1;
|
|
hwDeviceExtension->TrappedValidatorData[0].Port = Port;
|
|
hwDeviceExtension->TrappedValidatorData[0].AccessType =
|
|
VGA_VALIDATOR_ULONG_ACCESS;
|
|
|
|
hwDeviceExtension->TrappedValidatorData[0].Data = *Data;
|
|
|
|
//
|
|
// Start keeping track of the state of the sequencer port.
|
|
//
|
|
|
|
hwDeviceExtension->SequencerAddressValue = IND_SYNC_RESET;
|
|
|
|
} else {
|
|
|
|
VideoPortWritePortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
|
Port),
|
|
*Data);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
*Data = VideoPortReadPortUlong((PULONG) (hwDeviceExtension->IOAddress +
|
|
Port));
|
|
|
|
}
|
|
}
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaValidatorUlongEntry()
|
|
|
|
|
|
BOOLEAN
|
|
VgaPlaybackValidatorData(
|
|
PVOID Context
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Performs all the DOS apps IO port accesses that were trapped by the
|
|
validator. Only IO accesses that can be processed are WRITEs
|
|
|
|
The number of outstanding IO access in deviceExtension is set to
|
|
zero as a side effect.
|
|
|
|
This function must be called via a call to VideoPortSynchronizeRoutine.
|
|
|
|
Arguments:
|
|
|
|
Context - Context parameter passed to the synchronized routine.
|
|
Must be a pointer to the miniport driver's device extension.
|
|
|
|
Return Value:
|
|
|
|
TRUE.
|
|
|
|
--*/
|
|
|
|
{
|
|
PHW_DEVICE_EXTENSION hwDeviceExtension = Context;
|
|
ULONG ioBaseAddress = (ULONG) hwDeviceExtension->IOAddress;
|
|
ULONG i;
|
|
PVGA_VALIDATOR_DATA validatorData = hwDeviceExtension->TrappedValidatorData;
|
|
|
|
for (i = 0; i < hwDeviceExtension->TrappedValidatorCount;
|
|
i++, validatorData++) {
|
|
|
|
//
|
|
// Calculate base address first
|
|
//
|
|
|
|
ioBaseAddress = (ULONG)hwDeviceExtension->IOAddress +
|
|
validatorData->Port;
|
|
|
|
//
|
|
// This is a write operation. We will automatically stop when the
|
|
// buffer is empty.
|
|
//
|
|
|
|
switch (validatorData->AccessType) {
|
|
|
|
case VGA_VALIDATOR_UCHAR_ACCESS :
|
|
|
|
//
|
|
// Compensate for hardware bug in the VRAM 1 with certain oddball
|
|
// tests.
|
|
//
|
|
|
|
if (validatorData->Port == CRTC_DATA_PORT_COLOR) {
|
|
|
|
ULONG temp;
|
|
|
|
if (VideoPortReadPortUchar((PUCHAR) hwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR) == 0x00) {
|
|
|
|
VideoPortWritePortUchar((PUCHAR)
|
|
hwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, 1);
|
|
|
|
temp = VideoPortReadPortUchar((PUCHAR)
|
|
hwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_COLOR);
|
|
|
|
VideoPortWritePortUchar((PUCHAR)
|
|
hwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_COLOR, 0);
|
|
|
|
if (validatorData->Data < (temp - 2)) {
|
|
|
|
validatorData->Data = temp - 2;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
if (validatorData->Port == CRTC_DATA_PORT_MONO) {
|
|
|
|
ULONG temp;
|
|
|
|
if (VideoPortReadPortUchar((PUCHAR) hwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO) == 0x00) {
|
|
|
|
VideoPortWritePortUchar((PUCHAR)
|
|
hwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO, 1);
|
|
|
|
temp = VideoPortReadPortUchar((PUCHAR)
|
|
hwDeviceExtension->IOAddress +
|
|
CRTC_DATA_PORT_MONO);
|
|
|
|
VideoPortWritePortUchar((PUCHAR)
|
|
hwDeviceExtension->IOAddress +
|
|
CRTC_ADDRESS_PORT_MONO, 0);
|
|
|
|
if (validatorData->Data < (temp - 2)) {
|
|
|
|
validatorData->Data = temp - 2;
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
VideoPortWritePortUchar((PUCHAR)ioBaseAddress,
|
|
(UCHAR) validatorData->Data);
|
|
break;
|
|
|
|
case VGA_VALIDATOR_USHORT_ACCESS :
|
|
|
|
VideoPortWritePortUshort((PUSHORT)ioBaseAddress,
|
|
(USHORT) validatorData->Data);
|
|
break;
|
|
|
|
case VGA_VALIDATOR_ULONG_ACCESS :
|
|
|
|
VideoPortWritePortUlong((PULONG)ioBaseAddress,
|
|
(ULONG) validatorData->Data);
|
|
break;
|
|
|
|
default:
|
|
|
|
VideoDebugPrint((0, "InvalidValidatorAccessType\n" ));
|
|
|
|
}
|
|
}
|
|
|
|
hwDeviceExtension->TrappedValidatorCount = 0;
|
|
|
|
return TRUE;
|
|
|
|
} // end VgaPlaybackValidatorData()
|
|
|
|
|
|
VP_STATUS
|
|
VgaQueryPointerCapabilities(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_CAPABILITIES PointerCaps,
|
|
ULONG PointerCapsSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Returns information about miniport pointer support in the specified mode.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
PointerCaps - Pointer to a VIDEO_POINTER_CAPABILITIES structure.
|
|
|
|
PointerCapsSize - Size of output buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a variable in which to return the actual size of
|
|
the data returned in the output buffer.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
--*/
|
|
|
|
{
|
|
UNREFERENCED_PARAMETER(HwDeviceExtension);
|
|
|
|
//
|
|
// The minimum passed buffer size is a VIDEO_BANK_SELECT
|
|
// structure, so that we can return the required size; we can't do
|
|
// anything if we don't have at least that much buffer.
|
|
//
|
|
|
|
if (PointerCapsSize < sizeof(VIDEO_POINTER_CAPABILITIES)) {
|
|
|
|
*OutputSize = 0; // nothing to return
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
|
|
//
|
|
// Normally, this would be mode based, but the hardware pointer works in
|
|
// all modes, even text.
|
|
// WARNING when we support 256-color modes, the pointer load address will
|
|
// change; also, this should change depending on how much memory is present
|
|
//
|
|
|
|
PointerCaps->Flags = VIDEO_MODE_MONO_POINTER; // mono cursor only
|
|
PointerCaps->MaxWidth = PTR_WIDTH_IN_PIXELS;
|
|
PointerCaps->MaxHeight = PTR_HEIGHT;
|
|
PointerCaps->HWPtrBitmapStart =
|
|
0xC000+(HW_POINTER_LOAD_LEN*DEFAULT_PPA_NUM);
|
|
PointerCaps->HWPtrBitmapEnd =
|
|
PointerCaps->HWPtrBitmapStart + HW_POINTER_LOAD_LEN - 1;
|
|
|
|
|
|
//
|
|
// Number of bytes we're returning.
|
|
//
|
|
|
|
*OutputSize = sizeof(VIDEO_POINTER_CAPABILITIES);
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaQueryPointerCapsCode()
|
|
|
|
|
|
VP_STATUS
|
|
VgaSetPointerPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_POSITION pPointerPosition,
|
|
ULONG PointerPositionSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Sets the location of the hardware pointer. Does not enable it if it's not
|
|
already enabled.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
pPointerPosition - Pointer to PVIDEO_POINTER_POSITION structure describing
|
|
new pointer position.
|
|
|
|
PointerPositionSize - Length of the input buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a variable in which to return the actual size of
|
|
the data returned in the output buffer.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - input buffer not large enough to return
|
|
any useful data
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
//
|
|
// We don't return anything.
|
|
//
|
|
|
|
*OutputSize = 0;
|
|
|
|
//
|
|
// Make sure enough data was passed in.
|
|
//
|
|
|
|
if (PointerPositionSize < sizeof(VIDEO_POINTER_POSITION)) {
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Update the pointer position variables.
|
|
//
|
|
|
|
HwDeviceExtension->videoPointerAttributes.Row = pPointerPosition->Row;
|
|
HwDeviceExtension->videoPointerAttributes.Column = pPointerPosition->Column;
|
|
|
|
//
|
|
// Move the pointer.
|
|
// LATER: shouldn't be hardwired for bank.
|
|
//
|
|
|
|
V7DrawPointer((ULONG)pPointerPosition->Column,
|
|
(ULONG)pPointerPosition->Row,
|
|
(PUCHAR)HwDeviceExtension->VideoMemoryAddress +
|
|
(0xC000+(HW_POINTER_LOAD_LEN*DEFAULT_PPA_NUM)),
|
|
POINTER_BANK,
|
|
HwDeviceExtension->jCurAndMask,
|
|
&HwDeviceExtension->hwPtrShiftInfo);
|
|
|
|
V7EnablePointer(HwDeviceExtension); // make sure the pointer is on
|
|
// LATER: should this be part of this function?
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaSetPointerPosition()
|
|
|
|
|
|
VP_STATUS
|
|
VgaQueryPointerPosition(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_POSITION pPointerPosition,
|
|
ULONG PointerPositionSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Gets the location of the hardware pointer.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
pPointerPosition - Pointer to PVIDEO_POINTER_POSITION structure in which
|
|
current pointer position is to be returned.
|
|
|
|
PointerPositionSize - Length of the output buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a variable in which to return the actual size of
|
|
the data returned in the output buffer.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
//
|
|
// Make sure the output buffer is big enough.
|
|
//
|
|
|
|
if (PointerPositionSize < sizeof(VIDEO_POINTER_POSITION)) {
|
|
|
|
*OutputSize = 0;
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Return the pointer position
|
|
//
|
|
|
|
pPointerPosition->Row =
|
|
(SHORT)HwDeviceExtension->videoPointerAttributes.Row;
|
|
pPointerPosition->Column =
|
|
(SHORT)HwDeviceExtension->videoPointerAttributes.Column;
|
|
|
|
*OutputSize = sizeof(VIDEO_POINTER_POSITION);
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaQueryPointerPosition()
|
|
|
|
VP_STATUS
|
|
VgaSetPointerAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_ATTRIBUTES pVideoPointerAttributes,
|
|
ULONG PointerAttributesSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Sets the desired pointer attributes. If the pointer is not accepted,
|
|
for any reason, an error is returned and the pointer is disabled.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
pVideoPointerAttributes - Pointer to PVIDEO_POINTER_ATTRIBUTES structure
|
|
containing the desired pointer attributes.
|
|
|
|
PointerAttributesSize - Length of the input buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a variable in which to return the actual size of
|
|
the data returned in the output buffer.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
//
|
|
// We don't return anything.
|
|
//
|
|
|
|
*OutputSize = 0;
|
|
|
|
//
|
|
// Make sure the input buffer is big enough to have the basic pointer
|
|
// attributes structure.
|
|
//
|
|
|
|
if (PointerAttributesSize < sizeof(VIDEO_POINTER_ATTRIBUTES)) {
|
|
|
|
V7DisablePointer(HwDeviceExtension);
|
|
HwDeviceExtension->videoPointerAttributes.Enable = FALSE;
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// See if we can accept these attributes. We only support a monochrome
|
|
// pointer up to a certain size.
|
|
//
|
|
|
|
if ( (pVideoPointerAttributes->Flags & VIDEO_MODE_COLOR_POINTER) ||
|
|
(!(pVideoPointerAttributes->Flags & VIDEO_MODE_MONO_POINTER)) ||
|
|
(pVideoPointerAttributes->Height > PTR_HEIGHT) ||
|
|
(pVideoPointerAttributes->Width > PTR_WIDTH_IN_PIXELS) ) {
|
|
|
|
V7DisablePointer(HwDeviceExtension);
|
|
HwDeviceExtension->videoPointerAttributes.Enable = FALSE;
|
|
|
|
return ERROR_INVALID_PARAMETER;
|
|
}
|
|
|
|
//
|
|
// Make sure the input buffer is big enough to have the basic pointer
|
|
// attributes structure plus the pointer bitmap.
|
|
//
|
|
|
|
if (PointerAttributesSize <
|
|
(sizeof(VIDEO_POINTER_ATTRIBUTES) +
|
|
(pVideoPointerAttributes->Height *
|
|
pVideoPointerAttributes->WidthInBytes * 2)) ) {
|
|
|
|
V7DisablePointer(HwDeviceExtension);
|
|
HwDeviceExtension->videoPointerAttributes.Enable = FALSE;
|
|
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
//
|
|
// Disable the pointer while we change and move it.
|
|
//
|
|
if (!(pVideoPointerAttributes->Flags & VIDEO_MODE_ANIMATE_UPDATE))
|
|
V7DisablePointer(HwDeviceExtension);
|
|
|
|
//
|
|
// Copy the AND and XOR masks to the local buffer.
|
|
//
|
|
|
|
VideoPortMoveMemory(HwDeviceExtension->jCurAndMask,
|
|
pVideoPointerAttributes->Pixels,
|
|
PTR_HEIGHT * PTR_WIDTH * 2);
|
|
|
|
//
|
|
// Mark that there is no currently loaded cursor.
|
|
//
|
|
|
|
HwDeviceExtension->hwPtrShiftInfo.ulShiftedFlag = 0xFF;
|
|
|
|
//
|
|
// Restore default Sequencer Index.
|
|
//
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, IND_MAP_MASK);
|
|
|
|
//
|
|
// Load the pointer and Set the position.
|
|
// LATER: shouldn't be hardwired for bank.
|
|
//
|
|
|
|
V7DrawPointer(pVideoPointerAttributes->Column,
|
|
pVideoPointerAttributes->Row,
|
|
(PUCHAR)HwDeviceExtension->VideoMemoryAddress +
|
|
(0xC000+(HW_POINTER_LOAD_LEN*DEFAULT_PPA_NUM)),
|
|
POINTER_BANK,
|
|
HwDeviceExtension->jCurAndMask,
|
|
&HwDeviceExtension->hwPtrShiftInfo);
|
|
|
|
//
|
|
// Enable if appropriate.
|
|
//
|
|
|
|
if (pVideoPointerAttributes->Enable != 0) {
|
|
|
|
V7EnablePointer(HwDeviceExtension);
|
|
|
|
}
|
|
|
|
//
|
|
// Copy over the pointer attributes.
|
|
//
|
|
|
|
HwDeviceExtension->videoPointerAttributes = *pVideoPointerAttributes;
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaQueryPointerAttributes()
|
|
|
|
|
|
VP_STATUS
|
|
VgaQueryPointerAttributes(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension,
|
|
PVIDEO_POINTER_ATTRIBUTES pVideoPointerAttributes,
|
|
ULONG PointerAttributesSize,
|
|
PULONG OutputSize
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Returns the current pointer attributes.
|
|
|
|
Arguments:
|
|
|
|
HwDeviceExtension - Pointer to the miniport driver's device extension.
|
|
|
|
pVideoPointerAttributes - Pointer to PVIDEO_POINTER_ATTRIBUTES structure in
|
|
which current pointer attributes are to be returned.
|
|
|
|
PointerAttributesSize - Length of the output buffer supplied by the user.
|
|
|
|
OutputSize - Pointer to a variable in which to return the actual size of
|
|
the data returned in the output buffer.
|
|
|
|
Return Value:
|
|
|
|
NO_ERROR - information returned successfully
|
|
|
|
ERROR_INSUFFICIENT_BUFFER - output buffer not large enough to return
|
|
any useful data
|
|
|
|
--*/
|
|
|
|
{
|
|
|
|
//
|
|
// Make sure the output buffer is big enough.
|
|
//
|
|
|
|
if (PointerAttributesSize < sizeof(VIDEO_POINTER_ATTRIBUTES)) {
|
|
|
|
*OutputSize = 0;
|
|
return ERROR_INSUFFICIENT_BUFFER;
|
|
|
|
}
|
|
|
|
//
|
|
// Return the pointer attributes.
|
|
//
|
|
|
|
*pVideoPointerAttributes = HwDeviceExtension->videoPointerAttributes;
|
|
|
|
*OutputSize = sizeof(VIDEO_POINTER_ATTRIBUTES);
|
|
|
|
return NO_ERROR;
|
|
|
|
} // end VgaQueryPointerAttributes()
|
|
|
|
|
|
VOID
|
|
V7EnablePointer(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Enables the hardware pointer (makes it visible).
|
|
|
|
Arguments:
|
|
|
|
None.
|
|
|
|
Return Value:
|
|
|
|
None.
|
|
|
|
--*/
|
|
|
|
{
|
|
// Turn on the hardware graphics pointer.
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT, IND_SEQ_HW_POINTER);
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_DATA_PORT,
|
|
(UCHAR) ((ULONG) VideoPortReadPortUchar(
|
|
HwDeviceExtension->IOAddress + SEQ_DATA_PORT) |
|
|
(ULONG) HW_POINTER_ON));
|
|
|
|
// Restore default Map Mask setting.
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT), IND_MAP_MASK + (MAP_MASK_DEFAULT << 8));
|
|
|
|
} // end V7EnablePointer()
|
|
|
|
|
|
VOID
|
|
V7DisablePointer(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
Disables the hardware pointer (makes it invisible).
|
|
|
|
Arguments:
|
|
|
|
None.
|
|
|
|
Return Value:
|
|
|
|
None.
|
|
|
|
--*/
|
|
|
|
{
|
|
// Turn off the hardware graphics pointer.
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
|
IND_SEQ_HW_POINTER);
|
|
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_DATA_PORT,
|
|
(UCHAR) ((ULONG) VideoPortReadPortUchar(
|
|
HwDeviceExtension->IOAddress + SEQ_DATA_PORT) &
|
|
(ULONG) HW_POINTER_OFF));
|
|
|
|
// Restore default Map Mask setting.
|
|
|
|
VideoPortWritePortUshort((PUSHORT) (HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT), IND_MAP_MASK + (MAP_MASK_DEFAULT << 8));
|
|
|
|
} // end V7DisablePointer()
|
|
|
|
BOOLEAN
|
|
V7IsPresent(
|
|
PHW_DEVICE_EXTENSION HwDeviceExtension
|
|
)
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
This routine returns TRUE if a supported V7 adapter is present. It assumes
|
|
that it's already been established that a VGA is present. It tests for
|
|
a V7 VGA chip by checking that whatever value we put in CRTC0A shows up in
|
|
CRTC1F, XORed with 0xEA. If this works, then we look at the BIOS V7
|
|
ID word to figure out if it's a supported V7 VGA.
|
|
|
|
If this function fails to find a supported V7 adapter, it attempts to undo
|
|
any damage it may have inadvertently done while testing.
|
|
|
|
If a supported V7 adapter is found, the adapter is returned to its original
|
|
state after testing is finished, and the adapter type in the hardware
|
|
device extension is set to the appropriate adapter type.
|
|
|
|
Arguments:
|
|
|
|
None.
|
|
|
|
Return Value:
|
|
|
|
TRUE if a supported V7 adapter (currently VRAM 1, VRAM 2, or VRAM 2 Ergo)
|
|
is present, FALSE if not.
|
|
|
|
--*/
|
|
|
|
{
|
|
UCHAR originalCRTCIndex;
|
|
UCHAR originalIndV7IDWrite;
|
|
UCHAR temp1, temp2, temp3;
|
|
PUCHAR CRTCAddressPort, CRTCDataPort;
|
|
PUSHORT pusROMPtr;
|
|
|
|
//
|
|
// Determine where the CRTC registers are addressed (color or mono).
|
|
//
|
|
|
|
CRTCAddressPort = HwDeviceExtension->IOAddress;
|
|
CRTCDataPort = HwDeviceExtension->IOAddress;
|
|
|
|
if (VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
MISC_OUTPUT_REG_READ_PORT) & 0x01) {
|
|
|
|
CRTCAddressPort += CRTC_ADDRESS_PORT_COLOR;
|
|
CRTCDataPort += CRTC_DATA_PORT_COLOR;
|
|
|
|
} else {
|
|
|
|
CRTCAddressPort += CRTC_ADDRESS_PORT_MONO;
|
|
CRTCDataPort += CRTC_DATA_PORT_MONO;
|
|
|
|
}
|
|
|
|
//
|
|
// Save the original state of the CRTC Index.
|
|
//
|
|
|
|
originalCRTCIndex = VideoPortReadPortUchar(CRTCAddressPort);
|
|
|
|
//
|
|
// Modify IND_V7_ID_WRITE, then see whether IND_V7_ID_READ changes to the
|
|
// value written to IND_V7_ID_WRITE XORed with 0xEA.
|
|
//
|
|
|
|
//
|
|
// Set the CRTC Index to IND_V7_ID_WRITE.
|
|
//
|
|
|
|
VideoPortWritePortUchar(CRTCAddressPort, IND_V7_ID_WRITE);
|
|
|
|
//
|
|
// Save the original state of CRTC register IND_V7_ID_WRITE.
|
|
//
|
|
|
|
originalIndV7IDWrite = VideoPortReadPortUchar(CRTCDataPort);
|
|
|
|
//
|
|
// Write one possible IND_V7_ID_WRITE state and read it back from
|
|
// IND_V7_ID_READ (where it should be XORed with 0xEA).
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
|
|
(USHORT)((0x55 << 8) + IND_V7_ID_WRITE));
|
|
VideoPortWritePortUchar(CRTCAddressPort, IND_V7_ID_READ);
|
|
temp1 = VideoPortReadPortUchar(CRTCDataPort);
|
|
|
|
//
|
|
// Write another possible IND_V7_ID_WRITE state and read it back.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
|
|
(USHORT)((0xAA << 8) + IND_V7_ID_WRITE));
|
|
|
|
VideoPortWritePortUchar(CRTCAddressPort, IND_V7_ID_READ);
|
|
temp2 = VideoPortReadPortUchar(CRTCDataPort);
|
|
|
|
//
|
|
// Write yet another possible IND_V7_ID_WRITE state and read it back.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
|
|
(USHORT)((0x3E << 8) + IND_V7_ID_WRITE));
|
|
VideoPortWritePortUchar(CRTCAddressPort, IND_V7_ID_READ);
|
|
temp3 = VideoPortReadPortUchar(CRTCDataPort);
|
|
|
|
//
|
|
// Restore the original IND_V7_ID_WRITE state.
|
|
//
|
|
|
|
VideoPortWritePortUshort((PUSHORT)CRTCAddressPort,
|
|
(USHORT)((originalIndV7IDWrite << 8) + IND_V7_ID_WRITE));
|
|
|
|
//
|
|
// Restore the original CRTC Index.
|
|
//
|
|
|
|
VideoPortWritePortUchar(CRTCAddressPort, originalCRTCIndex);
|
|
|
|
//
|
|
// See if CRTC1F changed properly.
|
|
//
|
|
|
|
if ((temp1 != (UCHAR) (0x55 ^ 0xEA)) ||
|
|
(temp2 != (UCHAR) (0xAA ^ 0xEA)) ||
|
|
(temp3 != (UCHAR) (0x3E ^ 0xEA))) {
|
|
|
|
//
|
|
// Didn't change properly; not a V7 VGA chip.
|
|
//
|
|
|
|
VideoDebugPrint((1, "V7 VGA chip not found\n"));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
//
|
|
// Determine if this is a V7 VRAM (I). We do the check
|
|
// for the older VRAM this way since it is possible that
|
|
// this card may have the old BIOS.
|
|
//
|
|
|
|
//
|
|
// Save Sequencer index, enable extensions, get chip revision,
|
|
// disable extensions, and restore index.
|
|
//
|
|
temp1 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT);
|
|
|
|
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),(USHORT)0xea06);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
|
IND_CHIP_REVISION);
|
|
temp2 = VideoPortReadPortUchar(HwDeviceExtension->IOAddress +
|
|
SEQ_DATA_PORT) & 0xF0;
|
|
VideoPortWritePortUshort((PUSHORT)(HwDeviceExtension->IOAddress +
|
|
SEQ_ADDRESS_PORT),(USHORT)0xae06);
|
|
VideoPortWritePortUchar(HwDeviceExtension->IOAddress + SEQ_ADDRESS_PORT,
|
|
temp1);
|
|
|
|
//
|
|
// Assume this is a VRAM1.
|
|
//
|
|
|
|
HwDeviceExtension->AdapterType = Vram1;
|
|
HwDeviceExtension->ChipWithRefreshProblems = 0; // VRAM1s always refresh OK
|
|
|
|
if (temp2 != 0x70) {
|
|
|
|
//
|
|
// It *is* a V7 VGA chip, but is not a VRAM1,
|
|
// Now see if it's a supported V7 adapter, by checking the V7 adapter
|
|
// ID word in the BIOS.
|
|
//
|
|
|
|
pusROMPtr = (PUSHORT) (((PUCHAR)HwDeviceExtension->ROMBaseAddress) +
|
|
V7_ID_WORD_ROM_OFFSET);
|
|
switch (*pusROMPtr) {
|
|
case VRAM2_ROM_ID_1:
|
|
case VRAM2_ROM_ID_2:
|
|
HwDeviceExtension->AdapterType = Vram2;
|
|
break;
|
|
|
|
case VRAM2ERGO_ROM_ID:
|
|
HwDeviceExtension->AdapterType = Vram2Ergo;
|
|
break;
|
|
|
|
default:
|
|
HwDeviceExtension->AdapterType = OtherV7;
|
|
VideoDebugPrint((1,
|
|
"ID #%x is not a V7 VRAM adapter \n", *pusROMPtr));
|
|
//
|
|
// We do not support the 1024 i because it has weird bugs in
|
|
// it.
|
|
// If we did want to support it, just brak instead of returning
|
|
// and try to solve the other bugs ...
|
|
//
|
|
|
|
// break;
|
|
|
|
return FALSE;
|
|
}
|
|
|
|
//
|
|
// See if this is a version of the VRAM2 chip that doesn't refresh
|
|
// offscreen memory (version 0x5X).
|
|
//
|
|
|
|
if (temp2 == 0x50) {
|
|
|
|
//
|
|
// It is a no-offscreen-refresh chip, so tell the display driver
|
|
// not to use offscreen memory.
|
|
//
|
|
|
|
HwDeviceExtension->ChipWithRefreshProblems = 1;
|
|
}
|
|
}
|
|
|
|
//
|
|
// It's a supported V7 adapter.
|
|
//
|
|
|
|
//
|
|
// ***************************
|
|
// ***** IMPORTANT NOTE ******
|
|
// ***************************
|
|
//
|
|
// We can not get the memory size and calculate valid modes here
|
|
// because we need to do an int10 for that.
|
|
// An int 10 is only possible when being called by the display driver,
|
|
// and must therefore be done in the Initialize routine
|
|
//
|
|
|
|
return TRUE;
|
|
|
|
} // V7IsPresent()
|
|
|
|
//---------------------------------------------------------------------------
|
|
//
|
|
// The memory manager needs a "C" interface to the banking function
|
|
//
|
|
|
|
/*++
|
|
|
|
Routine Description:
|
|
|
|
These functions are a "C" callable interface to the ASM banking
|
|
functions. They are NON paged because they are called from the
|
|
Memory Manager during some page faults.
|
|
|
|
Arguments:
|
|
|
|
iBankRead - Index of bank we want mapped in to read from.
|
|
iBankWrite - Index of bank we want mapped in to write to.
|
|
|
|
Return Value:
|
|
|
|
None.
|
|
|
|
--*/
|
|
|
|
|
|
VOID
|
|
vBankMap_1RW(
|
|
LONG iBankRead,
|
|
LONG iBankWrite,
|
|
PVOID pvContext
|
|
)
|
|
{
|
|
VideoDebugPrint((1, "vBankMap_1RW(%d,%d) - enter\n",iBankRead,iBankWrite));
|
|
|
|
//
|
|
// This adapter doesn't support separate read and write banks. We'll use
|
|
// the read bank requested since they should be the same.
|
|
//
|
|
|
|
#ifdef _X86_
|
|
_asm {
|
|
mov eax,iBankRead
|
|
lea ebx,BankSwitchStart256
|
|
call ebx
|
|
}
|
|
#endif
|
|
VideoDebugPrint((1, "vBankMap_1RW - exit\n"));
|
|
}
|
|
|
|
VOID
|
|
vBankMap_2RW(
|
|
LONG iBankRead,
|
|
LONG iBankWrite,
|
|
PVOID pvContext
|
|
)
|
|
{
|
|
VideoDebugPrint((1, "vBankMap_2RW(%d,%d) - enter\n",iBankRead,iBankWrite));
|
|
#ifdef _X86_
|
|
_asm {
|
|
mov eax,iBankRead
|
|
mov edx,eax
|
|
inc edx
|
|
lea ebx,BankSwitchStart256_2RW
|
|
call ebx
|
|
}
|
|
#endif
|
|
VideoDebugPrint((1, "vBankMap_2RW - exit\n"));
|
|
}
|