delete scrollback code
This commit is contained in:
@ -1,95 +0,0 @@
|
||||
#include "BufferedCGA.h"
|
||||
#include "kernel/Globals.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(unsigned int pages) {
|
||||
this->scrollback_buffer = std::make_unique<ScrollbackBuffer>(ROWS, pages); // No delete since it's only off when shutting the os down
|
||||
this->screen_buffer = std::make_unique<CGA::cga_page_t>();
|
||||
|
||||
if (this->scrollback_buffer == NULL || this->screen_buffer == NULL) {
|
||||
if constexpr (DEBUG) { kout << "Error initializing scrollback buffer" << endl; }
|
||||
return;
|
||||
}
|
||||
|
||||
this->initialized = true;
|
||||
if constexpr (DEBUG) { kout << "Initialized scrollback buffer" << endl; }
|
||||
}
|
||||
|
||||
void BufferedCGA::display_scrollback() {
|
||||
if (this->initialized) {
|
||||
if (this->scrollback == 0) {
|
||||
// Use pagebuffer
|
||||
mmem::memcpy<CGA::cga_page_t>((CGA::cga_page_t*)CGA_START, this->screen_buffer.get());
|
||||
} else {
|
||||
// Use scrollback
|
||||
this->scrollback_buffer->get((CGA::cga_line_t*)CGA_START, this->scrollback - 1);
|
||||
}
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
}
|
||||
}
|
||||
|
||||
void BufferedCGA::print(char* string, int n, unsigned char attrib) {
|
||||
if (this->scrollback != 0) {
|
||||
// Display newest content from buffer when new prints happen
|
||||
|
||||
this->scrollback = 0;
|
||||
this->display_scrollback();
|
||||
}
|
||||
|
||||
CGA::print(string, n, attrib);
|
||||
}
|
||||
|
||||
void BufferedCGA::scrollup() {
|
||||
if (this->initialized) {
|
||||
this->scrollback_buffer->put((CGA::cga_line_t*)CGA_START);
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
}
|
||||
|
||||
CGA::scrollup();
|
||||
}
|
||||
|
||||
void BufferedCGA::clear() {
|
||||
CGA::clear();
|
||||
this->scrollback = 0;
|
||||
|
||||
if (this->initialized) {
|
||||
this->scrollback_buffer->clear();
|
||||
mmem::zero<CGA::cga_page_t>(this->screen_buffer.get());
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
}
|
||||
}
|
||||
|
||||
void BufferedCGA::scroll_page_backward() {
|
||||
if (this->initialized) {
|
||||
|
||||
// If this is the first scrollback we have to save the current screen content
|
||||
if (this->scrollback == 0) {
|
||||
mmem::memcpy<CGA::cga_page_t>(this->screen_buffer.get(), (CGA::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->scrollback < this->scrollback_buffer->pages) {
|
||||
this->scrollback = this->scrollback + 1;
|
||||
}
|
||||
this->display_scrollback();
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
}
|
||||
}
|
||||
|
||||
void BufferedCGA::scroll_page_forward() {
|
||||
if (this->initialized) {
|
||||
|
||||
if (this->scrollback > 0) {
|
||||
this->scrollback = this->scrollback - 1;
|
||||
}
|
||||
this->display_scrollback();
|
||||
} else {
|
||||
if constexpr (DEBUG) { kout << "ScrollbackBuffer not initialized" << endl; }
|
||||
}
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef __BUFFEREDCGA_INCLUDE_H_
|
||||
#define __BUFFEREDCGA_INCLUDE_H_
|
||||
|
||||
#include "devices/CGA.h"
|
||||
#include "devices/Keyboard.h"
|
||||
#include "lib/ScrollbackBuffer.h"
|
||||
#include <memory>
|
||||
|
||||
// NOTE: I added this file, I will probably replace this in the end by an application
|
||||
class BufferedCGA : public CGA {
|
||||
private:
|
||||
std::unique_ptr<ScrollbackBuffer> scrollback_buffer; // Contains previous pages
|
||||
std::unique_ptr<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 BufferedCGA&) = delete;
|
||||
|
||||
public:
|
||||
BufferedCGA() : initialized(false), scrollback(0) {}
|
||||
|
||||
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)
|
||||
|
||||
void print(char* string, int n, unsigned char attrib = STD_ATTR) override;
|
||||
void scrollup() override;
|
||||
void clear() override;
|
||||
};
|
||||
|
||||
#endif
|
@ -15,11 +15,9 @@
|
||||
#ifndef __CGA_Stream_include__
|
||||
#define __CGA_Stream_include__
|
||||
|
||||
// #include "devices/BufferedCGA.h"
|
||||
#include "devices/BufferedCGA.h"
|
||||
#include "devices/CGA.h"
|
||||
#include "lib/OutStream.h"
|
||||
|
||||
// NOTE: I added this
|
||||
class fgc {
|
||||
public:
|
||||
fgc() : fg(CGA::LIGHT_GREY) {}
|
||||
@ -33,8 +31,7 @@ public:
|
||||
CGA::color bg;
|
||||
};
|
||||
|
||||
// NOTE: I added this (changed this) to use BufferedCGA
|
||||
class CGA_Stream : public OutStream, public BufferedCGA {
|
||||
class CGA_Stream : public OutStream, public CGA {
|
||||
private:
|
||||
CGA_Stream(CGA_Stream& copy) = delete; // Verhindere Kopieren
|
||||
|
||||
@ -50,7 +47,6 @@ public:
|
||||
// Methode zur Ausgabe des Pufferinhalts der Basisklasse StringBuffer.
|
||||
void flush() override;
|
||||
|
||||
// NOTE: I added this
|
||||
template<typename T>
|
||||
// requires std::derived_from<T, CGA_Stream>
|
||||
friend T& operator<<(T& os, const fgc& fg) {
|
||||
|
@ -341,23 +341,4 @@ void Keyboard::trigger() {
|
||||
if (key.ctrl_left() && key.alt_left() && (char)key == 'r') {
|
||||
this->reboot();
|
||||
}
|
||||
else if ((char)key == 'k' || (char)key == 'j') {
|
||||
scroll_mode(key);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Where to place this?
|
||||
// To use keyboard interrupts from different applications more work is needed:
|
||||
// - Ereignisverwaltung, wo man Threads registrieren kann
|
||||
// - Blockierte Threads verwalten und aufwecken bei ereignissen
|
||||
// Waits for keys to control the scrollback buffer display
|
||||
void scroll_mode(Key key) {
|
||||
switch ((char)key) {
|
||||
case 'k':
|
||||
kout.scroll_page_backward();
|
||||
break;
|
||||
case 'j':
|
||||
kout.scroll_page_forward();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1,33 +0,0 @@
|
||||
#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.get() + 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.get() + wrapline);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollbackBuffer::clear() {
|
||||
for (unsigned char page = 0; page < this->pages; ++page) {
|
||||
mmem::zero<CGA::cga_page_t>(this->buffer.get() + page);
|
||||
}
|
||||
this->pos = 0;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
#ifndef __SCROLLBACKBUFFER_INCLUDE_H_
|
||||
#define __SCROLLBACKBUFFER_INCLUDE_H_
|
||||
|
||||
#include "devices/CGA.h"
|
||||
#include "lib/MyStdLib.h"
|
||||
#include <memory>
|
||||
#include <stddef.h>
|
||||
|
||||
// NOTE: I added this file
|
||||
|
||||
class ScrollbackBuffer {
|
||||
private:
|
||||
std::unique_ptr<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
|
||||
const unsigned int rows; // Number of lines in buffer
|
||||
|
||||
ScrollbackBuffer(unsigned char rows, unsigned char pages)
|
||||
: pos(0), pages(pages), rows(rows * pages) {
|
||||
this->buffer = std::make_unique<CGA::cga_page_t[]>(pages); // Allocate with new because it's quite large (and I want to use the allocator)
|
||||
this->clear(); // Null out the buffer so no crap gets displayed
|
||||
}
|
||||
|
||||
void put(CGA::cga_line_t* line);
|
||||
void get(CGA::cga_line_t* destination, unsigned char page) const;
|
||||
void clear();
|
||||
};
|
||||
|
||||
#endif
|
@ -25,9 +25,6 @@ int main() {
|
||||
// Speicherverwaltung initialisieren
|
||||
allocator.init();
|
||||
|
||||
// Initialize scrollback buffer after allocator.init()
|
||||
kout.init(5);
|
||||
|
||||
// Startmeldung
|
||||
kout << "HHUos 0.10\n"
|
||||
<< "=========\n"
|
||||
|
Reference in New Issue
Block a user