diff --git a/README.md b/README.md index a3318ff..81c63d4 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,17 @@ Just another implementation of a NES emulator written in Rust. -**A note of warning:** This is an exploratory coding project with the aim to understand concepts of assembler and emulation in general. If you are looking for a cycle-accurate ready-to-use NES emulator to play some games, this is the wrong one. +**A note of warning:** This is an exploratory coding project with the aim to understand concepts of assembler and emulation in general. If you are looking for a cycle-accurate ready-to-use NES emulator to play some games, this is the wrong one. + +Usage: +``` bash +./jane super_mario.nes + +# With optional start address for the CPU (mainly for debugging) +./jane nestest.nes C000 +``` + +Make sure to compile with `--release` for 60 fps. ## what works * CPU diff --git a/src/main.rs b/src/main.rs index 28585af..49cbfb4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,6 +10,7 @@ extern crate fps_counter; mod nes; +use std::env; use crate::nes::*; use std::path::Path; use piston_window::*; @@ -35,14 +36,23 @@ lazy_static! { } fn main() -> Result<(), Error> { - simple_logger::init_with_level(Level::Warn).unwrap(); - + simple_logger::init_with_level(Level::Info).unwrap(); + let args: Vec = env::args().collect(); + if args.len() < 2 { + bail!("No cartridge supplied. Usage: ./jane cartridge.nes"); + } else { + println!("Loading cartridge: {}", args[1]); + } + let mut nes = NES::new(); - let cartridge = Path::new("test_roms/nestest.nes"); - let cartridge = Cartridge::new(cartridge)?; + let cartridge = Cartridge::new(Path::new(&args[1]))?; nes.insert_cartridge(cartridge); nes.start(); - // nes.cpu.regs.pc = 0xC000; + if args.len() > 2 { + let pc = Addr::from_str_radix(&args[2], 16)?; + println!("Setting PC to {:#06x}", pc); + nes.cpu.regs.pc = pc; + } // disassemble instructions let disasm = Disasm::disassemble(&nes.memory, 0xC000, 0xFFFF).unwrap(); diff --git a/src/nes.rs b/src/nes.rs index 16f08fa..365fe6d 100644 --- a/src/nes.rs +++ b/src/nes.rs @@ -85,6 +85,7 @@ impl NES { self.clock(); } self.ppu.borrow_mut().frame_ready = false; + info!("clock {}", self.clock_count); } } diff --git a/src/nes/cpu.rs b/src/nes/cpu.rs index b76ba7b..c6824f3 100644 --- a/src/nes/cpu.rs +++ b/src/nes/cpu.rs @@ -86,7 +86,7 @@ impl CPU { self.curr_op = opcode; let instruction = Instruction::decode_op(opcode); - info!("{:#06X} {:02X} {} A:{:02X} X:{:02X} Y:{:02X} P:{:02X} SP:{:02X} CYC:{}", + debug!("{:#06X} {:02X} {} A:{:02X} X:{:02X} Y:{:02X} P:{:02X} SP:{:02X} CYC:{}", self.regs.pc-1, opcode, instruction.operation, self.regs.a, self.regs.x, self.regs.y, self.regs.flags, self.regs.sp, self.cycles); self.cycles_ahead += self.run_instruction(mem, instruction);