#include "time.h" #include #include #include #include #include #include #include #include #include #include #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(); } }