diff --git a/src/drivers/fb/font.cpp b/src/drivers/fb/font.cpp index ee5b170..d164af5 100644 --- a/src/drivers/fb/font.cpp +++ b/src/drivers/fb/font.cpp @@ -62,6 +62,9 @@ font::draw_glyph( unsigned x, unsigned y) const { + if (glyph >= m_count) + return; + unsigned bwidth = (m_sizex+7)/8; uint8_t const *data = m_data + (glyph * glyph_bytes()); diff --git a/src/drivers/fb/main.cpp b/src/drivers/fb/main.cpp index b37943f..2a580f9 100644 --- a/src/drivers/fb/main.cpp +++ b/src/drivers/fb/main.cpp @@ -30,6 +30,32 @@ struct entry 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 main(int argc, const char **argv) { @@ -83,6 +109,10 @@ main(int argc, const char **argv) scr.fill(bg); scr.update(); + draw_stuff(scr, fnt); + scr.update(); + + /* constexpr int margin = 2; const unsigned xstride = (margin + fnt.width()); const unsigned ystride = (margin + fnt.height()); @@ -94,12 +124,26 @@ main(int argc, const char **argv) int pending = 0; 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) { - size_t size = sizeof(message_buffer); - j6_system_get_log(__handle_sys, message_buffer, &size); - if (size != 0) { - entry *e = reinterpret_cast(&message_buffer); + size_t size = buffer_size; + j6_status_t s = j6_system_get_log(sys, message_buffer, &size); + + 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(message_buffer); size_t eom = e->bytes - sizeof(entry); e->message[eom] = 0; @@ -118,7 +162,7 @@ main(int argc, const char **argv) } } } - + */ j6_system_log("fb driver done, exiting"); return 0; diff --git a/src/drivers/fb/screen.cpp b/src/drivers/fb/screen.cpp index 3a95d7d..35d7e59 100644 --- a/src/drivers/fb/screen.cpp +++ b/src/drivers/fb/screen.cpp @@ -10,6 +10,7 @@ screen::screen(volatile void *addr, unsigned hres, unsigned vres, unsigned scanl m_resy(vres) { m_back = reinterpret_cast(malloc(scanline*vres*sizeof(pixel_t))); + //m_back = const_cast(m_fb); } screen::pixel_t @@ -33,21 +34,25 @@ screen::color(uint8_t r, uint8_t g, uint8_t b) const void screen::fill(pixel_t color) { - const size_t len = m_resx * m_resy; - for (size_t i = 0; i < len; ++i) - m_back[i] = color; -} - -void -screen::draw_pixel(unsigned x, unsigned y, pixel_t color) -{ - m_back[x + y * m_resx] = color; + const size_t len = m_scanline * m_resy; + asm volatile ( "rep stosl" : : + "a"(color), "c"(len), "D"(m_back) ); } void screen::update() { + /* const size_t len = m_scanline * m_resy * sizeof(pixel_t); asm volatile ( "rep movsb" : : "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; + */ + } } diff --git a/src/drivers/fb/screen.h b/src/drivers/fb/screen.h index fbc9d82..77ac221 100644 --- a/src/drivers/fb/screen.h +++ b/src/drivers/fb/screen.h @@ -17,7 +17,13 @@ public: pixel_t color(uint8_t r, uint8_t g, uint8_t b) const; 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();