From b860c82d879e184c82eec1fd1c263b2f06d0d3ab Mon Sep 17 00:00:00 2001 From: churl Date: Tue, 10 May 2022 00:20:25 +0200 Subject: [PATCH] fix bufferedcga bug where buffer was used before init --- c_os/devices/BufferedCGA.cc | 54 ++++++++++++++++++++++--------------- c_os/devices/BufferedCGA.h | 8 +++--- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/c_os/devices/BufferedCGA.cc b/c_os/devices/BufferedCGA.cc index 86fdba0..a63b2fe 100755 --- a/c_os/devices/BufferedCGA.cc +++ b/c_os/devices/BufferedCGA.cc @@ -10,12 +10,16 @@ void BufferedCGA::init() { } void BufferedCGA::displaypage() { - if (this->current_page == 0) { - // Use pagebuffer - this->scrollback_buffer->copy_page_from_pagebuffer((cga_page_t*)CGA_START); + if (this->initialized) { + if (this->current_page == 0) { + // Use pagebuffer + this->scrollback_buffer->copy_page_from_pagebuffer((cga_page_t*)CGA_START); + } else { + // Use scrollback + this->scrollback_buffer->copy_page_from_buffer((cga_line_t*)CGA_START, this->current_page - 1); + } } else { - // Use scrollback - this->scrollback_buffer->copy_page_from_buffer((cga_line_t*)CGA_START, this->current_page - 1); + this->print("ScrollbackBuffer not initialized\n\n", 34); } } @@ -51,25 +55,33 @@ void BufferedCGA::clear() { } } -unsigned int BufferedCGA::scroll_page_backward() { - // If this is the first scrollback we have to save the current screen content - if (this->current_page == 0) { - this->scrollback_buffer->copy_page_to_pagebuffer((cga_page_t*)CGA_START); - } +void BufferedCGA::scroll_page_backward() { + if (this->initialized) { - // current_page can be equal to scrollback_buffer->pages - // as we have a separate pagebuffer for the current screen content - if (this->current_page < this->scrollback_buffer->pages) { - this->current_page = this->current_page + 1; + // If this is the first scrollback we have to save the current screen content + if (this->current_page == 0) { + this->scrollback_buffer->copy_page_to_pagebuffer((cga_page_t*)CGA_START); + } + + // current_page can be equal to scrollback_buffer->pages + // as we have a separate pagebuffer for the current screen content + if (this->current_page < this->scrollback_buffer->pages) { + this->current_page = this->current_page + 1; + } + this->displaypage(); + } else { + this->print("ScrollbackBuffer not initialized\n\n", 34); } - this->displaypage(); - return this->current_page; } -unsigned int BufferedCGA::scroll_page_forward() { - if (this->current_page > 0) { - this->current_page = this->current_page - 1; +void BufferedCGA::scroll_page_forward() { + if (this->initialized) { + + if (this->current_page > 0) { + this->current_page = this->current_page - 1; + } + this->displaypage(); + } else { + this->print("ScrollbackBuffer not initialized\n\n", 34); } - this->displaypage(); - return this->current_page; } diff --git a/c_os/devices/BufferedCGA.h b/c_os/devices/BufferedCGA.h index 77024a4..c9550f8 100755 --- a/c_os/devices/BufferedCGA.h +++ b/c_os/devices/BufferedCGA.h @@ -19,10 +19,10 @@ private: public: BufferedCGA() : CGA(), initialized(false), current_page(0) {}; - void init(); // Scrollback needs to be initialized after memorymanagement - unsigned char current_page; // The page that is displayed - unsigned int scroll_page_backward(); // Scroll up the page history - unsigned int scroll_page_forward(); // Scroll down the page history (to the current page) + void init(); // Scrollback needs to be initialized after memorymanagement + unsigned char current_page; // The page that is displayed + void scroll_page_backward(); // Scroll up the page history + void scroll_page_forward(); // Scroll down the page history (to the current page) void print(char* string, int n, unsigned char attrib = STD_ATTR) override; void scrollup() override;