1
0

ps2.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * PS/2 Keyboard library
  3. * Library for handling PS/2 Scancodes
  4. * Reads scancodes and translates them to ASCII values
  5. * For certain extended keys like the arrow keys,
  6. * a virtual code > 256 is used.
  7. * Writes resulting code to hid FIFO.
  8. *
  9. * TODO:
  10. * - implement alt, control
  11. * - implement caps
  12. * - implement F-keys
  13. * - implement ps, sl, pb
  14. * - implement windows key
  15. */
  16. #define PS2_ADDR 0xC02740
  17. #define PS2_DATA_OFFSET 3
  18. // uses PS2SCANCODES.c
  19. // uses hidfifo.c
  20. word ps2caps = 0;
  21. word ps2shifted = 0;
  22. word ps2controlled = 0;
  23. word ps2alted = 0;
  24. word ps2extended = 0;
  25. word ps2released = 0;
  26. void PS2_HandleInterrupt()
  27. {
  28. word *scanCode = (word *) PS2_ADDR;
  29. // last key was a break code
  30. if (ps2released)
  31. {
  32. // left or right shift
  33. if (*scanCode == 0x59 || *scanCode == 0x12)
  34. ps2shifted = 0;
  35. // extended
  36. if (ps2extended)
  37. ps2extended = 0;
  38. if (*scanCode == 0x14)
  39. ps2controlled = 0;
  40. ps2released = 0;
  41. }
  42. else
  43. {
  44. // extended
  45. if (*scanCode == 0xE0)
  46. {
  47. ps2extended = 1;
  48. }
  49. else
  50. {
  51. if (*scanCode == 0x59 || *scanCode == 0x12) // left or right shift
  52. ps2shifted = 1;
  53. else if (*scanCode == 0xF0) // break code
  54. ps2released = 1;
  55. else if (*scanCode == 0x14) // control
  56. ps2controlled = 1;
  57. else
  58. {
  59. if (ps2extended)
  60. {
  61. word *tableExtended = (word*) &DATA_PS2SCANCODE_EXTENDED;
  62. tableExtended += PS2_DATA_OFFSET; // set offset to data in function
  63. HID_FifoWrite(*(tableExtended+*scanCode));
  64. }
  65. else if (ps2shifted)
  66. {
  67. word *tableShifted = (word*) &DATA_PS2SCANCODE_SHIFTED;
  68. tableShifted += PS2_DATA_OFFSET; // set offset to data in function
  69. HID_FifoWrite(*(tableShifted+*scanCode));
  70. }
  71. else
  72. {
  73. word *tableNomal = (word*) &DATA_PS2SCANCODE_NORMAL;
  74. tableNomal += PS2_DATA_OFFSET; // set offset to data in function
  75. HID_FifoWrite(*(tableNomal+*scanCode));
  76. }
  77. }
  78. }
  79. }
  80. }