From a65ecb157dc9829311644efe2795d7b693b4221f Mon Sep 17 00:00:00 2001 From: "Justin C. Miller" Date: Sat, 6 Feb 2021 00:33:45 -0800 Subject: [PATCH] [fb] Fix fb log scrolling While working on the double-buffering issue, I ripped out this feature from scrollback and didn't put it back in. Also having main allocate extra space for the message buffer since calling malloc/free over again several times was causing malloc to panic. (Which should also separately be fixed..) --- src/drivers/fb/main.cpp | 4 ++-- src/drivers/fb/scrollback.cpp | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/drivers/fb/main.cpp b/src/drivers/fb/main.cpp index 793b53e..49defb0 100644 --- a/src/drivers/fb/main.cpp +++ b/src/drivers/fb/main.cpp @@ -92,7 +92,7 @@ main(int argc, const char **argv) scrollback scroll(rows, cols); int pending = 0; - constexpr int pending_threshold = 10; + constexpr int pending_threshold = 5; j6_handle_t sys = __handle_sys; size_t buffer_size = 0; @@ -104,7 +104,7 @@ main(int argc, const char **argv) if (s == j6_err_insufficient) { free(message_buffer); - message_buffer = malloc(size); + message_buffer = malloc(size * 2); buffer_size = size; continue; } else if (s != j6_status_ok) { diff --git a/src/drivers/fb/scrollback.cpp b/src/drivers/fb/scrollback.cpp index 625d8e3..50c28f6 100644 --- a/src/drivers/fb/scrollback.cpp +++ b/src/drivers/fb/scrollback.cpp @@ -45,8 +45,12 @@ scrollback::render(screen &scr, font &fnt) const unsigned xstride = (m_margin + fnt.width()); const unsigned ystride = (m_margin + fnt.height()); + unsigned start = m_count <= m_rows ? 0 : + m_count % m_rows; + for (unsigned y = 0; y < m_rows; ++y) { - char *line = &m_data[y*m_cols]; + unsigned i = (start + y) % m_rows; + char *line = &m_data[i*m_cols]; for (unsigned x = 0; x < m_cols; ++x) { fnt.draw_glyph(scr, line[x], fg, bg, m_margin+x*xstride, m_margin+y*ystride); }