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
|
#include "time.h"
#include <drivers/ps2kb.h>
#include <drivers/ps2mouse.h>
#include <panic.h>
#include <print.h>
#include <stddef.h>
#include <arch.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <term.h>
#define WIDTH 30
static char buf[WIDTH];
static double x = 0, y = 0;
void kernel_main(void *boot_info) {
term_init();
arch_init(boot_info);
ps2kb_init();
ps2mouse_init();
set_timezone(EST);
while(1) {
arch_wait_int();
struct Keycode code = ps2kb_get();
if(code.key != KEY_NONE) {
if(code.flags & KC_FLAG_ERROR) {
printk("error: %X\n", code.key);
} else if(code.flags & KC_FLAG_KEY_DOWN) {
printk("pressed: %X\n", code.key);
} else {
printk("released: %X\n", code.key);
}
}
if (code.key == KEY_ESCAPE) {
arch_poweroff();
}
struct MouseEvent event = ps2mouse_get();
if (event.updated) {
putchar(event.lmb ? 'L' : '_');
putchar(event.rmb ? 'R' : '_');
putchar(event.mmb ? 'M' : '_');
x += event.relx / 10.0;
y -= event.rely / 10.0;
x = fclamp(x, 0, TERM_W);
y = fclamp(y, 0, TERM_H);
printk(" x%d y%d\n", (int)x, (int)y);
}
uint32_t state = term_save();
term_setfg(VGA_LIGHT_GREEN);
term_setpos(TERM_W - WIDTH - 1, 0);
for (size_t i = 0; i < WIDTH; i++) putchar(' ');
term_setpos(TERM_W - WIDTH - 1, 0);
struct Time t = get_localtime();
timetostr(&t, "%a %b %d %Y %H:%M:%S", buf, WIDTH);
printk("%s", buf);
term_load(state);
arch_update();
term_flush();
}
}
|