/
Kernel.cs
124 lines (116 loc) · 4.29 KB
/
Kernel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Sys = Cosmos.System;
using System.IO;
using Cosmos.System.ScanMaps;
using Cosmos.Debug.Kernel;
using Cosmos.HAL.BlockDevice;
//128, 38
namespace VerySmallOS
{
public class Kernel : Sys.Kernel
{
//public static Sys.FileSystem.FileSystem fileSystem;
public static Sys.FileSystem.CosmosVFS fileSystem;
string[] supportedCommands = new string[] { "ls", "dir", "mkdir", "cat", "exit", "startx", "help", "touch"};
string currentPath = "0:";
string[] cmd;
public static Debugger debugger;
public void RunCommand(string[] cmd)
{
FileSystemUtils.CheckForFileinsertOperator(cmd, out bool containsWriteOp);
if (containsWriteOp)
return;
switch (cmd[0])
{
case "ls":
case "dir":
FileSystemUtils.Dir(currentPath, cmd);
break;
case "cat":
FileSystemUtils.Cat(cmd[1]);
break;
case "touch":
FileSystemUtils.Touch(cmd[1]);
break;
case "mkdir":
FileSystemUtils.Mkdir(cmd[1]);
break;
case "help":
for (int i = 0; i < supportedCommands.Length; i++)
Console.Write($"{supportedCommands[i]}\t");
Console.Write('\n');
break;
case "exit":
EnvironmentUtils.Exit();
break;
case "startx":
Console.WriteLine("Are you sure you want to change to graphical mode? (Y/N)");
string isSure = Console.ReadLine();
if (isSure.ToUpper() != "Y")
return;
Console.WriteLine("For cursor mode press 1, for shape mode press 2");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
GraphicsSubsystemUtil.StartGraphicalMode(System.Drawing.Color.Wheat);
GraphicsSubsystemUtil.EnableCursor();
break;
case "2":
GraphicsSubsystemUtil.StartGraphicalMode(System.Drawing.Color.Wheat);
break;
default:
Console.WriteLine("Invalid choice. :/\nBack to console mode. ");
break;
}
break;
default:
if (cmd[0] != "")
Console.WriteLine("Command not recognized");
break;
}
}
protected override void BeforeRun()
{
debugger = mDebugger;
Console.Clear();
Console.WriteLine("Welcome to verySmallOS\n");
SetKeyboardScanMap(EnvironmentUtils.QueryUserForKeymap());
/*
var fsFactory = new Sys.FileSystem.FatFileSystemFactory();
var blockDevice = BlockDevice.Devices.First();
var partition = new Partition(blockDevice, 254, 50000);
fileSystem = fsFactory.Create(partition, "0:", 47000);
*/
fileSystem = new Sys.FileSystem.CosmosVFS();
Sys.FileSystem.VFS.VFSManager.RegisterVFS(fileSystem);
Console.WriteLine("\n(Use \"startx\" to enter the rudimentary graphical mode :))\n\n\n\n\n\n");
}
protected override void Run()
{
try
{
if (GraphicsSubsystemUtil.IsGraphicsSubsystemRunning)
{
GraphicsSubsystemUtil.Redraw();
}
else
{
cmd = Console.ReadLine().Split(' ');
RunCommand(cmd);
}
}
catch (Exception e)
{
mDebugger.Send("Exception occurred: " + e.Message);
mDebugger.Send(e.Message);
Stop();
}
}
}
}