Initial items (ITEM.DAT)
File formats · Field reference · Schema
In brief
ITEM.DAT holds the game's initial item records and the list of item names.
Each item record says which names to show before and after the item is
identified, its type, where it is and how it is linked to other items. The
game copies the records unchanged into its item table, which then changes as
items are created, moved and removed.
Item properties shared by all items of a kind — damage, where they can be worn, who can use them — are not here but in item types (ITEMTYPE.DAT).
Organization
| Part | Size | Contents |
|---|---|---|
| Items | count, then 14 bytes each | Initial item records, copied as they are into the runtime item table. |
| Names | count, then 35 bytes each | Fixed-size name slots, read as zero-terminated text. |
The reference file holds 434 item records and 123 names. The field reference gives the fields of a record.
Reading the file
The game reads ITEM.DAT once, when the program starts, among the set-up
routines that run before the introduction and the start menu. One routine
reads both counts and arrays, and compares neither count with the room it
has.1 A saved game holds the whole item table, which
replaces the one read from the file when the game is loaded.2
What it becomes in memory
The records are copied as they are into the item table, which has 600 slots
of the same 14-byte layout,
ItemRuntime.3 Each record has two links that join items into circular
chains; when the game adds an item to a chain, it also records the block
where the item now is.4 The links are zero in every record of the
file, and the game never reads them as loaded: loading a level rebuilds the
chains of its blocks from the items lying there, and inserting an item
writes both of its links.5
Who uses it
The item table serves everything that holds or moves an item: the inventory, the floors of the levels and the scripts.
The names are used by the code that chooses an item's displayed name.6
Each name is plain text, one byte per character: the original names use
only printable ASCII, and the game's two fonts hold 128 characters in
ASCII order. Bytes 1 to 31 are control codes of the game's text output; a
byte from 0x80 up has no character of its own. The text output replaces
it by two characters taken from tables that are empty in the executable, so
it gives no character: after an ordinary character it is skipped, while at
the start of a name or right after another such byte it hides the rest
of the line. Nothing fills the tables with the original data.7 The game reads a name from the
start of its slot up to the
first zero byte, without stopping at the end of the 35-byte slot: a slot
with no zero would run on into the next one. Every slot of the original
file ends with zeros, the longest name having 29 characters.
Example
The file starts with the item count, b2 01 (434 items). The name list
starts at offset 0x17be, after the 434 records:
offset bytes meaning
17be 7b 00 123 names
17c0 4d 6f 75 73 65 20 50 6f 69 6e 74 65 72 00 name 0: "Mouse Pointer", then zeros to 35 bytes
Related pages
- Items: how items behave in the game.
- The item types: the items and values of the original file.
ItemRuntimeandItemRuntimeFlags: the runtime record and its flags.
Sources
Locations refer to the game executable reference;
comparative sources are listed in the technical references
(REF-MW-010).