diff options
Diffstat (limited to 'src/formats/debug.rs')
-rw-r--r-- | src/formats/debug.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/formats/debug.rs b/src/formats/debug.rs new file mode 100644 index 0000000..23fd34f --- /dev/null +++ b/src/formats/debug.rs @@ -0,0 +1,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()); +} |