Clean up console

This commit is contained in:
Josh Holtrop 2022-03-25 12:37:18 -04:00
parent 0568a813f2
commit cb31e36e90
2 changed files with 32 additions and 20 deletions

View File

@ -8,17 +8,30 @@ import hulk.kfont;
struct console struct console
{ {
/** Console width in text columns. */
private static __gshared size_t m_width; private static __gshared size_t m_width;
/** Console height in text rows. */
private static __gshared size_t m_height; private static __gshared size_t m_height;
/** Current console cursor X position. */
private static __gshared size_t m_x; private static __gshared size_t m_x;
/** Current console cursor Y position. */
private static __gshared size_t m_y; private static __gshared size_t m_y;
/**
* Initialize the console.
*/
public static void initialize() public static void initialize()
{ {
m_width = fb.width / kfont.advance; m_width = fb.width / kfont.advance;
m_height = fb.height / kfont.line_height; m_height = fb.height / kfont.line_height;
} }
/**
* Clear the console.
*/
public static void clear() public static void clear()
{ {
fb.clear(); fb.clear();
@ -26,6 +39,11 @@ struct console
m_y = 0u; m_y = 0u;
} }
/**
* Write a character to the console.
*
* @param ch Character to write.
*/
public static void write(char ch) public static void write(char ch)
{ {
if (ch == '\n') if (ch == '\n')
@ -53,17 +71,30 @@ struct console
} }
} }
/**
* Render a character.
*
* @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) private static void render_char(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.height, ci.bitmap, ci.width, ci.height); fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top - ci.height, ci.bitmap, ci.width, ci.height);
} }
/**
* Get the framebuffer X coordinate corresponding to the console X position.
*/
private static size_t fb_x(size_t x) private static size_t fb_x(size_t x)
{ {
return x * kfont.advance; return x * kfont.advance;
} }
/**
* Get the framebuffer Y coordinate corresponding to the console Y position.
*/
private static size_t fb_y(size_t y) private static size_t fb_y(size_t y)
{ {
return fb.height - ((y + 1u) * kfont.line_height); return fb.height - ((y + 1u) * kfont.line_height);

View File

@ -28,30 +28,11 @@ private __gshared Header hulk_header = {
extern(C) void hulk_start(ulong rdi, ulong rsi, ulong rdx, BootInfo * bootinfo) extern(C) void hulk_start(ulong rdi, ulong rsi, ulong rdx, BootInfo * bootinfo)
{ {
fb.initialize(bootinfo.fb.buffer, bootinfo.fb.width, bootinfo.fb.height, bootinfo.fb.stride); fb.initialize(bootinfo.fb.buffer, bootinfo.fb.width, bootinfo.fb.height, bootinfo.fb.stride);
fb.clear(0xFF8800u);
for (size_t y = 100u; y < 120u; y++)
{
memset32(&bootinfo.fb.buffer[y * bootinfo.fb.stride + 20u], 0x001199u, 20u);
}
string message = "Hello, world! 0123456789!@#$%^&*()_-=+[]{};:\"'<>,./";
int x = 100u;
foreach (ch; message)
{
const(CharInfo) * ci = &kfont.chars[ch];
fb.blend_alpha_bitmap(x + ci.left, 100 + ci.top - ci.height, ci.bitmap, ci.width, ci.height, 0x0088CCu);
x += kfont.advance;
}
console.initialize(); console.initialize();
console.clear(); console.clear();
klog.initialize(); klog.initialize();
for (size_t i = 1u; i != 0u; i++) klog.writefln("Welcome to HULK, the HOS UltraLight Kernel!");
{
klog.writef("Hello! i = %010u\n", i);
}
for (;;) for (;;)
{ {