From 9a0695fef3a155564cd1026ed24ef50856ebd1a2 Mon Sep 17 00:00:00 2001 From: pjht Date: Tue, 24 Jan 2023 10:27:13 -0600 Subject: [PATCH] Add a poke command --- src/main.rs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.rs b/src/main.rs index 52e84ac..48a54d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -292,6 +292,33 @@ fn main() -> Result<(), anyhow::Error> { )) }, ) + .with_command( + Command::new("poke") + .arg(Arg::new("address").help("The address to write to").required(true)) + .arg(Arg::new("data").help("The data to write").required(true)) + .arg( + Arg::new("word") + .long("word") + .short('w') + .action(ArgAction::SetTrue) + .help("Write a word instead of a byte"), + ) + .about("Write to a memory address"), + |args, state| { + let address = parse::(args.get_one::("address").unwrap())?; + if args.get_flag("word") { + if (address & 0x1) != 0 { + return Err(anyhow!("Cannot poke a word to a non-aligned address")); + } + let data = parse::(args.get_one::("data").unwrap())?; + state.cpu.bus_mut().write_word(address, data)?; + } else { + let data = parse::(args.get_one::("data").unwrap())?; + state.cpu.bus_mut().write_byte(address, data as u8)?; + } + Ok(None) + } + ) .with_command( Command::new("disas") .arg(Arg::new("addr").help("Address to start disassembly at. Defaults to current PC"))