comparison src/th06/ecl_vm.rs @ 653:16aa9a636d35

Some starting point for ecl_vm.
author Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
date Thu, 08 Aug 2019 16:03:38 +0200
parents
children ec7e888e88f3
comparison
equal deleted inserted replaced
652:93bdc7b9df15 653:16aa9a636d35
1 //! ECL runner.
2
3 use crate::th06::anm0::{
4 Script,
5 Anm0,
6 Call,
7 Instruction,
8 };
9 use crate::th06::interpolator::{Interpolator1, Interpolator2, Interpolator3, Formula};
10 use crate::util::math::Mat4;
11 use crate::util::prng::Prng;
12 use std::cell::RefCell;
13 use std::rc::{Rc, Weak};
14
15 fn run_instruction(&mut self, instruction: Instruction) {
16 let mut sprite = self.sprite.borrow_mut();
17 match instruction {
18 Instruction::Noop() {
19 // really
20 }
21 // 1
22 Instruction::Stop() {
23 self._enemy.removed = true;
24 }
25 // 2
26 Instruction::RelativeJump(frame, ip) {
27 self.frame = frame;
28 // ip = ip + flag in th06
29 self.ip = ip;
30 // we jump back to the main of the interpreter
31 }
32 // 3
33 // GHIDRA SAYS THERE IS A COMPARISON_REG BUFFER BUT THERE IS NOT!!!
34 //
35 // MOV ECX,dword ptr [EBP + 0x8] jumptable 00407544 case 31
36 // CMP dword ptr [0x9d4 + ECX],0x0
37 // JLE LAB_00407abb
38 // aka ECX = enemy pointer
39 // ECX->9d4 (aka enemy_pointer_copy->comparison_reg) == 0
40 // only the pointer is copied, not the value, thus we are safe
41 Instruction::RelativeJumpEx(frame, ip, var_id) {
42 // TODO: counter_value is a field of "enemy" in th06, to check
43 counter_value = self._getval(var_id) - 1
44 if counter_value > 0 {
45 Instruction::RelativeJump(frame, ip);
46 }
47 }
48
49 //4, 5
50 Instruction::SetVariable(var_id, value) {
51 self._setval(var_id, value);
52 }
53 // 6
54 Instruction::SetRandomInt(var_id, maxval) {
55 self._setval(var_id, self._game.prng.rand_32()%self._getval(maxval));
56 }
57 // 7
58 Instruction::SetRandomIntMin(var_id, maxval, minval) {
59 self._setval(var_id, (self._game.prng.rand_32()%self._getval(maxval))+self._getval(minval));
60 }
61 // 8
62 Instruction::SetRandomFloat(var_id, maxval) {
63 self._setval(var_id, self._getval(maxval) * self._game.prng.rand_double())
64 }
65 // 9
66 Instruction::SetRandomFloatMin(var_id, maxval, minval) {
67 self._setval(var_id, (self._getval(maxval) * self._game.prng.rand_double())+self._getval(minval))
68 }
69 // 10
70 Instruction::StoreX(var_id) {
71 self._setval(var_id, self._enemy.x);
72 }
73 // 11
74 Instruction::StoreY(var_id) {
75 self._setval(var_id, self._enemy.y);
76 }
77 // 12
78 Instruction::StoreZ(var_id) {
79 self._setval(var_id, self._enemy.z);
80 }
81 // 13(int), 20(float), same impl in th06
82 Instruction::Add(var_id, a, b) {
83 self._setval(var_id, self._getval(a) + self._getval(b));
84 }
85 // 14(int), 21(float), same impl in th06
86 Instruction::Substract(var_id, a, b) {
87 self._setval(var_id, self._getval(a) - self._getval(b));
88 }
89 // 15(int), 22(unused)
90 Instruction::Multiply(var_id, a, b) {
91 self._setval(var_id, self._getval(a) * self._getval(b));
92 }
93 // 16(int), 23(unused)
94 Instruction::Divide(var_id, a, b) {
95 self._setval(var_id, self._getval(a) / self._getval(b));
96 }
97 // 17(int) 24(unused)
98 Instruction::Divide(var_id, a, b) {
99 self._setval(var_id, self._getval(a) % self._getval(b));
100 }
101 // 18
102 // setval used by pytouhou, but not in game(???)
103 Instruction::Increment(var_id) {
104 var_id = self._getval(var_id) + 1
105 }
106 // 19
107 Instruction::Decrement(var_id) {
108 var_id = self._getval(var_id) - 1
109 }
110 //25
111
112
113
114
115
116 // 32
117 Instruction::RelativeJumpIfGreaterThan(frame, ip) {
118 if self.comparison_reg == 1
119 Instruction::RelativeJump();
120 }
121 // 34
122 Instruction::RelativeJumpIfNotEqual(frame, ip) {
123 if self.comparison_reg != 0
124 Instruction::RelativeJump();
125 }
126
127
128
129
130
131