Add a poke command

This commit is contained in:
pjht 2023-01-24 10:27:13 -06:00
parent f69ade25e9
commit 1237cc4163
Signed by: pjht
GPG Key ID: E911DEB42C25F8E1

View File

@ -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::<u32>(args.get_one::<String>("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::<u16>(args.get_one::<String>("data").unwrap())?;
state.cpu.bus_mut().write_word(address, data)?;
} else {
let data = parse::<u8>(args.get_one::<String>("data").unwrap())?;
state.cpu.bus_mut().write_byte(address, data as u8)?;
}
Ok(None)
}
)
.with_command( .with_command(
Command::new("disas") Command::new("disas")
.arg(Arg::new("addr").help("Address to start disassembly at. Defaults to current PC")) .arg(Arg::new("addr").help("Address to start disassembly at. Defaults to current PC"))