1

implement a scrollback buffer

This commit is contained in:
churl
2022-05-09 16:19:59 +02:00
parent b5a66f769e
commit 6f6301d5d0
7 changed files with 229 additions and 17 deletions

75
c_os/devices/BufferedCGA.cc Executable file
View File

@ -0,0 +1,75 @@
#include "BufferedCGA.h"
// 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() {
this->scrollback_buffer = new ScrollbackBuffer(COLUMNS, ROWS, 5);
this->initialized = true;
this->print("\nInitialized scrollback buffer with 5 pages\n\n", 45);
}
void BufferedCGA::displaypage() {
if (this->current_page == 0) {
// Use pagebuffer
this->scrollback_buffer->copy_page_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);
}
}
void BufferedCGA::print(char* string, int n, unsigned char attrib) {
if (this->current_page != 0) {
// Display newest content from buffer when new prints happen
this->current_page = 0;
this->displaypage();
}
CGA::print(string, n, attrib);
}
void BufferedCGA::scrollup() {
if (this->initialized) {
this->scrollback_buffer->line_to_buffer((cga_line_t*)CGA_START);
} else {
this->print("ScrollbackBuffer not initialized\n\n", 34);
}
CGA::scrollup();
}
void BufferedCGA::clear() {
CGA::clear();
this->current_page = 0;
if (this->initialized) {
this->scrollback_buffer->clear();
} else {
this->print("ScrollbackBuffer not initialized\n\n", 34);
}
}
unsigned int BufferedCGA::scroll_page_backward() {
// 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);
}
// 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;
}
this->displaypage();
return this->current_page;
}
unsigned int BufferedCGA::scroll_page_forward() {
if (this->current_page > 0) {
this->current_page = this->current_page - 1;
}
this->displaypage();
return this->current_page;
}

32
c_os/devices/BufferedCGA.h Executable file
View File

@ -0,0 +1,32 @@
#ifndef __BUFFEREDCGA_INCLUDE_H_
#define __BUFFEREDCGA_INCLUDE_H_
#include "devices/CGA.h"
#include "devices/Keyboard.h"
#include "lib/ScrollbackBuffer.h"
// NOTE: I added this file
class BufferedCGA : public CGA {
private:
ScrollbackBuffer* scrollback_buffer;
bool initialized; // Don't do ScrollbackBuffer actions if not initialized
BufferedCGA(const CGA& copy);
void displaypage(); // Write the current_page to CGA memory
public:
BufferedCGA() : CGA(), initialized(false), current_page(0) {};
void init(); // Scrollback needs to be initialized after memorymanagement
unsigned char current_page; // The page that is displayed
unsigned int scroll_page_backward(); // Scroll up the page history
unsigned int scroll_page_forward(); // Scroll down the page history (to the current page)
void print(char* string, int n, unsigned char attrib = STD_ATTR) override;
void scrollup() override;
void clear() override;
};
#endif

View File

@ -15,7 +15,7 @@
#ifndef __CGA_Stream_include__
#define __CGA_Stream_include__
#include "devices/CGA.h"
#include "devices/BufferedCGA.h"
#include "lib/OutStream.h"
// NOTE: I added this
@ -32,7 +32,8 @@ public:
CGA::color bg;
};
class CGA_Stream : public OutStream, public CGA {
// NOTE: I added this (changed this) to use BufferedCGA
class CGA_Stream : public OutStream, public BufferedCGA {
private:
CGA_Stream(CGA_Stream& copy); // Verhindere Kopieren
@ -41,7 +42,7 @@ public:
CGA::color color_bg;
bool blink;
CGA_Stream() : OutStream(), CGA() {
CGA_Stream() : OutStream(), BufferedCGA() {
color_fg = CGA::LIGHT_GREY;
color_bg = CGA::BLACK;
blink = false;