Implemented some console methods and fixed a bug in the console, copying the behaviour of background color in

windows console applications.
This commit is contained in:
José Pedro 2016-06-24 00:41:30 +01:00
parent 610f2b652a
commit fbac0cabcf
2 changed files with 111 additions and 84 deletions

View file

@ -8,9 +8,11 @@ using Cosmos.Debug.Kernel;
namespace Cosmos.HAL { namespace Cosmos.HAL {
// Dont hold state here. This is a raw to hardware class. Virtual screens should be done // Dont hold state here. This is a raw to hardware class. Virtual screens should be done
// by memory moves // by memory moves
public class TextScreen : TextScreenBase { public class TextScreen : TextScreenBase
{
protected byte Color = 0x0F; // White protected byte Color = 0x0F; // White
protected UInt16 mClearCellValue; protected UInt16 mBackgroundClearCellValue;
protected UInt16 mTextClearCellValue;
protected UInt32 mRow2Addr; protected UInt32 mRow2Addr;
protected UInt32 mScrollSize; protected UInt32 mScrollSize;
protected Int32 mCursorSize = 25; // 25 % as C# Console class protected Int32 mCursorSize = 25; // 25 % as C# Console class
@ -19,8 +21,8 @@ namespace Cosmos.HAL {
protected Core.IOGroup.TextScreen IO = new Cosmos.Core.IOGroup.TextScreen(); protected Core.IOGroup.TextScreen IO = new Cosmos.Core.IOGroup.TextScreen();
protected readonly MemoryBlock08 mRAM; protected readonly MemoryBlock08 mRAM;
public TextScreen() { public TextScreen()
{
if (this is TextScreen) if (this is TextScreen)
{ {
TextScreenHelpers.Debug("this is TextScreen"); TextScreenHelpers.Debug("this is TextScreen");
@ -32,6 +34,7 @@ namespace Cosmos.HAL {
mRAM = IO.Memory.Bytes; mRAM = IO.Memory.Bytes;
// 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 // 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); SetColors(ConsoleColor.White, ConsoleColor.Black);
mBackgroundClearCellValue = mTextClearCellValue;
mRow2Addr = (UInt32)(Cols * 2); mRow2Addr = (UInt32)(Cols * 2);
mScrollSize = (UInt32)(Cols * (Rows - 1) * 2); mScrollSize = (UInt32)(Cols * (Rows - 1) * 2);
SetCursorSize(mCursorSize); SetCursorSize(mCursorSize);
@ -44,34 +47,38 @@ namespace Cosmos.HAL {
public override void Clear() { public override void Clear() {
TextScreenHelpers.Debug("Clearing screen with value "); TextScreenHelpers.Debug("Clearing screen with value ");
TextScreenHelpers.DebugNumber(mClearCellValue); TextScreenHelpers.DebugNumber(mTextClearCellValue);
IO.Memory.Fill(mClearCellValue); IO.Memory.Fill(mTextClearCellValue);
mBackgroundClearCellValue = mTextClearCellValue;
} }
public override void ScrollUp() public override void ScrollUp()
{ {
IO.Memory.MoveDown(0, mRow2Addr, mScrollSize); IO.Memory.MoveDown(0, mRow2Addr, mScrollSize);
//IO.Memory.Fill(mScrollSize, mRowSize32, mClearCellValue32); //IO.Memory.Fill(mScrollSize, mRowSize32, mClearCellValue32);
IO.Memory.Fill(mScrollSize, Cols, mClearCellValue); IO.Memory.Fill(mScrollSize, Cols, mBackgroundClearCellValue);
} }
public override char this[int aX, int aY] public override char this[int aX, int aY]
{ {
get { get
{
var xScreenOffset = (UInt32)((aX + aY * Cols) * 2); var xScreenOffset = (UInt32)((aX + aY * Cols) * 2);
return (char)mRAM[xScreenOffset]; return (char)mRAM[xScreenOffset];
} }
set { set
{
var xScreenOffset = (UInt32)((aX + aY * Cols) * 2); var xScreenOffset = (UInt32)((aX + aY * Cols) * 2);
mRAM[xScreenOffset] = (byte)value; mRAM[xScreenOffset] = (byte)value;
mRAM[xScreenOffset + 1] = Color; mRAM[xScreenOffset + 1] = Color;
} }
} }
public override void SetColors(ConsoleColor aForeground, ConsoleColor aBackground) { public override void SetColors(ConsoleColor aForeground, ConsoleColor aBackground)
{
Color = (byte)((byte)(aForeground) | ((byte)(aBackground) << 4)); Color = (byte)((byte)(aForeground) | ((byte)(aBackground) << 4));
// The Color | the NUL character this is used to Clear the Screen // The Color | the NUL character this is used to Clear the Screen
mClearCellValue = (UInt16)(Color << 8 | 0x00); mTextClearCellValue = (UInt16)(Color << 8 | 0x00);
} }
public override void SetCursorPos(int aX, int aY) public override void SetCursorPos(int aX, int aY)

View file

@ -57,8 +57,7 @@ namespace Cosmos.System.Plugs.System
public static bool get_CapsLock() public static bool get_CapsLock()
{ {
WriteLine("Not implemented: get_CapsLock"); return Global.CapsLock;
return false;
} }
public static int get_CursorLeft() public static int get_CursorLeft()
@ -80,8 +79,16 @@ namespace Cosmos.System.Plugs.System
// for now: // for now:
return; return;
} }
if (x < get_WindowWidth())
{
xConsole.X = x; xConsole.X = x;
} }
else
{
WriteLine("x must be lower than the console width!");
}
}
public static int get_CursorSize() public static int get_CursorSize()
{ {
@ -124,14 +131,26 @@ namespace Cosmos.System.Plugs.System
// for now: // for now:
return; return;
} }
GetConsole().Y = y;
if (y < get_WindowHeight())
{
xConsole.Y = y;
}
else
{
WriteLine("y must be lower than the console height!");
}
} }
public static bool get_CursorVisible() public static bool get_CursorVisible()
{ {
WriteLine("Not implemented: get_CursorVisible"); var xConsole = GetConsole();
if (xConsole == null)
{
return false; return false;
} }
return GetConsole().CursorVisible;
}
public static void set_CursorVisible(bool value) public static void set_CursorVisible(bool value)
{ {
@ -199,8 +218,7 @@ namespace Cosmos.System.Plugs.System
public static bool get_NumberLock() public static bool get_NumberLock()
{ {
WriteLine("Not implemented: get_NumberLock"); return Global.NumLock;
return false;
} }
//public static TextWriter get_Out() { //public static TextWriter get_Out() {
@ -494,7 +512,8 @@ namespace Cosmos.System.Plugs.System
public static void ResetColor() public static void ResetColor()
{ {
WriteLine("Not implemented: ResetColor"); set_BackgroundColor(ConsoleColor.Black);
set_ForegroundColor(ConsoleColor.White);
} }
public static void SetBufferSize(int width, int height) public static void SetBufferSize(int width, int height)
@ -504,7 +523,8 @@ namespace Cosmos.System.Plugs.System
public static void SetCursorPosition(int left, int top) public static void SetCursorPosition(int left, int top)
{ {
WriteLine("Not implemented: SetCursorPosition"); set_CursorLeft(left);
set_CursorTop(top);
} }
//public static void SetError(TextWriter newError) { //public static void SetError(TextWriter newError) {