diff --git a/Cargo.lock b/Cargo.lock index 3707ad6..9064ce8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -101,6 +101,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "327762f6e5a765692301e5bb513e0d9fef63be86bbc14528052b1cd3e6f03e07" + [[package]] name = "block-buffer" version = "0.10.4" @@ -171,6 +177,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "colored" +version = "2.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2674ec482fbc38012cf31e6c42ba0177b431a0cb6f15fe40efa5aab1bda516f6" +dependencies = [ + "is-terminal", + "lazy_static", + "windows-sys", +] + [[package]] name = "cpufeatures" version = "0.2.11" @@ -212,6 +229,16 @@ version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a26ae43d7bcc3b814de94796a5e736d4029efb0ee900c12e2d54c993ad1a1e07" +[[package]] +name = "errno" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f258a7194e7f7c2a7837a8913aeab7fd8c383457034fa20ce4dd3dcb813e8eb8" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -234,12 +261,29 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "hermit-abi" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" + [[package]] name = "hex-literal" version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6fe2267d4ed49bc07b63801559be28c718ea06c4738b7a03c94df7386d2cde46" +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + [[package]] name = "itertools" version = "0.11.0" @@ -267,6 +311,12 @@ version = "0.2.149" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a08173bc88b7955d1b3145aa561539096c421ac8debde8cbc3612ec635fee29b" +[[package]] +name = "linux-raw-sys" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "969488b55f8ac402214f3f5fd243ebb7206cf82de60d3172994707a4bcc2b829" + [[package]] name = "memchr" version = "2.6.4" @@ -335,6 +385,19 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +[[package]] +name = "rustix" +version = "0.38.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b426b0506e5d50a7d8dafcf2e81471400deb602392c7dd110815afb4eaf02a3" +dependencies = [ + "bitflags 2.4.1", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -353,7 +416,7 @@ version = "0.35.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f7959277b623f1fb9e04aea73686c3ca52f01b2145f8ea16f4ff30d8b7623b1a" dependencies = [ - "bitflags", + "bitflags 1.3.2", "lazy_static", "libc", "sdl2-sys", @@ -418,6 +481,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "colored", "dbg_hex", "hex-literal", "itertools", diff --git a/Cargo.toml b/Cargo.toml index 33278ea..d34ab41 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,6 +8,7 @@ default-run = "siena" [dependencies] anyhow = { version = "1.0.75", features = ["backtrace"] } clap = { version = "4.4.6", features = ["derive"] } +colored = "2.0.4" dbg_hex = "0.1.1" hex-literal = "0.4.1" itertools = "0.11.0" diff --git a/src/bin/siena/main.rs b/src/bin/siena/main.rs index 5fc0565..41047a7 100644 --- a/src/bin/siena/main.rs +++ b/src/bin/siena/main.rs @@ -3,6 +3,7 @@ use std::io::{stdin, Read}; use anyhow::Result; use clap::Parser; +use colored::*; use sdl2::event::Event; use sdl2::keyboard::Keycode; @@ -79,7 +80,7 @@ fn main() -> Result<()> { let eventpump = SDLEventPump::new(); let cart = Cartridge::load(&f); println!("Cartridge: {}", &cart); - let bus = Mainbus::::new(cart, args.bustrace, display, joypads); + let bus = Mainbus::::new(cart, args.bustrace, display, joypads, args.verbose); let reset = bus.read16(0xFFFC); let mut cpu = Cpu65816::>::new(bus, reset); @@ -87,7 +88,7 @@ fn main() -> Result<()> { let mut eventpoll = 0; 'mainloop: loop { if args.verbose { - println!("{}", cpu.dump_state()); + println!("{}", cpu.dump_state().green()); } if args.pause { diff --git a/src/snes/apu/mod.rs b/src/snes/apu/mod.rs index d418330..5027007 100644 --- a/src/snes/apu/mod.rs +++ b/src/snes/apu/mod.rs @@ -1,7 +1,9 @@ pub mod apubus; use anyhow::Result; +use colored::*; +use crate::snes::bus::{Address, BusMember}; use crate::snes::cpu_spc700::cpu::{CpuSpc700, SpcAddress}; use crate::tickable::{Tickable, Ticks}; @@ -17,6 +19,9 @@ pub struct Apu { /// Master ticks received that we can spend. spc_master_credit: Ticks, + + /// Print instructions + verbose: bool, } impl Apu { @@ -34,11 +39,12 @@ impl Apu { 0x00, 0x00, 0xC0, 0xFF, ]; - pub fn new() -> Self { + pub fn new(verbose: bool) -> Self { Self { cpu: CpuSpc700::::new(Apubus::new(&Self::IPL_BIN), Self::IPL_ENTRYPOINT), spc_cycles_taken: 0, spc_master_credit: 0, + verbose, } } } @@ -52,6 +58,9 @@ impl Tickable for Apu { while self.spc_master_credit >= Self::SPC_MASTER_FACTOR { if self.spc_cycles_taken == 0 { + if self.verbose { + println!("{}", self.cpu.dump_state().red()); + } self.spc_cycles_taken += self.cpu.step()?; } self.spc_cycles_taken -= 1; @@ -61,3 +70,13 @@ impl Tickable for Apu { Ok(()) } } + +impl BusMember
for Apu { + fn read(&self, fulladdr: Address) -> Option { + None + } + + fn write(&mut self, fulladdr: Address, val: u8) -> Option<()> { + None + } +} diff --git a/src/snes/bus/mainbus.rs b/src/snes/bus/mainbus.rs index bc42d5b..b0383f8 100644 --- a/src/snes/bus/mainbus.rs +++ b/src/snes/bus/mainbus.rs @@ -4,6 +4,7 @@ use anyhow::Result; use dbg_hex::dbg_hex; use crate::frontend::Renderer; +use crate::snes::apu::Apu; use crate::snes::bus::{Address, Bus, BusMember, ADDRESS_MASK}; use crate::snes::cartridge::Cartridge; use crate::snes::joypad::{Joypad, JOYPAD_COUNT}; @@ -36,6 +37,8 @@ where /// Controllers joypads: [Joypad; JOYPAD_COUNT], + pub apu: Apu, + /// Picture Processing Unit pub ppu: PPU, @@ -225,6 +228,7 @@ where trace: BusTrace, renderer: TRenderer, joypads: [Joypad; JOYPAD_COUNT], + apu_verbose: bool, ) -> Self { Self { cartridge, @@ -235,6 +239,7 @@ where joypads, ppu: PPU::::new(renderer), + apu: Apu::new(apu_verbose), memsel: 0, wmadd: Cell::new(0), @@ -749,6 +754,8 @@ where TRenderer: Renderer, { fn tick(&mut self, ticks: Ticks) -> Result<()> { + self.apu.tick(ticks)?; + // This ratio is not based on anything that makes sense yet for _ in 0..(ticks * 8) { self.ppu.tick(1)?;