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.

293 lines
12 KiB

  1. /*/****************************************************************************
  2. * name: SetMGALut
  3. *
  4. * description: Keep the Current LUT, Update it on request and send it to the
  5. * RAMDAC.
  6. *
  7. * designed: Bart Simpson, february 11, 1993
  8. * last modified: $Author: bleblanc $, $Date: 94/06/20 10:53:50 $
  9. *
  10. * version: $Id: LUT.C 1.14 94/06/20 10:53:50 bleblanc Exp $
  11. *
  12. * parameters: Far BYTE* pDevice, BYTE* pLUT, BYTE PWidth
  13. * modifies: -
  14. * calls: -
  15. * returns: -
  16. ******************************************************************************/
  17. #include "switches.h"
  18. #include "g3dstd.h"
  19. #include "caddi.h"
  20. #include "def.h"
  21. #include "mga.h"
  22. #include "global.h"
  23. #include "proto.h"
  24. #include "mgai.h"
  25. #ifdef WINDOWS_NT
  26. #if defined(ALLOC_PRAGMA)
  27. #pragma alloc_text(PAGE,SetMGALUT)
  28. #endif
  29. #if defined(ALLOC_PRAGMA)
  30. #pragma data_seg("PAGE")
  31. #endif
  32. #include "video.h"
  33. #endif /* #ifdef WINDOWS_NT */
  34. static BYTE MGALUT[256] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
  35. 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
  36. 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
  37. 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
  38. 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
  39. 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
  40. 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
  41. 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  42. 80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
  43. 90, 91, 92, 93, 94, 95, 96, 97, 98, 99,
  44. 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
  45. 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
  46. 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
  47. 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
  48. 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
  49. 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
  50. 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
  51. 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
  52. 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
  53. 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
  54. 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
  55. 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
  56. 220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
  57. 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
  58. 240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
  59. 250, 251, 252, 253, 254, 255};
  60. VOID SetMGALUT(volatile BYTE _Far *pDevice, BYTE* pLUT, BYTE PWidth, BYTE ModeType)
  61. {
  62. DWORD DST0, DST1, Info;
  63. WORD i;
  64. if (pLUT != (BYTE*)0) /*** Update Local LUT ***/
  65. {
  66. for (i = 0; i < 256; i++)
  67. {
  68. MGALUT[i] = *(pLUT + i);
  69. }
  70. }
  71. /*** Get System Configuration ***/
  72. GetMGAConfiguration(pDevice, &DST0, &DST1, &Info);
  73. /*** Send The LUT to the RAMDAC ***/
  74. switch (Info & (DWORD)Info_Dac_M)
  75. {
  76. case (DWORD)Info_Dac_ATT:
  77. break;
  78. case (DWORD)Info_Dac_Sierra:
  79. break;
  80. case (DWORD)Info_Dac_BT481:
  81. case (DWORD)Info_Dac_BT482:
  82. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT482_WADR_PAL), 0x00);
  83. for (i = 0; i < 256; i++) /*** This is a 3:3:2 (RGB) LUT ***/
  84. {
  85. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT482_COL_PAL), MGALUT[(((i>>5)&7)*0x2492)>>8]);
  86. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT482_COL_PAL), MGALUT[(((i>>2)&7)*0x2492)>>8]);
  87. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT482_COL_PAL), MGALUT[(i&3)*85]);
  88. }
  89. break;
  90. case (DWORD)Info_Dac_BT484:
  91. case (DWORD)Info_Dac_BT485:
  92. case (DWORD)Info_Dac_PX2085:
  93. case (DWORD)Info_Dac_ATT2050:
  94. switch (PWidth)
  95. {
  96. case (BYTE)(TITAN_PWIDTH_PW8 >> TITAN_PWIDTH_A):
  97. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_WADR_PAL), 0x00);
  98. for (i = 0; i < 256; i++) /*** This is a 3:3:2 (RGB) LUT ***/
  99. {
  100. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[(((i>>5)&7)*0x2492)>>8]);
  101. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[(((i>>2)&7)*0x2492)>>8]);
  102. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[(i&3)*85]);
  103. }
  104. break;
  105. case 15:
  106. case (BYTE)(TITAN_PWIDTH_PW16 >> TITAN_PWIDTH_A):
  107. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_WADR_PAL), 0x00);
  108. if(! (ModeType&0x08)) /*** ! M565 ***/
  109. {
  110. for (i = 0; i < 256; i++) /*** This is a 5:5:5 (RGB) LUT contigously indexed ***/
  111. {
  112. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[((i&0x1f)*0x0842)>>8]);
  113. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[((i&0x1f)*0x0842)>>8]);
  114. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[((i&0x1f)*0x0842)>>8]);
  115. }
  116. }
  117. else
  118. {
  119. for (i = 0; i < 256; i++) /*** This is a 5:6:5 (RGB) LUT contigously indexed ***/
  120. {
  121. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[((i&0x1f)*0x0842)>>8]);
  122. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[((i&0x3f)*0x0410)>>8]);
  123. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[((i&0x1f)*0x0842)>>8]);
  124. }
  125. }
  126. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_WADR_PAL), 0x00);
  127. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), 0);
  128. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), 0);
  129. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), 0);
  130. break;
  131. case (BYTE)(TITAN_PWIDTH_PW32 >> TITAN_PWIDTH_A):
  132. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_WADR_PAL), 0x00);
  133. for (i = 0; i < 256; i++)
  134. {
  135. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[i]);
  136. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[i]);
  137. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), MGALUT[i]);
  138. }
  139. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_WADR_PAL), 0x00);
  140. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), 0);
  141. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), 0);
  142. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + BT484_COL_PAL), 0);
  143. break;
  144. }
  145. break;
  146. case (DWORD)Info_Dac_Chameleon: /*** UNKNOWN ***/
  147. break;
  148. case (DWORD)Info_Dac_TVP3026:
  149. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_WADR_PAL), 0);
  150. if( (ModeType&0x10)) /*** DB Front-Back ***/
  151. {
  152. for (i = 0; i < 256; i++) /*** This is a 3:3:2 (RGB) LUT ***/
  153. {
  154. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[(((i>>5)&7)*0x2492)>>8]);
  155. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[(((i>>2)&7)*0x2492)>>8]);
  156. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[(i&3)*85]);
  157. }
  158. }
  159. else
  160. {
  161. switch (PWidth)
  162. {
  163. case (BYTE)(TITAN_PWIDTH_PW8 >> TITAN_PWIDTH_A):
  164. for (i = 0; i < 256; i++) /*** This is a 3:3:2 (RGB) LUT ***/
  165. {
  166. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[(((i>>5)&7)*0x2492)>>8]);
  167. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[(((i>>2)&7)*0x2492)>>8]);
  168. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[(i&3)*85]);
  169. }
  170. break;
  171. case (BYTE)(TITAN_PWIDTH_PW16 >> TITAN_PWIDTH_A):
  172. case (BYTE)(TITAN_PWIDTH_PW24 >> TITAN_PWIDTH_A):
  173. case (BYTE)(TITAN_PWIDTH_PW32 >> TITAN_PWIDTH_A):
  174. {
  175. int err, count;
  176. BYTE r, g, b;
  177. err = 0; count = 0;
  178. do
  179. {
  180. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_WADR_PAL), 0);
  181. for (i = 0; i < 256; i++)
  182. {
  183. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[i]);
  184. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[i]);
  185. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), MGALUT[i]);
  186. }
  187. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_RADR_PAL), 0);
  188. for (i = 0; i < 256; i++)
  189. {
  190. mgaReadBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), r);
  191. mgaReadBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), g);
  192. mgaReadBYTE(*(pDevice + RAMDAC_OFFSET + TVP3026_COL_PAL), b);
  193. err = err || (r != MGALUT[i]);
  194. err = err || (g != MGALUT[i]);
  195. err = err || (b != MGALUT[i]);
  196. if (err) break;
  197. }
  198. count++;
  199. } while ( err && (count < 5000) );
  200. }
  201. break;
  202. }
  203. }
  204. break;
  205. case (DWORD)Info_Dac_ViewPoint:
  206. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_WADR_PAL), 0x00);
  207. switch (PWidth)
  208. {
  209. case (BYTE)(TITAN_PWIDTH_PW8 >> TITAN_PWIDTH_A):
  210. for (i = 0; i < 256; i++) /*** This is a 3:3:2 (RGB) LUT ***/
  211. {
  212. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[(((i>>5)&7)*0x2492)>>8]);
  213. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[(((i>>2)&7)*0x2492)>>8]);
  214. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[(i&3)*85]);
  215. }
  216. break;
  217. case 15:
  218. case (BYTE)(TITAN_PWIDTH_PW16 >> TITAN_PWIDTH_A):
  219. for (i = 0; i < 256; i++)
  220. {
  221. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[i]);
  222. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[i]);
  223. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[i]);
  224. }
  225. break;
  226. case (BYTE)(TITAN_PWIDTH_PW32 >> TITAN_PWIDTH_A):
  227. for (i = 0; i < 256; i++)
  228. {
  229. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[i]);
  230. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[i]);
  231. mgaWriteBYTE(*(pDevice + RAMDAC_OFFSET + VPOINT_COL_PAL), MGALUT[i]);
  232. }
  233. break;
  234. }
  235. break;
  236. }
  237. }