home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 1 / RISC_DISC_1.iso / pd_share / games / inform / compiler / manuals / Specific < prev    next >
Encoding:
Text File  |  1994-10-14  |  121.7 KB  |  2,696 lines

  1. %
  2. %  TeX source for The Specification of the Z-machine
  3. %
  4.  
  5. \newif\iffiles\filesfalse
  6. %
  7. %  Manual macros
  8. %
  9. %  Page layout
  10. %
  11. \newif\ifshutup\shutupfalse
  12. \magnification=\magstep 1
  13. \hoffset=0.15 true in
  14. \voffset=2\baselineskip
  15. %
  16. %  General hacks
  17. %
  18. \def\PAR{\par}
  19. %
  20. %  Font loading
  21. %
  22. \font\medfont=cmr10 scaled \magstep2
  23. \font\bigfont=cmr10 scaled \magstep3
  24. %\def\sectfont{\bf}
  25. \font\sectfont=cmbx12
  26. \def\small{\sevenrm}
  27. \font\rhrm=cmr8
  28. \font\rhit=cmsl8
  29. %
  30. %  Titles
  31. %
  32. \newcount\subsectno    %  Subsection number
  33. \def\rhead{}           %  The running head will go here
  34. %
  35. \def\newsection#1#2{%     To begin a section...
  36. %\global\titletrue%        Declare this as a title page
  37. \xdef\rhead{{\rhrm #1}\quad #2}%       Initialise running head and ssn
  38. \subsectno=0%
  39. \iffiles
  40. \write\conts{\string\sli\string{#1\string}\string{#2\string}\string{\the\pageno\string}}%
  41. \fi
  42. }
  43. %
  44. \def\section#1#2{\vskip 1 true in\goodbreak\newsection{#1}{#2}
  45. \noindent{\sectfont #1\quad #2}\bigskip\noindent}
  46. %
  47. %  Headers and footers
  48. %
  49. \newif\iftitle
  50. \headline={\iftitle\hfil\global\titlefalse%
  51.            \else{\hfil{\rhit \rhead}}%
  52.            \fi}
  53. \footline={\ifnum\pageno<0\hfil{\tenbf\romannumeral -\pageno}%
  54. \else\hfil{\tenbf \number\pageno}\fi}
  55. %\footline={\ifnum\pageno=1\hfil\else\hfil{\tenbf \number\pageno}\fi}
  56. %
  57. %  (Old date-stamping version:)
  58. % \footline={\hfil{\rm \number\pageno}\hfil{\rm \number\day/\number\month}}
  59. %
  60. % If this works I'll be impressed
  61. %
  62.  
  63. \font\ninerm=cmr9
  64. \font\ninei=cmmi9
  65. \font\ninesy=cmsy9
  66. \font\ninebf=cmbx9
  67. \font\eightbf=cmbx8
  68. \font\ninett=cmtt9
  69. \font\nineit=cmti9
  70. \font\ninesl=cmsl9
  71. \def\ninepoint{\def\rm{\fam0\ninerm}%
  72.   \textfont0=\ninerm
  73.   \textfont1=\ninei
  74.   \textfont2=\ninesy
  75.   \textfont3=\tenex
  76.   \textfont\itfam=\nineit \def\it{\fam\itfam\nineit}%
  77.   \textfont\slfam=\ninesl \def\sl{\fam\slfam\ninesl}%
  78.   \textfont\ttfam=\ninett \def\tt{\fam\ttfam\ninett}%
  79.   \textfont\bffam=\ninebf
  80.   \normalbaselineskip=11pt
  81.   \setbox\strutbox=\hbox{\vrule height8pt depth3pt width0pt}%
  82.   \normalbaselines\rm}
  83.  
  84. \def\tenpoint{\def\rm{\fam0\tenrm}%
  85.   \textfont0=\tenrm
  86.   \textfont1=\teni
  87.   \textfont2=\tensy
  88.   \textfont3=\tenex
  89.   \textfont\itfam=\tenit \def\it{\fam\itfam\tenit}%
  90.   \textfont\slfam=\tensl \def\sl{\fam\slfam\tensl}%
  91.   \textfont\ttfam=\tentt \def\tt{\fam\ttfam\tentt}%
  92.   \textfont\bffam=\tenbf
  93.   \normalbaselineskip=12pt
  94.   \setbox\strutbox=\hbox{\vrule height8.5pt depth3.5pt width0pt}%
  95.   \normalbaselines\rm}
  96.  
  97. \parindent=30pt
  98. \def\inpar{\hangindent40pt\hangafter1\qquad}
  99. \def\onpar{\par\hangindent40pt\hangafter0}
  100.  
  101. \newskip\ttglue
  102. \ttglue=.5em plus.25em minus.15em
  103.  
  104. \def\orsign{$\mid\mid$}
  105.  
  106. \outer\def\begindisplay{\obeylines\startdisplay}
  107. {\obeylines\gdef\startdisplay#1
  108.   {\catcode`\^^M=5$$#1\halign\bgroup\indent##\hfil&&\qquad##\hfil\cr}}
  109. \outer\def\enddisplay{\crcr\egroup$$}
  110.  
  111. \chardef\other=12
  112.  
  113. \def\ttverbatim{\begingroup \catcode`\\=\other \catcode`\{=\other
  114.   \catcode`\}=\other \catcode`\$=\other \catcode`\&=\other 
  115.   \catcode`\#=\other \catcode`\%=\other \catcode`\~=\other 
  116.   \catcode`\_=\other \catcode`\^=\other
  117.   \obeyspaces \obeylines \tt}
  118. {\obeyspaces\gdef {\ }}
  119.  
  120. \outer\def\beginstt{$$\let\par=\endgraf \ttverbatim\ninett \parskip=0pt
  121.   \catcode`\|=0 \rightskip=-5pc \ttfinish}
  122. \outer\def\begintt{$$\let\par=\endgraf \ttverbatim \parskip=0pt
  123.   \catcode`\|=0 \rightskip=-5pc \ttfinish}
  124. {\catcode`\|=0 |catcode`|\=\other
  125.   |obeylines
  126.   |gdef|ttfinish#1^^M#2\endtt{#1|vbox{#2}|endgroup$$}}
  127.  
  128. \catcode`\|=\active
  129. {\obeylines\gdef|{\ttverbatim\spaceskip=\ttglue\let^^M=\ \let|=\endgroup}}
  130.  
  131. \def\beginlines{\par\begingroup\nobreak\medskip\parindent=0pt
  132.   \nobreak\ninepoint \obeylines \everypar{\strut}}
  133. \def\endlines{\endgroup\medbreak\noindent}
  134.  
  135. \def\<#1>{\leavevmode\hbox{$\langle$#1\/$\rangle$}}
  136.  
  137. \def\dbend{{$\triangle$}}
  138. \def\d@nger{\medbreak\begingroup\clubpenalty=10000
  139.   \def\par{\endgraf\endgroup\medbreak} \noindent\hang\hangafter=-2
  140.   \hbox to0pt{\hskip-\hangindent\dbend\hfill}\ninepoint}
  141. \outer\def\danger{\d@nger}
  142. \def\dd@nger{\medskip\begingroup\clubpenalty=10000
  143.   \def\par{\endgraf\endgroup\medbreak} \noindent\hang\hangafter=-2
  144.   \hbox to0pt{\hskip-\hangindent\dbend\kern 1pt\dbend\hfill}\ninepoint}
  145. \outer\def\ddanger{\dd@nger}
  146. \def\enddanger{\endgraf\endsubgroup}
  147.  
  148. \def\cstok#1{\leavevmode\thinspace\hbox{\vrule\vtop{\vbox{\hrule\kern1pt
  149.        \hbox{\vphantom{\tt/}\thinspace{\tt#1}\thinspace}}
  150.      \kern1pt\hrule}\vrule}\thinspace}
  151.  
  152. \newcount\exno
  153. \exno=0
  154.  
  155. \def\xd@nger{%
  156.   \begingroup\def\par{\endgraf\endgroup\medbreak}\ninepoint}
  157.  
  158. \outer\def\warning{\medbreak
  159.   \noindent\llap{$\bullet$\rm\kern.15em}%
  160.   {\ninebf WARNING}\par\nobreak\noindent}
  161. \outer\def\exercise{\medbreak \global\advance\exno by 1
  162.   \noindent\llap{$\bullet$\rm\kern.15em}%
  163.   {\ninebf EXERCISE \bf\the\exno}\par\nobreak\noindent}
  164. \def\dexercise#1{\global\advance\exno by 1
  165.   \medbreak\noindent\llap{$\bullet$\rm\kern.15em}%
  166.   #1{\eightbf ~EXERCISE \bf\the\exno}\hfil\break}
  167. \outer\def\dangerexercise{\xd@nger \dexercise{\dbend}}
  168. \outer\def\ddangerexercise{\xd@nger \dexercise{\dbend\dbend}}
  169.  
  170.  
  171. \newwrite\ans%
  172. \newwrite\conts%
  173. \iffiles
  174. \immediate\openout\conts=$.games.infocom.ftp.toolkit.mandir.conts
  175. \fi
  176.  
  177. \iffiles\else\outer\def\answer#1{\par\medbreak}\shutuptrue\fi
  178.  
  179. \newwrite\inx
  180. \ifshutup\else
  181. \immediate\openout\inx=$.games.infocom.ftp.toolkit.mandir.inxdata
  182. \fi
  183. \def\marginstyle{\sevenrm %
  184.   \vrule height6pt depth2pt width0pt } %
  185.  
  186. \newif\ifsilent
  187. \def\specialhat{\ifmmode\def\next{^}\else\let\next=\beginxref\fi\next}
  188. \def\beginxref{\futurelet\next\beginxrefswitch}
  189. \def\beginxrefswitch{\ifx\next\specialhat\let\next=\silentxref
  190.   \else\silentfalse\let\next=\xref\fi \next}
  191. \catcode`\^=\active \let ^=\specialhat
  192. \def\silentxref^{\silenttrue\xref}
  193.  
  194. \newif\ifproofmode
  195. \proofmodetrue %
  196.  
  197. \def\xref{\futurelet\next\xrefswitch}
  198. \def\xrefswitch{\begingroup\ifx\next|\aftergroup\vxref
  199.   \else\ifx\next\<\aftergroup\anglexref
  200.     \else\aftergroup\normalxref \fi\fi \endgroup}
  201. \def\vxref|{\catcode`\\=\active \futurelet\next\vxrefswitch}
  202. \def\vxrefswitch#1|{\catcode`\\=0
  203.   \ifx\next\empty\def\xreftype{2}%
  204.     \def\next{{\tt\text}}%
  205.   \else\def\xreftype{1}\def\next{{\tt\text}}\fi %
  206.   \edef\text{#1}\makexref}
  207. {\catcode`\|=0 \catcode`\\=\active |gdef\{}}
  208. \def\anglexref\<#1>{\def\xreftype{3}\def\text{#1}%
  209.   \def\next{\<\text>}\makexref} %
  210. \def\normalxref#1{\def\xreftype{0}\def\text{#1}\let\next=\text\makexref}
  211.  
  212. \def\makexref{\ifproofmode%
  213.   \xdef\writeit{\write\inx{\text\space!\xreftype\space
  214.     \noexpand\number\pageno.}}\iffiles\writeit\fi
  215.   \else\ifhmode\kern0pt \fi\fi
  216.  \ifsilent\ignorespaces\else\next\fi}
  217.  
  218. \newdimen\fullhsize
  219. \def\fullline{\hbox to\fullhsize}
  220. \let\lr=L \newbox\leftcolumn
  221.  
  222. \def\doubleformat{\shipout\vbox{\makeheadline
  223.     \fullline{\box\leftcolumn\hfil\columnbox}
  224.     \makefootline}
  225.   \advancepageno}
  226. \def\tripleformat{\shipout\vbox{\makeheadline
  227.     \fullline{\box\leftcolumn\hfil\box\midcolumn\hfil\columnbox}
  228.     \makefootline}
  229.   \advancepageno}
  230. \def\columnbox{\leftline{\pagebody}}
  231.  
  232. \newbox\leftcolumn
  233. \newbox\midcolumn
  234. \def\beginindex{
  235. \fullhsize=6.5true in \hsize=2.1true in
  236.  \global\def\makeheadline{\vbox to 0pt{\vskip-22.5pt
  237.       \fullline{\vbox to8.5pt{}\the\headline}\vss}\nointerlineskip}
  238.  \global\def\makefootline{\baselineskip=24pt \fullline{\the\footline}}
  239.  \output={\if L\lr
  240.    \global\setbox\leftcolumn=\columnbox \global\let\lr=M
  241.  \else\if M\lr
  242.    \global\setbox\midcolumn=\columnbox \global\let\lr=R
  243.  \else\tripleformat \global\let\lr=L\fi\fi
  244.  \ifnum\outputpenalty>-20000 \else\dosupereject\fi}
  245. \begingroup
  246.   \parindent=1em \maxdepth=\maxdimen
  247.   \def\par{\endgraf \futurelet\next\inxentry}
  248.   \obeylines \everypar={\hangindent 2\parindent}
  249.   \exhyphenpenalty=10000 \raggedright}
  250. \def\inxentry{\ifx\next\sub \let\next=\subentry
  251.   \else\ifx\next\endindex \let\next=\vfill
  252.   \else\let\next=\mainentry \fi\fi\next}
  253. \def\endindex{\mark{}\break\endgroup
  254. \supereject
  255. \if L\lr \else\null\vfill\eject\fi
  256. \if L\lr \else\null\vfill\eject\fi
  257. }
  258. \let\sub=\indent \newtoks\maintoks \newtoks\subtoks
  259. \def\mainentry#1,{\mark{}\noindent
  260.   \maintoks={#1}\mark{\the\maintoks}#1,}
  261. \def\subentry\sub#1,{\mark{\the\maintoks}\indent
  262.   \subtoks={#1}\mark{\the\maintoks\sub\the\subtoks}#1,}
  263.  
  264. \def\subsection#1{\medbreak\par\noindent{\bf #1}\qquad}
  265.  
  266. %  For contents
  267.  
  268. \def\cl#1#2{\bigskip\par\noindent{\bf #1}\quad {\bf #2}}
  269. \def\li#1#2#3{\smallskip\par\noindent\hbox to 5 in{{\bf #1}\quad #2\dotfill #3}}
  270. \def\sli#1#2#3{\par\noindent\hbox to 5 in{\qquad\item{#1}\quad #2\dotfill #3}}
  271. \def\fcl#1#2{\bigskip\par\noindent\hbox to 5 in{\phantom{\bf 1}\quad {\bf #1}\dotfill #2}}
  272.  
  273. % Epigrams
  274.  
  275. \def\poem{\begingroup\narrower\narrower\narrower\obeylines\ninepoint}
  276. \def\widepoem{\begingroup\narrower\narrower\obeylines\ninepoint}
  277. \def\verywidepoem{\begingroup\narrower\obeylines\ninepoint}
  278. \def\quote{\medskip\begingroup\narrower\narrower\noindent\ninepoint}
  279. \def\poemby#1#2{\par\smallskip\qquad\qquad\qquad\qquad\qquad -- #1, {\it #2}
  280. \tenpoint\endgroup\bigskip}
  281. \def\widepoemby#1#2{\par\smallskip\qquad\qquad\qquad -- #1, {\it #2}
  282. \tenpoint\endgroup\bigskip}
  283. \def\quoteby#1{\par\smallskip\qquad\qquad\qquad\qquad\qquad
  284.  -- #1\tenpoint\endgroup\bigskip}
  285. \def\endquote{\par\tenpoint\endgroup\medskip}
  286.  
  287. %
  288. %  End of macros
  289.  
  290. \def\subtitle#1{\bigbreak\noindent{\bf #1}\medskip}
  291.  
  292. \titletrue
  293.  
  294. \centerline{\bigfont The Specification of the Z-Machine}
  295. \vskip 0.3in
  296. \centerline{\medfont and Inform assembly language}
  297. \vskip 0.3in
  298. \centerline{\sl last updated 24/9/94}
  299. \vskip 0.5in 
  300.  
  301. \sli{1}{Introduction}{2}
  302. \sli{2}{Resources available}{4}
  303. \sli{3}{History and the six versions}{5}
  304. \sli{4}{How text is encoded}{7}
  305. \sli{5}{How instructions are encoded}{9}
  306. \sli{6}{The early Z-machine}{12}
  307. \sli{7}{The late Z-machine}{16}
  308. \sli{8}{Complete table of opcodes}{22}
  309. \sli{9}{Dictionary of opcodes}{29}
  310. \sli{10}{Header format through the ages}{40}
  311. \sli{11}{A few statistics}{41}
  312.  
  313.  
  314. \vfill\eject
  315. \section{1}{Introduction}
  316.  
  317. \quote
  318.      The legend that every cipher is breakable is of course absurd,
  319.      though still quite widespread among people who should know better.
  320. \poemby{J. E. Littlewood}{A Mathematician's Miscellany}
  321. \quote
  322.      There is an obvious resemblance between an unreadable script
  323.      and a secret code; similar methods can be employed to break
  324.      both.  But the differences must not be overlooked.  The code is
  325.      deliberately designed to baffle the investigator; the script
  326.      is only puzzling by accident.
  327. \poemby{John Chadwick}{The Decipherment of Linear B}
  328.  
  329. The Z-machine is an imaginary computer originally devised by Joel Berez and
  330. Marc Blank in 1979 to run the Infocom adventure games.  Since the demise of
  331. Infocom much effort by many people has gone into deciphering it and
  332. implementing it with new portable interpreters to allow modern-day players
  333. to run the classic Infocom games.  The Z-machine is also the run-time code
  334. format of the Inform compiler, which means that there are now more
  335. Infocom-format games in play than the ones Infocom actually wrote.
  336.  
  337. It is well-adapted to its task.  Its behaviour is (very, very nearly)
  338. exactly specified and it has been accurately implemented on virtually every
  339. small computer.  It maintains a hierarchy of objects and possessions, and
  340. does the computationally-intensive part of parsing input itself.
  341.  
  342. The purpose of this paper is to fully document the Z-machine, discuss to
  343. what extent it is presently implemented and detail how to use Inform as an
  344. assembler.
  345.  
  346. Only a few of the pieces in this jigsaw were placed by myself, and the
  347. credit belongs to many people.  Old hands at the decipherment game will
  348. no doubt find the opcode table tiresomely familiar: but, as with a chemist
  349. finding Mendeleyev's periodic table on a laboratory wall, so will the hacker
  350. be reassured by the sight.
  351.  
  352. I gratefully acknowledge the help of Paul David Doherty and Mark Howell, who
  353. each read a draft of this paper and sent back detailed corrections. 
  354. Mistakes and misunderstandings remain my own.
  355. \medskip
  356.  
  357. To begin, three general points.  The fascination with the letter Z began
  358. with `Zork': apparently ``zork" was a nonsense word used at MIT for the
  359. current uninstalled program in progress, and stuck.  The Z-machine runs what
  360. we shall call Z-code.  Just as we shall use the term ``Z-machine" for both
  361. the machine and its loaded program, so ZIP (Zork Implementation Program) was
  362. used to mean either the interpreter or the object code it interpreted.  Code
  363. was written in ZIL (Zork Implementation Language), which was derived from
  364. MDL (informally called ``muddle"), a particularly unhelpful form of LISP. 
  365. It was then compiled by ZILCH to assembly code which was passed to ZAP to
  366. make the ZIP.  We refer to code as ``Z-code" to avoid confusion with ``Zip",
  367. the name of Mark Howell's interpreter (by far the best available).
  368.  
  369. Secondly.  In talking about ``the Z-machine", what do we really mean: the
  370. design Infocom had in mind, the syntax which seems to be in their surviving
  371. game files, or what is actually done by various interpreters, theirs or
  372. ours?  Aided by the patient detective work of my predecessors (e.g.
  373. disassembling Infocom-written interpreters, and going through all existing
  374. game files) I shall try to give all three specifications.  (Inform
  375. assembly-language programmers will need to bear in mind that it is the third
  376. that really counts.)
  377.  
  378. For the standard format (version 3) there are many existing games and there
  379. isn't much conflict.  But for later versions, there are few games, not all
  380. the opcodes were ever used and the interpreters publically available
  381. disagree about what to do with some of the obscure ones.  To some extent
  382. this account is an attempt to settle arguments.
  383.  
  384. Finally, note that the Z-machine does not provide the bulk of a game's
  385. parser, or its `operating system'.  The parser has to be coded, and the
  386. tables it uses (which some investigators think are part of the Z-code
  387. format) are in fact the same across different Infocom games only because
  388. they contain similar parsers.  So those are not specified here.  An account
  389. of the parsing tables as generated by Inform can be found in the {\sl Inform
  390. Technical Manual}.  For the usual format of Infocom's parsing tables, see
  391. the C source code to Mark Howell's utility ``Infodump''.
  392.  
  393. \medskip
  394.  
  395. Hexadecimal numbers are written with an initial dollar, as in |$ff|, while
  396. binary numbers are written with a double-dollar as in |$$11011|, according
  397. to Inform conventions.  The bits in a byte are numbered 0 to 7, 0 being
  398. the least significant and the top bit, 7, the most.
  399.  
  400. \medskip
  401. \hbox to\hsize{\hfill\it Graham Nelson}
  402. \hbox to\hsize{\hfill\it Magdalen College, Oxford}
  403. \hbox to\hsize{\hfill\it September 1994}
  404. \vfill\eject
  405.  
  406. \section{2}{Resources available}
  407.  
  408. \quote
  409. ...the dead hand of the academy had yet to stifle the unbridled
  410. enthusiasms of a small band of amateurs in Europe and America.
  411. \poemby{Michael D. Coe}{Breaking the Maya Code}
  412.  
  413. (This document representing the dead hand of the academy.)
  414.  
  415. The four publically available {\bf interpreters} that I know of are:
  416. \item{$\bullet$} ``Zip'', the fastest and most accurate, which is currently
  417. being updated to interpret even version 6;
  418. \item{$\bullet$} ``InfoTaskForce'' (henceforth ITF), which is almost as good
  419. for most purposes but slightly inaccurate in some screen-handling matters
  420. and does not provide the necessary features for ``undo'' in Version 5 games;
  421. \item{$\bullet$} ``Pinfocom'', which is competent on version 3 games but
  422. unable to cope with higher versions;
  423. \item{$\bullet$} ``Zterp'', similarly primitive.
  424. \medskip
  425.  
  426. Bryan Scattergood has made a considerable enhancement of ITF for his
  427. Psion and Archimedes interpreters.  However, the ITF no longer seems to
  428. exist as such.
  429.  
  430. The only existing {\bf compiler} is Inform, since Zilch no longer exists.
  431.  
  432. Mark Howell's toolkit of utility programs includes a {\bf disassembler}
  433. called ``txd'' and a {\bf vocabulary dumper} called ``infodump'', together
  434. with other less generally useful programs.
  435.  
  436. An enhanced version of Zip which will be a source-level {\bf debugger} for
  437. Inform games, called Infix, will soon be available.
  438.  
  439. The {\bf Infocom story files} are, with a few exceptions (the samplers)
  440. copyright and are currently being sold by Activision in the collections
  441. `The Lost Treasures of Infocom'.  They represent excellent value for
  442. money.  They should not be present at any archive site, and if they
  443. are then this is so illegally.
  444.  
  445. A few other {\bf story files}, such as `Curses' and `Advent', are freely
  446. available.
  447. \medskip
  448.  
  449. Most of the above programs have publically available source code (in C)
  450. and many have executables as well; the |if-archive| at the anonymous
  451. ftp site |ftp.gmd.de| is the best place to find them.
  452.  
  453. A curse of these programs is that they almost all use different names for
  454. the opcodes internally (that is, in their source code).  Mark Howell and
  455. I (as authors of the disassembler and assembler, respectively) have agreed
  456. on what we think is a reasonable standard, and these are the opcode names
  457. documented here.  They are used from Inform 5.4 and in recent editions of
  458. txd.
  459.  
  460.  
  461. \section{3}{History and the six versions}
  462.  
  463. \quote
  464. Confusion now hath made his masterpiece
  465. \poemby{Shakespeare}{Macbeth}
  466.  
  467. There were six main versions of the Z-machine, and several minor variant
  468. forms.  These are recognisably similar but with labyrinthine differences,
  469. like different archaic dialects of the same language.  (And, of course, the
  470. job of decipherment is made harder by the fact that the archaeological
  471. record suddenly stops in about 1989 when the civilisation in question
  472. collapsed.)
  473.  
  474. Broadly, these fall into two groups: early (versions 1 to 3) and late
  475. (4 to 6).  This paper will give an expository account of versions 3 and 5
  476. (as representative of these two groups) but will conclude with brief tables
  477. and specification for all versions.
  478.  
  479. The six versions are:
  480. \smallskip
  481. \settabs\+\indent Version 1\quad&\cr
  482. \+ Version 1 & Early Apple ][ games for DOS 3.2, and the TRS-80 Models I/II\cr
  483. \+ Version 2 & Early Apple ][ games for DOS 3.3, and the TRS-80 Models I/II\cr
  484. \smallskip
  485. \+ Version 3 & ``Standard'' series games\cr
  486. \+ Version 4 & ``Plus'' series games\cr
  487. \+ Version 5 & ``Advanced" series games, or, as the marketing division would\cr
  488. \+           & have it, ``Solid Gold Interactive Fiction" - a reference to\cr
  489. \+           & the colour (though not composition) of the boxes they came in\cr
  490. \smallskip
  491. \+ Version 6 & Later games with graphics, mouse support, sound effects, etc.\cr
  492. \smallskip
  493. \noindent 
  494. Infocom called their own interpreters ZIP (versions 1 to 3), EZIP/LZIP
  495. (V4), XZIP (V5) and YZIP (V6).
  496.  
  497. Versions 1 and 2 are thought to be extinct, though collectors have a few
  498. fossils and Zip and ITF implement them anyway.  Many Version 3 games are
  499. still in circulation, and enough worthwhile Version 4 and 5 ones to make
  500. the format important.
  501.  
  502. Most of the Infocom games exist in several different releases, and some
  503. were written for one version and then ported to later ones.  `Zork I', for
  504. instance, exists in at least ten editions, two early, seven in version-3
  505. (with release numbers between 5 to 88 in chronological order) and one in
  506. version 5 (release 52 - the releases go back to 1 when the version changes).
  507.  
  508. There are few version 6 games, and they are of (arguably) poorer quality.
  509. Few interpreters exist for them, because they are inherently difficult to
  510. port to different machines.  However, there will be a brief discussion of
  511. the version-6 format here and in effect a full specification in the
  512. dictionary which follows the opcode table.
  513.  
  514. The definitive guide to all Infocom story files known to exist is Paul David
  515. Doherty's ``fact sheet'' file, which can be found at |ftp.gmd.de|.
  516. \bigskip
  517.  
  518. The Z-machine as originally constructed was surprisingly similar to that
  519. in use when Infocom ground to a halt.  Version 1 (1979-80) had essentially
  520. the same object format, for instance, and a similar header, but encoded text
  521. with a different character table and had no concept of synonyms.  Its
  522. addresses were all word-addresses and not byte-addresses, so presumably a
  523. small amount of memory was wasted in null bytes to fix parities everywhere.
  524.  
  525. Version 2 was quite a minor enhancement, presumably made only because a new
  526. interpreter had to be written anyway.  Synonyms appeared, but only in one
  527. 32-word bank, and the six-digit serial number appeared in the header,
  528. though it wasn't always the date in those days: Release 7 of `Zork II',
  529. for instance, is (reputedly) called |UG3AU5|.
  530.  
  531. Version 3 changed the text encoding alphabets again, and tripled the number
  532. of synonyms possible.  (Consequently the previous ``caps lock" style
  533. permanent changes of alphabet were dropped.)  The ``verify" code and verify
  534. checksums appeared; and a new opcode to print the status bar at the top of
  535. the screen was introduced.  (Previously, this was updated only when input
  536. was taken from the keyboard.)  The earliest Version-3 releases (`Deadline',
  537. then `Zork I' and `II') were in March and April 1982; the latest (the
  538. `Minizork', a cassette-based Commodore-64 sampler of `Zork') in November
  539. 1987.
  540.  
  541. A primitive form of screen-splitting (which, presumably, was devised in a
  542. hurry in 1984 and then accidentally became the foundation for the character
  543. graphics designs of later versions) was allowed by some interpreters, in
  544. order to give `Seastalker' a sonar display.  In order that `Seastalker'
  545. should run on less enlightened interpreters, the game itself contained code
  546. to check whether this feature was available before using the opcodes.
  547. And `The Lurking Horror' (1987) has sound effects (on some machines) - another
  548. sign of things to come.
  549.  
  550. Nevertheless by 1982 the Z-machine had stabilised to a reasonably clean
  551. design.  It was very portable, contained everything reasonably necessary and
  552. most of its complications were optimisations to squeeze a few more bytes out
  553. of the 100K or so available on an early-1980s floppy disc.  (Actually the
  554. Zilch's code generator, although very good at exploiting these tricks, had
  555. little larger-scale optimisation, and some of its code makes disheartening
  556. reading.  But then the same could be said of Inform.)
  557. \medskip
  558.  
  559. By 1985 there were two basic pressures to change.  One was that home
  560. computers were larger, and several fundamental restrictions (the game size
  561. being only 128K, the number of objects only 255, the attributes only 32,
  562. the properties only 30) were beginning to bite.  The other was the drive for
  563. more gimmicks - character graphics, flashier status bars, sound effects,
  564. different typefaces, and so on.  The former led to logical, easy to
  565. understand structural changes in the machine.  The latter, in contrast, made
  566. a mess of the system of opcodes.
  567.  
  568. More does not mean better: just because the price of paper falls is no
  569. reason to double the size of the modern novel, for instance.  Nor is
  570. literature (pace e. e. cummings) much improved by using four different
  571. typefaces and illustrating it with typewriter pictures.  Also, the relieving
  572. of size restrictions only increased design time - or lowered its quality.
  573.  
  574. Nonetheless, two excellent games resulted from the lifting of size
  575. restrictions.  In August 1985 the first version-4 game (`A Mind Forever
  576. Voyaging') reached production, and it was followed most notably by
  577. `Trinity' (which had previously been shelved as too ambitious for the
  578. version-3 format).  Still, most of the new 1985/6 games remained in
  579. version-3: after all, there were still plenty of 8-bit home computers
  580. around, too small for version-4 games: and, despite critical acclaim,
  581. the new games consequently did not sell as well.
  582.  
  583. Version 5 games began to appear in September 1987 with `Beyond Zork' and
  584. `Border Zone'.  Both of these games needed new features - character graphics
  585. gone wild in the case of the former, and real-time keyboard interaction in
  586. the latter.  The number of opcodes grew ever faster as a result. 
  587.  
  588. Although five old games were re-released in Version 5 editions (with an
  589. in-game hints system added, and benefiting from 9-letter word dictionaries,
  590. but otherwise as written), the direction was all too clearly away from
  591. the old text game into graphics.  Having gradually moved this way (`Beyond
  592. Zork' can look like a parody of an early mainframe maze game, for instance)
  593. there was nothing left but to complete the process, and so Version 6 was
  594. born.  After something of a hiatus in 1988, the last few
  595. increasingly-unrecognisable Infocom games appeared: `Zork Zero', `Shogun',
  596. `Journey', `Arthur'.
  597.  
  598. Infocom gradually ceased to exist during 1987-9 for financial reasons
  599. generally said to be unrelated to their games output.  Whether they would
  600. have continued to release text games of the classical style is arguable.
  601.  
  602. \section{4}{How text is encoded}
  603.  
  604. \quote
  605.     This technique is similar to the five-bit Baudot code, which
  606.     was used by early Teletypes before ASCII was invented.
  607. \endquote
  608. \quote Marc S. Blank and S. W. Galley, {\sl How to Fit a Large Program
  609. Into a Small Machine}
  610. \endquote
  611.  
  612. Text is stored as a sequence of 2-byte words.  Each of these is divided into
  613. three 5-bit pieces, plus 1 bit left over, arranged as
  614. \begintt
  615.    --first byte-------   --second byte---
  616.    7    6 5 4 3 2  1 0   7 6 5  4 3 2 1 0 
  617.    bit  --first--  --second---  --third--
  618. \endtt
  619. The bit is set only on the last 2-byte word of the text, and so marks the
  620. end.
  621.  
  622. These pieces are called `Z-characters' and have values in the range 0 to 31.
  623.  
  624. There are three alphabets, in which the numbers 6 to 31 mean:
  625. \begintt
  626.   A0     abcdefghijklmnopqrstuvwxyz
  627.   A1     ABCDEFGHIJKLMNOPQRSTUVWXYZ
  628.   A2      ^0123456789.,!?_#'"/\-:()
  629. \endtt
  630. (Here the new-line character is written as a circumflex |^|).
  631.  
  632. Character 0 is a space in all alphabets.  Characters 1, 2 and 3 are used for
  633. abbreviations: thus, 1 followed by 14 means ``print entry 14 in the synonym
  634. table"; 2 followed by 5 means ``print entry 32+5=37..."; 3 followed by 20
  635. means ``print entry 64+20=84..." and so on.
  636.  
  637. The Z-machine provides these for commonly occurring strings to be printed
  638. out as if they were characters, thus saving memory.  Though they are
  639. actually abbreviations, by accident of history they have come to be called
  640. `synonyms'.  (Well chosen synonyms tend to make about a 10\% space saving.)
  641.  
  642. By default, a character is presumed to be in A0, i.e. to be a lower-case
  643. English letter.  However, the character 4 means that the next one (only) is
  644. in A1; and 5 means the next is in A2.
  645.  
  646. (Note for purists: actually the full rule is
  647. \begintt
  648.             A0      A1      A2
  649.     4       [A1->]  [A1->]  [A0->]
  650.     5       [A2->]  [A0->]  [A2->]
  651. \endtt
  652. but since alphabet changes are (in versions 3 and onward) not permanent,
  653. it seems pointless ever to use 4 and 5 in alphabets 1 and 2.)
  654.  
  655. Notice that character 6 in A2 is blank.  It isn't a space: it simply isn't
  656. there.  The sequence 5 followed by 6 indicates that the next two characters
  657. define an ASCII value.  This is the way to get at the characters not in any
  658. of the three alphabets.  For example, the familiar message
  659. \begintt
  660.   *** You are dead ***
  661. \endtt
  662. takes four Z-characters to produce each of the asterisks.
  663.  
  664. Finally, note that the end-bit only comes up once every three characters,
  665. so that a way is needed to safely use up any spare characters in the last
  666. 2-byte block.  This is done by padding out with 5's.  (5 followed by 5 does
  667. nothing.)
  668.  
  669. This is especially the case with dictionary entries.  Some dictionary
  670. entries, like ``i", ought only to take one 2-byte block, but in order to make
  671. all entries the same number of 2-byte blocks long and so alphabetically
  672. sortable by number, they are padded out by as many 5's in a row as needed
  673. (possibly as many as eight of them).  Dictionary entries are not permitted
  674. to use synonyms and their letters are in lower case (though they can
  675. contain characters from A2).
  676.  
  677. In practice the text compression factor is not really very good: for
  678. instance, 155000 characters of text squashes into 99000 bytes.  (Text
  679. usually accounts for about 75\% of a story file.)  But the encoding does
  680. at least encrypt the text so that casual browsers can't read it.
  681. \medskip
  682.  
  683. Footnotes: 1. The versions 1 and 2 formats are slightly different: see
  684. below.
  685.  
  686. 2. In versions 5 and 6, the three alphabet blocks need not be the
  687. default ones A0 to A2 tabulated above, but instead can be chosen by the
  688. story file itself by means of an entry in the game's header.
  689.  
  690. 3. In version 6, it is expected that the ASCII codes for tab (9) and
  691. control-K (11) are printed slightly differently: a tab at the start of a
  692. line should be a paragraph indentation suitable for the font being used, but
  693. anywhere in the middle of a line should be a space; and 11 should be
  694. rendered as a gap between two sentences.
  695.  
  696.  
  697. \section{5}{How instructions are encoded}
  698.  
  699. \widepoem
  700. We do but teach bloody instructions
  701. Which, being taught, return to plague th' inventor
  702. \poemby{Shakespeare}{Macbeth}
  703.  
  704. This account is to be read in conjunction with the opcode table and
  705. dictionary, so it does not tabulate or individually discuss opcodes.
  706. Experimenting with Inform as an assembler, while tracing is turned on, may
  707. be helpful.
  708.  
  709. Except for the printing instructions |print| and |print_ret|, which are
  710. simply opcodes followed by an encrypted string, an instruction consists of
  711. the following:
  712. \begintt
  713.   Opcode               1 byte (possibly 2 in versions 5-6)
  714.   (Types of operands)  1 byte; only for VAR form opcodes
  715.   Operands             Between 0 and 4, each taking 1-2 bytes
  716.   (Store)              1 byte; variable to store a result
  717.   (Branch)             1-2 bytes; offset to branch to
  718. \endtt
  719. (not all opcodes take ``store'' or ``branch''; a few take both).
  720.  
  721. \subtitle{Operands}
  722.  
  723. Z-code understands four kinds of operand, and describes these in 2-bit
  724. fields:
  725. \begintt
  726.   $$00    Large constant (>=256 or <0)   2 bytes
  727.   $$01    Small constant (0 to 255)      1 byte
  728.   $$10    Variable                       1 byte
  729.   $$11    Omitted altogether             0 bytes
  730. \endtt
  731. Variables are described in one byte.  |$00| means the top of the stack,
  732. |$01| to |$0f| are the local variables of the current routine and |$10| to
  733. |$ff| are the global variables, 0 to 239.  Writing to the stack pointer,
  734. or variable |$00|, pushes something onto the stack; and reading from it
  735. pulls it off.  The stack can also be manipulated with the use of opcodes.
  736. The stack is guaranteed to be at least 512 bytes long, and some interpreters
  737. are more generous.  There isn't any way for a Z-code program to check stack
  738. overflowing, so recursion requires care.
  739.  
  740. \subtitle{Opcodes}
  741.  
  742. In versions 1 to 4, Z-code opcodes are 1 byte only.  To begin with, look at
  743. the top two bits.  If these are |$$11|, we shall call it ``variable"; if
  744. |$$10|, ``short" (0OP or 1OP, i.e. 0 or 1 operands); and otherwise ``long"
  745. (2OP: 2 operands).  In versions 5 and 6, there are also ``extended", EXT,
  746. opcodes two bytes long.
  747. \medskip
  748.  
  749. For short opcodes, look at the next two bits (4 and 5).  These give the kind
  750. of operand which the code has.  If this is |$11|, there isn't an operand and
  751. the opcode has no argument at all.  In this event, the opcode number is the
  752. bottom 4 bits (see table of 0OP opcodes).
  753.  
  754. If the type wasn't |$11|, then an operand follows of the given type (large
  755. constant, small constant or variable), and the bottom four bits gives the
  756. opcode number (see table of 1OP opcodes).
  757. \medskip
  758.  
  759. Long opcodes have two operands.  The bottom 5 bits of the opcode say what
  760. it is (see table of 2OP opcodes).
  761.  
  762. The alert reader will notice that this only leaves bits 5 and 6 spare to
  763. hold the operand types.  As there are two operands to specify, this ought
  764. to take up 4 bits, which obviously won't fit.  So a more economical form is
  765. used instead.  Bit 6 refers to the first operand, and bit 5 to the second.
  766. A value of 0 means a small constant and 1 means a variable.  Now, type |$11|
  767. (not really there) operands can't happen, so that's no problem, but there
  768. might well be type |$00| (large constant) operands, for example in assembling
  769. \begintt
  770. @mul x #666 sp;
  771. \endtt
  772. In this event, the opcode must instead be assembled as a ``variable" opcode.
  773. \medskip
  774.  
  775. So we must now describe the ``variable" or VAR opcode form.  In addition to
  776. the possible opcodes which can arise from overflowing ``long" opcodes, there
  777. are others which can only be ``variable".  In the former case bit 6 is clear
  778. and in the latter it is set.  In either case the bottom 5 bits contain the
  779. opcode number: see the 2OP or VAR tables accordingly.
  780.  
  781. Some of these are only of ``variable" type because the available codes for
  782. the other types had run out; |print_char|, for instance.  Others, especially
  783. |call|, need the flexibility to have between 1 and 4 operands.
  784.  
  785. In the ``variable" type opcode, all eight bits of the opcode have been used
  786. up, so we have to add another byte describing the operands.  This is divided
  787. into four 2-bit fields.  For example, |$$00101111| means large constant
  788. followed by variable (and no third or fourth opcode).
  789.  
  790. Once the opcode is out of the way, the operands are simply stored in one or
  791. two-byte form as appropriate.
  792.  
  793. \subtitle{Numbers and addresses}
  794.  
  795. These are two-byte words, stored in the order high-byte then
  796. low-byte.  The top bit is treated as the sign when needed
  797. (e.g. for numerical comparisons) and not otherwise (e.g. for addresses).
  798.  
  799. When holding an address such a number can be a byte address, which puts
  800. it necessarily in the bottom 64K of the memory map, or a packed address.
  801. Routines and static strings will be at addresses in memory which can be
  802. pointed to by packed addresses.  Given a packed address $p$, the formula
  803. to obtain the corresponding `real address' in bytes is:
  804. $$ b = \cases{ 2p & versions 1-3\cr
  805.                4p & versions 4-5\cr
  806.                8p+o & version 6\cr} $$
  807. where the offset $o$ in Version 6 is given in the game header (this can
  808. be used to stretch the memory map another 64K or so beyond the apparent
  809. 512K limit).
  810.  
  811. \subtitle{Strings, stores, branches}
  812.  
  813. |print| and |print_ret| are followed by text: this is assembled in the usual
  814. way immediately after the opcode (which may well be at an odd address, but
  815. this doesn't matter) and execution resumes after the last 2-byte word of text
  816. (the one with top bit set).
  817.  
  818. ``Store" opcodes return a value: for example, |mul| multiplies its two
  819. arguments together, and |call| calls a routine which must return a value.  Such
  820. instructions are followed by a single byte giving the variable (stack
  821. pointer, local or global as usual) to put it in.  This may look like an extra
  822. operand but is not: there is no need to tell the Z-machine what type it has,
  823. since it must be a variable.
  824.  
  825. Finally, there are instructions which test a condition.  More opcodes than
  826. just the obvious branch instructions do this; e.g. |save| does so (in
  827. version 3), the test in question being whether or not the save was
  828. successful.  Branches are stored in two different ways for economy reasons:
  829. nearby ones in a single byte at the end of the instruction, farther ones
  830. in two such bytes.
  831.  
  832. The top bit of the first byte of a branch is the ``flag".  If this is clear,
  833. then a branch occurs when the condition came out false.  If it is set, then
  834. the branch occurs when it was true.
  835.  
  836. If the next bit (bit 6) is set, then the branch is in abbreviated 1-byte
  837. format and the offset is in the bottom 6 bits (0 to 5).  If not, the offset
  838. is in the bottom 14 bits (0 to 5 of the first byte, and all of the second).
  839. This offset can be positive or negative.  (E.g., all 1's means -1 in the
  840. usual way.)
  841.  
  842. In the abbreviated form, an offset of 1 in fact means ``return true from the
  843. current routine" and an offset of |$20| (i.e., -31) means ``return false".  An
  844. offset of 1 is never useful but -31 might arise, and so it is essential to
  845. use the long form for such branches.
  846.  
  847. Working out what the offset ought to be is more complicated than it appears
  848. because the PC has already moved on from the start of the instruction when
  849. it reaches the branch.  The bizarre formula in question is
  850. \beginstt
  851.   Offset = Destination address - Address of this instruction - Length + B
  852. \endtt
  853. where
  854. \beginstt
  855.   Length = number of bytes in instruction (not counting the branch)
  856. \endtt
  857. and |B| is 1 for short branches, 0 for long ones.
  858.  
  859. (For its own code Inform compiles branches in the long form, considering the
  860. economy to be not worth the nightmarish computation needed to make the
  861. long/short decision.  (One problem is that the number of bytes in each
  862. instruction must be the same in both passes, so that the decision needs to
  863. be made before the value of the offset is known... in a 2-pass compiler this
  864. is insoluble.  Another is that the offsets are affected by the size of the
  865. branch, confusing matters on forward branches.)  However, its assembler
  866. mode allows you to make an explicit choice.)
  867.  
  868. |jump| instructions similarly encode their address operand as an offset, but
  869. always as a two-byte (signed) constant.
  870.  
  871. A few instructions both store results and branch: if so, the store comes
  872. first.
  873.  
  874.  
  875. \subtitle{Extended set of opcodes}
  876.  
  877. The extended (or EXT) set only applies in versions 5 and 6.  These are two
  878. byte opcodes, of which the first byte is always 190, the second the opcode
  879. number.  Subsequently, they behave exactly as VAR...
  880.  
  881. ...except that, actually, two of them don't.  Two of them, |call_vs2| and
  882. |call_vn2|, have up to 8 operands and so have two bytes of type information
  883. instead of one.  (These are provided for calling functions with up to 7
  884. arguments instead of only 3, the limit in earlier versions.)
  885.  
  886. (Inform's assembler is unable to use these two opcodes.)
  887.  
  888.  
  889. \section{6}{The early Z-machine}
  890.  
  891. Since the majority of extant Infocom story files use it, this section talks
  892. about version 3 unless otherwise stated.  The following section will indicate
  893. how the late Z-machine differs.
  894.  
  895. The early Z-machine has a memory map at most 128K long.
  896. \topinsert
  897. \centerline{\sl An example memory map of a small game (produced by Inform)}
  898. \medskip
  899. $$ \vbox{\offinterlineskip
  900. \hrule
  901. \halign{\vrule#&\strut\quad{\it #}\hfil\quad&\hfil # \quad&%
  902. \vrule#&\strut\quad\hfil#\hfil\quad&\vrule#\cr
  903. height2pt&\omit&\omit&&\omit&\cr
  904. && Start && Contains &\cr
  905. height2pt&\omit&\omit&&\omit&\cr
  906. \noalign{\hrule}
  907. height2pt&\omit&\omit&&\omit&\cr
  908. & Dynamic& |00000| && header &\cr
  909. &        & |00040| && synonym strings &\cr
  910. &        & |00042| && synonym table &\cr
  911. &        & |00102| && property defaults &\cr
  912. &        & |00140| && objects &\cr
  913. &        & |002f0| && object descriptions &\cr
  914. &        &         && and properties &\cr
  915. &        & |006e3| && global variables &\cr
  916. &        & |008c3| && arrays &\cr
  917. & Static & |00b48| && grammar table &\cr
  918. &        & |010a7| && actions table &\cr
  919. &        & |01153| && preactions table &\cr
  920. &        & |01201| && adjectives table &\cr
  921. &        & |0124d| && dictionary &\cr
  922. & Paged  & |01a0a| && Z-code &\cr
  923. &        & |05d56| && static strings &\cr
  924. &        & |06ae6| && end of file &\cr
  925. height2pt&\omit&\omit&&\omit&\cr
  926. }\hrule}$$
  927. \endinsert
  928.  
  929. \subtitle{The Header}
  930.  
  931. The first 64 bytes contain a header, to be detailed fully later.  It
  932. contains (mainly) addresses of other tables and flags, and is both a
  933. vehicle for the game to tell the interpreter what to do, and for the
  934. interpreter to tell the game what it can do.
  935.  
  936. To briefly run through the essential points of the version-3 header:
  937. the first 4 bytes are
  938. \begintt
  939.       03  <Flags>  <Release Number>
  940.                    ----2 bytes-----
  941. \endtt
  942. (The first byte is the version number.)
  943. Next come seven word addresses, at words 2 to 8:
  944. \begintt
  945. 2     <Start of Routines>    Where routines begin, in bytes
  946. \endtt
  947. Actually, in some games, read-only data seems to continue here: this
  948. pointer actually tells the interpreter where the ``resident" data ends,
  949. i.e. the part of the game which is kept in memory at all times rather
  950. than loaded off disc as and when required.  (Of course modern interpreters
  951. should almost certainly not be swapping pages from the disc anyway, now
  952. that 128K is no longer a scandalous amount of memory.)
  953. \begintt
  954. 3     <Main Routine>         Address of main routine, in bytes, +1
  955. \endtt
  956. (This +1 is why the Main routine cannot have local variables - it is a
  957. peculiarity of the standard.  Note also that this is uniquely a routine
  958. address in bytes and not a packed address: Main must occur in the lower 64K
  959. of the file.  Inform always sets word 3 to be word 2, plus 1, because it
  960. requires Main to be the first routine defined.)
  961. \begintt
  962. 4     <Dictionary>           The dictionary table address, in bytes
  963. 5     <Object tree>          Object table address, in bytes
  964. 6     <Variables>            Global variables address, in bytes
  965. 7     <Save area size>       The total number of bytes in a saved game
  966. \endtt
  967. Saving the game is done by saving this many bytes from the beginning of the
  968. machine.  (Saved games also contain the current state of the Z-machine
  969. stack; the stack is {\sl not} stored anywhere in the Z-machine's memory.)
  970. \begintt
  971. 8     <More flags>
  972. \endtt
  973. This is followed by the six bytes from byte 18 to 23, which are the version
  974. number string.  (By custom these hold the compilation date in the form
  975. YYMMDD.)  Then more words:
  976. \begintt
  977. 12    <Synonyms table>       Synonym table address in bytes
  978. 13    <Length>               Length of file, in words
  979. 14    <Checksum>             Sum of bytes from 64 upwards, mod $10000
  980. \endtt
  981. The length and checksum are needed to perform ``verify", something which
  982. most games only do when explicitly asked.
  983.  
  984. \subtitle{Synonyms}
  985.  
  986. We are now at byte address |$0040| and by convention we reach the synonyms.
  987. Usually, the actual strings (the expansions of the synonyms) are stored
  988. here, one after another, making up 96 strings.  When that is out of the way,
  989. the actual table begins (and this is what the synonyms address points to).
  990. The table contains 96 word addresses in sequence.
  991.  
  992. Note: extremely annoyingly (from the point of view of the compiler writer),
  993. these are word addresses and not packed addresses: thus a synonym string
  994. must lie in the bottom 128K of memory.  (Inform has to go to a considerable
  995. amount of extra trouble because of this.)  Of course in the original design
  996. synonym strings had to be resident (hence low in memory) anyway for speed
  997. reasons.
  998.  
  999. \subtitle{Object Table}
  1000.  
  1001. Next is the object table.  In fact it begins with what is sometimes called
  1002. the ``global properties table", though it is actually a table of default
  1003. values of properties.  This is a list of 31 2-byte numbers.  There is no
  1004. property 0, so the first word is always |0000|.  (Recall that there are
  1005. 30 properties in versions 1 to 3.)
  1006.  
  1007. After these 62 bytes, the objects begin, beginning from object 1.  An object
  1008. entry consists of 9 bytes, looking like:
  1009. \beginstt
  1010.    <the 32 attribute flags>   <parent>  <sibling>  <child>  <properties>
  1011.    ---32 bits in 4 bytes---   ---3 bytes------------------  ---2 bytes--
  1012. \endtt
  1013. The three parent-sibling-child bytes are |00| when the object pointed to is
  1014. ``nothing".  The |properties| pointer is the byte address of the list of
  1015. properties attached to the given object.
  1016.  
  1017. When all these 9-byte entries are out of the way, the property lists
  1018. begin.  (Inform keeps these in the same order as the objects they are
  1019. attached to but the specification does not require this.)  An individual
  1020. property table has the brief header
  1021. \beginstt
  1022.   <text-length>   <text of short name of object>
  1023.   -----byte----   --some even number of bytes---
  1024. \endtt
  1025. (where the |text-length| is the number of 2-byte words making up the text,
  1026. which is stored in the usual format).
  1027.  
  1028. Then the properties held are listed, in descending numerical order.  (This
  1029. order is essential.)  An individual property is stored as
  1030. \beginstt
  1031.   <size byte>   <the actual property data>
  1032.                 ---between 1 and 8 bytes--
  1033. \endtt
  1034. The |size byte| is arranged as 32 times the number of data bytes, plus the
  1035. property number.
  1036. Each list of properties is ended by a |00| size byte.  This is why there is no
  1037. property 0.
  1038.  
  1039.  
  1040. \subtitle{Global variables}
  1041.  
  1042. When all the property tables are done, we come to the global variable table.
  1043. Global variables are numbered from 0 to 239, and this table begins with 240
  1044. initial 2-byte values for them.  After this is conventionally left space for
  1045. all the arrays, dynamic strings and so on which they point to.
  1046. \medskip
  1047.  
  1048. We have now reached the top of the save area.  Everything higher in memory
  1049. than here is never altered (and not saved when the game is saved, hence
  1050. the name).
  1051.  
  1052.  
  1053. \subtitle{Grammar and parsing tables}
  1054.  
  1055. Next is the table of grammar, an actions table, a preactions table and then
  1056. an adjectives table.  Note that this is not a part of the specification at
  1057. all, and the Z-machine knows nothing about these tables.  The old Infocom
  1058. files have certain standards about their formats because they used roughly
  1059. similar parsers; Inform follows these conventions to some extent (see the
  1060. {\sl Inform Technical Manual} for the formats it writes here).
  1061.  
  1062.  
  1063. \subtitle{The dictionary}
  1064.  
  1065. And next the dictionary table, which has the following short header:
  1066. \beginstt
  1067.   n    <list of ASCII codes>  entry-length  number-of-entries
  1068.  byte  ------n bytes--------      byte         2-byte word
  1069. \endtt
  1070. The codes listed are word-separators: typically (and under Inform
  1071. mandatorily) these are
  1072. \begintt
  1073.    .   ,   "
  1074. \endtt
  1075. A space character (32) does not appear because these characters will not
  1076. only divide words but also come out as words in their own right: thus,
  1077. \begintt
  1078.   > fred,go
  1079. \endtt
  1080. will be lexically analysed as three words:
  1081. \begintt
  1082. "fred"  ","  "go"
  1083. \endtt
  1084. Each word entry has 4 bytes of text (i.e. 6 Z-characters, padded out
  1085. with as many ``pad'' characters, that is 5s, as necessary), and
  1086. then a few extra bytes of data: almost invariably (and under Inform
  1087. mandatorily) three.
  1088.  
  1089. Dictionary entries appear in alphabetical order (precisely, this means
  1090. in numerical order, regarding the first 4 bytes as an unsigned
  1091. integer).  They use only alphabets A0 and A2 (i.e., they don't use
  1092. upper case letters).
  1093.  
  1094. The contents of the data bytes are not specified by the Z-machine,
  1095. which never does anything with them.  (See the {\sl Inform Technical
  1096. Manual} for what Inform does with them.)
  1097.  
  1098.  
  1099. \subtitle{The code area and static strings}
  1100.  
  1101. Next is the code area.  (In fact some Infocom games, though no Inform
  1102. ones, put some static data next before the code begins.)  
  1103. The code area simply contains a list of routines; the specification
  1104. does not require the first routine to be the `main routine', and indeed
  1105. it is not in some existing files (though it always is under Inform).
  1106.  
  1107. All routines (and static strings) must occur at addresses which can
  1108. be packed addresses (meaning, at even byte addresses in Version 3).
  1109. The bytes sometimes left over in between them are unspecified (but under
  1110. Inform, always 0).
  1111.  
  1112. A routine begins with one byte indicating the number of local variables the
  1113. routine has (from 0 to 15), and then with that many 2-byte numbers giving
  1114. their initial values.  When a function call takes place, the arguments --
  1115. however many there are -- are written into the first few local variables,
  1116. over-riding the default values here.  Unlike global variables, these bytes
  1117. are not used for the current values of the variables: they are kept on
  1118. the stack.
  1119.  
  1120. (Inform never makes use of these initialisation numbers, and simply stores
  1121. zeros.) 
  1122.  
  1123. Executable code follows this header.  There is no special marker for the end
  1124. of a routine; it is simply expected that in every case a legal return
  1125. instruction will be hit.
  1126.  
  1127. Finally, from the end of the code to the top of memory are the static
  1128. strings.  These are put up here to be out of the way, where they won't clog
  1129. up the bottom 64K of memory.  There's no table of their addresses, or pointer
  1130. to where they begin; each is referred to by a packed address in code or
  1131. data given earlier.
  1132.  
  1133.  
  1134. \section{7}{The late Z-machine}
  1135.  
  1136. \subtitle{Versions 4 and 5: Architecture}
  1137.  
  1138.  
  1139. The bulk of this section is given over to a detailed discussion of the
  1140. differences between version 3 and version 5, since those are the two forms
  1141. Inform can produce.  (Version 4 is nearer to version 5 than 3.)  We
  1142. begin with the architecture.
  1143.  
  1144. The memory map doubles to 256K, a change which is surprisingly easy to make. 
  1145. But the processor remains 16-bit, so packed addresses are now multiples of
  1146. 4.  However, this only really affects addresses of routines and static
  1147. strings (which are now aligned to longword boundaries, not word-boundaries).
  1148.  
  1149. As mentioned in \S 6, an annoying exception is that the synonyms table
  1150. contains word addresses still, and so assumes that the synonym strings lie
  1151. in the lower 128K.  This is understandable because the Z-machine used to
  1152. rely on virtual memory (swapping pages of memory on and off of disc), and
  1153. the synonyms need to be accessed at virtually all times: keeping them
  1154. together in low memory (just after |$0040|) is therefore efficient, and
  1155. giving them addresses divisible by four would waste bytes in the
  1156. save-game-area.
  1157.  
  1158. The only important change to the header, then, is that the length is in
  1159. longwords, being a packed address.
  1160.  
  1161. A minor new feature in Version 5 is that the game can change the alphabet
  1162. tables used for text decoding, putting a pointer to them in the header at
  1163. |$34-5|: this is usually left as |$0000|, meaning the default alphabets.  See
  1164. \S 10.  Also, it seems to be expected that the interpreter tells the game
  1165. the dimensions of the screen by writing them into the header itself, in
  1166. play. Thus it is fairly safe to consult
  1167. \begintt
  1168.   Byte 32 - Screen height
  1169.   Byte 33 - Screen width
  1170. \endtt
  1171. and it's hard to cope without this information, since games after Version 3
  1172. have to construct their own status lines.  (It isn't clear that the various
  1173. interpreters all understand the same thing by ``height" and ``width",
  1174. though.)
  1175.  
  1176. There is effectively no limit on the number of possible objects, since an
  1177. object number is no longer expected to fit into a single byte.  This has the
  1178. knock-on effect that in most games many properties will have to allow for a
  1179. word and not a byte (which is why Inform defaults property definitions as
  1180. |long| in version-5 mode), but the only architectural effect is that object
  1181. definitions grow in size.  Since the number of attributes is increased from
  1182. 32 to 48, and of properties from 30 to 62, this would be needed anyway: and
  1183. here is the new form:
  1184. \beginstt
  1185.    <the 48 attribute flags>   <parent>  <sibling>  <child>  <properties>
  1186.    ---48 bits in 6 bytes---   ---3 words, i.e. 6 bytes----  ---2 bytes--
  1187. \endtt
  1188. giving a 14-byte block.  As before, the properties field is the byte address
  1189. of the property table.
  1190.  
  1191. The property table is also altered.  A property is now stored as
  1192. \beginstt
  1193.   <size and number>     <the actual property data>
  1194.   --1 or 2 bytes---     --between 1 and 64 bytes--
  1195. \endtt
  1196. The property number now occupies the bottom 6 bits, not 5, of the first size
  1197. byte, which is why more properties are available.  But this only leaves two
  1198. bits.  If these are |$$00|, the size is taken as 1, and if |$$01|, then it
  1199. is taken as 2.  (These are the most common sizes in practice.)  Otherwise
  1200. the top bit is set, which means that the second byte is present, and
  1201. contains the size in its bottom six bits.
  1202.  
  1203. However, when present the second byte must also have the top bits set to
  1204. |$$10|.  The reason for this is that the size must be parsable either
  1205. forwards or backwards - the Z-machine needs to be able to reconstruct the
  1206. length of a property given only the address of the first byte of its data.
  1207.  
  1208. There are very many (e.g. 2000) property entries in a story file, so this
  1209. optimisation is probably worthwhile.
  1210. \medskip
  1211.  
  1212. The formats of the parsing tables are generally different in later
  1213. versions, but this isn't part of the Z-machine specification.
  1214.  
  1215. Whereas Version 3 games have dictionaries store words in 6 Z-characters,
  1216. all Version 4 and above games take 9 Z-characters.  (I.e., four and six
  1217. bytes of encoded text respectively.)  This increases the length of entries.
  1218. Otherwise, the specification is the same.
  1219.  
  1220. The extra resolution makes it reasonable to include hyphenated words, which
  1221. might not have been sensible earlier because of the number of five-bit
  1222. blocks they would have needed.
  1223.  
  1224. These modifications appear at first sight to make much larger, less
  1225. efficient code, but this is misleading.  The original version-3 `Curses' was
  1226. only 3\% larger when first compiled as version-5, and a good part of that
  1227. was the extra dictionary resolution.
  1228.  
  1229. There is one sensible structural change to the way actual code is written:
  1230. in Version 5 (not Version 4, though) the header of a function no longer
  1231. contains initialisation values for its local variables.  In practice these
  1232. were very often zero, wasting a large number of bytes across the whole story
  1233. file.  On the other hand, one peculiarity of the machine is that functions
  1234. can be called with 0, 1, 2 or 3 arguments, and routines in version-3 games
  1235. used to be able to put a default value in their headers for any argument not
  1236. supplied by the caller.  This they can no longer do, so that they are unable
  1237. to tell how many arguments actually were supplied: and so a new branch
  1238. instruction |check_arg_count| exists to test this.
  1239.  
  1240. Another improvement is in subroutine calls.  In Version 3 code, a |call|
  1241. instruction is always VAR and has a variable argument list, which wastes a
  1242. byte even when there are no parameters.  Also, every function call returns a
  1243. value, and in Version 3 this value had to be written somewhere even when it
  1244. wasn't wanted - wasting another byte.  (In fact Inform used to return this
  1245. to the stack, and then pop it from the stack - wasting another one. 
  1246. Nowadays it stores unwanted return values in a scratch global variable.)  In
  1247. Version 4 (and to a greater extent in Version 5), new forms of the |call|
  1248. instruction are provided which automatically throw away the return value.
  1249.  
  1250. This leads to the nightmarish position that there are eight variant forms of
  1251. |call| in the Version 5 machine.  Inform christens six of these as follows:
  1252. \beginstt
  1253.   call_vs  <address> <0 to 3 arguments> <place to put answer>
  1254. \endtt
  1255. (which is just as in version 3 |call|, and compatible with it),
  1256. \beginstt
  1257.   call_vn  <address> <0 to 3 arguments>
  1258. \endtt
  1259. which is the same but throws away the answer, and
  1260. \beginstt
  1261.   call_1n  <address>                   address();
  1262.   call_1s  <address> <answer>          answer=address();
  1263.   call_2n  <address> <a1>              address(a1);
  1264.   call_2s  <address> <a1> <answer>     answer=address(a1);
  1265. \endtt
  1266. Two of the others are called |call_vs2| and |call_vn2| by Inform: these are
  1267. provided for function calls with up to seven arguments, circumventing the
  1268. usual restriction on function calls to have at most three: and, uniquely,
  1269. they have two bytes of type bits, arranged as eight two-bit fields.  (Inform
  1270. does not compile these instructions, and does not make use of them when
  1271. coding function calls, because it would be extremely unportable to lower
  1272. versions.)  Note that the standard opcode name for all eight opcodes is
  1273. |call|, and this is what appears in disassembly, but that Inform uses these
  1274. eight names internally and for assembly.
  1275.  
  1276.  
  1277. \subtitle{Versions 4 and 5: Reliable extra features}
  1278.  
  1279.  
  1280. We now discuss those important extra features which can more or less be
  1281. relied upon to be safely interpreted.  Roughly speaking, don't rely on
  1282. interpreters other than Zip to correctly perform an opcode not actually used
  1283. in any existing Infocom game.
  1284.  
  1285. But we must begin with unfortunate clashes with version 3.  Chief among
  1286. these is |pop| which used simply to throw away the top of the stack.  In
  1287. version 5 no such instruction exists (there is less need for it anyway given
  1288. the new |n| form of the |call| opcodes).
  1289.  
  1290. Also, the |read| opcode (although it has the same basic form,
  1291. \beginstt
  1292.   read text_buffer parse_buffer;
  1293. \endtt
  1294. as before) does a subtly different job: it appends the result of parsing the
  1295. text to the |parse_buffer|, rather than over-writing the parse buffer.  It
  1296. also no longer prints any kind of status bar.  (To avoid confusion of the
  1297. syntax, Inform calls the version-3 opcode |sread| and the version-5 opcode
  1298. |aread|; and its higher-level command |read| translates into sensible code
  1299. for either.)
  1300.  
  1301. And since there is no longer any Z-machine ``status bar", the old opcode to
  1302. display it (|show_status|) disappears and in theory becomes illegal.
  1303.  
  1304. The |random| function now makes the random number generator predictable for
  1305. a while if given a negative argument (some version 3 games had a |#random|
  1306. opcode - so called because typing |#random| into the game made it happen).
  1307.  
  1308. Cutting and pasting bits of parse buffer is a common job for Z-code parsers,
  1309. and there are new opcodes to help with shuffling tables around.  One can
  1310. also (using |tokenise|) parse from any string, with any supplied dictionary
  1311. table (not necessarily the default one).  One may also |encode_text| to
  1312. Z-machine text format - which might be useful for constructing dictionary
  1313. entries at run-time.
  1314.  
  1315. A few opcodes have been moved around, irritatingly, and there have been
  1316. three casualties.  |not| has moved.  |save| and |restore| now appear in the
  1317. extended set, as a result of which they are no longer branch instructions
  1318. (presumably to avoid coping with branch offsets being different for extended
  1319. opcodes), and now take a less convenient syntax:
  1320. \beginstt
  1321.   save <variable>;
  1322.   restore <variable>;
  1323. \endtt
  1324. These put return codes in the variable.  They return 0 if they fail;
  1325. |restore| returns 1 if successful, |save| returns either 1 or 2.  The
  1326. ambiguity is because a successful |restore| results in execution continuing
  1327. from immediately after the |save| instruction which produced the save game
  1328. file... so in order that the program could know whether a restore had just
  1329. taken place, or only a save of a game after which normal execution
  1330. continued, the return value is altered.
  1331.  
  1332. Being in the extended set does give them extra functions but not very useful
  1333. ones.  It is possible to imagine saving a ``preferred settings" file, for
  1334. instance.
  1335.  
  1336. (Inform compiles a little code to make |save| and |restore| emulate the
  1337. version 3 opcodes, for portability between versions.  To get at the raw
  1338. opcodes, they must be assembled in |@| mode.)
  1339.  
  1340. \subtitle{Character graphics before Version 6}
  1341.  
  1342. Now for the graphics routines.  The simplest of these allows for different
  1343. text styles: boldface, underlining and reverse video (e.g. white on black if
  1344. text would normally be black on white).  These effects are modelled on the
  1345. VT100 (design of terminal) and cannot safely be combined, even though the
  1346. codes for them look like bit masks:
  1347. \beginstt
  1348.   set_text_style 0     Default: Inform calls this "Roman"
  1349.                  1     Reverse video
  1350.                  2     Boldface
  1351.                  4     Underlined (or italic)
  1352. \endtt
  1353. An interpreter providing coloured text may implement these with colour
  1354. changes: my own represents bold as blue lettering instead of black on white,
  1355. for instance, which is quite pleasant.
  1356.  
  1357. Some ports of ITF paint entirely-reversed next lines when scrolling
  1358. the screen in Reverse video, but this is incorrect.  Some interpreters
  1359. do not implement ``bold face".  A stone tablet with keywords picked out in
  1360. bold might be impossible to decipher to some players.
  1361.  
  1362. (There is another option, 8, which forces use of a fixed-spaced font,
  1363. used in `Beyond Zork'.)
  1364.  
  1365. An upper (usually status line) screen can be split off from the main screen
  1366. with:
  1367. \beginstt
  1368.   split_window <n>
  1369. \endtt
  1370. creating one which is |n| lines tall.  There are then two screens, 0 (the
  1371. main screen) and 1 (the upper one).  Text output can be switched between
  1372. them by
  1373. \beginstt
  1374.   set_window 0       to lower
  1375.              1       to upper
  1376. \endtt
  1377. The lower window is just a text stream and its cursor position cannot be
  1378. set: on the other hand, when it is returned to, the cursor will be where it
  1379. was before it was left.
  1380.  
  1381. Within the upper window, anyway, the cursor can be moved by
  1382. \beginstt
  1383.   set_cursor <line> <column>
  1384. \endtt
  1385. where $(1,1)$ is the top left hand character.  Printing on the upper window
  1386. overlies printing on the lower, and is always done in a fixed-space font,
  1387. and does not appear in a printed transcript of the game.
  1388.  
  1389. However, before printing to the ``status line" screen, it is essential to
  1390. change the printing format - this is the |buffer_mode| opcode alluded to
  1391. earlier.  Before printing, execute
  1392. \beginstt
  1393. buffer_mode 0
  1394. \endtt
  1395. and when returning to the normal screen,
  1396. \beginstt
  1397. buffer_mode 1
  1398. \endtt
  1399. Otherwise, if the cursor comes near the edge the interpreter may continue
  1400. trying to split lines at word breaks; some ports of ITF make a horrid mess
  1401. in this case, though Zip manages.
  1402.  
  1403. Also, the status line screen must be tall enough to include all the cursor
  1404. positions you want to write to.  If it is not quite tall enough, different
  1405. interpreters flounder about in different ways: some will scroll the upper
  1406. window, some won't.
  1407.  
  1408. A common thing to want to do is to erase areas of screen - especially a
  1409. status bar which is being redisplayed.  Opcodes
  1410. \beginstt
  1411.   erase_window $ffff  - erases whole screen, both windows
  1412.   erase_line          - erases from cursor to end of line  [Achtung!]
  1413. \endtt
  1414. are provided for this.  If you are in reverse video mode, they erase to the
  1415. reversed colour: a particularly unpleasant effect is achieved by
  1416. \beginstt
  1417. set_text_style 1; erase_window $ffff;
  1418. \endtt
  1419. Unfortunately |erase_window| (which is intended to erase window $n$, or all
  1420. windows if $n=-1$) is not fully implemented by ITF and cannot safely be used
  1421. except in this drastic way.  (E.g., the Version 4 file `Trinity', for
  1422. instance, only uses it thus.)
  1423.  
  1424. |erase_line| is only sometimes implemented and does slightly unpredictable
  1425. things in reverse video mode, which is a nuisance since it would otherwise
  1426. be ideal for blanking out an out-of-date status bar. However, no existing V4
  1427. or V5 game uses this opcode and so it may not be relied upon.  (It's
  1428. interesting to note that the Version-5 edition of `Zork I' - one of the
  1429. earliest Version 5 files - blanks out lines by looking up the screen width
  1430. and printing that many spaces.)
  1431.  
  1432.  
  1433. There are new arithmetic opcodes:
  1434. \beginstt
  1435.   art_shift x y z    z=x arithmetically shifted y bits
  1436.   log_shift x y z    z=x logically shifted y bits
  1437. \endtt
  1438. Version 5 games effectively have ``undo" provided for them, though the logic
  1439. is tricky to get right (from a programmer's point of view).  The two
  1440. relevant opcodes are |save_undo| and |restore_undo|, which work in exactly
  1441. the same way as |save| and |restore| except that they save the game
  1442. internally to spare memory.  The idea is that if the game is saved before
  1443. any action, then the last action can be undone by restoring this
  1444. memory-saved game.
  1445.  
  1446. |save_undo| provides one more return code than |save|: it returns -1 if the
  1447. interpreter is unable to manage internal saves (presumably this was provided
  1448. for machines tight on memory).  Now, of course, an interpreter which knows
  1449. about |save_undo| enough to return this code probably knows enough to
  1450. implement it fully.
  1451.  
  1452. Zip does provide this, but the ITF interpreter currently does not (and
  1453. |save_undo| returns 0).  This is probably the biggest feature it lacks. 
  1454. In any case, ``undo" is such a worthwhile feature and so easy to code that
  1455. games probably ought to provide it in hope.
  1456.  
  1457. Changing input/output streams and reading the keyboard in real time
  1458. are, similarly, more reliable under Zip.
  1459.  
  1460.  
  1461. \subtitle{Architecture: version 6}
  1462.  
  1463.  
  1464. The architecture of the Version 6 Z-machine is extremely similar to that
  1465. of Version 5.  Packed addresses are expanded again and this allows the
  1466. memory map to stretch yet further.  (`Shogun', for instance, is about 335K
  1467. long.)
  1468.  
  1469. Pictures and sampled sounds are not stored in the Z-machine itself and it
  1470. is simply expected that the interpreter has them to hand.  They were
  1471. thus stored in different formats for different machines.
  1472.  
  1473. A few opcodes are changed (mostly the character graphics ones) and
  1474. many new ones are added: see the dictionary.
  1475.  
  1476. The graphical features are the most disheartening to interpreter writers,
  1477. but most of them seem to be optional.  For instance, the interpreter
  1478. can declare itself unable to draw pictures, or to produce sound effects.
  1479. It is not impossible to imagine that a fairly portable version-6 interpreter
  1480. could be constructed, and Zip is currently going down this road.
  1481.  
  1482. The display is expected to be arranged in pixels.  Coordinates are usually
  1483. given in the form $(y,x)$, with $(1,1)$ in the top left.  There is a
  1484. generalised colour scheme intended to look like the basic IBM PC colours
  1485. (which is to say, not very pleasant).  There are eight, instead of two,
  1486. windows, and they have more elaborate possibilities; but essentially
  1487. similar to the two windows in version 4 onward.
  1488.  
  1489. There may be a mouse, but if so it is not expected to do much beyond move
  1490. an arrow around and have one or more buttons.  Similarly, there may be a
  1491. concept of ``menus" - which seems primarily furnished for Apple Macintoshes.
  1492.  
  1493.  
  1494. \section{8}{Complete table of opcodes}
  1495.  
  1496.  
  1497. This table might be called a variorum edition of the Z-machine
  1498. specification: it contains all 120 or so possible opcodes for every version
  1499. of the Z-machine, from 1 to 6 and (taken with the accompanying dictionary)
  1500. documents them and their corresponding Inform assembly language syntax.
  1501.  
  1502. A few opcodes do not in fact occur in any existing files, but they can
  1503. be deduced by disassembling Infocom-supplied interpreters.  This table
  1504. specifies also which opcodes occur in V1 to V5 files, at least.
  1505.  
  1506. Inform names (and can assemble) all the opcodes, even the version-6 ones.
  1507. This may be useful for preparing test files.  The names here are the set
  1508. used by Inform 5.4 and later, extended from a system worked out by Mark
  1509. Howell for his disassembler, which we have agreed on as a standard.  We hope
  1510. that this will provide interpreter writers and others with a common lexicon. 
  1511. It would be helpful if interpreter sources use these names internally.
  1512.  
  1513. \subtitle{Reading the opcode tables}
  1514.  
  1515. The two columns ``St" and ``Br" (store and branch) mark whether an
  1516. instruction stores a result in a variable, and whether it must provide a
  1517. label to jump to, respectively.
  1518.  
  1519. The ``Opcode" is written
  1520. \begintt
  1521.    TYPE:Decimal
  1522. \endtt
  1523. where the TYPE is 2OP, 1OP, 0OP, VAR or EXT: two operands, one operand, no
  1524. operands, variable number of said, and variable number of said but occurring
  1525. in the ``extended" set.  The extended set of opcodes are two-byte opcodes
  1526. where the first byte is (decimal) 190.
  1527.  
  1528. Briefly, single byte opcodes have types as follows:
  1529. \beginstt
  1530.   0 to 31, 32 to 63, 64 to 95, 96 to 127:  forms of 2OP, the opcode number
  1531.                                                being the value mod 32
  1532.   128 to 143, 144 to 159, 160 to 175:      forms of 1OP, the opcode number
  1533.                                                being the value mod 16
  1534.   176 to 191:                              0OP, the opcode number
  1535.                                                being the value mod 16
  1536.   192 to 223:                              2OP opcodes implemented in the
  1537.                                                VAR form, the opcode number
  1538.                                                being the value mod 32
  1539.   224 to 255:                              VAR, the opcode number
  1540.                                                being the value mod 32
  1541. \endtt
  1542. The decimal number is the lowest possible decimal opcode value.  The hex
  1543. number is the opcode number within each TYPE.
  1544.  
  1545. The ``V" column gives the version information.  If nothing is specified, the
  1546. opcode is as stated from version 1 onwards.  Otherwise, it exists only from
  1547. the version quoted onwards.  Before this time, its use is illegal.  Some
  1548. opcodes change their meanings and these have more than one line of
  1549. specification.  Others become illegal again, and these are marked
  1550. |[illegal]|.
  1551.  
  1552. In a few cases, the version is given as ``3/4" or some such.  The first
  1553. number is the version number whose specification the opcode belongs to, and
  1554. the second is the earliest version in which the opcode is known actually to
  1555. be used.  A dash means that it is never used at all (in versions 1 to 5 at
  1556. least: possibly a few of the 5/- opcodes may be used in version 6).
  1557.  
  1558. The table explicitly marks opcodes which remain unused in all six versions
  1559. of the Z-machine as |------|.  In principle, the interpreter is at liberty
  1560. to crash if it finds them, though in practice ignoring them is more polite.
  1561.  
  1562. However, the extended set, which could in principle run from |$00| to |$ff|,
  1563. stops at |$1c|: subsequent codes |$1d| to |$ff| were never used, even in
  1564. version 6.
  1565.  
  1566. \subtitle{Inform assembly language}
  1567.  
  1568. An Inform line beginning with an |@| is sent direct to the assembler.  The
  1569. syntax is as laid out in the tables below.  (Remember that opcodes can only
  1570. be used if the game version number is right.)
  1571.  
  1572. |<variable>| and |<result>| must be variables (or |sp|, the stack pointer);
  1573. |<label>| a label (not a routine name).  In a branch instruction, the
  1574. logical effect can be negated using a tilde |~| before the label name, so
  1575. for instance
  1576. \beginstt
  1577.   @je a b ~Different;  ! Jump to Different if a not equal to b
  1578. \endtt
  1579. The programmer must specify whether a branch is in the ``near" or ``far"
  1580. form, the default being ``near".  A question mark |?| before the label (and
  1581. the tilde, if there is one) forces it to be far, it otherwise being ``near"
  1582. (which is cheaper and more likely).
  1583.  
  1584. |<string>| must be literal text in quotation marks ``thus" and it is
  1585. translated in the usual Inform way.  When |function| is listed, a constant
  1586. is expected to be a packed address of a function.  Inform assembles these in
  1587. the right way if you just name a function at the appropriate point.
  1588.  
  1589. Generally speaking any Inform constant term (such as |'a'| or |'beetle'|)
  1590. can be used as an operand but a compound expression (which would obviously
  1591. incur extra assembly) cannot.
  1592.  
  1593. \subtitle{Opcode names changed since Inform 5.2}
  1594.  
  1595. In order to bring Inform into line with the agreed standard names for opcodes,
  1596. the following changes have been made to opcode names:
  1597. \beginstt
  1598.      From              To
  1599.      ====================================
  1600.      compare_pobj      same_parent
  1601.      colour            set_colour
  1602.      retsp             ret_popped
  1603.      show_score        show_status
  1604.      scanw             scan_table
  1605.      aparse            tokenise
  1606.      encrypt           encode_text
  1607.      check_no_args     check_arg_count
  1608. \endtt
  1609. \vfill\eject
  1610. \hrule\smallskip
  1611. \centerline{\bf Two-operand (long) opcodes 2OP}\smallskip\hrule
  1612. \beginlines
  1613. |   St  Br  Opcode Hex  V  Inform name and syntax|
  1614. \endlines\smallskip\hrule\smallskip\beginlines
  1615. |           ------   0  ------|
  1616. |       *   2OP:1    1     je              a b <label>|
  1617. |       *   2OP:2    2     jl              a b <label>|
  1618. |       *   2OP:3    3     jg              a b <label>|
  1619. |       *   2OP:4    4     dec_chk         <variable> value <label>|
  1620. |       *   2OP:5    5     inc_chk         <variable> value <label>|
  1621. |       *   2OP:6    6     same_parent     obj1 obj2 <label>|
  1622. |       *   2OP:7    7     test            bitmap flags <label>|
  1623. |   *       2OP:8    8     or              a b <result>|
  1624. |   *       2OP:9    9     and             a b <result>|
  1625. |       *   2OP:10   A     test_attr       object attribute <label>|
  1626. |           2OP:11   B     set_attr        object attribute|
  1627. |           2OP:12   C     clear_attr      object attribute|
  1628. |           2OP:13   D     store           <variable> value|
  1629. |           2OP:14   E     insert_obj      object destination|
  1630. |   *       2OP:15   F     loadw           table index <result>|
  1631. |   *       2OP:16  10     loadb           table index <result>|
  1632. |   *       2OP:17  11     get_prop        object property <result>|
  1633. |   *       2OP:18  12     get_prop_addr   object property <result>|
  1634. |   *       2OP:19  13     get_next_prop   object property <result>|
  1635. |   *       2OP:20  14     add             a b <result>|
  1636. |   *       2OP:21  15     sub             a b <result>|
  1637. |   *       2OP:22  16     mul             a b <result>|
  1638. |   *       2OP:23  17     div             a b <result>|
  1639. |   *       2OP:24  18     mod             a b <result>|
  1640. |   *       2OP:25  19  4  call_2s         function arg1 arg2 <result>|
  1641. |           2OP:26  1A  5  call_2n         function arg1 arg2|
  1642. |           2OP:27  1B  5  set_colour      foreground background|
  1643. |           2OP:28  1C 5/- throw           value stack-frame|
  1644. |           ------  1D  ------|
  1645. |           ------  1E  ------|
  1646. |           ------  1F  ------|
  1647. \endlines\smallskip\hrule\smallskip
  1648. \vfill\eject
  1649. \smallskip\hrule\smallskip
  1650. \centerline{\bf One-operand opcodes \rm 1OP}\smallskip\hrule
  1651. \beginlines
  1652. |   St  Br  Opcode Hex  V  Inform name and syntax|
  1653. \endlines\smallskip\hrule\smallskip\beginlines
  1654. |       *   1OP:128  0     jz              a <label>|
  1655. |   *   *   1OP:129  1     get_sibling     object <result> <label>|
  1656. |   *   *   1OP:130  2     get_child       object <result> <label>|
  1657. |   *       1OP:131  3     get_parent      object <result>|
  1658. |   *       1OP:132  4     get_prop_len    property-address <result>|
  1659. |           1OP:133  5     inc             <variable>|
  1660. |           1OP:134  6     dec             <variable>|
  1661. |           1OP:135  7     print_addr      byte-address-of-string|
  1662. |   *       1OP:136  8  4  call_1s         function arg1 <result>|
  1663. |           1OP:137  9     remove_obj      object|
  1664. |           1OP:138  A     print_obj       object|
  1665. |           1OP:139  B     ret             value|
  1666. |           1OP:140  C     jump            <label>|
  1667. |           1OP:141  D     print_paddr     word-address-of-string|
  1668. |   *       1OP:142  E     load            value <result>|
  1669. |   *       1OP:143  F 1/4 not             value <result>|
  1670. |                       5  call_1n         function arg1|
  1671. \endlines\smallskip\hrule\smallskip
  1672. \centerline{\bf Zero-operand opcodes \rm 0OP}\smallskip\hrule
  1673. \beginlines
  1674. |   St  Br  Opcode Hex  V  Inform name and syntax|
  1675. \endlines\smallskip\hrule\smallskip\beginlines
  1676. |           0OP:176  0     rtrue|
  1677. |           0OP:177  1     rfalse|
  1678. |           0OP:178  2     print           <string>|
  1679. |           0OP:179  3     print_ret       <string>|
  1680. |           0OP:180  4 1/- nop|
  1681. |       *   0OP:181  5  1  save            <label>|
  1682. |                       5  [illegal]|
  1683. |       *   0OP:182  6  1  restore         <label>|
  1684. |                       5  [illegal]|
  1685. |           0OP:183  7     restart|
  1686. |           0OP:184  8     ret_popped|
  1687. |           0OP:185  9  1  pop|
  1688. |   *                   5  catch           <result>|
  1689. |           0OP:186  A     quit|
  1690. |           0OP:187  B     new_line|
  1691. |           0OP:188  C  3  show_status|
  1692. |                       4  [illegal]|
  1693. |       *   0OP:189  D  3  verify|
  1694. |           0OP:190  E  5  [first byte of extended opcode]|
  1695. |       *   0OP:191  F  5  piracy|
  1696. \endlines\smallskip\hrule\smallskip
  1697. \vfill\eject
  1698. \smallskip\hrule\smallskip
  1699. \centerline{\bf Variable-operand opcodes \rm VAR}\smallskip\hrule
  1700. \beginlines
  1701. |   St  Br  Opcode Hex  V  Inform name and syntax|
  1702. \endlines\smallskip\hrule\smallskip\beginlines
  1703. |   *       VAR:224  0  1  call            function ...args... <result>|
  1704. |                          icall           address <result>|
  1705. |                       4  call_vs         function ...args... <result>|
  1706. |           VAR:225  1     storew          table word value|
  1707. |           VAR:226  2     storeb          table byte value|
  1708. |           VAR:227  3     put_prop        object property value|
  1709. |   *       VAR:228  4  1  sread           text-buffer parse-buffer|
  1710. |                       5  aread           text parse time function|
  1711. |           VAR:229  5     print_char      ascii-value|
  1712. |           VAR:230  6     print_num       value|
  1713. |   *       VAR:231  7     random          range <result>|
  1714. |           VAR:232  8     push            value|
  1715. |   *       VAR:233  9  1  pull            <result>|
  1716. |                      5/- pull            stack <result>|
  1717. |           VAR:234  A  3  split_window    lines|
  1718. |           VAR:235  B  3  set_window      window|
  1719. |   *       VAR:236  C  4  call_vs2        [not properly assembled]|
  1720. |           VAR:237  D  4  erase_window    window|
  1721. |           VAR:238  E 4/- erase_line      value|
  1722. |                       6  erase_line      pixels|
  1723. |           VAR:239  F  4  set_cursor      line row|
  1724. |                       6  set_cursor      line row window|
  1725. |           VAR:240 10 4/- get_cursor      table|
  1726. |           VAR:241 11  4  set_text_style  style|
  1727. |           VAR:242 12  4  buffer_mode     flag|
  1728. |           VAR:243 13  3  output_stream   number|
  1729. |                       5  output_stream   number table|
  1730. |                       6  output_stream   number table width|
  1731. |           VAR:244 14  3  input_stream    number|
  1732. |           VAR:245 15  4  beep|
  1733. |                      5/3 sound_effect    number effect volume|
  1734. |                          sound_effect    number effect repeats volume|
  1735. |                       6  sound_effect    number effect volume repeats|
  1736. |   *       VAR:246 16  4  read_char       1 time function <result>|
  1737. |   *    *  VAR:247 17  4  scan_table      x table len form <result> <label>|
  1738. |   *       1OP:248 18 5/- not             value <result>|
  1739. |           VAR:249 19  5  call_vn         function ...args...|
  1740. |           VAR:250 1A  5  call_vn2        [not properly assembled]|
  1741. |           VAR:251 1B  5  tokenise        text parse dictionary flag|
  1742. |           VAR:252 1C  5  encode_text     ascii-text length from coded-text|
  1743. |           VAR:253 1D  5  copy_table      from to size|
  1744. |           VAR:254 1E  5  print_table     ascii-text width height skip|
  1745. |        *  VAR:255 1F  5  check_arg_count argument-number|
  1746. \endlines\smallskip\hrule\smallskip
  1747. \vfill\eject
  1748. \smallskip\hrule\smallskip
  1749. \centerline{\bf Extended opcodes \rm EXT}\smallskip\hrule
  1750. \beginlines
  1751. |   St  Br  Opcode Hex  V  Inform name and syntax|
  1752. \endlines\smallskip\hrule\smallskip\beginlines
  1753. |   *       EXT:256  0  5  save            table bytes name <result>|
  1754. |   *       EXT:257  1  5  restore         table bytes name <result>|
  1755. |   *       EXT:258  2  5  log_shift       number places <result>|
  1756. |   *       EXT:259  3 5/- art_shift       number places <result>|
  1757. |   *       EXT:260  4  5  set_font        font window <result>|
  1758. |           EXT:261  5  6  draw_picture    picture-number y x|
  1759. |        *  EXT:262  6  6  picture_data    picture-number table <label>|
  1760. |           EXT:263  7  6  erase_picture   picture-number y x|
  1761. |           EXT:264  8  6  set_margins     left right window|
  1762. |   *       EXT:265  9  5  save_undo       <result>|
  1763. |   *       EXT:266  A  5  restore_undo    <result>|
  1764. |           -------  B  ------|
  1765. |           -------  C  ------|
  1766. |           -------  D  ------|
  1767. |           -------  E  ------|
  1768. |           -------  F  ------|
  1769. |           EXT:272 10  6  move_window     window y x|
  1770. |           EXT:273 11  6  window_size     window y x|
  1771. |           EXT:274 12  6  window_style    window flags operation|
  1772. |   *       EXT:275 13  6  get_wind_prop   window property-number <result>|
  1773. |           EXT:276 14  6  scroll_window   window pixels|
  1774. |           EXT:277 15  6  pop_stack       items stack|
  1775. |           EXT:278 16  6  read_mouse      table|
  1776. |           EXT:279 17  6  mouse_window    window|
  1777. |        *  EXT:280 18  6  push_stack      value stack <label>|
  1778. |           EXT:281 19  6  put_wind_prop   window property-number value|
  1779. |           EXT:282 1A  6  print_form      formatted-table|
  1780. |        *  EXT:283 1B  6  make_menu       number table <label>|
  1781. |           EXT:284 1C  6  picture_table   table|
  1782. \endlines\smallskip\hrule\bigskip
  1783.  
  1784. Notes: 1. The opcodes 5, 6, 7, 8 in the extended set were very likely in the
  1785. V5 specification, and are named in some interpreter sources (though only
  1786. very haphazardly implemented) but they do not occur in any existing V5 story
  1787. file.
  1788.  
  1789. 2. The notation ``5/3" for |sound_effect| is because this plainly version-5
  1790. feature was used also in one solitary Version-3 game, `The Lurking Horror'
  1791. (the sound version of which was the last V3 release, in September 1987).
  1792. A V3 interpreter may ignore this but may not crash.
  1793.  
  1794. 3. The opcode 0 (in the 2-operand set, i.e. the actual byte 00) was possibly
  1795. intended for setting break-points in debugging.  It was not |nop|.  (At
  1796. time of writing, the Infix debugger uses the actual |nop| instruction as
  1797. a break-point.)
  1798.  
  1799.  
  1800. \section{9}{Dictionary of opcodes}
  1801.  
  1802. \quote
  1803.        The highest ideal of a translation... is achieved when the
  1804.        reader flings it impatiently into the fire, and begins
  1805.        patiently to learn the language for himself.
  1806. \quoteby{Philip Vellacott}
  1807.  
  1808. This dictionary is alphabetical and includes entries on every opcode listed
  1809. in the table above, as well as brief notes on some Inform internal synonyms
  1810. which might otherwise be confused with opcodes.  Although concise it
  1811. essentially documents correct interpreter behaviour.
  1812.  
  1813. The following have been corrected since the first edition: |aread|,
  1814. |erase_line|, |get_cursor|, |get_wind_prop|, |input_stream|, |picture_data|,
  1815. |random|, |set_cursor| and
  1816. |split_window|.  |picture_table|, the last opcode
  1817. to be discovered, has been added.
  1818. \bigskip
  1819.  
  1820. \def\de{\medskip\noindent}
  1821.  
  1822. \de |add |\inpar   Signed 16-bit addition.
  1823.  
  1824. \de |and |\inpar   Bitwise and.
  1825.  
  1826. \de |"aparse"|\inpar   Obselete name for |tokenise|.
  1827.  
  1828. \de |aread|\inpar   Advanced form of |read|.  This behaves just as the standard
  1829.     form does if the last two operands are not
  1830.     supplied, except that: (i) the status line is not redisplayed, and
  1831.     (ii) if the parse buffer supplied is zero, no attempt is made to parse
  1832.     the input.
  1833.     \onpar
  1834.     The parse buffer is appended to, not over-written as in version 3.
  1835.     \onpar
  1836.     If all four operands are supplied, then every |time| seconds
  1837.     while the player is working on her input, the |function| is called: if it
  1838.     returns 1 (true) then the reading process is interrupted.  (The function
  1839.     obviously needs to run pretty quickly.)
  1840.     \onpar
  1841.     The |function| is called with one argument: the |time| value.
  1842.  
  1843. \de |art_shift|\inpar   Does an arithmetic shift of number by the given number of
  1844.     places, shifting left (i.e. increasing) if places is positive, right if negative.
  1845.     In a right shift, the sign bit is preserved as well as being shifted on
  1846.     down.  (The alternative behaviour is |log_shift|.)
  1847.  
  1848. \de |beep|\inpar   Beeps in a more or less irksome fashion and possibly flashes the
  1849.     display.
  1850.  
  1851. \de |buffer_mode|\inpar   If set to 1, text output is buffered up so that it can be
  1852.     word-wrapped properly.  If set to 0, it isn't.
  1853.  
  1854. \de |call|\inpar   The only call instruction in version-3, Inform reads this as
  1855.     |call_vs| in higher versions: it calls the function with 0, 1, 2 or 3
  1856.     arguments as supplied and stores the resulting return value.
  1857.  
  1858. \de |call_1n|\inpar   Executes |function(arg)| and throws away result.
  1859.  
  1860. \de |call_1s|\inpar   Stores |function(arg)|.
  1861.  
  1862. \de |call_2n|\inpar   Executes |function(arg1, arg2)| and throws away result.
  1863.  
  1864. \de |call_2s|\inpar   Stores |function(arg1, arg2)|.
  1865.  
  1866. \de |call_vn|\inpar   Like |call|, but throws away result.
  1867.  
  1868. \de |call_vs|\inpar   See |call|.
  1869.  
  1870. \de |call_vn2|\inpar   Call with a variable number (from 0 to 7) of arguments, then
  1871.     throw away the result.  This (and |call_vs2|) uniquely have an extra byte
  1872.     of opcode types to specify the types of arguments 4 to 7.
  1873.  
  1874. \de |call_vs2|\inpar   See |call_vn2|.
  1875.  
  1876. \de |catch|\inpar   Opposite to |throw|, and occupying the same opcode that |pop| used
  1877.     to in versions 3 and 4, but now with a store argument.  |catch| gives the
  1878.     stack frame of the current routine: see |throw| for what to do with it
  1879.     subsequently.
  1880.  
  1881. \de |check_arg_count|\inpar   Branches if the given argument-number (1 being the first of
  1882.     these) has been provided by the function call to the current routine.
  1883.     (Default values would otherwise be difficult to provide in versions 5
  1884.     and 6.)
  1885.  
  1886. \de |"check_no_args"|\inpar   Obselete name for |check_arg_count|.
  1887.  
  1888. \de |clear_attr|\inpar   Make |object| not have |attribute|.
  1889.  
  1890. \de |clear_flag|\inpar   A name once used for one of the not-really-present extended v5
  1891.     opcodes.
  1892.  
  1893. \de |"colour"|\inpar   Obselete name for |set_colour|.
  1894.  
  1895. \de |"compare_pobj"|\inpar   Obselete name for |same_parent|.
  1896.  
  1897. \de |copy_table|\inpar   Copies size bytes from the first table to the second.  If the
  1898.     second table is given as 0, then it zeroes the bytes in the first table.
  1899.     If the length is positive, it copies backwards:
  1900.     \onpar |copy_table $1000 $1001 20|
  1901.     \onpar
  1902.     would push the first 20 bytes forward by one.  However, if the length is
  1903.     negative, it copies forwards.  Thus the same operation with -20 would
  1904.     result in the byte at |$1000| being copied into the 20 following bytes.
  1905.  
  1906. \de |dec |\inpar   Decrement variable
  1907.  
  1908. \de |dec_chk|\inpar   Decrement variable, and jump if now equal to value
  1909.  
  1910. \de |div |\inpar   Signed 16-bit division
  1911.  
  1912. \de |draw_picture|\inpar   Displays the picture with the given number from the library of
  1913.     pictures which the interpreter is expected to have (which is not resident
  1914.     in the Z-machine itself).  The Z-machine knows nothing of what picture
  1915.     format is being used.  By default, this appears at the current cursor
  1916.     position in the current window.  Y and X pixel coordinates from the top
  1917.     left can be given instead, though (the top left having coordinates $(1,1)$).
  1918.     \onpar
  1919.     Pictures are numbered from 1 and need not be numbered contiguously.
  1920.  
  1921. \de |encode_text|\inpar   Translates an ASCII word to the internal (z-encoded) text format,
  1922.     suitable for dictionary use.  The text begins at |from| in the |ascii-text|
  1923.     and is |length| characters long, which should contain the right length
  1924.     value even though in fact the interpreter translates the word as far
  1925.     as a 0 terminator.  A 6-byte z-encoded string results: this is the
  1926.     dictionary resolution in versions 4, 5 and 6 and usually represents
  1927.     9 characters of ASCII.
  1928.  
  1929. \de |"encrypt"|\inpar   Obselete name for |encode_text|.
  1930.  
  1931. \de |erase_line|\inpar   Before version 6: erase the current cursor line in the current
  1932.     window.  (Badly interpreted by ITF.)  In version 6: if the value is 1, do
  1933.     just that: if not, erase the given number of pixels minus one across from
  1934.     the cursor (clipped to the window size).
  1935.     In both cases, don't move the cursor.
  1936.  
  1937. \de |erase_picture|\inpar   Like |draw_picture|, but wipes the appropriate region to
  1938.     the background colour for the given window.
  1939.  
  1940. \de |erase_window|\inpar   Erases window with given number (to the background colour in
  1941.     version-6), or if -1 it unsplits the screen and clears the lot.  The
  1942.     cursor moves back to top left.  (In version 6, -2 means clear the whole
  1943.     screen but don't unsplit it.)
  1944.  
  1945. \de |extended|\inpar   This byte (decimal 190) is not really an instruction, but
  1946.     indicates that the opcode is ``extended": the next byte contains the
  1947.     number in the extended set.
  1948.  
  1949. \de |get_next_prop|\inpar   Gives the number of the next property provided by the
  1950.     quoted object.  This may be zero, indicating the end of the property list;
  1951.     if called with zero, it gives the first property number present.  (If
  1952.     called with the number of a property not present, the Z-machine may
  1953.     legitimately crash.)
  1954.  
  1955. \de |get_prop|\inpar   Read property from object (resulting in the default value if it
  1956.     had no such declared property).
  1957.  
  1958. \de |get_prop_addr|\inpar   Get address of property data for given object's property.
  1959.  
  1960. \de |get_prop_len|\inpar   Get length of property data.
  1961.  
  1962. \de |get_child|\inpar   Get first object contained in given object, branching if there
  1963.     are none (i.e., if this is |nothing|, or 0).
  1964.  
  1965. \de |get_cursor|\inpar   Puts the current cursor row into the first word of the given
  1966.     table, and the current cursor column into the second word.
  1967.  
  1968. \de |get_parent|\inpar   Get parent object (note that this has no ``branch if nothing"
  1969.     clause).
  1970.  
  1971. \de |get_sibling|\inpar   Get next object in tree, branching if this is |nothing| (i.e. 0).
  1972.  
  1973. \de |get_wind_prop|\inpar   The eight windows (in version 6) have 16 properties, numbered
  1974.     0 to 15, which can be read using this call and (mostly) written
  1975.     using |put_wind_prop|.  The 16 properties are:
  1976.     \onpar|0  y coordinate  6   left margin size            12  font number|
  1977.     \onpar|1  x coordinate  7   right margin size           13  font size|
  1978.     \onpar|2  y size        8   newline interrupt function  14  attributes|
  1979.     \onpar|3  x size        9   interrupt countdown         15  line count|
  1980.     \onpar|4  y cursor      10  highlight mode|
  1981.     \onpar|5  x cursor      11  colour data|
  1982.     \onpar
  1983.     These properties are all explained elsewhere except for 8 and 9, about
  1984.     ``newline interrupts".  If the countdown is set non-zero, it begins to
  1985.     count downwards, once per new-line.  When it then hits zero, the
  1986.     interrupt function is called.  This is provided so that text can be
  1987.     shaped past crinkly margins (e.g., to roll nicely around a picture)
  1988.     because the interrupt function can fix the margins at the crucial moment.
  1989.     The interrupt function should not attempt to print anything to the same
  1990.     window!
  1991.     \onpar
  1992.     Window coordinates are relative to the screen; cursor coordinates are
  1993.     relative to the window.
  1994.     \onpar
  1995.     Font size contains two bytes: height then width, in pixels.  Colour data
  1996.     similarly gives foreground, then background colour.
  1997.  
  1998. \de |icall|\inpar   This is an Inform internal name for ``call to a function whose
  1999.     address is supplied, not its name".  It allows calculated calls; but takes
  2000.     no arguments.  It stores the result as |call| does.
  2001.  
  2002. \de |inc |\inpar   Increment variable.
  2003.  
  2004. \de |inc_chk|\inpar   Increment variable, and branch if now equal to value.
  2005.  
  2006. \de |input_stream|\inpar   Switches the input stream (the source of the player's commands).
  2007.     0 is the keyboard, and 1 a command file (the idea is that a list of
  2008.     commands produced by |output_stream 4| can be fed back in again: Zip
  2009.     provides this useful feature).
  2010.  
  2011. \de |insert_obj|\inpar   Moves object to destination (it need not be removed from the tree
  2012.     first).
  2013.  
  2014. \de |je  |\inpar   Jump if |a = b|.
  2015.  
  2016. \de |jg  |\inpar   Jump if |a > b|  (note: not |a>=b|).
  2017.  
  2018. \de |"jge"|\inpar   Inform used to call |jg| this, which was rather confusing, and now it
  2019.     is withdrawn.
  2020.  
  2021. \de |jl  |\inpar   Jump if |a < b|  (note: not |a<=b|).
  2022.  
  2023. \de |"jle"|\inpar   Inform used to call |jl| this, which was rather confusing, and now it
  2024.     is withdrawn.
  2025.  
  2026. \de |jump|\inpar   Jump (unconditionally) to the given label.  It is safe to jump into a
  2027.     different routine but care is advisable.  (The operand to jump is always
  2028.     a 2-byte signed offset: not an absolute routine address.)
  2029.  
  2030. \de |jz  |\inpar   Jump if |a = 0|.
  2031.  
  2032. \de |load|\inpar   Results in the value of the given variable: so load v1 v2 actually
  2033.     does "v2 = v1".  This is better done with |store| or |push| as appropriate
  2034.     and Inform never uses it in compiled code.
  2035.  
  2036. \de |loadb|\inpar   Stores |table->index|.
  2037.  
  2038. \de |loadw|\inpar   Stores |table-->index|.
  2039.  
  2040. \de |log_shift|\inpar   Does a logical shift of number by the given number of places,
  2041.     shifting left (i.e. increasing) if places is positive, right if negative.
  2042.     In a right shift, the sign is zeroed instead of being shifted on.  (The
  2043.     alternative behaviour is |art_shift|.)
  2044.  
  2045. \de |lstore|\inpar   Inform names this to force |store| to take the ``long"
  2046.     form; it is only used internally.
  2047.  
  2048. \de |make_menu|\inpar   Provided for the benefit of the Apple Macintosh, and who are
  2049.     we to object.  Interpreters which don't provide menus are supposed to set
  2050.     a bit to say so in the header, but anyway this instruction can simply
  2051.     do nothing and not branch if there are no menus (or if there are too many
  2052.     already).
  2053.     \onpar
  2054.     The menu number to be added has to be more than 2 (since 0 is the Apple
  2055.     menu, 1 the File menu, 2 the Edit menu).  If the table supplied is 0,
  2056.     the menu is removed.  Otherwise it is a table of tables.  Each table is
  2057.     an ASCII string: the first item being a menu name, subsequent ones the
  2058.     entries.
  2059.  
  2060. \de |mod |\inpar   Remainder after signed 16-bit division.
  2061.  
  2062. \de |mouse_window|\inpar   Constrain the mouse arrow to sit inside the given window.
  2063.     By default it sits in window 1.  Setting to -1 takes all restriction away.
  2064.     (The mouse clicks are not reported if the arrow is outside the window
  2065.     and interpreters are presumably supposed to hold the arrow there by
  2066.     hardware means if possible.)
  2067.  
  2068. \de |move_window|\inpar   Moves the given window to pixels $(y,x)$: $(1,1)$ being
  2069.     the top left.  Nothing actually happens (since windows are entirely
  2070.     notional transparencies): but any future plotting happens in the new place.
  2071.  
  2072. \de |mul |\inpar   Signed 16-bit multiplication.
  2073.  
  2074. \de |new_line|\inpar   Print carriage return.
  2075.  
  2076. \de |nop |\inpar   Probably the official ``no operation" instruction.  Ironically,
  2077.     since there is hardly ever any point in using it (self-modifying code is
  2078.     illegal in the Z-machine since the code is outside the save area)
  2079.     interpreters sometimes do not bother to implement it... and crash.
  2080.     (In any event, no V1 to V5 datafile actually uses this opcode.)
  2081.  
  2082. \de |not |\inpar   Bitwise not (i.e., all 16 bits reversed).  Note: in versions 3 and 4
  2083.     this was a one-operand instruction (as would be expected) but in versions
  2084.     5 and 6 it was pushed into the extended set to make room for |call_1n|.
  2085.     (Inform knows which to compile to.)
  2086.     (Note also that although this opcode seems to belong to V3, it is not
  2087.     in fact used until V4.)
  2088.  
  2089. \de |or  |\inpar   Bitwise or.
  2090.  
  2091. \de |output_stream|\inpar   Text can be output to a variety of different "streams",
  2092.     possibly simultaneously.  0 does nothing.  +n switches stream n on,
  2093.     -n switches it off.  The output streams are: 1 (the screen),
  2094.     2 (the game transcript), 3 (memory) and 4 (script of player's commands).
  2095.     Thus, one can turn the screen off and print only to the transcript,
  2096.     for instance.  Zip does now provide 4, which is extremely useful
  2097.     in debugging games.  Other interpreters do not.
  2098.     \onpar
  2099.     Case 3 is more complicated.  Here the syntax is:
  2100.     \onpar|output_stream 3 table|
  2101.     \onpar
  2102.     and the text is printed into the table+2, the first word always holding
  2103.     the number of characters printed.  Printing is never buffered in this
  2104.     stream, whatever the state of |buffer_mode|.
  2105.     \onpar
  2106.     In Version 6, the total number of pixels width is kept in a field in
  2107.     the game's header.  Also, the |width| field may optionally be given,
  2108.     and the text will then be justified as if it were in the window with
  2109.     that number (if width is positive) or a box -|width| pixels wide (if
  2110.     negative).  Then the table will contain not ordinary text but formatted
  2111.     text: see |print_form|.
  2112.     \onpar
  2113.     In version 3 (which does not have this opcode) transcripting is caused
  2114.     purely by setting the header bit.  In higher versions games do this
  2115.     as well anyway, despite using the opcode.
  2116.  
  2117. \de |picture_data|\inpar   Asks the interpreter for data on the picture with the given
  2118.     number.  This is a branch instruction: if the picture number is not valid,
  2119.     no branch is made.  Otherwise information is written to the table and a
  2120.     branch occurs.
  2121.     \onpar
  2122.     If the number is zero, the first word of the table is simply written as
  2123.     the highest legal picture number, and the second word is the highest
  2124.     legal picture number.
  2125.     \onpar
  2126.     Otherwise, the first word of the table contains the height and the second
  2127.     the width.
  2128.  
  2129. \de |piracy|\inpar   Branches if the game disc is believed to be genuine by the
  2130.     interpreter (which is assumed to have some evil way of finding out).
  2131.     Earlier specifications suggested this to be an unconditional branch
  2132.     instruction... interpreter writers are urged to code it as such,
  2133.     and Z-code programmers not to use it at all.
  2134.  
  2135. \de |pop |\inpar   This exists only in versions 3 and 4, and simply throws away the top of
  2136.     the stack.  (The need for it was largely circumvented by the
  2137.     call-and-throw-away-result instructions.)  The same opcode was then used
  2138.     for |catch| which tends to crash the machine if used naively.
  2139.  
  2140. \de |pop_stack|\inpar   In Version 6, an honest |pop| instruction was finally re-invented.
  2141.     This throws the given number of items off the system stack, unless a stack
  2142.     is given as a second argument, in which case it pops off that one instead.
  2143.  
  2144. \de |print|\inpar   Print the quoted (literal) string.
  2145.  
  2146. \de |print_addr|\inpar   Print (Z-encoded) string at given byte address.
  2147.  
  2148. \de |print_char|\inpar   Print ASCII character.
  2149.  
  2150. \de |print_form|\inpar   Prints a formatted table of the kind produced when the output
  2151.     stream is 3.  This is an elaborated version of |print_table| to cope with
  2152.     fonts, pixels and other impedimenta.  It is a sequence of lines,
  2153.     terminated with a zero word.  Each line is a word containing the number
  2154.     of characters, followed by that many bytes which hold the characters
  2155.     concerned.
  2156.  
  2157. \de |print_num|\inpar   Print (signed) number in decimal.
  2158.  
  2159. \de |print_paddr|\inpar   Print the (Z-encoded) string at the given packed address.
  2160.  
  2161. \de |print_ret|\inpar   Print the quoted (literal) string, and print a new-line, and
  2162.     then return true (i.e., 1).
  2163.  
  2164. \de |print_table|\inpar   Prints a rectangle of text on screen spreading right and
  2165.     down from the current cursor position, of given |width| and |height|, from
  2166.     the table of ASCII text given.  (Height is optional and defaults to 1.)
  2167.     If a |skip| value is given, then that many characters of text are skipped
  2168.     over in between each line and the next.  So one could make this display,
  2169.     for instance, a 2 by 3 region of a giant 40 by 40 character graphics
  2170.     map.
  2171.  
  2172. \de |pull|\inpar   Pulls value off the stack (crashing if it underflows).  In versions
  2173.     5 and 6, the stack in question may be specified as a user one.  A user
  2174.     stack is just a table of words in the save area somewhere, whose first
  2175.     word always holds the number of spare slots on the stack (so the initial
  2176.     value is the capacity of the stack).  User stacks are not well interpreted.
  2177.  
  2178. \de |push|\inpar   Pushes value onto the system stack.
  2179.  
  2180. \de |push_stack|\inpar   Pushes the value onto the user-specified stack, and branches
  2181.     if successful.  If the stack was full already, nothing happens and no
  2182.     branch is made.
  2183.  
  2184. \de |put_prop|\inpar   Write value to the given property of the given object (this crashes
  2185.     the machine if the object has no such property).  The interpreter stores
  2186.     a word or a byte as appropriate.
  2187.  
  2188. \de |put_wind_prop|\inpar   Writes a window property (see |get_wind_prop|).  This should
  2189.     only be used when there is no direct command (such as |move_window|) to
  2190.     use instead, as some such operations may have side-effects.
  2191.  
  2192. \de |quit|\inpar   Exit the game.  (Any ``Are you sure?" question must be asked by
  2193.     the game, not the interpreter.)  It is not legal to return from the main
  2194.     routine: this must be used.
  2195.  
  2196. \de |random|\inpar   Returns a random number between 1 and range (supposing range to be
  2197.     positive).
  2198.     If range is negative, it is used as a seed for the random number generator
  2199.     (different interpreters do this in different ways), to make the generator
  2200.     predictable.  Random then returns 0.
  2201.     If range is zero, some interpreters crash (though they absolutely should
  2202.     not).  Correct behaviour is to reset the generator to some suitable seed
  2203.     value (say, taken from a real-time clock).  Again, random should then
  2204.     return 0.
  2205.  
  2206. \de |read|\inpar   The two forms of |read| are called |aread| and |sread| by Inform,
  2207.     for the sake of clarity (Advanced and Standard read).  |read| is actually
  2208.     a high-level Inform command which compiles suitably portable code for
  2209.     either version.
  2210.  
  2211. \de |read_char|\inpar   Reads a single character.  The stream (the first operand) is
  2212.     always 1, meaning the keyboard for some reason.  Time and function are
  2213.     optional and dealt with as in |aread|.  Function keys return special
  2214.     values from 129 onwards:
  2215.     \onpar |up  down  left  right  f1 ... f12  keypad 0...9|
  2216.     \onpar |menu click  double mouse click  single mouse click|
  2217.     \onpar (Mice only being at play in version 6.)
  2218.  
  2219. \de |read_mouse|\inpar   The four words in the |table| are written with the mouse
  2220.     y coordinate, x coordinate, button bits (low bits on the right of the
  2221.     mouse, rising as one looks left), and a menu word.  In the menu word,
  2222.     the upper byte is the menu number (from 1) and the lower byte is the
  2223.     item number (from 0).
  2224.  
  2225. \de |restore|\inpar   See |save|.  In version 3, the branch is never actually made,
  2226.     since either the game has successfully picked up again from where it
  2227.     was saved, or it failed to load the save game file.  From version 5
  2228.     it can have optional parameters as |save| does, and returns the number
  2229.     of bytes loaded if so.  If the restore fails, 0 is returned, but once
  2230.     again this necessarily happens since otherwise control is already
  2231.     elsewhere.
  2232.  
  2233. \de |restore_undo|\inpar   Like |restore|, but restores from the internal RAM saved
  2234.     game made by |save_undo|.  (The optional parameters of |restore| may not be
  2235.     supplied.)
  2236.  
  2237. \de |restart|\inpar   Restarts the game.  (Any ``Are you sure?" question must be asked
  2238.     by the game, not the interpreter.) 
  2239.  
  2240. \de |ret |\inpar   Returns the value given.
  2241.  
  2242. \de |ret_popped|\inpar   Pops top of stack and returns that.  This is equivalent to
  2243.     |ret sp|, but is one byte cheaper.
  2244.  
  2245. \de |"retsp"|\inpar   Obselete name for |ret_popped|.
  2246.  
  2247. \de |rfalse|\inpar   Return false (i.e., 0).
  2248.  
  2249. \de |rtrue|\inpar   Return true (i.e., 1).
  2250.  
  2251. \de |same_parent|\inpar   Compare parent objects of the two given: branch if equal.
  2252.  
  2253. \de |save|\inpar   On versions 3 and 4, this attempts to save the game (all questions
  2254.     about filenames are asked by interpreters) and branches if successful.
  2255.     From version 5 it moves to the extended set, as a result of which it is
  2256.     no longer a branch instruction, and works in a different way (see the
  2257.     explanation above).  This returns 0 for failure, 1 for ``save
  2258.     succeeded" and 2 for ``the game is being restored and is resuming
  2259.     execution again from here, the point where it was saved".
  2260.     \onpar
  2261.     The extension also has (optional) parameters, which save a region of
  2262.     the save area, whose address and length are in bytes, and provides a
  2263.     suggested filename: name is a pointer to an array of ASCII characters
  2264.     giving this name (as usual preceded by a byte giving the number of
  2265.     characters).
  2266.  
  2267. \de |save_undo|\inpar   Like |save|, except that the optional parameters may not be
  2268.     specified: it saves the game into a cache of RAM held by the interpreter.
  2269.     (This is typically done once per turn, in order to implement ``UNDO", so
  2270.     it needs to be quick.)  It may also return -1, meaning that the
  2271.     interpreter is unable to offer this feature.  (Alas, most interpreters
  2272.     do not understand this opcode well enough to be able to confess to being
  2273.     unable to act on it.)
  2274.  
  2275. \de |scan_table|\inpar   Is |x| one of the words in |table|, which is |len| words
  2276.     long?  If so, return the address where it first occurs and branch.  If not,
  2277.     return 0 and don't.
  2278.     \onpar
  2279.     The |form| is optional (and only used in version 5?): bit 8 is set for
  2280.     words, clear for bytes: the rest contains the length of each field in
  2281.     the table.  (The first word or byte in each field being the one looked
  2282.     at.)  Thus |$82| is the default.
  2283.  
  2284. \de |"scanw"|\inpar   Obselete name for |scan_table|.
  2285.  
  2286. \de |scroll_window|\inpar   Scrolls the given window by the given number of pixels
  2287.     (a negative value scrolls backwards, i.e., down) writing in blank
  2288.     (background colour) pixels in the new lines.  This can be done to any
  2289.     window and is not related to the ``scrolling" attribute of a window
  2290.     (which controls text scrolling, a different matter).
  2291.  
  2292. \de |set_attr|\inpar   Give |object| the |attribute|.
  2293.  
  2294. \de |set_colour|\inpar   If coloured text is available, set text to be foreground-against-
  2295.     background, where colour numbers are borrowed from the IBM PC:
  2296.     2 - black, 3 - red, 4 - green, 5 - yellow, 6 - blue, 7 - magenta, 8 - cyan,
  2297.     9 - white: in addition, 0 means keep the current colour setting, 1 means
  2298.     use the default and -1 means the colour of the pixel under the mouse arrow
  2299.     \onpar
  2300.     One of the V5 games, `Beyond Zork', uses this (Paul David Doherty reports
  2301.     it as used ``76 times in 870915 and 870917, 58 times in 871221'') and from
  2302.     the structure of the table it clearly logically belongs in version 5.
  2303.     \onpar
  2304.     Text styles such as bold and underline may also be realised with colour
  2305.     changes, if this is used.
  2306.  
  2307. \de |set_cursor|\inpar   Move cursor in the current window to $(x,y)$ character position
  2308.     (relative to $(1,1)$ in the top left).  (In version 6 the window is supplied
  2309.     and need not be the current one.)  Each window remembers its own cursor
  2310.     position.  Using this call may result in any buffered text being printed
  2311.     out first (if word-wrapping is going on, for instance).
  2312.     \onpar
  2313.     In V6, |set_cursor -1| turns the cursor off, and either |set_cursor -2| or
  2314.     |set_cursor -2 0| turn it back on.  It is not known what, if anything, this
  2315.     second argument means: in all known cases it is 0.
  2316.  
  2317. \de |set_flag|\inpar   See |clear_flag|.
  2318.  
  2319. \de |set_font|\inpar   The (text) font in the given window is changed.  All windows
  2320.     (and this includes both windows in Version 5, contrary to common
  2321.     interpreter practice) seem to be expected to start with a non-fixed-space
  2322.     font.  Anyway font 0 means ``keep current one" (this seems less than
  2323.     altogether useful), font 1 means ``default", font 3 refers to character
  2324.     graphics fonts (in versions 5 and 6) and font 4 means a fixed space font.
  2325.     \onpar
  2326.     No such opcode exists in versions 3 and 4:  turning on and off the
  2327.     fixed space font is done by altering a bit in the header as usual.  This
  2328.     remains the best way for interpreters to work even in higher versions.
  2329.  
  2330. \de |set_margins|\inpar   Sets the margin widths (in pixels) on the left and right
  2331.     for the given window which are by default 0.  These are only used by
  2332.     windows which have word-wrapping (i.e., |buffer_mode| 1) and do nothing
  2333.     for others.
  2334.  
  2335. \de |set_text_style|\inpar   Sets printing style: 0 means normal, 1 means inverse video,
  2336.     2 means bold, 4 means underline.  (In version 6, 8 means change to a
  2337.     fixed-width characters font.)  In principle the interpreter should
  2338.     clear flags in the header according to which of these it is unable to
  2339.     provide (in practice, few bother, and it doesn't much matter).
  2340.  
  2341. \de |set_window|\inpar   Moves text output to one of the windows.  0 is the default
  2342.     (lower) window and 1 means the upper one.  This only just counts as a
  2343.     version-3 instruction: it was used by `Seastalker' on some machines.
  2344.     \onpar
  2345.     In version 6 this is much more fulsome.  There are 8 windows, 0 to 7,
  2346.     which can do almost anything.  In addition, the window number -3
  2347.     means ``the current window", in this and all the other calls.
  2348.  
  2349. \de |"show_score"|\inpar   Obselete name for |show_status|.
  2350.  
  2351. \de |show_status|\inpar   (In version 3 only)  Display and update the status line now
  2352.     (don't wait until the next keyboard input).  Ideally this should not
  2353.     crash in version 5, since the v5 release of `Wishbringer' (V23) contains
  2354.     this opcode by accident.
  2355.  
  2356. \de |sound_effect|\inpar   `The Lurking Horror' used this opcode, but no other version-3
  2357.     game did: the v5 game `Sherlock' also used its full form.  See |beep|, the
  2358.     Inform name for the simpler form of this opcode in versions 4 and 5.
  2359.     \onpar
  2360.     In Version 6, this produces the given sound (1 meaning a high-pitched
  2361.     beep, 2 meaning a low one and other values corresponding to noises
  2362.     held by the interpreter) at the given volume (1 to 8: -1 being the
  2363.     default, loudest value: Mark Howell suggests |$34FB| causes fade in
  2364.     and |$3507|, fade out) repeated the given number of times (-1 now meaning
  2365.     forever).  The ``effect" can be: 1 (prepare), 2 (start), 3 (stop), 4
  2366.     (finish with).  (Preparation means in effect loading the sample file
  2367.     off disc.)
  2368.     \onpar
  2369.     Version 5 (and 3) is similar but the parameters seem to be less
  2370.     sensibly arranged, as shown.
  2371.  
  2372. \de |split_window|\inpar   Divides the screen into two windows, an upper one (of the
  2373.     stated number of lines) which is in effect a big status bar, and a
  2374.     lower one (all the rest).  This only just counts as a version-3
  2375.     instruction: it was used by `Seastalker' on some machines.
  2376.     In V6, this seems to be used just to bound the cursor movement.  `Journey'
  2377.     creates a status region which is the whole screen and then overlays it
  2378.     with two other windows.
  2379.  
  2380. \de |sread|\inpar   Standard (version 3) form of |read|.  For details, see the |read|
  2381.     command's description in section (8).  Note that this automatically
  2382.     redisplays the status line before the keyboard is listened to.
  2383.  
  2384. \de |store|\inpar   Set |variable| to |value|.
  2385.  
  2386. \de |storeb|\inpar   |table->byte = value|.
  2387.  
  2388. \de |storew|\inpar   |table-->word = value|.
  2389.  
  2390. \de |sub |\inpar   Signed 16-bit subtraction.
  2391.  
  2392. \de |test|\inpar   Jump if any of the flags in bitmap are set
  2393.     (i.e. if |bitmap & flags ~= 0|).
  2394.  
  2395. \de |test_array|\inpar   See |clear_flag| (ITF makes this come out
  2396.     unconditionally false, though).
  2397.  
  2398. \de |test_attr|\inpar   Jump if |object| has |attribute|.
  2399.  
  2400. \de |throw|\inpar   Opposite of |catch|.  This causes the game to behave as if the
  2401.     current routine was that whose stack-frame is given (which was found
  2402.     using |catch| at the right moment).  Thus the next return to happen
  2403.     will return as if from the ``caught" routine.  This is useful for getting
  2404.     out of large recursive tangles in a hurry, if an error has occurred.
  2405.     (This opcode plainly belongs to the V5 specification, but is not actually
  2406.     used in any V5 game.)
  2407.  
  2408. \de |tokenise|\inpar   The parser (strictly speaking, the lexical analyser) from |aread|.
  2409.     The given |text| is parsed into the given parse table.  Unlike in version
  2410.     3, |aread| appends to the parse table, not over-writes it.
  2411.     \onpar
  2412.     If a non-zero |dictionary| is supplied, it is used (if not, the ordinary
  2413.     game dictionary is).  If the |flag| is set, unrecognised words are not
  2414.     listed as zero in the parse table: this is presumably so that if several
  2415.     |tokenise|s are done in a row, each fills in more slots without wiping those
  2416.     filled by the others.
  2417.     \onpar
  2418.     Parsing a user dictionary is slightly different.  A user dictionary
  2419.     should look just like the main one, except that it should have no
  2420.     ``separator" characters listed (the ones listed in the main one are
  2421.     valid instead), and that it need not be alphabetically sorted.  If the
  2422.     number of entries is given as $-n$, then the interpreter reads this as
  2423.     ``$n$ entries unsorted".  This is very convenient if the table is being
  2424.     altered in play: if, for instance, the player is naming things.
  2425.  
  2426. \de |verify|\inpar   Some version-3 interpreters are said not to implement this.  It
  2427.     counts a (two byte, unsigned) checksum of the file from |$0040| onwards and
  2428.     compares this against the value in the game header, branching if correct.
  2429.  
  2430. \de |vje |\inpar   Internal Inform name for the variable-length form of |je| (for
  2431.     compiling conditions such as |a==1 or 2 or 4|).
  2432.  
  2433. \de |window_size|\inpar   Change size of window in pixels.  (Does not change the current
  2434.     display.)
  2435.  
  2436. \de |window_style|\inpar   Changes the four attributes for a given window.  The bits in
  2437.     question are: 1 - word wrapping (if this is off text is clipped to the
  2438.     window size instead), 2 - scrolling, 3 - text to be sent to the printer
  2439.     (if transcripting is switched on), 4 - text is buffered.
  2440.     \onpar
  2441.     The operation, by default, is 0.  0 means ``set to these settings".  1 means
  2442.     ``set the bits supplied".  2 means ``clear the ones supplied", and 3 means
  2443.     ``reverse the bits supplied" (i.e. exclusive or).
  2444.  
  2445.  
  2446. \section{10}{Header format through the ages}
  2447.  
  2448.  
  2449. The initial block of 64 bytes in the Z-machine, the ``header", is of
  2450. particular fascination to Infocom hackers and many tables have been drawn up
  2451. of its contents.  The table here steals from its predecessors (I am
  2452. particularly indebted to Paul David Doherty) but also fills some gaps to do
  2453. with version 6.
  2454.  
  2455. Once again ``V" refers to the earliest version in which the feature appeared;
  2456. ``Dyn" is marked if the entry is dynamic, i.e. changes as the game plays;
  2457. ``Int" if it is written by the interpreter (otherwise it is set in or by the
  2458. game file).
  2459.  
  2460. Bits in a byte are numbered from 0 (|$01|) up to 7 (|$80|).
  2461.  
  2462. \pageinsert
  2463. \smallskip\hrule\smallskip
  2464. \beginlines
  2465. | Hex  V  Dyn Int  Contents|
  2466. \endlines\smallskip\hrule\smallskip\beginlines
  2467. |  0   1           Version number (1 to 6)|
  2468. |  1   3           Flags 1:|
  2469. |      3       *     Bit 0    (unused: possibly a flag to indicate byte sex,|
  2470. |                              i.e. LSB-MSB or MSB-LSB in 2-byte words, at|
  2471. |                              a time when two different forms of game file|
  2472. |                              was considered: no such forms ever emerged)|
  2473. |                        1    Status line type: clear for score/moves,|
  2474. |                               set for time in hours/minutes|
  2475. |              *         2    (unused: set in V3?)|
  2476. |              *         3    The legendary "Tandy" bit (see below)|
  2477. |              *         4    The interpreter sets this if it cannot|
  2478. |                               produce a status line|
  2479. |              *         5    Interpreter sets if it _can_ split the screen|
  2480. |                               (only `Seastalker' uses this in V3)|
  2481. |              *         6    Interpreter sets if it uses non-fixed-space|
  2482. |                               fonts|
  2483. |                        7    (unused)|
  2484. |      4       *   Flags 1:   Interpreter sets bits to say what it can do:|
  2485. |       4      *     Bit 0    (always set)|
  2486. |       6      *              Colours available?|
  2487. |       4      *         1    (always set)|
  2488. |       6      *              Picture displaying available?|
  2489. |       4      *         2    Boldface available?|
  2490. |       4      *         3    Underlining available?|
  2491. |                             (the only one of these flags any V4/5 games|
  2492. |                             actually ever looked at)|
  2493. |       4      *         4    Fixed-space font available?|
  2494. |       6      *         5    Sound effects available?|
  2495. |                      6,7    (unused)|
  2496. |  2   1           Release number|
  2497. |  4   1           Start of code area (bytes)|
  2498. |  6   1           Main routine address (uniquely, a byte address which|
  2499. |                    points to first byte of code in routine)|
  2500. |  8   1           Dictionary address (bytes)|
  2501. |  A   1           Object table address (bytes)|
  2502. |  C   1           Global variables table address (bytes)|
  2503. |  E   1           Size of save area (bytes)|
  2504. \endlines\smallskip\hrule\endinsert
  2505.  
  2506. \pageinsert
  2507. \smallskip\hrule\beginlines
  2508. | Hex  V  Dyn Int  Contents|
  2509. \endlines\smallskip\hrule\smallskip\beginlines
  2510. | 10   3   *       Flags 2:|
  2511. |          *         Bit 0    Printer transcripting happens when the game|
  2512. |                               sets this bit|
  2513. |          *             1    The interpreter is forced to use a fixed-space|
  2514. |                               font when the game sets this bit|
  2515. |                               (does not apply in version 6?)|
  2516. |      6   *   *         2    If the interpreter thinks the status line needs|
  2517. |                               redrawing (because, e.g., the player has|
  2518. |                               dragged a menu across it) it sets this bit.|
  2519. |                               The game should notice, redraw the status|
  2520. |                               line and clear the bit itself.|
  2521. |      6                 3    If set, game wants to use pictures|
  2522. |      3                 4    Set in the Amiga version of The Lurking Horror|
  2523. |                               so presumably to do with sound effects|
  2524. |      5                      If set, game wants to use the UNDO opcodes|
  2525. |      6                 5    If set, game wants to use a mouse|
  2526. |      6                 6    If set, game wants to use colours|
  2527. |      6                 7    If set, game wants to use sound effects|
  2528. |      6                 8    If set, game wants to use menus|
  2529. |                               (In each case except bit 6, if the|
  2530. |                               interpreter cannot manage the given feature,|
  2531. |                               it should clear the relevant bit again.)|
  2532. |                        9    (unused)|
  2533. |          *   *        10    Possibly set by interpreter to indicate an error|
  2534. |                               with the printer during transcription|
  2535. |                    11-15    (unused)|
  2536. | 12   2           Serial number (six characters of ASCII, conventionally|
  2537. |                    the compilation date in the form YYMMDD)|
  2538. | 18   2           Synonyms table address (bytes)|
  2539. | 1A   3+          Length of file (in words (V3) or longwords (V4,5,6))|
  2540. | 1C   3+          Checksum of file (sum of bytes from $0040 to length|
  2541. |                    by unsigned 16-bit addition)|
  2542. | 1E   4       *   Interpreter number, identifying the machine as one of:|
  2543. |                    1   DECSystem-20     6   IBM PC|
  2544. |                    2   Apple IIe        7   Commodore 128|
  2545. |                    3   Macintosh        8   Commodore 64|
  2546. |                    4   Amiga            9   Apple IIc|
  2547. |                    5   Atari ST        10   Apple IIgs|
  2548. |                                        11   Tandy Color|
  2549. |                    The latest versions of the portable interpreters I|
  2550. |                    have seen are: InfoTaskForce 2 Version A|
  2551. |                                   Zip           6 Version B|
  2552. | 1F   4       *   Interpreter version (a single ASCII character,|
  2553. |                    conventionally running through capital letters from A)|
  2554. \endlines\smallskip\hrule\endinsert
  2555.  
  2556. \pageinsert
  2557. \smallskip\hrule\beginlines
  2558. | Hex  V  Dyn Int  Contents|
  2559. \endlines\smallskip\hrule\smallskip\beginlines
  2560. | 20   4       *   Screen height (lines): 255 means "infinite", i.e. never|
  2561. |                    worry about screen overflow and never produce [MORE]|
  2562. | 21   4       *   Screen width (characters)|
  2563. | 22   5   *   *   Leftmost screen coordinate|
  2564. | 23   5   *   *   Rightmost screen coordinate|
  2565. | 24   5   *   *   Highest screen coordinate|
  2566. | 25   5   *   *   Lowest screen coordinate|
  2567. | 26   5   *   *   Width in these coordinate terms of a character in the|
  2568. |                  current font|
  2569. | 27   5   *   *   Similarly, font height|
  2570. |                  (Note: it is perfectly permissible for 22 to 25 to be|
  2571. |                  character grid positions, and the width and height both|
  2572. |                  to be 1: or they could all be in pixels.)|
  2573. | 22   6       *   Screen width in pixels|
  2574. | 24   6       *   Screen height in pixels|
  2575. | 26   6   *   *   Font height in pixels|
  2576. | 27   6   *   *   Font width in pixels (defined as width of a '0')|
  2577. |                  (Note: 22-27 are similar in V6 to V5, with the coordinates|
  2578. |                  now being pixels, but the highest and leftmost slots are|
  2579. |                  dropped (both values being 1) to give room for 2-byte values,|
  2580. |                  i.e. for resolutions of more than 255 pixels.)|
  2581. | 28   6           Functions extra offset (longwords): this may be 0.  It is|
  2582. |                    added to all function addresses and effectively allows|
  2583. |                    the program to exceed the 256K maximum address space|
  2584. |                    by the size of the save area|
  2585. | 2A   6           Static strings extra offset (longwords): similar (needed|
  2586. |                    since static strings come last, after the functions)|
  2587. | 2C   6       *   Default background colour|
  2588. | 2D   6       *   Default foreground colour|
  2589. | 2E   6           Address of terminating characters table (bytes)|
  2590. | 30   6   *   *   Slot used when the output_stream is to memory, to record|
  2591. |                    total width of text in pixels|
  2592. | 32  ---          (these 2 bytes unused in any version)|
  2593. | 34   5           Character set table address (bytes), or 0 if the default|
  2594. |                    character set is to be used|
  2595. | 36   6           Mouse data table address (bytes)|
  2596. | 38   6       *   8 bytes of ASCII: the player's user-name on Infocom's|
  2597. |                    own mainframe, used for debugging purposes and|
  2598. |                    possibly allowing users access to special features.|
  2599. \endlines\smallskip\hrule\bigskip
  2600. \noindent Some early version-3 files do not contain length and checksum
  2601. data, hence the mysterious |3+|.
  2602. \endinsert
  2603.  
  2604. \subtitle{The ``Tandy" bit}
  2605.  
  2606. Some early Infocom games were sold by the Tandy Corporation, who seem to
  2607. have been sensitive souls.  `Zork I' pretends not to have sequels if it
  2608. finds this bit set.  And to quote Paul David Doherty:
  2609. \quote
  2610.    In `The Witness', the Tandy Flag can be set while playing the game,
  2611.    by typing |$DB| and then |$TA|.  If it is set, some of the prose will be
  2612.    less offensive. For example, ``private dicks" become ``private eyes",
  2613.    ``bastards" are only ``idiots", and all references to ``slanteyes" and
  2614.    ``necrophilia" are removed.
  2615. \endquote
  2616. We live in an age of censorship.
  2617.  
  2618. \subtitle{The character set table}
  2619.  
  2620. Is 78 bytes long, arranged as 3 blocks of 26 ASCII values for what
  2621. characters to print when translating text.  (The first two characters of
  2622. block 3 are ignored anyway as they correspond to newline and the literal
  2623. escape code.)  This feature is implemented by Zip but not ITF, which
  2624. means that the German translation of `Zork I' (which uses the character
  2625. set for non-English letters like 'sz') is illegible on it.
  2626.  
  2627. \subtitle{The terminating characters table}
  2628.  
  2629. Is a zero-terminated list of character codes which cause |read| to finish
  2630. (other than new-line).  An entry of 255 means that any function key
  2631. terminates input.
  2632.  
  2633. \subtitle{The mouse data table}
  2634.  
  2635. Seems to have been intended to grow at some future time, because the first
  2636. word is the length of it.  But the only data is the second and third words:
  2637. the mouse x and y coordinates respectively.  The interpreter writes these
  2638. and they alter.
  2639.  
  2640.  
  2641. \section{11}{A few statistics}
  2642.  
  2643.  
  2644. To give some idea of the sizes found in typical story files, here are a few
  2645. statistics, mostly gathered by Paul David Doherty, whose ``fact sheet" file
  2646. contains many more.
  2647.  
  2648. \medskip
  2649. (i) {\sl Length}\quad
  2650.   The shortest files are those dating from the time of the `Zork'
  2651.   trilogy, at about 85K; middle-period version 3 games are typically 105K,
  2652.   and only the latest use the full memory map.  In versions 4 and 5, only
  2653.   `Trinity', `A Mind Forever Voyaging' and `Beyond Zork' use the full 256K.
  2654.   `Border Zone' and `Sherlock', for instance, are about 180K.  (The author's
  2655.   short story `Balances' is about 50K, an edition of `Adventure' takes 80K,
  2656.   and `Curses' about 240K.)
  2657.  
  2658.  
  2659. \medskip
  2660. (ii) {\sl Code size}\quad
  2661.   `Zork I' uses only about 5500 opcodes, but the number rises
  2662.   steeply with later games; `Hollywood Hijinx' has 10355 and, e.g.
  2663.   `Moonmist' has 15900 (both these being version 3).  Against this, `A Mind
  2664.   Forever Voyaging' has only 18700, and only `Trinity' and `Beyond Zork'
  2665.   reach 32000 or so.  (Inform games are more efficiently compiled and make
  2666.   better use of common code - the library - so perform much better here:
  2667.   the version 3, release 10 of `Curses' (128K long, and a larger game than
  2668.   any Infocom v3 game) has only 6720 opcodes.)
  2669.  
  2670.  
  2671. \medskip
  2672. (iii) {\sl Objects and rooms}\quad
  2673.   Obviously, this varies greatly with the style of
  2674.   game.  `Zork I' has 110 rooms and 60 takeable objects, but several quite
  2675.   complex games have as few as 30 rooms (the mysteries, or `Hitch-hikers'). 
  2676.   The average for version-3 games is 69 rooms, 39 takeable objects.
  2677.  
  2678.   `A Mind Forever Voyaging' contains many rooms (178) but few objects (30). 
  2679.   `Trinity', a more typical style of game, contains 134 rooms and 49
  2680.   objects: the version-5 `Curses' has a few more of each.  Of the version-6
  2681.   games, only `Zork Zero' scores highly here, with 215 rooms and 106
  2682.   objects.  The average for version 4/5 games is 105 rooms and 54 objects.
  2683.  
  2684.  
  2685. \medskip
  2686. (iv) {\sl Dictionary}\quad  Early games such as `Zork I' know about 600 words, but
  2687.   again this rises steeply to about 1000 even in v3.  Later games know
  2688.   1569 (`Beyond Zork') to the record, 2120 (`Trinity').  (This is achieved
  2689.   by heroic inclusion of unlikely synonyms: e.g. the Japanese lady with the
  2690.   umbrella can be called WOMAN, LADY, CRONE, MADAM, MADAME, MATRON, DAME or
  2691.   FACE with any of the adjectives OLD, AGED, ANCIENT, JAP, JAPANESE,
  2692.   ORIENTAL or YELLOW.)  V6 games have smaller dictionaries.
  2693.  
  2694. \vfill\eject
  2695. \end
  2696.