# HG changeset patch # User Emmanuel Gil Peyrot # Date 1314231245 25200 # Node ID 8527fe640844a8da82123427e5cc59672f0ad31f # Parent 1f591adcea043fff7bcc8d4efa921c815014fca3 Implement simple arithmetic instructions. diff --git a/pytouhou/formats/ecl.py b/pytouhou/formats/ecl.py --- a/pytouhou/formats/ecl.py +++ b/pytouhou/formats/ecl.py @@ -31,25 +31,25 @@ class ECL(object): 8: ('if', 'set_random_float'), 9: ('iff', 'set_random_float2'), 10: ('i', None), - 13: ('iii', None), - 14: ('iii', None), - 15: ('iii', None), - 16: ('iii', None), - 17: ('iii', None), + 13: ('iii', 'set_random_int2'), + 14: ('iii', 'substract_int'), + 15: ('iii', 'multiply_int'), + 16: ('iii', 'divide_int'), + 17: ('iii', 'modulo'), 18: ('i', None), - 20: ('iff', 'add'), - 21: ('iff', 'sub'), - 23: ('iff', None), + 20: ('iff', 'add_float'), + 21: ('iff', 'substract_float'), + 23: ('iff', 'divide_float'), 25: ('iffff', None), 26: ('i', None), 27: ('ii', 'compare_ints'), - 28: ('ff', None), - 29: ('ii', None), - 30: ('ii', None), + 28: ('ff', 'compare_floats'), + 29: ('ii', 'relative_jump?'), + 30: ('ii', 'relative_jump?'), 31: ('ii', 'relative_jump_if_equal'), - 32: ('ii', None), - 33: ('ii', None), - 34: ('ii', None), + 32: ('ii', 'relative_jump?'), + 33: ('ii', 'relative_jump?'), + 34: ('ii', 'relative_jump?'), 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 @@ -206,7 +206,7 @@ class ECLRunner(object): @instruction(6) def set_random_int(self, variable_id, maxval): - """Set the specified variable to a random int in the [[0, maxval)) range. + """Set the specified variable to a random int in the [0, maxval) range. """ self._setval(variable_id, int(self._getval(maxval) * self._game_state.prng.rand_double())) @@ -223,20 +223,62 @@ class ECLRunner(object): self._setval(variable_id, self._getval(minval) + self._getval(amp) * self._game_state.prng.rand_double()) + @instruction(13) + def set_random_int2(self, variable_id, minval, amp): + self._setval(variable_id, int(self._getval(minval)) + int(self._getval(amp)) * self._game_state.prng.rand_double()) + + + @instruction(14) + def substract_int(self, variable_id, a, b): + self._setval(variable_id, int(self._getval(a)) - int(self._getval(b))) + + + @instruction(15) + def multiply_int(self, variable_id, a, b): + self._setval(variable_id, int(self._getval(a)) * int(self._getval(b))) + + + @instruction(16) + def divide_int(self, variable_id, a, b): + self._setval(variable_id, int(self._getval(a)) / int(self._getval(b))) + + + @instruction(17) + def modulo(self, variable_id, a, b): + self._setval(variable_id, int(self._getval(a)) % int(self._getval(b))) + + @instruction(20) - def add(self, variable_id, a, b): + def add_float(self, variable_id, a, b): #TODO: int vs float thing self._setval(variable_id, self._getval(a) + self._getval(b)) @instruction(21) - def substract(self, variable_id, a, b): + def substract_float(self, variable_id, a, b): #TODO: int vs float thing self._setval(variable_id, self._getval(a) - self._getval(b)) + @instruction(23) + def divide_float(self, variable_id, a, b): + #TODO: int vs float thing + self._setval(variable_id, self._getval(a) / self._getval(b)) + + @instruction(27) def compare_ints(self, a, b): + a, b = int(self._getval(a)), int(self._getval(b)) + if a < b: + self.comparison_reg = -1 + elif a == b: + self.comparison_reg = 0 + else: + self.comparison_reg = 1 + + + @instruction(28) + def compare_floats(self, a, b): a, b = self._getval(a), self._getval(b) if a < b: self.comparison_reg = -1