diff --git a/src/mudlib/zmachine/quetzal.py b/src/mudlib/zmachine/quetzal.py index 730eb9d..19e3dd8 100644 --- a/src/mudlib/zmachine/quetzal.py +++ b/src/mudlib/zmachine/quetzal.py @@ -214,13 +214,16 @@ class QuetzalParser: evalstack_size = (bytes[ptr] << 8) + bytes[ptr + 1] ptr += 2 - # read anywhere from 0 to 15 local vars + # read anywhere from 0 to 15 local vars, pad to 15 + num_locals = flags_bitfield[0:4] local_vars = [] - for _i in range(flags_bitfield[0:4]): + for _i in range(num_locals): var = (bytes[ptr] << 8) + bytes[ptr + 1] ptr += 2 local_vars.append(var) - log(f" Found {len(local_vars)} local vars") + # runtime expects 15 slots, save only stores declared count + local_vars.extend([0] * (15 - num_locals)) + log(f" Found {num_locals} local vars (padded to 15)") # least recent to most recent stack values: stack_values = []