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.

138 lines
2.7 KiB

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