Skip to content

Commit

Permalink
disasm: Add * if the last line is the same as current
Browse files Browse the repository at this point in the history
  • Loading branch information
Granddave committed Jan 13, 2024
1 parent 24e889b commit 0ec4571
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/disassembler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub fn disassemble(args: &DisassemblyArgs) -> Result<()> {
.into_iter()
.map(Node::Instruction)
.collect();
println!("{}", listing::generate(0, ast));
println!("{}", listing::generate(0x0000, ast));
Ok(())
}

Expand Down
21 changes: 18 additions & 3 deletions src/disassembler/listing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,30 @@ pub fn generate(program_addr: usize, ast: AST) -> String {
let mut string = String::new();
string.push_str(" Addr Hexdump Instructions\n");
string.push_str("-----------------------------\n");
// $8000 20 06 80 JSR $8006
// $8000 20 06 80 JSR $8006

let mut current_address = program_addr;
let mut last_node: Option<&Node> = None;
let mut first_double = true;
for node in &ast {
let same_as_last = if let Some(last_node) = last_node {
last_node == node
} else {
false
};

// TODO: Add support for other AST nodes
if let Node::Instruction(ins) = node {
string.push_str(generate_line(current_address, ins).as_str());
if let Node::Instruction(ins) = &node {
if same_as_last && first_double {
string.push_str("*\n");
first_double = false;
} else if !same_as_last {
string.push_str(generate_line(current_address, &ins).as_str());
}
current_address += ins.size();
}

last_node = Some(&node);
}

string.clone()
Expand Down

0 comments on commit 0ec4571

Please sign in to comment.