Skip to content

Commit

Permalink
WIP tui disassembler
Browse files Browse the repository at this point in the history
  • Loading branch information
David Isaksson committed Jan 3, 2024
1 parent 6d20cc3 commit 76be97f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/disassembler/listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,19 @@ impl Listing {
Self::new(ast, 0x8000)
}

/// Generate listing line from an AST Node and its memory address
///
/// E.g. `$8000 20 06 80 JSR $8006`
#[tracing::instrument]
fn generate_line(&self, ins: &ASTInstructionNode) -> String {
let bytes =
Compiler::instruction_to_bytes(ins).expect("Failed to convert instruction to bytes");
let bytes_str = bytes
pub fn generate_line(addr: usize, ins: &ASTInstructionNode) -> String {
let bytes_str = Compiler::instruction_to_bytes(ins)
.expect("Failed to convert instruction to bytes") // TODO: Return result
.iter()
.map(|b| format!("{:02X}", b))
.map(|b| format!("{:02x}", b))
.collect::<Vec<String>>()
.join(" ");
format!("${:04X} {:08} {}\n", self.current_address, bytes_str, ins)

format!("${:04X} {:08} {}\n", addr, bytes_str, ins)
}

#[tracing::instrument]
Expand All @@ -46,7 +49,8 @@ impl Listing {
for node in &self.ast {
// TODO: Add support for other AST nodes
if let ASTNode::Instruction(ins_node) = node {
self.str.push_str(self.generate_line(ins_node).as_str());
self.str
.push_str(Listing::generate_line(self.current_address, ins_node).as_str());
self.current_address += ins_node.size();
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/emulator/tui/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ pub fn render(app: &mut App, frame: &mut Frame) {
app_layout[1],
);

// Disassembled code

// Bottom help text
frame.render_widget(
Paragraph::new(vec![
Expand Down

0 comments on commit 76be97f

Please sign in to comment.