-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsect01.html
200 lines (165 loc) · 7.65 KB
/
sect01.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!DOCTYPE html>
<html>
<head>
<title>The Z-Machine Standards Document</title>
<link rel="stylesheet" type="text/css" href="zspec.css">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
</head>
<body>
<img class="icon" src="images/icon01.gif" alt="">
<h1>1. The memory map</h1>
<hr>
<p>1.1 <a href="#1.1">Regions of memory</a> /
1.2 <a href="#1.2">Addresses</a></p>
<hr>
<h2 id="1.1">1.1</h2>
<p>The memory map of the Z-machine is an array of bytes with
"byte addresses" running from 0 upwards. This is divided into
three regions: "dynamic", "static" and "high". Dynamic
memory begins from byte address <strong>$00000</strong> and runs up to the byte
before the byte address stored in the word at <strong>$0e</strong> in the header.
(Dynamic memory must contain at least 64 bytes.) Static memory
follows immediately on. Its extent is not defined in the header
(or anywhere else), though it must end by the last byte of the
story file or by byte address <strong>$0ffff</strong> (whichever is lower).
High memory begins at the "high memory mark" (the byte address
stored in the word at <strong>$04</strong> in the header) and continues to the
end of the story file. The bottom of high memory may overlap with
the top of static memory (but not with dynamic memory).
</p>
<h2 id="1.1.1">1.1.1</h2>
<p>Dynamic memory can be read or written to (either directly,
using <a href="sect15.html#loadb"><strong>loadb</strong></a>, <a href="sect15.html#loadw"><strong>loadw</strong></a>,
<a href="sect15.html#storeb"><strong>storeb</strong></a> and <a href="sect15.html#storew"><strong>storew</strong></a>,
or indirectly with opcodes such as <a href="sect15.html#insert_obj"><strong>insert_obj</strong></a> and
<a href="sect15.html#remove_obj"><strong>remove_obj</strong></a>).
</p>
<h2 id="1.1.1.1">1.1.1.1</h2>
<p>By tradition, the first 64 bytes are known as the
"header". The contents of this are given later but note that games
are not permitted to alter many bits inside it.
</p>
<h2 id="1.1.1.2">1.1.1.2</h2>
<p>It is legal for games to alter any of the tables stored
in dynamic memory above the header, provided they leave the tables
in legal states.
</p>
<h2 id="1.1.2">1.1.2</h2>
<p>Static memory can be read using the opcodes <a href="sect15.html#loadb"><strong>loadb</strong></a> and
<a href="sect15.html#loadw"><strong>loadw</strong></a>. It is illegal for a game to attempt to write to static
memory.
</p>
<h2 id="1.1.3">1.1.3</h2>
<p>Except for its (possible) overlap with static memory,
high memory cannot be directly accessed at all by a
game program. It contains routines, which can be called,
and strings, which can be printed using <strong>print_paddr</strong>.
</p>
<h2 id="1.1.4">1.1.4</h2>
<p>The maximum permitted length of a story file depends
on the Version, as follows:
</p>
<pre>
V1-3 V4-5 V6-8
128K 256K 512K
</pre>
<h2 id="1.2">1.2</h2>
<p>There are three kinds of address in the Z-machine, all of
which can be stored in a 2-byte number: byte addresses, word
addresses and packed addresses.
</p>
<h2 id="1.2.1">1.2.1</h2>
<p>A byte address specifies a byte in memory in the range 0
up to the last byte of static memory.
</p>
<h2 id="1.2.2">1.2.2</h2>
<p>A word address specifies an even address in the bottom
128K of memory (by giving the address divided by 2). (Word addresses
are used only in the abbreviations table.)
</p>
<h2 id="1.2.3">1.2.3</h2>
<p><strong>***</strong>
A packed address specifies where a routine or string begins
in high memory. Given a packed address <em>P</em>, the formula to obtain the
corresponding byte address <em>B</em> is:
</p>
<pre>
2P Versions 1, 2 and 3
4P Versions 4 and 5
4P + 8R_O Versions 6 and 7, for routine calls
4P + 8S_O Versions 6 and 7, for print_paddr
8P Version 8
</pre>
<p><em>R_O</em> and <em>S_O</em> are the routine and strings offsets
(specified in the <a href="sect11.html">header</a> as words at <strong>$28</strong> and <strong>$2a</strong>,
respectively).
</p>
<h2 id="1.2.4">1.2.4</h2>
<p><strong>***</strong>
Throughout the specification, Versions 7 and 8 are identical
to Version 5 except as stated at <a href=sect01.html#1.1.4><strong>§</strong> 1.1.4</a> and
<a href=sect01.html#1.2.3><strong>§</strong> 1.2.3</a> above, and in the constant used to
find the file length, as stated in <a href=sect11.html#11.1.6><strong>§</strong> 11.1.6</a>.
</p>
<hr>
<table>
<caption><strong>An example memory map of a small game</strong></caption>
<tr><td>Dynamic </td><td> <strong>00000</strong> </td><td> header </td></tr>
<tr><td> </td><td> <strong>00040</strong> </td><td> abbreviation strings </td></tr>
<tr><td> </td><td> <strong>00042</strong> </td><td> abbreviation table </td></tr>
<tr><td> </td><td> <strong>00102</strong> </td><td> property defaults </td></tr>
<tr><td> </td><td> <strong>00140</strong> </td><td> objects </td></tr>
<tr><td> </td><td> <strong>002f0</strong> </td><td> object descriptions and properties </td></tr>
<tr><td> </td><td> <strong>006e3</strong> </td><td> global variables </td></tr>
<tr><td> </td><td> <strong>008c3</strong> </td><td> arrays </td></tr>
<tr><td> Static </td><td> <strong>00b48</strong> </td><td> grammar table </td></tr>
<tr><td> </td><td> <strong>010a7</strong> </td><td> actions table </td></tr>
<tr><td> </td><td> <strong>01153</strong> </td><td> preactions table </td></tr>
<tr><td> </td><td> <strong>01201</strong> </td><td> adjectives table </td></tr>
<tr><td> </td><td> <strong>0124d</strong> </td><td> dictionary </td></tr>
<tr><td> High </td><td> <strong>01a0a</strong> </td><td> Z-code </td></tr>
<tr><td> </td><td> <strong>05d56</strong> </td><td> static strings </td></tr>
<tr><td> </td><td> <strong>06ae6</strong> </td><td> end of file </td></tr>
</table>
<hr>
<h2>Remarks</h2>
<p>Inform never compiles any overlap between static and high memory
(it places all data tables in dynamic memory). However, many
Infocom games group tables of static data just above the high
memory mark, before routines begin; some, such as 'Nord 'n'
Bert...', interleave static data between routines, so that static
memory actually overlaps code; and a few, such as 'Seastalker'
release 15, even contain routines placed below the high memory
mark. (The original idea behind the high memory mark was that
everything below it should be stored in the interpreter's RAM, while
what was above could reasonably be kept in "virtual memory", i.e.,
loaded off disc as needed.)
</p>
<p>Note that the total of dynamic plus static memory must not exceed 64K.
(In fact, 64K minus 2 bytes.) This is the most serious limitation
on the Z-machine.
</p>
<hr>
<p>
<a href="index.html">Contents</a> /
<a href="preface.html">Preface</a> /
<a href="overview.html">Overview</a>
</p>
<p>Section
<a href="sect01.html">1</a> / <a href="sect02.html">2</a> /
<a href="sect03.html">3</a> / <a href="sect04.html">4</a> /
<a href="sect05.html">5</a> / <a href="sect06.html">6</a> /
<a href="sect07.html">7</a> / <a href="sect08.html">8</a> /
<a href="sect09.html">9</a> / <a href="sect10.html">10</a> /
<a href="sect11.html">11</a> / <a href="sect12.html">12</a> /
<a href="sect13.html">13</a> / <a href="sect14.html">14</a> /
<a href="sect15.html">15</a> / <a href="sect16.html">16</a>
</p>
<p>Appendix
<a href="appa.html">A</a> / <a href="appb.html">B</a> /
<a href="appc.html">C</a> / <a href="appd.html">D</a> /
<a href="appe.html">E</a> / <a href="appf.html">F</a>
</p>
<hr>
</body>
</html>