mirror of
https://github.com/danbulant/Cosmos
synced 2026-06-11 18:51:41 +00:00
Made the demo console. Try out the type command...
This commit is contained in:
parent
10ba077bb8
commit
78d2fdc405
6 changed files with 106 additions and 30 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,6 @@ namespace Cosmos.Shell.Console.Commands {
|
|||
get;
|
||||
}
|
||||
|
||||
public abstract void Execute();
|
||||
public abstract void Execute(string param);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -48,6 +49,10 @@
|
|||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Cosmos.Hardware\Cosmos.Hardware.csproj">
|
||||
<Project>{CE50FE98-9AC4-4B4D-ADC7-31F6DCD28755}</Project>
|
||||
<Name>Cosmos.Hardware</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Cosmos.Kernel\Cosmos.Kernel.csproj">
|
||||
<Project>{A1F83D9F-2D44-4264-A08B-416797123018}</Project>
|
||||
<Name>Cosmos.Kernel</Name>
|
||||
|
|
|
|||
|
|
@ -24,37 +24,40 @@ namespace Cosmos.Shell.Console {
|
|||
}
|
||||
|
||||
public override void Initialize() {
|
||||
_commands = new List<Cosmos.Shell.Console.Commands.CommandBase>();
|
||||
_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<Char> target = new List<char>();
|
||||
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()
|
||||
{
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue