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.

1477 lines
44 KiB

  1. /*/****************************************************************************
  2. * name: mtxvideo.c
  3. *
  4. * description: Routine for switching between VGA mode and TERMINATOR mode
  5. *
  6. * designed: Christian Toutant
  7. * last modified: $Author: ctoutant $, $Date: 94/06/13 14:06:06 $
  8. *
  9. * version: $Id: MTXVIDEO.C 1.50 94/06/13 14:06:06 ctoutant Exp $
  10. *
  11. *
  12. * void mtxSetVideoMode (word mode)
  13. * word mtxGetVideoMode (void)
  14. *
  15. ******************************************************************************/
  16. #include "switches.h"
  17. #ifdef WINDOWS_NT
  18. #if defined(ALLOC_PRAGMA)
  19. #pragma alloc_text(PAGE,testFifo)
  20. #pragma alloc_text(PAGE,mtxSetVLB)
  21. #pragma alloc_text(PAGE,mtxIsVLBBios)
  22. #pragma alloc_text(PAGE,compareDac)
  23. #pragma alloc_text(PAGE,mgaVL_AC00)
  24. #pragma alloc_text(PAGE,SetVgaDis)
  25. #pragma alloc_text(PAGE,mtxSetVideoMode)
  26. #pragma alloc_text(PAGE,mtxGetVideoMode)
  27. //Not to be paged out:
  28. //#pragma alloc_text(PAGE,SetVgaEn)
  29. //#pragma alloc_text(PAGE,rdTitanReg)
  30. //#pragma alloc_text(PAGE,wrTitanReg)
  31. //#pragma alloc_text(PAGE,rdDacReg)
  32. //#pragma alloc_text(PAGE,wrDacReg)
  33. //#pragma alloc_text(PAGE,rdDubicDReg)
  34. //#pragma alloc_text(PAGE,wrDubicDReg)
  35. //#pragma alloc_text(PAGE,rdDubicIReg)
  36. //#pragma alloc_text(PAGE,wrDubicIReg)
  37. //#pragma alloc_text(PAGE,delay_us)
  38. //#pragma alloc_text(PAGE,mtxIsVLB)
  39. //#pragma alloc_text(PAGE,mtxMapVLBSpace)
  40. //#pragma alloc_text(PAGE,mtxUnMapVLBSpace)
  41. //#pragma alloc_text(PAGE,mtxCheckVgaEn)
  42. //#pragma alloc_text(PAGE,checkCursorEn)
  43. //#pragma alloc_text(PAGE,setVgaMode)
  44. //#pragma alloc_text(PAGE,restoreVga)
  45. //#pragma alloc_text(PAGE,blankEcran)
  46. //#pragma alloc_text(PAGE,isPciBus)
  47. //#pragma alloc_text(PAGE,isaToWide)
  48. //#pragma alloc_text(PAGE,wideToIsa)
  49. #endif
  50. //Not to be paged out:
  51. // isVLBFlag
  52. // cursorStat
  53. // saveBitOperation
  54. //#if defined(ALLOC_PRAGMA)
  55. //#pragma data_seg("PAGE")
  56. //#endif
  57. #endif /* #ifdef WINDOWS_NT */
  58. #ifdef WINDOWS
  59. #include "windows.h"
  60. #endif
  61. #ifndef WINDOWS_NT
  62. #include <stdio.h>
  63. #include <stdlib.h>
  64. #include <string.h>
  65. #include <dos.h>
  66. #include <conio.h>
  67. #include <time.h>
  68. #endif
  69. #include "bind.h"
  70. #include "defbind.h"
  71. #ifndef __DDK_SRC__
  72. #include "sxci.h"
  73. #endif
  74. #include "def.h"
  75. #include "mga.h"
  76. #include "mgai_c.h"
  77. #include "mgai.h"
  78. static byte ucCrtc0, ucCrtc1, ucCrtc6, ucCrtc11, ucGctl6, ucMisc, ucGctlIndx;
  79. /* vgadac.h replaced with vgadac.c */
  80. /* #include "vgadac.h" */
  81. typedef struct {unsigned short r, g, b;} DacReg;
  82. extern DacReg vgaDac[];
  83. #ifdef OS2
  84. extern byte getVgaMode();
  85. #endif /* OS2 */
  86. long setTVP3026Freq ( volatile byte _Far *pDeviceParam, long fout, long reg, byte pWidth );
  87. # define TEMP_BUF_S 0x4000
  88. # define BIOS_VL 0xc0000
  89. # define BIOS_ID_OFF 0x78
  90. # define MOUSE_SRATE 18
  91. # define LASER_SRATE 2
  92. # define SEQ_ADDR 0x3c4
  93. # define SEQ_DATA 0x3c5
  94. # define PEL_ADDR_WR 0x3c7
  95. # define PEL_ADDR_RD 0x3c8
  96. # define PEL_DATA 0x3c9
  97. # define SEQ_SYNCRST 0x01
  98. # define SEQ_ASYNCRST 0x02
  99. # define VGA_RESET_REG 0x00
  100. # define BOARD_MGA_VL 0x0a
  101. # define BOARD_MGA_VL_M 0x0e
  102. # define ROBITWREN_M 0xff000000L
  103. # define ROBITWREN_A 24
  104. # define SETROBITWREN 0x8d000000L
  105. # define CLRROBITWREN 0x00000000L
  106. # define AllocVideoBuffer(x) (dword *)malloc(x << 2)
  107. # define FreeVideoBuffer(x) free(x)
  108. # define MaxVideoBuffer(x) findMaxVideoBuffer(x, 0)
  109. // Need these to figure out where the VGA i/o port registers are mapped
  110. #ifdef WINDOWS_NT
  111. extern PUCHAR pMgaBiosVl;
  112. typedef struct _MULTI_MODE
  113. {
  114. ULONG MulModeNumber; // unique mode Id
  115. ULONG MulWidth; // total width of mode
  116. ULONG MulHeight; // total height of mode
  117. ULONG MulPixWidth; // pixel depth of mode
  118. ULONG MulRefreshRate; // refresh rate of mode
  119. USHORT MulArrayWidth; // number of boards arrayed along X
  120. USHORT MulArrayHeight; // number of boards arrayed along Y
  121. UCHAR MulBoardNb[NB_BOARD_MAX]; // board numbers of required boards
  122. USHORT MulBoardMode[NB_BOARD_MAX]; // mode required from each board
  123. HwModeData *MulHwModes[NB_BOARD_MAX]; // pointers to required HwModeData
  124. } MULTI_MODE, *PMULTI_MODE;
  125. /*--------------------------------------------------------------------------*\
  126. | HW_DEVICE_EXTENSION
  127. |
  128. | Define device extension structure. This is device dependant/private
  129. | information.
  130. |
  131. \*--------------------------------------------------------------------------*/
  132. typedef struct _MGA_DEVICE_EXTENSION {
  133. ULONG SuperModeNumber; // Current mode number
  134. ULONG NumberOfSuperModes; // Total number of modes
  135. PMULTI_MODE pSuperModes; // Array of super-modes structures
  136. // For each board:
  137. ULONG NumberOfModes[NB_BOARD_MAX]; // Number of available modes
  138. ULONG NumberOfValidModes[NB_BOARD_MAX];
  139. // Number of valid modes
  140. ULONG ModeFlags2D[NB_BOARD_MAX]; // 2D modes supported by each board
  141. ULONG ModeFlags3D[NB_BOARD_MAX]; // 3D modes supported by each board
  142. USHORT ModeFreqs[NB_BOARD_MAX][64]; // Refresh rates bit fields
  143. UCHAR ModeList[NB_BOARD_MAX][64]; // Valid hardware modes list
  144. HwModeData *pMgaHwModes[NB_BOARD_MAX]; // Array of mode information structs.
  145. BOOLEAN bUsingInt10; // May need this later
  146. PVOID KernelModeMappedBaseAddress[NB_BOARD_MAX];
  147. // Kern-mode virt addr base of MGA regs
  148. PVOID UserModeMappedBaseAddress[NB_BOARD_MAX];
  149. // User-mode virt addr base of MGA regs
  150. PVOID MappedAddress[]; // NUM_MGA_COMMON_ACCESS_RANGES elements
  151. } MGA_DEVICE_EXTENSION, *PMGA_DEVICE_EXTENSION;
  152. #define TITAN_SEQ_ADDR_PORT (PVOID) ((ULONG_PTR)(((PMGA_DEVICE_EXTENSION)pMgaDeviceExtension)->MappedAddress[2]) + (0x3c4 - 0x3c0))
  153. #define TITAN_SEQ_DATA_PORT (PVOID) ((ULONG_PTR)(((PMGA_DEVICE_EXTENSION)pMgaDeviceExtension)->MappedAddress[2]) + (0x3c5 - 0x3c0))
  154. #define TITAN_GCTL_ADDR_PORT (PVOID) ((ULONG_PTR)(((PMGA_DEVICE_EXTENSION)pMgaDeviceExtension)->MappedAddress[2]) + (0x3ce - 0x3c0))
  155. #define TITAN_GCTL_DATA_PORT (PVOID) ((ULONG_PTR)(((PMGA_DEVICE_EXTENSION)pMgaDeviceExtension)->MappedAddress[2]) + (0x3cf - 0x3c0))
  156. #define TITAN_1_CRTC_ADDR_PORT (PVOID) ((ULONG_PTR)(((PMGA_DEVICE_EXTENSION)pMgaDeviceExtension)->MappedAddress[3]) + (0x3d4 - 0x3d4))
  157. #define TITAN_1_CRTC_DATA_PORT (PVOID) ((ULONG_PTR)(((PMGA_DEVICE_EXTENSION)pMgaDeviceExtension)->MappedAddress[3]) + (0x3d5 - 0x3d4))
  158. //#define ADDR_46E8_PORT (PVOID) ((ULONG_PTR)(((PMGA_DEVICE_EXTENSION)pMgaDeviceExtension)->MappedAddress[5]) + (0x46e8 - 0x46e8))
  159. #define ADDR_46E8_PORT 0x46e8
  160. #endif
  161. /* Debug */
  162. /*-------------- Start of extern global variables -----------------------*/
  163. extern dword MgaSel;
  164. extern volatile byte _Far* pMgaBaseAddr;
  165. extern HwData Hw[];
  166. extern byte iBoard;
  167. extern byte InitBuf[NB_BOARD_MAX][INITBUF_S];
  168. extern byte VideoBuf[NB_BOARD_MAX][VIDEOBUF_S];
  169. extern word mtxVideoMode;
  170. #if 0
  171. /*VIDEOPRO*/
  172. extern bool VAFCconnector;
  173. extern bool initVideoPro(byte mode, byte dactype);
  174. #endif
  175. extern void MGASysInit(byte *);
  176. extern void MGAVidInit(byte *, byte *);
  177. #ifdef OS2
  178. extern volatile byte _Far *setmgasel(dword MgaSel, dword phyadr, word limit);
  179. #else
  180. extern volatile byte _Far *setmgasel(dword MgaSel, dword phyadr, dword limit);
  181. #endif
  182. /*--------------- end of extern global variables ------------------------*/
  183. #ifdef WINDOWS
  184. extern dword ValMSec;
  185. #endif
  186. /*----------------------start of local Variables ---------------------------*/
  187. /* Dac VGA */
  188. static PixMap cursorStat = {0,0,0,0x102,0};
  189. byte saveBitOperation = 0;
  190. bool isVLBFlag = 0; /* OS2 needs this variable Global */
  191. /*---------------------- End of Local variables ----------------------------*/
  192. /*
  193. static void testFifo(word count)
  194. {
  195. word FifoCount;
  196. FifoCount = 0;
  197. while (FifoCount < count)
  198. {
  199. FifoCount = 64;
  200. mgaReadBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_FIFOSTATUS), FifoCount);
  201. }
  202. }
  203. */
  204. static dword rdTitanReg(word reg)
  205. {
  206. dword dat;
  207. mgaReadDWORD(*(pMgaBaseAddr + TITAN_OFFSET + (reg)), dat);
  208. return dat;
  209. }
  210. static void wrTitanReg(word reg, dword mask, dword donnee)
  211. {
  212. dword tmp;
  213. if (mask != 0xffffffff)
  214. {
  215. mgaReadDWORD(*(pMgaBaseAddr + TITAN_OFFSET + (reg)), tmp);
  216. donnee = (tmp & ~mask) | donnee;
  217. }
  218. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + (reg)), donnee);
  219. }
  220. static byte rdDacReg(word reg)
  221. {
  222. byte dat;
  223. mgaReadBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + (reg)), dat);
  224. return dat;
  225. }
  226. static void wrDacReg(word reg, byte mask, byte donnee)
  227. {
  228. byte tmp;
  229. if (mask != 0xff)
  230. {
  231. mgaReadBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + (reg)), tmp);
  232. donnee = (tmp & ~mask) | donnee;
  233. }
  234. mgaWriteBYTE(*(pMgaBaseAddr + (long)RAMDAC_OFFSET + (reg)), donnee);
  235. }
  236. static byte rdDubicDReg(word reg)
  237. {
  238. byte tmp;
  239. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + (reg)), tmp);
  240. return tmp;
  241. }
  242. static void wrDubicDReg(word reg, byte mask, byte donnee)
  243. {
  244. byte tmp;
  245. if (mask != 0xff)
  246. {
  247. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + (reg)), tmp);
  248. donnee = (tmp & ~mask) | donnee;
  249. }
  250. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + (reg)), donnee);
  251. }
  252. static dword rdDubicIReg(word reg)
  253. {
  254. dword tmp;
  255. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), (byte)reg);
  256. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[0]);
  257. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[1]);
  258. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[2]);
  259. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[3]);
  260. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 8);
  261. return tmp;
  262. }
  263. void wrDubicIReg(word reg, dword mask, dword donnee)
  264. {
  265. dword tmp;
  266. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), (byte)reg);
  267. if (mask != 0xffffffff)
  268. {
  269. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[0]);
  270. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[1]);
  271. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[2]);
  272. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), ((byte *)&tmp)[3]);
  273. donnee = (tmp & ~mask) | donnee;
  274. }
  275. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), (byte)reg);
  276. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA),((byte *)&donnee)[0]);
  277. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA),((byte *)&donnee)[1]);
  278. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA),((byte *)&donnee)[2]);
  279. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA),((byte *)&donnee)[3]);
  280. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 8);
  281. }
  282. void delay_us(dword delai) /* delai = number of microseconds */
  283. {
  284. #ifdef WINDOWS_NT
  285. VideoPortStallExecution(delai);
  286. #else
  287. #ifdef OS2
  288. DosSleep((unsigned long)delai / 1000L);
  289. #else
  290. #ifdef WINDOWS
  291. {
  292. dword _Far *tick = MAKELP(0x40, 0x6c);
  293. unsigned long t;
  294. _asm{ pushf
  295. sti } /* enable the interrupt because of a hang bug */
  296. if(delai < 55000L)
  297. t = (delai * (ValMSec /100L)) / 550L;
  298. else
  299. t = (delai / 550L) * (ValMSec/100);
  300. /*** Wait a moment (based on the loop in mtxinit.c) ***/
  301. while(t && *tick)
  302. t --;
  303. _asm popf
  304. }
  305. #else
  306. clock_t start;
  307. delai = delai / 1000; /* Convert in millisecond */
  308. delai = delai / 55; /* delai become now a number of tick */
  309. if(delai == 0)
  310. delai = 1;
  311. start = clock();
  312. while ((clock() - start) < delai);
  313. #endif
  314. #endif
  315. #endif
  316. }
  317. /*----------------------- VLB Support -----------------------------------------*/
  318. bool mtxSetVLB(dword sel)
  319. {
  320. word i, c;
  321. char id[] = "_VB";
  322. volatile byte _Far* pMgaBiosAddr;
  323. isVLBFlag = mtxOK;
  324. #ifdef WINDOWS_NT
  325. if ((pMgaBiosAddr = pMgaBiosVl) == NULL)
  326. #else
  327. if ((pMgaBiosAddr = setmgasel(MgaSel, BIOS_VL, 4)) == NULL)
  328. #endif
  329. {
  330. isVLBFlag = mtxFAIL;
  331. }
  332. else
  333. {
  334. for(i = 0; i <= strlen(id) ; i++)
  335. {
  336. mgaReadBYTE(*(pMgaBiosAddr + BIOS_ID_OFF + i), c);
  337. if (c != id[i])
  338. {
  339. isVLBFlag = mtxFAIL;
  340. break;
  341. }
  342. }
  343. }
  344. return isVLBFlag;
  345. }
  346. bool mtxIsVLBBios()
  347. {
  348. return ( isVLBFlag );
  349. }
  350. bool mtxIsVLB ()
  351. {
  352. dword val_id;
  353. if ( isVLBFlag && Hw[iBoard].VGAEnable )
  354. return mtxOK;
  355. mgaReadDWORD(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_REV),val_id);
  356. return (isVLBFlag && !( (val_id & (~TITAN_CHIPREV_M)) == TITAN_ID));
  357. }
  358. void mtxMapVLBSpace()
  359. {
  360. if ( mtxIsVLB() )
  361. {
  362. #ifndef WINDOWS_NT
  363. _outp(0x46e8, 0x00);
  364. #else
  365. _outp(ADDR_46E8_PORT, 0x00);
  366. #endif
  367. if (Hw[iBoard].MapAddress == MGA_ISA_BASE_1)
  368. mgaWriteDWORD(*(pMgaBaseAddr + 0x2010), 0x000ac000);
  369. }
  370. }
  371. void mtxUnMapVLBSpace()
  372. {
  373. if ( mtxIsVLB() )
  374. {
  375. if (Hw[iBoard].MapAddress == MGA_ISA_BASE_1)
  376. mgaWriteDWORD(*(pMgaBaseAddr + 0x2010), 0x800ac000);
  377. #ifndef WINDOWS_NT
  378. _outp(0x46e8, 0x08);
  379. #else
  380. _outp(ADDR_46E8_PORT, 0x08);
  381. #endif
  382. }
  383. }
  384. bool mtxCheckVgaEn()
  385. {
  386. mtxMapVLBSpace();
  387. if (rdTitanReg(TITAN_CONFIG) & TITAN_VGAEN_M)
  388. {
  389. mtxUnMapVLBSpace();
  390. return mtxOK;
  391. }
  392. else
  393. return mtxFAIL;
  394. }
  395. static bool checkCursorEn()
  396. {
  397. byte stat;
  398. stat = 0;
  399. switch(Hw[iBoard].DacType)
  400. {
  401. case BT482:
  402. /*-- Permits the access to Extented register */
  403. wrDacReg(BT482_WADR_PAL, 0xff, BT482_CUR_REG); /* points to Cursor register */
  404. stat = rdDacReg(BT482_PIX_RD_MSK) & BT482_CUR_MODE_M;
  405. break;
  406. case BT485:
  407. case PX2085:
  408. stat = rdDacReg(BT485_CMD_REG2) & BT485_CUR_MODE_M;
  409. break;
  410. case VIEWPOINT:
  411. wrDacReg(VPOINT_INDEX, 0xff, VPOINT_CUR_CTL);
  412. stat = rdDacReg(VPOINT_DATA) & 0x40;
  413. break;
  414. }
  415. return stat;
  416. }
  417. /*------------------------------------------------
  418. * setVgaMode
  419. *
  420. * Call VGA bios for select video mode
  421. *
  422. *
  423. * Return: nothing
  424. *------------------------------------------------*/
  425. static void setVgaMode(word mode)
  426. {
  427. //[dlee] Modified for Windows NT - can't call _int86...
  428. #ifdef WINDOWS_NT
  429. #ifndef MGA_ALPHA
  430. // VIDEO_X86_BIOS_ARGUMENTS BiosArguments;
  431. //
  432. // BiosArguments.Eax = mode;
  433. // BiosArguments.Ebx = 0;
  434. // BiosArguments.Ecx = 0;
  435. // BiosArguments.Edx = 0;
  436. // BiosArguments.Esi = 0;
  437. // BiosArguments.Edi = 0;
  438. // BiosArguments.Ebp = 0;
  439. //
  440. // VideoPortInt10(pMgaDeviceExtension, &BiosArguments);
  441. //
  442. #else /* #ifndef MGA_ALPHA */
  443. #ifdef MGA_WINNT35
  444. // Try this for Alpha/3.5
  445. // setupVga();
  446. #endif
  447. #endif /* #ifndef MGA_ALPHA */
  448. #else /* #ifdef WINDOWS_NT */
  449. #ifdef OS2
  450. setupVga();
  451. #else
  452. union _REGS r;
  453. #ifdef __WATCOMC__
  454. r.w.ax = mode;
  455. #else
  456. r.x.ax = mode;
  457. #endif
  458. _int86(0x10, &r, &r);
  459. #endif
  460. #endif /* #ifdef WINDOWS_NT */
  461. }
  462. /*
  463. static void compareDac()
  464. {
  465. word i;
  466. wrDacReg(BT485_RADR_PAL,0xff,00);
  467. for(i = 0; i < 0x100; i ++)
  468. {
  469. DacVga[i][0] = rdDacReg(BT485_COL_PAL);
  470. DacVga[i][1] = rdDacReg(BT485_COL_PAL);
  471. DacVga[i][2] = rdDacReg(BT485_COL_PAL);
  472. }
  473. for(i = 0; i < 0x100; i ++)
  474. {
  475. if ( (DacVga[i][0] != vgaDac[i].r) ||
  476. (DacVga[i][1] != vgaDac[i].g) ||
  477. (DacVga[i][2] != vgaDac[i].b)
  478. )
  479. {
  480. printf ("Erreur DAC index %02x Ecrit[%02x %02x %02x] Lue[%02x %02x %02x]\n",
  481. i,
  482. vgaDac[i].r,vgaDac[i].g,vgaDac[i].b,
  483. DacVga[i][0],DacVga[i][1],DacVga[i][2]
  484. );
  485. }
  486. }
  487. }
  488. */
  489. #ifdef WINDOWS_NT
  490. void restoreVga()
  491. #else
  492. static void restoreVga()
  493. #endif
  494. {
  495. word i;
  496. wrDacReg(BT485_WADR_PAL,0xff,00);
  497. for(i = 0; i < 0x100; i ++)
  498. {
  499. #ifdef WINDOWS_NT
  500. wrDacReg(BT485_COL_PAL, 0xff, (byte) vgaDac[i].r);
  501. wrDacReg(BT485_COL_PAL, 0xff, (byte) vgaDac[i].g);
  502. wrDacReg(BT485_COL_PAL, 0xff, (byte) vgaDac[i].b);
  503. #else
  504. wrDacReg(BT485_COL_PAL, 0xff, (byte)vgaDac[i].r);
  505. wrDacReg(BT485_COL_PAL, 0xff, (byte)vgaDac[i].g);
  506. wrDacReg(BT485_COL_PAL, 0xff, (byte)vgaDac[i].b);
  507. #endif
  508. }
  509. }
  510. /* Works only if board is in mode terminator */
  511. static void blankEcran(bool b)
  512. {
  513. byte TmpByte;
  514. if ( mtxCheckVgaEn() ) /* Acces IO (mode VGA) */
  515. {
  516. if (b) /* Blank the screen */
  517. {
  518. #ifndef WINDOWS_NT
  519. _outp(TITAN_SEQ_ADDR, 0x01);
  520. TmpByte = _inp(TITAN_SEQ_DATA);
  521. TmpByte |= 0x20; /* screen off */
  522. _outp(TITAN_SEQ_DATA, TmpByte);
  523. #else
  524. _outp(TITAN_SEQ_ADDR_PORT, 0x01);
  525. TmpByte = _inp(TITAN_SEQ_DATA_PORT);
  526. TmpByte |= 0x20; /* screen off */
  527. _outp(TITAN_SEQ_DATA_PORT, TmpByte);
  528. #endif
  529. }
  530. else /* Unblank the screen */
  531. {
  532. #ifndef WINDOWS_NT
  533. _outp(TITAN_SEQ_ADDR, 0x01);
  534. TmpByte = _inp(TITAN_SEQ_DATA);
  535. TmpByte &= 0xdf;
  536. _outp(TITAN_SEQ_DATA, TmpByte);
  537. #else
  538. _outp(TITAN_SEQ_ADDR_PORT, 0x01);
  539. TmpByte = _inp(TITAN_SEQ_DATA_PORT);
  540. TmpByte &= 0xdf;
  541. _outp(TITAN_SEQ_DATA_PORT, TmpByte);
  542. #endif
  543. }
  544. }
  545. else /* Memory Access (mode terminator) */
  546. {
  547. if (b) /* Blank the screen */
  548. {
  549. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_SEQ_ADDR), 0x01);
  550. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_SEQ_DATA), TmpByte);
  551. TmpByte |= 0x20; /* screen off */
  552. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_SEQ_DATA), TmpByte);
  553. }
  554. else /* Unblank the screen */
  555. {
  556. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_SEQ_ADDR), 0x01);
  557. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_SEQ_DATA), TmpByte);
  558. TmpByte &= 0xdf; /* screen on */
  559. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_SEQ_DATA), TmpByte);
  560. }
  561. }
  562. }
  563. /*------------------------------------------------
  564. * mgaVL_AC00
  565. *
  566. * Check the BIOS id for VL BUS if we use the special mapping AC00
  567. *
  568. *
  569. * Return: 1 if VL BUS at AC00
  570. *------------------------------------------------*/
  571. static int mgaVL_AC00()
  572. {
  573. int i;
  574. char c;
  575. int retValue = 0;
  576. char id[] = "_VL";
  577. volatile byte _Far* pMgaBiosAddr;
  578. if (Hw[iBoard].MapAddress == MGA_ISA_BASE_1)
  579. {
  580. #ifdef WINDOWS_NT
  581. if ((pMgaBiosAddr = pMgaBiosVl) == NULL)
  582. #else
  583. if ((pMgaBiosAddr = setmgasel(MgaSel, BIOS_VL, 4)) == NULL)
  584. #endif
  585. {
  586. retValue = 0;
  587. }
  588. else
  589. {
  590. for(retValue = 1, i = 0; i < 3; i++)
  591. {
  592. mgaReadBYTE(*(pMgaBiosAddr + BIOS_ID_OFF + i), c);
  593. if (c != id[i])
  594. {
  595. retValue = 0;
  596. break;
  597. }
  598. }
  599. // #ifdef WINDOWS_NT
  600. // pMgaBaseAddr = Hw[iBoard].BaseAddress;
  601. // #else
  602. // if ((pMgaBaseAddr = setmgasel(MgaSel, MGA_ISA_BASE_1, 4)) == NULL)
  603. // {
  604. // retValue = 0;
  605. // }
  606. // #endif
  607. }
  608. }
  609. return retValue;
  610. }
  611. /*------------------------------------------------
  612. * isPciBus
  613. *
  614. *
  615. * Return: mtxOK if PCI bus
  616. *------------------------------------------------*/
  617. bool isPciBus()
  618. {
  619. return ((Hw[iBoard].ProductRev >> 4 ) & 0x0f) &&
  620. (rdTitanReg(TITAN_CONFIG) & (dword)TITAN_PCI_M);
  621. }
  622. /*------------------------------------------------
  623. * isaToWide
  624. *
  625. * Go in wide bus and disable VGA
  626. *
  627. * Note : If we are at adresse AC00 use a special
  628. * sequence to disable VGA.
  629. *
  630. * Return: nothing
  631. *------------------------------------------------*/
  632. static void isaToWide()
  633. {
  634. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_RST), TITAN_SOFTRESET_CLR);
  635. delay_us(2);
  636. /* Special procedure for adresse AC00 */
  637. if (Hw[iBoard].MapAddress == MGA_ISA_BASE_1)
  638. {
  639. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_TEST + 3), 0x8d);
  640. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_CONFIG + 3), 0x01);
  641. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_CONFIG), 0x00);
  642. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_TEST + 3), 0x00);
  643. delay_us(1);
  644. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_CONFIG + 1), 0x00);
  645. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_CONFIG), 0x01000300);
  646. }
  647. else
  648. {
  649. wrTitanReg(TITAN_TEST, ROBITWREN_M, SETROBITWREN);
  650. wrTitanReg(TITAN_CONFIG,TITAN_ISA_M, TITAN_ISA_WIDE_BUS);
  651. delay_us(1);
  652. wrTitanReg(TITAN_TEST, ROBITWREN_M, CLRROBITWREN);
  653. wrTitanReg(TITAN_CONFIG, TITAN_VGAEN_M, 0);
  654. }
  655. }
  656. /*------------------------------------------------
  657. * wideToIsa
  658. *
  659. * Go in ISA mode and enable VGA
  660. *
  661. * Note : If we are at adresse AC00 use a special
  662. * sequence to enable VGA.
  663. *
  664. * Return: nothing
  665. *------------------------------------------------*/
  666. static void wideToIsa()
  667. {
  668. #if (defined (WINDOWS) || defined (OS2)|| defined(__MICROSOFTC600__))
  669. dword configAddr; /* Use only for windows */
  670. #endif
  671. /* Remove Soft Reset */
  672. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_RST), TITAN_SOFTRESET_CLR);
  673. delay_us(2);
  674. /* Unlock acces to ISA/WIDE field */
  675. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_TEST + 3), 0x8d);
  676. /* Note : For a VL card at base adress AC00, the acces to the CONFIG
  677. register must be 32 bits. For the make SXCIEXT.DLL, we use
  678. the microsoft 16bit C/C++ 7.0 compiler. Whit C/C++ 7.0,
  679. a 32 bits acces is broke in two 16 bits acces, we must use
  680. an inline assembler programme to make a 32 bit acces.
  681. */
  682. #if(!defined(WINDOWS) && !defined(OS2))
  683. wrTitanReg(TITAN_CONFIG,TITAN_ISA_M | TITAN_VGAEN_M | TITAN_BIOSEN_M,
  684. TITAN_ISA_ISA_BUS| TITAN_VGAEN_M | TITAN_BIOSEN_M);
  685. #else
  686. if (Hw[iBoard].MapAddress == MGA_ISA_BASE_1)
  687. {
  688. configAddr = (dword)pMgaBaseAddr + TITAN_OFFSET + TITAN_CONFIG;
  689. #ifdef OS2
  690. _asm
  691. #else
  692. __asm
  693. #endif
  694. {
  695. push es
  696. push di
  697. les di, [configAddr]
  698. ; mov eax, 11000700h
  699. _emit 066h
  700. _emit 0b8h
  701. _emit 000h
  702. _emit 007h
  703. _emit 000h
  704. _emit 011h
  705. ; stosd
  706. _emit 066h
  707. _emit 0abh
  708. pop di
  709. pop es
  710. }
  711. }
  712. else
  713. wrTitanReg(TITAN_CONFIG,TITAN_ISA_M | TITAN_VGAEN_M | TITAN_BIOSEN_M,
  714. TITAN_ISA_ISA_BUS| TITAN_VGAEN_M | TITAN_BIOSEN_M);
  715. #endif
  716. /* lock acces to ISA/WIDE field */
  717. delay_us(1);
  718. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_TEST + 3), 0x00);
  719. }
  720. /*------------------------------------------------
  721. * SetVgaEn
  722. *
  723. * Initialise all the MGA register for the VGA mode
  724. *
  725. *
  726. * Return: nothing
  727. *------------------------------------------------*/
  728. #ifdef WINDOWS_NT
  729. void SetVgaEn()
  730. #else
  731. static void SetVgaEn()
  732. #endif
  733. {
  734. dword mask, donnee;
  735. byte reg, tmpByte;
  736. mtxMapVLBSpace();
  737. cursorStat.Width = Hw[iBoard].cursorInfo.CurWidth;
  738. cursorStat.Height = (word)checkCursorEn();
  739. /*--------------------------- Blank Screen ---------------------------------*/
  740. blankEcran(1);
  741. #ifdef OS2
  742. if(Hw[iBoard].DacType == TVP3026)
  743. {
  744. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_AUX_ADDR), AUX_INPUT_1);
  745. mgaReadBYTE( *(pMgaBaseAddr + TITAN_OFFSET + TITAN_AUX_DATA), tmpByte);
  746. vmode = getVgaMode();
  747. if ( (vmode < 4) || (vmode == 7) )
  748. {
  749. /* 28 Mhz */
  750. if (tmpByte & HI_REFRESH_M)
  751. setTVP3026Freq(pMgaBaseAddr, 40400, 2, 0);
  752. else
  753. setTVP3026Freq(pMgaBaseAddr, 28636, 2, 0);
  754. }
  755. else /* 25 Mhz */
  756. {
  757. if (tmpByte & HI_REFRESH_M)
  758. setTVP3026Freq(pMgaBaseAddr, 36000, 2, 0);
  759. else
  760. setTVP3026Freq(pMgaBaseAddr, 25057, 2, 0);
  761. }
  762. }
  763. #endif
  764. /*------------------------ Host vgaen inactif ------------------------------*/
  765. /* to be sure that the VGA registers are accessible */
  766. wrTitanReg(TITAN_CONFIG, TITAN_VGAEN_M, 0);
  767. /* -- We select the VGA clock (else it could be to high for the
  768. VGA section
  769. */
  770. //mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_MISC_OUT_W), 0x67);
  771. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_MISC_OUT_W), ucMisc);
  772. /* reset extended crtc start address */
  773. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_AUX_ADDR), 0x0a);
  774. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_AUX_DATA), 0x80);
  775. /*--------------------------------------------------------------------------*/
  776. /* Remove all synch */
  777. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_ADDR), 0x11);
  778. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_DATA), 0x40);
  779. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_ADDR), 0x01); /* -- Kill synch -- */
  780. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_DATA), 0x00);
  781. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_ADDR), 0x00);
  782. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_DATA), 0x00);
  783. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_ADDR), 0x06);
  784. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_1_CRTC_DATA), 0x00);
  785. /*--------------------------------------------------------------------------*/
  786. /*------ reset exterm hsync and vsync polarity (no inversion ------*/
  787. if(Hw[iBoard].DacType == VIEWPOINT)
  788. {
  789. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + VPOINT_INDEX), VPOINT_GEN_CTL);
  790. mgaReadBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + VPOINT_DATA), tmpByte);
  791. /* Put hsync = negative, vsync = negative */
  792. tmpByte = tmpByte & 0xfc;
  793. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + VPOINT_INDEX), VPOINT_GEN_CTL);
  794. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + VPOINT_DATA), tmpByte);
  795. }
  796. else
  797. if(Hw[iBoard].DacType == TVP3026)
  798. {
  799. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + TVP3026_INDEX), TVP3026_GEN_CTL);
  800. mgaReadBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + TVP3026_DATA), tmpByte);
  801. /* Put hsync = negative, vsync = negative */
  802. tmpByte = tmpByte & 0xfc;
  803. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + TVP3026_INDEX), TVP3026_GEN_CTL);
  804. mgaWriteBYTE(*(pMgaBaseAddr + RAMDAC_OFFSET + TVP3026_DATA), tmpByte);
  805. }
  806. else
  807. {
  808. mgaReadBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_CONFIG + 2), tmpByte);
  809. tmpByte |= 1; /* Expansion device available <16> of CONFIG */
  810. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_CONFIG + 2), tmpByte);
  811. mgaWriteBYTE(*(pMgaBaseAddr + EXPDEV_OFFSET), 0 );
  812. }
  813. /*--------------------------------------------------------------------------*/
  814. /*--------------- Disable interrupt Genere By Dubic --------------------*/
  815. /* The index pointer of the DUBIC must have the value 8 before
  816. we acces the direct register
  817. */
  818. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 8);
  819. /* We save the value of the DUBIC register 0 and we disable the mouse
  820. (or laser) interrupt
  821. */
  822. reg = rdDubicDReg(DUBIC_DUB_SEL);
  823. wrDubicDReg(DUBIC_DUB_SEL, 0xff, 0x40);
  824. /*--------------------------------------------------------------------------*/
  825. /*------------------------ Start programming of DUBIC --------------------*/
  826. /* We don't touch to this DAC type */
  827. mask = ~(
  828. (dword)DUBIC_DACTYPE_M |
  829. (dword)DUBIC_LVID_M
  830. );
  831. if (rdDubicIReg(DUBIC_DUB_CTL2) & DUBIC_LASEREN_M) /* SRATE */
  832. donnee = (dword)LASER_SRATE << DUBIC_SRATE_A; /* LASER */
  833. else
  834. donnee = (dword)MOUSE_SRATE << DUBIC_SRATE_A ; /* MOUSE */
  835. donnee |= (dword)DUBIC_BLANKDEL_M;
  836. wrDubicIReg(DUBIC_DUB_CTL, mask , donnee);
  837. /*--------------------------------------------------------------------------*/
  838. /*---------------------------- Place DAC in VGA mode -----------------------*/
  839. switch(Hw[iBoard].DacType)
  840. {
  841. case BT482:
  842. wrDacReg(BT482_CMD_REGA, 0xff, 1);
  843. wrDacReg(BT482_WADR_PAL, 0xff,BT482_CMD_REGB);
  844. wrDacReg(BT482_PIX_RD_MSK, 0xff,0x00); /* command reg B = 00h */
  845. wrDacReg(BT482_WADR_PAL, 0xff,BT482_CUR_REG);
  846. wrDacReg(BT482_PIX_RD_MSK, 0xff,0x10); /* command reg Cur = 10h (interlace)*/
  847. wrDacReg(BT482_CMD_REGA, 0xff,0);
  848. break;
  849. case BT485:
  850. case PX2085:
  851. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR),DUBIC_DUB_CTL2);
  852. mgaReadBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA), tmpByte);
  853. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR),DUBIC_DUB_CTL2);
  854. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_DATA),tmpByte | DUBIC_LDCLKEN_M);
  855. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 8);
  856. wrDacReg(BT485_CMD_REG0,0xff, 0x80); /* access sequence cmd 3 */
  857. wrDacReg(BT485_WADR_PAL,0xff, 0x01);
  858. wrDacReg(BT485_CMD_REG1,0xff, 0);
  859. wrDacReg(BT485_CMD_REG2,0xff, 0);
  860. wrDacReg(BT485_CMD_REG3,0xff, 0);
  861. wrDacReg(BT485_CMD_REG0,0xff, 0x00); /* access sequence cmd 3 */
  862. break;
  863. case VIEWPOINT:
  864. /* Software reset to put the DAC in a default state */
  865. wrDacReg(VPOINT_INDEX,0xff, VPOINT_RESET);
  866. wrDacReg(VPOINT_DATA,0xff, 0x00 );
  867. wrDacReg(VPOINT_INDEX, 0xff, VPOINT_GEN_CTL);
  868. wrDacReg(VPOINT_DATA, 0xff, 00);
  869. /* Change DUBIC CTL2 */
  870. wrDubicIReg(DUBIC_DUB_CTL2, (dword)0x40 , 0);
  871. break;
  872. case TVP3026:
  873. /* Software reset to put the DAC in a default state */
  874. wrDacReg(TVP3026_INDEX,0xff, TVP3026_GEN_IO_CTL);
  875. wrDacReg(TVP3026_DATA,0xff, 0x01 );
  876. wrDacReg(TVP3026_INDEX,0xff, TVP3026_GEN_IO_DATA);
  877. wrDacReg(TVP3026_DATA,0xff, 0x01 );
  878. wrDacReg(TVP3026_INDEX,0xff, TVP3026_MISC_CTL);
  879. wrDacReg(TVP3026_DATA,0xff, 0x04 );
  880. wrDacReg(TVP3026_INDEX, 0xff, TVP3026_GEN_CTL);
  881. wrDacReg(TVP3026_DATA, 0xff, 00);
  882. wrDacReg(TVP3026_INDEX, 0xff, TVP3026_CLK_SEL);
  883. wrDacReg(TVP3026_DATA, 0xff, 00);
  884. wrDacReg(TVP3026_INDEX, 0xff, TVP3026_TRUE_COLOR_CTL);
  885. wrDacReg(TVP3026_DATA, 0xff, 0x80);
  886. wrDacReg(TVP3026_INDEX, 0xff, TVP3026_MUX_CTL);
  887. wrDacReg(TVP3026_DATA, 0xff, 0x98);
  888. wrDacReg(TVP3026_INDEX, 0xff, TVP3026_MCLK_CTL);
  889. wrDacReg(TVP3026_DATA, 0xff, 0x18);
  890. /* Change DUBIC CTL2 */
  891. wrDubicIReg(DUBIC_DUB_CTL2, (dword)0x40 , 0);
  892. break;
  893. }
  894. /*--------------------------------------------------------------------------*/
  895. /* Softreset ON */
  896. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_RST), TITAN_SOFTRESET_SET);
  897. delay_us(2);
  898. /*-------------------------- Host vgaen actif ------------------------------*/
  899. if ( !isPciBus() && (Hw[iBoard].ProductType & BOARD_MGA_VL_M) == BOARD_MGA_VL)
  900. wideToIsa(); /* This function put also the mga in VGA mode */
  901. else
  902. {
  903. wrTitanReg(TITAN_CONFIG, TITAN_VGAEN_M, TITAN_VGAEN_M);
  904. }
  905. wrDubicIReg(DUBIC_DUB_CTL, DUBIC_VGA_EN_M , DUBIC_VGA_EN_M);
  906. /*--------------------------------------------------------------------------*/
  907. /*---------------------------- SoftReset inactif ---------------------------*/
  908. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_RST), TITAN_SOFTRESET_CLR);
  909. delay_us(2);
  910. /*--------------------------------------------------------------------------*/
  911. /*------------------------ Restore interrupt du DUBIC --------------------*/
  912. wrDubicDReg(DUBIC_DUB_SEL, 0xff, reg);
  913. /*--------------------------------------------------------------------------*/
  914. /*----------------- Special case where we use MGA_ISA_BASE_1 ---------------*/
  915. if ( !isPciBus() &&
  916. ((Hw[iBoard].ProductType & BOARD_MGA_VL_M) != BOARD_MGA_VL) &&
  917. (Hw[iBoard].MapAddress == MGA_ISA_BASE_1)
  918. )
  919. {
  920. /* if vga boots vga 8 bit, force access 8 bit and enable bios */
  921. if ( (saveBitOperation & 3) == 0 )
  922. {
  923. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_CONFIG), tmpByte);
  924. tmpByte &= ~(byte)TITAN_CONFIG_M;
  925. tmpByte |= TITAN_CONFIG_8;
  926. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_CONFIG), tmpByte);
  927. wrTitanReg(TITAN_CONFIG, TITAN_BIOSEN_M, TITAN_BIOSEN_M);
  928. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_CONFIG), tmpByte);
  929. }
  930. }
  931. /*--------------------------------------------------------------------------*/
  932. #ifndef WINDOWS_NT
  933. _outp(TITAN_SEQ_ADDR, 0x00); /* -- Stop VGA sequenceur --- */
  934. _outp(TITAN_SEQ_DATA, 0x03);
  935. _outp(TITAN_GCTL_ADDR, 0x06);
  936. _outp(TITAN_GCTL_DATA, ucGctl6);
  937. _outp(TITAN_1_CRTC_ADDR, 0x11); /* -- Unlock CRTC register -- */
  938. _outp(TITAN_1_CRTC_DATA, (byte)(ucCrtc11 & 0x7f));
  939. _outp(TITAN_1_CRTC_ADDR, 0x01);
  940. _outp(TITAN_1_CRTC_DATA, ucCrtc1);
  941. _outp(TITAN_1_CRTC_ADDR, 0x00);
  942. _outp(TITAN_1_CRTC_DATA, ucCrtc0);
  943. _outp(TITAN_1_CRTC_ADDR, 0x06);
  944. _outp(TITAN_1_CRTC_DATA, ucCrtc6);
  945. _outp(TITAN_1_CRTC_ADDR, 0x11); /* -- Restore CRTC register -- */
  946. _outp(TITAN_1_CRTC_DATA, ucCrtc11);
  947. // _outp(TITAN_GCTL_ADDR, ucGctlIndx);
  948. #else
  949. _outp(TITAN_SEQ_ADDR_PORT, 0x00); /* -- Stop VGA sequenceur --- */
  950. _outp(TITAN_SEQ_DATA_PORT, 0x03);
  951. _outp(TITAN_GCTL_ADDR_PORT, 0x06);
  952. _outp(TITAN_GCTL_DATA_PORT, ucGctl6);
  953. _outp(TITAN_1_CRTC_ADDR_PORT, 0x11); /* -- Unlock CRTC register -- */
  954. _outp(TITAN_1_CRTC_DATA_PORT, (byte)(ucCrtc11 & 0x7f));
  955. _outp(TITAN_1_CRTC_ADDR_PORT, 0x01);
  956. _outp(TITAN_1_CRTC_DATA_PORT, ucCrtc1);
  957. _outp(TITAN_1_CRTC_ADDR_PORT, 0x00);
  958. _outp(TITAN_1_CRTC_DATA_PORT, ucCrtc0);
  959. _outp(TITAN_1_CRTC_ADDR_PORT, 0x06);
  960. _outp(TITAN_1_CRTC_DATA_PORT, ucCrtc6);
  961. _outp(TITAN_1_CRTC_ADDR_PORT, 0x11); /* -- Restore CRTC register -- */
  962. _outp(TITAN_1_CRTC_DATA_PORT, ucCrtc11);
  963. // _outp(TITAN_GCTL_ADDR_PORT, ucGctlIndx);
  964. #endif
  965. /*-------------------------- Restore VGA mode ------------------------------*/
  966. mtxUnMapVLBSpace();
  967. setVgaMode(3);
  968. #ifndef WINDOWS_NT
  969. restoreVga(); /* Dac */
  970. #endif
  971. /*--------------------------------------------------------------------------*/
  972. /*--------------------------- UnBlank Screen ---------------------------------*/
  973. blankEcran(0);
  974. /*--------------------------------------------------------------------------*/
  975. }
  976. /*------------------------------------------------
  977. * SetVgaDis
  978. *
  979. * Initialize all the MGA register for the TERMINATOR mode
  980. *
  981. *
  982. * Return: nothing
  983. *------------------------------------------------*/
  984. static void SetVgaDis()
  985. {
  986. byte reg, tmpByte;
  987. int vlBiosId = 0;
  988. /*--------------------------- Blank Screen ---------------------------------*/
  989. blankEcran(1);
  990. /*--------------------------------------------------------------------------*/
  991. /*------------------ Save Vga and validate addresse Terminator ---------------*/
  992. #ifndef WINDOWS_NT
  993. // ucGctlIndx = _inp(TITAN_GCTL_ADDR);
  994. _outp(TITAN_GCTL_ADDR, 0x06);
  995. ucGctl6 = _inp(TITAN_GCTL_DATA);
  996. _outp(TITAN_GCTL_DATA, 0x0c); /* -- Memory map selecr 11 -- */
  997. _outp(TITAN_SEQ_ADDR, 0x00); /* -- Stop VGA sequenceur --- */
  998. _outp(TITAN_SEQ_DATA, 0x01);
  999. _outp(TITAN_1_CRTC_ADDR, 0x11); /* -- Unlock CRTC register -- */
  1000. ucCrtc11 = _inp(TITAN_1_CRTC_DATA);
  1001. _outp(TITAN_1_CRTC_DATA, (ucCrtc11 & 0x7f));
  1002. _outp(TITAN_1_CRTC_ADDR, 0x01); /* -- Kill synch -- */
  1003. ucCrtc1 = _inp(TITAN_1_CRTC_DATA);
  1004. _outp(TITAN_1_CRTC_DATA, 0x00);
  1005. _outp(TITAN_1_CRTC_ADDR, 0x00);
  1006. ucCrtc0 = _inp(TITAN_1_CRTC_DATA);
  1007. _outp(TITAN_1_CRTC_DATA, 0x00);
  1008. _outp(TITAN_1_CRTC_ADDR, 0x06);
  1009. ucCrtc6 = _inp(TITAN_1_CRTC_DATA);
  1010. _outp(TITAN_1_CRTC_DATA, 0x00);
  1011. #else
  1012. // ucGctlIndx = _inp(TITAN_GCTL_ADDR_PORT);
  1013. _outp(TITAN_GCTL_ADDR_PORT, 0x06);
  1014. ucGctl6 = _inp(TITAN_GCTL_DATA_PORT);
  1015. _outp(TITAN_GCTL_DATA_PORT, 0x0c); /* -- Memory map selecr 11 --*/
  1016. _outp(TITAN_SEQ_ADDR_PORT, 0x00); /* -- Stop VGA sequenceur --- */
  1017. _outp(TITAN_SEQ_DATA_PORT, 0x01);
  1018. _outp(TITAN_1_CRTC_ADDR_PORT, 0x11); /* -- Unlock CRTC register -- */
  1019. ucCrtc11 = _inp(TITAN_1_CRTC_DATA_PORT);
  1020. _outp(TITAN_1_CRTC_DATA_PORT, (byte)(ucCrtc11 & 0x7f));
  1021. _outp(TITAN_1_CRTC_ADDR_PORT, 0x01); /* -- Kill synch -- */
  1022. ucCrtc1 = _inp(TITAN_1_CRTC_DATA_PORT);
  1023. _outp(TITAN_1_CRTC_DATA_PORT, 0x00);
  1024. _outp(TITAN_1_CRTC_ADDR_PORT, 0x00);
  1025. ucCrtc0 = _inp(TITAN_1_CRTC_DATA_PORT);
  1026. _outp(TITAN_1_CRTC_DATA_PORT, 0x00);
  1027. _outp(TITAN_1_CRTC_ADDR_PORT, 0x06);
  1028. ucCrtc6 = _inp(TITAN_1_CRTC_DATA_PORT);
  1029. _outp(TITAN_1_CRTC_DATA_PORT, 0x00);
  1030. #endif
  1031. delay_us(8); /* time to complete stop sequenceur */
  1032. mtxMapVLBSpace();
  1033. /*--------------------------------------------------------------------------*/
  1034. /*----------------- Special case where we use MGA_ISA_BASE_1 ---------------*/
  1035. if ( !isPciBus() &&
  1036. ((Hw[iBoard].ProductType & BOARD_MGA_VL_M) != BOARD_MGA_VL) &&
  1037. (Hw[iBoard].MapAddress == MGA_ISA_BASE_1)
  1038. )
  1039. {
  1040. /* If this function is call from mtxCheckHwAll, the ProducType
  1041. unknow at this moment, we have to see in the BIOS eprom
  1042. to search for the VL ID
  1043. */
  1044. vlBiosId = mgaVL_AC00();
  1045. /* if vga 8 bit, disable bios and force acces 16 bit */
  1046. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_CONFIG), saveBitOperation);
  1047. if ( (saveBitOperation & 3) != 1 )
  1048. {
  1049. wrTitanReg(TITAN_CONFIG, TITAN_BIOSEN_M, 0);
  1050. mgaReadBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_CONFIG), tmpByte);
  1051. tmpByte &= ~(byte)TITAN_CONFIG_M;
  1052. tmpByte |= TITAN_CONFIG_16;
  1053. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET + TITAN_CONFIG), tmpByte);
  1054. }
  1055. }
  1056. /*--------------------------------------------------------------------------*/
  1057. /*---------------------------- SoftReset actif -----------------------------*/
  1058. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_RST), TITAN_SOFTRESET_SET);
  1059. delay_us(2);
  1060. /*--------------------------------------------------------------------------*/
  1061. /*------------------------ Host vgaen inactif ------------------------------*/
  1062. if ( !isPciBus() &&
  1063. (
  1064. ((Hw[iBoard].ProductType & BOARD_MGA_VL_M) == BOARD_MGA_VL ) ||
  1065. vlBiosId
  1066. )
  1067. )
  1068. {
  1069. isaToWide();
  1070. }
  1071. else
  1072. {
  1073. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_RST), TITAN_SOFTRESET_SET);
  1074. delay_us(2);
  1075. wrTitanReg(TITAN_CONFIG, TITAN_VGAEN_M, 0);
  1076. }
  1077. wrDubicIReg(DUBIC_DUB_CTL, DUBIC_VGA_EN_M , 0);
  1078. /*--------------------------------------------------------------------------*/
  1079. /*---------------------------- SoftReset inactif -----------------------------*/
  1080. mgaWriteDWORD(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_RST), TITAN_SOFTRESET_CLR);
  1081. delay_us(2);
  1082. /*--------------------------------------------------------------------------*/
  1083. /*--- vvvvv test seulement ----*/
  1084. mgaReadBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_MISC_OUT_R), ucMisc);
  1085. mgaWriteBYTE(*(pMgaBaseAddr + TITAN_OFFSET + TITAN_MISC_OUT_W), 0x27);
  1086. /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/
  1087. /*------------------------ Disable interrupt of DUBIC --------------------*/
  1088. mgaWriteBYTE(*(pMgaBaseAddr + DUBIC_OFFSET + DUBIC_NDX_PTR), 8);
  1089. reg = rdDubicDReg(DUBIC_DUB_SEL);
  1090. wrDubicDReg(DUBIC_DUB_SEL, 0xff, 0x40);
  1091. /*--------------------------------------------------------------------------*/
  1092. /*------------------------ start programming of DUBIC --------------------*/
  1093. wrDubicIReg(DUBIC_DUB_CTL, DUBIC_BLANKDEL_M | DUBIC_VGA_EN_M , 0);
  1094. /*--------------------------------------------------------------------------*/
  1095. /*------------------------ Restore interrupt of DUBIC --------------------*/
  1096. wrDubicDReg(DUBIC_DUB_SEL, 0xff, reg);
  1097. /*--------------------------------------------------------------------------*/
  1098. }
  1099. /*------------------------------------------------
  1100. * mtxSetVideoMode
  1101. *
  1102. * Select Video mode (VGA/TERMINATOR)
  1103. *
  1104. *
  1105. * Return: nothing
  1106. *------------------------------------------------*/
  1107. void mtxSetVideoMode (word mode)
  1108. {
  1109. switch(mode)
  1110. {
  1111. case mtxPASSTHRU:
  1112. #if 0
  1113. /*VIDEOPRO*/
  1114. initVideoPro(0, Hw[iBoard].DacType);
  1115. #endif
  1116. if (Hw[iBoard].VGAEnable && !mtxCheckVgaEn())
  1117. {
  1118. SetVgaEn();
  1119. mtxVideoMode = mtxPASSTHRU;
  1120. }
  1121. break;
  1122. case mtxADV_MODE:
  1123. if (mtxCheckVgaEn())
  1124. {
  1125. mgaWriteBYTE(*(pMgaBaseAddr+TITAN_OFFSET+TITAN_CONFIG+1), 0x07);
  1126. SetVgaDis();
  1127. wrDubicIReg(DUBIC_DUB_CTL,0,0);
  1128. if (Hw[iBoard].pCurrentHwMode != 0)
  1129. {
  1130. MGASysInit(InitBuf[iBoard]);
  1131. if (Hw[iBoard].pCurrentDisplayMode != 0)
  1132. {
  1133. MGAVidInit(InitBuf[iBoard], VideoBuf[iBoard]);
  1134. #if 0
  1135. /*VIDEOPRO*/
  1136. if (Hw[iBoard].pCurrentDisplayMode->DispType & 0x02)
  1137. {
  1138. if (VAFCconnector)
  1139. initVideoPro(1, PX2085);
  1140. else
  1141. initVideoPro(1, Hw[iBoard].DacType);
  1142. }
  1143. else
  1144. initVideoPro(0, Hw[iBoard].DacType);
  1145. #endif
  1146. blankEcran(0);
  1147. /* Restore Cursor visibility */
  1148. if (cursorStat.Width > 0)
  1149. {
  1150. mtxCursorSetShape(&cursorStat);
  1151. if (cursorStat.Height > 0)
  1152. mtxCursorEnable(1);
  1153. }
  1154. }
  1155. }
  1156. }
  1157. else
  1158. if ( !isPciBus() &&
  1159. ((Hw[iBoard].ProductType & BOARD_MGA_VL_M) == BOARD_MGA_VL)
  1160. ) isaToWide();
  1161. mtxVideoMode = mtxADV_MODE;
  1162. break;
  1163. }
  1164. }
  1165. #ifdef OS2
  1166. /*MTX* modified by mp on monday, 5/3/93 */
  1167. int mtxCheckMGAEnable()
  1168. {
  1169. int ret_value;
  1170. ret_value = (int)mtxVideoMode;
  1171. return(ret_value);
  1172. }
  1173. int mtxCheckVgaEnable()
  1174. {
  1175. return ((int)rdTitanReg(TITAN_CONFIG) & TITAN_VGAEN_M);
  1176. }
  1177. /*END*/
  1178. #endif
  1179. /*------------------------------------------------------
  1180. * mtxGetVideoMode
  1181. *
  1182. * Get video mode
  1183. *
  1184. * Return: - mtxVGA : mode VGA
  1185. * - mtxADV_MODE : mode high resolution
  1186. *------------------------------------------------------*/
  1187. word mtxGetVideoMode (void)
  1188. {
  1189. return (mtxVideoMode);
  1190. }