diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-09-07 22:31:33 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-09-07 23:03:55 +0200 |
| commit | a17bd972a99007099057d7901b88732b22d08270 (patch) | |
| tree | fd278e8863d1123598b697751e514051c83f2335 | |
| parent | 2f4caa8e39ac39969522c4a2a285256c9a13b2c6 (diff) | |
| download | tools.nes-a17bd972a99007099057d7901b88732b22d08270.tar.gz tools.nes-a17bd972a99007099057d7901b88732b22d08270.zip | |
vnf: add the 'Machine.halt_on_brk' field
This allows developers to use 'brk' as asserts which can then be
debugged. This is true by default but it can be turned off via the
--no-halting-brk option from runrom.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
| -rw-r--r-- | crates/runrom/src/main.rs | 10 | ||||
| -rw-r--r-- | lib/vnf/src/lib.rs | 9 | ||||
| -rwxr-xr-x | scripts/test-e2e.sh | 2 |
3 files changed, 20 insertions, 1 deletions
diff --git a/crates/runrom/src/main.rs b/crates/runrom/src/main.rs index 8f52f4a..9040261 100644 --- a/crates/runrom/src/main.rs +++ b/crates/runrom/src/main.rs @@ -16,6 +16,7 @@ struct Args { nasm: Option<PathBuf>, dump_memory: bool, until_address: u16, + halt_on_brk: bool, } fn print_help() { @@ -26,6 +27,7 @@ fn print_help() { println!(" -f, --function\t\tRun the code by assuming it's a function."); println!(" -h, --help\t\t\tPrint this message and quit."); println!(" -n, --nasm-directory <PATH>\tPath to the .nasm/ directory."); + println!(" --no-halting-brk\t\tDo not halt execution after a brk instruction."); println!(" -s, --start\t\t\tAddress from where to start (default: reset vector)."); println!(" -u, --until-address\t\tRun until the given address is met."); println!(" -v, --version\t\t\tPrint version information."); @@ -130,6 +132,8 @@ fn parse_arguments() -> Args { let mut start = None; let mut until_address = None; + res.halt_on_brk = true; + // Skip command name. args.next(); @@ -164,6 +168,9 @@ fn parse_arguments() -> Args { } None => die("you need to specify a file for the '-n/--nasm' flag".to_string()), }, + "--no-halting-brk" => { + res.halt_on_brk = false; + } "-u" | "--until-address" => { until_address = args.next(); if until_address.is_none() { @@ -260,12 +267,14 @@ fn run( start: u16, end: u16, assume_function: bool, + halt_on_brk: bool, dump_memory: bool, ) -> Result<(), String> { let mut machine = Machine::from(file, start, MemoryPolicy::default())?; machine.verbose = true; machine.run_function_mode = assume_function; + machine.halt_on_brk = halt_on_brk; machine.until_address(end)?; @@ -303,6 +312,7 @@ fn main() { start, args.until_address, args.assume_function, + args.halt_on_brk, args.dump_memory, ) { Ok(m) => m, diff --git a/lib/vnf/src/lib.rs b/lib/vnf/src/lib.rs index 61f117d..c9ae1a0 100644 --- a/lib/vnf/src/lib.rs +++ b/lib/vnf/src/lib.rs @@ -378,6 +378,10 @@ pub struct Machine { /// The status of both Joypads. joypads: [Joypad; 2], + + /// Whether execution should be halted _after_ a 'brk' instruction no matter + /// what. The break mark will be set accordingly. + pub halt_on_brk: bool, } // Returns a vector of MemoryCell representing the RAM for a Machine, which @@ -487,6 +491,7 @@ impl Machine { should_report_ppu: false, policy, joypads: [Joypad::default(), Joypad::default()], + halt_on_brk: true, }) } @@ -1220,6 +1225,10 @@ impl Machine { let low = &(self.prg_rom[len - 2] as usize); self.pc = high + low; self.skip_pc = true; + + if self.halt_on_brk { + self.active = false; + } } InstructionIdentifier::Rti => { self.pop_status_register()?; diff --git a/scripts/test-e2e.sh b/scripts/test-e2e.sh index 573a729..2dce6fb 100755 --- a/scripts/test-e2e.sh +++ b/scripts/test-e2e.sh @@ -284,7 +284,7 @@ exit_code=$((exit_code + $?)) echo "test: runrom => stack.nes" ./target/debug/nasm -Werror -o tests/out/stack.nes tests/runrom/stack.s -./target/debug/runrom --function --dump-memory tests/out/stack.nes > tests/out/stack.txt +./target/debug/runrom --no-halting-brk --function --dump-memory tests/out/stack.nes > tests/out/stack.txt diff tests/out/stack.txt tests/expected/runrom/stack.txt exit_code=$((exit_code + $?)) |
