Skip to content

Commit 19b09cf

Browse files
committed
Add simple disassembler
1 parent 9a734e0 commit 19b09cf

File tree

6 files changed

+25
-4
lines changed

6 files changed

+25
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ cbm = "0.1"
3838
tempfile = "3.3"
3939
anyhow = "1.0.64"
4040
reedline-repl-rs = "1.0.2"
41+
disasm6502 = "0.2"
4142

4243
[profile.release]
4344
strip = true # Automatically strip symbols from the binary.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ your involvement is very welcome.
6666
- [x] Poke into memory; single value or from file
6767
- [x] Logging with e.g. `export RUST_LOG=info`
6868
- [x] REPL command interface (experimental)
69-
- [ ] Disassembly
69+
- [x] Disassembly (currently only 6502 opcodes)
7070
- [ ] Transfer and mount disk images
7171
- [ ] Load at arbitrary address and optionally start with `SYS`
7272
- [ ] Memory dumps in YAML format

src/commands.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ pub fn peek(
1818
address: String,
1919
length: usize,
2020
outfile: Option<String>,
21+
disassemble: bool,
2122
) -> Result<(), anyhow::Error> {
22-
let bytes = serial::read_memory(port, parse::<u32>(&address)?, length)?;
23+
let start_address = parse::<u32>(&address)?;
24+
let bytes = serial::read_memory(port, start_address, length)?;
2325
match outfile {
2426
Some(name) => io::save_binary(&name, &bytes)?,
25-
None => matrix65::io::hexdump(&bytes, 8),
27+
None => {
28+
if disassemble {
29+
matrix65::io::disassemble(&bytes, start_address);
30+
} else {
31+
matrix65::io::hexdump(&bytes, 8);
32+
}
33+
},
2634
};
2735
Ok(())
2836
}

src/input.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ pub enum Commands {
5959
/// Output to binary file instead of hexdump
6060
#[clap(long, short = 'o')]
6161
outfile: Option<String>,
62+
/// Disassemble instead of hexdump (currently only 6502)
63+
#[clap(long = "dasm", short = 'd', action, conflicts_with = "outfile")]
64+
disassemble: bool,
6265
},
6366

6467
/// Poke into memory with value or file

src/lib/io.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
//! Routines for file; url; and terminal I/O
1616
17+
use disasm6502;
1718
use anyhow::Result;
1819
use cbm::disk;
1920
use cbm::disk::file::FileOps;
@@ -165,3 +166,10 @@ pub fn hexdump(bytes: &[u8], bytes_per_line: usize) {
165166
println!();
166167
});
167168
}
169+
/// Print disassembled bytes
170+
pub fn disassemble(bytes: &[u8], start_address: u32) {
171+
let instructions = disasm6502::from_addr_array(bytes, start_address as u16).unwrap();
172+
for i in instructions {
173+
println!("{}", i);
174+
}
175+
}

src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ fn do_main() -> Result<()> {
5353
address,
5454
length,
5555
outfile,
56-
} => commands::peek(&mut port, address, length, outfile)?,
56+
disassemble,
57+
} => commands::peek(&mut port, address, length, outfile, disassemble)?,
5758

5859
input::Commands::Poke {
5960
address,

0 commit comments

Comments
 (0)