Skip to content

Commit

Permalink
Console modifications
Browse files Browse the repository at this point in the history
- In MemoryBlock added Fill overloads that accept UInt16
- In TextScreen removed unused variables, magic number and finally the
Clear() method does what is expected!
  • Loading branch information
fanoI committed Nov 18, 2015
1 parent c85d421 commit f566917
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
20 changes: 20 additions & 0 deletions source/Cosmos.Core/MemoryBlock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,31 @@ public unsafe void Fill(UInt32 aStart, UInt32 aCount, UInt32 aData)
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)
{
Expand Down
26 changes: 13 additions & 13 deletions source/Cosmos.HAL/TextScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,24 +28,27 @@ public TextScreen() {
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");
}

public override UInt16 Rows { get { return 25; } }
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]
Expand All @@ -64,11 +64,11 @@ public override void ScrollUp()
}
}



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)
{
Expand Down

0 comments on commit f566917

Please sign in to comment.