From c6d3d9e1dedd6012ee3f737843237e33e6534d1e Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Mon, 24 Apr 2017 08:21:44 +0000 Subject: [PATCH] added an actual Kobject and a tty driver --- kernel/src/include/kobject.hpp | 29 ++++++++++++++++++++++++++++- kernel/src/include/tty.hpp | 3 ++- kernel/src/tty.cpp | 25 ++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/kernel/src/include/kobject.hpp b/kernel/src/include/kobject.hpp index 0a13c19..5c14d5d 100644 --- a/kernel/src/include/kobject.hpp +++ b/kernel/src/include/kobject.hpp @@ -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; + } +} diff --git a/kernel/src/include/tty.hpp b/kernel/src/include/tty.hpp index f76a0a5..769b96c 100644 --- a/kernel/src/include/tty.hpp +++ b/kernel/src/include/tty.hpp @@ -1,4 +1,5 @@ #pragma once +#include enum Color { BLACK, BLUE, @@ -17,7 +18,7 @@ enum Color { YELLOW, WHITE }; -class TTY { +class TTY: public Kobject { protected: int x; int y; diff --git a/kernel/src/tty.cpp b/kernel/src/tty.cpp index 05d2c67..b0d1110 100644 --- a/kernel/src/tty.cpp +++ b/kernel/src/tty.cpp @@ -1,5 +1,5 @@ #include -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;xwidth;x++) + for(int y=0;yheight;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