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.

293 lines
6.4 KiB

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