Add Console class
This commit is contained in:
parent
989118d8d3
commit
5f0c65bf81
2 changed files with 99 additions and 0 deletions
49
src/Console.cc
Normal file
49
src/Console.cc
Normal file
|
@ -0,0 +1,49 @@
|
|||
/* Console.cc
|
||||
* vim: set tw=80:
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
/**
|
||||
* Implementation of the Console class.
|
||||
*/
|
||||
|
||||
#include "Console.hh"
|
||||
|
||||
/** Create a VGA color pair. */
|
||||
static inline uint8_t
|
||||
makeVGAColor(Console::Color fg,
|
||||
Console::Color bg)
|
||||
{
|
||||
return fg | bg << 4;
|
||||
}
|
||||
|
||||
/** Create a VGA character entry. */
|
||||
static inline uint16_t
|
||||
makeVGAEntry(char c,
|
||||
uint8_t color)
|
||||
{
|
||||
uint16_t c16 = c;
|
||||
uint16_t color16 = color;
|
||||
return c16 | color16 << 8;
|
||||
}
|
||||
|
||||
|
||||
namespace kernel {
|
||||
|
||||
Console::Console()
|
||||
: mBase(0xB8000),
|
||||
mCursor({0, 0})
|
||||
{ }
|
||||
|
||||
|
||||
Console::clear(Console::Color color)
|
||||
{
|
||||
const uint16_t color = makeVGAColor(Color::LightGray, Color::Blue);
|
||||
for (size_t y = 0; y < Console::Height; y++) {
|
||||
for (size_t x = 0; x < Console::Width; x++) {
|
||||
const size_t index = y * Console::Width + x;
|
||||
mBase[index] = makeVGAEntry(' ', color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace kernel */
|
50
src/Console.hh
Normal file
50
src/Console.hh
Normal file
|
@ -0,0 +1,50 @@
|
|||
/* Console.hh
|
||||
* vim: set tw=80:
|
||||
* Eryn Wells <eryn@erynwells.me>
|
||||
*/
|
||||
/**
|
||||
* Declaration of the Console class. Presents an API for a VGA console.
|
||||
*/
|
||||
|
||||
namespace kernel {
|
||||
|
||||
struct Console
|
||||
{
|
||||
enum class Color {
|
||||
Black = 0,
|
||||
Blue = 1,
|
||||
Green = 2,
|
||||
Cyan = 3,
|
||||
Red = 4,
|
||||
Magenta = 5,
|
||||
Brown = 6,
|
||||
LightGray = 7,
|
||||
DarkGray = 8,
|
||||
LightBlue = 9,
|
||||
LightGreen = 10,
|
||||
LightCyan = 11,
|
||||
LightRed = 12,
|
||||
LightMagenta = 13,
|
||||
LightBrown = 14,
|
||||
White = 15
|
||||
};
|
||||
|
||||
struct Cursor
|
||||
{
|
||||
size_t row, col;
|
||||
};
|
||||
|
||||
static const size_t Width = 80;
|
||||
static const size_t Height = 25;
|
||||
|
||||
Console();
|
||||
|
||||
/** Clear the console to the provided color. */
|
||||
clear(Color color = Color::Black);
|
||||
|
||||
private:
|
||||
uint16_t *const mBase;
|
||||
Cursor mCursor;
|
||||
};
|
||||
|
||||
} /* namespace kernel */
|
Loading…
Add table
Add a link
Reference in a new issue