diff --git a/Cargo.lock b/Cargo.lock index 96e8212..f5cad34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,122 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "4.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eb41c13df48950b20eb4cd0eefa618819469df1bffc49d11e8487c4ba0037e5" +dependencies = [ + "atty", + "bitflags", + "clap_lex", + "once_cell", + "strsim", + "termcolor", +] + +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "hermit-abi" +version = "0.1.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" +dependencies = [ + "libc", +] + +[[package]] +name = "libc" +version = "0.2.137" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89" + +[[package]] +name = "once_cell" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" + +[[package]] +name = "os_str_bytes" +version = "6.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b5bf27447411e9ee3ff51186bf7a08e16c341efdde93f4d823e8844429bed7e" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] + [[package]] name = "voctool" version = "0.1.0" +dependencies = [ + "clap", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index e10cd56..007691a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap = { version = "4.0.22", features = ["cargo"] } diff --git a/src/main.rs b/src/main.rs index 99fdd46..b54205c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,31 @@ pub mod voc; fn main() { - /* - parse_voc("_C24FF78A.voc"); - parse_voc("pest.voc"); - parse_voc("C24FF78A.voc"); - parse_voc("pest2.voc"); - */ - //parse_voc("EDEN.MUS"); - //parse_voc("EDEN_.MUS"); + let cmd = clap::Command::new(env!("CARGO_CRATE_NAME")) + .multicall(false) + .arg_required_else_help(true) + .subcommand_value_name("COMMAND") + .subcommand_help_heading("COMMAND") + .subcommand(clap::Command::new("info") + .about("Show information about the ") + .arg( + clap::arg!() + .value_parser(clap::value_parser!(String)) + .required(true) + .help("Filename"), + ), + ); + + let matches = cmd.get_matches(); + let matches = match matches.subcommand() { + Some(("info", arguments)) => { + let filename = arguments.get_one::("file").unwrap(); + let voc = voc::VocFile::from_file(filename); + println!("{:?}", voc); + println!("{:02X?}", voc.to_bytes()); + } + _ => unreachable!("parser should ensure only valid subcommand names are used"), + }; + - let voc = voc::VocFile::from_file("pest2.voc"); - println!("{:?}", voc); - for b in voc.blocks { - println!("{:02X?}", b.to_bytes()); - } } diff --git a/src/voc.rs b/src/voc.rs index 64ab1ee..f9af89e 100644 --- a/src/voc.rs +++ b/src/voc.rs @@ -158,6 +158,32 @@ impl VocFile { } voc } + + pub fn to_bytes(&self) -> Vec { + let mut result: Vec = Vec::new(); + + // Signature1 + let signature = "Creative Voice File".as_bytes(); + result.extend_from_slice(signature); + + // Signature2 + result.extend_from_slice(&[0x1A, 0x1A, 0x00]); + + // Version + result.extend_from_slice(&[self.version.1, self.version.0]); + + // Version Checksum + let version_int = i16::from_le_bytes([self.version.1, self.version.0]); + let checksum = (!version_int + 0x1234).to_le_bytes(); + result.extend_from_slice(&checksum); + + // Iterate Blocks + for block in &self.blocks { + result.extend_from_slice(&*block.to_bytes()); + } + + result + } } type BlockT = Box;