Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394#include "print.h"
unsigned char kbd_us[128] = { 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*', 0, ' '};
static inline unsigned char inb(unsigned short port) { unsigned char ret; asm volatile ("inb %1, %0" : "=a"(ret) : "Nd"(port)); return ret;}
static inline void outb(unsigned short port, unsigned char val) { asm volatile ("outb %0, %1" : : "a"(val), "Nd"(port));}
char command_buffer[64];int buffer_i = 0;
int is_command(char* str) { int i = 0; while (str[i] != '\0') { if (command_buffer[i] != str[i]) return 0; i++; } return (command_buffer[i] == '\0');}
void kernel_main() { print_clear(); print_set_color(PRINT_COLOR_YELLOW, PRINT_COLOR_BLACK); print_str("Lupey-Kernel Loaded.\nType 'help' for commands.\n\n"); print_str("Lupey-Kernel > ");
while (1) { if (inb(0x64) & 0x01) { unsigned char scancode = inb(0x60);
if (scancode & 0x80) continue;
if (scancode < 128 && kbd_us[scancode] != 0) { char letter = kbd_us[scancode];
if (scancode == 0x1C) { // Enter command_buffer[buffer_i] = '\0'; print_str("\n");
if (is_command("clear")) { print_clear(); } else if (is_command("hello")) { print_str("Hello World!\n"); else if (is_command("cow")) { print_str("\|/ (__) ") print_str("`\------(oo)") print_str("|| (__)") print_str("||w--||\|/") print_str("\|/") } } else if (is_command("help")) { print_str("Commands: clear, hello, help, reboot\n"); } else if (is_command("reboot")) { // reset cpu print_str("Rebooting..."); unsigned char good = 0x02; while (good & 0x02) good = inb(0x64); outb(0x64, 0xFE); } else if (buffer_i > 0) { print_str("Unknown command.\n"); }
print_str("Lupey-Kernel > "); buffer_i = 0; } else if (scancode == 0x0E) { // Backspace if (buffer_i > 0) { buffer_i--; command_buffer[buffer_i] = '\0'; print_char('\b'); } } else { // Characters if (buffer_i < 63) { command_buffer[buffer_i++] = letter; char str[2] = {letter, '\0'}; print_str(str); } } } } }}