From 61765fa6ba3e7e5023f247ebe212bc13360001d8 Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Mon, 9 Feb 2026 21:03:10 -0500 Subject: [PATCH] Allow game writes to header region in dynamic memory write_word() was routing all header writes through game_set_header() which enforced overly strict per-byte permissions. Zork 1 legitimately writes to header address 2 on startup. Now uses the same dynamic/static boundary check that viola does, matching the reference implementation. --- src/mudlib/zmachine/zmemory.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/mudlib/zmachine/zmemory.py b/src/mudlib/zmachine/zmemory.py index 4f0f012..87c5d30 100644 --- a/src/mudlib/zmachine/zmemory.py +++ b/src/mudlib/zmachine/zmemory.py @@ -262,17 +262,12 @@ class ZMemory: """Write the given 16-bit value at ADDRESS, ADDRESS+1.""" if address < 0 or address >= (self._total_size - 1): raise ZMemoryOutOfBounds - # Handle writing of a word to the game headers. If write_word is - # used for this, we assume that it's the game that is setting the - # header. The interpreter should use the specialized method. value_msb = (value >> 8) & 0xFF value_lsb = value & 0xFF - if 0 <= address < 64: - self.game_set_header(address, value_msb) - self.game_set_header(address + 1, value_lsb) - else: - self._memory[address] = value_msb - self._memory[address + 1] = value_lsb + self._check_static(address) + self._check_static(address + 1) + self._memory[address] = value_msb + self._memory[address + 1] = value_lsb # Normal sequence syntax cannot be used to set bytes in the 64-byte # header. Instead, the interpreter or game must call one of the