namespace mylibs
This commit is contained in:
@ -150,10 +150,10 @@ void CGA::scrollup() {
|
||||
/* Hier muss Code eingefuegt werden */
|
||||
|
||||
// Move up
|
||||
mymemcpy<cga_line_t>((cga_line_t*)CGA_START, (cga_line_t*)CGA_START + 1, ROWS - 1);
|
||||
mmem::memcpy<cga_line_t>((cga_line_t*)CGA_START, (cga_line_t*)CGA_START + 1, ROWS - 1);
|
||||
|
||||
// Clear last line
|
||||
myzero<cga_line_t>((cga_line_t*)CGA_START + ROWS - 1);
|
||||
mmem::zero<cga_line_t>((cga_line_t*)CGA_START + ROWS - 1);
|
||||
}
|
||||
|
||||
/*****************************************************************************
|
||||
@ -165,7 +165,7 @@ void CGA::clear() {
|
||||
|
||||
/* Hier muess Code eingefuegt werden */
|
||||
|
||||
myzero<cga_page_t>((cga_page_t*)CGA_START);
|
||||
mmem::zero<cga_page_t>((cga_page_t*)CGA_START);
|
||||
this->setpos(0, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -2,22 +2,22 @@
|
||||
|
||||
// NOTE: I added this file
|
||||
|
||||
int mymin(int a, int b) {
|
||||
int mmath::min(int a, int b) {
|
||||
if (a < b) { return a; }
|
||||
return b;
|
||||
}
|
||||
|
||||
int mymax(int a, int b) {
|
||||
int mmath::max(int a, int b) {
|
||||
if (a < b) { return b; }
|
||||
return a;
|
||||
}
|
||||
|
||||
int myabs(int a) {
|
||||
int mmath::abs(int a) {
|
||||
if (a < 0) { return -a; }
|
||||
return a;
|
||||
}
|
||||
|
||||
int mypow(int a, unsigned int b) {
|
||||
int mmath::pow(int a, unsigned int b) {
|
||||
int result = 1;
|
||||
for (unsigned int i = 0; i < b; ++i) {
|
||||
result = result * a;
|
||||
|
||||
@ -3,10 +3,11 @@
|
||||
|
||||
// NOTE: I added this file
|
||||
|
||||
// TODO: namespace this
|
||||
int mymin(int, int);
|
||||
int mymax(int, int);
|
||||
int myabs(int);
|
||||
int mypow(int, unsigned int);
|
||||
namespace mmath {
|
||||
int min(int, int);
|
||||
int max(int, int);
|
||||
int abs(int);
|
||||
int pow(int, unsigned int);
|
||||
} // namespace mmath
|
||||
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "MyStdLib.h"
|
||||
|
||||
void mymemset(char* destination, char value, unsigned int bytes) {
|
||||
void mmem::memset(char* destination, char value, unsigned int bytes) {
|
||||
for (unsigned int byte = 0; byte < bytes; ++byte) {
|
||||
*(destination + byte) = value;
|
||||
}
|
||||
|
||||
@ -2,23 +2,24 @@
|
||||
#define __MYSTDLIB_INCLUDE_H_
|
||||
|
||||
// NOTE: I added this file
|
||||
// TODO: namespace this
|
||||
|
||||
template<typename T>
|
||||
void mymemcpy(T* destination, T* source, unsigned int count = 1) {
|
||||
for (unsigned int i = 0; i < count; ++i) {
|
||||
*(destination + i) = *(source + i);
|
||||
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 mymemset(char* destination, char value, unsigned int bytes);
|
||||
void memset(char* destination, char value, unsigned int bytes);
|
||||
|
||||
template<typename T>
|
||||
void myzero(T* destination) {
|
||||
mymemset((char*)destination, '\0', sizeof(T));
|
||||
}
|
||||
template<typename T>
|
||||
void zero(T* destination) {
|
||||
mmem::memset((char*)destination, '\0', sizeof(T));
|
||||
}
|
||||
|
||||
void mystrcpy(char* destination, char* source);
|
||||
unsigned int mystrlen(char* string);
|
||||
void strcpy(char* destination, char* source);
|
||||
unsigned int strlen(char* string);
|
||||
} // namespace mmem
|
||||
|
||||
#endif
|
||||
|
||||
@ -12,7 +12,7 @@ CGA::cga_line_t* ScrollbackBuffer::get_current_line() const {
|
||||
}
|
||||
|
||||
void ScrollbackBuffer::line_to_buffer(CGA::cga_line_t* line) {
|
||||
mymemcpy<CGA::cga_line_t>(this->get_current_line(), line);
|
||||
mmem::memcpy<CGA::cga_line_t>(this->get_current_line(), line);
|
||||
this->buffer_next_line();
|
||||
}
|
||||
|
||||
@ -40,22 +40,22 @@ void ScrollbackBuffer::copy_page_from_buffer(CGA::cga_line_t* destination, unsig
|
||||
unsigned int wrapline;
|
||||
for (unsigned int line = 0; line < this->pageheight; ++line) {
|
||||
wrapline = (this->current_linenumber + rpage * this->pageheight + line) % this->lines;
|
||||
mymemcpy<CGA::cga_line_t>(destination + line, this->buffer + wrapline);
|
||||
mmem::memcpy<CGA::cga_line_t>(destination + line, this->buffer + wrapline);
|
||||
}
|
||||
}
|
||||
|
||||
void ScrollbackBuffer::copy_page_from_pagebuffer(CGA::cga_page_t* destination) const {
|
||||
mymemcpy<CGA::cga_page_t>(destination, this->pagebuffer);
|
||||
mmem::memcpy<CGA::cga_page_t>(destination, this->pagebuffer);
|
||||
}
|
||||
|
||||
void ScrollbackBuffer::copy_page_to_pagebuffer(CGA::cga_page_t* source) {
|
||||
mymemcpy<CGA::cga_page_t>(this->pagebuffer, source);
|
||||
mmem::memcpy<CGA::cga_page_t>(this->pagebuffer, source);
|
||||
}
|
||||
|
||||
void ScrollbackBuffer::clear() {
|
||||
for (unsigned char page = 0; page < this->pages; ++page) {
|
||||
myzero<CGA::cga_page_t>((CGA::cga_page_t*)this->buffer + page);
|
||||
mmem::zero<CGA::cga_page_t>((CGA::cga_page_t*)this->buffer + page);
|
||||
}
|
||||
myzero<CGA::cga_page_t>(this->pagebuffer);
|
||||
mmem::zero<CGA::cga_page_t>(this->pagebuffer);
|
||||
this->current_linenumber = 0;
|
||||
}
|
||||
|
||||
@ -11,7 +11,10 @@
|
||||
class ScrollbackBuffer {
|
||||
private:
|
||||
CGA::cga_line_t* buffer; // Circular buffer to store lines that left the screen
|
||||
CGA::cga_page_t* pagebuffer; // Contains the current page separately from the scrollback
|
||||
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
|
||||
// (but only if it's less than a page)
|
||||
unsigned int current_linenumber;
|
||||
|
||||
CGA::cga_line_t* get_current_line() const; // Translate linenumber to memory location
|
||||
|
||||
Reference in New Issue
Block a user