From 789541a9b34b74f82af02fc4e7f4d7a0bc31e4c2 Mon Sep 17 00:00:00 2001 From: Joursoir Date: Mon, 11 Apr 2022 21:43:40 +0300 Subject: main: add the string drawing routine --- UefiMonitorTest/UefiMonitorTest.c | 90 +++++++++++++++++++++++++++++++++++++ UefiMonitorTest/UefiMonitorTest.inf | 1 + 2 files changed, 91 insertions(+) diff --git a/UefiMonitorTest/UefiMonitorTest.c b/UefiMonitorTest/UefiMonitorTest.c index 1b6e026..5bd56cd 100644 --- a/UefiMonitorTest/UefiMonitorTest.c +++ b/UefiMonitorTest/UefiMonitorTest.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -13,6 +14,8 @@ #include "UefiMonitorTest.h" #include "fonts/System-8x16.h" +#define UMT_MAXPRINT_BUFFER_SIZE 6400 // TODO: Use Pcd + #define SWAP(A, B, C) \ C = A; \ A = B; \ @@ -335,6 +338,93 @@ DrawChar ( } } +/** + Draws output based on a null-terminated Unicode format string + and a arguments list to the screen + + @retval The number of Unicode characters drawn +**/ +STATIC +UINTN +EFIAPI +DrawStringVF ( + IN GRAPHICS_CONTEXT *Graphics, + IN UINTN X, + IN UINTN Y, + IN GRAPHICS_PIXEL_COLOR *Color, + IN CONST CHAR16 *FormatString, + IN VA_LIST Marker + ) +{ + UINTN WalkerSize; + CHAR16 *FormatWalker; + UINTN Length; + UINTN Index; + UINTN OldX; + UINT32 Ucolor; + UINT32 Icolor; + + ASSERT(FormatString != NULL); + + WalkerSize = (UMT_MAXPRINT_BUFFER_SIZE + 1) * sizeof(CHAR16); + FormatWalker = AllocateZeroPool(WalkerSize); + if (FormatWalker == NULL) + return 0; + + Length = UnicodeVSPrint(FormatWalker, WalkerSize, FormatString, Marker); + Index = 0; + OldX = X; + Ucolor = *(UINT32 *)Color; + Icolor = GET_ICOLOR (Graphics, Ucolor); + + while (FormatWalker[Index] != '\0' && Index < Length) { + switch (FormatWalker[Index]) { + case L'\n': + X = OldX; + Y += SYSTEM8X16_FONT_HEIGHT; + break; + case L'\t': + X += SYSTEM8X16_FONT_WIDTH * 4; + break; + default: + DrawChar (Graphics, X, Y, Icolor, FormatWalker[Index]); + X += SYSTEM8X16_FONT_WIDTH; + if (X > Graphics->Width) + break; + } + Index++; + } + + FreePool(FormatWalker); + return Index; +} + +/** + Draws a null-terminated formatted Unicode string to the screen + + @retval The number of Unicode characters drawn +**/ +STATIC +UINTN +EFIAPI +DrawStringF ( + IN GRAPHICS_CONTEXT *Graphics, + IN UINTN X, + IN UINTN Y, + IN GRAPHICS_PIXEL_COLOR *Color, + IN CONST CHAR16 *FormatString, + ... + ) +{ + VA_LIST Marker; + UINTN NumberOfPrinted; + + VA_START (Marker, FormatString); + NumberOfPrinted = DrawStringVF(Graphics, X, Y, Color, FormatString, Marker); + VA_END (Marker); + return NumberOfPrinted; +} + STATIC EFI_STATUS Run ( diff --git a/UefiMonitorTest/UefiMonitorTest.inf b/UefiMonitorTest/UefiMonitorTest.inf index 64a3b08..36f7971 100644 --- a/UefiMonitorTest/UefiMonitorTest.inf +++ b/UefiMonitorTest/UefiMonitorTest.inf @@ -18,6 +18,7 @@ DebugLib MemoryAllocationLib PcdLib + PrintLib UefiApplicationEntryPoint UefiBootServicesTableLib UefiLib -- cgit v1.2.3-18-g5258