Types for the Z-Machine interpreter.
Import this module to pattern match on result types:
import ZMachine.Types exposing (StepResult(..), OutputEvent(..))Opaque Z-Machine memory image, re-exported so consumers can annotate
ZMachine fields without a second import.
A single call stack frame, re-exported so consumers can annotate
ZMachine fields without a second import.
Opaque snapshot of Z-Machine state, produced by the save path and
consumed by the restore path. See ZMachine.Snapshot
for operations.
Result of executing one or more instructions.
Every variant carries a List OutputEvent containing the output
accumulated during the call that produced this result, followed by the
current ZMachine. The returned machine's output buffer is always
empty — the run-loop drains it into the variant, so callers never need
to manage output state themselves.
Continue — step budget exhausted, call
ZMachine.runSteps again to keep going.NeedInput — the machine is waiting for a line of player input.
Call ZMachine.provideInput to resume.NeedChar — the machine is waiting for a single keypress.
Call ZMachine.provideChar to resume.NeedSave — the story executed a save opcode. The attached
snapshot captures the state to be persisted; call
ZMachine.provideSaveResult to resume.NeedRestore — the story executed a restore opcode. Call
ZMachine.provideRestoreResult
with a snapshot (or Nothing on failure) to resume.Halted — the story called quit.Error — an unrecoverable error occurred.Errors that can halt the machine.
DivisionByZero — a div or mod instruction divided by zero.StackUnderflow — a pop from an empty evaluation stack.InvalidOpcode — an unrecognised opcode number.InvalidVariable — a variable reference outside 0–255.Metadata about a line-input request from sread/aread.
Carried by the NeedInput variant of StepResult.
Structured output events for the host to render.
PrintText — display a string. Line breaks are embedded as \n
in the string; consecutive prints are coalesced into a single
event, so a rendered paragraph typically arrives as one
PrintText.PrintObject — display a string that the game identified as an
object's short name (via print_obj or print_addr). Rendered
identically to PrintText; split out so clients can learn the
names of the objects the game refers to.ShowStatusLine — update the status bar with a StatusLine.SetBufferMode — enable or disable word-wrap buffering.SetTextStyle — change text style (bold, italic, etc.).SetColour — change foreground/background colours.PlaySound — play a sound effect by number.Status line data shown at the top of the screen.
locationId — the object number of the current location.locationName — the short name of the current location.mode — score/turns, time, or raw screen rows depending on version.How the status line content is provided.
ScoreAndTurns score turns — V3 score game.TimeOfDay hours minutes — V3 time game (hours 0–23, minutes 0–59).ScreenRows rows — V5+ game that draws its own status area.
Each string is one rendered row of the upper window, trimmed.Screen window identifier. Z-Machine v3 has two windows:
Upper — the fixed-size status area at the top.Lower — the scrolling main text area.Virtual upper window state. V5 games draw the status line by
writing directly to the upper window with cursor positioning. The
interpreter tracks this internally and emits a ShowStatusLine event
when the game switches back to the lower window.
The complete state of a running Z-Machine. You will receive this inside each
StepResultvariant.