start from cli

This commit is contained in:
Daniel Bauer
2020-01-05 15:09:20 +01:00
parent 788648deba
commit bf4505c69f
4 changed files with 28 additions and 7 deletions

View File

@@ -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

View File

@@ -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<String> = 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();

View File

@@ -85,6 +85,7 @@ impl NES {
self.clock();
}
self.ppu.borrow_mut().frame_ready = false;
info!("clock {}", self.clock_count);
}
}

View File

@@ -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);