mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Continuing terminal I/O
- Made stdio.h work - Moved printFiletable back into kernel.c - TODO: Add stdio.h to all files that should use it (probably next commmit) - Added some more global addresses. There's a memory layout, but i'm not using it - Got cursor to be drawn - Calc program now gets user input
This commit is contained in:
@@ -3,66 +3,37 @@
|
||||
|
||||
#include <interrupt/idt.h>
|
||||
#include <interrupt/pic.h>
|
||||
#include <screen/text.h>
|
||||
#include <keyboard/keys.h>
|
||||
#include <memory/addresses.h>
|
||||
#include <stdio.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define MAX_INPUT_LENGTH 256
|
||||
|
||||
typedef struct {
|
||||
char character;
|
||||
uint8_t shift;
|
||||
bool shift;
|
||||
} keyboardState_t;
|
||||
|
||||
// TODO: Put at set address
|
||||
keyboardState_t keyboard;
|
||||
keyboardState_t* keyboard = (keyboardState_t*)KEYBOARD_STATE_LOC;
|
||||
|
||||
__attribute__ ((interrupt))
|
||||
void keyboardHandler(intFrame_t* iframe) { // TODO: Make this better and be able to read multi-byte scancode
|
||||
uint8_t scancode = inb(0x60);
|
||||
char c = US_Keyboard[keyboard.shift][scancode];
|
||||
char c = US_Keyboard[keyboard->shift][scancode];
|
||||
|
||||
if (scancode == LEFT_SHIFT_PRESS || scancode == RIGHT_SHIFT_PRESS) {
|
||||
keyboard.shift = 1;
|
||||
keyboard->shift = true;
|
||||
} else if (scancode == LEFT_SHIFT_RELEASE || scancode == RIGHT_SHIFT_RELEASE) {
|
||||
keyboard.shift = 0;
|
||||
keyboard->shift = false;
|
||||
}
|
||||
|
||||
if (scancode & 0x80) { // Keyup
|
||||
} else if (c != '\0') {
|
||||
keyboard.character = c;
|
||||
keyboard->character = c;
|
||||
}
|
||||
|
||||
sendPicEOI(1);
|
||||
}
|
||||
|
||||
char getc() {
|
||||
keyboard.character = '\0';
|
||||
while (keyboard.character == '\0') { __asm__ volatile ("hlt"); }
|
||||
return keyboard.character;
|
||||
}
|
||||
|
||||
// Reads until a newline
|
||||
void read(char* buffer) {
|
||||
char c;
|
||||
uint8_t len = 0;
|
||||
|
||||
while ((c = getc()) != '\n') {
|
||||
if (c == '\b') {
|
||||
if (len < 1) continue; // Can we backspace?
|
||||
len--;
|
||||
putc(c);
|
||||
} else if (len + 1 != MAX_INPUT_LENGTH) { // Check if we can add a new character (this method avoids overflow issues)
|
||||
buffer[len++] = c;
|
||||
putc(c);
|
||||
}
|
||||
}
|
||||
|
||||
buffer[len++] = c; // Add newline
|
||||
putc(c);
|
||||
buffer[len] = '\0'; // Null terminate
|
||||
}
|
||||
|
||||
void setupKeyboard() {
|
||||
idtSetGate(0x21, keyboardHandler, INT_GATE_FLAGS);
|
||||
unsetIrqMask(1);
|
||||
|
||||
Reference in New Issue
Block a user