Recently I came across an add-on for Visual Studio 2013 named Cosmos, which lets you use C# or Visual Basic to develop a fully independent OS. I have been working on one now for a couple of weeks. Sadly, Cosmos is still in early development stages, but it is still possible to make basic graphical OS’s. This post uses C#, but it is just as easy to use Visual Basic. My current code is:
using System;
using System.Collections.Generic;
using System.Text;
using Sys = Cosmos.System;
using Cosmos.Hardware;
using Cosmos.Hardware.BlockDevice;
namespace CosmosOS
{
public class Kernel : Sys.Kernel
{
protected override void BeforeRun()
{
while (true)
{
Run();
}
}
protected override void Run()
{
string input = Console.ReadLine();
string input1 = input.ToLower();
if (input1 == "shutdown" || input1 == "quit" || input1 == "exit") Shutdown();
else if (input1 == "reboot" || input1 == "restart" || input1 == "reload") Reboot();
else Console.WriteLine("Command \"" + input1 + "\" not recognized!");
public void Shutdown()
{
this.Stop();
Cosmos.Core.Bootstrap.CPU.Halt();
}
public void Reboot()
{
}
public static void WriteData(byte[] aData, ulong block)
{
if (BlockDevice.Devices.Count > 0)
{
for (int i = 0; i < BlockDevice.Devices.Count; i++)
{
var xDevice = BlockDevice.Devices[i];
if (xDevice is Partition)
{
xDevice.WriteBlock(block, 1, aData);
}
}
}
}
public static byte[] ReadData(ulong block)
{
byte[] aData = new byte[] { 1 };
if (BlockDevice.Devices.Count > 0)
{
for (int i = 0; i < BlockDevice.Devices.Count; i++)
{
var xDevice = BlockDevice.Devices[i];
if (xDevice is Partition)
{
aData = xDevice.NewBlockArray(1);
xDevice.ReadBlock(block, 1, aData);
}
}
}
return aData;
}
}
}
Lets go over some of this code.
protected override void BeforeRun()
{
while (true)
{
Run();
}
}
This Run function is looped by default anyway, but it loops slightly faster when this code is put in BeforeRun.
protected override void Run()
{
string input = Console.ReadLine();
string input1 = input.ToLower();
if (input1 == "shutdown" || input1 == "quit" || input1 == "exit") Shutdown();
else if (input1 == "reboot" || input1 == "restart" || input1 == "reload") Reboot();
else Console.WriteLine("Command \"" + input1 + "\" not recognized!");
This is fairly trivial code for a command-line OS, simple input.
public void Shutdown()
{
this.Stop();
Cosmos.Core.Bootstrap.CPU.Halt();
}
public void Reboot()
{
}
This is my own shutdown code. I have yet to figure out reboot, though.
public static void WriteData(byte[] aData, ulong block)
{
if (BlockDevice.Devices.Count > 0)
{
for (int i = 0; i < BlockDevice.Devices.Count; i++)
{
var xDevice = BlockDevice.Devices[i];
if (xDevice is Partition)
{
xDevice.WriteBlock(block, 1, aData);
}
}
}
}
public static byte[] ReadData(ulong block)
{
byte[] aData = new byte[] { 1 };
if (BlockDevice.Devices.Count > 0)
{
for (int i = 0; i < BlockDevice.Devices.Count; i++)
{
var xDevice = BlockDevice.Devices[i];
if (xDevice is Partition)
{
aData = xDevice.NewBlockArray(1);
xDevice.ReadBlock(block, 1, aData);
}
}
}
return aData;
}
I got this code from a forum and modified it a little to make it work – it writes arrays of bytes to the hard disk. Sadly the built-in FAT fileystem can currently only read files, so you will have to make your own.
This is a fun tool to just play around with, although it is extremely limited at the moment.
http://www.nikeairmaxfreerun.com nike air max thea
Good stuff 🙂
Hi
Try Cosmos.Core.Bootstrap.CPU.Reboot();
This hasn’t been tested btw