Skip to content

Commit fa5cf28

Browse files
committed
[FREELDR] Add a vgafont.h header (reactos#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.
1 parent e700c25 commit fa5cf28

File tree

7 files changed

+37
-32
lines changed

7 files changed

+37
-32
lines changed

boot/freeldr/freeldr/arch/i386/pc98/pc98video.c

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
#include <freeldr.h>
1111
#include <drivers/pc98/video.h>
12+
#include "../../vgafont.h"
1213

13-
extern UCHAR BitmapFont8x16[];
1414
extern BOOLEAN HiResoMachine;
1515

1616
/* GLOBALS ********************************************************************/
@@ -21,9 +21,6 @@ extern BOOLEAN HiResoMachine;
2121
UCHAR TextCols;
2222
UCHAR TextLines;
2323

24-
#define CHAR_WIDTH 8
25-
#define CHAR_HEIGHT 16
26-
2724
#define SCREEN_WIDTH 640
2825
#define SCREEN_HEIGHT 400
2926
#define BYTES_PER_SCANLINE (SCREEN_WIDTH / 8)
@@ -321,7 +318,7 @@ Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
321318
UCHAR R = (Attr & 0x40) ? 0xFF : 0;
322319
UCHAR I = (Attr & 0x80) ? 0xFF : 0;
323320
ULONG VramOffset = X + (Y * CHAR_HEIGHT) * BYTES_PER_SCANLINE;
324-
PUCHAR FontPtr = BitmapFont8x16 + Ch * 16;
321+
const UCHAR* FontPtr = BitmapFont8x16 + Ch * CHAR_HEIGHT;
325322
BOOLEAN CGFont = UseCGFont && (Ch != LIGHT_FILL && Ch != MEDIUM_FILL && Ch != DARK_FILL);
326323

327324
if (CGFont)
@@ -347,34 +344,35 @@ Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
347344

348345
for (Line = 0; Line < CHAR_HEIGHT; Line++)
349346
{
347+
UCHAR CharLine = FontPtr[Line];
350348
if (CGFont)
351349
{
352350
if (CGAccelDraw)
353351
{
354352
/* Character is already displayed by GDC (Text RAM),
355353
* so display only background for it. */
356-
FontPtr[Line] = 0;
354+
CharLine = 0;
357355
}
358356
else
359357
{
360358
/* Obtain glyph data from CG Window */
361359
WRITE_PORT_UCHAR((PUCHAR)KCG_IO_o_LINE, Line | 0x20);
362-
FontPtr[Line] = READ_PORT_UCHAR((PUCHAR)KCG_IO_i_PATTERN);
360+
CharLine = READ_PORT_UCHAR((PUCHAR)KCG_IO_i_PATTERN);
363361
}
364362
}
365363
if (Attr & 0x0F)
366364
{
367-
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B | ((Attr & 0x01) ? FontPtr[Line] : 0);
368-
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G | ((Attr & 0x02) ? FontPtr[Line] : 0);
369-
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R | ((Attr & 0x04) ? FontPtr[Line] : 0);
370-
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I | ((Attr & 0x08) ? FontPtr[Line] : 0);
365+
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B | ((Attr & 0x01) ? CharLine : 0);
366+
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G | ((Attr & 0x02) ? CharLine : 0);
367+
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R | ((Attr & 0x04) ? CharLine : 0);
368+
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I | ((Attr & 0x08) ? CharLine : 0);
371369
}
372370
else
373371
{
374-
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B & ~FontPtr[Line];
375-
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G & ~FontPtr[Line];
376-
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R & ~FontPtr[Line];
377-
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I & ~FontPtr[Line];
372+
*(PUCHAR)(VramPlaneB + VramOffset + Line * BYTES_PER_SCANLINE) = B & ~CharLine;
373+
*(PUCHAR)(VramPlaneG + VramOffset + Line * BYTES_PER_SCANLINE) = G & ~CharLine;
374+
*(PUCHAR)(VramPlaneR + VramOffset + Line * BYTES_PER_SCANLINE) = R & ~CharLine;
375+
*(PUCHAR)(VramPlaneI + VramOffset + Line * BYTES_PER_SCANLINE) = I & ~CharLine;
378376
}
379377
}
380378
}

boot/freeldr/freeldr/arch/i386/xbox/xboxvideo.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include <freeldr.h>
23+
#include "../../vgafont.h"
2324

2425
#include <debug.h>
2526
DBG_DEFAULT_CHANNEL(UI);
@@ -35,9 +36,6 @@ extern multiboot_info_t * MultibootInfoPtr;
3536

3637
UCHAR MachDefaultTextColor = COLOR_GRAY;
3738

38-
#define CHAR_WIDTH 8
39-
#define CHAR_HEIGHT 16
40-
4139
#define TOP_BOTTOM_LINES 0
4240

4341
#define FB_SIZE_MB 4
@@ -47,13 +45,13 @@ UCHAR MachDefaultTextColor = COLOR_GRAY;
4745
static VOID
4846
XboxVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
4947
{
50-
PUCHAR FontPtr;
48+
const UCHAR* FontPtr;
5149
PULONG Pixel;
5250
UCHAR Mask;
5351
unsigned Line;
5452
unsigned Col;
5553

56-
FontPtr = BitmapFont8x16 + Char * 16;
54+
FontPtr = BitmapFont8x16 + Char * CHAR_HEIGHT;
5755
Pixel = (PULONG) ((char *) FrameBuffer + (Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta
5856
+ X * CHAR_WIDTH * BytesPerPixel);
5957
for (Line = 0; Line < CHAR_HEIGHT; Line++)

boot/freeldr/freeldr/arch/uefi/ueficon.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77

88
#include <uefildr.h>
99

10-
#define CHAR_WIDTH 8
11-
#define CHAR_HEIGHT 16
12-
1310
/* GLOBALS ********************************************************************/
1411

1512
extern EFI_SYSTEM_TABLE* GlobalSystemTable;

boot/freeldr/freeldr/arch/uefi/uefivid.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,18 @@
66
*/
77

88
#include <uefildr.h>
9+
#include "../vgafont.h"
910

1011
#include <debug.h>
1112
DBG_DEFAULT_CHANNEL(WARNING);
1213

13-
#define CHAR_WIDTH 8
14-
#define CHAR_HEIGHT 16
1514
#define TOP_BOTTOM_LINES 0
1615
#define LOWEST_SUPPORTED_RES 1
1716

1817
/* GLOBALS ********************************************************************/
1918

2019
extern EFI_SYSTEM_TABLE* GlobalSystemTable;
2120
extern EFI_HANDLE GlobalImageHandle;
22-
extern UCHAR BitmapFont8x16[256 * 16];
2321

2422
UCHAR MachDefaultTextColor = COLOR_GRAY;
2523
REACTOS_INTERNAL_BGCONTEXT framebufferData;
@@ -115,14 +113,14 @@ UefiVideoClearScreen(UCHAR Attr)
115113
VOID
116114
UefiVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
117115
{
118-
PUCHAR FontPtr;
116+
const UCHAR* FontPtr;
119117
PULONG Pixel;
120118
UCHAR Mask;
121119
unsigned Line;
122120
unsigned Col;
123121
ULONG Delta;
124122
Delta = (framebufferData.PixelsPerScanLine * 4 + 3) & ~ 0x3;
125-
FontPtr = BitmapFont8x16 + Char * 16;
123+
FontPtr = BitmapFont8x16 + Char * CHAR_HEIGHT;
126124
Pixel = (PULONG) ((char *) framebufferData.BaseAddress +
127125
(Y * CHAR_HEIGHT + TOP_BOTTOM_LINES) * Delta + X * CHAR_WIDTH * 4);
128126

boot/freeldr/freeldr/arch/vgafont.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@
22
* PROJECT: FreeLoader
33
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
44
* PURPOSE: VGA font 8x16
5-
* COPYRIGHT: Copyright 2004 Gé van Geldorp ([email protected])
5+
* COPYRIGHT: Copyright 2004 Gé van Geldorp <[email protected]>
66
*/
77

88
/* Note: Converted from the XFree vga.bdf font */
99

1010
#include <freeldr.h>
11+
#include "vgafont.h"
1112

12-
UCHAR BitmapFont8x16[256 * 16] =
13+
const UCHAR BitmapFont8x16[256 * CHAR_HEIGHT] =
1314
{
1415
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0x00 */
1516
0x00,0x00,0x7e,0x81,0xa5,0x81,0x81,0xa5,0x99,0x81,0x81,0x7e,0x00,0x00,0x00,0x00, /* 0x01 */
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* PROJECT: FreeLoader
3+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4+
* PURPOSE: VGA font 8x16
5+
* COPYRIGHT: Copyright 2004 Gé van Geldorp <[email protected]>
6+
*/
7+
8+
#pragma once
9+
10+
#define CHAR_WIDTH 8
11+
#define CHAR_HEIGHT 16
12+
13+
extern const UCHAR BitmapFont8x16[256 * CHAR_HEIGHT];
14+
15+
/* EOF */

boot/freeldr/freeldr/include/arch/i386/machxbox.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
#include <drivers/xbox/xgpu.h>
2626

27-
extern UCHAR BitmapFont8x16[256 * 16];
28-
2927
VOID XboxConsPutChar(int Ch);
3028
BOOLEAN XboxConsKbHit(VOID);
3129
int XboxConsGetCh(VOID);

0 commit comments

Comments
 (0)