Zork (Dungeon) built with Zig 0.17, wrapping the C port of the MIT mainframe game in one executable with its game data embedded.
README.md

zig-zork #

Zork (a.k.a. Dungeon), built with the Zig build system.

This project packages devshane/zork — the C port of the original 1977–1981 MIT mainframe Zork — using zig build in place of the original Makefile. The game source is pulled in as a Zig package dependency; no code is vendored here.

One file of it is replaced. Upstream's dinit.c sets up the game by reading the database dtextc.dat from a path compiled into the binary; src/dinit.zig exports the same C symbols but embeds the database with @embedFile, so the executable is self-contained and runs from anywhere, with no data file to install.

Source #

The repository lives at https://git.jcollie.dev/jeff/zig-zork:

git clone https://git.jcollie.dev/jeff/zig-zork.git

It is mirrored on Tangled at https://tangled.org/jcollie.dev/zig-zork.

Requirements #

  • Zig 0.17
  • termcap (headers and library)
  • A C compiler is not needed separately — Zig compiles the C sources.

Building #

zig build

The results land in zig-out/:

  • zig-out/bin/zig-zork — the game, with its data built in
  • zig-out/share/man/man6/dungeon.6 — the manpage

To build and play in one step:

zig build run

zig build test plays a few moves and checks that the game answers them.

Build options #

Option Default Description
-Dallow-gdt false Enable the in-game debugging tool, invoked by typing gdt. Not much use except for debugging.
-Doptimize=... Debug Standard Zig optimization mode, e.g. ReleaseSafe or ReleaseFast.
-Dtarget=... native Standard Zig cross-compilation target.

Nix #

A flake is included:

# Play the game
nix run .#zig-zork

# Build the package
nix build .#zig-zork

# Development shell with Zig, termcap, and tooling
nix develop

The flake builds with Zig's --system mode using dependencies pre-fetched via zon2nix; after changing dependencies in build.zig.zon, regenerate build.zig.zon.nix with:

nix develop -c zon2nix --17 --nix=build.zig.zon.nix build.zig.zon

nixpkgs has no Zig 0.17 yet, so the flake takes the 0.17.0 release from zig-overlay.

Playing #

You are standing in an open field west of a white house, with a boarded front door. Type commands like open mailbox, go north, or take lamp. See the dungeon(6) manpage for details, or type help in-game. Save yourself some grief: don't wake the thief.

References cited #

The entries are kept in the zig-zork collection in Zotero.