/private/ntos/boot/lib/i386/display.c

https://github.com/ZoloZiak/WinNT4 · C · 659 lines · 296 code · 99 blank · 264 comment · 36 complexity · 330715daa016f5a73927c9b78ac2e442 MD5 · raw file

  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. //
  76. // Cast a pointer to the first word on the stack
  77. //
  78. ap = (PUCHAR)&cp + sizeof(PCHAR);
  79. //
  80. // Process the arguments using the descriptor string
  81. //
  82. while(b = *cp++) {
  83. if(b == '%') {
  84. c = *cp++;
  85. switch (c) {
  86. case 'd':
  87. puti((long)*((int *)ap));
  88. ap += sizeof(int);
  89. break;
  90. case 's':
  91. TextStringOut(*((PCHAR *)ap));
  92. ap += sizeof(char *);
  93. break;
  94. case 'c':
  95. //
  96. // Does not handle dbcs chars
  97. //
  98. pTextCharOut(*((char *)ap));
  99. ap += sizeof(int);
  100. break;
  101. case 'x':
  102. w = *((USHORT *)ap);
  103. len = (USHORT)ZLEN_SHORT(w);
  104. while(len--) pTextCharOut('0');
  105. putx((ULONG)*((USHORT *)ap));
  106. ap += sizeof(int);
  107. break;
  108. case 'u':
  109. putu((ULONG)*((USHORT *)ap));
  110. ap += sizeof(int);
  111. break;
  112. case 'w':
  113. c = *cp++;
  114. switch (c) {
  115. case 'S':
  116. case 'Z':
  117. putwS(*((PUNICODE_STRING *)ap));
  118. ap += sizeof(PUNICODE_STRING);
  119. break;
  120. }
  121. break;
  122. case 'l':
  123. c = *cp++;
  124. switch(c) {
  125. case '0':
  126. break;
  127. case 'u':
  128. putu(*((ULONG *)ap));
  129. ap += sizeof(long);
  130. break;
  131. case 'x':
  132. l = *((ULONG *)ap);
  133. len = (USHORT)ZLEN_LONG(l);
  134. while(len--) pTextCharOut('0');
  135. putx(*((ULONG *)ap));
  136. ap += sizeof(long);
  137. break;
  138. case 'd':
  139. puti(*((ULONG *)ap));
  140. ap += sizeof(long);
  141. break;
  142. }
  143. break;
  144. default :
  145. pTextCharOut((char)b);
  146. pTextCharOut((char)c);
  147. }
  148. } else {
  149. //
  150. // Could be a double-byte char.
  151. //
  152. cp = TextCharOut(cp-1);
  153. }
  154. }
  155. }
  156. VOID
  157. putwS(
  158. PUNICODE_STRING String
  159. )
  160. /*++
  161. Routine Description:
  162. Writes unicode string to the display at the current cursor position.
  163. Arguments:
  164. String - pointer to unicode string to display
  165. Returns:
  166. Nothing
  167. --*/
  168. {
  169. ULONG i;
  170. for(i=0; i < String->Length/sizeof(WCHAR); i++) {
  171. pTextCharOut((UCHAR)String->Buffer[i]);
  172. }
  173. }
  174. VOID
  175. putx(
  176. ULONG x
  177. )
  178. /*++
  179. Routine Description:
  180. Writes hex long to the display at the current cursor position.
  181. Arguments:
  182. x - ulong to write
  183. Returns:
  184. Nothing
  185. --*/
  186. {
  187. ULONG j;
  188. if(x/16) {
  189. putx(x/16);
  190. }
  191. if((j=x%16) > 9) {
  192. pTextCharOut((UCHAR)(j+'A'-10));
  193. } else {
  194. pTextCharOut((UCHAR)(j+'0'));
  195. }
  196. }
  197. VOID
  198. puti(
  199. LONG i
  200. )
  201. /*++
  202. Routine Description:
  203. Writes a long integer on the display at the current cursor position.
  204. Arguments:
  205. i - the integer to write to the display.
  206. Returns:
  207. Nothing
  208. --*/
  209. {
  210. if(i<0) {
  211. i = -i;
  212. pTextCharOut('-');
  213. }
  214. if(i/10) {
  215. puti(i/10);
  216. }
  217. pTextCharOut((UCHAR)((i%10)+'0'));
  218. }
  219. VOID
  220. putu(
  221. ULONG u
  222. )
  223. /*++
  224. Routine Description:
  225. Write an unsigned long to display
  226. Arguments:
  227. u - unsigned
  228. Returns:
  229. Nothing
  230. --*/
  231. {
  232. if(u/10) {
  233. putu(u/10);
  234. }
  235. pTextCharOut((UCHAR)((u%10)+'0'));
  236. }
  237. VOID
  238. pTextCharOut(
  239. IN UCHAR c
  240. )
  241. {
  242. if(DbcsLangId) {
  243. //
  244. // Single-byte only
  245. //
  246. TextGrCharOut(&c);
  247. } else {
  248. TextTmCharOut(&c);
  249. }
  250. }
  251. PUCHAR
  252. TextCharOut(
  253. IN PUCHAR pc
  254. )
  255. {
  256. if(DbcsLangId) {
  257. return(TextGrCharOut(pc));
  258. } else {
  259. return(TextTmCharOut(pc));
  260. }
  261. }
  262. VOID
  263. TextStringOut(
  264. IN PUCHAR String
  265. )
  266. {
  267. if(DbcsLangId) {
  268. TextGrStringOut(String);
  269. } else {
  270. TextTmStringOut(String);
  271. }
  272. }
  273. VOID
  274. TextClearToEndOfLine(
  275. VOID
  276. )
  277. /*++
  278. Routine Description:
  279. Clears from the current cursor position to the end of the line
  280. by writing blanks with the current video attribute.
  281. Arguments:
  282. None
  283. Returns:
  284. Nothing
  285. --*/
  286. {
  287. if(DbcsLangId) {
  288. TextGrClearToEndOfLine();
  289. } else {
  290. TextTmClearToEndOfLine();
  291. }
  292. }
  293. VOID
  294. TextClearFromStartOfLine(
  295. VOID
  296. )
  297. /*++
  298. Routine Description:
  299. Clears from the start of the line to the current cursor position
  300. by writing blanks with the current video attribute.
  301. The cursor position is not changed.
  302. Arguments:
  303. None
  304. Returns:
  305. Nothing
  306. --*/
  307. {
  308. if(DbcsLangId) {
  309. TextGrClearFromStartOfLine();
  310. } else {
  311. TextTmClearFromStartOfLine();
  312. }
  313. }
  314. VOID
  315. TextClearToEndOfDisplay(
  316. VOID
  317. )
  318. /*++
  319. Routine Description:
  320. Clears from the current cursor position to the end of the video
  321. display by writing blanks with the current video attribute.
  322. The cursor position is not changed.
  323. Arguments:
  324. None
  325. Returns:
  326. Nothing
  327. --*/
  328. {
  329. if(DbcsLangId) {
  330. TextGrClearToEndOfDisplay();
  331. } else {
  332. TextTmClearToEndOfDisplay();
  333. }
  334. }
  335. VOID
  336. TextClearDisplay(
  337. VOID
  338. )
  339. /*++
  340. Routine Description:
  341. Clears the video display and positions the cursor
  342. at the upper left corner of the screen (0,0).
  343. Arguments:
  344. None
  345. Returns:
  346. Nothing
  347. --*/
  348. {
  349. if(DbcsLangId) {
  350. TextGrClearDisplay();
  351. } else {
  352. TextTmClearDisplay();
  353. }
  354. TextSetCursorPosition(0,0);
  355. }
  356. VOID
  357. TextSetCursorPosition(
  358. IN ULONG X,
  359. IN ULONG Y
  360. )
  361. /*++
  362. Routine Description:
  363. Moves the location of the software cursor to the specified X,Y position
  364. on screen.
  365. Arguments:
  366. X - Supplies the X-position of the cursor
  367. Y - Supplies the Y-position of the cursor
  368. Return Value:
  369. None.
  370. --*/
  371. {
  372. TextColumn = (USHORT)X;
  373. TextRow = (USHORT)Y;
  374. if(DbcsLangId) {
  375. TextGrPositionCursor((USHORT)Y,(USHORT)X);
  376. } else {
  377. TextTmPositionCursor((USHORT)Y,(USHORT)X);
  378. }
  379. }
  380. VOID
  381. TextGetCursorPosition(
  382. OUT PULONG X,
  383. OUT PULONG Y
  384. )
  385. /*++
  386. Routine Description:
  387. Gets the position of the soft cursor.
  388. Arguments:
  389. X - Receives column coordinate of where character would be written.
  390. Y - Receives row coordinate of where next character would be written.
  391. Returns:
  392. Nothing.
  393. --*/
  394. {
  395. *X = (ULONG)TextColumn;
  396. *Y = (ULONG)TextRow;
  397. }
  398. VOID
  399. TextSetCurrentAttribute(
  400. IN UCHAR Attribute
  401. )
  402. /*++
  403. Routine Description:
  404. Sets the character attribute to be used for subsequent text display.
  405. Arguments:
  406. Returns:
  407. Nothing.
  408. --*/
  409. {
  410. TextCurrentAttribute = Attribute;
  411. if(DbcsLangId) {
  412. TextGrSetCurrentAttribute(Attribute);
  413. } else {
  414. TextTmSetCurrentAttribute(Attribute);
  415. }
  416. }
  417. UCHAR
  418. TextGetCurrentAttribute(
  419. VOID
  420. )
  421. {
  422. return(TextCurrentAttribute);
  423. }
  424. VOID
  425. TextFillAttribute(
  426. IN UCHAR Attribute,
  427. IN ULONG Length
  428. )
  429. /*++
  430. Routine Description:
  431. Changes the screen attribute starting at the current cursor position.
  432. The cursor is not moved.
  433. Arguments:
  434. Attribute - Supplies the new attribute
  435. Length - Supplies the length of the area to change (in bytes)
  436. Return Value:
  437. None.
  438. --*/
  439. {
  440. if(DbcsLangId) {
  441. TextGrFillAttribute(Attribute,Length);
  442. } else {
  443. TextTmFillAttribute(Attribute,Length);
  444. }
  445. }
  446. UCHAR
  447. TextGetGraphicsCharacter(
  448. IN GraphicsChar WhichOne
  449. )
  450. {
  451. return((WhichOne < GraphicsCharMax)
  452. ? (DbcsLangId ? TextGrGetGraphicsChar(WhichOne) : TextTmGetGraphicsChar(WhichOne))
  453. : ' ');
  454. }