From 6eb89688aba49dacf2ee1772aff15ec1fa542a18 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Mon, 4 Sep 2023 20:57:20 +0200 Subject: [PATCH] [SC64][SW] Added ability to send debug commands at startup in deployer --- sw/deployer/src/debug.rs | 9 +++++++++ sw/deployer/src/main.rs | 20 ++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/sw/deployer/src/debug.rs b/sw/deployer/src/debug.rs index 9920f98..734b701 100644 --- a/sw/deployer/src/debug.rs +++ b/sw/deployer/src/debug.rs @@ -18,6 +18,7 @@ pub enum Encoding { pub struct Handler { header: Option>, line_rx: Receiver, + external_line_tx: Sender, encoding: Encoding, } @@ -169,6 +170,10 @@ impl Handler { self.encoding = encoding; } + pub fn send_external_input(&self, input: &str) { + self.external_line_tx.send(input.to_string()).unwrap(); + } + pub fn process_user_input(&self) -> Option { let raw_line = match self.line_rx.try_recv() { Ok(line) => { @@ -388,10 +393,14 @@ impl Handler { pub fn new() -> Handler { let (line_tx, line_rx) = channel::(); + let external_line_tx = line_tx.clone(); + spawn(move || stdin_thread(line_tx)); + Handler { header: None, line_rx, + external_line_tx, encoding: Encoding::UTF8, } } diff --git a/sw/deployer/src/main.rs b/sw/deployer/src/main.rs index 883353a..f02fba5 100644 --- a/sw/deployer/src/main.rs +++ b/sw/deployer/src/main.rs @@ -159,7 +159,11 @@ struct DebugArgs { /// Do not enable save writeback via USB #[arg(long)] - no_writeback: bool + no_writeback: bool, + + /// List of commands to send after connecting to the SC64, semicolon separated (;) + #[arg(long)] + init: Option, } #[derive(Args)] @@ -408,7 +412,8 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s "========== [WARNING] ==========".bold().bright_yellow(), "Do not use this mode when real 64DD accessory is connected to the N64".bright_yellow(), "Doing so might permanently damage either N64, 64DD or SC64".bright_yellow(), - "\"Only 64DD IPL\" mode should be safe on development units without IPL builtin".bright_green() + "\"Only 64DD IPL\" mode should be safe on development units without IPL builtin" + .bright_green() ); sc64.reset_state()?; @@ -478,7 +483,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s let dd_mode = sc64::DdMode::DdIpl; println!("64DD mode set to [{dd_mode}]"); sc64.configure_64dd(dd_mode, None)?; - return Ok(()) + return Ok(()); } let disk_paths: Vec = args @@ -632,6 +637,13 @@ fn handle_debug_command(connection: Connection, args: &DebugArgs) -> Result<(), println!("{}: Started", "[Debug]".bold()); + if let Some(init) = args.init.clone() { + for command in init.split(";") { + println!("{}: {}", "[Init]".bold(), command); + debug_handler.send_external_input(command); + } + } + let exit = setup_exit_flag(); while !exit.load(Ordering::Relaxed) { if let Some(data_packet) = sc64.receive_data_packet()? { @@ -653,7 +665,7 @@ fn handle_debug_command(connection: Connection, args: &DebugArgs) -> Result<(), } else if let Some(user_input) = debug_handler.process_user_input() { match user_input { debug::UserInput::Packet(debug_packet) => sc64.send_debug_packet(debug_packet)?, - debug::UserInput::EOF => break + debug::UserInput::EOF => break, } } }