diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-23 16:15:02 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-23 16:15:02 +0100 |
| commit | 66ae61bd357f8b675be3ec9a965d50b1e39f3e8f (patch) | |
| tree | 2d571d43a777d74e632998fbd3217f8fbcf28bc2 /crates | |
| parent | 912b5bab6074d3bb2758c3d489009760d8c519d9 (diff) | |
| download | tools.nes-66ae61bd357f8b675be3ec9a965d50b1e39f3e8f.tar.gz tools.nes-66ae61bd357f8b675be3ec9a965d50b1e39f3e8f.zip | |
xa65: Create hex dumps for both binaries
This allows to compare both binaries more easily with tools such as
vimdiff and the likes.
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/xa65/src/main.rs | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/crates/xa65/src/main.rs b/crates/xa65/src/main.rs index cdfce59..85db01f 100644 --- a/crates/xa65/src/main.rs +++ b/crates/xa65/src/main.rs @@ -1,3 +1,5 @@ +use std::fs::File; +use std::io::prelude::*; use std::path::PathBuf; use std::process::Command; @@ -142,6 +144,50 @@ fn temporary_dir() -> PathBuf { tmp.join(name) } +// Attemps to generate an 'hexdump' with the given `bin` and taking the given +// `src` as an argument for 'hexdump'. The resulting dump will be saved in +// `dst`. +fn hexdump(bin: &PathBuf, src: &PathBuf, dst: &PathBuf) -> bool { + let Ok(nasm) = Command::new(bin).arg("-C").arg(src).output() else { + println!( + "xa65 (warning): could not produce an hexdump of '{}'", + src.display() + ); + return false; + }; + let Ok(mut nasm_file) = File::create(dst) else { + println!( + "xa65 (warning): could not produce an hexdump of '{}'", + src.display() + ); + return false; + }; + if let Err(_) = nasm_file.write_all(nasm.stdout.as_slice()) { + println!( + "xa65 (warning): could not produce an hexdump of '{}'", + src.display() + ); + return false; + } + true +} + +// Attempt to generate 'hexdump' files for both binaries. If this is not +// possible, then it will print a warning and return early. +fn attempt_hexdump(dir: &PathBuf) { + let Some(bin) = find_binary("hexdump") else { + println!( + "xa65 (warning): could not find 'hexdump' in your PATH. \ + A human-readable dump will not be generated" + ); + return; + }; + + if hexdump(&bin, &dir.join("nasm.nes"), &dir.join("nasm.txt")) { + hexdump(&bin, &dir.join("cl65.nes"), &dir.join("cl65.txt")); + } +} + fn main() { // Make sure that the binaries are there. let (nasm, cl65) = match get_binaries() { @@ -214,6 +260,9 @@ fn main() { Ok(diff) => { // If 'diff' failed, show it but don't error out. if !diff.status.success() { + // Try to generate a human-readable diff. + attempt_hexdump(&dir); + println!( "xa65 (error): 'nasm' and 'ca65' have a mismatch. Check the results at {}", dir.display() |
