Removed old C++ screen printing code

This commit is contained in:
2021-04-12 01:02:53 -05:00
parent bde2725b8f
commit 2d1d6574af
2 changed files with 0 additions and 185 deletions

View File

@@ -1,125 +0,0 @@
#include <stdbool.h>
#include "tty.hpp"
kernelns::TTY::TTY(char* vga)
{
this->vga = vga;
this->cursor = 0;
this->width = 0;
this->base = 10;
}
kernelns::TTY& kernelns::TTY::operator<<(kernelns::TTY::Format fmt)
{
switch(fmt)
{
case Binary:
base = 2;
break;
case Decimal:
base = 10;
break;
case Hex:
base = 16;
break;
}
}
kernelns::TTY& kernelns::TTY::operator<<(const char* str)
{
return printString(str);
}
kernelns::TTY& kernelns::TTY::operator<<(unsigned int n)
{
return printNumber(n, base, width);
}
kernelns::TTY& kernelns::TTY::operator<<(int n)
{
return printNumber((unsigned int) n, base, width);
}
kernelns::TTY& kernelns::TTY::operator<<(void* n)
{
return printNumber((unsigned int) n, 16, 8);
}
kernelns::TTY& kernelns::TTY::operator<<(char c)
{
return putChar(c);
}
void kernelns::TTY::setWidth(size_t width)
{
this->width = width;
}
size_t kernelns::TTY::getWidth()
{
return width;
}
void kernelns::TTY::clear()
{
for(int i = 0; i < 80*25; i++)
{
vga[i * 2] = ' ';
}
cursor = 0;
}
kernelns::TTY& kernelns::TTY::printNumber(unsigned int n, size_t base,
size_t width)
{
const char* digits = "0123456789ABCDEF";
char str[33];
size_t i = 1;
do
{
str[i] = digits[n % base];
n /= base;
i++;
} while(n > 0);
while(i <= width)
{
str[i] = '0';
i++;
}
str[0] = '\0';
for(char* s = str + (i - 1); *s; s--)
{
putChar(*s);
}
return *this;
}
kernelns::TTY& kernelns::TTY::printString(const char* str)
{
while(*str)
{
putChar(*str);
str++;
}
return *this;
}
kernelns::TTY& kernelns::TTY::putChar(char c)
{
switch(c)
{
case '\n':
cursor = (cursor + 80) - (cursor % 80);
break;
case '\t':
cursor = (cursor + 4) - (cursor % 4);
break;
case '\r':
cursor -= cursor % 160;
break;
default:
vga[cursor * 2] = c;
cursor++;
}
return *this;
}

View File

@@ -1,60 +0,0 @@
#ifndef TTY_H_
#define TTY_H_
#include <stddef.h>
namespace kernelns
{
class TTY
{
public:
enum Format
{
Binary,
Decimal,
Hex
};
TTY(char* vga);
TTY& operator<<(Format fmt);
TTY& operator<<(const char* str);
TTY& operator<<(unsigned int n);
TTY& operator<<(int n);
TTY& operator<<(void* n);
TTY& operator<<(char c);
void setWidth(size_t width);
size_t getWidth();
void clear();
private:
TTY& printNumber(unsigned int n, size_t base, size_t width);
TTY& printString(const char* str);
TTY& putChar(char c);
char* vga;
int cursor;
size_t width;
size_t base;
};
}
#endif