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.
This commit is contained in:
Jared Miller 2026-02-09 21:03:10 -05:00
parent e0e2e84dc2
commit 61765fa6ba
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -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