Compare commits
No commits in common. "74538756d5bb44dd475c435259d14a21e0e1390c" and "909ee0932bbd64796007b01b4ba214559082c893" have entirely different histories.
74538756d5
...
909ee0932b
5 changed files with 6 additions and 58 deletions
|
|
@ -36,20 +36,6 @@ class EmbeddedIFSession:
|
|||
self._zmachine = ZMachine(story_bytes, self._ui)
|
||||
self._filesystem = self._ui.filesystem
|
||||
|
||||
def _strip_prompt(self, output: str) -> str:
|
||||
"""Strip trailing > prompt from game output (matches dfrotz behavior)."""
|
||||
has_prompt = (
|
||||
output.endswith("> ") or output.endswith(">\n") or output.endswith(">\r\n")
|
||||
)
|
||||
text = output.rstrip()
|
||||
if text.endswith("\n>"):
|
||||
return text[:-2].rstrip()
|
||||
if text == ">":
|
||||
return ""
|
||||
if has_prompt and text.endswith(">"):
|
||||
return text[:-1].rstrip()
|
||||
return output
|
||||
|
||||
@property
|
||||
def save_path(self) -> Path:
|
||||
safe_name = re.sub(r"[^a-zA-Z0-9_-]", "_", self.player.name)
|
||||
|
|
@ -114,7 +100,6 @@ class EmbeddedIFSession:
|
|||
# buffer), producing unwanted output. Suppress it and only show the
|
||||
# restore confirmation.
|
||||
return "restoring saved game...\r\nrestored."
|
||||
output = self._strip_prompt(output)
|
||||
return output
|
||||
|
||||
async def handle_input(self, text: str) -> IFResponse:
|
||||
|
|
@ -145,7 +130,6 @@ class EmbeddedIFSession:
|
|||
await loop.run_in_executor(None, wait_for_next_input)
|
||||
|
||||
output = self._screen.flush()
|
||||
output = self._strip_prompt(output)
|
||||
if self._done and self._error:
|
||||
output = f"{output}\r\n{self._error}" if output else self._error
|
||||
return IFResponse(output=output, done=self._done)
|
||||
|
|
@ -165,8 +149,7 @@ class EmbeddedIFSession:
|
|||
except Exception as e:
|
||||
tb = traceback.format_exc()
|
||||
logger.error(f"Interpreter crashed:\n{tb}")
|
||||
msg = str(e) or type(e).__name__
|
||||
self._error = f"interpreter error: {msg}"
|
||||
self._error = f"interpreter error: {e}"
|
||||
finally:
|
||||
self._done = True
|
||||
self._keyboard._waiting.set()
|
||||
|
|
|
|||
|
|
@ -315,7 +315,8 @@ async def shell(
|
|||
if player.mode == "editor" and player.editor:
|
||||
_writer.write(f" {player.editor.cursor + 1}> ")
|
||||
elif player.mode == "if" and player.if_session:
|
||||
_writer.write("> ")
|
||||
# IF mode: game writes its own prompt, don't add another
|
||||
pass
|
||||
else:
|
||||
_writer.write("mud> ")
|
||||
await _writer.drain()
|
||||
|
|
|
|||
|
|
@ -107,9 +107,7 @@ class MudInputStream(zstream.ZInputStream):
|
|||
text = self._input_queue.get()
|
||||
if text:
|
||||
return ord(text[0])
|
||||
# Player hit Enter with no text — return 13 (ZSCII Enter/Return)
|
||||
# so "press any key" prompts work in a line-oriented MUD client.
|
||||
return 13
|
||||
return 0
|
||||
|
||||
def feed(self, text: str):
|
||||
self._input_queue.put(text)
|
||||
|
|
|
|||
|
|
@ -226,27 +226,17 @@ class ZCpu:
|
|||
return table
|
||||
|
||||
def step_fast(self):
|
||||
"""Execute a single instruction with lightweight tracing.
|
||||
"""Execute a single instruction without tracing.
|
||||
|
||||
Returns True if execution should continue.
|
||||
"""
|
||||
current_pc = self._opdecoder.program_counter
|
||||
(opcode_class, opcode_number, operands) = self._opdecoder.get_next_instruction()
|
||||
entry = self._dispatch[opcode_class][opcode_number]
|
||||
if entry is None:
|
||||
self._trace.append(f" {current_pc:06x} ILLEGAL")
|
||||
self._dump_trace()
|
||||
raise ZCpuIllegalInstruction(
|
||||
f"illegal opcode class={opcode_class} num={opcode_number}"
|
||||
f" at PC={current_pc:#x}"
|
||||
)
|
||||
raise ZCpuIllegalInstruction
|
||||
implemented, func = entry
|
||||
if not implemented:
|
||||
return False
|
||||
self._trace.append(
|
||||
f" {current_pc:06x} {func.__name__}"
|
||||
f"({', '.join(str(x) for x in operands)})"
|
||||
)
|
||||
try:
|
||||
func(self, *operands)
|
||||
except (ZCpuQuit, ZCpuRestart):
|
||||
|
|
|
|||
|
|
@ -163,8 +163,6 @@ class ZObjectParser:
|
|||
def get_attribute(self, objectnum, attrnum):
|
||||
"""Return value (0 or 1) of attribute number ATTRNUM of object
|
||||
number OBJECTNUM."""
|
||||
if objectnum == 0:
|
||||
return 0
|
||||
|
||||
object_addr = self._get_object_addr(objectnum)
|
||||
|
||||
|
|
@ -185,8 +183,6 @@ class ZObjectParser:
|
|||
|
||||
def set_attribute(self, objectnum, attrnum):
|
||||
"""Set attribute number ATTRNUM of object number OBJECTNUM to 1."""
|
||||
if objectnum == 0:
|
||||
return
|
||||
|
||||
object_addr = self._get_object_addr(objectnum)
|
||||
|
||||
|
|
@ -210,8 +206,6 @@ class ZObjectParser:
|
|||
|
||||
def clear_attribute(self, objectnum, attrnum):
|
||||
"""Clear attribute number ATTRNUM of object number OBJECTNUM to 0."""
|
||||
if objectnum == 0:
|
||||
return
|
||||
|
||||
object_addr = self._get_object_addr(objectnum)
|
||||
|
||||
|
|
@ -253,24 +247,18 @@ class ZObjectParser:
|
|||
|
||||
def get_parent(self, objectnum):
|
||||
"""Return object number of parent of object number OBJECTNUM."""
|
||||
if objectnum == 0:
|
||||
return 0
|
||||
|
||||
[parent, sibling, child] = self._get_parent_sibling_child(objectnum)
|
||||
return parent
|
||||
|
||||
def get_child(self, objectnum):
|
||||
"""Return object number of child of object number OBJECTNUM."""
|
||||
if objectnum == 0:
|
||||
return 0
|
||||
|
||||
[parent, sibling, child] = self._get_parent_sibling_child(objectnum)
|
||||
return child
|
||||
|
||||
def get_sibling(self, objectnum):
|
||||
"""Return object number of sibling of object number OBJECTNUM."""
|
||||
if objectnum == 0:
|
||||
return 0
|
||||
|
||||
[parent, sibling, child] = self._get_parent_sibling_child(objectnum)
|
||||
return sibling
|
||||
|
|
@ -310,8 +298,6 @@ class ZObjectParser:
|
|||
|
||||
def remove_object(self, objectnum):
|
||||
"""Detach object OBJECTNUM from its parent (unlink from sibling chain)."""
|
||||
if objectnum == 0:
|
||||
return
|
||||
|
||||
parent = self.get_parent(objectnum)
|
||||
if parent == 0:
|
||||
|
|
@ -349,8 +335,6 @@ class ZObjectParser:
|
|||
Per the Z-spec: if new_child already has a parent, it is first
|
||||
removed from that parent's child list, then made the first child
|
||||
of parent_object."""
|
||||
if parent_object == 0 or new_child == 0:
|
||||
return
|
||||
|
||||
# Remove from old parent first (spec says "first removed")
|
||||
self.remove_object(new_child)
|
||||
|
|
@ -363,8 +347,6 @@ class ZObjectParser:
|
|||
|
||||
def get_shortname(self, objectnum):
|
||||
"""Return 'short name' of object number OBJECTNUM as ascii string."""
|
||||
if objectnum == 0:
|
||||
return ""
|
||||
|
||||
addr = self._get_proptable_addr(objectnum)
|
||||
return self._stringfactory.get(addr + 1)
|
||||
|
|
@ -372,8 +354,6 @@ class ZObjectParser:
|
|||
def get_prop(self, objectnum, propnum):
|
||||
"""Return either a byte or word value of property PROPNUM of
|
||||
object OBJECTNUM."""
|
||||
if objectnum == 0:
|
||||
return 0
|
||||
(addr, size) = self.get_prop_addr_len(objectnum, propnum)
|
||||
if size == 1:
|
||||
return self._memory[addr]
|
||||
|
|
@ -487,8 +467,6 @@ class ZObjectParser:
|
|||
def get_property_data_address(self, objectnum, propnum):
|
||||
"""Return the address of property PROPNUM's data bytes for object
|
||||
OBJECTNUM. Return 0 if the object doesn't have that property."""
|
||||
if objectnum == 0:
|
||||
return 0
|
||||
|
||||
try:
|
||||
addr, size = self.get_prop_addr_len(objectnum, propnum)
|
||||
|
|
@ -506,8 +484,6 @@ class ZObjectParser:
|
|||
"""If PROPNUM is 0, return the first property number of object OBJECTNUM.
|
||||
Otherwise, return the property number after PROPNUM in the property list.
|
||||
Return 0 if there are no more properties."""
|
||||
if objectnum == 0:
|
||||
return 0
|
||||
|
||||
if propnum == 0:
|
||||
# Return first property number
|
||||
|
|
|
|||
Loading…
Reference in a new issue