Add console header line

This commit is contained in:
Josh Holtrop 2023-10-21 17:08:45 -04:00
parent 4273c703e9
commit 8638840cd8
3 changed files with 64 additions and 11 deletions

View File

@ -5,6 +5,9 @@ module hulk.console;
import hulk.fb; import hulk.fb;
import hulk.kfont; import hulk.kfont;
import hulk.ver;
import hulk.rtc;
import hulk.writef;
/** /**
* Represent the HULK console. * Represent the HULK console.
@ -13,6 +16,8 @@ import hulk.kfont;
*/ */
struct Console struct Console
{ {
private enum BORDER_COLOR = 0xFF8000u;
/** Console width in text columns. */ /** Console width in text columns. */
private static __gshared size_t m_width; private static __gshared size_t m_width;
@ -30,8 +35,9 @@ struct Console
*/ */
public static void initialize() public static void initialize()
{ {
size_t fb_console_height = Fb.height - Kfont.line_height - 1;
m_width = Fb.width / Kfont.advance; m_width = Fb.width / Kfont.advance;
m_height = Fb.height / Kfont.line_height; m_height = fb_console_height / Kfont.line_height;
} }
/** /**
@ -42,6 +48,7 @@ struct Console
Fb.clear(); Fb.clear();
m_x = 0u; m_x = 0u;
m_y = 0u; m_y = 0u;
draw_header();
} }
/** /**
@ -77,16 +84,28 @@ struct Console
} }
/** /**
* Render a character. * Render a character using console characters.
* *
* @param x X position. * @param x X position.
* @param y Y position. * @param y Y position.
* @param ch Character to render. * @param ch Character to render.
*/ */
private static void render_char(size_t x, size_t y, char ch) private static void render_char(size_t x, size_t y, char ch)
{
render_char_fb(fb_x(x), fb_y(y), ch);
}
/**
* Render a character using framebuffer coordinates.
*
* @param x X position.
* @param y Y position.
* @param ch Character to render.
*/
private static void render_char_fb(size_t x, size_t y, char ch)
{ {
const(CharInfo) * ci = &Kfont.chars[ch]; const(CharInfo) * ci = &Kfont.chars[ch];
Fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top, ci.bitmap, ci.width, ci.height); Fb.blit_alpha_bitmap(x + ci.left, y + ci.top, ci.bitmap, ci.width, ci.height);
} }
/** /**
@ -102,6 +121,38 @@ struct Console
*/ */
private static size_t fb_y(size_t y) private static size_t fb_y(size_t y)
{ {
return y * Kfont.line_height; return (y + 1) * Kfont.line_height + 1;
}
/**
* Draw console header line.
*/
private static draw_header()
{
static __gshared string header_text = "Welcome to HOS v" ~ VERSION ~ "!";
Fb.rect(0u, Kfont.line_height, Fb.width, 1, BORDER_COLOR);
size_t x = 0;
foreach (c; header_text)
{
render_char_fb(fb_x(x), 0, c);
x++;
}
update_header();
}
/**
* Update console header.
*/
public static update_header()
{
__gshared uint x;
x = Fb.width - 8 * Kfont.advance;
Fb.rect(x - 1, 0, 1, Kfont.line_height, BORDER_COLOR);
Fb.rect(x, 0, Fb.width - x, Kfont.line_height, 0);
Rtc.time rtc_time = Rtc.read_rtc_time();
writef(function(ubyte ch) {
render_char_fb(x, 0, ch);
x += Kfont.advance;
}, "%02u:%02u:%02u", rtc_time.hour, rtc_time.minute, rtc_time.second);
} }
} }

View File

@ -66,6 +66,7 @@ void hulk_start()
hulk_header.bootinfo.fb.height, hulk_header.bootinfo.fb.height,
hulk_header.bootinfo.fb.stride); hulk_header.bootinfo.fb.stride);
Console.initialize(); Console.initialize();
Rtc.initialize();
Console.clear(); Console.clear();
Klog.initialize(); Klog.initialize();
@ -75,7 +76,11 @@ void hulk_start()
Pic.initialize(); Pic.initialize();
Acpi.initialize(hulk_header.bootinfo.acpi_xsdt_phys); Acpi.initialize(hulk_header.bootinfo.acpi_xsdt_phys);
Apic.initialize(); Apic.initialize();
Rtc.initialize(); /* Read the current system time. */
Rtc.time t = Rtc.read_rtc_time();
Klog.writefln("System time is 20%02u-%02u-%02u %02u:%02u:%02u",
t.year, t.month, t.day, t.hour, t.minute, t.second);
Pci.initialize(); Pci.initialize();
sti(); sti();

View File

@ -5,6 +5,7 @@ module hulk.rtc;
import hulk.cpu; import hulk.cpu;
import hulk.klog; import hulk.klog;
import hulk.console;
struct Rtc struct Rtc
{ {
@ -51,11 +52,6 @@ struct Rtc
rtc_24hour_mode = (sr_b & SR_B_24HOUR) != 0u; rtc_24hour_mode = (sr_b & SR_B_24HOUR) != 0u;
rtc_binary_mode = (sr_b & SR_B_BINARY) != 0u; rtc_binary_mode = (sr_b & SR_B_BINARY) != 0u;
/* Read the current system time. */
time t = read_rtc_time();
Klog.writefln("System time is 20%02u-%02u-%02u %02u:%02u:%02u",
t.year, t.month, t.day, t.hour, t.minute, t.second);
/* Send EOI to enable more RTC interrupts and re-enable NMIs. */ /* Send EOI to enable more RTC interrupts and re-enable NMIs. */
eoi(); eoi();
} }
@ -86,11 +82,12 @@ struct Rtc
if ((count % 1024) == 0u) if ((count % 1024) == 0u)
{ {
seconds++; seconds++;
Console.update_header();
} }
eoi(); eoi();
} }
private static time read_rtc_time() public static time read_rtc_time()
{ {
time[2] times; time[2] times;
size_t reads; size_t reads;