aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mssola@mssola.com>2026-08-27 07:20:54 +0200
committerMiquel Sabaté Solà <mssola@mssola.com>2026-08-27 07:20:54 +0200
commit698f12a7b4cf403a53e98d5bd3f7318e107079f9 (patch)
treeb6f8fbad60d888d6a660036ab8ccacf3efa9d3c7
parent50ebac34fec99c853b2f010bfd100c11b5e0a603 (diff)
downloadtools.nes-698f12a7b4cf403a53e98d5bd3f7318e107079f9.tar.gz
tools.nes-698f12a7b4cf403a53e98d5bd3f7318e107079f9.zip
Change the first argument of Machine::from() into a &Path
This makes for a saner API, and some users (e.g. vnf-tests) don't have to go over backwards to provide a parameter they already had as a PathBuf. Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
-rw-r--r--crates/runrom/src/main.rs5
-rw-r--r--lib/vnf/src/lib.rs8
-rw-r--r--tests/vnf-tests/src/main.rs4
3 files changed, 10 insertions, 7 deletions
diff --git a/crates/runrom/src/main.rs b/crates/runrom/src/main.rs
index 3a18946..4388766 100644
--- a/crates/runrom/src/main.rs
+++ b/crates/runrom/src/main.rs
@@ -255,7 +255,7 @@ fn start_from_reset_vector(file: &String) -> u16 {
}
fn run(
- file: &String,
+ file: &Path,
start: u16,
end: u16,
assume_function: bool,
@@ -295,9 +295,10 @@ fn main() {
Some(s) => s,
None => start_from_reset_vector(&args.file),
};
+ let file = PathBuf::from(args.file.clone());
match run(
- &args.file,
+ &file,
start,
args.until_address,
args.assume_function,
diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs
index e9c7539..b4e2399 100644
--- a/lib/vnf/src/lib.rs
+++ b/lib/vnf/src/lib.rs
@@ -4,6 +4,7 @@ use std::collections::HashMap;
use std::fs::File;
use std::io::{ErrorKind, Read};
use std::ops::Range;
+use std::path::Path;
use xixanta::opcodes::AddressingMode;
use xixanta::opcodes::{Instruction, InstructionIdentifier, OPCODES};
@@ -337,9 +338,12 @@ impl Machine {
/// Initialize a Machine object by reading the ROM file located at
/// 'file'. The machine should be initialized to start from the 'start'
/// address, and the memory should be initialized with the given 'policy'.
- pub fn from(file: &String, start: u16, policy: MemoryPolicy) -> Result<Self, String> {
+ pub fn from(file: &Path, start: u16, policy: MemoryPolicy) -> Result<Self, String> {
let Ok(mut input) = File::open(file) else {
- return Err(format!("failed to open the given file '{}'", file));
+ return Err(format!(
+ "failed to open the given file '{}'",
+ file.display()
+ ));
};
// Read the header in order to detect the PRG ROM size.
diff --git a/tests/vnf-tests/src/main.rs b/tests/vnf-tests/src/main.rs
index 6c62dbd..58a19af 100644
--- a/tests/vnf-tests/src/main.rs
+++ b/tests/vnf-tests/src/main.rs
@@ -53,9 +53,7 @@ fn parse_arguments() -> Args {
fn run_break_mark_test(path: &String) -> Result<(), String> {
let rom = PathBuf::from(path).join("out/stack.nes");
- let roms: String = rom.to_string_lossy().into_owned().to_string();
-
- let mut machine = Machine::from(&roms, 0x8000, MemoryPolicy::default())?;
+ let mut machine = Machine::from(&rom, 0x8000, MemoryPolicy::default())?;
// Get out of <start>
let _ = machine.next_iteration();