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.

323 lines
7.1 KiB

  1. //***************************************************************************
  2. // PCI Interface(DACK) process
  3. //
  4. //***************************************************************************
  5. #include "common.h"
  6. #include "regs.h"
  7. #include "cdack.h"
  8. extern DWORD GetCurrentTime_ms( void );
  9. void Dack::init( const PDEVICE_INIT_INFO pDevInit )
  10. {
  11. ioBase = pDevInit->ioBase;
  12. }
  13. NTSTATUS Dack::PCIF_RESET( void )
  14. {
  15. DWORD st, et;
  16. UCHAR val;
  17. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, 0x80 );
  18. DigitalOutMode = 0x00;
  19. st = GetCurrentTime_ms();
  20. for( ; ; ) {
  21. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  22. if( ( val & 0x80 ) != 0x80 )
  23. break;
  24. et = GetCurrentTime_ms();
  25. if( st + 10000 < et ) {
  26. TRAP;
  27. return STATUS_UNSUCCESSFUL;
  28. }
  29. }
  30. UCHAR initpaldata[256];
  31. int i;
  32. for( i = 0; i < 256; i++ )
  33. initpaldata[i] = (UCHAR)i;
  34. PCIF_SET_PALETTE( PALETTE_Y, initpaldata );
  35. PCIF_SET_PALETTE( PALETTE_Cb, initpaldata );
  36. PCIF_SET_PALETTE( PALETTE_Cr, initpaldata );
  37. return STATUS_SUCCESS;
  38. }
  39. void Dack::PCIF_AMUTE_ON( void )
  40. {
  41. UCHAR val;
  42. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  43. val |= 0x40;
  44. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  45. }
  46. void Dack::PCIF_AMUTE_OFF( void )
  47. {
  48. UCHAR val;
  49. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  50. val &= 0xbf;
  51. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  52. }
  53. void Dack::PCIF_AMUTE2_ON( void )
  54. {
  55. UCHAR val;
  56. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  57. val |= 0x20;
  58. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  59. }
  60. void Dack::PCIF_AMUTE2_OFF( void )
  61. {
  62. UCHAR val;
  63. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  64. val &= 0xdf;
  65. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  66. }
  67. void Dack::PCIF_VSYNC_ON( void )
  68. {
  69. UCHAR val;
  70. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  71. val |= 0x10;
  72. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  73. }
  74. void Dack::PCIF_VSYNC_OFF( void )
  75. {
  76. UCHAR val;
  77. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  78. val &= 0xef;
  79. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  80. }
  81. void Dack::PCIF_PACK_START_ON( void )
  82. {
  83. WRITE_PORT_UCHAR( ioBase + PCIF_PSCNT, 0x04 );
  84. }
  85. void Dack::PCIF_PACK_START_OFF( void )
  86. {
  87. WRITE_PORT_UCHAR( ioBase + PCIF_PSCNT, 0x00 );
  88. }
  89. void Dack::PCIF_SET_DIGITAL_OUT( UCHAR mode )
  90. {
  91. DigitalOutMode = mode;
  92. PCIF_SET_PALETTE( PALETTE_Y, paldata[PALETTE_Y-1] );
  93. PCIF_SET_PALETTE( PALETTE_Cb, paldata[PALETTE_Cb-1] );
  94. PCIF_SET_PALETTE( PALETTE_Cr, paldata[PALETTE_Cr-1] );
  95. WRITE_PORT_UCHAR( ioBase + PCIF_VMODE, mode );
  96. WRITE_PORT_UCHAR( ioBase + PCIF_HSCNT, 0x70 );
  97. WRITE_PORT_UCHAR( ioBase + PCIF_VSCNT, 0x0b );
  98. if ( mode == 0x04 ) // S3 LPB
  99. WRITE_PORT_UCHAR( ioBase + PCIF_HSVS, 0x00 );
  100. else
  101. WRITE_PORT_UCHAR( ioBase + PCIF_HSVS, 0x00 );
  102. }
  103. void Dack::PCIF_SET_DMA0_SIZE( ULONG dmaSize )
  104. {
  105. UCHAR val;
  106. if ( dmaSize == 0 )
  107. return;
  108. dmaSize--;
  109. // select MTC-0
  110. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  111. val &= 0xf8;
  112. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  113. // write DMA size
  114. WRITE_PORT_UCHAR( ioBase + PCIF_MTCLL, (UCHAR)( dmaSize & 0xff ) );
  115. WRITE_PORT_UCHAR( ioBase + PCIF_MTCLH, (UCHAR)( ( dmaSize >> 8 ) & 0xff ) );
  116. WRITE_PORT_UCHAR( ioBase + PCIF_MTCHL, (UCHAR)( ( dmaSize >> 16 ) & 0xff ) );
  117. WRITE_PORT_UCHAR( ioBase + PCIF_MTCHH, (UCHAR)( ( dmaSize >> 24 ) & 0xff ) );
  118. }
  119. void Dack::PCIF_SET_DMA1_SIZE( ULONG dmaSize )
  120. {
  121. UCHAR val;
  122. if ( dmaSize == 0 )
  123. return;
  124. dmaSize--;
  125. // select MTC-1
  126. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  127. val &= 0xf8;
  128. val |= 0x04;
  129. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  130. // write DMA size
  131. WRITE_PORT_UCHAR( ioBase + PCIF_MTCLL, (UCHAR)( dmaSize & 0xff ) );
  132. WRITE_PORT_UCHAR( ioBase + PCIF_MTCLH, (UCHAR)( ( dmaSize >> 8 ) & 0xff ) );
  133. WRITE_PORT_UCHAR( ioBase + PCIF_MTCHL, (UCHAR)( ( dmaSize >> 16 ) & 0xff ) );
  134. WRITE_PORT_UCHAR( ioBase + PCIF_MTCHH, (UCHAR)( ( dmaSize >> 24 ) & 0xff ) );
  135. }
  136. void Dack::PCIF_SET_DMA0_ADDR( ULONG dmaAddr )
  137. {
  138. UCHAR val;
  139. // select MTC-0
  140. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  141. val &= 0xf8;
  142. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  143. // write DMA0 address
  144. WRITE_PORT_UCHAR( ioBase + PCIF_MADRLL, (UCHAR)( dmaAddr & 0xff ) );
  145. WRITE_PORT_UCHAR( ioBase + PCIF_MADRLH, (UCHAR)( ( dmaAddr >> 8 ) & 0xff ) );
  146. WRITE_PORT_UCHAR( ioBase + PCIF_MADRHL, (UCHAR)( ( dmaAddr >> 16 ) & 0xff ) );
  147. WRITE_PORT_UCHAR( ioBase + PCIF_MADRHH, (UCHAR)( ( dmaAddr >> 24 ) & 0xff ) );
  148. }
  149. void Dack::PCIF_SET_DMA1_ADDR( ULONG dmaAddr )
  150. {
  151. UCHAR val;
  152. // select MTC-1
  153. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  154. val &= 0xf8;
  155. val |= 0x04;
  156. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  157. // write DMA1 address
  158. WRITE_PORT_UCHAR( ioBase + PCIF_MADRLL, (UCHAR)( dmaAddr & 0xff ) );
  159. WRITE_PORT_UCHAR( ioBase + PCIF_MADRLH, (UCHAR)( ( dmaAddr >> 8 ) & 0xff ) );
  160. WRITE_PORT_UCHAR( ioBase + PCIF_MADRHL, (UCHAR)( ( dmaAddr >> 16 ) & 0xff ) );
  161. WRITE_PORT_UCHAR( ioBase + PCIF_MADRHH, (UCHAR)( ( dmaAddr >> 24 ) & 0xff ) );
  162. }
  163. void Dack::PCIF_DMA0_START( void )
  164. {
  165. UCHAR val;
  166. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  167. val &= 0xfc;
  168. val |= 0x01;
  169. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  170. }
  171. void Dack::PCIF_DMA1_START( void )
  172. {
  173. UCHAR val;
  174. val = READ_PORT_UCHAR( ioBase + PCIF_CNTL );
  175. val &= 0xfc;
  176. val |= 0x02;
  177. WRITE_PORT_UCHAR( ioBase + PCIF_CNTL, val );
  178. }
  179. void Dack::PCIF_SET_PALETTE( UCHAR select, PUCHAR pPalette )
  180. {
  181. int i;
  182. UCHAR val;
  183. ASSERT( PALETTE_Y <= select && select <= PALETTE_Cr );
  184. for ( i = 0; i < 256; i++ )
  185. paldata[select-1][i] = pPalette[i];
  186. val = (UCHAR)( ( READ_PORT_UCHAR( ioBase + PCIF_CPCNT ) & 0xFC ) | select | 0x04 );
  187. WRITE_PORT_UCHAR( ioBase + PCIF_CPCNT, val ); // clear color palette pointer
  188. for ( i = 0; i < 256; i++ ) {
  189. // DACK bug recovery. Use value from 0x07 to 0xFD in AMC mode and setting Palette Y.
  190. if( DigitalOutMode == 0x07 ) {
  191. if( select == PALETTE_Y ) {
  192. // convert 0x00 to 0xFF --> 0x07 to 0xFD
  193. // round up numbers of five and above and drop anything under five
  194. val = (UCHAR)(((LONG)pPalette[i] * 246 * 2 + 255) / (255 * 2) + 7);
  195. }
  196. else {
  197. if( pPalette[i] > 253 )
  198. val = 253;
  199. else
  200. val = pPalette[i];
  201. }
  202. }
  203. else
  204. val = pPalette[i];
  205. WRITE_PORT_UCHAR( ioBase + PCIF_CPLT, val );
  206. }
  207. }
  208. void Dack::PCIF_GET_PALETTE( UCHAR select, PUCHAR pPalette )
  209. {
  210. int i;
  211. UCHAR val;
  212. val = (UCHAR)( ( READ_PORT_UCHAR( ioBase + PCIF_CPCNT ) & 0xFC ) | select | 0x04 );
  213. WRITE_PORT_UCHAR( ioBase + PCIF_CPCNT, val ); // clear color palette pointer
  214. for ( i = 0; i < 256; i++ )
  215. pPalette[i] = READ_PORT_UCHAR( ioBase + PCIF_CPLT );
  216. }
  217. void Dack::PCIF_CHECK_SERIAL( void )
  218. {
  219. DWORD st, et;
  220. UCHAR val;
  221. st = GetCurrentTime_ms();
  222. for( ; ; ) {
  223. val = READ_PORT_UCHAR( ioBase + PCIF_SCNT );
  224. if( ( val & 0x80 ) != 0x80 )
  225. break;
  226. et = GetCurrentTime_ms();
  227. if( st + 10000 < et ) {
  228. TRAP;
  229. break;
  230. }
  231. }
  232. }
  233. void Dack::PCIF_DMA_ABORT( void )
  234. {
  235. WRITE_PORT_UCHAR( ioBase + PCIF_INTF, 0x04 );
  236. }
  237. void Dack::PCIF_ALL_IFLAG_CLEAR( void )
  238. {
  239. UCHAR val;
  240. val = READ_PORT_UCHAR( ioBase + PCIF_INTF );
  241. val |= 0x23;
  242. WRITE_PORT_UCHAR( ioBase + PCIF_INTF, val );
  243. }
  244. void Dack::PCIF_ASPECT_0403( void )
  245. {
  246. UCHAR val;
  247. val = READ_PORT_UCHAR( ioBase + PCIF_TEST );
  248. val |= 0x10;
  249. WRITE_PORT_UCHAR( ioBase + PCIF_TEST, val );
  250. }
  251. void Dack::PCIF_ASPECT_1609( void )
  252. {
  253. UCHAR val;
  254. val = READ_PORT_UCHAR( ioBase + PCIF_TEST );
  255. val &= 0xef;
  256. WRITE_PORT_UCHAR( ioBase + PCIF_TEST, val );
  257. }