From 7632445d4350022fb12d45e04d7d315d6a7f8634 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Sat, 21 Oct 2023 22:13:20 -0400 Subject: [PATCH] Add console escape sequences to draw headings --- src/hulk/acpi.d | 2 ++ src/hulk/console.d | 63 ++++++++++++++++++++++++++++++++++++++++++++++ src/hulk/hulk.d | 2 +- src/hulk/pci.d | 3 +-- src/hulk/rtc.d | 2 ++ 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/hulk/acpi.d b/src/hulk/acpi.d index 8bcd162..05051ad 100644 --- a/src/hulk/acpi.d +++ b/src/hulk/acpi.d @@ -106,6 +106,8 @@ struct Acpi public static void initialize(ulong acpi_xsdt_phys) { + Klog.writefln("\a3Initialize ACPI"); + /* Map the XSDT header. */ map_table(acpi_xsdt_phys, PAGE_SIZE); const(XSDT) * xsdt = cast(const(XSDT) *)acpi_xsdt_phys; diff --git a/src/hulk/console.d b/src/hulk/console.d index 4112777..7824315 100644 --- a/src/hulk/console.d +++ b/src/hulk/console.d @@ -19,6 +19,9 @@ struct Console /** Border color. */ private enum BORDER_COLOR = 0xFF8000u; + /** Heading color. */ + private enum HEADING_COLOR = 0x0066FFu; + /** Console page width in text columns. */ private static __gshared size_t m_width; @@ -37,6 +40,12 @@ struct Console /** Number of delayed newline characters. */ private static __gshared size_t m_newlines; + /** Active console escape code. */ + private static __gshared char m_escape_code; + + /** Flag to indicate the previous character was an escape character. */ + private static __gshared bool m_escape; + /** * Initialize the console. */ @@ -68,6 +77,8 @@ struct Console { if (ch == '\n') { + render_heading_end(); + m_escape_code = 0u; m_newlines++; } else @@ -76,6 +87,46 @@ struct Console } } + private static void render_heading_start() + { + if ('0' <= m_escape_code && m_escape_code <= '9' && m_x < (m_width - 1)) + { + size_t heading_level = m_escape_code - ('0' - 1); + size_t nx = m_x + heading_level; + if (nx >= m_width) + { + nx = m_width - 1; + } + size_t hx = fb_x(m_page, m_x); + size_t hy = fb_y(m_y) + Kfont.line_height / 2 - 1; + size_t hwidth = (nx - m_x - 1) * Kfont.advance + Kfont.advance / 2 - 1; + Fb.rect(hx, hy, hwidth, 2, HEADING_COLOR); + Fb.rect(hx + hwidth, fb_y(m_y) + Kfont.line_height / 8, + 2, Kfont.line_height * 3 / 4, HEADING_COLOR); + m_x = nx; + } + } + + private static void render_heading_end() + { + if ('0' <= m_escape_code && m_escape_code <= '9' && m_x < (m_width - 1)) + { + size_t heading_level = m_escape_code - ('0' - 1); + size_t nx = m_x + heading_level; + if (nx >= m_width) + { + nx = m_width - 1; + } + size_t hwidth = (nx - m_x - 1) * Kfont.advance + Kfont.advance / 2 - 1; + size_t hx = fb_x(m_page, nx) - hwidth; + size_t hy = fb_y(m_y) + Kfont.line_height / 2 - 1; + Fb.rect(hx, hy, hwidth, 2, HEADING_COLOR); + Fb.rect(hx - 2, fb_y(m_y) + Kfont.line_height / 8, + 2, Kfont.line_height * 3 / 4, HEADING_COLOR); + m_x = nx; + } + } + /** * Write a character to the console (no newline buffering). * @@ -92,6 +143,18 @@ struct Console dowrite('\n'); } } + if (m_escape) + { + m_escape_code = ch; + render_heading_start(); + m_escape = false; + return; + } + if (ch == '\a') + { + m_escape = true; + return; + } if (ch == '\n') { m_x = 0u; diff --git a/src/hulk/hulk.d b/src/hulk/hulk.d index 4cc4157..c198c55 100644 --- a/src/hulk/hulk.d +++ b/src/hulk/hulk.d @@ -69,7 +69,7 @@ void hulk_start() Console.clear(); Klog.initialize(); - Klog.writefln("Welcome to HULK, the HOS UltraLight Kernel!"); + Klog.writefln("\a5Welcome to HULK, the HOS UltraLight Kernel!"); Hurl.initialize(&hulk_header); Pic.initialize(); diff --git a/src/hulk/pci.d b/src/hulk/pci.d index f2e93a0..255220c 100644 --- a/src/hulk/pci.d +++ b/src/hulk/pci.d @@ -347,7 +347,7 @@ struct Pci public static void initialize() { - Klog.writefln("Scanning PCI devices..."); + Klog.writefln("\a3Initializing PCI Bus"); size_t n_sgma_descs = Acpi.mcfg.n_sgma_descs; for (size_t i = 0u; i < n_sgma_descs; i++) { @@ -367,6 +367,5 @@ struct Pci } } } - Klog.writefln("PCI scan complete."); } } diff --git a/src/hulk/rtc.d b/src/hulk/rtc.d index 4719395..0be2d13 100644 --- a/src/hulk/rtc.d +++ b/src/hulk/rtc.d @@ -44,6 +44,8 @@ struct Rtc public static void initialize() { + Klog.writefln("\a3Initializing RTC"); + /* Enable IRQ 8 to receive RTC interrupts. */ ubyte sr_b = read_register(REG_SR_B, true); write_register(REG_SR_B, sr_b | SR_B_ENABLE_IRQ, true);