diff --git a/Demos/Guess/Guess.Cosmos b/Demos/Guess/Guess.Cosmos index 592ab1ee5..246ba2c6b 100644 --- a/Demos/Guess/Guess.Cosmos +++ b/Demos/Guess/Guess.Cosmos @@ -21,17 +21,17 @@ MicrosoftNET False True - Source + IL User PXE Player - False + True Workstation ISO False ISO VMware - False + True All PXE None @@ -59,8 +59,8 @@ false ISO VMware - False - Source + True + IL False Workstation bin\Debug\ @@ -68,7 +68,7 @@ False All True - False + True ISO None False @@ -187,17 +187,17 @@ MicrosoftNET False True - Source + IL User PXE Player - False + True Workstation ISO False ISO VMware - False + True All PXE None @@ -225,8 +225,8 @@ false ISO VMware - False - Source + True + IL False Workstation bin\Debug\ @@ -234,7 +234,7 @@ False All True - False + True ISO None False diff --git a/Demos/Guess/GuessOS.cs b/Demos/Guess/GuessOS.cs index 3b2f5cdeb..91f499c7e 100644 --- a/Demos/Guess/GuessOS.cs +++ b/Demos/Guess/GuessOS.cs @@ -26,8 +26,13 @@ namespace GuessKernel { private Debugger mDebugger = new Debugger("User", "Guess"); [StructLayout(LayoutKind.Explicit)] - private struct MyStruct + private class MyStruct { + public MyStruct() + { + + } + public MyStruct(short a, short b, short c, short d, short e) { A = a; @@ -60,63 +65,63 @@ namespace GuessKernel { //xQueue.Enqueue(new MyStruct(1, 2, 3, 4, 5)); //xQueue.Enqueue(new MyStruct(6, 7, 8, 9, 10)); - var xTest = 3 % 8; - Console.Write("Test: "); - Console.WriteLine(xTest.ToString()); + //var xTest = 3 % 8; + //Console.Write("Test: "); + //Console.WriteLine(xTest.ToString()); - //var xItem = xQueue.Dequeue(); - //Console.Write("Char: "); - //Console.WriteLine(xResult.KeyChar); - var xItem = new MyStruct - { - A = 1, - B = 2, - C = 3, - D = 4, - E = 5 - }; + ////var xItem = xQueue.Dequeue(); + ////Console.Write("Char: "); + ////Console.WriteLine(xResult.KeyChar); + //var xItem = new MyStruct + // { + // A = 1, + // B = 2, + // C = 3, + // D = 4, + // E = 5 + // }; - var xArray = new MyStruct[1]; - xArray[0] = xItem; - //xArray[0] = new MyStruct(1, 2, 3, 4, 5); + //var xArray = new MyStruct[1]; + //xArray[0] = xItem; + ////xArray[0] = new MyStruct(1, 2, 3, 4, 5); - xItem = xArray[0]; - Console.Write("A: "); - Console.WriteLine(xItem.A); - Console.Write("B: "); - Console.WriteLine(xItem.B); - Console.Write("C: "); - Console.WriteLine(xItem.C); - Console.Write("D: "); - Console.WriteLine(xItem.D); - Console.Write("E: "); - Console.WriteLine(xItem.E); + //xItem = xArray[0]; + //Console.Write("A: "); + //Console.WriteLine(xItem.A); + //Console.Write("B: "); + //Console.WriteLine(xItem.B); + //Console.Write("C: "); + //Console.WriteLine(xItem.C); + //Console.Write("D: "); + //Console.WriteLine(xItem.D); + //Console.Write("E: "); + //Console.WriteLine(xItem.E); - //xItem = new MyStruct(6, 7, 8, 9, 10); + ////xItem = new MyStruct(6, 7, 8, 9, 10); - Console.WriteLine("Next: "); - //xItem = xQueue.Dequeue(); - //Console.Write("Char: "); - //Console.WriteLine(xResult.KeyChar); + //Console.WriteLine("Next: "); + ////xItem = xQueue.Dequeue(); + ////Console.Write("Char: "); + ////Console.WriteLine(xResult.KeyChar); - //var xArray = new MyStruct[0]; - //xArray[0] = new MyStruct(1, 2, 3, 4, 5); + ////var xArray = new MyStruct[0]; + ////xArray[0] = new MyStruct(1, 2, 3, 4, 5); - xItem = GetValue(xArray, 0); - Console.Write("A: "); - Console.WriteLine(xItem.A); - Console.Write("B: "); - Console.WriteLine(xItem.B); - Console.Write("C: "); - Console.WriteLine(xItem.C); - Console.Write("D: "); - Console.WriteLine(xItem.D); - Console.Write("E: "); - Console.WriteLine(xItem.E); + //xItem = GetValue(xArray, 0); + //Console.Write("A: "); + //Console.WriteLine(xItem.A); + //Console.Write("B: "); + //Console.WriteLine(xItem.B); + //Console.Write("C: "); + //Console.WriteLine(xItem.C); + //Console.Write("D: "); + //Console.WriteLine(xItem.D); + //Console.Write("E: "); + //Console.WriteLine(xItem.E); - while (true) - ; + //while (true) + // ; //Stop(); mCount++; diff --git a/source/Cosmos.HAL/DefaultKeyboard.cs b/source/Cosmos.HAL/DefaultKeyboard.cs index 0f8cd786b..1383f5d0a 100644 --- a/source/Cosmos.HAL/DefaultKeyboard.cs +++ b/source/Cosmos.HAL/DefaultKeyboard.cs @@ -85,7 +85,7 @@ namespace Cosmos.HAL } if (!aReleased) { - ConsoleKeyInfo xKeyInfo; + ConsoleKeyInfoEx xKeyInfo; if (!GetKey(xTheScancode, out xKeyInfo)) { Global.Dbg.SendError("Keyboard", "error while getting scancode character!"); @@ -169,30 +169,30 @@ namespace Cosmos.HAL #region digits - //AddKey(0x1, '`'); + //AddKey(0x1, '`',); //AddKey(0x10000, '~'); - //AddKey(0x29, '`', ConsoleKey.NoName); - //AddKey(0x290000, '~', ConsoleKey.NoName); - //AddKey(0x2, '1', ConsoleKey.D1); - //AddKey(0x20000, '!', ConsoleKey.D1); - //AddKey(0x3, '2', ConsoleKey.D2); - //AddKey(0x30000, '@', ConsoleKey.D2); - //AddKey(0x4, '3', ConsoleKey.D3); - //AddKey(0x40000, '#', ConsoleKey.D3); - //AddKey(0x5, '4', ConsoleKey.D4); - //AddKey(0x50000, '$', ConsoleKey.D5); - //AddKey(0x6, '5', ConsoleKey.D5); - //AddKey(0x60000, '%', ConsoleKey.D5); - //AddKey(0x7, '6', ConsoleKey.D6); - //AddKey(0x70000, '^', ConsoleKey.D6); - //AddKey(0x8, '7', ConsoleKey.D7); - //AddKey(0x80000, '&', ConsoleKey.D7); - //AddKey(0x9, '8', ConsoleKey.D8); - //AddKey(0x90000, '*', ConsoleKey.D8); - //AddKey(0xA, '9', ConsoleKey.D9); - //AddKey(0xA0000, '(', ConsoleKey.D9); + AddKey(0x29, '`', ConsoleKey.NoName); + AddKey(0x290000, '~', ConsoleKey.NoName); + AddKey(0x2, '1', ConsoleKey.D1); + AddKey(0x20000, '!', ConsoleKey.D1); + AddKey(0x3, '2', ConsoleKey.D2); + AddKey(0x30000, '@', ConsoleKey.D2); + AddKey(0x4, '3', ConsoleKey.D3); + AddKey(0x40000, '#', ConsoleKey.D3); + AddKey(0x5, '4', ConsoleKey.D4); + AddKey(0x50000, '$', ConsoleKey.D5); + AddKey(0x6, '5', ConsoleKey.D5); + AddKey(0x60000, '%', ConsoleKey.D5); + AddKey(0x7, '6', ConsoleKey.D6); + AddKey(0x70000, '^', ConsoleKey.D6); + AddKey(0x8, '7', ConsoleKey.D7); + AddKey(0x80000, '&', ConsoleKey.D7); + AddKey(0x9, '8', ConsoleKey.D8); + AddKey(0x90000, '*', ConsoleKey.D8); + AddKey(0xA, '9', ConsoleKey.D9); + AddKey(0xA0000, '(', ConsoleKey.D9); AddKey(0xB, '0', ConsoleKey.D0); - //AddKey(0xB0000, ')', ConsoleKey.D0); + AddKey(0xB0000, ')', ConsoleKey.D0); #endregion @@ -419,20 +419,20 @@ namespace Cosmos.HAL // return xResult; //} - public bool GetKey(uint aScancode, out ConsoleKeyInfo keyInfo) + public bool GetKey(uint aScancode, out ConsoleKeyInfoEx keyInfo) { ConsoleKey xKey; if (!GetKeyValue(aScancode, out xKey)) { - keyInfo = new ConsoleKeyInfo(); + keyInfo = null; return false; } char xChar; if (!GetCharValue(aScancode, out xChar)) { - keyInfo = new ConsoleKeyInfo(); + keyInfo = null; return false; } Console.WriteLine("Returning key"); @@ -442,7 +442,7 @@ namespace Cosmos.HAL Console.WriteLine((int)xKey); Console.Write("Char = "); Console.WriteLine((int)xChar); - keyInfo = new ConsoleKeyInfo(xChar, xKey, ShiftPressed, AltPressed, ControlPressed); + keyInfo = new ConsoleKeyInfoEx(xChar, xKey, ShiftPressed, AltPressed, ControlPressed); return true; } diff --git a/source/Cosmos.HAL/Keyboard.cs b/source/Cosmos.HAL/Keyboard.cs index b06b2d94f..ca6f3c99c 100644 --- a/source/Cosmos.HAL/Keyboard.cs +++ b/source/Cosmos.HAL/Keyboard.cs @@ -4,6 +4,48 @@ using System.Linq; using System.Text; namespace Cosmos.HAL { + public class ConsoleKeyInfoEx + { + // once Github issue #137 is fixed, replace this class with ConsoleKeyInfo struct. + + public char KeyChar + { + get; + set; + } + + public ConsoleKey Key + { + get; + set; + } + + public ConsoleModifiers Modifiers + { + get; + set; + } + + public ConsoleKeyInfoEx(char keyChar, ConsoleKey key, bool shift, bool alt, bool control) + { + this.KeyChar = keyChar; + this.Key = key; + this.Modifiers = (ConsoleModifiers)0; + if (shift) + { + this.Modifiers |= ConsoleModifiers.Shift; + } + if (alt) + { + this.Modifiers |= ConsoleModifiers.Alt; + } + if (control) + { + this.Modifiers |= ConsoleModifiers.Control; + } + } + } + public abstract class Keyboard : Device { // TODO: MtW: I don't like the following line in the baseclass, but for now, lets keep it here. protected Core.IOGroup.Keyboard IO = Core.Global.BaseIOGroups.Keyboard; @@ -11,9 +53,9 @@ namespace Cosmos.HAL { { if (mQueuedKeys != null) { - Console.WriteLine("Skippign creation on key queue!"); + Console.WriteLine("Skipping creation of key queue!"); } - mQueuedKeys = new Queue(32); + mQueuedKeys = new Queue(32); Initialize(); Core.INTs.SetIrqHandler(0x01, HandleIRQ); @@ -37,9 +79,9 @@ namespace Cosmos.HAL { protected abstract void HandleScancode(byte aScancode, bool aReleased); - private static Queue mQueuedKeys; + private static Queue mQueuedKeys; - protected void Enqueue(ConsoleKeyInfo aKey) + protected void Enqueue(ConsoleKeyInfoEx aKey) { mQueuedKeys.Enqueue(aKey); Global.Dbg.SendNumber("Keyboard", "Key enqueued. QueuedKeys.Count", (uint)mQueuedKeys.Count, 32); @@ -49,18 +91,18 @@ namespace Cosmos.HAL { global::System.Console.WriteLine(); } - public bool TryReadKey(out ConsoleKeyInfo oKey) + public bool TryReadKey(out ConsoleKeyInfoEx oKey) { if (mQueuedKeys.Count > 0) { oKey = mQueuedKeys.Dequeue(); return true; } - oKey = default(ConsoleKeyInfo); + oKey = default(ConsoleKeyInfoEx); return false; } - public ConsoleKeyInfo ReadKey() + public ConsoleKeyInfoEx ReadKey() { while (mQueuedKeys.Count == 0) { diff --git a/source/Cosmos.IL2CPU/IL/Ldelem.cs b/source/Cosmos.IL2CPU/IL/Ldelem.cs index 4b3f8560a..7e020a3bb 100644 --- a/source/Cosmos.IL2CPU/IL/Ldelem.cs +++ b/source/Cosmos.IL2CPU/IL/Ldelem.cs @@ -11,7 +11,13 @@ namespace Cosmos.IL2CPU.X86.IL { public override void Execute(MethodInfo aMethod, ILOpCode aOpCode) { var xOpType = (OpType)aOpCode; var xSize = SizeOfType(xOpType.Value); + if (xOpType.Value.IsValueType && !xOpType.Value.IsPrimitive) + { + Ldelema.Assemble(Assembler, xSize, DebugEnabled); + Ldobj.DoAssemble(xOpType.Value); + return; + } Ldelem_Ref.Assemble(Assembler, xSize, false, DebugEnabled); } } -} \ No newline at end of file +} diff --git a/source/Cosmos.IL2CPU/IL/Ldobj.cs b/source/Cosmos.IL2CPU/IL/Ldobj.cs index 668f3b762..7e4e0f7db 100644 --- a/source/Cosmos.IL2CPU/IL/Ldobj.cs +++ b/source/Cosmos.IL2CPU/IL/Ldobj.cs @@ -15,43 +15,51 @@ namespace Cosmos.IL2CPU.X86.IL public override void Execute( MethodInfo aMethod, ILOpCode aOpCode ) { DoNullReferenceCheck(Assembler, DebugEnabled, 0); - OpType xType = ( OpType )aOpCode; - new CPUx86.Pop { DestinationReg = CPUx86.Registers.EAX }; - var xObjSize = GetStorageSize(xType.Value); + OpType xType = (OpType)aOpCode; + DoAssemble(xType.Value); + } + + public static void DoAssemble(Type type) + { + if (type == null) + { + throw new ArgumentNullException("type"); + } + new CPUx86.Pop {DestinationReg = CPUx86.Registers.EAX}; + var xObjSize = GetStorageSize(type); switch (xObjSize % 4) { case 1: - { - new CPUx86.Xor { DestinationReg = CPUx86.Registers.EBX, SourceReg = CPUx86.Registers.EBX }; - new CPUx86.Mov { DestinationReg = CPUx86.Registers.BL, SourceIsIndirect = true, SourceReg = CPUx86.Registers.EAX, SourceDisplacement = (int)(xObjSize - 1) }; - //new CPUx86.ShiftLeft { DestinationReg = CPUx86.Registers.EBX, SourceValue = 24 }; - new CPUx86.Push { DestinationReg = CPUx86.Registers.EBX }; - break; - } + { + new CPUx86.Xor {DestinationReg = CPUx86.Registers.EBX, SourceReg = CPUx86.Registers.EBX}; + new CPUx86.Mov {DestinationReg = CPUx86.Registers.BL, SourceIsIndirect = true, SourceReg = CPUx86.Registers.EAX, SourceDisplacement = (int)(xObjSize - 1)}; + //new CPUx86.ShiftLeft { DestinationReg = CPUx86.Registers.EBX, SourceValue = 24 }; + new CPUx86.Push {DestinationReg = CPUx86.Registers.EBX}; + break; + } case 2: - { - new CPUx86.Xor { DestinationReg = CPUx86.Registers.EBX, SourceReg = CPUx86.Registers.EBX }; - new CPUx86.Mov { DestinationReg = CPUx86.Registers.BX, SourceIsIndirect = true, SourceReg = CPUx86.Registers.EAX, SourceDisplacement = (int)(xObjSize - 2) }; - //new CPUx86.ShiftLeft {DestinationReg = CPUx86.Registers.EBX, SourceValue = 16}; - new CPUx86.Push { DestinationReg = CPUx86.Registers.EBX }; - break; - } + { + new CPUx86.Xor {DestinationReg = CPUx86.Registers.EBX, SourceReg = CPUx86.Registers.EBX}; + new CPUx86.Mov {DestinationReg = CPUx86.Registers.BX, SourceIsIndirect = true, SourceReg = CPUx86.Registers.EAX, SourceDisplacement = (int)(xObjSize - 2)}; + //new CPUx86.ShiftLeft {DestinationReg = CPUx86.Registers.EBX, SourceValue = 16}; + new CPUx86.Push {DestinationReg = CPUx86.Registers.EBX}; + break; + } case 0: - { - break; - } + { + break; + } default: - throw new Exception( "Remainder not supported!" ); + throw new Exception("Remainder not supported!"); } xObjSize -= (xObjSize % 4); for (int i = 1; i <= (xObjSize / 4); i++) { - new CPUx86.Push { DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = (int)(xObjSize - (i * 4)) }; + new CPUx86.Push {DestinationReg = CPUx86.Registers.EAX, DestinationIsIndirect = true, DestinationDisplacement = (int)(xObjSize - (i * 4))}; } - } } } diff --git a/source/Cosmos.System.Plugs/System/ConsoleImpl.cs b/source/Cosmos.System.Plugs/System/ConsoleImpl.cs index 5beb7059f..a74534e69 100644 --- a/source/Cosmos.System.Plugs/System/ConsoleImpl.cs +++ b/source/Cosmos.System.Plugs/System/ConsoleImpl.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using Cosmos.HAL; using Encoding = System.Text.Encoding; using Plug = Cosmos.IL2CPU.Plugs.PlugAttribute; @@ -303,7 +304,7 @@ namespace Cosmos.System.Plugs.System { public static int Read() { // TODO special cases, if needed, that returns -1 - ConsoleKeyInfo xResult; + ConsoleKeyInfoEx xResult; if (HAL.Global.Keyboard.TryReadKey(out xResult)) { @@ -317,7 +318,7 @@ namespace Cosmos.System.Plugs.System { // ReadKey() pure CIL - public static ConsoleKeyInfo ReadKey(Boolean intercept) { + public static ConsoleKeyInfoEx ReadKey(Boolean intercept) { var key = Cosmos.HAL.Global.Keyboard.ReadKey(); if (false == intercept) @@ -335,7 +336,7 @@ namespace Cosmos.System.Plugs.System { return null; } List chars = new List(32); - ConsoleKeyInfo current; + ConsoleKeyInfoEx current; int currentCount = 0; while ((current = HAL.Global.Keyboard.ReadKey()).Key != ConsoleKey.Enter)