[fb] Output klog to fb if video exists
If there's no video, do as we did before, otherwise route logs to the fb driver instead. (Need to clean this up to just have a log consumer general interface?) Also added a "scrollback" class to fb driver and updated the system_get_log syscall.
This commit is contained in:
61
src/drivers/fb/scrollback.cpp
Normal file
61
src/drivers/fb/scrollback.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "font.h"
|
||||
#include "screen.h"
|
||||
#include "scrollback.h"
|
||||
|
||||
scrollback::scrollback(unsigned lines, unsigned cols, unsigned margin) :
|
||||
m_rows {lines},
|
||||
m_cols {cols},
|
||||
m_start {0},
|
||||
m_count {0},
|
||||
m_margin {margin}
|
||||
{
|
||||
m_data = reinterpret_cast<char*>(malloc(lines*cols));
|
||||
m_lines = reinterpret_cast<char**>(malloc(lines*sizeof(char*)));
|
||||
for (unsigned i = 0; i < lines; ++i)
|
||||
m_lines[i] = &m_data[i*cols];
|
||||
|
||||
memset(m_data, ' ', lines*cols);
|
||||
}
|
||||
|
||||
void
|
||||
scrollback::add_line(const char *line, size_t len)
|
||||
{
|
||||
unsigned i = 0;
|
||||
if (m_count < m_rows)
|
||||
i = m_count++;
|
||||
else
|
||||
i = m_start++;
|
||||
|
||||
if (len > m_cols)
|
||||
len = m_cols;
|
||||
|
||||
memcpy(m_lines[i % m_rows], line, len);
|
||||
if (len < m_cols)
|
||||
memset(m_lines[i % m_rows]+len, ' ', m_cols - len);
|
||||
}
|
||||
|
||||
char *
|
||||
scrollback::get_line(unsigned i)
|
||||
{
|
||||
return m_lines[(i+m_start)%m_rows];
|
||||
}
|
||||
|
||||
void
|
||||
scrollback::render(screen &scr, font &fnt)
|
||||
{
|
||||
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
|
||||
screen::pixel_t bg = scr.color(49, 79, 128);
|
||||
|
||||
const unsigned xstride = (m_margin + fnt.width());
|
||||
const unsigned ystride = (m_margin + fnt.height());
|
||||
|
||||
for (unsigned y = 0; y < m_rows; ++y) {
|
||||
char *line = get_line(y);
|
||||
for (unsigned x = 0; x < m_cols; ++x) {
|
||||
fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user