Add utility binaries for disassembly and screenshot viewing

This commit is contained in:
2023-03-25 18:17:55 -05:00
parent 73a69f3469
commit 5355e10218
3 changed files with 58 additions and 0 deletions

40
src/bin/chirp-disasm.rs Normal file
View File

@@ -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, std::num::ParseIntError> {
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(())
}

View File

@@ -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()
}