[BOOTVID] Split common.c into graphics-specific and console (in console.c) parts (#8547)

In addition:
- move back common function prototypes to precomp.h;
- const-ify `VidpFontData` and adjust its usages;
- improve SAL annotations for `InitPaletteWithTable()`;
- rename the (Vid)ResetDisplay() parameter to "SetMode".
This commit is contained in:
Hermès Bélusca-Maïto
2025-12-24 23:06:13 +01:00
parent 379eb14596
commit 44e4781600
15 changed files with 248 additions and 306 deletions

View File

@@ -27,6 +27,7 @@ endif()
list(APPEND SOURCE
common.c
console.c
fontdata.c
precomp.h)

View File

@@ -31,7 +31,7 @@ extern PUSHORT VgaArmBase;
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count);
VOID
@@ -42,21 +42,3 @@ SetPixel(
_In_ ULONG Left,
_In_ ULONG Top,
_In_ UCHAR Color);
VOID
PreserveRow(
_In_ ULONG CurrentTop,
_In_ ULONG TopDelta,
_In_ BOOLEAN Restore);
VOID
DoScroll(
_In_ ULONG Scroll);
VOID
DisplayCharacter(
_In_ CHAR Character,
_In_ ULONG Left,
_In_ ULONG Top,
_In_ ULONG TextColor,
_In_ ULONG BackColor);

View File

@@ -62,7 +62,7 @@ DisplayCharacter(
_In_ ULONG TextColor,
_In_ ULONG BackColor)
{
PUCHAR FontChar;
const UCHAR* FontChar;
ULONG i, j, XOffset;
/* Get the font line for this character */
@@ -209,7 +209,7 @@ VidpInitializeDisplay(VOID)
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count)
{
UNIMPLEMENTED;
@@ -251,24 +251,13 @@ VidInitialize(
}
VOID
NTAPI
VidResetDisplay(
_In_ BOOLEAN HalReset)
ResetDisplay(
_In_ BOOLEAN SetMode)
{
//
// Clear the current position
//
VidpCurrentX = 0;
VidpCurrentY = 0;
//
// Re-initialize the VGA Display
//
/* Re-initialize the display */
VidpInitializeDisplay();
//
// Re-initialize the palette and fill the screen black
//
/* Re-initialize the palette and fill the screen black */
InitializePalette();
VidSolidColorFill(0, 0, SCREEN_WIDTH - 1, SCREEN_HEIGHT - 1, BV_COLOR_BLACK);
}

View File

@@ -11,19 +11,6 @@
/* GLOBALS ********************************************************************/
UCHAR VidpTextColor = BV_COLOR_WHITE;
ULONG VidpCurrentX = 0;
ULONG VidpCurrentY = 0;
ULONG VidpScrollRegion[4] =
{
0,
0,
SCREEN_WIDTH - 1,
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
@@ -49,8 +36,6 @@ const RGBQUAD VidpDefaultPalette[BV_MAX_COLORS] =
RGB(255, 255, 255), /* White */
};
static BOOLEAN ClearRow = FALSE;
/* PRIVATE FUNCTIONS **********************************************************/
static VOID
@@ -310,144 +295,6 @@ RleBitBlt(
/* PUBLIC FUNCTIONS ***********************************************************/
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(
_In_z_ PUCHAR String,
_In_ ULONG Left,
_In_ ULONG Top,
_In_ BOOLEAN Transparent)
{
ULONG BackColor;
/*
* If the caller wanted transparent, then send the special value (16),
* else use our default and call the helper routine.
*/
BackColor = Transparent ? BV_COLOR_NONE : BV_COLOR_LIGHT_CYAN;
/* Loop every character and adjust the position */
for (; *String; ++String, Left += BOOTCHAR_WIDTH)
{
/* Display a character */
DisplayCharacter(*String, Left, Top, BV_COLOR_LIGHT_BLUE, BackColor);
}
}
VOID
NTAPI
VidSetScrollRegion(
_In_ ULONG Left,
_In_ ULONG Top,
_In_ ULONG Right,
_In_ ULONG Bottom)
{
/* Assert alignment */
ASSERT((Left % BOOTCHAR_WIDTH) == 0);
ASSERT((Right % BOOTCHAR_WIDTH) == BOOTCHAR_WIDTH - 1);
/* Set Scroll Region */
VidpScrollRegion[0] = Left;
VidpScrollRegion[1] = Top;
VidpScrollRegion[2] = Right;
VidpScrollRegion[3] = Bottom;
/* Set current X and Y */
VidpCurrentX = Left;
VidpCurrentY = Top;
}
VOID
NTAPI
VidDisplayString(
_In_z_ 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(

View File

@@ -0,0 +1,181 @@
/*
* PROJECT: ReactOS Boot Video Driver
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: Platform-independent console functionality
* COPYRIGHT: Copyright 2010 Gregor Schneider <gregor.schneider@reactos.org>
* Copyright 2011 Rafal Harabien <rafalh@reactos.org>
* Copyright 2020 Stanislav Motylkov <x86corez@gmail.com>
*/
#include "precomp.h"
/* GLOBALS ********************************************************************/
UCHAR VidpTextColor = BV_COLOR_WHITE;
ULONG VidpCurrentX = 0;
ULONG VidpCurrentY = 0;
ULONG VidpScrollRegion[4] =
{
0,
0,
SCREEN_WIDTH - 1,
SCREEN_HEIGHT - 1
};
static BOOLEAN ClearRow = FALSE;
/* PUBLIC FUNCTIONS ***********************************************************/
VOID
NTAPI
VidResetDisplay(
_In_ BOOLEAN SetMode)
{
/* Clear the current position */
VidpCurrentX = 0;
VidpCurrentY = 0;
/* Invoke the hardware-specific routine */
ResetDisplay(SetMode);
}
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
VidSetScrollRegion(
_In_ ULONG Left,
_In_ ULONG Top,
_In_ ULONG Right,
_In_ ULONG Bottom)
{
/* Assert alignment */
ASSERT((Left % BOOTCHAR_WIDTH) == 0);
ASSERT((Right % BOOTCHAR_WIDTH) == BOOTCHAR_WIDTH - 1);
/* Set Scroll Region */
VidpScrollRegion[0] = Left;
VidpScrollRegion[1] = Top;
VidpScrollRegion[2] = Right;
VidpScrollRegion[3] = Bottom;
/* Set current X and Y */
VidpCurrentX = Left;
VidpCurrentY = Top;
}
VOID
NTAPI
VidDisplayStringXY(
_In_z_ PUCHAR String,
_In_ ULONG Left,
_In_ ULONG Top,
_In_ BOOLEAN Transparent)
{
ULONG BackColor;
/*
* If the caller wanted transparent, then send the special value (16),
* else use our default and call the helper routine.
*/
BackColor = Transparent ? BV_COLOR_NONE : BV_COLOR_LIGHT_CYAN;
/* Loop every character and adjust the position */
for (; *String; ++String, Left += BOOTCHAR_WIDTH)
{
/* Display a character */
DisplayCharacter(*String, Left, Top, BV_COLOR_LIGHT_BLUE, BackColor);
}
}
VOID
NTAPI
VidDisplayString(
_In_z_ 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];
}
}
}
}

View File

@@ -13,7 +13,7 @@
// Available from https://web.archive.org/web/20210510052051/http://mirtchovski.com/p9/fonts/
// FontData Array generated by bootvid_font_generator.
//
UCHAR VidpFontData[256 * BOOTCHAR_HEIGHT] =
const 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

View File

@@ -440,7 +440,7 @@ VidInitialize(
/* Set the VGA Memory Base */
VgaBase = Base;
/* Now check if we have to set the mode */
/* Check whether we have to set the video mode */
if (SetMode)
{
/* Clear the current position */
@@ -460,27 +460,18 @@ VidInitialize(
}
}
/* VGA is ready */
return TRUE;
}
VOID
NTAPI
VidResetDisplay(
_In_ BOOLEAN HalReset)
ResetDisplay(
_In_ BOOLEAN SetMode)
{
/* Clear the current position */
VidpCurrentX = 0;
VidpCurrentY = 0;
/* Clear the screen with HAL if we were asked to */
if (HalReset)
/* Reset the video mode with HAL if requested */
if (SetMode && !HalResetDisplay())
{
if (!HalResetDisplay())
{
/* The HAL didn't handle the display, fully re-initialize the VGA */
VgaInterpretCmdStream(VGA_640x480);
}
/* The HAL didn't handle the display, fully re-initialize the VGA */
VgaInterpretCmdStream(VGA_640x480);
}
/* Always re-initialize the AC registers */

View File

@@ -27,7 +27,7 @@ extern UCHAR PixelMask[8];
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count);
VOID
@@ -54,21 +54,3 @@ SetPixel(
/* Set the new color */
WRITE_REGISTER_UCHAR(PixelPosition, Color);
}
VOID
PreserveRow(
_In_ ULONG CurrentTop,
_In_ ULONG TopDelta,
_In_ BOOLEAN Restore);
VOID
DoScroll(
_In_ ULONG Scroll);
VOID
DisplayCharacter(
_In_ CHAR Character,
_In_ ULONG Left,
_In_ ULONG Top,
_In_ ULONG TextColor,
_In_ ULONG BackColor);

View File

@@ -117,7 +117,8 @@ DisplayCharacter(
_In_ ULONG TextColor,
_In_ ULONG BackColor)
{
PUCHAR FontChar, PixelPtr;
const UCHAR* FontChar;
PUCHAR PixelPtr;
ULONG Height;
UCHAR Shift;
@@ -215,11 +216,11 @@ SetPaletteEntryRGB(
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count)
{
const ULONG* Entry = Table;
ULONG i;
PULONG Entry = Table;
for (i = 0; i < Count; i++, Entry++)
{

View File

@@ -252,11 +252,11 @@ SetPaletteEntryRGB(
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count)
{
const ULONG* Entry = Table;
ULONG i;
PULONG Entry = Table;
for (i = 0; i < Count; i++)
SetPaletteEntryRGB(i, *Entry++);
@@ -273,8 +273,8 @@ DisplayCharacter(
_In_ ULONG TextColor,
_In_ ULONG BackColor)
{
const UCHAR* FontChar = GetFontPtr(Character);
ULONG X, Y, PixelMask;
PUCHAR FontChar = GetFontPtr(Character);
for (Y = Top;
Y < Top + BOOTCHAR_HEIGHT;
@@ -394,19 +394,14 @@ VidCleanUp(VOID)
}
VOID
NTAPI
VidResetDisplay(
_In_ BOOLEAN HalReset)
ResetDisplay(
_In_ BOOLEAN SetMode)
{
PULONG PixelsPosition = (PULONG)(FrameBuffer + FB_OFFSET(0, 0));
ULONG PixelCount = ((SCREEN_WIDTH * SCREEN_HEIGHT) / sizeof(ULONG)) + 1;
/* Clear the current position */
VidpCurrentX = 0;
VidpCurrentY = 0;
/* Clear the screen with HAL if we were asked to */
if (HalReset)
/* Reset the video mode with HAL if requested */
if (SetMode)
HalResetDisplay();
WRITE_PORT_UCHAR((PUCHAR)GDC1_IO_o_MODE_FLIPFLOP1, GRAPH_MODE_DISPLAY_DISABLE);

View File

@@ -18,36 +18,16 @@
extern ULONG_PTR FrameBuffer;
/* PROTOTYPES *****************************************************************/
VOID
DisplayCharacter(
_In_ CHAR Character,
_In_ ULONG Left,
_In_ ULONG Top,
_In_ ULONG TextColor,
_In_ ULONG BackColor);
VOID
DoScroll(
_In_ ULONG Scroll);
/* FUNCTIONS ******************************************************************/
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count);
VOID
PreserveRow(
_In_ ULONG CurrentTop,
_In_ ULONG TopDelta,
_In_ BOOLEAN Restore);
VOID
PrepareForSetPixel(VOID);
/* FUNCTIONS ******************************************************************/
FORCEINLINE
VOID
SetPixel(

View File

@@ -10,6 +10,7 @@
#include "precomp.h"
#include <drivers/xbox/xgpu.h>
#define NDEBUG
#include <debug.h>
/* GLOBALS ********************************************************************/
@@ -199,7 +200,7 @@ VidInitialize(
/* Place backbuffer in the hidden part of framebuffer */
BackBuffer = (PUCHAR)(FrameBufferStart + NV2A_VIDEO_MEMORY_SIZE - BackBufferSize);
/* Now check if we have to set the mode */
/* Check whether we have to set the video mode */
if (SetMode)
VidResetDisplay(TRUE);
@@ -220,16 +221,11 @@ VidCleanUp(VOID)
}
VOID
NTAPI
VidResetDisplay(
_In_ BOOLEAN HalReset)
ResetDisplay(
_In_ BOOLEAN SetMode)
{
/* Clear the current position */
VidpCurrentX = 0;
VidpCurrentY = 0;
/* Clear the screen with HAL if we were asked to */
if (HalReset)
/* Reset the video mode with HAL if requested */
if (SetMode)
HalResetDisplay();
/* Re-initialize the palette and fill the screen black */
@@ -240,10 +236,10 @@ VidResetDisplay(
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count)
{
PULONG Entry = Table;
const ULONG* Entry = Table;
for (ULONG i = 0; i < Count; i++, Entry++)
{
@@ -354,7 +350,7 @@ DisplayCharacter(
_In_ ULONG BackColor)
{
/* Get the font and pixel pointer */
PUCHAR FontChar = GetFontPtr(Character);
const UCHAR* FontChar = GetFontPtr(Character);
/* Loop each pixel height */
for (ULONG y = Top; y < Top + BOOTCHAR_HEIGHT; y++, FontChar += FONT_PTR_DELTA)

View File

@@ -7,9 +7,6 @@
* Copyright 2020 Stanislav Motylkov <x86corez@gmail.com>
*/
#ifndef _BOOTVID_XBOX_H_
#define _BOOTVID_XBOX_H_
#pragma once
#define BB_OFFSET(x, y) ((y) * SCREEN_WIDTH + (x))
@@ -17,7 +14,7 @@
VOID
InitPaletteWithTable(
_In_ PULONG Table,
_In_reads_(Count) const ULONG* Table,
_In_ ULONG Count);
VOID
@@ -28,23 +25,3 @@ SetPixel(
_In_ ULONG Left,
_In_ ULONG Top,
_In_ UCHAR Color);
VOID
PreserveRow(
_In_ ULONG CurrentTop,
_In_ ULONG TopDelta,
_In_ BOOLEAN Restore);
VOID
DoScroll(
_In_ ULONG Scroll);
VOID
DisplayCharacter(
_In_ CHAR Character,
_In_ ULONG Left,
_In_ ULONG Top,
_In_ ULONG TextColor,
_In_ ULONG BackColor);
#endif /* _BOOTVID_XBOX_H_ */

View File

@@ -7,14 +7,13 @@
* Copyright 2020 Stanislav Motylkov <x86corez@gmail.com>
*/
#ifndef _BOOTVID_PCH_
#define _BOOTVID_PCH_
#pragma once
#include <ntifs.h>
#include <ndk/halfuncs.h>
#include <drivers/bootvid/bootvid.h>
/* Arch specific includes */
/* Arch-specific includes */
#if defined(_M_IX86) || defined(_M_AMD64)
#if defined(SARCH_PC98)
#include "i386/pc98/pc98.h"
@@ -30,7 +29,7 @@
#error Unknown architecture
#endif
/* Define if FontData has upside down characters */
/* Define if FontData has upside-down characters */
#undef CHAR_GEN_UPSIDE_DOWN
#define BOOTCHAR_HEIGHT 13
@@ -65,7 +64,7 @@ extern UCHAR VidpTextColor;
extern ULONG VidpCurrentX;
extern ULONG VidpCurrentY;
extern ULONG VidpScrollRegion[4];
extern UCHAR VidpFontData[256 * BOOTCHAR_HEIGHT];
extern const 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)))
@@ -84,4 +83,25 @@ extern const RGBQUAD VidpDefaultPalette[BV_MAX_COLORS];
# define FONT_PTR_DELTA (1)
#endif
#endif /* _BOOTVID_PCH_ */
VOID
PreserveRow(
_In_ ULONG CurrentTop,
_In_ ULONG TopDelta,
_In_ BOOLEAN Restore);
VOID
DoScroll(
_In_ ULONG Scroll);
VOID
DisplayCharacter(
_In_ CHAR Character,
_In_ ULONG Left,
_In_ ULONG Top,
_In_ ULONG TextColor,
_In_ ULONG BackColor);
VOID
ResetDisplay(
_In_ BOOLEAN SetMode);

View File

@@ -20,7 +20,7 @@ VidInitialize(
VOID
NTAPI
VidResetDisplay(
_In_ BOOLEAN HalReset);
_In_ BOOLEAN SetMode);
ULONG
NTAPI