summaryrefslogtreecommitdiff
path: root/kernel/src/main.c
blob: 2a04c24a69a54a3b871c48cf9922814f2d5e9369 (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
58
59
60
61
62
63
64
65
66
67
68
#include "acpi/acpi.h"
#include "boot/tag.h"
#include "cpu/cpu.h"
#include "drivers/ps2ctrl.h"
#include "drivers/ps2kb.h"
#include "drivers/ps2mouse.h"
#include "interrupt/idt.h"
#include "interrupt/pic.h"
#include "tty/cursor.h"
#include "tty/term.h"

#include <print.h>
#include <math.h>
#include <stdlib.h>
#include <sys.h>

static double x = 0, y = 0;

void kernel_main(void* boot_info) {
    
    term_init();
    cursor_enable();

    idt_init();
    pic_remap(PIC_REMAP_OFFSET);

    load_boot_info(boot_info);
    acpi_init();

    memory_init();

    ps2ctrl_init();
    ps2kb_init();
    ps2mouse_init();

    init_registers();

    while(1) {
        int_wait();

        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) {
            acpi_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);
        }
    }
}