Add console escape sequences to draw headings

This commit is contained in:
Josh Holtrop 2023-10-21 22:13:20 -04:00
parent 601ea50e4b
commit 7632445d43
5 changed files with 69 additions and 3 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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();

View File

@ -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.");
}
}

View File

@ -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);