blob: 33e4ceae61f2ad30f398fe566cb65833ce881374 (
plain)
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
|
#include "time.h"
#include <drivers/ps2kb.h>
#include <drivers/ps2mouse.h>
#include <panic.h>
#include <print.h>
#include <sys.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>
#include <term.h>
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();
arch_update();
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);
}
term_flush();
}
}
|