1#include <unistd.h>
2#include <stdio.h>
3#include <stdlib.h>
4
5#include "iopl.h"
6
7int main(void)
8{
9    int i, HTotal, HDisplay, HSyncStart, HSyncEnd,
10    VTotal, VDisplay, VSyncStart, VSyncEnd;
11    unsigned char storeReg, bpp, shift, IOSS = 0, MSS = 0, again = 0;
12    unsigned short port;
13    int isHiQV = 0;
14    int is69030 = 0;
15
16    SET_IOPL();
17
18    printf("0x3C6\t0x%X\n",inw(0x3C6));
19
20/* Check to see if the Chip is HiQV */
21    outb(0x3D6,0x02);
22    storeReg = inb(0x3D7);
23    if (storeReg == 0xE0	/* CT65550 */
24	|| storeReg == 0xE4	/* CT65554 */
25	|| storeReg == 0xE5	/* CT65555 */
26	|| storeReg == 0xF4	/* CT68554 */
27	|| storeReg == 0xC0)	/* CT69000 */
28    {
29	isHiQV = 1;
30    } else if (storeReg == 0x30) {
31      outb(0x3D6,0x03);
32      storeReg = inb(0x3D7);
33      if (storeReg == 0xC) {
34	isHiQV = 1;
35	is69030 = 1;
36	IOSS=inb(0x3CD);
37	MSS=inb(0x3CB);
38	outb(0x3CD,((IOSS&0xE0)| 0x11));  /* Select Channel 0 */
39	outb(0x3CB,((MSS&0xF0)| 0x8));
40	again = 1;
41	printf("Pipeline A:\n");
42      }
43    }
44
45 again:
46    printf("port 0x3D6 (C&T)\n");
47    storeReg = inb(0x3D6);
48    shift = 3;
49    if (isHiQV==1) {
50	outw(0x102,1);	/*global enable, VGA awake*/
51	printf("0x%2.2X\n",inb(0x3C3)&0xFF);
52	outb(0x3C3,0);	/*disable VGA*/
53	outb(0x3C3,1);	/*enable VGA*/
54	for(i = 0;i < 0xFF;i++){
55	    outb(0x3D6,i);
56	    printf("XR 0x%2.2X\t0x%2.2X\n",i,inb(0x3D7)&0xFF);
57	}
58	outb(0x3D6,0xE2);
59	bpp = inb(0x3D7)&0xF0;
60    } else {
61	outb(0x3D6, 0x70);
62	outw(0x3D6, (inw(0x3D6) | 0x8070));
63	outw(0x46E8,0x0016);	/*setup mode*/
64	outw(0x102,1);	/*global enable, VGA awake*/
65	outw(0x46E8,0x000E);	/*exit from setup mode*/
66	printf("0x%2.2X\n",inb(0x3C3)&0xFF);
67	outb(0x3C3,0);	/*disable VGA*/
68	outw(0x46E8,0x0000);	/*exit from setup mode*/
69	outw(0x46E8,0x000E);	/*exit from setup mode*/
70	outb(0x3C3,1);	/*enable VGA*/
71	outw(0x46E8,0x0000);	/*exit from setup mode*/
72	for(i = 0;i < 0x80;i++){
73	    outb(0x3D6,i);
74	    printf("XR 0x%2.2X\t0x%2.2X\n",i,inb(0x3D7)&0xFF);
75	}
76	outb(0x3D6,0x2B);
77	bpp = inb(0x3D7)&0xF0;
78    }
79
80    switch(bpp){
81      case 0x20:
82	bpp = 4;
83	break;
84      case 0x30:
85	bpp = 8;
86	break;
87      case 0x40:
88	bpp = 16;
89	shift = 2;
90	break;
91      case 0x50:
92	bpp = 24;
93	break;
94      default:
95	bpp = 0;
96    }
97    outb(0x3D6,storeReg);
98
99    printf("\nport 0x3D4 (CRTC)\n");
100    storeReg = inb(0x3D4);
101    if (isHiQV==1) {
102	for(i = 0;i < 0x7F;i++){
103	    outb(0x3D4,i);
104	    printf("CR 0x%2.2X\t0x%2.2X\n",i,inb(0x3D5)&0xFF);
105	}
106	outb(0x3D4,storeReg);
107	printf("\nport 0x3D0 (Flat Panel)\n");
108	storeReg = inb(0x3D0);
109	for(i = 0;i < 0x7F;i++){
110	    outb(0x3D0,i);
111	    printf("FR 0x%2.2X\t0x%2.2X\n",i,inb(0x3D1)&0xFF);
112	}
113	outb(0x3D1,storeReg);
114	printf("\nport 0x3D2 (Multimedia)\n");
115	storeReg = inb(0x3D2);
116	for(i = 0;i < 0x7F;i++){
117	    outb(0x3D2,i);
118	    printf("MR 0x%2.2X\t0x%2.2X\n",i,inb(0x3D3)&0xFF);
119	}
120	outb(0x3D3,storeReg);
121    } else {
122	for(i = 0;i < 0x40;i++){
123	    outb(0x3D4,i);
124	    printf("CR 0x%2.2X\t0x%2.2X\n",i,inb(0x3D5)&0xFF);
125	}
126	outb(0x3D4,storeReg);
127    }
128
129
130    printf("port 0x3CE (GC)\n");
131    storeReg = inb(0x3CE);
132    for(i = 0;i < 0x10;i++){
133	outb(0x3CE,i);
134	printf("GC 0x%2.2X\t0x%2.2X\n",i,inb(0x3CF)&0xFF);
135    }
136    outb(0x3CE,storeReg);
137    printf("port 0x3C4 (Sequencer)\n");
138    storeReg = inb(0x3C4);
139    for(i = 0;i < 0x10;i++){
140	outb(0x3C4,i);
141	printf("SQ 0x%2.2X\t0x%X2.2\n",i,inb(0x3C5)&0xFF);
142    }
143    outb(0x3C4,storeReg);
144
145
146    printf("port 0x3C0 (Attribute)\n");
147    inb(0x3DA);
148    storeReg = inb(0x3C0);
149    for(i = 0;i < 0xFF;i++){
150	inb(0x3DA);
151	outb(0x3C0,i);
152	printf("AT 0x%2.2X\t0x%2.2X\n",i,inb(0x3C1)&0xFF);
153    }
154    inb(0x3DA);
155    outb(0x3C0,storeReg);
156
157    printf("0x3CC\t0x%X\n",inb(0x3CC)&0xFF);
158    printf("0x3C2\t0x%X\n",inb(0x3C2)&0xFF);
159    printf("0x3C3\t0x%X\n",inb(0x3C2)&0xFF);
160    printf("0x3CA\t0x%X\n",inb(0x3CA)&0xFF);
161    printf("0x3DA\t0x%X\n",inb(0x3DA)&0xFF);
162
163    printf("\nRAMDAC\nport\tvalue\n");
164    for(port = 0x83C6; port < 0x83CA;port++){
165      printf("0x%4X\t0x%4X\n",port,inw(port));
166    }
167
168    if (isHiQV!=1) {
169	printf("\nBitBLT\nport\tvalue\n");
170	for(port = 0x83D0; port <= 0x9FD0;port+=0x400){
171	    printf("0x%4.4X\t0x%4X\n",port,inw(port));
172	}
173
174	printf("\nH/W cursor\nport\tvalue\n");
175	for(port = 0xA3D0; port <= 0xB3D0;port+=0x400){
176	    printf("0x%4.4X\t0x%4X\n",port,inw(port));
177	}
178
179
180	outb(0x3D6, 0x70);
181	outw(0x3D6, (inw(0x3D6) | 0x8070));
182
183	printf("0x46E8\t0x%8X\n",inl(0x46E8));
184	printf("0x4AE8\t0x%8X\n",inl(0x4AE8));
185	printf("0x102\t0x%8X\n",inl(0x102));
186	printf("0x103\t0x%8X\n",inl(0x103));
187
188    }
189
190    storeReg = inb(0x3D4);
191    {
192	outb(0x3D4,0);
193	HTotal = ((inb(0x3D5)&0xFF) + 5) << shift;
194	outb(0x3D4,1);
195	HDisplay = ((inb(0x3D5)&0xFF) + 1) << shift;
196	outb(0x3D4,4);
197	HSyncStart = ((inb(0x3D5)&0xFF) + 1) << shift;
198	outb(0x3D4,5);
199	HSyncEnd = inb(0x3D5)&0x1F;
200	outb(0x3D4,5);
201	HSyncEnd += HSyncStart >> shift;
202	HSyncEnd <<= shift;
203
204	outb(0x3D4,6);
205	VTotal = inb(0x3D5)&0xFF;
206	outb(0x3D4,7);
207	VTotal |= (inb(0x3D5)&0x1) << 8;
208	VTotal |= (inb(0x3D5)&0x20) << 4;
209	VTotal += 2;
210	VDisplay = (inb(0x3D5)&0x2) << 7;
211	VDisplay |= (inb(0x3D5)&0x40) << 3;
212	VSyncStart = (inb(0x3D5)&0x4) << 6;
213	VSyncStart |= (inb(0x3D5)&0x80) << 2;
214	outb(0x3D4,0x12);
215	    VDisplay |= inb(0x3D5)&0xFF;
216	VDisplay += 1;
217	outb(0x3D4,0x10);
218	VSyncStart |= inb(0x3D5)&0xFF;
219
220	outb(0x3D4,0x11);
221	VSyncEnd = inb(0x3D5)&0xF;
222	VSyncEnd += VSyncStart;
223
224    }
225    outb(0x3D4,storeReg);
226
227    printf("\nModeLine with port 0x3D4 (CRTC) %d %d %d %d %d %d %d %d\n",
228	   HDisplay, HSyncStart, HSyncEnd, HTotal,
229	   VDisplay, VSyncStart, VSyncEnd, VTotal);
230
231
232    if (is69030==1) {
233      if (again==1) {
234	again=0;
235	printf("\n\nPipeline B:\n");
236	outb(0x3CD,((IOSS&0xE0)| 0x1F));  /* Select Channel 1 */
237	outb(0x3CB,((MSS&0xF0)| 0xF));
238	goto again;
239      } else {
240	outb(0x3CD,IOSS);
241	outb(0x3CB,MSS);
242	printf("\n\n0x3CB\t0x%X  (MSS)\n",inb(0x3CB)&0xFF);
243	printf("0x3CD\t0x%X  (IOSS)\n",inb(0x3CD)&0xFF);
244      }
245    }
246    RESET_IOPL();
247    return 0;
248}
249