Fix 7-bit truncation bug in write_global corrupting game state

This commit is contained in:
Jared Miller 2026-02-09 21:45:54 -05:00
parent 311a67e80a
commit e5329d6788
Signed by: shmup
GPG key ID: 22B5C6D66A38B06C

View file

@ -5,7 +5,6 @@
# root directory of this distribution. # root directory of this distribution.
# #
from . import bitfield
from .zlogging import log from .zlogging import log
# This class that represents the "main memory" of the z-machine. It's # This class that represents the "main memory" of the z-machine. It's
@ -317,9 +316,8 @@ class ZMemory:
raise ZMemoryIllegalWrite(value) raise ZMemoryIllegalWrite(value)
log(f"Write {value} to global variable {varnum}") log(f"Write {value} to global variable {varnum}")
actual_address = self._global_variable_start + ((varnum - 0x10) * 2) actual_address = self._global_variable_start + ((varnum - 0x10) * 2)
bf = bitfield.BitField(value) self._memory[actual_address] = (value >> 8) & 0xFF
self._memory[actual_address] = bf[8:15] self._memory[actual_address + 1] = value & 0xFF
self._memory[actual_address + 1] = bf[0:7]
# The 'verify' opcode and the QueztalWriter class both need to have # The 'verify' opcode and the QueztalWriter class both need to have
# a checksum of memory generated. # a checksum of memory generated.