Mercurial > touhou
annotate formats/src/th06/ecl.rs @ 764:d18c0bf11138
Python: Use logger.warning() as logger.warn() is deprecated
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Fri, 26 Aug 2022 18:55:39 +0200 |
parents | 21b186be2590 |
children |
rev | line source |
---|---|
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
1 //! ECL enemy script format support. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
2 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
3 use nom::{ |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
4 IResult, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
5 number::complete::{le_u8, le_u16, le_u32, le_i16, le_i32, le_f32}, |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
6 sequence::tuple, |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
7 multi::{count, many0}, |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
8 error::ErrorKind, |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
9 Err, |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
10 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
11 use encoding_rs::SHIFT_JIS; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
12 use bitflags::bitflags; |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
13 |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
14 bitflags! { |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
15 /// Bit flags describing the current difficulty level. |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
16 pub struct Rank: u16 { |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
17 /// Easy mode. |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
18 const EASY = 0x100; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
19 |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
20 /// Normal mode. |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
21 const NORMAL = 0x200; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
22 |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
23 /// Hard mode. |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
24 const HARD = 0x400; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
25 |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
26 /// Lunatic mode. |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
27 const LUNATIC = 0x800; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
28 |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
29 /// Any or all modes. |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
30 const ALL = 0xff00; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
31 } |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
32 } |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 |
665
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
34 impl std::str::FromStr for Rank { |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
35 type Err = String; |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
36 |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
37 fn from_str(s: &str) -> Result<Rank, Self::Err> { |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
38 Ok(match s { |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
39 "easy" => Rank::EASY, |
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
40 "normal" => Rank::NORMAL, |
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
41 "hard" => Rank::HARD, |
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
42 "lunatic" => Rank::LUNATIC, |
665
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
43 _ => return Err(format!("unknown rank {}", s)) |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
44 }) |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
45 } |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
46 } |
965ecdbf0316
Make rank user-defined in eclrenderer.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
664
diff
changeset
|
47 |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 /// A single instruction, part of a `Script`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 pub struct CallSub { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 /// Time at which this instruction will be called. |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
651
diff
changeset
|
52 pub time: i32, |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
54 /// The difficulty level(s) this instruction will be called at. |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
55 pub rank_mask: Rank, |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 /// TODO |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 pub param_mask: u16, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
59 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
60 /// The instruction to call. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 pub instr: SubInstruction, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
62 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
63 |
696
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
64 impl CallSub { |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
65 /// Create a new instruction call. |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
66 pub fn new(time: i32, rank_mask: Rank, instr: SubInstruction) -> CallSub { |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
67 CallSub { |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
68 time, |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
69 rank_mask, |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
70 param_mask: 0, |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
71 instr, |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
72 } |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
73 } |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
74 } |
7ae576a418ff
ecl_vm: implement Call, Return, and the call stack thingy.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
686
diff
changeset
|
75 |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 /// Script driving an animation. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 pub struct Sub { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 /// List of instructions in this script. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 pub instructions: Vec<CallSub>, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
82 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
83 /// A single instruction, part of a `Script`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 pub struct CallMain { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 /// Time at which this instruction will be called. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 pub time: u16, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
88 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
89 /// Subroutine to call for this enemy. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 pub sub: u16, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 /// The instruction to call. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 pub instr: MainInstruction, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 /// Script driving an animation. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 pub struct Main { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 /// List of instructions in this script. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 pub instructions: Vec<CallMain>, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
101 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
102 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
103 /// Main struct of the ANM0 animation format. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 pub struct Ecl { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 /// A list of subs. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 pub subs: Vec<Sub>, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 /// A list of mains. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 pub mains: Vec<Main>, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
112 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
113 impl Ecl { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 /// Parse a slice of bytes into an `Ecl` struct. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 pub fn from_slice(data: &[u8]) -> IResult<&[u8], Ecl> { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 parse_ecl(data) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
117 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
118 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
119 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
120 macro_rules! declare_main_instructions { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
121 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 /// Available instructions in an `Ecl`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
123 #[allow(missing_docs)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
124 #[derive(Debug, Clone, Copy)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
125 pub enum MainInstruction { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 $name($($arg_type),*) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
128 ),* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
129 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 fn parse_main_instruction_args(input: &[u8], opcode: u16) -> IResult<&[u8], MainInstruction> { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 let mut i = &input[..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 let instr = match opcode { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 $opcode => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 let (i2, $arg) = concat_idents!(le_, $arg_type)(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 i = i2; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
139 )* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
140 MainInstruction::$name($($arg),*) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
141 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 )* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 _ => unreachable!() |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 Ok((i, instr)) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
148 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
149 |
651
5f02984dd12a
Fix SHIFT_JIS parsing to not include nul bytes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
650
diff
changeset
|
150 /// Parse a SHIFT_JIS byte string of length 34 into a String. |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
151 #[allow(non_snake_case)] |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> { |
669
1bb8b34dbd32
Don’t allocate a Vec while reading a String in ECL.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
665
diff
changeset
|
153 let data = i.splitn(2, |c| *c == b'\0').nth(0).unwrap(); |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
154 let (string, _encoding, _replaced) = SHIFT_JIS.decode(data); |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 Ok((&i[34..], string.into_owned())) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
156 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
157 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
158 macro_rules! declare_sub_instructions { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 /// Available instructions in an `Ecl`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
161 #[allow(missing_docs)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
162 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
163 pub enum SubInstruction { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
164 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 $name($($arg_type),*) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 ),* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
168 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
169 fn parse_sub_instruction_args(input: &[u8], opcode: u16) -> IResult<&[u8], SubInstruction> { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
170 let mut i = &input[..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 let instr = match opcode { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
173 $opcode => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
174 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
175 let (i2, $arg) = concat_idents!(le_, $arg_type)(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 i = i2; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 )* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 SubInstruction::$name($($arg),*) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
179 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 )* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 _ => unreachable!() |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
182 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 Ok((i, instr)) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
185 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
186 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 declare_main_instructions!{ |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 0 => fn SpawnEnemy(x: f32, y: f32, z: f32, life: i16, bonus_dropped: i16, die_score: u32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 2 => fn SpawnEnemyMirrored(x: f32, y: f32, z: f32, life: i16, bonus_dropped: i16, die_score: u32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
191 4 => fn SpawnEnemyRandom(x: f32, y: f32, z: f32, life: i16, bonus_dropped: i16, die_score: u32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 6 => fn SpawnEnemyMirroredRandom(x: f32, y: f32, z: f32, life: i16, bonus_dropped: i16, die_score: u32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
193 8 => fn CallMessage(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
194 9 => fn WaitMessage(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
195 10 => fn ResumeEcl(x: f32, y: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 12 => fn WaitForBossDeath(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
198 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
199 declare_sub_instructions!{ |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
200 0 => fn Noop(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
201 1 => fn Destroy(unused: u32), |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
651
diff
changeset
|
202 2 => fn RelativeJump(frame: i32, ip: i32), |
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
651
diff
changeset
|
203 3 => fn RelativeJumpEx(frame: i32, ip: i32, variable_id: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 4 => fn SetInt(var: i32, value: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 5 => fn SetFloat(var: i32, value: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 6 => fn SetRandomInt(var: i32, max: i32), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
207 7 => fn SetRandomIntMin(var: i32, max: i32, min: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 8 => fn SetRandomFloat(var: i32, max: f32), |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
651
diff
changeset
|
209 9 => fn SetRandomFloatMin(var: i32, amplitude: f32, min: f32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
210 10 => fn StoreX(var: i32), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
211 11 => fn StoreY(var: i32), |
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
212 12 => fn StoreZ(var: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
213 13 => fn AddInt(var: i32, a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
214 14 => fn SubstractInt(var: i32, a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
215 15 => fn MultiplyInt(var: i32, a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
216 16 => fn DivideInt(var: i32, a: i32, b: i32), |
660
31fc0d881105
Make ecl_vm compile, and use it in eclrenderer (doesn’t render yet).
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
651
diff
changeset
|
217 17 => fn ModuloInt(var: i32, a: i32, b: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
218 18 => fn Increment(var: i32), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
219 19 => fn Decrement(var: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 20 => fn AddFloat(var: i32, a: f32, b: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 21 => fn SubstractFloat(var: i32, a: f32, b: f32), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
222 22 => fn MultiplyFloat(var: i32, a: f32, b: f32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 23 => fn DivideFloat(var: i32, a: f32, b: f32), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
224 24 => fn ModuloFloat(var: i32, a: f32, b: f32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 25 => fn GetDirection(var: i32, x1: f32, y1: f32, x2: f32, y2: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 26 => fn FloatToUnitCircle(var: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 27 => fn CompareInts(a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 28 => fn CompareFloats(a: f32, b: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 29 => fn RelativeJumpIfLowerThan(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 30 => fn RelativeJumpIfLowerOrEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 31 => fn RelativeJumpIfEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
232 32 => fn RelativeJumpIfGreaterThan(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
233 33 => fn RelativeJumpIfGreaterOrEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 34 => fn RelativeJumpIfNotEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
235 35 => fn Call(sub: i32, param1: i32, param2: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 36 => fn Return(), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
237 37 => fn CallIfSuperior(sub: i32, param1: i32, param2: f32, a: i32, b: i32), |
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
238 38 => fn CallIfSuperiorOrEqual(sub: i32, param1: i32, param2: f32, a: i32, b: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 39 => fn CallIfEqual(sub: i32, param1: i32, param2: f32, a: i32, b: i32), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
240 40 => fn CallIfInferior(sub: i32, param1: i32, param2: f32, a: i32, b: i32), |
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
241 41 => fn CallIfInferiorOrEqual(sub: i32, param1: i32, param2: f32, a: i32, b: i32), |
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
242 42 => fn CallIfNotEqual(sub: i32, param1: i32, param2: f32, a: i32, b: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
243 43 => fn SetPosition(x: f32, y: f32, z: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 45 => fn SetAngleAndSpeed(angle: f32, speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 46 => fn SetRotationSpeed(speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 47 => fn SetSpeed(speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 48 => fn SetAcceleration(acceleration: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 49 => fn SetRandomAngle(min: f32, max: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 50 => fn SetRandomAngleEx(min: f32, max: f32), |
682
d6cc9086058c
ecl_vm: more instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
676
diff
changeset
|
250 51 => fn TargetPlayer(angle: f32, speed: f32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 52 => fn MoveInDecel(duration: i32, angle: f32, speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
252 56 => fn MoveToLinear(duration: i32, x: f32, y: f32, z: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
253 57 => fn MoveToDecel(duration: i32, x: f32, y: f32, z: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
254 59 => fn MoveToAccel(duration: i32, x: f32, y: f32, z: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 61 => fn StopIn(duration: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 63 => fn StopInAccel(duration: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 65 => fn SetScreenBox(xmin: f32, ymin: f32, xmax: f32, ymax: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 66 => fn ClearScreenBox(), |
686
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
685
diff
changeset
|
259 67 => fn SetBulletAttributes1(anim: i16, sprite_index_offset: i16, bullets_per_shot: i32, number_of_shots: i32, speed: f32, speed2: f32, launch_angle: f32, angle: f32, flags: u32), |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
685
diff
changeset
|
260 68 => fn SetBulletAttributes2(anim: i16, sprite_index_offset: i16, bullets_per_shot: i32, number_of_shots: i32, speed: f32, speed2: f32, launch_angle: f32, angle: f32, flags: u32), |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
685
diff
changeset
|
261 69 => fn SetBulletAttributes3(anim: i16, sprite_index_offset: i16, bullets_per_shot: i32, number_of_shots: i32, speed: f32, speed2: f32, launch_angle: f32, angle: f32, flags: u32), |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
685
diff
changeset
|
262 70 => fn SetBulletAttributes4(anim: i16, sprite_index_offset: i16, bullets_per_shot: i32, number_of_shots: i32, speed: f32, speed2: f32, launch_angle: f32, angle: f32, flags: u32), |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
685
diff
changeset
|
263 71 => fn SetBulletAttributes5(anim: i16, sprite_index_offset: i16, bullets_per_shot: i32, number_of_shots: i32, speed: f32, speed2: f32, launch_angle: f32, angle: f32, flags: u32), |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
685
diff
changeset
|
264 74 => fn SetBulletAttributes6(anim: i16, sprite_index_offset: i16, bullets_per_shot: i32, number_of_shots: i32, speed: f32, speed2: f32, launch_angle: f32, angle: f32, flags: u32), |
aefe5b5f481e
ecl_vm: implement the SetBulletAttributes opcodes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
685
diff
changeset
|
265 75 => fn SetBulletAttributes7(anim: i16, sprite_index_offset: i16, bullets_per_shot: i32, number_of_shots: i32, speed: f32, speed2: f32, launch_angle: f32, angle: f32, flags: u32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
266 76 => fn SetBulletInterval(interval: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
267 77 => fn SetBulletIntervalEx(interval: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
268 78 => fn DelayAttack(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
269 79 => fn NoDelayAttack(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 81 => fn SetBulletLaunchOffset(x: f32, y: f32, z: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
271 82 => fn SetExtendedBulletAttributes(a: i32, b: i32, c: i32, d: i32, e: f32, f: f32, g: f32, h: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
272 83 => fn ChangeBulletsInStarBonus(), |
676
826c16e5f909
Rename unknown ECL instructions to better recognise them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
674
diff
changeset
|
273 // TODO: Found in stage 4 onward. |
728
414f8611f344
ecl: Add support for bullet sounds, instruction 84.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
716
diff
changeset
|
274 84 => fn SetBulletSound(sound: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
275 85 => fn NewLaser(laser_type: i16, sprite_idx_offset: i16, angle: f32, speed: f32, start_offset: f32, end_offset: f32, max_length: f32, width: f32, start_duration: i32, duration: i32, end_duration: i32, grazing_delay: i32, grazing_extra_duration: i32, UNK1: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
276 86 => fn NewLaserTowardsPlayer(laser_type: i16, sprite_idx_offset: i16, angle: f32, speed: f32, start_offset: f32, end_offset: f32, max_length: f32, width: f32, start_duration: i32, duration: i32, end_duration: i32, grazing_delay: i32, grazing_extra_duration: i32, UNK1: i32), |
683
8c50a7b19425
ecl_vm: more work
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
682
diff
changeset
|
277 87 => fn SetUpcomingLaserId(id: u32), |
8c50a7b19425
ecl_vm: more work
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
682
diff
changeset
|
278 88 => fn AlterLaserAngle(id: u32, delta: f32), |
8c50a7b19425
ecl_vm: more work
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
682
diff
changeset
|
279 90 => fn RepositionLaser(id: u32, ox: f32, oy: f32, oz: f32), |
684
c8bb28961d31
ecl_vm: fixes for previous instructions
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
683
diff
changeset
|
280 91 => fn LaserSetCompare(id: u32), |
683
8c50a7b19425
ecl_vm: more work
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
682
diff
changeset
|
281 92 => fn CancelLaser(id: u32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
282 93 => fn SetSpellcard(face: i16, number: i16, name: String), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
283 94 => fn EndSpellcard(), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
284 95 => fn SpawnEnemy(sub: i32, x: f32, y: f32, z: f32, life: i16, bonus_dropped: i16, die_score: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
285 96 => fn KillAllEnemies(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
286 97 => fn SetAnim(script: i32), |
716
5016c09e5d7c
Fix some warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
714
diff
changeset
|
287 98 => fn SetMultipleAnims(default: i16, end_left: i16, end_right: i16, left: i16, right: i16, _unused: i16), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
288 99 => fn SetAuxAnm(number: i32, script: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
289 100 => fn SetDeathAnim(sprite_index: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
290 101 => fn SetBossMode(value: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
291 102 => fn CreateSquares(UNK1: i32, UNK2: f32, UNK3: f32, UNK4: f32, UNK5: f32), |
661
598f3125cbac
Implement enough instructions to execute sub 0 from stage 1.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
660
diff
changeset
|
292 103 => fn SetHitbox(width: f32, height: f32, depth: f32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
293 104 => fn SetCollidable(collidable: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
294 105 => fn SetDamageable(damageable: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
295 106 => fn PlaySound(index: i32), |
674
3e4cc64a254d
ecl_vm: more instructions.
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
669
diff
changeset
|
296 107 => fn SetDeathFlags(death_flags: u32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
297 108 => fn SetDeathCallback(sub: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
298 109 => fn MemoryWriteInt(value: i32, index: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
299 111 => fn SetLife(life: i32), |
685
11d7e4d6947a
ecl_vm: nearing the complete list
Gauvain "GovanifY" Roussel-Tarbouriech <gauvain@govanify.com>
parents:
684
diff
changeset
|
300 112 => fn SetElapsedTime(frame: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
301 113 => fn SetLowLifeTrigger(trigger: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
302 114 => fn SetLowLifeCallback(sub: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
303 115 => fn SetTimeout(timeout: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
304 116 => fn SetTimeoutCallback(sub: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 117 => fn SetTouchable(touchable: i32), |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
306 118 => fn DropParticles(anim: i32, number: u32, r: u8, g: u8, b: u8, a: u8), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
307 119 => fn DropBonus(number: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
308 120 => fn SetAutomaticOrientation(automatic: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
309 121 => fn CallSpecialFunction(function: i32, argument: i32), |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
310 122 => fn SetSpecialFunctionCallback(function: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
311 123 => fn SkipFrames(frames: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
312 124 => fn DropSpecificBonus(type_: i32), |
676
826c16e5f909
Rename unknown ECL instructions to better recognise them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
674
diff
changeset
|
313 // TODO: Found in stage 3. |
826c16e5f909
Rename unknown ECL instructions to better recognise them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
674
diff
changeset
|
314 125 => fn UNK_ins125(), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
315 126 => fn SetRemainingLives(lives: i32), |
676
826c16e5f909
Rename unknown ECL instructions to better recognise them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
674
diff
changeset
|
316 // TODO: Found in stage 4. |
716
5016c09e5d7c
Fix some warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
714
diff
changeset
|
317 127 => fn UNK_ins127(UNK1: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
318 128 => fn Interrupt(event: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
319 129 => fn InterruptAux(number: i32, event: i32), |
676
826c16e5f909
Rename unknown ECL instructions to better recognise them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
674
diff
changeset
|
320 // TODO: Found in stage 4. |
716
5016c09e5d7c
Fix some warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
714
diff
changeset
|
321 130 => fn UNK_ins130(UNK1: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
322 131 => fn SetDifficultyCoeffs(speed_a: f32, speed_b: f32, nb_a: i32, nb_b: i32, shots_a: i32, shots_b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
323 132 => fn SetInvisible(invisible: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
324 133 => fn CopyCallbacks(), |
676
826c16e5f909
Rename unknown ECL instructions to better recognise them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
674
diff
changeset
|
325 // TODO: Found in stage 4. |
826c16e5f909
Rename unknown ECL instructions to better recognise them.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
674
diff
changeset
|
326 134 => fn UNK_ins134(), |
716
5016c09e5d7c
Fix some warnings.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
714
diff
changeset
|
327 135 => fn EnableSpellcardBonus(UNK1: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
328 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
329 |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
330 fn parse_sub_instruction(input: &[u8]) -> IResult<&[u8], CallSub> { |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
331 let i = &input[..]; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
332 let (i, (time, opcode)) = tuple((le_i32, le_u16))(i)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
333 if time == -1 || opcode == 0xffff { |
755
fc937d93a57c
Bump nom to version 6, and image to 0.23.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
728
diff
changeset
|
334 return Err(Err::Error(nom::error::Error::new(i, ErrorKind::Eof))); |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
335 } |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
336 |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
337 let (i, (size, rank_mask, param_mask)) = tuple((le_u16, le_u16, le_u16))(i)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
338 let rank_mask = Rank::from_bits(rank_mask).unwrap(); |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
339 let (i, instr) = parse_sub_instruction_args(i, opcode)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
340 assert_eq!(input.len() - i.len(), size as usize); |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
341 let call = CallSub { time, rank_mask, param_mask, instr }; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
342 Ok((i, call)) |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
343 } |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
344 |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
345 fn parse_sub(i: &[u8]) -> IResult<&[u8], Sub> { |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
346 let (i, instructions) = many0(parse_sub_instruction)(i)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
347 let sub = Sub { instructions }; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
348 Ok((i, sub)) |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
349 } |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
350 |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
351 fn parse_main_instruction(input: &[u8]) -> IResult<&[u8], CallMain> { |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
352 let i = &input[..]; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
353 let (i, (time, sub)) = tuple((le_u16, le_u16))(i)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
354 if time == 0xffff && sub == 4 { |
755
fc937d93a57c
Bump nom to version 6, and image to 0.23.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
728
diff
changeset
|
355 return Err(Err::Error(nom::error::Error::new(i, ErrorKind::Eof))); |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
356 } |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
357 |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
358 let (i, (opcode, size)) = tuple((le_u16, le_u16))(i)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
359 let size = size as usize; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
360 let (i, instr) = parse_main_instruction_args(i, opcode)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
361 assert_eq!(input.len() - i.len(), size as usize); |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
362 let call = CallMain { time, sub, instr }; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
363 Ok((i, call)) |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
364 } |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
365 |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
366 fn parse_main(i: &[u8]) -> IResult<&[u8], Main> { |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
367 let (i, instructions) = many0(parse_main_instruction)(i)?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
368 let main = Main { instructions }; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
369 Ok((i, main)) |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
370 } |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
371 |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
372 fn parse_ecl(input: &[u8]) -> IResult<&[u8], Ecl> { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
373 let i = input; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
374 |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
375 let (i, (sub_count, main_count)) = tuple((le_u16, le_u16))(i)?; |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
376 let sub_count = sub_count as usize; |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
377 |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
378 if main_count != 0 { |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
379 // TODO: use a better error. |
755
fc937d93a57c
Bump nom to version 6, and image to 0.23.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
728
diff
changeset
|
380 return Err(Err::Error(nom::error::Error::new(i, ErrorKind::Eof))); |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
381 } |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
382 |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
383 let (_, (main_offsets, sub_offsets)) = tuple(( |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
384 count(le_u32, 3), |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
385 count(le_u32, sub_count), |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
386 ))(i)?; |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
387 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
388 // Read all subs. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
389 let mut subs = Vec::new(); |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
390 for offset in sub_offsets.into_iter().map(|offset| offset as usize) { |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
391 let (_, sub) = parse_sub(&input[offset..])?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
392 subs.push(sub); |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
393 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
394 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
395 // Read all mains (always a single one atm). |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
396 let mut mains = Vec::new(); |
703
81232dac8136
ecl: simplify parsing with more combinators.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
696
diff
changeset
|
397 for offset in main_offsets.into_iter().map(|offset| offset as usize) { |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
398 if offset == 0 { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
399 break; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
400 } |
714
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
401 let (_, main) = parse_main(&input[offset..])?; |
fcc8f736c746
ecl: Simplify parsing.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
703
diff
changeset
|
402 mains.push(main); |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
403 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
404 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
405 let ecl = Ecl { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
406 subs, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
407 mains, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
408 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
409 Ok((b"", ecl)) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
410 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
411 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
412 #[cfg(test)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
413 mod tests { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
414 use super::*; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
415 use std::io::{self, Read}; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
416 use std::fs::File; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
417 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
418 #[test] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
419 fn ecl() { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
420 let file = File::open("EoSD/ST/ecldata1.ecl").unwrap(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
421 let mut file = io::BufReader::new(file); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
422 let mut buf = vec![]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
423 file.read_to_end(&mut buf).unwrap(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
424 let (_, ecl) = Ecl::from_slice(&buf).unwrap(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
425 assert_eq!(ecl.subs.len(), 24); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
426 assert_eq!(ecl.mains.len(), 1); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
427 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
428 } |