From 78d2fdc40540aff82dc32c47cbaf2d3e078295a3 Mon Sep 17 00:00:00 2001
From: moitoius_cp <7bd20ad30720b36bd251fb928c419f8754d57bfcCkJyHhZD>
Date: Wed, 2 Jan 2008 09:46:04 +0000
Subject: [PATCH] Made the demo console. Try out the type command...
---
source/Cosmos/Cosmos.Kernel/Keyboard.cs | 5 ++
.../Commands/FSTestCommand.cs | 33 ++++++++++--
.../Cosmos.Shell.Console/Commands/ICommand.cs | 2 +-
.../Cosmos.Shell.Console.csproj | 5 ++
.../Cosmos/Cosmos.Shell.Console/Prompter.cs | 53 ++++++++++---------
.../CustomImplementation/System/StringImpl.cs | 38 ++++++++++++-
6 files changed, 106 insertions(+), 30 deletions(-)
diff --git a/source/Cosmos/Cosmos.Kernel/Keyboard.cs b/source/Cosmos/Cosmos.Kernel/Keyboard.cs
index d1ed6f339..e612e240a 100644
--- a/source/Cosmos/Cosmos.Kernel/Keyboard.cs
+++ b/source/Cosmos/Cosmos.Kernel/Keyboard.cs
@@ -115,6 +115,11 @@ namespace Cosmos.Kernel {
AddKey(0x39, ' ');
AddKey(0x390000, ' ');
#endregion
+
+ #region Punctuation
+ AddKey(0x34, '.');
+ AddKey(0x340000, '>');
+ #endregion
}
private static void AddKey(uint p, char p_2)
diff --git a/source/Cosmos/Cosmos.Shell.Console/Commands/FSTestCommand.cs b/source/Cosmos/Cosmos.Shell.Console/Commands/FSTestCommand.cs
index 28d4cea3a..c18470ea6 100644
--- a/source/Cosmos/Cosmos.Shell.Console/Commands/FSTestCommand.cs
+++ b/source/Cosmos/Cosmos.Shell.Console/Commands/FSTestCommand.cs
@@ -1,17 +1,44 @@
using System;
using System.Collections.Generic;
using System.Text;
+using Cosmos.Kernel;
namespace Cosmos.Shell.Console.Commands {
public class FSTestCommand : CommandBase {
public override string Name {
get {
- return "fstest";
+ return "type";
}
}
- public override void Execute() {
- System.Console.WriteLine ("Testing...");
+ public override void Execute(string param) {
+ System.Console.Write("Emitting contents of ");
+ System.Console.Write(param);
+ System.Console.WriteLine(":");
+
+ Hardware.Storage.ATA xDrive = new Cosmos.Hardware.Storage.ATA(0, 0);
+ Cosmos.Kernel.FileSystem.Ext2 xExt2 = new Cosmos.Kernel.FileSystem.Ext2(xDrive);
+ if (xExt2.Initialize())
+ {
+ System.Console.WriteLine("Ext2 Initialized");
+ }
+ else
+ {
+ System.Console.WriteLine("Ext2 Initialization failed!");
+ }
+ byte[] xItem = xExt2.ReadFile(new string[] { param });
+ if (xItem == null)
+ {
+ System.Console.WriteLine("Couldn't read file!");
+ return;
+ }
+ char[] xChars = new char[xItem.Length - 1];
+ for (int i = 0; i < xChars.Length; i++)
+ {
+ xChars[i] = (char)xItem[i];
+ }
+ String s = new String(xChars);
+ System.Console.WriteLine(s);
}
}
}
diff --git a/source/Cosmos/Cosmos.Shell.Console/Commands/ICommand.cs b/source/Cosmos/Cosmos.Shell.Console/Commands/ICommand.cs
index 54fba961b..040ec3399 100644
--- a/source/Cosmos/Cosmos.Shell.Console/Commands/ICommand.cs
+++ b/source/Cosmos/Cosmos.Shell.Console/Commands/ICommand.cs
@@ -14,6 +14,6 @@ namespace Cosmos.Shell.Console.Commands {
get;
}
- public abstract void Execute();
+ public abstract void Execute(string param);
}
}
diff --git a/source/Cosmos/Cosmos.Shell.Console/Cosmos.Shell.Console.csproj b/source/Cosmos/Cosmos.Shell.Console/Cosmos.Shell.Console.csproj
index bed8f22ba..6d5678ab2 100644
--- a/source/Cosmos/Cosmos.Shell.Console/Cosmos.Shell.Console.csproj
+++ b/source/Cosmos/Cosmos.Shell.Console/Cosmos.Shell.Console.csproj
@@ -26,6 +26,7 @@
prompt
4
x86
+ false
pdbonly
@@ -48,6 +49,10 @@
+
+ {CE50FE98-9AC4-4B4D-ADC7-31F6DCD28755}
+ Cosmos.Hardware
+
{A1F83D9F-2D44-4264-A08B-416797123018}
Cosmos.Kernel
diff --git a/source/Cosmos/Cosmos.Shell.Console/Prompter.cs b/source/Cosmos/Cosmos.Shell.Console/Prompter.cs
index c1e38d53c..80685717a 100644
--- a/source/Cosmos/Cosmos.Shell.Console/Prompter.cs
+++ b/source/Cosmos/Cosmos.Shell.Console/Prompter.cs
@@ -24,37 +24,40 @@ namespace Cosmos.Shell.Console {
}
public override void Initialize() {
+ _commands = new List();
+ _commands.Add(new Commands.FSTestCommand());
+
while (running)
{
+ System.Console.Write("/> ");
string line = System.Console.ReadLine();
- int index = IndexOf(line, ' ') + 1;
- string command = Substring(line, index);
- System.Console.WriteLine(command);
+ int index = line.IndexOf(' ');
+ string command;
+ string param;
+ if (index == -1)
+ {
+ command = line;
+ param = "";
+ }
+ else
+ {
+ command = line.Substring(0, index);
+ param = line.Substring(index + 1);
+ }
+
+ for (int i = 0; i < _commands.Count; i++)
+ {
+
+ if (_commands[i].Name.CompareTo(command) == 0)
+ {
+ _commands[i].Execute(param);
+ break;
+ }
+ }
+
}
}
- private int IndexOf(string source, char look)
- {
- for (int i = 0; i < source.Length; i++)
- if (source[i] == look)
- return i;
- return -1;
- }
-
- private string Substring(string source, int index)
- {
- List target = new List();
- for (int i = index; i < source.Length; i++)
- target.Add(source[i]);
-
- // HACK: Should use .ToArray here.
- char[] final = new char[target.Count];
- for (int i = 0; i < final.Length; i++)
- final[i] = target[i];
-
- return new string(final);
- }
-
public override void Teardown()
{
diff --git a/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs b/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs
index 7d0cbc115..f5fe28262 100644
--- a/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs
+++ b/source/Indy.IL2CPU/CustomImplementation/System/StringImpl.cs
@@ -38,7 +38,43 @@ namespace Indy.IL2CPU.CustomImplementation.System {
return -1;
}
- [PlugMethod(Enabled = false)]
+ public static string Substring(string aThis, int startpos)
+ {
+ char[] cs = new char[aThis.Length - startpos];
+
+ int j = 0;
+ for (int i = startpos; i < aThis.Length; i++)
+ cs[j++] = aThis[i];
+
+ return new string(cs);
+ }
+
+ public static string Substring(string aThis, int startpos, int length)
+ {
+ if (startpos + length > aThis.Length)
+ length = aThis.Length - startpos;
+
+ char[] cs = new char[length];
+
+ int j = 0;
+ for (int i = startpos; i < startpos + length; i++)
+ cs[j++] = aThis[i];
+
+ return new string(cs);
+ }
+
+ // HACK: We need to redo this once char support is complete (only returns 0, -1).
+ public static int CompareTo(string aThis, string other)
+ {
+ if (aThis.Length != other.Length)
+ return -1;
+ for (int i = 0; i < aThis.Length; i++)
+ if (aThis[i] != other[i])
+ return -1;
+ return 0;
+ }
+
+ [PlugMethod(Enabled = false)]
public static uint GetStorage(string aString) {
return 0;
}