From: linhart@remus.rutgers.edu (Mike Threepoint)
Newsgroups: rec.games.int-fiction
Subject: Re: Wanted: A listings of anonymous ftp for Infocom stuffs.
Date: 28 Sep 92 02:33:03 GMT
Organization: Frobozz Magic Amulet of Yendor Company

tstark@access.digex.com (Timothy M. Stark) writes:
>      I am looking for a listing of anonymous ftp that contains infocom
> stuffs like ZIL Interpreter/compiler/decompiler package, protocol
> guide for .dat files. Since I heard that you discussed about ZIL
> interpreters on this machine. If so, I will appericate that. Thanks!

As I wrote in the zorkword post earlier this week, I've put a few
files up for ftp on remus.rutgers.edu, including zorkword.c, a beta
version of the revised InfoTaskForce version 3 Z-code interpreter
(which does not crash on Lurking Horror sounds like zmachine, BTW),
and Mark Howell's impressive Infocom Tools which include a compiled
Z-code disassembler.

>      Since I already have some few stuffs but I still am looking for
> memory map guide for .dat file (all versions). 

Here's a mostly accurate file that tells a bit about version 3 structures:

              -------------------------------------      2.0 - Aug 11, 1992
              Structure of the Z-Code 3 Game Header
              -------------------------------------
                 Compiled by Paul David Doherty

This list contains everything I know abot the flags and offsets in the game
header of Infocom's standard data files (version 3). If you have additional
information, please contact me at <h0106kdb@rz.hu-berlin.de> or at
<d.doherty@bamp.berlinet.in-berlin.de>.


The Data File
=============

An Infocom data file consists of three parts:

    The Game Header

    The Tables (Synonyms, Objects, Global Variables, Dictionary)

    The Z-code


The Game Header
===============

The first 0x40 bytes of a data file are called the "game header". The game
header contains:

    Offsets

    [These offsets for the various tables in the data file are needed by
    the Z-machine.]

    Revision Information

    [Release and serial numbers of the data file; needed by the Z-code for
    printing out the VERSION info and by the Z-machine to identify save
    files etc.]

    Flags

    [Needed by Z-code and Z-machine.]


This is the information contained in the header:

Offset Length   Function

0x00   byte     Z-code Version

                [This is always set to 0x03 in version 3 games.]

0x01   byte     Flags #1

                [See under "Flags".]

0x02   word     Release Number

                [ (value & 0x07ff) is the release number of the data
                file.]

0x04   word     Size of Resident Data

                [At this offset begins the third part of the data file, the
                actual Z-code.]

0x06   word     Start of Main Routine

                [This is where the Z-machine begins to interpret the
                Z-code.]

0x08   word     Dictionary Offset

                [Offset of the dictionary table, which contains the
                vocabulary that the player can use.]

0x0a   word     Object Offset

                [Offset of the object table.]

0x0c   word     Variables Offset

                [Offset of the global variables table.]

0x0e   word     Save Area Size

                [Everything after that offset is permanent and remains
                unchanged while the Z-code is interpreted.]

0x10   word     Flags #2

                [See under "Flags".]

0x12   6 bytes  Serial Number

                [This is the serial number of the game, as ASCII
                characters.]

0x18   word     Synonyms Offset

                [Offset for the synonym table.]

0x1a   word     Game Length

                [Length of the data file in words.]

0x1c   word     Checksum

                [Checksum of the data file. Result of the addition of all
                bytes from 0x40 to ( Game Length * 2 ). Used by $VERIFY.]

The rest of the header is not used in version 3 data files.

"Game Length" and "Checksum" were introduced in 1982. Old games may not
have those.


Flags
=====

I have tried to give a "direction" in which the flags work. The four
directions are:

  (1)   Implementors  ->  Z-machine
  (2)   Implementors  ->  Z-code
  (3)   Z-machine     ->  Z-code
  (4)   Z-code        ->  Z-machine

(1) and (2) are results of the compilation process and can't be changed.
(3) and (4) can be adjusted before and during the interpretation process.


Flag Bit  Direction  Function

 #1  0x01    (1)     ??

 #1  0x02    (1)     Status Line Type

                     [If the flag is set the Z-machine will print a "Time"
                     status line, otherwise a "Score" status line.]

                     [The only games which use a "Time" status line are:
                     Cutthroats, Deadline, Moonmist, Suspect, Wishbringer,
                     The Witness.]

 #1  0x04    (1)     ??

 #1  0x08  (2 or 3)  Tandy License

                     [Some Infocom games have been licensed to Tandy
                     Corporation. If this flag is set, the VERSION
                     command tells you of this license.]

                     [The following games support this flag:
                     Hollywood Hijinx, Seastalker, Suspect, The Witness,
                     Zork I, Zork II.]

                     [If the Tandy Flag is set in "Zork I", the final text
                     does not mention "Zork II" and "Zork III".]

                     [In "The Witness", the Tandy Flag can be set while
                     playing the game, by typing $DB and then $TA. If it is
                     set, some of the prose will be less offensive. For
                     example, "private dicks" become "private eyes",
                     "bastards" are only "idiots", and all references to
                     "slanteyes" and "necrophilia" are removed.]

 #1  0x10  (2 or 3)  Alternative Prompt

                     [This flag will enable alternative prompts, probably
                     for machines without a status line.]

                     [It is only supported by:
                     Deadline, Moonmist, Suspect, Suspended, The Witness.]

                     [If the flag is set in one of the four mystery games
                     and an incident occurs while you are WAITing, you'll
                     get a time display before the "Do you want to keep
                     waiting?" prompt.
                     In "Suspended", the prompt will always tell you to
                     which robot the FC is linked.]

 #1  0x20    (3)     Status Window Support

                     [This flag is set if the interpreter is able to create
                     a status window between status line and text window.]

                     [Only "Seastalker" supports this flag. If it is set,
                     you will have a fixed sonarscope display in the upper
                     part of the screen; otherwise it will scroll away like
                     normal text.]


 #2  0x01    (4)     Scripting

                     [The Z-machine directs every text output to the
                     printer if this flag is set.]

 #2  0x02    (4)     Disable Proportional Fonts

                     [The Z-machine must use fixed fonts for screen output
                     if this flag is set. Usually it will be set before a
                     table or map is printed.]

                     [The following games use this flag:
                     Ballyhoo, Cutthroats, Enchanter, Hollywood Hijinx,
                     Planetfall, Seastalker, Sorcerer, Stationfall,
                     Suspended, Wishbringer, Zork II, Zork III.]

 #2  0x10  (1 or 2)  Sound Support

                     [As this flag is only set in the Amiga version of "The
                     Lurking Horror", I suppose it was meant as a sound
                     flag. However, neither Z-code nor Z-machine care about
                     it.]

No other flags are used in version 3 data files.


Data File Structure
===================

As an example, let's look at the "Zork I" data file (release 88, serial
840726):

000000:  03000058 4e374f05 3b2102b0 22712e53   ...XN7O.;!.."q.S
000010:  00003834 30373236 01f0a5c6 a1290000   ..840726.....)..
000020:  00000000 00000000 00000000 00000000   ................
000030:  00000000 00000000 00000000 00000000   ................


That translates to this data file structure:

00000   +---------------------+
        |     game header     |
00040   +---------------------+
        |      synonyms       |
        + - - - - - - - - - - +   001f0
        |   synonym offsets   |
        +---------------------+   002b0
        |      objects        |
        + - - - - - - - - - - +
        | object descriptions |
        |   and properties    |
        +---------------------+   02271
        |   global offsets    |
        + - - - - - - - - - - +
        |       globals       |
        |                     |<- 02e53 (save area size)
        +---------------------+   03b21
        |     dictionary      |
        +---------------------+   04e37
        |       Z-code        |<- 04f05 (main routine)
        |                     |
        +---------------------+   14b8c

This structure is more or less the same for all data files (except
"Plundered Hearts", where the global offsets come between the synonym
offsets and the object offsets).


Credits
=======

Thanks to everybody who helped me. Special thanks to Mark Howell.
Newsgroups: rec.games.int-fiction