-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.c
More file actions
60 lines (48 loc) · 1.13 KB
/
Copy pathconsole.c
File metadata and controls
60 lines (48 loc) · 1.13 KB
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
/* SPDX-License-Identifier: MIT */
#include <stdint.h>
#define FB (0xb8000 + KERNEL_VMA_BASE)
#define TAB_SIZE 4
static uint8_t cur_x = 0;
static uint8_t cur_y = 0;
void put_char(uint8_t c, uint8_t fg, uint8_t bg, uint32_t x, uint32_t y)
{
uint8_t attrib = (bg << 4) | (fg & 0xf);
volatile uint16_t *video = (volatile uint16_t *)FB + (cur_y * 80 + cur_x);
switch (c) {
case '\t':
cur_x += TAB_SIZE;
if (cur_x >= 80) {
cur_x = 0;
cur_y++;
}
break;
case '\r':
cur_x = 0;
break;
case '\n':
cur_y++;
break;
case '\b':
cur_x--;
*video = ' ';
break;
default:
*video = c | (attrib << 8);
cur_x++;
if (cur_x == 80) {
cur_y++;
cur_x = 0;
}
}
}
void put_str(char *str, uint8_t forecolor, uint8_t backcolor)
{
while (*str != 0) {
put_char(*str++, forecolor, backcolor, cur_x, cur_y);
}
}
void platform_init_console(void)
{
put_str("Rix (build 0.0.1)\n\r", 0xf, 0x0);
put_str("Welcome to Rix kernel!", 0xf, 0x0);
}