Mercurial > touhou
annotate src/th06/ecl_vm.rs @ 654:ec7e888e88f3
Up to instruction 34 validated.
author | Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com> |
---|---|
date | Thu, 08 Aug 2019 16:42:25 +0200 |
parents | 16aa9a636d35 |
children | 6b4d2b405442 |
rev | line source |
---|---|
653
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
1 //! ECL runner. |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
2 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
3 use crate::th06::anm0::{ |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
4 Script, |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
5 Anm0, |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
6 Call, |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
7 Instruction, |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
8 }; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
9 use crate::th06::interpolator::{Interpolator1, Interpolator2, Interpolator3, Formula}; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
10 use crate::util::math::Mat4; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
11 use crate::util::prng::Prng; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
12 use std::cell::RefCell; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
13 use std::rc::{Rc, Weak}; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
14 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
15 fn run_instruction(&mut self, instruction: Instruction) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
16 let mut sprite = self.sprite.borrow_mut(); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
17 match instruction { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
18 Instruction::Noop() { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
19 // really |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
20 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
21 // 1 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
22 Instruction::Stop() { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
23 self._enemy.removed = true; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
24 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
25 // 2 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
26 Instruction::RelativeJump(frame, ip) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
27 self.frame = frame; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
28 // ip = ip + flag in th06 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
29 self.ip = ip; |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
30 // we jump back to the main of the interpreter |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
31 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
32 // 3 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
33 // GHIDRA SAYS THERE IS A COMPARISON_REG BUFFER BUT THERE IS NOT!!! |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
34 // |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
35 // MOV ECX,dword ptr [EBP + 0x8] jumptable 00407544 case 31 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
36 // CMP dword ptr [0x9d4 + ECX],0x0 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
37 // JLE LAB_00407abb |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
38 // aka ECX = enemy pointer |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
39 // ECX->9d4 (aka enemy_pointer_copy->comparison_reg) == 0 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
40 // only the pointer is copied, not the value, thus we are safe |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
41 Instruction::RelativeJumpEx(frame, ip, var_id) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
42 // TODO: counter_value is a field of "enemy" in th06, to check |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
43 counter_value = self._getval(var_id) - 1 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
44 if counter_value > 0 { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
45 Instruction::RelativeJump(frame, ip); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
46 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
47 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
48 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
49 //4, 5 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
50 Instruction::SetVariable(var_id, value) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
51 self._setval(var_id, value); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
52 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
53 // 6 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
54 Instruction::SetRandomInt(var_id, maxval) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
55 self._setval(var_id, self._game.prng.rand_32()%self._getval(maxval)); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
56 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
57 // 7 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
58 Instruction::SetRandomIntMin(var_id, maxval, minval) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
59 self._setval(var_id, (self._game.prng.rand_32()%self._getval(maxval))+self._getval(minval)); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
60 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
61 // 8 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
62 Instruction::SetRandomFloat(var_id, maxval) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
63 self._setval(var_id, self._getval(maxval) * self._game.prng.rand_double()) |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
64 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
65 // 9 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
66 Instruction::SetRandomFloatMin(var_id, maxval, minval) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
67 self._setval(var_id, (self._getval(maxval) * self._game.prng.rand_double())+self._getval(minval)) |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
68 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
69 // 10 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
70 Instruction::StoreX(var_id) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
71 self._setval(var_id, self._enemy.x); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
72 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
73 // 11 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
74 Instruction::StoreY(var_id) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
75 self._setval(var_id, self._enemy.y); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
76 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
77 // 12 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
78 Instruction::StoreZ(var_id) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
79 self._setval(var_id, self._enemy.z); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
80 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
81 // 13(int), 20(float), same impl in th06 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
82 Instruction::Add(var_id, a, b) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
83 self._setval(var_id, self._getval(a) + self._getval(b)); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
84 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
85 // 14(int), 21(float), same impl in th06 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
86 Instruction::Substract(var_id, a, b) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
87 self._setval(var_id, self._getval(a) - self._getval(b)); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
88 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
89 // 15(int), 22(unused) |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
90 Instruction::Multiply(var_id, a, b) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
91 self._setval(var_id, self._getval(a) * self._getval(b)); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
92 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
93 // 16(int), 23(unused) |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
94 Instruction::Divide(var_id, a, b) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
95 self._setval(var_id, self._getval(a) / self._getval(b)); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
96 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
97 // 17(int) 24(unused) |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
98 Instruction::Divide(var_id, a, b) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
99 self._setval(var_id, self._getval(a) % self._getval(b)); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
100 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
101 // 18 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
102 // setval used by pytouhou, but not in game(???) |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
103 Instruction::Increment(var_id) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
104 var_id = self._getval(var_id) + 1 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
105 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
106 // 19 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
107 Instruction::Decrement(var_id) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
108 var_id = self._getval(var_id) - 1 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
109 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
110 //25 |
654
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
111 Instruction::GetDirection(var_id, x1, y1, x2, y2) { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
112 //__ctrandisp2 in ghidra, let's assume from pytouhou it's atan2 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
113 self._setval(var_id, atan2(self._getval(y2) - self._getval(y1), self._getval(x2) - self._getval(x1))); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
114 } |
653
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
115 |
654
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
116 // 26 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
117 Instruction::FloatToUnitCircle(var_id) { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
118 // TODO: atan2(var_id, ??) is used by th06, maybe ?? is pi? |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
119 // we suck at trigonometry so let's use pytouhou for now |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
120 self._setval(var_id, (self._getval(var_id) + pi) % (2*pi) - pi); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
121 } |
653
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
122 |
654
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
123 // 27(int), 28(float) |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
124 Instruction::Compare(a, b) { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
125 a = self._getval(a); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
126 b = self._getval(b); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
127 if a < b { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
128 self.comparison_reg = -1 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
129 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
130 else if a == b { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
131 self.comparison_reg = 0 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
132 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
133 else { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
134 self.comparison_reg = 1 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
135 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
136 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
137 // 29 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
138 Instruction::RelativeJumpIfLowerThan(frame, ip) { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
139 if self.comparison_reg == -1 { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
140 Instruction::RelativeJump(); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
141 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
142 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
143 // 30 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
144 Instruction::RelativeJumpIfLowerOrEqual(frame, ip) { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
145 if self.comparison_reg != 1 { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
146 Instruction::RelativeJump(); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
147 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
148 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
149 // 31 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
150 Instruction::RelativeJumpIfEqual(frame, ip) { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
151 if self.comparison_reg == 0 { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
152 Instruction::RelativeJump(); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
153 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
154 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
155 // 32 |
653
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
156 Instruction::RelativeJumpIfGreaterThan(frame, ip) { |
654
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
157 if self.comparison_reg == 1 { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
158 Instruction::RelativeJump(); |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
159 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
160 } |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
161 // 33 |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
162 Instruction::RelativeJumpIfGreaterOrEqual(frame, ip) { |
ec7e888e88f3
Up to instruction 34 validated.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
653
diff
changeset
|
163 if self.comparison_reg != -1 |
653
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
164 Instruction::RelativeJump(); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
165 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
166 // 34 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
167 Instruction::RelativeJumpIfNotEqual(frame, ip) { |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
168 if self.comparison_reg != 0 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
169 Instruction::RelativeJump(); |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
170 } |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
171 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
172 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
173 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
174 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
175 |
16aa9a636d35
Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff
changeset
|
176 |