[NTOSKRNL][HAL][BOOTVID] Some more code refactoring bootvid_refactor 2763/head
authorStanislav Motylkov <x86corez@gmail.com>
Sat, 9 May 2020 14:20:57 +0000 (17:20 +0300)
committerStanislav Motylkov <x86corez@gmail.com>
Tue, 12 May 2020 12:56:37 +0000 (15:56 +0300)
- Add boot video color constants
- Refactor palette initialization
- Move some common stuff in right place
- Get rid of some magic constants and hardcoded values
- Get rid of TopDelta variable (calculated at compile time)
- Update SAL annotations

Addendum to 5f2ca473. CORE-16216 CORE-16219

15 files changed:
drivers/base/bootvid/arm/arm.h
drivers/base/bootvid/arm/bootvid.c
drivers/base/bootvid/common.c
drivers/base/bootvid/fontdata.c
drivers/base/bootvid/i386/pc/bootvid.c
drivers/base/bootvid/i386/pc/pc.h
drivers/base/bootvid/i386/pc/vga.c
drivers/base/bootvid/precomp.h
hal/halx86/generic/misc.c
ntoskrnl/inbv/inbv.c
ntoskrnl/kd/kdio.c
ntoskrnl/ke/bug.c
ntoskrnl/po/poshtdwn.c
sdk/include/reactos/drivers/bootvid/bootvid.h
sdk/include/reactos/drivers/bootvid/display.h

index 2f46aa8..7c3801c 100644 (file)
@@ -23,41 +23,28 @@ extern PUSHORT VgaArmBase;
 #define READ_REGISTER_USHORT(r) (*(volatile USHORT * const)(r))
 #define WRITE_REGISTER_USHORT(r, v) (*(volatile USHORT *)(r) = (v))
 
-PALETTE_ENTRY VidpVga8To16BitTransform[16] =
-{
-    {0x00, 0x00, 0x00}, // Black
-    {0x00, 0x00, 0x08}, // Blue
-    {0x00, 0x08, 0x00}, // Green
-    {0x00, 0x08, 0x08}, // Cyan
-    {0x08, 0x00, 0x00}, // Red
-    {0x08, 0x00, 0x08}, // Magenta
-    {0x0B, 0x0D, 0x0F}, // Brown
-    {0x10, 0x10, 0x10}, // Light Gray
-    {0x08, 0x08, 0x08}, // Dark Gray
-    {0x00, 0x00, 0x1F}, // Light Blue
-    {0x00, 0x1F, 0x00}, // Light Green
-    {0x00, 0x1F, 0x1F}, // Light Cyan
-    {0x1F, 0x00, 0x00}, // Light Red
-    {0x1F, 0x00, 0x1F}, // Light Magenta
-    {0x1F, 0x1F, 0x00}, // Yellow
-    {0x1F, 0x1F, 0x1F}, // White
-};
-
 FORCEINLINE
 USHORT
-VidpBuildColor(_In_ UCHAR Color)
+VidpBuildColor(
+    _In_ UCHAR Color)
 {
     UCHAR Red, Green, Blue;
 
     /* Extract color components */
-    Red   = VidpVga8To16BitTransform[Color].Red;
-    Green = VidpVga8To16BitTransform[Color].Green;
-    Blue  = VidpVga8To16BitTransform[Color].Blue;
+    Red   = GetRValue(DefaultPalette[Color]) >> 3;
+    Green = GetGValue(DefaultPalette[Color]) >> 3;
+    Blue  = GetBValue(DefaultPalette[Color]) >> 3;
 
     /* Build the 16-bit color mask */
     return ((Red & 0x1F) << 11) | ((Green & 0x1F) << 6) | ((Blue & 0x1F));
 }
 
+VOID
+NTAPI
+InitPaletteWithTable(
+    _In_ PULONG Table,
+    _In_ ULONG Count);
+
 FORCEINLINE
 VOID
 SetPixel(
@@ -73,3 +60,24 @@ SetPixel(
     /* Set our color */
     WRITE_REGISTER_USHORT(PixelPosition, VidpBuildColor(Color));
 }
+
+VOID
+NTAPI
+PreserveRow(
+    _In_ ULONG CurrentTop,
+    _In_ ULONG TopDelta,
+    _In_ BOOLEAN Restore);
+
+VOID
+NTAPI
+DoScroll(
+    _In_ ULONG Scroll);
+
+VOID
+NTAPI
+DisplayCharacter(
+    _In_ CHAR Character,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG TextColor,
+    _In_ ULONG BackColor);
index c21ec62..d34f081 100644 (file)
@@ -5,23 +5,23 @@
 
 PUSHORT VgaArmBase;
 PHYSICAL_ADDRESS VgaPhysical;
-BOOLEAN ClearRow = FALSE;
 
 /* PRIVATE FUNCTIONS *********************************************************/
 
 VOID
 NTAPI
-DisplayCharacter(IN CHAR Character,
-                 IN ULONG Left,
-                 IN ULONG Top,
-                 IN ULONG TextColor,
-                 IN ULONG BackColor)
+DisplayCharacter(
+    _In_ CHAR Character,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG TextColor,
+    _In_ ULONG BackColor)
 {
     PUCHAR FontChar;
     ULONG i, j, XOffset;
 
     /* Get the font line for this character */
-    FontChar = &FontData[Character * BOOTCHAR_HEIGHT - Top];
+    FontChar = &VidpFontData[Character * BOOTCHAR_HEIGHT - Top];
 
     /* Loop each pixel height */
     for (i = BOOTCHAR_HEIGHT; i > 0; --i)
@@ -36,7 +36,7 @@ DisplayCharacter(IN CHAR Character,
                 /* We do, use the given Text Color */
                 SetPixel(XOffset, Top, (UCHAR)TextColor);
             }
-            else if (BackColor < 16)
+            else if (BackColor < BV_COLOR_NONE)
             {
                 /*
                  * This is a background pixel. We're drawing it
@@ -56,7 +56,8 @@ DisplayCharacter(IN CHAR Character,
 
 VOID
 NTAPI
-VgaScroll(IN ULONG Scroll)
+DoScroll(
+    _In_ ULONG Scroll)
 {
     ULONG Top, Offset;
     PUSHORT SourceOffset, DestOffset;
@@ -103,9 +104,10 @@ VgaScroll(IN ULONG Scroll)
 
 VOID
 NTAPI
-PreserveRow(IN ULONG CurrentTop,
-            IN ULONG TopDelta,
-            IN BOOLEAN Restore)
+PreserveRow(
+    _In_ ULONG CurrentTop,
+    _In_ ULONG TopDelta,
+    _In_ BOOLEAN Restore)
 {
     PUSHORT Position1, Position2;
     ULONG Count;
@@ -179,7 +181,8 @@ InitPaletteWithTable(
  */
 BOOLEAN
 NTAPI
-VidInitialize(IN BOOLEAN SetMode)
+VidInitialize(
+    _In_ BOOLEAN SetMode)
 {
     DPRINT1("bv-arm v0.1\n");
 
@@ -214,7 +217,8 @@ VidInitialize(IN BOOLEAN SetMode)
  */
 VOID
 NTAPI
-VidResetDisplay(IN BOOLEAN HalReset)
+VidResetDisplay(
+    _In_ BOOLEAN HalReset)
 {
     //
     // Clear the current position
@@ -230,29 +234,8 @@ VidResetDisplay(IN BOOLEAN HalReset)
     //
     // Re-initialize the palette and fill the screen black
     //
-    //InitializePalette();
-    VidSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0);
-}
-
-/*
- * @implemented
- */
-ULONG
-NTAPI
-VidSetTextColor(IN ULONG Color)
-{
-    UCHAR OldColor;
-
-    //
-    // Save the old, set the new
-    //
-    OldColor = VidpTextColor;
-    VidpTextColor = Color;
-
-    //
-    // Return the old text color
-    //
-    return OldColor;
+    InitializePalette();
+    VidSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_BLACK);
 }
 
 /*
@@ -271,98 +254,13 @@ VidCleanUp(VOID)
  */
 VOID
 NTAPI
-VidDisplayString(IN PUCHAR String)
-{
-    ULONG TopDelta = BOOTCHAR_HEIGHT + 1;
-
-    /* Start looping the string */
-    for (; *String; ++String)
-    {
-        /* Treat new-line separately */
-        if (*String == '\n')
-        {
-            /* Modify Y position */
-            VidpCurrentY += TopDelta;
-            if (VidpCurrentY + TopDelta - 1 > VidpScrollRegion[3])
-            {
-                /* Scroll the view and clear the current row */
-                VgaScroll(TopDelta);
-                VidpCurrentY -= TopDelta;
-                PreserveRow(VidpCurrentY, TopDelta, TRUE);
-            }
-            else
-            {
-                /* Preserve the current row */
-                PreserveRow(VidpCurrentY, TopDelta, FALSE);
-            }
-
-            /* Update current X */
-            VidpCurrentX = VidpScrollRegion[0];
-
-            /* No need to clear this row */
-            ClearRow = FALSE;
-        }
-        else if (*String == '\r')
-        {
-            /* Update current X */
-            VidpCurrentX = VidpScrollRegion[0];
-
-            /* If a new-line does not follow we will clear the current row */
-            if (String[1] != '\n') ClearRow = TRUE;
-        }
-        else
-        {
-            /* Clear the current row if we had a return-carriage without a new-line */
-            if (ClearRow)
-            {
-                PreserveRow(VidpCurrentY, TopDelta, TRUE);
-                ClearRow = FALSE;
-            }
-
-            /* Display this character */
-            DisplayCharacter(*String,
-                             VidpCurrentX,
-                             VidpCurrentY,
-                             VidpTextColor,
-                             16);
-            VidpCurrentX += 8;
-
-            /* Check if we should scroll */
-            if (VidpCurrentX + 7 > VidpScrollRegion[2])
-            {
-                /* Update Y position and check if we should scroll it */
-                VidpCurrentY += TopDelta;
-                if (VidpCurrentY + TopDelta - 1 > VidpScrollRegion[3])
-                {
-                    /* Scroll the view and clear the current row */
-                    VgaScroll(TopDelta);
-                    VidpCurrentY -= TopDelta;
-                    PreserveRow(VidpCurrentY, TopDelta, TRUE);
-                }
-                else
-                {
-                    /* Preserve the current row */
-                    PreserveRow(VidpCurrentY, TopDelta, FALSE);
-                }
-
-                /* Update current X */
-                VidpCurrentX = VidpScrollRegion[0];
-            }
-        }
-    }
-}
-
-/*
- * @implemented
- */
-VOID
-NTAPI
-VidScreenToBufferBlt(OUT PUCHAR Buffer,
-                     IN ULONG Left,
-                     IN ULONG Top,
-                     IN ULONG Width,
-                     IN ULONG Height,
-                     IN ULONG Delta)
+VidScreenToBufferBlt(
+    _Out_ PUCHAR Buffer,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Width,
+    _In_ ULONG Height,
+    _In_ ULONG Delta)
 {
     UNIMPLEMENTED;
     while (TRUE);
@@ -373,11 +271,12 @@ VidScreenToBufferBlt(OUT PUCHAR Buffer,
  */
 VOID
 NTAPI
-VidSolidColorFill(IN ULONG Left,
-                  IN ULONG Top,
-                  IN ULONG Right,
-                  IN ULONG Bottom,
-                  IN UCHAR Color)
+VidSolidColorFill(
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Right,
+    _In_ ULONG Bottom,
+    _In_ UCHAR Color)
 {
     int y, x;
 
index 07e98ec..7979ea4 100644 (file)
@@ -2,7 +2,7 @@
 
 /* GLOBALS ********************************************************************/
 
-UCHAR VidpTextColor = 0x0F;
+UCHAR VidpTextColor = BV_COLOR_WHITE;
 
 ULONG VidpCurrentX = 0;
 ULONG VidpCurrentY = 0;
@@ -15,6 +15,33 @@ ULONG VidpScrollRegion[4] =
     SCREEN_HEIGHT - 1
 };
 
+/*
+ * Boot video driver default palette is similar to the standard 16-color
+ * CGA palette, but it has Red and Blue channels swapped, and also dark
+ * and light gray colors swapped.
+ */
+const RGBQUAD VidpDefaultPalette[BV_MAX_COLORS] =
+{
+    RGB(  0,   0,   0), /* Black */
+    RGB(128,   0,   0), /* Red */
+    RGB(  0, 128,   0), /* Green */
+    RGB(128, 128,   0), /* Brown */
+    RGB(  0,   0, 128), /* Blue */
+    RGB(128,   0, 128), /* Magenta */
+    RGB(  0, 128, 128), /* Cyan */
+    RGB(128, 128, 128), /* Dark Gray */
+    RGB(192, 192, 192), /* Light Gray */
+    RGB(255,   0,   0), /* Light Red */
+    RGB(  0, 255,   0), /* Light Green */
+    RGB(255, 255,   0), /* Yellow */
+    RGB(  0,   0, 255), /* Light Blue */
+    RGB(255,   0, 255), /* Light Magenta */
+    RGB(  0, 255, 255), /* Light Cyan */
+    RGB(255, 255, 255), /* White */
+};
+
+static BOOLEAN ClearRow = FALSE;
+
 /* PRIVATE FUNCTIONS **********************************************************/
 
 static VOID
@@ -272,6 +299,22 @@ RleBitBlt(
 
 /* PUBLIC FUNCTIONS ***********************************************************/
 
+/*
+ * @implemented
+ */
+ULONG
+NTAPI
+VidSetTextColor(
+    _In_ ULONG Color)
+{
+    ULONG OldColor;
+
+    /* Save the old color and set the new one */
+    OldColor = VidpTextColor;
+    VidpTextColor = Color;
+    return OldColor;
+}
+
 VOID
 NTAPI
 VidDisplayStringXY(
@@ -286,13 +329,13 @@ VidDisplayStringXY(
      * If the caller wanted transparent, then send the special value (16),
      * else use our default and call the helper routine.
      */
-    BackColor = Transparent ? 16 : 14;
+    BackColor = Transparent ? BV_COLOR_NONE : BV_COLOR_LIGHT_CYAN;
 
     /* Loop every character and adjust the position */
-    for (; *String; ++String, Left += 8)
+    for (; *String; ++String, Left += BOOTCHAR_WIDTH)
     {
         /* Display a character */
-        DisplayCharacter(*String, Left, Top, 12, BackColor);
+        DisplayCharacter(*String, Left, Top, BV_COLOR_LIGHT_BLUE, BackColor);
     }
 }
 
@@ -305,8 +348,8 @@ VidSetScrollRegion(
     _In_ ULONG Bottom)
 {
     /* Assert alignment */
-    ASSERT((Left  & 0x7) == 0);
-    ASSERT((Right & 0x7) == 7);
+    ASSERT((Left % BOOTCHAR_WIDTH) == 0);
+    ASSERT((Right % BOOTCHAR_WIDTH) == BOOTCHAR_WIDTH - 1);
 
     /* Set Scroll Region */
     VidpScrollRegion[0] = Left;
@@ -319,6 +362,87 @@ VidSetScrollRegion(
     VidpCurrentY = Top;
 }
 
+/*
+ * @implemented
+ */
+VOID
+NTAPI
+VidDisplayString(
+    _In_ PUCHAR String)
+{
+    /* Start looping the string */
+    for (; *String; ++String)
+    {
+        /* Treat new-line separately */
+        if (*String == '\n')
+        {
+            /* Modify Y position */
+            VidpCurrentY += BOOTCHAR_HEIGHT + 1;
+            if (VidpCurrentY + BOOTCHAR_HEIGHT > VidpScrollRegion[3])
+            {
+                /* Scroll the view and clear the current row */
+                DoScroll(BOOTCHAR_HEIGHT + 1);
+                VidpCurrentY -= BOOTCHAR_HEIGHT + 1;
+                PreserveRow(VidpCurrentY, BOOTCHAR_HEIGHT + 1, TRUE);
+            }
+            else
+            {
+                /* Preserve the current row */
+                PreserveRow(VidpCurrentY, BOOTCHAR_HEIGHT + 1, FALSE);
+            }
+
+            /* Update current X */
+            VidpCurrentX = VidpScrollRegion[0];
+
+            /* No need to clear this row */
+            ClearRow = FALSE;
+        }
+        else if (*String == '\r')
+        {
+            /* Update current X */
+            VidpCurrentX = VidpScrollRegion[0];
+
+            /* If a new-line does not follow we will clear the current row */
+            if (String[1] != '\n') ClearRow = TRUE;
+        }
+        else
+        {
+            /* Clear the current row if we had a return-carriage without a new-line */
+            if (ClearRow)
+            {
+                PreserveRow(VidpCurrentY, BOOTCHAR_HEIGHT + 1, TRUE);
+                ClearRow = FALSE;
+            }
+
+            /* Display this character */
+            DisplayCharacter(*String, VidpCurrentX, VidpCurrentY, VidpTextColor, BV_COLOR_NONE);
+            VidpCurrentX += BOOTCHAR_WIDTH;
+
+            /* Check if we should scroll */
+            if (VidpCurrentX + BOOTCHAR_WIDTH - 1 > VidpScrollRegion[2])
+            {
+                /* Update Y position and check if we should scroll it */
+                VidpCurrentY += BOOTCHAR_HEIGHT + 1;
+                if (VidpCurrentY + BOOTCHAR_HEIGHT > VidpScrollRegion[3])
+                {
+                    /* Scroll the view and clear the current row */
+                    DoScroll(BOOTCHAR_HEIGHT + 1);
+                    VidpCurrentY -= BOOTCHAR_HEIGHT + 1;
+                    PreserveRow(VidpCurrentY, BOOTCHAR_HEIGHT + 1, TRUE);
+                }
+                else
+                {
+                    /* Preserve the current row */
+                    PreserveRow(VidpCurrentY, BOOTCHAR_HEIGHT + 1, FALSE);
+                }
+
+                /* Update current X */
+                VidpCurrentX = VidpScrollRegion[0];
+            }
+        }
+    }
+}
+
 VOID
 NTAPI
 VidBufferToScreenBlt(
@@ -347,14 +471,16 @@ VidBitBlt(
     PBITMAPINFOHEADER BitmapInfoHeader;
     LONG Delta;
     PUCHAR BitmapOffset;
+    ULONG PaletteCount;
 
     /* Get the Bitmap Header */
     BitmapInfoHeader = (PBITMAPINFOHEADER)Buffer;
 
     /* Initialize the palette */
+    PaletteCount = BitmapInfoHeader->biClrUsed ?
+                   BitmapInfoHeader->biClrUsed : BV_MAX_COLORS;
     InitPaletteWithTable((PULONG)(Buffer + BitmapInfoHeader->biSize),
-                         (BitmapInfoHeader->biClrUsed) ?
-                         BitmapInfoHeader->biClrUsed : 16);
+                         PaletteCount);
 
     /* Make sure we can support this bitmap */
     ASSERT((BitmapInfoHeader->biBitCount * BitmapInfoHeader->biPlanes) <= 4);
@@ -366,7 +492,7 @@ VidBitBlt(
     Delta = (BitmapInfoHeader->biBitCount * BitmapInfoHeader->biWidth) + 31;
     Delta >>= 3;
     Delta &= ~3;
-    BitmapOffset = Buffer + sizeof(BITMAPINFOHEADER) + 16 * sizeof(ULONG);
+    BitmapOffset = Buffer + sizeof(BITMAPINFOHEADER) + PaletteCount * sizeof(ULONG);
 
     /* Check the compression of the bitmap */
     if (BitmapInfoHeader->biCompression == BI_RLE4)
index 12f4a1d..e4a6922 100644 (file)
@@ -6,7 +6,7 @@
 // Available from http://mirtchovski.com/p9/fonts/
 // FontData Array generated by bootvid_font_generator.
 //
-UCHAR FontData[256 * BOOTCHAR_HEIGHT] =
+UCHAR VidpFontData[256 * BOOTCHAR_HEIGHT] =
 {
     0x00, 0x00, 0x00, 0x00, 0xFE, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFE, 0x00, 0x00,  // 0
     0x00, 0x00, 0x00, 0x00, 0xFE, 0x82, 0x82, 0x82, 0x82, 0x82, 0xFE, 0x00, 0x00,  // 13
index c80911d..f333652 100644 (file)
@@ -4,7 +4,8 @@
 
 static BOOLEAN
 NTAPI
-VgaInterpretCmdStream(IN PUSHORT CmdStream)
+VgaInterpretCmdStream(
+    _In_ PUSHORT CmdStream)
 {
     USHORT Cmd;
     UCHAR Major, Minor;
@@ -358,7 +359,8 @@ VgaIsPresent(VOID)
  */
 BOOLEAN
 NTAPI
-VidInitialize(IN BOOLEAN SetMode)
+VidInitialize(
+    _In_ BOOLEAN SetMode)
 {
     ULONG_PTR Context = 0;
     PHYSICAL_ADDRESS TranslatedAddress;
@@ -464,7 +466,8 @@ VidInitialize(IN BOOLEAN SetMode)
  */
 VOID
 NTAPI
-VidResetDisplay(IN BOOLEAN HalReset)
+VidResetDisplay(
+    _In_ BOOLEAN HalReset)
 {
     /* Clear the current position */
     VidpCurrentX = 0;
@@ -485,5 +488,5 @@ VidResetDisplay(IN BOOLEAN HalReset)
 
     /* Re-initialize the palette and fill the screen black */
     InitializePalette();
-    VidSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0);
+    VidSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_BLACK);
 }
index fef2324..c1a96e7 100644 (file)
@@ -19,6 +19,15 @@ extern UCHAR PixelMask[8];
 #define __outpw(Port, Value) \
     WRITE_PORT_USHORT((PUSHORT)(VgaRegisterBase + (Port)), (USHORT)(Value))
 
+VOID
+NTAPI
+InitPaletteWithTable(
+    _In_ PULONG Table,
+    _In_ ULONG Count);
+
+VOID
+PrepareForSetPixel(VOID);
+
 FORCEINLINE
 VOID
 SetPixel(
@@ -37,3 +46,24 @@ SetPixel(
     /* Read the current pixel value and add our color */
     WRITE_REGISTER_UCHAR(PixelPosition, READ_REGISTER_UCHAR(PixelPosition) & Color);
 }
+
+VOID
+NTAPI
+PreserveRow(
+    _In_ ULONG CurrentTop,
+    _In_ ULONG TopDelta,
+    _In_ BOOLEAN Restore);
+
+VOID
+NTAPI
+DoScroll(
+    _In_ ULONG Scroll);
+
+VOID
+NTAPI
+DisplayCharacter(
+    _In_ CHAR Character,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG TextColor,
+    _In_ ULONG BackColor);
index b2d0036..b985bc6 100644 (file)
@@ -57,13 +57,13 @@ static ULONG lookup[16] =
 
 ULONG_PTR VgaRegisterBase = 0;
 ULONG_PTR VgaBase = 0;
-static BOOLEAN ClearRow = FALSE;
 
 /* PRIVATE FUNCTIONS *********************************************************/
 
 static VOID
 NTAPI
-ReadWriteMode(IN UCHAR Mode)
+ReadWriteMode(
+    _In_ UCHAR Mode)
 {
     UCHAR Value;
 
@@ -98,14 +98,6 @@ do {                                                        \
     WRITE_REGISTER_UCHAR((_PixelPtr), (UCHAR)(_TextColor)); \
 } while (0);
 
-#ifdef CHAR_GEN_UPSIDE_DOWN
-# define GetFontPtr(_Char) &FontData[_Char * BOOTCHAR_HEIGHT] + BOOTCHAR_HEIGHT - 1;
-# define FONT_PTR_DELTA (-1)
-#else
-# define GetFontPtr(_Char) &FontData[_Char * BOOTCHAR_HEIGHT];
-# define FONT_PTR_DELTA (1)
-#endif
-
 VOID
 NTAPI
 DisplayCharacter(
@@ -156,7 +148,7 @@ DisplayCharacter(
     }
 
     /* Check if the background color is transparent */
-    if (BackColor >= 16)
+    if (BackColor >= BV_COLOR_NONE)
     {
         /* We are done */
         return;
@@ -199,18 +191,17 @@ DisplayCharacter(
 
 static VOID
 NTAPI
-SetPaletteEntryRGB(IN ULONG Id,
-                   IN ULONG Rgb)
+SetPaletteEntryRGB(
+    _In_ ULONG Id,
+    _In_ RGBQUAD Rgb)
 {
-    PCHAR Colors = (PCHAR)&Rgb;
-
     /* Set the palette index */
     __outpb(VGA_BASE_IO_PORT + DAC_ADDRESS_WRITE_PORT, (UCHAR)Id);
 
     /* Set RGB colors */
-    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, Colors[2] >> 2);
-    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, Colors[1] >> 2);
-    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, Colors[0] >> 2);
+    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, GetRValue(Rgb) >> 2);
+    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, GetGValue(Rgb) >> 2);
+    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, GetBValue(Rgb) >> 2);
 }
 
 VOID
@@ -222,57 +213,16 @@ InitPaletteWithTable(
     ULONG i;
     PULONG Entry = Table;
 
-    /* Loop every entry */
     for (i = 0; i < Count; i++, Entry++)
     {
-        /* Set the entry */
         SetPaletteEntryRGB(i, *Entry);
     }
 }
 
-static VOID
-NTAPI
-SetPaletteEntry(IN ULONG Id,
-                IN ULONG PaletteEntry)
-{
-    /* Set the palette index */
-    __outpb(VGA_BASE_IO_PORT + DAC_ADDRESS_WRITE_PORT, (UCHAR)Id);
-
-    /* Set RGB colors */
-    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, PaletteEntry & 0xFF);
-    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, (PaletteEntry >>= 8) & 0xFF);
-    __outpb(VGA_BASE_IO_PORT + DAC_DATA_REG_PORT, (PaletteEntry >> 8) & 0xFF);
-}
-
 VOID
 NTAPI
-InitializePalette(VOID)
-{
-    ULONG PaletteEntry[16] = {0x000000,
-                              0x000020,
-                              0x002000,
-                              0x002020,
-                              0x200000,
-                              0x200020,
-                              0x202000,
-                              0x202020,
-                              0x303030,
-                              0x00003F,
-                              0x003F00,
-                              0x003F3F,
-                              0x3F0000,
-                              0x3F003F,
-                              0x3F3F00,
-                              0x3F3F3F};
-    ULONG i;
-
-    /* Loop all the entries and set their palettes */
-    for (i = 0; i < 16; i++) SetPaletteEntry(i, PaletteEntry[i]);
-}
-
-static VOID
-NTAPI
-VgaScroll(IN ULONG Scroll)
+DoScroll(
+    _In_ ULONG Scroll)
 {
     ULONG Top, RowSize;
     PUCHAR OldPosition, NewPosition;
@@ -309,11 +259,12 @@ VgaScroll(IN ULONG Scroll)
     }
 }
 
-static VOID
+VOID
 NTAPI
-PreserveRow(IN ULONG CurrentTop,
-            IN ULONG TopDelta,
-            IN BOOLEAN Restore)
+PreserveRow(
+    _In_ ULONG CurrentTop,
+    _In_ ULONG TopDelta,
+    _In_ BOOLEAN Restore)
 {
     PUCHAR Position1, Position2;
     ULONG Count;
@@ -360,21 +311,6 @@ PreserveRow(IN ULONG CurrentTop,
 
 /* PUBLIC FUNCTIONS **********************************************************/
 
-/*
- * @implemented
- */
-ULONG
-NTAPI
-VidSetTextColor(IN ULONG Color)
-{
-    ULONG OldColor;
-
-    /* Save the old color and set the new one */
-    OldColor = VidpTextColor;
-    VidpTextColor = Color;
-    return OldColor;
-}
-
 /*
  * @implemented
  */
@@ -392,94 +328,13 @@ VidCleanUp(VOID)
  */
 VOID
 NTAPI
-VidDisplayString(IN PUCHAR String)
-{
-    ULONG TopDelta = BOOTCHAR_HEIGHT + 1;
-
-    /* Start looping the string */
-    for (; *String; ++String)
-    {
-        /* Treat new-line separately */
-        if (*String == '\n')
-        {
-            /* Modify Y position */
-            VidpCurrentY += TopDelta;
-            if (VidpCurrentY + TopDelta - 1 > VidpScrollRegion[3])
-            {
-                /* Scroll the view and clear the current row */
-                VgaScroll(TopDelta);
-                VidpCurrentY -= TopDelta;
-                PreserveRow(VidpCurrentY, TopDelta, TRUE);
-            }
-            else
-            {
-                /* Preserve the current row */
-                PreserveRow(VidpCurrentY, TopDelta, FALSE);
-            }
-
-            /* Update current X */
-            VidpCurrentX = VidpScrollRegion[0];
-
-            /* No need to clear this row */
-            ClearRow = FALSE;
-        }
-        else if (*String == '\r')
-        {
-            /* Update current X */
-            VidpCurrentX = VidpScrollRegion[0];
-
-            /* If a new-line does not follow we will clear the current row */
-            if (String[1] != '\n') ClearRow = TRUE;
-        }
-        else
-        {
-            /* Clear the current row if we had a return-carriage without a new-line */
-            if (ClearRow)
-            {
-                PreserveRow(VidpCurrentY, TopDelta, TRUE);
-                ClearRow = FALSE;
-            }
-
-            /* Display this character */
-            DisplayCharacter(*String, VidpCurrentX, VidpCurrentY, VidpTextColor, 16);
-            VidpCurrentX += 8;
-
-            /* Check if we should scroll */
-            if (VidpCurrentX + 7 > VidpScrollRegion[2])
-            {
-                /* Update Y position and check if we should scroll it */
-                VidpCurrentY += TopDelta;
-                if (VidpCurrentY + TopDelta - 1 > VidpScrollRegion[3])
-                {
-                    /* Scroll the view and clear the current row */
-                    VgaScroll(TopDelta);
-                    VidpCurrentY -= TopDelta;
-                    PreserveRow(VidpCurrentY, TopDelta, TRUE);
-                }
-                else
-                {
-                    /* Preserve the current row */
-                    PreserveRow(VidpCurrentY, TopDelta, FALSE);
-                }
-
-                /* Update current X */
-                VidpCurrentX = VidpScrollRegion[0];
-            }
-        }
-    }
-}
-
-/*
- * @implemented
- */
-VOID
-NTAPI
-VidScreenToBufferBlt(OUT PUCHAR Buffer,
-                     IN ULONG Left,
-                     IN ULONG Top,
-                     IN ULONG Width,
-                     IN ULONG Height,
-                     IN ULONG Delta)
+VidScreenToBufferBlt(
+    _Out_ PUCHAR Buffer,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Width,
+    _In_ ULONG Height,
+    _In_ ULONG Delta)
 {
     ULONG Plane;
     ULONG XDistance;
@@ -573,11 +428,12 @@ VidScreenToBufferBlt(OUT PUCHAR Buffer,
  */
 VOID
 NTAPI
-VidSolidColorFill(IN ULONG Left,
-                  IN ULONG Top,
-                  IN ULONG Right,
-                  IN ULONG Bottom,
-                  IN UCHAR Color)
+VidSolidColorFill(
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Right,
+    _In_ ULONG Bottom,
+    _In_ UCHAR Color)
 {
     ULONG rMask, lMask;
     ULONG LeftOffset, RightOffset, Distance;
index d89e93d..da64ef7 100644 (file)
@@ -41,35 +41,7 @@ typedef struct tagBITMAPINFOHEADER
 #define BI_RGB  0
 #define BI_RLE4 2
 
-typedef struct _PALETTE_ENTRY
-{
-    UCHAR Red;
-    UCHAR Green;
-    UCHAR Blue;
-} PALETTE_ENTRY, *PPALETTE_ENTRY;
-
-VOID
-NTAPI
-InitializePalette(VOID);
-
-VOID
-NTAPI
-DisplayCharacter(
-    _In_ CHAR Character,
-    _In_ ULONG Left,
-    _In_ ULONG Top,
-    _In_ ULONG TextColor,
-    _In_ ULONG BackColor
-);
-
-VOID
-PrepareForSetPixel(VOID);
-
-VOID
-NTAPI
-InitPaletteWithTable(
-    _In_ PULONG Table,
-    _In_ ULONG Count);
+typedef ULONG RGBQUAD;
 
 /*
  * Globals
@@ -78,6 +50,23 @@ extern UCHAR VidpTextColor;
 extern ULONG VidpCurrentX;
 extern ULONG VidpCurrentY;
 extern ULONG VidpScrollRegion[4];
-extern UCHAR FontData[256 * BOOTCHAR_HEIGHT];
+extern UCHAR VidpFontData[256 * BOOTCHAR_HEIGHT];
+extern const RGBQUAD VidpDefaultPalette[BV_MAX_COLORS];
+
+#define RGB(r, g, b)    ((RGBQUAD)(((UCHAR)(b) | ((USHORT)((UCHAR)(g))<<8)) | (((ULONG)(UCHAR)(r))<<16)))
+
+#define GetRValue(quad)    ((UCHAR)(((quad)>>16) & 0xFF))
+#define GetGValue(quad)    ((UCHAR)(((quad)>>8) & 0xFF))
+#define GetBValue(quad)    ((UCHAR)((quad) & 0xFF))
+
+#define InitializePalette()    InitPaletteWithTable((PULONG)VidpDefaultPalette, BV_MAX_COLORS)
+
+#ifdef CHAR_GEN_UPSIDE_DOWN
+# define GetFontPtr(_Char) &VidpFontData[_Char * BOOTCHAR_HEIGHT] + BOOTCHAR_HEIGHT - 1;
+# define FONT_PTR_DELTA (-1)
+#else
+# define GetFontPtr(_Char) &VidpFontData[_Char * BOOTCHAR_HEIGHT];
+# define FONT_PTR_DELTA (1)
+#endif
 
 #endif /* _BOOTVID_PCH_ */
index 407f1e6..7e1eb37 100644 (file)
@@ -244,7 +244,7 @@ HalHandleNMI(IN PVOID NmiInfo)
     SystemControl.Bits = __inbyte(SYSTEM_CONTROL_PORT_B);
 
     //
-    // Switch to boot vieo
+    // Switch to boot video
     //
     if (InbvIsBootDriverInstalled())
     {
@@ -257,13 +257,13 @@ HalHandleNMI(IN PVOID NmiInfo)
         //
         // Fill the screen
         //
-        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 1);
+        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_RED);
         InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
 
         //
         // Enable text
         //
-        InbvSetTextColor(15);
+        InbvSetTextColor(BV_COLOR_WHITE);
         InbvInstallDisplayStringFilter(NULL);
         InbvEnableDisplayString(TRUE);
     }
index 5617e85..76af14c 100644 (file)
@@ -779,7 +779,7 @@ InbvUpdateProgressBar(IN ULONG Progress)
                           ProgressBarTop,
                           ProgressBarLeft + FillCount,
                           ProgressBarTop + 12,
-                          15);
+                          BV_COLOR_WHITE);
 
         /* Release the lock */
         InbvReleaseLock();
@@ -827,7 +827,7 @@ InbvBitBlt(IN PUCHAR Buffer,
 
 VOID
 NTAPI
-InbvScreenToBufferBlt(IN PUCHAR Buffer,
+InbvScreenToBufferBlt(OUT PUCHAR Buffer,
                       IN ULONG X,
                       IN ULONG Y,
                       IN ULONG Width,
@@ -1021,7 +1021,7 @@ InbvRotationThread(
             if (Index >= 3)
             {
                 /* Fill previous bar position */
-                VidSolidColorFill(X + ((Index - 3) * 8), Y, (X + ((Index - 3) * 8)) + 8 - 1, Y + 9 - 1, 0);
+                VidSolidColorFill(X + ((Index - 3) * 8), Y, (X + ((Index - 3) * 8)) + 8 - 1, Y + 9 - 1, BV_COLOR_BLACK);
             }
             if (Index < Total - 1)
             {
@@ -1120,9 +1120,9 @@ DisplayBootBitmap(IN BOOLEAN TextMode)
         if (SharedUserData->NtProductType == NtProductWinNt)
         {
             /* Workstation; set colors */
-            InbvSetTextColor(15);
-            InbvSolidColorFill(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, 7);
-            InbvSolidColorFill(0, VID_FOOTER_BG_TOP, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, 1);
+            InbvSetTextColor(BV_COLOR_WHITE);
+            InbvSolidColorFill(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, BV_COLOR_DARK_GRAY);
+            InbvSolidColorFill(0, VID_FOOTER_BG_TOP, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, BV_COLOR_RED);
 
             /* Get resources */
             Header = InbvGetResourceAddress(IDB_WKSTA_HEADER);
@@ -1131,9 +1131,9 @@ DisplayBootBitmap(IN BOOLEAN TextMode)
         else
         {
             /* Server; set colors */
-            InbvSetTextColor(14);
-            InbvSolidColorFill(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, 6);
-            InbvSolidColorFill(0, VID_FOOTER_BG_TOP, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, 1);
+            InbvSetTextColor(BV_COLOR_LIGHT_CYAN);
+            InbvSolidColorFill(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, BV_COLOR_CYAN);
+            InbvSolidColorFill(0, VID_FOOTER_BG_TOP, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, BV_COLOR_RED);
 
             /* Get resources */
             Header = InbvGetResourceAddress(IDB_SERVER_HEADER);
@@ -1246,7 +1246,7 @@ DisplayBootBitmap(IN BOOLEAN TextMode)
                 InbvScreenToBufferBlt(Buffer, VID_SKU_SAVE_AREA_LEFT,
                                       VID_SKU_SAVE_AREA_TOP, 7, 7, 8);
                 InbvSolidColorFill(VID_SKU_AREA_LEFT, VID_SKU_AREA_TOP,
-                                   VID_SKU_AREA_RIGHT, VID_SKU_AREA_BOTTOM, 0);
+                                   VID_SKU_AREA_RIGHT, VID_SKU_AREA_BOTTOM, BV_COLOR_BLACK);
                 InbvBufferToScreenBlt(Buffer, VID_SKU_SAVE_AREA_LEFT,
                                       VID_SKU_SAVE_AREA_TOP, 7, 7, 8);
 
@@ -1390,7 +1390,7 @@ FinalizeBootLogo(VOID)
     if (InbvGetDisplayState() == INBV_DISPLAY_STATE_OWNED)
     {
         /* Clear the screen */
-        VidSolidColorFill(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, 0);
+        VidSolidColorFill(0, 0, SCREEN_WIDTH-1, SCREEN_HEIGHT-1, BV_COLOR_BLACK);
     }
 
     /* Reset progress bar and lock */
index 89ca168..678a335 100644 (file)
@@ -418,8 +418,8 @@ KdpScreenAcquire(VOID)
         /* Acquire ownership and reset the display */
         InbvAcquireDisplayOwnership();
         InbvResetDisplay();
-        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0);
-        InbvSetTextColor(15);
+        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_BLACK);
+        InbvSetTextColor(BV_COLOR_WHITE);
         InbvInstallDisplayStringFilter(NULL);
         InbvEnableDisplayString(TRUE);
         InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
index 0601855..38e0077 100644 (file)
@@ -626,8 +626,8 @@ KiDisplayBlueScreen(IN ULONG MessageId,
         InbvResetDisplay();
 
         /* Display blue screen */
-        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 4);
-        InbvSetTextColor(15);
+        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_BLUE);
+        InbvSetTextColor(BV_COLOR_WHITE);
         InbvInstallDisplayStringFilter(NULL);
         InbvEnableDisplayString(TRUE);
         InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
index 31a1165..c52f8c7 100644 (file)
@@ -162,7 +162,7 @@ PopShutdownHandler(VOID)
         /* Yes we do, cleanup for shutdown screen */
         if (!InbvCheckDisplayOwnership()) InbvAcquireDisplayOwnership();
         InbvResetDisplay();
-        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, 0);
+        InbvSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_BLACK);
         InbvEnableDisplayString(TRUE);
         InbvSetScrollRegion(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1);
 
index 2397195..6df26e9 100644 (file)
 
 BOOLEAN
 NTAPI
-VidInitialize(IN BOOLEAN SetMode);
+VidInitialize(
+    _In_ BOOLEAN SetMode);
 
 VOID
 NTAPI
-VidResetDisplay(IN BOOLEAN HalReset);
+VidResetDisplay(
+    _In_ BOOLEAN HalReset);
 
 ULONG
 NTAPI
-VidSetTextColor(IN ULONG Color);
+VidSetTextColor(
+    _In_ ULONG Color);
 
 VOID
 NTAPI
-VidDisplayStringXY(IN PUCHAR String,
-                   IN ULONG Left,
-                   IN ULONG Top,
-                   IN BOOLEAN Transparent);
+VidDisplayStringXY(
+    _In_ PUCHAR String,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ BOOLEAN Transparent);
 
 VOID
 NTAPI
-VidSetScrollRegion(IN ULONG Left,
-                   IN ULONG Top,
-                   IN ULONG Right,
-                   IN ULONG Bottom);
+VidSetScrollRegion(
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Right,
+    _In_ ULONG Bottom);
 
 VOID
 NTAPI
@@ -44,38 +49,43 @@ VidCleanUp(VOID);
 
 VOID
 NTAPI
-VidBufferToScreenBlt(IN PUCHAR Buffer,
-                     IN ULONG Left,
-                     IN ULONG Top,
-                     IN ULONG Width,
-                     IN ULONG Height,
-                     IN ULONG Delta);
+VidBufferToScreenBlt(
+    _In_ PUCHAR Buffer,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Width,
+    _In_ ULONG Height,
+    _In_ ULONG Delta);
 
 VOID
 NTAPI
-VidDisplayString(IN PUCHAR String);
+VidDisplayString(
+    _In_ PUCHAR String);
 
 VOID
 NTAPI
-VidBitBlt(IN PUCHAR Buffer,
-          IN ULONG Left,
-          IN ULONG Top);
+VidBitBlt(
+    _In_ PUCHAR Buffer,
+    _In_ ULONG Left,
+    _In_ ULONG Top);
 
 VOID
 NTAPI
-VidScreenToBufferBlt(OUT PUCHAR Buffer,
-                     IN ULONG Left,
-                     IN ULONG Top,
-                     IN ULONG Width,
-                     IN ULONG Height,
-                     IN ULONG Delta);
+VidScreenToBufferBlt(
+    _Out_ PUCHAR Buffer,
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Width,
+    _In_ ULONG Height,
+    _In_ ULONG Delta);
 
 VOID
 NTAPI
-VidSolidColorFill(IN ULONG Left,
-                  IN ULONG Top,
-                  IN ULONG Right,
-                  IN ULONG Bottom,
-                  IN UCHAR Color);
+VidSolidColorFill(
+    _In_ ULONG Left,
+    _In_ ULONG Top,
+    _In_ ULONG Right,
+    _In_ ULONG Bottom,
+    _In_ UCHAR Color);
 
 #endif // _BOOTVID_
index af91781..fc509c1 100644 (file)
 /* For default VGA */
 #define SCREEN_WIDTH    640
 #define SCREEN_HEIGHT   480
+
+/* Boot video default color palette constants */
+#define BV_COLOR_BLACK          0
+#define BV_COLOR_RED            1
+#define BV_COLOR_GREEN          2
+#define BV_COLOR_BROWN          3
+#define BV_COLOR_BLUE           4
+#define BV_COLOR_MAGENTA        5
+#define BV_COLOR_CYAN           6
+#define BV_COLOR_DARK_GRAY      7
+#define BV_COLOR_LIGHT_GRAY     8
+#define BV_COLOR_LIGHT_RED      9
+#define BV_COLOR_LIGHT_GREEN    10
+#define BV_COLOR_YELLOW         11
+#define BV_COLOR_LIGHT_BLUE     12
+#define BV_COLOR_LIGHT_MAGENTA  13
+#define BV_COLOR_LIGHT_CYAN     14
+#define BV_COLOR_WHITE          15
+#define BV_COLOR_NONE           16
+#define BV_MAX_COLORS           16