summaryrefslogtreecommitdiff
path: root/src/formats/debug.rs
blob: 23fd34fab273d551f44e2d7f583d585552d5efcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::*;


pub fn format_debug(segments: &[Segment]) -> Result<Vec<u8>, FormatError> {
    let mut output = String::new();
    for segment in segments {
        // Find maximum width of all words in the segment.
        let width = segment.words.iter().map(|w| w.to_string().chars().count()).max().unwrap_or(0);
        let address = &segment.address;
        output.push_str(&format!("SEGMENT: 0x{address:>04x}\n"));
        for word in &segment.words {
            let string = word.to_string();
            let w = width as usize;
            output.push_str(&format!("  {string:>w$}\n"));
        }
    }
    return Ok(output.as_bytes().to_vec());
}