masking: Follow the hand state bit layout more closely

By not using 32-bit ints, we already saved a noticeable amount of space. If we
follow the `*HandState` bit layout more closely, we can shave off some more
bytes too.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/365/head
Gergely Nagy 7 years ago
parent 8e98e30f62
commit 7e09236306

@ -209,9 +209,9 @@ void Model01::maskKey(byte row, byte col) {
return; return;
if (col >= 8) { if (col >= 8) {
rightHandMask[row] |= 1 << (col - 8); rightHandMask[row] |= 1 << (7 - (col - 8));
} else { } else {
leftHandMask[row] |= 1 << (col); leftHandMask[row] |= 1 << (7 - col);
} }
} }
@ -220,9 +220,9 @@ void Model01::unMaskKey(byte row, byte col) {
return; return;
if (col >= 8) { if (col >= 8) {
rightHandMask[row] &= ~(1 << (col - 8)); rightHandMask[row] &= ~(1 << (7 - (col - 8)));
} else { } else {
leftHandMask[row] &= ~(1 << col); leftHandMask[row] &= ~(1 << (7 - col));
} }
} }
@ -231,21 +231,15 @@ bool Model01::isKeyMasked(byte row, byte col) {
return false; return false;
if (col >= 8) { if (col >= 8) {
return rightHandMask[row] & (1 << (col - 8)); return rightHandMask[row] & (1 << (7 - (col - 8)));
} else { } else {
return leftHandMask[row] & (1 << col); return leftHandMask[row] & (1 << (7 - col));
} }
} }
void Model01::maskHeldKeys(void) { void Model01::maskHeldKeys(void) {
for (byte row = 0; row < ROWS; row++) { memcpy(leftHandMask, leftHandState.rows, sizeof(leftHandMask));
for (byte col = 0; col < COLS / 2; col++) { memcpy(rightHandMask, rightHandState.rows, sizeof(rightHandMask));
if (leftHandState.all & SCANBIT(row, col))
leftHandMask[row] |= 1 << col;
if (rightHandState.all & SCANBIT(row, col))
rightHandMask[row] |= 1 << col;
}
}
} }
HARDWARE_IMPLEMENTATION KeyboardHardware; HARDWARE_IMPLEMENTATION KeyboardHardware;

Loading…
Cancel
Save