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.

631 lines
9.1 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. display.c
  5. Author:
  6. Thomas Parslow (tomp) Mar-01-90
  7. Abstract:
  8. Video support routines.
  9. The SU module only need to be able to write to the video display
  10. in order to report errors, traps, etc.
  11. The routines in this file all write to a video buffer assumed to be
  12. at realmode address b800:0000, and 4k bytes in length. The segment
  13. portion of the far pointers used to access the video buffer are stamped
  14. with a protmode selector value when we switch to protect mode. This is
  15. done in the routine "ProtMode" in "misc386.asm".
  16. --*/
  17. #include "hwdetect.h"
  18. #if DBG
  19. #define ZLEN_SHORT(x) ((x < 0x10) + (x < 0x100) + (x < 0x1000))
  20. #define ZLEN_LONG(x) ((x < 0x10) + (x < 0x100) + (x < 0x1000) + (x < 0x10000) + (x < 0x100000)+(x < 0x1000000)+(x < 0x10000000))
  21. #define ROWS 25
  22. #define COLUMNS 80
  23. #define SCREEN_WIDTH COLUMNS
  24. #define SCREEN_SIZE ROWS * COLUMNS
  25. #define NORMAL_ATTRIB 0x07
  26. #define REVERSE_ATTRIB 0x70
  27. #define SCREEN_START 0xb8000000
  28. //
  29. // Internal routines
  30. //
  31. VOID
  32. putc(
  33. IN CHAR
  34. );
  35. VOID
  36. putu(
  37. IN ULONG
  38. );
  39. VOID
  40. BlPuts(
  41. IN PCHAR
  42. );
  43. VOID
  44. puti(
  45. IN LONG
  46. );
  47. VOID
  48. putx(
  49. IN ULONG
  50. );
  51. VOID
  52. scroll(
  53. VOID
  54. );
  55. static
  56. VOID
  57. tab(
  58. VOID
  59. );
  60. static
  61. VOID
  62. newline(
  63. VOID
  64. );
  65. static
  66. VOID
  67. putzeros(
  68. USHORT,
  69. USHORT
  70. );
  71. USHORT
  72. Redirect = 0;
  73. //
  74. // Used by all BlPrint subordinate routines for padding computations.
  75. //
  76. CHAR sc=0;
  77. ULONG fw=0;
  78. VOID
  79. BlPrint(
  80. PCHAR cp,
  81. ...
  82. )
  83. /*++
  84. Routine Description:
  85. Standard printf function with a subset of formating features supported.
  86. Currently handles
  87. %d, %ld - signed short, signed long
  88. %u, %lu - unsigned short, unsigned long
  89. %c, %s - character, string
  90. %x, %lx - unsigned print in hex, unsigned long print in hex
  91. Does not do:
  92. - field width specification
  93. - floating point.
  94. Arguments:
  95. cp - pointer to the format string, text string.
  96. Returns:
  97. Nothing
  98. --*/
  99. {
  100. USHORT b,c,w,len;
  101. PUCHAR ap;
  102. ULONG l;
  103. //
  104. // Cast a pointer to the first word on the stack
  105. //
  106. ap = (PUCHAR)&cp + sizeof(PCHAR);
  107. sc = ' '; // default padding char is space
  108. //
  109. // Process the arguments using the descriptor string
  110. //
  111. while (b = *cp++)
  112. {
  113. if (b == '%')
  114. {
  115. c = *cp++;
  116. switch (c)
  117. {
  118. case 'd':
  119. puti((long)*((int *)ap));
  120. ap += sizeof(int);
  121. break;
  122. case 's':
  123. BlPuts(*((PCHAR *)ap));
  124. ap += sizeof (char *);
  125. break;
  126. case 'c':
  127. putc(*((char *)ap));
  128. ap += sizeof(int);
  129. break;
  130. case 'x':
  131. w = *((USHORT *)ap);
  132. len = ZLEN_SHORT(w);
  133. while(len--) putc('0');
  134. putx((ULONG)*((USHORT *)ap));
  135. ap += sizeof(int);
  136. break;
  137. case 'u':
  138. putu((ULONG)*((USHORT *)ap));
  139. ap += sizeof(int);
  140. break;
  141. case 'l':
  142. c = *cp++;
  143. switch(c) {
  144. case 'u':
  145. putu(*((ULONG *)ap));
  146. ap += sizeof(long);
  147. break;
  148. case 'x':
  149. l = *((ULONG *)ap);
  150. len = ZLEN_LONG(l);
  151. while(len--) putc('0');
  152. putx(*((ULONG *)ap));
  153. ap += sizeof(long);
  154. break;
  155. case 'd':
  156. puti(*((ULONG *)ap));
  157. ap += sizeof(long);
  158. break;
  159. }
  160. break;
  161. default :
  162. putc((char)b);
  163. putc((char)c);
  164. }
  165. }
  166. else
  167. putc((char)b);
  168. }
  169. }
  170. FPUCHAR vp = (FPUCHAR)SCREEN_START;
  171. FPUCHAR ScreenStart = (FPUCHAR)SCREEN_START;
  172. static int lcnt = 0;
  173. static int row = 0;
  174. VOID BlPuts(
  175. PCHAR cp
  176. )
  177. /*++
  178. Routine Description:
  179. Writes a string on the display at the current cursor position
  180. Arguments:
  181. cp - pointer to ASCIIZ string to display.
  182. Returns:
  183. Nothing
  184. --*/
  185. {
  186. char c;
  187. while(c = *cp++)
  188. putc(c);
  189. }
  190. //
  191. // Write a hex short to display
  192. //
  193. VOID putx(
  194. ULONG x
  195. )
  196. /*++
  197. Routine Description:
  198. Writes hex long to the display at the current cursor position.
  199. Arguments:
  200. x - ulong to write.
  201. Returns:
  202. Nothing
  203. --*/
  204. {
  205. ULONG j;
  206. if (x/16)
  207. putx(x/16);
  208. if((j=x%16) > 9) {
  209. putc((char)(j+'A'- 10));
  210. } else {
  211. putc((char)(j+'0'));
  212. }
  213. }
  214. VOID puti(
  215. LONG i
  216. )
  217. /*++
  218. Routine Description:
  219. Writes a long integer on the display at the current cursor position.
  220. Arguments:
  221. i - the integer to write to the display.
  222. Returns:
  223. Nothing
  224. --*/
  225. {
  226. if (i<0)
  227. {
  228. i = -i;
  229. putc((char)'-');
  230. }
  231. if (i/10)
  232. puti(i/10);
  233. putc((char)((i%10)+'0'));
  234. }
  235. VOID putu(
  236. ULONG u
  237. )
  238. /*++
  239. Routine Description:
  240. Write an unsigned long to display
  241. Arguments:
  242. u - unsigned
  243. --*/
  244. {
  245. if (u/10)
  246. putu(u/10);
  247. putc((char)((u%10)+'0'));
  248. }
  249. VOID putc(
  250. CHAR c
  251. )
  252. /*++
  253. Routine Description:
  254. Writes a character on the display at the current position.
  255. Arguments:
  256. c - character to write
  257. Returns:
  258. Nothing
  259. --*/
  260. {
  261. switch (c)
  262. {
  263. case '\n':
  264. newline();
  265. break;
  266. case '\t':
  267. tab();
  268. break;
  269. default :
  270. if (FP_OFF(vp) >= (SCREEN_SIZE * 2)) {
  271. vp = (FPUCHAR)((ScreenStart + (2*SCREEN_WIDTH*(ROWS-1))));
  272. scroll();
  273. }
  274. *vp = c;
  275. vp += 2;
  276. ++lcnt;
  277. }
  278. }
  279. VOID newline(
  280. VOID
  281. )
  282. /*++
  283. Routine Description:
  284. Moves the cursor to the beginning of the next line. If the bottom
  285. of the display has been reached, the screen is scrolled one line up.
  286. Arguments:
  287. None
  288. Returns:
  289. Nothing
  290. --*/
  291. {
  292. vp += (SCREEN_WIDTH - lcnt)<<1;
  293. if (++row > ROWS-1) {
  294. vp = (FPUCHAR)((ScreenStart + (2*SCREEN_WIDTH*(ROWS-1))));
  295. scroll();
  296. }
  297. lcnt = 0;
  298. }
  299. VOID scroll(
  300. VOID
  301. )
  302. /*++
  303. Routine Description:
  304. Scrolls the display UP one line.
  305. Arguments:
  306. None
  307. Returns:
  308. Nothing
  309. Notes:
  310. Currently we scroll the display by reading and writing directly from
  311. and to the video display buffer. We optionally switch to real mode
  312. and to int 10s
  313. --*/
  314. {
  315. USHORT i,j;
  316. USHORT far *p1 = (USHORT far *)ScreenStart;
  317. USHORT far *p2 = (USHORT far *)(ScreenStart + 2*SCREEN_WIDTH) ;
  318. for (i=0; i < ROWS - 1; i++)
  319. for (j=0; j < SCREEN_WIDTH; j++)
  320. *p1++ = *p2++;
  321. for (i=0; i < SCREEN_WIDTH; i++)
  322. *p1++ = REVERSE_ATTRIB*256 + ' ';
  323. }
  324. static
  325. VOID tab(
  326. VOID
  327. )
  328. /*++
  329. Routine Description:
  330. Computes the next tab stop and moves the cursor to that location.
  331. Arguments:
  332. None
  333. Returns:
  334. Nothing
  335. --*/
  336. {
  337. int inc;
  338. inc = 8 - (lcnt % 8);
  339. vp += inc<<1;
  340. lcnt += inc;
  341. }
  342. VOID clrscrn(
  343. VOID
  344. )
  345. /*++
  346. Routine Description:
  347. Clears the video display by writing blanks with the current
  348. video attribute over the entire display.
  349. Arguments:
  350. None
  351. Returns:
  352. Nothing
  353. --*/
  354. {
  355. int i,a;
  356. unsigned far *vwp = (unsigned far *)SCREEN_START;
  357. a = REVERSE_ATTRIB*256 + ' ';
  358. for (i = SCREEN_SIZE ; i ; i--)
  359. *vwp++ = a;
  360. row = 0;
  361. lcnt = 0;
  362. vp = (FPUCHAR)ScreenStart;
  363. }
  364. #else
  365. VOID
  366. BlPrint(
  367. PCHAR cp,
  368. ...
  369. )
  370. /*++
  371. Routine Description:
  372. Standard printf function with a subset of formating features supported.
  373. Currently handles
  374. %d, %ld - signed short, signed long
  375. %u, %lu - unsigned short, unsigned long
  376. %c, %s - character, string
  377. %x, %lx - unsigned print in hex, unsigned long print in hex
  378. Does not do:
  379. - field width specification
  380. - floating point.
  381. Arguments:
  382. cp - pointer to the format string, text string.
  383. Returns:
  384. Nothing
  385. --*/
  386. {
  387. }
  388. VOID clrscrn(
  389. VOID
  390. )
  391. /*++
  392. Routine Description:
  393. Clears the video display by writing blanks with the current
  394. video attribute over the entire display.
  395. Arguments:
  396. None
  397. Returns:
  398. Nothing
  399. --*/
  400. {
  401. }
  402. #endif