-
Notifications
You must be signed in to change notification settings - Fork 1
/
kernel.c
81 lines (75 loc) · 1.49 KB
/
kernel.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <stdint.h>
#include "mem.h"
#include "uart.h"
#include "framebuffer.h"
static uint32_t x = 0;
static uint32_t y = 0;
void halt()
{
while(1){}
}
void tty_write(uint8_t chr)
{
uart_write(chr);
if(chr == '\b'){
uart_write(' ');
uart_write('\b');
x-=8;
draw_char(' ', x, y);
} else if(chr == '\n'){
x=0;
y+=16;
} else {
draw_char(chr, x, y);
x+=8;
}
}
void puts(uint8_t *str)
{
uint8_t chr;
while(chr = *str++)
{
tty_write(chr);
}
tty_write('\n');
}
uint8_t *gets(uint8_t *str, size_t len)
{
uint8_t *current_chr = str;
while(1){
uint8_t input_chr = uart_read();
switch(input_chr){
case '\r':
case '\n':
tty_write('\n');
return str;
case '\b':
case 0x7F:
if(current_chr > str) {
tty_write('\b');
current_chr--;
*current_chr = '\0';
}
break;
default:
if(current_chr >= str+len-1)
continue;
tty_write(input_chr);
*current_chr = input_chr;
current_chr++;
break;
}
}
}
void kmain()
{
uart_init();
if(!fb_init(1920, 1080))
halt();
uint8_t line[241] = {0};
while(1){
puts(gets(line, 241));
memset(line, 0, 241);
}
halt();
}