mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-11 10:41:33 +00:00
Added support for moving cursor through text with left and right arrows.
This commit is contained in:
parent
8bd4438678
commit
a7016a72cc
5 changed files with 532 additions and 358 deletions
|
|
@ -3,8 +3,8 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.Hardware {
|
||||
|
||||
namespace Cosmos.Hardware
|
||||
{
|
||||
//public class Keyboard : Cosmos.Hardware.SerialDevice {
|
||||
// public Keyboard() {
|
||||
// mType = DeviceType.Keyboard;
|
||||
|
|
@ -22,248 +22,297 @@ namespace Cosmos.Hardware {
|
|||
//}
|
||||
|
||||
public delegate void HandleKeyboardDelegate(byte aScanCode, bool aReleased);
|
||||
public class Keyboard : Hardware {
|
||||
public class Keyboard : Hardware
|
||||
{
|
||||
private static HandleKeyboardDelegate mHandleKeyboardKey;
|
||||
public static void Initialize(HandleKeyboardDelegate aHandleKeyboardKeyDelegate) {
|
||||
public static void Initialize(HandleKeyboardDelegate aHandleKeyboardKeyDelegate)
|
||||
{
|
||||
mHandleKeyboardKey = aHandleKeyboardKeyDelegate;
|
||||
}
|
||||
|
||||
public static void HandleKeyboardInterrupt() {
|
||||
if (mHandleKeyboardKey != null) {
|
||||
public static void Initialize()
|
||||
{
|
||||
CheckInit();
|
||||
}
|
||||
|
||||
public static void HandleKeyboardInterrupt()
|
||||
{
|
||||
if (mHandleKeyboardKey != null)
|
||||
{
|
||||
byte xScanCode = IOReadByte(0x60);
|
||||
bool xReleased = (xScanCode & 0x80) == 0x80;
|
||||
if (xReleased) {
|
||||
if (xReleased)
|
||||
{
|
||||
xScanCode = (byte)(xScanCode ^ 0x80);
|
||||
}
|
||||
mHandleKeyboardKey(xScanCode, xReleased);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
DebugUtil.SendError("Keyboard", "No Keyboard Handler found!");
|
||||
}
|
||||
}
|
||||
|
||||
private class KeyMapping {
|
||||
public uint Scancode;
|
||||
public char Value;
|
||||
public KeyMapping(uint aScanCode, char aValue) {
|
||||
Scancode = aScanCode;
|
||||
Value = aValue;
|
||||
}
|
||||
}
|
||||
private static Queue<uint> mBuffer;
|
||||
private const int BufferSize = 64;
|
||||
private static bool mEscaped;
|
||||
private static List<KeyMapping> mKeys;
|
||||
private static bool mShiftState;
|
||||
|
||||
protected static void HandleScancode(byte aScancode, bool aReleased) {
|
||||
uint xTheScancode = aScancode;
|
||||
if (mEscaped) {
|
||||
xTheScancode = (ushort)(xTheScancode << 8);
|
||||
mEscaped = false;
|
||||
}
|
||||
switch (xTheScancode) {
|
||||
private static Queue<uint> mBuffer;
|
||||
private const int BufferSize = 64;
|
||||
private static bool mEscaped;
|
||||
private static List<KeyMapping> mKeys;
|
||||
private static bool mShiftState;
|
||||
|
||||
protected static void HandleScancode(byte aScancode, bool aReleased)
|
||||
{
|
||||
uint xTheScancode = aScancode;
|
||||
if (mEscaped)
|
||||
{
|
||||
xTheScancode = (ushort)(xTheScancode << 8);
|
||||
mEscaped = false;
|
||||
}
|
||||
switch (xTheScancode)
|
||||
{
|
||||
case 0x36:
|
||||
case 0x2A: {
|
||||
mShiftState = !aReleased;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
if (mShiftState) {
|
||||
xTheScancode = xTheScancode << 16;
|
||||
}
|
||||
if (mBuffer.Count < BufferSize) {
|
||||
if (!aReleased) {
|
||||
char xTheChar;
|
||||
if (!GetCharValue(xTheScancode, out xTheChar)) {
|
||||
//DebugUtil.SendError("Keyboard", "error while getting scancode character!");
|
||||
} else {
|
||||
//DebugUtil.SendDoubleNumber("Keyboard", "Scancode and Char", xTheScancode, 32, xTheChar, 16);
|
||||
}
|
||||
mBuffer.Enqueue(xTheScancode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//DebugUtil.SendKeyboardEvent(xTheScancode, aReleased);
|
||||
}
|
||||
case 0x2A:
|
||||
{
|
||||
mShiftState = !aReleased;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
if (mShiftState)
|
||||
{
|
||||
xTheScancode = xTheScancode << 16;
|
||||
}
|
||||
if (mBuffer.Count < BufferSize)
|
||||
{
|
||||
if (!aReleased)
|
||||
{
|
||||
char xTheChar;
|
||||
if (!GetCharValue(xTheScancode, out xTheChar))
|
||||
{
|
||||
//DebugUtil.SendError("Keyboard", "error while getting scancode character!");
|
||||
}
|
||||
else
|
||||
{
|
||||
//DebugUtil.SendDoubleNumber("Keyboard", "Scancode and Char", xTheScancode, 32, xTheChar, 16);
|
||||
}
|
||||
mBuffer.Enqueue(xTheScancode);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
//DebugUtil.SendKeyboardEvent(xTheScancode, aReleased);
|
||||
}
|
||||
|
||||
// Can merge HandleScancode after we remove old code
|
||||
// Remove the static.. Make it a real class
|
||||
protected static void ByteReceived(byte aValue) {
|
||||
bool xReleased = (aValue & 0x80) == 0x80;
|
||||
if (xReleased) {
|
||||
aValue = (byte)(aValue ^ 0x80);
|
||||
}
|
||||
HandleScancode(aValue, xReleased);
|
||||
}
|
||||
private static void CheckInit() {
|
||||
if (mBuffer == null) {
|
||||
mBuffer = new Queue<uint>(BufferSize);
|
||||
// Can merge HandleScancode after we remove old code
|
||||
// Remove the static.. Make it a real class
|
||||
protected static void ByteReceived(byte aValue)
|
||||
{
|
||||
bool xReleased = (aValue & 0x80) == 0x80;
|
||||
if (xReleased)
|
||||
{
|
||||
aValue = (byte)(aValue ^ 0x80);
|
||||
}
|
||||
HandleScancode(aValue, xReleased);
|
||||
}
|
||||
|
||||
// Old
|
||||
Keyboard.Initialize(HandleScancode);
|
||||
// New
|
||||
// TODO: Need to add support for mult keyboards. ie one in PS2 and one in USB, or even more
|
||||
//var xKeyboard = (HW.SerialDevice)(HW.Device.Find(HW.Device.DeviceType.Keyboard)[0]);
|
||||
//xKeyboard.ByteReceived += new HW.SerialDevice.ByteReceivedDelegate(ByteReceived);
|
||||
// End
|
||||
private static void CheckInit()
|
||||
{
|
||||
if (mBuffer == null)
|
||||
{
|
||||
mBuffer = new Queue<uint>(BufferSize);
|
||||
|
||||
mKeys = new List<KeyMapping>(128);
|
||||
// Old
|
||||
Keyboard.Initialize(HandleScancode);
|
||||
// New
|
||||
// TODO: Need to add support for mult keyboards. ie one in PS2 and one in USB, or even more
|
||||
//var xKeyboard = (HW.SerialDevice)(HW.Device.Find(HW.Device.DeviceType.Keyboard)[0]);
|
||||
//xKeyboard.ByteReceived += new HW.SerialDevice.ByteReceivedDelegate(ByteReceived);
|
||||
// End
|
||||
|
||||
//TODO: Direction Arrows, alt, ctrl, num pad, function keys, insert, home, pg up, delete, end, page down, esc, fn (for laptops)
|
||||
|
||||
//reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html#ss1.1
|
||||
#region Letters
|
||||
AddKey(0x10, 'q');
|
||||
AddKey(0x100000, 'Q');
|
||||
AddKey(0x11, 'w');
|
||||
AddKey(0x110000, 'W');
|
||||
AddKey(0x12, 'e');
|
||||
AddKey(0x120000, 'E');
|
||||
AddKey(0x13, 'r');
|
||||
AddKey(0x130000, 'R');
|
||||
AddKey(0x14, 't');
|
||||
AddKey(0x140000, 'T');
|
||||
AddKey(0x15, 'y');
|
||||
AddKey(0x150000, 'Y');
|
||||
AddKey(0x16, 'u');
|
||||
AddKey(0x160000, 'U');
|
||||
AddKey(0x17, 'i');
|
||||
AddKey(0x170000, 'I');
|
||||
AddKey(0x18, 'o');
|
||||
AddKey(0x180000, 'O');
|
||||
AddKey(0x19, 'p');
|
||||
AddKey(0x190000, 'P');
|
||||
if (mKeys == null)
|
||||
{
|
||||
CreateDefaultKeymap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AddKey(0x1E, 'a');
|
||||
AddKey(0x1E0000, 'A');
|
||||
AddKey(0x1F, 's');
|
||||
AddKey(0x1F0000, 'S');
|
||||
AddKey(0x20, 'd');
|
||||
AddKey(0x200000, 'D');
|
||||
AddKey(0x21, 'f');
|
||||
AddKey(0x210000, 'F');
|
||||
AddKey(0x22, 'g');
|
||||
AddKey(0x220000, 'G');
|
||||
AddKey(0x23, 'h');
|
||||
AddKey(0x230000, 'H');
|
||||
AddKey(0x24, 'j');
|
||||
AddKey(0x240000, 'J');
|
||||
AddKey(0x25, 'k');
|
||||
AddKey(0x250000, 'K');
|
||||
AddKey(0x26, 'l');
|
||||
AddKey(0x260000, 'L');
|
||||
private static void CreateDefaultKeymap()
|
||||
{
|
||||
mKeys = new List<KeyMapping>(128);
|
||||
|
||||
AddKey(0x2C, 'z');
|
||||
AddKey(0x2C0000, 'Z');
|
||||
AddKey(0x2D, 'x');
|
||||
AddKey(0x2D0000, 'X');
|
||||
AddKey(0x2E, 'c');
|
||||
AddKey(0x2E0000, 'C');
|
||||
AddKey(0x2F, 'v');
|
||||
AddKey(0x2F0000, 'V');
|
||||
AddKey(0x30, 'b');
|
||||
AddKey(0x300000, 'B');
|
||||
AddKey(0x31, 'n');
|
||||
AddKey(0x310000, 'N');
|
||||
AddKey(0x32, 'm');
|
||||
AddKey(0x320000, 'M');
|
||||
#endregion
|
||||
//TODO: up and down Arrows, alt, ctrl, num pad, function keys, insert, home, pg up, delete, end, page down, esc, fn (for laptops)
|
||||
|
||||
#region digits
|
||||
//AddKey(0x1, '`');
|
||||
//AddKey(0x10000, '~');
|
||||
AddKey(0x29, '`');
|
||||
AddKey(0x290000, '~');
|
||||
AddKey(0x2, '1');
|
||||
AddKey(0x20000, '!');
|
||||
AddKey(0x3, '2');
|
||||
AddKey(0x30000, '@');
|
||||
AddKey(0x4, '3');
|
||||
AddKey(0x40000, '#');
|
||||
AddKey(0x5, '4');
|
||||
AddKey(0x50000, '$');
|
||||
AddKey(0x6, '5');
|
||||
AddKey(0x60000, '%');
|
||||
AddKey(0x7, '6');
|
||||
AddKey(0x70000, '^');
|
||||
AddKey(0x8, '7');
|
||||
AddKey(0x80000, '&');
|
||||
AddKey(0x9, '8');
|
||||
AddKey(0x90000, '*');
|
||||
AddKey(0xA, '9');
|
||||
AddKey(0xA0000, '(');
|
||||
AddKey(0xB, '0');
|
||||
AddKey(0xB0000, ')');
|
||||
//reference: http://www.win.tue.nl/~aeb/linux/kbd/scancodes-1.html#ss1.1
|
||||
#region Letters
|
||||
AddKey(0x10, 'q');
|
||||
AddKey(0x100000, 'Q');
|
||||
AddKey(0x11, 'w');
|
||||
AddKey(0x110000, 'W');
|
||||
AddKey(0x12, 'e');
|
||||
AddKey(0x120000, 'E');
|
||||
AddKey(0x13, 'r');
|
||||
AddKey(0x130000, 'R');
|
||||
AddKey(0x14, 't');
|
||||
AddKey(0x140000, 'T');
|
||||
AddKey(0x15, 'y');
|
||||
AddKey(0x150000, 'Y');
|
||||
AddKey(0x16, 'u');
|
||||
AddKey(0x160000, 'U');
|
||||
AddKey(0x17, 'i');
|
||||
AddKey(0x170000, 'I');
|
||||
AddKey(0x18, 'o');
|
||||
AddKey(0x180000, 'O');
|
||||
AddKey(0x19, 'p');
|
||||
AddKey(0x190000, 'P');
|
||||
|
||||
#endregion
|
||||
AddKey(0x1E, 'a');
|
||||
AddKey(0x1E0000, 'A');
|
||||
AddKey(0x1F, 's');
|
||||
AddKey(0x1F0000, 'S');
|
||||
AddKey(0x20, 'd');
|
||||
AddKey(0x200000, 'D');
|
||||
AddKey(0x21, 'f');
|
||||
AddKey(0x210000, 'F');
|
||||
AddKey(0x22, 'g');
|
||||
AddKey(0x220000, 'G');
|
||||
AddKey(0x23, 'h');
|
||||
AddKey(0x230000, 'H');
|
||||
AddKey(0x24, 'j');
|
||||
AddKey(0x240000, 'J');
|
||||
AddKey(0x25, 'k');
|
||||
AddKey(0x250000, 'K');
|
||||
AddKey(0x26, 'l');
|
||||
AddKey(0x260000, 'L');
|
||||
|
||||
#region Special
|
||||
AddKey(0x0E, '\u0968'); //Backspace
|
||||
AddKey(0x0E0000, '\u0968');
|
||||
AddKey(0x0F, '\t'); //Tabulator
|
||||
AddKey(0x1C, '\n'); //Enter
|
||||
AddKey(0x1C0000, '\n');
|
||||
AddKey(0x39, ' '); //Space
|
||||
AddKey(0x390000, ' ');
|
||||
#endregion
|
||||
AddKey(0x2C, 'z');
|
||||
AddKey(0x2C0000, 'Z');
|
||||
AddKey(0x2D, 'x');
|
||||
AddKey(0x2D0000, 'X');
|
||||
AddKey(0x2E, 'c');
|
||||
AddKey(0x2E0000, 'C');
|
||||
AddKey(0x2F, 'v');
|
||||
AddKey(0x2F0000, 'V');
|
||||
AddKey(0x30, 'b');
|
||||
AddKey(0x300000, 'B');
|
||||
AddKey(0x31, 'n');
|
||||
AddKey(0x310000, 'N');
|
||||
AddKey(0x32, 'm');
|
||||
AddKey(0x320000, 'M');
|
||||
#endregion
|
||||
|
||||
#region Punctuation and Signs
|
||||
AddKey(0x27, ';');
|
||||
AddKey(0x270000, ':');
|
||||
AddKey(0x28, '\'');
|
||||
AddKey(0x280000, '"');
|
||||
AddKey(0x2B, '\\');
|
||||
AddKey(0x2B0000, '|');
|
||||
AddKey(0x33, ',');
|
||||
AddKey(0x330000, '<');
|
||||
AddKey(0x34, '.');
|
||||
AddKey(0x340000, '>');
|
||||
AddKey(0x35, '/');
|
||||
AddKey(0x350000, '?');
|
||||
//AddKey(0x4A, '-');
|
||||
AddKey(0x0C, '-');
|
||||
AddKey(0x0C0000, '_');
|
||||
AddKey(0x0D, '=');
|
||||
AddKey(0x0D0000, '+');
|
||||
//AddKey(0x4E, '+');
|
||||
AddKey(0x1A, '[');
|
||||
AddKey(0x1A0000, '{');
|
||||
AddKey(0x1B, ']');
|
||||
AddKey(0x1B0000, '}');
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize() {
|
||||
CheckInit();
|
||||
}
|
||||
#region digits
|
||||
//AddKey(0x1, '`');
|
||||
//AddKey(0x10000, '~');
|
||||
AddKey(0x29, '`');
|
||||
AddKey(0x290000, '~');
|
||||
AddKey(0x2, '1');
|
||||
AddKey(0x20000, '!');
|
||||
AddKey(0x3, '2');
|
||||
AddKey(0x30000, '@');
|
||||
AddKey(0x4, '3');
|
||||
AddKey(0x40000, '#');
|
||||
AddKey(0x5, '4');
|
||||
AddKey(0x50000, '$');
|
||||
AddKey(0x6, '5');
|
||||
AddKey(0x60000, '%');
|
||||
AddKey(0x7, '6');
|
||||
AddKey(0x70000, '^');
|
||||
AddKey(0x8, '7');
|
||||
AddKey(0x80000, '&');
|
||||
AddKey(0x9, '8');
|
||||
AddKey(0x90000, '*');
|
||||
AddKey(0xA, '9');
|
||||
AddKey(0xA0000, '(');
|
||||
AddKey(0xB, '0');
|
||||
AddKey(0xB0000, ')');
|
||||
|
||||
private static void AddKey(uint p, char p_2) {
|
||||
mKeys.Add(new KeyMapping(p, p_2));
|
||||
}
|
||||
#endregion
|
||||
|
||||
private static bool GetCharValue(uint aScanCode, out char aValue) {
|
||||
for (int i = 0; i < mKeys.Count; i++) {
|
||||
if (mKeys[i].Scancode == aScanCode) {
|
||||
aValue = mKeys[i].Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Char not found!");
|
||||
aValue = '\0';
|
||||
return false;
|
||||
}
|
||||
#region Special
|
||||
AddKey(0x0E, '\u0968'); //Backspace
|
||||
AddKey(0x0E0000, '\u0968');
|
||||
AddKey(0x0F, '\t'); //Tabulator
|
||||
AddKey(0x1C, '\n'); //Enter
|
||||
AddKey(0x1C0000, '\n');
|
||||
AddKey(0x39, ' '); //Space
|
||||
AddKey(0x390000, ' ');
|
||||
AddKey(0x4b0000, '\u2190'); //Left arrow
|
||||
AddKey(0x4d0000, '\u2192'); //Right arrow
|
||||
#endregion
|
||||
|
||||
public static char ReadChar() {
|
||||
CheckInit();
|
||||
char xResult = '\0';
|
||||
while (mBuffer.Count == 0 || !GetCharValue(mBuffer.Dequeue(), out xResult))
|
||||
{
|
||||
Global.Sleep(10); //ToDo optimize value
|
||||
}
|
||||
return xResult;
|
||||
}
|
||||
}
|
||||
#region Punctuation and Signs
|
||||
AddKey(0x27, ';');
|
||||
AddKey(0x270000, ':');
|
||||
AddKey(0x28, '\'');
|
||||
AddKey(0x280000, '"');
|
||||
AddKey(0x2B, '\\');
|
||||
AddKey(0x2B0000, '|');
|
||||
AddKey(0x33, ',');
|
||||
AddKey(0x330000, '<');
|
||||
AddKey(0x34, '.');
|
||||
AddKey(0x340000, '>');
|
||||
AddKey(0x35, '/');
|
||||
AddKey(0x350000, '?');
|
||||
//AddKey(0x4A, '-');
|
||||
AddKey(0x0C, '-');
|
||||
AddKey(0x0C0000, '_');
|
||||
AddKey(0x0D, '=');
|
||||
AddKey(0x0D0000, '+');
|
||||
//AddKey(0x4E, '+');
|
||||
AddKey(0x1A, '[');
|
||||
AddKey(0x1A0000, '{');
|
||||
AddKey(0x1B, ']');
|
||||
AddKey(0x1B0000, '}');
|
||||
#endregion
|
||||
}
|
||||
|
||||
private static void AddKey(uint p, char p_2)
|
||||
{
|
||||
mKeys.Add(new KeyMapping(p, p_2));
|
||||
}
|
||||
|
||||
public static void ChangeKeyMap(List<KeyMapping> aKeys)
|
||||
{
|
||||
mKeys = aKeys;
|
||||
}
|
||||
|
||||
private static bool GetCharValue(uint aScanCode, out char aValue)
|
||||
{
|
||||
for (int i = 0; i < mKeys.Count; i++)
|
||||
{
|
||||
if (mKeys[i].Scancode == aScanCode)
|
||||
{
|
||||
aValue = mKeys[i].Value;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Char not found!");
|
||||
aValue = '\0';
|
||||
return false;
|
||||
}
|
||||
|
||||
public static char ReadChar()
|
||||
{
|
||||
CheckInit();
|
||||
char xResult = '\0';
|
||||
while (mBuffer.Count == 0 || !GetCharValue(mBuffer.Dequeue(), out xResult))
|
||||
;
|
||||
return xResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the current KeyMap
|
||||
/// </summary>
|
||||
public class KeyMapping
|
||||
{
|
||||
public uint Scancode;
|
||||
public char Value;
|
||||
|
||||
public KeyMapping(uint aScanCode, char aValue)
|
||||
{
|
||||
Scancode = aScanCode;
|
||||
Value = aValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,53 +2,63 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Cosmos.Hardware {
|
||||
public class TextScreen {
|
||||
public static int CurrentRow = 0;
|
||||
public static int CurrentChar = 0;
|
||||
namespace Cosmos.Hardware
|
||||
{
|
||||
public class TextScreen
|
||||
{
|
||||
//public static int CurrentRow = 0;
|
||||
//public static int CurrentChar = 0;
|
||||
protected const int VideoAddr = 0xB8000;
|
||||
//protected const byte DefaultColor = 7; //Gray
|
||||
protected const byte DefaultColor = 15; //White
|
||||
protected static bool mInitialized = false;
|
||||
protected static byte Color;
|
||||
|
||||
protected static void CheckInit() {
|
||||
if (!mInitialized) {
|
||||
Color = DefaultColor;
|
||||
mInitialized = true;
|
||||
}
|
||||
}
|
||||
protected static void CheckInit()
|
||||
{
|
||||
if (!mInitialized)
|
||||
{
|
||||
Color = DefaultColor;
|
||||
mInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
public static int Rows {
|
||||
public static int Rows
|
||||
{
|
||||
get { return 24; }
|
||||
}
|
||||
|
||||
public static int Columns {
|
||||
get { return 80; }
|
||||
}
|
||||
|
||||
public static void NewLine() {
|
||||
public static int Columns
|
||||
{
|
||||
get { return 80; }
|
||||
}
|
||||
|
||||
public static void NewLine()
|
||||
{
|
||||
CurrentRow += 1;
|
||||
CurrentChar = 0;
|
||||
if (CurrentRow > Rows) {
|
||||
ScrollUp();
|
||||
CurrentChar = 0;
|
||||
if (CurrentRow > Rows)
|
||||
{
|
||||
ScrollUp();
|
||||
CurrentRow -= 1;
|
||||
CurrentChar = 0;
|
||||
}
|
||||
CurrentChar = 0;
|
||||
}
|
||||
|
||||
SetCursor();
|
||||
}
|
||||
|
||||
public static unsafe void Clear() {
|
||||
CheckInit();
|
||||
public static unsafe void Clear()
|
||||
{
|
||||
CheckInit();
|
||||
|
||||
byte* xScreenPtr = (byte*)VideoAddr;
|
||||
for (int i = 0; i < Columns * (Rows + 1); i++) {
|
||||
*xScreenPtr = 0;
|
||||
xScreenPtr++;
|
||||
*xScreenPtr = Color;
|
||||
for (int i = 0; i < Columns * (Rows + 1); i++)
|
||||
{
|
||||
*xScreenPtr = 0;
|
||||
xScreenPtr++;
|
||||
}
|
||||
*xScreenPtr = Color;
|
||||
xScreenPtr++;
|
||||
}
|
||||
|
||||
CurrentChar = 0;
|
||||
CurrentRow = 0;
|
||||
|
|
@ -56,56 +66,63 @@ namespace Cosmos.Hardware {
|
|||
SetCursor();
|
||||
}
|
||||
|
||||
public static void WriteChar(char aChar) {
|
||||
public static void WriteChar(char aChar)
|
||||
{
|
||||
PutChar(CurrentRow, CurrentChar, aChar);
|
||||
CurrentChar += 1;
|
||||
if (CurrentChar == Columns) {
|
||||
NewLine();
|
||||
if (CurrentChar == Columns)
|
||||
{
|
||||
NewLine();
|
||||
}
|
||||
|
||||
SetCursor();
|
||||
}
|
||||
|
||||
protected static unsafe void ScrollUp() {
|
||||
CheckInit();
|
||||
protected static unsafe void ScrollUp()
|
||||
{
|
||||
CheckInit();
|
||||
int Columns2 = Columns * 2;
|
||||
byte* xScreenPtr = (byte*)(VideoAddr );
|
||||
for (int i = 0; i < Columns * Rows; i++) {
|
||||
*xScreenPtr = *(xScreenPtr + Columns2);
|
||||
xScreenPtr ++;
|
||||
*xScreenPtr = *(xScreenPtr + Columns2);
|
||||
xScreenPtr++;
|
||||
}
|
||||
|
||||
xScreenPtr = (byte*)(VideoAddr + Rows * Columns * 2);
|
||||
for (int i = 0; i < Columns; i++) {
|
||||
*xScreenPtr = 0;
|
||||
xScreenPtr ++;
|
||||
*xScreenPtr = Color;
|
||||
byte* xScreenPtr = (byte*)(VideoAddr);
|
||||
for (int i = 0; i < Columns * Rows; i++)
|
||||
{
|
||||
*xScreenPtr = *(xScreenPtr + Columns2);
|
||||
xScreenPtr++;
|
||||
}
|
||||
*xScreenPtr = *(xScreenPtr + Columns2);
|
||||
xScreenPtr++;
|
||||
}
|
||||
|
||||
xScreenPtr = (byte*)(VideoAddr + Rows * Columns * 2);
|
||||
for (int i = 0; i < Columns; i++)
|
||||
{
|
||||
*xScreenPtr = 0;
|
||||
xScreenPtr++;
|
||||
*xScreenPtr = Color;
|
||||
xScreenPtr++;
|
||||
}
|
||||
|
||||
SetCursor();
|
||||
}
|
||||
}
|
||||
|
||||
public unsafe static void PutChar(int aLine, int aRow, char aChar) {
|
||||
CheckInit();
|
||||
public unsafe static void PutChar(int aLine, int aRow, char aChar)
|
||||
{
|
||||
CheckInit();
|
||||
int xScreenOffset = ((aRow + (aLine * Columns)) * 2);
|
||||
byte* xScreenPtr = (byte*)(VideoAddr + xScreenOffset);
|
||||
byte xVal = (byte)aChar;
|
||||
*xScreenPtr = xVal;
|
||||
xScreenPtr ++;
|
||||
*xScreenPtr = Color;
|
||||
byte xVal = (byte)aChar;
|
||||
*xScreenPtr = xVal;
|
||||
xScreenPtr++;
|
||||
*xScreenPtr = Color;
|
||||
|
||||
SetCursor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetColors(ConsoleColor aForeground, ConsoleColor aBackground) {
|
||||
CheckInit();
|
||||
Color = (byte)((byte)(aForeground ) | ((byte)(aBackground ) << 4));
|
||||
}
|
||||
public static void SetColors(ConsoleColor aForeground, ConsoleColor aBackground)
|
||||
{
|
||||
CheckInit();
|
||||
Color = (byte)((byte)(aForeground) | ((byte)(aBackground) << 4));
|
||||
}
|
||||
|
||||
public static void SetCursor()
|
||||
private static void SetCursor()
|
||||
{
|
||||
CheckInit();
|
||||
|
||||
|
|
@ -132,5 +149,33 @@ namespace Cosmos.Hardware {
|
|||
|
||||
Color = tempColor;
|
||||
}
|
||||
|
||||
private static int mCurrentRow = 0;
|
||||
public static int CurrentRow
|
||||
{
|
||||
get
|
||||
{
|
||||
return mCurrentRow;
|
||||
}
|
||||
set
|
||||
{
|
||||
mCurrentRow = value;
|
||||
SetCursor();
|
||||
}
|
||||
}
|
||||
|
||||
private static int mCurrentChar = 0;
|
||||
public static int CurrentChar
|
||||
{
|
||||
get
|
||||
{
|
||||
return mCurrentChar;
|
||||
}
|
||||
set
|
||||
{
|
||||
mCurrentChar = value;
|
||||
SetCursor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,9 +5,11 @@ using Cosmos.Kernel;
|
|||
using Cosmos.Hardware;
|
||||
using Indy.IL2CPU.Plugs;
|
||||
|
||||
namespace Cosmos.Kernel.Plugs {
|
||||
[Plug(Target = typeof(System.Console))]
|
||||
class Console {
|
||||
namespace Cosmos.Kernel.Plugs
|
||||
{
|
||||
[Plug(Target = typeof(System.Console))]
|
||||
class Console
|
||||
{
|
||||
private static ConsoleColor _background = ConsoleColor.Black;
|
||||
private static ConsoleColor _foreground = ConsoleColor.White;
|
||||
|
||||
|
|
@ -38,108 +40,186 @@ namespace Cosmos.Kernel.Plugs {
|
|||
return TextScreen.CurrentChar;
|
||||
}
|
||||
|
||||
public static int get_CursorTop() {
|
||||
public static int get_CursorTop()
|
||||
{
|
||||
return TextScreen.CurrentRow;
|
||||
}
|
||||
}
|
||||
|
||||
public static void set_CursorLeft(int x)
|
||||
{
|
||||
TextScreen.CurrentChar = x;
|
||||
}
|
||||
|
||||
public static void set_CursorTop(int y) {
|
||||
public static void set_CursorTop(int y)
|
||||
{
|
||||
TextScreen.CurrentRow = y;
|
||||
}
|
||||
}
|
||||
|
||||
public static int get_WindowHeight() {
|
||||
public static int get_WindowHeight()
|
||||
{
|
||||
return TextScreen.Rows;
|
||||
}
|
||||
}
|
||||
|
||||
public static int get_WindowWidth() {
|
||||
return TextScreen.Columns;
|
||||
}
|
||||
|
||||
//TODO: Console uses TextWriter - intercept and plug it instead
|
||||
public static void Clear() {
|
||||
public static int get_WindowWidth()
|
||||
{
|
||||
return TextScreen.Columns;
|
||||
}
|
||||
|
||||
//TODO: Console uses TextWriter - intercept and plug it instead
|
||||
public static void Clear()
|
||||
{
|
||||
TextScreen.Clear();
|
||||
set_CursorLeft(0);
|
||||
set_CursorTop(0);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Write(char aChar) {
|
||||
TextScreen.WriteChar(aChar);
|
||||
}
|
||||
public static void Write(char aChar)
|
||||
{
|
||||
TextScreen.WriteChar(aChar);
|
||||
}
|
||||
|
||||
public static void Write(string aText) {
|
||||
for (int i = 0; i < aText.Length; i++) {
|
||||
if (aText[i] == '\n') {
|
||||
TextScreen.NewLine();
|
||||
continue;
|
||||
}
|
||||
if (aText[i] == '\r') {
|
||||
continue;
|
||||
}
|
||||
TextScreen.WriteChar(aText[i]);
|
||||
}
|
||||
}
|
||||
public static void Write(string aText)
|
||||
{
|
||||
for (int i = 0; i < aText.Length; i++)
|
||||
{
|
||||
if (aText[i] == '\n')
|
||||
{
|
||||
TextScreen.NewLine();
|
||||
continue;
|
||||
}
|
||||
if (aText[i] == '\r')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
TextScreen.WriteChar(aText[i]);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLine(string aLine) {
|
||||
Write(aLine);
|
||||
TextScreen.NewLine();
|
||||
}
|
||||
public static void WriteLine(string aLine)
|
||||
{
|
||||
Write(aLine);
|
||||
TextScreen.NewLine();
|
||||
}
|
||||
|
||||
public static void WriteLine(uint aValue) {
|
||||
WriteLine(aValue.ToString());
|
||||
}
|
||||
public static void WriteLine(uint aValue)
|
||||
{
|
||||
WriteLine(aValue.ToString());
|
||||
}
|
||||
|
||||
public static void WriteLine(int aValue) {
|
||||
WriteLine(aValue.ToString());
|
||||
}
|
||||
public static void WriteLine(int aValue)
|
||||
{
|
||||
WriteLine(aValue.ToString());
|
||||
}
|
||||
|
||||
public static void Write(char[] buffer) {
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
Write(buffer[i]);
|
||||
}
|
||||
public static void Write(char[] buffer)
|
||||
{
|
||||
for (int i = 0; i < buffer.Length; i++)
|
||||
Write(buffer[i]);
|
||||
}
|
||||
|
||||
public static void WriteLine(char[] buffer) {
|
||||
Write(buffer);
|
||||
WriteLine();
|
||||
}
|
||||
public static void WriteLine(char[] buffer)
|
||||
{
|
||||
Write(buffer);
|
||||
WriteLine();
|
||||
}
|
||||
|
||||
public static void WriteLine() {
|
||||
TextScreen.NewLine();
|
||||
}
|
||||
public static void WriteLine()
|
||||
{
|
||||
TextScreen.NewLine();
|
||||
}
|
||||
|
||||
public static string ReadLine() {
|
||||
List<char> chars = new List<char>(32);
|
||||
char current;
|
||||
// HACK: convert this to "while ((current = Keyboard.ReadChar()) != '\n') {"
|
||||
// MTW: SOmehow an invalid opcode exception is occurring.
|
||||
while (true) {
|
||||
current = Cosmos.Hardware.Keyboard.ReadChar();
|
||||
if (current == '\n') {
|
||||
break;
|
||||
} else if (current == '\u0968') { // Backspace
|
||||
if (chars.Count > 0) {
|
||||
chars.RemoveAt(chars.Count - 1);
|
||||
TextScreen.CurrentChar--;
|
||||
TextScreen.WriteChar(' ');
|
||||
public static string ReadLine()
|
||||
{
|
||||
List<char> chars = new List<char>(32);
|
||||
char current;
|
||||
int currentCount = 0;
|
||||
|
||||
while ((current = Keyboard.ReadChar()) != '\n')
|
||||
{
|
||||
//Check for "special" keys
|
||||
if (current == '\u0968') // Backspace
|
||||
{
|
||||
if (currentCount > 0)
|
||||
{
|
||||
int curCharTemp = TextScreen.CurrentChar;
|
||||
chars.RemoveAt(currentCount - 1);
|
||||
TextScreen.CurrentChar--;
|
||||
|
||||
//Move characters to the left
|
||||
for (int x = currentCount - 1; x < chars.Count; x++)
|
||||
{
|
||||
Write(chars[x]);
|
||||
}
|
||||
|
||||
Write(' ');
|
||||
|
||||
TextScreen.CurrentChar = curCharTemp - 1;
|
||||
|
||||
currentCount--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (current == '\u2190') // Arrow Left
|
||||
{
|
||||
if (currentCount > 0)
|
||||
{
|
||||
TextScreen.CurrentChar--;
|
||||
currentCount--;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (current == '\u2192') // Arrow Right
|
||||
{
|
||||
if (currentCount < chars.Count)
|
||||
{
|
||||
TextScreen.CurrentChar++;
|
||||
currentCount++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
chars.Add(current);
|
||||
Write(current);
|
||||
}
|
||||
WriteLine();
|
||||
|
||||
// HACK: Should use .ToArray here.
|
||||
char[] final = new char[chars.Count];
|
||||
for (int i = 0; i < final.Length; i++) {
|
||||
final[i] = chars[i];
|
||||
//Write the character to the screen
|
||||
if (currentCount == chars.Count)
|
||||
{
|
||||
chars.Add(current);
|
||||
Write(current);
|
||||
currentCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
//Insert the new character in the correct location
|
||||
//For some reason, List.Insert() doesn't work properly
|
||||
//so the character has to be inserted manually
|
||||
List<char> temp = new List<char>();
|
||||
|
||||
for (int x = 0; x < chars.Count; x++)
|
||||
{
|
||||
if (x == currentCount)
|
||||
{
|
||||
temp.Add(current);
|
||||
}
|
||||
|
||||
temp.Add(chars[x]);
|
||||
}
|
||||
|
||||
chars = temp;
|
||||
|
||||
//Shift the characters to the right
|
||||
for (int x = currentCount; x < chars.Count; x++)
|
||||
{
|
||||
Write(chars[x]);
|
||||
}
|
||||
|
||||
TextScreen.CurrentChar -= (chars.Count - currentCount) - 1;
|
||||
currentCount++;
|
||||
}
|
||||
}
|
||||
|
||||
return new string(final);
|
||||
}
|
||||
}
|
||||
WriteLine();
|
||||
|
||||
char[] final = chars.ToArray();
|
||||
|
||||
return new string(final);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,8 +23,7 @@ namespace CosmosBoot
|
|||
Commander shell = Commander.GetInstance();
|
||||
shell.Start();
|
||||
|
||||
while (true)
|
||||
;
|
||||
while (true) ;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<PlatformTarget>x86</PlatformTarget>
|
||||
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
|
|
|
|||
Loading…
Reference in a new issue