#include "console.h" #include "file.h" #include "drivers/tty.h" #include "drivers/console.h" #include "drivers/keyboard.h" file_operations_t tty_fops = { tty_open, /* open */ tty_openat, /* openat */ tty_read, /* read */ tty_write, /* write */ NULL, /* dir_next */ NULL, /* lseek */ NULL /* tell */ }; int tty_open(const char *pathname, int flags) { (void)pathname; (void)flags; return 0; } int tty_openat(file_t *file, file_t *handle, const char *fname, int flags) { (void)file; (void)handle; (void)fname; (void)flags; return 0; } ssize_t tty_read(file_t *file, char *buffer, size_t size) { ssize_t i = 0; static int state = 0; static char next[2]; (void)file; while (i < size) { if (state > 0) { buffer[i++] = next[--state]; continue; } char table[] = { '^', 0x1B, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '\\', '`', 0x08, '\t', 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', 'o', 'p', '?', '+', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', '?', '?', '#', 0, '<', 'y', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '-', 0, 0, 0, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'A' }; int scancode = std_kb->read(); if (scancode < 0) { break; } else if (scancode <= 60) { char c = scancode <= 60 ? table[scancode] : 0; if (c == 0) { continue; } buffer[i++] = c; } else if (scancode == 0xE0) { scancode = std_kb->read(); if (scancode > 0x48 || table[scancode] == 0) { continue; } buffer[i++] = '^'; next[1] = '['; next[0] = table[scancode]; state = 2; } } return i; } ssize_t tty_write(file_t *file, const char *buffer, size_t size) { (void)file; vga_con.write_n(buffer, size); return size; }