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.

328 lines
7.2 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. #if defined (_IA64_)
  10. #include "bootia64.h"
  11. #endif
  12. #if defined (_X86_)
  13. #include "bldrx86.h"
  14. #endif
  15. #include "displayp.h"
  16. #include "stdio.h"
  17. #include "efi.h"
  18. #include "efip.h"
  19. #include "flop.h"
  20. #include "bootefi.h"
  21. //
  22. // Externals
  23. //
  24. extern BOOT_CONTEXT BootContext;
  25. extern EFI_HANDLE EfiImageHandle;
  26. extern EFI_SYSTEM_TABLE *EfiST;
  27. extern EFI_BOOT_SERVICES *EfiBS;
  28. extern EFI_RUNTIME_SERVICES *EfiRS;
  29. extern EFI_GUID EfiDevicePathProtocol;
  30. extern EFI_GUID EfiBlockIoProtocol;
  31. //
  32. // Takes any pending input and converts it into a KEY value. Non-blocking, returning 0 if no input available.
  33. //
  34. ULONG
  35. BlGetKey()
  36. {
  37. ULONG Key = 0;
  38. UCHAR Ch;
  39. ULONG Count;
  40. if (ArcGetReadStatus(BlConsoleInDeviceId) == ESUCCESS) {
  41. ArcRead(BlConsoleInDeviceId, &Ch, sizeof(Ch), &Count);
  42. if (Ch == ASCI_CSI_IN) {
  43. if (ArcGetReadStatus(BlConsoleInDeviceId) == ESUCCESS) {
  44. ArcRead(BlConsoleInDeviceId, &Ch, sizeof(Ch), &Count);
  45. //
  46. // All the function keys start with ESC-O
  47. //
  48. switch (Ch) {
  49. case 'O':
  50. ArcRead(BlConsoleInDeviceId, &Ch, sizeof(Ch), &Count); // will not or block, as the buffer is already filled
  51. switch (Ch) {
  52. case 'P':
  53. Key = F1_KEY;
  54. break;
  55. case 'Q':
  56. Key = F2_KEY;
  57. break;
  58. case 'w':
  59. Key = F3_KEY;
  60. break;
  61. case 't':
  62. Key = F5_KEY;
  63. break;
  64. case 'u':
  65. Key = F6_KEY;
  66. break;
  67. case 'r':
  68. Key = F8_KEY;
  69. break;
  70. case 'M':
  71. Key = F10_KEY;
  72. break;
  73. }
  74. break;
  75. case 'A':
  76. Key = UP_ARROW;
  77. break;
  78. case 'B':
  79. Key = DOWN_ARROW;
  80. break;
  81. case 'C':
  82. Key = RIGHT_KEY;
  83. break;
  84. case 'D':
  85. Key = LEFT_KEY;
  86. break;
  87. case 'H':
  88. Key = HOME_KEY;
  89. break;
  90. case 'K':
  91. Key = END_KEY;
  92. break;
  93. case '@':
  94. Key = INS_KEY;
  95. break;
  96. case 'P':
  97. Key = DEL_KEY;
  98. break;
  99. case TAB_KEY:
  100. Key = BACKTAB_KEY;
  101. break;
  102. }
  103. } else { // Single escape key, as no input is waiting.
  104. Key = ESCAPE_KEY;
  105. }
  106. } else if (Ch == 0x8) {
  107. Key = BKSP_KEY;
  108. } else {
  109. Key = (ULONG)Ch;
  110. }
  111. }
  112. return Key;
  113. }
  114. VOID
  115. BlInputString(
  116. IN ULONG Prompt,
  117. IN ULONG CursorX,
  118. IN ULONG PosY,
  119. IN PUCHAR String,
  120. IN ULONG MaxLength
  121. )
  122. {
  123. PTCHAR PromptString;
  124. ULONG TextX, TextY;
  125. ULONG Length, Index;
  126. _TUCHAR CursorChar[2];
  127. ULONG Key;
  128. _PTUCHAR p;
  129. ULONG i;
  130. ULONG Count;
  131. _PTUCHAR pString;
  132. #ifdef UNICODE
  133. WCHAR StringW[200];
  134. UNICODE_STRING uString;
  135. ANSI_STRING aString;
  136. pString = StringW;
  137. uString.Buffer = StringW;
  138. uString.MaximumLength = sizeof(StringW);
  139. RtlInitAnsiString(&aString, String );
  140. RtlAnsiStringToUnicodeString( &uString, &aString, FALSE );
  141. #else
  142. pString = String;
  143. #endif
  144. PromptString = BlFindMessage(Prompt);
  145. Length = strlen(String);
  146. CursorChar[1] = TEXT('\0');
  147. //
  148. // Print prompt
  149. //
  150. BlEfiPositionCursor( PosY, CursorX );
  151. BlEfiEnableCursor( TRUE );
  152. ArcWrite(BlConsoleOutDeviceId, PromptString, _tcslen(PromptString)*sizeof(TCHAR), &Count);
  153. //
  154. // Indent cursor to right of prompt
  155. //
  156. CursorX += _tcslen(PromptString);
  157. TextX = CursorX;
  158. Key = 0;
  159. for (; ;) {
  160. TextY = TextX + Length;
  161. if (CursorX > TextY) {
  162. CursorX = TextY;
  163. }
  164. if (CursorX < TextX) {
  165. CursorX = TextX;
  166. }
  167. Index = CursorX - TextX;
  168. pString[Length] = 0;
  169. //
  170. // Display current string
  171. //
  172. BlEfiPositionCursor( TextY, TextX );
  173. ArcWrite(
  174. BlConsoleOutDeviceId,
  175. pString,
  176. _tcslen(pString)*sizeof(TCHAR),
  177. &Count);
  178. ArcWrite(BlConsoleOutDeviceId, TEXT(" "), sizeof(TEXT(" ")), &Count);
  179. if (Key == 0x0d) { // enter key?
  180. break ;
  181. }
  182. //
  183. // Display cursor
  184. //
  185. BlEfiPositionCursor( PosY, CursorX );
  186. BlEfiSetInverseMode( TRUE );
  187. CursorChar[0] = pString[Index] ? pString[Index] : TEXT(' ');
  188. ArcWrite(BlConsoleOutDeviceId, CursorChar, sizeof(_TUCHAR), &Count);
  189. BlEfiSetInverseMode( FALSE );
  190. BlEfiPositionCursor( PosY, CursorX );
  191. BlEfiEnableCursor(TRUE);
  192. //
  193. // Get key and process it
  194. //
  195. while (!(Key = BlGetKey())) ;
  196. switch (Key) {
  197. case HOME_KEY:
  198. CursorX = TextX;
  199. break;
  200. case END_KEY:
  201. CursorX = TextY;
  202. break;
  203. case LEFT_KEY:
  204. CursorX -= 1;
  205. break;
  206. case RIGHT_KEY:
  207. CursorX += 1;
  208. break;
  209. case BKSP_KEY:
  210. if (!Index) {
  211. break;
  212. }
  213. CursorX -= 1;
  214. pString[Index-1] = CursorChar[0];
  215. // fallthough to DEL_KEY
  216. case DEL_KEY:
  217. if (Length) {
  218. p = pString+Index;
  219. i = Length-Index+1;
  220. while (i) {
  221. p[0] = p[1];
  222. p += 1;
  223. i -= 1;
  224. }
  225. Length -= 1;
  226. }
  227. break;
  228. case INS_KEY:
  229. if (Length < MaxLength) {
  230. p = pString+Length;
  231. i = Length-Index+1;
  232. while (i) {
  233. p[1] = p[0];
  234. p -= 1;
  235. i -= 1;
  236. }
  237. pString[Index] = TEXT(' ');
  238. Length += 1;
  239. }
  240. break;
  241. default:
  242. Key = Key & 0xff;
  243. if (Key >= ' ' && Key <= 'z') {
  244. if (CursorX == TextY && Length < MaxLength) {
  245. Length += 1;
  246. }
  247. pString[Index] = (_TUCHAR)Key;
  248. pString[MaxLength] = 0;
  249. CursorX += 1;
  250. }
  251. break;
  252. }
  253. }
  254. }