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.

587 lines
14 KiB

  1. /*/****************************************************************************
  2. * name: mtxvpro.c
  3. *
  4. * description: Routines to initialise VIDEO PRO board
  5. *
  6. * designed: Christian Toutant
  7. * last modified:
  8. *
  9. * version:
  10. *
  11. * bool InitVideoPro( bool );
  12. *
  13. ******************************************************************************/
  14. #if 0
  15. #include "switches.h"
  16. #ifdef WINDOWS_NT
  17. #if defined(ALLOC_PRAGMA)
  18. // #pragma alloc_text(PAGE,detectVideoBoard)
  19. #pragma alloc_text(PAGE,init_denc)
  20. #pragma alloc_text(PAGE,init_dac)
  21. #pragma alloc_text(PAGE,init_adc)
  22. #pragma alloc_text(PAGE,init_psg)
  23. #pragma alloc_text(PAGE,init_ctrl)
  24. #pragma alloc_text(PAGE,init_luts)
  25. // #pragma alloc_text(PAGE,en_encoder)
  26. #pragma alloc_text(PAGE,initVideoMode)
  27. // #pragma alloc_text(PAGE,initVideoPro)
  28. #endif
  29. //Not to be paged out:
  30. // Hw
  31. // pMgaBaseAddr
  32. // iBoard
  33. // mtxVideoMode
  34. // pMgaDeviceExtension
  35. //#if defined(ALLOC_PRAGMA)
  36. //#pragma data_seg("PAGE")
  37. //#endif
  38. #else /* #ifdef WINDOWS_NT */
  39. #include <stdlib.h>
  40. #include <string.h>
  41. #include <stdio.h>
  42. #include <dos.h>
  43. #include <time.h>
  44. #endif /* #ifdef WINDOWS_NT */
  45. #ifdef WINDOWS
  46. #include "windows.h"
  47. #endif
  48. #include "bind.h"
  49. #include "defbind.h"
  50. #include "def.h"
  51. #include "mga.h"
  52. #include "mgai_c.h"
  53. #include "mgai.h"
  54. #include "caddi.h"
  55. #include "mtxvpro.h"
  56. #include "ENC_REG.h"
  57. #define TO_FLOAT(i) ((dword)(i) * 10000)
  58. #define TO_INT(f) ((dword)(f) / 10000)
  59. /*------- Extern global variables */
  60. extern HwData Hw[];
  61. extern byte iBoard;
  62. #ifndef WINDOWS_NT
  63. extern volatile byte _Far *pMgaBaseAddr;
  64. static word encBaseAddr;
  65. #else /* #ifndef WINDOWS_NT */
  66. #define inp _inp
  67. #define outp _outp
  68. extern PUCHAR pMgaBaseAddr;
  69. extern PVOID pMgaDeviceExtension;
  70. extern VIDEO_ACCESS_RANGE VideoProAccessRange;
  71. static PUCHAR encBaseAddr;
  72. #endif /* #ifndef WINDOWS_NT */
  73. static EncReg *ptrEncReg;
  74. static dword gain = 10000;
  75. #ifndef WINDOWS_NT
  76. word detectVideoBoard()
  77. {
  78. word videoProPorts[3] = {0x240, 0x300, 0x340};
  79. byte i;
  80. for (i = 0; i < 3; i++)
  81. if ( ( inp(videoProPorts[i]+2) & 0xe0 ) == 0x40 )
  82. return videoProPorts[i];
  83. return 0;
  84. }
  85. #else /* #ifndef WINDOWS_NT */
  86. PUCHAR detectVideoBoard()
  87. {
  88. // If this call succeeds, pVideoProIo will be valid upon return. The
  89. // calling function will have to execute a VideoPortFreeDeviceBase().
  90. #if 1
  91. return 0;
  92. #else
  93. ULONG videoProPorts[3] = {0x240, 0x300, 0x340};
  94. PUCHAR pVideoProIo;
  95. byte i;
  96. for (i = 0; i < 3; i++)
  97. {
  98. // Get access to ports before trying to map I/O configuration space.
  99. VideoProAccessRange.RangeStart.LowPart = (ULONG)videoProPorts[i];
  100. if (VideoPortVerifyAccessRanges(pMgaDeviceExtension,
  101. 1,
  102. &VideoProAccessRange) == NO_ERROR &&
  103. (pVideoProIo = VideoPortGetDeviceBase(pMgaDeviceExtension,
  104. VideoProAccessRange.RangeStart,
  105. VideoProAccessRange.RangeLength,
  106. VideoProAccessRange.RangeInIoSpace)) != NULL)
  107. {
  108. if ( (inp(pVideoProIo+2) & 0xe0) == 0x40 )
  109. {
  110. // pVideoProIo will be freed later by the calling routine.
  111. return pVideoProIo;
  112. }
  113. VideoPortFreeDeviceBase(pMgaDeviceExtension,pVideoProIo);
  114. }
  115. }
  116. return 0;
  117. #endif
  118. }
  119. #endif /* #ifndef WINDOWS_NT */
  120. void init_denc()
  121. {
  122. #ifndef WINDOWS_NT
  123. word indexPort, dataPort, i;
  124. #else
  125. PUCHAR indexPort, dataPort;
  126. word i;
  127. #endif
  128. indexPort = encBaseAddr + DENC_ADDR_CTRL;
  129. dataPort = encBaseAddr + DENC_DATA_CTRL;
  130. outp (indexPort, 0); /* Point to the first index */
  131. for (i = 0; i < DENC_NBRE_REG; i++)
  132. outp (dataPort, ptrEncReg->dencReg[i]);
  133. }
  134. void init_dac()
  135. {
  136. byte offset;
  137. for (offset = 0; offset < DAC_NBRE_REG-1; offset++)
  138. outp ((encBaseAddr + DAC_OFFSET + offset), ptrEncReg->dacReg[offset]);
  139. }
  140. void init_adc()
  141. {
  142. word i;
  143. for (i = 0; i < ADC_NBRE_REG; i++)
  144. outp (encBaseAddr + ADC_OFFSET + i, ptrEncReg->adcReg[i]);
  145. }
  146. void init_psg(int dacAdjust )
  147. {
  148. #ifndef WINDOWS_NT
  149. word indexPort, dataPort, i;
  150. #else
  151. PUCHAR indexPort, dataPort;
  152. word i;
  153. #endif
  154. indexPort = encBaseAddr + PSG_ADDR_CTRL;
  155. dataPort = encBaseAddr + PSG_DATA_CTRL;
  156. for (i = 0; i < PSG_NBRE_REG - 3; i++) /* 3 for 3 registers RO */
  157. {
  158. outpw (indexPort, i);
  159. #ifndef WINDOWS_NT
  160. if (i == 0x0a) /* Ajustement dependant du DAC */
  161. outpw (dataPort, ptrEncReg->psgReg[i] + dacAdjust);
  162. else
  163. outpw (dataPort, ptrEncReg->psgReg[i]);
  164. #else
  165. if (i == 0x0a) /* Ajustement dependant du DAC */
  166. outpw ((PUSHORT)dataPort, (USHORT)(ptrEncReg->psgReg[i] + dacAdjust));
  167. else
  168. outpw ((PUSHORT)dataPort, (USHORT)(ptrEncReg->psgReg[i]));
  169. #endif
  170. }
  171. }
  172. void init_ctrl()
  173. {
  174. /* Enable filter */
  175. #ifndef WINDOWS_NT
  176. outpw (encBaseAddr + ENC_CTRL_OFFSET, ptrEncReg->boardCtrlReg | ENC_FILTER);
  177. #else
  178. outpw ((PUSHORT)(encBaseAddr + ENC_CTRL_OFFSET),
  179. (USHORT)(ptrEncReg->boardCtrlReg | ENC_FILTER));
  180. #endif
  181. }
  182. void init_luts()
  183. {
  184. #ifndef WINDOWS_NT
  185. word indexPort, dataPort;
  186. #else
  187. PUCHAR indexPort, dataPort;
  188. #endif
  189. byte colorTab[256][3];
  190. word i, j;
  191. dword tmp;
  192. for (i = 0; i < 256; i++)
  193. for (j = 0; j < 3; j++)
  194. colorTab[i][j] = (byte)i;
  195. indexPort = encBaseAddr + DAC_LUT_CTRL_WR;
  196. dataPort = encBaseAddr + DAC_LUT_DATA;
  197. outp (indexPort, 0);
  198. for (i = 0; i < 256; i++)
  199. for (j = 0; j < 3; j++)
  200. {
  201. tmp = TO_INT((dword)colorTab[i][j] * gain);
  202. if (tmp > 0xff) tmp = 0xff;
  203. outp (dataPort, (byte)tmp);
  204. }
  205. for (i = 0; i < 256; i++)
  206. for (j = 0; j < 3; j++)
  207. {
  208. tmp = TO_INT( (((dword)colorTab[i][j] * (dword)220 * gain) / (dword)256)
  209. + TO_FLOAT(16) + (TO_FLOAT(1) / 2)
  210. );
  211. if ( tmp > 0xeb )
  212. colorTab[i][j] = 0xeb;
  213. else
  214. colorTab[i][j] = (byte)tmp;
  215. }
  216. // colorTab[i][j] = (double)(colorTab[i][j]*220.0/256.0)
  217. // + 16.0 + 0.5;
  218. indexPort = encBaseAddr + DENC_CLUT_CTRL_WR;
  219. dataPort = encBaseAddr + DENC_CLUT_DATA;
  220. outp (indexPort, 0);
  221. for (i = 0; i < 256; i++)
  222. for (j = 0; j < 3; j++)
  223. outp (dataPort, colorTab[i][j]);
  224. inp (encBaseAddr + DENC_DATA_CTRL); /* To activate the CLUT */
  225. }
  226. #ifndef WINDOWS_NT
  227. void en_encoder (bool state,int encBaseAddr)
  228. #else
  229. void en_encoder (bool state,PUCHAR encBaseAddr)
  230. #endif
  231. {
  232. #ifndef WINDOWS_NT
  233. word indexPort, dataPort;
  234. #else
  235. PUCHAR indexPort, dataPort;
  236. #endif
  237. byte colorTab[256][3];
  238. word i, j;
  239. if (state)
  240. init_luts();
  241. else
  242. {
  243. for (i = 0; i < 256; i++)
  244. for (j = 0; j < 3; j++)
  245. colorTab[i][j] = 0;
  246. indexPort = encBaseAddr + 0x10 + 0x00;
  247. dataPort = encBaseAddr + 0x10 + 0x01;
  248. outp (indexPort, 0);
  249. for (i = 0; i < 256; i++)
  250. for (j = 0; j < 3; j++)
  251. outp (dataPort, colorTab[i][j]);
  252. for (i = 0; i < 256; i++)
  253. for (j = 0; j < 3; j++)
  254. {
  255. colorTab[i][j] = (byte)TO_INT((colorTab[i][j] * TO_FLOAT(220) / 256)
  256. + TO_FLOAT(16) + (TO_FLOAT(1) / 2)
  257. );
  258. // ((double)(colorTab[i][j]*220.0/256.0)+ 16.0 + 0.5) );
  259. }
  260. indexPort = encBaseAddr + 0x04 + 0x00;
  261. dataPort = encBaseAddr + 0x04 + 0x01;
  262. outp (indexPort, 0);
  263. for (i = 0; i < 256; i++)
  264. for (j = 0; j < 3; j++)
  265. outp (dataPort, colorTab[i][j]);
  266. #ifndef WINDOWS_NT
  267. inp (encBaseAddr + 0x04 + 0x03); /* To activate the CLUT */
  268. #else
  269. inp ((PUCHAR)(encBaseAddr + 0x04 + 0x03)); /* To activate the CLUT */
  270. #endif
  271. }
  272. }
  273. bool initVideoMode(word mode, byte pwidth)
  274. {
  275. int dacAdjust = 0;
  276. if ( !(encBaseAddr = detectVideoBoard()) )
  277. return mtxFAIL;
  278. gain = 10000;
  279. if ( (inp(encBaseAddr + 2) & 0x7) > 0 )
  280. {
  281. switch (mode)
  282. {
  283. case NTSC_STD:
  284. ptrEncReg = &ntsca_1;
  285. gain = 14100;
  286. break;
  287. case PAL_STD:
  288. ptrEncReg = &pala_1;
  289. gain = 14100;
  290. break;
  291. case NTSC_STD | VAFC:
  292. ptrEncReg = &ntsc_1;
  293. break;
  294. case PAL_STD | VAFC:
  295. ptrEncReg = &pal_1;
  296. break;
  297. }
  298. if ( mode & VAFC )
  299. {
  300. switch( pwidth )
  301. {
  302. case 8:
  303. dacAdjust = 4;
  304. break;
  305. case 16:
  306. dacAdjust = 2;
  307. break;
  308. case 32:
  309. dacAdjust = 0;
  310. break;
  311. }
  312. }
  313. else
  314. {
  315. switch(Hw[iBoard].DacType)
  316. {
  317. case BT482:
  318. case BT485:
  319. switch( pwidth )
  320. {
  321. case 8:
  322. dacAdjust = 0;
  323. break;
  324. case 16:
  325. case 32:
  326. dacAdjust = 1;
  327. break;
  328. }
  329. break;
  330. case VIEWPOINT:
  331. dacAdjust = 5;
  332. break;
  333. case TVP3026:
  334. switch( pwidth )
  335. {
  336. case 8:
  337. dacAdjust = 18;
  338. break;
  339. case 16:
  340. dacAdjust = 22;
  341. break;
  342. case 32:
  343. dacAdjust = 26;
  344. break;
  345. }
  346. break;
  347. }
  348. }
  349. }
  350. else
  351. switch (mode)
  352. {
  353. case NTSC_STD:
  354. ptrEncReg = &ntsca_0;
  355. break;
  356. case PAL_STD:
  357. ptrEncReg = &pala_0;
  358. break;
  359. case NTSC_STD | VAFC:
  360. switch (pwidth)
  361. {
  362. case 8: ptrEncReg = &ntsc8_0; break;
  363. case 16: ptrEncReg = &ntsc16_0; break;
  364. case 32: ptrEncReg = &ntsc32_0; break;
  365. }
  366. break;
  367. case PAL_STD | VAFC:
  368. switch (pwidth)
  369. {
  370. case 8: ptrEncReg = &pal8_0; break;
  371. case 16: ptrEncReg = &pal16_0; break;
  372. case 32: ptrEncReg = &pal32_0; break;
  373. }
  374. break;
  375. }
  376. init_denc();
  377. init_dac();
  378. init_adc();
  379. init_psg( dacAdjust );
  380. init_ctrl();
  381. init_luts();
  382. return mtxOK;
  383. }
  384. /*
  385. mode OFF/NTSC/PAL
  386. */
  387. bool initVideoPro(byte mode , word DacType)
  388. {
  389. byte tmpByte;
  390. #ifndef WINDOWS_NT
  391. word encBaseAddr;
  392. #else
  393. PUCHAR encBaseAddr;
  394. #endif
  395. if ( !(encBaseAddr = detectVideoBoard()) )
  396. return mtxFAIL;
  397. en_encoder(mode, encBaseAddr);
  398. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_CRT_CTRL),tmpByte);
  399. if (mode)
  400. tmpByte |= 0xc0; /* Set vertical and horizontal reset */
  401. else
  402. tmpByte &= 0x3f; /* Reset vertical and horizontal reset */
  403. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_CRT_CTRL),tmpByte);
  404. #ifndef WINDOWS_NT
  405. if (mode)
  406. outpw(encBaseAddr, inpw(encBaseAddr) | 0x48); /* set GENCLOCK_EN et VIDRST_EN */
  407. else
  408. outpw(encBaseAddr, inpw(encBaseAddr) & ~(0x48));/* reset GENCLOCK_EN et VIDRST_EN */
  409. #else
  410. if (mode)
  411. outpw((PUSHORT)encBaseAddr, (USHORT)(inpw((PUSHORT)encBaseAddr) | 0x48)); /* set GENCLOCK_EN et VIDRST_EN */
  412. else
  413. outpw((PUSHORT)encBaseAddr, (USHORT)(inpw((PUSHORT)encBaseAddr) & ~(0x48))); /* reset GENCLOCK_EN et VIDRST_EN */
  414. #endif
  415. if ( (DacType == VIEWPOINT) && mode )
  416. {
  417. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_MISC_OUT_R), tmpByte);
  418. tmpByte = tmpByte & 0xfb; /* force bit 2 a 0 (clock) */
  419. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_MISC_OUT_W), tmpByte);
  420. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+VPOINT_INDEX), VPOINT_INPUT_CLK);
  421. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+VPOINT_DATA), 0x01);
  422. }
  423. if ( (DacType == TVP3026) && mode )
  424. {
  425. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_MISC_OUT_R), tmpByte);
  426. tmpByte = tmpByte & 0xfb; /* force bit 2 a 0 (clock) */
  427. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_MISC_OUT_W), tmpByte);
  428. /* remove use of double clock */
  429. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+TVP3026_INDEX), TVP3026_CLK_SEL);
  430. mgaReadBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+TVP3026_DATA), tmpByte);
  431. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+TVP3026_DATA), (tmpByte & 0xf0) | 1);
  432. }
  433. if (mode)
  434. {
  435. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_MISC_OUT_R), tmpByte);
  436. tmpByte = tmpByte & 0xfb; /* force bit 2 a 0 (clock) */
  437. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_MISC_OUT_W), tmpByte);
  438. if (DacType == BT485)
  439. {
  440. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + BT485_WADR_PAL), 1);
  441. mgaReadBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + BT485_CMD_REG0), tmpByte);
  442. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + BT485_CMD_REG0), tmpByte | 0x80);
  443. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + BT485_CMD_REG3), 0x00);
  444. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + BT485_CMD_REG0), tmpByte);
  445. }
  446. }
  447. if ( (DacType == PX2085) )
  448. {
  449. /* ASC:GCRE to 1 */
  450. mgaReadBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x18),tmpByte);
  451. if (mode)
  452. tmpByte |= 0x80;
  453. else
  454. tmpByte &= 0x7f;
  455. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x18),tmpByte);
  456. /* GCR:BLK to 0100b */
  457. mgaReadBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x28),tmpByte);
  458. if (mode)
  459. tmpByte &= 0x07;
  460. else
  461. tmpByte &= 0x0f;
  462. tmpByte |= 0x40;
  463. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x28),tmpByte);
  464. /* TEST:GT to 01 */
  465. mgaReadBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x1c),tmpByte);
  466. if (mode)
  467. tmpByte |= 0x80;
  468. else
  469. tmpByte &= 0x7f;
  470. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x1c),tmpByte);
  471. /*---*/
  472. mgaReadBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x18),tmpByte);
  473. tmpByte &= 0x7f;
  474. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x18),tmpByte);
  475. mgaReadBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x28),tmpByte);
  476. tmpByte &= 0x0f;
  477. mgaWriteBYTE(*(pMgaBaseAddr+RAMDAC_OFFSET+0x28),tmpByte);
  478. }
  479. }
  480. #endif