#ifndef C_BINDINGS_LINK_PS2_KEYBOARD_H
#define C_BINDINGS_LINK_PS2_KEYBOARD_H

#ifdef __cplusplus
extern "C" {
#endif

#include <tonc_core.h>

typedef void* C_LinkPS2KeyboardHandle;

typedef void (*C_LinkPS2Keyboard_EventCallback)(u8 event);

C_LinkPS2KeyboardHandle C_LinkPS2Keyboard_create(
    C_LinkPS2Keyboard_EventCallback callback);
void C_LinkPS2Keyboard_destroy(C_LinkPS2KeyboardHandle handle);

bool C_LinkPS2Keyboard_isActive(C_LinkPS2KeyboardHandle handle);
void C_LinkPS2Keyboard_activate(C_LinkPS2KeyboardHandle handle);
void C_LinkPS2Keyboard_deactivate(C_LinkPS2KeyboardHandle handle);

void C_LinkPS2Keyboard_onVBlank(C_LinkPS2KeyboardHandle handle);
void C_LinkPS2Keyboard_onSerial(C_LinkPS2KeyboardHandle handle);

extern C_LinkPS2KeyboardHandle cLinkPS2Keyboard;

inline void C_LINK_PS2_KEYBOARD_ISR_VBLANK() {
  C_LinkPS2Keyboard_onVBlank(cLinkPS2Keyboard);
}

inline void C_LINK_PS2_KEYBOARD_ISR_SERIAL() {
  C_LinkPS2Keyboard_onSerial(cLinkPS2Keyboard);
}

enum C_LINK_PS2_KEYBOARD_KEY {
  C_LINK_PS2_KEYBOARD_KEY_ESC = 118,
  C_LINK_PS2_KEYBOARD_KEY_F1 = 5,
  C_LINK_PS2_KEYBOARD_KEY_F2 = 6,
  C_LINK_PS2_KEYBOARD_KEY_F3 = 4,
  C_LINK_PS2_KEYBOARD_KEY_F4 = 12,
  C_LINK_PS2_KEYBOARD_KEY_F5 = 3,
  C_LINK_PS2_KEYBOARD_KEY_F6 = 11,
  C_LINK_PS2_KEYBOARD_KEY_F7 = 131,
  C_LINK_PS2_KEYBOARD_KEY_F8 = 10,
  C_LINK_PS2_KEYBOARD_KEY_F9 = 1,
  C_LINK_PS2_KEYBOARD_KEY_F10 = 9,
  C_LINK_PS2_KEYBOARD_KEY_F11 = 120,
  C_LINK_PS2_KEYBOARD_KEY_F12 = 7,
  C_LINK_PS2_KEYBOARD_KEY_BACKSPACE = 102,
  C_LINK_PS2_KEYBOARD_KEY_TAB = 13,
  C_LINK_PS2_KEYBOARD_KEY_ENTER = 90,
  C_LINK_PS2_KEYBOARD_KEY_SHIFT_L = 18,
  C_LINK_PS2_KEYBOARD_KEY_SHIFT_R = 89,
  C_LINK_PS2_KEYBOARD_KEY_SUPER = 97,
  C_LINK_PS2_KEYBOARD_KEY_CTRL_L = 20,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_CTRL_R = 224 + 20,
  C_LINK_PS2_KEYBOARD_KEY_ALT_L = 17,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_ALT_R = 224 + 17,
  C_LINK_PS2_KEYBOARD_KEY_SPACE = 41,
  C_LINK_PS2_KEYBOARD_KEY_CAPS_LOCK = 88,
  C_LINK_PS2_KEYBOARD_KEY_NUM_LOCK = 119,
  C_LINK_PS2_KEYBOARD_KEY_SCROLL_LOCK = 126,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_INSERT = 224 + 112,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_DELETE = 224 + 113,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_HOME = 224 + 108,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_END = 224 + 105,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_PAGE_UP = 224 + 125,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_PAGE_DOWN = 224 + 122,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_UP = 224 + 117,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_DOWN = 224 + 114,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_LEFT = 224 + 107,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_RIGHT = 224 + 116,
  C_LINK_PS2_KEYBOARD_KEY_A = 28,
  C_LINK_PS2_KEYBOARD_KEY_B = 50,
  C_LINK_PS2_KEYBOARD_KEY_C = 33,
  C_LINK_PS2_KEYBOARD_KEY_D = 35,
  C_LINK_PS2_KEYBOARD_KEY_E = 36,
  C_LINK_PS2_KEYBOARD_KEY_F = 43,
  C_LINK_PS2_KEYBOARD_KEY_G = 52,
  C_LINK_PS2_KEYBOARD_KEY_H = 51,
  C_LINK_PS2_KEYBOARD_KEY_I = 67,
  C_LINK_PS2_KEYBOARD_KEY_J = 59,
  C_LINK_PS2_KEYBOARD_KEY_K = 66,
  C_LINK_PS2_KEYBOARD_KEY_L = 75,
  C_LINK_PS2_KEYBOARD_KEY_M = 58,
  C_LINK_PS2_KEYBOARD_KEY_N = 49,
  C_LINK_PS2_KEYBOARD_KEY_O = 68,
  C_LINK_PS2_KEYBOARD_KEY_P = 77,
  C_LINK_PS2_KEYBOARD_KEY_Q = 21,
  C_LINK_PS2_KEYBOARD_KEY_R = 45,
  C_LINK_PS2_KEYBOARD_KEY_S = 27,
  C_LINK_PS2_KEYBOARD_KEY_T = 44,
  C_LINK_PS2_KEYBOARD_KEY_U = 60,
  C_LINK_PS2_KEYBOARD_KEY_V = 42,
  C_LINK_PS2_KEYBOARD_KEY_W = 29,
  C_LINK_PS2_KEYBOARD_KEY_X = 34,
  C_LINK_PS2_KEYBOARD_KEY_Y = 53,
  C_LINK_PS2_KEYBOARD_KEY_Z = 26,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_0 = 112,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_1 = 105,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_2 = 114,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_3 = 122,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_4 = 107,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_5 = 115,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_6 = 116,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_7 = 108,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_8 = 117,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_9 = 125,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_PLUS = 121,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_MINUS = 123,
  C_LINK_PS2_KEYBOARD_KEY_SPECIAL_NUMPAD_ENTER = 224 + 90,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_DOT = 113,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_ASTERISK = 124,
  C_LINK_PS2_KEYBOARD_KEY_NUMPAD_SLASH = 74
};

enum C_LINK_PS2_KEYBOARD_EVENT {
  C_LINK_PS2_KEYBOARD_EVENT_SELF_TEST_PASSED = 0xAA,
  C_LINK_PS2_KEYBOARD_EVENT_RELEASE = 240,
  C_LINK_PS2_KEYBOARD_EVENT_SPECIAL = 224
};

#ifdef __cplusplus
}
#endif

#endif  // C_BINDINGS_LINK_PS2_KEYBOARD_H
