move user stuff to user
This commit is contained in:
@ -1,7 +0,0 @@
|
||||
#include "MyStdLib.h"
|
||||
|
||||
void mmem::memset(char* destination, char value, unsigned int bytes) {
|
||||
for (unsigned int byte = 0; byte < bytes; ++byte) {
|
||||
*(destination + byte) = value;
|
||||
}
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
#ifndef __MYSTDLIB_INCLUDE_H_
|
||||
#define __MYSTDLIB_INCLUDE_H_
|
||||
|
||||
// NOTE: I added this file
|
||||
|
||||
namespace mmem {
|
||||
template<typename T>
|
||||
void memcpy(T* destination, T* source, unsigned int count = 1) {
|
||||
for (unsigned int i = 0; i < count; ++i) {
|
||||
*(destination + i) = *(source + i);
|
||||
}
|
||||
}
|
||||
|
||||
void memset(char* destination, char value, unsigned int bytes);
|
||||
|
||||
template<typename T>
|
||||
void zero(T* destination) {
|
||||
mmem::memset((char*)destination, '\0', sizeof(T));
|
||||
}
|
||||
|
||||
void strcpy(char* destination, char* source);
|
||||
unsigned int strlen(char* string);
|
||||
} // namespace mmem
|
||||
|
||||
#endif
|
||||
@ -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
|
||||
Reference in New Issue
Block a user