WIP framebuffer issue

This commit is contained in:
Justin C. Miller
2021-02-04 21:37:53 -08:00
parent c87563a520
commit 2652cc449c
4 changed files with 74 additions and 16 deletions

View File

@@ -62,6 +62,9 @@ font::draw_glyph(
unsigned x, unsigned x,
unsigned y) const unsigned y) const
{ {
if (glyph >= m_count)
return;
unsigned bwidth = (m_sizex+7)/8; unsigned bwidth = (m_sizex+7)/8;
uint8_t const *data = m_data + (glyph * glyph_bytes()); uint8_t const *data = m_data + (glyph * glyph_bytes());

View File

@@ -30,6 +30,32 @@ struct entry
char message[0]; char message[0];
}; };
void
draw_stuff(screen &scr, font &fnt)
{
screen::pixel_t fg = scr.color(0xb0, 0xb0, 0xb0);
screen::pixel_t bg = scr.color(49, 79, 128);
unsigned h = fnt.height();
unsigned w = fnt.width();
unsigned lines = scr.height()/h;
unsigned columns = scr.width()/w;
for (unsigned y = 0; y < lines; ++y) {
for (unsigned x = 0; x < columns; ++x) {
char d = (x + y * columns) % 10 + '0';
fnt.draw_glyph(scr, d, fg, bg, x*w, y*h);
}
}
for (unsigned y = 0; y < scr.height(); ++y) {
for (unsigned x = 0; x < scr.width(); x += 61) {
scr.draw_pixel(x, y, 0xffffff);
}
}
}
int int
main(int argc, const char **argv) main(int argc, const char **argv)
{ {
@@ -83,6 +109,10 @@ main(int argc, const char **argv)
scr.fill(bg); scr.fill(bg);
scr.update(); scr.update();
draw_stuff(scr, fnt);
scr.update();
/*
constexpr int margin = 2; constexpr int margin = 2;
const unsigned xstride = (margin + fnt.width()); const unsigned xstride = (margin + fnt.width());
const unsigned ystride = (margin + fnt.height()); const unsigned ystride = (margin + fnt.height());
@@ -94,12 +124,26 @@ main(int argc, const char **argv)
int pending = 0; int pending = 0;
constexpr int pending_threshold = 10; constexpr int pending_threshold = 10;
char message_buffer[256]; j6_handle_t sys = __handle_sys;
size_t buffer_size = 0;
void *message_buffer = nullptr;
while (true) { while (true) {
size_t size = sizeof(message_buffer); size_t size = buffer_size;
j6_system_get_log(__handle_sys, message_buffer, &size); j6_status_t s = j6_system_get_log(sys, message_buffer, &size);
if (size != 0) {
entry *e = reinterpret_cast<entry*>(&message_buffer); if (s == j6_err_insufficient) {
free(message_buffer);
message_buffer = malloc(size);
buffer_size = size;
continue;
} else if (s != j6_status_ok) {
j6_system_log("fb driver got error from get_log, quitting");
return s;
}
if (size > 0) {
entry *e = reinterpret_cast<entry*>(message_buffer);
size_t eom = e->bytes - sizeof(entry); size_t eom = e->bytes - sizeof(entry);
e->message[eom] = 0; e->message[eom] = 0;
@@ -118,7 +162,7 @@ main(int argc, const char **argv)
} }
} }
} }
*/
j6_system_log("fb driver done, exiting"); j6_system_log("fb driver done, exiting");
return 0; return 0;

View File

@@ -10,6 +10,7 @@ screen::screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanl
m_resy(vres) m_resy(vres)
{ {
m_back = reinterpret_cast<pixel_t*>(malloc(scanline*vres*sizeof(pixel_t))); m_back = reinterpret_cast<pixel_t*>(malloc(scanline*vres*sizeof(pixel_t)));
//m_back = const_cast<pixel_t*>(m_fb);
} }
screen::pixel_t screen::pixel_t
@@ -33,21 +34,25 @@ screen::color(uint8_t r, uint8_t g, uint8_t b) const
void void
screen::fill(pixel_t color) screen::fill(pixel_t color)
{ {
const size_t len = m_resx * m_resy; const size_t len = m_scanline * m_resy;
for (size_t i = 0; i < len; ++i) asm volatile ( "rep stosl" : :
m_back[i] = color; "a"(color), "c"(len), "D"(m_back) );
}
void
screen::draw_pixel(unsigned x, unsigned y, pixel_t color)
{
m_back[x + y * m_resx] = color;
} }
void void
screen::update() screen::update()
{ {
/*
const size_t len = m_scanline * m_resy * sizeof(pixel_t); const size_t len = m_scanline * m_resy * sizeof(pixel_t);
asm volatile ( "rep movsb" : : asm volatile ( "rep movsb" : :
"c"(len), "S"(m_back), "D"(m_fb) ); "c"(len), "S"(m_back), "D"(m_fb) );
*/
const size_t len = m_scanline * m_resy;
for (size_t i = 0; i < len; ++i) {
m_fb[i] = m_back[i];
/*
for (int j = 0; j < 10000; ++j)
volatile char c = j;
*/
}
} }

View File

@@ -17,7 +17,13 @@ public:
pixel_t color(uint8_t r, uint8_t g, uint8_t b) const; pixel_t color(uint8_t r, uint8_t g, uint8_t b) const;
void fill(pixel_t color); void fill(pixel_t color);
void draw_pixel(unsigned x, unsigned y, pixel_t color);
inline void draw_pixel(unsigned x, unsigned y, pixel_t color) {
const size_t index = x + y * m_scanline;
if (x > m_resx || y > m_resy)
return;
m_back[index] = color;
}
void update(); void update();