diff --git a/src/keyboard.c b/src/keyboard.c new file mode 100644 index 0000000..4110d82 --- /dev/null +++ b/src/keyboard.c @@ -0,0 +1,28 @@ +#include +#include + +extern uint8_t systemRegister; + +static uint8_t keyboardResult; + +static sfKeyCode scanMatrix[48] = { + sfKeyNum1, sfKeyNum2, sfKeyNum3, sfKeyNum4, sfKeyNum5, sfKeyNum6, sfKeyNum7, sfKeyNum8, + sfKeyQ, sfKeyW, sfKeyE, sfKeyR, sfKeyT, sfKeyY, sfKeyU, sfKeyI, + sfKeyA, sfKeyS, sfKeyD, sfKeyF, sfKeyG, sfKeyH, sfKeyJ, sfKeyK, + sfKeyZ, sfKeyX, sfKeyC, sfKeyV, sfKeyB, sfKeyN, sfKeyM, sfKeyComma, + sfKeyNum9, sfKeyNum0, sfKeyL, sfKeyO, sfKeyP, sfKeyPeriod,sfKeyEnter, sfKeyBackspace, + sfKeyLShift,sfKeyLControl, sfKeyLAlt, sfKeySpace, sfKeyUp, sfKeyRight, sfKeyDown, sfKeyLeft, +}; + + +void scanKeyboard(const sfKeyCode key){ + keyboardResult = 0; + + for (int i = 0; i < 8; i++) { + if (key == scanMatrix[i + (((systemRegister & 0x07) % 6) * 8)]){ + keyboardResult |= (0x80 >> i); + } + } + + keyboardResult ^= 0xFF; +}