Add console, klog, and writef modules.
They are not complete, but adding to checkpoint progress.
This commit is contained in:
1 parent
e214a9c3de
commit
06242a0c9f
5 files changed
+373
No files matched your search
@@ -0,0 +1,72 @@
|
||||
/**
|
||||
* HULK Console functionality.
|
||||
*/
|
||||
module hulk.console;
|
||||
|
||||
import hulk.framebuffer;
|
||||
import hulk.kfont;
|
||||
|
||||
struct Console
|
||||
{
|
||||
Framebuffer * m_fb;
|
||||
size_t m_width;
|
||||
size_t m_height;
|
||||
size_t m_x;
|
||||
size_t m_y;
|
||||
|
||||
public void initialize(Framebuffer * fb)
|
||||
{
|
||||
m_fb = fb;
|
||||
m_width = fb.width / kfont.advance;
|
||||
m_height = fb.height / kfont.line_height;
|
||||
}
|
||||
|
||||
public void clear()
|
||||
{
|
||||
m_fb.clear();
|
||||
m_x = 0u;
|
||||
m_y = 0u;
|
||||
}
|
||||
|
||||
public void write(char ch)
|
||||
{
|
||||
if (ch == '\n')
|
||||
{
|
||||
m_x = 0u;
|
||||
m_y++;
|
||||
}
|
||||
else
|
||||
{
|
||||
render_char(m_x, m_y, ch);
|
||||
m_x++;
|
||||
if (m_x == m_width)
|
||||
{
|
||||
m_x = 0u;
|
||||
m_y++;
|
||||
}
|
||||
}
|
||||
if (m_y == m_height)
|
||||
{
|
||||
m_y--;
|
||||
m_fb.copy_rows_up(fb_y(m_height - 1u),
|
||||
(m_height - 1u) * kfont.line_height,
|
||||
kfont.line_height);
|
||||
}
|
||||
}
|
||||
|
||||
private void render_char(size_t x, size_t y, char ch)
|
||||
{
|
||||
const(CharInfo) * ci = &kfont.chars[ch];
|
||||
m_fb.blit_alpha_bitmap(fb_x(x) + ci.left, fb_y(y) + ci.top - ci.height, ci.bitmap, ci.width, ci.height);
|
||||
}
|
||||
|
||||
private size_t fb_x(size_t x)
|
||||
{
|
||||
return x * kfont.advance;
|
||||
}
|
||||
|
||||
private size_t fb_y(size_t y)
|
||||
{
|
||||
return m_fb.height - ((y + 1u) * kfont.line_height);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user