[Cowlark Logo] cowlark.com

vbccz

a C compiler that targets the Z machine

There is only one real language that you use when writing code for the Z-machine: Inform. Don't get me wrong, Inform is a great language, but the Z-machine is Turing complete, it's got combined data and address space, a decent set of opcodes, a sensible memory map... you should be able to compile anything into it. Like, say, C.

Damn. I should know better than to say things like that.

About a year later, after several false starts, I had successfully written a back end for Volker Barthelmann's VBCC C compiler that targeted the Z-machine. It does varargs, 32-bit ints, signed and unsigned variables, everything. It will, basically, compile ordinary ANSI C into Z-machine assembler ready for including in your game. It doesn't do floating point support (but I have an idea about that), and there is no libc, so you have to do everything from scratch.

You can get it here.

Note that because of the licensing restrictions on vbcc (which is really neat, by the way; it's got excellent global optimisations, an easy-to-understand back end interface, is small and incredibly fast; if you're interested in compilers for embedded systems, take a look) I can't distribute it with my changes. What I can do is to distribute the original source code plus a patch containing all my alterations, so that's what you get here.

These links, by the way, are hosted on Interactive Fiction Archive, because it's got way more bandwidth than I do. Check it out.

Once the patch is applied the compiler should build relatively straightforwardly.

Debian users should note that you can get a prebuilt version on my Debian repository. I'm working on getting it included in the main Debian archive.

For an example of a complicated project that uses it, see my game Silicon Castles which is written in a combination of Inform and C. It also contains a stripped down libc I stole from the ELKS Embedded Linux project.


Now, remember I said earlier about there being a few false starts? Well, on the way I had several interesting and entertaining encounters with some compilers...

Firstly, lcc. lcc is a freeish retargetable ANSI C compiler for several systems, including Windows. Before I discovered vbcc, lcc was my best bet. However, the lcc back end interface is pretty naff and is only partially documented, so I never finished anything. Interested parties might want to look at my code.

Page last updated: 2008 October 14 © 2008-2013 David Given, unless specified otherwise