aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoursoir <chat@joursoir.net>2022-04-11 21:43:40 +0300
committerJoursoir <chat@joursoir.net>2022-04-11 21:43:40 +0300
commit789541a9b34b74f82af02fc4e7f4d7a0bc31e4c2 (patch)
treecd805d1af8bcb73198c40973a73f6737d0b51707
parent0c2bba19840f78fbea8da299ff30fa4f5d09e125 (diff)
downloadumt-789541a9b34b74f82af02fc4e7f4d7a0bc31e4c2.tar.gz
umt-789541a9b34b74f82af02fc4e7f4d7a0bc31e4c2.tar.bz2
umt-789541a9b34b74f82af02fc4e7f4d7a0bc31e4c2.zip
main: add the string drawing routine
-rw-r--r--UefiMonitorTest/UefiMonitorTest.c90
-rw-r--r--UefiMonitorTest/UefiMonitorTest.inf1
2 files changed, 91 insertions, 0 deletions
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 <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/BaseMemoryLib.h>
+#include <Library/PrintLib.h>
#include <Library/UefiApplicationEntryPoint.h>
#include <Library/UefiLib.h>
#include <Library/UefiBootServicesTableLib.h>
@@ -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