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

Loading…
Cancel
Save