Tag Archives: visual studio

Operating System

ctOS – 6502 TypeScript Operating System

For my Operating Systems class, I was tasked with making an Operating System simulation using basic OS architecture and 6502 operations.

Using TypeScript, I implemented a CPU, CPU scheduler with 3 scheduling methods, memory manager for RAM, kernel interrupt and ready/resident queue, hard drive and hard drive driver with swap virtual memory. I also added neat features like achievements, boot video, step mode, and tons of little special commands.

It was one of my favorite projects of all time in my education. It was a lot of fun to implement new achievements into something like an Operating System and the design for ready queues/CPU scheduling was really interesting. I also found a new language to love. TypeScript is a JavaScript transpiler that gives type checking and more to JS, made by none other than Microsoft. I’m a strict type kind of guy, and it has been my biggest pet peeve of JS for a long time. TypeScript was a god send, and will be what I use whenever I have to write JS now. Combined with native debugging in Visual Studio, it can be extremely powerful and helpful. It makes Object Orientated programming in JS to be a breeze.

There are a bunch of built in programs to ctOS you can find in the sidebar, but feel free to make your own. There was discussion on how it would easily be possible to read/write executable programs to the hard drive, and with a few more op codes, you could have the simplified 6502 CPU do some pretty legit algorithms like merge sort and stuff. Its a fun Operating System.

Feel free to check it out here:
http://anthonyb28.github.io/ctOS/

Source & Readme:
http://github.com/anthonyb28/ctOS/

Recommended Reading: RunTime C++ Scripting

Interesting bit came up at work with our bi-weekly “brown bag” lunches with our programming team – Scripting vs Native C++ code. A lot of game developers, and even in many other realms, some of the code base may be split into Lua or Python for easy, quick iteration. I know many studios, such as many of the Call of Duty studios, use primarily Lua for their gameplay scripts.

The argument is that is easy to write, iterate fast, and provide to employees who don’t have deep programming knowledge (like some gameplay designers and such). It’s perfectly legitimate too, there isn’t anything inherently wrong with the scripting languages augmenting a huge C++ code-base engine. However, there are caveats such as managing two different languages and creating wrappers for stuff. Also, Lua doesn’t have proper debugging tools many C++ programmers are used to, and when tied into that code-base, it can become a nightmare to debug.

Enter C++ code thats runtime-compiled and used as a scripting language.

Fantastic read, pretty classy too. Each script is a single cpp file that gets compiled into a dynamic library which recompiles everytime the file changes, even during gameplay. The scripts even get a nice little compression size reduction too. Good read.

Today I Learned: Struct Packing With A Microsoft Twist

Member declaration order for structs and classes are important. You want to order the smallest to the largest (or vice versa) in order to avoid what’s known as ‘padding’. Padding is basically what the compiler will use to keep the memory allocation of the struct/class aligned in memory. This padding tends to be wasted space unless some compiler specific enhancement is occurring.

What I learned today was that Microsoft’s C++ compiler actually has extra padding involved, by design. And the solution to avoid the extra previous memory being stolen from you? Quite elementary, how could you not know? Inheriting from an empty abstract class makes your objects smaller.

Continue reading