OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
FontTester.c
Go to the documentation of this file.
1
8#include <Uefi.h>
10#include <Library/OcMiscLib.h>
11#include <Library/UefiLib.h>
12#include <Library/UefiBootServicesTableLib.h>
13
14#define APP_TITLE L" <<<Font Tester>>> "
15
16#define NROWS (8)
17#define NCOLUMNS (16)
18#define GAP (8)
19
20STATIC
21VOID
23 UINTN Seconds
24 )
25{
26 UINTN Index;
27
28 //
29 // Note: Ensure that stall value is within UINT32 in nanoseconds (required on some broken firmware).
30 //
31 for (Index = 0; Index < Seconds; ++Index) {
32 gBS->Stall (SECONDS_TO_MICROSECONDS (1));
33 }
34}
35
36STATIC
37VOID
39 UINT8 PageNumber,
40 UINTN CursorColumn,
41 UINTN CursorRow
42 )
43{
44 CHAR16 Char;
45 CHAR16 String[2];
46 UINTN Row;
47 UINTN Column;
48
49 gST->ConOut->SetAttribute (gST->ConOut, EFI_BACKGROUND_CYAN | EFI_DARKGRAY);
50 gST->ConOut->SetCursorPosition (gST->ConOut, CursorColumn, CursorRow);
51 Print (L"Page %u:", PageNumber);
52 gST->ConOut->SetAttribute (gST->ConOut, EFI_BACKGROUND_BLACK | EFI_LIGHTGRAY);
53
54 String[1] = CHAR_NULL;
55 Char = PageNumber << 7;
56
57 for (Row = 0; Row < NROWS; Row++) {
58 for (Column = 0; Column < NCOLUMNS; Column++) {
59 String[0] = (Char < 32) ? L'_' : Char;
60
61 gST->ConOut->SetCursorPosition (gST->ConOut, CursorColumn + (Column * 2) + 1, CursorRow + Row + 1);
62 gST->ConOut->OutputString (gST->ConOut, String);
63
64 ++Char;
65 }
66 }
67}
68
69UINTN
71 UINTN Width
72 )
73{
74 EFI_STATUS Status;
75 UINTN Columns;
76 UINTN Rows;
77
78 Status = gST->ConOut->QueryMode (
79 gST->ConOut,
80 gST->ConOut->Mode->Mode,
81 &Columns,
82 &Rows
83 );
84
85 if (EFI_ERROR (Status) || (Columns < Width)) {
86 return 0;
87 }
88
89 //
90 // Note: Subtract then divide can be different by one, and is less well centred.
91 //
92 return (Columns / 2) - (Width / 2);
93}
94
95VOID
97 CHAR16 *String
98 )
99{
100 gST->ConOut->SetCursorPosition (
101 gST->ConOut,
102 CentrePos (StrLen (String)),
103 gST->ConOut->Mode->CursorRow
104 );
105
106 gST->ConOut->OutputString (
107 gST->ConOut,
108 String
109 );
110}
111
112EFI_STATUS
113EFIAPI
115 IN EFI_HANDLE ImageHandle,
116 IN EFI_SYSTEM_TABLE *SystemTable
117 )
118{
119 UINTN Column0;
120 UINTN Column1;
121 UINTN Row0;
122 UINTN Row1;
123 UINTN Row2;
124 INT32 OriginalAttribute;
125 BOOLEAN OriginalCursorVisible;
126
127 OriginalAttribute = gST->ConOut->Mode->Attribute;
128 OriginalCursorVisible = gST->ConOut->Mode->CursorVisible;
129
130 gST->ConOut->EnableCursor (gST->ConOut, FALSE);
131
132 gST->ConOut->SetAttribute (gST->ConOut, EFI_BACKGROUND_BLACK | EFI_LIGHTGRAY);
133 gST->ConOut->ClearScreen (gST->ConOut);
134
135 Print (L"\r\n");
136 gST->ConOut->SetAttribute (gST->ConOut, EFI_BACKGROUND_BROWN | EFI_CYAN);
138
139 Column0 = CentrePos (NCOLUMNS * 4 + GAP);
140 Column1 = Column0 + NCOLUMNS * 2 + GAP;
141 Row0 = gST->ConOut->Mode->CursorRow + 2;
142 Row1 = Row0 + 10;
143 Row2 = Row1 + 10;
144
145 PrintFontPage (0, Column0, Row0);
146 PrintFontPage (67, Column1, Row0);
147 PrintFontPage (74, Column0, Row1);
148 PrintFontPage (75, Column1, Row1);
149
150 //
151 // Give time for F10 screenshot.
152 //
153 PauseSeconds (2);
154
155 gST->ConOut->SetCursorPosition (gST->ConOut, 0, Row2);
156 gST->ConOut->SetAttribute (gST->ConOut, EFI_BACKGROUND_RED | EFI_WHITE);
157 Centre (L"Press any key...");
158 WaitForKeyPress (L"");
159 Centre (L"Done.");
160
161 gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
162 gST->ConOut->EnableCursor (gST->ConOut, OriginalCursorVisible);
163
164 return EFI_SUCCESS;
165}
#define GAP
Definition FontTester.c:18
EFI_STATUS EFIAPI UefiMain(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition FontTester.c:114
STATIC VOID PauseSeconds(UINTN Seconds)
Definition FontTester.c:22
#define NCOLUMNS
Definition FontTester.c:17
VOID Centre(CHAR16 *String)
Definition FontTester.c:96
#define APP_TITLE
Definition FontTester.c:14
UINTN CentrePos(UINTN Width)
Definition FontTester.c:70
#define NROWS
Definition FontTester.c:16
STATIC VOID PrintFontPage(UINT8 PageNumber, UINTN CursorColumn, UINTN CursorRow)
Definition FontTester.c:38
EFI_SYSTEM_TABLE * gST
EFI_BOOT_SERVICES * gBS
VOID WaitForKeyPress(IN CONST CHAR16 *Message)
Definition DebugHelp.c:35
#define SECONDS_TO_MICROSECONDS(x)
Definition OcMiscLib.h:30