From f566917239890fbd899083b0ae80c7ad72145696 Mon Sep 17 00:00:00 2001 From: fanoI Date: Wed, 18 Nov 2015 23:27:33 +0100 Subject: [PATCH] Console modifications - In MemoryBlock added Fill overloads that accept UInt16 - In TextScreen removed unused variables, magic number and finally the Clear() method does what is expected! --- source/Cosmos.Core/MemoryBlock.cs | 20 ++++++++++++++++++++ source/Cosmos.HAL/TextScreen.cs | 26 +++++++++++++------------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/source/Cosmos.Core/MemoryBlock.cs b/source/Cosmos.Core/MemoryBlock.cs index e11055813..a8e77f7c1 100644 --- a/source/Cosmos.Core/MemoryBlock.cs +++ b/source/Cosmos.Core/MemoryBlock.cs @@ -67,11 +67,31 @@ namespace Cosmos.Core xDest++; } } + public void Fill(byte aData) { Fill(0, Size, aData); } + public void Fill(UInt16 aData) + { + Fill(0, Size / 2, aData); + } + + [DebugStub(Off = true)] + public unsafe void Fill(UInt32 aStart, UInt32 aCount, UInt16 aData) + { + //TODO: before next step can at least check bounds here and do the addition just once to + //start the loop. + //TODO - When asm can check count against size just one time and use a native fill asm op + UInt16* xDest = (UInt16*)(this.Base + aStart); + for (UInt32 i = 0; i < aCount; i++) + { + *xDest = aData; + xDest++; + } + } + [DebugStub(Off = true)] public unsafe void Fill(UInt32 aStart, UInt32 aCount, byte aData) { diff --git a/source/Cosmos.HAL/TextScreen.cs b/source/Cosmos.HAL/TextScreen.cs index b3f3de6f1..637180453 100644 --- a/source/Cosmos.HAL/TextScreen.cs +++ b/source/Cosmos.HAL/TextScreen.cs @@ -10,12 +10,9 @@ namespace Cosmos.HAL { // by memory moves public class TextScreen : TextScreenBase { protected byte Color = 0x0F; // White - // Empty + White - protected UInt16 mClearCellValue = 0x000F; - protected UInt32 mClearCellValue32; + protected UInt16 mClearCellValue; protected UInt32 mRow2Addr; protected UInt32 mScrollSize; - protected UInt32 mRowSize32; protected Core.IOGroup.TextScreen IO = new Cosmos.Core.IOGroup.TextScreen(); protected readonly MemoryBlock08 mRAM; @@ -31,10 +28,10 @@ namespace Cosmos.HAL { Debugger.DoSend("ERROR: This is not of type TextScreen!"); } mRAM = IO.Memory.Bytes; - mClearCellValue32 = (UInt32)(mClearCellValue << 16 | mClearCellValue); + // Set the Console default colors: White foreground on Black background, the default value of mClearCellValue is set there too as it is linked with the Color + SetColors(ConsoleColor.White, ConsoleColor.Black); mRow2Addr = (UInt32)(Cols * 2); mScrollSize = (UInt32)(Cols * (Rows - 1) * 2); - mRowSize32 = (UInt32)Cols * 2 / 4; Debugger.DoSend("End of TextScreen..ctor"); } @@ -42,13 +39,16 @@ namespace Cosmos.HAL { public override UInt16 Cols { get { return 80; } } public override void Clear() { - IO.Memory.Fill(mClearCellValue32); + Debugger.DoSend("Clearing screen with value "); + Debugger.DoSendNumber(mClearCellValue); + IO.Memory.Fill(mClearCellValue); } public override void ScrollUp() { IO.Memory.MoveDown(0, mRow2Addr, mScrollSize); - IO.Memory.Fill(mScrollSize, mRowSize32, mClearCellValue32); + //IO.Memory.Fill(mScrollSize, mRowSize32, mClearCellValue32); + IO.Memory.Fill(mScrollSize, Cols, mClearCellValue); } public override char this[int aX, int aY] @@ -64,11 +64,11 @@ namespace Cosmos.HAL { } } - - - public override void SetColors(ConsoleColor aForeground, ConsoleColor aBackground) { - Color = (byte)((byte)(aForeground) | ((byte)(aBackground) << 4)); - } + public override void SetColors(ConsoleColor aForeground, ConsoleColor aBackground) { + Color = (byte)((byte)(aForeground) | ((byte)(aBackground) << 4)); + // The Color | the NUL character this is used to Clear the Screen + mClearCellValue = (UInt16)(Color << 8 | 0x00); + } public override void SetCursorPos(int aX, int aY) {