Source code of Windows XP (NT5)
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.

293 lines
6.5 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 't':
  43. Key = F5_KEY;
  44. break;
  45. case 'u':
  46. Key = F6_KEY;
  47. break;
  48. case 'r':
  49. Key = F8_KEY;
  50. break;
  51. case 'M':
  52. Key = F10_KEY;
  53. break;
  54. case 'A':
  55. Key = F11_KEY;
  56. break;
  57. case 'B':
  58. Key = F12_KEY;
  59. break;
  60. }
  61. break;
  62. case 'A':
  63. Key = UP_ARROW;
  64. break;
  65. case 'B':
  66. Key = DOWN_ARROW;
  67. break;
  68. case 'C':
  69. Key = RIGHT_KEY;
  70. break;
  71. case 'D':
  72. Key = LEFT_KEY;
  73. break;
  74. case 'H':
  75. Key = HOME_KEY;
  76. break;
  77. case 'K':
  78. Key = END_KEY;
  79. break;
  80. case '@':
  81. Key = INS_KEY;
  82. break;
  83. case 'P':
  84. Key = DEL_KEY;
  85. break;
  86. case TAB_KEY:
  87. Key = BACKTAB_KEY;
  88. break;
  89. }
  90. } else { // Single escape key, as no input is waiting.
  91. Key = ESCAPE_KEY;
  92. }
  93. } else if (Ch == 0x8) {
  94. Key = BKSP_KEY;
  95. } else {
  96. Key = (ULONG)Ch;
  97. }
  98. }
  99. return Key;
  100. }
  101. VOID
  102. BlInputString(
  103. IN ULONG Prompt,
  104. IN ULONG CursorX,
  105. IN ULONG PosY,
  106. IN PUCHAR String,
  107. IN ULONG MaxLength
  108. )
  109. {
  110. PUCHAR PromptString;
  111. ULONG TextX, TextY;
  112. ULONG Length, Index;
  113. UCHAR CursorChar[2];
  114. ULONG Key;
  115. PUCHAR p;
  116. ULONG i;
  117. ULONG Count;
  118. PromptString = BlFindMessage(Prompt);
  119. Length = strlen(String);
  120. CursorChar[1] = 0;
  121. //
  122. // Print prompt
  123. //
  124. ARC_DISPLAY_POSITION_CURSOR(CursorX, PosY);
  125. ArcWrite(BlConsoleOutDeviceId, PromptString, strlen(PromptString), &Count);
  126. //
  127. // Indent cursor to right of prompt
  128. //
  129. CursorX += strlen(PromptString);
  130. TextX = CursorX;
  131. Key = 0;
  132. for (; ;) {
  133. TextY = TextX + Length;
  134. if (CursorX > TextY) {
  135. CursorX = TextY;
  136. }
  137. if (CursorX < TextX) {
  138. CursorX = TextX;
  139. }
  140. Index = CursorX - TextX;
  141. String[Length] = 0;
  142. //
  143. // Display current string
  144. //
  145. ARC_DISPLAY_POSITION_CURSOR(TextX, PosY);
  146. ArcWrite(BlConsoleOutDeviceId, String, strlen(String), &Count);
  147. ArcWrite(BlConsoleOutDeviceId, " ", sizeof(" "), &Count);
  148. if (Key == 0x0d) { // enter key?
  149. break ;
  150. }
  151. //
  152. // Display cursor
  153. //
  154. ARC_DISPLAY_POSITION_CURSOR(CursorX, PosY);
  155. ARC_DISPLAY_INVERSE_VIDEO();
  156. CursorChar[0] = String[Index] ? String[Index] : ' ';
  157. ArcWrite(BlConsoleOutDeviceId, CursorChar, sizeof(UCHAR), &Count);
  158. ARC_DISPLAY_ATTRIBUTES_OFF();
  159. ARC_DISPLAY_POSITION_CURSOR(CursorX, PosY);
  160. //
  161. // Get key and process it
  162. //
  163. while (!(Key = BlGetKey())) {
  164. }
  165. switch (Key) {
  166. case HOME_KEY:
  167. CursorX = TextX;
  168. break;
  169. case END_KEY:
  170. CursorX = TextY;
  171. break;
  172. case LEFT_KEY:
  173. CursorX -= 1;
  174. break;
  175. case RIGHT_KEY:
  176. CursorX += 1;
  177. break;
  178. case BKSP_KEY:
  179. if (!Index) {
  180. break;
  181. }
  182. CursorX -= 1;
  183. String[Index-1] = CursorChar[0];
  184. // fallthough to DEL_KEY
  185. case DEL_KEY:
  186. if (Length) {
  187. p = String+Index;
  188. i = Length-Index+1;
  189. while (i) {
  190. p[0] = p[1];
  191. p += 1;
  192. i -= 1;
  193. }
  194. Length -= 1;
  195. }
  196. break;
  197. case INS_KEY:
  198. if (Length < MaxLength) {
  199. p = String+Length;
  200. i = Length-Index+1;
  201. while (i) {
  202. p[1] = p[0];
  203. p -= 1;
  204. i -= 1;
  205. }
  206. String[Index] = ' ';
  207. Length += 1;
  208. }
  209. break;
  210. default:
  211. Key = Key & 0xff;
  212. if (Key >= ' ' && Key <= 'z') {
  213. if (CursorX == TextY && Length < MaxLength) {
  214. Length += 1;
  215. }
  216. String[Index] = (UCHAR)Key;
  217. String[MaxLength] = 0;
  218. CursorX += 1;
  219. }
  220. break;
  221. }
  222. }
  223. }