Skip to main content

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).

From the file ITEM.DAT to the game. The file holds, in order: Items (count, 14 bytes each); Names (count, 35 bytes each). The game: Copy the records into the item table; Read the names. In memory: The item table of 600 entries (ItemRuntime) and the item names. Used by: Inventory and floors, Scripts, Item names.
The game turns it into the item table of 600 entries (ItemRuntime) and the item names.

Organization​

PartSizeContents
Itemscount, then 14 bytes eachInitial item records, copied as they are into the runtime item table.
Namescount, then 35 bytes eachFixed-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

Sources​

Locations refer to the game executable reference; comparative sources are listed in the technical references (REF-MW-010).

Footnotes​

  1. ITEM.DAT loader, run with the other set-up routines of overlay 249 before the start menu, and the loaded counts. ↩

  2. Read a saved game. ↩

  3. Item records; wand charges are counted by casting a spell from an item. ↩

  4. Item-chain insertion and unlinking and neighbouring links. ↩

  5. Rebuild the block item chains and chain insertion. ↩

  6. Item name selection, the inventory search, the string helpers and the name tests of script conditions. The fonts are FONT6.FNT and FONT8.FNT in the file inventory. ↩

  7. Text output, its character reader and the character-pair tables; the display drivers' text routine and glyph drawer, and the EGA text routine. ↩