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.

702 lines
11 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. display.c
  5. Author:
  6. Thomas Parslow [TomP] Feb-13-1991
  7. Reworked substantially in Tokyo 7-July-95 (tedm)
  8. Abstract:
  9. This file contains an interface to the screen that is independent
  10. of the screen type actually being written to. It is layered on top
  11. of modules pecific to vga text mode and vga graphics mode.
  12. --*/
  13. #include "bootx86.h"
  14. #include "displayp.h"
  15. #define ZLEN_SHORT(x) ((x < 0x10) + (x < 0x100) + (x < 0x1000))
  16. #define ZLEN_LONG(x) ((x < 0x10) + (x < 0x100) + (x < 0x1000) + \
  17. (x < 0x10000) + (x < 0x100000)+(x < 0x1000000)+(x < 0x10000000))
  18. //
  19. // Current screen position.
  20. //
  21. USHORT TextColumn = 0;
  22. USHORT TextRow = 0;
  23. //
  24. // Current text attribute
  25. //
  26. UCHAR TextCurrentAttribute = 0x07; // start with white on black.
  27. //
  28. // Internal routines
  29. //
  30. VOID
  31. puti(
  32. LONG
  33. );
  34. VOID
  35. putx(
  36. ULONG
  37. );
  38. VOID
  39. putu(
  40. ULONG
  41. );
  42. VOID
  43. pTextCharOut(
  44. IN UCHAR c
  45. );
  46. VOID
  47. putwS(
  48. PUNICODE_STRING String
  49. );
  50. VOID
  51. BlPrint(
  52. PCHAR cp,
  53. ...
  54. )
  55. /*++
  56. Routine Description:
  57. Standard printf function with a subset of formating features supported.
  58. Currently handles
  59. %d, %ld - signed short, signed long
  60. %u, %lu - unsigned short, unsigned long
  61. %c, %s - character, string
  62. %x, %lx - unsigned print in hex, unsigned long print in hex
  63. Does not do:
  64. - field width specification
  65. - floating point.
  66. Arguments:
  67. cp - pointer to the format string, text string.
  68. Returns:
  69. Nothing
  70. --*/
  71. {
  72. USHORT b,c,w,len;
  73. PUCHAR ap;
  74. ULONG l;
  75. ULONG Count;
  76. CHAR ch;
  77. ULONG DeviceId;
  78. if (BlConsoleOutDeviceId == 0) {
  79. DeviceId = 1;
  80. } else {
  81. DeviceId = BlConsoleOutDeviceId;
  82. }
  83. //
  84. // Cast a pointer to the first word on the stack
  85. //
  86. ap = (PUCHAR)&cp + sizeof(PCHAR);
  87. //
  88. // Process the arguments using the descriptor string
  89. //
  90. while((b = *cp++) != 0) {
  91. if(b == '%') {
  92. c = *cp++;
  93. switch (c) {
  94. case 'd':
  95. puti((long)*((int *)ap));
  96. ap += sizeof(int);
  97. break;
  98. case 's':
  99. ArcWrite(DeviceId, *((PCHAR *)ap), strlen(*((PCHAR *)ap)), &Count);
  100. ap += sizeof(char *);
  101. break;
  102. case 'c':
  103. //
  104. // Does not handle dbcs chars
  105. //
  106. ArcWrite(DeviceId, ((char *)ap), 1, &Count);
  107. ap += sizeof(int);
  108. break;
  109. case 'x':
  110. w = *((USHORT *)ap);
  111. len = (USHORT)ZLEN_SHORT(w);
  112. ch = '0';
  113. while (len--) {
  114. ArcWrite(DeviceId, &ch, 1, &Count);
  115. }
  116. putx((ULONG)*((USHORT *)ap));
  117. ap += sizeof(int);
  118. break;
  119. case 'u':
  120. putu((ULONG)*((USHORT *)ap));
  121. ap += sizeof(int);
  122. break;
  123. case 'w':
  124. c = *cp++;
  125. switch (c) {
  126. case 'S':
  127. case 'Z':
  128. putwS(*((PUNICODE_STRING *)ap));
  129. ap += sizeof(PUNICODE_STRING);
  130. break;
  131. }
  132. break;
  133. case 'l':
  134. c = *cp++;
  135. switch(c) {
  136. case '0':
  137. break;
  138. case 'u':
  139. putu(*((ULONG *)ap));
  140. ap += sizeof(long);
  141. break;
  142. case 'x':
  143. l = *((ULONG *)ap);
  144. len = (USHORT)ZLEN_LONG(l);
  145. ch = '0';
  146. while (len--) {
  147. ArcWrite(DeviceId, &ch, 1, &Count);
  148. }
  149. putx(*((ULONG *)ap));
  150. ap += sizeof(long);
  151. break;
  152. case 'd':
  153. puti(*((ULONG *)ap));
  154. ap += sizeof(long);
  155. break;
  156. }
  157. break;
  158. default :
  159. ch = (char)b;
  160. ArcWrite(DeviceId, &ch, 1, &Count);
  161. ch = (char)c;
  162. ArcWrite(DeviceId, &ch, 1, &Count);
  163. }
  164. } else {
  165. if (DbcsLangId && GrIsDBCSLeadByte(*(cp - 1))) {
  166. //
  167. // A double-byte char.
  168. //
  169. ArcWrite(DeviceId, cp - 1, 2, &Count);
  170. cp++;
  171. } else {
  172. ArcWrite(DeviceId, cp - 1, 1, &Count);
  173. }
  174. }
  175. }
  176. }
  177. VOID
  178. putwS(
  179. PUNICODE_STRING String
  180. )
  181. /*++
  182. Routine Description:
  183. Writes unicode string to the display at the current cursor position.
  184. Arguments:
  185. String - pointer to unicode string to display
  186. Returns:
  187. Nothing
  188. --*/
  189. {
  190. ULONG i;
  191. ULONG Count;
  192. UCHAR ch;
  193. for(i=0; i < String->Length/sizeof(WCHAR); i++) {
  194. ch = (UCHAR)String->Buffer[i];
  195. ArcWrite(BlConsoleOutDeviceId, &ch, 1, &Count);
  196. }
  197. }
  198. VOID
  199. putx(
  200. ULONG x
  201. )
  202. /*++
  203. Routine Description:
  204. Writes hex long to the display at the current cursor position.
  205. Arguments:
  206. x - ulong to write
  207. Returns:
  208. Nothing
  209. --*/
  210. {
  211. ULONG j;
  212. ULONG Count;
  213. UCHAR ch;
  214. if(x/16) {
  215. putx(x/16);
  216. }
  217. if((j=x%16) > 9) {
  218. ch = (UCHAR)(j+'A'-10);
  219. ArcWrite(BlConsoleOutDeviceId, &ch, 1, &Count);
  220. } else {
  221. ch = (UCHAR)(j+'0');
  222. ArcWrite(BlConsoleOutDeviceId, &ch, 1, &Count);
  223. }
  224. }
  225. VOID
  226. puti(
  227. LONG i
  228. )
  229. /*++
  230. Routine Description:
  231. Writes a long integer on the display at the current cursor position.
  232. Arguments:
  233. i - the integer to write to the display.
  234. Returns:
  235. Nothing
  236. --*/
  237. {
  238. ULONG Count;
  239. UCHAR ch;
  240. if(i<0) {
  241. i = -i;
  242. ch = '-';
  243. ArcWrite(BlConsoleOutDeviceId, &ch, 1, &Count);
  244. }
  245. if(i/10) {
  246. puti(i/10);
  247. }
  248. ch = (UCHAR)((i%10)+'0');
  249. ArcWrite(BlConsoleOutDeviceId, &ch, 1, &Count);
  250. }
  251. VOID
  252. putu(
  253. ULONG u
  254. )
  255. /*++
  256. Routine Description:
  257. Write an unsigned long to display
  258. Arguments:
  259. u - unsigned
  260. Returns:
  261. Nothing
  262. --*/
  263. {
  264. ULONG Count;
  265. UCHAR ch;
  266. if(u/10) {
  267. putu(u/10);
  268. }
  269. ch = (UCHAR)((u%10)+'0');
  270. ArcWrite(BlConsoleOutDeviceId, &ch, 1, &Count);
  271. }
  272. VOID
  273. pTextCharOut(
  274. IN UCHAR c
  275. )
  276. {
  277. if(DbcsLangId) {
  278. //
  279. // Single-byte only
  280. //
  281. TextGrCharOut(&c);
  282. } else {
  283. TextTmCharOut(&c);
  284. }
  285. }
  286. PUCHAR
  287. TextCharOut(
  288. IN PUCHAR pc
  289. )
  290. {
  291. if(DbcsLangId) {
  292. return(TextGrCharOut(pc));
  293. } else {
  294. return(TextTmCharOut(pc));
  295. }
  296. }
  297. VOID
  298. TextStringOut(
  299. IN PUCHAR String
  300. )
  301. {
  302. if(DbcsLangId) {
  303. TextGrStringOut(String);
  304. } else {
  305. TextTmStringOut(String);
  306. }
  307. }
  308. VOID
  309. TextClearToEndOfLine(
  310. VOID
  311. )
  312. /*++
  313. Routine Description:
  314. Clears from the current cursor position to the end of the line
  315. by writing blanks with the current video attribute.
  316. Arguments:
  317. None
  318. Returns:
  319. Nothing
  320. --*/
  321. {
  322. if(DbcsLangId) {
  323. TextGrClearToEndOfLine();
  324. } else {
  325. TextTmClearToEndOfLine();
  326. }
  327. }
  328. VOID
  329. TextClearFromStartOfLine(
  330. VOID
  331. )
  332. /*++
  333. Routine Description:
  334. Clears from the start of the line to the current cursor position
  335. by writing blanks with the current video attribute.
  336. The cursor position is not changed.
  337. Arguments:
  338. None
  339. Returns:
  340. Nothing
  341. --*/
  342. {
  343. if(DbcsLangId) {
  344. TextGrClearFromStartOfLine();
  345. } else {
  346. TextTmClearFromStartOfLine();
  347. }
  348. }
  349. VOID
  350. TextClearToEndOfDisplay(
  351. VOID
  352. )
  353. /*++
  354. Routine Description:
  355. Clears from the current cursor position to the end of the video
  356. display by writing blanks with the current video attribute.
  357. The cursor position is not changed.
  358. Arguments:
  359. None
  360. Returns:
  361. Nothing
  362. --*/
  363. {
  364. if(DbcsLangId) {
  365. TextGrClearToEndOfDisplay();
  366. } else {
  367. TextTmClearToEndOfDisplay();
  368. }
  369. }
  370. VOID
  371. TextClearDisplay(
  372. VOID
  373. )
  374. /*++
  375. Routine Description:
  376. Clears the video display and positions the cursor
  377. at the upper left corner of the screen (0,0).
  378. Arguments:
  379. None
  380. Returns:
  381. Nothing
  382. --*/
  383. {
  384. if(DbcsLangId) {
  385. TextGrClearDisplay();
  386. } else {
  387. TextTmClearDisplay();
  388. }
  389. TextSetCursorPosition(0,0);
  390. }
  391. VOID
  392. TextSetCursorPosition(
  393. IN ULONG X,
  394. IN ULONG Y
  395. )
  396. /*++
  397. Routine Description:
  398. Moves the location of the software cursor to the specified X,Y position
  399. on screen.
  400. Arguments:
  401. X - Supplies the X-position of the cursor
  402. Y - Supplies the Y-position of the cursor
  403. Return Value:
  404. None.
  405. --*/
  406. {
  407. TextColumn = (USHORT)X;
  408. TextRow = (USHORT)Y;
  409. if(DbcsLangId) {
  410. TextGrPositionCursor((USHORT)Y,(USHORT)X);
  411. } else {
  412. TextTmPositionCursor((USHORT)Y,(USHORT)X);
  413. }
  414. }
  415. VOID
  416. TextGetCursorPosition(
  417. OUT PULONG X,
  418. OUT PULONG Y
  419. )
  420. /*++
  421. Routine Description:
  422. Gets the position of the soft cursor.
  423. Arguments:
  424. X - Receives column coordinate of where character would be written.
  425. Y - Receives row coordinate of where next character would be written.
  426. Returns:
  427. Nothing.
  428. --*/
  429. {
  430. *X = (ULONG)TextColumn;
  431. *Y = (ULONG)TextRow;
  432. }
  433. VOID
  434. TextSetCurrentAttribute(
  435. IN UCHAR Attribute
  436. )
  437. /*++
  438. Routine Description:
  439. Sets the character attribute to be used for subsequent text display.
  440. Arguments:
  441. Returns:
  442. Nothing.
  443. --*/
  444. {
  445. TextCurrentAttribute = Attribute;
  446. if(DbcsLangId) {
  447. TextGrSetCurrentAttribute(Attribute);
  448. } else {
  449. TextTmSetCurrentAttribute(Attribute);
  450. }
  451. }
  452. UCHAR
  453. TextGetCurrentAttribute(
  454. VOID
  455. )
  456. {
  457. return(TextCurrentAttribute);
  458. }
  459. VOID
  460. TextFillAttribute(
  461. IN UCHAR Attribute,
  462. IN ULONG Length
  463. )
  464. /*++
  465. Routine Description:
  466. Changes the screen attribute starting at the current cursor position.
  467. The cursor is not moved.
  468. Arguments:
  469. Attribute - Supplies the new attribute
  470. Length - Supplies the length of the area to change (in bytes)
  471. Return Value:
  472. None.
  473. --*/
  474. {
  475. if(DbcsLangId) {
  476. TextGrFillAttribute(Attribute,Length);
  477. } else {
  478. TextTmFillAttribute(Attribute,Length);
  479. }
  480. }
  481. UCHAR
  482. TextGetGraphicsCharacter(
  483. IN GraphicsChar WhichOne
  484. )
  485. {
  486. return((WhichOne < GraphicsCharMax)
  487. ? (DbcsLangId ? TextGrGetGraphicsChar(WhichOne) : TextTmGetGraphicsChar(WhichOne))
  488. : ' ');
  489. }
  490.