Skip to main content

A Z-machine interpreter in Python, targeting v3 story files

Project description

yazm-py

Yet Another Z-Machine in Python — an interpreter for Infocom interactive fiction games.

Currently targets version 3 story files (.z3), such as the original Zork trilogy, Hitchhiker's Guide, and other classic Infocom titles.

Features

  • Fetch-decode-execute VM for Z-machine v3 bytecode
  • Full object system with tree traversal (parent/child/sibling)
  • ZSCII text decoding with alphabet tables, abbreviations, and Unicode extensions
  • Dictionary tokenization and input parsing
  • Terminal UI with ANSI status bar and optional object highlighting
  • Plain output mode (--plain) for clean piped/diffable output
  • Interactive debugger with commands like $tree, $dict, $room, $find
  • Pure Python 3.12+ with no runtime dependencies

Installation

Requires uv:

uv sync

Usage

# Run a game
yazm minizork.z3

# Disable object name highlighting
yazm --no-highlight lurkinghorror.z3

# Plain mode (no ANSI codes, suitable for piping)
yazm --plain czech.z3

# Run directly without installing
python -m yazm.main minizork.z3

Development

# Run all tests
pytest

# Run a single test file
pytest tests/test_zdata.py

# Lint and format
ruff check src/ tests/
ruff format src/ tests/

# Type check
uvx ty check

Architecture

The interpreter follows a fetch-decode-execute VM pattern:

File Role
zmachine.py Core ZMachine class: memory, object system, instruction loop, dictionary/tokenization
zinstruction.py Decodes variable-length bytecode (LONG, SHORT, VAR, EXT forms) into Instruction dataclasses
ops.py ~50 opcode handlers dispatched via DISPATCH_TABLE (control flow, arithmetic, objects, I/O, etc.)
zdata.py ZData(bytearray) with big-endian u8/u16 reads/writes and sequential Reader/Writer helpers
zheader.py Parses the 64-byte story file header (version, memory layout, flags)
frame.py Call stack Frame: resume address, local variables, evaluation stack, argument count
zscii.py ZSCII text encoding: 5-bit packed characters, 3 alphabet tables, abbreviation expansion
zui_std.py Terminal UI: ANSI status bar, styled output, plain mode
zdebug.py Interactive debugger ($tree, $dict, $room, $find, etc.)
enums.py Opcode IntEnum (~100 opcodes), operand type enums, opcode name mappings
options.py Options dataclass for runtime config (save dir, RNG seed, highlighting)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yazm_py-0.1.0.tar.gz (44.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yazm_py-0.1.0-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

File details

Details for the file yazm_py-0.1.0.tar.gz.

File metadata

  • Download URL: yazm_py-0.1.0.tar.gz
  • Upload date:
  • Size: 44.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for yazm_py-0.1.0.tar.gz
Algorithm Hash digest
SHA256 779fdd75d679361dc90e4124afdd70f318f594dd520f53b5c0d90f7edb3681f1
MD5 be2311540cabb155f905fcd8e7c5063f
BLAKE2b-256 fa2dc58381d8b69460681ad3b54bb5176e1eeb487629fbfc894ee2f2886ca74f

See more details on using hashes here.

File details

Details for the file yazm_py-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: yazm_py-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 30.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.4

File hashes

Hashes for yazm_py-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2ff9974905a0b816176779891cf02b60d2ddfb0d198ed3ca0daa32c9093d0df9
MD5 7f47f1ac381ac994c1053afcafb4a5c4
BLAKE2b-256 48dec394e7633e0648efdaef13e1468d31f0c4422793b1618b0bb5b84a3942b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page