Leaked source code of windows server 2003
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.

297 lines
6.9 KiB

  1. /*++
  2. Copyright (c) 1997 Microsoft Corporation
  3. Module Name:
  4. input.c
  5. Author:
  6. Ken Reneris Oct-2-1997
  7. Abstract:
  8. --*/
  9. #include "bootx86.h"
  10. #include "displayp.h"
  11. #include "stdio.h"
  12. //
  13. // Takes any pending input and converts it into a KEY value. Non-blocking, returning 0 if no input available.
  14. //
  15. ULONG
  16. BlGetKey()
  17. {
  18. ULONG Key = 0;
  19. UCHAR Ch;
  20. ULONG Count;
  21. if (ArcGetReadStatus(BlConsoleInDeviceId) == ESUCCESS) {
  22. ArcRead(BlConsoleInDeviceId, &Ch, sizeof(Ch), &Count);
  23. if (Ch == ASCI_CSI_IN) {
  24. if (ArcGetReadStatus(BlConsoleInDeviceId) == ESUCCESS) {
  25. ArcRead(BlConsoleInDeviceId, &Ch, sizeof(Ch), &Count);
  26. //
  27. // All the function keys start with ESC-O
  28. //
  29. switch (Ch) {
  30. case 'O':
  31. ArcRead(BlConsoleInDeviceId, &Ch, sizeof(Ch), &Count); // will not or block, as the buffer is already filled
  32. switch (Ch) {
  33. case 'P':
  34. Key = F1_KEY;
  35. break;
  36. case 'Q':
  37. Key = F2_KEY;
  38. break;
  39. case 'w':
  40. Key = F3_KEY;
  41. break;
  42. case 'x':
  43. Key = F4_KEY;
  44. break;
  45. case 't':
  46. Key = F5_KEY;
  47. break;
  48. case 'u':
  49. Key = F6_KEY;
  50. break;
  51. case 'r':
  52. Key = F8_KEY;
  53. break;
  54. case 'M':
  55. Key = F10_KEY;
  56. break;
  57. case 'A':
  58. Key = F11_KEY;
  59. break;
  60. case 'B':
  61. Key = F12_KEY;
  62. break;
  63. }
  64. break;
  65. case 'A':
  66. Key = UP_ARROW;
  67. break;
  68. case 'B':
  69. Key = DOWN_ARROW;
  70. break;
  71. case 'C':
  72. Key = RIGHT_KEY;
  73. break;
  74. case 'D':
  75. Key = LEFT_KEY;
  76. break;
  77. case 'H':
  78. Key = HOME_KEY;
  79. break;
  80. case 'K':
  81. Key = END_KEY;
  82. break;
  83. case '@':
  84. Key = INS_KEY;
  85. break;
  86. case 'P':
  87. Key = DEL_KEY;
  88. break;
  89. case TAB_KEY:
  90. Key = BACKTAB_KEY;
  91. break;
  92. }
  93. } else { // Single escape key, as no input is waiting.
  94. Key = ESCAPE_KEY;
  95. }
  96. } else if (Ch == 0x8) {
  97. Key = BKSP_KEY;
  98. } else {
  99. Key = (ULONG)Ch;
  100. }
  101. }
  102. return Key;
  103. }
  104. VOID
  105. BlInputString(
  106. IN ULONG Prompt,
  107. IN ULONG CursorX,
  108. IN ULONG PosY,
  109. IN PUCHAR String,
  110. IN ULONG MaxLength
  111. )
  112. {
  113. PTCHAR PromptString;
  114. ULONG TextX, TextY;
  115. ULONG Length, Index;
  116. UCHAR CursorChar[2];
  117. ULONG Key;
  118. PUCHAR p;
  119. ULONG i;
  120. ULONG Count;
  121. PromptString = BlFindMessage(Prompt);
  122. Length = strlen((PCHAR)String);
  123. CursorChar[1] = 0;
  124. //
  125. // Print prompt
  126. //
  127. ARC_DISPLAY_POSITION_CURSOR(CursorX, PosY);
  128. ArcWrite(BlConsoleOutDeviceId, PromptString, _tcslen(PromptString), &Count);
  129. //
  130. // Indent cursor to right of prompt
  131. //
  132. CursorX += _tcslen(PromptString);
  133. TextX = CursorX;
  134. Key = 0;
  135. for (; ;) {
  136. TextY = TextX + Length;
  137. if (CursorX > TextY) {
  138. CursorX = TextY;
  139. }
  140. if (CursorX < TextX) {
  141. CursorX = TextX;
  142. }
  143. Index = CursorX - TextX;
  144. String[Length] = 0;
  145. //
  146. // Display current string
  147. //
  148. ARC_DISPLAY_POSITION_CURSOR(TextX, PosY);
  149. ArcWrite(BlConsoleOutDeviceId, String, strlen((PCHAR)String), &Count);
  150. ArcWrite(BlConsoleOutDeviceId, " ", sizeof(" "), &Count);
  151. if (Key == 0x0d) { // enter key?
  152. break ;
  153. }
  154. //
  155. // Display cursor
  156. //
  157. ARC_DISPLAY_POSITION_CURSOR(CursorX, PosY);
  158. ARC_DISPLAY_INVERSE_VIDEO();
  159. CursorChar[0] = String[Index] ? String[Index] : ' ';
  160. ArcWrite(BlConsoleOutDeviceId, CursorChar, sizeof(UCHAR), &Count);
  161. ARC_DISPLAY_ATTRIBUTES_OFF();
  162. ARC_DISPLAY_POSITION_CURSOR(CursorX, PosY);
  163. //
  164. // Get key and process it
  165. //
  166. while ((Key = BlGetKey()) == 0) {
  167. }
  168. switch (Key) {
  169. case HOME_KEY:
  170. CursorX = TextX;
  171. break;
  172. case END_KEY:
  173. CursorX = TextY;
  174. break;
  175. case LEFT_KEY:
  176. CursorX -= 1;
  177. break;
  178. case RIGHT_KEY:
  179. CursorX += 1;
  180. break;
  181. case BKSP_KEY:
  182. if (!Index) {
  183. break;
  184. }
  185. CursorX -= 1;
  186. String[Index-1] = CursorChar[0];
  187. // fallthough to DEL_KEY
  188. case DEL_KEY:
  189. if (Length) {
  190. p = String+Index;
  191. i = Length-Index+1;
  192. while (i) {
  193. p[0] = p[1];
  194. p += 1;
  195. i -= 1;
  196. }
  197. Length -= 1;
  198. }
  199. break;
  200. case INS_KEY:
  201. if (Length < MaxLength) {
  202. p = String+Length;
  203. i = Length-Index+1;
  204. while (i) {
  205. p[1] = p[0];
  206. p -= 1;
  207. i -= 1;
  208. }
  209. String[Index] = ' ';
  210. Length += 1;
  211. }
  212. break;
  213. default:
  214. Key = Key & 0xff;
  215. if (Key >= ' ' && Key <= 'z') {
  216. if (CursorX == TextY && Length < MaxLength) {
  217. Length += 1;
  218. }
  219. String[Index] = (UCHAR)Key;
  220. String[MaxLength] = 0;
  221. CursorX += 1;
  222. }
  223. break;
  224. }
  225. }
  226. }