Adds basic Console class.
This commit is contained in:
parent
f85042a9c7
commit
9e3bfe3f82
5 changed files with 75 additions and 19 deletions
|
@ -4,7 +4,7 @@ CC=gcc
|
|||
CXX=g++
|
||||
LD=ld
|
||||
|
||||
FLAGS = -ffreestanding -m32 -Wall -iquote include
|
||||
FLAGS = -ffreestanding -m32 -Werror -Wall -iquote include
|
||||
ASFLAGS = $(FLAGS)
|
||||
CFLAGS = $(FLAGS)
|
||||
CXXFLAGS = $(FLAGS) -std=c++14 -fno-rtti -fno-exceptions -fno-leading-underscore -fno-use-cxa-atexit -nostdlib -fno-builtin
|
||||
|
|
31
prototypes/base/include/console.hpp
Normal file
31
prototypes/base/include/console.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
#pragma once
|
||||
|
||||
#include "screen.hpp"
|
||||
|
||||
class Console
|
||||
{
|
||||
public:
|
||||
static Console main;
|
||||
private:
|
||||
Screen * const screen;
|
||||
int x;
|
||||
int y;
|
||||
public:
|
||||
Console(Screen *screen);
|
||||
|
||||
void put(char c);
|
||||
|
||||
void newline();
|
||||
};
|
||||
|
||||
static inline Console operator << (Console & console, char c) {
|
||||
console.put(c);
|
||||
return console;
|
||||
}
|
||||
|
||||
static inline Console operator << (Console & console, const char *str) {
|
||||
while(*str) {
|
||||
console << *str++;
|
||||
}
|
||||
return console;
|
||||
}
|
|
@ -37,12 +37,13 @@ class Screen
|
|||
{
|
||||
private:
|
||||
static ScreenChar outOfScreen;
|
||||
private:
|
||||
ScreenChar * const buffer;
|
||||
const int width;
|
||||
const int height;
|
||||
public:
|
||||
static Screen main;
|
||||
private:
|
||||
ScreenChar * const buffer;
|
||||
public:
|
||||
const int width;
|
||||
const int height;
|
||||
public:
|
||||
Screen(ScreenChar *buffer, int width, int height);
|
||||
|
||||
|
|
|
@ -1,21 +1,10 @@
|
|||
#include <inttypes.h>
|
||||
|
||||
#include "screen.hpp"
|
||||
#include "console.hpp"
|
||||
#include "compat.h"
|
||||
|
||||
extern "C" void init(void)
|
||||
{
|
||||
const char hw[] = "Hello World!";
|
||||
int i;
|
||||
|
||||
// C-Strings haben ein Nullbyte als Abschluss
|
||||
for (i = 0; hw[i] != '\0'; i++) {
|
||||
|
||||
// Zeichen i in den Videospeicher kopieren
|
||||
Screen::main(i,0).c = hw[i];
|
||||
|
||||
// 0x07 = Hellgrau auf Schwarz
|
||||
Screen::main(i,0).fg = (int)Color::Black;
|
||||
Screen::main(i,0).bg = (int)Color::LightRed;
|
||||
}
|
||||
const char * hw = "Hello World!\nHello new line!";
|
||||
Console::main << hw;
|
||||
}
|
||||
|
|
35
prototypes/base/src/console.cpp
Normal file
35
prototypes/base/src/console.cpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
#include "console.hpp"
|
||||
|
||||
Console Console::main(&Screen::main);
|
||||
|
||||
Console::Console(Screen *screen) :
|
||||
screen(screen),
|
||||
x(0), y(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Console::put(char c)
|
||||
{
|
||||
switch(c) {
|
||||
|
||||
case '\r': break; /* ignore \r */
|
||||
case '\n':
|
||||
this->newline();
|
||||
break;
|
||||
default:
|
||||
ScreenChar &sc = (*this->screen)(this->x++, this->y);
|
||||
sc.c = c;
|
||||
sc.fg = (int)Color::Black;
|
||||
sc.bg = (int)Color::LightRed;
|
||||
break;
|
||||
}
|
||||
if(this->x >= this->screen->width) {
|
||||
this->newline();
|
||||
}
|
||||
}
|
||||
|
||||
void Console::newline() {
|
||||
this->x = 0;
|
||||
this->y += 1;
|
||||
}
|
Loading…
Reference in a new issue