BufferedCGA refactoring
This commit is contained in:
@ -3,20 +3,20 @@
|
||||
// Can't initialize in constructor as memory management already needs working CGA for output
|
||||
// NOTE: This has to be called when memorymanagement is active
|
||||
void BufferedCGA::init(unsigned int pages) {
|
||||
this->scrollback_buffer = new ScrollbackBuffer(COLUMNS, ROWS, pages);
|
||||
this->scrollback_buffer = new ScrollbackBuffer(ROWS, pages);
|
||||
this->initialized = true;
|
||||
|
||||
this->print("\nInitialized scrollback buffer\n\n", 32);
|
||||
}
|
||||
|
||||
void BufferedCGA::displaypage() {
|
||||
void BufferedCGA::display_scrollback() {
|
||||
if (this->initialized) {
|
||||
if (this->current_page == 0) {
|
||||
if (this->scrollback == 0) {
|
||||
// Use pagebuffer
|
||||
this->scrollback_buffer->copy_page_from_pagebuffer((cga_page_t*)CGA_START);
|
||||
this->scrollback_buffer->copy_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);
|
||||
this->scrollback_buffer->get((cga_line_t*)CGA_START, this->scrollback - 1);
|
||||
}
|
||||
} else {
|
||||
this->print("ScrollbackBuffer not initialized\n\n", 34);
|
||||
@ -24,11 +24,11 @@ void BufferedCGA::displaypage() {
|
||||
}
|
||||
|
||||
void BufferedCGA::print(char* string, int n, unsigned char attrib) {
|
||||
if (this->current_page != 0) {
|
||||
if (this->scrollback != 0) {
|
||||
// Display newest content from buffer when new prints happen
|
||||
|
||||
this->current_page = 0;
|
||||
this->displaypage();
|
||||
this->scrollback = 0;
|
||||
this->display_scrollback();
|
||||
}
|
||||
|
||||
CGA::print(string, n, attrib);
|
||||
@ -36,7 +36,7 @@ void BufferedCGA::print(char* string, int n, unsigned char attrib) {
|
||||
|
||||
void BufferedCGA::scrollup() {
|
||||
if (this->initialized) {
|
||||
this->scrollback_buffer->line_to_buffer((cga_line_t*)CGA_START);
|
||||
this->scrollback_buffer->put((cga_line_t*)CGA_START);
|
||||
} else {
|
||||
this->print("ScrollbackBuffer not initialized\n\n", 34);
|
||||
}
|
||||
@ -46,7 +46,7 @@ void BufferedCGA::scrollup() {
|
||||
|
||||
void BufferedCGA::clear() {
|
||||
CGA::clear();
|
||||
this->current_page = 0;
|
||||
this->scrollback = 0;
|
||||
|
||||
if (this->initialized) {
|
||||
this->scrollback_buffer->clear();
|
||||
@ -59,16 +59,16 @@ void BufferedCGA::scroll_page_backward() {
|
||||
if (this->initialized) {
|
||||
|
||||
// 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);
|
||||
if (this->scrollback == 0) {
|
||||
this->scrollback_buffer->copy_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;
|
||||
if (this->scrollback < this->scrollback_buffer->pages) {
|
||||
this->scrollback = this->scrollback + 1;
|
||||
}
|
||||
this->displaypage();
|
||||
this->display_scrollback();
|
||||
} else {
|
||||
this->print("ScrollbackBuffer not initialized\n\n", 34);
|
||||
}
|
||||
@ -77,10 +77,10 @@ void BufferedCGA::scroll_page_backward() {
|
||||
void BufferedCGA::scroll_page_forward() {
|
||||
if (this->initialized) {
|
||||
|
||||
if (this->current_page > 0) {
|
||||
this->current_page = this->current_page - 1;
|
||||
if (this->scrollback > 0) {
|
||||
this->scrollback = this->scrollback - 1;
|
||||
}
|
||||
this->displaypage();
|
||||
this->display_scrollback();
|
||||
} else {
|
||||
this->print("ScrollbackBuffer not initialized\n\n", 34);
|
||||
}
|
||||
|
||||
@ -14,13 +14,17 @@ private:
|
||||
|
||||
BufferedCGA(const CGA& copy);
|
||||
|
||||
void displaypage(); // Write the current_page to CGA memory
|
||||
void display_scrollback(); // Write the current_page to CGA memory
|
||||
|
||||
public:
|
||||
BufferedCGA() : CGA(), initialized(false), current_page(0) {};
|
||||
BufferedCGA() : CGA(), initialized(false), scrollback(0) {};
|
||||
~BufferedCGA() {
|
||||
if (this->initialized) { delete this->scrollback_buffer; }
|
||||
}
|
||||
|
||||
unsigned char scrollback; // The page that is displayed, public to enable page display
|
||||
|
||||
void init(unsigned int pages); // 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)
|
||||
|
||||
|
||||
@ -355,11 +355,11 @@ void scroll_mode(Key key) {
|
||||
switch ((char)key) {
|
||||
case 'k':
|
||||
kout.scroll_page_backward();
|
||||
kout.show(kout.COLUMNS - 1, 0, (char)(48 + kout.current_page));
|
||||
kout.show(kout.COLUMNS - 1, 0, (char)(48 + kout.scrollback));
|
||||
break;
|
||||
case 'j':
|
||||
kout.scroll_page_forward();
|
||||
kout.show(kout.COLUMNS - 1, 0, (char)(48 + kout.current_page));
|
||||
kout.show(kout.COLUMNS - 1, 0, (char)(48 + kout.scrollback));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user