From ac3b197d6d5f9a9e44d4e68c24c0e6d49291260c Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Wed, 22 Feb 2023 10:38:27 +1100 Subject: [PATCH] command line option to connect serial to stdout --- src/main.rs | 8 ++++++-- src/processor/memory.rs | 9 +++++++-- src/processor/memory/mmio/serial.rs | 5 +++++ 3 files changed, 18 insertions(+), 4 deletions(-) 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 {