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.

381 lines
11 KiB

  1. /*/****************************************************************************
  2. * name: MoveToVideoBuffer
  3. *
  4. * description: This function will move from the NPI structures the required
  5. * information for MGAVidInit.
  6. *
  7. * designed: Bart Simpson. february 17, 1993
  8. * last modified: $Author: bleblanc $, $Date: 94/05/26 09:39:51 $
  9. *
  10. * version: $Id: MVTOVID.C 1.16 94/05/26 09:39:51 bleblanc Exp $
  11. *
  12. * parameters: BYTE* VidTab, BYTE* CrtcTab, BYTE* VideoBuffer
  13. * modifies: VideoBuffer content
  14. * calls: -
  15. * returns: -
  16. ******************************************************************************/
  17. #include "switches.h"
  18. #include "g3dstd.h"
  19. #include "bind.h"
  20. #include "defbind.h"
  21. #ifndef __DDK_SRC__
  22. #include "sxci.h"
  23. #endif
  24. #include "def.h"
  25. #ifdef WINDOWS_NT
  26. #if defined(ALLOC_PRAGMA)
  27. #ifdef NO_FLOAT
  28. VOID MoveToVideoBuffer(BYTE* pVidTab, BYTE* pCrtcTab, BYTE* pVideoBuffer);
  29. #else
  30. VOID MoveToVideoBuffer(BYTE* pVidTab, BYTE* pCrtcTab, BYTE* pVideoBuffer);
  31. #endif
  32. #pragma alloc_text(PAGE,MoveToVideoBuffer)
  33. #endif
  34. //#if defined(ALLOC_PRAGMA)
  35. // #pragma data_seg("PAGE")
  36. //#endif
  37. #endif /* #ifdef WINDOWS_NT */
  38. #ifdef OS2
  39. #define _Far far
  40. #endif
  41. #ifdef NO_FLOAT
  42. VOID MoveToVideoBuffer(BYTE* pVidTab, BYTE* pCrtcTab, BYTE* pVideoBuffer)
  43. {
  44. /*** Values of PCLK for the RAMDAC ***/
  45. typedef struct
  46. {
  47. word FbPitch;
  48. long Pclk_I;
  49. long Pclk_NI;
  50. } Pclk;
  51. Pclk Pclk_Ramdac[] = {
  52. 640, 1227, 3150,
  53. 768, 1475, 4500,
  54. 800, 3300 , 5000,
  55. 1024, 4500 , 7500,
  56. 1152, 6200 , 10600,
  57. 1280, 8000 , 13500,
  58. 1600, 0 , 20000, {(word) -1}
  59. };
  60. extern volatile byte _Far *pMgaBaseAddr;
  61. extern HwData Hw[NB_BOARD_MAX+1];
  62. extern byte iBoard;
  63. Pclk *p1;
  64. long Sclk;
  65. dword Srate;
  66. byte LaserScl;
  67. /*** Move parameters from VidTab in the VideoBuffer ***/
  68. /* [dlee] Don't use magic numbers to index into Vid structure! When building
  69. 32-bit executables, the elements of the Vid structure are dword aligned,
  70. not byte aligned!!! */
  71. #ifdef WINDOWS_NT
  72. *((BYTE*)(pVideoBuffer + VIDEOBUF_ALW)) = (BYTE)((vid *)pVidTab)[18].valeur;
  73. *((BYTE*)(pVideoBuffer + VIDEOBUF_Interlace)) = (BYTE)((vid *)pVidTab)[13].valeur;
  74. *((DWORD*)(pVideoBuffer + VIDEOBUF_PCLK)) = (DWORD)((vid *)pVidTab)[0].valeur;
  75. *((WORD*)(pVideoBuffer + VIDEOBUF_DBWinXOffset)) = (WORD)((vid *)pVidTab)[3].valeur;
  76. /* In interlace mode, we must double the Vertical back porch */
  77. *((WORD*)(pVideoBuffer + VIDEOBUF_DBWinYOffset)) =
  78. (WORD)((vid *)pVidTab)[13].valeur ?
  79. (WORD)((vid *)pVidTab)[8].valeur * 2 : /* Interlace */
  80. (WORD)((vid *)pVidTab)[8].valeur;
  81. /*** Set some new parameters in the VideoBuffer ***/
  82. *((BYTE*)(pVideoBuffer + VIDEOBUF_VideoDelay)) = *((BYTE*)(pCrtcTab + (31 * LONG_S)));
  83. *((BYTE*)(pVideoBuffer + VIDEOBUF_VsyncPol)) = (BYTE)((vid *)pVidTab)[28].valeur;
  84. *((BYTE*)(pVideoBuffer + VIDEOBUF_HsyncPol)) = (BYTE)((vid *)pVidTab)[27].valeur;
  85. *((BYTE*)(pVideoBuffer + VIDEOBUF_HsyncDelay)) = *((BYTE*)(pCrtcTab + (33 * LONG_S)));
  86. *((BYTE*)(pVideoBuffer + VIDEOBUF_Pedestal)) &= 0x80; /**** FORCE !#@$!@#$!@#$ ***/
  87. #else
  88. *((BYTE*)(pVideoBuffer + VIDEOBUF_ALW)) = *((BYTE*)(pVidTab + (18*(26+LONG_S)) + 26));
  89. *((BYTE*)(pVideoBuffer + VIDEOBUF_Interlace)) = *((BYTE*)(pVidTab + (13*(26+LONG_S)) + 26));
  90. *((DWORD*)(pVideoBuffer + VIDEOBUF_PCLK)) = *((DWORD*)(pVidTab + (0*(26+LONG_S)) + 26));
  91. *((WORD*)(pVideoBuffer + VIDEOBUF_DBWinXOffset)) = *((WORD*)(pVidTab + (3*(26+LONG_S)) + 26));
  92. /* In interlace mode, we must double the Vertical back porch */
  93. *((WORD*)(pVideoBuffer + VIDEOBUF_DBWinYOffset)) =
  94. *((WORD*)(pVidTab + (13*(26+LONG_S)) + 26)) ?
  95. *((WORD*)(pVidTab + (8*(26+LONG_S)) + 26)) * 2 : /* Interlace */
  96. *((WORD*)(pVidTab + (8*(26+LONG_S)) + 26)) ;
  97. /*** Set some new parameters in the VideoBuffer ***/
  98. *((BYTE*)(pVideoBuffer + VIDEOBUF_VideoDelay)) = *((BYTE*)(pCrtcTab + (31 * LONG_S)));
  99. *((BYTE*)(pVideoBuffer + VIDEOBUF_VsyncPol)) = *((BYTE*)(pVidTab + (28*(26+LONG_S)) + 26));
  100. *((BYTE*)(pVideoBuffer + VIDEOBUF_HsyncPol)) = *((BYTE*)(pVidTab + (27*(26+LONG_S)) + 26));
  101. *((BYTE*)(pVideoBuffer + VIDEOBUF_HsyncDelay)) = *((BYTE*)(pCrtcTab + (33 * LONG_S)));
  102. *((BYTE*)(pVideoBuffer + VIDEOBUF_Pedestal)) &= 0x80; /**** FORCE !#@$!@#$!@#$ ***/
  103. #endif /* #ifdef WINDOWS_NT */
  104. *((DWORD*)(pVideoBuffer + VIDEOBUF_OvsColor)) = 0x0000; /**** FORCE !#@$!@#$!@#$ ***/
  105. /*** srate and laserscl need to be set according to PCLK ***/
  106. /*******************************************************************/
  107. /*** PIXEL CLOCK : Programmation of registers SRATE and LASERSCL ***/
  108. /*** N.B. Values of SCLK and SPLCLK are in MHz ***/
  109. /* Find PCLK value in table Pclk_Ramdac[] */
  110. for (p1 = Pclk_Ramdac; p1->FbPitch != (word)-1; p1++)
  111. {
  112. if (p1->FbPitch == Hw[iBoard].pCurrentDisplayMode->FbPitch)
  113. {
  114. if (Hw[iBoard].pCurrentDisplayMode->DispType & 0x1) /* if interlace */
  115. {
  116. switch (Hw[iBoard].DacType)
  117. {
  118. case BT482:
  119. Sclk = p1->Pclk_I*(Hw[iBoard].pCurrentDisplayMode->PixWidth/8);
  120. break;
  121. case BT485:
  122. case PX2085:
  123. case VIEWPOINT:
  124. case TVP3026:
  125. Sclk = p1->Pclk_I/(32/Hw[iBoard].pCurrentDisplayMode->PixWidth);
  126. break;
  127. }
  128. }
  129. else
  130. {
  131. switch (Hw[iBoard].DacType)
  132. {
  133. case BT482:
  134. Sclk = p1->Pclk_NI*(Hw[iBoard].pCurrentDisplayMode->PixWidth/8);
  135. break;
  136. case BT485:
  137. case PX2085:
  138. case VIEWPOINT:
  139. case TVP3026:
  140. Sclk = p1->Pclk_NI/(32/Hw[iBoard].pCurrentDisplayMode->PixWidth);
  141. break;
  142. }
  143. }
  144. break;
  145. }
  146. }
  147. /*** MOUSE ***/
  148. if (Hw[iBoard].PortCfg == MOUSE_PORT)
  149. Srate = (dword)((Sclk*100)/16384); /* Srate = SCLK / (200*32*256) */
  150. /*** LASER ***/
  151. else
  152. {
  153. if (Sclk < 2200)
  154. Srate = 0;
  155. else if (Sclk >= 2200 && Sclk < 4400)
  156. Srate = 1;
  157. else if (Sclk >= 4400 && Sclk < 8800)
  158. Srate = 3;
  159. else if (Sclk >= 8800 && Sclk < 17600)
  160. Srate = 7;
  161. else
  162. Srate = 9;
  163. if ((Sclk/(Srate+1)) < 1400)
  164. LaserScl = 0;
  165. else if ((Sclk/(Srate+1)) >= 1400 && (Sclk/(Srate+1)) < 1750)
  166. LaserScl = 1;
  167. else if ((Sclk/(Srate+1)) >= 1750)
  168. LaserScl = 2;
  169. }
  170. *((BYTE*)(pVideoBuffer + VIDEOBUF_Srate)) = (byte)Srate;
  171. if (Hw[iBoard].PortCfg != MOUSE_PORT)
  172. *((BYTE*)(pVideoBuffer + VIDEOBUF_LaserScl)) = LaserScl;
  173. /*** move the CTRC parameters in the VideoBuffer ***/
  174. { WORD i;
  175. for (i = 0; i <= 28; i++)
  176. {
  177. *((BYTE*)(pVideoBuffer + VIDEOBUF_CRTC + i)) = *((BYTE*)(pCrtcTab + (i * LONG_S)));
  178. }
  179. }
  180. }
  181. /**************************************************************************/
  182. #else
  183. VOID MoveToVideoBuffer(BYTE* pVidTab, BYTE* pCrtcTab, BYTE* pVideoBuffer)
  184. {
  185. /*** Values of PCLK for the RAMDAC ***/
  186. typedef struct
  187. {
  188. word FbPitch;
  189. float Pclk_I;
  190. float Pclk_NI;
  191. } Pclk;
  192. Pclk Pclk_Ramdac[] = {
  193. 640, 12.27, 31.5,
  194. 768, 14.75, 45.0,
  195. 800, 33.0 , 50.0,
  196. 1024, 45.0 , 75.0,
  197. 1152, 62.0 , 106.0,
  198. 1280, 80.0 , 135.0,
  199. 1600, 0 , 200.0, {-1}
  200. };
  201. extern volatile byte _Far *pMgaBaseAddr;
  202. extern HwData Hw[NB_BOARD_MAX+1];
  203. extern byte iBoard;
  204. Pclk *p1;
  205. float Sclk;
  206. dword Srate;
  207. byte LaserScl;
  208. /*** Move parameters from VidTab in the VideoBuffer ***/
  209. *((BYTE*)(pVideoBuffer + VIDEOBUF_ALW)) = *((BYTE*)(pVidTab + (18*(26+LONG_S)) + 26));
  210. *((BYTE*)(pVideoBuffer + VIDEOBUF_Interlace)) = *((BYTE*)(pVidTab + (13*(26+LONG_S)) + 26));
  211. *((DWORD*)(pVideoBuffer + VIDEOBUF_PCLK)) = *((DWORD*)(pVidTab + (0*(26+LONG_S)) + 26));
  212. *((WORD*)(pVideoBuffer + VIDEOBUF_DBWinXOffset)) = *((WORD*)(pVidTab + (3*(26+LONG_S)) + 26));
  213. /* In interlace mode, we must double the Vertical back porch */
  214. *((WORD*)(pVideoBuffer + VIDEOBUF_DBWinYOffset)) =
  215. *((WORD*)(pVidTab + (13*(26+LONG_S)) + 26)) ?
  216. *((WORD*)(pVidTab + (8*(26+LONG_S)) + 26)) * 2 : /* Interlace */
  217. *((WORD*)(pVidTab + (8*(26+LONG_S)) + 26)) ;
  218. /*** Set some new parameters in the VideoBuffer ***/
  219. *((BYTE*)(pVideoBuffer + VIDEOBUF_VideoDelay)) = *((BYTE*)(pCrtcTab + (31 * LONG_S)));
  220. *((BYTE*)(pVideoBuffer + VIDEOBUF_VsyncPol)) = *((BYTE*)(pVidTab + (28*(26+LONG_S)) + 26));
  221. *((BYTE*)(pVideoBuffer + VIDEOBUF_HsyncPol)) = *((BYTE*)(pVidTab + (27*(26+LONG_S)) + 26));
  222. *((BYTE*)(pVideoBuffer + VIDEOBUF_HsyncDelay)) = *((BYTE*)(pCrtcTab + (33 * LONG_S)));
  223. *((BYTE*)(pVideoBuffer + VIDEOBUF_Pedestal)) &= 0x80; /**** FORCE !#@$!@#$!@#$ ***/
  224. *((DWORD*)(pVideoBuffer + VIDEOBUF_OvsColor)) = 0x0000; /**** FORCE !#@$!@#$!@#$ ***/
  225. /*** srate and laserscl need to be set according to PCLK ***/
  226. /*******************************************************************/
  227. /*** PIXEL CLOCK : Programmation of registers SRATE and LASERSCL ***/
  228. /*** N.B. Values of SCLK and SPLCLK are in MHz ***/
  229. /* Find PCLK value in table Pclk_Ramdac[] */
  230. for (p1 = Pclk_Ramdac; p1->FbPitch != (word)-1; p1++)
  231. {
  232. if (p1->FbPitch == Hw[iBoard].pCurrentDisplayMode->FbPitch)
  233. {
  234. if (Hw[iBoard].pCurrentDisplayMode->DispType & 0x1) /* if interlace */
  235. {
  236. switch (Hw[iBoard].DacType)
  237. {
  238. case BT482:
  239. Sclk = p1->Pclk_I*(Hw[iBoard].pCurrentDisplayMode->PixWidth/8);
  240. break;
  241. case BT485:
  242. case PX2085:
  243. case VIEWPOINT:
  244. case TVP3026:
  245. Sclk = p1->Pclk_I/(32/Hw[iBoard].pCurrentDisplayMode->PixWidth);
  246. break;
  247. }
  248. }
  249. else
  250. {
  251. switch (Hw[iBoard].DacType)
  252. {
  253. case BT482:
  254. Sclk = p1->Pclk_NI*(Hw[iBoard].pCurrentDisplayMode->PixWidth/8);
  255. break;
  256. case BT485:
  257. case PX2085:
  258. case VIEWPOINT:
  259. case TVP3026:
  260. Sclk = p1->Pclk_NI/(32/Hw[iBoard].pCurrentDisplayMode->PixWidth);
  261. break;
  262. }
  263. }
  264. break;
  265. }
  266. }
  267. /*** MOUSE ***/
  268. if (Hw[iBoard].PortCfg == MOUSE_PORT)
  269. Srate = (dword)(Sclk/1.638400); /* Srate = SCLK / (200*32*256) */
  270. /*** LASER ***/
  271. else
  272. {
  273. if (Sclk < 22)
  274. Srate = 0;
  275. else if (Sclk >= 22 && Sclk < 44)
  276. Srate = 1;
  277. else if (Sclk >= 44 && Sclk < 88)
  278. Srate = 3;
  279. else if (Sclk >= 88 && Sclk < 176)
  280. Srate = 7;
  281. else
  282. Srate = 9;
  283. if ((Sclk/(Srate+1)) >= 0 && (Sclk/(Srate+1)) < 14)
  284. LaserScl = 0;
  285. else if ((Sclk/(Srate+1)) >= 14 && (Sclk/(Srate+1)) < 17.5)
  286. LaserScl = 1;
  287. else if ((Sclk/(Srate+1)) >= 17.5)
  288. LaserScl = 2;
  289. }
  290. *((BYTE*)(pVideoBuffer + VIDEOBUF_Srate)) = Srate;
  291. *((BYTE*)(pVideoBuffer + VIDEOBUF_LaserScl)) = LaserScl;
  292. /*** move the CTRC parameters in the VideoBuffer ***/
  293. { WORD i;
  294. for (i = 0; i <= 28; i++)
  295. {
  296. *((BYTE*)(pVideoBuffer + VIDEOBUF_CRTC + i)) = *((BYTE*)(pCrtcTab + (i * LONG_S)));
  297. }
  298. }
  299. }
  300. #endif
  301.