Z-machine Hacks

From IFWiki
Revision as of 19:50, 8 August 2013 by Zzo38 (Talk | contribs)

Jump to: navigation, search


Here I list a bunch of things that can be done with Z-machine, not specific to any programming language (although some may only be possible in some programming languages). Examples may sometimes be given in the Frolg assembler language, if necessary.

Alphabet table

The alphabet table can be modified so that common characters are on row 0. If there are uncommon characters but they often go together in long strings (for output only, though), you might put them on row 2; a permanent shift into row 2 can more efficiently select a single character from row 1 than the other way around. (Note: Frolg is the only known compiler that can take advantage of this, and not if it is in COMPLIANT mode.)

See also: Fun With ZCharacter

Global variables overlapping the extension table

The global variable table can overlap the extension table, so that the mouse and joystick state can be accessed directly as variables.

Global variables overlapping the object table

If the object table is placed right after the global variables table, the first object header might fit in the global variables table. If the first object is the player, then you can read their location easily as a global variable.

Level data in high memory

If the level data doesn't fit in core memory, you can store it in high memory, as a text string loaded into output stream 3.

A two-stage compression can be used, one of which is the Z-machine text packing (which can use the fwords table and other things), and then use a secondary decompression implemented in your program, which might involve run-length encoding, Huffman coding, and whatever else is necessary.

Remember that you will want to represent the most common tiles, as well as other things like run-length, in row 0 (lowercase letters).

Shared property tables

You can make multiple objects sharing property tables if it would help. Such objects will then share their name and property values, although they will still have their individual locations and attributes.

It might help if the properties are read-only for those class of objects. An example might be if many rooms contain an identical magical portal all leading to the same location.

Truncated default property table

If you don't need 63 default properties, you can truncate the default property table to only the default properties you need. Number the properties that need defaults with the highest numbers, 63 and down. The header to specify where the object table is, it is then deducted the unused default properties so that the address of the default properties will be correct. (Frolg automatically does this.)

Very long object names

Object names have to be in core (which is limited to 64K) and are limited to 765 Z-characters. If you have very long names, you can make them fit by storing them in the fwords table. (The Z-machine port of Wry Humor does this.)