Mirror of CollapseOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 line
2.3KB

  1. #include <string.h>
  2. #include <ctype.h>
  3. #include "ti84_kbd.h"
  4. void kbd_init(KBD *kbd)
  5. {
  6. memset(kbd->pressed, 0xff, 8);
  7. kbd->selected = 0xff;
  8. }
  9. uint8_t kbd_rd(KBD *kbd)
  10. {
  11. uint8_t res = 0xff;
  12. for (int i=0; i<8; i++) {
  13. if ((kbd->selected & (1<<i)) == 0) {
  14. res &= kbd->pressed[i];
  15. }
  16. }
  17. return res;
  18. }
  19. void kbd_wr(KBD *kbd, uint8_t val)
  20. {
  21. kbd->selected = val;
  22. }
  23. // The key is separated in two nibble. High nibble is group, low nibble is key.
  24. void kbd_setkey(KBD *kbd, uint8_t key, bool pressed)
  25. {
  26. uint8_t group = kbd->pressed[key>>4];
  27. if (pressed) {
  28. group &= ~(1<<(key&0x7));
  29. } else {
  30. group |= 1<<(key&0x7);
  31. }
  32. kbd->pressed[key>>4] = group;
  33. }
  34. // Attempts to returns a key code corresponding to the specified char. 0 if
  35. // nothing matches.
  36. uint8_t kbd_trans(char c)
  37. {
  38. c = toupper(c);
  39. switch (c) {
  40. case 0x0a:
  41. case 0x0d: return 0x10; // ENTER
  42. case '+': return 0x11;
  43. case '-': return 0x12;
  44. case '*': return 0x13;
  45. case '/': return 0x14;
  46. case '^': return 0x15;
  47. case '3': return 0x21;
  48. case '6': return 0x22;
  49. case '9': return 0x23;
  50. case ')': return 0x24;
  51. case '.': return 0x30;
  52. case '2': return 0x31;
  53. case '5': return 0x32;
  54. case '8': return 0x33;
  55. case '(': return 0x34;
  56. case '0': return 0x40;
  57. case '1': return 0x41;
  58. case '4': return 0x42;
  59. case '7': return 0x43;
  60. case ',': return 0x44;
  61. case 0x7f: return 0x67; // DEL
  62. case '"': return 0x11;
  63. case 'W': return 0x12;
  64. case 'R': return 0x13;
  65. case 'M': return 0x14;
  66. case 'H': return 0x15;
  67. case '?': return 0x20;
  68. case 'V': return 0x22;
  69. case 'Q': return 0x23;
  70. case 'L': return 0x24;
  71. case 'G': return 0x25;
  72. case ':': return 0x30;
  73. case 'Z': return 0x31;
  74. case 'U': return 0x32;
  75. case 'P': return 0x33;
  76. case 'K': return 0x34;
  77. case 'F': return 0x35;
  78. case 'C': return 0x36;
  79. case ' ': return 0x40;
  80. case 'Y': return 0x41;
  81. case 'T': return 0x42;
  82. case 'O': return 0x43;
  83. case 'J': return 0x44;
  84. case 'E': return 0x45;
  85. case 'B': return 0x46;
  86. case 'X': return 0x51;
  87. case 'S': return 0x52;
  88. case 'N': return 0x53;
  89. case 'I': return 0x54;
  90. case 'D': return 0x55;
  91. case 'A': return 0x56;
  92. default: return 0;
  93. }
  94. }