From fc6d56141c46806a81759a7de45bfeb8fd644232 Mon Sep 17 00:00:00 2001 From: Explorer09 Date: Sat, 10 Feb 2024 18:31:29 +0800 Subject: [PATCH] makeDetailsMask() special bits code (p10) --- Meter.c | 47 +++++++++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 18 deletions(-) diff --git a/Meter.c b/Meter.c index e0929cec5..64db54332 100644 --- a/Meter.c +++ b/Meter.c @@ -551,33 +551,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; }