From a4a52fd15a87e9096ee7c172e9368ed85159e6e2 Mon Sep 17 00:00:00 2001 From: Mateusz Faderewski Date: Fri, 25 Aug 2023 17:10:22 +0200 Subject: [PATCH] [SC64][SW] Added support for Only 64DD IPL mode in deployer. (#43) And added ability to pipe commands in debug mode. --- sw/deployer/src/debug.rs | 20 +++++++++++++++----- sw/deployer/src/main.rs | 29 +++++++++++++++++++++-------- sw/deployer/src/sc64/mod.rs | 12 +++++++----- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/sw/deployer/src/debug.rs b/sw/deployer/src/debug.rs index 3aacc91..9920f98 100644 --- a/sw/deployer/src/debug.rs +++ b/sw/deployer/src/debug.rs @@ -137,6 +137,11 @@ impl TryFrom<&[u8]> for Heartbeat { } } +pub enum UserInput { + Packet(sc64::DebugPacket), + EOF, +} + macro_rules! success { ($($a: tt)*) => { println!("{}", format!($($a)*).bright_blue()); @@ -164,11 +169,11 @@ impl Handler { self.encoding = encoding; } - pub fn process_user_input(&self) -> Option { - let line = match self.line_rx.try_recv() { + pub fn process_user_input(&self) -> Option { + let raw_line = match self.line_rx.try_recv() { Ok(line) => { if line.len() == 0 { - return None; + return Some(UserInput::EOF); } else { line } @@ -176,6 +181,11 @@ impl Handler { Err(_) => return None, }; + let line = raw_line.trim_end(); + if line.len() == 0 { + return None; + } + let token_count = line.matches("@").count(); if (token_count % 2) != 0 { @@ -235,7 +245,7 @@ impl Handler { ); } - Some(packet) + Some(UserInput::Packet(packet)) } pub fn handle_debug_packet(&mut self, debug_packet: sc64::DebugPacket) { @@ -419,7 +429,7 @@ fn stdin_thread(line_tx: Sender) { loop { let mut line = String::new(); if stdin().read_line(&mut line).is_ok() { - if line_tx.send(line.trim_end().to_string()).is_err() { + if line_tx.send(line.to_string()).is_err() { return; } } diff --git a/sw/deployer/src/main.rs b/sw/deployer/src/main.rs index 07af7a6..883353a 100644 --- a/sw/deployer/src/main.rs +++ b/sw/deployer/src/main.rs @@ -120,7 +120,6 @@ struct _64DDArgs { ddipl: PathBuf, /// Path to the 64DD disk file (.ndd format, can be specified multiple times) - #[arg(required = true)] disk: Vec, /// Path to the ROM file @@ -405,10 +404,11 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s let mut debug_handler = debug::new(); println!( - "{}\n{}\n{}", + "{}\n{}\n{}\n{}", "========== [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() + "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() ); sc64.reset_state()?; @@ -474,6 +474,13 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s sc64.calculate_cic_parameters()?; + if args.disk.len() == 0 { + let dd_mode = sc64::DdMode::DdIpl; + println!("64DD mode set to [{dd_mode}]"); + sc64.configure_64dd(dd_mode, None)?; + return Ok(()) + } + let disk_paths: Vec = args .disk .iter() @@ -493,7 +500,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s let dd_mode = sc64::DdMode::Full; println!("64DD mode set to [{dd_mode} / {drive_type}]"); - sc64.configure_64dd(dd_mode, drive_type)?; + sc64.configure_64dd(dd_mode, Some(drive_type))?; println!( "{}: {}", @@ -587,8 +594,11 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s } _ => {} } - } else if let Some(debug_packet) = debug_handler.process_user_input() { - sc64.send_debug_packet(debug_packet)?; + } 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, + } } } @@ -640,8 +650,11 @@ fn handle_debug_command(connection: Connection, args: &DebugArgs) -> Result<(), } _ => {} } - } else if let Some(debug_packet) = debug_handler.process_user_input() { - sc64.send_debug_packet(debug_packet)?; + } 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 + } } } diff --git a/sw/deployer/src/sc64/mod.rs b/sw/deployer/src/sc64/mod.rs index ff99a29..cb4a85b 100644 --- a/sw/deployer/src/sc64/mod.rs +++ b/sw/deployer/src/sc64/mod.rs @@ -559,13 +559,15 @@ impl SC64 { pub fn configure_64dd( &mut self, dd_mode: DdMode, - drive_type: DdDriveType, + drive_type: Option, ) -> Result<(), Error> { self.command_config_set(Config::DdMode(dd_mode))?; - self.command_config_set(Config::DdSdEnable(Switch::Off))?; - self.command_config_set(Config::DdDriveType(drive_type))?; - self.command_config_set(Config::DdDiskState(DdDiskState::Ejected))?; - self.command_config_set(Config::ButtonMode(ButtonMode::UsbPacket))?; + if let Some(drive_type) = drive_type { + self.command_config_set(Config::DdSdEnable(Switch::Off))?; + self.command_config_set(Config::DdDriveType(drive_type))?; + self.command_config_set(Config::DdDiskState(DdDiskState::Ejected))?; + self.command_config_set(Config::ButtonMode(ButtonMode::UsbPacket))?; + } Ok(()) }