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.

2950 lines
74 KiB

  1. /******************************************************************************\
  2. * *
  3. * CL6100.C - Hardware abstraction level library. *
  4. * *
  5. * Copyright (c) C-Cube Microsystems 1996 *
  6. * All Rights Reserved. *
  7. * *
  8. * Use of C-Cube Microsystems code is governed by terms and conditions *
  9. * stated in the accompanying licensing statement. *
  10. * *
  11. \******************************************************************************/
  12. #ifdef VTOOLSD
  13. #include <vtoolsc.h>
  14. #include "monovxd.h"
  15. #else
  16. #include "Headers.h"
  17. #pragma hdrstop
  18. #endif
  19. #include "cl6100.h"
  20. #include "fpga.h"
  21. #include "bmaster.h"
  22. #include "boardio.h"
  23. #include "misc.h"
  24. #if defined(DECODER_DVDPC) || defined(EZDVD)
  25. #include "bio_dram.h"
  26. #include "dataxfer.h"
  27. #endif
  28. #ifdef EZDVD
  29. #include "vxp.h"
  30. #endif
  31. extern PHW_DEVICE_EXTENSION pDevEx;
  32. //#ifdef EZDVD
  33. //#define INTERVAL_TIME 10
  34. //#else
  35. #define INTERVAL_TIME 30
  36. //#endif
  37. /******************************************************************************\
  38. * *
  39. * DEFINITIONS *
  40. * *
  41. \******************************************************************************/
  42. #ifdef LOBYTE
  43. #undef LOBYTE
  44. #define LOBYTE(w) ((BYTE)(w))
  45. #endif
  46. #ifdef HIBYTE
  47. #undef HIBYTE
  48. #define HIBYTE(w) ((BYTE)(((WORD)(w) >> 8) & 0xFF))
  49. #endif
  50. #ifdef MAKELONG
  51. #undef MAKELONG
  52. #define MAKELONG(a, b) ((LONG)(((WORD)(a)) | ((DWORD)((WORD)(b))) << 16))
  53. #endif
  54. // HIO 7 Bit Defines
  55. #define HIO7_SOFT_RESET 0x01
  56. #define HIO7_ENDIAN 0x02
  57. #define HIO7_RESET 0x04 // D3 Set
  58. #define HIO7_AUTOINCREMET 0x08 // D3 Set
  59. #define HIO7_CPU_HALT 0x20
  60. #define HIO7_TOSHIBA 0x40 // Toshiba Mode
  61. #define HIO7_COMPI 0x40 // Compressed Data in I mode
  62. #define HIO7_REQUEST 0x80 // D3 Set
  63. // CL6100 Commands IDs
  64. #define CID_ABORT 0x8120
  65. #define CID_DIGEST 0x0621
  66. #define CID_DUMPDATA_VCD 0x0322
  67. #define CID_DUMPDATA_DVD 0x0136
  68. #define CID_FADE 0x0223
  69. #define CID_FLUSHBUFFER 0x0124
  70. #define CID_FREEZE 0x0125
  71. #define CID_HIGHLIGHT 0x0326
  72. #define CID_HIGHLIGHT_2 0x0327
  73. #define CID_NEWAUDIOMODE 0x0027
  74. #define CID_NEWPLAYMODE 0x0028
  75. #define CID_NEWVIDEOMODE 0x0029
  76. #define CID_PAUSE 0x012A
  77. #define CID_PLAY 0x042B
  78. #define CID_ROMTODRAM 0x032C
  79. #define CID_RESET 0x802D
  80. #define CID_RESUME 0x012E
  81. #define CID_SCAN 0x032F
  82. #define CID_SCREENLOAD 0x0330
  83. #define CID_SELECTSTREAM 0x0231
  84. #define CID_SETFILL 0x0532
  85. #define CID_SETSTREAMS 0x0233
  86. #define CID_SINGLESTEP 0x0134
  87. #define CID_SLOWMOTION 0x0235
  88. #define CID_TRANSFERKEY 0x0137
  89. #ifdef UCODE_VER_2
  90. #define CID_ZOOM 0x329
  91. #define CID_REVERSEPLAY 0x33B
  92. #endif
  93. // Command Status Stage
  94. #define CMD_STATE_INITIALIZATION 0x0000
  95. #define CMD_STATE_INTERNAL_FIFO 0x0001
  96. #define CMD_STATE_PROCESSED 0x0002
  97. #define CMD_STATE_STEADY 0x0003
  98. #define CMD_STATE_DONE 0x0004
  99. #define CMD_STATE_ERROR 0x0005
  100. // Processing States
  101. #define PROC_STATE_INITIALIZATION 0x0001
  102. #define PROC_STATE_IDLE 0x0002
  103. #define PROC_STATE_PLAY 0x0004
  104. #define PROC_STATE_PAUSE 0x0008
  105. #define PROC_STATE_SCAN 0x0010
  106. #define PROC_STATE_FREEZE 0x0020
  107. #define PROC_STATE_SLOWMOTION 0x0040
  108. // CL6100 DRAM map
  109. #define DRAM_CommandID 0x000040
  110. #define DRAM_Parameter1 0x000044
  111. #define DRAM_Parameter2 0x000048
  112. #define DRAM_Parameter3 0x00004C
  113. #define DRAM_Parameter4 0x000050
  114. #define DRAM_Parameter5 0x000054
  115. #define DRAM_Parameter6 0x000058
  116. #define DRAM_StatusPtr 0x00005C
  117. #define VIDEO_MODE 0x00007C
  118. #define IC_TYPE 0x0000B0
  119. #define ERR_CONCEALMENT_LEVEL 0x0000b4
  120. #define FORCE_CODED_ASPECT_RATIO 0x0000C8
  121. #define INT_MASK 0x000200
  122. #define AUTO_FLUSH_INTERVAL 0x000204
  123. #define INT_STATUS 0x0002AC
  124. #define HLI_INT_SRC 0x0002b0
  125. #define BUFF_INT_SRC 0x0002b4
  126. #define UND_INT_SRC 0x0002b8
  127. #define AOR_INT_SRC 0x0002bc
  128. #define AEE_INT_SRC 0x0002c0
  129. #define ERR_INT_SRC 0x0002c4
  130. #define DRAM_Stream_Source 0x0001A4
  131. #define DRAM_SD_Mode 0x0001A8
  132. #define DRAM_CFifo_Level 0x000214
  133. #define DRAM_INFO 0x000068
  134. #define UCODE_MEMORY 0x00006C
  135. #define DISPLAY_ASPECT_RATIO 0x000080
  136. #define ASPECT_RATIO_MODE 0x000084
  137. #define AUDIO_ATTENUATION 0x0000F4
  138. #define AUDIO_CONFIG 0x0000E0
  139. #define AUDIO_DAC_MODE 0x0000E8
  140. #define NEW_AUDIO_CONFIG 0x000468
  141. #define MEMORY_MAP 0x00021C
  142. #define PROC_STATE 0x0002A0
  143. #define AC3_OUTPUT_MODE 0x000110
  144. #define AC3_OPERATIONAL_MODE 0x000114
  145. #define AC3_LOW_BOOST 0x000118
  146. #define AC3_HIGH_CUT 0x00011C
  147. #define AC3_PCM_SCALE_FACTOR 0x000120
  148. #define AC3_LFE_OUTPUT_ENABLE 0x000124
  149. #define AC3_VOICE_SELECT 0x000128
  150. #define BITSTREAM_TYPE 0x0001A0
  151. #define VIDEO_ENV_CHANGE 0x0001E0
  152. #define HOST_OPTIONS 0x0000AC
  153. #define UCODE_START 0x000070
  154. #define UCODE_END 0x000074
  155. #define AUDIO_OUTPUT_BUFFER_START 0x000268
  156. #define AUDIO_OUTPUT_BUFFER_END 0x00026C
  157. #define AUDIO_INPUT_BUFFER_START 0x000260
  158. #define AUDIO_INPUT_BUFFER_END 0x000264
  159. #define SUB_PICTURE_BUFFER_START 0x000238
  160. #define SUB_PICTURE_BUFFER_END 0x00023C
  161. #define VIDEO_RATE_BUFFER_START 0x000230
  162. #define VIDEO_RATE_BUFFER_END 0x000234
  163. #define OSD_BUFFER_START 0x000240
  164. #define OSD_BUFFER_END 0x000244
  165. #define MRC_PIC_STC 0x0002F4
  166. #define MRC_PIC_PTS 0x0002F0
  167. #define NEW_SUBPICTURE_PALETTE 0x000464
  168. #define HOST_SPU_SWITCH 0x000474
  169. #define SUB_PICTURE_PALETTE_START 0x000288
  170. #define SUB_PICTURE_PALETTE_END 0x00028C
  171. #define KEY_ADDRESS 0x000480
  172. #define SECTOR_LENGTH 0x000484
  173. #define CFIFO_SIZE 256
  174. #define CFIFO_THRESHOLD 240
  175. // AUDIO_DAC_MODE bitfields definitions
  176. #define AUDIO_DAC_MODE_LEFT_ON_LEFT_RIGHR_ON_RIGHT 0x00
  177. #define AUDIO_DAC_MODE_LEFT_ON_BOTH 0x10
  178. #define AUDIO_DAC_MODE_RIGHT_ON_BOTH 0x20
  179. #define AUDIO_DAC_MODE_LEFT_ON_RIGHT_RIGHT_ON_LEFT 0x30
  180. #ifdef UCODE_VER_2
  181. #define VERTICAL_DISPLAYMODE 0x1F4
  182. #endif
  183. #define HOST_OPTIONS_MASK_DISABLE_INT 0x00000100
  184. #define HOST_OPTIONS_MASK_WDM_COMP 0x00000080
  185. #define TRICK_DISPLAY_MODE ( 4 ) // Even Field - 1
  186. // Odd Field - 2
  187. // Interlaced - 3
  188. // Auto - 4
  189. // CL6100 GBUS map
  190. #define CF_read1 0x2d
  191. #define CF_intrpt 0x1c // all the CFIFO registers changed
  192. #define CF_command 0x1f
  193. #define CPU_imdt 0x34 // IMEM data register
  194. #define CPU_imadr 0x36 // IMEM read/write pointer
  195. #define CPU_index 0x3a // index register for indirect regs
  196. #define CPU_idxdt 0x3b // data port for indirect regs
  197. #define HOST_control 0x00
  198. #define DMA_adr 0x22 // DMA Indirect Index registe
  199. #define DMA_MODE 0x0f // DMA Mode Setting register
  200. #define DMA_data 0x23 // DMA Indirect Data register
  201. #define DMA_CYCLE 0x11 // DMA Cycle register to define rom cycle/size
  202. #define CPU_PC 0x9 // IMEM instruction pointer register
  203. #define CPU_DIR 0xA // instruction register
  204. #if (defined UCODE_VER_2 || /*defined DECODER_DVDPC ||*/ defined DECODER_ZIVA_3)
  205. #define AUDIO_MASTER_MODE 0xEC
  206. #else
  207. #define AUDIO_MASTER_MODE 0xF8
  208. #endif
  209. #ifdef DECODER_DVDPC
  210. //DRam Locn
  211. #define CLOCK_SELECTION 0xD0
  212. // GBus Register
  213. #define AUDXCLK 0x33 // instruction register
  214. #endif
  215. /******************************************************************************\
  216. * *
  217. * EXTERNAL VARIABLES *
  218. * *
  219. \******************************************************************************/
  220. extern DWORD gdwHWVersion;
  221. /******************************************************************************\
  222. * *
  223. * GLOBAL VARIABLES *
  224. * *
  225. \******************************************************************************/
  226. static DWORD Data_HIO0, Data_HIO1, Data_HIO2, Data_HIO3;
  227. static DWORD Address_HIO4, Address_HIO5, Address_HIO6;
  228. static DWORD MemMode_HIO7 = 0;
  229. static DWORD dwCFIFO = 0;
  230. static DWORD gdwAudioDACMode;
  231. static DWORD gdwCurrentVideoStreamNum = 0;
  232. static DWORD gdwCurrentBitstreamType = 0;
  233. static BYTE btDiskAuthStatus = 0; //0 - encrypted, 1 - fake encrypted
  234. /******************************************************************************\
  235. * *
  236. * FUNCTION PROTOTYPES *
  237. * *
  238. \******************************************************************************/
  239. void DVD_HardwareReset( void );
  240. void DVD_WriteReg( DWORD dwReg, DWORD dwData );
  241. DWORD DVD_ReadReg( DWORD dwReg );
  242. void DVD_WriteIMEM( DWORD dwAddress, DWORD dwData );
  243. DWORD DVD_ReadIMEM( DWORD dwAddress );
  244. BOOL DVD_NewCommand( DWORD CommandID ,
  245. DWORD Parameter1,
  246. DWORD Parameter2,
  247. DWORD Parameter3,
  248. DWORD Parameter4,
  249. DWORD Parameter5,
  250. DWORD Parameter6,
  251. DWORD dwIntMask,
  252. DWORD dwStatus );
  253. #define WDM_MINI
  254. #if defined(DECODER_DVDPC) || defined(EZDVD)
  255. #define TIMEOUT_DURATION 100000 // 100 milli seconds
  256. #else
  257. #define TIMEOUT_DURATION 40000 // 1600 milli seconds
  258. #endif
  259. static myTime = 0;
  260. DWORD My_GetSystemTime()
  261. {
  262. return myTime;
  263. }
  264. DWORD WAIT_Get_System_Time()
  265. {
  266. #if defined VTOOLSD // VXD
  267. return Get_System_Time();
  268. #elif defined WDM_MINI
  269. return My_GetSystemTime();
  270. #elif defined _WIN32
  271. return GetTickCount();
  272. #endif
  273. }
  274. void DelayNoYield(int nIOCycles)
  275. {
  276. int i;
  277. for (i = 0; i < nIOCycles; i++)
  278. _asm
  279. {
  280. mov dx, 080h
  281. in al, dx
  282. }
  283. }
  284. void WAIT_Time_Slice_Sleep(int nMilliSec)
  285. {
  286. #if defined VTOOLSD // VXD
  287. Time_Slice_Sleep(nMilliSec);
  288. #elif defined WDM_MINI
  289. DelayNoYield(nMilliSec);
  290. myTime += nMilliSec;
  291. #elif defined _WIN32
  292. Sleep(nMilliSec);
  293. #endif
  294. }
  295. /**************************************************************************/
  296. /********************* DVD API Implementation ********************************/
  297. /**************************************************************************/
  298. int dvd_CheckCFIFO()
  299. {
  300. //int i;
  301. static DWORD dwVErrors = 0;
  302. static DWORD dwAErrors = 0;
  303. static DWORD dwSErrors = 0;
  304. DWORD dwTmp;
  305. #define N_VID_ERRORS 0x31c
  306. #define N_AUD_ERRORS 0x320
  307. #define N_SYS_ERRORS 0x318
  308. #define N_AUD_DECODED 0x2f8
  309. #define NUM_DECODED 0x2e4
  310. dwTmp = DVD_ReadDRAM( N_VID_ERRORS );
  311. if ( dwVErrors != dwTmp )
  312. {
  313. dwVErrors = dwTmp;
  314. MonoOutStr( "<" );
  315. MonoOutULong( dwVErrors );
  316. MonoOutStr( ">" );
  317. #if 0//def DEBUG
  318. {
  319. DWORD dwAddress, dwStartAddress, dwCount, dwCnt;
  320. dwStartAddress = 0x47f30;
  321. dwCount = 0x380d0;
  322. Debug_Printf_Service( "DRAM Log Start address: %08lx, Count: %08lu\n", dwStartAddress, dwCount );
  323. for ( dwAddress = dwStartAddress, dwCnt=0; dwAddress < dwStartAddress+dwCount; )
  324. {
  325. Debug_Printf_Service( "%08lx ",DVD_ReadDRAM( dwAddress ) );
  326. dwAddress += 4; // Next 32-bit-WORD byte address in DRAM
  327. dwCnt++;
  328. if ( (dwCnt%8) == 0 )
  329. {
  330. Debug_Printf_Service( "\n" );
  331. }
  332. }
  333. Debug_Printf_Service( "\nEnd of log\n" );
  334. }
  335. #endif // DEBUG
  336. }
  337. #if 0
  338. dwTmp = DVD_ReadDRAM( N_AUD_ERRORS );
  339. // if ( dwAErrors != dwTmp )
  340. {
  341. dwAErrors = dwTmp;
  342. MonoOutStr( "(" );
  343. MonoOutULong( dwAErrors );
  344. MonoOutStr( ")" );
  345. //return 1;
  346. }
  347. dwTmp = DVD_ReadDRAM( N_SYS_ERRORS );
  348. // if ( dwSErrors != dwTmp )
  349. {
  350. dwSErrors = dwTmp;
  351. MonoOutStr( "_" );
  352. MonoOutULong( dwSErrors );
  353. MonoOutStr( "_" );
  354. //return 1;
  355. }
  356. dwTmp = DVD_ReadDRAM( NUM_DECODED );
  357. // if ( dwNumDecoded != dwTmp )
  358. {
  359. //dwNumDecoded = dwTmp;
  360. MonoOutStr( "%" );
  361. MonoOutULong( dwTmp );
  362. MonoOutStr( "%" );
  363. //return 1;
  364. }
  365. dwTmp = DVD_ReadDRAM( N_AUD_DECODED );
  366. // if ( dwSErrors != dwTmp )
  367. {
  368. // dwSErrors = dwTmp;
  369. MonoOutStr( "~" );
  370. MonoOutULong( dwTmp );
  371. MonoOutStr( "~" );
  372. //return 1;
  373. }
  374. dwTmp = DVD_ReadDRAM( HOST_OPTIONS );
  375. // if ( dwSErrors != dwTmp )
  376. {
  377. // dwSErrors = dwTmp;
  378. MonoOutStr( "@" );
  379. MonoOutULong( dwTmp );
  380. MonoOutStr( "@" );
  381. //return 1;
  382. }
  383. #endif
  384. #ifdef DEBUG //!!!!!!!!!!!!!!!!!!!
  385. #define CPU_cntl 0x39 /* multi-function register */
  386. {
  387. unsigned long /*cpu_dir,*/ cpu_pc, /*cpu_index,*/ cpu_cntl;
  388. if ( 0 )
  389. {
  390. DVD_WriteReg( CPU_index, 0x9 );
  391. cpu_pc = DVD_ReadReg( CPU_idxdt ); // read CPU_PC
  392. //MonoOutStr( " CPU_PC: " );
  393. MonoOutStr( "=>" );
  394. MonoOutULongHex( cpu_pc );
  395. cpu_cntl = DVD_ReadReg( CPU_cntl ); // save old CPU_cntl
  396. DVD_WriteReg( CPU_cntl, 0xd00000 ); // halt the cpu
  397. MonoOutStr( "->" );
  398. MonoOutULongHex( DVD_ReadIMEM( cpu_pc ) );
  399. //DVD_WriteReg( CPU_cntl, cpu_cntl ); // restore CPU_cntl
  400. DVD_WriteReg( CPU_cntl, 0x900000 ); // Run CPU.
  401. }
  402. }
  403. #endif
  404. //DVD_Isr();
  405. return 0;
  406. }
  407. static DWORD reg_CF_command;
  408. static DWORD reg_CF_intrpt;
  409. void dvd_SaveRequest()
  410. {
  411. reg_CF_command = DVD_ReadReg( CF_command );
  412. reg_CF_intrpt = DVD_ReadReg( CF_intrpt );
  413. }
  414. void dvd_RestoreRequest()
  415. {
  416. DVD_WriteReg( CF_command, reg_CF_command );
  417. DVD_WriteReg( CF_intrpt, reg_CF_intrpt );
  418. }
  419. void dvd_SetRequestEnable()
  420. {
  421. //MonoOutStr( " Req Enable " );
  422. DVD_WriteReg( CF_command, 0x03 );
  423. DVD_WriteReg( CF_intrpt, 0x0C );
  424. }
  425. void dvd_SetRequestDisable()
  426. {
  427. //MonoOutStr( " Req Disable " );
  428. DVD_WriteReg( CF_intrpt, 0x08 );
  429. }
  430. BOOL DVD_Initialize( DWORD dwBaseAddress, DWORD dwCFIFOBase )
  431. {
  432. MonoOutStr( " �� DVD_Initialize " );
  433. MonoOutHex( dwBaseAddress );
  434. MonoOutStr( " // " );
  435. MonoOutHex( dwCFIFOBase );
  436. #if defined(ENCORE)
  437. {
  438. #ifdef USE_MONOCHROMEMONITOR
  439. int i;
  440. #endif
  441. FPGA_Write( AUDIO_STROBE|DMA_NO_RESET);
  442. #ifdef USE_MONOCHROMEMONITOR
  443. for ( i = 0; i < 0x520; i++ )
  444. {
  445. // MonoOutStr("Reset in progress !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
  446. }
  447. #endif
  448. FPGA_Write( AUDIO_STROBE|DMA_NO_RESET|ZIVA_NO_RESET|CP_NO_RESET );
  449. MonoOutStr(" Reset finished ");
  450. }
  451. #endif // ENCORE
  452. Data_HIO0 = dwBaseAddress;
  453. Data_HIO1 = dwBaseAddress + 1;
  454. Data_HIO2 = dwBaseAddress + 2;
  455. Data_HIO3 = dwBaseAddress + 3;
  456. Address_HIO4 = dwBaseAddress + 4;
  457. Address_HIO5 = dwBaseAddress + 5;
  458. Address_HIO6 = dwBaseAddress + 6;
  459. MemMode_HIO7 = dwBaseAddress + 7;
  460. dwCFIFO = dwCFIFOBase;
  461. // Check board presence
  462. BRD_WriteByte( Address_HIO4, 0xA5 );
  463. if ( BRD_ReadByte(Address_HIO4) != 0xA5 )
  464. return FALSE;
  465. MonoOutStr( " Ķ " );
  466. return TRUE;
  467. }
  468. void DVD_HardwareReset( void )
  469. {
  470. BYTE HIO7;
  471. if ( !MemMode_HIO7 )
  472. return ;
  473. HIO7 = BRD_ReadByte(MemMode_HIO7);
  474. BRD_WriteByte( MemMode_HIO7, (BYTE)(HIO7|HIO7_RESET) );
  475. BRD_WriteByte( MemMode_HIO7, HIO7 );
  476. #if defined(ENCORE)
  477. FPGA_Clear( ZIVA_NO_RESET );
  478. FPGA_Set( ZIVA_NO_RESET );
  479. FPGA_Clear( DMA_NO_RESET );
  480. FPGA_Set( DMA_NO_RESET );
  481. FPGA_Clear( FPGA_STATE_MACHINE );
  482. FPGA_Set( FPGA_STATE_MACHINE );
  483. #endif // ENCORE
  484. }
  485. DWORD DVD_GetHWVersion()
  486. {
  487. MonoOutStr(" HOST_control reg: ");
  488. MonoOutULongHex( DVD_ReadReg(HOST_control) );
  489. if ( DVD_ReadReg(HOST_control) & 0x40000 )
  490. return DVD_HW_VERSION_1_0;
  491. else
  492. return DVD_HW_VERSION_1_1;
  493. }
  494. DWORD DVD_GetFWVersion()
  495. {
  496. return 0;
  497. }
  498. BOOL DVD_Play()
  499. {
  500. BOOL bStatus;
  501. DWORD dwPlaymode;
  502. MonoOutStr( " �� DVD_Play " );
  503. // Workarond to fix the playback of the VCD still image streams.
  504. if ( gdwCurrentBitstreamType == 2 && gdwCurrentVideoStreamNum > 0 )
  505. {
  506. dwPlaymode = 2;
  507. MonoOutStr( "StillStop" );
  508. }
  509. else
  510. {
  511. dwPlaymode = 1;
  512. MonoOutStr( "Normal" );
  513. }
  514. bStatus = DVD_NewCommand( CID_PLAY, dwPlaymode, 0, 0, 0, 0, 0,
  515. CL6100_INT_MASK_RDY_D, 0/*CMD_STATE_PROCESSED*/ );
  516. // Workaround for AUDIO_DAC_MODE settings
  517. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  518. if ( DVD_ReadDRAM( AC3_OUTPUT_MODE ) == 1 )
  519. {
  520. DVD_WriteDRAM( AUDIO_DAC_MODE, gdwAudioDACMode|AUDIO_DAC_MODE_RIGHT_ON_BOTH );
  521. }
  522. else
  523. {
  524. DVD_WriteDRAM( AUDIO_DAC_MODE, gdwAudioDACMode );
  525. }
  526. DVD_WriteDRAM( NEW_AUDIO_CONFIG, 1 );
  527. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  528. // End of workaround for AUDIO_DAC_MODE settings
  529. pDevEx->bTrickModeToPlay=TRUE;
  530. return bStatus;
  531. }
  532. BOOL DVD_Pause()
  533. {
  534. BOOL bStatus;
  535. MonoOutStr( " �� DVD_Pause " );
  536. #if 0 //def DEBUG
  537. Debug_Printf_Service( "DRAM<80>: %08lx, DRAM<84>: %08lx\n", DVD_ReadDRAM( 0x80 ), DVD_ReadDRAM( 0x84 ) );
  538. {
  539. DWORD dwAddress, dwStartAddress, dwCount, dwCnt;
  540. dwStartAddress = 0x47f30;
  541. dwCount = 0x380d0;
  542. Debug_Printf_Service( "DRAM Log Start address: %08lx, Count: %08lu\n", dwStartAddress, dwCount );
  543. for ( dwAddress = dwStartAddress, dwCnt=0; dwAddress < dwStartAddress+dwCount; )
  544. {
  545. Debug_Printf_Service( "%08lx ",DVD_ReadDRAM( dwAddress ) );
  546. dwAddress += 4; // Next 32-bit-WORD byte address in DRAM
  547. dwCnt++;
  548. if ( (dwCnt%8) == 0 )
  549. {
  550. Debug_Printf_Service( "\n" );
  551. }
  552. }
  553. Debug_Printf_Service( "\nEnd of log\n" );
  554. }
  555. #endif // DEBUG
  556. bStatus = DVD_NewCommand( CID_PAUSE, 1, 0, 0, 0, 0, 0,
  557. CL6100_INT_MASK_END_P, CMD_STATE_DONE );
  558. pDevEx->bTrickModeToPlay=TRUE;
  559. return bStatus;
  560. }
  561. BOOL DVD_Resume()
  562. {
  563. BOOL bStatus;
  564. MonoOutStr( " �� DVD_Resume " );
  565. bStatus = DVD_NewCommand( CID_RESUME, 1, 0, 0, 0, 0, 0,
  566. CL6100_INT_MASK_RDY_D, 0/*CMD_STATE_STEADY*/ );
  567. // Workaround for AUDIO_DAC_MODE settings
  568. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  569. if ( DVD_ReadDRAM( AC3_OUTPUT_MODE ) == 1 )
  570. {
  571. DVD_WriteDRAM( AUDIO_DAC_MODE, gdwAudioDACMode|AUDIO_DAC_MODE_RIGHT_ON_BOTH );
  572. }
  573. else
  574. {
  575. DVD_WriteDRAM( AUDIO_DAC_MODE, gdwAudioDACMode );
  576. }
  577. DVD_WriteDRAM( NEW_AUDIO_CONFIG, 1 );
  578. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  579. // End of workaround for AUDIO_DAC_MODE settings
  580. pDevEx->bTrickModeToPlay=TRUE;
  581. return bStatus;
  582. }
  583. BOOL DVD_Reset()
  584. {
  585. MonoOutStr( " �� DVD_Reset " );
  586. return DVD_NewCommand( CID_RESET, 0, 0, 0, 0, 0, 0,
  587. CL6100_INT_MASK_INIT, CMD_STATE_DONE );
  588. }
  589. BOOL DVD_Abort()
  590. {
  591. BOOL bStatus;
  592. MonoOutStr( " �� DVD_Abort " );
  593. bStatus = DVD_NewCommand( CID_ABORT, 0, 0, 0, 0, 0, 0,
  594. CL6100_INT_MASK_END_C, CMD_STATE_DONE );
  595. return bStatus;
  596. }
  597. BOOL DVD_SlowMotion( WORD wRatio )
  598. {
  599. pDevEx->bTrickModeToPlay=TRUE;
  600. MonoOutStr( " �� DVD_SlowMotion " );
  601. return DVD_NewCommand( CID_SLOWMOTION, wRatio, 1, 0, 0, 0, 0,
  602. CL6100_INT_MASK_RDY_D, 0/*CMD_STATE_STEADY*/ );
  603. }
  604. BOOL DVD_SetStreams( DWORD dwStreamType, DWORD dwStreamNum )
  605. {
  606. MonoOutStr( " �� DVD_SetStreams " );
  607. MonoOutULong( dwStreamType );
  608. MonoOutStr( " / " );
  609. MonoOutULong( dwStreamNum );
  610. MonoOutStr( "" );
  611. // Remember the video stream number to implement
  612. // Play( Still ) workaround.
  613. if ( dwStreamType == 0 ) // Video stream
  614. {
  615. gdwCurrentVideoStreamNum = dwStreamNum;
  616. }
  617. return DVD_NewCommand( CID_SELECTSTREAM, dwStreamType, dwStreamNum, 0, 0, 0, 0,
  618. 0, CMD_STATE_DONE );
  619. }
  620. BOOL DVD_SetAudioVolume( WORD wValue )
  621. {
  622. MonoOutStr( " �� DVD_SetAudioVolume: " );
  623. MonoOutInt( wValue );
  624. MonoOutStr( " Ķ " );
  625. if ( wValue > 96 )
  626. return FALSE;
  627. DVD_WriteDRAM( AUDIO_ATTENUATION, 96 - wValue );
  628. return TRUE;
  629. }
  630. BOOL DVD_SetPcmScaleFactor( WORD wValue )
  631. {
  632. MonoOutStr( " �� DVD_SetPcmScaleFactor: " );
  633. MonoOutInt( wValue );
  634. MonoOutStr( " Ķ " );
  635. if ( wValue > 128 )
  636. return FALSE;
  637. DVD_WriteDRAM( AC3_PCM_SCALE_FACTOR, wValue );
  638. return TRUE;
  639. }
  640. BOOL DVD_SetAC3OutputMode( WORD wValue )
  641. {
  642. MonoOutStr( " �� DVD_SetAC3OutputMode: " );
  643. MonoOutInt( wValue );
  644. if ( wValue > 7 )
  645. return FALSE;
  646. // Oak is using CENTER mode as a MONO.
  647. // Since on the ZiVA-DS chip center channel
  648. // redirects to the left - Creative wants ZiVA
  649. // to double it to the right channel
  650. MonoOutStr( "" );
  651. if ( wValue == 1 )
  652. {
  653. MonoOutULongHex( gdwAudioDACMode|AUDIO_DAC_MODE_LEFT_ON_BOTH );
  654. DVD_WriteDRAM( AUDIO_DAC_MODE, gdwAudioDACMode|AUDIO_DAC_MODE_RIGHT_ON_BOTH );
  655. }
  656. else
  657. {
  658. MonoOutULongHex( gdwAudioDACMode );
  659. DVD_WriteDRAM( AUDIO_DAC_MODE, gdwAudioDACMode );
  660. }
  661. DVD_WriteDRAM( NEW_AUDIO_CONFIG, 1 );
  662. DVD_WriteDRAM( AC3_OUTPUT_MODE, wValue );
  663. MonoOutStr( " Ķ " );
  664. return TRUE;
  665. }
  666. BOOL DVD_SetAC3OperationalMode( WORD wValue )
  667. {
  668. MonoOutStr( " �� DVD_SetAC3OperationalMode: " );
  669. MonoOutInt( wValue );
  670. MonoOutStr( " Ķ " );
  671. if ( wValue > 3 )
  672. return FALSE;
  673. DVD_WriteDRAM( AC3_OPERATIONAL_MODE, wValue );
  674. return TRUE;
  675. }
  676. BOOL DVD_SetAC3LfeOutputEnable( WORD wValue )
  677. {
  678. MonoOutStr( " �� DVD_SetAC3LfeOutputEnable: " );
  679. MonoOutInt( wValue );
  680. MonoOutStr( " Ķ " );
  681. if ( wValue > 1 )
  682. return FALSE;
  683. DVD_WriteDRAM( AC3_LFE_OUTPUT_ENABLE, wValue );
  684. return TRUE;
  685. }
  686. BOOL DVD_SetKaraokeMode( WORD wMode )
  687. {
  688. MonoOutStr( " �� DVD_SetKaraokeMode: " );
  689. MonoOutInt( wMode );
  690. MonoOutStr( " Ķ " );
  691. DVD_WriteDRAM( AC3_VOICE_SELECT, wMode );
  692. return TRUE;
  693. }
  694. BOOL DVD_SetAC3LowBoost( WORD wValue )
  695. {
  696. MonoOutStr( " �� DVD_SetAC3LowBoost: " );
  697. MonoOutInt( wValue );
  698. MonoOutStr( " Ķ " );
  699. if ( wValue > 128 )
  700. return FALSE;
  701. DVD_WriteDRAM( AC3_LOW_BOOST, wValue );
  702. return TRUE;
  703. }
  704. BOOL DVD_SetAC3HighCut( WORD wValue )
  705. {
  706. MonoOutStr( " �� DVD_SetAC3HighCut: " );
  707. MonoOutInt( wValue );
  708. MonoOutStr( " Ķ " );
  709. if ( wValue > 128 )
  710. return FALSE;
  711. DVD_WriteDRAM( AC3_HIGH_CUT, wValue );
  712. return TRUE;
  713. }
  714. BOOL DVD_SetIEC958On( WORD wValue )
  715. {
  716. DWORD dwAudioConfig;
  717. MonoOutStr( " �� DVD_SetIEC958On: " );
  718. MonoOutInt( wValue );
  719. MonoOutStr( " Ķ " );
  720. dwAudioConfig = DVD_ReadDRAM( AUDIO_CONFIG );
  721. if ( wValue )
  722. {
  723. dwAudioConfig |= 0x2;
  724. }
  725. else
  726. {
  727. dwAudioConfig &= ~0x2;
  728. }
  729. DVD_WriteDRAM( AUDIO_CONFIG, dwAudioConfig );
  730. DVD_WriteDRAM( NEW_AUDIO_CONFIG, 1 );
  731. return TRUE;
  732. }
  733. BOOL DVD_SetIEC958Decoded( WORD wValue )
  734. {
  735. DWORD dwAudioConfig;
  736. MonoOutStr( " �� DVD_SetIEC958Decoded: " );
  737. MonoOutInt( wValue );
  738. MonoOutStr( " Ķ " );
  739. dwAudioConfig = DVD_ReadDRAM( AUDIO_CONFIG );
  740. if ( wValue )
  741. {
  742. dwAudioConfig |= 0x1;
  743. }
  744. else
  745. {
  746. dwAudioConfig &= ~0x1;
  747. }
  748. DVD_WriteDRAM( AUDIO_CONFIG, dwAudioConfig );
  749. DVD_WriteDRAM( NEW_AUDIO_CONFIG, 1 );
  750. return TRUE;
  751. }
  752. BOOL DVD_SetPalette( DWORD * pdwPalettes )
  753. {
  754. DWORD dwStart, i;
  755. MonoOutStr( " �� DVD_SetPalette: " );
  756. // Copy palettes to DRAM
  757. dwStart = DVD_ReadDRAM( SUB_PICTURE_PALETTE_START );
  758. for ( i=0; i<16; i++ )
  759. {
  760. MonoOutULongHex( dwStart+i );
  761. MonoOutStr( ":" );
  762. MonoOutULongHex( pdwPalettes[i] );
  763. MonoOutStr( " " );
  764. DVD_WriteDRAM( dwStart+i*4, pdwPalettes[i] );
  765. }
  766. // Set semaphore
  767. DVD_WriteDRAM( NEW_SUBPICTURE_PALETTE, 1 );
  768. MonoOutStr( " Ķ " );
  769. return TRUE;
  770. }
  771. BOOL DVD_SetSubPictureMute( BOOL bMute )
  772. {
  773. MonoOutStr( " �� DVD_SetSubPictureMute: " );
  774. MonoOutInt( bMute );
  775. DVD_WriteDRAM( HOST_SPU_SWITCH, (DWORD)(!bMute) );
  776. MonoOutStr( " Ķ " );
  777. return TRUE;
  778. }
  779. BOOL DVD_SetDisplayMode( WORD wDisplay, WORD wMode )
  780. {
  781. MonoOutStr( " �� DVD_SetDisplayMode:Display: " );
  782. MonoOutULongHex( wDisplay );
  783. MonoOutStr( " Mode:" );
  784. MonoOutULongHex( wMode );
  785. if ( wMode == 0 )
  786. {
  787. MonoOutStr( " !!! changing Mode to 2 !!! " );
  788. wMode = 2;
  789. }
  790. DVD_WriteDRAM( DISPLAY_ASPECT_RATIO, wDisplay );
  791. DVD_WriteDRAM( ASPECT_RATIO_MODE, wMode );
  792. MonoOutStr( " Ķ " );
  793. return TRUE;
  794. }
  795. BOOL DVD_HighLight( DWORD dwButton, DWORD dwAction )
  796. {
  797. MonoOutStr( " �� DVD_HighLight " );
  798. MonoOutInt( dwButton );
  799. MonoOutStr( " / " );
  800. MonoOutInt( dwAction );
  801. MonoOutStr( "" );
  802. return DVD_NewCommand( CID_HIGHLIGHT, dwButton, dwAction, 0, 0, 0, 0, 0, 0 );
  803. }
  804. BOOL DVD_HighLight2( DWORD dwContrast, DWORD dwColor, DWORD dwYGeom, DWORD dwXGeom )
  805. {
  806. MonoOutStr( " �� DVD_HighLight_2 " );
  807. MonoOutULongHex( dwContrast );
  808. MonoOutStr( " / " );
  809. MonoOutULongHex( dwColor );
  810. MonoOutStr( " / " );
  811. MonoOutULongHex( dwYGeom );
  812. MonoOutStr( " / " );
  813. MonoOutULongHex( dwXGeom );
  814. MonoOutStr( "" );
  815. return DVD_NewCommand( CID_HIGHLIGHT_2, dwContrast, dwColor, dwYGeom, dwXGeom, 0, 0, 0, 0 );
  816. }
  817. BOOL DVD_Scan( DWORD dwScanMode, DWORD dwSkip )
  818. {
  819. MonoOutStr( " �� DVD_Scan " );
  820. MonoOutInt( dwScanMode );
  821. MonoOutStr( "" );
  822. MonoOutInt( dwSkip );
  823. MonoOutStr( "" );
  824. pDevEx->bTrickModeToPlay=TRUE;
  825. return DVD_NewCommand( CID_SCAN, dwScanMode, dwSkip, TRICK_DISPLAY_MODE, 0, 0, 0,
  826. CL6100_INT_MASK_RDY_D, 0/*CMD_STATE_STEADY*/ );
  827. }
  828. BOOL DVD_SingleStep()
  829. {
  830. MonoOutStr( " �� DVD_Step" );
  831. return DVD_NewCommand( CID_SINGLESTEP, TRICK_DISPLAY_MODE, 0, 0, 0, 0, 0,
  832. CL6100_INT_MASK_RDY_D, 0/*CMD_STATE_STEADY*/ );
  833. }
  834. BOOL DVD_NewPlayMode( DWORD dwBitstreamType, DWORD dwVideoMode )
  835. {
  836. MonoOutStr( " �� DVD_NewPlayMode:" );
  837. MonoOutULong( dwBitstreamType );
  838. MonoOutStr( "" );
  839. MonoOutULong( dwVideoMode );
  840. MonoOutStr( "" );
  841. // Remember the following parameter to implement
  842. // Play( Still ) workaround.
  843. gdwCurrentBitstreamType = dwBitstreamType;
  844. #if 1 // !!!! A temporary workaround to disable an AC-3 watchdog
  845. {
  846. DWORD dwDRAM_160 = DVD_ReadDRAM( 0x160 );
  847. MonoOutStr(" --dwDRAM_160=0x");
  848. MonoOutULongHex( dwDRAM_160 );
  849. MonoOutStr("--");
  850. // Test : Disable always
  851. {
  852. MonoOutStr(" !!!!!! Disabling AC-3 Watchdog, dwDRAM_160=0x");
  853. MonoOutULongHex( dwDRAM_160 | 0xC0 );
  854. MonoOutStr(" !!!!!! ");
  855. DVD_WriteDRAM( 0x160, dwDRAM_160 | 0xC0 );
  856. }
  857. }
  858. #endif // Disable watchdog
  859. DVD_WriteDRAM( BITSTREAM_TYPE, dwBitstreamType );
  860. DVD_WriteDRAM( VIDEO_ENV_CHANGE, dwVideoMode );
  861. return DVD_NewCommand( CID_NEWPLAYMODE, 0, 0, 0, 0, 0, 0,
  862. 0, CMD_STATE_DONE );
  863. }
  864. DWORD DVD_GetSTC()
  865. {
  866. static int nCount=0;
  867. ULONG vPTS;
  868. DWORD dwSTC = DVD_ReadDRAM( MRC_PIC_STC );
  869. if( ( ZivaHw_GetState() == ZIVA_STATE_PAUSE) || (pDevEx->bPlayCommandPending))
  870. {
  871. dwSTC = pDevEx->dwPrevSTC;
  872. return dwSTC;
  873. }
  874. /* if(pDevEx->fFirstSTC)
  875. {
  876. pDevEx->dwPrevSTC = dwSTC;
  877. pDevEx->fFirstSTC = FALSE;
  878. }*/
  879. if(dwSTC > pDevEx->dwPrevSTC)
  880. {
  881. if((dwSTC - pDevEx->dwPrevSTC) > 1000000000)
  882. {
  883. MonoOutStr( " veyHighSTC " );
  884. // dwSTC = pDevEx->dwPrevSTC;
  885. }
  886. if((dwSTC - pDevEx->dwPrevSTC) > 180000)
  887. {
  888. MonoOutStr("MoreThan 2Sec Jump in STC");
  889. vPTS = DVD_ReadDRAM( MRC_PIC_PTS );
  890. if(vPTS != 0)
  891. {
  892. dwSTC = vPTS;
  893. MonoOutStr( " VPTS " );
  894. }
  895. else
  896. {
  897. dwSTC = pDevEx->dwPrevSTC+20000;
  898. MonoOutStr( " Prev STC " );
  899. }
  900. }
  901. }
  902. // if((!pDevEx->bTrickModeToPlay) && (gLastCommand == CMD_PLAY))
  903. {
  904. if(dwSTC < pDevEx->dwPrevSTC)
  905. {
  906. // vPTS=ConvertStrmToPTS(pDevEx->VideoSTC);
  907. vPTS = DVD_ReadDRAM( MRC_PIC_PTS );
  908. //tmp MonoOutStr( " GetPTS " );
  909. //tmp MonoOutULong( vPTS );
  910. //tmp MonoOutStr( " GetSTC " );
  911. //tmp MonoOutULong( dwSTC );
  912. // if( (dwSTC==0)&&(vPTS!=0))
  913. /* if(dwSTC != 0)
  914. dwSTC = pDevEx->dwPrevSTC;
  915. else
  916. dwSTC = pDevEx->dwPrevSTC+20000;*/
  917. if(vPTS != 0)
  918. {
  919. dwSTC = vPTS;
  920. MonoOutStr( " VPTS " );
  921. }
  922. else
  923. {
  924. dwSTC = pDevEx->dwPrevSTC+20000;
  925. MonoOutStr( " Prev STC " );
  926. }
  927. // MonoOutStr( " Prev STC " );
  928. }
  929. }
  930. // if(pDevEx->bTrickModeToPlay)
  931. // nCount++;
  932. // if(nCount == 15)
  933. // {
  934. // pDevEx->bTrickModeToPlay = FALSE;
  935. // nCount=0;
  936. // }
  937. // if(dwSTC == 0)
  938. // {
  939. // if(pDevEx->VideoSTC != 0)
  940. // {
  941. // vPTS=ConvertStrmToPTS(pDevEx->VideoSTC);
  942. // pDevEx->dwPrevSTC= dwSTC = vPTS;
  943. // MonoOutStr( " Vid PTS " );
  944. // }
  945. // else
  946. // {
  947. // dwSTC = pDevEx->dwPrevSTC;
  948. // MonoOutStr( " VidPTS :: Prev STC " );
  949. // }
  950. // }
  951. // else
  952. pDevEx->dwPrevSTC = dwSTC;
  953. MonoOutStr( " �� DVD_GetSTC " );
  954. MonoOutULong( dwSTC );
  955. MonoOutStr( " Ķ " );
  956. return dwSTC;
  957. }
  958. BOOL DVD_ForceCodedAspectRatio( WORD wRatio )
  959. {
  960. MonoOutStr( " �� DVD_ForceCodedAspectRatio" );
  961. DVD_WriteDRAM( FORCE_CODED_ASPECT_RATIO, wRatio );
  962. MonoOutInt( wRatio );
  963. MonoOutStr( " Ķ " );
  964. return TRUE;
  965. }
  966. /**************************************************************************/
  967. /********************* CL6100 Macrocommand function ***********************/
  968. /**************************************************************************/
  969. #if 1//ndef ENCORE
  970. BOOL DVD_NewCommand( DWORD CommandID ,
  971. DWORD Parameter1,
  972. DWORD Parameter2,
  973. DWORD Parameter3,
  974. DWORD Parameter4,
  975. DWORD Parameter5,
  976. DWORD Parameter6,
  977. DWORD dwIntMask,
  978. DWORD dwStatus )
  979. {
  980. //DWORD dwTimeout = 100000;
  981. DWORD dwTimeout = 0;
  982. DWORD dwWaitStart = 0;
  983. BOOL bStatus = TRUE;
  984. //#if defined(DECODER_DVDPC) || defined(EZDVD)
  985. // DWORD dwDramValue;
  986. //#endif
  987. #ifndef DISABLE_DVD_ISR
  988. DWORD dwIntMaskOriginal;
  989. INTSOURCES IntSrc;
  990. DWORD dwIntStatus;
  991. BOOL bIntPassOpenedOriginal;
  992. #ifndef ENCORE
  993. DWORD dwDramValue;
  994. #endif
  995. #endif
  996. MonoOutStr( "NC-1 " );
  997. if ( !MemMode_HIO7 )
  998. return FALSE;
  999. #if defined (DISABLE_DVD_ISR)
  1000. // DO nothing
  1001. #else
  1002. // Prepare for interrupt checking
  1003. if ( dwIntMask )
  1004. {
  1005. // 1. Save original state of the decoder interrupt pass.
  1006. bIntPassOpenedOriginal = BRD_GetDecoderInterruptState();
  1007. // 2. Close decoder interrupt pass.
  1008. #if defined(DECODER_DVDPC) || defined(EZDVD)
  1009. dwDramValue = DVD_ReadDRAM(HOST_OPTIONS);
  1010. dwDramValue |= HOST_OPTIONS_MASK_DISABLE_INT;
  1011. DVD_WriteDRAM( HOST_OPTIONS, dwDramValue );
  1012. #else
  1013. BRD_CloseDecoderInterruptPass();
  1014. #endif
  1015. // 3. Save original interrupt mask
  1016. dwIntMaskOriginal = DVD_ReadDRAM( INT_MASK );
  1017. // 4. Clear any pending interrupts.
  1018. dwIntStatus = DVD_Isr( &IntSrc );
  1019. // 5. Set the interrupt mask we have to wait for
  1020. DVD_WriteDRAM( INT_MASK, dwIntMask );
  1021. }
  1022. #endif
  1023. MonoOutStr( "NC-6 " );
  1024. // 6. Check if Microcode is ready to accept a command.
  1025. // Ignore this for commands with no status check and intmask
  1026. MonoOutStr( "Wait for Command acceptance" );
  1027. dwWaitStart = WAIT_Get_System_Time();
  1028. while (dwTimeout < TIMEOUT_DURATION)
  1029. {
  1030. if ( DVD_ReadDRAM( DRAM_StatusPtr ) )
  1031. break;
  1032. WAIT_Time_Slice_Sleep(5);
  1033. dwTimeout = WAIT_Get_System_Time() - dwWaitStart;
  1034. if (dwTimeout > TIMEOUT_DURATION)
  1035. {
  1036. MonoOutStr( "!!! Not ready to accept a command !!!" );
  1037. bStatus = FALSE;
  1038. }
  1039. }
  1040. MonoOutStr( "NC-7 " );
  1041. // 7. Issue command to the decoder.
  1042. DVD_WriteDRAM( DRAM_CommandID, CommandID );
  1043. DVD_WriteDRAM( DRAM_Parameter1, Parameter1 );
  1044. DVD_WriteDRAM( DRAM_Parameter2, Parameter2 );
  1045. DVD_WriteDRAM( DRAM_Parameter3, Parameter3 );
  1046. DVD_WriteDRAM( DRAM_Parameter4, Parameter4 );
  1047. DVD_WriteDRAM( DRAM_Parameter5, Parameter5 );
  1048. DVD_WriteDRAM( DRAM_Parameter6, Parameter6 );
  1049. DVD_WriteDRAM( DRAM_StatusPtr, 0 );
  1050. MonoOutStr( "NC-8 " );
  1051. // 8. Wait for interrupt if requested.
  1052. #if defined (DISABLE_DVD_ISR)
  1053. // Do nothing
  1054. WAIT_Time_Slice_Sleep(100);
  1055. #else
  1056. if ( dwIntMask )
  1057. {
  1058. //dwTimeout = 100000;
  1059. dwTimeout = 0;
  1060. dwWaitStart = WAIT_Get_System_Time();
  1061. do
  1062. {
  1063. if ( (dwIntStatus = DVD_Isr( &IntSrc )) & dwIntMask )
  1064. break;
  1065. WAIT_Time_Slice_Sleep(5);
  1066. dwTimeout = WAIT_Get_System_Time() - dwWaitStart;
  1067. if (dwTimeout > TIMEOUT_DURATION)
  1068. MonoOutStr( "!!! Status not set !!!" );
  1069. } while (dwTimeout < TIMEOUT_DURATION);
  1070. // 9. Restore original mask
  1071. DVD_WriteDRAM( INT_MASK, dwIntMaskOriginal );
  1072. // 10. Restore original state for the Decoder interrupt pass.
  1073. if ( bIntPassOpenedOriginal )
  1074. {
  1075. #if defined(DECODER_DVDPC) || defined(EZDVD)
  1076. dwDramValue = DVD_ReadDRAM(HOST_OPTIONS);
  1077. dwDramValue &= (~HOST_OPTIONS_MASK_DISABLE_INT);
  1078. DVD_WriteDRAM( HOST_OPTIONS, dwDramValue );
  1079. #else
  1080. BRD_OpenDecoderInterruptPass();
  1081. #endif
  1082. }
  1083. //if ( !dwTimeout )
  1084. if (dwTimeout > TIMEOUT_DURATION)
  1085. {
  1086. MonoOutStr( " !!!! Wait for interrupt " );
  1087. MonoOutULongHex( dwIntMask );
  1088. MonoOutStr( " timeout !!!! " );
  1089. //return FALSE;
  1090. bStatus = FALSE;
  1091. }
  1092. }
  1093. #endif
  1094. MonoOutStr( "NC-11 " );
  1095. // 11. Wait for the status if requested.
  1096. if ( dwStatus )
  1097. {
  1098. dwTimeout = 0;
  1099. dwWaitStart = WAIT_Get_System_Time();
  1100. do
  1101. {
  1102. if ( DVD_ReadDRAM( DRAM_StatusPtr ) )
  1103. {
  1104. if ( DVD_ReadDRAM( DVD_ReadDRAM( DRAM_StatusPtr )) == dwStatus )
  1105. break;
  1106. }
  1107. WAIT_Time_Slice_Sleep(5);
  1108. dwTimeout = WAIT_Get_System_Time() - dwWaitStart;
  1109. } while (dwTimeout < TIMEOUT_DURATION);
  1110. if (dwTimeout > TIMEOUT_DURATION)
  1111. {
  1112. MonoOutStr( " !!!! Wait for status " );
  1113. MonoOutULongHex( dwStatus );
  1114. MonoOutStr( " timeout !!!! " );
  1115. //return FALSE;
  1116. bStatus = FALSE;
  1117. }
  1118. }
  1119. //MonoOutStr( " �� DVD_Status value: " );
  1120. MonoOutStr( " Status: " );
  1121. MonoOutInt( DVD_ReadDRAM( DVD_ReadDRAM( DRAM_StatusPtr ) ) );
  1122. return bStatus;
  1123. }
  1124. #endif
  1125. #if 0//def Encore
  1126. BOOL DVD_NewCommand( DWORD CommandID ,
  1127. DWORD Parameter1,
  1128. DWORD Parameter2,
  1129. DWORD Parameter3,
  1130. DWORD Parameter4,
  1131. DWORD Parameter5,
  1132. DWORD Parameter6,
  1133. DWORD dwIntMask,
  1134. DWORD dwStatus )
  1135. {
  1136. DWORD dwTimeout = 100000;
  1137. BOOL bIntPassOpenedOriginal;
  1138. BOOL bStatus = TRUE;
  1139. DWORD dwIntMaskOriginal;
  1140. INTSOURCES IntSrc;
  1141. DWORD dwIntStatus;
  1142. if ( !MemMode_HIO7 )
  1143. return FALSE;
  1144. // Prepare for interrupt checking
  1145. if ( dwIntMask )
  1146. {
  1147. // 1. Save original state of the decoder interrupt pass.
  1148. bIntPassOpenedOriginal = BRD_GetDecoderInterruptState();
  1149. // 2. Close decoder interrupt pass.
  1150. BRD_CloseDecoderInterruptPass();
  1151. // 3. Save original interrupt mask
  1152. dwIntMaskOriginal = DVD_ReadDRAM( INT_MASK );
  1153. // 4. Clear any pending interrupts.
  1154. dwIntStatus = DVD_Isr( &IntSrc );
  1155. // 5. Set the interrupt mask we have to wait for
  1156. DVD_WriteDRAM( INT_MASK, dwIntMask );
  1157. }
  1158. // 6. Check if Microcode is ready to accept a command.
  1159. while ( dwTimeout )
  1160. {
  1161. if ( DVD_ReadDRAM( DRAM_StatusPtr ) )
  1162. break;
  1163. if ( !(--dwTimeout) )
  1164. {
  1165. MonoOutStr( "!!! Not ready to accept a command !!!" );
  1166. bStatus = FALSE;
  1167. //return FALSE;
  1168. }
  1169. }
  1170. // 7. Issue command to the decoder.
  1171. DVD_WriteDRAM( DRAM_CommandID, CommandID );
  1172. DVD_WriteDRAM( DRAM_Parameter1, Parameter1 );
  1173. DVD_WriteDRAM( DRAM_Parameter2, Parameter2 );
  1174. DVD_WriteDRAM( DRAM_Parameter3, Parameter3 );
  1175. DVD_WriteDRAM( DRAM_Parameter4, Parameter4 );
  1176. DVD_WriteDRAM( DRAM_Parameter5, Parameter5 );
  1177. DVD_WriteDRAM( DRAM_Parameter6, Parameter6 );
  1178. DVD_WriteDRAM( DRAM_StatusPtr, 0 );
  1179. // 8. Wait for interrupt if requested.
  1180. if ( dwIntMask )
  1181. {
  1182. dwTimeout = 100000;
  1183. do
  1184. {
  1185. if ( (dwIntStatus = DVD_Isr( &IntSrc )) & dwIntMask )
  1186. break;
  1187. #if 0//def DEBUG
  1188. if ( CommandID == CID_PLAY )
  1189. {
  1190. if ( (dwTimeout%10) == 0 )
  1191. {
  1192. MonoOutStr( " " );
  1193. MonoOutInt( DVD_ReadDRAM( DVD_ReadDRAM( DRAM_StatusPtr ) ) );
  1194. }
  1195. }
  1196. #endif // DEBUG
  1197. } while ( --dwTimeout );
  1198. // 9. Restore original mask
  1199. DVD_WriteDRAM( INT_MASK, dwIntMaskOriginal );
  1200. // 10. Restore original state for the Decoder interrupt pass.
  1201. if ( bIntPassOpenedOriginal )
  1202. BRD_OpenDecoderInterruptPass();
  1203. if ( !dwTimeout )
  1204. {
  1205. MonoOutStr( " !!!! Wait for interrupt " );
  1206. MonoOutULongHex( dwIntMask );
  1207. MonoOutStr( " timeout !!!! " );
  1208. //return FALSE;
  1209. bStatus = FALSE;
  1210. }
  1211. }
  1212. // 11. Wait for the status if requested.
  1213. if ( dwStatus )
  1214. {
  1215. dwTimeout = 100000l;
  1216. do
  1217. {
  1218. if ( DVD_ReadDRAM( DRAM_StatusPtr ) )
  1219. {
  1220. if ( DVD_ReadDRAM( DVD_ReadDRAM( DRAM_StatusPtr )) == dwStatus )
  1221. break;
  1222. }
  1223. } while ( --dwTimeout );
  1224. if ( !dwTimeout )
  1225. {
  1226. MonoOutStr( " !!!! Wait for status " );
  1227. MonoOutULongHex( dwStatus );
  1228. MonoOutStr( " timeout !!!! " );
  1229. //return FALSE;
  1230. bStatus = FALSE;
  1231. }
  1232. }
  1233. //MonoOutStr( " �� DVD_Status value: " );
  1234. MonoOutStr( " Status: " );
  1235. MonoOutInt( DVD_ReadDRAM( DVD_ReadDRAM( DRAM_StatusPtr ) ) );
  1236. /*
  1237. MonoOutStr(" Microcode state: ");
  1238. MonoOutULong( DVD_ReadDRAM(PROC_STATE) );
  1239. */
  1240. MonoOutStr( " Ķ " );
  1241. return bStatus;
  1242. }
  1243. #endif
  1244. /**************************************************************************/
  1245. /**************** CL6100 Memories and Registers access functions ************/
  1246. /**************************************************************************/
  1247. void DVD_WriteDRAM( DWORD dwAddress, DWORD dwData )
  1248. {
  1249. BYTE btAddress0, btAddress1, btAddress2;
  1250. BYTE btMemMode;
  1251. BYTE btData0, btData1, btData2, btData3;
  1252. if ( !MemMode_HIO7 )
  1253. return ;
  1254. btAddress0 = LOBYTE(LOWORD(dwAddress));
  1255. btAddress1 = HIBYTE(LOWORD(dwAddress));
  1256. btAddress2 = LOBYTE(HIWORD(dwAddress));
  1257. //btAddress2 &= 0x3F; // Set XFER to DRAM write
  1258. // Set Auto increment off
  1259. //MonoOutStr( " 1" );
  1260. btMemMode = BRD_ReadByte( MemMode_HIO7 );
  1261. btMemMode &= ~HIO7_AUTOINCREMET;
  1262. //MonoOutStr( " 2" );
  1263. BRD_WriteByte( MemMode_HIO7, btMemMode );
  1264. // Write address
  1265. //MonoOutStr( " 3" );
  1266. BRD_WriteByte( Address_HIO4, btAddress0 );
  1267. //MonoOutStr( " 4" );
  1268. BRD_WriteByte( Address_HIO5, btAddress1 );
  1269. //MonoOutStr( " 5" );
  1270. BRD_WriteByte( Address_HIO6, btAddress2 );
  1271. btData0 = LOBYTE(LOWORD(dwData));
  1272. btData1 = HIBYTE(LOWORD(dwData));
  1273. btData2 = LOBYTE(HIWORD(dwData));
  1274. btData3 = HIBYTE(HIWORD(dwData));
  1275. //MonoOutStr( " 6" );
  1276. BRD_WriteByte( Data_HIO3, btData3 );
  1277. //MonoOutStr( " 7" );
  1278. BRD_WriteByte( Data_HIO2, btData2 );
  1279. //MonoOutStr( " 8" );
  1280. BRD_WriteByte( Data_HIO1, btData1 );
  1281. //MonoOutStr( " 9" );
  1282. BRD_WriteByte( Data_HIO0, btData0 );
  1283. //BRD_WriteByte( Data_HIO2, 0 ); // workaround for DVD1 chip
  1284. }
  1285. DWORD DVD_ReadDRAM ( DWORD dwAddress )
  1286. {
  1287. BYTE btAddress0, btAddress1, btAddress2;
  1288. BYTE btMemMode;
  1289. BYTE btData0, btData1, btData2, btData3;
  1290. DWORD dwData;
  1291. WORD wLow, wHigh;
  1292. if ( !MemMode_HIO7 )
  1293. return 0;
  1294. btAddress0 = LOBYTE(LOWORD(dwAddress));
  1295. btAddress1 = HIBYTE(LOWORD(dwAddress));
  1296. btAddress2 = LOBYTE(HIWORD(dwAddress));
  1297. //btAddress2 &= 0x3F; // Set XFER to DRAM write
  1298. // Set Auto increment off
  1299. //MonoOutStr( " 10" );
  1300. btMemMode = BRD_ReadByte( MemMode_HIO7 );
  1301. btMemMode &= ~HIO7_AUTOINCREMET;
  1302. //MonoOutStr( " 11" );
  1303. BRD_WriteByte( MemMode_HIO7, btMemMode );
  1304. // Write address
  1305. //MonoOutStr( " 12" );
  1306. BRD_WriteByte( Address_HIO4, btAddress0 );
  1307. //MonoOutStr( " 13" );
  1308. BRD_WriteByte( Address_HIO5, btAddress1 );
  1309. //MonoOutStr( " 14" );
  1310. BRD_WriteByte( Address_HIO6, btAddress2 );
  1311. //MonoOutStr( " 15" );
  1312. btData3 = BRD_ReadByte( Data_HIO3 );
  1313. #if defined(ENCORE)
  1314. btData3 = BRD_ReadByte( Data_HIO3 );
  1315. #endif // ENCORE
  1316. //MonoOutStr( " 16" );
  1317. btData2 = BRD_ReadByte( Data_HIO2 );
  1318. //MonoOutStr( " 17" );
  1319. btData1 = BRD_ReadByte( Data_HIO1 );
  1320. //MonoOutStr( " 18" );
  1321. btData0 = BRD_ReadByte( Data_HIO0 );
  1322. wLow = ((WORD)btData1 << 8) | ((WORD)btData0);
  1323. wHigh = ((WORD)btData3 << 8) | ((WORD)btData2);
  1324. dwData = MAKELONG(wLow, wHigh);
  1325. return dwData;
  1326. }
  1327. void DVD_WriteReg( DWORD dwReg, DWORD dwData )
  1328. {
  1329. DVD_WriteDRAM( dwReg|0x00800000, dwData );
  1330. }
  1331. DWORD DVD_ReadReg( DWORD dwReg )
  1332. {
  1333. return DVD_ReadDRAM( dwReg|0x00800000 );
  1334. }
  1335. void DVD_WriteIMEM( DWORD dwAddress, DWORD dwData )
  1336. {
  1337. DVD_WriteReg( CPU_imadr, dwAddress );
  1338. DVD_WriteReg( CPU_imdt, dwData );
  1339. }
  1340. DWORD DVD_ReadIMEM( DWORD dwAddress )
  1341. {
  1342. DVD_WriteReg( CPU_index, 0x0B );
  1343. DVD_WriteReg( CPU_idxdt, dwAddress );
  1344. DVD_WriteReg( CPU_index, 0x0E );
  1345. return DVD_ReadReg( CPU_idxdt );
  1346. }
  1347. /**************************************************************************/
  1348. /*********************** CL6100 Data Send routines ************************/
  1349. /**************************************************************************/
  1350. //#define TIME_OUT_COUNT 100000
  1351. WORD gwFifoBurst = (CFIFO_SIZE - CFIFO_THRESHOLD)/4;
  1352. DWORD DVD_Send( DWORD * dwpData, DWORD dwCount, DWORD dwTimeOutCount )
  1353. {
  1354. DWORD dwTimeout = dwTimeOutCount;
  1355. DWORD dwNextBurst;
  1356. DWORD *dwpCurData = dwpData;
  1357. DWORD dwTries = 0;
  1358. while ( dwTimeout-- )
  1359. {
  1360. if ( (BRD_ReadByte(MemMode_HIO7) & HIO7_REQUEST) )
  1361. {
  1362. //KN_MonoOut('�');
  1363. dwTries++;
  1364. continue;
  1365. }
  1366. /*
  1367. if ( dwTries )
  1368. {
  1369. MonoOutChar( ' ' );
  1370. MonoOutInt( dwTries );
  1371. dwTries = 0;
  1372. }
  1373. */
  1374. dwTimeout = dwTimeOutCount;
  1375. dwNextBurst = min( gwFifoBurst, dwCount );
  1376. _asm
  1377. {
  1378. push ESI ;save registers
  1379. push DX
  1380. push ECX
  1381. mov EDX, dwCFIFO ;set destination IO port
  1382. mov ECX, dwNextBurst ;set transfer count
  1383. mov ESI, dwpCurData ;set source address
  1384. cld
  1385. rep outsd ;transfer
  1386. pop ECX ;restore registers
  1387. pop DX
  1388. pop ESI
  1389. }
  1390. dwpCurData += dwNextBurst;
  1391. dwCount -= dwNextBurst;
  1392. if ( !dwCount )
  1393. break;
  1394. }
  1395. return dwpCurData - dwpData;
  1396. }
  1397. /**************************************************************************/
  1398. /*********************** CL6100 Load UCode routine ************************/
  1399. /**************************************************************************/
  1400. #define IMEM_START_OFFSET 0x800 // byte offset
  1401. #define IMEM_LENGTH 0xFF // in 32-bit words
  1402. #define DRAM_IMAGE_LENGTH 0x7FF // in bytes
  1403. #define GBUS_TABLE_OFFSET 0xBFC // byte offset
  1404. #if defined(TC6807AF) || defined(TC6807AF_ZIVA_CPP) || defined(AMC)
  1405. #define STREAM_SOURCE 0x0 // SD Interface
  1406. #else
  1407. #define STREAM_SOURCE 0x2 // Host Interface
  1408. #endif //TC6807AF
  1409. #ifdef BUS_MASTER
  1410. #if defined(TC6807AF) || defined(TC6807AF_ZIVA_CPP)
  1411. #define SD_MODE 0xD // For SD Interface
  1412. #elif defined(AMC)
  1413. #define SD_MODE 0x0 // For SD Interface
  1414. #else
  1415. #define SD_MODE 0x8 // For Host Interface
  1416. #endif // TC6807AF
  1417. #else // BUS_MASTER
  1418. #define SD_MODE 0x8
  1419. #endif // BUS_MASTER
  1420. //
  1421. // Static variables declaration
  1422. //
  1423. static BYTE * gpbRead; // Read pointer to the UCode buffer
  1424. /*
  1425. ** load_GetDWORD()
  1426. ** Read next 32 bit as a DWORD value and advance read pointer one
  1427. ** word forward
  1428. */
  1429. static DWORD load_GetDWORD()
  1430. {
  1431. DWORD dwResult = gpbRead[0] +
  1432. (gpbRead[1] << 8) +
  1433. (gpbRead[2] << 16) +
  1434. (gpbRead[3] << 24);
  1435. gpbRead += 4;
  1436. return dwResult;
  1437. }
  1438. /*
  1439. ** load_GetDWORDSwap()
  1440. ** Read next 32 bit as a swapped DWORD value and advance read pointer one
  1441. ** word forward
  1442. */
  1443. static DWORD load_GetDWORDSwap()
  1444. {
  1445. DWORD dwResult = gpbRead[3] +
  1446. (gpbRead[2] << 8) +
  1447. (gpbRead[1] << 16) +
  1448. (gpbRead[0] << 24);
  1449. gpbRead += 4;
  1450. return dwResult;
  1451. }
  1452. /*
  1453. ** load_GetDWORDSwapBackward()
  1454. ** Read next 32 bit as a swapped DWORD value and advance read pointer one
  1455. ** word backwards
  1456. */
  1457. static DWORD load_GetDWORDSwapBackward()
  1458. {
  1459. DWORD dwResult = gpbRead[3] +
  1460. (gpbRead[2] << 8) +
  1461. (gpbRead[1] << 16) +
  1462. (gpbRead[0] << 24);
  1463. gpbRead -= 4;
  1464. return dwResult;
  1465. }
  1466. //
  1467. // DVD_LoadUCode
  1468. //
  1469. /////////////////////////////////////////////////////////////////////
  1470. BOOL DVD_LoadUCode( BYTE * pbUCode )
  1471. {
  1472. DWORD dwSectionLength; // Section length in bytes
  1473. DWORD dwSectionAddress; // Start address in DRAM (WORD address)
  1474. DWORD dwSectionChecksum; // Section check sum value
  1475. DWORD dwCnt; // Counter of the bytes written to the DVD chip
  1476. DWORD dwAddress; // Current DRAM address (byte address)
  1477. BYTE * pbUCodeStart; // Sarting point of the UCode in the buffer (file)
  1478. BYTE * pbFinalGBUSStart; // Sarting point of the final GBUS writes.
  1479. DWORD dwTimeOut; // Waiting Idle state time out
  1480. #ifndef ENCORE
  1481. DWORD dwDramParam;
  1482. #endif
  1483. DWORD dwDramValue;
  1484. MonoOutStr( " �� DVD_LoadUCode " );
  1485. MonoOutStr( " ~@ Oct 22 ~@ " );
  1486. gpbRead = pbUCode; // Set pointer to the beginning of the buffer
  1487. // A. Skip the initial header of the file (12 bytes)
  1488. gpbRead += 12;
  1489. // B. Skip data_type, section flags and unused (4 bytes)
  1490. gpbRead += 4;
  1491. dwSectionLength = load_GetDWORD();
  1492. MonoOutULongHex( dwSectionLength );
  1493. MonoOutStr( " " );
  1494. dwSectionAddress = load_GetDWORD();
  1495. MonoOutULongHex( dwSectionAddress );
  1496. MonoOutStr( " " );
  1497. dwSectionChecksum = load_GetDWORD();
  1498. MonoOutULongHex( dwSectionChecksum );
  1499. MonoOutStr( " " );
  1500. // Remember the start of the UCode.
  1501. pbUCodeStart = gpbRead;
  1502. // C.1. Configuration-specific GBUS writes
  1503. // Reset DVD1 chip
  1504. DVD_HardwareReset();
  1505. // Issue "Host Run" command
  1506. DVD_WriteReg( HOST_control, 0x1000 );
  1507. // C.1.1 Set up the DRAM.
  1508. DVD_WriteReg( DMA_adr, DMA_MODE );
  1509. #ifdef DECODER_ZIVA_3
  1510. DVD_WriteReg( DMA_adr, 0x12 );
  1511. DVD_WriteReg( DMA_data, 0x24800);
  1512. DVD_WriteReg( DMA_adr, 0x10000 );
  1513. #elif DECODER_DVDPC
  1514. DVD_WriteReg( DMA_adr, 0x12 );
  1515. DVD_WriteReg( DMA_data, 0x020800);
  1516. DVD_WriteReg( DMA_adr, 0x10000 ); // Auto Init SDRAM
  1517. #elif EZDVD
  1518. //DVD_WriteReg( DMA_data, 0x4EC ); // 16 Mbits DRAM
  1519. DVD_WriteReg( DMA_data, 0x14EC ); // 20 Mbits DRAM
  1520. #else
  1521. #ifdef MEMCFG_16MB // for Ziva 2.0 16MBit version
  1522. MonoOutStr( "################## 16 MB version of Ziva.Vxd ###################" );
  1523. DVD_WriteReg( DMA_data, 0x4EC ); // 16 Mbits DRAM
  1524. #else
  1525. DVD_WriteReg( DMA_data, 0x14EC ); // 20 Mbits DRAM
  1526. #endif // MEMCFG_16MB
  1527. #endif
  1528. // C.1.2 Set up the ROM and SRAM (if any).
  1529. DVD_WriteReg( DMA_adr, DMA_CYCLE );
  1530. DVD_WriteReg( DMA_data, 0 ); // No ROM or SRAM present
  1531. // C.2. Initial GBUS writes:
  1532. gpbRead = pbUCodeStart + GBUS_TABLE_OFFSET;
  1533. for ( dwCnt = load_GetDWORDSwapBackward(); dwCnt; dwCnt-- )
  1534. {
  1535. dwAddress = load_GetDWORDSwapBackward();
  1536. DVD_WriteReg( dwAddress, load_GetDWORDSwapBackward() );
  1537. }
  1538. // Remember the start of the Final GBUS writes table.
  1539. pbFinalGBUSStart = gpbRead;
  1540. // C.3. Copy bootstrap code into IMEM
  1541. gpbRead = pbUCodeStart + IMEM_START_OFFSET;
  1542. MonoOutStr( "Load IMEM: " );
  1543. for ( dwAddress=0; dwAddress < IMEM_LENGTH; dwAddress ++ )
  1544. {
  1545. DWORD dwValue = load_GetDWORDSwap();
  1546. DVD_WriteIMEM( dwAddress, dwValue );
  1547. #ifdef USE_MONOCHROMEMONITOR
  1548. if ( dwAddress < 2 )
  1549. {
  1550. MonoOutULong( dwAddress );
  1551. MonoOutStr( ":" );
  1552. MonoOutULongHex( dwValue );
  1553. MonoOutStr( "-" );
  1554. MonoOutULongHex( DVD_ReadIMEM( dwAddress*2 ) );
  1555. MonoOutStr( " " );
  1556. }
  1557. #endif
  1558. }
  1559. // C.4. Copy default DVD1 configuration data into DRAM
  1560. gpbRead = pbUCodeStart;
  1561. MonoOutStr( "Load DRAM:" );
  1562. for ( dwAddress=0; dwAddress < dwSectionLength/*DRAM_IMAGE_LENGTH*/; )
  1563. {
  1564. DVD_WriteDRAM( dwAddress, load_GetDWORDSwap() );
  1565. dwAddress += 4; // Next 32-bit-WORD byte address in DRAM
  1566. }
  1567. // Check DRAM 12345
  1568. MonoOutStr( " Check DRAM 12345:" );
  1569. MonoOutULongHex( DVD_ReadDRAM( 0x128 ) );
  1570. MonoOutStr( " " );
  1571. MonoOutStr( " DISPLAY_ASPECT_RATIO:" );
  1572. MonoOutULongHex( DVD_ReadDRAM( DISPLAY_ASPECT_RATIO ) );
  1573. MonoOutStr( " ASPECT_RATIO_MODE:" );
  1574. MonoOutULongHex( DVD_ReadDRAM( ASPECT_RATIO_MODE ) );
  1575. MonoOutStr( " " );
  1576. DVD_WriteDRAM( ASPECT_RATIO_MODE, 2 ); // force letterbox output !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1577. // C.5. Update configuration data in DRAM for the specific system.
  1578. // Dirty patch:
  1579. // Use SD interface for designs with TC6807 and
  1580. // HOST interface with DVD 1.1 chips.
  1581. #if defined(DECODER_DVDPC)
  1582. dwDramParam = BRD_GetDramParam(DRAM_Stream_Source);
  1583. if (dwDramParam != 0xFFFFFFFF)
  1584. DVD_WriteDRAM( DRAM_Stream_Source, dwDramParam);
  1585. dwDramParam = BRD_GetDramParam(DRAM_SD_Mode);
  1586. if (dwDramParam != 0xFFFFFFFF)
  1587. DVD_WriteDRAM( DRAM_SD_Mode, dwDramParam);
  1588. dwDramParam = BRD_GetDramParam(AUDIO_CLOCK_SELECTION);
  1589. if (dwDramParam != 0xFFFFFFFF)
  1590. DVD_WriteDRAM( AUDIO_CLOCK_SELECTION, dwDramParam);
  1591. dwDramParam = BRD_GetDramParam(AUDIO_DAC_MODE);
  1592. if (dwDramParam != 0xFFFFFFFF)
  1593. DVD_WriteDRAM( AUDIO_DAC_MODE, dwDramParam);
  1594. #elif defined(EZDVD)
  1595. dwDramParam = BRD_GetDramParam(DRAM_Stream_Source);
  1596. if (dwDramParam != 0xFFFFFFFF)
  1597. DVD_WriteDRAM( DRAM_Stream_Source, dwDramParam);
  1598. dwDramParam = BRD_GetDramParam(DRAM_SD_Mode);
  1599. if (dwDramParam != 0xFFFFFFFF)
  1600. DVD_WriteDRAM( DRAM_SD_Mode, dwDramParam);
  1601. dwDramParam = BRD_GetDramParam(AUDIO_CLOCK_SELECTION);
  1602. if (dwDramParam != 0xFFFFFFFF)
  1603. {
  1604. DWORD dwDramValue;
  1605. dwDramValue=DVD_ReadDRAM (AUDIO_CLOCK_SELECTION);
  1606. dwDramValue &= (~AUDIO_DAXDK_MASK);
  1607. dwDramValue |= (dwDramParam<<1);
  1608. DVD_WriteDRAM(AUDIO_CLOCK_SELECTION,dwDramValue);
  1609. }
  1610. dwDramParam = BRD_GetDramParam(AUDIO_DAC_MODE);
  1611. if (dwDramParam != 0xFFFFFFFF)
  1612. DVD_WriteDRAM( AUDIO_DAC_MODE, dwDramParam);
  1613. #else
  1614. if ( DVD_GetHWVersion() == DVD_HW_VERSION_1_0 )
  1615. {
  1616. // DVD 1.0 and, most likely, Toshiba
  1617. MonoOutStr(" <<<<<<< DVD 1.0 >>>>>>>");
  1618. DVD_WriteDRAM( DRAM_Stream_Source, 0 /*STREAM_SOURCE*/ );
  1619. DVD_WriteDRAM( DRAM_SD_Mode, 0xD /*SD_MODE*/ );
  1620. }
  1621. else
  1622. {
  1623. // DVD 1.1
  1624. MonoOutStr(" <<<<<<< DVD 1.1 >>>>>>>");
  1625. DVD_WriteDRAM( DRAM_Stream_Source, 2 /*STREAM_SOURCE*/ );
  1626. DVD_WriteDRAM( DRAM_SD_Mode, 0x8 /*SD_MODE*/ );
  1627. }
  1628. #endif
  1629. // DVD_WriteDRAM( DRAM_SD_Mode, 5 );
  1630. // DVD_WriteDRAM( DRAM_SD_Mode, SD_MODE );
  1631. /*
  1632. DVD_WriteDRAM( DRAM_Stream_Source, STREAM_SOURCE );
  1633. DVD_WriteDRAM( DRAM_SD_Mode, SD_MODE );
  1634. */
  1635. DVD_WriteDRAM( DRAM_CFifo_Level, CFIFO_THRESHOLD );
  1636. DVD_WriteDRAM( DRAM_INFO, 1 ); // one 4Mbits DRAM increment
  1637. DVD_WriteDRAM( UCODE_MEMORY, 0 ); // Microcode is in DRAM
  1638. #if (defined DECODER_DVDPC || defined DECODER_ZIVA_3)
  1639. DVD_WriteDRAM( MEMORY_MAP, 1 ); // for 16 Mbits DRAM
  1640. #else
  1641. #ifdef MEMCFG_16MB
  1642. MonoOutStr( "################## 16 MB version of Ziva.Vxd ###################" );
  1643. DVD_WriteDRAM( DRAM_INFO, 0 ); //AuraVision, I am not sure zero 4Mbits DRAM increment
  1644. DVD_WriteDRAM( MEMORY_MAP, 1 ); // for 16 Mbits DRAM
  1645. #else
  1646. DVD_WriteDRAM( DRAM_INFO, 1 ); // AuraVision, I am not sure one 4Mbits DRAM increment
  1647. DVD_WriteDRAM( MEMORY_MAP, 3 ); // for 20 Mbits DRAM
  1648. #endif
  1649. #endif
  1650. //DVD_WriteDRAM( AC3_OUTPUT_MODE, 7 ); // 6 channels audio !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1651. DVD_WriteDRAM( AC3_OUTPUT_MODE, 0 ); // 2 channels audio !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1652. DVD_WriteDRAM( IC_TYPE, 1 ); // ZiVA-DS decoder
  1653. DVD_WriteDRAM( ERR_CONCEALMENT_LEVEL, 0 ); // Do not show bad picture
  1654. #if defined(ENCORE)
  1655. DVD_WriteDRAM( VIDEO_MODE, 2 );
  1656. #elif defined(EZDVD)
  1657. DVD_WriteDRAM( AC3_OUTPUT_MODE, 0 ); // 2 channels audio !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  1658. DVD_WriteDRAM( VIDEO_MODE, 2 ); // 601
  1659. #else
  1660. DVD_WriteDRAM( VIDEO_MODE, 3 );
  1661. #endif
  1662. DVD_WriteReg( CPU_index, CPU_DIR ); // ????????? Set instraction register.
  1663. DVD_WriteReg( CPU_idxdt, 0xC000 );
  1664. DVD_WriteReg( CPU_index, CPU_PC ); // ????????? Set program counter.
  1665. DVD_WriteReg( CPU_idxdt, 0x0 );
  1666. // C.6. Perform final GBUS writes.
  1667. gpbRead = pbFinalGBUSStart;
  1668. #ifdef USE_MONOCHROMEMONITOR
  1669. MonoOutStr( "Number of final GBUS writes:" );
  1670. MonoOutULongHex( load_GetDWORDSwap() );
  1671. MonoOutStr( " " );
  1672. gpbRead -= 4;
  1673. #endif
  1674. for ( dwCnt = load_GetDWORDSwapBackward(); dwCnt; dwCnt-- )
  1675. {
  1676. dwAddress = load_GetDWORDSwapBackward();
  1677. DVD_WriteReg( dwAddress, load_GetDWORDSwapBackward() );
  1678. }
  1679. //DVD_WriteReg( CPU_cntl, 0x900000 ); // Run CPU.
  1680. // D. Wait for the DVD1 to enter the Idle state
  1681. dwTimeOut = 100000L;
  1682. while ( --dwTimeOut )
  1683. {
  1684. if ( DVD_ReadDRAM( PROC_STATE ) == 2 )
  1685. break;
  1686. }
  1687. // Clear all interrupts just in case.
  1688. DVD_WriteDRAM( INT_MASK, 0/*CL6100_INT_MASK_VSYNC*/ );
  1689. // From ucode Build 332
  1690. //DVD_WriteDRAM( VIDEO_MODE, 2 );
  1691. DVD_WriteDRAM( AUTO_FLUSH_INTERVAL, 4 );
  1692. #if defined(DECODER_DVDPC) || defined(DECODER_ZIVA_3)
  1693. DVD_WriteDRAM( AUTO_FLUSH_INTERVAL, 15 );
  1694. dwDramParam = DVD_ReadReg(AUDXCLK);
  1695. dwDramParam &= ~(0x80);
  1696. DVD_WriteReg( AUDXCLK, dwDramParam);
  1697. DVD_WriteDRAM(CLOCK_SELECTION, 5);
  1698. #endif
  1699. #if (defined UCODE_VER_2 /*|| defined DECODER_DVDPC */|| defined DECODER_ZIVA_3)
  1700. dwDramValue=DVD_ReadDRAM (AUDIO_MASTER_MODE);
  1701. dwDramValue &= (~AUDIO_MODE_MASK);
  1702. #ifdef ZIVA_AUDIO_MASTER
  1703. dwDramValue |= (AUDIO_MODE_MASTER);
  1704. #else
  1705. dwDramValue |= (AUDIO_MODE_SLAVE);
  1706. #endif
  1707. DVD_WriteDRAM(AUDIO_MASTER_MODE,dwDramValue);
  1708. #endif
  1709. // Test Overwrite pAud master mode setting for EZDVD
  1710. #ifdef EZDVD
  1711. dwDramValue=DVD_ReadDRAM (AUDIO_MASTER_MODE);
  1712. dwDramValue &= (~AUDIO_MODE_MASK);
  1713. #ifdef ZIVA_AUDIO_MASTER
  1714. dwDramValue |= (AUDIO_MODE_MASTER);
  1715. #else
  1716. dwDramValue |= (AUDIO_MODE_SLAVE);
  1717. #endif
  1718. DVD_WriteDRAM(AUDIO_MASTER_MODE,dwDramValue);
  1719. #endif
  1720. DVD_WriteDRAM( AUDIO_CONFIG, 6 );
  1721. DVD_WriteDRAM( NEW_AUDIO_CONFIG, 1 );
  1722. gdwAudioDACMode = DVD_ReadDRAM( AUDIO_DAC_MODE ); // Save AUDIO_DAC_MODE value
  1723. // Set WDM compatibility
  1724. // Currently this is supported for ZivaPC Ucode
  1725. // Ignored in other Ucodes
  1726. dwDramValue = DVD_ReadDRAM(HOST_OPTIONS);
  1727. dwDramValue |= HOST_OPTIONS_MASK_WDM_COMP; // Set WDM compatibility
  1728. DVD_WriteDRAM( HOST_OPTIONS, dwDramValue );
  1729. if ( dwTimeOut )
  1730. {
  1731. MonoOutStr( " Load UCode completed " );
  1732. }
  1733. else
  1734. {
  1735. MonoOutStr( " Load UCode failed:" );
  1736. MonoOutULongHex( DVD_ReadDRAM( PROC_STATE ) );
  1737. MonoOutStr( " Ķ" );
  1738. return FALSE;
  1739. }
  1740. #if defined(ENCORE)
  1741. {
  1742. DWORD dwTimeout = 8000;
  1743. while(dwTimeout--);
  1744. // FPGA_Write(0x83);
  1745. FPGA_Write(AUDIO_STROBE|CP_NO_RESET|ZIVA_NO_RESET);
  1746. // FPGA_Write(0x8B);
  1747. FPGA_Write(AUDIO_STROBE|DMA_NO_RESET|CP_NO_RESET|ZIVA_NO_RESET);
  1748. dwTimeout = 8000;
  1749. while(dwTimeout--);
  1750. // FPGA_Write(0xBB);
  1751. FPGA_Write(AUDIO_STROBE|FPGA_STATE_MACHINE|BGNI_ON|DMA_NO_RESET|CP_NO_RESET|ZIVA_NO_RESET);
  1752. BRD_CloseDecoderInterruptPass();
  1753. // IHW_SetRegister(9,0x50);
  1754. // IHW_SetRegister(9,0x40);
  1755. }
  1756. #endif // ENCORE
  1757. MonoOutStr( " Ķ" );
  1758. return TRUE;
  1759. }
  1760. /**************************************************************************/
  1761. /*********************** CL6100 Authentication API ************************/
  1762. /**************************************************************************/
  1763. //--------------------------------------------------------------------------
  1764. // STATIC FUNCTIONS DECLARATION
  1765. //--------------------------------------------------------------------------
  1766. BOOL dvd_GetChallengeData( BYTE * CHG );
  1767. BOOL dvd_SendChallengeData( BYTE * CHG );
  1768. BOOL dvd_GetResponseData( BYTE * RSP );
  1769. BOOL dvd_SendResponseData( BYTE * RSP );
  1770. BOOL dvd_SendDiskKeyData( BYTE * pBuffer );
  1771. BOOL dvd_SendTitleKeyData( BYTE * ETK );
  1772. BOOL dvd_SetDecryptionMode( BYTE * SR_FLAG );
  1773. //--------------------------------------------------------------------------
  1774. // CONSTANT AND MACROS DEFINITIONS
  1775. //--------------------------------------------------------------------------
  1776. #define RESET_AUTHENTICATION 0x0
  1777. #define GET_CHALLENGE_DATA 0x1
  1778. #define SEND_RESPONSE_DATA 0x2
  1779. #define SEND_CHALLENGE_DATA 0x3
  1780. #define GET_RESPONSE_DATA 0x4
  1781. #define SEND_DISK_KEY 0x5
  1782. #define SEND_TITLE_KEY 0x6
  1783. #define SET_DECRYPTION_MODE 0x7
  1784. #define SET_PASS_THROUGH_MODE 0x8
  1785. #define KEY_COMMAND (gdwTransferKeyAddress + 0*4)
  1786. #define KEY_STATUS (gdwTransferKeyAddress + 1*4)
  1787. #define DRIVE_CHALLENGE_0 (gdwTransferKeyAddress + 2*4)
  1788. #define DRIVE_CHALLENGE_1 (gdwTransferKeyAddress + 3*4)
  1789. #define DRIVE_CHALLENGE_2 (gdwTransferKeyAddress + 4*4)
  1790. #define DRIVE_CHALLENGE_3 (gdwTransferKeyAddress + 5*4)
  1791. #define DRIVE_CHALLENGE_4 (gdwTransferKeyAddress + 6*4)
  1792. #define DRIVE_CHALLENGE_5 (gdwTransferKeyAddress + 7*4)
  1793. #define DRIVE_CHALLENGE_6 (gdwTransferKeyAddress + 8*4)
  1794. #define DRIVE_CHALLENGE_7 (gdwTransferKeyAddress + 9*4)
  1795. #define DRIVE_CHALLENGE_8 (gdwTransferKeyAddress + 10*4)
  1796. #define DRIVE_CHALLENGE_9 (gdwTransferKeyAddress + 11*4)
  1797. #define DECODER_CHALLENGE_0 (gdwTransferKeyAddress + 12*4)
  1798. #define DECODER_CHALLENGE_1 (gdwTransferKeyAddress + 13*4)
  1799. #define DECODER_CHALLENGE_2 (gdwTransferKeyAddress + 14*4)
  1800. #define DECODER_CHALLENGE_3 (gdwTransferKeyAddress + 15*4)
  1801. #define DECODER_CHALLENGE_4 (gdwTransferKeyAddress + 16*4)
  1802. #define DECODER_CHALLENGE_5 (gdwTransferKeyAddress + 17*4)
  1803. #define DECODER_CHALLENGE_6 (gdwTransferKeyAddress + 18*4)
  1804. #define DECODER_CHALLENGE_7 (gdwTransferKeyAddress + 19*4)
  1805. #define DECODER_CHALLENGE_8 (gdwTransferKeyAddress + 20*4)
  1806. #define DECODER_CHALLENGE_9 (gdwTransferKeyAddress + 21*4)
  1807. #define DRIVE_RESULT_0 (gdwTransferKeyAddress + 22*4)
  1808. #define DRIVE_RESULT_1 (gdwTransferKeyAddress + 23*4)
  1809. #define DRIVE_RESULT_2 (gdwTransferKeyAddress + 24*4)
  1810. #define DRIVE_RESULT_3 (gdwTransferKeyAddress + 25*4)
  1811. #define DRIVE_RESULT_4 (gdwTransferKeyAddress + 26*4)
  1812. #define DECODER_RESULT_0 (gdwTransferKeyAddress + 27*4)
  1813. #define DECODER_RESULT_1 (gdwTransferKeyAddress + 28*4)
  1814. #define DECODER_RESULT_2 (gdwTransferKeyAddress + 29*4)
  1815. #define DECODER_RESULT_3 (gdwTransferKeyAddress + 30*4)
  1816. #define DECODER_RESULT_4 (gdwTransferKeyAddress + 31*4)
  1817. #define TITLE_KEY_0 (gdwTransferKeyAddress + 32*4)
  1818. #define TITLE_KEY_1 (gdwTransferKeyAddress + 33*4)
  1819. #define TITLE_KEY_2 (gdwTransferKeyAddress + 34*4)
  1820. #define TITLE_KEY_3 (gdwTransferKeyAddress + 35*4)
  1821. #define TITLE_KEY_4 (gdwTransferKeyAddress + 36*4)
  1822. #define ACC (gdwTransferKeyAddress + 42*4)
  1823. //--------------------------------------------------------------------------
  1824. // GLOBAL VARIABLES DEFINITION
  1825. //--------------------------------------------------------------------------
  1826. static DWORD gdwTransferKeyAddress;
  1827. BOOL dvd_DiskAuthStatus( BYTE * btStatus )
  1828. {
  1829. *btStatus = btDiskAuthStatus;
  1830. return TRUE;
  1831. }
  1832. BOOL dvd_SetDscBypassMode()
  1833. {
  1834. DWORD dwValue;
  1835. dwValue = DVD_ReadDRAM(HOST_OPTIONS);
  1836. dwValue |= 0x04; // Set to by pass mode (bit D2)
  1837. DVD_WriteDRAM( HOST_OPTIONS, dwValue );
  1838. return TRUE;
  1839. }
  1840. //
  1841. // DVD_Authenticate
  1842. //
  1843. /////////////////////////////////////////////////////////////////////
  1844. BOOL DVD_Authenticate( WORD wFunction, BYTE * pbyDATA )
  1845. {
  1846. // Initialize DRAM pointer
  1847. gdwTransferKeyAddress = /*0x37b6*2;//*/DVD_ReadDRAM( KEY_ADDRESS );
  1848. /*
  1849. MonoOutStr( " TransferKeyAddress:" );
  1850. MonoOutULongHex( gdwTransferKeyAddress );
  1851. MonoOutStr( " ACC:" );
  1852. MonoOutULongHex( DVD_ReadDRAM( ACC ) );
  1853. */
  1854. switch ( wFunction )
  1855. {
  1856. case DVD_GET_CHALLENGE:
  1857. return dvd_GetChallengeData( pbyDATA );
  1858. case DVD_SEND_CHALLENGE:
  1859. return dvd_SendChallengeData( pbyDATA );
  1860. case DVD_GET_RESPONSE:
  1861. return dvd_GetResponseData( pbyDATA );
  1862. case DVD_SEND_RESPONSE:
  1863. return dvd_SendResponseData( pbyDATA );
  1864. case DVD_SEND_DISK_KEY:
  1865. return dvd_SendDiskKeyData( pbyDATA );
  1866. case DVD_SEND_TITLE_KEY:
  1867. return dvd_SendTitleKeyData( pbyDATA );
  1868. case DVD_SET_DECRYPTION_MODE:
  1869. return dvd_SetDecryptionMode( pbyDATA );
  1870. }
  1871. return FALSE;
  1872. }
  1873. /******************************************************************************/
  1874. /******************* STATIC FUNCTIONS IMPLEMENTATION **************************/
  1875. /******************************************************************************/
  1876. //
  1877. // dvd_GetChallengeData
  1878. //
  1879. /////////////////////////////////////////////////////////////////////
  1880. BOOL dvd_GetChallengeData( BYTE * CHG )
  1881. {
  1882. DWORD dwTimeout;
  1883. //MonoOutStr( " [1.DEC_RAND:" );
  1884. MonoOutStr( "\n1.GetChallengeData:" );
  1885. if ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  1886. {
  1887. MonoOutStr( " Previous command was not completed KEY_STATUS:" );
  1888. MonoOutULongHex( DVD_ReadDRAM( KEY_STATUS ) );
  1889. return FALSE;
  1890. }
  1891. DVD_WriteDRAM( KEY_COMMAND, GET_CHALLENGE_DATA );
  1892. DVD_WriteDRAM( KEY_STATUS, 0 );
  1893. if ( !DVD_NewCommand( CID_TRANSFERKEY, 1, 0, 0, 0, 0, 0, 0, CMD_STATE_STEADY ) )
  1894. {
  1895. MonoOutStr( " CID_TRANSFERKEY has failed " );
  1896. return FALSE;
  1897. }
  1898. dwTimeout = 100000;
  1899. while ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  1900. {
  1901. if ( !--dwTimeout )
  1902. {
  1903. MonoOutStr( " Timeout waiting for command to complete " );
  1904. return FALSE;
  1905. }
  1906. }
  1907. CHG[0] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_9 );
  1908. CHG[1] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_8 );
  1909. CHG[2] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_7 );
  1910. CHG[3] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_6 );
  1911. CHG[4] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_5 );
  1912. CHG[5] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_4 );
  1913. CHG[6] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_3 );
  1914. CHG[7] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_2 );
  1915. CHG[8] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_1 );
  1916. CHG[9] = (BYTE)DVD_ReadDRAM( DRIVE_CHALLENGE_0 );
  1917. /*
  1918. MonoOutHex( CHG[0] );
  1919. MonoOutChar(' ');
  1920. MonoOutHex( CHG[1] );
  1921. MonoOutChar(' ');
  1922. MonoOutHex( CHG[2] );
  1923. MonoOutChar(' ');
  1924. MonoOutHex( CHG[3] );
  1925. MonoOutChar(' ');
  1926. MonoOutHex( CHG[4] );
  1927. MonoOutChar(' ');
  1928. MonoOutHex( CHG[5] );
  1929. MonoOutChar(' ');
  1930. MonoOutHex( CHG[6] );
  1931. MonoOutChar(' ');
  1932. MonoOutHex( CHG[7] );
  1933. MonoOutChar(' ');
  1934. MonoOutHex( CHG[8] );
  1935. MonoOutChar(' ');
  1936. MonoOutHex( CHG[9] );
  1937. */
  1938. MonoOutStr( "End] " );
  1939. return TRUE;
  1940. }
  1941. //
  1942. // dvd_SendChallengeData
  1943. //
  1944. /////////////////////////////////////////////////////////////////////
  1945. BOOL dvd_SendChallengeData( BYTE * CHG )
  1946. {
  1947. DWORD dwTimeout;
  1948. //MonoOutStr( " [3.DEC_AUTH:" );
  1949. MonoOutStr( "\n3.SendChallengeData:" );
  1950. if ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  1951. {
  1952. MonoOutStr( " Previous command was not completed " );
  1953. return FALSE;
  1954. }
  1955. DVD_WriteDRAM( DECODER_CHALLENGE_9, CHG[0] );
  1956. DVD_WriteDRAM( DECODER_CHALLENGE_8, CHG[1] );
  1957. DVD_WriteDRAM( DECODER_CHALLENGE_7, CHG[2] );
  1958. DVD_WriteDRAM( DECODER_CHALLENGE_6, CHG[3] );
  1959. DVD_WriteDRAM( DECODER_CHALLENGE_5, CHG[4] );
  1960. DVD_WriteDRAM( DECODER_CHALLENGE_4, CHG[5] );
  1961. DVD_WriteDRAM( DECODER_CHALLENGE_3, CHG[6] );
  1962. DVD_WriteDRAM( DECODER_CHALLENGE_2, CHG[7] );
  1963. DVD_WriteDRAM( DECODER_CHALLENGE_1, CHG[8] );
  1964. DVD_WriteDRAM( DECODER_CHALLENGE_0, CHG[9] );
  1965. DVD_WriteDRAM( KEY_COMMAND, SEND_CHALLENGE_DATA );
  1966. DVD_WriteDRAM( KEY_STATUS, 0 );
  1967. dwTimeout = 100000;
  1968. while ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  1969. {
  1970. if ( !--dwTimeout )
  1971. {
  1972. MonoOutStr( " Timeout waiting for command to complete " );
  1973. return FALSE;
  1974. }
  1975. }
  1976. return TRUE;
  1977. }
  1978. //
  1979. // dvd_GetResponseData
  1980. //
  1981. /////////////////////////////////////////////////////////////////////
  1982. BOOL dvd_GetResponseData( BYTE * RSP )
  1983. {
  1984. DWORD dwTimeout;
  1985. //sri MonoOutStr( "\n4.GetResponseData: " );
  1986. if ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  1987. {
  1988. MonoOutStr( " Previous command was not completed " );
  1989. return FALSE;
  1990. }
  1991. DVD_WriteDRAM( KEY_COMMAND, GET_RESPONSE_DATA );
  1992. DVD_WriteDRAM( KEY_STATUS, 0 );
  1993. dwTimeout = 100000;
  1994. while ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  1995. {
  1996. if ( !--dwTimeout )
  1997. {
  1998. MonoOutStr( " Timeout waiting for command to complete " );
  1999. return FALSE;
  2000. }
  2001. }
  2002. RSP[0] = (BYTE)DVD_ReadDRAM( DECODER_RESULT_4 );
  2003. RSP[1] = (BYTE)DVD_ReadDRAM( DECODER_RESULT_3 );
  2004. RSP[2] = (BYTE)DVD_ReadDRAM( DECODER_RESULT_2 );
  2005. RSP[3] = (BYTE)DVD_ReadDRAM( DECODER_RESULT_1 );
  2006. RSP[4] = (BYTE)DVD_ReadDRAM( DECODER_RESULT_0 );
  2007. // Cancel TransferKey() command
  2008. DVD_WriteDRAM( KEY_COMMAND, RESET_AUTHENTICATION );
  2009. DVD_WriteDRAM( KEY_STATUS, 0 );
  2010. MonoOutStr( "End] " );
  2011. return TRUE;
  2012. }
  2013. //
  2014. // dvd_SendResponseData
  2015. //
  2016. /////////////////////////////////////////////////////////////////////
  2017. BOOL dvd_SendResponseData( BYTE * RSP )
  2018. {
  2019. DWORD dwTimeout;
  2020. //MonoOutStr( " [2.DRV_AUTH:" );
  2021. MonoOutStr( "\n2.SendResponseData: " );
  2022. if ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  2023. {
  2024. MonoOutStr( " Previous command was not completed " );
  2025. return FALSE;
  2026. }
  2027. DVD_WriteDRAM( DRIVE_RESULT_4, RSP[0] );
  2028. DVD_WriteDRAM( DRIVE_RESULT_3, RSP[1] );
  2029. DVD_WriteDRAM( DRIVE_RESULT_2, RSP[2] );
  2030. DVD_WriteDRAM( DRIVE_RESULT_1, RSP[3] );
  2031. DVD_WriteDRAM( DRIVE_RESULT_0, RSP[4] );
  2032. /*
  2033. MonoOutHex( RSP[0] );
  2034. MonoOutChar(' ');
  2035. MonoOutHex( RSP[1] );
  2036. MonoOutChar(' ');
  2037. MonoOutHex( RSP[2] );
  2038. MonoOutChar(' ');
  2039. MonoOutHex( RSP[3] );
  2040. MonoOutChar(' ');
  2041. MonoOutHex( RSP[4] );
  2042. MonoOutChar(' ');
  2043. */
  2044. DVD_WriteDRAM( KEY_COMMAND, SEND_RESPONSE_DATA );
  2045. DVD_WriteDRAM( KEY_STATUS, 0 );
  2046. dwTimeout = 100000;
  2047. while ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  2048. {
  2049. if ( !--dwTimeout )
  2050. {
  2051. MonoOutStr( " Timeout waiting for command to complete " );
  2052. return FALSE;
  2053. }
  2054. }
  2055. MonoOutStr( "End] " );
  2056. return TRUE;
  2057. }
  2058. //
  2059. // dvd_SendDiskKeyData
  2060. //
  2061. /////////////////////////////////////////////////////////////////////
  2062. BOOL dvd_SendDiskKeyData( BYTE * pBuffer )
  2063. {
  2064. DWORD physAddress;
  2065. DWORD dwTimeout = 10000;
  2066. btDiskAuthStatus = 0; // Assume encrypted correctly
  2067. //MonoOutStr( " [DEC_DKY:" );
  2068. MonoOutStr( "\n5.Send DK:" );
  2069. if ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  2070. {
  2071. MonoOutStr( " Previous command was not completed " );
  2072. return FALSE;
  2073. }
  2074. if ( !DVD_NewCommand( CID_TRANSFERKEY, 1, 0, 0, 0, 0, 0, 0, CMD_STATE_STEADY ) )
  2075. {
  2076. MonoOutStr( " CID_TRANSFERKEY has failed " );
  2077. return FALSE;
  2078. }
  2079. DVD_WriteDRAM( KEY_COMMAND, SEND_DISK_KEY );
  2080. DVD_WriteDRAM( KEY_STATUS, 0 );
  2081. dwTimeout = 100000;
  2082. while ( DVD_ReadDRAM( KEY_STATUS ) != 3 )
  2083. {
  2084. if ( !--dwTimeout )
  2085. {
  2086. MonoOutStr( " Waiting for KEY_STATUS == 3 " );
  2087. return FALSE;
  2088. }
  2089. }
  2090. // Send one sector
  2091. #ifdef VTOOLSD
  2092. CopyPageTable( (DWORD)pBuffer >> 12, 1, (PVOID*)&physAddress, 0 );
  2093. physAddress = (physAddress & 0xfffff000) + (((DWORD)pBuffer) & 0xfff);
  2094. #else
  2095. physAddress = (DWORD)pBuffer;
  2096. #endif
  2097. //FPGA_Set( FPGA_SECTOR_START );
  2098. #if defined(DECODER_DVDPC)
  2099. DataTransfer_DiskKey(pBuffer);
  2100. #elif defined(EZDVD)
  2101. if(!BMA_Send((DWORD*)pBuffer,2048))
  2102. return FALSE;
  2103. #else
  2104. if ( !BMA_Send( (DWORD *) physAddress, 2048 ) )
  2105. return FALSE;
  2106. dwTimeout = 10000;
  2107. while ( !BMA_Complete() )
  2108. {
  2109. if ( !(--dwTimeout) )
  2110. {
  2111. MonoOutStr( " BMA did not complete !!! " );
  2112. return FALSE;
  2113. }
  2114. }
  2115. #endif
  2116. DelayNoYield(5000);
  2117. MonoOutStr( " KEY_STATUS = " );
  2118. MonoOutULongHex(DVD_ReadDRAM( KEY_STATUS ));
  2119. if (DVD_ReadDRAM( KEY_STATUS ) == 4) // Fake authentication
  2120. {
  2121. MonoOutStr( " Fake Encrypted Disk " );
  2122. btDiskAuthStatus = 1; // Fake Encryption
  2123. }
  2124. //FPGA_Clear( FPGA_SECTOR_START );
  2125. // Cancel TransferKey() command
  2126. DVD_WriteDRAM( KEY_COMMAND, RESET_AUTHENTICATION );
  2127. DVD_WriteDRAM( KEY_STATUS, 0 );
  2128. DelayNoYield(5000);
  2129. MonoOutStr( " OK] " );
  2130. return TRUE;
  2131. }
  2132. //
  2133. // dvd_SendTilteKeyData
  2134. //
  2135. /////////////////////////////////////////////////////////////////////
  2136. BOOL dvd_SendTitleKeyData( BYTE * ETK )
  2137. {
  2138. DWORD dwTimeout = 100000L;
  2139. //MonoOutStr( "\n[DEC_DTK:" );
  2140. //sri MonoOutStr( "\n6.Send TK:" );
  2141. if ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  2142. {
  2143. MonoOutStr( " Previous command was not completed " );
  2144. return FALSE;
  2145. }
  2146. if ( !DVD_NewCommand( CID_TRANSFERKEY, 1, 0, 0, 0, 0, 0, 0, CMD_STATE_STEADY ) )
  2147. {
  2148. MonoOutStr( " CID_TRANSFERKEY has failed " );
  2149. return FALSE;
  2150. }
  2151. // ETK[0] is used by the TS6807AF chip only
  2152. DVD_WriteDRAM( TITLE_KEY_4, ETK[1] );
  2153. DVD_WriteDRAM( TITLE_KEY_3, ETK[2] );
  2154. DVD_WriteDRAM( TITLE_KEY_2, ETK[3] );
  2155. DVD_WriteDRAM( TITLE_KEY_1, ETK[4] );
  2156. DVD_WriteDRAM( TITLE_KEY_0, ETK[5] );
  2157. DVD_WriteDRAM( KEY_COMMAND, SEND_TITLE_KEY );
  2158. DVD_WriteDRAM( KEY_STATUS, 0 );
  2159. dwTimeout = 100000;
  2160. while ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  2161. {
  2162. if ( !--dwTimeout )
  2163. {
  2164. MonoOutStr( " SEND_TITLE_KEY command was not completed " );
  2165. return FALSE;
  2166. }
  2167. }
  2168. // Cancel TransferKey() command
  2169. DVD_WriteDRAM( KEY_COMMAND, RESET_AUTHENTICATION );
  2170. DVD_WriteDRAM( KEY_STATUS, 0 );
  2171. if (btDiskAuthStatus) // Fake disk
  2172. {
  2173. dvd_SetDscBypassMode();
  2174. }
  2175. MonoOutStr( "End] " );
  2176. return TRUE;
  2177. }
  2178. //
  2179. // dvd_SetDecryptionMode
  2180. //
  2181. /////////////////////////////////////////////////////////////////////
  2182. BOOL dvd_SetDecryptionMode( BYTE * SR_FLAG )
  2183. {
  2184. DWORD dwTimeout = 100000;
  2185. //MonoOutStr( " [DEC_DT:" );
  2186. MonoOutStr( "\n7.Set Decrypt mode:" );
  2187. if ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  2188. {
  2189. MonoOutStr( " Previous command was not completed " );
  2190. return FALSE;
  2191. }
  2192. if ( !DVD_NewCommand( CID_TRANSFERKEY, 1, 0, 0, 0, 0, 0, 0, CMD_STATE_STEADY ) )
  2193. {
  2194. MonoOutStr( " CID_TRANSFERKEY has failed " );
  2195. return FALSE;
  2196. }
  2197. if ( *SR_FLAG )
  2198. {
  2199. MonoOutStr( " Decrypt" );
  2200. DVD_WriteDRAM( KEY_COMMAND, SET_DECRYPTION_MODE );
  2201. }
  2202. else
  2203. {
  2204. MonoOutStr( " Pass through" );
  2205. DVD_WriteDRAM( KEY_COMMAND, SET_PASS_THROUGH_MODE );
  2206. }
  2207. DVD_WriteDRAM( KEY_STATUS, 0 );
  2208. dwTimeout = 100000;
  2209. while ( DVD_ReadDRAM( KEY_STATUS ) != 1 )
  2210. {
  2211. if ( !--dwTimeout )
  2212. {
  2213. MonoOutStr( " SEND_TITLE_KEY command was not completed " );
  2214. return FALSE;
  2215. }
  2216. }
  2217. // Cancel TransferKey() command
  2218. DVD_WriteDRAM( KEY_COMMAND, RESET_AUTHENTICATION );
  2219. DVD_WriteDRAM( KEY_STATUS, 0 );
  2220. #ifdef DEBUG
  2221. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2222. DVD_WriteReg( 0x8, 0x15F );
  2223. DVD_WriteReg( 0x8, 0x11E );
  2224. MonoOutStr( " DK:" );
  2225. MonoOutULongHex( DVD_ReadReg(0x9) );
  2226. DVD_WriteReg( 0x8, 0x17F );
  2227. DVD_WriteReg( 0x8, 0x11E );
  2228. MonoOutStr( "-" );
  2229. MonoOutULongHex( DVD_ReadReg(0x9) );
  2230. MonoOutStr( " " );
  2231. DVD_WriteReg( 0x8, 0x15F );
  2232. DVD_WriteReg( 0x8, 0x13E );
  2233. MonoOutStr( " TK:" );
  2234. MonoOutULongHex( DVD_ReadReg(0x9) );
  2235. DVD_WriteReg( 0x8, 0x17F );
  2236. DVD_WriteReg( 0x8, 0x13E );
  2237. MonoOutStr( "-" );
  2238. MonoOutULongHex( DVD_ReadReg(0x9) );
  2239. MonoOutStr( " " );
  2240. // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  2241. #endif
  2242. MonoOutStr( "End] " );
  2243. return TRUE;
  2244. }
  2245. /**************************************************************************/
  2246. /*********************** CL6100 Interrupt functions ***********************/
  2247. /**************************************************************************/
  2248. //
  2249. // DVD_IntEnable
  2250. //
  2251. /////////////////////////////////////////////////////////////////////
  2252. BOOL DVD_IntEnable( DWORD dwMask )
  2253. {
  2254. DWORD dwCurrentMask;
  2255. MonoOutStr( " <INT Enable:" );
  2256. //#ifndef EZDVD
  2257. dwCurrentMask = DVD_ReadDRAM( INT_MASK );
  2258. dwCurrentMask |= dwMask;
  2259. MonoOutULongHex( dwCurrentMask );
  2260. DVD_WriteDRAM( INT_MASK, dwCurrentMask );
  2261. // Enable PCI Interrupts //sri
  2262. if ( dwCurrentMask )
  2263. {
  2264. if ( !BRD_OpenDecoderInterruptPass() )
  2265. return FALSE;
  2266. }
  2267. MonoOutStr( ">" );
  2268. //#endif
  2269. return TRUE;
  2270. }
  2271. //
  2272. // DVD_IntDisable
  2273. //
  2274. /////////////////////////////////////////////////////////////////////
  2275. BOOL DVD_IntDisable( DWORD dwMask )
  2276. {
  2277. DWORD dwCurrentMask;
  2278. MonoOutStr( " <INT Disable:" );
  2279. //#ifndef EZDVD
  2280. dwCurrentMask = DVD_ReadDRAM( INT_MASK );
  2281. dwCurrentMask &= ~dwMask;
  2282. MonoOutULongHex( dwCurrentMask );
  2283. DVD_WriteDRAM( INT_MASK, dwCurrentMask );
  2284. // Disable PCI Interrupts if mask is empty //sri
  2285. if ( !dwCurrentMask )
  2286. {
  2287. if ( !BRD_CloseDecoderInterruptPass() )
  2288. return FALSE;
  2289. }
  2290. MonoOutStr( ">" );
  2291. //#endif
  2292. return TRUE;
  2293. }
  2294. //
  2295. // DVD_Isr
  2296. //
  2297. // CL6100 Interrupt service routine
  2298. //
  2299. /////////////////////////////////////////////////////////////////////
  2300. DWORD DVD_Isr( PINTSOURCES pIntSrc )
  2301. {
  2302. DWORD DVDIntStat;
  2303. /*
  2304. DWORD DVDIntHLI;
  2305. DWORD DVDIntBUFF;
  2306. DWORD DVDIntUND;
  2307. DWORD DVDIntAOR;
  2308. DWORD DVDIntAEE;
  2309. DWORD DVDIntERR;
  2310. */
  2311. DWORD DVDPauseCount = 0;
  2312. DVDIntStat = DVD_ReadDRAM( INT_STATUS ); // Read Interrupt Status
  2313. if ( DVDIntStat )
  2314. {
  2315. DVD_WriteReg( HOST_control, 0x1002L ); // Clear 6100 HW Interrupt
  2316. // MonoOutStr( " <INT:" );
  2317. //MonoOutULongHex( DVDIntStat );
  2318. if ( DVDIntStat & CL6100_INT_MASK_HLI )
  2319. {
  2320. pIntSrc->DVDIntHLI = DVD_ReadDRAM( HLI_INT_SRC );
  2321. MonoOutStr( " Button:" );
  2322. MonoOutULong( pIntSrc->DVDIntHLI );
  2323. DVD_WriteDRAM( HLI_INT_SRC, 0 );
  2324. }
  2325. if ( DVDIntStat & CL6100_INT_MASK_BUF_F )
  2326. {
  2327. pIntSrc->DVDIntBUFF = DVD_ReadDRAM( BUFF_INT_SRC );
  2328. DVD_WriteDRAM( BUFF_INT_SRC, 0 );
  2329. }
  2330. if ( DVDIntStat & CL6100_INT_MASK_UND )
  2331. {
  2332. pIntSrc->DVDIntUND = DVD_ReadDRAM( UND_INT_SRC );
  2333. // MonoOutULong(pIntSrc->DVDIntUND);
  2334. DVD_WriteDRAM( UND_INT_SRC, 0 );
  2335. // MonoOutULongHex( DVDIntStat );
  2336. // MonoOutStr(".U.");
  2337. }
  2338. if ( DVDIntStat & CL6100_INT_MASK_AOR )
  2339. {
  2340. pIntSrc->DVDIntAOR = DVD_ReadDRAM( AOR_INT_SRC );
  2341. DVD_WriteDRAM( AOR_INT_SRC, 0 );
  2342. }
  2343. if ( DVDIntStat & CL6100_INT_MASK_AEE )
  2344. {
  2345. pIntSrc->DVDIntAEE = DVD_ReadDRAM( AEE_INT_SRC );
  2346. DVD_WriteDRAM( AEE_INT_SRC, 0 );
  2347. }
  2348. if ( DVDIntStat & CL6100_INT_MASK_ERR )
  2349. {
  2350. pIntSrc->DVDIntERR = DVD_ReadDRAM( ERR_INT_SRC );
  2351. DVD_WriteDRAM( ERR_INT_SRC, 0 );
  2352. MonoOutStr("Error Reported");
  2353. }
  2354. if ( DVDIntStat & CL6100_INT_MASK_VSYNC )
  2355. {
  2356. // MonoOutStr("VS");
  2357. // DbgPrint("ZiVA: VSyncInterrupt ");
  2358. if(pDevEx->dwVSyncCount++ >= INTERVAL_TIME)
  2359. {
  2360. // DbgPrint("ZiVA: VSyncInterrupt ");
  2361. ReleaseClockEvents(pDevEx,TRUE);
  2362. pDevEx->dwVSyncCount=0;
  2363. }
  2364. else
  2365. {
  2366. ReleaseClockEvents(pDevEx,FALSE);
  2367. }
  2368. }
  2369. if ( DVDIntStat & CL6100_INT_MASK_USR )
  2370. {
  2371. MonoOutStr("US");
  2372. //#ifndef EZDVD
  2373. UserDataEvents(pDevEx);
  2374. //#endif
  2375. }
  2376. if ( DVDIntStat & CL6100_INT_MASK_END_P )
  2377. DVDPauseCount++;
  2378. DVD_WriteDRAM( INT_STATUS, 0 ); // Clear 6100 Interrupt Semaphore
  2379. // MonoOutStr( ">" );
  2380. }
  2381. return DVDIntStat;
  2382. }
  2383. #ifdef UCODE_VER_2
  2384. BOOL DVD_SetZoom(DWORD dwZoomFactor, DWORD dwXOffset, DWORD dwYOffset)
  2385. {
  2386. BOOL bStatus;
  2387. bStatus = DVD_NewCommand( CID_ZOOM, dwXOffset, dwYOffset, dwZoomFactor, 0, 0, 0,
  2388. 0, CMD_STATE_DONE );
  2389. return bStatus;
  2390. }
  2391. BOOL DVD_ReversePlay(DWORD dwDecoderSpeed, DWORD dwFrameMode)
  2392. {
  2393. BOOL bStatus;
  2394. MonoOutStr( " �� DVD_ReversePlay " );
  2395. MonoOutULongHex(dwDecoderSpeed);
  2396. MonoOutStr( " : " );
  2397. MonoOutULongHex(dwFrameMode);
  2398. MonoOutStr( " " );
  2399. bStatus = DVD_NewCommand( CID_REVERSEPLAY, dwDecoderSpeed, dwFrameMode, 3, 0, 0, 0,
  2400. CL6100_INT_MASK_RDY_D, CMD_STATE_DONE );
  2401. return bStatus;
  2402. }
  2403. void DVD_SetVerticalDiaplyMode(DWORD dwVerticalDisplayMode)
  2404. {
  2405. DVD_WriteDRAM( VERTICAL_DISPLAYMODE, dwVerticalDisplayMode );
  2406. }
  2407. #endif
  2408. #ifdef DEBUG
  2409. BOOL DVD_SetParam(DWORD dwParamID, DWORD dwParamValue)
  2410. {
  2411. DVD_WriteDRAM( dwParamID, dwParamValue);
  2412. MonoOutStr( " �� DVD_GetParam: " );
  2413. MonoOutInt( dwParamID );
  2414. MonoOutStr( " " );
  2415. MonoOutInt( dwParamValue );
  2416. MonoOutStr( " Ķ " );
  2417. return TRUE;
  2418. }
  2419. BOOL DVD_GetParam(DWORD dwParamID, DWORD *dwParamValue)
  2420. {
  2421. *dwParamValue = DVD_ReadDRAM( dwParamID);
  2422. MonoOutStr( " �� DVD_GetParam: " );
  2423. MonoOutInt( *dwParamValue );
  2424. MonoOutStr( " Ķ " );
  2425. return TRUE;
  2426. }
  2427. BOOL DVD_SendCommand(DWORD dwCommandID,
  2428. DWORD dwParam1,
  2429. DWORD dwParam2,
  2430. DWORD dwParam3,
  2431. DWORD dwParam4,
  2432. DWORD dwParam5,
  2433. DWORD dwParam6,
  2434. DWORD dwIntMask,
  2435. DWORD dwStatus )
  2436. {
  2437. return DVD_NewCommand( dwCommandID,
  2438. dwParam1,
  2439. dwParam2,
  2440. dwParam3,
  2441. dwParam4,
  2442. dwParam5,
  2443. dwParam6,
  2444. dwIntMask,
  2445. dwStatus );
  2446. }
  2447. #endif // DEBUG