mirror of
https://github.com/Tom-on64/kern.git
synced 2026-11-03 18:22:22 +00:00
Added keyboard support (hell yeah)
This commit is contained in:
+2
-4
@@ -20,11 +20,9 @@ start:
|
|||||||
; Setup screen
|
; Setup screen
|
||||||
mov ax, 3 ; 80x25 Text mode
|
mov ax, 3 ; 80x25 Text mode
|
||||||
int 0x10
|
int 0x10
|
||||||
mov ah, 1 ; Hide cursor
|
|
||||||
mov cx, 0x2607
|
|
||||||
int 0x10
|
|
||||||
|
|
||||||
mov byte [0xb800], 'A'
|
mov si, msg
|
||||||
|
call puts
|
||||||
.read:
|
.read:
|
||||||
; Location
|
; Location
|
||||||
mov bx, KERNEL_LOC
|
mov bx, KERNEL_LOC
|
||||||
|
|||||||
@@ -9,8 +9,7 @@
|
|||||||
;; Calls the main function in 'main.c'
|
;; Calls the main function in 'main.c'
|
||||||
_start:
|
_start:
|
||||||
call main
|
call main
|
||||||
cli
|
jmp $ ;; If we used cli, hlt we wouldn't have interrupts :/
|
||||||
hlt
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
;; --- IDT ---
|
;; --- IDT ---
|
||||||
|
|||||||
@@ -31,6 +31,5 @@ void setupIdt() {
|
|||||||
idtp.base = (uint32_t)&idt;
|
idtp.base = (uint32_t)&idt;
|
||||||
|
|
||||||
idtLoad();
|
idtLoad();
|
||||||
sti();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -14,16 +14,16 @@ void uninstallIrqHandler(uint32_t irq) {
|
|||||||
|
|
||||||
// I have no clue how or what this does, but it makes everything work
|
// I have no clue how or what this does, but it makes everything work
|
||||||
void irqRemap(void) {
|
void irqRemap(void) {
|
||||||
outb(0xA0, 0x11);
|
outb(0xa0, 0x11);
|
||||||
outb(0x20, 0x11);
|
outb(0x20, 0x11);
|
||||||
outb(0x21, 0x20);
|
outb(0x21, 0x20);
|
||||||
outb(0xA1, 0x28);
|
outb(0xa1, 0x28);
|
||||||
outb(0x21, 0x04);
|
outb(0x21, 0x04);
|
||||||
outb(0xA1, 0x02);
|
outb(0xa1, 0x02);
|
||||||
outb(0x21, 0x01);
|
outb(0x21, 0x01);
|
||||||
outb(0xA1, 0x01);
|
outb(0xa1, 0x01);
|
||||||
outb(0x21, 0x0);
|
outb(0x21, 0x0);
|
||||||
outb(0xA1, 0x0);
|
outb(0xa1, 0x0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void irqHandler(struct regs* r) {
|
void irqHandler(struct regs* r) {
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
#include "keyboard.h"
|
||||||
|
#include "irq.h"
|
||||||
|
#include "idt.h"
|
||||||
|
#include "system.h"
|
||||||
|
#include "screen.h"
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
const char US_Keyboard[2][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, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
'7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.', // Numpad
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
0, 27, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', '\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, ' ', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
|
0, 0, 0, 0, 0, 0, 0, '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', '0', '.',
|
||||||
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
uint8_t shift = 0;
|
||||||
|
|
||||||
|
void keyboardHandler() {
|
||||||
|
uint8_t scancode;
|
||||||
|
scancode = inb(0x60);
|
||||||
|
|
||||||
|
if (scancode == LEFT_SHIFT_PRESS || scancode == RIGHT_SHIFT_PRESS) shift = 1;
|
||||||
|
else if (scancode == LEFT_SHIFT_RELEASE || scancode == RIGHT_SHIFT_RELEASE) shift = 0;
|
||||||
|
|
||||||
|
char c = US_Keyboard[shift][scancode];
|
||||||
|
|
||||||
|
if (scancode & 0x80) { // Keyup
|
||||||
|
} else if (c != 0) {
|
||||||
|
putc(c, 0x07);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
char* read(char terminator, uint8_t attr) {
|
||||||
|
// TODO: This
|
||||||
|
}
|
||||||
|
|
||||||
|
void setupKeyboard() {
|
||||||
|
installIrqHandler(1, keyboardHandler);
|
||||||
|
}
|
||||||
|
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
#ifndef KEYBOARD_H
|
||||||
|
#define KEYBOARD_H
|
||||||
|
|
||||||
|
#include "stdint.h"
|
||||||
|
|
||||||
|
// Keycodes
|
||||||
|
#define LEFT_SHIFT_PRESS 0x2a
|
||||||
|
#define LEFT_SHIFT_RELEASE (LEFT_SHIFT_PRESS | 0x80)
|
||||||
|
#define RIGHT_SHIFT_PRESS 0x36
|
||||||
|
#define RIGHT_SHIFT_RELEASE (RIGHT_SHIFT_PRESS | 0x80)
|
||||||
|
#define LEFT_CTRL_PRESS 0x1D
|
||||||
|
#define LEFT_CTRL_RELEASE (LEFT_CTRL_PRESS | 0x80)
|
||||||
|
#define RIGHT_CTRL_PRESS 0x1D
|
||||||
|
#define RIGHT_CTRL_RELEASE (RIGHT_CTRL_PRESS | 0x80)
|
||||||
|
#define LEFT_ALT_PRESS 0x38
|
||||||
|
#define LEFT_ALT_RELEASE (LEFT_ALT_PRESS | 0x80)
|
||||||
|
#define RIGHT_ALT_PRESS 0x38
|
||||||
|
#define RIGHT_ALT_RELEASE (RIGHT_ALT_PRESS | 0x80)
|
||||||
|
|
||||||
|
#define MAX_BUFFER_SIZE 256
|
||||||
|
|
||||||
|
void setupKeyboard();
|
||||||
|
char* read(char terminator, uint8_t attr);
|
||||||
|
|
||||||
|
#endif
|
||||||
+6
-1
@@ -2,14 +2,19 @@
|
|||||||
#include "idt.h"
|
#include "idt.h"
|
||||||
#include "isrs.h"
|
#include "isrs.h"
|
||||||
#include "irq.h"
|
#include "irq.h"
|
||||||
|
#include "keyboard.h"
|
||||||
|
#include "system.h"
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
// Interrupts
|
// Interrupts
|
||||||
setupIdt();
|
setupIdt();
|
||||||
setupIsrs();
|
setupIsrs();
|
||||||
setupIrqs();
|
setupIrqs();
|
||||||
|
sti();
|
||||||
|
|
||||||
|
setupKeyboard();
|
||||||
|
|
||||||
clear(0x0f);
|
clear(0x0f);
|
||||||
print("kern.\n", 0x0f);
|
print("kern.\n\n", 0x0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ void putc(char c, uint8_t attr) {
|
|||||||
uint16_t line = cursor - (cursor % COLS);
|
uint16_t line = cursor - (cursor % COLS);
|
||||||
setCursorPos(line + COLS);
|
setCursorPos(line + COLS);
|
||||||
return;
|
return;
|
||||||
|
} else if (c == '\b') {
|
||||||
|
cursor--;
|
||||||
|
int mem = VIDMEM + cursor * 2;
|
||||||
|
*(char*)(mem) = ' ';
|
||||||
|
*(char*)(mem+1) = attr;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mem = VIDMEM + cursor * 2;
|
int mem = VIDMEM + cursor * 2;
|
||||||
@@ -48,8 +54,10 @@ void clear(uint8_t attr) {
|
|||||||
*(char*)(VIDMEM + i) = ' ';
|
*(char*)(VIDMEM + i) = ' ';
|
||||||
*(char*)(VIDMEM + i + 1) = attr;
|
*(char*)(VIDMEM + i + 1) = attr;
|
||||||
}
|
}
|
||||||
|
cursor = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void printHex(uint8_t d, uint8_t attr) {
|
void printHex(uint8_t d, uint8_t attr) {
|
||||||
char hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
char hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
|
||||||
uint8_t low = d & 0x0f;
|
uint8_t low = d & 0x0f;
|
||||||
|
|||||||
Reference in New Issue
Block a user