From 80cbe0900d773bef1a2022022933f7b7498021eb Mon Sep 17 00:00:00 2001 From: churl Date: Tue, 17 May 2022 18:38:52 +0200 Subject: [PATCH] BufferedCGA refactoring --- c_os/devices/BufferedCGA.cc | 4 ++-- c_os/lib/ScrollbackBuffer.cc | 18 +++--------------- c_os/lib/ScrollbackBuffer.h | 10 +++++----- 3 files changed, 10 insertions(+), 22 deletions(-) diff --git a/c_os/devices/BufferedCGA.cc b/c_os/devices/BufferedCGA.cc index e65f904..b358c9c 100755 --- a/c_os/devices/BufferedCGA.cc +++ b/c_os/devices/BufferedCGA.cc @@ -13,7 +13,7 @@ void BufferedCGA::display_scrollback() { if (this->initialized) { if (this->scrollback == 0) { // Use pagebuffer - this->scrollback_buffer->copy_from_pagebuffer((cga_page_t*)CGA_START); + this->scrollback_buffer->save_screen((cga_page_t*)CGA_START); } else { // Use scrollback this->scrollback_buffer->get((cga_line_t*)CGA_START, this->scrollback - 1); @@ -60,7 +60,7 @@ void BufferedCGA::scroll_page_backward() { // If this is the first scrollback we have to save the current screen content if (this->scrollback == 0) { - this->scrollback_buffer->copy_to_pagebuffer((cga_page_t*)CGA_START); + this->scrollback_buffer->restore_screen((cga_page_t*)CGA_START); } // current_page can be equal to scrollback_buffer->pages diff --git a/c_os/lib/ScrollbackBuffer.cc b/c_os/lib/ScrollbackBuffer.cc index 90b9492..bddc878 100755 --- a/c_os/lib/ScrollbackBuffer.cc +++ b/c_os/lib/ScrollbackBuffer.cc @@ -14,22 +14,10 @@ void ScrollbackBuffer::get(CGA::cga_line_t* destination, unsigned char page) con return; } - // We reverse the pagenumber so page 0 is always the current page - // (The last written line is always before curent_line - // so we need to take the last page if we want the newest lines) + // We reverse the pagenumber so page 0 is always the newest page unsigned char rpage = this->pages - page - 1; // Copy linewise because page may wrap around buffer borders - - // Pageheight: 4, Pages: 2 | page = 0 => rpage = 2 - 0 - 1 = 1 - // LINE 0 | - line = 0 => wrapline = (5 + 1 * 4 + 0) % 8 = 1 - // LINE 1 | - [...] - // LINE 2 | - line = 3 => wrapline = (5 + 1 * 4 + 3) % 8 = 4 - // LINE 3 | - // LINE 4 | page = 1 => rpage = 2 - 1 - 1 = 0 - // LINE 5 - current_linenumber | - line = 0 => wrapline = (5 + 0 * 4 + 0) % 8 = 5 - // LINE 6 | - [...] - // LINE 7 | - line = 3 => wrapline = (5 + 0 * 4 + 3) % 8 = 0 unsigned int wrapline; for (unsigned int line = 0; line < (this->rows / this->pages); ++line) { wrapline = (this->pos + rpage * (this->rows / this->pages) + line) % this->rows; @@ -37,11 +25,11 @@ void ScrollbackBuffer::get(CGA::cga_line_t* destination, unsigned char page) con } } -void ScrollbackBuffer::copy_from_pagebuffer(CGA::cga_page_t* destination) const { +void ScrollbackBuffer::save_screen(CGA::cga_page_t* destination) const { mmem::memcpy(destination, this->pagebuffer); } -void ScrollbackBuffer::copy_to_pagebuffer(CGA::cga_page_t* source) { +void ScrollbackBuffer::restore_screen(CGA::cga_page_t* source) { mmem::memcpy(this->pagebuffer, source); } diff --git a/c_os/lib/ScrollbackBuffer.h b/c_os/lib/ScrollbackBuffer.h index 621a4f4..16810ad 100755 --- a/c_os/lib/ScrollbackBuffer.h +++ b/c_os/lib/ScrollbackBuffer.h @@ -23,9 +23,9 @@ public: ScrollbackBuffer(unsigned char rows, unsigned char pages) : pos(0), pages(pages), rows(rows * pages) { - this->buffer = new CGA::cga_page_t[pages]; - this->pagebuffer = new CGA::cga_page_t; - this->clear(); // Null out the buffer so no crap gets displayed + this->buffer = new CGA::cga_page_t[pages]; // Allocate with new because it's quite large, + this->pagebuffer = new CGA::cga_page_t; // also I wanted to use the new memory manager. + this->clear(); // Null out the buffer so no crap gets displayed. } ~ScrollbackBuffer() { delete[] this->buffer; @@ -34,8 +34,8 @@ public: void put(CGA::cga_line_t* line); void get(CGA::cga_line_t* destination, unsigned char page) const; - void copy_from_pagebuffer(CGA::cga_page_t* destination) const; - void copy_to_pagebuffer(CGA::cga_page_t* source); + void save_screen(CGA::cga_page_t* destination) const; // Do not lose video memory when scrolling + void restore_screen(CGA::cga_page_t* source); void clear(); };