summaryrefslogtreecommitdiffhomepage
path: root/dev/Boot/src/BootTextWriter.cc
diff options
context:
space:
mode:
authorAmlal <amlal.elmahrouss@icloud.com>2025-01-24 10:38:36 +0100
committerAmlal <amlal.elmahrouss@icloud.com>2025-01-24 10:38:36 +0100
commit7b4bd3577a31d0f0adc7371840642791ae1567f4 (patch)
tree1a8afc973aaa739d0d763315cad2fd376d1cea9c /dev/Boot/src/BootTextWriter.cc
ADD: Open version, with important changes kept out.
Signed-off-by: Amlal <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'dev/Boot/src/BootTextWriter.cc')
-rw-r--r--dev/Boot/src/BootTextWriter.cc169
1 files changed, 169 insertions, 0 deletions
diff --git a/dev/Boot/src/BootTextWriter.cc b/dev/Boot/src/BootTextWriter.cc
new file mode 100644
index 00000000..b972deb0
--- /dev/null
+++ b/dev/Boot/src/BootTextWriter.cc
@@ -0,0 +1,169 @@
+/* -------------------------------------------
+
+ Copyright (C) 2024, Amlal EL Mahrouss, all rights reserved.
+
+ File: BootTextWriter.cc
+ Purpose: BootZ string library
+
+ Revision History:
+
+
+
+------------------------------------------- */
+
+#include <FirmwareKit/EFI/API.h>
+#include <BootKit/Platform.h>
+#include <BootKit/Protocol.h>
+#include <BootKit/BootKit.h>
+
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+/// BUGS: 0 ///
+/////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+/**
+@brief puts wrapper over EFI ConOut.
+*/
+Boot::BTextWriter& Boot::BTextWriter::Write(const CharacterTypeUTF16* str)
+{
+#ifdef __DEBUG__
+ if (!str || *str == 0)
+ return *this;
+
+ CharacterTypeUTF16 strTmp[2];
+ strTmp[1] = 0;
+
+ for (size_t i = 0; str[i] != 0; i++)
+ {
+ if (str[i] == '\r')
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+
+ strTmp[0] = '\n';
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ else
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ }
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+/// @brief UTF-8 equivalent of Write (UTF-16).
+/// @param str the input string.
+Boot::BTextWriter& Boot::BTextWriter::Write(const Char* str)
+{
+#ifdef __DEBUG__
+ if (!str || *str == 0)
+ return *this;
+
+ CharacterTypeUTF16 strTmp[2];
+ strTmp[1] = 0;
+
+ for (size_t i = 0; str[i] != 0; i++)
+ {
+ if (str[i] == '\r')
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+
+ strTmp[0] = '\n';
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ else
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ }
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+Boot::BTextWriter& Boot::BTextWriter::Write(const UChar* str)
+{
+#ifdef __DEBUG__
+ if (!str || *str == 0)
+ return *this;
+
+ CharacterTypeUTF16 strTmp[2];
+ strTmp[1] = 0;
+
+ for (size_t i = 0; str[i] != 0; i++)
+ {
+ if (str[i] == '\r')
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+
+ strTmp[0] = '\n';
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ else
+ {
+ strTmp[0] = str[i];
+ ST->ConOut->OutputString(ST->ConOut, strTmp);
+ }
+ }
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+/**
+@brief putc wrapper over EFI ConOut.
+*/
+Boot::BTextWriter& Boot::BTextWriter::WriteCharacter(CharacterTypeUTF16 c)
+{
+#ifdef __DEBUG__
+ EfiCharType str[2];
+
+ str[0] = c;
+ str[1] = 0;
+ ST->ConOut->OutputString(ST->ConOut, str);
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+Boot::BTextWriter& Boot::BTextWriter::Write(const Long& x)
+{
+#ifdef __DEBUG__
+ this->_Write(x);
+ this->Write("h");
+#endif // ifdef __DEBUG__
+
+ return *this;
+}
+
+Boot::BTextWriter& Boot::BTextWriter::_Write(const Long& x)
+{
+#ifdef __DEBUG__
+ UInt64 y = (x > 0 ? x : -x) / 16;
+ UInt64 h = (x > 0 ? x : -x) % 16;
+
+ if (y)
+ this->_Write(y);
+
+ /* fail if the hex number is not base-16 */
+ if (h > 16)
+ {
+ this->WriteCharacter('?');
+ return *this;
+ }
+
+ if (y < 0)
+ y = -y;
+
+ const char cNumbers[] = "0123456789ABCDEF";
+
+ this->WriteCharacter(cNumbers[h]);
+#endif // ifdef __DEBUG__
+
+ return *this;
+}