diff --git a/src/driver.rs b/src/driver.rs index 74be7e91..63d1b23b 100644 --- a/src/driver.rs +++ b/src/driver.rs @@ -34,7 +34,9 @@ pub enum OutputFormat BinDump, HexDump, Mif, - IntelHex, + IntelHex { + address_unit: usize, + }, DecComma, HexComma, DecSpace, @@ -567,6 +569,11 @@ pub fn parse_output_format( [2, 16].contains(&base) }; + let check_8_16_or_32 = &mut |base: usize| -> bool + { + [8, 16, 32].contains(&base) + }; + let format = { match format_id { @@ -594,7 +601,9 @@ pub fn parse_output_format( "hexdump" => OutputFormat::HexDump, "mif" => OutputFormat::Mif, - "intelhex" => OutputFormat::IntelHex, + "intelhex" => OutputFormat::IntelHex { + address_unit: get_arg_usize("addr_unit", 8, check_8_16_or_32)?, + }, "deccomma" => OutputFormat::DecComma, "hexcomma" => OutputFormat::HexComma, @@ -759,7 +768,8 @@ pub fn format_output( OutputFormat::HexDump => output.format_hexdump(), OutputFormat::Mif => output.format_mif(), - OutputFormat::IntelHex => output.format_intelhex(), + OutputFormat::IntelHex { address_unit } => + output.format_intelhex(address_unit), OutputFormat::DecComma => output.format_separator(10, ", "), OutputFormat::HexComma => output.format_separator(16, ", "), diff --git a/src/usage_help.md b/src/usage_help.md index 3c3eb41c..3e5b741e 100644 --- a/src/usage_help.md +++ b/src/usage_help.md @@ -71,7 +71,7 @@ Examples: * `hexdump` * `mif` -* `intelhex` +* `intelhex,addr_unit:8` * `deccomma` * `hexcomma` diff --git a/src/util/bitvec_format.rs b/src/util/bitvec_format.rs index c2117773..78d9914d 100644 --- a/src/util/bitvec_format.rs +++ b/src/util/bitvec_format.rs @@ -205,10 +205,10 @@ impl util::BitVec result.push_str("END;"); result } - - - pub fn format_intelhex(&self) -> String - { + + + pub fn format_intelhex(&self, address_unit: usize) -> String + { let mut result = String::new(); let mut bytes_left = self.len() / 8 + if self.len() % 8 != 0 { 1 } else { 0 }; @@ -220,13 +220,13 @@ impl util::BitVec result.push(':'); result.push_str(&format!("{:02X}", bytes_in_row)); - result.push_str(&format!("{:04X}", index / 8)); + result.push_str(&format!("{:04X}", index / address_unit)); result.push_str("00"); let mut checksum = 0_u8; checksum = checksum.wrapping_add(bytes_in_row as u8); - checksum = checksum.wrapping_add(((index / 8) >> 8) as u8); - checksum = checksum.wrapping_add((index / 8) as u8); + checksum = checksum.wrapping_add(((index / address_unit) >> 8) as u8); + checksum = checksum.wrapping_add((index / address_unit) as u8); for _ in 0..bytes_in_row {