Revision: 66452209ff
Author: Ben Collins-Sussman <sus...@red-bean.com>
Date: Wed May 27 15:38:42 2009
Log: Implement rtrue and rfalse opcodes. Plus some docstrings.
http://code.google.com/p/zvm/source/detail?r=66452209ff
Revision: bd6fd89b1c
Author: Ben Collins-Sussman <sus...@red-bean.com>
Date: Wed May 27 17:36:20 2009
Log: Implement get_prop opcode, and fix rtrue, rfalse opcodes.
http://code.google.com/p/zvm/source/detail?r=bd6fd89b1c
==============================================================================
Revision: 66452209ff
Author: Ben Collins-Sussman <sus...@red-bean.com>
Date: Wed May 27 15:38:42 2009
Log: Implement rtrue and rfalse opcodes. Plus some docstrings.
http://code.google.com/p/zvm/source/detail?r=66452209ff
Modified:
/zvm/zcpu.py
/zvm/zstackmanager.py
/zvm/zstreammanager.py
=======================================
--- /zvm/zcpu.py Wed May 27 15:36:21 2009
+++ /zvm/zcpu.py Wed May 27 15:38:42 2009
@@ -417,12 +417,12 @@
## 0OP opcodes (opcodes 176-191)
def op_rtrue(self, *args):
- """TODO: Write docstring here."""
- raise ZCpuNotImplemented
+ """Make the current routine return true (1)."""
+ self._stackmanager.finish_routine(1)
def op_rfalse(self, *args):
- """TODO: Write docstring here."""
- raise ZCpuNotImplemented
+ """Make the current routine return false (0)."""
+ self._stackmanager.finish_routine(0)
def op_print(self):
"""Print the embedded ZString."""
=======================================
--- /zvm/zstackmanager.py Sun Dec 2 09:43:16 2007
+++ /zvm/zstackmanager.py Wed May 27 15:38:42 2009
@@ -29,7 +29,7 @@
pass
# Helper class used by ZStackManager; a 'routine' object which
-# includes its own privae stack of data.
+# includes its own private stack of data.
class ZRoutine(object):
def __init__(self, start_addr, return_addr, zmem, args,
=======================================
--- /zvm/zstreammanager.py Wed May 27 15:36:21 2009
+++ /zvm/zstreammanager.py Wed May 27 15:38:42 2009
@@ -9,10 +9,10 @@
# Constants for output streams. These are human-readable names for
# the stream ID numbers as described in sections 7.1.1 and 7.1.2
# of the Z-Machine Standards Document.
-OUTPUT_SCREEN = 1
-OUTPUT_TRANSCRIPT = 2
-OUTPUT_MEMORY = 3
-OUTPUT_PLAYER_INPUT = 4
+OUTPUT_SCREEN = 1 # spews text to the the screen
+OUTPUT_TRANSCRIPT = 2 # contains everything player typed, plus our
responses
+OUTPUT_MEMORY = 3 # if the z-machine wants to write to memory
+OUTPUT_PLAYER_INPUT = 4 # contains *only* the player's typed commands
# Constants for input streams. These are human-readable names for the
# stream ID numbers as described in section 10.2 of the Z-Machine
@@ -51,7 +51,7 @@
streams."""
# TODO: Implement section 7.1.2.2 of the Z-Machine Standards
- # Document, so that while stream 3 it is selected, no text is
+ # Document, so that while stream 3 is selected, no text is
# sent to any other output streams which are selected. (However,
# they remain selected.).
==============================================================================
Revision: bd6fd89b1c
Author: Ben Collins-Sussman <sus...@red-bean.com>
Date: Wed May 27 17:36:20 2009
Log: Implement get_prop opcode, and fix rtrue, rfalse opcodes.
http://code.google.com/p/zvm/source/detail?r=bd6fd89b1c
Modified:
/zvm/zcpu.py
/zvm/zobjectparser.py
=======================================
--- /zvm/zcpu.py Wed May 27 15:38:42 2009
+++ /zvm/zcpu.py Wed May 27 17:36:20 2009
@@ -262,9 +262,12 @@
val = self._memory[base+offset]
self._write_result(val)
- def op_get_prop(self, *args):
- """TODO: Write docstring here."""
- raise ZCpuNotImplemented
+ def op_get_prop(self, objectnum, propnum):
+ """Store in the given result an object's property value
+ (either a byte or word)."""
+ self._objects.describe_object(objectnum)
+ val = self._objects.get_prop(objectnum, propnum)
+ self._write_result(val)
def op_get_prop_addr(self, *args):
"""TODO: Write docstring here."""
@@ -418,11 +421,13 @@
def op_rtrue(self, *args):
"""Make the current routine return true (1)."""
- self._stackmanager.finish_routine(1)
+ pc = self._stackmanager.finish_routine(1)
+ self._opdecoder.program_counter = pc
def op_rfalse(self, *args):
"""Make the current routine return false (0)."""
- self._stackmanager.finish_routine(0)
+ pc = self._stackmanager.finish_routine(0)
+ self._opdecoder.program_counter = pc
def op_print(self):
"""Print the embedded ZString."""
=======================================
--- /zvm/zobjectparser.py Mon Apr 30 20:04:02 2007
+++ /zvm/zobjectparser.py Wed May 27 17:36:20 2009
@@ -35,6 +35,9 @@
"Unsupported z-machine version."
pass
+class ZObjectIllegalPropLength(ZObjectError):
+ "Illegal property length."
+ pass
# The interpreter should only need exactly one instance of this class.
@@ -191,6 +194,18 @@
return self._stringfactory.get(addr+1)
+ def get_prop(self, objectnum, propnum):
+ """Return either a byte or word value of property PROPNUM of
+ object OBJECTNUM."""
+ (addr, size) = self.get_prop_addr_len(objectnum, propnum)
+ if size == 1:
+ return self._memory[addr]
+ elif size == 2:
+ return self._memory.read_word(addr)
+ else:
+ raise ZObjectIllegalPropLength
+
+
def get_prop_addr_len(self, objectnum, propnum):
"""Return address & length of value for property number PROPNUM of
object number OBJECTNUM. If object has no such property, then
@@ -288,6 +303,7 @@
return proplist
+
def set_property(self, objectnum, propnum, value):
"""Set a property on an object."""
proplist = self.get_all_properties(objectnum)
@@ -302,6 +318,7 @@
else:
raise ZObjectIllegalPropertySet
+
def describe_object(self, objectnum):
"""For debugging purposes, pretty-print everything known about
object OBJECTNUM."""