diff --git a/src/hulk/console.d b/src/hulk/console.d index dc48e9d..e22e117 100644 --- a/src/hulk/console.d +++ b/src/hulk/console.d @@ -5,6 +5,9 @@ module hulk.console; import hulk.fb; import hulk.kfont; +import hulk.ver; +import hulk.rtc; +import hulk.writef; /** * Represent the HULK console. @@ -13,6 +16,8 @@ import hulk.kfont; */ struct Console { + private enum BORDER_COLOR = 0xFF8000u; + /** Console width in text columns. */ private static __gshared size_t m_width; @@ -30,8 +35,9 @@ struct Console */ public static void initialize() { + size_t fb_console_height = Fb.height - Kfont.line_height - 1; 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(); m_x = 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 y Y position. * @param ch Character to render. */ 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]; - 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) { - 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); } } diff --git a/src/hulk/hulk.d b/src/hulk/hulk.d index f221a8c..e7ba02f 100644 --- a/src/hulk/hulk.d +++ b/src/hulk/hulk.d @@ -66,6 +66,7 @@ void hulk_start() hulk_header.bootinfo.fb.height, hulk_header.bootinfo.fb.stride); Console.initialize(); + Rtc.initialize(); Console.clear(); Klog.initialize(); @@ -75,7 +76,11 @@ void hulk_start() Pic.initialize(); Acpi.initialize(hulk_header.bootinfo.acpi_xsdt_phys); 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(); sti(); diff --git a/src/hulk/rtc.d b/src/hulk/rtc.d index 8488b51..4719395 100644 --- a/src/hulk/rtc.d +++ b/src/hulk/rtc.d @@ -5,6 +5,7 @@ module hulk.rtc; import hulk.cpu; import hulk.klog; +import hulk.console; struct Rtc { @@ -51,11 +52,6 @@ struct Rtc rtc_24hour_mode = (sr_b & SR_B_24HOUR) != 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. */ eoi(); } @@ -86,11 +82,12 @@ struct Rtc if ((count % 1024) == 0u) { seconds++; + Console.update_header(); } eoi(); } - private static time read_rtc_time() + public static time read_rtc_time() { time[2] times; size_t reads;