1
Files
lecture-operating-system-de…/c_os/lib/ScrollbackBuffer.cc
2022-05-17 18:38:52 +02:00

43 lines
1.4 KiB
C++
Executable File

#include "ScrollbackBuffer.h"
// NOTE: I added this file
void ScrollbackBuffer::put(CGA::cga_line_t* line) {
CGA::cga_line_t* destination = (CGA::cga_line_t*)this->buffer + this->pos;
mmem::memcpy<CGA::cga_line_t>(destination, line);
this->pos = (this->pos + 1) % this->rows;
}
void ScrollbackBuffer::get(CGA::cga_line_t* destination, unsigned char page) const {
if (page < 0 || page >= this->pages) {
return;
}
// 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
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;
mmem::memcpy<CGA::cga_line_t>(destination + line, (CGA::cga_line_t*)this->buffer + wrapline);
}
}
void ScrollbackBuffer::save_screen(CGA::cga_page_t* destination) const {
mmem::memcpy<CGA::cga_page_t>(destination, this->pagebuffer);
}
void ScrollbackBuffer::restore_screen(CGA::cga_page_t* source) {
mmem::memcpy<CGA::cga_page_t>(this->pagebuffer, source);
}
void ScrollbackBuffer::clear() {
for (unsigned char page = 0; page < this->pages; ++page) {
mmem::zero<CGA::cga_page_t>(this->buffer + page);
}
mmem::zero<CGA::cga_page_t>(this->pagebuffer);
this->pos = 0;
}