# HG changeset patch # User Emmanuel Gil Peyrot # Date 1314251080 25200 # Node ID d469012368b38808f3cc3cf0d2f191366aafd440 # Parent 8527fe640844a8da82123427e5cc59672f0ad31f Implement conditional jumps. diff --git a/pytouhou/formats/ecl.py b/pytouhou/formats/ecl.py --- a/pytouhou/formats/ecl.py +++ b/pytouhou/formats/ecl.py @@ -44,12 +44,12 @@ class ECL(object): 26: ('i', None), 27: ('ii', 'compare_ints'), 28: ('ff', 'compare_floats'), - 29: ('ii', 'relative_jump?'), - 30: ('ii', 'relative_jump?'), + 29: ('ii', 'relative_jump_if_lower_than'), + 30: ('ii', 'relative_jump_if_lower_or_equal'), 31: ('ii', 'relative_jump_if_equal'), - 32: ('ii', 'relative_jump?'), - 33: ('ii', 'relative_jump?'), - 34: ('ii', 'relative_jump?'), + 32: ('ii', 'relative_jump_if_greater_than'), + 33: ('ii', 'relative_jump_if_greater_or_equal'), + 34: ('ii', 'relative_jump_if_not_equal'), 35: ('iif', 'call'), 36: ('', 'return?'), 39: ('iifii', 'call_if_equal'), diff --git a/pytouhou/game/eclrunner.py b/pytouhou/game/eclrunner.py --- a/pytouhou/game/eclrunner.py +++ b/pytouhou/game/eclrunner.py @@ -288,12 +288,42 @@ class ECLRunner(object): self.comparison_reg = 1 + @instruction(29) + def relative_jump_if_lower_than(self, frame, instruction_pointer): + if self.comparison_reg == -1: + self.relative_jump(frame, instruction_pointer) + + + @instruction(30) + def relative_jump_if_lower_or_equal(self, frame, instruction_pointer): + if self.comparison_reg != 1: + self.relative_jump(frame, instruction_pointer) + + @instruction(31) def relative_jump_if_equal(self, frame, instruction_pointer): if self.comparison_reg == 0: self.relative_jump(frame, instruction_pointer) + @instruction(32) + def relative_jump_if_greater_than(self, frame, instruction_pointer): + if self.comparison_reg == 1: + self.relative_jump(frame, instruction_pointer) + + + @instruction(33) + def relative_jump_if_greater_or_equal(self, frame, instruction_pointer): + if self.comparison_reg != -1: + self.relative_jump(frame, instruction_pointer) + + + @instruction(34) + def relative_jump_if_not_equal(self, frame, instruction_pointer): + if self.comparison_reg != 0: + self.relative_jump(frame, instruction_pointer) + + @instruction(35) def call(self, sub, param1, param2): self.stack.append((self.sub, self.frame, self.instruction_pointer,