Compare commits

..

No commits in common. "909ee0932bbd64796007b01b4ba214559082c893" and "e72f13e78a042b57128fb263457d8c14acd4da0e" have entirely different histories.

2 changed files with 17 additions and 29 deletions

View file

@ -12,30 +12,14 @@
# root directory of this distribution.
#
# Woohoo! Python has a module to parse IFF files, which is a generic
# interchange format. A Quetzal file is in fact a type of IFF file.
import chunk
import os
import struct
from . import bitfield, zstackmanager
from .zlogging import log
def _read_iff_chunk(f):
"""Read one IFF chunk from a file-like object. Returns (name, data).
Raises EOFError when there are no more chunks to read.
"""
header = f.read(8)
if len(header) < 8:
raise EOFError
name = header[:4]
(size,) = struct.unpack(">I", header[4:8])
data = f.read(size)
# IFF chunks are padded to even byte boundaries
if size % 2 == 1:
f.read(1)
return name, data
# The general format of Queztal is that of a "FORM" IFF file, which is
# a container class for 'chunks'.
#
@ -355,8 +339,10 @@ class QuetzalParser:
log("Parsing chunks from byte data")
try:
while 1:
chunkname, chunk_data = _read_iff_chunk(self._file)
chunksize = len(chunk_data)
c = chunk.Chunk(self._file)
chunkname = c.getname()
chunksize = c.getsize()
chunk_data = c.read(chunksize)
log(f"** Found chunk ID {chunkname}: length {chunksize}")
self._last_loaded_metadata[chunkname] = chunksize
@ -420,8 +406,10 @@ class QuetzalParser:
try:
while 1:
chunkname, data = _read_iff_chunk(self._file)
chunksize = len(data)
c = chunk.Chunk(self._file)
chunkname = c.getname()
chunksize = c.getsize()
data = c.read(chunksize)
log(f"** Found chunk ID {chunkname}: length {chunksize}")
self._last_loaded_metadata[chunkname] = chunksize

View file

@ -104,7 +104,6 @@ class ZStackBottom:
def __init__(self):
self.program_counter = 0 # used as a cache only
self.return_addr = None
self.stack = []
self.local_vars = [0 for _ in range(15)]
@ -202,14 +201,15 @@ class ZStackManager:
current_routine = self._call_stack[-1]
# Depending on many things, return stuff.
if exiting_routine.return_addr is not None:
if exiting_routine.return_addr == 0:
if exiting_routine.return_addr is not None: # type: ignore[possibly-missing-attribute]
if exiting_routine.return_addr == 0: # type: ignore[possibly-missing-attribute]
# Push to stack
self.push_stack(return_value)
elif 0 < exiting_routine.return_addr < 0x10:
elif 0 < exiting_routine.return_addr < 0x10: # type: ignore[possibly-missing-attribute]
# Store in local var
self.set_local_variable(exiting_routine.return_addr - 1, return_value)
self.set_local_variable(exiting_routine.return_addr - 1, return_value) # type: ignore[possibly-missing-attribute]
else:
# Store in global var
self._memory.write_global(exiting_routine.return_addr, return_value)
self._memory.write_global(exiting_routine.return_addr, return_value) # type: ignore[possibly-missing-attribute]
return current_routine.program_counter