diff --git a/Cargo.lock b/Cargo.lock index 8eeba79..8ccc5df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,12 @@ version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" +[[package]] +name = "adler2" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" + [[package]] name = "ahash" version = "0.8.11" @@ -510,6 +516,15 @@ dependencies = [ "libc", ] +[[package]] +name = "crc32fast" +version = "1.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a97769d94ddab943e4510d138150169a2758b5ef3eb191a9ee688de3e23ef7b3" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam-utils" version = "0.8.21" @@ -576,6 +591,16 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "flate2" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c" +dependencies = [ + "crc32fast", + "miniz_oxide", +] + [[package]] name = "fnv" version = "1.0.7" @@ -1028,6 +1053,15 @@ dependencies = [ "paste", ] +[[package]] +name = "miniz_oxide" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394" +dependencies = [ + "adler2", +] + [[package]] name = "naga" version = "0.19.2" @@ -1813,10 +1847,11 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "svc16" -version = "0.7.2" +version = "0.7.3" dependencies = [ "anyhow", "clap", + "flate2", "gilrs", "pixels", "thiserror 2.0.3", diff --git a/Cargo.toml b/Cargo.toml index 80c57fc..78232f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "svc16" -version = "0.7.2" +version = "0.7.3" edition = "2021" authors = ["Jan Neuendorf"] description = "An emulator for a simple virtual computer" @@ -9,6 +9,7 @@ license="MIT" [dependencies] anyhow = "1.0.93" clap = { version = "4.5.21", features = ["derive"] } +flate2 = "1.0.35" gilrs = { version = "0.11.0",optional=true} # There seems to be some incompatibility with the latest crates.io version of pixels? pixels = { git = "https://github.com/parasyte/pixels.git", rev = "d4df286"} diff --git a/src/cli.rs b/src/cli.rs index dd67c19..bb76e4a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -3,6 +3,7 @@ use clap::Parser; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] pub struct Cli { + #[arg(help = "(Decompressed if it ends in .gz)")] pub program: String, #[arg(short, long, default_value = "1", help = "Set initial window scaling")] diff --git a/src/utils.rs b/src/utils.rs index ec59669..d890ba9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,10 @@ +use std::io::Read; + use crate::RES; use anyhow::Result; +use flate2::read::GzDecoder; use pixels::Pixels; +use std::fs::File; use winit::{ event::MouseButton, event_loop::EventLoopWindowTarget, @@ -54,9 +58,15 @@ pub fn build_gamepad_map() -> InputMap { } pub fn read_u16s_from_file(file_path: &str) -> Result> { - use std::io::{BufReader, Read}; - let file = std::fs::File::open(file_path)?; - let mut reader = BufReader::new(file); + let mut file = File::open(file_path)?; + if file_path.ends_with(".gz") { + read_u16s_to_buffer(&mut GzDecoder::new(file)) + } else { + read_u16s_to_buffer(&mut file) + } +} + +fn read_u16s_to_buffer(reader: &mut T) -> Result> { let mut buffer = [0u8; 2]; let mut u16s = Vec::new(); while reader.read_exact(&mut buffer).is_ok() {