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.

233 lines
11 KiB

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