From 25ee3336c861088c2a3ff7ec43f4aa230f6b3745 Mon Sep 17 00:00:00 2001 From: Morten Delenk Date: Thu, 15 Oct 2015 20:14:04 +0200 Subject: [PATCH] Created a german keymap for the keyboard driver. --- kernel/hal/x86/include/keyboard.hpp | 1 + kernel/hal/x86/include/keycodes.hpp | 41 +++++++++++++++++++++++++ kernel/hal/x86/include/keymap_DE.hpp | 17 +++++++++++ kernel/hal/x86/init/idt.cpp | 6 ++-- kernel/hal/x86/init/init.cpp | 2 +- kernel/hal/x86/io/keyboard.cpp | 45 +++++++++++++++++++++++++++- kernel/hal/x86/io/textDISP.cpp | 9 ++++-- 7 files changed, 114 insertions(+), 7 deletions(-) create mode 100644 kernel/hal/x86/include/keycodes.hpp create mode 100644 kernel/hal/x86/include/keymap_DE.hpp diff --git a/kernel/hal/x86/include/keyboard.hpp b/kernel/hal/x86/include/keyboard.hpp index 9765faf..6c03f6a 100644 --- a/kernel/hal/x86/include/keyboard.hpp +++ b/kernel/hal/x86/include/keyboard.hpp @@ -5,6 +5,7 @@ #include #include namespace MTGosHAL { + class Keyboard: public Input { private: //This kernel has a buffer of 16 chars diff --git a/kernel/hal/x86/include/keycodes.hpp b/kernel/hal/x86/include/keycodes.hpp new file mode 100644 index 0000000..c79a76f --- /dev/null +++ b/kernel/hal/x86/include/keycodes.hpp @@ -0,0 +1,41 @@ +#ifndef _KEYCODES_HPP +#define _KEYCODES_HPP +bool keydowns[0x69]; +uint8_t keyboardKeycodes[2][128] { + { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, + 0x50, 0x51, 0x52, 0x53, 0x00, 0x00, 0x54, 0x55, + 0x56, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + }, { + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x57, 0x58, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x59, 0x00, 0x00, + 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x5B, + 0x5C, 0x5D, 0x00, 0x5E, 0x00, 0x5F, 0x00, 0x60, + 0x61, 0x62, 0x63, 0x64, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x64, 0x65, 0x66, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + } +}; +#endif + diff --git a/kernel/hal/x86/include/keymap_DE.hpp b/kernel/hal/x86/include/keymap_DE.hpp new file mode 100644 index 0000000..1249854 --- /dev/null +++ b/kernel/hal/x86/include/keymap_DE.hpp @@ -0,0 +1,17 @@ +#ifndef _KEYMAP_DE_HPP +#define _KEYMAP_DE_HPP +#include +#define SHIFT 1 +#define CTRL 2 +#define ALT 4 +char keymap[8][0x80] = { + "\0\0001234567890\xe1\xa7\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\000789-456+1230,<\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // No modifier + "\0\000!\"§$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Shift modifier + "\0\0001234567890\xe1\xa7\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control modifier + "\0\000!\"§$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers + "\0\0001234567890\xe1\xa7\b\0qwertzuiop\x81+\n\0asdfghjkl\x94\x84^\0#yxcvbnm,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,<\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt modifier + "\0\000!\"§$%&/()=?`\b\0QWERTZUIOP\x9A*\n\0ASDFGHJKL\x99\x8e\xF8\0'YXCVBNM;:_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,>\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Alt+Shift modifiers + "\0\0001\xFD\x33\xAC\xAB\xAA{[]}\\\xa7\b\0@w\xEErtzui\xEDp\x81~\n\0\x91sdfghjkl\x94^\0#\xAF\xAE\x9Bvbn\xe6,.-\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Alt modifiers + "\0\000\xAD\"\x9C\x0F%&/(\xF1\xF8\xA8`\b\0\xEAW\xEERT\x9DUIOP\xF8*\n\0\x92SD\xA6GHJ&L\x99\x8e\xF8\0|YXCVBN\xF8;\xF6_\0*\0 \0\0\0\0\0\0\0\0\0\0\0\0\0789-456+1230,|\0\0\n\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", // Control+Shift modifiers +}; +#endif diff --git a/kernel/hal/x86/init/idt.cpp b/kernel/hal/x86/init/idt.cpp index a76ef03..1479ce1 100644 --- a/kernel/hal/x86/init/idt.cpp +++ b/kernel/hal/x86/init/idt.cpp @@ -31,7 +31,7 @@ namespace MTGosHAL { loadIDT((void*)&idtptr); } auto IDT::handle(struct cpu_state* cpu) -> void { - debug << "Interrupt 0x" << Base::HEXADECIMAL << (int) cpu->intr << " was raised.\n"; + //debug << "Interrupt 0x" << Base::HEXADECIMAL << (int) cpu->intr << " was raised.\n"; if(cpu->intr<=0x1F) { out << "Exception 0x" << Base::HEXADECIMAL << (int) cpu->intr << "! Kernel halted!\n"; while(1) { @@ -42,9 +42,9 @@ namespace MTGosHAL { outb(0xA0, 0x20); } outb(0x20, 0x20); - debug << "The IRQ " << Base::DECIMAL << (int) cpu->intr-0x20 << " was handled.\n"; + //debug << "The IRQ " << Base::DECIMAL << (int) cpu->intr-0x20 << " was handled.\n"; if(cpu->intr==0x20) { - debug.debug(); + //debug.debug(); } } for(int i=0;i<16;i++) { diff --git a/kernel/hal/x86/init/init.cpp b/kernel/hal/x86/init/init.cpp index 9c54d50..4dd80bf 100644 --- a/kernel/hal/x86/init/init.cpp +++ b/kernel/hal/x86/init/init.cpp @@ -16,7 +16,7 @@ namespace MTGosHAL { void main() { out << BG_color::BLACK << FG_color::WHITE << "Loading MTGos...\n"; err << BG_color::BLACK << FG_color::RED; - debug << "Hello debugger! This is MTGos version 0.0\nThese logs are probably very long, so please redirect the output to a file.\n"; + debug << "Hello debugger! This is MTGos v00r01\nThese logs are probably very long, so please redirect the output to a file.\n"; gdt.setEntry(0, 0, 0, 0); gdt.setEntry(1, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_CODESEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT); gdt.setEntry(2, 0, 0xfffff, GDT_FLAG_SEGMENT | GDT_FLAG_32_BIT | GDT_FLAG_DATASEG | GDT_FLAG_4K_GRAN | GDT_FLAG_PRESENT); diff --git a/kernel/hal/x86/io/keyboard.cpp b/kernel/hal/x86/io/keyboard.cpp index 3087864..7a52a22 100644 --- a/kernel/hal/x86/io/keyboard.cpp +++ b/kernel/hal/x86/io/keyboard.cpp @@ -2,6 +2,7 @@ #include #include #include +#include namespace MTGosHAL { auto Keyboard::getChar() -> char { char chr=buf[0]; @@ -18,7 +19,49 @@ namespace MTGosHAL { outb(0x60, command); } auto Keyboard::handleIRQ1(struct cpu_state* cpu) -> void { - debug << "Keyboard interrupt received.\nGot: 0x" << Base::HEXADECIMAL << (int) inb(0x60) << ".\n"; + uint8_t keycode=0,scancode=inb(0x60); + bool break_code=false; + static bool e0_code=false; + static int e1_code=0; + static uint16_t e1_prev=0; + if((scancode & 0x80 ) && (e1_code || (scancode != 0xE1)) && (e0_code || (scancode != 0xE0))) { + break_code = true; + scancode &= ~0x80; + } + if(e0_code) { + if((scancode==0x2A) || (scancode = 0x36)) { + e0_code = false; + return; + } + keycode=keyboardKeycodes[1][scancode]; + e0_code=false; + } else if (e1_code == 2) { + e1_prev |= ((uint16_t) scancode << 8); + //TODO. translate it, although I might not even use this code + return; + } else if (e1_code) { + e1_prev = scancode; + e1_code++; + return; + } else if (scancode == 0xE0) { + e0_code = true; + return; + } else if (scancode == 0xE1) { + e1_code = true; + return; + } else { + keycode=keyboardKeycodes[0][scancode]; + } + //Now put it into the keystate array + if(break_code) + keydowns[keycode]=false; + else + keydowns[keycode]=true; + //Convert it into a char + if(!break_code) + out << keymap[0][keycode]; + //TODO add checking for shift, and so on + debug << "Keyboard interrupt received.\nGot: 0x" << Base::HEXADECIMAL << (int)scancode << " -> 0x" << (int)keycode << ".\n"; } Keyboard::Keyboard(): shift(false), numlock(true), caps(false), scrollock(false) { if(!idt.request(0x21, (void(*)(struct cpu_state*))&MTGosHAL::Keyboard::handleIRQ1)) { diff --git a/kernel/hal/x86/io/textDISP.cpp b/kernel/hal/x86/io/textDISP.cpp index 4970f83..a32f6e8 100644 --- a/kernel/hal/x86/io/textDISP.cpp +++ b/kernel/hal/x86/io/textDISP.cpp @@ -9,14 +9,19 @@ namespace MTGosHAL { break; case '\r': x=0; + break; - case 0x7F: + case '\b': x--; if(x<0) x=0; + putChar(' '); + x--; + if(x<0) x=0; + break; case '\0': break; default: - vmem[y*SCREEN_WIDTH+(x++)]=((uint16_t)fg) | ((uint16_t)bg) | ((uint16_t)c); + vmem[y*SCREEN_WIDTH+(x++)]=((uint16_t)fg) | ((uint16_t)bg) | ((uint8_t)c); if(x==SCREEN_WIDTH) { x=0; y++; }