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.

441 lines
7.0 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. disp_tm.c
  5. Author:
  6. Ted Miller 6-July-1995
  7. Abstract:
  8. This routine contains low-level routines to operate on a
  9. CGA-style text mode video buffer.
  10. It collects up various other bits and pieces that were written by
  11. others and once contained in other source files.
  12. --*/
  13. #include "bootx86.h"
  14. #include "displayp.h"
  15. //
  16. // Standard cga 80x25 text mode's video buffer address,
  17. // resolution, etc.
  18. //
  19. #define VIDEO_BUFFER_VA 0xb8000
  20. #define VIDEO_ROWS 25
  21. #define VIDEO_COLUMNS 80
  22. #define VIDEO_BYTES_PER_ROW (VIDEO_COLUMNS*2)
  23. //
  24. // Various globals to track location on screen, attribute, etc.
  25. //
  26. PUCHAR Vp = (PUCHAR)VIDEO_BUFFER_VA;
  27. VOID
  28. TextTmPositionCursor(
  29. USHORT Row,
  30. USHORT Column
  31. )
  32. /*++
  33. Routine Description:
  34. Sets the position of the soft cursor. That is, it doesn't move the
  35. hardware cursor but sets the location of the next write to the
  36. screen.
  37. Arguments:
  38. Row - Row coordinate of where character is to be written.
  39. Column - Column coordinate of where character is to be written.
  40. Returns:
  41. Nothing.
  42. --*/
  43. {
  44. if(Row >= VIDEO_ROWS) {
  45. Row = VIDEO_ROWS-1;
  46. }
  47. if(Column >= VIDEO_COLUMNS) {
  48. Column = VIDEO_COLUMNS-1;
  49. }
  50. Vp = (PUCHAR)(VIDEO_BUFFER_VA + (Row * VIDEO_BYTES_PER_ROW) + (2 * Column));
  51. }
  52. VOID
  53. TextTmStringOut(
  54. IN PUCHAR String
  55. )
  56. {
  57. PUCHAR p = String;
  58. while(*p) {
  59. p = TextTmCharOut(p);
  60. }
  61. }
  62. PUCHAR
  63. TextTmCharOut(
  64. PUCHAR pc
  65. )
  66. /*++
  67. Routine Description:
  68. Writes a character on the display at the current position.
  69. Newlines and tabs are interpreted and acted upon.
  70. Arguments:
  71. c - pointer to character to write
  72. Returns:
  73. Pointer to next char in string
  74. --*/
  75. {
  76. unsigned u;
  77. UCHAR c;
  78. UCHAR temp;
  79. c = *pc;
  80. switch (c) {
  81. case '\n':
  82. if(TextRow == (VIDEO_ROWS-1)) {
  83. TextTmScrollDisplay();
  84. TextSetCursorPosition(0,TextRow);
  85. } else {
  86. TextSetCursorPosition(0,TextRow+1);
  87. }
  88. break;
  89. case '\r':
  90. //
  91. // ignore
  92. //
  93. break;
  94. case '\t':
  95. temp = ' ';
  96. u = 8 - (TextColumn % 8);
  97. while(u--) {
  98. TextTmCharOut(&temp);
  99. }
  100. TextSetCursorPosition(TextColumn+u,TextRow);
  101. break;
  102. default :
  103. *Vp++ = c;
  104. *Vp++ = TextCurrentAttribute;
  105. TextSetCursorPosition(TextColumn+1,TextRow);
  106. }
  107. return(pc+1);
  108. }
  109. VOID
  110. TextTmFillAttribute(
  111. IN UCHAR Attribute,
  112. IN ULONG Length
  113. )
  114. /*++
  115. Routine Description:
  116. Changes the screen attribute starting at the current cursor position.
  117. The cursor is not moved.
  118. Arguments:
  119. Attribute - Supplies the new attribute
  120. Length - Supplies the length of the area to change (in bytes)
  121. Return Value:
  122. None.
  123. --*/
  124. {
  125. PUCHAR Temp;
  126. Temp = Vp+1;
  127. while((Vp+1+Length*2) > Temp) {
  128. *Temp++ = (UCHAR)Attribute;
  129. Temp++;
  130. }
  131. }
  132. VOID
  133. TextTmClearToEndOfLine(
  134. VOID
  135. )
  136. /*++
  137. Routine Description:
  138. Clears from the current cursor position to the end of the line
  139. by writing blanks with the current video attribute.
  140. The cursor position is not changed.
  141. Arguments:
  142. None
  143. Returns:
  144. Nothing
  145. --*/
  146. {
  147. PUSHORT p;
  148. unsigned u;
  149. //
  150. // Calculate address of current cursor position
  151. //
  152. p = (PUSHORT)((PUCHAR)VIDEO_BUFFER_VA + (TextRow*VIDEO_BYTES_PER_ROW)) + TextColumn;
  153. //
  154. // Fill with blanks up to end of line.
  155. //
  156. for(u=TextColumn; u<VIDEO_COLUMNS; u++) {
  157. *p++ = (TextCurrentAttribute << 8) + ' ';
  158. }
  159. }
  160. VOID
  161. TextTmClearFromStartOfLine(
  162. VOID
  163. )
  164. /*++
  165. Routine Description:
  166. Clears from the start of the line to the current cursor position
  167. by writing blanks with the current video attribute.
  168. The cursor position is not changed.
  169. Arguments:
  170. None
  171. Returns:
  172. Nothing
  173. --*/
  174. {
  175. PUSHORT p;
  176. unsigned u;
  177. //
  178. // Calculate address of start of line in video buffer
  179. //
  180. p = (PUSHORT)((PUCHAR)VIDEO_BUFFER_VA + (TextRow*VIDEO_BYTES_PER_ROW));
  181. //
  182. // Fill with blanks up to char before cursor position.
  183. //
  184. for(u=0; u<TextColumn; u++) {
  185. *p++ = (TextCurrentAttribute << 8) + ' ';
  186. }
  187. }
  188. VOID
  189. TextTmClearToEndOfDisplay(
  190. VOID
  191. )
  192. /*++
  193. Routine Description:
  194. Clears from the current cursor position to the end of the video
  195. display by writing blanks with the current video attribute.
  196. The cursor position is not changed.
  197. Arguments:
  198. None
  199. Returns:
  200. Nothing
  201. --*/
  202. {
  203. USHORT x,y;
  204. PUSHORT p;
  205. //
  206. // Clear current line
  207. //
  208. TextTmClearToEndOfLine();
  209. //
  210. // Clear the remaining lines
  211. //
  212. p = (PUSHORT)((PUCHAR)VIDEO_BUFFER_VA + ((TextRow+1)*VIDEO_BYTES_PER_ROW));
  213. for(y=TextRow+1; y<VIDEO_ROWS; y++) {
  214. for(x=0; x<VIDEO_COLUMNS; x++) {
  215. *p++ =(TextCurrentAttribute << 8) + ' ';
  216. }
  217. }
  218. }
  219. VOID
  220. TextTmClearDisplay(
  221. VOID
  222. )
  223. /*++
  224. Routine Description:
  225. Clears the text-mode video display by writing blanks with
  226. the current video attribute over the entire display.
  227. Arguments:
  228. None
  229. Returns:
  230. Nothing
  231. --*/
  232. {
  233. unsigned u;
  234. //
  235. // Write blanks in the current attribute to the entire screen.
  236. //
  237. for(u=0; u<VIDEO_ROWS*VIDEO_COLUMNS; u++) {
  238. ((PUSHORT)VIDEO_BUFFER_VA)[u] = (TextCurrentAttribute << 8) + ' ';
  239. }
  240. }
  241. VOID
  242. TextTmScrollDisplay(
  243. VOID
  244. )
  245. /*++
  246. Routine Description:
  247. Scrolls the display up one line. The cursor position is not changed.
  248. Arguments:
  249. None
  250. Returns:
  251. Nothing
  252. --*/
  253. {
  254. PUSHORT Sp,Dp;
  255. USHORT i,j,c;
  256. Dp = (PUSHORT) VIDEO_BUFFER_VA;
  257. Sp = (PUSHORT) (VIDEO_BUFFER_VA + VIDEO_BYTES_PER_ROW);
  258. //
  259. // Move each row up one row
  260. //
  261. for(i=0 ; i < (USHORT)(VIDEO_ROWS-1) ; i++) {
  262. for(j=0; j < (USHORT)VIDEO_COLUMNS; j++) {
  263. *Dp++ = *Sp++;
  264. }
  265. }
  266. //
  267. // Write blanks in the bottom line, using the attribute
  268. // from the leftmost char on the bottom line on the screen.
  269. //
  270. c = (*Dp & (USHORT)0xff00) + (USHORT)' ';
  271. for(i=0; i < (USHORT)VIDEO_COLUMNS; ++i) {
  272. *Dp++ = c;
  273. }
  274. }
  275. VOID
  276. TextTmSetCurrentAttribute(
  277. IN UCHAR Attribute
  278. )
  279. /*++
  280. Routine Description:
  281. Noop.
  282. Arguments:
  283. Attribute - New attribute to set to.
  284. Return Value:
  285. Nothing.
  286. --*/
  287. {
  288. UNREFERENCED_PARAMETER(Attribute);
  289. }
  290. CHAR TmGraphicsChars[GraphicsCharMax] = { '','','','','','' };
  291. UCHAR
  292. TextTmGetGraphicsChar(
  293. IN GraphicsChar WhichOne
  294. )
  295. {
  296. return((UCHAR)TmGraphicsChars[WhichOne]);
  297. }