-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconsole.c
68 lines (57 loc) · 1.31 KB
/
console.c
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
#include "console.h"
#include "fb.h"
static void Console_update_cursor(Console * console)
{
const word row = console->current_pos / 80;
const word col = console->current_pos % 80;
fb_set_cursor(row, col);
}
static void
Console_increment_cursor(Console * console, word count)
{
const word new_pos = console->current_pos + count;
console->current_pos = new_pos % FB_SIZE;
Console_update_cursor(console);
}
static void Console_newline(Console * console)
{
const word row = console->current_pos / 80;
if (row >= 24)
{
console->current_pos=0;
}
else
{
const word new_row = (row + 1) * 80;
console->current_pos = new_row;
}
}
void Console_init(Console * console)
{
console->current_pos = 0;
Console_reset(console);
}
void Console_write(Console * console, char * str)
{
word i = 0;
while (str[i] != (char)0)
{
Console_putchar(console, str[i++]);
}
}
void Console_writeln(Console * console, char * str)
{
Console_write(console, str);
Console_newline(console);
}
void Console_putchar(Console * console, char c)
{
fb_putchar(console->current_pos, c);
Console_increment_cursor(console, 1);
}
void Console_reset(Console * console)
{
fb_clear();
console->current_pos = 0;
// no cursor update required here
}