Add a poke command
This commit is contained in:
parent
f69ade25e9
commit
1237cc4163
27
src/main.rs
27
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::<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(
|
||||
Command::new("disas")
|
||||
.arg(Arg::new("addr").help("Address to start disassembly at. Defaults to current PC"))
|
||||
|
Loading…
Reference in New Issue
Block a user