comparison src/th06/ecl_vm.rs @ 661:598f3125cbac

Implement enough instructions to execute sub 0 from stage 1.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Sat, 10 Aug 2019 21:04:54 +0200
parents 31fc0d881105
children 994f41154be8
comparison
equal deleted inserted replaced
660:31fc0d881105 661:598f3125cbac
12 #[derive(Default)] 12 #[derive(Default)]
13 pub struct EclRunner { 13 pub struct EclRunner {
14 enemy: Rc<RefCell<Enemy>>, 14 enemy: Rc<RefCell<Enemy>>,
15 ecl: Option<Ecl>, 15 ecl: Option<Ecl>,
16 sub: u8, 16 sub: u8,
17 running: bool, 17 /// XXX
18 pub running: bool,
18 /// XXX 19 /// XXX
19 pub frame: i32, 20 pub frame: i32,
20 ip: i32, 21 ip: i32,
21 variables: Variables, 22 variables: Variables,
22 comparison_reg: i8, 23 comparison_reg: i8,
29 EclRunner { 30 EclRunner {
30 enemy, 31 enemy,
31 // XXX: no clone. 32 // XXX: no clone.
32 ecl: Some(ecl.clone()), 33 ecl: Some(ecl.clone()),
33 sub, 34 sub,
35 running: true,
34 ..Default::default() 36 ..Default::default()
35 } 37 }
36 } 38 }
37 39
38 /// Advance the ECL of a single frame. 40 /// Advance the ECL of a single frame.
141 let enemy = self.enemy.borrow(); 143 let enemy = self.enemy.borrow();
142 enemy.prng.upgrade().unwrap() 144 enemy.prng.upgrade().unwrap()
143 } 145 }
144 146
145 fn run_instruction(&mut self, instruction: SubInstruction) { 147 fn run_instruction(&mut self, instruction: SubInstruction) {
148 println!("Running instruction {:?}", instruction);
146 match instruction { 149 match instruction {
147 SubInstruction::Noop() => { 150 SubInstruction::Noop() => {
148 // really 151 // really
149 } 152 }
150 // 1 153 // 1
426 enemy.set_pos(self.get_f32(x), self.get_f32(y), self.get_f32(z)); 429 enemy.set_pos(self.get_f32(x), self.get_f32(y), self.get_f32(z));
427 } 430 }
428 */ 431 */
429 // 45 432 // 45
430 SubInstruction::SetAngleAndSpeed(angle, speed) => { 433 SubInstruction::SetAngleAndSpeed(angle, speed) => {
434 let angle = self.get_f32(angle);
435 let speed = self.get_f32(speed);
431 let mut enemy = self.enemy.borrow_mut(); 436 let mut enemy = self.enemy.borrow_mut();
432 enemy.update_mode = 0; 437 enemy.update_mode = 0;
433 enemy.angle = self.get_f32(angle); 438 enemy.angle = angle;
434 enemy.speed = self.get_f32(speed); 439 enemy.speed = speed;
435 } 440 }
436 // 46 441 // 46
437 SubInstruction::SetRotationSpeed(speed) => { 442 SubInstruction::SetRotationSpeed(speed) => {
443 let rotation_speed = self.get_f32(speed);
438 let mut enemy = self.enemy.borrow_mut(); 444 let mut enemy = self.enemy.borrow_mut();
439 enemy.update_mode = 0; 445 enemy.update_mode = 0;
440 enemy.rotation_speed = self.get_f32(speed); 446 enemy.rotation_speed = rotation_speed;
441 } 447 }
442 // 47 448 // 47
443 SubInstruction::SetSpeed(speed) => { 449 SubInstruction::SetSpeed(speed) => {
444 let mut enemy = self.enemy.borrow_mut(); 450 let mut enemy = self.enemy.borrow_mut();
445 enemy.update_mode = 0; 451 enemy.update_mode = 0;
458 enemy.angle = angle; 464 enemy.angle = angle;
459 } 465 }
460 466
461 // 83 -> star items >>> life items 467 // 83 -> star items >>> life items
462 468
469 // 97
470 SubInstruction::SetAnim(index) => {
471 // TODO: check in ghidra!
472 let mut enemy = self.enemy.borrow_mut();
473 enemy.set_anim(index as u8);
474 }
475
476 // 100
477 SubInstruction::SetDeathAnim(index) => {
478 // TODO: check in ghidra!
479 let mut enemy = self.enemy.borrow_mut();
480 enemy.death_anim = index;
481 }
482
483 // 103
484 SubInstruction::SetHitbox(width, height, depth) => {
485 // TODO: check in ghidra!
486 assert_eq!(depth, 32.);
487 let mut enemy = self.enemy.borrow_mut();
488 enemy.set_hitbox(width, height);
489 }
490
463 _ => unimplemented!() 491 _ => unimplemented!()
464 } 492 }
465 } 493 }
466 } 494 }