ReactOS 0.4.16-dev-329-g9223134
uefivid.c
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader UEFI Support
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Video output
5 * COPYRIGHT: Copyright 2022 Justin Miller <justinmiller100@gmail.com>
6 */
7
8#include <uefildr.h>
9
10#include <debug.h>
12
13#define CHAR_WIDTH 8
14#define CHAR_HEIGHT 16
15#define TOP_BOTTOM_LINES 0
16#define LOWEST_SUPPORTED_RES 1
17
18/* GLOBALS ********************************************************************/
19
22extern UCHAR BitmapFont8x16[256 * 16];
23
27
28/* FUNCTIONS ******************************************************************/
29
32{
35
38 if (Status != EFI_SUCCESS)
39 {
40 TRACE("Failed to find GOP with status %d\n", Status);
41 return Status;
42 }
43
44 /* We don't need high resolutions for freeldr */
46
53
54 return Status;
55}
56
57VOID
59{
60 TRACE("Framebuffer BaseAddress : %X\n", framebufferData.BaseAddress);
61 TRACE("Framebuffer BufferSize : %X\n", framebufferData.BufferSize);
62 TRACE("Framebuffer ScreenWidth : %d\n", framebufferData.ScreenWidth);
63 TRACE("Framebuffer ScreenHeight : %d\n", framebufferData.ScreenHeight);
64 TRACE("Framebuffer PixelsPerScanLine : %d\n", framebufferData.PixelsPerScanLine);
65 TRACE("Framebuffer PixelFormat : %d\n", framebufferData.PixelFormat);
66}
67
68static ULONG
70{
72 Intensity = (0 == (Attr & 0x08) ? 127 : 255);
73
74 return 0xff000000 |
75 (0 == (Attr & 0x04) ? 0 : (Intensity << 16)) |
76 (0 == (Attr & 0x02) ? 0 : (Intensity << 8)) |
77 (0 == (Attr & 0x01) ? 0 : Intensity);
78}
79
80static VOID
81UefiVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
82{
83 *FgColor = UefiVideoAttrToSingleColor(Attr & 0xf);
84 *BgColor = UefiVideoAttrToSingleColor((Attr >> 4) & 0xf);
85}
86
87
88static VOID
90{
92 ULONG Line, Col;
93 PULONG p;
94
95 Delta = (framebufferData.PixelsPerScanLine * 4 + 3) & ~ 0x3;
96 for (Line = 0; Line < framebufferData.ScreenHeight - (FullScreen ? 0 : 2 * TOP_BOTTOM_LINES); Line++)
97 {
98 p = (PULONG) ((char *) framebufferData.BaseAddress + (Line + (FullScreen ? 0 : TOP_BOTTOM_LINES)) * Delta);
99 for (Col = 0; Col < framebufferData.ScreenWidth; Col++)
100 {
101 *p++ = Color;
102 }
103 }
104}
105
106VOID
108{
109 ULONG FgColor, BgColor;
110
111 UefiVideoAttrToColors(Attr, &FgColor, &BgColor);
113}
114
115VOID
116UefiVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
117{
118 PUCHAR FontPtr;
119 PULONG Pixel;
120 UCHAR Mask;
121 unsigned Line;
122 unsigned Col;
123 ULONG Delta;
124 Delta = (framebufferData.PixelsPerScanLine * 4 + 3) & ~ 0x3;
125 FontPtr = BitmapFont8x16 + Char * 16;
126 Pixel = (PULONG) ((char *) framebufferData.BaseAddress +
128
129 for (Line = 0; Line < CHAR_HEIGHT; Line++)
130 {
131 Mask = 0x80;
132 for (Col = 0; Col < CHAR_WIDTH; Col++)
133 {
134 Pixel[Col] = (0 != (FontPtr[Line] & Mask) ? FgColor : BgColor);
135 Mask = Mask >> 1;
136 }
137 Pixel = (PULONG) ((char *) Pixel + Delta);
138 }
139}
140
141VOID
142UefiVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
143{
144 ULONG FgColor = 0;
145 ULONG BgColor = 0;
146 if (Ch != 0)
147 {
148 UefiVideoAttrToColors(Attr, &FgColor, &BgColor);
149 UefiVideoOutputChar(Ch, X, Y, FgColor, BgColor);
150 }
151}
152
153VOID
155{
158 *Depth = 0;
159}
160
163{
164 /* We only have one mode, semi-text */
165 return VideoTextMode;
166}
167
168ULONG
170{
172}
173
174VOID
176{
177 PUCHAR OffScreenBuffer = (PUCHAR)Buffer;
178
179 ULONG Col, Line;
181 {
182 for (Col = 0; Col < framebufferData.ScreenWidth / CHAR_WIDTH; Col++)
183 {
184 UefiVideoPutChar(OffScreenBuffer[0], OffScreenBuffer[1], Col, Line);
185 OffScreenBuffer += 2;
186 }
187 }
188}
189
190VOID
192{
193 ULONG BgColor, Dummy;
194 ULONG Delta;
195 Delta = (framebufferData.PixelsPerScanLine * 4 + 3) & ~ 0x3;
200
202
203 while (PixelCount--)
204 *Dst++ = *Src++;
205
206 for (PixelCount = 0; PixelCount < framebufferData.ScreenWidth * CHAR_HEIGHT; PixelCount++)
207 *Dst++ = BgColor;
208}
209
210VOID
212{
213 /* We don't have a cursor yet */
214}
215
216VOID
218{
219 /* We don't have a cursor yet */
220}
221
224{
225 return 0;
226}
227
228VOID
231{
232 /* Not supported */
233}
234
235VOID
238{
239 /* Not supported */
240}
#define WARNING
Definition: BusLogic958.h:56
#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
unsigned char BOOLEAN
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:31
#define EFI_SUCCESS
Definition: UefiBaseType.h:120
@ Green
Definition: bl.h:199
@ Red
Definition: bl.h:201
@ Blue
Definition: bl.h:198
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
@ VideoTextMode
Definition: machine.h:35
enum tagVIDEODISPLAYMODE VIDEODISPLAYMODE
#define COLOR_GRAY
Definition: ui.h:329
#define ATTR(cFore, cBack)
Definition: ui.h:317
#define COLOR_WHITE
Definition: ui.h:338
#define COLOR_BLACK
Definition: ui.h:322
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define Y(I)
#define ULONG_PTR
Definition: config.h:101
unsigned int Mask
Definition: fpcontrol.c:82
Status
Definition: gdiplustypes.h:25
GLfloat GLfloat p
Definition: glext.h:8902
#define Dst
Definition: mesh.h:153
static WORD Intensity(RGBQUAD clr)
Definition: msrle32.c:44
static VIDEODISPLAYMODE DisplayMode
Definition: pcvideo.c:117
#define Ch(x, y, z)
Definition: sha2.c:141
#define TRACE(s)
Definition: solgame.cpp:4
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:1873
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
EFI_PHYSICAL_ADDRESS FrameBufferBase
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * Info
EFI_BOOT_SERVICES * BootServices
Definition: UefiSpec.h:1959
Definition: ncftp.h:79
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
uint32_t * PULONG
Definition: typedefs.h:59
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
VOID UefiVideoGetPaletteColor(UCHAR Color, UCHAR *Red, UCHAR *Green, UCHAR *Blue)
Definition: uefivid.c:236
EFI_GUID EfiGraphicsOutputProtocol
Definition: uefivid.c:26
VOID UefiVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue)
Definition: uefivid.c:229
VOID UefiVideoClearScreen(UCHAR Attr)
Definition: uefivid.c:107
#define TOP_BOTTOM_LINES
Definition: uefivid.c:15
VOID UefiVideoHideShowTextCursor(BOOLEAN Show)
Definition: uefivid.c:217
ULONG UefiVideoGetBufferSize(VOID)
Definition: uefivid.c:169
UCHAR BitmapFont8x16[256 *16]
Definition: vgafont.c:12
EFI_STATUS UefiInitializeVideo(VOID)
Definition: uefivid.c:31
#define CHAR_WIDTH
Definition: uefivid.c:13
VOID UefiVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth)
Definition: uefivid.c:154
VOID UefiVideoSetTextCursorPosition(UCHAR X, UCHAR Y)
Definition: uefivid.c:211
EFI_SYSTEM_TABLE * GlobalSystemTable
Definition: uefildr.c:16
#define LOWEST_SUPPORTED_RES
Definition: uefivid.c:16
REACTOS_INTERNAL_BGCONTEXT framebufferData
Definition: uefivid.c:25
VOID UefiVideoScrollUp(VOID)
Definition: uefivid.c:191
static ULONG UefiVideoAttrToSingleColor(UCHAR Attr)
Definition: uefivid.c:69
VOID UefiVideoOutputChar(UCHAR Char, unsigned X, unsigned Y, ULONG FgColor, ULONG BgColor)
Definition: uefivid.c:116
VOID UefiVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
Definition: uefivid.c:142
VOID UefiVideoCopyOffScreenBufferToVRAM(PVOID Buffer)
Definition: uefivid.c:175
UCHAR MachDefaultTextColor
Definition: uefivid.c:24
VIDEODISPLAYMODE UefiVideoSetDisplayMode(char *DisplayMode, BOOLEAN Init)
Definition: uefivid.c:162
EFI_HANDLE GlobalImageHandle
Definition: uefildr.c:15
static VOID UefiVideoClearScreenColor(ULONG Color, BOOLEAN FullScreen)
Definition: uefivid.c:89
VOID UefiPrintFramebufferData(VOID)
Definition: uefivid.c:58
BOOLEAN UefiVideoIsPaletteFixed(VOID)
Definition: uefivid.c:223
#define CHAR_HEIGHT
Definition: uefivid.c:14
static VOID UefiVideoAttrToColors(UCHAR Attr, ULONG *FgColor, ULONG *BgColor)
Definition: uefivid.c:81
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
static ULONG Delta
Definition: xboxvideo.c:33
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:819
unsigned char UCHAR
Definition: xmlstorage.h:181