added an actual Kobject and a tty driver

This commit is contained in:
Morten Delenk 2017-04-24 08:21:44 +00:00
parent b8d42f1506
commit c6d3d9e1de
3 changed files with 54 additions and 3 deletions

View file

@ -2,8 +2,9 @@
enum class kobjectType { enum class kobjectType {
POINTER, //Pointer to non-object POINTER, //Pointer to non-object
KOBJECT, //garbage collected kobject KOBJECT, //garbage collected kobject
TTY,
}; };
class Kobject { class Kref {
public: public:
kobjectType type; kobjectType type;
void *ptr; void *ptr;
@ -46,3 +47,29 @@ class Kobject {
return *this; return *this;
} }
}; };
class Kobject {
public:
KobjectType type;
unsigned int refctr;
Kobject(KobjectType type):type(type),refctr(1) {}
virtual ~Kobject() {
refctr=0;
}
virtual auto operator++() -> Kobject & {
unsigned int tmp=refctr;
refctr++;
if(refctr < tmp) {
//TODO panic("Refcounter overflow");
for(;;);
}
return *this;
}
virtual auto operator--() -> Kobject & {
refctr--;
if(refctr == 0) {
//TODO delete this;
return *((Kobject*)nullptr);
}
return *this;
}
}

View file

@ -1,4 +1,5 @@
#pragma once #pragma once
#include <kobject.h>
enum Color { enum Color {
BLACK, BLACK,
BLUE, BLUE,
@ -17,7 +18,7 @@ enum Color {
YELLOW, YELLOW,
WHITE WHITE
}; };
class TTY { class TTY: public Kobject {
protected: protected:
int x; int x;
int y; int y;

View file

@ -1,5 +1,5 @@
#include <tty.hpp> #include <tty.hpp>
TTY::TTY(int width, int height): x(0), y(0), width(width), height(height), curColor(WHITE), rgbColor(0xFFFFFF), useRGB(false) {} TTY::TTY(int width, int height): x(0), y(0), width(width), height(height), curColor(WHITE), rgbColor(0xFFFFFF), useRGB(false), Kobject(KobjectType::TTY) {}
TTY::~TTY() {} TTY::~TTY() {}
auto TTY::plotChar(int x, int y, int c) -> void {} auto TTY::plotChar(int x, int y, int c) -> void {}
auto TTY::rgbSupport() -> bool {return true;} auto TTY::rgbSupport() -> bool {return true;}
@ -11,6 +11,29 @@ auto TTY::setColor(unsigned int c) -> void {
rgbColor = c; rgbColor = c;
useRGB=true; useRGB=true;
} }
auto TTY::putChar(int c) -> void {
auto scroll = [this]()->void {
for(int x=0;x<this->width;x++)
for(int y=0;y<this->height;y++)
this->plotChar(x,y,0);
this->x=this->y=0;
};
switch(c) {
case '\n':
x=0;
y++;
if(y>=height)
scroll();
break;
default:
plotChar(x,y,c);
x++;
if(x>width)
y++;
if(y>=height)
scroll();
}
}
auto TTY::puts(const char *str) -> void { auto TTY::puts(const char *str) -> void {
for(int i=0;str[i];i++) { for(int i=0;str[i];i++) {
//Decode UTF-8 //Decode UTF-8