mirror of
https://github.com/Polprzewodnikowy/SummerCart64.git
synced 2024-11-22 05:59:15 +01:00
minor code cleanup
This commit is contained in:
parent
f68461657b
commit
3eae2b92b4
@ -134,8 +134,9 @@ module n64_flashram (
|
|||||||
endcase
|
endcase
|
||||||
end
|
end
|
||||||
end else begin
|
end else begin
|
||||||
if (reg_bus.address[1] && state != STATE_BUFFER) begin
|
if (reg_bus.address[1] && state == STATE_STATUS) begin
|
||||||
status <= reg_bus.wdata[3:0];
|
status[ERASE_DONE] <= 1'b0;
|
||||||
|
status[WRITE_DONE] <= 1'b0;
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
958
sw/deployer/Cargo.lock
generated
958
sw/deployer/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,8 @@ include-flate = { version = "0.2.0", features = ["stable"] }
|
|||||||
md5 = "0.7.0"
|
md5 = "0.7.0"
|
||||||
panic-message = "0.3.0"
|
panic-message = "0.3.0"
|
||||||
rust-ini = "0.18.0"
|
rust-ini = "0.18.0"
|
||||||
serial2 = "0.1.7"
|
serial2 = "0.2.17"
|
||||||
serialport = "4.2.0"
|
serialport = "4.3.0"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
lto = true
|
lto = true
|
||||||
|
@ -166,6 +166,20 @@ const MAX_PACKET_LENGTH: usize = 8 * 1024 * 1024;
|
|||||||
const SUPPORTED_USB_PROTOCOL_VERSION: u16 = 2;
|
const SUPPORTED_USB_PROTOCOL_VERSION: u16 = 2;
|
||||||
|
|
||||||
impl Handler {
|
impl Handler {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
let (line_tx, line_rx) = channel::<String>();
|
||||||
|
let external_line_tx = line_tx.clone();
|
||||||
|
|
||||||
|
spawn(move || stdin_thread(line_tx));
|
||||||
|
|
||||||
|
Handler {
|
||||||
|
header: None,
|
||||||
|
line_rx,
|
||||||
|
external_line_tx,
|
||||||
|
encoding: Encoding::UTF8,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn set_text_encoding(&mut self, encoding: Encoding) {
|
pub fn set_text_encoding(&mut self, encoding: Encoding) {
|
||||||
self.encoding = encoding;
|
self.encoding = encoding;
|
||||||
}
|
}
|
||||||
@ -391,20 +405,6 @@ impl Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new() -> Handler {
|
|
||||||
let (line_tx, line_rx) = channel::<String>();
|
|
||||||
let external_line_tx = line_tx.clone();
|
|
||||||
|
|
||||||
spawn(move || stdin_thread(line_tx));
|
|
||||||
|
|
||||||
Handler {
|
|
||||||
header: None,
|
|
||||||
line_rx,
|
|
||||||
external_line_tx,
|
|
||||||
encoding: Encoding::UTF8,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_file(path: &str) -> Result<Vec<u8>, String> {
|
fn load_file(path: &str) -> Result<Vec<u8>, String> {
|
||||||
if path.len() == 0 {
|
if path.len() == 0 {
|
||||||
return Err(format!("Couldn't open file: Specified path is empty"));
|
return Err(format!("Couldn't open file: Specified path is empty"));
|
||||||
|
@ -417,7 +417,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s
|
|||||||
|
|
||||||
let mut sc64 = init_sc64(connection, true)?;
|
let mut sc64 = init_sc64(connection, true)?;
|
||||||
|
|
||||||
let mut debug_handler = debug::new();
|
let mut debug_handler = debug::Handler::new();
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
"{}\n{}\n{}\n{}",
|
"{}\n{}\n{}\n{}",
|
||||||
@ -627,7 +627,7 @@ fn handle_64dd_command(connection: Connection, args: &_64DDArgs) -> Result<(), s
|
|||||||
fn handle_debug_command(connection: Connection, args: &DebugArgs) -> Result<(), sc64::Error> {
|
fn handle_debug_command(connection: Connection, args: &DebugArgs) -> Result<(), sc64::Error> {
|
||||||
let mut sc64 = init_sc64(connection, true)?;
|
let mut sc64 = init_sc64(connection, true)?;
|
||||||
|
|
||||||
let mut debug_handler = debug::new();
|
let mut debug_handler = debug::Handler::new();
|
||||||
|
|
||||||
if args.euc_jp {
|
if args.euc_jp {
|
||||||
debug_handler.set_text_encoding(debug::Encoding::EUCJP);
|
debug_handler.set_text_encoding(debug::Encoding::EUCJP);
|
||||||
@ -859,7 +859,7 @@ fn handle_server_command(connection: Connection, args: &ServerArgs) -> Result<()
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
sc64::run_server(port, args.address.clone(), |event| match event {
|
sc64::server::run(port, args.address.clone(), |event| match event {
|
||||||
sc64::ServerEvent::Listening(address) => {
|
sc64::ServerEvent::Listening(address) => {
|
||||||
println!(
|
println!(
|
||||||
"{}: Listening on address [{}]",
|
"{}: Listening on address [{}]",
|
||||||
@ -895,8 +895,8 @@ fn handle_server_command(connection: Connection, args: &ServerArgs) -> Result<()
|
|||||||
|
|
||||||
fn init_sc64(connection: Connection, check_firmware: bool) -> Result<sc64::SC64, sc64::Error> {
|
fn init_sc64(connection: Connection, check_firmware: bool) -> Result<sc64::SC64, sc64::Error> {
|
||||||
let mut sc64 = match connection {
|
let mut sc64 = match connection {
|
||||||
Connection::Local(port) => sc64::new_local(port),
|
Connection::Local(port) => sc64::SC64::open_local(port),
|
||||||
Connection::Remote(remote) => sc64::new_remote(remote),
|
Connection::Remote(remote) => sc64::SC64::open_remote(remote),
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
if check_firmware {
|
if check_firmware {
|
||||||
|
@ -2,7 +2,7 @@ mod cic;
|
|||||||
mod error;
|
mod error;
|
||||||
pub mod firmware;
|
pub mod firmware;
|
||||||
mod link;
|
mod link;
|
||||||
mod server;
|
pub mod server;
|
||||||
mod time;
|
mod time;
|
||||||
mod types;
|
mod types;
|
||||||
|
|
||||||
@ -787,7 +787,8 @@ impl SC64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_local(port: Option<String>) -> Result<SC64, Error> {
|
impl SC64 {
|
||||||
|
pub fn open_local(port: Option<String>) -> Result<Self, Error> {
|
||||||
let port = if let Some(port) = port {
|
let port = if let Some(port) = port {
|
||||||
port
|
port
|
||||||
} else {
|
} else {
|
||||||
@ -800,23 +801,11 @@ pub fn new_local(port: Option<String>) -> Result<SC64, Error> {
|
|||||||
Ok(sc64)
|
Ok(sc64)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_remote(address: String) -> Result<SC64, Error> {
|
pub fn open_remote(address: String) -> Result<Self, Error> {
|
||||||
let mut sc64 = SC64 {
|
let mut sc64 = SC64 {
|
||||||
link: link::new_remote(&address)?,
|
link: link::new_remote(&address)?,
|
||||||
};
|
};
|
||||||
sc64.check_device()?;
|
sc64.check_device()?;
|
||||||
Ok(sc64)
|
Ok(sc64)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_server(
|
|
||||||
port: Option<String>,
|
|
||||||
address: String,
|
|
||||||
event_callback: fn(ServerEvent),
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let port = if let Some(port) = port {
|
|
||||||
port
|
|
||||||
} else {
|
|
||||||
list_local_devices()?[0].port.clone()
|
|
||||||
};
|
|
||||||
server::run_server(&port, address, event_callback)
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use super::{
|
use super::{
|
||||||
error::Error,
|
error::Error,
|
||||||
link::{new_serial, Command, DataType, Packet, Response, Serial},
|
link::{list_local_devices, new_serial, Command, DataType, Packet, Response, Serial},
|
||||||
};
|
};
|
||||||
use std::{
|
use std::{
|
||||||
collections::VecDeque,
|
collections::VecDeque,
|
||||||
@ -22,11 +22,16 @@ pub enum ServerEvent {
|
|||||||
Err(String),
|
Err(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn run_server(
|
pub fn run(
|
||||||
port: &str,
|
port: Option<String>,
|
||||||
address: String,
|
address: String,
|
||||||
event_callback: fn(ServerEvent),
|
event_callback: fn(ServerEvent),
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
|
let port = if let Some(port) = port {
|
||||||
|
port
|
||||||
|
} else {
|
||||||
|
list_local_devices()?[0].port.clone()
|
||||||
|
};
|
||||||
let listener = TcpListener::bind(address)?;
|
let listener = TcpListener::bind(address)?;
|
||||||
let listening_address = listener.local_addr()?;
|
let listening_address = listener.local_addr()?;
|
||||||
event_callback(ServerEvent::Listening(listening_address.to_string()));
|
event_callback(ServerEvent::Listening(listening_address.to_string()));
|
||||||
@ -36,7 +41,7 @@ pub fn run_server(
|
|||||||
Ok(mut stream) => {
|
Ok(mut stream) => {
|
||||||
let peer = stream.peer_addr()?.to_string();
|
let peer = stream.peer_addr()?.to_string();
|
||||||
event_callback(ServerEvent::Connected(peer.clone()));
|
event_callback(ServerEvent::Connected(peer.clone()));
|
||||||
match server_accept_connection(port, &mut stream) {
|
match server_accept_connection(port.clone(), &mut stream) {
|
||||||
Ok(()) => event_callback(ServerEvent::Disconnected(peer.clone())),
|
Ok(()) => event_callback(ServerEvent::Disconnected(peer.clone())),
|
||||||
Err(error) => event_callback(ServerEvent::Err(error.to_string())),
|
Err(error) => event_callback(ServerEvent::Err(error.to_string())),
|
||||||
}
|
}
|
||||||
@ -58,14 +63,14 @@ enum Event {
|
|||||||
Closed(Option<Error>),
|
Closed(Option<Error>),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn server_accept_connection(port: &str, stream: &mut TcpStream) -> Result<(), Error> {
|
fn server_accept_connection(port: String, stream: &mut TcpStream) -> Result<(), Error> {
|
||||||
let (event_sender, event_receiver) = channel::<Event>();
|
let (event_sender, event_receiver) = channel::<Event>();
|
||||||
let exit_flag = Arc::new(AtomicBool::new(false));
|
let exit_flag = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let mut stream_writer = BufWriter::new(stream.try_clone()?);
|
let mut stream_writer = BufWriter::new(stream.try_clone()?);
|
||||||
let mut stream_reader = stream.try_clone()?;
|
let mut stream_reader = stream.try_clone()?;
|
||||||
|
|
||||||
let serial = Arc::new(new_serial(port)?);
|
let serial = Arc::new(new_serial(&port)?);
|
||||||
let serial_writer = serial.clone();
|
let serial_writer = serial.clone();
|
||||||
let serial_reader = serial.clone();
|
let serial_reader = serial.clone();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user