home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / games / info / inform / Inform / Manual < prev   
Text File  |  1993-09-08  |  90KB  |  2,047 lines

  1.  
  2. ---------------------------------------------------------------------------
  3.                           Inform: An Apology
  4.  
  5.                     pertaining to the second release
  6. ---------------------------------------------------------------------------
  7.  
  8.  
  9.             "Look on my works, ye mighty, and despair..."
  10.  
  11.  
  12.   Hello, Informer!
  13.  
  14.   Inform is an assembler for Infocom version-3 format story files.  It has
  15. some of the trappings of a compiler, though its code is still haphazard
  16. in some places.  It reports errors strangely at times, and in particular its
  17. expression evaluator has a few eccentric mannerisms.  Some features one
  18. might expect from a compiler are flagrantly missing.  Worse yet, much of
  19. the source code is still written in a naive and unsystematic fashion.
  20.  
  21.   On the bright side, it works most of the time, and runs in only two
  22. passes.  (This may sound easy but is not, because the story file format
  23. requires all manner of tricky operations to be done: for example, the
  24. dictionary must be alphabetically sorted, and the code must know absolute
  25. addresses of its entries... and the address of the start of the dictionary
  26. depends on many other things not known during pass 1... and so on.)  It
  27. produces "Curses", the author's game, correctly.  This is a fairly
  28. strenuous test since the game is about 123K long and pushes most of the
  29. version-3 format to the limits.
  30.  
  31.   In Appendix A is a complete specification of the version-3 "Z-machine",
  32. and some details of how to use Inform as an assembler instead of a compiler. 
  33. Some of this information is already circulating in other files, but
  34. uncollated.  The rest seems only to be available in as much as it is
  35. implicit in the interpreter sources.
  36.  
  37.   Implementation bears about the same relation to designing a game as typing
  38. does to writing poetry.  Appendix B contains some of the author's opinions
  39. on game design, and may safely be ignored by those of a nervous disposition.
  40. (In any case he has not absolutely always followed his own advice.)
  41.  
  42.   Appendix C discusses example programs.  One of these ("Deja Vu") is a toy
  43. game which, although small and not very interesting in itself, contains the
  44. source of a fairly good parser and implements most of the standard kernel
  45. of adventure games; this may freely be stolen and adapted.  The source of
  46. the other ("Hello Cruel World") is included within this file.  The source of
  47. "Curses", on the other hand, is not on public show.
  48.  
  49.   Inform is not public domain, as mistakenly stated at earlier times,
  50. in the proper legal sense of the term.  The copyright is retained by the
  51. author, Graham Nelson.  He is perfectly happy for Inform to be used by
  52. anybody for any recreational purpose.  It may be freely distributed
  53. provided no profit is involved, and provided the copyright message is
  54. retained.  Please do not circulate heavily modified versions, and please
  55. comment any private changes of your own at the top of the source code.
  56. Story files produced by Inform belong to whoever wrote the source for them;
  57. I think, however, it is fair to ask that game-writers put some message into
  58. their credits saying that Inform was used, and giving the version number
  59. used to compile it.
  60.  
  61.   And now the author stands back, and looks forward to seeing new games with
  62. bated breath...
  63.  
  64.                                                               Graham Nelson
  65.                                                    Magdalen College, Oxford
  66.                                                                  April 1993
  67.  
  68.  
  69.   Since the first release, much improvement has been made in memory
  70. management which is now quite efficient: it allocates between 50 and 75K of
  71. memory, as opposed to 800K in the first edition.  The code is in ANSI C, is
  72. contained in a single file (without needing non-standard headers) and some
  73. effort has been made to improve its portability.  Hopefully it doesn't
  74. assume an ASCII character set, or 32-bit integers, or any particular
  75. byte-orientation within integers.  PC versions now ought to be feasible.
  76.  
  77.   The code has been annotated to some extent, and contains notes which
  78. should be useful to anyone trying to port the code to a new machine.
  79.  
  80.   This documentation has changed only within the above introduction, in the
  81. new "objectloop" construction, and in Appendix C (sample output for the
  82. given programs).  The language which Inform compiles has not changed (except
  83. that two defunct features, which had not in any case been documented, have
  84. been withdrawn).  Details of changes to the ANSI source code of Inform may
  85. be found in detailed comments at its head.
  86.  
  87.   The author's email address may be found at the bottom of this file. 
  88. Comments and bug reports (by email) are welcomed with whatever degree of
  89. enthusiasm he can muster.
  90.  
  91.                                                                         GAN
  92.                                                                   June 1993
  93.  
  94. ---------------------------------------------------------------------------
  95.                              Contents
  96. ---------------------------------------------------------------------------
  97.  
  98.            1.   Command line format
  99.            2.   Source file format
  100.            3.   Compiler directives
  101.            4.   Variables
  102.            5.   Constants
  103.            6.   Routines
  104.            7.   Expressions
  105.            8.   Commands
  106.            9.   Conditions
  107.            10.  Built-in functions
  108.            11.  Objects
  109.            12.  Verbs and grammar
  110.            13.  The Dictionary
  111.            14.  Indirect function calls
  112.            15.  Text spacing
  113.            
  114.            A1.  The Z-machine
  115.            A2.  How text is encoded
  116.            A3.  How Z-code is encoded
  117.            A4.  Using Inform as an assembler
  118.  
  119.            B1.  A Bill of Player's Rights
  120.            B2.  What makes a good game?
  121.  
  122.            C1.  A Hello Cruel World program
  123.            C2.  "Deja Vu": a toy game
  124.  
  125.  
  126. ---------------------------------------------------------------------------
  127. 1. Command line format
  128. ---------------------------------------------------------------------------
  129.  
  130.   inform [-options] <filename>
  131.  
  132. where four switches may be given in options:
  133.  
  134.   h   help information
  135.   l   list assembly lines
  136.   s   give statistics
  137.   p   give statistics after both passes
  138.   m   print memory allocation made
  139.   d   contract double spaces in text
  140.  
  141. Samples of -s output can be found in Appendix C.  For -d, see section (15).
  142.  
  143. -m reveals how many bytes were malloc'ed.  The program can be compiled in
  144. several different version: the default (and most economical) settings
  145. use about 75K.  With judicious adjustment of various #defines at the
  146. beginning, this could be reduced a little further.
  147.  
  148. Inform will write its output to a file with the same name, but prefixed with
  149. "z3".  (This is easy to alter by changing #defines at the beginning of the
  150. source.)
  151.  
  152.  
  153. ---------------------------------------------------------------------------
  154. 2. Source file format
  155. ---------------------------------------------------------------------------
  156.  
  157.  
  158. Lines in an Inform file are terminated by semicolons.  Exclamation marks
  159. ! thus...
  160. denote that the rest of that physical line is a comment.  Backslashes "fold"
  161. lines, thus:
  162.  
  163. initpos "A hinged trapdoor in the floor stands open, and light streams in \
  164.          from below.";
  165.          
  166. is treated as if the "f" in "from below." follows directly from where the
  167. backslash \ is; i.e., the carriage return and leading spaces are removed.
  168.  
  169. These lines may either be compiler directives (all of which fit on one line)
  170. or routines (which take more than one line).
  171.  
  172. Inform command names are not case sensitive.
  173.  
  174.  
  175. ---------------------------------------------------------------------------
  176. 3. Compiler directives
  177. ---------------------------------------------------------------------------
  178.  
  179.  
  180. ATTRIBUTE <name>                     Make new attribute flag
  181. CONSTANT <name> <value>              Declare a constant
  182. DICTIONARY <name> <text>             Enter <text> in dictionary, and make
  183.                                      a new constant for its address
  184. END                                  End compilation here (this is optional)
  185. GLOBAL <name> [ = <a> ]              Make a new global variable;
  186.                                        [give it the initial value a]
  187.               [ string <a> ]           [make it point to an (a+1)-byte array,
  188.                                          which has <a> as first byte, and is
  189.                                          otherwise zeros]
  190.               [ data <a> ]             [make it point to an a-byte array,
  191.                                          which is all zeros]
  192.               [ initial <i1> ... ]     [make it point to an array, the bytes
  193.                                          of which are as given]
  194.               [ initstr "text" ]       [make it point to an array, the bytes
  195.                                          of which are the ASCII values of the
  196.                                          characters in the string]
  197. OBJECT ...                           Make an object (see below)
  198. PROPERTY ...                         Make a new property (see below)
  199. RELEASE <a>                          Set the release number to <a>
  200. VERB ...                             Enter a line of grammar (see below)
  201.  
  202. The following are mainly for debugging the compiler (should anyone ever
  203. get around to doing this) but might sometimes be amusing or helpful:
  204.  
  205. LIST                                 List the symbol table
  206. SHOWDICT                             Show dictionary
  207. TREE                                 List object tree
  208. VERBS                                List verb table
  209.  
  210. TRACE                                Trace assembler
  211. LTRACE                               List the lines of input
  212. ETRACE                               Trace expression evaluator
  213. BTRACE                               Trace assembler on both passes
  214. NOTRACE, NOLTRACE, etc               Turn off appropriate tracing
  215.  
  216.  
  217. ---------------------------------------------------------------------------
  218. 4. Variables
  219. ---------------------------------------------------------------------------
  220.  
  221.  
  222. Variables are all two-byte integers, which are treated as signed when it
  223. makes sense to do so (eg in asking whether one is positive or not) but
  224. not when it isn't (eg when it is used as an address).
  225.  
  226. There can be up to 240 global variables; as indicated in (3), these can be
  227. initialised to point to dynamic workspace, so as to achieve the effect of
  228. strings and arrays.
  229.  
  230. In any routine, there can be up to 15 local variables.
  231.  
  232. There is also a stack, but it should be tampered with only with care.  Never
  233. call a variable "sp", as this is the stack pointer variable which you might
  234. occasionally need to use.
  235.  
  236. The observant reader will have noticed that 240+15+1 = 256.  This is of
  237. course no coincidence.
  238.  
  239.  
  240. ---------------------------------------------------------------------------
  241. 5. Constants
  242. ---------------------------------------------------------------------------
  243.  
  244.  
  245. Constants may be prefixed with a # character if desired.  This can be useful
  246. if they are alphabetical and might otherwise be confused with something else.
  247.  
  248. A constant in "double quotes" assembles the given text at a suitable (even)
  249. address, and gives half this address as the integer value.  Inside this text
  250. the character ^ is replaced by a newline character, and the character ~ by
  251. a double-quote mark.
  252.  
  253. A character in single quotes, such as 'e', means the ASCII value of that
  254. character.
  255.  
  256. A dollar $ indicates that a hexadecimal constant follows; $$ indicates that
  257. binary follows.
  258.  
  259. Declared constants can be given, and so can the special constants
  260.  
  261.   adjectives_table
  262.   preactions_table
  263.   actions_table
  264.  
  265. which give the code address of these tables.
  266.  
  267. A constant beginning a$, followed by the name of a routine which is an
  268. action routine, will have as value the number of the action.
  269.  
  270. A constant beginning w$, followed by a word of text, has as value the
  271. address of the given word in the dictionary (Inform will give an error
  272. at compile time if no such word is there).
  273.  
  274. Thus, for instance, the following are legal constants:
  275.  
  276.   31415
  277.   $ff
  278.   $$1001001
  279.   #adjectives_table
  280.   #a$LookSub
  281.   #w$invent
  282.   'X'
  283.   "an emerald the size of a plover's egg"
  284.   "~Hello,~ said Peter.^~Hello, Peter,~ said Jane.^"
  285.  
  286.  
  287. ---------------------------------------------------------------------------
  288. 6. Routines
  289. ---------------------------------------------------------------------------
  290.  
  291.  
  292. The syntax to begin a routine is
  293.  
  294.   [ RoutineName <l1> ... <ln>;
  295.  
  296. and to end it, is
  297.  
  298.   ];
  299.  
  300. l1 to ln are the names of local variables, which are also the call
  301. parameters.  For example, if you have a routine
  302.  
  303.   [ Look i j k;
  304.     ...some code...
  305.   ];
  306.  
  307. and it is called by
  308.  
  309.   Look(attic);
  310.  
  311. then i will initially have the value "attic" when this is executed.
  312. Any local variables not specified (in this case, j and k) are initially
  313. zero.
  314.  
  315. Every routine returns a value to the caller; if no such value is
  316. explicitly given, this value is the integer 1.
  317.  
  318. Inside a routine, labels may be declared with a line of their own:
  319.  
  320.   .labelname;
  321.  
  322. but note that whereas local variables have names which only mean anything
  323. locally, labels have names which are global.  In other words, you can't
  324. have a label called "loop" more than once in the file.
  325.  
  326. There is one special routine, which you must define, called Main.  This is
  327. where execution of the game will begin, and it _must_ be the first one
  328. defined.  Returning from Main will cause the interpreter to crash: you
  329. should explicitly QUIT instead.  Also, uniquely and for peculiar reasons,
  330. Main is _not_ permitted to have any local variables of its own.  This means
  331. it is usually only used as an outer shell.
  332.  
  333.  
  334. ---------------------------------------------------------------------------
  335. 7. Expressions
  336. ---------------------------------------------------------------------------
  337.  
  338.  
  339. The usual arithmetic expressions are allowed, including the operators:
  340.  
  341.     =             set variable (only) on left equal to value on right
  342.     + -           plus, minus
  343.     * / % & |     times, divide, remainder, bitwise and, bitwise or
  344.     -> -->        byte, word array entry
  345.                   (eg: buffer->4 gives contents of the byte with address
  346.                   buffer+4, while table-->3 gives the word at table+6)
  347.                   
  348. In addition one may call a function, either a built-in function or a
  349. routine.
  350.  
  351. For example:
  352.  
  353.   4*(x+3/y)
  354.   i=j-->1
  355.   Fish(x)+Fowl(y)
  356.  
  357. Warning: for a few commands, strange results may occur if two or more
  358. complicated expressions are used in the same command, for instance:
  359.  
  360.   put buffer+6 byte i+j+1 56*prime(4);
  361.  
  362. One can only describe this as a hideous bug, but in practice the need
  363. seldom arises and the solution would be quite difficult to implement.
  364.  
  365.  
  366. ---------------------------------------------------------------------------
  367. 8. Commands
  368. ---------------------------------------------------------------------------
  369.  
  370.  
  371. The "high level" commands in Inform are as follows:
  372.  
  373. NEW_LINE                     Print a carriage return
  374. QUIT                         Quit the game (at once, with no confirmatory
  375.                              question to the user)
  376. RESTART                      Restart the game from its initial state (ditto)
  377. SHOW_SCORE                   Redisplay the score bar immediately, without
  378.                              waiting for the next keyboard input
  379. PRINT "text"                 Print text
  380. PRINT_RET "text"             Print text, print a newline and return 1
  381. PRINT_NUM <a>                Print a as a (signed) decimal number
  382. PRINT_CHAR <a>               Print the character whose ASCII value is a
  383. PRINT_ADDR <a>               Print the string whose address is a
  384. PRINT_PADDR <a>              Print the string whose address is 2*a
  385. PRINT_OBJ <a>                Print the short name of object a
  386.  
  387. READ <a> <b>                 Reads keyboard into buffer a and decomposes it
  388.                              to the buffer b:
  389.                              on entry, a[0] = buffer size, b[0] similarly
  390.                              on exit a[1] = no chars typed,
  391.                                        2 to a[1]+1 are the chars (unterminated)
  392.                              From byte 2, b contains 4-byte chunks, one for
  393.                              each word of input:
  394.                                  address of dictionary entry if recognised,
  395.                                    0000 otherwise
  396.                                  number of letters in word
  397.                                  first char of word in a
  398.                              This command automatically redisplays the status
  399.                              (score) line.  Precisely, it prints the short name
  400.                              of the object whose number is the first declared
  401.                              global variable, then prints the next two
  402.                              globals in the form "45/34".  It is assumed that
  403.                              these are the location, score and number of turns
  404.                              so far.
  405.  
  406. REMOVE <a>                   Remove object a from the tree of objects
  407.                              (it may certainly be later put back)
  408. MOVE <a> TO <b>              Add object a to the things possessed by b
  409.  
  410. PUT <addr> BYTE <index> <v>  Write byte value v into index'th byte after addr
  411. PUT <addr> WORD <index> <v>  ...and similarly for words
  412.  
  413. PUT_PROP <o> <p> <v>         Set property p of object o to value v
  414.  
  415. INC <var>                    Increment variable
  416. DEC <var>                    Decrement 
  417.  
  418. RETURN <a>                   Return the value a
  419. RET#TRUE                     Return true, i.e. the value 1
  420. RET#FALSE                    Return false, i.e. the value 0
  421.  
  422. INVERSION                    Print the version number of Inform used to
  423.                              compile the story file
  424.  
  425. IF <condition>               If the condition is true, execute the code
  426.   {  ... code ... }          (braces are _compulsory_) [else execute the
  427. [ ELSE { ... other ...} ]    other code instead]
  428.  
  429. WHILE <condition>            While loop
  430.   {  ... code ... }
  431.  
  432. FOR <var> <init> TO <final>  For loop: the final value must be a constant
  433.   {  ... code ... }          or another variable.  If the range is empty, it
  434.                              does not execute even once.
  435. DO                           Until loop
  436.   {  ... code ... }
  437. UNTIL <condition>
  438.  
  439. OBJECTLOOP <var> FROM/IN <obj>  A form of while loop.  The var first holds
  440.                              either the obj value (if it is FROM) or its
  441.                              child (if IN), and runs through the sibling
  442.                              objects.  So, for instance,
  443.  
  444.                        objectloop x in lamp { print_obj x; new_line; }
  445.  
  446.                              is equivalent to
  447.  
  448.                        x=child(lamp); while x~=0 { print_obj x; new_line;
  449.                        x=sibling(x); }
  450.  
  451. BREAK                        Break out of current loop (not block)
  452. JUMP <label>                 Jump to label (warning: exercise caution in
  453.                              jumping out of one routine into another)
  454. SAVE <label>                 Try to save the game (asking the user for a file
  455.                              to put it in): if successful, jump to the label,
  456.                              otherwise carry on
  457. RESTORE <label>              Ditto, but restore
  458.  
  459. If a command matches none of these, or if it began with an @ character, the
  460. line is sent to the assembler instead.
  461.  
  462.  
  463. ---------------------------------------------------------------------------
  464. 9. Conditions
  465. ---------------------------------------------------------------------------
  466.  
  467.  
  468. These take the form
  469.  
  470.   <a>  <relation>  <b>
  471.  
  472. where the relation is one of
  473.  
  474.   ==            a equals b
  475.   ~=            a doesn't equal b
  476.   < > >= <=     comparisons
  477.   has           object a has attribute b at the moment
  478.   hasnt         ...hasnt...
  479.   near          objects a and b have the same parent
  480.   far           ...haven't...
  481.  
  482. These may _not_ be used in expressions (as if the language were C) and
  483. there is no AND/OR construction.  There is a reason for this, but not a
  484. very good one (unless you count laziness).  However, one tiny concession
  485. towards such a feature is provided, viz. the construction
  486.  
  487.   <something> == <v1> [or <v2> [or <v3>]]
  488.  
  489. which is true if the first something is any of the values given.
  490.  
  491. ---------------------------------------------------------------------------
  492. 10. Built-in functions
  493. ---------------------------------------------------------------------------
  494.  
  495.  
  496. The built in functions are
  497.  
  498.   PARENT(obj)  SIBLING(obj)  CHILD(obj)
  499.  
  500. for reading the object tree (see (11) below), and
  501.  
  502.   RANDOM(x)
  503.  
  504. which returns a uniformly random number between 1 and x, and
  505.  
  506.   PROP_LEN(addr)  PROP_ADDR(o,p)  PROP(o,p)
  507.  
  508. for which see (11) below.
  509.  
  510. Warning: some interpreters set up the random number generator with poor
  511. choices of seed value, which means that the first few random numbers may be
  512. rather peculiarly distributed.  After a time, it settles down.  To get
  513. around this, "Curses" (for example) takes and throws away 100 random numbers
  514. when it begins.
  515.  
  516.  
  517. ---------------------------------------------------------------------------
  518. 11. Objects
  519. ---------------------------------------------------------------------------
  520.  
  521.  
  522. The object hierarchy is a tree of up to 255 "objects", which you might use
  523. for many different game elements: rooms, compass points, scenery, things
  524. which can be picked up, and so on.
  525.  
  526. They are numbered from 1 to 255, and the number 0 by convention means
  527. "nothing".  Attempting to print_obj object 0 will produce a string full of
  528. peculiar letters and (if you are very unlucky indeed) even random ASCII
  529. values.
  530.  
  531. In the tree, each object has a parent, a sibling, and a child.  Thus, for
  532. instance, a portion may resemble
  533.  
  534.             Meadow
  535.                |
  536.             Mailbox -> Player
  537.                |          |
  538.              Note      Sceptre -> Cucumber -> Torch -> Magic Rod
  539.                                                 |
  540.                                               Battery
  541.  
  542. in which -> shows siblings, and | parents and children.  In this case, the
  543. Meadow has nothing as its parent.  Anything with no possessions, such as the
  544. note, has nothing as its child, and so on.
  545.  
  546. When an object is moved, its possessions move with it, of course.
  547.  
  548. In practice an object needs rather more data than just a position in a tree. 
  549. It also has a collection of variables attached to it.
  550.  
  551. Firstly, there are 32 flags, called "attributes", which can be either set or
  552. clear.  These might be such conditions as "giving light", "currently worn"
  553. or "is one of the featureless white cubes".  All 32 are free for the user to
  554. use.  They must be declared before use, by commands like
  555.  
  556.   ATTRIBUTE locked;
  557.  
  558. which will allocate a new attribute and make a constant "locked" to have the
  559. value of its number.  You never then need to know about these numbers,
  560. because you can use commands like
  561.  
  562.   IF obj HAS locked { print_ret "But it's locked!"; }
  563.  
  564.   SET_ATTR obj locked;
  565.  
  566.   CLEAR_ATTR obj locked;
  567.  
  568. Warning: 32 sounds like plenty, but the limit can quite easily be hit.  The
  569. author has found it useful to declare one as "general", to be used for
  570. different things for different objects.
  571.  
  572. Secondly, there are 30 "properties".  These are far more elaborate.  For one
  573. thing, not every object has every property.  The following all declare new
  574. properties:
  575.  
  576.   PROPERTY door_to;
  577.   PROPERTY article "a";
  578.   PROPERTY blorpleroutine $ffff;
  579.  
  580. The value given, in the case of article and blorpleroutine, is the default
  581. value: that is, the value of the property which an object will have if it
  582. doesn't explicitly have some other value.  If you don't define a default
  583. value, it will by default be 0.
  584.  
  585. The data for a given property can be a number, or up to four numbers in a
  586. row, or up to eight bytes of data.  The simplest way to get at the current
  587. value is something like
  588.  
  589.   i=PROP(location,door_to);
  590.  
  591. which will get the first number in the property door_to of object location.
  592. Similarly, it can be written to with
  593.  
  594.   PUT_PROP location door_to hall_of_mists;
  595.  
  596. A subtle point is that numbers smaller than 256 are stored differently from
  597. larger ones.  In order to decide whether the property is one byte's worth or
  598. two, the Z-machine looks at the number of bytes which the property has in
  599. all, and sees whether it is odd or even; if even, it presumes the number is
  600. a 2-byte word; if odd, it presumes it is just one byte.
  601.  
  602. This is seldom something you need to know about, but occasionally you will
  603. want a property which will, later in the game, need to hold a value of, say,
  604. 1000, but which initially will be zero.  This is particularly the case with
  605. timing mechanisms, for instance.  The command
  606.  
  607.   PROPERTY LONG timeleft;
  608.  
  609. declares the property "timeleft" and requires Inform to make sure that all
  610. "timeleft" fields are 2 bytes wide, even if they have small initial values.
  611.  
  612. More elaborate manipulation has to be done by hand.
  613.  
  614.   k=PROP_ADDR(o,weird);
  615.  
  616. sets k to the address of the "weird" data of object o.  To find out how many
  617. bytes there are, apply PROP_LEN to this address.
  618.  
  619.   l=PROP_LEN(k);
  620.     
  621. Once you have the address you can read and write to it directly.  Be careful
  622. not to overrun the length, which may not be changed.
  623.  
  624. Warning: the Z-machine crashes if you attempt to write to a property field
  625. which an object hasn't got.
  626.  
  627. An object is declared (before the body of the code) by something like:
  628.  
  629. OBJECT trapdoor "hinged trapdoor" attic
  630.   WITH name "hinged" "trap" "door" "trapdoor",
  631.        initpos "A hinged trapdoor in the floor stands open, and light \
  632.                 streams in from below.",
  633.        closedpos "There is a closed trapdoor in the middle of the floor.",
  634.        portalto house,
  635.        postroutine TrapdoorPost,
  636.        dirprop d_to
  637.   HAS  portal static open light openable;
  638.  
  639. trapdoor is a constant which is set to its object number; "hinged trapdoor"
  640. is its attached short name; attic is the object which initially possesses
  641. it.  If it was to be initially unowned, this would be "nothing" instead of
  642. "attic".
  643.  
  644. After WITH is a list of property definitions, in the form
  645.  
  646.    <property> <data1> ...
  647.    [[, <property> <data1> ...]]
  648.  
  649. Warning: an excellent source of mysterious errors is missing off the commas
  650. between these, since property names are themselves legal constants.
  651.  
  652. There is one special property, called "name" and numbered 1.  Its data must
  653. be (up to four at most) words, as above, and these are entered into the
  654. dictionary as nouns (if they aren't already present): the data actually
  655. stored is the dictionary addresses.
  656.  
  657. Note that the dictionary itself does _not_ know that "door" refers to this
  658. object: there might be any number of objects which could be called "door".
  659.  
  660. After HAS is a list of attributes which the object initially has.
  661.  
  662.  
  663. ---------------------------------------------------------------------------
  664. 12. Verbs and grammar
  665. ---------------------------------------------------------------------------
  666.  
  667.  
  668. Whereas objects should be declared at the start of the file, the grammar
  669. to be allowed by the game should be declared at the end.  This is done with
  670. the VERB command.  VERB does something very complicated, but probably not
  671. what you think.  A typical VERB command would be:
  672.  
  673. VERB "take" "get" "pick" "lift"  * "out"                    -> ExitSub
  674.                                  * multi                    -> TakeSub
  675.                                  * multiinside "from" noun  -> RemoveSub
  676.                                  * "in" noun                -> EnterSub
  677.                                  * "off" held               -> DisrobeSub;
  678.  
  679. This declares a verb, for which "take", "get" etc are synonyms, and which
  680. can take five different courses.  In the first, it must be followed by the
  681. word "out".  In the last, it must be followed by "off" and then an item
  682. which is currently held by the player.  In the second, it can be followed by
  683. one object, or a list, perhaps specified as "everything", for instance.
  684. There can be no grammar at all, for example
  685.  
  686. VERB "invent" "i"                *                          -> InvSub;
  687.  
  688. After the "->" is the name of a routine which is to be called when this is
  689. matched.
  690.  
  691. For traditional reasons unclear to the author, previous Infocom hackers have
  692. called words such as "out" and "off", adjectives.  This is monstrously
  693. illiterate since they are of course prepositions.  We shall wearily follow
  694. convention anyway.
  695.  
  696. Remember that the Z-machine does _not_ contain the bulk of a game parser,
  697. only the computationally expensive and low-level part which works out what
  698. the words are.  So this command only sets up a table with some numbers in. 
  699. If you want a parser, you have to write code to deal with the table again.
  700.  
  701. By convention, adjectives are numbered downwards from $ff.  Thus, if
  702. the above were the opening lines of grammar, "from" would be $fe, and so on. 
  703. As they are created, they are entered into the dictionary, and also into the
  704. adjective table, which has four-byte entries
  705.  
  706.   <dictionary address of word>  00  <adjective number>
  707.   ----2 bytes-----------------  ----2 bytes----------- 
  708.  
  709. In order to make life more interesting, these entries are stored in reverse
  710. order (i.e., lowest adjective number first).  The address of this table is
  711. rather difficult to deduce from the file header information, so the constant
  712. #adjectives_table is set up by Inform to refer to it.  In any event, the
  713. table isn't very useful and is created only for the sake of conforming to
  714. Infocom internal conventions.
  715.  
  716. The important tables are the grammar and action tables.
  717.  
  718. The grammar table address is stored in word 7 (ie bytes 14 and 15) of the
  719. header.  The table consists of a list of two-byte addresses to the entries
  720. for each word.  This list is immediately followed by these entries, one
  721. after another.
  722.  
  723. An entry consists of one byte giving the number of lines (eg, 5 for the
  724. "take" definition above) and then that many 8-byte lines.  These lines
  725. have the form
  726.  
  727.   <objects>  <sequence of words>  <action number>
  728.   --1 byte-  ----6 bytes--------  --1 byte-------
  729.  
  730. <objects> is the number of objects which need to be supplied: eg, 0 for
  731. "inventory", 1 for "take frog", 2 for "tie rope to dog".  The sequence
  732. of words gives up to 6 blocks of syntax to follow the verb, which must
  733. be matched in order.  Large numbers such as $ff mean that the appropriate
  734. adjective must appear; small numbers are inserted by special words such as 
  735. "held" or "noun" in the VERB command:
  736.  
  737.    Word         Byte       What the "Deja Vu" parser uses it for
  738.    ====         ====       =====================================
  739.    noun          0         any visible object
  740.    held          1         object held
  741.    multi         2         one or more visible objects
  742.    multiheld     3         one or more held objects
  743.    multiexcept   4         one or more objects, except the other object 
  744.    multiinside   5         one or more objects, inside the other object
  745.    creature      6         an animate creature
  746.    special       7         any word or number
  747.  
  748. The sequence is padded out to 6 bytes with zeros.
  749.  
  750. The action numbers begin at 0.  The first routine mentioned as an action (in
  751. the above example, ExitSub) is assigned action number 0; the next (TakeSub)
  752. is given 1, and so on.  The appropriate number is stored in the last byte of
  753. the line.
  754.  
  755. Thus, a little later on in the grammar, the line
  756.  
  757. VERB "exit" "leave"              *                          -> ExitSub;
  758.  
  759. might well appear, and ExitSub will mean "action 0" as before.
  760.  
  761. So this table does not store the address of the action routine, as one might
  762. expect.  Instead the addresses corresponding to the action numbers are
  763. stored in the actions table.  Once again, Inform puts this table in its
  764. conventional place, but this address being difficult to work out, the
  765. constant #actions_table is set up to hold it.  The actions table is simply
  766. a list of 2-byte entries giving the routine addresses (divided by 2).
  767.  
  768. There is also a preactions table, with another constant #preactions_table,
  769. created only to conform to Infocom conventions; it is set up containing 0000
  770. for each action.  ("Curses", for instance, makes no use of this.)
  771.  
  772. In the mean time, what has happened to the actual words, "take", "get",
  773. "pick" and "lift"?  Note that these do not appear in the grammar table at
  774. all.  Instead they are entered into the dictionary, along with the verb
  775. number.  As a final baroque twist, these numbers also count down from $ff.
  776. Any number of words can be given, all referring to the same verb number;
  777. "Curses" has 11 synonyms for "attack", for instance.
  778.  
  779. Of course, Inform does not know or care what is done with any of these
  780. tables.   For instance, the "take" verb has the entry
  781.  
  782. 005
  783. 000 255 000 000 000 000 000 000
  784. 001 002 000 000 000 000 000 001
  785. 002 005 254 000 000 000 000 002
  786. 001 253 000 000 000 000 000 003
  787. 001 252 001 000 000 000 000 004
  788.  
  789. but it is up to the code you write to deal with this.  (The VERBS command
  790. will print out the full verb table in a similar format.)
  791.  
  792.  
  793. ---------------------------------------------------------------------------
  794. 13. The Dictionary
  795. ---------------------------------------------------------------------------
  796.  
  797.  
  798. This section describes what Inform does with the dictionary.
  799.  
  800. The fourth word of the file header (bytes 8 and 9) contain the dictionary
  801. table's address.
  802.  
  803. The table begins with a 7-byte header:
  804.  
  805.   03 '.' ',' '"'
  806.  
  807. meaning there are three characters used to separate words in typed input,
  808. full stops, commas and quotation marks.  (The Z-machine will allow any list
  809. to be given here but Inform decides on this for you.)
  810.  
  811.   07  <number_of_entries>
  812.       ----2 bytes--------
  813.  
  814. meaning there are that many entries in the dictionary, all 7 bytes long. 
  815. (This could again be in principle varied, but allows for six significant
  816. letters in words, while still enabling the text of the word to occupy a
  817. 4-byte integer - which is convenient and fast when the compiler is
  818. alphabetically sorting.)
  819.  
  820. The seven-byte entries are in alphabetical order, and look like:
  821.  
  822.   <the text of the word>  <flags>  <verb number>  <adjective number>
  823.   ----4 bytes-----------  --1 b--  ----1 byte---  ----1 byte--------
  824.  
  825. The text is stored in the usual text format, thus allowing up to 6
  826. characters.  The flags (chosen once again to conform loosely to Infocom
  827. conventions, not for any sensible reason) have the eight bits
  828.  
  829.   7      6  5  4  3     2      1  0
  830.   <noun> .. .. .. <adj> <spec> .. <verb>
  831.  
  832. <verb>, <noun> and <adj> mean the word can be a verb, noun or adjective; the
  833. <spec> bit means the word was inserted by a DICTIONARY command in the
  834. program, except that <verb> words also have the <spec> bit set (ours not to
  835. wonder why).
  836.  
  837. Note that a word can be any combination of these at once.  It can even be
  838. simultaneously a verb, adjective and noun.
  839.  
  840. Typically a full game contains about 600 dictionary entries - about ten
  841. times the number of portable objects.  Even so it only consumes about 4K, or
  842. 1/64th of the available memory.  It's never worth economising on dictionary
  843. entries; nothing else a designer can do with 4K will be as good to the user.
  844.  
  845.  
  846. ---------------------------------------------------------------------------
  847. 14. Indirect function calls
  848. ---------------------------------------------------------------------------
  849.  
  850.  
  851. Occasionally one needs to call a function whose address is in a variable:
  852. for example, if the routine address has been looked up from a table, or an
  853. object's property list.
  854.  
  855. For this, the function "indirect" is provided:
  856.  
  857.   a=indirect(b);
  858.  
  859. sets a to the return value of calling the function whose address is in b.
  860.  
  861. If you want to pass arguments as well, you should use the assembler-level
  862. @icall.  But do so with care: it is dangerously easy to leave values lying
  863. about on the stack, which will overflow causing a mysterious crash
  864. hundreds of turns later.
  865.  
  866.  
  867. ---------------------------------------------------------------------------
  868. 15.  Text spacing
  869. ---------------------------------------------------------------------------
  870.  
  871.  
  872. Typewritten English, like this file, normally puts a double space after a
  873. full stop.  This is much easier to read.  Unfortunately Infocom-standard
  874. interpreters do not usually understand that.  When they fold text across
  875. lines, they can easily turn
  876.  
  877.   ...and a pomegranate.  After all, you always hated fruit.
  878.  
  879. into something which looks like
  880.  
  881.    |You decline the offer of a banana, an apple and a pomegranate.   |
  882.    | After all, you always hated fruit.                              |
  883.    |                                                                 |
  884.    |>                                                                |
  885.  
  886. which looks awful.  It would be easy to fix the interpreter not to do this;
  887. but nobody does.  In case (like the author's) your typing is habitually
  888. double-spaced, Inform provides a command line option -d to change it back
  889. again.  It does this only by replacing the string ".  " by ". " in text
  890. conversion.
  891.  
  892.  
  893. ---------------------------------------------------------------------------
  894. A1. The Z-machine
  895. ---------------------------------------------------------------------------
  896.  
  897.  
  898. The so-called Z-machine (the imaginary machine for which story files are
  899. programs) is quite well-adapted to its task.  It maintains a hierarchy of
  900. objects and possessions, and does the computationally-intensive part of
  901. parsing input itself.  That said, it does not contain the bulk of the
  902. parser.  The parsing tables which some investigators think are part of the
  903. Z-machine format, are in fact the same across different Infocom games only
  904. because they all contain essentially the same parser code.  Thus, Inform is
  905. in principle free not to compile such tables, but it does so in order to
  906. INFODUMP properly.  Some tables are put to subtly different uses, however.
  907.  
  908. The following description is fairly complete, but only covers version 3.
  909. It would be helpful if someone public-spirited would write an account of the
  910. differences in later versions.
  911.  
  912. The version 3 Z-machine is 128K long at most.  Addresses within it are
  913. nonetheless held in 2-byte words, which is why some addresses are stored as
  914. half their actual values, and why some items (routines and static strings)
  915. are always stored at even addresses.
  916.  
  917.  
  918. The first 64 bytes contain a header.  The first 4 bytes are:
  919.  
  920. 03  <Flags>  <Release Number>
  921.              ----2 bytes-----
  922.  
  923. 3 indicates version 3; the release number is as set in the program; the
  924. flags byte contains bits:
  925.  
  926.   1   Status line type (clear for Score/Turns, set for Hours:Mins)
  927.   3   Censorship bit (used by some games, but not by the Z-machine)
  928.   4   Alternative prompts - sometimes used by primitive interpreters
  929.   5   Status window support - used only by "Seastalker"
  930.  
  931. Next come seven word addresses, at words 2 to 8:
  932.  
  933. 2     <Start of Routines>    Where routines begin, in bytes
  934. 3     <Main Routine>         Address of main routine, in bytes, +1
  935.  
  936. (This +1 is why Main cannot have local variables - it is a peculiarity
  937. of the standard.  Note also that this is uniquely a routine address in
  938. bytes and not words: Main must occur in the lower 64K of the file.  Inform
  939. always sets word 3 to be word 2, plus 1.)
  940.  
  941. 4     <Dictionary>           The dictionary table address, in bytes
  942. 5     <Object tree>          Object table address, in bytes
  943. 6     <Variables>            Global variables address, in bytes
  944. 7     <Save area size>       The total number of bytes in a saved game
  945.  
  946. (Saving the game is done by saving this many bytes from the beginning of
  947. the machine.  (Saved games also contain the current state of the Z-machine
  948. stack; the stack is _not_ stored anywhere in the Z-machine's memory.))
  949.  
  950. 8     <More flags>
  951.  
  952. This word of flags has bits:
  953.  
  954.   0   Scripting on: send output to printer
  955.   1   Disable proportional fonts while this is set
  956.   4   Something mysterious to do with sound effects in The Lurking Horror
  957.  
  958. This is followed by the six bytes from byte 18 to 23, which are the version
  959. number string.  (Inform sets these to the current date, in the form YYMMDD.)
  960. Then more words:
  961.  
  962. 12    <Synonyms table>       Synonym table address in bytes
  963. 13    <Length>               Length of file, in words
  964. 14    <Checksum>             Sum of bytes from 64 upwards, mod $10000
  965.  
  966. (The length and checksum are not actually used at all by many interpreters.)
  967.  
  968. The remaining bytes in the header are used by the interpreter and should be
  969. left alone by the game code.
  970.  
  971.  
  972. By convention, the next item in the memory map, beginning at $40, is the
  973. synonyms table.  There are 3*32=96 strings stored here (entries 0 to 31 in
  974. three dictionaries), one after another.  This means they all have even
  975. addresses, conveniently.  Once these 96 strings are entered, the actual
  976. table begins, and this is what the synonyms address points to.  The table
  977. contains 96 two-byte entries, which are the word addresses of the strings
  978. before it.
  979.  
  980. (Since Inform never makes use of synonyms, this could just be left out
  981. altogether, but for the sake of convention it creates a null table
  982. containing 96 copies of "   " (three spaces).) 
  983.  
  984.  
  985. Next is the object table.  In fact it begins with what is sometimes called
  986. the "global properties table", though it is actually a table of default
  987. values of properties.  This is a list of 31 2-byte words.  There is no
  988. property 0, so the first word is always 0000.
  989.  
  990. (Inform also sets the default for property 1 - the special "name" property -
  991. to 0000; the remainder are set in property definitions.)
  992.  
  993. After these 62 bytes, the objects begin, beginning from object 1.  An object
  994. entry consists of 9 bytes, looking like:
  995.  
  996.    <the 32 attribute flags>   <parent>  <sibling>  <child>  <properties>
  997.    ---32 bits in 4 bytes---   ---3 bytes------------------  ---2 bytes--
  998.  
  999. The last three bytes are 00 when the object pointed to is "nothing".  The
  1000. <properties> is an address (in bytes) of the properties attached to the
  1001. given object.
  1002.  
  1003. When all these 9-byte entries are out of the way, the properties tables
  1004. begin.  (Inform keeps these in the same order as the objects they are
  1005. attached to.)  An individual property table has the brief header
  1006.  
  1007.   03  <text of short name of object>
  1008.       --some even number of bytes---
  1009.  
  1010. and then lists the properties held, in descending numerical order.  (This
  1011. order is essential.)  A property is stored as
  1012.  
  1013.   <size byte>   <the actual property data>
  1014.                 ---between 1 and 8 bytes--
  1015.  
  1016. The size byte is arranged as 32*the number of data bytes, plus the property
  1017. number.
  1018.  
  1019. Each list of properties is ended by a 00 size byte.  This is why there is no
  1020. property 0.
  1021.  
  1022.  
  1023. When all the property tables are done, we come to the global variable table.
  1024. Global variables are numbered from 0 to 239, and this table begins with 240
  1025. initial 2-byte values for them.  After this is conventially left space for
  1026. all the arrays, dynamic strings and so on which they point to.
  1027.  
  1028.  
  1029. We have now reached the top of the save area.  Everything above here is
  1030. never altered.
  1031.  
  1032.  
  1033. Next is the table of grammar, which is described as above.  It is
  1034. immediately followed by the actions table, the preactions table and then the
  1035. adjectives table, also described above.
  1036.  
  1037.  
  1038. And next the dictionary table, described above.
  1039.  
  1040.  
  1041. Next is the code area.  Not all Infocom games begin with Main, but all
  1042. Informed ones do.  The code area simply contains a list of routines.
  1043.  
  1044. All routines (and static strings) must occur at even addresses, so as to
  1045. enable them to have word addresses instead.  (Inform occasionally inserts
  1046. 00 bytes between routines to ensure this.)
  1047.  
  1048. A routine begins with one byte indicating the number of local variables the
  1049. routine has (from 0 to 15), and then with that many 2-byte words giving
  1050. their initial values, if not supplied by the call to the routine.  (Inform
  1051. never makes use of this initialisation, and simply stores 0000's here.) 
  1052. Unlike global variables, these bytes are _not_ used for the current values
  1053. of the variables: they are kept on the stack.
  1054.  
  1055. Executable code follows this header.  There is no special marker for the end
  1056. of a routine; it is simply expected that in every case a legal return
  1057. instruction will be hit.
  1058.  
  1059. Finally, from the end of the code to the top of memory are the static
  1060. strings.  These are put up here to be out of the way, where they won't clog
  1061. up the bottom 64K of memory.  There's no table of their addresses, or pointer
  1062. to where they begin; each is referred to by an address in the code or data
  1063. given earlier.
  1064.  
  1065.  
  1066. ---------------------------------------------------------------------------
  1067. A2. How text is encoded
  1068. ---------------------------------------------------------------------------
  1069.  
  1070.  
  1071. Text is stored as a sequence of 2-byte words.  Each of these is divided into
  1072. three 5-bit pieces, plus 1 bit left over, arranged as
  1073.  
  1074.    --first byte-------   --second byte---
  1075.    7    6 5 4 3 2  1 0   7 6 5  4 3 2 1 0 
  1076.    bit  --first--  --second---  --third--
  1077.  
  1078. The bit is set only on the last 2-byte word of the text, and so marks the
  1079. end.
  1080.  
  1081. The pieces are then characters, with values in the range 0 to 31.
  1082.  
  1083. There are three alphabets, in which the numbers 6 to 31 mean:
  1084.  
  1085.   A0     abcdefghijklmnopqrstuvwxyz
  1086.   A1     ABCDEFGHIJKLMNOPQRSTUVWXYZ
  1087.   A2      ^0123456789.,!?_#'~/\-:()
  1088.  
  1089. ('^' being actually the new-line character.)
  1090.  
  1091. Character 0 is a space in all alphabets.  Characters 1, 2 and 3 are used for
  1092. abbreviations.  Inform makes no use of these, but the Z-machine provides for
  1093. commonly occurring strings to be printed out as if they were characters. 
  1094. Being plainly abbreviations, these are for some reason called "synonyms".
  1095.  
  1096. By default, a character is presumed to be in A0, i.e. to be a lower-case
  1097. English letter.  However, the character 4 means that the next one (only) is
  1098. in A1; and 5 means the next is in A2.
  1099.  
  1100. Notice that character 6 in A2 is blank.  It isn't a space: it simply isn't
  1101. there.  The sequence 5 followed by 6 indicates that the next two characters
  1102. define an ASCII value.  This is the way to get at the characters not in any
  1103. of the three alphabets.  For example, the familiar message
  1104.  
  1105.   *** You are dead ***
  1106.  
  1107. takes four "characters" to produce each of the *'s.
  1108.  
  1109. Finally, note that the end-bit only comes up once every three characters,
  1110. so that a way is needed to safely use up any spare characters in the last
  1111. 2-byte block.  This is done by padding out with 5's.  (5 followed by 5 does
  1112. nothing.)
  1113.  
  1114. This is especially the case with dictionary entries.  Some dictionary
  1115. entries, like "i", ought only to take one 2-byte block, but in order to make
  1116. all entries 2-byte blocks and alphabetically sortable by number, they are
  1117. padded out by up to five 5's in a row.
  1118.  
  1119. In practice the text compression factor is not really very good: "Curses"
  1120. contains about 127000 characters of text, stored in 91000 bytes.  (Text
  1121. usually accounts for about three quarters of a story file.)  But the
  1122. encoding does at least encrypt the text so that casual browsers can't read
  1123. it.
  1124.  
  1125.  
  1126. ---------------------------------------------------------------------------
  1127. A3. How Z-code is encoded
  1128. ---------------------------------------------------------------------------
  1129.  
  1130.  
  1131. The encoding of version 3 Z-code is to say the least complicated.  The
  1132. reader is warned that it is also different to that in all other versions. 
  1133. There are all kinds of exceptions intended either to make small economies of
  1134. code size (these are very seldom worth the effort, in fact) or to provide
  1135. new features tacked on at the last minute.
  1136.  
  1137. Experimenting with Inform as an assembler, while tracing is turned on, may
  1138. be helpful.
  1139.  
  1140. Z-code understands four kinds of operand, and describes these in 2-bit
  1141. fields:
  1142.  
  1143.   $$00    Large constant (>=256)         2 bytes
  1144.   $$01    Small constant (0 to 255)      1 byte
  1145.   $$10    Variable                       1 byte
  1146.   $$11    Omitted altogether             0 bytes
  1147.  
  1148. Variables are described in one byte.  00 means the top of the stack, 01 to
  1149. $0f are the local variables of the current routine and $10 to $ff are the
  1150. global variables, 0 to 239.  Writing to 00 pushes something onto the stack
  1151. and reading from it pulls it off.  The stack can also be manipulated (with
  1152. care) using the PUSH, PULL and POP instructions.  The stack is guaranteed to
  1153. be at least 512 bytes long, and some interpreters are more generous.  There
  1154. isn't any way to check stack overflowing, so be careful with recursion.
  1155.  
  1156. (One of the trickiest problems in compiling Z-code is throwing away unwanted
  1157. return values of routines which are left on the stack... it can take
  1158. hundreds of turns before a game crashes if this is got wrong.)
  1159.  
  1160. Z-code opcodes are 1 byte only.  To begin with, look at the top two bits.
  1161. If these are $$11, we shall call it "variable"; if $$10, "short"; and
  1162. otherwise "long".
  1163.  
  1164. In this description, we shall adopt the opcode names used by the existing
  1165. Infocom disassembler "TXD".
  1166.  
  1167. For short opcodes, look at the next two bits (4 and 5).  These give the kind
  1168. of operand which the code has.  If this is $11, there isn't an operand and
  1169. the opcode has no argument at all.  In this event, the remaining part of the
  1170. opcode gives what it is:
  1171.  
  1172.     $00   RET#TRUE                       (1) The opcode is followed by text
  1173.     $01   RET#FALSE                          in 2-byte chunks as usual
  1174.     $02   PRINT             (1)
  1175.     $03   PRINT_RET         (1)          (2) Opcode followed by a branch
  1176.     $05   SAVE              (2)
  1177.     $06   RESTORE           (2)          (3) This is an abbreviation for
  1178.     $07   RESTARE                            RET SP, to save one byte
  1179.     $08   RET(SP)+          (3)
  1180.     $09   POP
  1181.     $0A   QUIT
  1182.     $0B   NEW_LINE
  1183.     $0C   SHOW_SCORE
  1184.     $0D   VERIFY            (2)
  1185.  
  1186. If the type wasn't $11, then an operand follows, and moreover the "code"
  1187. part of the opcode means something different:
  1188.  
  1189.     $00   JZ                (2)          (4) Followed by a store opcode
  1190.     $01   GET_SIBLING       (2) (4)          (before the branch, if there
  1191.     $02   GET_CHILD         (2) (4)          is also a branch)
  1192.     $03   GET_PARENT        (4)
  1193.     $04   GET_PROP_LEN      (4)          (5) Refers indirectly to variables
  1194.     $05   INC               (5)              by their number (Inform
  1195.     $06   DEC               (5)              suppresses this feature, so
  1196.     $07   PRINT_ADDR                         "@inc sp" produces the constant
  1197.                                              0 instead of variable no. 0 as
  1198.     $09   REMOVE_OBJ                         operand)
  1199.     $0A   PRINT_OBJ
  1200.     $0B   RET
  1201.     $0C   JUMP
  1202.     $0D   PRINT_PADDR
  1203.     $0E   LOAD              (4) (5)
  1204.     $0F   NOT               (4)
  1205.  
  1206. "Long" opcodes have two operands.  The bottom 5 bits of the opcode say what
  1207. it is:
  1208.  
  1209.     $01   JE                (2) (6)      (6) If this is encoded as
  1210.     $02   JLE               (2)              "variable", then operands 3 and
  1211.     $03   JGE               (2)              4 (if present) are used as a
  1212.     $04   DEC_CHK           (2) (5)          kind of OR command: eg,
  1213.     $05   INC_CHK           (2) (5)          branch if o1 = o2, o3 or o4
  1214.     $06   COMPARE_POBJ      (2)   
  1215.     $07   TEST              (2)   
  1216.     $08   OR                (4)   
  1217.     $09   AND               (4)   
  1218.     $0A   TEST_ATTR         (2)   
  1219.     $0B   SET_ATTR
  1220.     $0C   CLEAR_ATTR
  1221.     $0D   STORE             (5)
  1222.     $0E   INSERT_OBJ
  1223.     $0F   LOADW             (4)   
  1224.     $10   LOADB             (4)   
  1225.     $11   GET_PROP          (4)   
  1226.     $12   GET_PROP_ADDR     (4)   
  1227.     $13   GET_NEXT_PROP     (4)   
  1228.     $14   ADD               (4)   
  1229.     $15   SUB               (4)   
  1230.     $16   MUL               (4)   
  1231.     $17   DIV               (4)   
  1232.     $18   MOD               (4)
  1233.  
  1234. The alert reader will notice that bits 5 and 6 are left spare to be used. 
  1235. Now there are two operands to specify, which ought to take up 4 bits, which
  1236. obviously won't fit.  So a more economical form is used instead.  Bit 6
  1237. refers to the first operand, and bit 5 to the second.  A value of 0 means a
  1238. small constant and 1 means a variable.  Now, type $11 (not really there)
  1239. operands can't happen, so that's no problem, but there might well be type
  1240. $00 (large constant) operands, for example in "@mul x #666 sp".  In this
  1241. event, the opcode is instead programmed as a "variable" opcode.
  1242.  
  1243. So we must now describe the "variable" opcode form.  In addition to the
  1244. possible opcodes which can arise from overflowing "long" opcodes, there are
  1245. others which can only be "variable".  Here all of the bottom 6 bits are
  1246. available to describe the opcode, and this either holds the above numbers
  1247. $00 to $18 or else:
  1248.  
  1249.     $20   CALL              (4)          (7) These codes are somewhat
  1250.     $21   STOREW                             conjectural and only apply
  1251.     $22   STOREB                             to a few Infocom games; Inform
  1252.     $23   PUT_PROP                           never uses them unless told to
  1253.     $24   READ                               explicitly
  1254.     $25   PRINT_CHAR
  1255.     $26   PRINT_NUM               
  1256.     $27   RANDOM            (4)
  1257.     $28   PUSH                    
  1258.     $29   PULL              (5)
  1259.     $2A   STATUS_SIZE       (7)      
  1260.     $2B   SET_WINDOW        (7)      
  1261.  
  1262.     $33   SET_PRINT         (7)      
  1263.     $34   #RECORD_MODE      (7)      
  1264.     $35   SOUND             (7)      
  1265.  
  1266. Some of these are only of "variable" type because the available codes for
  1267. the other types had run out - PRINT_CHAR, for instance.  Others, especially
  1268. CALL, need the flexibility to have between 1 and 4 operands.
  1269.  
  1270. In the "variable" type opcode, all eight bits of the opcode have been used
  1271. up, so we have to add another byte describing the operands.  This is divided
  1272. into four 2-bit fields.  For example, $$00101111 means large constant
  1273. followed by variable (and no third or fourth opcode).
  1274.  
  1275. Once the opcode is out of the way, the operands are simply stored in one or
  1276. two-byte form as appropriate.
  1277.  
  1278. PRINT and PRINT_RET are followed by text: this is assembled in the usual way
  1279. immediately after the opcode (which may well be at an odd address, but this
  1280. doesn't matter) and execution resumes after the last 2-byte chunk of text
  1281. (the one with top bit set).
  1282.  
  1283. Opcodes marked as "store" in the above tables, return a value: for example,
  1284. MUL multiplies its two arguments together, and CALL calls a routine which
  1285. must return a value.  Such instructions are followed by a single byte giving
  1286. the variable (stack pointer, local or global as usual) to put it in.  This
  1287. may look like an extra operand but is not: there is no need to tell the
  1288. Z-machine what type it has, since it must be a variable.
  1289.  
  1290. Finally, there are instructions which test a condition.  Apart from the
  1291. obvious branch instructions (JE and so on), SAVE does this, for example, the
  1292. test in question being whether or not the save was successful.  Branches are
  1293. stored in two different ways for economy reasons: nearby ones in a single
  1294. byte at the end of the instruction, farther ones in two bytes.
  1295.  
  1296. The top bit of the first byte of a branch is the "flag".  If this is clear,
  1297. then a branch occurs when the condition came out false.  If it is set, then
  1298. the branch occurs when it was true.
  1299.  
  1300. If the next bit (bit 6) is set, then the branch is in abbreviated 1-byte
  1301. format and the offset is in the bottom 6 bits (0 to 5).  If not, the offset
  1302. is in the bottom 15 bits (0 to 6 of the first byte, and all of the second).
  1303. This offset can be positive or negative.  (Eg., all 1's means -1 in the
  1304. usual way.)
  1305.  
  1306. In the abbreviated form, an offset of 1 in fact means "return true from the
  1307. current routine" and an offset of $20 (i.e., -31) means "return false".  An
  1308. offset of 1 is never useful but -31 might arise, and so it is essential to
  1309. use the long form for such branches.
  1310.  
  1311. Working out what the offset ought to be is more complicated than it appears
  1312. because the PC has already moved on from the start of the instruction when
  1313. it reaches the branch.  The bizarre formula in question is
  1314.  
  1315.   Offset = Destination address - Address of this instruction - Length + B
  1316.  
  1317. where
  1318.  
  1319.   Length = number of bytes in instruction (not counting the branch)
  1320.  
  1321. and B is 1 for short branches, 0 for long ones.
  1322.  
  1323. In practice Inform compiles branches in the long form, considering the
  1324. economy to be not worth the nightmarish computation needed to make the
  1325. long/short decision.  (One problem is that the number of bytes in each
  1326. instruction _must_ be the same in both passes, so that the decision needs to
  1327. be made before the value of the offset is known... in a 2-pass compiler this
  1328. is insoluble.  Another is that the offsets are affected by the size of the
  1329. branch, confusing things considerably on forward branches.)  However, its
  1330. assembler mode allows you to make an explicit choice.
  1331.  
  1332. JUMP instructions similarly encode their address operand as an offset, but
  1333. always as a two-byte (signed) constant.  In this respect they differ from
  1334. CALL instructions.  In a CALL, the address is half the absolute routine
  1335. address.
  1336.  
  1337.  
  1338. ---------------------------------------------------------------------------
  1339. A4. Using Inform as an assembler
  1340. ---------------------------------------------------------------------------
  1341.  
  1342.  
  1343. Inform can also act as an assembler.  A line beginning with an @ character
  1344. is sent straight to the assembly routines.  Constants and variable names
  1345. can be given as operands but not compound expressions.  The following are
  1346. supported:
  1347.  
  1348. jump <label>                               go to (local) label
  1349.  
  1350. jz <a> [~]<label>                          If a==0 go to label
  1351.                                            (or return if "rtrue" or "rfalse")
  1352. je <a> <b> [~]<label>                      a=b
  1353. jge <a> <b> [~]<label>                     a>b    (note: not >=)
  1354. jle <a> <b> [~]<label>                     a<b
  1355. test_attr <a> <b> [~]<label>               object a has attribute b
  1356. test <a> <b> [~]<label>                    a&b != 0
  1357. compare_pobj <a> <b> [~]<label>            objects a, b have same parent
  1358.                                            In the above, if the ~ is set,
  1359.                                            the condition is negated
  1360.  
  1361. ret#true                                   return true
  1362. ret#false                                  return false
  1363. ret
  1364. ret(sp)+                                   return sp
  1365. ret <a>                                    return a
  1366.  
  1367. save [~]<label>                            save; go to label if successful
  1368. restore [~]<label>                         restore; ...
  1369. verify                                     verify file integrity
  1370. restart                                    reset Z-machine
  1371. quit                                       exit Z-machine
  1372. show_score                                 redisplay status line immediately
  1373.  
  1374. store <v> <a>                              v=a
  1375. loadw <a> <b> <v>                          v=word at (word address) a+b
  1376. loadb <a> <b> <v>                          v=byte at (byte address) a+b
  1377. storew <a> <b> <c>                         word at (word address) a+b=c
  1378. storeb <a> <b> <c>                         byte at (byte address) a+b=c
  1379. get_prop <a> <b> <v>                       v=property b of object a
  1380. get_prop_addr <a> <b> <v>                  v=address of...
  1381. get_next_prop <a> <b> <v>                  ? - seldom used
  1382. put_prop <a> <b> <c>                       property b of obj a is c
  1383. get_parent <a> <v>                         v=parent of a
  1384. get_prop_len <a> <v>                       v=property length of a
  1385. get_sibling <a> <v> [~]<label>             v=sibling of a, branch if this =0
  1386. get_child <a> <v> [~]<label>               ...child
  1387. inc_chk <v> <a> [~]<label>                 if v++=a then label
  1388. dec_chk <v> <a> [~]<label>                 if v--=a then label
  1389.  
  1390. load <v1> <v2>                             ?
  1391.  
  1392. random <a> <v>                             v=random number up to a
  1393.  
  1394. inc <v>                                    v=v+1
  1395. dec <v>                                    v=v-1
  1396.  
  1397. or <a> <b> <v>                             v=a | b
  1398. and <a> <b> <v>                            v=a & b
  1399. add <a> <b> <v>                            v=a + b
  1400. sub <a> <b> <v>                            v=a - b
  1401. div <a> <b> <v>                            v=a / b
  1402. mod <a> <b> <v>                            v=a % b
  1403.  
  1404. set_attr <a> <b>                           set attribute bit b on object a
  1405. clear_attr <a> <b>                         clear...
  1406.  
  1407. push <a1> [... <a4>]                       push a1 to a4 onto the stack
  1408. pull <a1> [... <a4>]                       pull a1 to a4 from it
  1409. pop                                        throw away top of stack
  1410.  
  1411. insert_obj <a> <b>                         give object a to b
  1412. remove_obj <a>                             remove a from hierarchy
  1413.  
  1414. call <rname> [ <a1>... ] <v>               v=rname(a1,...)
  1415.  
  1416. icall                                      indirect call: sp=(sp)()
  1417.  
  1418. read <a> <b>                               see above
  1419. print_num <v>                              print v in decimal
  1420. print "<text>"                             print text
  1421. print_ret "<text>"                         print text, newline and return 1
  1422. new_line                                   print newline
  1423. print_addr <a>                             print string at address a
  1424. print_paddr <a>                            print string at address 2*a
  1425. print_obj <a>                              print name of object a
  1426. print_char <a>                             print ASCII char <a>
  1427.  
  1428. Branch statements use the long form of the branch code if the label (or
  1429. tilde) is prefaced with a question mark '?', and otherwise use the short
  1430. form.
  1431.  
  1432.  
  1433. ---------------------------------------------------------------------------
  1434. B1. A Bill of Player's Rights
  1435. ---------------------------------------------------------------------------
  1436.  
  1437.  
  1438.   Perhaps the most important point about designing a game is to think as a
  1439. player and not a designer.  I think the least a player deserves is:
  1440.  
  1441.     1.  Not to be killed without warning
  1442.  
  1443.   At its most basic level, this means that a room with three exits, two of
  1444. which lead to instant death and the third to treasure, is unreasonable
  1445. without some hint.  Mention of which brings us to:
  1446.  
  1447.     2.  Not to be given horribly unclear hints
  1448.  
  1449.   Many years ago, I played a game in which going north from a cave led to a
  1450. lethal pit.  The hint was: there was a pride of lions carved above the
  1451. doorway.  Good hints can be skilfully hidden, or very brief (I think, for
  1452. example, the hint in the moving-rocks plain problem in "Spellbreaker" is a
  1453. masterpiece) but should not need explaining even after the event.
  1454.  
  1455.   A more sophisticated version of (1) leads us to:
  1456.  
  1457.     3.  To be able to win without experience of past lives
  1458.  
  1459.   Suppose, for instance, there is a nuclear bomb buried under some anonymous
  1460. floor somewhere, which must be disarmed.  It is unreasonable to expect a
  1461. player to dig up this floor purely because in previous games, the bomb blew
  1462. up there.  To take a more concrete example, in "The Lurking Horror" there is
  1463. something which needs cooking for the right length of time.  As far as I can
  1464. tell, the only way to find out the right time is by trial and error.  But
  1465. you only get one trial per game.  In principle a good player should be able
  1466. to play the entire game out without doing anything illogical.  In similar
  1467. vein:
  1468.  
  1469.     4.  To be able to win without knowledge of future events
  1470.  
  1471.   For example, the game opens near a shop.  You have one coin and can buy a
  1472. lamp, a magic carpet or a periscope.  Five minutes later you are transported
  1473. away without warning to a submarine, whereupon you need a periscope.  If you
  1474. bought the carpet, bad luck.
  1475.  
  1476.     5.  Not to have the game closed off without warning
  1477.  
  1478.   Closed off meaning that it would become impossible to proceed at some
  1479. later date.  If there is a papier-mache wall which you can walk through at
  1480. the very beginning of the game, it is extremely annoying to find that a
  1481. puzzle at the very end requires it to still be intact, because every one of
  1482. your saved games will be useless.  Similarly it is quite common to have a
  1483. room which can only be visited once per game.  If there are two different
  1484. things to be accomplished there, this should be hinted at.
  1485.  
  1486.     6.  Not to need to do unlikely things
  1487.  
  1488.   For example, a game which depends on asking a policeman about something he
  1489. could not reasonably know about.  (Less extremely, the problem of the
  1490. hacker's keys in "The Lurking Horror".)  Another unlikely thing is waiting
  1491. in uninteresting places.  If you have a junction such that after five turns
  1492. an elf turns up and gives you a magic ring, a player may well never spend
  1493. five turns there and never solve what you intended to be straightforward. 
  1494. On the other hand, if you were to put something which demanded investigation
  1495. in the junction, it might be fair enough.  ("Zork III" is especially poor in
  1496. this respect.)
  1497.  
  1498.     7.  Not to need to do boring things for the sake of it
  1499.  
  1500.   In the bad old days many games would make life difficult by putting
  1501. objects needed to solve a problem miles away from where the problem was,
  1502. despite all logic - say, putting a boat in the middle of a desert.  Or, for
  1503. example, it might be fun to have a four-discs tower of Hanoi puzzle in a
  1504. game.  But not an eight-discs one.
  1505.  
  1506.     8.  Not to have to type exactly the right verb
  1507.  
  1508.   For instance, looking inside a box finds nothing, but searching it does. 
  1509. Or consider the following dialogue (amazingly, from "Sorcerer"):
  1510.  
  1511.     >unlock journal
  1512.     (with the small key)
  1513.     No spell would help with that!
  1514.  
  1515.     >open journal
  1516.     (with the small key)
  1517.     The journal springs open.
  1518.  
  1519. This is so misleading as to constitute a bug.  But it's an easy design fault
  1520. to fall into.  (Similarly, the wording needed to use the brick in Zork II
  1521. strikes me as quite unfair.  Or perhaps I missed something obvious.)
  1522.  
  1523.     9.  To be allowed reasonable synonyms
  1524.  
  1525.   In the same room in "Sorcerer" is a "woven wall hanging" which can instead
  1526. be called "tapestry" (though not "curtain").  This is not a luxury, it's an
  1527. essential.
  1528.  
  1529.     10.  To have a decent parser
  1530.  
  1531.   This goes without saying.  At the very least it should provide for taking
  1532. and dropping multiple objects.
  1533.  
  1534.   The last few are more a matter of taste, but I believe in them:
  1535.  
  1536.     11.  To have reasonable freedom of action
  1537.  
  1538.   Being locked up in a long sequence of prisons, with only brief escapes
  1539. between them, is not all that entertaining.  After a while the player begins
  1540. to feel that the designer has tied him to a chair in order to shout the plot
  1541. at him.
  1542.  
  1543.     12.  Not to depend much on luck
  1544.  
  1545.   Small chance variations add to the fun, but only small ones.  The thief in
  1546. "Zork I" seems to me to be just about right in this respect, and similarly
  1547. the spinning room in "Zork II".  But a ten-ton weight which fell down and
  1548. killed you at a certain point in half of all games is just annoying.
  1549.  
  1550.     13.  To be able to understand a problem once it is solved
  1551.  
  1552.   This may sound odd, but many problems are solved by accident or trial and
  1553. error.  A guard-post which can be passed only if you are carrying a spear,
  1554. for instance, ought to have some indication that this is why you're allowed
  1555. past.  (The most extreme example must be the notorious Bank of Zork.)
  1556.  
  1557.     14.  Not to be given too many red herrings
  1558.  
  1559.   A few red herrings make a game more interesting.  A very nice feature of
  1560. "Zork I", "II" and "III" is that they each contain red herrings explained in
  1561. the others (in one case, explained in "Sorcerer").  But difficult puzzles
  1562. tend to be solved last, and the main technique players use is to look at
  1563. their maps and see what's left that they don't understand.  This is
  1564. frustrated when there are many insoluble puzzles and useless objects.  So
  1565. you can expect players to lose interest if you aren't careful.  My personal
  1566. view is that red herrings ought to have some clue provided (even only much
  1567. later): for instance, if there is a useless coconut near the beginning, then
  1568. perhaps much later an absent-minded botanist could be found who wandered
  1569. about dropping them.  The coconut should at least have some rationale.
  1570.  
  1571.   The very worst game I've played for red herrings is "Sorcerer", which by
  1572. my reckoning has 10.
  1573.  
  1574.     15.  To have a good reason why something is impossible
  1575.  
  1576.   Unless it's also funny, a very contrived reason why something is
  1577. impossible just irritates.  (The reason one can't walk on the grass in
  1578. "Trinity" is only just funny enough, I think.)
  1579.  
  1580.     16.  Not to need to be American to understand hints
  1581.  
  1582.   The diamond maze in "Zork II" being a case in point.  Similarly, it's
  1583. polite to allow the player to type English or American spellings or idiom. 
  1584. For instance "Trinity" endears itself to English players in that the soccer
  1585. ball can be called "football" - soccer is a word almost never used in
  1586. England.
  1587.  
  1588.     17.  To know how the game is getting on
  1589.  
  1590.   In other words, when the end is approaching, or how the plot is
  1591. developing.  Once upon a time, score was the only measure of this, but
  1592. hopefully not any more.
  1593.  
  1594.  
  1595. ---------------------------------------------------------------------------
  1596. B2. What makes a good game?
  1597. ---------------------------------------------------------------------------
  1598.  
  1599.  
  1600. 1.  The Plot
  1601.  
  1602. The days of games which consisted of wandering around doing unrelated things
  1603. to get treasures, are long passed: the original Adventure was fun, and so
  1604. was Zork, but two such games are enough.  There should be some overall task
  1605. to be achieved, and it ought to be apparent to the player in advance.
  1606.  
  1607. This isn't to say that it should be apparent at once.  Instead, one can
  1608. begin with just an atmosphere or mood.  But if so, there must be a
  1609. consistent style throughout and this isn't easy to keep up.  "The Lurking
  1610. Horror" is an excellent example of a successful genre style; so is "Leather
  1611. Goddesses of Phobos".
  1612.  
  1613. At its most basic, this means there should be no electric drills lying about
  1614. in a medieval-style fantasy.  The original Adventure was very clean in this
  1615. respect, whereas Zork was less so: I think this is why Adventure remains the
  1616. better game even though virtually everything in Zork was individually
  1617. better.
  1618.  
  1619. If the chosen genre isn't fresh and relatively new, then the game had better
  1620. be very good.
  1621.  
  1622. Plot begins with the opening message, rather the way an episode of Star Trek
  1623. begins before the credits come up.  It ought to be striking and concise (not
  1624. an effort to sit through, like the title page of "Beyond Zork").  By and
  1625. large Infocom were good at this.  A fine example is the overture to
  1626. "Trinity" (by Brian Moriarty):
  1627.  
  1628.   Sharp words between the superpowers. Tanks in East Berlin. And now,
  1629.   reports the BBC, rumors of a satellite blackout. It's enough to spoil your
  1630.   continental breakfast.
  1631.  
  1632.   But the world will have to wait. This is the last day of your $599 London
  1633.   Getaway Package, and you're determined to soak up as much of that
  1634.   authentic English ambience as you can. So you've left the tour bus behind,
  1635.   ditched the camera and escaped to Hyde Park for a contemplative stroll
  1636.   through the Kensington Gardens.
  1637.  
  1638. Already you know: who you are (an unadventurous American tourist, of no
  1639. significance in the world); exactly where you are (Kensington Gardens, Hyde
  1640. Park, London, England); and what is going on (World War III is about to
  1641. break out).  Notice the careful details: mention of the BBC, of continental
  1642. breakfasts, of the camera and the tour bus.  More subtly, "Trinity" is a
  1643. game which starts as a kind of escapism from a disastrous world out of
  1644. control: notice the way the first paragraph is in tense, blunt,
  1645. headline-like sentences, whereas the second is much more relaxed.  So a lot
  1646. has been achieved by these two opening paragraphs.
  1647.  
  1648. The most common plots boil down to saving the world, by exploring until
  1649. eventually you vanquish something ("Lurking Horror" again, for instance) or
  1650. collecting some number of objects hidden in awkward places ("Leather
  1651. Goddesses" again, say).  The latter can get very hackneyed (got to find the
  1652. nine magic spoons of Zenda to reunite the Kingdom...), so much so that it
  1653. becomes a bit of a joke ("Hollywood Hijinx") but still it isn't a bad idea,
  1654. because it enables many different problems to be open at once.
  1655.  
  1656. Most games have a prologue, a middle game and an end game, which are usually
  1657. quite closed off from each other.  Usually once one of these phases has been
  1658. left, it cannot be returned to.
  1659.  
  1660. 2.  The Prologue
  1661.  
  1662. In establishing an atmosphere, the prologue gives a good head start.  In the
  1663. original mainframe Adventure, this was the above-ground landscape; the fact
  1664. that it was there gave a much greater sense of claustrophobia and depth to
  1665. the underground bulk of the game.
  1666.  
  1667. Sometimes a dream-sequence is used (for instance, in "Lurking Horror"), or
  1668. sometimes simply a more mundane region of game (for instance, the
  1669. guild-house in "Sorcerer").  It should not be too large or too hard.
  1670.  
  1671. As well as establishing the mood of the game, and giving out some background
  1672. information, the prologue has to attract a player enough to make him carry
  1673. on playing.  It's worth imagining that the player is only toying with the
  1674. game at this stage, and isn't drawing a map or being at all careful.  If the
  1675. prologue is big, the player will quickly get lost and give up.  If it is too
  1676. hard, then many players simply won't reach the middle game.
  1677.  
  1678. Perhaps eight to ten rooms is the largest a prologue ought to be, and even
  1679. then it should have a simple (easily remembered) map layout.
  1680.  
  1681. 3.  The Middle Game
  1682.  
  1683. A useful exercise is to draw out a tree (or more accurately a lattice) of
  1684. all the puzzles in a game.  At the top is a node representing the start of
  1685. the game, and then lower nodes represent solved puzzles.  An arrow is drawn
  1686. between two puzzles if one has to be solved before the other can be.  For
  1687. instance, a simple portion might look like:
  1688.  
  1689.                                Start
  1690.                               /     \
  1691.                              /       \
  1692.                       Find key     Find car
  1693.                              \        |
  1694.                               \       |
  1695.                                Start car
  1696.                                    |
  1697.                                    |
  1698.                              Reach motorway
  1699.  
  1700. This is useful because it checks that the game is soluble (for example, if
  1701. the ignition key had been kept in a phone box on the motorway, it wouldn't
  1702. have been) but also because it shows the overall structure of the game.
  1703. The questions to ask are:
  1704.  
  1705.   How much is visible at once?
  1706.   Do large parts of the game depend on one difficult puzzle?
  1707.   How many steps does a typical problem need?
  1708.  
  1709. Some games, such as the original Adventure, are very wide: there are thirty or
  1710. so puzzles, all easily available, none leading to each other.  Others, such as
  1711. "Spellbreaker", are very narrow: a long sequence of puzzles, each of which
  1712. leads only to a chance to solve the next.
  1713.  
  1714. A compromise is probably best.  Wide games are not very interesting, while
  1715. narrow ones can in a way be easy: if only one puzzle is available at a time,
  1716. the player will just concentrate on it, and will not be held up by trying to
  1717. use objects which are provided for different puzzles.
  1718.  
  1719. Bottlenecks should be avoided unless they are reasonably guessable:
  1720. otherwise many players will simply get no further.
  1721.  
  1722. Puzzles ought not to be simply a matter of typing in one well-chosen line. 
  1723. One hallmark of a good game is not to get any points for picking up an
  1724. easily-available key and unlocking a door with it.  This sort of low-level
  1725. achievement - like wearing an overcoat found lying around, for instance -
  1726. should not be enough.  A memorable puzzle will need several different ideas 
  1727. to solve (the Babel fish dispenser in "Hitch-hikers", for instance).
  1728.  
  1729. 4.  Density
  1730.  
  1731. Once upon a time, the sole measure of quality in advertisements for
  1732. adventure games was the number of rooms.  Even quite small programs would
  1733. have 200 rooms, which meant only minimal room descriptions and simple
  1734. puzzles which were scattered thinly over the map.
  1735.  
  1736. Nowadays a healthier principle has been adopted: that (barring a few
  1737. junctions and corridors) there should be something out of the ordinary about
  1738. every room.
  1739.  
  1740. One reason for the quality of the "Infocom" games is that the version 3
  1741. system has an absolute maximum of 255 objects, which needs to cover rooms,
  1742. objects and many other things (eg, compass directions, or the spells in
  1743. "Enchanter" et al).  Many "objects" are not portable anyway: walls,
  1744. tapestries, thrones, control panels, coal-grinding machines and so on.
  1745.  
  1746. As a rule of thumb, four objects to one room is about right: this means
  1747. there will be, say, 50-60 rooms.  Of the remaining 200 objects, one can
  1748. expect 15-20 to be used up by the game's administration (eg, a "darkness"
  1749. room, 10 compass directions, a player and so on).  Another 50-75 or so
  1750. objects will be portable but the largest number, at least 100, will be
  1751. furniture.
  1752.  
  1753. So an object limit can be a blessing as well as a curse: it forces the
  1754. designer to make the game dense.  Rooms are too precious to be wasted.
  1755.  
  1756. 5.  Rewards
  1757.  
  1758. There are two kinds of reward which need to be given to a player in return
  1759. for solving a puzzle.  One is obvious: that the game should advance a
  1760. little.  But the player at the keyboard needs a reward as well, that the
  1761. game should offer something new to look at.  In the old days, when a puzzle
  1762. was solved, the player simply got a bar of gold and had one less puzzle to
  1763. solve.
  1764.  
  1765. Much better is to offer the player some new rooms and objects to play
  1766. with, as this is a real incentive.  If no new rooms are on offer, at least
  1767. the "treasure" objects can be made interesting, like the spells in the
  1768. "Enchanter" trilogy or the cubes in "Spellbreaker".
  1769.  
  1770. 6.  Mazes
  1771.  
  1772. Almost every game contains a maze.  Nothing nowadays will ever equal the
  1773. immortal
  1774.  
  1775.   You are in a maze of twisty little passages, all alike.
  1776.  
  1777. But now we are all jaded.  A maze should offer some twist which hasn't been
  1778. done before (the ones in "Enchanter" and "Sorcerer" being fine examples).
  1779.  
  1780. The point is not to make it hard and boring.  The standard maze solution is
  1781. to litter the rooms with objects in order to make the rooms distinguishable.
  1782. It's easy enough to obstruct this, the thief in "Zork I" being about the
  1783. wittiest way of doing so.  But that only makes a maze tediously difficult.
  1784.  
  1785. Instead there should be an elegant quick solution: for instance a guide who
  1786. needs to be bribed, or fluorescent arrows painted on the floor which can
  1787. only be seen in darkness (plus a hint about darkness, of course).
  1788.  
  1789. Above all, don't design a maze which appears to be a standard impossibly
  1790. hard one: even if it isn't, a player may lose heart and give up rather than
  1791. go to the trouble of mapping it.
  1792.  
  1793. 7.  Wrong guesses
  1794.  
  1795. For some puzzles, a perfectly good alternative solution will occur to
  1796. players.  It's good style to code two or more solutions to the same puzzle,
  1797. if that doesn't upset the rest of the game.  But even if it does, at least
  1798. a game should say something when a good guess is made.  (Trying to cross the
  1799. volcano on the magic carpet in "Spellbreaker" is a case in point.)
  1800.  
  1801. One reason why "Zork" held the player's attention so firmly (and why it took
  1802. about ten times the code size, despite being slightly smaller than the
  1803. original mainframe Adventure) was that it had a huge stock of usually funny
  1804. responses to reasonable things which might be tried.
  1805.  
  1806. My favourite funny response, which I can't resist reprinting here, is:
  1807.  
  1808.    You are falling towards the ground, wind whipping around you.
  1809.    >east
  1810.    Down seems more likely.                                  ["Spellbreaker"]
  1811.  
  1812. (Though I also recommend trying to take the sea serpent in "Zork II".)  This
  1813. is a good example because it's exactly the sort of boring rule (can't move
  1814. from the midair position) which most designers usually want to code as fast
  1815. as possible, and don't write with any imagination.
  1816.  
  1817. Just as some puzzles should have more than one solution, some objects should
  1818. have more than one purpose.  In bad old games, players automatically threw
  1819. away everything as soon as they'd used them.  In better designed games,
  1820. obviously useful things (like the crowbar and the gloves in "Lurking
  1821. Horror") should be hung on to by the player throughout.
  1822.  
  1823. 8.  The Map
  1824.  
  1825. To maintain an atmosphere throughout it's vital that the map should be
  1826. continuous.  Adventure games used to have maps like
  1827.  
  1828.                             Glacier
  1829.                                |
  1830.                           Oriental Room  --  Fire Station
  1831.                            (megaphone)        (pot plant)
  1832.                                |
  1833.                            Cheese Room
  1834.  
  1835. in which the rooms bore no relation to each other, so that the game had no
  1836. overall geography at all, and objects were unrelated to the rooms they were
  1837. in.  Much more believable is something like
  1838.  
  1839.                    Snowy Mountainside
  1840.                             \  
  1841.                          Carved Tunnel
  1842.                                |
  1843.                          Oriental Room  -- Jade Passage -- Fire Dragon
  1844.                             (buddha)       (bonsai tree)      Room
  1845.                                |
  1846.                          Blossom Room
  1847.  
  1848. Try to have some large-scale geography too: the mountainside should extend
  1849. across the map in both directions.  If there is a stream passing through a
  1850. given location, what happens to it?  And so on.
  1851.  
  1852. In designing a map, it adds to the interest to make a few connections in the
  1853. rarer compass directions (NE, NW, SE, SW) to prevent the player from a
  1854. feeling that the game has a square grid.  Also, it's nice to have a few
  1855. (possibly long) loops which can be walked around, to prevent endless
  1856. retracing of steps.
  1857.  
  1858. If the map is very large, or if a good deal of to-and-froing is called for,
  1859. there should be some rapid means of moving across it, such as the magic
  1860. words in Adventure, or the cubes in "Spellbreaker".
  1861.  
  1862. 9.  The End Game
  1863.  
  1864. Some end games are small ("Lurking Horror", or "Sorcerer" for instance),
  1865. others large (the master game of the mainframe Adventure).  Nonetheless
  1866. almost all games have one.
  1867.  
  1868. End games serve two purposes.  Firstly they give the player a sense of being
  1869. near to success, and can be used to culminate the plot, to reveal the game's
  1870. secrets.  This is obvious enough.  But secondly they also serve to stop the
  1871. final stage of the game from being too hard.
  1872.  
  1873. As a designer, you don't usually want the last step to be too difficult; you
  1874. want to give the player the satisfaction of finishing, as a reward for
  1875. having got through the game.  (But of course you want to make him work for
  1876. it.)  An end game helps, because it narrows the game, so that only a few
  1877. rooms and objects are accessible.
  1878.  
  1879. The most annoying thing is requiring the player to have brought a few
  1880. otherwise useless objects with him.  The player should not be thinking that
  1881. the reason for being stuck on the master game is that something very obscure
  1882. should have been done 500 turns before.
  1883.  
  1884. 10.  And Finally...
  1885.  
  1886. Finally, the winner gets some last message (which, like the opening message,
  1887. should have something amusing in it and should not be too long).  That
  1888. needn't quite be all, though.  In its final incarnations (alas, not the one
  1889. included in Lost Treasures), "Zork I" offered winners access to the hints
  1890. system at the RESTART, RESTORE or QUIT prompt.
  1891.  
  1892. As a last word on game design: Inform makes it easy to knock up games which
  1893. look a little bit like the classics, until you play them.  Infocom, Inc,
  1894. acquired a certain mystique in their time, but a game is not good merely
  1895. because it runs under one of their interpreters.  Still, I hope a few people
  1896. may put in the effort to turn out a finished game or two, and add to the
  1897. canon.
  1898.  
  1899.  
  1900. ---------------------------------------------------------------------------
  1901. C1. A Hello Cruel World program
  1902. ---------------------------------------------------------------------------
  1903.  
  1904.  
  1905. >   !
  1906. >   ! A great step backward in interactive fiction...
  1907. >   !
  1908. >
  1909. >   Object hillside "Bare hillside" nothing;
  1910. >   global place = hillside;
  1911. >   global score = 0;
  1912. >   global turns = 1;
  1913. >   
  1914. >   [ Main;
  1915. >   
  1916. >     print "^^^^^^^^^^^You wake up, shivering to see that Morgoth \
  1917. >            the Flatulent Devil is towering over you...^^";
  1918. >     Message();
  1919. >     print "^^\
  1920. >       ...and he squashes you effortlessly.^^   *** You have died ***^^^^^";
  1921. >   
  1922. >     quit;
  1923. >   ];
  1924. >   
  1925. >   [ Message i;
  1926. >     print "HELLO CRUEL WORLD^";
  1927. >     print "A Non-Interactive Demonstration^\
  1928. >            Copyright (c) 1993 by Graham Nelson. All rights reserved.^";
  1929. >     print "Release ";
  1930. >     print_num 0-->1;
  1931. >     print " / Serial number ";
  1932. >   
  1933. >     for i 18 to 23 { print_char 0->i; } new_line;
  1934. >   ];
  1935. >   
  1936.  
  1937. Note that the familiar banner has to be produced by your code.  By
  1938. convention, the first word (at bytes 2 and 3) of the file is the release
  1939. number, and this is what is set by the RELEASE command.  In this file there
  1940. isn't a RELEASE command, so it comes out as 1.  Bytes 18 to 23 contain the
  1941. serial number, or in fact the serial string of ASCII characters.  By custom
  1942. and tradition, these are the date of compilation arranged YYMMDD, and Inform
  1943. sets these automatically.
  1944.  
  1945. Note also that Message had to be a separate routine since we needed a local
  1946. variable, and Main is not permitted to have local variables of its own.
  1947.  
  1948. (The above source has changed a little since the first release: if the
  1949. object is not included, then some interpreters (not the InfoTaskForce one)
  1950. which voluntarily display the status line (when not asked to do so), get in
  1951. a quandary printing a location, time and score.  So for their benefit, here
  1952. are all three.)
  1953.  
  1954. On my machine (an Acorn Archimedes A5000), compiling with statistics
  1955. produces something like:
  1956.  
  1957. *inform -s hellow
  1958. Archimedes Inform 0.6 (v613)
  1959.    1 objects (maximum 255)        0 dictionary entries (maximum 800)
  1960.    0 attributes (maximum 32)      2 properties (maximum 30)
  1961.    0 adjectives (maximum 240)     0 verbs (maximum 250)
  1962.    0 actions (maximum 110)       1K long (maximum 128K)
  1963.    3 globals (maximum 240)      480 variable space (maximum 2048)
  1964.   28 symbols (maximum 3000)       2 routines
  1965.  314 characters of text (compressed to 276)
  1966.  
  1967. Offsets in story file:
  1968. 0042 Synonyms     0102 Defaults     0140 Objects    0149 Properties
  1969. 0155 Variables    0335 Parse table  0335 Actions    0335 Preactions
  1970. 0337 Adjectives   0337 Dictionary   033e Code       0480 Strings
  1971.  
  1972. Completed in 1 seconds.
  1973.  
  1974. (This second being mostly consumed in printing out the statistics.  In
  1975. practice the compilation time is roughly proportional to the output
  1976. length, and typically takes 1.5-2 seconds per K of story file on my
  1977. machine.)
  1978.  
  1979. Note: if you try compiling the example games, and get different
  1980. statistics outputs, do not worry; it probably means you're using a later
  1981. version of Inform than the one that printed the above.  Similarly,
  1982. do not worry if your compiled story file shows differences with the
  1983. object code in the archive.
  1984.  
  1985. If the "Deja Vu" example (see below) compiles without Inform errors and
  1986. plays at all properly, then Inform is probably working OK.
  1987.  
  1988.  
  1989. ---------------------------------------------------------------------------
  1990. C2. "Deja Vu": a toy game
  1991. ---------------------------------------------------------------------------
  1992.  
  1993.  
  1994. The "Hello World" program above is enticingly short and easy, but only
  1995. because it doesn't contain a parser.  A fully functioning parser is hard
  1996. work to write, and occupies a good deal of "Inform" code.  Besides this, the
  1997. everyday mechanics of an adventure game involve more coding than most
  1998. designers want to go into, at least at the outset.
  1999.  
  2000. "Deja Vu" is a toy game in terms of how large it is to play, but contains a
  2001. fairly good parser and a kernel of routines which is easily adapted to any
  2002. ordinary adventure game.  The source should be available from where this
  2003. file is.  It can freely be used or adapted by anybody who would like to.
  2004.  
  2005. For the most part it should be self-explanatory with a little experiment. 
  2006. Roughly it works like this: the main loop calls the parser.  This returns
  2007. an actor (person to carry out the action, usually the player), the action
  2008. number and one or two argument objects (one of which may in fact be a list
  2009. of argument objects).  Next, the address of the action routine is looked up. 
  2010. For each object the verb is to be applied to, the room where the actor is is
  2011. asked via its "preroutine" whether it objects; then the object in question
  2012. is similarly asked; then the action takes place, via an indirect jump; then
  2013. the object and room are told that is has taken place, via their
  2014. "postroutines", and given the opportunity to give their own output instead
  2015. of the usual one.  (Thus, "Taken" can become "You drop the snake in horror. 
  2016. It is still alive!" or some such.)  Finally, the Time routine is called, to
  2017. run timed and random events.
  2018.  
  2019. For the sake of contrast, compiling "Deja Vu" with statistics should give
  2020. something like:
  2021.  
  2022. *inform -s dejavu
  2023. Archimedes Inform 0.6 (v613)
  2024.   43 objects (maximum 255)      253 dictionary entries (maximum 800)
  2025.   28 attributes (maximum 32)     24 properties (maximum 30)
  2026.   16 adjectives (maximum 240)    71 verbs (maximum 250)
  2027.   78 actions (maximum 110)      21K long (maximum 128K)
  2028.   43 globals (maximum 240)     1044 variable space (maximum 2048)
  2029. 1116 symbols (maximum 3000)     127 routines
  2030. 16363 characters of text (compressed to 11982)
  2031.  
  2032. Offsets in story file:
  2033. 0042 Synonyms     0102 Defaults     0140 Objects    02c3 Properties
  2034. 0636 Variables    0a4a Parse table  0ef7 Actions    0f93 Preactions
  2035. 1031 Adjectives   1071 Dictionary   1764 Code       4c5a Strings
  2036.  
  2037. Completed in 36 seconds.
  2038.  
  2039.  
  2040. ---------------------------------------------------------------------------
  2041.     Graham Nelson,            gan10@uk.ac.cam.phx  (preferably)
  2042.     Magdalen College,         nelson@uk.ac.ox.vax  (my Mr Hyde)
  2043.     Oxford OX1 4AU,
  2044.     UK.                       18th April 1993
  2045.                               and 16th May 1993
  2046. ---------------------------------------------------------------------------
  2047.