Skip to content

Commit

Permalink
Implemented Console's CursorSize and CursorVisible properties
Browse files Browse the repository at this point in the history
- Now Console's CursorSize and CursorVisible properties
- Console Cursor default size is 25 as on Windows (before was 1)
- Console Cursor is visible by default
  • Loading branch information
fanoI committed Dec 7, 2015
1 parent 6a1614e commit 45a3f79
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 23 deletions.
20 changes: 20 additions & 0 deletions source/Cosmos.HAL/DebugTextScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,25 @@ public override void ScrollUp()
SendChar(new []{value});
}
}

public override int GetCursorSize()
{
return 0;
}
public override void SetCursorSize(int value)
{


}

public override bool GetCursorVisible()
{
return true;
}

public override void SetCursorVisible(bool value)
{

}
}
}
54 changes: 53 additions & 1 deletion source/Cosmos.HAL/TextScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ 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 {
protected byte Color = 0x0F; // White
protected byte Color = 0x0F; // White
protected UInt16 mClearCellValue;
protected UInt32 mRow2Addr;
protected UInt32 mScrollSize;
protected Int32 mCursorSize = 25; // 25 % as C# Console class
protected bool mCursorVisible = true;

protected Core.IOGroup.TextScreen IO = new Cosmos.Core.IOGroup.TextScreen();
protected readonly MemoryBlock08 mRAM;
Expand All @@ -32,6 +34,8 @@ public TextScreen() {
SetColors(ConsoleColor.White, ConsoleColor.Black);
mRow2Addr = (UInt32)(Cols * 2);
mScrollSize = (UInt32)(Cols * (Rows - 1) * 2);
SetCursorSize(mCursorSize);
SetCursorVisible(mCursorVisible);
Debugger.DoSend("End of TextScreen..ctor");
}

Expand Down Expand Up @@ -84,5 +88,53 @@ public override byte GetColor()
{
return Color;
}

public override int GetCursorSize()
{
return mCursorSize;
}
public override void SetCursorSize(int value)
{
mCursorSize = value;
Debugger.DoSend("Changing cursor size to ");
Debugger.DoSendNumber((uint)value);
// We need to transform value from a percentage to a value from 15 to 0
value = 16 - ((16 * value) / 100);
// This is the case in which value is in reality 1% and a for a truncation error we get 16 (invalid value)
if (value >= 16)
value = 15;
Debugger.DoSend("verticalSize is ");
Debugger.DoSendNumber((uint)value);
// Cursor Vertical Size Register here a value between 0x00 and 0x0F must be set with 0x00 meaning maximum size and 0x0F minimum
IO.Idx3.Byte = 0x0A;
IO.Data3.Byte = (byte)value;
// Cursor Horizontal Size Register we set it to 0x0F (100%) as a security measure is probably so already
IO.Idx3.Byte = 0x0B;
IO.Data3.Byte = 0x0F;
}

public override bool GetCursorVisible()
{
return mCursorVisible;
}

public override void SetCursorVisible(bool value)
{
byte cursorDisable;

mCursorVisible = value;

// The VGA Cursor is disabled when the value is 1 and enabled when is 0 so we need to invert 'value', sadly the ConvertToByte() function is not working
// so we need to do the if by hand...
if (value == true)
cursorDisable = 0;
else
cursorDisable = 1;

// Cursor Vertical Size Register if the bit 5 is set to 1 the cursor is disabled, if 0 is enabled
IO.Idx3.Byte = 0x0A;
IO.Data3.Byte |= (byte) (cursorDisable << 5);
}

}
}
7 changes: 7 additions & 0 deletions source/Cosmos.HAL/TextScreenBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,12 @@ public ConsoleColor Background
get;
set;
}

public abstract int GetCursorSize();
public abstract void SetCursorSize(int value);

public abstract bool GetCursorVisible();
public abstract void SetCursorVisible(bool value);

}
}
69 changes: 47 additions & 22 deletions source/Cosmos.System.Plugs/System/ConsoleImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,26 @@ public static void set_CursorLeft(int x) {
xConsole.X = x;
}

public static int get_CursorSize() {
WriteLine("Not implemented: get_CursorSize");
return -1;
}

public static int get_CursorSize() {
var xConsole = GetConsole();
if (xConsole == null)
{
// for now:
return 0;
}
return xConsole.CursorSize;
}

public static void set_CursorSize(int aSize) {
WriteLine("Not implemented: set_CursorSize");
}
var xConsole = GetConsole();
if (xConsole == null)
{
// for now:
return;
}
xConsole.CursorSize = aSize;
}

public static int get_CursorTop() {
var xConsole = GetConsole();
Expand All @@ -100,21 +112,34 @@ public static void set_CursorTop(int y) {
GetConsole().Y = y;
}

public static bool get_CursorVisible() {
WriteLine("Not implemented: get_CursorVisible");
return false;
}
public static bool get_CursorVisible()
{
var xConsole = GetConsole();
if (xConsole == null)
{
// for now:
return true;
}
return xConsole.CursorVisible;
}

public static void set_CursorVisible(bool value) {
WriteLine("Not implemented: set_CursorVisible");
}
public static void set_CursorVisible(bool value) {
var xConsole = GetConsole();
if (xConsole == null)
{
// for now:
return;
}
xConsole.CursorVisible = value;
}

//public static TextWriter get_Error() {
// WriteLine("Not implemented: get_Error");
// return null;
//}

public static ConsoleColor get_ForegroundColor() {
//public static TextWriter get_Error() {
// WriteLine("Not implemented: get_Error");
// return null;
//}

public static ConsoleColor get_ForegroundColor() {
return mForeground;
}

Expand Down Expand Up @@ -460,7 +485,7 @@ public static void SetWindowSize(int width, int height) {
WriteLine("Not implemented: SetWindowSize");
}

#region Write
#region Write

public static void Write(bool aBool) {
Write(aBool.ToString());
Expand Down Expand Up @@ -567,9 +592,9 @@ public static void Write(string format, object arg0, object arg1, object arg2, o
// Write(aByte.ToString());
//}

#endregion
#endregion

#region WriteLine
#region WriteLine

public static void WriteLine() {
var xConsole = GetConsole();
Expand Down Expand Up @@ -710,6 +735,6 @@ public static void WriteLine(string format, object arg0, object arg1, object arg
public static void WriteLine(string format, object arg0, object arg1, object arg2, object arg3) {
WriteLine("Not implemented: WriteLine");
}
#endregion
#endregion
}
}
17 changes: 17 additions & 0 deletions source/Cosmos.System/Console.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,22 @@ public ConsoleColor Background
get { return (ConsoleColor)(mText.GetColor() >> 4); }
set { mText.SetColors(Foreground, value); }
}

public int CursorSize
{
get { return mText.GetCursorSize(); }
set {
// Value should be a percentage from [1, 100].
if (value < 1 || value > 100)
throw new ArgumentOutOfRangeException("value", value, "CursorSize value " + value + " out of range (1 - 100)");

mText.SetCursorSize(value);
}
}

public bool CursorVisible {
get { return mText.GetCursorVisible(); }
set { mText.SetCursorVisible(value); }
}
}
}

0 comments on commit 45a3f79

Please sign in to comment.