1

BufferedCGA refactoring

This commit is contained in:
churl
2022-05-17 17:50:19 +02:00
parent c1b7c4cb5b
commit 13c7d898ab
7 changed files with 78 additions and 67 deletions

View File

@ -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);
}