-
Notifications
You must be signed in to change notification settings - Fork 0
/
vga.cpp
103 lines (85 loc) · 1.74 KB
/
vga.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <vga.h>
#include <ascii.h>
#ifdef TEST_BUILD
#include <iostream>
#endif
namespace VGA
{
Vga Display;
size_t Vga::NextRow()
{
if (++m_Row == VGA_HEIGHT)
m_Row = 0;
do { // clear line
PutChar(Entry(ASCII::SPACE, m_Color), m_Row, m_Col++);
} while (m_Col != VGA_WIDTH);
m_Col = 0;
return m_Row;
}
size_t Vga::NextCol()
{
if (++m_Col == VGA_WIDTH) // wrap around display
{
m_Col = 0;
NextRow();
}
return m_Col;
}
void Vga::PutChar(unsigned char Char)
{
auto Put = [&](const char c)
{
PutChar(Entry(c, m_Color), m_Row, m_Col);
NextCol();
};
if (Char == '\n') // new line
{
m_Col = 0;
NextRow();
}
else if (Char == '\t') // tab
{
for (size_t i = 0; i < 3; ++i)
{
Put(ASCII::SPACE);
}
}
else
{
Put(Char);
}
}
void Vga::Fill(const VgaChar Char)
{
for (m_Row = 0; m_Row < VGA_HEIGHT; ++m_Row) {
for (m_Col = 0; m_Col < VGA_WIDTH; ++m_Col) {
PutChar(Char, m_Row, m_Col);
}
}
m_Row = 0;
m_Col = 0;
}
void Vga::Initialize()
{
SetColor(EntryColor(COLOR::LIGHT_GREY, COLOR::BLACK));
const auto Char = Entry(' ', m_Color);
Fill(Char);
}
void Vga::Puts(const char *Str)
{
#ifdef TEST_BUILD
std::cout << Str;
#else
for (size_t i = 0; i < Strlen(Str); ++i)
PutChar(Str[i]);
#endif
}
} // namespace VGA
namespace INIT
{
void VGA()
{
VGA::Display.Puts("KernOS - v0.2\n");
VGA::Display.Puts("Reticulating splines!\n");
}
}