From 2ae21b274aa8bcc53ff720dde4142aa3e050cb24 Mon Sep 17 00:00:00 2001 From: churl Date: Sun, 5 Jun 2022 15:25:52 +0200 Subject: [PATCH] update vorgabe04 --- c_os/devices/Keyboard.cc | 30 ++++++++++++-------------- c_os/devices/Keyboard.h | 16 +++++++------- c_os/kernel/interrupts/IntDispatcher.h | 2 +- c_os/lib/Input.cc | 24 +++++++++++++++++++++ c_os/lib/Input.h | 17 +++++++++++++++ 5 files changed, 64 insertions(+), 25 deletions(-) create mode 100644 c_os/lib/Input.cc create mode 100644 c_os/lib/Input.h diff --git a/c_os/devices/Keyboard.cc b/c_os/devices/Keyboard.cc index cf4bd40..fce3400 100755 --- a/c_os/devices/Keyboard.cc +++ b/c_os/devices/Keyboard.cc @@ -73,16 +73,18 @@ bool Keyboard::key_decoded() { gather.shift(false); break; case 56: - if (prefix == prefix1) + if (prefix == prefix1) { gather.alt_right(false); - else + } else { gather.alt_left(false); + } break; case 29: - if (prefix == prefix1) + if (prefix == prefix1) { gather.ctrl_right(false); - else + } else { gather.ctrl_left(false); + } break; } @@ -108,16 +110,18 @@ bool Keyboard::key_decoded() { gather.shift(true); break; case 56: - if (prefix == prefix1) + if (prefix == prefix1) { gather.alt_right(true); - else + } else { gather.alt_left(true); + } break; case 29: - if (prefix == prefix1) + if (prefix == prefix1) { gather.ctrl_right(true); - else + } else { gather.ctrl_left(true); + } break; case 58: gather.caps_lock(!gather.caps_lock()); @@ -153,10 +157,7 @@ bool Keyboard::key_decoded() { // Also ist es jetzt abgehandelt. prefix = 0; - if (done) - return true; // Tastaturabfrage abgeschlossen - else - return false; + return done; } /***************************************************************************** @@ -333,9 +334,8 @@ void Keyboard::plugin() { void scroll_mode(Key key); void Keyboard::trigger() { - // TODO: Get data from PS/2 Mouse if necessary - Key key = this->key_hit(); + this->lastkey = key.ascii(); // NOTE: My keyboard has no delete key... if (key.ctrl_left() && key.alt_left() && (char)key == 'r') { @@ -343,8 +343,6 @@ void Keyboard::trigger() { } else if ((char)key == 'k' || (char)key == 'j') { scroll_mode(key); } - - // TODO: Keyboard insert mode } // TODO: Where to place this? diff --git a/c_os/devices/Keyboard.h b/c_os/devices/Keyboard.h index ffb1551..ba70d0b 100755 --- a/c_os/devices/Keyboard.h +++ b/c_os/devices/Keyboard.h @@ -6,21 +6,19 @@ * Beschreibung: Treiber für den Tastaturcontroller des PCs. * * * * Autor: Olaf Spinczyk, TU Dortmund * - * Modifikationen, Michael Schoettner, 17.8.2016 * + * Modifikationen, Michael Schoettner, 2.6.2022 * *****************************************************************************/ #ifndef __Keyboard_include__ #define __Keyboard_include__ #include "devices/Key.h" -#include "kernel/interrupts/IntDispatcher.h" #include "kernel/interrupts/ISR.h" -#include "kernel/interrupts/PIC.h" #include "kernel/IOport.h" class Keyboard : public ISR { private: - Keyboard(const Keyboard& copy); // Verhindere Kopieren + Keyboard(const Keyboard& copy) = delete; // Verhindere Kopieren unsigned char code; // Byte von Tastatur unsigned char prefix; // Prefix von Tastatur @@ -73,13 +71,15 @@ private: // Ermittelt anhand von Tabellen den ASCII-Code. void get_ascii_code(); -public: - // Initialisierung der Tastatur. - Keyboard(); - // Tastaturabfrage (vorerst Polling) Key key_hit(); +public: + unsigned int lastkey; // speichert den ASCII-Code der zuletzt gedrückten Taste + + // Initialisierung der Tastatur. + Keyboard(); + // Fuehrt einen Neustart des Rechners durch. void reboot(); diff --git a/c_os/kernel/interrupts/IntDispatcher.h b/c_os/kernel/interrupts/IntDispatcher.h index 94bcd65..b933f9d 100755 --- a/c_os/kernel/interrupts/IntDispatcher.h +++ b/c_os/kernel/interrupts/IntDispatcher.h @@ -34,7 +34,7 @@ public: IntDispatcher(); // Registrierung einer ISR. (Rueckgabewert: 0 = Erfolg, -1 = Fehler) - int assign(unsigned int vector, ISR& gate); + int assign(unsigned int vector, ISR& isr); // ISR fuer 'vector' ausfuehren int report(unsigned int vector); diff --git a/c_os/lib/Input.cc b/c_os/lib/Input.cc new file mode 100644 index 0000000..616560f --- /dev/null +++ b/c_os/lib/Input.cc @@ -0,0 +1,24 @@ +/***************************************************************************** + * * + * I N P U T * + * * + *---------------------------------------------------------------------------* + * Beschreibung: Hilfsfunktion zum Warten bis auf der Tastatur die Ein- * + * -gabetaste gedrückt wird. * + * * + * Autor: Michael Schoettner, HHU, 2.05.2022 * + *****************************************************************************/ +#include "devices/Keyboard.h" +#include "kernel/Globals.h" + +void waitForReturn() { + // Warten bis gedrueckt wird + kb.lastkey = '\0'; // lastKey loeschen + while (kb.lastkey != 10) {}; +} + +char getch() { + kb.lastkey = '\0'; // lastKey loeschen + while (kb.lastkey == '\0') {}; + return kb.lastkey; +} diff --git a/c_os/lib/Input.h b/c_os/lib/Input.h new file mode 100644 index 0000000..b9e603a --- /dev/null +++ b/c_os/lib/Input.h @@ -0,0 +1,17 @@ +/***************************************************************************** + * * + * I N P U T * + * * + *---------------------------------------------------------------------------* + * Beschreibung: Hilfsfunktion zum Warten bis auf der Tastatur die Ein- * + * -gabetaste gedrückt wird. * + * * + * Autor: Michael Schoettner, HHU, 2.05.2022 * + *****************************************************************************/ +#ifndef __Input_include__ +#define __Input_include__ + +char getch(); +void waitForReturn(); + +#endif