forked from Brunoo16/cpp-kernel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kernel.cpp
77 lines (67 loc) · 1.97 KB
/
kernel.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
#include "kernel.h"
Kernel::Kernel()
{
this->video_buffer = reinterpret_cast<unsigned short*>(Addresses::video_memory_color);
this->ClearVideoBuffer(VIDEO_COLOR_TABLE::WHITE);
}
unsigned short Kernel::VideoEntry(const unsigned char character, const unsigned char color)
{
return static_cast<unsigned short>(character) | color << 8;
}
void Kernel::ClearVideoBuffer(const unsigned char color)
{
for(unsigned char i = 0; i < VIDEO_HEIGHT; ++i)
{
for(unsigned char j = 0; j < VIDEO_WIDTH; ++j)
{
this->video_buffer[i * VIDEO_WIDTH + j] = this->VideoEntry(' ', color);
}
}
this->current_line = 0;
this->current_pos = 0;
}
void Kernel::PrintString(const char* str, const unsigned char color)
{
unsigned long length = 0;
while(str[length])
{
if(str[length] == '\n')
{
this->current_line++;
this->current_pos = VIDEO_WIDTH * this->current_line - 1;
}
else
{
this->video_buffer[(this->current_line * VIDEO_WIDTH + this->current_pos)] = this->VideoEntry(str[length], color);
}
if(++this->current_pos == VIDEO_WIDTH)
{
this->current_pos = 0;
if(++this->current_line == VIDEO_HEIGHT)
{
this->current_line = 0;
}
}
length++;
}
}
void Kernel::PrintCharacter(const char character, const unsigned char color)
{
if(character == '\n')
{
this->current_line++;
this->current_pos = VIDEO_WIDTH * this->current_line - 1;
}
else
{
this->video_buffer[(this->current_line * VIDEO_WIDTH + this->current_pos)] = this->VideoEntry(character, color);
}
if(++this->current_pos == VIDEO_WIDTH)
{
this->current_pos = 0;
if(++this->current_line == VIDEO_HEIGHT)
{
this->current_line = 0;
}
}
}