diff pytouhou/game/eclrunner.py @ 42:1b0ca2fb89f9

Refactor ECL parsing/etc.
author Thibaut Girka <thib@sitedethib.com>
date Thu, 18 Aug 2011 22:11:39 +0200
parents e3ba2fa966f6
children 7195aaf95f6e
line wrap: on
line diff
--- a/pytouhou/game/eclrunner.py
+++ b/pytouhou/game/eclrunner.py
@@ -1,13 +1,10 @@
-from struct import unpack
-
-
 class ECLRunner(object):
     def __init__(self, ecl, sub, frame=0, instruction_pointer=0, implementation=None):
         self.ecl = ecl
 
         self.labels = {}
-        self.implementation = {4: ('HHI', self.set_label),
-                               3: ('IHHHH', self.goto)}
+        self.implementation = {4: (self.set_label),
+                               3: (self.goto)}
         if implementation:
             self.implementation.update(implementation)
 
@@ -16,22 +13,21 @@ class ECLRunner(object):
         self.instruction_pointer = instruction_pointer
 
 
-    def set_label(self, label, unknown, count):
-        assert unknown == 0xffff
-        self.labels[label] = (self.sub, self.instruction_pointer, count)
+    def set_label(self, label, count):
+        self.labels[label & 0xffff] = (self.sub, self.instruction_pointer, count)
 
 
-    def goto(self, frame, unknown1, unknown2, label, unknown3):
+    def goto(self, frame, instruction_pointer, label):
         try:
-            sub, instruction_pointer, count = self.labels[label]
+            sub, instruction_pointer, count = self.labels[label & 0xffff]
         except KeyError:
             pass
         else:
             count -= 1
             if count:
-                self.labels[label] = sub, instruction_pointer, count
+                self.labels[label & 0xffff] = sub, instruction_pointer, count
             else:
-                del self.labels[label]
+                del self.labels[label & 0xffff]
             self.frame = frame
             self.sub, self.instruction_pointer = sub, instruction_pointer
 
@@ -44,11 +40,11 @@ class ECLRunner(object):
 
                 if frame == self.frame:
                     try:
-                        format, callback = self.implementation[instr_type]
+                        callback = self.implementation[instr_type]
                     except KeyError:
                         print('Warning: unhandled opcode %d!' % instr_type) #TODO
                     else:
-                        callback(*unpack('<' + format, args))
+                        callback(*args)
                 if frame <= self.frame:
                     self.instruction_pointer += 1
         except IndexError: