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.

217 lines
9.8 KiB

  1. /* SOURCE: http://www.netbsd.org/docs/Hardware/Machines/DEC/lk201.html */
  2. /**********************************************************************/
  3. /* requires LED number data */
  4. #define LK_LED_ENABLE 0x13 /* light LED */
  5. #define LK_LED_DISABLE 0x11 /* turn off LED */
  6. #define LED_WAIT 0x81 /* Wait LED */
  7. #define LED_COMP 0x82 /* Compose LED */
  8. #define LED_LOCK 0x84 /* Lock LED */
  9. #define LED_HOLD 0x88 /* Hold Screen LED */
  10. #define LED_ALL 0x8F /* All LED's */
  11. /**********************************************************************/
  12. /* Requires volume data byte */
  13. #define LK_CL_ENABLE 0x1B /* keyclick enable. Requires volume */
  14. /* byte. This does not affect the */
  15. /* SHIFT key. The CTRL key requires */
  16. /* LK_CL_ENABLE and LK_CCL_ENABLE to */
  17. /* have been sent before it clicks. */
  18. /* All other keys are only controlled */
  19. /* by LK_CL_ENABLE. */
  20. #define LK_CCL_ENABLE 0xBB /* Enable keyclicks for the CTRL key. */
  21. /* The CTRL keyclick volume is set to */
  22. /* be the same as the rest of the keys */
  23. /* LK_CCL_ENABLE sets a flag in the */
  24. /* keyboard with is logically AND'ed */
  25. /* with the LK_CL_ENABLE flag to enable*/
  26. /* CTRL key keyclicks. */
  27. #define LK_CL_DISABLE 0x99 /* keyclick disable */
  28. #define LK_CCL_DISABLE 0xB9 /* CTRL key keyclick disable */
  29. #define LK_SOUND_CLICK 0x9F /* causes the LK201 to sound a keyclick*/
  30. /* max volume is 0, lowest is 0x7 */
  31. #define LK_PARAM_VOLUME(v) (0x80|((v)&0x7))
  32. /**********************************************************************/
  33. /* requires bell volume data */
  34. #define LK_BELL_ENABLE 0x23 /* enable the keyboard bell. Requires */
  35. /* volume data byte. */
  36. #define LK_BELL_DISABLE 0xA1 /* disable the keyboard bell. */
  37. #define LK_RING_BELL 0xA7 /* ring the keyboard bell */
  38. /* max volume is 0, lowest is 0x7 */
  39. #define LK_PARAM_VOLUME(v) (0x80|((v)&0x7))
  40. /**********************************************************************/
  41. #define LK_UPDOWN 0x86
  42. #define LK_AUTODOWN 0x82
  43. #define LK_DOWN 0x80
  44. #define LK_CMD_MODE(m,div) ((m)|((div)<<3))
  45. #define LK_MODECHG_ACK 0xBA /* sent by the keyboard to acknowledge a */
  46. /* successful mode change. */
  47. #define LK_PFX_KEYDOWN 0xB9 /* indicates that the next byte is a key- */
  48. /* code for a key already down in a */
  49. /* division that has been changed to */
  50. /* LK_UPDOWN. I think this means that if */
  51. /* for example, the 'a' key is in LK_DOWN */
  52. /* mode and the key is being held down and*/
  53. /* division 1 is switched to LK_UPDOWN */
  54. /* mode, the keyboard will produce the */
  55. /* byte LK_PFX_KEYDOWN followed by 0xC2 */
  56. /* (KEY_A). */
  57. #define LK_CMD_RPT_TO_DOWN 0xD9 /* This command causes all divisions which */
  58. /* are programmed for LK_AUTODOWN mode to */
  59. /* be switched to LK_DOWN mode. */
  60. #define LK_CMD_ENB_RPT 0xE3 /* enables auto repeat on the keys */
  61. /* which are in LK_AUTODOWN mode */
  62. #define LK_CMD_DIS_RPT 0xE1 /* disables auto repeat on all keys, but */
  63. /* does not change the mode that the */
  64. /* divisions are programmed to. */
  65. #define LK_CMD_TMP_NORPT 0xD1 /* temporary auto repeat disable. This */
  66. /* command disables auto repeat for the key*/
  67. /* which is currently pressed down. Auto */
  68. /* repeat is re-enabled when another key is*/
  69. /* pressed. */
  70. #define LK_INPUT_ERROR 0xB6 /* sent by the keyboard if it receives an */
  71. /* invalid command. */
  72. #define LK_NO_ERROR 0x00 /* No Error */
  73. #define LK_KDOWN_ERROR 0x3D /* Key down on powerup error */
  74. #define LK_POWER_ERROR 0x3E /* Keyboard failure on pwrup tst */
  75. #define LK_ALLUP 0xB3
  76. /**********************************************************************/
  77. bool mod_shift = false;
  78. bool mod_ctrl = false;
  79. #define KB_CHAR(key_base, key_shift) c = ((mod_shift) ? (key_shift) : (key_base));
  80. void keyboard_handle_key(int key)
  81. {
  82. int c = -1;
  83. switch (key) {
  84. /* Key Division 191-255 */
  85. case 191: KB_CHAR('`', '~'); break; // (xbf): KEY_TILDE
  86. case 192: KB_CHAR('1', '!'); break; // (xc0): KEY_TR_1
  87. case 193: KB_CHAR('q', 'Q'); break; // (xc1): KEY_Q
  88. case 194: KB_CHAR('a', 'A'); break; // (xc2): KEY_A
  89. case 195: KB_CHAR('z', 'Z'); break; // (xc3): KEY_Z
  90. case 197: KB_CHAR('2', '@'); break; // (xc5): KEY_TR_2
  91. case 198: KB_CHAR('w', 'W'); break; // (xc6): KEY_W
  92. case 199: KB_CHAR('s', 'S'); break; // (xc7): KEY_S
  93. case 200: KB_CHAR('x', 'X'); break; // (xc8): KEY_X
  94. case 201: KB_CHAR('<', '>'); break; // (xc9): KEY_LANGLE_RANGLE
  95. case 203: KB_CHAR('3', '#'); break; // (xcb): KEY_TR_3
  96. case 204: KB_CHAR('e', 'E'); break; // (xcc): KEY_E
  97. case 205: KB_CHAR('d', 'D'); break; // (xcd): KEY_D
  98. case 206: KB_CHAR('c', 'C'); break; // (xce): KEY_C
  99. case 208: KB_CHAR('4', '$'); break; // (xd0): KEY_TR_4
  100. case 209: KB_CHAR('r', 'R'); break; // (xd1): KEY_R
  101. case 210: KB_CHAR('f', 'F'); break; // (xd2): KEY_F
  102. case 211: KB_CHAR('v', 'V'); break; // (xd3): KEY_V
  103. case 212: KB_CHAR(' ', ' '); break; // (xd4): KEY_SPACE
  104. case 214: KB_CHAR('5', '%'); break; // (xd6): KEY_TR_5
  105. case 215: KB_CHAR('t', 'T'); break; // (xd7): KEY_T
  106. case 216: KB_CHAR('g', 'G'); break; // (xd8): KEY_G
  107. case 217: KB_CHAR('b', 'B'); break; // (xd9): KEY_B
  108. case 219: KB_CHAR('6', '^'); break; // (xdb): KEY_TR_6
  109. case 220: KB_CHAR('y', 'Y'); break; // (xdc): KEY_Y
  110. case 221: KB_CHAR('h', 'H'); break; // (xdd): KEY_H
  111. case 222: KB_CHAR('n', 'N'); break; // (xde): KEY_N
  112. case 224: KB_CHAR('7', '&'); break; // (xe0): KEY_TR_7
  113. case 225: KB_CHAR('u', 'U'); break; // (xe1): KEY_U
  114. case 226: KB_CHAR('j', 'J'); break; // (xe2): KEY_J
  115. case 227: KB_CHAR('m', 'M'); break; // (xe3): KEY_M
  116. case 229: KB_CHAR('8', '*'); break; // (xe5): KEY_TR_8
  117. case 230: KB_CHAR('i', 'I'); break; // (xe6): KEY_I
  118. case 231: KB_CHAR('k', 'K'); break; // (xe7): KEY_K
  119. case 232: KB_CHAR(',', '<'); break; // (xe8): KEY_COMMA
  120. case 234: KB_CHAR('9', '('); break; // (xea): KEY_TR_9
  121. case 235: KB_CHAR('o', 'O'); break; // (xeb): KEY_O
  122. case 236: KB_CHAR('l', 'L'); break; // (xec): KEY_L
  123. case 237: KB_CHAR('.', '>'); break; // (xed): KEY_PERIOD
  124. case 239: KB_CHAR('0', ')'); break; // (xef): KEY_TR_0
  125. case 240: KB_CHAR('p', 'P'); break; // (xf0): KEY_P
  126. case 242: KB_CHAR(';', ':'); break; // (xf2): KEY_SEMICOLON
  127. case 243: KB_CHAR('/', '?'); break; // (xf3): KEY_QMARK
  128. case 245: KB_CHAR('=', '+'); break; // (xf5): KEY_PLUS
  129. case 246: KB_CHAR(']', '}'); break; // (xf6): KEY_RBRACE
  130. case 247: KB_CHAR('\\', '|'); break; // (xf7): KEY_VBAR
  131. case 249: KB_CHAR('-', '_'); break; // (xf9): KEY_UBAR
  132. case 250: KB_CHAR('[', '{'); break; // (xfa): KEY_LBRACE
  133. case 251: KB_CHAR('\'', '"'); break; // (xfb): KEY_QUOTE
  134. /* Key Division 2: 145 - 165 */
  135. /*146 (x92): KEY_KP_0
  136. 148 (x94): KEY_KP_PERIOD
  137. 149 (x95): KEY_KP_ENTER
  138. 150 (x96): KEY_KP_1
  139. 151 (x97): KEY_KP_2
  140. 152 (x98): KEY_KP_3
  141. 153 (x99): KEY_KP_4
  142. 154 (x9a): KEY_KP_5
  143. 155 (x9b): KEY_KP_6
  144. 156 (x9c): KEY_KP_COMMA
  145. 157 (x9d): KEY_KP_7
  146. 158 (x9e): KEY_KP_8
  147. 159 (x9f): KEY_KP_9
  148. 160 (xa0): KEY_KP_HYPHEN
  149. 161 (xa1): KEY_KP_PF1
  150. 162 (xa2): KEY_KP_PF2
  151. 163 (xa3): KEY_KP_PF3
  152. 164 (xa4): KEY_KP_PF4*/
  153. /* Key Division 3: 188 - 188 */
  154. case 188: c = 0177; Serial.print("<DELETE>"); break; // (xbc): KEY_DELETE
  155. /* Key Division 4: 189 - 190 */
  156. case 189: c = '\n'; break; // (xbd): KEY_RETURN
  157. case 190: c = '\t'; break; // (xbe): KEY_TAB
  158. /* Key Division 5: (176 - 178) */
  159. /*176 (xb0): KEY_LOCK
  160. 177 (xb1): KEY_META*/
  161. /* Key Division 6: (173 - 175) */
  162. case 174: mod_shift = !mod_shift; Serial.print("<SHIFT "); Serial.print(mod_shift); Serial.print(">"); break; // (xae): KEY_SHIFT
  163. case 175: mod_ctrl = !mod_ctrl; Serial.print("<CTRL "); Serial.print(mod_ctrl); Serial.print(">"); break; // (xaf): KEY_CTRL*/
  164. /* Key Division 7: (166 - 168) */
  165. case 167: SerialTty.print("\033[D"); Serial.print("LEFT "); break; // (xa7): KEY_LEFT
  166. case 168: SerialTty.print("\033[C"); Serial.print("RIGHT "); break; // (xa8): KEY_RIGHT
  167. /* Key Division 8: (169 - 172) */
  168. case 169: SerialTty.print("\033[B"); Serial.print("DOWN "); break; // (xa9): KEY_DOWN
  169. case 170: SerialTty.print("\033[A"); Serial.print("UP "); break; // (xaa): KEY_UP
  170. case 171: break; // (xab): KEY_R_SHIFT
  171. case LK_ALLUP:
  172. mod_shift = false;
  173. mod_ctrl = false;
  174. Serial.print("<ALLUP>");
  175. break;
  176. default:
  177. Serial.print(key); Serial.print(' ');
  178. }
  179. if (c != -1) {
  180. Serial.print((char) c);
  181. SerialTty.print((char) c);
  182. }
  183. }