Source code of Windows XP (NT5)
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.

558 lines
8.1 KiB

  1. /*++
  2. Copyright (c) 1993 Weitek Corporation
  3. Module Name:
  4. Bt485.c
  5. Abstract:
  6. This module contains code specific to the Bt485 DAC.
  7. Environment:
  8. Kernel mode
  9. Revision History may be found at the end of this file.
  10. --*/
  11. #include "p9.h"
  12. #include "p9gbl.h"
  13. #include "p9000.h"
  14. #include "bt485.h"
  15. #include "p91dac.h"
  16. //
  17. // DAC specific static data.
  18. //
  19. //
  20. // Define the DAC support routines structure for the Bt485 DAC.
  21. //
  22. DAC Bt485 = {
  23. DAC_ID_BT485,
  24. NUM_DAC_REGS,
  25. Bt485SetMode,
  26. Bt485RestoreMode,
  27. Bt485SetPalette,
  28. Bt485ClearPalette,
  29. Bt485PointerOn,
  30. Bt485PointerOff,
  31. Bt485SetPointerPos,
  32. Bt485SetPointerShape,
  33. CLK_MAX_FREQ,
  34. Bt485SetClkDoubler,
  35. Bt485ClrClkDoubler
  36. };
  37. VOID
  38. Bt485SetPalette(
  39. PHW_DEVICE_EXTENSION HwDeviceExtension,
  40. ULONG *pPal,
  41. ULONG StartIndex,
  42. ULONG Count
  43. )
  44. /*++
  45. Routine Description:
  46. Sets the Device palette
  47. Arguments:
  48. HwDeviceExtension - Pointer to the miniport driver's device extension.
  49. pPal - Pointer to the array of pallete entries.
  50. StartIndex - Specifies the first pallete entry provided in pPal.
  51. Count - Number of palette entries in pPal
  52. Return Value:
  53. None.
  54. --*/
  55. {
  56. UCHAR *pBytePal;
  57. PAL_WR_ADDR((UCHAR) StartIndex);
  58. pBytePal = (PUCHAR) pPal;
  59. //
  60. // Load the palette with RGB values. The input palette has 4 bytes
  61. // per entry, the last of which is ignored.
  62. //
  63. while (Count--)
  64. {
  65. PAL_WR_DATA(*pBytePal++);
  66. PAL_WR_DATA(*pBytePal++);
  67. PAL_WR_DATA(*pBytePal++);
  68. pBytePal++;
  69. }
  70. }
  71. VOID
  72. Bt485SetPointerPos(
  73. PHW_DEVICE_EXTENSION HwDeviceExtension,
  74. ULONG ptlX,
  75. ULONG ptlY
  76. )
  77. /*++
  78. Routine Description:
  79. Move Hardware Pointer.
  80. Arguments:
  81. HwDeviceExtension - Pointer to the miniport driver's device extension.
  82. ptlX, ptlY - Requested X,Y position for the pointer.
  83. Return Value:
  84. TRUE
  85. --*/
  86. {
  87. //
  88. // Strip off the invalid bits and update the cursor position regs.
  89. //
  90. WR_CURS_POS_X(((ptlX + CURSOR_WIDTH) & 0xFFF));
  91. WR_CURS_POS_Y(((ptlY + CURSOR_HEIGHT) & 0xFFF));
  92. return;
  93. }
  94. VOID
  95. Bt485SetPointerShape(
  96. PHW_DEVICE_EXTENSION HwDeviceExtension,
  97. PUCHAR pHWCursorShape
  98. )
  99. /*++
  100. Routine Description:
  101. Sets the hardware cursor shape.
  102. Arguments:
  103. HwDeviceExtension - Pointer to the miniport driver's device extension.
  104. pHWCursorShape - Pointer to the cursor bitmap.
  105. Return Value:
  106. None.
  107. --*/
  108. {
  109. ULONG iCount;
  110. //
  111. // The # of bytes of cursor bitmap data to send *= 2 for and/xor mask
  112. // *= 8 for 8bit/byte
  113. // *= 2 for 2 loops
  114. //
  115. ULONG iLoop = (CURSOR_WIDTH * CURSOR_HEIGHT * 2) / (8 * 2);
  116. //
  117. // AND mask will be loaded to plane 1.
  118. //
  119. PAL_WR_ADDR(0x80);
  120. iCount = iLoop;
  121. WAIT_FOR_RETRACE();
  122. while (iCount--)
  123. {
  124. WR_CURS_DATA(*pHWCursorShape++);
  125. }
  126. //
  127. // XOR mask will be loaded to plane 0.
  128. //
  129. PAL_WR_ADDR(0x00);
  130. iCount = iLoop;
  131. WAIT_FOR_RETRACE();
  132. while (iCount--)
  133. {
  134. WR_CURS_DATA(*pHWCursorShape++);
  135. }
  136. return;
  137. }
  138. VOID
  139. Bt485PointerOn(
  140. PHW_DEVICE_EXTENSION HwDeviceExtension
  141. )
  142. /*++
  143. Routine Description:
  144. Turn on the hardware cursor.
  145. Arguments:
  146. HwDeviceExtension - Pointer to the miniport driver's device extension.
  147. Return Value:
  148. None.
  149. --*/
  150. {
  151. //
  152. // Turn the cursor on only if it was disabled.
  153. //
  154. if (!CURS_IS_ON())
  155. {
  156. WAIT_FOR_RETRACE();
  157. CURS_ON();
  158. }
  159. return;
  160. }
  161. VOID
  162. Bt485PointerOff(
  163. PHW_DEVICE_EXTENSION HwDeviceExtension
  164. )
  165. /*++
  166. Routine Description:
  167. Turn off the hardware cursor.
  168. Arguments:
  169. HwDeviceExtension - Pointer to the miniport driver's device extension.
  170. Return Value:
  171. None.
  172. --*/
  173. {
  174. //
  175. // Turn the cursor off only if it was enabled.
  176. //
  177. if (CURS_IS_ON())
  178. {
  179. WAIT_FOR_RETRACE();
  180. CURS_OFF();
  181. }
  182. return;
  183. }
  184. VOID
  185. Bt485ClearPalette(
  186. PHW_DEVICE_EXTENSION HwDeviceExtension
  187. )
  188. /*++
  189. Routine Description:
  190. Clears the palette to all 0's
  191. Arguments:
  192. HwDeviceExtension - Pointer to the miniport driver's device extension.
  193. Return Value:
  194. None.
  195. --*/
  196. {
  197. int Count;
  198. //
  199. // Calculate the number of palette entries. It is assumed that the
  200. // caller has already determined that the current mode makes use
  201. // of the palette,
  202. //
  203. Count = 1 << HwDeviceExtension->usBitsPixel;
  204. //
  205. // Fill the palette with RGB values of 0.
  206. //
  207. while (Count--)
  208. {
  209. PAL_WR_DATA(0);
  210. PAL_WR_DATA(0);
  211. PAL_WR_DATA(0);
  212. }
  213. return;
  214. }
  215. BOOLEAN
  216. Bt485SetMode(
  217. PHW_DEVICE_EXTENSION HwDeviceExtension
  218. )
  219. /*++
  220. Routine Description:
  221. Initializes the DAC for the current mode.
  222. Arguments:
  223. HwDeviceExtension - Pointer to the miniport driver's device extension.
  224. Return Value:
  225. None.
  226. --*/
  227. {
  228. UCHAR ucCurState;
  229. //
  230. // Enable 8bit dacs, allow access to Command Register 3.
  231. //
  232. WR_DAC(CMD_REG_0, ENB_CMD_REG_3 | MODE_8_BIT);
  233. //
  234. // Set the DAC Pixel port value for the current bit depth.
  235. //
  236. switch (HwDeviceExtension->usBitsPixel)
  237. {
  238. case 8:
  239. WR_DAC(CMD_REG_1, PIX_PORT_8);
  240. break;
  241. case 16:
  242. WR_DAC(CMD_REG_1, PIX_PORT_16);
  243. break;
  244. case 32:
  245. WR_DAC(CMD_REG_1, PIX_PORT_32);
  246. break;
  247. default:
  248. //
  249. // Oops..invalid BPP value. Use 8BPP value for now.
  250. //
  251. WR_DAC(CMD_REG_1, PIX_PORT_8);
  252. break;
  253. };
  254. //
  255. // Select P9000 video clock, disable cursor
  256. //
  257. WR_DAC(CMD_REG_2, (PORTSEL_MSKD | PCLK1_SEL) & DIS_CURS);
  258. //
  259. // Select 32x32x2 cursor mode, and clock doubler mode if neccessary.
  260. //
  261. RD_CMD_REG_3(ucCurState);
  262. if (HwDeviceExtension->VideoData.dotfreq1 >
  263. HwDeviceExtension->Dac.ulMaxClkFreq)
  264. {
  265. //
  266. // Enable the DAC clock doubler mode.
  267. //
  268. HwDeviceExtension->Dac.DACSetClkDblMode(HwDeviceExtension);
  269. }
  270. else
  271. {
  272. //
  273. // Disable the DAC clock doubler mode.
  274. //
  275. HwDeviceExtension->Dac.DACClrClkDblMode(HwDeviceExtension);
  276. }
  277. //
  278. // Set the pixel read mask.
  279. //
  280. WR_DAC(PIXEL_MSK_REG, 0xff);
  281. //
  282. // Set cursor colors 1 and 2.
  283. //
  284. WR_DAC(CURS_CLR_ADDR, 1);
  285. WR_DAC(CURS_CLR_DATA, 0x00);
  286. WR_DAC(CURS_CLR_DATA, 0x00);
  287. WR_DAC(CURS_CLR_DATA, 0x00);
  288. WR_DAC(CURS_CLR_DATA, 0xFF);
  289. WR_DAC(CURS_CLR_DATA, 0xFF);
  290. WR_DAC(CURS_CLR_DATA, 0xFF);
  291. return(TRUE);
  292. }
  293. VOID
  294. Bt485RestoreMode(
  295. PHW_DEVICE_EXTENSION HwDeviceExtension
  296. )
  297. /*++
  298. routine description:
  299. Restore the DAC to its pristine state.
  300. arguments:
  301. hwdeviceextension - pointer to the miniport driver's device extension.
  302. return value:
  303. --*/
  304. {
  305. UCHAR ucCurState;
  306. //
  307. // Enable accesses to CMD_REG_3.
  308. //
  309. WR_DAC(CMD_REG_0, ENB_CMD_REG_3);
  310. //
  311. // Set pixel port for 8bit pixels.
  312. //
  313. WR_DAC(CMD_REG_1, RD_DAC(CMD_REG_1) & ~PIX_PORT_24);
  314. //
  315. // Select VGA video clock, disable cursor.
  316. //
  317. WR_DAC(CMD_REG_2, (RD_DAC(CMD_REG_2) & DIS_CURS));
  318. //
  319. // Select 32x32 cursor, clear clock doubler bit.
  320. //
  321. RD_CMD_REG_3(ucCurState);
  322. WR_CMD_REG_3(ucCurState & (~DAC_CLK_2X & CUR_MODE_32));
  323. //
  324. // Set pixel read mask.
  325. //
  326. WR_DAC(PIXEL_MSK_REG, 0xff);
  327. return;
  328. }
  329. VOID
  330. Bt485SetClkDoubler(
  331. PHW_DEVICE_EXTENSION HwDeviceExtension
  332. )
  333. /*++
  334. routine description:
  335. Enable the DAC's internal clock doubler.
  336. arguments:
  337. hwdeviceextension - pointer to the miniport driver's device extension.
  338. return value:
  339. --*/
  340. {
  341. UCHAR ucCurState;
  342. RD_CMD_REG_3(ucCurState);
  343. WR_CMD_REG_3(ucCurState | DAC_CLK_2X);
  344. return;
  345. }
  346. VOID
  347. Bt485ClrClkDoubler(
  348. PHW_DEVICE_EXTENSION HwDeviceExtension
  349. )
  350. /*++
  351. routine description:
  352. Disable the DAC's internal clock doubler.
  353. arguments:
  354. hwdeviceextension - pointer to the miniport driver's device extension.
  355. return value:
  356. --*/
  357. {
  358. UCHAR ucCurState;
  359. RD_CMD_REG_3(ucCurState);
  360. WR_CMD_REG_3(ucCurState & ~DAC_CLK_2X);
  361. return;
  362. }