mirror of
https://github.com/danbulant/Cosmos
synced 2026-05-24 12:35:31 +00:00
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:
parent
610f2b652a
commit
fbac0cabcf
2 changed files with 111 additions and 84 deletions
|
|
@ -8,9 +8,11 @@ using Cosmos.Debug.Kernel;
|
|||
namespace Cosmos.HAL {
|
||||
// Dont hold state here. This is a raw to hardware class. Virtual screens should be done
|
||||
// by memory moves
|
||||
public class TextScreen : TextScreenBase {
|
||||
public class TextScreen : TextScreenBase
|
||||
{
|
||||
protected byte Color = 0x0F; // White
|
||||
protected UInt16 mClearCellValue;
|
||||
protected UInt16 mBackgroundClearCellValue;
|
||||
protected UInt16 mTextClearCellValue;
|
||||
protected UInt32 mRow2Addr;
|
||||
protected UInt32 mScrollSize;
|
||||
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 readonly MemoryBlock08 mRAM;
|
||||
|
||||
public TextScreen() {
|
||||
|
||||
public TextScreen()
|
||||
{
|
||||
if (this is TextScreen)
|
||||
{
|
||||
TextScreenHelpers.Debug("this is TextScreen");
|
||||
|
|
@ -32,6 +34,7 @@ namespace Cosmos.HAL {
|
|||
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
|
||||
SetColors(ConsoleColor.White, ConsoleColor.Black);
|
||||
mBackgroundClearCellValue = mTextClearCellValue;
|
||||
mRow2Addr = (UInt32)(Cols * 2);
|
||||
mScrollSize = (UInt32)(Cols * (Rows - 1) * 2);
|
||||
SetCursorSize(mCursorSize);
|
||||
|
|
@ -44,34 +47,38 @@ namespace Cosmos.HAL {
|
|||
|
||||
public override void Clear() {
|
||||
TextScreenHelpers.Debug("Clearing screen with value ");
|
||||
TextScreenHelpers.DebugNumber(mClearCellValue);
|
||||
IO.Memory.Fill(mClearCellValue);
|
||||
TextScreenHelpers.DebugNumber(mTextClearCellValue);
|
||||
IO.Memory.Fill(mTextClearCellValue);
|
||||
mBackgroundClearCellValue = mTextClearCellValue;
|
||||
}
|
||||
|
||||
public override void ScrollUp()
|
||||
{
|
||||
IO.Memory.MoveDown(0, mRow2Addr, mScrollSize);
|
||||
//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]
|
||||
{
|
||||
get {
|
||||
get
|
||||
{
|
||||
var xScreenOffset = (UInt32)((aX + aY * Cols) * 2);
|
||||
return (char)mRAM[xScreenOffset];
|
||||
}
|
||||
set {
|
||||
set
|
||||
{
|
||||
var xScreenOffset = (UInt32)((aX + aY * Cols) * 2);
|
||||
mRAM[xScreenOffset] = (byte)value;
|
||||
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));
|
||||
// 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)
|
||||
|
|
|
|||
|
|
@ -57,8 +57,7 @@ namespace Cosmos.System.Plugs.System
|
|||
|
||||
public static bool get_CapsLock()
|
||||
{
|
||||
WriteLine("Not implemented: get_CapsLock");
|
||||
return false;
|
||||
return Global.CapsLock;
|
||||
}
|
||||
|
||||
public static int get_CursorLeft()
|
||||
|
|
@ -80,8 +79,16 @@ namespace Cosmos.System.Plugs.System
|
|||
// for now:
|
||||
return;
|
||||
}
|
||||
|
||||
if (x < get_WindowWidth())
|
||||
{
|
||||
xConsole.X = x;
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteLine("x must be lower than the console width!");
|
||||
}
|
||||
}
|
||||
|
||||
public static int get_CursorSize()
|
||||
{
|
||||
|
|
@ -124,14 +131,26 @@ namespace Cosmos.System.Plugs.System
|
|||
// for now:
|
||||
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()
|
||||
{
|
||||
WriteLine("Not implemented: get_CursorVisible");
|
||||
var xConsole = GetConsole();
|
||||
if (xConsole == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return GetConsole().CursorVisible;
|
||||
}
|
||||
|
||||
public static void set_CursorVisible(bool value)
|
||||
{
|
||||
|
|
@ -199,8 +218,7 @@ namespace Cosmos.System.Plugs.System
|
|||
|
||||
public static bool get_NumberLock()
|
||||
{
|
||||
WriteLine("Not implemented: get_NumberLock");
|
||||
return false;
|
||||
return Global.NumLock;
|
||||
}
|
||||
|
||||
//public static TextWriter get_Out() {
|
||||
|
|
@ -494,7 +512,8 @@ namespace Cosmos.System.Plugs.System
|
|||
|
||||
public static void ResetColor()
|
||||
{
|
||||
WriteLine("Not implemented: ResetColor");
|
||||
set_BackgroundColor(ConsoleColor.Black);
|
||||
set_ForegroundColor(ConsoleColor.White);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
WriteLine("Not implemented: SetCursorPosition");
|
||||
set_CursorLeft(left);
|
||||
set_CursorTop(top);
|
||||
}
|
||||
|
||||
//public static void SetError(TextWriter newError) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue