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.

318 lines
7.1 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. port.c
  5. Abstract:
  6. This is the console fullscreen driver for the VGA card.
  7. Environment:
  8. kernel mode only
  9. Notes:
  10. Revision History:
  11. --*/
  12. #include "fsvga.h"
  13. #define MAKEWORD(a, b) (USHORT)((((USHORT)a) & 0xFF) | ((((USHORT)(b)) << 8) & 0xFF00))
  14. VOID
  15. GetHardwareScrollReg(
  16. PPORT_LIST PortList,
  17. PEMULATE_BUFFER_INFORMATION EmulateInfo
  18. )
  19. /*++
  20. Routine Description:
  21. This routine gets the hardware scrolls register value.
  22. Arguments:
  23. Return Value:
  24. --*/
  25. {
  26. UCHAR low;
  27. UCHAR high;
  28. UCHAR mid;
  29. WRITE_PORT_UCHAR(PortList[CRTCAddressPortColor].Port,
  30. IND_START_ADRS_L);
  31. low = READ_PORT_UCHAR(PortList[CRTCDataPortColor].Port);
  32. WRITE_PORT_UCHAR(PortList[CRTCAddressPortColor].Port,
  33. IND_START_ADRS_H);
  34. high = READ_PORT_UCHAR(PortList[CRTCDataPortColor].Port);
  35. EmulateInfo->StartAddress = MAKEWORD(low, high);
  36. WRITE_PORT_UCHAR(PortList[CRTCAddressPortColor].Port,
  37. IND_LINE_COMPARE);
  38. low = READ_PORT_UCHAR(PortList[CRTCDataPortColor].Port);
  39. WRITE_PORT_UCHAR(PortList[CRTCAddressPortColor].Port,
  40. IND_LINE_COMPARE8);
  41. mid = READ_PORT_UCHAR(PortList[CRTCDataPortColor].Port);
  42. mid = (mid >> 4) & 1;
  43. WRITE_PORT_UCHAR(PortList[CRTCAddressPortColor].Port,
  44. IND_LINE_COMPARE9);
  45. high = READ_PORT_UCHAR(PortList[CRTCDataPortColor].Port);
  46. high = (high >> 5) & 2;
  47. high |= mid;
  48. EmulateInfo->LineCompare = MAKEWORD(low, high);
  49. }
  50. VOID
  51. SetGRAMWriteMode(
  52. PPORT_LIST PortList
  53. )
  54. /*++
  55. Routine Description:
  56. This routine sets the write mode of graphics register.
  57. Arguments:
  58. Return Value:
  59. --*/
  60. {
  61. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  62. MAKEWORD(IND_GRAPH_MODE, M_PROC_WRITE+M_DATA_READ));
  63. //
  64. // Set up to write data without interacting with the latches.
  65. //
  66. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  67. MAKEWORD(IND_DATA_ROTATE, DR_SET));
  68. //
  69. // Enable all the available EGA planes.
  70. //
  71. WRITE_PORT_USHORT(PortList[SEQAddressPort].Port,
  72. MAKEWORD(IND_MAP_MASK, GRAPH_ADDR_MASK));
  73. //
  74. // Use all pixel positions.
  75. //
  76. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  77. MAKEWORD(IND_BIT_MASK, BIT_MASK_DEFAULT));
  78. }
  79. VOID
  80. SetGRAMCopyMode(
  81. PPORT_LIST PortList
  82. )
  83. /*++
  84. Routine Description:
  85. This routine sets the copy mode of graphics register.
  86. Arguments:
  87. Return Value:
  88. --*/
  89. {
  90. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  91. MAKEWORD(IND_GRAPH_MODE, M_LATCH_WRITE+M_COLOR_READ));
  92. //
  93. // Set up to write data without interacting with the latches.
  94. //
  95. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  96. MAKEWORD(IND_DATA_ROTATE, DR_SET));
  97. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  98. MAKEWORD(IND_COLOR_DONT_CARE, 0));
  99. }
  100. VOID
  101. SetGRAMInvertMode(
  102. PPORT_LIST PortList
  103. )
  104. /*++
  105. Routine Description:
  106. This routine sets the invert mode of graphics register.
  107. Arguments:
  108. Return Value:
  109. --*/
  110. {
  111. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  112. MAKEWORD(IND_GRAPH_MODE, M_AND_WRITE+M_COLOR_READ));
  113. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  114. MAKEWORD(IND_DATA_ROTATE, DR_XOR));
  115. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  116. MAKEWORD(IND_BIT_MASK, BIT_MASK_DEFAULT));
  117. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  118. MAKEWORD(IND_COLOR_DONT_CARE, 0));
  119. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  120. MAKEWORD(IND_SET_RESET, 0xff));
  121. }
  122. VOID
  123. set_opaque_bkgnd_proc(
  124. PPORT_LIST PortList,
  125. PEMULATE_BUFFER_INFORMATION EmulateInfo,
  126. PUCHAR FrameBuffer,
  127. USHORT Attributes
  128. )
  129. /*++
  130. set_opaque_bkgnd
  131. Set the VGA registers for drawing a full screen byte with opaque
  132. font and opaque background.
  133. Created.
  134. --*/
  135. {
  136. UCHAR ColorFg = Attributes & 0x0f;
  137. UCHAR ColorBg = (Attributes & 0xf0) >> 4;
  138. if (Attributes & COMMON_LVB_REVERSE_VIDEO)
  139. {
  140. Attributes = ColorBg;
  141. ColorBg = ColorFg;
  142. ColorFg = (UCHAR)Attributes;
  143. }
  144. if (EmulateInfo->ColorFg == ColorFg &&
  145. EmulateInfo->ColorBg == ColorBg)
  146. return;
  147. EmulateInfo->ColorFg = ColorFg;
  148. EmulateInfo->ColorBg = ColorBg;
  149. ColorSetDirect(PortList, FrameBuffer, ColorFg, ColorBg);
  150. }
  151. VOID
  152. ColorSetGridMask(
  153. PPORT_LIST PortList,
  154. UCHAR BitMask
  155. )
  156. {
  157. //
  158. // That color is used for all planes.
  159. //
  160. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  161. MAKEWORD(IND_SET_RESET_ENABLE, GRAPH_ADDR_MASK));
  162. //
  163. // Change the Set/Reset register to be all set.
  164. //
  165. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  166. MAKEWORD(IND_SET_RESET, 0x07));
  167. //
  168. // Use specified pixel positions.
  169. //
  170. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  171. MAKEWORD(IND_BIT_MASK, BitMask));
  172. //
  173. // Set up to write data without interacting with the latches.
  174. //
  175. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  176. MAKEWORD(IND_DATA_ROTATE, DR_SET));
  177. }
  178. VOID
  179. ColorSetDirect(
  180. PPORT_LIST PortList,
  181. PUCHAR FrameBuffer,
  182. UCHAR ColorFg,
  183. UCHAR ColorBg
  184. )
  185. /*++
  186. ColorSetDirect
  187. Set the VGA registers for drawing a full screen byte with opaque
  188. font and opaque background.
  189. Created.
  190. --*/
  191. {
  192. //
  193. // Set up to write data without interacting with the latches.
  194. //
  195. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  196. MAKEWORD(IND_DATA_ROTATE, DR_SET));
  197. //
  198. // Put the background color in the Set/Reset register.
  199. //
  200. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  201. MAKEWORD(IND_SET_RESET, ColorBg));
  202. //
  203. // That color is used for all planes.
  204. //
  205. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  206. MAKEWORD(IND_SET_RESET_ENABLE, GRAPH_ADDR_MASK));
  207. //
  208. // This gets our background color into the latches.
  209. //
  210. AccessGRAM_WR(FrameBuffer, GRAPH_ADDR_MASK);
  211. //
  212. // Change the Set/Reset register to be all zeroes.
  213. //
  214. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  215. MAKEWORD(IND_SET_RESET, 0));
  216. //
  217. // The Set/Reset enable register now flags where the foreground/background colors are the same.
  218. //
  219. ColorFg = ~(ColorFg ^ ColorBg);
  220. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  221. MAKEWORD(IND_SET_RESET_ENABLE, ColorFg));
  222. //
  223. // Color differences will be xor'd with the latches.
  224. //
  225. WRITE_PORT_USHORT(PortList[GRAPHAddressPort].Port,
  226. MAKEWORD(IND_DATA_ROTATE, DR_XOR));
  227. }