Friday, May 30, 2014

Cosmos - Part 1 - Programming your own OS in less than 5 minutes

This advertising slot is open! To have a paragraph here featuring your company (doesn't have to be tech related), go to http://www.fiverr.com/armmaster17/mention-your-company-in-a-blog-post.

Hey blog readers! we have a new Facebook page! Check it out at http://on.fb.me/U9s2Ld

Have you ever wanted to program your own operating system. If you have ever talked to someone who has done this before, they probably tried to scare you away with "bootstraps" and "GDT tables" and so on. Well, there is an easier solution, and you can make your own operating system in less that 10 minutes with NO programming experience. Welcome to Cosmos.

Prerequisites:
-Basic programming knowledge (C# is recommended, but Java, C++, VB.NET, FORTRAN, or Delphi should be fine)
-Patience
-some more patience
-about an hour (or a weekend, whatever you think you'll need)
-VMware Player (if you know what you are doing, you can skip this and use your own Virtual Machine)
 You can get VMware Player for free at https://my.vmware.com/web/vmware/free#desktop_end_user_computing/vmware_player/6_0
-A copy of Visual Studio (instructions below)

To obtain a copy of Visual Studio that works with Cosmos, first you need to know what you are looking for. You are looking for one of the following versions of Visual Studio.
-Visual Studio 2013 Express
-Visual Studio 2013 Professional
-Visual Studio 2013 Ultimate
-Any other version of Visual Studio 2013 (except for Beta, Team Explorer, and Shell editions)

If you don't already own any of these, I recommend Visual Studio 2013 Express, it's the only free one. I will be uploading screenshots from Visual Studio 2013 Professional. There should be no difference other than you might see a few extra buttons on my screen (which aren't required to make Cosmos work).

This is what your add project dialog should look like.
Ok, enough of that. let's get started! First head over to http://cosmos.codeplex.com/ and click on the big purple download button. Before you proceed, make sure you have installed Visual Studio and have run it at least once). After it finishes downloading, run it. Make sure you are on an administrative account or it won't work. If it gets stuck around the 100% mark, don't worry. This is normal. Once it finishes, open up Visual Studio and click File->New->Project. On the left hand side, look for an item that says Cosmos. Click on it then look at the big window with the icons. Click the one that has C# in it (make sure it is the C# one, or else you're going to have a bad day). Name it and select a folder to save it to (make sure it gets its own folder, there are a lot files in there that we are going to need). Now we can get coding!

The default code that loads with the template
Once your project loads, you will see some code. To the average programmer, this code is nothing new. To someone who has never typed a line of code, this could look pretty frightening. DON'T PANIC! If you get really lost (or lazy), you can just delete all of that code and copy and paste the finished code at the bottom.
But before we start changing the code, let's just run the default code and see what it does. If you look at the toolbars at the top of the screen, you should see a green arrow.

Next to it should be some text (Launch, Debug or Start are the most common, it depends on which version of Visual Studio you are running). Click the green arrow. It can take some time to compile (on my six year old machine, it takes about one or two minutes). Once done, you should see VMware Player pop up. If you see VMware, skip the next paragraph.

If not and you got an error, it could be one of two things. One, you edited the code. To fix this, go back and create a new project. Or two, you decided to not install VMware and use your own Virtual Machine or even use your own machine. In this case, navigate to your project directory and look around for a .ISO file. You can plug this into your own Virtual Machine or burn it to a CD or USB drive and try it on a real machine. You could also try to network boot it, but you will need your own tools (the integrated PXE server has been removed from Cosmos).

Now you should see a bunch of text followed by:
Cosmos booted successfully. Type a line of text to get it echoed back.
Congratulations! You have created your first operating system! Stay tuned for my next article where we will jump strait in and add mouse support with only a few lines of code! If you run into any trouble, leave a comment and any one of our authors will help you. Go to part two here -> http://allstuffnerdy.blogspot.com/2014/05/cosmos-part-2-lets-make-shell.html. If you are more experienced at programming, head over here http://www.codeproject.com/Articles/99928/Develop-Your-Own-Operating-System-in-C-or-VB-NET. They cover everything that I covered in this article, but they also go over the advanced debugging features in Cosmos that you may find handy to use at one point or another. Have Fun!

Hey blog readers! If you want to follow our meaningless updates, check out our pages here:
Facebook: http://on.fb.me/U9s2Ld
Twitter: Follow us @allstuffnerdy
Google+: https://www.google.com/+AllstuffnerdyBlogspot
If you have a business you would like us to mention at the beginning of a post, check out our gigs on Fiverr:
Joshua: http://fiverr.com/armmaster17
Brandon: http://fiverr.com/maltzy

1 comment:

  1. I found an error that at unexpected exception during attach System.IO.FileNotFoundException

    on github: https://github.com/CosmosOS/Cosmos/issues/1365

    ReplyDelete