Skip to content

Commit

Permalink
makeDetailsMask() special bits code (q10)
Browse files Browse the repository at this point in the history
  • Loading branch information
Explorer09 committed Feb 13, 2024
1 parent ec21942 commit 45e913b
Showing 1 changed file with 29 additions and 18 deletions.
47 changes: 29 additions & 18 deletions Meter.c
Original file line number Diff line number Diff line change
Expand Up @@ -552,33 +552,44 @@ static uint16_t GraphMeterMode_makeDetailsMask(const GraphColorComputeState* pre
uint16_t mask = 0xFFFF >> blanksAtStart;
// See the code and comments of the "printCellDetails" function for how
// special bits are used.
bool needsTiebreak = (blanksAtStart == blanksAtEnd && (mask & 0xDFFF) == 0x1FFF);
if (needsTiebreak && roundsUpInAscii)
mask &= 0xF7FF;
bool needsTiebreak = blanksAtStart >= 2 && blanksAtStart < 4 && blanksAtStart == blanksAtEnd;

if (new->nCellsPainted - prev->nCellsPainted == 1)
if (new->nCellsPainted - prev->nCellsPainted == 1) {
assert(blanksAtStart + blanksAtEnd < 8);
if (roundsUpInAscii && needsTiebreak) {
mask &= 0xF7FF;
}
mask >>= 8;
} else if (roundsUpInAscii) {
if (blanksAtStart < 4 && (uint8_t)(blanksAtStart + blanksAtEnd % 4) >= 4) {
mask &= 0xF7FF;
}
}

mask &= 0xFFFF << blanksAtEnd;

if (needsTiebreak) {
if (roundsUpInAscii) {
if (new->nCellsPainted - prev->nCellsPainted == 1) {
mask |= 0x0004;
}
} else if (roundsDownInAscii) {
if (roundsUpInAscii) {
if (needsTiebreak) {
mask |= 0x0004;
}
} else if (roundsDownInAscii) {
assert(blanksAtStart <= blanksAtEnd);
if (needsTiebreak) {
mask = (mask & 0xFFEF) | 0x0020;
} else if (new->nCellsPainted - prev->nCellsPainted != 1) {
if (blanksAtEnd < 4 && (uint8_t)(blanksAtStart + blanksAtEnd) >= 4) {
mask = (mask & 0xFFEF) | 0x0020;
}
}
} else if ((mask & 0xBFFD) == 0x1FFC) {
// 5 dots at start, 6 or 7 dots at end
assert(mask == 0x1FFC || mask == 0x1FFE);
mask &= 0xF7FF;
} else if ((mask & 0xBFFD) == 0x3FF8) {
// 6 or 7 dots at start, 5 dots at end
assert(mask == 0x3FF8 || mask == 0x7FF8);
mask &= 0xFFEF;
}

// The following result values are impossible as they lack special bits
// needed for the ASCII display mode.
assert(mask != 0x3FF8); // Should be 0x37F8 or 0x3FE8
assert(mask != 0x7FF8); // Should be 0x77F8 or 0x7FE8
assert(mask != 0x1FFC); // Should be 0x17FC
assert(mask != 0x1FFE); // Should be 0x17FE

return mask;
}

Expand Down

0 comments on commit 45e913b

Please sign in to comment.