From 7e092363068976b949ad34b719b39592f97e238b Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 6 Aug 2017 08:22:57 +0200 Subject: [PATCH] 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 --- src/Kaleidoscope-Hardware-Model01.cpp | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Kaleidoscope-Hardware-Model01.cpp b/src/Kaleidoscope-Hardware-Model01.cpp index 682a0480..13b19350 100644 --- a/src/Kaleidoscope-Hardware-Model01.cpp +++ b/src/Kaleidoscope-Hardware-Model01.cpp @@ -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;