# HG changeset patch # User Gauvain "GovanifY" Roussel-Tarbouriech # Date 1565275345 -7200 # Node ID ec7e888e88f30d2d241c89d9241c3ccc4b8e36f8 # Parent 16aa9a636d3578f0272fdc4bedc931285ecf9e54 Up to instruction 34 validated. diff --git a/src/th06/ecl_vm.rs b/src/th06/ecl_vm.rs --- a/src/th06/ecl_vm.rs +++ b/src/th06/ecl_vm.rs @@ -108,14 +108,59 @@ use std::rc::{Rc, Weak}; var_id = self._getval(var_id) - 1 } //25 - + Instruction::GetDirection(var_id, x1, y1, x2, y2) { + //__ctrandisp2 in ghidra, let's assume from pytouhou it's atan2 + self._setval(var_id, atan2(self._getval(y2) - self._getval(y1), self._getval(x2) - self._getval(x1))); + } - + // 26 + Instruction::FloatToUnitCircle(var_id) { + // TODO: atan2(var_id, ??) is used by th06, maybe ?? is pi? + // we suck at trigonometry so let's use pytouhou for now + self._setval(var_id, (self._getval(var_id) + pi) % (2*pi) - pi); + } - - // 32 + // 27(int), 28(float) + Instruction::Compare(a, b) { + a = self._getval(a); + b = self._getval(b); + if a < b { + self.comparison_reg = -1 + } + else if a == b { + self.comparison_reg = 0 + } + else { + self.comparison_reg = 1 + } + } + // 29 + Instruction::RelativeJumpIfLowerThan(frame, ip) { + if self.comparison_reg == -1 { + Instruction::RelativeJump(); + } + } + // 30 + Instruction::RelativeJumpIfLowerOrEqual(frame, ip) { + if self.comparison_reg != 1 { + Instruction::RelativeJump(); + } + } + // 31 + Instruction::RelativeJumpIfEqual(frame, ip) { + if self.comparison_reg == 0 { + Instruction::RelativeJump(); + } + } + // 32 Instruction::RelativeJumpIfGreaterThan(frame, ip) { - if self.comparison_reg == 1 + if self.comparison_reg == 1 { + Instruction::RelativeJump(); + } + } + // 33 + Instruction::RelativeJumpIfGreaterOrEqual(frame, ip) { + if self.comparison_reg != -1 Instruction::RelativeJump(); } // 34