1

Buffered CGA refactor finish

This commit is contained in:
churl
2022-05-20 16:15:43 +02:00
parent 80cbe0900d
commit 5e2196c898
5 changed files with 29 additions and 36 deletions

View File

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

View File

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

View File

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