aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-14 22:26:24 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-14 22:26:24 +0100
commit4de5d3b70e1e8ba33e6cb49f94cc77e56a21750f (patch)
tree29ff7f5817a1c042b13045247e4a340cc9aa70a0 /crates
parentfb836cb4cae07b2c66a41ad1413a8cab1a080e6a (diff)
downloadtools.nes-4de5d3b70e1e8ba33e6cb49f94cc77e56a21750f.tar.gz
tools.nes-4de5d3b70e1e8ba33e6cb49f94cc77e56a21750f.zip
readrom: Print addresses for vectors
Signed-off-by: Miquel Sabaté Solà <mikisabate@gmail.com>
Diffstat (limited to 'crates')
-rw-r--r--crates/readrom/src/main.rs40
1 files changed, 39 insertions, 1 deletions
diff --git a/crates/readrom/src/main.rs b/crates/readrom/src/main.rs
index b43ccca..ae2a44c 100644
--- a/crates/readrom/src/main.rs
+++ b/crates/readrom/src/main.rs
@@ -1,4 +1,4 @@
-use clap::{Arg, Command};
+use clap::{arg, Arg, Command};
use header::{Header, Kind};
use std::fs::File;
use std::io::{ErrorKind, Read};
@@ -24,6 +24,22 @@ fn print_header(header: &Header) {
println!(" Mapper:\t{}", header.mapper);
}
+fn print_vectors(addrs: &[u8]) {
+ println!("Vectors:");
+ println!(
+ " NMI:\t\t{:#04x}",
+ u16::from_le_bytes([addrs[0], addrs[1]])
+ );
+ println!(
+ " Reset:\t{:#04x}",
+ u16::from_le_bytes([addrs[2], addrs[3]])
+ );
+ println!(
+ " IRQ:\t\t{:#04x}",
+ u16::from_le_bytes([addrs[4], addrs[5]])
+ );
+}
+
// Print the given `message` and exit(1).
fn die(message: String) {
println!("error: {}", message);
@@ -35,6 +51,7 @@ fn main() {
.version("0.1.0")
.about("Display information about NES/Famicom ROM files.")
.arg(Arg::new("FILE").required(true).help("ROM file to be read"))
+ .arg(arg!(-H --header "Just print the ROM header and quit"))
.get_matches();
let file = match args.get_one::<String>("FILE") {
Some(file) => file,
@@ -49,6 +66,8 @@ fn main() {
return;
};
+ // Header.
+
let mut buf = vec![0u8; 0x10];
if let Err(e) = input.read_exact(&mut buf) {
match e.kind() {
@@ -65,4 +84,23 @@ fn main() {
}
};
print_header(&header);
+
+ if *args.get_one::<bool>("header").unwrap() {
+ std::process::exit(0);
+ }
+
+ // PRG ROM.
+
+ buf = vec![0u8; header.prg_rom_size * 16 * 1024];
+ if let Err(e) = input.read_exact(&mut buf) {
+ match e.kind() {
+ ErrorKind::UnexpectedEof => die("could not read advertised PRG ROM space".to_string()),
+ _ => die(e.to_string()),
+ }
+ }
+
+ // Vectors.
+
+ let vectors = &buf.as_slice()[buf.len() - 6..];
+ print_vectors(vectors);
}