1

BufferedCGA refactoring

This commit is contained in:
churl
2022-05-17 18:38:52 +02:00
parent 7506cc40b9
commit 80cbe0900d
3 changed files with 10 additions and 22 deletions

View File

@ -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

View File

@ -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<CGA::cga_page_t>(destination, this->pagebuffer);
}
void ScrollbackBuffer::copy_to_pagebuffer(CGA::cga_page_t* source) {
void ScrollbackBuffer::restore_screen(CGA::cga_page_t* source) {
mmem::memcpy<CGA::cga_page_t>(this->pagebuffer, source);
}

View File

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