added an actual Kobject and a tty driver
This commit is contained in:
parent
b8d42f1506
commit
c6d3d9e1de
3 changed files with 54 additions and 3 deletions
|
@ -2,8 +2,9 @@
|
|||
enum class kobjectType {
|
||||
POINTER, //Pointer to non-object
|
||||
KOBJECT, //garbage collected kobject
|
||||
TTY,
|
||||
};
|
||||
class Kobject {
|
||||
class Kref {
|
||||
public:
|
||||
kobjectType type;
|
||||
void *ptr;
|
||||
|
@ -46,3 +47,29 @@ class Kobject {
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include <kobject.h>
|
||||
enum Color {
|
||||
BLACK,
|
||||
BLUE,
|
||||
|
@ -17,7 +18,7 @@ enum Color {
|
|||
YELLOW,
|
||||
WHITE
|
||||
};
|
||||
class TTY {
|
||||
class TTY: public Kobject {
|
||||
protected:
|
||||
int x;
|
||||
int y;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#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() {}
|
||||
auto TTY::plotChar(int x, int y, int c) -> void {}
|
||||
auto TTY::rgbSupport() -> bool {return true;}
|
||||
|
@ -11,6 +11,29 @@ auto TTY::setColor(unsigned int c) -> void {
|
|||
rgbColor = c;
|
||||
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 {
|
||||
for(int i=0;str[i];i++) {
|
||||
//Decode UTF-8
|
||||
|
|
Loading…
Reference in a new issue