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
|
#include <stdint.h>
#include <stddef.h>
#include <toxic/vga.h>
#include <toxic/string.h>
struct vga_display display;
void
vga_set_color(uint16_t c)
{
display.color = c;
}
void
vga_set_pos(size_t r, size_t c)
{
display.row = r;
display.col = c;
}
static uint16_t
vga_build_char(char c, char color)
{
return (uint16_t)((color << 8) | c);
}
void
vga_put_char(size_t row, size_t col, char c, uint16_t color)
{
size_t pos = (VGA_WIDTH * row) + col;
display.buf[pos] = vga_build_char(c, color);
}
void
vga_write_char(char c)
{
switch (c) {
case '\n':
vga_set_pos(++display.row, 0);
break;
default:
vga_put_char(display.row, display.col, c, display.color);
display.col++;
}
if (display.col == VGA_WIDTH)
vga_set_pos(++display.row, 0);
}
void
vprintl(char *str)
{
int i = 0;
size_t len = strlen(str);
for (i = 0; i <= len; i++) {
vga_write_char(str[i]);
}
}
static void
clean_display(void)
{
int row, col;
for (row = 0; row < VGA_HEIGHT; row++)
for (col = 0; col < VGA_WIDTH; col++)
vga_put_char(row, col, ' ', 0);
}
void
init_display(uint16_t color)
{
display.buf = (uint16_t *)VGA_ADDRESS;
vga_set_pos(0, 0);
clean_display();
vga_set_color(color);
vga_set_pos(0, 0);
}
|