Add utility binaries for disassembly and screenshot viewing

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

View File

@ -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"

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