comparison 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
comparison
equal deleted inserted replaced
653:16aa9a636d35 654:ec7e888e88f3
106 // 19 106 // 19
107 Instruction::Decrement(var_id) { 107 Instruction::Decrement(var_id) {
108 var_id = self._getval(var_id) - 1 108 var_id = self._getval(var_id) - 1
109 } 109 }
110 //25 110 //25
111 Instruction::GetDirection(var_id, x1, y1, x2, y2) {
112 //__ctrandisp2 in ghidra, let's assume from pytouhou it's atan2
113 self._setval(var_id, atan2(self._getval(y2) - self._getval(y1), self._getval(x2) - self._getval(x1)));
114 }
111 115
116 // 26
117 Instruction::FloatToUnitCircle(var_id) {
118 // TODO: atan2(var_id, ??) is used by th06, maybe ?? is pi?
119 // we suck at trigonometry so let's use pytouhou for now
120 self._setval(var_id, (self._getval(var_id) + pi) % (2*pi) - pi);
121 }
112 122
113 123 // 27(int), 28(float)
114 124 Instruction::Compare(a, b) {
115 125 a = self._getval(a);
116 // 32 126 b = self._getval(b);
127 if a < b {
128 self.comparison_reg = -1
129 }
130 else if a == b {
131 self.comparison_reg = 0
132 }
133 else {
134 self.comparison_reg = 1
135 }
136 }
137 // 29
138 Instruction::RelativeJumpIfLowerThan(frame, ip) {
139 if self.comparison_reg == -1 {
140 Instruction::RelativeJump();
141 }
142 }
143 // 30
144 Instruction::RelativeJumpIfLowerOrEqual(frame, ip) {
145 if self.comparison_reg != 1 {
146 Instruction::RelativeJump();
147 }
148 }
149 // 31
150 Instruction::RelativeJumpIfEqual(frame, ip) {
151 if self.comparison_reg == 0 {
152 Instruction::RelativeJump();
153 }
154 }
155 // 32
117 Instruction::RelativeJumpIfGreaterThan(frame, ip) { 156 Instruction::RelativeJumpIfGreaterThan(frame, ip) {
118 if self.comparison_reg == 1 157 if self.comparison_reg == 1 {
158 Instruction::RelativeJump();
159 }
160 }
161 // 33
162 Instruction::RelativeJumpIfGreaterOrEqual(frame, ip) {
163 if self.comparison_reg != -1
119 Instruction::RelativeJump(); 164 Instruction::RelativeJump();
120 } 165 }
121 // 34 166 // 34
122 Instruction::RelativeJumpIfNotEqual(frame, ip) { 167 Instruction::RelativeJumpIfNotEqual(frame, ip) {
123 if self.comparison_reg != 0 168 if self.comparison_reg != 0