How would I go about writing a Virtual Machine

whoozat picture whoozat · Nov 5, 2009 · Viewed 19.2k times · Source

I'm interested in programming a virtual machine, nothing as fancy as virtualbox or vmware, but something that can emulate a simple architecture, be it cisc or risc, say the Zilog, SPARC, MIPS, or 80686 architecture models.

I suppose by doing this it would be relatively simple to make an emulator of the same kind, I'm just interested in using this for experience more than anything else (being my first C project, I'd rather do this in C than in anything else).

Answer

mjv picture mjv · Nov 5, 2009

Check what others have done in this area!

A good way to pick-up info about a particular type of application (and in your case a good way to pick up c idioms as well) is by looking at the structure and the detail of an open source project of the same type. One may decide to merely peek, briefly review and then "forget", in order to start one's very own project from scratch, but in all cases this type of visit is beneficial.

Since you mentioned "simple architecture" and Zilog, I figured the Z80 processor could be a good match. For various reasons there are many current and past projects in the Z80 emulator genre. BTW, one of the reasons is that many older slot-type video consoles were running on Z80, which prompted nostalgic gamers to write emulators to run their old favorites ;-)

An example of such a project is YAZE-AG which includes both a full Z80 emulator as well as C/PM. The whole thing is written in C. Also it is relatively mature (Version 2.x) and active. I'm guessing this is the work of a very small team (possibly of one ;-) ).

Good luck!