Skip to content

Commit

Permalink
add intelhex format argument addr_unit
Browse files Browse the repository at this point in the history
  • Loading branch information
fisherdog1 authored and hlorenzi committed Jan 20, 2024
1 parent 5cc272a commit 0869890
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
16 changes: 13 additions & 3 deletions src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ pub enum OutputFormat
BinDump,
HexDump,
Mif,
IntelHex,
IntelHex {
address_unit: usize,
},
DecComma,
HexComma,
DecSpace,
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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, ", "),
Expand Down
2 changes: 1 addition & 1 deletion src/usage_help.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ Examples:
* `hexdump`

* `mif`
* `intelhex`
* `intelhex,addr_unit:8`

* `deccomma`
* `hexcomma`
Expand Down
14 changes: 7 additions & 7 deletions src/util/bitvec_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand All @@ -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
{
Expand Down

0 comments on commit 0869890

Please sign in to comment.