[FREELDR] Add a vgafont.h header (#8498)

It contains the symbols & macros used for the embedded VGA font.

- Adjust users to use `const UCHAR*` instead of `PUCHAR` pointer;
- pc98video.c: Capture the current `FontPtr[Line]` into an `UCHAR`,
  so as to safely modify it.
This commit is contained in:
Hermès Bélusca-Maïto
2025-12-01 16:19:57 +01:00
parent e700c2548b
commit fa5cf28166
7 changed files with 37 additions and 32 deletions

View File

@@ -9,8 +9,8 @@
#include <freeldr.h>
#include <drivers/pc98/video.h>
#include "../../vgafont.h"
extern UCHAR BitmapFont8x16[];
extern BOOLEAN HiResoMachine;
/* GLOBALS ********************************************************************/
@@ -21,9 +21,6 @@ extern BOOLEAN HiResoMachine;
UCHAR TextCols;
UCHAR TextLines;
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 400
#define BYTES_PER_SCANLINE (SCREEN_WIDTH / 8)
@@ -321,7 +318,7 @@ Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
UCHAR R = (Attr & 0x40) ? 0xFF : 0;
UCHAR I = (Attr & 0x80) ? 0xFF : 0;
ULONG VramOffset = X + (Y * CHAR_HEIGHT) * BYTES_PER_SCANLINE;
PUCHAR FontPtr = BitmapFont8x16 + Ch * 16;
const UCHAR* FontPtr = BitmapFont8x16 + Ch * CHAR_HEIGHT;
BOOLEAN CGFont = UseCGFont && (Ch != LIGHT_FILL && Ch != MEDIUM_FILL && Ch != DARK_FILL);
if (CGFont)
@@ -347,34 +344,35 @@ Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
for (Line = 0; Line < CHAR_HEIGHT; Line++)
{
UCHAR CharLine = FontPtr[Line];
if (CGFont)
{
if (CGAccelDraw)
{
/* Character is already displayed by GDC (Text RAM),
* so display only background for it. */
FontPtr[Line] = 0;
CharLine = 0;
}
else
{
/* Obtain glyph data from CG Window */
WRITE_PORT_UCHAR((PUCHAR)KCG_IO_o_LINE, Line | 0x20);
FontPtr[Line] = READ_PORT_UCHAR((PUCHAR)KCG_IO_i_PATTERN);
CharLine = READ_PORT_UCHAR((PUCHAR)KCG_IO_i_PATTERN);
}
}
if (Attr & 0x0F)
{
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B | ((Attr & 0x01) ? FontPtr[Line] : 0);
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G | ((Attr & 0x02) ? FontPtr[Line] : 0);
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R | ((Attr & 0x04) ? FontPtr[Line] : 0);
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I | ((Attr & 0x08) ? FontPtr[Line] : 0);
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B | ((Attr & 0x01) ? CharLine : 0);
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G | ((Attr & 0x02) ? CharLine : 0);
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R | ((Attr & 0x04) ? CharLine : 0);
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I | ((Attr & 0x08) ? CharLine : 0);
}
else
{
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B & ~FontPtr[Line];
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G & ~FontPtr[Line];
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R & ~FontPtr[Line];
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I & ~FontPtr[Line];
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B & ~CharLine;
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G & ~CharLine;
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R & ~CharLine;
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I & ~CharLine;
}
}
}

View File

@@ -20,6 +20,7 @@
*/
#include <freeldr.h>
#include "../../vgafont.h"
#include <debug.h>
DBG_DEFAULT_CHANNEL(UI);
@@ -35,9 +36,6 @@ extern multiboot_info_t * MultibootInfoPtr;
UCHAR MachDefaultTextColor = COLOR_GRAY;
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16
#define TOP_BOTTOM_LINES 0
#define FB_SIZE_MB 4
@@ -47,13 +45,13 @@ UCHAR MachDefaultTextColor = COLOR_GRAY;
static VOID
XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
{
PUCHAR FontPtr;
const UCHAR* FontPtr;
PULONG Pixel;
UCHAR Mask;
unsigned Line;
unsigned Col;
FontPtr = BitmapFont8x16 + Char * 16;
FontPtr = BitmapFont8x16 + Char * CHAR_HEIGHT;
Pixel = (PULONG) ((char *) FrameBuffer + (Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta
+ X * CHAR_WIDTH * BytesPerPixel);
for (Line = 0; Line < CHAR_HEIGHT; Line++)

View File

@@ -7,9 +7,6 @@
#include <uefildr.h>
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16
/* GLOBALS ********************************************************************/
extern EFI_SYSTEM_TABLE* GlobalSystemTable;

View File

@@ -6,12 +6,11 @@
*/
#include <uefildr.h>
#include "../vgafont.h"
#include <debug.h>
DBG_DEFAULT_CHANNEL(WARNING);
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16
#define TOP_BOTTOM_LINES 0
#define LOWEST_SUPPORTED_RES 1
@@ -19,7 +18,6 @@ DBG_DEFAULT_CHANNEL(WARNING);
extern EFI_SYSTEM_TABLE* GlobalSystemTable;
extern EFI_HANDLE GlobalImageHandle;
extern UCHAR BitmapFont8x16[256 * 16];
UCHAR MachDefaultTextColor = COLOR_GRAY;
REACTOS_INTERNAL_BGCONTEXT framebufferData;
@@ -115,14 +113,14 @@ UefiVideoClearScreen(UCHAR Attr)
VOID
UefiVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
{
PUCHAR FontPtr;
const UCHAR* FontPtr;
PULONG Pixel;
UCHAR Mask;
unsigned Line;
unsigned Col;
ULONG Delta;
Delta = (framebufferData.PixelsPerScanLine * 4 + 3) & ~ 0x3;
FontPtr = BitmapFont8x16 + Char * 16;
FontPtr = BitmapFont8x16 + Char * CHAR_HEIGHT;
Pixel = (PULONG) ((char *) framebufferData.BaseAddress +
(Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta + X * CHAR_WIDTH * 4);

View File

@@ -2,14 +2,15 @@
* PROJECT: FreeLoader
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: VGA font 8x16
* COPYRIGHT: Copyright 2004 Gé van Geldorp (gvg@reactos.org)
* COPYRIGHT: Copyright 2004 Gé van Geldorp <gvg@reactos.org>
*/
/* Note: Converted from the XFree vga.bdf font */
#include <freeldr.h>
#include "vgafont.h"
UCHAR BitmapFont8x16[256 * 16] =
const UCHAR BitmapFont8x16[256 * CHAR_HEIGHT] =
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x00 */
0x00,0x00,0x7e,0x81,0xa5,0x81,0x81,0xa5,0x99,0x81,0x81,0x7e,0x00,0x00,0x00,0x00, /* 0x01 */

View File

@@ -0,0 +1,15 @@
/*
* PROJECT: FreeLoader
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
* PURPOSE: VGA font 8x16
* COPYRIGHT: Copyright 2004 Gé van Geldorp <gvg@reactos.org>
*/
#pragma once
#define CHAR_WIDTH 8
#define CHAR_HEIGHT 16
extern const UCHAR BitmapFont8x16[256 * CHAR_HEIGHT];
/* EOF */

View File

@@ -24,8 +24,6 @@
#include <drivers/xbox/xgpu.h>
extern UCHAR BitmapFont8x16[256 * 16];
VOID XboxConsPutChar(int Ch);
BOOLEAN XboxConsKbHit(VOID);
int XboxConsGetCh(VOID);