Mercurial > touhou
annotate src/th06/ecl.rs @ 664:f08e8e3c6196
Use bitflags for the rank, instead of an u16.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 11 Aug 2019 19:55:45 +0200 |
parents | 598f3125cbac |
children | 965ecdbf0316 |
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 bytes::complete::take_while_m_n, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
6 number::complete::{le_u8, le_u16, le_u32, le_i16, le_i32, le_f32}, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
7 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
8 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
|
9 use bitflags::bitflags; |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
10 |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
11 bitflags! { |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
12 /// 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
|
13 pub struct Rank: u16 { |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
14 /// Easy mode. |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
15 const Easy = 0x100; |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
16 |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
17 /// Normal mode. |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
18 const Normal = 0x200; |
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 /// Hard mode. |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
21 const Hard = 0x400; |
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 /// Lunatic mode. |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
24 const Lunatic = 0x800; |
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 /// Any or all modes. |
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
27 const All = 0xff00; |
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 } |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
30 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
31 /// A single instruction, part of a `Script`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
32 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
33 pub struct CallSub { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
34 /// 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
|
35 pub time: i32, |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
36 |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
37 /// 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
|
38 pub rank_mask: Rank, |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
39 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
40 /// TODO |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
41 pub param_mask: u16, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
42 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
43 /// The instruction to call. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
44 pub instr: SubInstruction, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
45 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
46 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
47 /// Script driving an animation. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
48 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
49 pub struct Sub { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
50 /// List of instructions in this script. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
51 pub instructions: Vec<CallSub>, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
52 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
53 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
54 /// A single instruction, part of a `Script`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
55 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
56 pub struct CallMain { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
57 /// Time at which this instruction will be called. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
58 pub time: 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 /// Subroutine to call for this enemy. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
61 pub sub: u16, |
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 /// The instruction to call. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
64 pub instr: MainInstruction, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
65 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
66 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
67 /// Script driving an animation. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
68 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
69 pub struct Main { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
70 /// List of instructions in this script. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
71 pub instructions: Vec<CallMain>, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
72 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
73 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
74 /// Main struct of the ANM0 animation format. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
75 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
76 pub struct Ecl { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
77 /// A list of subs. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
78 pub subs: Vec<Sub>, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
79 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
80 /// A list of mains. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
81 pub mains: Vec<Main>, |
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 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
84 impl Ecl { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
85 /// Parse a slice of bytes into an `Ecl` struct. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
86 pub fn from_slice(data: &[u8]) -> IResult<&[u8], Ecl> { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
87 parse_ecl(data) |
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 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
90 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
91 macro_rules! declare_main_instructions { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
92 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
93 /// Available instructions in an `Ecl`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
94 #[allow(missing_docs)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
95 #[derive(Debug, Clone, Copy)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
96 pub enum MainInstruction { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
97 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
98 $name($($arg_type),*) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
99 ),* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
100 } |
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 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
|
103 let mut i = &input[..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
104 let instr = match opcode { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
105 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
106 $opcode => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
107 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
108 let (i2, $arg) = concat_idents!(le_, $arg_type)(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
109 i = i2; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
110 )* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
111 MainInstruction::$name($($arg),*) |
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 )* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
114 _ => unreachable!() |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
115 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
116 Ok((i, instr)) |
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 |
651
5f02984dd12a
Fix SHIFT_JIS parsing to not include nul bytes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
650
diff
changeset
|
121 /// Parse a SHIFT_JIS byte string of length 34 into a String. |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
122 pub fn le_String(i: &[u8]) -> IResult<&[u8], String> { |
651
5f02984dd12a
Fix SHIFT_JIS parsing to not include nul bytes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
650
diff
changeset
|
123 assert_eq!(i.len(), 34); |
5f02984dd12a
Fix SHIFT_JIS parsing to not include nul bytes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
650
diff
changeset
|
124 let data = i.splitn(2, |c| *c == b'\0').collect::<Vec<_>>()[0]; |
5f02984dd12a
Fix SHIFT_JIS parsing to not include nul bytes.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
650
diff
changeset
|
125 let (string, encoding, replaced) = SHIFT_JIS.decode(data); |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
126 Ok((&i[34..], string.into_owned())) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
127 } |
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 macro_rules! declare_sub_instructions { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
130 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ident),*)),*,) => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
131 /// Available instructions in an `Ecl`. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
132 #[allow(missing_docs)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
133 #[derive(Debug, Clone)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
134 pub enum SubInstruction { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
135 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
136 $name($($arg_type),*) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
137 ),* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
138 } |
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 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
|
141 let mut i = &input[..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
142 let instr = match opcode { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
143 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
144 $opcode => { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
145 $( |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
146 let (i2, $arg) = concat_idents!(le_, $arg_type)(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
147 i = i2; |
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 SubInstruction::$name($($arg),*) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
150 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
151 )* |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
152 _ => unreachable!() |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
153 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
154 Ok((i, instr)) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
155 } |
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 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
159 declare_main_instructions!{ |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
160 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
|
161 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
|
162 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
|
163 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
|
164 8 => fn CallMessage(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
165 9 => fn WaitMessage(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
166 10 => fn ResumeEcl(x: f32, y: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
167 12 => fn WaitForBossDeath(), |
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 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
170 declare_sub_instructions!{ |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
171 0 => fn Noop(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
172 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
|
173 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
|
174 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
|
175 4 => fn SetInt(var: i32, value: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
176 5 => fn SetFloat(var: i32, value: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
177 6 => fn SetRandomInt(var: i32, max: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
178 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
|
179 9 => fn SetRandomFloatMin(var: i32, amplitude: f32, min: f32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
180 10 => fn StoreX(var: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
181 13 => fn AddInt(var: i32, a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
182 14 => fn SubstractInt(var: i32, a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
183 15 => fn MultiplyInt(var: i32, a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
184 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
|
185 17 => fn ModuloInt(var: i32, a: i32, b: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
186 18 => fn Increment(var: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
187 20 => fn AddFloat(var: i32, a: f32, b: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
188 21 => fn SubstractFloat(var: i32, a: f32, b: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
189 23 => fn DivideFloat(var: i32, a: f32, b: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
190 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
|
191 26 => fn FloatToUnitCircle(var: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
192 27 => fn CompareInts(a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
193 28 => fn CompareFloats(a: f32, b: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
194 29 => fn RelativeJumpIfLowerThan(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
195 30 => fn RelativeJumpIfLowerOrEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
196 31 => fn RelativeJumpIfEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
197 32 => fn RelativeJumpIfGreaterThan(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
198 33 => fn RelativeJumpIfGreaterOrEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
199 34 => fn RelativeJumpIfNotEqual(frame: i32, ip: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
200 35 => fn Call(sub: i32, param1: i32, param2: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
201 36 => fn Return(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
202 39 => fn CallIfEqual(sub: i32, param1: i32, param2: f32, a: i32, b: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
203 43 => fn SetPosition(x: f32, y: f32, z: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
204 45 => fn SetAngleAndSpeed(angle: f32, speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
205 46 => fn SetRotationSpeed(speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
206 47 => fn SetSpeed(speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
207 48 => fn SetAcceleration(acceleration: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
208 49 => fn SetRandomAngle(min: f32, max: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
209 50 => fn SetRandomAngleEx(min: f32, max: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
210 51 => fn TargetPlayer(TODO: f32, speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
211 52 => fn MoveInDecel(duration: i32, angle: f32, speed: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
212 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
|
213 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
|
214 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
|
215 61 => fn StopIn(duration: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
216 63 => fn StopInAccel(duration: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
217 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
|
218 66 => fn ClearScreenBox(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
219 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: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
220 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: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
221 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: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
222 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: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
223 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: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
224 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: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
225 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: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
226 76 => fn SetBulletInterval(interval: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
227 77 => fn SetBulletIntervalEx(interval: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
228 78 => fn DelayAttack(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
229 79 => fn NoDelayAttack(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
230 81 => fn SetBulletLaunchOffset(x: f32, y: f32, z: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
231 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
|
232 83 => fn ChangeBulletsInStarBonus(), |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
233 84 => fn UNK0(UNK: i32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
234 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
|
235 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), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
236 87 => fn SetUpcomingLaserId(id: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
237 88 => fn AlterLaserAngle(id: i32, delta: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
238 90 => fn RepositionLaser(id: i32, ox: f32, oy: f32, oz: f32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
239 92 => fn CanceLaser(id: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
240 93 => fn SetSpellcard(face: i16, number: i16, name: String), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
241 94 => fn Endspellcard(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
242 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
|
243 96 => fn KillAllEnemies(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
244 97 => fn SetAnim(script: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
245 98 => fn SetMultipleAnims(default: i16, end_left: i16, end_right: i16, left: i16, right: i16, UNUSED: i16), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
246 99 => fn SetAuxAnm(number: i32, script: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
247 100 => fn SetDeathAnim(sprite_index: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
248 101 => fn SetBossMode(value: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
249 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
|
250 103 => fn SetHitbox(width: f32, height: f32, depth: f32), |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
251 104 => fn SetCollidable(collidable: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
252 105 => fn SetDamageable(damageable: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
253 106 => fn PlaySound(index: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
254 107 => fn SetDeathFlags(death_flags: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
255 108 => fn SetDeathCallback(sub: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
256 109 => fn MemoryWriteInt(value: i32, index: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
257 111 => fn SetLife(life: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
258 112 => fn SetEllapsedTime(frame: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
259 113 => fn SetLowLifeTrigger(trigger: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
260 114 => fn SetLowLifeCallback(sub: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
261 115 => fn SetTimeout(timeout: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
262 116 => fn SetTimeoutCallback(sub: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
263 117 => fn SetTouchable(touchable: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
264 118 => fn DropParticles(anim: i32, number: u32, r: u8, g: u8, b: u8, UNUSED: u8), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
265 119 => fn DropBonus(number: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
266 120 => fn SetAutomaticOrientation(automatic: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
267 121 => fn CallSpecialFunction(function: i32, argument: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
268 122 => fn UNK1(TODO: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
269 123 => fn SkipFrames(frames: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
270 124 => fn DropSpecificBonus(type_: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
271 125 => fn UNK2(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
272 126 => fn SetRemainingLives(lives: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
273 127 => fn UNK3(TODO: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
274 128 => fn Interrupt(event: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
275 129 => fn InterruptAux(number: i32, event: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
276 130 => fn UNK5(TODO: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
277 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
|
278 132 => fn SetInvisible(invisible: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
279 133 => fn CopyCallbacks(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
280 134 => fn UNK6(), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
281 135 => fn EnableSpellcardBonus(UNKNOW: i32), |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
282 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
283 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
284 fn parse_ecl(input: &[u8]) -> IResult<&[u8], Ecl> { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
285 let i = input; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
286 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
287 let (i, sub_count) = le_u16(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
288 let (mut i, main_count) = le_u16(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
289 assert_eq!(main_count, 0); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
290 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
291 let mut main_offsets = Vec::new(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
292 for _ in 0..3 { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
293 let (i2, offset) = le_u32(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
294 main_offsets.push(offset as usize); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
295 i = i2; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
296 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
297 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
298 let mut sub_offsets = Vec::new(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
299 for _ in 0..sub_count { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
300 let (i2, offset) = le_u32(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
301 sub_offsets.push(offset as usize); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
302 i = i2; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
303 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
304 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
305 // Read all subs. |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
306 let mut subs = Vec::new(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
307 for offset in sub_offsets { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
308 let mut i = &input[offset..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
309 let mut instructions = Vec::new(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
310 loop { |
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
|
311 let (i2, time) = le_i32(i)?; |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
312 let (i2, opcode) = le_u16(i2)?; |
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
|
313 if time == -1 || opcode == 0xffff { |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
314 break; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
315 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
316 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
317 let (i2, size) = le_u16(i2)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
318 let (i2, rank_mask) = le_u16(i2)?; |
664
f08e8e3c6196
Use bitflags for the rank, instead of an u16.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
661
diff
changeset
|
319 let rank_mask = Rank::from_bits(rank_mask).unwrap(); |
650
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
320 let (i2, param_mask) = le_u16(i2)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
321 // FIXME: this - 12 can trigger a panic, fuzz it! |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
322 let data = &i2[..size as usize - 12]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
323 let (data, instr) = parse_sub_instruction_args(data, opcode)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
324 assert_eq!(data.len(), 0); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
325 instructions.push(CallSub { time, rank_mask, param_mask, instr }); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
326 i = &i[size as usize..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
327 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
328 subs.push(Sub { instructions }); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
329 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
330 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
331 // Read all mains (always a single one atm). |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
332 let mut mains = Vec::new(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
333 for offset in main_offsets { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
334 if offset == 0 { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
335 break; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
336 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
337 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
338 let mut i = &input[offset..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
339 let mut instructions = Vec::new(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
340 loop { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
341 let (i2, time) = le_u16(i)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
342 let (i2, sub) = le_u16(i2)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
343 if time == 0xffff && sub == 4 { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
344 break; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
345 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
346 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
347 let (i2, opcode) = le_u16(i2)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
348 let (i2, size) = le_u16(i2)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
349 // FIXME: this - 8 can trigger a panic, fuzz it! |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
350 let data = &i2[..size as usize - 8]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
351 let (data, instr) = parse_main_instruction_args(data, opcode)?; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
352 assert_eq!(data.len(), 0); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
353 instructions.push(CallMain { time, sub, instr }); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
354 i = &i[size as usize..]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
355 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
356 mains.push(Main { instructions }); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
357 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
358 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
359 let ecl = Ecl { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
360 subs, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
361 mains, |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
362 }; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
363 Ok((b"", ecl)) |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
364 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
365 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
366 #[cfg(test)] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
367 mod tests { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
368 use super::*; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
369 use std::io::{self, Read}; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
370 use std::fs::File; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
371 |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
372 #[test] |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
373 fn ecl() { |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
374 let file = File::open("EoSD/ST/ecldata1.ecl").unwrap(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
375 let mut file = io::BufReader::new(file); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
376 let mut buf = vec![]; |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
377 file.read_to_end(&mut buf).unwrap(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
378 let (_, ecl) = Ecl::from_slice(&buf).unwrap(); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
379 assert_eq!(ecl.subs.len(), 24); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
380 assert_eq!(ecl.mains.len(), 1); |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
381 } |
f6bfc9e6dab0
Add an ECL parser.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff
changeset
|
382 } |