annotate src/th06/anm0.rs @ 638:a806f28e94fc

Add anm0 support.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Wed, 03 Jul 2019 22:17:04 +0200
parents
children a8e0219162b6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
638
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
1 //! ANM0 animation format support.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
2
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
3 use nom::{
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
4 IResult,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
5 bytes::complete::{tag, take_while_m_n},
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
6 number::complete::{le_u8, le_u16, le_u32, le_f32},
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
7 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
8 use std::collections::HashMap;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
9
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
10 /// Coordinates of a sprite into the image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
11 #[derive(Debug, Clone)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
12 pub struct Sprite {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
13 index: u32,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
14 x: f32,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
15 y: f32,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
16 width: f32,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
17 height: f32,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
18 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
19
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
20 /// A single instruction, part of a `Script`.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
21 #[derive(Debug, Clone)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
22 struct Instruction {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
23 time: u16,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
24 opcode: u8,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
25 args: Vec<Arg>,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
26 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
27
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
28 /// Script driving an animation.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
29 #[derive(Debug, Clone)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
30 pub struct Script {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
31 instructions: Vec<Instruction>,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
32 interrupts: HashMap<u32, u8>
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
33 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
34
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
35 /// Main struct of the ANM0 animation format.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
36 #[derive(Debug, Clone)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
37 pub struct Anm0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
38 /// Resolution of the image used by this ANM.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
39 pub size: (u32, u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
40
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
41 /// Format of this ANM.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
42 pub format: u32,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
43
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
44 /// File name of the main image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
45 pub first_name: String,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
46
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
47 /// File name of an alpha channel image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
48 pub second_name: String,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
49
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
50 /// A list of sprites, coordinates into the attached image.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
51 pub sprites: Vec<Sprite>,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
52
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
53 /// A map of scripts.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
54 pub scripts: HashMap<u8, Script>,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
55 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
56
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
57 impl Anm0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
58 /// Parse a slice of bytes into an `Anm0` struct.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
59 pub fn from_slice(data: &[u8]) -> Result<Anm0, ()> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
60 // XXX: report the exact nom error instead!
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
61 let (_, anm0) = parse_anm0(data).or_else(|_| Err(()))?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
62 assert_eq!(anm0.len(), 1);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
63 Ok(anm0[0].clone())
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
64 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
65 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
66
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
67 fn parse_name(i: &[u8], is_present: bool) -> IResult<&[u8], String> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
68 if !is_present {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
69 return Ok((i, String::new()));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
70 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
71 let (_, slice) = take_while_m_n(0, 32, |c| c != 0)(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
72 // XXX: no unwrap!
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
73 let string = String::from_utf8(slice.to_vec()).unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
74 Ok((i, string))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
75 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
76
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
77 fn parse_sprite(i: &[u8]) -> IResult<&[u8], Sprite> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
78 let (i, index) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
79 let (i, x) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
80 let (i, y) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
81 let (i, width) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
82 let (i, height) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
83 Ok((i, Sprite {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
84 index,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
85 x,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
86 y,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
87 width,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
88 height,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
89 }))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
90 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
91
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
92 #[derive(Debug, Clone, Copy)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
93 enum Arg {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
94 U8(u8),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
95 U32(u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
96 F32(f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
97 Ptr(u8),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
98 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
99
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
100 fn parse_u8_arg(i: &[u8]) -> IResult<&[u8], Arg> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
101 let (i, value) = le_u8(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
102 Ok((i, Arg::U8(value)))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
103 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
104
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
105 fn parse_u32_arg(i: &[u8]) -> IResult<&[u8], Arg> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
106 let (i, value) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
107 Ok((i, Arg::U32(value)))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
108 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
109
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
110 fn parse_f32_arg(i: &[u8]) -> IResult<&[u8], Arg> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
111 let (i, value) = le_f32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
112 Ok((i, Arg::F32(value)))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
113 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
114
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
115 macro_rules! declare_anm_instructions {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
116 ($($opcode:tt => fn $name:ident($($arg:ident: $arg_type:ty),*)),*,) => {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
117 fn parse_instruction_args(input: &[u8], opcode: u8) -> IResult<&[u8], Vec<Arg>> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
118 let mut args = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
119 let mut i = &input[..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
120 match opcode {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
121 $(
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
122 $opcode => {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
123 $(
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
124 let (i2, data) = match stringify!($arg_type) {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
125 "u8" => parse_u8_arg(i),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
126 "u32" => parse_u32_arg(i),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
127 "f32" => parse_f32_arg(i),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
128 "x8" => parse_u8_arg(i),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
129 _ => unreachable!(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
130 }?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
131 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
132 if stringify!($arg_type) != "x8" {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
133 args.push(data);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
134 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
135 )*
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
136 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
137 )*
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
138 _ => unreachable!()
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
139 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
140 Ok((i, args))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
141 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
142 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
143 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
144
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
145 declare_anm_instructions!{
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
146 0 => fn delete(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
147 1 => fn set_sprite(sprite_number: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
148 2 => fn set_scale(sx: f32, sy: f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
149 3 => fn set_alpha(alpha: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
150 4 => fn set_color(red: u8, green: u8, blue: u8, XXX: x8),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
151 5 => fn jump(instruction: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
152 7 => fn toggle_mirrored(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
153 9 => fn set_3d_rotations(x: f32, y: f32, z: f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
154 10 => fn set_3d_rotations_speed(x: f32, y: f32, z: f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
155 11 => fn set_scale_speed(sx: f32, sy: f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
156 12 => fn fade(alpha: u32, duration: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
157 13 => fn set_blendmode_add(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
158 14 => fn set_blendmode_alphablend(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
159 15 => fn keep_still(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
160 16 => fn set_random_sprite(min_index: u32, amplitude: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
161 17 => fn set_3d_translation(x: f32, y: f32, z: f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
162 18 => fn move_to_linear(x: f32, y: f32, z: f32, duration: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
163 19 => fn move_to_decel(x: f32, y: f32, z: f32, duration: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
164 20 => fn move_to_accel(x: f32, y: f32, z: f32, duration: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
165 21 => fn wait(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
166 22 => fn interrupt_label(label: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
167 23 => fn set_corner_relative_placement(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
168 24 => fn wait_ex(),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
169 25 => fn set_allow_offset(allow: u32), // TODO: better name
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
170 26 => fn set_automatic_orientation(automatic: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
171 27 => fn shift_texture_x(dx: f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
172 28 => fn shift_texture_y(dy: f32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
173 29 => fn set_visible(visible: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
174 30 => fn scale_in(sx: f32, sy: f32, duration: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
175 31 => fn TODO(TODO: u32),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
176 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
177
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
178 fn parse_anm0(input: &[u8]) -> IResult<&[u8], Vec<Anm0>> {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
179 let mut list = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
180 let start_offset = 0;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
181 loop {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
182 let i = &input[start_offset..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
183 let (i, num_sprites) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
184 let (i, num_scripts) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
185 let (i, _) = tag(b"\0\0\0\0")(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
186 let (i, width) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
187 let (i, height) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
188 let (i, format) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
189 let (i, _unknown1) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
190 let (i, first_name_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
191 let (i, _unused) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
192 let (i, second_name_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
193 let (i, version) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
194 let (i, _unknown2) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
195 let (i, _texture_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
196 let (i, has_data) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
197 let (i, _next_offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
198 let (mut i, unknown3) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
199
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
200 assert_eq!(version, 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
201 assert_eq!(unknown3, 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
202 assert_eq!(has_data, 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
203
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
204 let mut sprite_offsets = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
205 for _ in 0..num_sprites {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
206 let (i2, offset) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
207 sprite_offsets.push(offset as usize);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
208 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
209 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
210
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
211 let mut script_offsets = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
212 for _ in 0..num_scripts {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
213 let (i2, index) = le_u32(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
214 let (i2, offset) = le_u32(i2)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
215 script_offsets.push((index as u8, offset as usize));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
216 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
217 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
218
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
219 let i = &input[start_offset + first_name_offset as usize..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
220 let (_, first_name) = parse_name(i, first_name_offset > 0)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
221
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
222 let i = &input[start_offset + second_name_offset as usize..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
223 let (_, second_name) = parse_name(i, second_name_offset > 0)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
224
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
225 let mut sprites = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
226 let mut i;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
227 for offset in sprite_offsets {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
228 i = &input[start_offset + offset..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
229 let (_, sprite) = parse_sprite(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
230 sprites.push(sprite);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
231 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
232
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
233 let mut scripts = HashMap::new();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
234 for (index, offset) in script_offsets {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
235 i = &input[start_offset + offset..];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
236 let mut instruction_offsets = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
237
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
238 let mut instructions = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
239 loop {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
240 let tell = input.len() - i.len();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
241 instruction_offsets.push(tell - (start_offset + offset));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
242 let (i2, time) = le_u16(i)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
243 let (i2, opcode) = le_u8(i2)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
244 // TODO: maybe check against the size of parsed data?
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
245 let (i2, _size) = le_u8(i2)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
246 let (i2, args) = parse_instruction_args(i2, opcode)?;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
247 instructions.push(Instruction { time, opcode, args });
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
248 i = i2;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
249 if opcode == 0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
250 break;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
251 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
252 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
253 let mut interrupts = HashMap::new();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
254 let mut j = 0;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
255 for Instruction { time: _, opcode, args } in &mut instructions {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
256 match opcode {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
257 5 => {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
258 let offset = match args[0] {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
259 Arg::U32(offset) => offset as usize,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
260 _ => panic!("Wrong argument type for jump!"),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
261 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
262 let result = instruction_offsets.binary_search(&offset);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
263 let ptr = match result {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
264 Ok(ptr) => ptr as u8,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
265 // TODO: make that a recoverable error instead.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
266 Err(ptr) => panic!("Instruction offset not found for pointer: {}", ptr),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
267 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
268 args[0] = Arg::Ptr(ptr);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
269 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
270 22 => {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
271 // TODO: maybe also remove this instruction, as the label is already
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
272 // present.
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
273 if let Arg::U32(interrupt) = args[0] {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
274 interrupts.insert(interrupt, j + 1);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
275 } else {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
276 panic!("Wrong argument type for interrupt!");
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
277 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
278 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
279 _ => ()
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
280 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
281 j += 1;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
282 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
283 scripts.insert(index, Script {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
284 instructions,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
285 interrupts,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
286 });
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
287 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
288
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
289 assert!(has_data == 0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
290
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
291 let anm0 = Anm0 {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
292 size: (width, height),
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
293 format,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
294 first_name,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
295 second_name,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
296 sprites,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
297 scripts,
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
298 };
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
299 list.push(anm0);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
300 break;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
301 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
302 Ok((b"", list))
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
303 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
304
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
305 #[cfg(test)]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
306 mod tests {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
307 use super::*;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
308 use std::io::{self, Read};
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
309 use std::fs::File;
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
310
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
311 #[test]
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
312 fn anm0() {
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
313 let file = File::open("/home/linkmauve/games/pc/東方/TH06 ~ The Embodiment of Scarlet Devil/CM/player01.anm").unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
314 let mut file = io::BufReader::new(file);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
315 let mut buf = vec![];
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
316 file.read_to_end(&mut buf).unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
317 let anm0 = Anm0::from_slice(&buf).unwrap();
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
318 assert_eq!(anm0.size, (256, 256));
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
319 assert_eq!(anm0.format, 5);
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
320 }
a806f28e94fc Add anm0 support.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents:
diff changeset
321 }