Implement ReadAll and WritePattern modes

This commit is contained in:
NGnius (Graham) 2024-02-18 17:32:30 -05:00
parent 821f538f6d
commit ef5afdee93
2 changed files with 29 additions and 3 deletions

View file

@ -38,7 +38,9 @@ pub enum Operation {
},
/// Write a pattern to the whole address space
WritePattern {
// TODO
/// Bytes to write to every address
#[arg(value_parser = clap_num::maybe_hex::<u8>)]
bytes: Vec<u8>,
},
/// Write a value to a specific address
Write {

View file

@ -4,6 +4,7 @@ use smokepatio::ec::EmbeddedController;
fn main() {
let cli = args::Args::load();
#[cfg(debug_assertions)]
println!("args: {:?}", cli);
let mut ec = EmbeddedController::new(cli.data_address, cli.cmd_address);
@ -15,11 +16,34 @@ fn main() {
}
match cli.op {
args::Operation::ReadAll => todo!(),
args::Operation::ReadAll => {
let (bytes_per_line, range) = if cli.extended { (16, 0..=u16::MAX) } else { (8, 0..=(u8::MAX as u16)) };
for addr in range {
let addr_mod = addr % bytes_per_line;
if addr_mod == 0 {
print!("{:#02x}: ", addr);
}
print!("{:#02x} ", ec.get(addr));
if addr_mod == (bytes_per_line - 1) {
println!("");
} else {
print!(" ");
}
}
println!("");
},
args::Operation::Read { address } => {
println!("{:#02x}", ec.get(address));
},
args::Operation::WritePattern { } => todo!(),
args::Operation::WritePattern { bytes } => {
let range = if cli.extended { 0..=u16::MAX } else { 0..=(u8::MAX as u16) };
for addr in range {
println!("{:#02x}", addr);
for b in bytes.iter() {
ec.set(addr, *b);
}
}
},
args::Operation::Write { address, value } => {
ec.set(address, value);
},