From 5355e10218c10cc49ab2fc6285228e41bdbeca37 Mon Sep 17 00:00:00 2001 From: John Breaux Date: Sat, 25 Mar 2023 18:17:55 -0500 Subject: [PATCH] Add utility binaries for disassembly and screenshot viewing --- Cargo.toml | 11 ++++++++++ src/bin/chirp-disasm.rs | 40 ++++++++++++++++++++++++++++++++++++ src/bin/chirp-shot-viewer.rs | 7 +++++++ 3 files changed, 58 insertions(+) create mode 100644 src/bin/chirp-disasm.rs create mode 100644 src/bin/chirp-shot-viewer.rs diff --git a/Cargo.toml b/Cargo.toml index 182930e..04fbe42 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,6 +4,17 @@ version = "0.1.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[profile.release] +opt-level = 'z' +debug = false +rpath = false +lto = true +debug-assertions = false +codegen-units = 1 +panic = 'unwind' +incremental = true +overflow-checks = false + [dependencies] gumdrop = "0.8.1" diff --git a/src/bin/chirp-disasm.rs b/src/bin/chirp-disasm.rs new file mode 100644 index 0000000..c65f633 --- /dev/null +++ b/src/bin/chirp-disasm.rs @@ -0,0 +1,40 @@ +use chirp::{error::Result, prelude::*}; +use gumdrop::*; +use std::{fs::read, path::PathBuf}; +use owo_colors::OwoColorize; + +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Options, Hash)] +struct Arguments { + #[options(help = "Show help text")] + help: bool, + #[options(help = "Load a ROM to run on Chirp", free, required)] + pub file: PathBuf, + #[options(help = "Load address (usually 200)", parse(try_from_str = "parse_hex"))] + pub loadaddr: u16, + #[options(help = "Start disassembling at offset...")] + pub offset: usize, +} + +fn parse_hex(value: &str) -> std::result::Result { + u16::from_str_radix(value, 16) +} + +fn main() -> Result<()> { + let options = Arguments::parse_args_default_or_exit(); + let contents = &read(&options.file)?; + let disassembler = Disassemble::default(); + for (addr, insn) in contents[options.offset..].chunks_exact(2).enumerate() { + let insn = u16::from_be_bytes( + insn.try_into() + .expect("Iterated over 2-byte chunks, got <2 bytes"), + ); + println!( + "{:03x}: {} {:04x}", + 2 * addr + 0x200 + options.offset, + disassembler.instruction(insn), + insn.bright_black(), + + ); + } + Ok(()) +} diff --git a/src/bin/chirp-shot-viewer.rs b/src/bin/chirp-shot-viewer.rs new file mode 100644 index 0000000..e03c6a5 --- /dev/null +++ b/src/bin/chirp-shot-viewer.rs @@ -0,0 +1,7 @@ +use chirp::{error::Result, prelude::*}; +use std::{env::args, fs::read}; + +fn main() -> Result<()> { + bus! {Screen [0..0x100] = &read(args().nth(1).unwrap_or("screen_dump.bin".to_string()))?} + .print_screen() +}