From 7b653878ee84add4172c20f13a436582c744a603 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Sat, 24 Aug 2024 14:49:23 +0200 Subject: [API] Refactors and improvements. Signed-off-by: Amlal El Mahrouss --- dev/ZBA/Sources/HEL/AMD64/BootMain.cxx | 4 ++-- dev/ZBA/Sources/Thread.cxx | 4 ++-- dev/ZKA/Modules/CoreCG/Accessibility.hxx | 14 +++++--------- dev/ZKA/Modules/CoreCG/Lerp.hxx | 22 ---------------------- dev/ZKA/Modules/CoreCG/Math.hxx | 22 ++++++++++++++++++++++ dev/ZKA/Modules/CoreCG/TextRenderer.hxx | 25 +++++++++---------------- dev/ZKA/Modules/CoreCG/WindowRenderer.hxx | 18 ++++++++++-------- dev/ZKA/Modules/Flash/Flash.hxx | 2 ++ dev/ZKA/Sources/KernelCheck.cxx | 26 +++++++++++++------------- 9 files changed, 65 insertions(+), 72 deletions(-) delete mode 100644 dev/ZKA/Modules/CoreCG/Lerp.hxx create mode 100644 dev/ZKA/Modules/CoreCG/Math.hxx (limited to 'dev') diff --git a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx index c98f700c..9cdaf603 100644 --- a/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx +++ b/dev/ZBA/Sources/HEL/AMD64/BootMain.cxx @@ -141,8 +141,8 @@ EFI_EXTERN_C EFI_API Int Main(EfiHandlePtr ImageHandle, CGDrawInRegion(CGColor(0xff, 0x3a, 0x3a), handoverHdrPtr->f_GOP.f_Height, handoverHdrPtr->f_GOP.f_Width, 0, 0); CGFini(); - cg_write_text("NEWOSLDR (C) ZKA TECHNOLOGIES.", 10, 10, RGB(0xFF, 0xFF, 0xFF)); - cg_write_text(BVersionString::The(), 20, 10, RGB(0xFF, 0xFF, 0xFF)); + CGDrawString("NEWOSLDR (C) ZKA TECHNOLOGIES.", 10, 10, RGB(0xFF, 0xFF, 0xFF)); + CGDrawString(BVersionString::The(), 20, 10, RGB(0xFF, 0xFF, 0xFF)); // Fill handover header now. diff --git a/dev/ZBA/Sources/Thread.cxx b/dev/ZBA/Sources/Thread.cxx index aba6b03b..6290178f 100644 --- a/dev/ZBA/Sources/Thread.cxx +++ b/dev/ZBA/Sources/Thread.cxx @@ -110,7 +110,7 @@ namespace Boot structHandover->HandoverType != HEL::kTypeKernel) { writer.Write("newosldr: Entrypoint of SYS: ").Write((UIntPtr)fStartAddress).Write("\r"); - cg_write_text("NEWOSLDR: NOT AN HANDOVER IMAGE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); + CGDrawString("NEWOSLDR: NOT AN HANDOVER IMAGE...", 40, 10, RGB(0xFF, 0xFF, 0xFF)); } } @@ -149,7 +149,7 @@ namespace Boot } HEL::HandoverProc err_fn = [](HEL::HandoverInformationHeader* rcx) -> void { - cg_write_text("NEWOSLDR: INVALID IMAGE! ABORTING...", 50, 10, RGB(0xFF, 0xFF, 0xFF)); + CGDrawString("NEWOSLDR: INVALID IMAGE! ABORTING...", 50, 10, RGB(0xFF, 0xFF, 0xFF)); EFI::Stop(); }; diff --git a/dev/ZKA/Modules/CoreCG/Accessibility.hxx b/dev/ZKA/Modules/CoreCG/Accessibility.hxx index 11fed494..b5ce03e9 100644 --- a/dev/ZKA/Modules/CoreCG/Accessibility.hxx +++ b/dev/ZKA/Modules/CoreCG/Accessibility.hxx @@ -10,29 +10,25 @@ #include #include #include -#include +#include #include namespace CG { using namespace Kernel; - inline Bool cKTSyncCall = false; - - inline float cDeviceWidthAlert = 150; - inline float cDeviceHeightAlert = 141; - - /// @brief common user interface class. + /// @brief common User interface class. class UIAccessibilty final { explicit UIAccessibilty() = default; + ~UIAccessibilty() = default; public: ZKA_COPY_DELETE(UIAccessibilty); - static UIAccessibilty& The() + STATIC UIAccessibilty& The() { - static UIAccessibilty the; + STATIC UIAccessibilty the; return the; } diff --git a/dev/ZKA/Modules/CoreCG/Lerp.hxx b/dev/ZKA/Modules/CoreCG/Lerp.hxx deleted file mode 100644 index ea2de1dd..00000000 --- a/dev/ZKA/Modules/CoreCG/Lerp.hxx +++ /dev/null @@ -1,22 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -/// @file Lerp.hxx -/// @brief Linear interpolation implementation. - -typedef float CGReal; - -/// @brief Linear interpolation equation solver. -/// @param from where? -/// @param to to? -/// @param at which state we're at **to**. -inline CGReal CGLerp(CGReal to, CGReal from, CGReal stat) -{ - CGReal difference = to - from; - return from + (difference * stat); -} diff --git a/dev/ZKA/Modules/CoreCG/Math.hxx b/dev/ZKA/Modules/CoreCG/Math.hxx new file mode 100644 index 00000000..bfa28a3d --- /dev/null +++ b/dev/ZKA/Modules/CoreCG/Math.hxx @@ -0,0 +1,22 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +/// @file Math.hxx +/// @brief Linear interpolation implementation. + +typedef float CGReal; + +/// @brief Linear interpolation equation solver. +/// @param from where? +/// @param to to? +/// @param at which state we're at **to**. +inline CGReal CGLerp(CGReal to, CGReal from, CGReal stat) +{ + CGReal difference = to - from; + return from + (difference * stat); +} diff --git a/dev/ZKA/Modules/CoreCG/TextRenderer.hxx b/dev/ZKA/Modules/CoreCG/TextRenderer.hxx index 086d0399..34caa420 100644 --- a/dev/ZKA/Modules/CoreCG/TextRenderer.hxx +++ b/dev/ZKA/Modules/CoreCG/TextRenderer.hxx @@ -145,19 +145,20 @@ inline const Kernel::UInt8 cFontBitmap[FONT_NOF_CHARS][FONT_SIZE_X] = { }; -inline Kernel::Void cg_render_text_font(const Kernel::UInt8* bitmap, Kernel::Int32& x_dst, Kernel::Int32& y_dst, Kernel::Int32& color) +inline Kernel::Void CGRenderStringFromBitMap(const Kernel::UInt8* bitmap, const Kernel::SizeT& x_sz, const Kernel::SizeT& y_sz, Kernel::Int32& x_dst, Kernel::Int32& y_dst, Kernel::Int32& color) { Kernel::Int32 x, y; Kernel::Int32 set; - x = 0; - y = 0; + x = 0; + y = 0; + set = 0; - for (; y < FONT_SIZE_Y; y++) + for (; y < y_sz; ++y) { - for (x = 0; x < FONT_SIZE_X; x++) + for (x = 0; x < x_sz; ++x) { - set = bitmap[x] & 1 << y; + set = bitmap[x] & (1 << y); if (set) CGDrawInRegion(color, 1, 1, ((x_dst) + x), ((y_dst) + y)); @@ -165,19 +166,11 @@ inline Kernel::Void cg_render_text_font(const Kernel::UInt8* bitmap, Kernel::Int } } -inline Kernel::Void cg_write_text(const Kernel::Char* text, Kernel::Int32 x_dst, Kernel::Int32 y_dst, Kernel::Int32 color) +inline Kernel::Void CGDrawString(const Kernel::Char* text, Kernel::Int32 x_dst, Kernel::Int32 y_dst, Kernel::Int32 color) { for (Kernel::SizeT i = 0; text[i] != 0; ++i) { - if (text[i] == '\r' || - text[i] == '\n') - { - y_dst += FONT_SIZE_Y; - - continue; - } - - cg_render_text_font(&cFontBitmap[text[i]][0], x_dst, y_dst, color); + CGRenderStringFromBitMap(&cFontBitmap[text[i]][0], FONT_SIZE_X, FONT_SIZE_Y, x_dst, y_dst, color); y_dst += FONT_SIZE_Y; } } diff --git a/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx b/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx index a1aadf8a..59ebd9f2 100644 --- a/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx +++ b/dev/ZKA/Modules/CoreCG/WindowRenderer.hxx @@ -20,12 +20,14 @@ namespace CG { using namespace Kernel; + struct UI_WINDOW_STRUCT; + enum { cWndFlagNoShow = 0x04, }; - struct CG_WINDOW + struct UI_WINDOW_STRUCT final { Int32 w_flags{0}; Char w_window_name[255]{0}; @@ -38,9 +40,9 @@ namespace CG Bool w_needs_repaint{false}; }; - typedef struct CG_WINDOW CG_WINDOW; + typedef struct UI_WINDOW_STRUCT UI_WINDOW_STRUCT; - inline struct CG_WINDOW* CGCreateWindow(Int32 flags, const Char* window_name, const Char* class_name, Int32 x, Int32 y, Int32 width, Int32 height) + inline struct UI_WINDOW_STRUCT* CGCreateWindow(Int32 flags, const Char* window_name, const Char* class_name, Int32 x, Int32 y, Int32 width, Int32 height) { const auto cMaxLimit = 214; @@ -51,7 +53,7 @@ namespace CG return nullptr; } - CG_WINDOW* wnd = new CG_WINDOW(); + UI_WINDOW_STRUCT* wnd = new UI_WINDOW_STRUCT(); if (!wnd) { @@ -75,7 +77,7 @@ namespace CG return wnd; } - inline bool CGDestroyWindow(struct CG_WINDOW* wnd) + inline bool CGDestroyWindow(struct UI_WINDOW_STRUCT* wnd) { if (wnd) { @@ -93,7 +95,7 @@ namespace CG return false; } - inline SizeT CGDrawWindowList(CG_WINDOW** wnd, SizeT wnd_cnt) + inline SizeT CGDrawWindowList(UI_WINDOW_STRUCT** wnd, SizeT wnd_cnt) { if (wnd_cnt == 0 || !wnd) @@ -138,11 +140,11 @@ namespace CG CGInit(); - CGDrawBitMapInRegionA(wnd[index]->display_ptr, wnd[index]->w_h, wnd[index]->w_w, wnd[index]->w_y, wnd[index]->w_x); + CGDrawBitMapInRegion(wnd[index]->display_ptr, wnd[index]->w_h, wnd[index]->w_w, wnd[index]->w_y, wnd[index]->w_x); CGDrawInRegion(CGColor(0xFF, 0xFF, 0xFF), wnd[index]->w_w, FLATCONTROLS_HEIGHT, wnd[index]->w_y, wnd[index]->w_x); CGDrawBitMapInRegion(FlatControls, FLATCONTROLS_HEIGHT, FLATCONTROLS_WIDTH, wnd[index]->w_y, wnd[index]->w_x+wnd[index]->w_w-FLATCONTROLS_WIDTH); - cg_write_text(wnd[index]->w_window_name, wnd[index]->w_y + 8, wnd[index]->w_x + 8, CGColor(0x00, 0x00, 0x00)); + CGDrawString(wnd[index]->w_window_name, wnd[index]->w_y + 8, wnd[index]->w_x + 8, CGColor(0x00, 0x00, 0x00)); CGFini(); } diff --git a/dev/ZKA/Modules/Flash/Flash.hxx b/dev/ZKA/Modules/Flash/Flash.hxx index d8cfc28f..b5878d6d 100644 --- a/dev/ZKA/Modules/Flash/Flash.hxx +++ b/dev/ZKA/Modules/Flash/Flash.hxx @@ -8,6 +8,8 @@ #ifdef __FLASH_MEM__ +#include + /// @brief get sector count. /// @return drive sector count. Kernel::SizeT drv_std_get_sector_count(); diff --git a/dev/ZKA/Sources/KernelCheck.cxx b/dev/ZKA/Sources/KernelCheck.cxx index f046fe41..3d97ccfa 100644 --- a/dev/ZKA/Sources/KernelCheck.cxx +++ b/dev/ZKA/Sources/KernelCheck.cxx @@ -40,7 +40,7 @@ namespace Kernel auto start_y = 10; auto x = 10; - cg_write_text("newoskrnl.dll stopped working properly so we had to stop.", start_y, x, panicTxt); + CGDrawString("newoskrnl.dll stopped working properly so we had to stop.", start_y, x, panicTxt); CGFini(); @@ -70,50 +70,50 @@ namespace Kernel switch (id) { case RUNTIME_CHECK_PROCESS: { - cg_write_text("0x00000008 Process scheduler error (Catasrophic failure).", start_y, x, panicTxt); + CGDrawString("0x00000008 Process scheduler error (Catasrophic failure).", start_y, x, panicTxt); break; } case RUNTIME_CHECK_ACPI: { - cg_write_text("0x00000006 ACPI error.", start_y, x, panicTxt); + CGDrawString("0x00000006 ACPI error.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_FILESYSTEM: { - cg_write_text("0x0000000A Filesystem corruption error.", start_y, x, panicTxt); + CGDrawString("0x0000000A Filesystem corruption error.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_POINTER: { - cg_write_text("0x00000000 Kernel heap error.", start_y, x, panicTxt); + CGDrawString("0x00000000 Kernel heap error.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_BAD_BEHAVIOR: { - cg_write_text("0x00000009 Undefined Behavior error.", start_y, x, panicTxt); + CGDrawString("0x00000009 Undefined Behavior error.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_BOOTSTRAP: { - cg_write_text("0x0000000A End of code.", start_y, x, panicTxt); + CGDrawString("0x0000000A End of code.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_HANDSHAKE: { - cg_write_text("0x00000005 Handshake error.", start_y, x, panicTxt); + CGDrawString("0x00000005 Handshake error.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_IPC: { - cg_write_text("0x00000003 Kernel IPC error.", start_y, x, panicTxt); + CGDrawString("0x00000003 Kernel IPC error.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_INVALID_PRIVILEGE: { - cg_write_text("0x00000007 Kernel privilege violation.", start_y, x, panicTxt); + CGDrawString("0x00000007 Kernel privilege violation.", start_y, x, panicTxt); break; case RUNTIME_CHECK_UNEXCPECTED: { - cg_write_text("0x0000000B Catasrophic failure.", start_y, x, panicTxt); + CGDrawString("0x0000000B Catasrophic failure.", start_y, x, panicTxt); break; } case RUNTIME_CHECK_FAILED: { - cg_write_text("0x10000001 Assertion failed.", start_y, x, panicTxt); + CGDrawString("0x10000001 Assertion failed.", start_y, x, panicTxt); break; } default: { - cg_write_text("0xFFFFFFFF Unknown error.", start_y, x, panicTxt); + CGDrawString("0xFFFFFFFF Unknown error.", start_y, x, panicTxt); break; } } -- cgit v1.2.3