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.

150 lines
3.0 KiB

  1. //***************************************************************************
  2. // Copy protect process
  3. //
  4. //***************************************************************************
  5. #include "common.h"
  6. #include "ccpp.h"
  7. void Cpp::cpp_outp( UCHAR index, UCHAR data )
  8. {
  9. WRITE_PORT_UCHAR( (PUCHAR)( ioBase + CG_INDEX ), (UCHAR)index );
  10. WRITE_PORT_UCHAR( (PUCHAR)( ioBase + CG_DATA ), data );
  11. }
  12. UCHAR Cpp::cpp_inp( UCHAR index )
  13. {
  14. WRITE_PORT_UCHAR( (PUCHAR)( ioBase + CG_INDEX ), (UCHAR)index );
  15. return READ_PORT_UCHAR( (PUCHAR)( ioBase + CG_DATA ) );
  16. }
  17. void Cpp::wait( ULONG msec )
  18. {
  19. DWORD st, et;
  20. st = GetCurrentTime_ms();
  21. for( ; ; ) {
  22. KeStallExecutionProcessor( 1 );
  23. et = GetCurrentTime_ms();
  24. if( st + msec * 10 < et )
  25. break;
  26. }
  27. }
  28. BOOLEAN Cpp::cmd_wait_loop( void )
  29. {
  30. int i;
  31. for ( i = 0; i < 100; i++ )
  32. {
  33. if ( ( cpp_inp( COM ) & 0xc0 ) != 0 )
  34. break;
  35. wait( 1 );
  36. }
  37. if ( ( cpp_inp( COM ) & 0x40 ) == 0x40 )
  38. return FALSE;
  39. else
  40. return TRUE;
  41. }
  42. BOOLEAN Cpp::decoder_challenge( PKS_DVDCOPY_CHLGKEY r1 )
  43. {
  44. int i;
  45. cpp_outp( COM, CMD_DEC_RAND );
  46. for ( i = 0; i < 10; i++ )
  47. r1->ChlgKey[i] = cpp_inp( (UCHAR)(CHGG1 + i) );
  48. r1->Reserved[0] = r1->Reserved[1] = 0;
  49. return TRUE;
  50. }
  51. BOOLEAN Cpp::drive_bus( PKS_DVDCOPY_BUSKEY fsr1 )
  52. {
  53. int i;
  54. cpp_outp( COM, CMD_NOP );
  55. for ( i = 0; i < 5; i++ )
  56. cpp_outp( (UCHAR)(RSPG1 + i), fsr1->BusKey[i] );
  57. cpp_outp( COM, CMD_DRV_AUTH );
  58. return cmd_wait_loop();
  59. }
  60. BOOLEAN Cpp::drive_challenge( PKS_DVDCOPY_CHLGKEY r2 )
  61. {
  62. int i;
  63. for ( i = 0; i < 10; i++ )
  64. cpp_outp( (UCHAR)(CHGG1 + i), r2->ChlgKey[i] );
  65. cpp_outp( COM, CMD_DEC_AUTH );
  66. return cmd_wait_loop();
  67. }
  68. BOOLEAN Cpp::decoder_bus( PKS_DVDCOPY_BUSKEY fsr2 )
  69. {
  70. int i;
  71. for ( i = 0; i < 5; i++ )
  72. fsr2->BusKey[i] = cpp_inp( (UCHAR)(RSPG1 + i) );
  73. return TRUE;
  74. }
  75. BOOLEAN Cpp::DiscKeyStart()
  76. {
  77. cpp_outp( COM, CMD_DEC_DKY );
  78. return TRUE;
  79. }
  80. BOOLEAN Cpp::DiscKeyEnd()
  81. {
  82. return cmd_wait_loop();
  83. }
  84. BOOLEAN Cpp::TitleKey( PKS_DVDCOPY_TITLEKEY tk )
  85. {
  86. int i;
  87. BOOLEAN stat;
  88. cpp_outp( ETKG1 + 0, (UCHAR)(tk->KeyFlags) );
  89. for ( i = 1; i < 6; i++ )
  90. cpp_outp( (UCHAR)(ETKG1 + i), tk->TitleKey[i-1] );
  91. cpp_outp( COM, CMD_NOP );
  92. cpp_outp( COM, CMD_DEC_DTK );
  93. stat = cmd_wait_loop();
  94. cpp_outp( COM, CMD_NOP );
  95. cpp_outp( COM, CMD_DEC_DT );
  96. return stat;
  97. }
  98. void Cpp::init( const PDEVICE_INIT_INFO pDevInit )
  99. {
  100. ioBase = pDevInit->ioBase;
  101. }
  102. BOOLEAN Cpp::reset( CPPMODE mode )
  103. {
  104. UCHAR val;
  105. // Reset TC6808AF
  106. val = READ_PORT_UCHAR( ioBase + 0x27 );
  107. val |= 0x10;
  108. WRITE_PORT_UCHAR( ioBase + 0x27, val );
  109. wait( 10 );
  110. val = READ_PORT_UCHAR( ioBase + 0x27 );
  111. val &= 0xef;
  112. WRITE_PORT_UCHAR( ioBase + 0x27, val );
  113. // _outp( (WORD)( pIO_Base + 0x27 ), _inp( (WORD)( pIO_Base + 0x27 ) ) | 0x10 );
  114. // dcg_wait( 10 );
  115. // _outp( (WORD)( pIO_Base + 0x27 ), _inp( (WORD)( pIO_Base + 0x27 ) ) & 0xef );
  116. // Set Registers
  117. cpp_outp( CNT_1, 0xe3 ); // ???????????????
  118. if ( mode == NO_GUARD )
  119. cpp_outp( CNT_2, CNT2_DEFAULT + 0x01 );
  120. else
  121. cpp_outp( CNT_2, CNT2_DEFAULT );
  122. cpp_outp( DETP_L, 0x00 );
  123. cpp_outp( DETP_M, 0x00 );
  124. return TRUE;
  125. }