- Make VBEMP compile with msvc/ddk.
[reactos.git] / reactos / drivers / video / miniport / vbe / vbemp.c
index 6e9bae4..07c0b70 100644 (file)
@@ -77,11 +77,11 @@ VBEFindAdapter(
 static int
 VBESortModesCallback(PVBE_MODEINFO VbeModeInfoA, PVBE_MODEINFO VbeModeInfoB)
 {
-   DPRINT(("VBESortModesCallback: %dx%dx%d / %dx%dx%d\n",
+   VideoPortDebugPrint(Info, "VBESortModesCallback: %dx%dx%d / %dx%dx%d\n",
       VbeModeInfoA->XResolution, VbeModeInfoA->YResolution,
       VbeModeInfoA->BitsPerPixel,
       VbeModeInfoB->XResolution, VbeModeInfoB->YResolution,
-      VbeModeInfoB->BitsPerPixel));
+      VbeModeInfoB->BitsPerPixel);
 
    /*
     * FIXME: Until some reasonable method for changing video modes will
@@ -110,7 +110,7 @@ VBESortModes(PVBE_DEVICE_EXTENSION DeviceExtension)
    ULONG Pos;
    int Result;
    VBE_MODEINFO TempModeInfo;
-   WORD TempModeNumber;
+   USHORT TempModeNumber;
 
    while (!Finished)
    {
@@ -187,7 +187,7 @@ VBEInitialize(PVOID HwDeviceExtension)
 
    if (Status != NO_ERROR)
    {
-      DPRINT(("Failed to get Int 10 service functions (Status %x)\n", Status));
+      VideoPortDebugPrint(Error, "Failed to get Int 10 service functions (Status %x)\n", Status);
       return FALSE;
    }
 
@@ -206,7 +206,7 @@ VBEInitialize(PVOID HwDeviceExtension)
 
    if (Status != NO_ERROR)
    {
-      DPRINT(("Failed to allocate virtual memory (Status %x)\n", Status));
+      VideoPortDebugPrint(Error, "Failed to allocate virtual memory (Status %x)\n", Status);
       return FALSE;
    }
 
@@ -238,10 +238,17 @@ VBEInitialize(PVOID HwDeviceExtension)
          &VBEDeviceExtension->VbeInfo,
          sizeof(VBEDeviceExtension->VbeInfo));
 
-      DPRINT(("VBE BIOS Present (%d.%d, %8ld Kb)\n",
+      /* Verify the VBE signature. */
+      if (VideoPortCompareMemory(VBEDeviceExtension->VbeInfo.Signature, "VESA", 4) != 4)
+      {
+         VideoPortDebugPrint(Warn, "No VBE BIOS present\n");
+         return FALSE;
+      }
+      
+      VideoPortDebugPrint(Trace, "VBE BIOS Present (%d.%d, %8ld Kb)\n",
          VBEDeviceExtension->VbeInfo.Version / 0x100,
          VBEDeviceExtension->VbeInfo.Version & 0xFF,
-         VBEDeviceExtension->VbeInfo.TotalMemory * 16));
+         VBEDeviceExtension->VbeInfo.TotalMemory * 64);
 
 #ifdef VBE12_SUPPORT
       if (VBEDeviceExtension->VbeInfo.Version < 0x102)
@@ -249,13 +256,13 @@ VBEInitialize(PVOID HwDeviceExtension)
       if (VBEDeviceExtension->VbeInfo.Version < 0x200)
 #endif
       {
-         DPRINT(("VBE BIOS present, but incompatible version.\n"));
+         VideoPortDebugPrint(Warn, "VBE BIOS present, but incompatible version.\n");
          return FALSE;
       }
    }
    else
    {
-      DPRINT(("No VBE BIOS found.\n"));
+      VideoPortDebugPrint(Warn, "No VBE BIOS found.\n");
       return FALSE;
    }
 
@@ -292,9 +299,9 @@ VBEInitialize(PVOID HwDeviceExtension)
     */
 
    VBEDeviceExtension->ModeInfo =
-      ExAllocatePool(PagedPool, ModeCount * sizeof(VBE_MODEINFO));
+      VideoPortAllocatePool(HwDeviceExtension, VpPagedPool, ModeCount * sizeof(VBE_MODEINFO), TAG_VBE);
    VBEDeviceExtension->ModeNumbers =
-      ExAllocatePool(PagedPool, ModeCount * sizeof(WORD));
+      VideoPortAllocatePool(HwDeviceExtension, VpPagedPool, ModeCount * sizeof(USHORT), TAG_VBE);
 
    /*
     * Get the actual mode infos.
@@ -337,7 +344,8 @@ VBEInitialize(PVOID HwDeviceExtension)
           VbeModeInfo->XResolution >= 640 &&
           VbeModeInfo->YResolution >= 480 &&
           (VbeModeInfo->MemoryModel == VBE_MEMORYMODEL_PACKEDPIXEL ||
-           VbeModeInfo->MemoryModel == VBE_MEMORYMODEL_DIRECTCOLOR))
+           VbeModeInfo->MemoryModel == VBE_MEMORYMODEL_DIRECTCOLOR) &&
+          VbeModeInfo->PhysBasePtr != 0)
       {
          if (VbeModeInfo->ModeAttributes & VBE_MODEATTR_LINEAR)
          {
@@ -356,7 +364,7 @@ VBEInitialize(PVOID HwDeviceExtension)
 
    if (SuitableModeCount == 0)
    {
-      DPRINT(("VBEMP: No video modes supported\n"));
+      VideoPortDebugPrint(Warn, "VBEMP: No video modes supported\n");
       return FALSE;
    }
 
@@ -369,20 +377,18 @@ VBEInitialize(PVOID HwDeviceExtension)
    VBESortModes(VBEDeviceExtension);
 
    /*
-    * Print the supported video modes when DBG is set.
+    * Print the supported video modes when NDEBUG is not set.
     */
 
-#ifdef DBG
    for (CurrentMode = 0;
         CurrentMode < SuitableModeCount;
         CurrentMode++)
    {
-      DPRINT(("%dx%dx%d\n",
+      VideoPortDebugPrint(Trace, "%dx%dx%d\n",
          VBEDeviceExtension->ModeInfo[CurrentMode].XResolution,
          VBEDeviceExtension->ModeInfo[CurrentMode].YResolution,
-         VBEDeviceExtension->ModeInfo[CurrentMode].BitsPerPixel));
+         VBEDeviceExtension->ModeInfo[CurrentMode].BitsPerPixel);
    }
-#endif
 
    return TRUE;
 }
@@ -398,9 +404,9 @@ VBEStartIO(
    PVOID HwDeviceExtension,
    PVIDEO_REQUEST_PACKET RequestPacket)
 {
-   BOOL Result;
+   BOOLEAN Result;
 
-   RequestPacket->StatusBlock->Status = STATUS_UNSUCCESSFUL;
+   RequestPacket->StatusBlock->Status = ERROR_INVALID_FUNCTION;
 
    switch (RequestPacket->IoControlCode)
    {
@@ -477,7 +483,7 @@ VBEStartIO(
          if (RequestPacket->InputBufferLength < sizeof(VIDEO_CLUT) ||
              RequestPacket->InputBufferLength <
              (((PVIDEO_CLUT)RequestPacket->InputBuffer)->NumEntries * sizeof(ULONG)) +
-             sizeof(VIDEO_CLUT))
+             FIELD_OFFSET(VIDEO_CLUT, LookupTable))
          {
             RequestPacket->StatusBlock->Status = ERROR_INSUFFICIENT_BUFFER;
             return TRUE;
@@ -501,12 +507,12 @@ VBEStartIO(
          break;
 
       default:
-         RequestPacket->StatusBlock->Status = STATUS_NOT_IMPLEMENTED;
+         RequestPacket->StatusBlock->Status = ERROR_INVALID_FUNCTION;
          return FALSE;
    }
 
    if (Result)
-      RequestPacket->StatusBlock->Status = STATUS_SUCCESS;
+      RequestPacket->StatusBlock->Status = NO_ERROR;
 
    return TRUE;
 }
@@ -609,7 +615,7 @@ VBEGetPowerState(
       &BiosRegisters);
 
    if (BiosRegisters.Eax == VBE_NOT_SUPPORTED)
-      return ERROR_NOT_SUPPORTED;
+      return ERROR_DEV_NOT_EXIST;
    if (BiosRegisters.Eax != VBE_SUCCESS)
       return ERROR_INVALID_FUNCTION;
 
@@ -642,7 +648,7 @@ VBEGetPowerState(
       return NO_ERROR;
    }
 
-   return ERROR_NOT_SUPPORTED;
+   return ERROR_DEV_NOT_EXIST;
 }
 
 /*
@@ -691,7 +697,7 @@ VBESetPowerState(
       &BiosRegisters);
 
    if (BiosRegisters.Eax == VBE_NOT_SUPPORTED)
-      return ERROR_NOT_SUPPORTED;
+      return ERROR_DEV_NOT_EXIST;
    if (BiosRegisters.Eax != VBE_SUCCESS)
       return ERROR_INVALID_FUNCTION;
 
@@ -704,7 +710,7 @@ VBESetPowerState(
  * Sets the adapter to the specified operating mode.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBESetCurrentMode(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PVIDEO_MODE RequestedMode,
@@ -730,7 +736,7 @@ VBESetCurrentMode(
    }
    else
    {
-      DPRINT(("VBEMP: VBESetCurrentMode failed (%x)\n", BiosRegisters.Eax));
+      VideoPortDebugPrint(Error, "VBEMP: VBESetCurrentMode failed (%x)\n", BiosRegisters.Eax);
       DeviceExtension->CurrentMode = -1;
    }
 
@@ -744,7 +750,7 @@ VBESetCurrentMode(
  * at system boot.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBEResetDevice(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PSTATUS_BLOCK StatusBlock)
@@ -768,7 +774,7 @@ VBEResetDevice(
  * space of the requestor.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBEMapVideoMemory(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PVIDEO_MEMORY RequestedAddress,
@@ -825,7 +831,7 @@ VBEMapVideoMemory(
  * frame buffer and video RAM.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBEUnmapVideoMemory(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PVIDEO_MEMORY VideoMemory,
@@ -844,7 +850,7 @@ VBEUnmapVideoMemory(
  * buffer for an IOCTL_VIDEO_QUERY_AVAIL_MODES request.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBEQueryNumAvailModes(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PVIDEO_NUM_MODES Modes,
@@ -936,7 +942,7 @@ VBEQueryMode(
  * Returns information about each video mode supported by the adapter.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBEQueryAvailModes(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PVIDEO_MODE_INFORMATION ReturnedModes,
@@ -966,7 +972,7 @@ VBEQueryAvailModes(
  * Returns information about current video mode.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBEQueryCurrentMode(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PVIDEO_MODE_INFORMATION VideoModeInfo,
@@ -991,7 +997,7 @@ VBEQueryCurrentMode(
  * yet implemented.
  */
 
-BOOL FASTCALL
+BOOLEAN FASTCALL
 VBESetColorRegisters(
    PVBE_DEVICE_EXTENSION DeviceExtension,
    PVIDEO_CLUT ColorLookUpTable,