Buffered CGA refactor finish
This commit is contained in:
@ -4,8 +4,14 @@
|
||||
// NOTE: This has to be called when memorymanagement is active
|
||||
void BufferedCGA::init(unsigned int pages) {
|
||||
this->scrollback_buffer = new ScrollbackBuffer(ROWS, pages);
|
||||
this->initialized = true;
|
||||
this->screen_buffer = new CGA::cga_page_t;
|
||||
|
||||
if (this->scrollback_buffer == NULL || this->screen_buffer == NULL) {
|
||||
this->print("\nError initializing scrollback buffer\n\n", 39);
|
||||
return;
|
||||
}
|
||||
|
||||
this->initialized = true;
|
||||
this->print("\nInitialized scrollback buffer\n\n", 32);
|
||||
}
|
||||
|
||||
@ -13,7 +19,7 @@ void BufferedCGA::display_scrollback() {
|
||||
if (this->initialized) {
|
||||
if (this->scrollback == 0) {
|
||||
// Use pagebuffer
|
||||
this->scrollback_buffer->save_screen((cga_page_t*)CGA_START);
|
||||
mmem::memcpy<CGA::cga_page_t>((CGA::cga_page_t*)CGA_START, this->screen_buffer);
|
||||
} else {
|
||||
// Use scrollback
|
||||
this->scrollback_buffer->get((cga_line_t*)CGA_START, this->scrollback - 1);
|
||||
@ -50,6 +56,7 @@ void BufferedCGA::clear() {
|
||||
|
||||
if (this->initialized) {
|
||||
this->scrollback_buffer->clear();
|
||||
mmem::zero<CGA::cga_page_t>(this->screen_buffer);
|
||||
} else {
|
||||
this->print("ScrollbackBuffer not initialized\n\n", 34);
|
||||
}
|
||||
@ -60,7 +67,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->restore_screen((cga_page_t*)CGA_START);
|
||||
mmem::memcpy<CGA::cga_page_t>(this->screen_buffer, (CGA::cga_page_t*)CGA_START);
|
||||
}
|
||||
|
||||
// current_page can be equal to scrollback_buffer->pages
|
||||
|
||||
@ -5,26 +5,32 @@
|
||||
#include "devices/Keyboard.h"
|
||||
#include "lib/ScrollbackBuffer.h"
|
||||
|
||||
// NOTE: I added this file
|
||||
// NOTE: I added this file, I don't know if it will be used till the end but right know it's nice to have
|
||||
|
||||
// NOTE: I wanted to write to screen_buffer always and copy this to video mem to allow easier composition
|
||||
// of different screen elements, but this would disable printing before initialization or I would
|
||||
// have to replace print with unbuffered_print or something, which I don't like.
|
||||
class BufferedCGA : public CGA {
|
||||
private:
|
||||
ScrollbackBuffer* scrollback_buffer;
|
||||
bool initialized; // Don't do ScrollbackBuffer actions if not initialized
|
||||
ScrollbackBuffer* scrollback_buffer; // Contains previous pages
|
||||
CGA::cga_page_t* screen_buffer; // Contains the current page separately from the scrollback.
|
||||
bool initialized; // Don't do ScrollbackBuffer actions if not initialized
|
||||
|
||||
BufferedCGA(const CGA& copy);
|
||||
|
||||
void display_scrollback(); // Write the current_page to CGA memory
|
||||
BufferedCGA(const BufferedCGA&) = delete;
|
||||
|
||||
public:
|
||||
BufferedCGA() : CGA(), initialized(false), scrollback(0) {};
|
||||
~BufferedCGA() {
|
||||
if (this->initialized) { delete this->scrollback_buffer; }
|
||||
if (this->initialized) {
|
||||
delete this->scrollback_buffer;
|
||||
delete this->screen_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
|
||||
void display_scrollback(); // Write the current_page to CGA memory
|
||||
void scroll_page_backward(); // Scroll up the page history
|
||||
void scroll_page_forward(); // Scroll down the page history (to the current page)
|
||||
|
||||
|
||||
@ -345,8 +345,6 @@ void Keyboard::trigger() {
|
||||
}
|
||||
|
||||
// TODO: Keyboard insert mode
|
||||
|
||||
// kout.show(0, 0, (char)key);
|
||||
}
|
||||
|
||||
// TODO: Where to place this?
|
||||
@ -355,11 +353,9 @@ void scroll_mode(Key key) {
|
||||
switch ((char)key) {
|
||||
case 'k':
|
||||
kout.scroll_page_backward();
|
||||
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.scrollback));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,18 +25,9 @@ void ScrollbackBuffer::get(CGA::cga_line_t* destination, unsigned char page) con
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -7,15 +7,12 @@
|
||||
|
||||
// NOTE: I added this file
|
||||
|
||||
// The buffer dimensions must match with the destination dimensions
|
||||
class ScrollbackBuffer {
|
||||
private:
|
||||
CGA::cga_page_t* buffer; // Circular buffer to store lines that left the screen
|
||||
CGA::cga_page_t* pagebuffer; // Contains the current page separately from the scrollback.
|
||||
// I thought this was easier since it also captures the little output
|
||||
// generated before the scrollback buffer is initialized by accident
|
||||
// (but only if it's less than a page)
|
||||
unsigned int pos;
|
||||
CGA::cga_page_t* buffer; // Circular buffer to store lines that left the screen
|
||||
unsigned int pos; // Buffer write position
|
||||
|
||||
ScrollbackBuffer(const ScrollbackBuffer&) = delete;
|
||||
|
||||
public:
|
||||
const unsigned int pages; // Number of pages in buffer
|
||||
@ -23,19 +20,15 @@ public:
|
||||
|
||||
ScrollbackBuffer(unsigned char rows, unsigned char pages)
|
||||
: pos(0), pages(pages), rows(rows * pages) {
|
||||
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.
|
||||
this->buffer = new CGA::cga_page_t[pages]; // Allocate with new because it's quite large
|
||||
this->clear(); // Null out the buffer so no crap gets displayed
|
||||
}
|
||||
~ScrollbackBuffer() {
|
||||
delete[] this->buffer;
|
||||
delete this->pagebuffer;
|
||||
}
|
||||
|
||||
void put(CGA::cga_line_t* line);
|
||||
void get(CGA::cga_line_t* destination, unsigned char page) const;
|
||||
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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user