LS7-Emulator/src/keyboard.c

42 lines
1.3 KiB
C
Raw Normal View History

2025-01-07 14:35:57 +01:00
#include <SDL2/SDL.h>
2024-11-29 03:18:05 +01:00
#include <stdint.h>
extern uint8_t systemRegister;
2024-12-02 10:37:30 +01:00
extern uint8_t keyboardResult;
2025-01-07 14:35:57 +01:00
extern SDL_Scancode currentKey;
2024-11-29 03:18:05 +01:00
2025-01-07 14:35:57 +01:00
/* Virtual Keyrows */
const static SDL_Scancode scanMatrix[48] = {
SDL_SCANCODE_1, SDL_SCANCODE_2, SDL_SCANCODE_3, SDL_SCANCODE_4,
SDL_SCANCODE_5, SDL_SCANCODE_6, SDL_SCANCODE_7, SDL_SCANCODE_8,
SDL_SCANCODE_Q, SDL_SCANCODE_W, SDL_SCANCODE_E, SDL_SCANCODE_R,
SDL_SCANCODE_T, SDL_SCANCODE_Y, SDL_SCANCODE_U, SDL_SCANCODE_I,
SDL_SCANCODE_A, SDL_SCANCODE_S, SDL_SCANCODE_D, SDL_SCANCODE_F,
SDL_SCANCODE_G, SDL_SCANCODE_H, SDL_SCANCODE_J, SDL_SCANCODE_K,
SDL_SCANCODE_Z, SDL_SCANCODE_X, SDL_SCANCODE_C, SDL_SCANCODE_V,
SDL_SCANCODE_B, SDL_SCANCODE_N, SDL_SCANCODE_M, SDL_SCANCODE_COMMA,
SDL_SCANCODE_9, SDL_SCANCODE_0, SDL_SCANCODE_L, SDL_SCANCODE_O,
SDL_SCANCODE_P, SDL_SCANCODE_PERIOD, SDL_SCANCODE_RETURN, SDL_SCANCODE_BACKSPACE,
SDL_SCANCODE_LSHIFT, SDL_SCANCODE_LCTRL, SDL_SCANCODE_LALT, SDL_SCANCODE_SPACE,
SDL_SCANCODE_UP, SDL_SCANCODE_RIGHT, SDL_SCANCODE_DOWN, SDL_SCANCODE_LEFT,
2024-11-29 03:18:05 +01:00
};
2024-12-02 10:37:30 +01:00
void scanKeyboard(){
2024-12-05 11:45:31 +01:00
keyboardResult = 0;
for (int i = 0; i < 8; i++) {
if (currentKey == scanMatrix[i + (((systemRegister & 0x07) % 6) * 8)]){
keyboardResult |= (0x80 >> i);
}
}
keyboardResult ^= 0xFF;
2024-11-29 03:18:05 +01:00
}