mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 21:12:59 +00:00
[NTOSKRNL][HAL][BOOTVID] Some more code refactoring
- 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
This commit is contained in:
parent
909f50a857
commit
cd91271796
15 changed files with 367 additions and 426 deletions
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue