File: /usr/src/linux/drivers/video/sis/sis_301.c

1     /* Recently Update by v1.09.50 */
2     
3     #include <linux/config.h>
4     #include "sis_301.h"
5     
6     #ifndef CONFIG_FB_SIS_LINUXBIOS
7     
8     BOOLEAN SetCRT2Group(USHORT BaseAddr,ULONG ROMAddr,USHORT ModeNo,
9     			PHW_DEVICE_EXTENSION HwDeviceExtension)
10     {
11     	USHORT temp;
12     	
13     	SetFlag=SetFlag|ProgrammingCRT2;
14     	SearchModeID(ROMAddr,ModeNo);
15     
16     	temp=GetRatePtrCRT2(ROMAddr,ModeNo);
17     	if(((temp&0x02)==0) && ((VBInfo&CRT2DisplayFlag)==0))
18     		return(FALSE);
19     	SaveCRT2Info(ModeNo);	
20     	DisableBridge(BaseAddr);
21     	UnLockCRT2(BaseAddr);
22     	SetDefCRT2ExtRegs(BaseAddr);
23     	SetCRT2ModeRegs(BaseAddr,ModeNo);
24     	if(VBInfo&CRT2DisplayFlag){
25     		LockCRT2(BaseAddr);
26     		return 0;	
27     	}
28     	GetCRT2Data(ROMAddr,ModeNo);
29     	if(IF_DEF_LVDS==1){	//LVDS
30     		GetLVDSDesData(ROMAddr,ModeNo);
31     	}
32     	SetGroup1(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
33     	if(IF_DEF_LVDS==0){
34     		SetGroup2(BaseAddr,ROMAddr);		
35     		SetGroup3(BaseAddr);
36     		SetGroup4(BaseAddr,ROMAddr,ModeNo);
37     		SetGroup5(BaseAddr,ROMAddr);
38     	}else{	//LVDS
39     		if(IF_DEF_TRUMPION==0){
40     			ModCRT1CRTC(ROMAddr,ModeNo);
41     		}
42     		SetCRT2ECLK(ROMAddr,ModeNo);
43     	}
44     
45     	EnableCRT2();
46     	EnableBridge(BaseAddr);
47     	SetLockRegs();
48     	LockCRT2(BaseAddr);
49      
50     	return 1;				
51     }
52     
53     VOID overwriteregs(ULONG ROMAddr,USHORT BaseAddr)
54     {
55     	int i;
56     	USHORT	Part1Port; //reg data is for 1024x768 16bit 85hz
57     	int p1reg[0x29]={0x84,0x76,0x4B,0x21,0x00,0x00,0x00,0x00,0x1F,0x51,
58     					 0x0C,0x10,0x44,0x90,0x1E,0xFF,0x00,0x34,0x13,0x10,
59     					 0x00,0x00,0x00,0x01,0x03,0x00,0x00,0x00,0x00,0x00,
60     					 0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01,0x97,0x16,
61     					 0xA3};
62     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
63     	for(i=0;i<29;i++){
64     		SetReg1(Part1Port,(USHORT)i,(USHORT)p1reg[i]);
65     	}
66     }
67     
68     VOID SetDefCRT2ExtRegs(USHORT BaseAddr)
69     {
70     	USHORT	Part1Port,Part2Port,Part4Port;
71     	USHORT	temp;
72     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
73     	Part2Port=BaseAddr+IND_SIS_CRT2_PORT_10;
74     	Part4Port=BaseAddr+IND_SIS_CRT2_PORT_14;
75     	SetReg1(Part1Port,0x02,0x40);
76     	SetReg1(Part4Port,0x10,0x80);
77     	temp=(UCHAR)GetReg1(P3c4,0x16);
78     	temp=temp&0xC3;
79     	SetReg1(P3d4,0x35,temp);
80     }
81     			
82     USHORT GetRatePtrCRT2(ULONG ROMAddr, USHORT ModeNo)
83     {								//return bit0=>0:standard mode 1:extended mode
84     	SHORT   index;				//		 bit1=>0:crt2 no support this mode
85     	USHORT  temp;				//			   1:crt2 support this mode 
86     	USHORT  ulRefIndexLength;
87     	USHORT  temp1;
88     	SHORT   LCDRefreshIndex[4]={0x0,0x0,0x03,0x01};
89     								// LCDPanel:no lcd,800x600,1024x768,1280x1024
90     	if(ModeNo<0x14) return(0);	// Mode No <= 13h then return
91     
92     	index=GetReg1(P3d4,0x33);		// Get 3d4 CRTC33
93     	index=index>>SelectCRT2Rate;	//For CRT2,cl=SelectCRT2Rate=4, shr ah,cl		 
94     	index=index&0x0F;				// Frame rate index
95     	if(index!=0) index--;
96     	
97     	if(IF_DEF_TRUMPION==1){
98     	 	if(VBInfo&SetSimuScanMode){
99     			index=0;
100     		}
101     	}
102     	if(SetFlag&ProgrammingCRT2){
103     		if(VBInfo&SetCRT2ToLCD){
104     			if(IF_DEF_LVDS==0){
105     				temp=LCDResInfo;
106     				temp1=LCDRefreshIndex[temp];
107     				if(index>temp1){
108     			 		index=temp1;
109     				}
110     			}else{
111     				index=0;
112     			}			
113     		}	
114     	}
115     	
116     	REFIndex=*((USHORT *)(ROMAddr+ModeIDOffset+0x04));	// si+Ext_point
117     
118     	ulRefIndexLength =Ext2StructSize;
119     	do {
120     		temp=*((USHORT *)(ROMAddr+REFIndex));			// di => REFIndex
121     		if(temp==0xFFFF) break;
122     		temp=temp&ModeInfoFlag;
123     		if(temp<ModeType) break;
124     
125     		REFIndex=REFIndex+ulRefIndexLength;				// rate size
126     		index--;
127     		if(index<0){
128     			if(!(VBInfo&SetCRT2ToRAMDAC)){
129     				if(VBInfo&SetInSlaveMode){
130     			 		temp1=*((USHORT *)(ROMAddr+REFIndex+0-Ext2StructSize));
131     			 		if(temp1&InterlaceMode){
132     						index=0;	 
133     			 		}		
134     				}
135     			}
136     	 	}	
137     	} while(index>=0);
138     
139     	REFIndex=REFIndex-ulRefIndexLength;					// rate size
140     	
141     	if((SetFlag&ProgrammingCRT2)){
142     		temp1=AjustCRT2Rate(ROMAddr);
143     	}else{
144     		temp1=0;
145     	}
146     
147     	return(0x01|(temp1<<1));
148     }
149     
150     BOOLEAN AjustCRT2Rate(ULONG ROMAddr)
151     {
152     	USHORT tempbx=0,tempax,temp;
153     	USHORT tempextinfoflag;
154     	tempax=0;
155     
156     	if(IF_DEF_LVDS==0){
157     		if(VBInfo&SetCRT2ToRAMDAC){
158     			tempax=tempax|SupportRAMDAC2;
159     		}
160     		if(VBInfo&SetCRT2ToLCD){
161     			tempax=tempax|SupportLCD;
162     			if(LCDResInfo!=Panel1280x1024){
163     				temp=*((UCHAR *)(ROMAddr+ModeIDOffset+0x09)); //si+Ext_ResInfo
164     				if(temp>=9){
165     					tempax=0;
166     				}
167     			}
168     		}
169     		if(VBInfo&(SetCRT2ToAVIDEO|SetCRT2ToSVIDEO|SetCRT2ToSCART)){
170     			tempax=tempax|SupportTV;
171     			if(!(VBInfo&SetPALTV)){
172     				tempextinfoflag=*((USHORT *)(ROMAddr+REFIndex+0x0)); //di+Ext_InfoFlag
173     				if(tempextinfoflag&NoSupportSimuTV){
174     					if(VBInfo&SetInSlaveMode){
175     						if(!(VBInfo&SetNotSimuTVMode)){
176     							return 0;
177     						}
178     					}
179     				}
180     			}
181     		}
182     		tempbx=*((USHORT *)(ROMAddr+ModeIDOffset+0x04));	// si+Ext_point
183     	}else{	//for LVDS
184     		if(VBInfo&SetCRT2ToLCD){
185     			tempax=tempax|SupportLCD;
186     			temp=*((UCHAR *)(ROMAddr+ModeIDOffset+0x09)); //si+Ext_ResInfo
187     			if(temp>0x08){ //1024x768
188     				return 0;
189     			}
190     			if(LCDResInfo<Panel1024x768){
191     				if(temp>0x07){ //800x600
192     					return 0;
193     				}
194     				if(temp==0x04){ //512x384
195     					return 0;
196     				}
197     			}
198     		}
199     	}
200     
201     	for(;REFIndex>tempbx;REFIndex-=Ext2StructSize){
202     		tempextinfoflag=*((USHORT *)(ROMAddr+REFIndex+0x0)); //di+Ext_InfoFlag
203     		if(tempextinfoflag&tempax){
204     			return 1;
205     		}
206     	} 
207     	for(REFIndex=tempbx;;REFIndex+=Ext2StructSize){
208     		tempextinfoflag=*((USHORT *)(ROMAddr+REFIndex+0x0)); //di+Ext_InfoFlag
209     		if(tempextinfoflag==0x0FFFF){
210     			return 0;
211     		}
212     		if(tempextinfoflag&tempax){
213     			return 1;
214     		}
215     	}
216     	return(FALSE);
217     }
218     
219     VOID SaveCRT2Info(USHORT ModeNo){
220     	USHORT temp1,temp2,temp3;
221     	temp1=(VBInfo&SetInSlaveMode)>>8;
222     	temp2=~(SetInSlaveMode>>8);
223     	temp3=(UCHAR)GetReg1(P3d4,0x31);
224     	temp3=((temp3&temp2)|temp1);
225     	SetReg1(P3d4,0x31,(USHORT)temp3);
226     	temp3=(UCHAR)GetReg1(P3d4,0x35);
227     	temp3=temp3&0xF3;
228     	SetReg1(P3d4,0x35,(USHORT)temp3);
229     }
230     
231     VOID DisableLockRegs(){
232     	UCHAR temp3;
233     	temp3=(UCHAR)GetReg1(P3c4,0x32);
234     	temp3=temp3&0xDF;
235     	SetReg1(P3c4,0x32,(USHORT)temp3);
236     }
237     
238     VOID DisableCRT2(){
239     	UCHAR temp3;
240     	temp3=(UCHAR)GetReg1(P3c4,0x1E);
241     	temp3=temp3&0xDF;
242     	SetReg1(P3c4,0x1E,(USHORT)temp3);
243     }
244     
245     void DisableBridge(USHORT	BaseAddr)
246     {
247     	USHORT	Part2Port,Part1Port;
248     	Part2Port=BaseAddr+IND_SIS_CRT2_PORT_10;
249     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
250     
251     	if(IF_DEF_LVDS==0){
252     		SetRegANDOR(Part2Port,0x00,0xDF,0x00);	//Set Part2 Index0 D[5]=0
253     		DisableLockRegs();	// SR 32 
254     		DisableCRT2();	// SR 1E
255     	}else{
256     		DisableLockRegs();
257     		DisableCRT2();
258     		if(IF_DEF_TRUMPION==0){
259     			UnLockCRT2(BaseAddr);
260     			SetRegANDOR(Part1Port,0x02,0xFF,0x40); //set Part1Port ,index 2, D6=1,
261     		}
262     	}
263     }
264     
265     VOID GetCRT2Data(ULONG ROMAddr,USHORT ModeNo)
266     {
267     	if(IF_DEF_LVDS==0){ //301
268     		GetCRT2Data301(ROMAddr,ModeNo);
269     		return;
270     	}else{ //LVDS
271     		GetCRT2DataLVDS(ROMAddr,ModeNo);
272     		return;
273     	}
274     }
275     
276     VOID GetCRT2DataLVDS(ULONG ROMAddr,USHORT ModeNo)
277     {
278     	USHORT tempax,tempbx,OldREFIndex;	
279     
280     	OldREFIndex=(USHORT)REFIndex;			//push di
281     	GetResInfo(ROMAddr,ModeNo);
282     	GetCRT2Ptr(ROMAddr,ModeNo);
283     
284     	tempax=*((USHORT *)(ROMAddr+REFIndex));
285     	tempax=tempax&0x0FFF;
286     	VGAHT=tempax;
287     
288     	tempax=*((USHORT *)(ROMAddr+REFIndex+1));
289     	tempax=tempax>>4;
290     	tempax=tempax&0x07FF;
291     	VGAVT=tempax;
292     
293     	tempax=*((USHORT *)(ROMAddr+REFIndex+3));
294     	tempax=tempax&0x0FFF;
295     	tempbx=*((USHORT *)(ROMAddr+REFIndex+4));
296     	tempbx=tempbx>>4;
297     	tempbx=tempbx&0x07FF;
298     
299     	HT=tempax;
300     	VT=tempbx;
301     
302     	if(IF_DEF_TRUMPION==0){
303     		if(VBInfo&SetCRT2ToLCD){
304     			if(!(LCDInfo&LCDNonExpanding)){
305     				if(LCDResInfo==Panel800x600){
306     					tempax=800;
307     					tempbx=600;
308     				}else if(LCDResInfo==Panel1024x768){
309     					tempax=1024;
310     					tempbx=768;
311     				}else{
312     					tempax=1280;
313     					tempbx=1024;
314     				}
315     				HDE=tempax;
316     				VDE=tempbx;
317     			}
318     		}
319     	}
320     	REFIndex=OldREFIndex;		//pop di
321     	return;
322     }
323     
324     VOID GetCRT2Data301(ULONG ROMAddr,USHORT ModeNo)
325     {
326     	USHORT tempax,tempbx,modeflag1,OldREFIndex;
327     	USHORT tempal,tempah,tempbl;
328     	
329     	OldREFIndex=(USHORT)REFIndex;			//push di
330     	RVBHRS=50;NewFlickerMode=0;RY1COE=0;
331     	RY2COE=0;RY3COE=0;RY4COE=0;
332     
333     	GetResInfo(ROMAddr,ModeNo);
334     	if(VBInfo&SetCRT2ToRAMDAC){
335     		GetRAMDAC2DATA(ROMAddr,ModeNo);
336     		REFIndex=OldREFIndex;			//pop di
337     		return;
338     	}
339     	GetCRT2Ptr(ROMAddr,ModeNo);
340     
341     	tempal=*((UCHAR *)(ROMAddr+REFIndex));
342     	tempah=*((UCHAR *)(ROMAddr+REFIndex+4));
343     	tempax=tempal|(((tempah<<8)>>7)&0xFF00);
344     	RVBHCMAX=tempax;
345     
346     	tempal=*((UCHAR *)(ROMAddr+REFIndex+1));
347     	RVBHCFACT=tempal;
348     
349     	tempax=*((USHORT *)(ROMAddr+REFIndex+2));
350     	VGAHT=(tempax&0x0FFF);
351     
352     	tempax=*((USHORT *)(ROMAddr+REFIndex+3));
353     	VGAVT=((tempax>>4)&0x07FF);
354     
355     	tempax=*((USHORT *)(ROMAddr+REFIndex+5));
356     	tempax=(tempax&0x0FFF);
357     	tempbx=*((USHORT *)(ROMAddr+REFIndex+6));
358     	tempbx=((tempbx>>4)&0x07FF);
359     	tempbl=tempbx&0x00FF;
360     
361     	if(VBInfo&SetCRT2ToTV){
362     		tempax=*((USHORT *)(ROMAddr+REFIndex+5));
363     		tempax=(tempax&0x0FFF);
364     		HDE=tempax;
365     		tempax=*((USHORT *)(ROMAddr+REFIndex+6));
366     		tempax=((tempax>>4)&0x07FF);
367     		VDE=tempax;
368     		//skipp something about hivisiontv
369     		tempax=*((USHORT *)(ROMAddr+REFIndex+8));
370     		tempbl=(tempax>>8);
371     		tempax=tempax&0x0FFF;	
372     		modeflag1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
373     		if(modeflag1&HalfDCLK){
374     			tempax=*((USHORT *)(ROMAddr+REFIndex+10));
375     		}
376     		RVBHRS=tempax;
377     		NewFlickerMode=(tempbl&0x080);
378     
379     		tempax=*((USHORT *)(ROMAddr+REFIndex+12));
380     		RY1COE=(tempax&0x00FF);
381     		RY2COE=((tempax&0xFF00)>>8);
382     		tempax=*((USHORT *)(ROMAddr+REFIndex+14));
383     		RY3COE=(tempax&0x00FF);
384     		RY4COE=((tempax&0xFF00)>>8);
385     		if(!(VBInfo&SetPALTV)){ 
386     			tempax=NTSCHT;
387     			tempbx=NTSCVT;
388     		}else{
389     			tempax=PALHT;
390     			tempbx=PALVT;
391     		} 
392     	}
393     	HT=tempax;
394     	VT=tempbx;
395     	if(!(VBInfo&SetCRT2ToLCD)){
396     		REFIndex=OldREFIndex;			//pop di
397     		return;
398     	}
399     
400     	tempax=1024;
401     	if(VGAVDE==350){		//cx->VGAVDE
402     		tempbx=560;
403     	}else if(VGAVDE==400){
404     		tempbx=640;
405     	}else{
406     		tempbx=768;
407     	}
408     
409     	if(LCDResInfo==Panel1280x1024){
410     		tempax=1280;			
411     		if(VGAVDE==360){
412     			tempbx=768;
413     		}else if(VGAVDE==375){
414     			tempbx=800;		 
415     		}else if(VGAVDE==405){
416     			tempbx=864;		 
417     		}else{
418     			tempbx=1024;
419     		}	
420     	}
421     
422     	HDE=tempax;
423     	VDE=tempbx; 
424     	REFIndex=OldREFIndex;		//pop di
425     	return; 
426     }
427     
428     VOID GetResInfo(ULONG ROMAddr,USHORT ModeNo)
429     { 
430     	USHORT temp,xres,yres,modeflag1;
431     	if(ModeNo<=0x13){
432     		temp=(USHORT)*((UCHAR *)(ROMAddr+ModeIDOffset+0x05));	// si+St_ResInfo
433     		xres=StResInfo[temp][0];
434     		yres=StResInfo[temp][1];
435     	}else{
436     		temp=(USHORT)*((UCHAR *)(ROMAddr+ModeIDOffset+0x09));	// si+Ext_ResInfo
437     		xres=ModeResInfo[temp][0];	//xres->ax
438     		yres=ModeResInfo[temp][1];	//yres->bx
439     		modeflag1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
440     		if(modeflag1&HalfDCLK){ xres=xres*2;}
441     		if(modeflag1&DoubleScanMode){yres=yres*2;}
442     	}
443     	if(!(LCDResInfo==Panel1024x768)){
444     		if(yres==400) yres=405;
445     		if(yres==350) yres=360;
446     		if(SetFlag&LCDVESATiming){
447     			if(yres==360) yres=375;	
448     		}				
449     	}
450     	VGAHDE=xres;
451     	HDE=xres;
452     	VGAVDE=yres;
453     	VDE=yres;
454     }
455     
456     VOID GetLVDSDesData(ULONG ROMAddr,USHORT ModeNo)
457     {
458     	USHORT old_REFIndex,tempax;
459     
460     	old_REFIndex=(USHORT)REFIndex; //push di
461     	REFIndex=GetLVDSDesPtr(ROMAddr,ModeNo);
462     
463     	tempax=*((USHORT *)(ROMAddr+REFIndex));
464     	tempax=tempax&0x0FFF;
465     	LCDHDES=tempax;
466     
467     	if(LCDInfo&LCDNonExpanding){ //hw walk-a-round
468     		if(LCDResInfo>=Panel1024x768){
469     			if(ModeNo<=0x13){
470     				LCDHDES=320;
471     			}
472     		}
473     	}
474     
475     	tempax=*((USHORT *)(ROMAddr+REFIndex+1));
476     	tempax=tempax>>4;
477     	tempax=tempax&0x07FF;
478     	LCDVDES=tempax;
479     
480     	REFIndex=old_REFIndex; //pop di
481     	return;	
482     }
483     
484     
485     VOID GetRAMDAC2DATA(ULONG ROMAddr,USHORT ModeNo)
486     {
487     	USHORT tempax,tempbx,tempbh,modeflag1,t1=0,t2;
488     	RVBHCMAX=1;RVBHCFACT=1;
489     	if(ModeNo<=0x13){
490     		tempax=*((UCHAR *)(ROMAddr+REFIndex+10)); 
491     		tempbx=*((USHORT *)(ROMAddr+REFIndex+16));
492     	}else{
493     		t1=*((UCHAR *)(ROMAddr+REFIndex+0x2)); //Ext_CRT1CRTC=2
494     		t1=t1&0x03F;	//[06/29/2000] fix bug for vbios >=v1.07.00
495     		t1=t1*CRT1Len;
496     		REFIndex=*((USHORT *)(ROMAddr+0x204));		// Get CRT1Table
497     		REFIndex=REFIndex+t1;
498     		t1=*((UCHAR *)(ROMAddr+REFIndex+0));
499     		t2=*((UCHAR *)(ROMAddr+REFIndex+14));
500     		tempax=(t1&0xFF)|((t2&0x03)<<8);
501     		tempbx=*((USHORT *)(ROMAddr+REFIndex+6));
502     		t1=*((UCHAR *)(ROMAddr+REFIndex+13));
503     		t1=(t1&0x01)<<2;
504     	}
505     
506     	tempbh=tempbx>>8;
507     	tempbh=((tempbh&0x20)>>4)|(tempbh&0x01);
508     	tempbh=tempbh|t1;
509     	tempbx=(tempbx&0xFF)|(tempbh<<8);
510     	tempax=tempax+5;
511     	modeflag1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
512     	if(modeflag1&Charx8Dot){
513     		tempax=tempax*8;
514     	}else{
515     		tempax=tempax*9;
516     	}
517     
518     	VGAHT=tempax;
519     	HT=tempax;
520     	tempbx++;
521     	VGAVT=tempbx;
522     	VT=tempbx;
523     
524     }
525     
526     VOID GetCRT2Ptr(ULONG ROMAddr,USHORT ModeNo)
527     {
528     	USHORT tempcl,tempbx,tempal,tempax,CRT2PtrData;
529     
530     	if(IF_DEF_LVDS==0){
531     		if(VBInfo&SetCRT2ToLCD){		//LCD
532     			tempbx=0; //default tempbx=0 -> ExtLCD1Data
533     			tempcl=LCDDataLen;
534     			if(LCDResInfo==Panel1024x768){
535     				tempbx=0;
536     			}else if(LCDResInfo==Panel1280x1024){
537     				tempbx=1;
538     			}
539     			if(!(SetFlag&LCDVESATiming)) tempbx+=5;
540     		}else if(VBInfo&SetPALTV){
541     			tempcl=TVDataLen;
542     			tempbx=3;
543     		}else{
544     			tempbx=4;
545     			tempcl=TVDataLen;
546     		}	
547     		if(SetFlag&TVSimuMode){
548     			tempbx=tempbx+4;
549     		}
550     		if(ModeNo<=0x13){
551     			tempal=*((UCHAR *)(ROMAddr+ModeIDOffset+0x04));	// si+St_CRT2CRTC
552     		}else{
553     			tempal=*((UCHAR *)(ROMAddr+REFIndex+4));	 //di+Ext_CRT2CRTC
554     		}
555     		tempal=tempal&0x1F;
556     
557     		tempax=tempal*tempcl;
558     		REFIndex=*((USHORT *)(ROMAddr+tempbx*2+0x20E));
559     		REFIndex+=tempax;
560     	}else{ //for LVDS
561     
562     		tempcl=LVDSDataLen;
563     		tempbx=LCDResInfo-Panel800x600;
564     		if(LCDInfo&LCDNonExpanding){
565     			tempbx=tempbx+3;
566     		}
567     		if(ModeNo<=0x13){
568     			tempal=*((UCHAR *)(ROMAddr+ModeIDOffset+0x04));	// si+St_CRT2CRTC
569     		}else{
570     			tempal=*((UCHAR *)(ROMAddr+REFIndex+0x04));		// di+Ext_CRT2CRTC
571     		}
572     		tempal=tempal&0x1F;
573     		tempax=tempal*tempcl;
574     		CRT2PtrData=*((USHORT *)(ROMAddr+ADR_CRT2PtrData)); //ADR_CRT2PtrData is defined in init.def
575     		REFIndex=*((USHORT *)(ROMAddr+CRT2PtrData+tempbx*2));
576     		REFIndex+=tempax;
577     	}
578     }
579     
580     VOID UnLockCRT2(USHORT BaseAddr)
581     {
582     	UCHAR temp3;
583     	USHORT	Part1Port;
584     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
585     	temp3=(UCHAR)GetReg1(Part1Port,0x24);
586     	temp3=temp3|0x01;
587     	SetReg1(Part1Port,0x24,(USHORT)temp3);
588     }
589     
590     VOID SetCRT2ModeRegs(USHORT BaseAddr,USHORT ModeNo)
591     {
592     	USHORT i,j;
593     	USHORT tempah=0,temp3;
594     	SHORT	tempcl;
595     	USHORT	Part4Port;
596     	USHORT	Part1Port;
597     	Part4Port=BaseAddr+IND_SIS_CRT2_PORT_14;
598     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
599     	for(i=0,j=4;i<3;i++,j++){
600     		SetReg1(Part1Port,j,0);
601     	}
602     	
603     	tempcl=(USHORT)ModeType;
604     	if(ModeNo>0x13){
605     		tempcl=tempcl-ModeVGA; 
606     		if(tempcl>=0){
607     			tempah=((0x010>>tempcl)|0x080);
608     		}
609     	}else{
610     		tempah=0x080;
611     	}
612     
613     	if(VBInfo&SetInSlaveMode){
614     		tempah=(tempah^0x0A0);
615     	}
616     	if(VBInfo&CRT2DisplayFlag){
617     		tempah=0;
618     	}
619     	SetReg1(Part1Port,0,tempah);
620     
621     	if(IF_DEF_LVDS==0){ //301
622     		tempah=0x01;
623     		if(!(VBInfo&SetInSlaveMode)){
624     			tempah=(tempah|0x02);
625     		}
626     		if(!(VBInfo&SetCRT2ToRAMDAC)){
627     			tempah=(tempah^0x05);
628     			if(!(VBInfo&SetCRT2ToLCD)){
629     				tempah=(tempah^0x01);
630     			}
631     		}
632     		tempah=(tempah<<5)&0xFF;
633     		if(VBInfo&CRT2DisplayFlag){
634     			tempah=0;
635     		}
636     		SetReg1(Part1Port,0x01,tempah);
637     
638     		tempah=tempah>>5;
639     		if((ModeType==ModeVGA)&&(!(VBInfo&SetInSlaveMode))){
640     			tempah=tempah|0x010;
641     		}
642     		if(LCDResInfo!=Panel1024x768){
643     			tempah=tempah|0x080;
644     		}
645     		if(VBInfo&SetCRT2ToTV){
646     			if(VBInfo&SetInSlaveMode){
647     				tempah=tempah|0x020;
648     			}
649     		}
650     	
651     		temp3=(UCHAR)GetReg1(Part4Port,0x0D);
652     		temp3=temp3&(~0x0BF);
653     		temp3=temp3|tempah;
654     		SetReg1(Part4Port,0x0D,(USHORT)temp3);
655     	}else{ //LVDS
656     		tempah=0;
657     		if(!(VBInfo&SetInSlaveMode)){
658     			tempah=tempah|0x02;
659     		}
660     		tempah=(tempah<<5)&0x0FF;
661     		if(VBInfo&CRT2DisplayFlag){
662     			tempah=0;
663     		}
664     		SetReg1(Part1Port,0x01,tempah);
665     	}
666     }
667     
668     VOID SetGroup1(USHORT	BaseAddr,ULONG ROMAddr,USHORT ModeNo,
669     		PHW_DEVICE_EXTENSION HwDeviceExtension)
670     {
671     	if(IF_DEF_LVDS==0){	//301
672     		SetGroup1_301(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
673     	}else{	//LVDS
674     		SetGroup1_LVDS(BaseAddr,ROMAddr,ModeNo,HwDeviceExtension);
675     	}
676     }
677     VOID SetGroup1_LVDS(USHORT	BaseAddr,ULONG ROMAddr,USHORT ModeNo,
678     		PHW_DEVICE_EXTENSION HwDeviceExtension)
679     {
680     	USHORT temp1,temp2,tempcl,tempch,tempbh,tempal,tempah,tempax,tempbx;
681     	USHORT tempcx,OldREFIndex,lcdhdee;
682     	USHORT	Part1Port;
683     	USHORT temppush1,temppush2;
684     	unsigned long int tempeax,tempebx,tempecx,templong;
685     
686     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
687     	OldREFIndex=(USHORT)REFIndex;		//push di
688     
689     	SetCRT2Offset(Part1Port,ROMAddr);
690     	SetCRT2FIFO(Part1Port,ROMAddr,ModeNo,HwDeviceExtension);
691     	SetCRT2Sync(BaseAddr,ROMAddr,ModeNo);
692     
693     	temp1=(VGAHT-1)&0x0FF;				//BTVGA2HT 0x08,0x09
694     	SetReg1(Part1Port,0x08,temp1);
695     	temp1=(((VGAHT-1)&0xFF00)>>8)<<4;
696     	SetRegANDOR(Part1Port,0x09,~0x0F0,temp1);
697      
698     	
699     	temp1=(VGAHDE+12)&0x0FF;			//BTVGA2HDEE 0x0A,0x0C
700     	SetReg1(Part1Port,0x0A,temp1);
701     	
702     	temp1=VGAHDE+12;			//bx	BTVGA@HRS 0x0B,0x0C
703     	temp2=(VGAHT-VGAHDE)>>2;	//cx
704     	temp1=temp1+temp2;
705     	temp2=(temp2<<1)+temp1;
706     	tempcl=temp2&0x0FF;
707     			//
708     	SetReg1(Part1Port,0x0B,(USHORT)(temp1&0x0FF));
709     	tempah=(temp1&0xFF00)>>8;
710     	tempbh=((((VGAHDE+12)&0xFF00)>>8)<<4)&0x0FF;
711     	tempah=tempah|tempbh;
712     	SetReg1(Part1Port,0x0C,tempah);
713     	SetReg1(Part1Port,0x0D,tempcl);		//BTVGA2HRE 0x0D
714     	tempcx=(VGAVT-1);
715     	tempah=tempcx&0x0FF;
716     	SetReg1(Part1Port,0x0E,tempah);		//BTVGA2TV 0x0E,0x12
717     	tempbx=VGAVDE-1;
718     	tempah=tempbx&0x0FF;
719     	SetReg1(Part1Port,0x0F,tempah);		//BTVGA2VDEE 0x0F,0x12
720     	tempah=((tempbx&0xFF00)<<3)>>8;
721     	tempah=tempah|((tempcx&0xFF00)>>8);
722     	SetReg1(Part1Port,0x12,tempah);
723     	
724     	tempbx=(VGAVT+VGAVDE)>>1;				//BTVGA2VRS		0x10,0x11
725     	tempcx=((VGAVT-VGAVDE)>>4)+tempbx+1;	//BTVGA2VRE		0x11
726     			//
727     	tempah=tempbx&0x0FF;
728     	SetReg1(Part1Port,0x10,tempah);
729     	tempbh=(tempbx&0xFF00)>>8;
730     	tempah=((tempbh<<4)&0x0FF)|(tempcx&0x0F);
731     	SetReg1(Part1Port,0x11,tempah);
732     
733     	SetRegANDOR(Part1Port,0x13,~0x03C,tempah);
734     
735     	tempax=LCDHDES;
736     	tempbx=HDE;
737     	tempcx=HT;
738     	tempcx=tempcx-tempbx; //HT-HDE
739     	tempax=tempax+tempbx; //lcdhdee
740     	tempbx=HT;
741     	if(tempax>=tempbx){
742     		tempax=tempax-tempbx;
743     	}
744     
745     	lcdhdee=tempax;
746     	tempcx=tempcx>>2;		//temp
747     	tempcx=tempcx+tempax;	//lcdhrs
748     	if(tempcx>=tempbx){
749     		tempcx=tempcx-tempbx;
750     	}
751     
752     	tempax=tempcx;
753     	tempax=tempax>>3;		//BPLHRS
754     	tempah=tempax&0x0FF;
755     	SetReg1(Part1Port,0x14,tempah); //Part1_14h
756     	tempah=tempah+2;
757     	tempah=tempah+0x01F;
758     	tempcl=tempcx&0x0FF;
759     	tempcl=tempcl&0x07;
760     	tempcl=(tempcl<<5)&0xFF; //BPHLHSKEW
761     	tempah=tempah|tempcl;
762     	SetReg1(Part1Port,0x15,tempah); //Part1_15h
763     	tempbx=lcdhdee;			//lcdhdee
764     	tempcx=LCDHDES;			//lcdhdes
765     	tempah=(tempcx&0xFF);
766     	tempah=tempah&0x07;		//BPLHDESKEW
767     	SetReg1(Part1Port,0x1A,tempah); //Part1_1Ah
768     	tempcx=tempcx>>3;		//BPLHDES
769     	tempah=(tempcx&0xFF);
770     	SetReg1(Part1Port,0x16,tempah); //Part1_16h
771     	tempbx=tempbx>>3;		//BPLHDEE
772     	tempah=tempbx&0xFF;
773     	SetReg1(Part1Port,0x17,tempah); //Part1_17h
774     
775     	tempcx=VGAVT;
776     	tempbx=VGAVDE;
777     	tempcx=tempcx-tempbx;		//VGAVT-VGAVDE
778     	tempbx=LCDVDES;				//VGAVDES
779     	temppush1=tempbx;			//push bx temppush1
780     	if(IF_DEF_TRUMPION==0){
781     		if(LCDResInfo==Panel800x600){
782     			tempax=600;
783     		}else{
784     			tempax=768;
785     		}
786     	}else{
787     		tempax=VGAVDE;
788     	}
789     	tempbx=tempbx+tempax;
790     	tempax=VT;				//VT
791     	if(tempbx>=VT){
792     		tempbx=tempbx-tempax;
793     	}
794     	temppush2=tempbx;		//push bx	temppush2
795     	tempcx=tempcx>>1;
796     	tempbx=tempbx+tempcx;
797     	tempbx++;		//BPLVRS
798     	if(tempbx>=tempax){
799     		tempbx=tempbx-tempax;
800     	}
801     	tempah=tempbx&0xFF;
802     	SetReg1(Part1Port,0x18,tempah); //Part1_18h
803     	tempcx=tempcx>>3;
804     	tempcx=tempcx+tempbx;
805     	tempcx++;				 //BPLVRE
806     	tempah=tempcx&0xFF;
807     	tempah=tempah&0x0F;
808     	tempah=tempah|0x030;
809     	SetRegANDOR(Part1Port,0x19,~0x03F,tempah); //Part1_19h
810     	tempbh=(tempbx&0xFF00)>>8;
811     	tempbh=tempbh&0x07;
812     	tempah=tempbh;
813     	tempah=(tempah<<3)&0xFF;		//BPLDESKEW =0
814     	tempbx=VGAVDE;
815     	if(tempbx!=VDE){
816     		tempah=tempah|0x40;
817     	}
818     	SetRegANDOR(Part1Port,0x1A,0x07,tempah); //Part1_1Ah
819     	tempecx=VGAVT;
820     	tempebx=VDE;
821     	tempeax=VGAVDE;
822     	tempecx=tempecx-tempeax;		//VGAVT-VGAVDE
823     	tempeax=tempeax*64;
824     	templong=tempeax/tempebx;
825     	if(templong*tempebx<tempeax){
826     		templong++;
827     	}
828     	tempebx=templong;		//BPLVCFACT
829     	if(SetFlag&EnableLVDSDDA){
830     		tempebx=tempebx&0x03F;
831     	}
832     	tempah=(USHORT)(tempebx&0x0FF);
833     	SetReg1(Part1Port,0x1E,tempah); //Part1_1Eh
834     	tempbx=temppush2;		//pop bx temppush2 BPLVDEE
835     	tempcx=temppush1;		//pop cx temppush1 NPLVDES
836     	tempbh=(tempbx&0xFF00)>>8;
837     	tempah=tempah&0x07;
838     	tempah=tempbh;
839     	tempah=tempah<<3;
840     	tempch=(tempcx&0xFF00)>>8;
841     	tempch=tempah&0x07;
842     	tempah=tempah|tempch;
843     	SetReg1(Part1Port,0x1D,tempah); //Part1_1Dh
844     	tempah=tempbx&0xFF;
845     	SetReg1(Part1Port,0x1C,tempah); //Part1_1Ch
846     	tempah=tempcx&0xFF;
847     	SetReg1(Part1Port,0x1B,tempah); //Part1_1Bh
848     	
849     	tempecx=VGAHDE;
850     	tempebx=HDE;
851     	tempeax=tempecx;
852     	tempeax=tempeax<<6;
853     	tempeax=tempeax<<10;
854     	tempeax=tempeax/tempebx;
855     	if(tempebx==tempecx){
856     		tempeax=65535;
857     	}
858     	tempecx=tempeax;
859     	tempeax=VGAHT;
860     	tempeax=tempeax<<6;
861     	tempeax=tempeax<<10;
862     	tempeax=tempeax/tempecx;
863     	tempecx=tempecx<<16;
864     	tempeax=tempeax-1;
865     	tempax=(USHORT)(tempeax&0x00FFFF);
866     	tempcx=tempax;
867     	tempah=tempcx&0x0FF;
868     	SetReg1(Part1Port,0x1F,tempah); //Part1_1Fh
869     	tempbx=VDE;
870     	tempbx--;				 //BENPLACCEND
871     	if(SetFlag&EnableLVDSDDA){
872     		tempbx=1;
873     	}
874     	tempah=(tempbx&0xFF00)>>8;
875     	tempah=(tempah<<3)&0xFF;
876     	tempch=(tempcx&0xFF00)>>8;
877     	tempch=tempch&0x07;
878     	tempah=tempah|tempch;
879     	SetReg1(Part1Port,0x20,tempah); //Part1_20h
880     	tempah=tempbx&0xFF;
881     	SetReg1(Part1Port,0x21,tempah); //Part1_21h
882     	tempecx=tempecx>>16;			 //BPLHCFACT
883     	temp1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
884     	if(temp1&HalfDCLK){
885     		tempecx=tempecx>>1;
886     	}
887     	tempcx=(USHORT)(tempecx&0x0FFFF);
888     	tempah=(tempcx&0xFF00)>>8;
889     	SetReg1(Part1Port,0x22,tempah); //Part1_22h
890     	tempah=tempcx&0x0FF;
891     	SetReg1(Part1Port,0x23,tempah); //Part1_23h
892     	if(IF_DEF_TRUMPION==1){
893     		tempal=(USHORT)*((UCHAR *)(ROMAddr+ModeIDOffset+0x05));	// si+St_ResInfo
894     		if(ModeNo>0x13){
895     			SetFlag=SetFlag|ProgrammingCRT2;
896     			GetRatePtrCRT2(ROMAddr,ModeNo);
897     			tempal=*((UCHAR *)(ROMAddr+REFIndex+0x04));		// di+Ext_CRT2CRTC
898     			tempal=tempal&0x1F;
899     	 	}
900     		tempah=0x80;
901     		tempal=tempal*tempah;
902     		REFIndex= offset_Zurac; //offset Zurac need added in rompost.asm
903     		REFIndex=REFIndex+tempal;
904     		SetTPData();	//this function not implemented yet
905     		SetTPData();
906     		SetTPData();
907     		SetTPData();
908     		SetTPData();
909     		SetTPData();
910     		SetTPData();
911     		SetTPData();
912     		SetTPData();
913     	}
914      
915     	REFIndex=OldREFIndex;			//pop di
916     	return;
917     }
918     
919     VOID SetTPData(VOID)
920     {
921     	return;
922     }
923     
924     VOID SetGroup1_301(USHORT	BaseAddr,ULONG ROMAddr,USHORT ModeNo,
925     		PHW_DEVICE_EXTENSION HwDeviceExtension)
926     {
927     	USHORT temp1,temp2,tempcl,tempch,tempbl,tempbh,tempal,tempah,tempax,tempbx;
928     	USHORT tempcx,OldREFIndex;
929     	USHORT	Part1Port;
930     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
931     	OldREFIndex=(USHORT)REFIndex;			//push di
932     
933     	SetCRT2Offset(Part1Port,ROMAddr);
934     	SetCRT2FIFO(Part1Port,ROMAddr,ModeNo,HwDeviceExtension);
935     	SetCRT2Sync(BaseAddr,ROMAddr,ModeNo);
936     
937     	GetCRT1Ptr(ROMAddr);
938     
939     	temp1=(VGAHT-1)&0x0FF;				//BTVGA2HT 0x08,0x09
940     	SetReg1(Part1Port,0x08,temp1);
941     	temp1=(((VGAHT-1)&0xFF00)>>8)<<4;
942     	SetRegANDOR(Part1Port,0x09,~0x0F0,temp1);
943      
944     	temp1=(VGAHDE+12)&0x0FF;					//BTVGA2HDEE 0x0A,0x0C
945     	SetReg1(Part1Port,0x0A,temp1);
946     	
947     	temp1=VGAHDE+12;			//bx	BTVGA@HRS 0x0B,0x0C
948     	temp2=(VGAHT-VGAHDE)>>2;	//cx
949     	temp1=temp1+temp2;
950     	temp2=(temp2<<1)+temp1;
951     	tempcl=temp2&0x0FF;
952     	if(VBInfo&SetCRT2ToRAMDAC){
953     		tempbl=*((UCHAR *)(ROMAddr+REFIndex+4));	//di+4
954     		tempbh=*((UCHAR *)(ROMAddr+REFIndex+14));	//di+14
955     		temp1=((tempbh>>6)<<8)|tempbl;				//temp1->bx
956     		temp1=(temp1-1)<<3;						
957     		tempcl=*((UCHAR *)(ROMAddr+REFIndex+5));	//di+5
958     		tempch=*((UCHAR *)(ROMAddr+REFIndex+15));	//di+15
959     		tempcl=tempcl&0x01F;
960     		tempch=(tempch&0x04)<<(6-2);
961     		tempcl=((tempcl|tempch)-1)<<3;	 
962     	}
963     	SetReg1(Part1Port,0x0B,(USHORT)(temp1&0x0FF));
964     	tempah=(temp1&0xFF00)>>8;
965     	tempbh=((((VGAHDE+12)&0xFF00)>>8)<<4)&0x0FF;
966     	tempah=tempah|tempbh;
967     	SetReg1(Part1Port,0x0C,tempah);
968     	SetReg1(Part1Port,0x0D,tempcl);		//BTVGA2HRE 0x0D
969     	tempcx=(VGAVT-1);
970     	tempah=tempcx&0x0FF;
971     	SetReg1(Part1Port,0x0E,tempah);		//BTVGA2TV 0x0E,0x12
972     	tempbx=VGAVDE-1;
973     	tempah=tempbx&0x0FF;
974     	SetReg1(Part1Port,0x0F,tempah);		//BTVGA2VDEE 0x0F,0x12
975     	tempah=((tempbx&0xFF00)<<3)>>8;
976     	tempah=tempah|((tempcx&0xFF00)>>8);
977     	SetReg1(Part1Port,0x12,tempah);
978     	
979     	tempbx=(VGAVT+VGAVDE)>>1;				//BTVGA2VRS		0x10,0x11
980     	tempcx=((VGAVT-VGAVDE)>>4)+tempbx+1;	//BTVGA2VRE		0x11
981     	if(VBInfo&SetCRT2ToRAMDAC){
982     		tempbx=*((UCHAR *)(ROMAddr+REFIndex+8));	 //di+8
983     		temp1=*((UCHAR *)(ROMAddr+REFIndex+7));	 //di+7
984     		if(temp1&0x04){
985     			tempbx=tempbx|0x0100;
986     		}
987     		if(temp1&0x080){
988     			tempbx=tempbx|0x0200;
989     		}
990     		temp1=*((UCHAR *)(ROMAddr+REFIndex+13));	 //di+13
991     		if(temp1&0x08){
992     			tempbx=tempbx|0x0400;
993     		}
994     		tempcl= *((UCHAR *)(ROMAddr+REFIndex+9));	 //di+9
995     		tempcx=(tempcx&0xFF00)|(tempcl&0x00FF);
996     	}
997     	tempah=tempbx&0x0FF;
998     	SetReg1(Part1Port,0x10,tempah);
999     	tempbh=(tempbx&0xFF00)>>8;
1000     	tempah=((tempbh<<4)&0x0FF)|(tempcx&0x0F);
1001     	SetReg1(Part1Port,0x11,tempah);
1002     
1003     	if(HwDeviceExtension->jChipID == SIS_Glamour)
1004     	{
1005     		tempah=0x10;
1006     	 	if((LCDResInfo!=Panel1024x768)&&(LCDResInfo==Panel1280x1024)){
1007     			tempah=0x20;		
1008     	 	}	
1009     	}else{
1010     		tempah=0x20;
1011     	}
1012     	if(VBInfo&SetCRT2ToTV){
1013     		tempah=0x08;
1014     	}
1015     	
1016     	SetRegANDOR(Part1Port,0x13,~0x03C,tempah);
1017     
1018     	if(!(VBInfo&SetInSlaveMode)){
1019     		REFIndex=OldREFIndex;
1020     		return;
1021     	}
1022     	if(VBInfo&SetCRT2ToTV){
1023     		tempax=0xFFFF;		
1024     	}else{
1025     		tempax=GetVGAHT2();
1026     	}
1027     	tempcl=0x08;						//Reg 0x03 Horozontal Total
1028     	temp1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
1029     	if(!(temp1&Charx8Dot)){								//temp1->St_ModeFlag
1030     		tempcl=0x09;
1031     	}
1032     	if(tempax>=VGAHT){
1033     		tempax=VGAHT;
1034     	}
1035     	if(temp1&HalfDCLK){
1036     		tempax=tempax>>1;
1037     	}
1038     	tempax=(tempax/tempcl)-5;
1039     	tempbl=tempax;
1040     	tempah=0xFF;			//set MAX HT
1041     	SetReg1(Part1Port,0x03,tempah);
1042     
1043     	tempax=VGAHDE;			//0x04 Horizontal Display End
1044     	if(temp1&HalfDCLK){
1045     		tempax=tempax>>1;
1046     	}
1047     	tempax=(tempax/tempcl)-1;
1048     	tempbh=tempax;
1049     	SetReg1(Part1Port,0x04,tempax);
1050     	
1051     	tempah=tempbh;
1052     	if(VBInfo&SetCRT2ToTV){
1053     		tempah=tempah+2;
1054     	}
1055     	SetReg1(Part1Port,0x05,tempah); //0x05 Horizontal Display Start
1056     	SetReg1(Part1Port,0x06,0x03);	//0x06 Horizontal Blank end
1057     											 //0x07 horizontal Retrace Start
1058     	tempcx=(tempbl+tempbh)>>1;
1059     	tempah=(tempcx&0xFF)+2;
1060     
1061     	if(VBInfo&SetCRT2ToTV){
1062     		tempah=tempah-1;	
1063     		if(!(temp1&HalfDCLK)){
1064     			if((temp1&Charx8Dot)){
1065     				tempah=tempah+4;
1066     				if(VGAHDE>=800){
1067     					tempah=tempah-6;
1068     				}
1069     			}
1070     		}
1071     	}else{
1072     		if(!(temp1&HalfDCLK)){
1073     			tempah=tempah-4;
1074     		 	if(VGAHDE>=800){
1075     				tempah=tempah-7;
1076     				if(ModeType==ModeEGA){
1077     					if(VGAVDE==1024){
1078     				 		tempah=tempah+15;
1079     				 		if(LCDResInfo!=Panel1280x1024){
1080     					 		tempah=tempah+7;
1081     				 		}	
1082     					}	 
1083     				}
1084     				if(VGAHDE>=1280){
1085     					tempah=tempah+28;
1086     				}
1087     			}
1088     		}
1089     	}
1090     	
1091     	SetReg1(Part1Port,0x07,tempah);//0x07 Horizontal Retrace Start 
1092     	
1093     	SetReg1(Part1Port,0x08,0);	 //0x08 Horizontal Retrace End
1094     	SetReg1(Part1Port,0x18,0x03); //0x18 SR08
1095     	SetReg1(Part1Port,0x19,0); //0x19 SR0C
1096     	SetReg1(Part1Port,0x09,0xFF); //0x09 Set Max VT
1097     	
1098     	tempcx=0x121;
1099     	tempcl=0x21;
1100     	tempch=0x01;
1101     	tempbx=VGAVDE;					 //0x0E Virtical Display End
1102     	if(tempbx==360) tempbx=350;
1103     	if(tempbx==375) tempbx=350;
1104     	if(tempbx==405) tempbx=400;	
1105     	tempbx--;
1106     	tempah=tempbx&0x0FF;
1107     	SetReg1(Part1Port,0x0E,tempah);
1108     	SetReg1(Part1Port,0x10,tempah);//0x10 vertical Blank Start
1109     	tempbh=(tempbx&0xFF00)>>8;
1110     	if(tempbh&0x01){
1111     		tempcl=tempcl|0x0A;
1112     	}
1113     	tempah=0;tempal=0x0B;
1114     	if(temp1&DoubleScanMode){
1115     		tempah=tempah|0x080;
1116     	}
1117     	if(tempbh&0x02){
1118     		tempcl=tempcl|0x040;
1119     		tempah=tempah|0x020;
1120     	}
1121     	SetReg1(Part1Port,0x0B,tempah);
1122     	if(tempbh&0x04){
1123     		tempch=tempch|0x06; 
1124     	}
1125     
1126     	SetReg1(Part1Port,0x11,0);	//0x11 Vertival Blank End
1127     	
1128     	tempax=VGAVT-tempbx;		//0x0C Vertical Retrace Start 
1129     	tempax=tempax>>2;
1130     	temp2=tempax;				//push ax
1131     	tempax=tempax<<1;
1132     	tempbx=tempax+tempbx;
1133     	if((SetFlag&TVSimuMode)&&(VBInfo&SetPALTV)&&(VGAHDE==800)){
1134     		tempbx=tempbx+40;
1135     	}
1136     	tempah=(tempbx&0x0FF);
1137     	SetReg1(Part1Port,0x0C,tempah);
1138     	tempbh=(tempbx&0xFF00)>>8;
1139     	if(tempbh&0x01){
1140     		tempcl=tempcl|0x04;
1141     	}
1142     	if(tempbh&0x02){
1143     		tempcl=tempcl|0x080;
1144     	}
1145     	if(tempbh&0x04){
1146     		tempch=tempch|0x08;
1147     	}
1148     
1149     	tempax=temp2;			//pop ax
1150     	tempax=(tempax>>2)+1;
1151     	tempbx=tempbx+tempax;
1152     	tempah=(tempbx&0x0FF)&0x0F;
1153     	SetReg1(Part1Port,0x0D,tempah);	//0x0D vertical Retrace End
1154     	tempbl=tempbx&0x0FF;
1155     	if(tempbl&0x10){
1156     		tempch=tempch|0x020;
1157     	}
1158     	
1159     	tempah=tempcl;
1160     	SetReg1(Part1Port,0x0A,tempah); //0x0A CR07
1161     	tempah=tempch;
1162     	SetReg1(Part1Port,0x17,tempah); //0x17 SR0A
1163     	tempax=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
1164     	tempah=(tempax&0xFF00)>>8;
1165     	tempah=(tempah>>1)&0x09;
1166     	SetReg1(Part1Port,0x16,tempah); //0x16 SR01
1167     	SetReg1(Part1Port,0x0F,0);		//0x0F CR14
1168     	SetReg1(Part1Port,0x12,0);		//0x12 CR17
1169     	SetReg1(Part1Port,0x1A,0);		//0x1A SR0E
1170     	
1171     	REFIndex=OldREFIndex;			//pop di
1172     }
1173     
1174     VOID SetCRT2Offset(USHORT Part1Port,ULONG ROMAddr)
1175     {
1176     	USHORT offset;
1177     	if(VBInfo&SetInSlaveMode){
1178     	 return;
1179     	}
1180     	offset=GetOffset(ROMAddr);
1181     	SetReg1(Part1Port,0x07,(USHORT)(offset&0xFF));
1182     	SetReg1(Part1Port,0x09,(USHORT)((offset&0xFF00)>>8));
1183     	SetReg1(Part1Port,0x03,(USHORT)(((offset>>3)&0xFF)+1));
1184     }
1185     
1186     USHORT GetOffset(ULONG ROMAddr)
1187     {
1188     	USHORT tempal,temp1,colordepth;
1189     	tempal=*((UCHAR *)(ROMAddr+ModeIDOffset+0x03));	// si+Ext_ModeInfo
1190     	tempal=(tempal>>4)&0xFF;
1191     	ScreenOffset=*((USHORT *)(ROMAddr+0x206));		// Get ScreeOffset table
1192     	tempal=*((UCHAR *)(ROMAddr+ScreenOffset+tempal));		// get ScreenOffset
1193     	tempal=tempal&0xFF;
1194     	temp1=*((UCHAR *)(ROMAddr+REFIndex));	 //di+Ext_InfoFlag	
1195     	if(temp1&InterlaceMode){
1196     		tempal=tempal<<1;
1197     	}
1198     	colordepth=GetColorDepth(ROMAddr);
1199     	return(tempal*colordepth); 
1200     }
1201     
1202     USHORT GetColorDepth(ULONG ROMAddr)
1203     {
1204     	USHORT ColorDepth[6]={1,2,4,4,6,8};
1205     	USHORT temp;
1206     	int temp1;
1207     	temp=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));		// si+St_ModeFlag
1208     	temp1=(temp&ModeInfoFlag)-ModeEGA;
1209     	if(temp1<0) temp1=0;
1210     	return(ColorDepth[temp1]);
1211     }
1212     
1213     VOID SetCRT2FIFO(USHORT	Part1Port,ULONG ROMAddr,USHORT ModeNo,
1214     			PHW_DEVICE_EXTENSION HwDeviceExtension)
1215     {
1216     	USHORT temp,temp1,temp2,temp3,flag;
1217     	USHORT vclk2ptr,latencyindex;
1218     	USHORT oldREFIndex,CRT1ModeNo,oldModeIDOffset;
1219     	long int longtemp;
1220     
1221     	USHORT LatencyFactor[48]={ 88, 80, 78, 72, 70, 00,			 // 64	bit	 BQ=2
1222     							   00, 79, 77, 71, 69, 49,			 // 64	bit	 BQ=1
1223     							   88, 80, 78, 72, 70, 00,			 // 128 bit	 BQ=2
1224     							   00, 72, 70, 64, 62, 44,			 // 128 bit	 BQ=1
1225     							   73, 65, 63, 57, 55, 00,			 // 64	bit	 BQ=2
1226     							   00, 64, 62, 56, 54, 34,			 // 64	bit	 BQ=1
1227     							   78, 70, 68, 62, 60, 00,			 // 128 bit	 BQ=2
1228     							   00, 62, 60, 54, 52, 34};			 // 128 bit	 BQ=1
1229     
1230     	oldREFIndex=(USHORT)REFIndex;			//push REFIndex(CRT2 now)
1231     	oldModeIDOffset=(USHORT)ModeIDOffset;	//push ModeIDOffset
1232     	
1233     	CRT1ModeNo=(UCHAR)GetReg1(P3d4,0x34);	//get CRT1 ModeNo
1234     	SearchModeID(ROMAddr,CRT1ModeNo);		//Get ModeID Table
1235     	 
1236     	GetRatePtr(ROMAddr,CRT1ModeNo);			//Set REFIndex-> for crt1 refreshrate	
1237     	temp1=GetVCLK(ROMAddr,CRT1ModeNo,HwDeviceExtension);
1238     	temp2=GetColorTh(ROMAddr);
1239     	temp3=GetMCLK(ROMAddr);
1240     	temp=((USHORT)(temp1*temp2)/temp3);		//temp->bx
1241     	temp1=(UCHAR)GetReg1(P3c4,0x14);		//SR_14
1242     	temp1=temp1>>6;
1243     	temp1=temp1<<1;
1244     	if(temp1==0) temp1=1;
1245     	temp1=temp1<<2;					//temp1->ax
1246     
1247     	longtemp=temp1-temp;
1248     	
1249     	temp2=(USHORT)((28*16)/(int)longtemp);	//temp2->cx
1250     	if(!((temp2*(int)longtemp)==(28*16))) temp2++;
1251     
1252     	if( HwDeviceExtension->jChipID == SIS_Glamour ){		
1253     		temp1=CalcDelay();
1254     	}else{ //for Trojan and Spartan
1255     		flag=(UCHAR)GetReg1(P3c4,0x14);	//SR_14
1256     		if(flag&0x80){
1257     			latencyindex=12;	//128 bit
1258     		}else{
1259     			latencyindex=0;	//64 bit
1260     		}
1261     		flag=GetQueueConfig();
1262     		if(!(flag&0x01)){
1263     			latencyindex+=24; //GUI timing =0
1264     		}
1265     		if(flag&0x10){
1266     			latencyindex+=6;	//BQ =2
1267     		}
1268     		latencyindex=latencyindex + (flag>>5);
1269     		temp1= LatencyFactor[latencyindex];
1270     		temp1=temp1+15;
1271     		flag=(UCHAR)GetReg1(P3c4,0x14);	//SR_14
1272     		if(!(flag&0x80)){
1273     			temp1=temp1+5;	 //64 bit
1274     		}
1275     	}	
1276     			
1277     	temp2=temp2+temp1;
1278     	REFIndex=oldREFIndex;			//pop REFIndex(CRT2)
1279     	ModeIDOffset=oldModeIDOffset;	//pop ModeIDOffset
1280     	
1281     	vclk2ptr=GetVCLK2Ptr(ROMAddr,ModeNo);
1282     	temp1=*((USHORT *)(ROMAddr+vclk2ptr+(VCLKLen-2)));
1283     	temp3=GetColorTh(ROMAddr);
1284     	longtemp=temp1*temp2*temp3;
1285     	temp3=GetMCLK(ROMAddr);
1286     	temp3=temp3<<4;
1287     	temp2=(int)(longtemp/temp3);
1288     	if((long int)temp2*(long int)temp3<(long int)longtemp) temp2++;	//temp2->cx
1289     
1290     	temp1=(UCHAR)GetReg1(Part1Port,0x01);			//part1port index 01
1291     
1292     
1293     	if( (HwDeviceExtension->jChipID == SIS_Trojan ) && 
1294     	    ((HwDeviceExtension->revision_id & 0xf0) == 0x30) ) /* 630s */
1295     	{
1296     		temp1=(temp1&(~0x1F))|0x19;
1297     	}else
1298     	{
1299     		temp1=(temp1&(~0x1F))|0x16;
1300     	}
1301     	SetReg1(Part1Port,0x01,temp1);
1302     
1303     	if(temp2<=6) temp2=6;
1304     	if(temp2>0x14) temp2=0x14;
1305     	temp1=(UCHAR)GetReg1(Part1Port,0x02);			//part1port index 02
1306     	temp1=(temp1&(~0x1F))|temp2;
1307     	SetReg1(Part1Port,0x02,temp1);
1308     }
1309     
1310     USHORT GetVCLK(ULONG ROMAddr,USHORT ModeNo,
1311     			PHW_DEVICE_EXTENSION HwDeviceExtension)
1312     {
1313     	USHORT tempptr;
1314     	USHORT temp1;	 
1315     	tempptr=GetVCLKPtr(ROMAddr,ModeNo);
1316     	temp1=*((USHORT *)(ROMAddr+tempptr+(VCLKLen-2)));
1317     
1318     	return temp1;
1319     }
1320     
1321     USHORT GetQueueConfig(void)
1322     {
1323     	USHORT tempal,tempbl;
1324     	ULONG tempeax;
1325     	
1326     	SetReg4(0xcf8,0x80000050);
1327     	tempeax=GetReg3(0xcfc);
1328     	tempeax=(tempeax>>24)&0x0f;
1329     	tempbl=(USHORT)tempeax;
1330     	tempbl=tempbl<<4;
1331     	
1332     	SetReg4(0xcf8,0x800000A0);
1333     	tempeax=GetReg3(0xcfc);
1334     	tempeax=(tempeax>>24)&0x0f;
1335     	tempal=(USHORT)tempeax;
1336     	tempbl=tempbl|tempal;
1337     	
1338     	return(tempbl);
1339     }
1340     
1341     USHORT GetVCLKPtr(ULONG ROMAddr,USHORT ModeNo)
1342     {
1343     	USHORT tempal;
1344     	tempal=(UCHAR)GetReg2((USHORT)(P3ca+0x02));		//	Port 3cch
1345     	tempal=((tempal>>2)&0x03);
1346     	if(ModeNo>0x13){
1347     		tempal=*((UCHAR *)(ROMAddr+REFIndex+0x03));	//di+Ext_CRTVCLK
1348     		tempal=tempal&0x03F;
1349     	}
1350     	VCLKLen=GetVCLKLen(ROMAddr);
1351     	tempal=tempal*VCLKLen;
1352     	tempal=tempal+(*((USHORT *)(ROMAddr+0x208)));	// VCLKData
1353     	return ((USHORT)tempal);
1354     }
1355     
1356     USHORT GetColorTh(ULONG ROMAddr)
1357     {
1358     	USHORT temp;
1359     	temp=GetColorDepth(ROMAddr);
1360     	temp=temp>>1;
1361     	if(temp==0) temp++;
1362     	return temp;
1363     }
1364     
1365     USHORT GetMCLK(ULONG ROMAddr)
1366     {
1367     	USHORT tempmclkptr;
1368     	USHORT tempmclk;
1369     	tempmclkptr=GetMCLKPtr(ROMAddr);
1370     	tempmclk=*((USHORT *)(ROMAddr+tempmclkptr+0x03));	//di+3
1371     	return tempmclk;
1372     }
1373     
1374     USHORT GetMCLKPtr(ULONG ROMAddr)
1375     {
1376     	USHORT tempdi;
1377     	USHORT tempdramtype,tempax;
1378     
1379     	tempdi=*((USHORT *)(ROMAddr+0x20C));	// MCLKData
1380     	tempdramtype=GetDRAMType(ROMAddr);
1381     	tempax=5*tempdramtype;
1382     	tempdi=tempdi+tempax;
1383     	return (tempdi); 
1384     }
1385     
1386     USHORT GetDRAMType(ULONG ROMAddr)
1387     {
1388     	USHORT tsoftsetting,temp3;
1389     
1390     	tsoftsetting=*((UCHAR *)(ROMAddr+0x52));
1391     	if(!(tsoftsetting&SoftDramType)){
1392     		temp3=(UCHAR)GetReg1(P3c4,0x3A);
1393     		tsoftsetting=temp3;	
1394     	}
1395     	tsoftsetting=tsoftsetting&0x07;
1396     	return(tsoftsetting);
1397     }
1398     
1399     static USHORT CalcDelay()
1400     {
1401     	USHORT tempal,tempah,temp1,tempbx;
1402     	USHORT ThTiming[8]={1,2,2,3,0,1,1,2};
1403     	USHORT ThLowB[24]={81,4,72,6,88,8,120,12,
1404     					   55,4,54,6,66,8,90,12,
1405     					   42,4,45,6,55,8,75,12};
1406     
1407     	tempah=(UCHAR)GetReg1(P3c4,0x18);	//SR_18
1408     	tempah=tempah&0x62;
1409     	tempah=tempah>>1;
1410     	tempal=tempah;
1411     	tempah=tempah>>3;
1412     	tempal=tempal|tempah;
1413     	tempal=tempal&0x07;
1414     
1415     	temp1=ThTiming[tempal];		 		//temp1->cl
1416     
1417     	tempbx=(UCHAR)GetReg1(P3c4,0x16);	//SR_16
1418     	tempbx=tempbx>>6;
1419     	tempah=(UCHAR)GetReg1(P3c4,0x14);	//SR_14
1420     	tempah=((tempah>>4)&0x0C);
1421     	tempbx=((tempbx|tempah)<<1);
1422     	
1423     	tempal=ThLowB[tempbx+1]*temp1;
1424     	tempbx=ThLowB[tempbx];
1425     	tempbx=tempal+tempbx;
1426     
1427     	return(tempbx);	
1428     }
1429     
1430     USHORT GetVCLK2Ptr(ULONG ROMAddr,USHORT ModeNo)
1431     {
1432     	USHORT tempal;
1433     	USHORT LCDXlat1VCLK[4]={VCLK65,VCLK65,VCLK65,VCLK65};
1434     	USHORT LCDXlat2VCLK[4]={VCLK108_2,VCLK108_2,VCLK108_2,VCLK108_2};
1435     
1436     	if(ModeNo<=0x13){
1437     		tempal=*((UCHAR *)(ROMAddr+ModeIDOffset+0x04));	// si+St_CRT2CRTC
1438     	}else{
1439     		tempal=*((UCHAR *)(ROMAddr+REFIndex+0x04));		// di+Ext_CRT2CRTC
1440     	}
1441     	tempal=tempal>>6;
1442     	if(LCDResInfo!=Panel1024x768){
1443     		tempal=LCDXlat2VCLK[tempal];
1444     	}else{
1445     		tempal=LCDXlat1VCLK[tempal];
1446     	}
1447     	
1448     	if(VBInfo&SetCRT2ToLCD){
1449     		tempal=tempal;
1450     	}else if(VBInfo&SetCRT2ToTV){
1451     		if(SetFlag&RPLLDIV2XO){
1452     			tempal=TVVCLKDIV2;
1453     		}else{
1454     			tempal=TVVCLK;
1455     		}
1456     	}else{
1457     		tempal=(UCHAR)GetReg2((USHORT)(P3ca+0x02)); //	Port 3cch
1458     		tempal=((tempal>>2)&0x03);
1459     		if(ModeNo>0x13){
1460     			tempal=*((UCHAR *)(ROMAddr+REFIndex+0x03));	 //di+Ext_CRTVCLK
1461     			tempal=tempal&0x03F;
1462     	 	}
1463     	}
1464     	VCLKLen=GetVCLKLen(ROMAddr);
1465     	tempal=tempal*VCLKLen;
1466     	tempal=tempal+(*((USHORT *)(ROMAddr+0x208)));	// VCLKData
1467     	return ((USHORT)tempal);
1468     }
1469     
1470     USHORT GetVCLKLen(ULONG ROMAddr)
1471     {
1472     	USHORT VCLKDataStart,vclklabel,temp;
1473     	VCLKDataStart=*((USHORT *)(ROMAddr+0x208));
1474     	for(temp=0;;temp++){
1475     		vclklabel=*((USHORT *)(ROMAddr+VCLKDataStart+temp));
1476     		if(vclklabel==VCLKStartFreq){
1477     			temp=temp+2;
1478     			return(temp);	 
1479     		}
1480     	}
1481     	return(0);
1482     }
1483     
1484     
1485     VOID SetCRT2Sync(USHORT BaseAddr,ULONG ROMAddr,USHORT ModeNo)
1486     {
1487     	USHORT temp1,tempah=0;
1488     	USHORT temp;	
1489     	USHORT	Part1Port;
1490     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
1491     	if(IF_DEF_LVDS==1){	//LVDS
1492     		if(VBInfo&SetCRT2ToLCD){
1493     			tempah=LCDInfo;
1494     			if(!(tempah&LCDSync)){
1495     				temp=*((USHORT *)(ROMAddr+REFIndex));	 //di+Ext_InfoFlag
1496     				tempah=(temp>>8)&0x0C0;
1497     			}else{
1498     				tempah=tempah&0x0C0;
1499     			}
1500     		}
1501     	}else{
1502     		temp=*((USHORT *)(ROMAddr+REFIndex));	 //di+Ext_InfoFlag
1503     		tempah=(temp>>8)&0x0C0;
1504     	}
1505     	temp1=(UCHAR)GetReg1(Part1Port,0x19);			//part1port index 02
1506     	temp1=(temp1&(~0x0C0))|tempah;
1507     	SetReg1(Part1Port,0x19,temp1);
1508     }
1509     
1510     VOID GetCRT1Ptr(ULONG ROMAddr)
1511     {
1512     	USHORT temprefcrt1;
1513     	USHORT temp;
1514     	temp=*((UCHAR *)(ROMAddr+REFIndex+0x02));	//di+Ext_CRT1CRTC
1515     	temp=temp&0x03F;
1516     	temp=temp*CRT1Len;
1517     	temprefcrt1=*((USHORT *)(ROMAddr+0x204));	// Get CRT1Table
1518     	REFIndex=temprefcrt1+temp;			// di->CRT1Table+Ext_CRT1CRTC*CRT1Len
1519     }
1520     
1521     USHORT GetVGAHT2()
1522     {
1523     	long int temp1,temp2;
1524     
1525     	temp1=(VGAVT-VGAVDE)*RVBHCMAX;
1526     	temp1=temp1&0x0FFFF;
1527     	temp2=(VT-VDE)*RVBHCFACT;
1528     	temp2=temp2&0x0FFFF;
1529     	temp2=temp2*HT;
1530     	temp2=temp2/temp1;
1531     	return((USHORT)temp2);
1532     }
1533     
1534     VOID SetGroup2(USHORT	BaseAddr,ULONG ROMAddr)
1535     {
1536     	USHORT tempah,tempbl,tempbh,tempcl,i,j,tempcx,pushcx,tempbx,tempax;
1537     	USHORT tempmodeflag,tempflowflag;
1538     	UCHAR *temp1;
1539     	USHORT *temp2;
1540     	USHORT pushbx;
1541     	USHORT	Part2Port;
1542     	long int longtemp;
1543     
1544     	Part2Port=BaseAddr+IND_SIS_CRT2_PORT_10;
1545     
1546     	tempcx=VBInfo;
1547     	tempah=VBInfo&0x0FF;
1548     	tempbl=VBInfo&0x0FF;
1549     	tempbh=VBInfo&0x0FF;
1550     	tempbx=(tempbl&0xFF)|(tempbh<<8);
1551     	tempbl=tempbl&0x10;
1552     	tempbh=(tempbh&0x04)<<1;
1553     	tempah=(tempah&0x08)>>1;
1554     	tempah=tempah|tempbh;
1555     	tempbl=tempbl>>3;
1556     	tempah=tempah|tempbl;
1557     	tempah=tempah^0x0C;
1558     	
1559     	if(VBInfo&SetPALTV){
1560     		temp1=(UCHAR *)(ROMAddr+0x0F1);		//PALPhase
1561     		temp2=PALTiming;
1562     	}else{
1563     		tempah=tempah|0x10;
1564     		temp1=(UCHAR *)(ROMAddr+0x0ED);		//NTSCPhase
1565     		temp2=NTSCTiming;
1566     	} 
1567     
1568     	SetReg1(Part2Port,0x0,tempah);
1569     	for(i=0x31;i<=0x34;i++,temp1++){
1570     		SetReg1(Part2Port,i,*(UCHAR *)temp1);
1571     	}
1572     	for(i=0x01,j=0;i<=0x2D;i++,j++){
1573     		SetReg1(Part2Port,i,temp2[j]);
1574     	}
1575     	for(i=0x39;i<=0x45;i++,j++){
1576     		SetReg1(Part2Port,i,temp2[j]);	//di->temp2[j]
1577     	}
1578     
1579     	tempah=GetReg1(Part2Port,0x0A);
1580     	tempah=tempah|NewFlickerMode;
1581     	SetReg1(Part2Port,0x0A,tempah);
1582     
1583     	SetReg1(Part2Port,0x35,RY1COE);
1584     	SetReg1(Part2Port,0x36,RY2COE);
1585     	SetReg1(Part2Port,0x37,RY3COE);
1586     	SetReg1(Part2Port,0x38,RY4COE);
1587     
1588     	tempcx=HT-1;
1589     	tempah=tempcx&0xFF;
1590     	SetReg1(Part2Port,0x1B,tempah);
1591     	tempah=(tempcx&0xFF00)>>8;
1592     	SetRegANDOR(Part2Port,0x1D,~0x0F,(UCHAR)tempah);
1593     
1594     	tempcx=HT>>1;
1595     	pushcx=tempcx;
1596     
1597     	tempcx=tempcx+7;
1598     	tempah=(tempcx&0xFF);
1599     	tempah=(tempah<<4)&0xFF;
1600     	SetRegANDOR(Part2Port,0x22,~0x0F0,tempah);
1601     
1602     	
1603     	tempbx=temp2[j];
1604     	tempbx=tempbx+tempcx;
1605     	tempah=tempbx&0xFF;
1606     	SetReg1(Part2Port,0x24,tempah);
1607     	tempah=(tempbx&0xFF00)>>8;
1608     	tempah=(tempah<<4)&0xFF;
1609     	SetRegANDOR(Part2Port,0x25,~0x0F0,tempah);
1610     
1611     	tempbx=tempbx+8;
1612     
1613     	tempah=((tempbx&0xFF)<<4)&0xFF;
1614     	SetRegANDOR(Part2Port,0x29,~0x0F0,tempah);
1615     
1616     	tempcx=tempcx+temp2[++j];
1617     	tempah=tempcx&0xFF;
1618     	SetReg1(Part2Port,0x27,tempah);
1619     	tempah=(((tempcx&0xFF00)>>8)<<4)&0xFF;
1620     	SetRegANDOR(Part2Port,0x28,~0x0F0,tempah);
1621     
1622     	tempcx=tempcx+8;
1623     
1624     	tempah=tempcx&0xFF;
1625     	tempah=(tempah<<4)&0xFF;
1626     	SetRegANDOR(Part2Port,0x2A,~0x0F0,tempah);
1627     
1628     	tempcx=pushcx;	//pop cx
1629     	tempcx=tempcx-temp2[++j];
1630     	tempah=tempcx&0xFF;
1631     	tempah=(tempah<<4)&0xFF;
1632     	SetRegANDOR(Part2Port,0x2D,~0x0F0,tempah);
1633     
1634     	tempcx=tempcx-11;
1635     	if(!(VBInfo&SetCRT2ToTV)){
1636     		tempax=GetVGAHT2(); 
1637     		tempcx=tempax-1;
1638     	}
1639     	tempah=tempcx&0xFF;
1640     	SetReg1(Part2Port,0x2E,tempah);
1641     
1642     	tempbx=VDE;
1643     	if(VGAVDE==360){
1644     		tempbx=746;
1645     	} 
1646     	if(VGAVDE==375){
1647     		tempbx=746;
1648     	}
1649     	if(VGAVDE==405){
1650     		tempbx=853;
1651     	}
1652     	if((VBInfo&SetCRT2ToTV)){
1653     	 tempbx=tempbx>>1;
1654     	}
1655     	
1656     	tempbx=tempbx-2;
1657     	tempah=tempbx&0xFF;
1658     	SetReg1(Part2Port,0x2F,tempah);
1659     
1660     	tempah=(tempcx&0xFF00)>>8;
1661     	tempbh=(tempbx&0xFF00)>>8;
1662     	tempbh=(tempbh<<6)&0xFF;
1663     	tempah=tempah|tempbh;
1664     	//assuming <<ifndef>> hivisiontv
1665     	tempah=tempah|0x10;
1666     	if(!(VBInfo&SetCRT2ToSVIDEO)){
1667     		tempah=tempah|0x20; 
1668     	}
1669      
1670     	SetReg1(Part2Port,0x30,tempah);
1671      
1672     	tempbh=0;
1673     	tempbx=tempbx&0xFF;
1674     	
1675     	tempmodeflag=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));		// si+St_ModeFlag
1676     	tempflowflag=0;
1677     	if(!(tempmodeflag&HalfDCLK)){
1678     		tempcx=VGAHDE;
1679     		if(tempcx>=HDE){
1680     			tempbh=tempbh|0x20;
1681     			tempbx=(tempbh<<8)|(tempbx&0xFF);
1682     			tempah=0;
1683     		}
1684     	}
1685     	tempcx=0x0101;
1686     	if(!(tempbh&0x20)){		
1687     		if(tempmodeflag&HalfDCLK){
1688     			tempcl=((tempcx&0xFF)<<1)&0xFF;
1689     			tempcx=(tempcx&0xFF00)|tempcl; 
1690     	 	}
1691     		pushbx=tempbx;
1692     		tempax=VGAHDE;
1693     		tempbx=(tempcx&0xFF00)>>8;
1694     		longtemp=tempax*tempbx;
1695     		tempcx=tempcx&0xFF;
1696     		longtemp=longtemp/tempcx;
1697     		longtemp=longtemp*8*1024;
1698     		tempax=(USHORT)((longtemp)/HDE);
1699     		if(tempax*HDE<longtemp){
1700     			tempax=tempax+1;
1701     	 	}else{
1702     			tempax=tempax;
1703     	 	}
1704     	 	tempbx=pushbx;
1705     	 	tempah=((tempax&0xFF00)>>8)&0x01F;
1706     	 	tempbh=tempbh|tempah;
1707     	 	tempah=tempax&0xFF;
1708     	}
1709     
1710     	SetReg1(Part2Port,0x44,tempah);
1711     	tempah=tempbh;
1712     	SetRegANDOR(Part2Port,0x45,~0x03F,tempah);
1713     	
1714     	if(VBInfo&SetCRT2ToTV){
1715     		return;
1716     	}
1717     
1718     	tempah=0x01;
1719     	if(LCDResInfo==Panel1280x1024){
1720     		if(ModeType==ModeEGA){		
1721     			if(VGAHDE>=1024){
1722     				tempah=0x02; 
1723     			}
1724     	 	}
1725     	} 
1726     	SetReg1(Part2Port,0x0B,tempah);
1727     	
1728     	tempbx=HDE-1;			//RHACTE=HDE-1
1729     	tempah=tempbx&0xFF;
1730     	SetReg1(Part2Port,0x2C,tempah);
1731     	tempah=(tempbx&0xFF00)>>8;
1732     	tempah=(tempah<<4)&0xFF;
1733     	SetRegANDOR(Part2Port,0x2B,~0x0F0,tempah);
1734     	
1735     	tempbx=VDE-1;			//RTVACTEO=(VDE-1)&0xFF
1736     	tempah=tempbx&0xFF;
1737     	SetReg1(Part2Port,0x03,tempah);
1738     	tempah=((tempbx&0xFF00)>>8)&0x07;
1739     	SetRegANDOR(Part2Port,0x0C,~0x07,tempah);
1740     
1741     	tempcx=VT-1;
1742     	tempah=tempcx&0xFF;	//RVTVT=VT-1
1743     	SetReg1(Part2Port,0x19,tempah);
1744     	tempah=(tempcx&0xFF00)>>8;
1745     	tempah=(tempah<<5)&0xFF;
1746     	if(LCDInfo&LCDRGB18Bit){
1747     		tempah=tempah|0x10;
1748     	}
1749     	SetReg1(Part2Port,0x1A,tempah);
1750     	
1751     	tempcx++;
1752     	if(LCDResInfo==Panel1024x768){
1753     		tempbx=768;
1754     	}else{
1755     		tempbx=1024;
1756     	}
1757     	
1758     	if(tempbx==VDE){
1759     		tempax=1;
1760     	}else{
1761     		tempax=tempbx;
1762     		tempax=(tempax-VDE)>>1;
1763     	}
1764     	tempcx=tempcx-tempax; //lcdvdes
1765     	tempbx=tempbx-tempax; //lcdvdee
1766     
1767     	tempah=tempcx&0xFF;	//RVEQ1EQ=lcdvdes
1768     	SetReg1(Part2Port,0x05,tempah);
1769     	tempah=tempbx&0xFF;	//RVEQ2EQ=lcdvdee
1770     	SetReg1(Part2Port,0x06,tempah);
1771     
1772     	tempah=(tempbx&0xFF00)>>8;
1773     	tempah=(tempah<<3)&0xFF;
1774     	tempah=tempah|((tempcx&0xFF00)>>8); 
1775     			//RTVACTSE=(lcdvdes&0x700>>8)+(lcdvdee&0x700>>5);
1776     	SetReg1(Part2Port,0x02,tempah);
1777     	
1778      
1779     	tempcx=(VT-VDE)>>4;	//(VT-VDE)>>4
1780     	tempbx=(VT+VDE)>>1;
1781     	tempah=tempbx&0xFF;	//RTVACTEE=lcdvrs
1782     	SetReg1(Part2Port,0x04,tempah);
1783     
1784     	tempah=(tempbx&0xFF00)>>8;
1785     	tempah=(tempah<<4)&0xFF;
1786     	tempbx=tempbx+tempcx+1;
1787     	tempbl=(tempbx&0x0F);
1788     	tempah=tempah|tempbl;	//RTVACTSO=lcdvrs&0x700>>4+lcdvre
1789     	SetReg1(Part2Port,0x01,tempah);
1790     
1791     	tempah=GetReg1(Part2Port,0x09);
1792     	tempah=tempah&0xF0;
1793     	SetReg1(Part2Port,0x09,tempah);
1794     
1795     	tempah=GetReg1(Part2Port,0x0A);
1796     	tempah=tempah&0xF0;
1797     	SetReg1(Part2Port,0x0A,tempah);
1798     
1799     	tempcx=(HT-HDE)>>2;	 //(HT-HDE)>>2
1800     	tempbx=(HDE+7);			//lcdhdee
1801     	tempah=tempbx&0xFF;	 //RHEQPLE=lcdhdee
1802     	SetReg1(Part2Port,0x23,tempah);
1803     	tempah=(tempbx&0xFF00)>>8;
1804     	SetRegANDOR(Part2Port,0x25,~0x0F,tempah);
1805     
1806     	SetReg1(Part2Port,0x1F,0x07);	//RHBLKE=lcdhdes
1807     	tempah=GetReg1(Part2Port,0x20);
1808     	tempah=tempah&0x0F;
1809     	SetReg1(Part2Port,0x20,tempah);
1810     
1811     	tempbx=tempbx+tempcx;
1812     	tempah=tempbx&0xFF;				//RHBURSTS=lcdhrs
1813     	SetReg1(Part2Port,0x1C,tempah);
1814     	tempah=(tempbx&0xFF00)>>8;
1815     	tempah=(tempah<<4)&0xFF; 
1816     	SetRegANDOR(Part2Port,0x1D,~0x0F0,tempah);
1817     
1818     	tempbx=tempbx+tempcx;
1819     	tempah=tempbx&0xFF;				//RHSYEXP2S=lcdhre
1820     	SetReg1(Part2Port,0x21,tempah);
1821     
1822     	tempah=GetReg1(Part2Port,0x17);
1823     	tempah=tempah&0xFB;
1824     	SetReg1(Part2Port,0x17,tempah);
1825     
1826     	tempah=GetReg1(Part2Port,0x18);
1827     	tempah=tempah&0xDF;
1828     	SetReg1(Part2Port,0x18,tempah);
1829     	return;
1830     }
1831     
1832     VOID SetGroup3(USHORT	BaseAddr)
1833     {
1834     	USHORT i;
1835     	USHORT *tempdi;
1836     	USHORT	Part3Port;
1837     	Part3Port=BaseAddr+IND_SIS_CRT2_PORT_12;
1838     	if(VBInfo&SetPALTV){
1839     		tempdi=PALGroup3Data;					
1840     	}else{
1841     		tempdi=NTSCGroup3Data;
1842     	}
1843     
1844     	for(i=0;i<=0x3E;i++){
1845     		SetReg1(Part3Port,i,tempdi[i]);
1846     	}
1847     	return;
1848     }
1849     
1850     VOID SetGroup4(USHORT	BaseAddr,ULONG ROMAddr,USHORT ModeNo)
1851     {
1852     	USHORT	Part4Port;
1853     	USHORT tempax,tempah,tempcx,tempbx,tempbh,tempch,tempmodeflag;
1854     	long int tempebx,tempeax,templong;	
1855     	Part4Port=BaseAddr+IND_SIS_CRT2_PORT_14;
1856     
1857     	tempax=0x0c;
1858     	if(VBInfo&SetCRT2ToTV){
1859     		if(VBInfo&SetInSlaveMode){
1860     			if(!(SetFlag&TVSimuMode)){
1861     				SetFlag=SetFlag|RPLLDIV2XO;
1862     				tempax=tempax|0x04000;	
1863     			}
1864     		}else{
1865     			SetFlag=SetFlag|RPLLDIV2XO;
1866     			tempax=tempax|0x04000;	 
1867     		}
1868     	}
1869     
1870     	if(LCDResInfo!=Panel1024x768){
1871     		tempax=tempax|0x08000;
1872     	}
1873     	tempah=(tempax&0xFF00)>>8;
1874     	SetReg1(Part4Port,0x0C,tempah);
1875     	
1876     	tempah=RVBHCFACT;
1877     	SetReg1(Part4Port,0x13,tempah);
1878     	
1879     	tempbx=RVBHCMAX;
1880     	tempah=tempbx&0xFF;
1881     	SetReg1(Part4Port,0x14,tempah);
1882     	tempbh=(((tempbx&0xFF00)>>8)<<7)&0xFF;
1883     
1884     	tempcx=VGAHT-1;
1885     	tempah=tempcx&0xFF;
1886     	SetReg1(Part4Port,0x16,tempah);
1887     	tempch=(((tempcx&0xFF00)>>8)<<3)&0xFF;
1888     	tempbh=tempbh|tempch;
1889     	
1890     	tempcx=VGAVT-1;
1891     	if(!(VBInfo&SetCRT2ToTV)){
1892     		tempcx=tempcx-5;
1893     	}
1894     	tempah=tempcx&0xFF;
1895     	SetReg1(Part4Port,0x17,tempah);
1896     	tempbh=tempbh|((tempcx&0xFF00)>>8);
1897     	tempah=tempbh;
1898     	SetReg1(Part4Port,0x15,tempah);
1899     	
1900     	tempcx=VBInfo;
1901     	tempbx=VGAHDE;
1902     	tempmodeflag=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));		// si+St_ModeFlag
1903     	if(tempmodeflag&HalfDCLK){
1904     		tempbx=tempbx>>1;				
1905     	}
1906      
1907     	if(VBInfo&SetCRT2ToLCD){
1908     		tempah=0;
1909     		if(tempbx>800){
1910     			tempah=0x60; 
1911     		}
1912     	}else{
1913     		tempah=0x080;
1914     	}
1915     	if(LCDResInfo!=Panel1280x1024){
1916     		tempah=tempah|0x0A;
1917     	}
1918     
1919     	SetRegANDOR(Part4Port,0x0E,~0xEF,tempah);
1920     
1921     	tempebx=VDE;
1922     	
1923     	tempcx=RVBHRS;
1924     	tempah=tempcx&0xFF;
1925     	SetReg1(Part4Port,0x18,tempah);
1926     
1927     	tempeax=VGAVDE;
1928     	tempcx=tempcx|0x04000;
1929     	tempeax=tempeax-tempebx;
1930     	if(tempeax<0){
1931     		tempcx=tempcx^(0x04000);
1932     		tempeax=VGAVDE;
1933     	}
1934     
1935     	templong=(tempeax*256*1024)/tempebx;
1936     	if(tempeax*256*1024-templong*tempebx>0){
1937     		tempebx=templong+1;
1938     	}else{
1939     		tempebx=templong;
1940     	} 
1941     	
1942     
1943     	tempah=(USHORT)(tempebx&0xFF);
1944     	SetReg1(Part4Port,0x1B,tempah);
1945     	tempah=(USHORT)((tempebx&0xFF00)>>8);
1946     	SetReg1(Part4Port,0x1A,tempah);
1947     	tempebx=tempebx>>16;
1948     	tempah=(USHORT)(tempebx&0xFF);
1949     	tempah=(tempah<<4)&0xFF;
1950     	tempah=tempah|((tempcx&0xFF00)>>8);
1951     	SetReg1(Part4Port,0x19,tempah);
1952     	
1953     	SetCRT2VCLK(BaseAddr,ROMAddr,ModeNo);
1954     }
1955     
1956     VOID SetCRT2VCLK(USHORT BaseAddr,ULONG ROMAddr,USHORT ModeNo)
1957     {
1958     	USHORT vclk2ptr;
1959     	USHORT tempah,temp1;
1960     	USHORT	Part4Port;
1961     	Part4Port=BaseAddr+IND_SIS_CRT2_PORT_14;
1962     	vclk2ptr=GetVCLK2Ptr(ROMAddr,ModeNo);
1963     	SetReg1(Part4Port,0x0A,0x01);
1964     	tempah=*((UCHAR *)(ROMAddr+vclk2ptr+0x01));	//di+1
1965     	SetReg1(Part4Port,0x0B,tempah);
1966     	tempah=*((UCHAR *)(ROMAddr+vclk2ptr+0x00));	//di
1967     	SetReg1(Part4Port,0x0A,tempah);
1968     	SetReg1(Part4Port,0x12,0x00);
1969     	tempah=0x08;
1970     	if(VBInfo&SetCRT2ToRAMDAC){
1971     		tempah=tempah|0x020;
1972     	}
1973     	temp1=GetReg1(Part4Port,0x12);
1974     	tempah=tempah|temp1;
1975     	SetReg1(Part4Port,0x12,tempah);
1976     }
1977     
1978     VOID SetGroup5(USHORT	BaseAddr,ULONG ROMAddr)
1979     {
1980     	USHORT	Part5Port;
1981     	USHORT Pindex,Pdata;
1982     	Part5Port=BaseAddr+IND_SIS_CRT2_PORT_14+2;
1983     	Pindex=Part5Port;
1984     	Pdata=Part5Port+1;
1985     	if(ModeType==ModeVGA){
1986     		if(!(VBInfo&(SetInSlaveMode|LoadDACFlag|CRT2DisplayFlag))){
1987     			EnableCRT2();
1988     			LoadDAC2(ROMAddr,Part5Port);
1989     		}
1990     	}
1991     	return;
1992     }
1993     
1994     VOID EnableCRT2()
1995     {
1996     	USHORT temp1;
1997     	temp1=GetReg1(P3c4,0x1E);
1998     	temp1=temp1|0x20;
1999     	SetReg1(P3c4,0x1E,temp1);		//SR 1E
2000     }
2001     
2002     VOID LoadDAC2(ULONG ROMAddr,USHORT Part5Port)
2003     {
2004     	USHORT data,data2;
2005     	USHORT time,i,j,k;
2006     	USHORT m,n,o;
2007     	USHORT si,di,bx,dl;
2008     	USHORT al,ah,dh;
2009     	USHORT *table=VGA_DAC;
2010     	USHORT Pindex,Pdata;
2011     	Pindex=Part5Port;
2012     	Pdata=Part5Port+1;
2013     	data=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));
2014     	data=data&DACInfoFlag;
2015     	time=64;
2016     	if(data==0x00) table=MDA_DAC;
2017     	if(data==0x08) table=CGA_DAC;
2018     	if(data==0x10) table=EGA_DAC;
2019     	if(data==0x18) {
2020     		time=256;
2021     		table=VGA_DAC;
2022     	}
2023     	if(time==256) j=16;
2024     	else j=time;
2025     
2026     	//SetReg3(P3c6,0xFF);
2027     	SetReg3(Pindex,0x00);
2028     
2029     	for(i=0;i<j;i++) {
2030     		data=table[i];
2031     		for(k=0;k<3;k++) {
2032     			data2=0;
2033     			if(data&0x01) data2=0x2A;
2034     			if(data&0x02) data2=data2+0x15;
2035     			SetReg3(Pdata,data2);
2036     			data=data>>2;
2037     		}
2038     	}
2039     
2040     	if(time==256) {
2041     		for(i=16;i<32;i++) {
2042     			data=table[i];
2043     			for(k=0;k<3;k++) SetReg3(Pdata,data);
2044     		}
2045     		si=32;
2046     		for(m=0;m<9;m++) {
2047     			di=si;
2048     			bx=si+0x04;
2049     			dl=0;
2050     			for(n=0;n<3;n++) {
2051     				for(o=0;o<5;o++) {
2052     					dh=table[si];
2053     					ah=table[di];
2054     					al=table[bx];
2055     					si++;
2056     					WriteDAC2(Pdata,dl,ah,al,dh);
2057     				}			// for 5
2058     				si=si-2;
2059     				for(o=0;o<3;o++) {
2060     					dh=table[bx];
2061     					ah=table[di];
2062     					al=table[si];
2063     					si--;
2064     					WriteDAC2(Pdata,dl,ah,al,dh);
2065     				}			// for 3
2066     				dl++;
2067     			}				// for 3
2068     			si=si+5;
2069     		}					// for 9
2070     	}
2071     }
2072     
2073     VOID WriteDAC2(USHORT Pdata,USHORT dl, USHORT ah, USHORT al, USHORT dh)
2074     {
2075     	USHORT temp;
2076     	USHORT bh,bl;
2077     
2078     	bh=ah;
2079     	bl=al;
2080     	if(dl!=0) {
2081     		temp=bh;
2082     		bh=dh;
2083     		dh=temp;
2084     		if(dl==1) {
2085     			temp=bl;
2086     			bl=dh;
2087     			dh=temp;
2088     		}
2089     		else {
2090     			temp=bl;
2091     			bl=bh;
2092     			bh=temp;
2093     		}
2094     	}
2095     	SetReg3(Pdata,(USHORT)dh);
2096     	SetReg3(Pdata,(USHORT)bh);
2097     	SetReg3(Pdata,(USHORT)bl);
2098     }
2099     
2100     VOID LockCRT2(USHORT BaseAddr)
2101     {
2102     	USHORT	Part1Port;
2103     	USHORT	Part4Port;
2104     	USHORT temp1;
2105     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
2106     	Part4Port=BaseAddr+IND_SIS_CRT2_PORT_14;
2107     	temp1=GetReg1(Part1Port,0x24);
2108     	temp1=temp1&0xFE;
2109     	SetReg1(Part1Port,0x24,temp1);
2110     }
2111     
2112     VOID SetLockRegs()
2113     {
2114     	USHORT temp1;
2115     
2116     	if((VBInfo&SetInSlaveMode)&&(!(VBInfo&SetCRT2ToRAMDAC))){
2117     		VBLongWait();
2118     		temp1=GetReg1(P3c4,0x32);
2119     		temp1=temp1|0x20;
2120     		SetReg1(P3c4,0x32,temp1);
2121     		VBLongWait();
2122     	}
2123     }
2124     
2125     VOID EnableBridge(USHORT BaseAddr)
2126     {
2127     	USHORT part2_02,part2_05;
2128     	USHORT	Part2Port,Part1Port;
2129     	Part2Port=BaseAddr+IND_SIS_CRT2_PORT_10;
2130     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
2131     
2132     	if(IF_DEF_LVDS==0){
2133     		part2_02=(UCHAR)GetReg1(Part2Port,0x02);
2134     		part2_05=(UCHAR)GetReg1(Part2Port,0x05);
2135     		SetReg1(Part2Port,0x02,0x38);
2136     		SetReg1(Part2Port,0x05,0xFF);
2137     		LongWait();
2138     		SetRegANDOR(Part2Port,0x00,~0x0E0,0x020);
2139     		WaitVBRetrace(BaseAddr);
2140     		SetReg1(Part2Port,0x02,part2_02);
2141     		SetReg1(Part2Port,0x05,part2_05);
2142     	}else{
2143     		EnableCRT2();
2144     		UnLockCRT2(BaseAddr);
2145     		SetRegANDOR(Part1Port,0x02,~0x040,0x0);
2146     	}
2147     }
2148     
2149     USHORT GetLockInfo(USHORT pattern)
2150     {
2151     	USHORT temp1;
2152     	temp1=GetReg1(P3d4,0x36);
2153     	return(temp1&pattern);
2154     }	
2155     
2156     VOID GetVBInfo(USHORT BaseAddr,ULONG ROMAddr)
2157     {
2158     	USHORT flag1,tempbx,tempbl,tempbh,tempah;
2159     	
2160     	SetFlag=0;
2161     	tempbx=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));		// si+St_ModeFlag
2162     	tempbl=tempbx&ModeInfoFlag;
2163     	ModeType=tempbl;
2164     	tempbx=0;
2165     	flag1=GetReg1(P3c4,0x38);		//call BridgeisOn
2166     	if(!(flag1&0x20)){
2167     		VBInfo=CRT2DisplayFlag;
2168     		return;
2169     	}
2170     	tempbl=GetReg1(P3d4,0x30);	
2171     	tempbh=GetReg1(P3d4,0x31);
2172     	if(!(tempbl&0x07C)){
2173     		VBInfo=CRT2DisplayFlag;
2174     		return;
2175     	}
2176     	if(IF_DEF_LVDS==1){	//for LVDS
2177     		if(!(tempbl&SetCRT2ToLCD)){
2178     			VBInfo=CRT2DisplayFlag;
2179     			return;
2180     		}
2181     	}
2182     	if(IF_DEF_LVDS==0){ //for 301
2183     		if(tempbl&SetCRT2ToRAMDAC){
2184     			tempbl=tempbl&(SetCRT2ToRAMDAC|SwitchToCRT2|SetSimuScanMode);
2185     		}else if(tempbl&SetCRT2ToLCD){
2186     			tempbl=tempbl&(SetCRT2ToLCD|SwitchToCRT2|SetSimuScanMode);
2187     		}else if(tempbl&SetCRT2ToSCART){
2188     			tempbl=tempbl&(SetCRT2ToSCART|SwitchToCRT2|SetSimuScanMode);
2189     		}else if(tempbl&SetCRT2ToHiVisionTV){
2190     			tempbl=tempbl&(SetCRT2ToHiVisionTV|SwitchToCRT2|SetSimuScanMode);
2191     		}
2192     	}else{ //for LVDS
2193     		if(tempbl&SetCRT2ToLCD){
2194     			tempbl=tempbl&(SetCRT2ToLCD|SwitchToCRT2|SetSimuScanMode);
2195     		}
2196     	}
2197     	tempah=GetReg1(P3d4,0x31);
2198     	if(tempah&(CRT2DisplayFlag>>8)){
2199     		if(!(tempbl&(SwitchToCRT2|SetSimuScanMode))){
2200     			tempbx=SetSimuScanMode|CRT2DisplayFlag;
2201     			tempbh=((tempbx&0xFF00)>>8);
2202     			tempbl=tempbx&0xFF;
2203     		}
2204     	}
2205     	if(!(tempbh&(DriverMode>>8))){
2206     		tempbl=tempbl|SetSimuScanMode;
2207     	}
2208     	VBInfo=tempbl|(tempbh<<8);
2209     	if(!(VBInfo&SetSimuScanMode)){
2210     		if(!(VBInfo&SwitchToCRT2)){
2211     			if(BridgeIsEnable(BaseAddr)){
2212     				if(BridgeInSlave()){
2213     					VBInfo=VBInfo|SetSimuScanMode;
2214     				}	
2215     			}
2216     		}
2217     	}
2218     	if(!((VBInfo&(SetSimuScanMode|SwitchToCRT2)))){
2219     		return;
2220     	}
2221     	if(!(VBInfo&DriverMode)){
2222     		VBInfo=VBInfo|SetInSlaveMode;
2223     		if((VBInfo&SetCRT2ToTV)&&(!(VBInfo&SetNotSimuTVMode))){
2224     			SetFlag=SetFlag|TVSimuMode;
2225     		}
2226     	 	return;
2227     	}
2228     	flag1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));		// si+St_ModeFlag
2229     	if(!(flag1&(CRT2Mode|CRT2DisplayFlag))){
2230     		VBInfo=VBInfo|SetInSlaveMode;
2231     		if((VBInfo&SetCRT2ToTV)&&(!(VBInfo&SetNotSimuTVMode))){
2232     			SetFlag=SetFlag|TVSimuMode;
2233     		}
2234     	}
2235     }
2236     
2237     BOOLEAN BridgeIsEnable(USHORT BaseAddr)
2238     {
2239     	USHORT flag1;
2240     	USHORT	Part1Port;
2241     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
2242     
2243     	if(IF_DEF_LVDS==1){
2244     		return 1;
2245     	}
2246     	flag1=GetReg1(P3c4,0x38);		//call BridgeisOn
2247     	if(!(flag1&0x20)){ return 0;}
2248     	flag1=GetReg1(Part1Port,0x0);
2249     	if(flag1&0x0a0){
2250     		return 1;
2251     	}else{
2252     		return 0;
2253     	}
2254     }
2255     
2256     BOOLEAN BridgeInSlave()
2257     {
2258     	USHORT flag1;
2259     	flag1=GetReg1(P3d4,0x31);
2260     	if(flag1&(SetInSlaveMode>>8)){
2261     		return 1;
2262     	}else{
2263     		return 0;
2264     	}
2265     }
2266     
2267     BOOLEAN GetLCDResInfo(ULONG ROMAddr,USHORT P3d4)
2268     {
2269     	USHORT tempah,tempbh,tempflag;			
2270     	
2271     	tempah=(UCHAR)GetReg1(P3d4,0x36);
2272     	tempbh=tempah;
2273     	tempah=tempah&0x0F;
2274     	if(tempah>Panel1280x1024) tempah=Panel1024x768;
2275     	LCDResInfo=tempah;
2276     	tempbh=tempbh>>4;
2277     	LCDTypeInfo=tempbh;
2278     	
2279     	tempah=(UCHAR)GetReg1(P3d4,0x37);
2280     	LCDInfo=tempah;
2281     	if(IF_DEF_TRUMPION){
2282     		LCDInfo=LCDInfo&(~LCDNonExpanding);
2283     	}
2284     	if(IF_DEF_LVDS==1){
2285     		tempflag=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));		// si+St_ModeFlag
2286     		if(tempflag&HalfDCLK){
2287     			if(IF_DEF_TRUMPION==0){
2288     				if(!(LCDInfo&LCDNonExpanding)){
2289     					if(LCDResInfo==Panel1024x768){
2290     						tempflag=*((UCHAR *)(ROMAddr+ModeIDOffset+0x09)); //si+Ext_ResInfo
2291     						if(tempflag==4){ //512x384
2292     							SetFlag=SetFlag|EnableLVDSDDA;
2293     						}
2294     					}else{
2295     						if(LCDResInfo==Panel800x600){
2296     							tempflag=*((UCHAR *)(ROMAddr+ModeIDOffset+0x09)); //si+Ext_ResInfo	
2297     							if(tempflag==3){ //400x300
2298     								SetFlag=SetFlag|EnableLVDSDDA;
2299     							} 
2300     						}
2301     					}
2302     				}else{
2303     					SetFlag=SetFlag|EnableLVDSDDA;
2304     				}
2305     			}else{
2306     				SetFlag=SetFlag|EnableLVDSDDA;
2307     			}
2308     		}
2309     	}
2310     
2311     	if(!(VBInfo&SetCRT2ToLCD)){
2312     		return 1;				
2313     	}
2314     	if(!(VBInfo&(SetSimuScanMode|SwitchToCRT2))){
2315     		return 1;	
2316     	}
2317     	if(VBInfo&SetInSlaveMode){
2318     		if(VBInfo&SetNotSimuTVMode){
2319     			SetFlag=SetFlag|LCDVESATiming;	 
2320     		}	
2321     	}else{
2322     		SetFlag=SetFlag|LCDVESATiming;		
2323     	}
2324     	return 1;		
2325     }
2326     
2327     VOID PresetScratchregister(USHORT P3d4,PHW_DEVICE_EXTENSION HwDeviceExtension)
2328     {
2329     	SetReg1(P3d4,0x37,0x00);		
2330     }
2331     
2332     BOOLEAN GetLCDDDCInfo(PHW_DEVICE_EXTENSION HwDeviceExtension)
2333     {
2334     	USHORT tempah;
2335     	tempah=(HwDeviceExtension->usLCDType);// set in sisv.c
2336     											//0:no lcd 1:1024x768 2:1280x1024
2337     	if(tempah>0) tempah++; // usLCDType: 
2338     								// 0:no lcd 1:800x600 2:1024x768 3:1280x1024
2339     	SetReg1(P3d4,0x36,tempah);//cr 36 0:no LCD 1:800x600 2:1024x768 3:1280x1024
2340     	if(tempah>0) return 1;
2341     	else return 0;			
2342     }
2343     
2344     VOID SetTVSystem(PHW_DEVICE_EXTENSION HwDeviceExtension,ULONG ROMAddr)
2345     {
2346     	USHORT tempah,temp;
2347     
2348     	if(IF_DEF_LVDS==0){ //301
2349     		if(PRIMARY_VGA==1){ //primary vga
2350     			if(HwDeviceExtension->jChipID >= SIS_Trojan){
2351     				tempah=GetReg1(P3c4,0x17);
2352     				if(tempah&ModeSwitchStatus){
2353     					tempah=GetReg1(P3c4,0x16);
2354     					tempah=tempah&ActivePAL;
2355     					tempah=tempah>>ActivePALShift;
2356     				}else{
2357     					temp=*((UCHAR *)(ROMAddr+SoftSettingAddr));
2358     					if(temp&SoftTVType){
2359     		 				tempah=*((UCHAR *)(ROMAddr+ModeSettingAddr));
2360     			 		}else{
2361     						tempah=GetReg1(P3c4,0x38);	//SR 38
2362     					}
2363     				}
2364     			}else{
2365     				temp=*((UCHAR *)(ROMAddr+SoftSettingAddr));
2366     				if(temp&SoftTVType){
2367     					tempah=*((UCHAR *)(ROMAddr+ModeSettingAddr));
2368     				}else{
2369     					tempah=GetReg1(P3c4,0x38);	//SR 38
2370     				}
2371     			}
2372     			tempah=tempah&0x01;		//get SR 38 D0 TV Type Selection
2373     									//0:NTSC 1:PAL
2374     			SetRegANDOR(P3d4,0x31,~0x01,tempah);//set CR 31 D0= SR 38 D0
2375     		}
2376     		else{ //Secondary 
2377     			tempah=GetReg1(P3c4,0x38);	//SR 38
2378     			tempah=tempah&0x01;			//get SR 38 D0 TV Type Selection
2379     										//0:NTSC 1:PAL
2380     			SetRegANDOR(P3d4,0x31,~0x01,tempah);//set CR 31 D0= SR 38 D0
2381     		}
2382     		return;
2383     	}else{ //LVDS
2384     		tempah=GetReg1(P3c4,0x16);	//SR 16
2385     		tempah=tempah&ActiveNonExpanding;
2386     		tempah=tempah>>ActiveNonExpandingShift;
2387     		tempah=tempah&0x01;	
2388     		tempah=tempah<<LCDNonExpandingShift;
2389     		SetRegANDOR(P3d4,0x37,~LCDNonExpanding,tempah);
2390     		return;
2391     	}		
2392     }
2393     
2394     BOOLEAN GetSenseStatus(PHW_DEVICE_EXTENSION HwDeviceExtension,USHORT BaseAddr,ULONG ROMAddr)
2395     {
2396     	USHORT flag1,tempbx,tempal,tempah,tempcx,i;	 
2397     	USHORT Part2Port,Part4Port;
2398     	USHORT RGBSenseData,YCSenseData,VideoSenseData;
2399     	USHORT P2reg0,SenseModeNo,OutputSelect;
2400     	Part2Port=BaseAddr+IND_SIS_CRT2_PORT_10;
2401     	Part4Port=BaseAddr+IND_SIS_CRT2_PORT_14;
2402     	RGBSenseData=*((USHORT *)(ROMAddr+0xF8)); //0:F8 in rompost.asm
2403     	YCSenseData=*((USHORT *)(ROMAddr+0xFA)); //0:FA in rompost.asm
2404     	VideoSenseData=*((USHORT *)(ROMAddr+0xFC)); //0:FC in rompost.asm
2405     
2406     	if(IF_DEF_LVDS==1){
2407     		GetPanelID();
2408     		tempah=LCDSense;
2409     		SetRegANDOR(P3d4,0x32,~0x5F,tempah); //Set CR 32
2410     		return 0;
2411     	}
2412     	 
2413     	flag1=GetReg1(P3c4,0x38);		//call BridgeisOn
2414     	if(!(flag1&0x20)){ return 0;}
2415     	P2reg0=GetReg1(Part2Port,0x00); //save Part2 Reg index 0
2416     	
2417     	if(!(BridgeIsEnable(BaseAddr))){
2418     		SenseModeNo=0x2E;
2419     		ModeType=ModeVGA;
2420     		VBInfo=SetCRT2ToRAMDAC;
2421     		SetFlag=0;
2422     		SetCRT2Group(BaseAddr,ROMAddr,SenseModeNo,HwDeviceExtension);
2423     		//here perform I/O delay ,read SR 05			
2424     		for(i=0;i<0x7FFF;i++){
2425     			flag1=GetReg1(P3c4,0x05);			
2426     		}
2427     	}		
2428     	
2429     	SetReg1(Part2Port,0x00,0x1C);	//Set part2 index 0= 0x1C
2430     	tempah=0;
2431     	
2432     	OutputSelect=*((UCHAR *)(ROMAddr+0xFE));	//OutputSelect 0:FE in Rompost.asm
2433     	if(OutputSelect&SetSCARTOutput){
2434     		tempal=SCARTSense;	
2435     	}else{
2436     		tempal=Monitor2Sense;
2437     	}
2438     	tempbx=RGBSenseData;
2439     	tempcx=0x0E08;
2440     	if(Sense(Part4Port,tempbx,tempcx)){
2441     		if(Sense(Part4Port,tempbx,tempcx)){
2442     			tempah=tempah|tempal; 
2443     		}		
2444     	}
2445     	tempbx=YCSenseData;
2446     	tempcx=0x0604;
2447     	if(Sense(Part4Port,tempbx,tempcx)){
2448     		if(Sense(Part4Port,tempbx,tempcx)){
2449     			tempah=tempah|SVIDEOSense;
2450     			//Skipped lines about HiTVSense, assuming not HiTV	
2451     		}
2452     	}
2453     
2454     	//Assuming not HiTV ,below is of ifndef HiVisionTV
2455     	if(OutputSelect&BoardTVType){
2456     		tempbx=VideoSenseData;
2457     		tempcx=0x0804;
2458     		if(Sense(Part4Port,tempbx,tempcx)){
2459     			if(Sense(Part4Port,tempbx,tempcx)){
2460     				tempah=tempah|AVIDEOSense;
2461     			}			
2462     		}	
2463     	}else{
2464     		if(!(tempah&SVIDEOSense)){
2465     			tempbx=VideoSenseData;
2466     			tempcx=0x0804;
2467     			if(Sense(Part4Port,tempbx,tempcx)){
2468     				if(Sense(Part4Port,tempbx,tempcx)){
2469     					tempah=tempah|AVIDEOSense; 
2470     				}		
2471     			}
2472     		}
2473     	}
2474     	//end of ifndef HivisionTv
2475     	if(SenseLCD(HwDeviceExtension,Part4Port,ROMAddr)){
2476     		if(SenseLCD(HwDeviceExtension,Part4Port,ROMAddr)){
2477     			tempah=tempah|LCDSense;
2478     		}		
2479     	}
2480     	
2481     	tempbx=0; 
2482     	tempcx=0;
2483     	Sense(Part4Port,tempbx,tempcx);
2484     	
2485     	SetRegANDOR(P3d4,0x32,~0x5F,tempah); //Set CR 32
2486     	SetReg1(Part2Port,0x00,P2reg0);		//recover Part2 reg index 0
2487     	
2488     	//here skipped lines about DisableCRT2Display 
2489     	return 0;	
2490     }
2491     
2492     BOOLEAN Sense(USHORT Part4Port,USHORT inputbx,USHORT inputcx)
2493     {
2494     	USHORT tempah,tempcl,tempch;
2495     	
2496     	tempah=inputbx&0xFF;
2497     	SetReg1(Part4Port,0x11,tempah);//Part4 index 11
2498     	tempah=(inputbx&0xFF00)>>8;
2499     	tempcl=inputcx&0xFF;
2500     	tempah=tempah|tempcl;
2501     	SetRegANDOR(Part4Port,0x10,~0x1F,tempah);//Part4 index 10
2502     	
2503     	tempch=(inputcx&0xFF00)>>8;
2504     	tempch=tempch&0x7F;
2505     	//here skipped lines about call Delay
2506     	tempah=GetReg1(Part4Port,0x03);		//Part4 index 03
2507     	tempah=tempah^(0x0E);
2508     	tempah=tempah&tempch;
2509     	if(tempah>0) return 1;
2510     	else return 0;			
2511     }
2512     
2513     BOOLEAN SenseLCD(PHW_DEVICE_EXTENSION HwDeviceExtension,USHORT Part4Port,ULONG ROMAddr)
2514     {
2515     	USHORT SoftSetting;
2516     	USHORT tempah;			
2517     	SoftSetting=*((UCHAR *)(ROMAddr+0x52));//0:52 in rompost.asm
2518     	if(GetLCDDDCInfo(HwDeviceExtension)){
2519     		return 1;	
2520     	}
2521     	if(SoftSetting&HotPlugFunction){
2522     		tempah=GetReg1(Part4Port,0x0F);
2523     		tempah=tempah&0x3F;
2524     		SetReg1(Part4Port,0x0F,tempah); //Part4 index 0F
2525     		if(Sense(Part4Port,0x0,0x9010)){
2526     			return 1; 
2527     		}else{
2528     			return 0;
2529     		}	
2530     	}else{
2531     		return 0;
2532     	}		
2533     }
2534     #endif
2535     
2536     VOID SetRegANDOR(USHORT Port,USHORT Index,USHORT DataAND,USHORT DataOR)
2537     {
2538     	USHORT temp1;
2539     	temp1=GetReg1(Port,Index);		//part1port index 02
2540     	temp1=(temp1&(DataAND))|DataOR;
2541     	SetReg1(Port,Index,temp1);
2542     }
2543     
2544     BOOLEAN DetectMonitor(PHW_DEVICE_EXTENSION HwDeviceExtension)
2545     {
2546     	USHORT flag1	;
2547     	USHORT DAC_TEST_PARMS[3]={0x0F,0x0F,0x0F};
2548     	USHORT DAC_CLR_PARMS[3]={0x00,0x00,0x00};
2549     	
2550     	flag1=GetReg1(P3c4,0x38);		//call BridgeisOn
2551     	if((flag1&0x20)){
2552     		SetReg1(P3d4,0x30,0x41);
2553     	}
2554     	
2555     	SiSSetMode(HwDeviceExtension,0x2E); //set mode to 0x2E instead of 0x3
2556      
2557     	ClearDAC(P3c8);
2558     	ClearALLBuffer(HwDeviceExtension);
2559     	
2560     	LongWait();	//wait vertical retrace
2561     	LongWait();
2562     	
2563     	flag1=TestMonitorType(DAC_TEST_PARMS[0],DAC_TEST_PARMS[1],
2564     			DAC_TEST_PARMS[2]);
2565     	if(flag1==0){
2566     		flag1=TestMonitorType(DAC_TEST_PARMS[0],DAC_TEST_PARMS[1],
2567     			DAC_TEST_PARMS[2]);		
2568     	}		
2569     	if(flag1==1){
2570     		SetRegANDOR(P3d4,0x32,~Monitor1Sense,Monitor1Sense);					 
2571     	}else{
2572     		SetRegANDOR(P3d4,0x32,~Monitor1Sense,0x0);
2573     	}
2574     	TestMonitorType(DAC_CLR_PARMS[0],DAC_CLR_PARMS[1],DAC_CLR_PARMS[2]);
2575     			
2576     	SetReg1(P3d4,0x34,0x4A);	//Preset default CRT1 ModeNo =0x4A
2577     								//which is used in SetCRT2FIFO()
2578     	return 1;		
2579     }
2580     
2581     BOOLEAN TestMonitorType(USHORT d1,USHORT d2,USHORT d3)
2582     {
2583     	USHORT temp;	
2584     	SetReg3(P3c6,0xFF);
2585     	SetReg3(P3c8,0x00);
2586     	SetReg3(P3c9,d1);
2587     	SetReg3(P3c9,d2);
2588     	SetReg3(P3c9,d3);
2589     	WaitDisplay();			//wait horizontal retrace
2590     	temp=GetReg2(P3c2);
2591     	if(temp&0x10) return 1;
2592     	else return 0;			
2593     }
2594     
2595     VOID WaitDisplay(void)
2596     {
2597     	USHORT temp;
2598      
2599     	for(temp=0;temp==0;){
2600     		temp=GetReg2(P3da);
2601     		temp=temp&0x01;	 
2602     	}
2603     	for(;temp==1;){
2604     		temp=GetReg2(P3da);
2605     		temp=temp&0x01;	 
2606     	}		
2607     }
2608     
2609     VOID LongWait(void)
2610     {
2611     	USHORT temp;
2612     	
2613     	for(temp=1;temp>0;){
2614     		temp=GetReg2(P3da);
2615     		temp=temp&0x08;	 
2616     	}
2617     	for(;temp==0;){
2618     		temp=GetReg2(P3da);
2619     		temp=temp&0x08;	 
2620     	}		
2621     }
2622     
2623     #ifndef CONFIG_FB_SIS_LINUXBIOS
2624     
2625     VOID VBLongWait(VOID)
2626     {
2627     	USHORT regsr1f,tempah,temp;
2628     
2629     	regsr1f=GetReg1(P3c4,0x1F);
2630     	tempah=regsr1f&(~0xC0);
2631     	SetReg1(P3c4,0x1F,tempah);
2632     
2633     	for(temp=1;temp>0;){
2634     		temp=GetReg2(P3da);
2635     		temp=temp&0x08;	 
2636     	}
2637     	for(;temp==0;){
2638     		temp=GetReg2(P3da);
2639     		temp=temp&0x08;	 
2640     	}
2641     
2642     	SetReg1(P3c4,0x1F,regsr1f);
2643     	return;	
2644     }
2645     
2646     BOOLEAN WaitVBRetrace(USHORT BaseAddr)
2647     {
2648     	USHORT temp;
2649     	USHORT Part1Port;
2650     	Part1Port=BaseAddr+IND_SIS_CRT2_PORT_04;
2651     	temp=GetReg1(Part1Port,0x00);
2652     	if(!(temp&0x80)){
2653     		return 0;
2654     	}
2655     
2656     	for(temp=0;temp==0;){
2657     		temp=GetReg1(Part1Port,0x25);
2658     		temp=temp&0x01;	 
2659     	}
2660     	for(;temp>0;){
2661     		temp=GetReg1(Part1Port,0x25);
2662     		temp=temp&0x01;	 
2663     	}
2664     	return 1; 
2665     }
2666     
2667     BOOLEAN GetPanelID(VOID)
2668     {
2669     	USHORT PanelTypeTable[16]={ SyncPP|Panel800x600|PanelType00,
2670     								SyncPP|Panel1024x768|PanelType01,
2671     								SyncPP|Panel1024x768|PanelType02,
2672     								SyncPP|Panel1024x768|PanelType03,
2673     								SyncPP|Panel1024x768|PanelType04,
2674     								SyncPP|Panel1024x768|PanelType05,
2675     								SyncPP|Panel1024x768|PanelType06,
2676     								SyncPP|Panel1024x768|PanelType07,
2677     								SyncPP|Panel1024x768|PanelType08,
2678     								SyncPP|Panel1024x768|PanelType09,
2679     								SyncPP|Panel800x600|PanelType0A,
2680     								SyncPP|Panel1024x768|PanelType0B,
2681     								SyncPP|Panel1024x768|PanelType0C,
2682     								SyncPP|Panel1024x768|PanelType0D,
2683     								SyncPP|Panel1024x768|PanelType0E,
2684     								SyncPP|Panel1024x768|PanelType0F};
2685     	// Bit 15 BPLVSPLTY
2686     	// Bit 14 BPLHSPLTY
2687     	// Bit 6-3 Panel Type
2688     	// Bit 2-0 Display Resolution(001:800x600 010:1024x768 011:1280x1024)
2689     	USHORT tempah,tempbx;
2690     	USHORT return_flag;
2691     
2692     	tempah=GetReg1(P3c4,0x18);
2693     	tempbx=tempah&0x0F;
2694     	if(tempah&0x10){
2695     		return_flag=1;
2696     	}else{
2697     		return_flag=0;
2698     	}
2699     
2700     	if(return_flag==0){
2701     		if(IF_DEF_LVDS==1){
2702     			tempbx=0;
2703     			tempah=GetReg1(P3c4,0x38);
2704     			if(tempah&0x40) tempbx=tempbx|0x08;
2705     			if(tempah&0x20) tempbx=tempbx|0x02;
2706     			if(tempah&0x01) tempbx=tempbx|0x01;
2707     			tempah=GetReg1(P3c4,0x39);
2708     			if(tempah&0x80) tempbx=tempbx|0x04;
2709     		}else{
2710     			return 0;
2711     		}
2712     	}
2713     
2714     	if(IF_DEF_TRUMPION==1){
2715     		tempbx=1;
2716     	}
2717     	tempbx=PanelTypeTable[tempbx]; //LVDS table entry
2718     	tempbx=tempbx|(USHORT)(LCDSync<<8);
2719     
2720     	tempah=tempbx&0x0FF;
2721     	SetReg1(P3d4,0x36,tempah);
2722     	tempah=(tempbx&0xFF00)>>8;
2723     	SetRegANDOR(P3d4,0x37,~LCDSyncBit,tempah);
2724     	return 1;
2725     }
2726     
2727     VOID ModCRT1CRTC(ULONG ROMAddr,USHORT ModeNo)
2728     {
2729     	USHORT OldREFIndex,temp,tempah,i,modeflag1;
2730     
2731     	OldREFIndex=(USHORT)REFIndex;
2732     	temp=GetLVDSCRT1Ptr(ROMAddr,ModeNo);
2733     	if(temp==0){
2734     		REFIndex=OldREFIndex;
2735     		return;
2736     	}
2737     	tempah=(UCHAR)GetReg1(P3d4,0x11);//unlock cr0-7
2738     	tempah=tempah&0x7F;
2739     	SetReg1(P3d4,0x11,tempah);
2740     	tempah=*((UCHAR *)(ROMAddr+REFIndex));
2741     	SetReg1(P3d4,0x0,tempah);
2742     	REFIndex++;
2743     	for(i=0x02;i<=0x05;REFIndex++){
2744     		tempah=*((UCHAR *)(ROMAddr+REFIndex));
2745     		SetReg1(P3d4,i,tempah); 
2746     	}
2747     	for(i=0x06;i<=0x07;REFIndex++){
2748     		tempah=*((UCHAR *)(ROMAddr+REFIndex));
2749     		SetReg1(P3d4,i,tempah); 
2750     	}
2751     	for(i=0x10;i<=0x11;REFIndex++){
2752     		tempah=*((UCHAR *)(ROMAddr+REFIndex));
2753     		SetReg1(P3d4,i,tempah); 
2754     	}
2755     	for(i=0x15;i<=0x16;REFIndex++){
2756     		tempah=*((UCHAR *)(ROMAddr+REFIndex));
2757     		SetReg1(P3d4,i,tempah); 
2758     	}
2759     
2760     	for(i=0x0A;i<=0x0C;REFIndex++){
2761     		tempah=*((UCHAR *)(ROMAddr+REFIndex));
2762     		SetReg1(P3c4,i,tempah); 
2763     	}
2764     	tempah=*((UCHAR *)(ROMAddr+REFIndex));
2765     	tempah=tempah&0x0E0;
2766     	SetReg1(P3c4,0x0E,tempah);
2767     
2768     	tempah=*((UCHAR *)(ROMAddr+REFIndex));
2769     	tempah=tempah&0x01;
2770     	tempah=tempah<<5;
2771     	modeflag1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
2772     	if(modeflag1&DoubleScanMode){
2773     		tempah=tempah|0x080;
2774     	}
2775     	SetRegANDOR(P3d4,0x09,~0x020,tempah);
2776     	REFIndex=OldREFIndex;
2777     	return; 
2778     }
2779     
2780     VOID SetCRT2ECLK(ULONG ROMAddr, USHORT ModeNo)
2781     {
2782     	USHORT OldREFIndex,tempah,tempal;
2783     	USHORT P3cc=P3c9+3;
2784     	OldREFIndex=(USHORT)REFIndex;
2785     	if(IF_DEF_TRUMPION==0){	//no trumpion
2786     		tempal=GetReg2(P3cc);
2787     		tempal=tempal&0x0C;
2788     		SetReg3(P3c2,tempal);
2789     		REFIndex=GetVCLKPtr(ROMAddr,ModeNo);
2790     	}else{	//trumpion
2791     		SetFlag=SetFlag&(~ProgrammingCRT2);
2792     		tempal=*((UCHAR *)(ROMAddr+REFIndex+0x03));	 //di+Ext_CRTVCLK
2793     		tempal=tempal&0x03F;
2794     		if(tempal==0x02){ //31.5MHz
2795     			REFIndex=REFIndex-Ext2StructSize;
2796     		}
2797     		REFIndex=GetVCLKPtr(ROMAddr,ModeNo);
2798     		SetFlag=SetFlag|ProgrammingCRT2;
2799     	}
2800     	tempal=0x02B;
2801     	if(!(VBInfo&SetInSlaveMode)){
2802     		tempal=tempal+3;
2803     	}
2804     	tempah=*((UCHAR *)(ROMAddr+REFIndex));	
2805     	SetReg1(P3c4,tempal,tempah);
2806     	tempah=*((UCHAR *)(ROMAddr+REFIndex+1));
2807     	tempal++; 
2808     	SetReg1(P3c4,tempal,tempah);
2809     	REFIndex=OldREFIndex;
2810     	return;
2811     }
2812     
2813     USHORT GetLVDSDesPtr(ULONG ROMAddr,USHORT ModeNo)
2814     {
2815     	USHORT tempcl,tempbx,tempal,tempptr,LVDSDesPtrData;
2816     	tempcl=LVDSDesDataLen;
2817     	tempbx=LCDTypeInfo;
2818     	if(LCDInfo&LCDNonExpanding){
2819     		tempbx=tempbx+16;
2820     	}
2821     	if(ModeNo<=0x13){
2822     		tempal=*((UCHAR *)(ROMAddr+ModeIDOffset+0x04));	// si+St_CRT2CRTC
2823     	}else{
2824     		tempal=*((UCHAR *)(ROMAddr+REFIndex+4));	 //di+Ext_CRT2CRTC
2825     	}
2826     	tempal=tempal&0x1F;
2827     	tempal=tempal*tempcl;
2828     	tempbx=tempbx<<1;
2829     	LVDSDesPtrData=*((USHORT *)(ROMAddr+ADR_LVDSDesPtrData));
2830     	tempptr=*((USHORT *)(ROMAddr+LVDSDesPtrData+tempbx));
2831     	tempptr=tempptr+tempal;
2832     	return(tempptr);
2833     	
2834     }
2835     
2836     BOOLEAN GetLVDSCRT1Ptr(ULONG ROMAddr,USHORT ModeNo)
2837     {
2838     	USHORT tempal,tempbx,modeflag1; 
2839     	USHORT LVDSCRT1DataPtr; 
2840     
2841     	if(!(VBInfo&SetInSlaveMode)){
2842     		return 0;
2843     	}
2844     	if(ModeNo<=0x13){
2845     		tempal=*((UCHAR *)(ROMAddr+ModeIDOffset+0x04));	// si+St_CRT2CRTC
2846     	}else{
2847     		tempal=*((UCHAR *)(ROMAddr+REFIndex+4));	 //di+Ext_CRT2CRTC
2848     	}
2849     	tempal=tempal&0x3F;
2850     
2851     	tempbx=LCDResInfo;
2852     	tempbx=tempbx-Panel800x600;
2853     	if(LCDInfo&LCDNonExpanding){
2854     		tempbx=tempbx+6;
2855     	}
2856     	modeflag1=*((USHORT *)(ROMAddr+ModeIDOffset+0x01));	// si+St_ModeFlag
2857     	if(modeflag1&HalfDCLK){
2858     		tempbx=tempbx+3;
2859     	}
2860     	tempbx=tempbx<<1;
2861     	LVDSCRT1DataPtr=*((USHORT *)(ROMAddr+ADR_LVDSCRT1DataPtr));
2862     	REFIndex=*((USHORT *)(ROMAddr+LVDSCRT1DataPtr+tempbx));
2863     	tempal=tempal*LVDSCRT1Len;
2864     	REFIndex=REFIndex+tempal;
2865     	return 1;
2866     }
2867     
2868     #endif
2869