Properly handle negative numbers

Now -3.141592 and -32768 are valid numbers that's stored correctly in memory
This commit is contained in:
MCUdude 2022-02-18 08:33:09 +01:00
parent 10e05eed21
commit 6e7f38e81f
1 changed files with 2 additions and 2 deletions

View File

@ -428,9 +428,9 @@ static int cmd_write(PROGRAMMER * pgm, struct avrpart * p,
}
}
buf[i - start_offset + bytes_grown] = (write_val >> 0) & 0xFF;
if (write_val > 0xFF || ptr)
if (labs(write_val) > 0xFF || ptr)
buf[i - start_offset + ++bytes_grown] = (write_val >> 8) & 0xFF;
if (write_val > 0xFFFF || ptr) {
if (labs(write_val) > 0xFFFF || ptr) {
buf[i - start_offset + ++bytes_grown] = (write_val >> 16) & 0xFF;
buf[i - start_offset + ++bytes_grown] = (write_val >> 24) & 0xFF;
}