Tags

vbccz

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.

My patch. To apply this, you'll need a copy of Larry Wall's patch program. It's
supplied with just about any remotely Unixoid operating system.
Windows users are instructed to get Cygwin.

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.

Before doing the Z-machine code generator, I had a look at
Andrew Plotkin's
Glulx virtual
machine instead. This is a code generator for Glulx. Does not
work, but works a lot better than the zcom code generator; you
can actually compile a reasonable number of programs with this.
You'll need the Glulxa assembler to
compile the output.