diff --git a/src/main.rs b/src/main.rs index be1d41f..3aae68a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -51,8 +51,12 @@ struct Args { #[arg(short, long)] verbose: bool, - /// Show cycle count + /// Connect the serial port output to stdout #[arg(short, long)] + connect_serial: bool, + + /// Show cycle count + #[arg(long)] cycle_count: bool, /// Show tile window @@ -127,7 +131,7 @@ fn main() { window.topmost(true); let mut cpu = Cpu::new( - Memory::init(bootrom, rom), + Memory::init(bootrom, rom, args.connect_serial), window, args.tile_window, bootrom_enabled, diff --git a/src/processor/memory.rs b/src/processor/memory.rs index e412274..43cb09d 100644 --- a/src/processor/memory.rs +++ b/src/processor/memory.rs @@ -29,7 +29,12 @@ pub struct Memory { } impl Memory { - pub fn init(bootrom: Option>, rom: Rom) -> Self { + pub fn init(bootrom: Option>, rom: Rom, connect_serial: bool) -> Self { + let serial = if connect_serial { + Serial::default().connected() + } else { + Serial::default() + }; Self { bootrom, rom, @@ -45,7 +50,7 @@ impl Memory { user_mode: false, joypad: Joypad::default(), apu: Apu::init_default(), - serial: Serial::default(), + serial, } } diff --git a/src/processor/memory/mmio/serial.rs b/src/processor/memory/mmio/serial.rs index f7500d2..e6daf0f 100644 --- a/src/processor/memory/mmio/serial.rs +++ b/src/processor/memory/mmio/serial.rs @@ -39,6 +39,11 @@ pub struct Serial { } impl Serial { + pub fn connected(mut self) -> Self { + self.is_connected = true; + self + } + pub fn tick(&mut self, steps: usize) -> bool { let mut will_interrupt = false; if !self.is_connected {