remove 64 bit for now
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
#include "print.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define KEYBOARD_DATA_PORT 0x60
|
||||
#define KEYBOARD_STATUS_PORT 0x64
|
||||
|
||||
static char scancode_to_ascii[] = { 0, 0, '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 char input_buffer[256];
|
||||
static int buffer_index = 0;
|
||||
static bool key_available = false;
|
||||
|
||||
static uint8_t inb(uint16_t port)
|
||||
{
|
||||
uint8_t result;
|
||||
__asm__ volatile("inb %1, %0" : "=a"(result) : "Nd"(port));
|
||||
return result;
|
||||
}
|
||||
|
||||
void keyboard_handler(void)
|
||||
{
|
||||
uint8_t scancode = inb(KEYBOARD_DATA_PORT);
|
||||
|
||||
if (scancode & 0x80)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (scancode < sizeof(scancode_to_ascii))
|
||||
{
|
||||
char ascii = scancode_to_ascii[scancode];
|
||||
if (ascii)
|
||||
{
|
||||
if (ascii == '\b')
|
||||
{
|
||||
if (buffer_index > 0)
|
||||
{
|
||||
buffer_index--;
|
||||
print("\b \b");
|
||||
}
|
||||
}
|
||||
else if (ascii == '\n')
|
||||
{
|
||||
input_buffer[buffer_index] = '\0';
|
||||
print("\n");
|
||||
key_available = true;
|
||||
}
|
||||
else if (buffer_index < 255)
|
||||
{
|
||||
input_buffer[buffer_index++] = ascii;
|
||||
char str[2] = { ascii, '\0' };
|
||||
print(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
char* keyboard_get_line(void)
|
||||
{
|
||||
buffer_index = 0;
|
||||
key_available = false;
|
||||
|
||||
while (!key_available)
|
||||
{
|
||||
__asm__ volatile("hlt");
|
||||
}
|
||||
|
||||
return input_buffer;
|
||||
}
|
||||
|
||||
void keyboard_init(void)
|
||||
{
|
||||
__asm__ volatile("sti");
|
||||
print_clr("[success]", FG_GREEN, BG_BLACK);
|
||||
print(" keyboard initialized\n");
|
||||
}
|
||||
Reference in New Issue
Block a user