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.

706 lines
20 KiB

  1. //***************************************************************************
  2. // Analog Copy protection Processor process
  3. //
  4. //***************************************************************************
  5. #include "common.h"
  6. #include "regs.h"
  7. #include "ccpgd.h"
  8. //--- 97.09.15 K.Chujo
  9. //=================================================//
  10. // Burst Inverse line data( Color stripe off ) //
  11. //=================================================//
  12. ULONG CPGD_BSTLNOFF_SIZE = 0x1A;
  13. WORD CPGD_BSTLNOFF_DATA[] = {
  14. 0x0000, 0x0000, 0x0000, 0x0000,
  15. 0x0000, 0x0000, 0x0000, 0x0000,
  16. 0x0000, 0x0000, 0x0000, 0x0000,
  17. 0x0000, 0x0000, 0x0000, 0x0000,
  18. 0x0000, 0x0000, 0x0000, 0x0000,
  19. 0x0000, 0x0000, 0x0000, 0x0000,
  20. 0x0000, 0x0000
  21. };
  22. //=================================================//
  23. // Burst Inverse line data( Color stripe 2 line) //
  24. //=================================================//
  25. ULONG CPGD_BSTLN2_SIZE = 0x1A;
  26. WORD CPGD_BSTLN2_DATA[] = {
  27. 0x001D, 0x002E, 0x003F, 0x0050,
  28. 0x0061, 0x0072, 0x0083, 0x0094,
  29. 0x00A5, 0x00B6, 0x00C7, 0x00D8,
  30. 0x00E9, 0x012C, 0x013D, 0x014E,
  31. 0x015F, 0x0170, 0x0181, 0x0192,
  32. 0x01A3, 0x01B4, 0x01C5, 0x01D6,
  33. 0x01E7, 0x01F8
  34. };
  35. //=================================================//
  36. // Burst Inverse line data( Color stripe 4 line) //
  37. //=================================================//
  38. ULONG CPGD_BSTLN4_SIZE = 0x1A;
  39. WORD CPGD_BSTLN4_DATA[] = {
  40. 0x0017, 0x002C, 0x0041, 0x0056,
  41. 0x006B, 0x0080, 0x0095, 0x00AA,
  42. 0x00BF, 0x00D4, 0x00E9, 0x0000,
  43. 0x0000, 0x0128, 0x013D, 0x0152,
  44. 0x0167, 0x017C, 0x0191, 0x01A6,
  45. 0x01BB, 0x01D0, 0x01E5, 0x01FA,
  46. 0x0000, 0x0000
  47. };
  48. //=================================================//
  49. // AGC data (for Y of S input) //
  50. //=================================================//
  51. WORD CPGD_AGC_Y_TBL[] = {
  52. 0x03E7, 0x03E2, 0x03DE, 0x03D9, 0x03D5, 0x03D0, 0x03CC, 0x03C7,
  53. 0x03C3, 0x03BE, 0x03BA, 0x03B5, 0x03B1, 0x03AC, 0x03A8, 0x03A3,
  54. 0x039E, 0x039A, 0x0395, 0x0391, 0x038C, 0x0388, 0x0383, 0x037F,
  55. 0x037A, 0x0376, 0x0371, 0x036D, 0x0368, 0x0363, 0x035F, 0x035A,
  56. 0x0356, 0x0351, 0x034D, 0x0348, 0x0344, 0x033F, 0x033B, 0x0336,
  57. 0x0332, 0x032D, 0x0329, 0x0324, 0x031F, 0x031B, 0x0316, 0x0312,
  58. 0x030D, 0x0309, 0x0304, 0x0300, 0x02FB, 0x02F7, 0x02F2, 0x02EE,
  59. 0x02E9, 0x02E4, 0x02E0, 0x02DB, 0x02D7, 0x02D2, 0x02CE, 0x02C9,
  60. 0x02C5, 0x02C0, 0x02BC, 0x02B7, 0x02B3, 0x02AE, 0x02AA, 0x02A5,
  61. 0x02A0, 0x029C, 0x0297, 0x0293, 0x028E, 0x028A, 0x0285, 0x0281,
  62. 0x027C, 0x0278, 0x0273, 0x026F, 0x026A, 0x0265, 0x0261, 0x025C,
  63. 0x0258, 0x0253, 0x024F, 0x024A, 0x0246, 0x0241, 0x023D, 0x0238,
  64. 0x0234, 0x022F, 0x022B, 0x0226, 0x0221, 0x021D, 0x0218, 0x0214,
  65. 0x020F, 0x020B, 0x0206, 0x0202, 0x01FD, 0x01F9, 0x01F4, 0x01F0,
  66. 0x01EB, 0x01E6, 0x01E2, 0x01DD, 0x01D9, 0x01D4, 0x01D0, 0x01CB,
  67. 0x01C7, 0x01C2, 0x01BE, 0x01B9, 0x01B5, 0x01B0, 0x01AC, 0x01A7,
  68. 0x01A2, 0x019E, 0x0199, 0x0195, 0x0190, 0x018C, 0x0187, 0x0183,
  69. 0x017E, 0x017A, 0x0175, 0x0171, 0x016C, 0x0167, 0x0163, 0x015E,
  70. 0x015A, 0x0155, 0x0151, 0x014C, 0x0148, 0x0143, 0x013F, 0x013A,
  71. 0x0136, 0x0131, 0x012D, 0x0128
  72. };
  73. //=================================================//
  74. // AGC data (for Composit input) //
  75. //=================================================//
  76. WORD CPGD_AGC_C_TBL[] = {
  77. 0x0382, 0x037E, 0x037A, 0x0375, 0x0371, 0x036D, 0x0369, 0x0364,
  78. 0x0360, 0x035C, 0x0358, 0x0353, 0x034F, 0x034B, 0x0347, 0x0342,
  79. 0x033E, 0x033A, 0x0336, 0x0331, 0x032D, 0x0329, 0x0325, 0x0320,
  80. 0x031C, 0x0318, 0x0314, 0x030F, 0x030B, 0x0307, 0x0303, 0x02FE,
  81. 0x02FA, 0x02F6, 0x02F2, 0x02ED, 0x02E9, 0x02E5, 0x02E1, 0x02DC,
  82. 0x02D8, 0x02D4, 0x02D0, 0x02CB, 0x02C7, 0x02C3, 0x02BF, 0x02BA,
  83. 0x02B6, 0x02B2, 0x02AE, 0x02A9, 0x02A5, 0x02A1, 0x029D, 0x0299,
  84. 0x0294, 0x0290, 0x028C, 0x0288, 0x0283, 0x027F, 0x027B, 0x0277,
  85. 0x0272, 0x026E, 0x026A, 0x0266, 0x0261, 0x025D, 0x0259, 0x0255,
  86. 0x0250, 0x024C, 0x0248, 0x0244, 0x023F, 0x023B, 0x0237, 0x0233,
  87. 0x022E, 0x022A, 0x0226, 0x0222, 0x021D, 0x0219, 0x0215, 0x0211,
  88. 0x020C, 0x0208, 0x0204, 0x0200, 0x01FB, 0x01F7, 0x01F3, 0x01EF,
  89. 0x01EA, 0x01E6, 0x01E2, 0x01DE, 0x01D9, 0x01D5, 0x01D1, 0x01CD,
  90. 0x01C9, 0x01C4, 0x01C0, 0x01BC, 0x01B8, 0x01B3, 0x01AF, 0x01AB,
  91. 0x01A7, 0x01A2, 0x019E, 0x019A, 0x0196, 0x0191, 0x018D, 0x0189,
  92. 0x0185, 0x0180, 0x017C, 0x0178, 0x0174, 0x016F, 0x016B, 0x0167,
  93. 0x0163, 0x015E, 0x015A, 0x0156, 0x0152, 0x014E, 0x0149, 0x0145,
  94. 0x0141, 0x013C, 0x0138, 0x0134, 0x0130, 0x012B, 0x0127, 0x0123,
  95. 0x011F, 0x011A, 0x0116, 0x0112, 0x010E, 0x0109, 0x0105, 0x0101,
  96. 0x00FD, 0x00F8, 0x00F4, 0x00F0
  97. };
  98. //--- End.
  99. void CGuard::init( const PDEVICE_INIT_INFO pDevInit )
  100. {
  101. ioBase = pDevInit->ioBase;
  102. //--- 97.09.15 K.Chujo
  103. ACGchip = NO_ACG;
  104. //--- End.
  105. }
  106. void CGuard::CPGD_RESET_FUNC()
  107. {
  108. WRITE_PORT_UCHAR( ioBase + CPGD_RESET, 0 );
  109. WRITE_PORT_UCHAR( ioBase + CPGD_RESET, 0x80 );
  110. VproRESET_REG = 0x80;
  111. VproVMODE_REG = 0; // ? ? ?
  112. VproAVM_REG = 0; // ? ? ?
  113. //--- 97.09.15 K.Chujo
  114. CpgdVsyncCount = 0;
  115. CGMSnCPGDvalid = FALSE;
  116. AspectFlag = 0x0000;
  117. LetterFlag = 0x0000;
  118. CgmsFlag = 0x0000;
  119. CpgdFlag = 0x0000;
  120. //--- End.
  121. }
  122. void CGuard::CPGD_VIDEO_MUTE_ON()
  123. {
  124. // debug
  125. // if ( !(VproRESET_REG & 0x80) )
  126. // Error;
  127. // debug
  128. VproRESET_REG |= 0x40;
  129. WRITE_PORT_UCHAR( ioBase + CPGD_RESET, VproRESET_REG );
  130. }
  131. void CGuard::CPGD_VIDEO_MUTE_OFF()
  132. {
  133. // debug
  134. // if ( !(VproRESET_REG & 0x80) )
  135. // Error;
  136. // debug
  137. VproRESET_REG &= 0xbf;
  138. WRITE_PORT_UCHAR( ioBase + CPGD_RESET, VproRESET_REG );
  139. }
  140. void CGuard::CPGD_INIT_NTSC()
  141. {
  142. VproVMODE_REG &= 0x7f;
  143. WRITE_PORT_UCHAR( ioBase + CPGD_VMODE, VproVMODE_REG );
  144. VproAVM_REG &= 0x5f;
  145. WRITE_PORT_UCHAR( ioBase + CPGD_AVM, VproAVM_REG );
  146. WRITE_PORT_UCHAR( ioBase + CPGD_DVEN, 0xc0 );
  147. }
  148. void CGuard::CPGD_INIT_PAL()
  149. {
  150. VproVMODE_REG |= 0x80;
  151. WRITE_PORT_UCHAR( ioBase + CPGD_VMODE, VproVMODE_REG );
  152. VproAVM_REG &= 0x5f;
  153. WRITE_PORT_UCHAR( ioBase + CPGD_AVM, VproAVM_REG );
  154. WRITE_PORT_UCHAR( ioBase + CPGD_DVEN, 0x80 );
  155. }
  156. void CGuard::CPGD_CC_ON()
  157. {
  158. // VproVMODE_REG &= 0xbf;
  159. VproVMODE_REG |= 0x40;
  160. WRITE_PORT_UCHAR( ioBase + CPGD_VMODE, VproVMODE_REG );
  161. }
  162. void CGuard::CPGD_CC_OFF()
  163. {
  164. // VproVMODE_REG |= 0x40;
  165. VproVMODE_REG &= 0xbf;
  166. WRITE_PORT_UCHAR( ioBase + CPGD_VMODE, VproVMODE_REG );
  167. }
  168. void CGuard::CPGD_SUBP_PALETTE( PUCHAR pPalData )
  169. {
  170. ULONG i;
  171. WRITE_PORT_UCHAR( ioBase + CPGD_CPSET, 0x80 );
  172. for( i = 0; i < 48; i++ )
  173. WRITE_PORT_UCHAR( ioBase + CPGD_CPSP, *pPalData++ );
  174. WRITE_PORT_UCHAR( ioBase + CPGD_CPSET, 0x40 );
  175. WRITE_PORT_UCHAR( ioBase + CPGD_CPSET, 0 );
  176. }
  177. void CGuard::CPGD_OSD_PALETTE( PUCHAR pPalData )
  178. {
  179. int i;
  180. WRITE_PORT_UCHAR( ioBase + CPGD_CPSET, 0x20 );
  181. for( i = 0; i < 48; i++ )
  182. WRITE_PORT_UCHAR( ioBase + CPGD_CPSP, *pPalData++ );
  183. WRITE_PORT_UCHAR( ioBase + CPGD_CPSET, 0x10 );
  184. WRITE_PORT_UCHAR( ioBase + CPGD_CPSET, 0 );
  185. }
  186. BOOL CGuard::CPGD_SET_AGC_CHIP( ULONG rev )
  187. {
  188. switch( rev ) {
  189. case 0x02:
  190. case 0x03:
  191. ACGchip = TC6802;
  192. DebugPrint( ( DebugLevelTrace, "TOSDVD: ACGchip: TC6802\r\n" ) );
  193. break;
  194. case 0x04:
  195. ACGchip = TC6814;
  196. DebugPrint( ( DebugLevelTrace, "TOSDVD: ACGchip: TC6814\r\n" ) );
  197. break;
  198. case 0x05:
  199. ACGchip = TC6818;
  200. DebugPrint( ( DebugLevelTrace, "TOSDVD: ACGchip: TC6818\r\n" ) );
  201. break;
  202. default :
  203. ACGchip = TC6818;
  204. DebugPrint( ( DebugLevelTrace, "TOSDVD: ACGchip: UNKNOWN, use parameter for TC6818\r\n" ) );
  205. break;
  206. }
  207. if( ACGchip == NO_ACG )
  208. return( FALSE );
  209. else
  210. return( TRUE );
  211. }
  212. void CGuard::CPGD_SET_ASPECT( ULONG aspect )
  213. {
  214. if( ACGchip==NO_ACG ) {
  215. return;
  216. }
  217. else {
  218. CPGD_SET_CGMSnCPGD( aspect, LetterFlag, CgmsFlag, CpgdFlag );
  219. }
  220. }
  221. void CGuard::CPGD_SET_LETTER( ULONG letter )
  222. {
  223. if( ACGchip==NO_ACG ) {
  224. return;
  225. }
  226. else {
  227. CPGD_SET_CGMSnCPGD( AspectFlag, letter, CgmsFlag, CpgdFlag );
  228. }
  229. }
  230. void CGuard::CPGD_SET_CGMS( ULONG cgms )
  231. {
  232. if( ACGchip==NO_ACG ) {
  233. return;
  234. }
  235. else {
  236. CPGD_SET_CGMSnCPGD( AspectFlag, LetterFlag, cgms, CpgdFlag );
  237. }
  238. }
  239. void CGuard::CPGD_SET_CPGD( ULONG cpgd )
  240. {
  241. if( ACGchip==NO_ACG ) {
  242. return;
  243. }
  244. else {
  245. CPGD_SET_CGMSnCPGD( AspectFlag, LetterFlag, CgmsFlag, cpgd );
  246. }
  247. }
  248. void CGuard::CPGD_SET_CGMSnCPGD( ULONG aspect, ULONG letter, ULONG cgms, ULONG cpgd )
  249. {
  250. if( ACGchip == NO_ACG ) {
  251. return;
  252. }
  253. else {
  254. // Clear unnecessary bits
  255. aspect &= 0x01;
  256. letter &= 0x01;
  257. cgms &= 0x03;
  258. cpgd &= 0x03;
  259. // When CpgdFlag is changed or all flags are not initialized,
  260. if( CGMSnCPGDvalid==FALSE || CpgdFlag!=cpgd) {
  261. DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSnCPGD(1)\r\n" ) );
  262. AspectFlag = aspect;
  263. LetterFlag = letter;
  264. CgmsFlag = cgms;
  265. CpgdFlag = cpgd;
  266. CPGD_SET_CGMSparameter();
  267. CPGD_SET_CPGDparameter();
  268. CGMSnCPGDvalid = TRUE;
  269. }
  270. // When one of Flags except CpgdFlag is changed,
  271. else if ( AspectFlag!=aspect || LetterFlag!=letter || CgmsFlag!=cgms ) {
  272. DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSnCPGD(2)\r\n" ) );
  273. AspectFlag = aspect;
  274. LetterFlag = letter;
  275. CgmsFlag = cgms;
  276. CPGD_SET_CGMSparameter();
  277. }
  278. // When no flags are changed,
  279. else
  280. DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSnCPGD(3)\r\n" ) );
  281. }
  282. }
  283. void CGuard::CPGD_UPDATE_AGC( void )
  284. {
  285. WORD Cval, Yval;
  286. if( ACGchip==NO_ACG ) {
  287. return;
  288. }
  289. else {
  290. if( CpgdVsyncCount == 0 ) {
  291. Cval = CPGD_AGC_C_TBL[0];
  292. Yval = CPGD_AGC_Y_TBL[0];
  293. CPGD_SET_AGC( Cval, Yval );
  294. // DebugPrint( ( DebugLevelTrace, "TOSDVD: AGC_C %x, AGC_Y %x\r\n", Cval, Yval ) );
  295. }
  296. else if( 720<=CpgdVsyncCount && CpgdVsyncCount<=875 ) {
  297. Cval = CPGD_AGC_C_TBL[CpgdVsyncCount- 720];
  298. Yval = CPGD_AGC_Y_TBL[CpgdVsyncCount- 720];
  299. CPGD_SET_AGC( Cval, Yval );
  300. // DebugPrint( ( DebugLevelTrace, "TOSDVD: AGC_C %x, AGC_Y %x\r\n", Cval, Yval ) );
  301. }
  302. else if( 1044<=CpgdVsyncCount && CpgdVsyncCount<=1199 ) {
  303. Cval = CPGD_AGC_C_TBL[1199-CpgdVsyncCount];
  304. Yval = CPGD_AGC_Y_TBL[1199-CpgdVsyncCount];
  305. CPGD_SET_AGC( Cval, Yval );
  306. // DebugPrint( ( DebugLevelTrace, "TOSDVD: AGC_C %x, AGC_Y %x\r\n", Cval, Yval ) );
  307. }
  308. CpgdVsyncCount++;
  309. if( CpgdVsyncCount>=1200 )
  310. CpgdVsyncCount = 0;
  311. }
  312. }
  313. void CGuard::CPGD_SET_CGMSparameter( void )
  314. {
  315. ULONG tmp;
  316. ULONG crc;
  317. tmp = ( 0x8000 | (AspectFlag<<13) | (LetterFlag<<12) | (CgmsFlag<<6) | (CpgdFlag<<4) );
  318. crc = CPGD_CALC_CRC( tmp ) << 2;
  319. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAL, (UCHAR)(tmp >> 8) );
  320. DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAL%x\r\n", (UCHAR)(tmp>>8) ) );
  321. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAM, (UCHAR)(tmp & 0xFF) );
  322. DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAM%x\r\n", (UCHAR)(tmp&0xFF) ) );
  323. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAH, (UCHAR)(crc & 0xFF) );
  324. DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAH%x\r\n", (crc & 0xFF) ) );
  325. }
  326. void CGuard::CPGD_SET_CPGDparameter( void )
  327. {
  328. switch( CpgdFlag ) {
  329. case 0x00 :
  330. CPGD_SET_CLR_STRIPE_OFF();
  331. CPGD_SET_CPGD_0();
  332. break;
  333. case 0x01 :
  334. CPGD_SET_CLR_STRIPE_OFF();
  335. CPGD_SET_CPGD_1();
  336. break;
  337. case 0x02 :
  338. CPGD_SET_CLR_STRIPE_2();
  339. CPGD_SET_CPGD_2();
  340. break;
  341. case 0x03 :
  342. CPGD_SET_CLR_STRIPE_4();
  343. CPGD_SET_CPGD_3();
  344. break;
  345. default :
  346. TRAP;
  347. break;
  348. }
  349. }
  350. void CGuard::CPGD_SET_CGMS_A_0( ULONG aspect, ULONG letter )
  351. {
  352. ULONG temp = 0x8000;
  353. ULONG crc;
  354. if( ACGchip==NO_ACG ) {
  355. return;
  356. }
  357. else {
  358. if( letter!=0 )
  359. temp |= 0x1000;
  360. if( aspect!=0 )
  361. temp |= 0x2000;
  362. temp |= 0xC0;
  363. crc = CPGD_CALC_CRC( temp ) << 2;
  364. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAL, (UCHAR)(temp >> 8) );
  365. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAL%x\r\n", (UCHAR)(temp>>8) ) );
  366. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAM, (UCHAR)(temp & 0xFF) );
  367. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAM%x\r\n", (UCHAR)(temp&0xFF) ) );
  368. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAH, (UCHAR)(crc & 0xFF) );
  369. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAH%x\r\n", (crc & 0xFF) ) );
  370. }
  371. }
  372. void CGuard::CPGD_SET_CGMS_A_1( ULONG aspect, ULONG letter )
  373. {
  374. ULONG temp = 0x8000;
  375. ULONG crc;
  376. if( ACGchip==NO_ACG ) {
  377. return;
  378. }
  379. else {
  380. if( letter!=0 )
  381. temp |= 0x1000;
  382. if( aspect!=0 )
  383. temp |= 0x2000;
  384. temp |= 0xD0;
  385. crc = CPGD_CALC_CRC( temp ) << 2;
  386. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAL, (UCHAR)(temp >> 8) );
  387. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAL%x\r\n", (UCHAR)(temp>>8) ) );
  388. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAM, (UCHAR)(temp & 0xFF) );
  389. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAM%x\r\n", (UCHAR)(temp&0xFF) ) );
  390. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAH, (UCHAR)(crc & 0xFF) );
  391. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSAH%x\r\n", (crc & 0xFF) ) );
  392. }
  393. }
  394. void CGuard::CPGD_SET_CGMS_A_2( ULONG aspect, ULONG letter )
  395. {
  396. ULONG temp = 0x8000;
  397. ULONG crc;
  398. if( ACGchip==NO_ACG ) {
  399. return;
  400. }
  401. else {
  402. if( letter!=0 )
  403. temp |= 0x1000;
  404. if( aspect!=0 )
  405. temp |= 0x2000;
  406. temp |= 0xE0;
  407. crc = CPGD_CALC_CRC( temp ) << 2;
  408. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAL, (UCHAR)(temp >> 8) );
  409. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSA L = %x\r\n", temp>>8 ) );
  410. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAM, (UCHAR)(temp & 0xFF) );
  411. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSA M = %x\r\n", temp & 0xFF ) );
  412. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAH, (UCHAR)(crc & 0xFF) );
  413. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSA H = %x\r\n", crc & 0xFF ) );
  414. }
  415. }
  416. void CGuard::CPGD_SET_CGMS_A_3( ULONG aspect, ULONG letter )
  417. {
  418. ULONG temp = 0x8000;
  419. ULONG crc;
  420. if( ACGchip==NO_ACG ) {
  421. return;
  422. }
  423. else {
  424. if( letter!=0 )
  425. temp |= 0x1000;
  426. if( aspect!=0 )
  427. temp |= 0x2000;
  428. temp |= 0xF0;
  429. crc = CPGD_CALC_CRC( temp ) << 2;
  430. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAL, (UCHAR)(temp >> 8) );
  431. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSA L = %x\r\n", temp>>8 ) );
  432. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAM, (UCHAR)(temp & 0xFF) );
  433. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSA M = %x\r\n", temp & 0xFF ) );
  434. WRITE_PORT_UCHAR( ioBase + CPGD_CGMSAH, (UCHAR)(crc & 0xFF) );
  435. // DebugPrint( ( DebugLevelTrace, "TOSDVD: CGMSA H = %x\r\n", crc & 0xFF ) );
  436. }
  437. }
  438. void CGuard::CPGD_SET_CLR_STRIPE_OFF( void )
  439. {
  440. // notes: *1 are unnecessary originally (if TC6802 is on board).
  441. // But I have to use TC6802 parameters when TC6814/TC6818 is on board for beta 3
  442. // because I can't get RevID ( I can't know which ACG chip is ).
  443. // These codes make safe when TC6814/TC6818 is, of cource TC6802 is, NO PROBLEM.
  444. if( ACGchip==NO_ACG ) {
  445. return;
  446. }
  447. else if( ACGchip==TC6802 ) {
  448. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 ); // *1
  449. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xFE ); // *1
  450. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x00 );
  451. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_OFF for TC6802\r\n" ) );
  452. }
  453. else if( ACGchip==TC6814 ) {
  454. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  455. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xFE );
  456. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x00 );
  457. CPGD_SET_BURST( CPGD_BSTLNOFF_DATA, CPGD_BSTLNOFF_SIZE );
  458. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_OFF for TC6814\r\n" ) );
  459. }
  460. else if( ACGchip==TC6818 ) {
  461. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  462. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0x04 );
  463. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x80 );
  464. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_OFF for TC6818\r\n" ) );
  465. }
  466. }
  467. void CGuard::CPGD_SET_CLR_STRIPE_2( void )
  468. {
  469. if( ACGchip==NO_ACG ) {
  470. return;
  471. }
  472. else if( ACGchip==TC6802 ) {
  473. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  474. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xFE );
  475. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x00 );
  476. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0x84 );
  477. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0xAA );
  478. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_2 for TC6802\r\n" ) );
  479. }
  480. else if( ACGchip==TC6814 ) {
  481. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  482. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xFE );
  483. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x00 );
  484. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0x84 );
  485. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0xAE );
  486. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_2 for TC6814\r\n" ) );
  487. }
  488. else if( ACGchip==TC6818 ) {
  489. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  490. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0x04 );
  491. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x80 );
  492. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0x84 );
  493. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0xAE );
  494. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_2 for TC6818\r\n" ) );
  495. }
  496. CPGD_SET_BURST( CPGD_BSTLN2_DATA, CPGD_BSTLN2_SIZE );
  497. }
  498. void CGuard::CPGD_SET_CLR_STRIPE_4( void )
  499. {
  500. if( ACGchip==NO_ACG ) {
  501. return;
  502. }
  503. else if( ACGchip==TC6802 ) {
  504. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  505. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xFE );
  506. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x00 );
  507. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0x84 );
  508. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0xAA );
  509. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_4 for TC6802\r\n" ) );
  510. }
  511. else if( ACGchip==TC6814 ) {
  512. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  513. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xFE );
  514. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x00 );
  515. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0x84 );
  516. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0xAE );
  517. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_4 for TC6814\r\n" ) );
  518. }
  519. else if( ACGchip==TC6818 ) {
  520. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0xB1 );
  521. WRITE_PORT_UCHAR( ioBase + CPGD_BSTINT, 0x04 );
  522. WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x80 );
  523. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0x84 );
  524. WRITE_PORT_UCHAR( ioBase + CPGD_BSTSE, 0xAE );
  525. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CLR_STRIPE_4 for TC6818\r\n" ) );
  526. }
  527. CPGD_SET_BURST( CPGD_BSTLN4_DATA, CPGD_BSTLN4_SIZE );
  528. }
  529. void CGuard::CPGD_SET_CPGD_0( void )
  530. {
  531. if( ACGchip==NO_ACG ) {
  532. return;
  533. }
  534. else {
  535. WRITE_PORT_UCHAR( ioBase + CPGD_CPG, 0x00 );
  536. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CPGD_0\r\n" ) );
  537. }
  538. }
  539. void CGuard::CPGD_SET_CPGD_1( void )
  540. {
  541. if( ACGchip==NO_ACG ) {
  542. return;
  543. }
  544. else {
  545. WRITE_PORT_UCHAR( ioBase + CPGD_CPG, 0xE8 );
  546. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CPGD_1\r\n" ) );
  547. }
  548. }
  549. void CGuard::CPGD_SET_CPGD_2( void )
  550. {
  551. if( ACGchip==NO_ACG ) {
  552. return;
  553. }
  554. else {
  555. WRITE_PORT_UCHAR( ioBase + CPGD_CPG, 0xF8 );
  556. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CPGD_2\r\n" ) );
  557. }
  558. }
  559. void CGuard::CPGD_SET_CPGD_3( void )
  560. {
  561. if( ACGchip==NO_ACG ) {
  562. return;
  563. }
  564. else {
  565. WRITE_PORT_UCHAR( ioBase + CPGD_CPG, 0xF8 );
  566. DebugPrint( ( DebugLevelTrace, "TOSDVD: SET_CPGD_3\r\n" ) );
  567. }
  568. }
  569. void CGuard::CPGD_SET_BURST( PWORD data, ULONG size )
  570. {
  571. ULONG i;
  572. WORD temp;
  573. for( i=0; i<size; i++ ) {
  574. temp = (WORD)((*(data+i)) & 0x3FF);
  575. WRITE_PORT_UCHAR( ioBase + CPGD_BSTLSL, (UCHAR)(temp & 0xFF) );
  576. // DebugPrint( ( DebugLevelTrace, "TOSDVD: BURST L %x\r\n", temp & 0xFF ) );
  577. WRITE_PORT_UCHAR( ioBase + CPGD_BSTLSH, (UCHAR)(temp >> 8) );
  578. // DebugPrint( ( DebugLevelTrace, "TOSDVD: BURST H %x\r\n", temp >> 8 ) );
  579. }
  580. }
  581. void CGuard::CPGD_SET_AGC( WORD Cval, WORD Yval )
  582. {
  583. WORD Lval;
  584. Lval = (WORD)(((Yval & 0x03) << 4) + ((Cval & 0x03) << 6));
  585. Cval >>= 2;
  586. Yval >>= 2;
  587. WRITE_PORT_UCHAR( ioBase + CPGD_CAGC, (UCHAR)Cval );
  588. WRITE_PORT_UCHAR( ioBase + CPGD_YAGC, (UCHAR)Yval );
  589. WRITE_PORT_UCHAR( ioBase + CPGD_LAGC, (UCHAR)Lval );
  590. }
  591. ULONG CGuard::CPGD_CALC_CRC( ULONG val )
  592. {
  593. ULONG crc = 0;
  594. ULONG i, j;
  595. crc = (val & 0x3FFF) << 6;
  596. i = 0x80000000;
  597. j = 0x86000000; // 100001100....00(b)
  598. do {
  599. // DebugPrint( ( DebugLevelTrace, "TOSDVD: i=%x, j=%x, crc=%x\r\n", i, j, crc ) );
  600. if( (crc & i)==0 ) {
  601. i >>= 1;
  602. j >>= 1;
  603. if( i<=0x20 )
  604. break;
  605. }
  606. else {
  607. crc ^= j;
  608. }
  609. } while( 1 );
  610. return( crc );
  611. }
  612. //void CGuard::CPGD_BURST_Y_OFF( void )
  613. //{
  614. // // always turn off Burst Y.
  615. // if( AGCchip==NO_AGC ) {
  616. // return;
  617. // }
  618. // else if( AGCchip==TC6802 || AGCchip==TC6814 ) {
  619. // WRITE_PORT_UCHAR( ioBase + CPGD_BSTONY, 0x00 );
  620. // DebugPrint( ( DebugLevelTrace, "TOSDVD: BURST_Y_OFF\r\n" ) );
  621. // }
  622. // else if( AGCchip==TC6818 ) {
  623. // // no operation, because this register is set by other functions.
  624. // }
  625. //}