diff --git a/source/Cosmos/Cosmos.Hardware/Interrupts.cs b/source/Cosmos/Cosmos.Hardware/Interrupts.cs index 16517840c..77c37b6af 100644 --- a/source/Cosmos/Cosmos.Hardware/Interrupts.cs +++ b/source/Cosmos/Cosmos.Hardware/Interrupts.cs @@ -67,7 +67,7 @@ namespace Cosmos.Hardware { //IRQ 1 - Keyboard. Reserved for the system. Cannot be altered even if no keyboard is present or needed. public static unsafe void HandleInterrupt_21(InterruptContext* aContext) { - byte xScanCode = IORead(0x60); + Keyboard.HandleKeyboardInterrupt(); PIC.SignalPrimary(); } diff --git a/source/Cosmos/Cosmos.Hardware/Keyboard.cs b/source/Cosmos/Cosmos.Hardware/Keyboard.cs index 574c3cd3e..5a8c17008 100644 --- a/source/Cosmos/Cosmos.Hardware/Keyboard.cs +++ b/source/Cosmos/Cosmos.Hardware/Keyboard.cs @@ -3,6 +3,19 @@ using System.Collections.Generic; using System.Text; namespace Cosmos.Hardware { - public class Keyboard : Hardware { - } + public delegate void HandleKeyboardDelegate(byte aScanCode, bool aReleased); + public class Keyboard: Hardware { + private static HandleKeyboardDelegate mHandleKeyboardKey; + public static void Initialize(HandleKeyboardDelegate aHandleKeyboardKeyDelegate) { + mHandleKeyboardKey = aHandleKeyboardKeyDelegate; + } + + internal static void HandleKeyboardInterrupt() { + if (mHandleKeyboardKey != null) { + //mHandleKeyboardKey( + byte xScanCode = IORead(0x60); + mHandleKeyboardKey(xScanCode, (xScanCode & 0x80) == 0x80); + } + } + } } diff --git a/source/Cosmos/Cosmos.Kernel/DebugUtil.cs b/source/Cosmos/Cosmos.Kernel/DebugUtil.cs index f2ba8dd5b..bf7ec5b9b 100644 --- a/source/Cosmos/Cosmos.Kernel/DebugUtil.cs +++ b/source/Cosmos/Cosmos.Kernel/DebugUtil.cs @@ -26,6 +26,20 @@ namespace Cosmos.Kernel { EndLogging(); } + public static void SendKeyboardEvent(byte aScanCode, bool aReleased) { + StartLogging(); + Serial.Write(0, "\r\n"); + EndLogging(); + } + public static void SendError(string aModule, string aData) { StartLogging(); Serial.Write(0, " mBuffer; + private const int BufferSize = 64; + private static bool mEscaped; + + private void HandleScancode(byte aScancode, bool aReleased) { + ushort xTheScancode = aScancode; + if (mEscaped) { + xTheScancode = (ushort)(xTheScancode + 256); + mEscaped = false; + } + switch (xTheScancode) { + case 0xE0: { + mEscaped = true; + break; + } + default: { + if (mBuffer.Count < BufferSize) { + mBuffer.Enqueue(xTheScancode); + } + break; + } + } + if (!aReleased) { + DebugUtil.SendKeyboardEvent(aScancode, aReleased); + } + } + + public static void Initialize() { + mBuffer = new Queue(BufferSize); + } + } } diff --git a/source/Cosmos/Cosmos.Shell.Console/Program.cs b/source/Cosmos/Cosmos.Shell.Console/Program.cs index 506345fbb..544214e22 100644 --- a/source/Cosmos/Cosmos.Shell.Console/Program.cs +++ b/source/Cosmos/Cosmos.Shell.Console/Program.cs @@ -6,16 +6,9 @@ namespace Cosmos.Shell.Console { class Program { static void Main() { Kernel.CPU.Init(); - //System.Console.WriteLine("Cosmos creation complete"); + System.Console.WriteLine("Cosmos creation complete"); Kernel.Interrupts.DoTest(); - object o = new object(); - System.Console.WriteLine("Object Created"); - if (o == null) { - System.Console.WriteLine("Object == null"); - } else { - System.Console.WriteLine("Object != null"); - } - o = null; + } } }