()
| 216 | } |
| 217 | |
| 218 | pub fn init() -> Cache { |
| 219 | let huff_file = fs::read(DATADIR.to_owned() + "/VGADICT.WL1") |
| 220 | .expect("Something went wrong reading the file"); |
| 221 | |
| 222 | let mut huff: Vec<(u16, u16)> = Vec::new(); |
| 223 | |
| 224 | for i in huff_file.chunks_exact(4) { |
| 225 | let bit0 = u16::from_le_bytes([i[0], i[1]]); |
| 226 | let bit1 = u16::from_le_bytes([i[2], i[3]]); |
| 227 | huff.push((bit0, bit1)); |
| 228 | } |
| 229 | |
| 230 | let headers_file = fs::read(DATADIR.to_owned() + "/VGAHEAD.WL1") |
| 231 | .expect("Something went wrong reading the file"); |
| 232 | |
| 233 | let mut buffer = [0u8; 4]; |
| 234 | let mut headers: Vec<u32> = Vec::new(); |
| 235 | |
| 236 | for i in headers_file.chunks_exact(3) { |
| 237 | buffer[..3].copy_from_slice(i); |
| 238 | headers.push(u32::from_le_bytes(buffer)); |
| 239 | } |
| 240 | |
| 241 | let graph_file = fs::read(DATADIR.to_owned() + "/VGAGRAPH.WL1") |
| 242 | .expect("Something went wrong reading the file"); |
| 243 | |
| 244 | let a = headers[1] as usize; |
| 245 | let pictable_bytes = huff_expand(&huff, &graph_file[4..a], (NUMPICS + 3) * 4); |
| 246 | |
| 247 | let mut pics: Vec<Picture> = Vec::new(); |
| 248 | |
| 249 | for chunk in STARTPICS..GETPSYCHEDPIC + 1 { |
| 250 | let i = (chunk - STARTPICS) * 4; |
| 251 | let width = u16::from_le_bytes([pictable_bytes[i], pictable_bytes[i + 1]]); |
| 252 | let height = u16::from_le_bytes([pictable_bytes[i + 2], pictable_bytes[i + 3]]); |
| 253 | let data = load_graphic(&graph_file, &headers, &huff, chunk); |
| 254 | |
| 255 | pics.push(Picture { |
| 256 | width: width as u32, |
| 257 | height: height as u32, |
| 258 | data, |
| 259 | }) |
| 260 | } |
| 261 | |
| 262 | let vswap_file = |
| 263 | fs::read(DATADIR.to_owned() + "/VSWAP.WL1").expect("Something went wrong reading the file"); |
| 264 | |
| 265 | let chunks_in_file = u16::from_le_bytes([vswap_file[0], vswap_file[1]]) as usize; |
| 266 | let pm_sprite_start = u16::from_le_bytes([vswap_file[2], vswap_file[3]]) as usize; |
| 267 | let pm_sound_start = u16::from_le_bytes([vswap_file[4], vswap_file[5]]) as usize; |
| 268 | let mut page_offsets: Vec<u32> = Vec::new(); |
| 269 | let mut page_lengths: Vec<u16> = Vec::new(); |
| 270 | let offsets_start = 6; |
| 271 | let offsets_end = offsets_start + 4 * (chunks_in_file + 1); |
| 272 | let lengths_start = offsets_end; |
| 273 | let lengths_end = lengths_start + 2 * chunks_in_file; |
| 274 | |
| 275 | for i in vswap_file[offsets_start..offsets_end].chunks_exact(4) { |
no test coverage detected