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"))