annotate src/th06/ecl_vm.rs @ 655:6b4d2b405442

More ECL stuff.
author Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
date Thu, 08 Aug 2019 17:01:42 +0200
parents ec7e888e88f3
children 53786d834444
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }
655
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
171 // 35
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
172 Instruction::Call(sub, param1, param2) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
173 // does insane stuff with the stack, not implemented
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
174 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
175
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
176 // 36
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
177 Instruction::Ret(frame, ip) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
178 // does insane stuff with the stack, not implemented
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
179 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
180 // 37
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
181 Instruction::CallIfSuperior(sub, param1, param2, a, b) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
182 if(self._getval(b) <= self._getval(a)) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
183 Instruction::Call(sub, param1, param2);
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
184 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
185 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
186 // 38
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
187 Instruction::CallIfSuperiorOrEqual(sub, param1, param2, a, b) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
188 if(self._getval(b) <= self._getval(a)) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
189 Instruction::Call(sub, param1, param2);
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
190 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
191 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
192 // 39
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
193 Instruction::CallIfEqual(sub, param1, param2, a, b) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
194 if(self._getval(b) == self._getval(a)) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
195 Instruction::Call(sub, param1, param2);
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
196 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
197 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
198 // 40
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
199 Instruction::CallIfEqual(sub, param1, param2, a, b) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
200 if(self._getval(b) == self._getval(a)) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
201 Instruction::Call(sub, param1, param2);
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
202 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
203 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
204 //41
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
205 Instruction::CallIfInferior(sub, param1, param2, a, b) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
206 if(self._getval(a) < self._getval(b)) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
207 Instruction::Call(sub, param1, param2);
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
208 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
209 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
210 //42
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
211 Instruction::CallIfInferiorOrEqual(sub, param1, param2, a, b) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
212 if(self._getval(a) <= self._getval(b)) {
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
213 Instruction::Call(sub, param1, param2);
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
214 }
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
215 }
653
16aa9a636d35 Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff changeset
216
16aa9a636d35 Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff changeset
217
16aa9a636d35 Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff changeset
218
16aa9a636d35 Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff changeset
219
16aa9a636d35 Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff changeset
220
16aa9a636d35 Some starting point for ecl_vm.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
diff changeset
221
655
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
222
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
223
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
224
6b4d2b405442 More ECL stuff.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents: 654
diff changeset
225