diff options
| author | Miquel Sabaté Solà <mssola@mssola.com> | 2026-08-30 00:06:39 +0200 |
|---|---|---|
| committer | Miquel Sabaté Solà <mssola@mssola.com> | 2026-09-06 15:47:50 +0200 |
| commit | ad77503d953302f22a621093ba359e24526892ec (patch) | |
| tree | 8ac6bf8e8839d0ebfe1d2d654cab0870f5a67136 /tests/vnf-tests | |
| parent | e1b830309d86f6b1fff803ed94f34ce7002eb532 (diff) | |
| download | tools.nes-ad77503d953302f22a621093ba359e24526892ec.tar.gz tools.nes-ad77503d953302f22a621093ba359e24526892ec.zip | |
vnf: add support for standard joypads
This means adding constants so developers can actually trigger which key
presses are available at any given read, as well as a simple interface
that allows to add button presses and clear them.
Signed-off-by: Miquel Sabaté Solà <mssola@mssola.com>
Diffstat (limited to 'tests/vnf-tests')
| -rw-r--r-- | tests/vnf-tests/src/main.rs | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/tests/vnf-tests/src/main.rs b/tests/vnf-tests/src/main.rs index 58a19af..7ebf9dd 100644 --- a/tests/vnf-tests/src/main.rs +++ b/tests/vnf-tests/src/main.rs @@ -1,6 +1,6 @@ use std::path::PathBuf; -use vnf::{Machine, MemoryPolicy}; +use vnf::{Joypad, Machine, MemoryPolicy}; use xixanta::opcodes::InstructionIdentifier; #[derive(Default)] @@ -92,6 +92,41 @@ fn run_break_mark_test(path: &String) -> Result<(), String> { Ok(()) } +fn run_joypad_test(path: &String) -> Result<(), String> { + let rom = PathBuf::from(path).join("out/joypad.nes"); + let mut machine = Machine::from(&rom, 0x8000, MemoryPolicy::default())?; + + // Manually change the PC to the reset function. + let len = machine.prg_rom.len(); + let high = (machine.prg_rom[len - 1] as u16) << 8; + let low = machine.prg_rom[len - 2] as u16; + machine.pc = (high + low) as usize; + + // Due to the code of joypad.s, there is a repeating read algorithm. Hence, + // we can to repeat each button combination. + machine.push_inputs_to( + 0, + &[ + // First read. + (Joypad::BUTTON_DOWN | Joypad::BUTTON_B), + (Joypad::BUTTON_DOWN | Joypad::BUTTON_B), + // Second read. + (Joypad::BUTTON_DOWN | Joypad::BUTTON_B), + (Joypad::BUTTON_DOWN | Joypad::BUTTON_B), + ], + ); + machine.run_function_mode = true; + machine.until_address(0xFFFF)?; + + assert_eq!(machine.ram[0x00].value, 2); + assert_eq!(machine.ram[0x01].value, 0); + assert_eq!(machine.ram[0x02].value, 1); + assert_eq!(machine.ram[0x03].value, 0); + assert_eq!(machine.ram[0x04].value, 1); + + Ok(()) +} + fn main() { let args = parse_arguments(); let file = PathBuf::from(args.file.clone()); @@ -103,4 +138,7 @@ fn main() { if let Err(e) = run_break_mark_test(&args.file) { die(e) } + if let Err(e) = run_joypad_test(&args.file) { + die(e) + } } |
