Tuesday, July 8, 2014


I've been toying with the notion of building a virtual machine as a means to make more game code more portable. What you see here is a rather flickery proof of concept.

I started off with a super simple pygame bouncing ball app - something like 20 lines, about evenly divided between setup code and the per-frame animation. I translated the Python code into my own invented assembly language, which I proceeded to assemble into machine code for my invented virtual machine.

The initialization is 34 bytes long, which initializes the speed, size, and position of the ball. The per-frame code is 108 bytes long, which moves the ball, tests to see if it's hit the edges, and if so, multiply the relevant velocity component by -1. At the end of updating the velocity, there's a call to draw the screen and draw the ball.

One of the next steps would be to write a compiler, rather than code in assembly.

Another thing to do would be to expand the app to do more, like actually accept user input.

Yet another thing to do, before or after the above steps. is to port the VM to other platforms, like JavaScript in the browser, Objective C on iOS, and Java on Android.