1 | ␊ |
2 | /* Copied from 915 resolution created by steve tomljenovic␊ |
3 | *␊ |
4 | * This code is based on the techniques used in :␊ |
5 | *␊ |
6 | * - 855patch. Many thanks to Christian Zietz (czietz gmx net)␊ |
7 | * for demonstrating how to shadow the VBIOS into system RAM␊ |
8 | * and then modify it.␊ |
9 | *␊ |
10 | * - 1280patch by Andrew Tipton (andrewtipton null li).␊ |
11 | *␊ |
12 | * - 855resolution by Alain Poirier␊ |
13 | *␊ |
14 | * This source code is into the public domain.␊ |
15 | */␊ |
16 | ␊ |
17 | #include "libsaio.h"␊ |
18 | #include "915resolution.h"␊ |
19 | ␊ |
20 | char * chipset_type_names[] = {␊ |
21 | ␉"UNKNOWN", "830", "845G", "855GM", "865G", "915G", "915GM", "945G", "945GM", "945GME",␊ |
22 | ␉"946GZ", "G965", "Q965", "965GM", "500"␊ |
23 | };␊ |
24 | ␊ |
25 | char * bios_type_names[] = {"UNKNOWN", "TYPE 1", "TYPE 2", "TYPE 3"};␊ |
26 | ␊ |
27 | int freqs[] = { 60, 75, 85 };␊ |
28 | ␊ |
29 | UInt32 get_chipset_id(void) {␊ |
30 | ␉outl(0xcf8, 0x80000000);␊ |
31 | ␉return inl(0xcfc);␊ |
32 | }␊ |
33 | ␊ |
34 | chipset_type get_chipset(UInt32 id) {␊ |
35 | ␉chipset_type type;␊ |
36 | ␉␊ |
37 | ␉switch (id) {␊ |
38 | ␉␉case 0x35758086:␊ |
39 | ␉␉␉type = CT_830;␊ |
40 | ␉␉␉break;␊ |
41 | ␉␉␊ |
42 | ␉␉case 0x25608086:␊ |
43 | ␉␉␉type = CT_845G;␊ |
44 | ␉␉␉break;␊ |
45 | ␉␉␉␉␊ |
46 | ␉␉case 0x35808086:␊ |
47 | ␉␉␉type = CT_855GM;␊ |
48 | ␉␉␉break;␊ |
49 | ␉␉␉␉␊ |
50 | ␉␉case 0x25708086:␊ |
51 | ␉␉␉type = CT_865G;␊ |
52 | ␉␉␉break;␊ |
53 | ␉␉␊ |
54 | ␉␉case 0x25808086:␊ |
55 | ␉␉␉type = CT_915G;␊ |
56 | ␉␉␉break;␊ |
57 | ␉␉␉␊ |
58 | ␉␉case 0x25908086:␊ |
59 | ␉␉␉type = CT_915GM;␊ |
60 | ␉␉␉break;␊ |
61 | ␉␉␉␊ |
62 | ␉␉case 0x27708086:␊ |
63 | ␉␉␉type = CT_945G;␊ |
64 | ␉␉␉break;␊ |
65 | ␉␉␊ |
66 | ␉␉case 0x27a08086:␊ |
67 | ␉␉␉type = CT_945GM;␊ |
68 | ␉␉␉break;␊ |
69 | ␊ |
70 | ␉␉case 0x27a68086:␊ |
71 | ␉␉␉type = CT_945GM;␊ |
72 | ␉␉␉break;␊ |
73 | ␊ |
74 | ␉␉case 0x27ac8086:␊ |
75 | ␉␉␉type = CT_945GME;␊ |
76 | ␉␉␉break;␊ |
77 | ␊ |
78 | ␉␉case 0x27ae8086:␊ |
79 | ␉␉␉type = CT_945GM;␊ |
80 | ␉␉␉break;␊ |
81 | ␊ |
82 | ␉␉case 0x29708086:␊ |
83 | ␉␉␉type = CT_946GZ;␊ |
84 | ␉␉␉break;␊ |
85 | ␉␉␉␊ |
86 | ␉␉case 0x29a08086:␊ |
87 | ␉␉␉type = CT_G965;␊ |
88 | ␉␉␉break;␊ |
89 | ␉␉␉␊ |
90 | ␉␉case 0x29908086:␊ |
91 | ␉␉␉type = CT_Q965;␊ |
92 | ␉␉␉break;␊ |
93 | ␉␉␉␊ |
94 | ␉␉case 0x81008086:␊ |
95 | ␉␉␉type = CT_500;␊ |
96 | ␉␉␉break;␊ |
97 | ␉␉␉␊ |
98 | ␉␉case 0x2a008086:␊ |
99 | ␉␉␉type = CT_965GM;␊ |
100 | ␉␉␉break;␊ |
101 | ␉␉␉␊ |
102 | ␉␉␉␊ |
103 | ␉␉default:␊ |
104 | ␉␉␉type = CT_UNKWN;␊ |
105 | ␉␉␉break;␊ |
106 | ␉}␊ |
107 | ␉return type;␊ |
108 | }␊ |
109 | ␊ |
110 | vbios_resolution_type1 * map_type1_resolution(vbios_map * map, UInt16 res) {␊ |
111 | ␉vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res)); ␊ |
112 | ␉return ptr;␊ |
113 | }␊ |
114 | ␊ |
115 | vbios_resolution_type2 * map_type2_resolution(vbios_map * map, UInt16 res) {␊ |
116 | ␉vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res)); ␊ |
117 | ␉return ptr;␊ |
118 | }␊ |
119 | ␊ |
120 | vbios_resolution_type3 * map_type3_resolution(vbios_map * map, UInt16 res) {␊ |
121 | ␉vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res)); ␊ |
122 | ␉return ptr;␊ |
123 | }␊ |
124 | ␊ |
125 | char detect_bios_type(vbios_map * map, char modeline, int entry_size) {␊ |
126 | ␉UInt32 i;␊ |
127 | ␉UInt16 r1, r2;␊ |
128 | ␉ ␊ |
129 | ␉r1 = r2 = 32000;␊ |
130 | ␉␊ |
131 | ␉for (i=0; i < map->mode_table_size; i++) {␊ |
132 | ␉␉if (map->mode_table[i].resolution <= r1) {␊ |
133 | ␉␉␉r1 = map->mode_table[i].resolution;␊ |
134 | ␉␉}␊ |
135 | ␉␉else {␊ |
136 | ␉␉␉if (map->mode_table[i].resolution <= r2) {␊ |
137 | ␉␉␉␉r2 = map->mode_table[i].resolution;␊ |
138 | ␉␉␉}␊ |
139 | ␉␉}␊ |
140 | ␉␉␊ |
141 | ␉␉/*printf("r1 = %d r2 = %d\n", r1, r2);*/␊ |
142 | ␉}␊ |
143 | ␊ |
144 | ␉return (r2-r1-6) % entry_size == 0;␊ |
145 | }␊ |
146 | ␊ |
147 | void close_vbios(vbios_map * map);␊ |
148 | ␊ |
149 | vbios_map * open_vbios(chipset_type forced_chipset) {␊ |
150 | ␉UInt32 z;␊ |
151 | ␉vbios_map * map = NEW(vbios_map);␊ |
152 | ␉for(z=0; z<sizeof(vbios_map); z++) ((char*)map)[z]=0;␊ |
153 | ␉/*␊ |
154 | ␉ * Determine chipset␊ |
155 | ␉␉ + */␊ |
156 | ␉␊ |
157 | ␉if (forced_chipset == CT_UNKWN) {␊ |
158 | ␉␉map->chipset_id = get_chipset_id();␊ |
159 | ␉␉map->chipset = get_chipset(map->chipset_id);␊ |
160 | ␉}␊ |
161 | ␉else if (forced_chipset != CT_UNKWN) {␊ |
162 | ␉␉map->chipset = forced_chipset;␊ |
163 | ␉}␊ |
164 | ␉else {␊ |
165 | ␉␉map->chipset = CT_915GM;␊ |
166 | ␉}␊ |
167 | ␉ ␊ |
168 | ␉/*␊ |
169 | ␉ * Map the video bios to memory␊ |
170 | ␉ */␊ |
171 | ␉␊ |
172 | ␉map->bios_ptr=(char*)VBIOS_START;␊ |
173 | ␉␊ |
174 | ␉/*␊ |
175 | ␉ * check if we have ATI Radeon␊ |
176 | ␉ */␊ |
177 | ␉ ␊ |
178 | ␉/*if (memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE1, strlen(ATI_SIGNATURE1)) ||␊ |
179 | ␉␉memmem(map->bios_ptr, VBIOS_SIZE, ATI_SIGNATURE2, strlen(ATI_SIGNATURE2)) ) {␊ |
180 | ␉␉printf(stderr, "ATI chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");␊ |
181 | ␉␉return 0;␊ |
182 | ␉}*/␊ |
183 | ␉␊ |
184 | ␉/*␊ |
185 | ␉ * check if we have NVIDIA␊ |
186 | ␉ */␊ |
187 | ␉ ␊ |
188 | ␉/*if (memmem(map->bios_ptr, VBIOS_SIZE, NVIDIA_SIGNATURE, strlen(NVIDIA_SIGNATURE))) {␊ |
189 | ␉␉printf("NVIDIA chipset detected. 915resolution only works with Intel 800/900 series graphic chipsets.\n");␊ |
190 | ␉␉return 0;␊ |
191 | ␉}*/␊ |
192 | ␉␊ |
193 | ␉/*␊ |
194 | ␉ * check if we have Intel␊ |
195 | ␉ */␊ |
196 | ␉ ␊ |
197 | ␉/*if (map->chipset == CT_UNKWN && memmem(map->bios_ptr, VBIOS_SIZE, INTEL_SIGNATURE, strlen(INTEL_SIGNATURE))) {␊ |
198 | ␉␉printf( "Intel chipset detected. However, 915resolution was unable to determine the chipset type.\n");␊ |
199 | ␉␊ |
200 | ␉␉printf("Chipset Id: %x\n", map->chipset_id);␊ |
201 | ␉␉␊ |
202 | ␉␉printf("Please report this problem to stomljen@yahoo.com\n");␊ |
203 | ␉␉␊ |
204 | ␉␉␉close_vbios(map);␊ |
205 | ␉␉␉return 0;␊ |
206 | ␉␉}*/␊ |
207 | ␉␊ |
208 | ␉␉/*␊ |
209 | ␉␉ * check for others␊ |
210 | ␉␉ */␊ |
211 | ␉␊ |
212 | ␉if (map->chipset == CT_UNKWN) {␊ |
213 | /*␉␉printf("Unknown chipset type and unrecognized bios.\n");␊ |
214 | ␉␉ ␊ |
215 | ␉␉printf("915resolution only works with Intel 800/900 series graphic chipsets.\n");␊ |
216 | */␊ |
217 | ␉␉printf("Chipset Id: %x\n", map->chipset_id);␊ |
218 | ␉␉close_vbios(map);␊ |
219 | ␉␉return 0;␊ |
220 | ␉}␊ |
221 | ␊ |
222 | ␉/*␊ |
223 | ␉ * Figure out where the mode table is ␊ |
224 | ␉ */␊ |
225 | ␉␊ |
226 | ␉{␊ |
227 | ␉␉char* p = map->bios_ptr + 16;␊ |
228 | ␉␉char* limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));␊ |
229 | ␉␉␉␊ |
230 | ␉␉while (p < limit && map->mode_table == 0) {␊ |
231 | ␉␉␉vbios_mode * mode_ptr = (vbios_mode *) p;␊ |
232 | ␉␉␉ ␊ |
233 | ␉␉␉if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&␊ |
234 | ␉␉␉␉((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30)) {␊ |
235 | ␉␉␉␊ |
236 | ␉␉␉␉map->mode_table = mode_ptr;␊ |
237 | ␉␉␉}␊ |
238 | ␉␉␉ ␊ |
239 | ␉␉␉p++;␊ |
240 | ␉␉}␊ |
241 | ␉␉␊ |
242 | ␉␉if (map->mode_table == 0) {␊ |
243 | ␉␉␉printf("Unable to locate the mode table.\n");␊ |
244 | ␉␉␉printf("Please run the program 'dump_bios' as root and\n");␊ |
245 | ␉␉␉printf("email the file 'vbios.dmp' to stomljen@yahoo.com.\n");␊ |
246 | ␉␉␉printf("Chipset: %s\n", chipset_type_names[map->chipset]);␊ |
247 | ␉␉␉close_vbios(map);␊ |
248 | ␉␉␉return 0;␊ |
249 | ␉␉}␊ |
250 | ␉}␊ |
251 | ␉␊ |
252 | ␉/*␊ |
253 | ␉ * Determine size of mode table␊ |
254 | ␉ */␊ |
255 | ␉ ␊ |
256 | ␉{␊ |
257 | ␉␉vbios_mode * mode_ptr = map->mode_table;␊ |
258 | ␉␉␉␊ |
259 | ␉␉while (mode_ptr->mode != 0xff) {␊ |
260 | ␉␉␉map->mode_table_size++;␊ |
261 | ␉␉␉mode_ptr++;␊ |
262 | ␉␉}␊ |
263 | ␉}␊ |
264 | ␉␊ |
265 | ␉/*␊ |
266 | ␉ * Figure out what type of bios we have␊ |
267 | ␉ * order of detection is important␊ |
268 | ␉ */␊ |
269 | ␉␊ |
270 | ␉if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type3))) {␊ |
271 | ␉␉map->bios = BT_3;␊ |
272 | ␉}␊ |
273 | ␉else if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type2))) {␊ |
274 | ␉␉map->bios = BT_2;␊ |
275 | ␉}␊ |
276 | ␉else if (detect_bios_type(map, FALSE, sizeof(vbios_resolution_type1))) {␊ |
277 | ␉␉map->bios = BT_1;␊ |
278 | ␉}␊ |
279 | ␉else {␊ |
280 | ␉␉printf("Unable to determine bios type.\n");␊ |
281 | ␉␉printf("Please run the program 'dump_bios' as root and\n");␊ |
282 | ␉␉printf("email the file 'vbios.dmp' to stomljen@yahoo.com.\n");␊ |
283 | ␉␊ |
284 | ␉␉printf("Chipset: %s\n", chipset_type_names[map->chipset]);␊ |
285 | ␉␉printf("Mode Table Offset: $C0000 + $%x\n", ((UInt32)map->mode_table) - ((UInt32)map->bios_ptr));␊ |
286 | ␉␉␊ |
287 | ␉␉printf("Mode Table Entries: %u\n", map->mode_table_size);␊ |
288 | ␉␉return 0;␊ |
289 | ␉}␊ |
290 | ␉␊ |
291 | ␉return map;␊ |
292 | }␊ |
293 | ␊ |
294 | void close_vbios(vbios_map * map) {␊ |
295 | ␉FREE(map);␊ |
296 | }␊ |
297 | ␊ |
298 | void unlock_vbios(vbios_map * map) {␊ |
299 | ␊ |
300 | ␉map->unlocked = TRUE;␊ |
301 | ␉ ␊ |
302 | ␉switch (map->chipset) {␊ |
303 | ␉␉case CT_UNKWN:␊ |
304 | ␉␉␉break;␊ |
305 | ␉␉case CT_830:␊ |
306 | ␉␉case CT_855GM:␊ |
307 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
308 | ␉␉␉map->b1 = inb(0xcfe);␊ |
309 | ␉␉␉␉␊ |
310 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
311 | ␉␉␉outb(0xcfe, 0x33);␊ |
312 | ␉␉␉break;␊ |
313 | ␉␉case CT_845G:␊ |
314 | ␉␉case CT_865G:␊ |
315 | ␉␉case CT_915G:␊ |
316 | ␉␉case CT_915GM:␊ |
317 | ␉␉case CT_945G:␊ |
318 | ␉␉case CT_945GM:␊ |
319 | ␉␉case CT_945GME:␊ |
320 | ␉␉case CT_946GZ:␊ |
321 | ␉␉case CT_G965:␊ |
322 | ␉␉case CT_Q965:␊ |
323 | ␉␉case CT_965GM:␊ |
324 | ␉␉case CT_500:␊ |
325 | ␊ |
326 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
327 | ␉␉␉map->b1 = inb(0xcfd);␊ |
328 | ␉␉␉map->b2 = inb(0xcfe);␊ |
329 | ␉␉␉outl(0xcf8, 0x80000090);␊ |
330 | ␉␉␉outb(0xcfd, 0x33);␊ |
331 | ␉␉␉outb(0xcfe, 0x33);␊ |
332 | ␉␉break;␊ |
333 | ␉}␊ |
334 | ␉␊ |
335 | ␉#if DEBUG␊ |
336 | ␉{␊ |
337 | ␉␉UInt32 t = inl(0xcfc);␊ |
338 | ␉␉printf("unlock PAM: (0x%08x)\n", t);␊ |
339 | ␉}␊ |
340 | #endif␊ |
341 | }␊ |
342 | ␊ |
343 | void relock_vbios(vbios_map * map) {␊ |
344 | ␊ |
345 | ␉map->unlocked = FALSE;␊ |
346 | ␉␊ |
347 | ␉switch (map->chipset) {␊ |
348 | ␉␉case CT_UNKWN:␊ |
349 | ␉␉␉break;␊ |
350 | ␉␉case CT_830:␊ |
351 | ␉␉case CT_855GM:␊ |
352 | ␉␉␉outl(0xcf8, 0x8000005a);␊ |
353 | ␉␉␉outb(0xcfe, map->b1);␊ |
354 | ␉␉␉break;␊ |
355 | ␉␉case CT_845G:␊ |
356 | ␉␉␉case CT_865G:␊ |
357 | ␉␉␉case CT_915G:␊ |
358 | ␉␉␉case CT_915GM:␊ |
359 | ␉␉␉case CT_945G:␊ |
360 | ␉␉␉case CT_945GM:␊ |
361 | ␉␉␉case CT_945GME:␊ |
362 | ␉␉␉case CT_946GZ:␊ |
363 | ␉␉␉case CT_G965:␊ |
364 | ␉␉␉case CT_Q965:␊ |
365 | ␉␉␉case CT_965GM:␊ |
366 | ␉␉␉case CT_500:␊ |
367 | ␊ |
368 | ␉␉␉␉outl(0xcf8, 0x80000090);␊ |
369 | ␉␉␉␉outb(0xcfd, map->b1);␊ |
370 | ␉␉␉␉outb(0xcfe, map->b2);␊ |
371 | ␉␉␉break;␊ |
372 | ␉}␊ |
373 | ␉␊ |
374 | ␉#if DEBUG␊ |
375 | ␉{␊ |
376 | UInt32 t = inl(0xcfc);␊ |
377 | ␉␉printf("relock PAM: (0x%08x)\n", t);␊ |
378 | ␉}␊ |
379 | ␉#endif␊ |
380 | }␊ |
381 | ␊ |
382 | ␊ |
383 | static void gtf_timings(UInt32 x, UInt32 y, UInt32 freq,␊ |
384 | ␉␉␉␉␉␉unsigned long *clock,␊ |
385 | ␉␉␉␉␉␉UInt16 *hsyncstart, UInt16 *hsyncend, UInt16 *hblank,␊ |
386 | ␉␉␉␉␉␉UInt16 *vsyncstart, UInt16 *vsyncend, UInt16 *vblank)␊ |
387 | {␊ |
388 | ␉UInt32 hbl, vbl, vfreq;␊ |
389 | ␊ |
390 | ␉vbl = y + (y+1)/(20000.0/(11*freq) - 1) + 1.5;␊ |
391 | ␉vfreq = vbl * freq;␊ |
392 | ␉hbl = 16 * (int)(x * (30.0 - 300000.0 / vfreq) /␊ |
393 | ␉␉␉␉␉␉ + (70.0 + 300000.0 / vfreq) / 16.0 + 0.5);␊ |
394 | ␊ |
395 | ␉*vsyncstart = y;␊ |
396 | ␉*vsyncend = y + 3;␊ |
397 | ␉*vblank = vbl - 1;␊ |
398 | ␉*hsyncstart = x + hbl / 2 - (x + hbl + 50) / 100 * 8 - 1;␊ |
399 | ␉*hsyncend = x + hbl / 2 - 1;␊ |
400 | ␉*hblank = x + hbl - 1;␊ |
401 | ␉*clock = (x + hbl) * vfreq / 1000;␊ |
402 | }␊ |
403 | ␊ |
404 | void set_mode(vbios_map * map, /*UInt32 mode,*/ UInt32 x, UInt32 y, UInt32 bp, UInt32 htotal, UInt32 vtotal) {␊ |
405 | ␉UInt32 xprev, yprev;␊ |
406 | ␉UInt32 i = 0, j;␉// patch first available mode␊ |
407 | ␊ |
408 | //␉for (i=0; i < map->mode_table_size; i++) {␊ |
409 | //␉␉if (map->mode_table[0].mode == mode) {␊ |
410 | ␉␉␉switch(map->bios) {␊ |
411 | ␉␉␉␉case BT_1:␊ |
412 | ␉␉␉␉␉{␊ |
413 | ␉␉␉␉␉␉vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);␊ |
414 | ␉␉␉␉␉␉␊ |
415 | ␉␉␉␉␉␉if (bp) {␊ |
416 | ␉␉␉␉␉␉␉map->mode_table[i].bits_per_pixel = bp;␊ |
417 | ␉␉␉␉␉␉}␊ |
418 | ␉␉␉␉␉␉␊ |
419 | ␉␉␉␉␉␉res->x2 = (htotal?(((htotal-x) >> 8) & 0x0f) : (res->x2 & 0x0f)) | ((x >> 4) & 0xf0);␊ |
420 | ␉␉␉␉␉␉res->x1 = (x & 0xff);␊ |
421 | ␉␉␉␉␉␉␊ |
422 | ␉␉␉␉␉␉res->y2 = (vtotal?(((vtotal-y) >> 8) & 0x0f) : (res->y2 & 0x0f)) | ((y >> 4) & 0xf0);␊ |
423 | ␉␉␉␉␉␉res->y1 = (y & 0xff);␊ |
424 | ␉␉␉␉␉␉if (htotal)␊ |
425 | ␉␉␉␉␉␉␉res->x_total = ((htotal-x) & 0xff);␊ |
426 | ␉␉␉␉␉␉␊ |
427 | ␉␉␉␉␉␉if (vtotal)␊ |
428 | ␉␉␉␉␉␉␉res->y_total = ((vtotal-y) & 0xff);␊ |
429 | ␉␉␉␉␉}␊ |
430 | ␉␉␉␉␉break;␊ |
431 | ␉␉␉␉case BT_2:␊ |
432 | ␉␉␉␉␉{␊ |
433 | ␉␉␉␉␉␉vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);␊ |
434 | ␉␉␉␉␉␉␊ |
435 | ␉␉␉␉␉␉res->xchars = x / 8;␊ |
436 | ␉␉␉␉␉␉res->ychars = y / 16 - 1;␊ |
437 | ␉␉␉␉␉␉xprev = res->modelines[0].x1;␊ |
438 | ␉␉␉␉␉␉yprev = res->modelines[0].y1;␊ |
439 | ␉␉␉␉␉␉␊ |
440 | ␉␉␉␉␉␉for(j=0; j < 3; j++) {␊ |
441 | ␉␉␉␉␉␉␉vbios_modeline_type2 * modeline = &res->modelines[j];␊ |
442 | ␉␉␉␉␉␉␉␊ |
443 | ␉␉␉␉␉␉␉if (modeline->x1 == xprev && modeline->y1 == yprev) {␊ |
444 | ␉␉␉␉␉␉␉␉modeline->x1 = modeline->x2 = x-1;␊ |
445 | ␉␉␉␉␉␉␉␉modeline->y1 = modeline->y2 = y-1;␊ |
446 | ␉␉␉␉␊ |
447 | ␉␉␉␉␉␉␉␉gtf_timings(x, y, freqs[j], &modeline->clock,␊ |
448 | ␉␉␉␉␉␉␉␉␉␉␉&modeline->hsyncstart, &modeline->hsyncend,␊ |
449 | ␉␉␉␉␉␉␉␉␉␉␉&modeline->hblank, &modeline->vsyncstart,␊ |
450 | ␉␉␉␉␉␉␉␉␉␉␉&modeline->vsyncend, &modeline->vblank);␊ |
451 | ␉␉␉␉␉␉␉␉␊ |
452 | ␉␉␉␉␉␉␉␉if (htotal)␊ |
453 | ␉␉␉␉␉␉␉␉␉modeline->htotal = htotal;␊ |
454 | ␉␉␉␉␉␉␉␉else␊ |
455 | ␉␉␉␉␉␉␉␉␉modeline->htotal = modeline->hblank;␊ |
456 | ␉␉␉␉␉␉␉␉␊ |
457 | ␉␉␉␉␉␉␉␉if (vtotal)␊ |
458 | ␉␉␉␉␉␉␉␉␉modeline->vtotal = vtotal;␊ |
459 | ␉␉␉␉␉␉␉␉else␊ |
460 | ␉␉␉␉␉␉␉␉␉modeline->vtotal = modeline->vblank;␊ |
461 | ␉␉␉␉␉␉␉}␊ |
462 | ␉␉␉␉␉␉}␊ |
463 | ␉␉␉␉␉}␊ |
464 | ␉␉␉␉␉break;␊ |
465 | ␉␉␉␉case BT_3:␊ |
466 | ␉␉␉␉␉{␊ |
467 | ␉␉␉␉␉␉vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);␊ |
468 | ␉␉␉␉␉␉␊ |
469 | ␉␉␉␉␉␉xprev = res->modelines[0].x1;␊ |
470 | ␉␉␉␉␉␉yprev = res->modelines[0].y1;␊ |
471 | ␉␉␉␉␊ |
472 | ␉␉␉␉␉␉for (j=0; j < 3; j++) {␊ |
473 | ␉␉␉␉␉␉␉vbios_modeline_type3 * modeline = &res->modelines[j];␊ |
474 | ␉␉␉␉␉␉␉ ␊ |
475 | ␉␉␉␉␉␉␉if (modeline->x1 == xprev && modeline->y1 == yprev) {␊ |
476 | ␉␉␉␉␉␉␉␉modeline->x1 = modeline->x2 = x-1;␊ |
477 | ␉␉␉␉␉␉␉␉modeline->y1 = modeline->y2 = y-1;␊ |
478 | ␉␉␉␉␉␉␉␉ ␊ |
479 | ␉␉␉␉␉␉␉␉gtf_timings(x, y, freqs[j], &modeline->clock,␊ |
480 | ␉␉␉␉␉␉␉␉␉␉␉&modeline->hsyncstart, &modeline->hsyncend,␊ |
481 | ␉␉␉␉␉␉␉␉␉␉␉&modeline->hblank, &modeline->vsyncstart,␊ |
482 | ␉␉␉␉␉␉␉␉␉␉␉&modeline->vsyncend, &modeline->vblank);␊ |
483 | ␉␉␉␉␉␉␉␉if (htotal)␊ |
484 | ␉␉␉␉␉␉␉␉␉modeline->htotal = htotal;␊ |
485 | ␉␉␉␉␉␉␉␉else␊ |
486 | ␉␉␉␉␉␉␉␉␉modeline->htotal = modeline->hblank;␊ |
487 | ␉␉␉␉␉␉␉␉if (vtotal)␊ |
488 | ␉␉␉␉␉␉␉␉␉modeline->vtotal = vtotal;␊ |
489 | ␉␉␉␉␉␉␉␉else␊ |
490 | ␉␉␉␉␉␉␉␉␉modeline->vtotal = modeline->vblank;␊ |
491 | ␉␉␉␉␉␉␊ |
492 | ␉␉␉␉␉␉␉␉modeline->timing_h = y-1;␊ |
493 | ␉␉␉␉␉␉␉␉modeline->timing_v = x-1;␊ |
494 | ␉␉␉␉␉␉␉}␊ |
495 | ␉␉␉␉␉␉}␊ |
496 | ␉␉␉␉␉}␊ |
497 | ␉␉␉␉␉break;␊ |
498 | ␉␉␉␉case BT_UNKWN:␊ |
499 | ␉␉␉␉␉break;␊ |
500 | ␉␉␉}␊ |
501 | //␉␉}␊ |
502 | //␉}␊ |
503 | } ␊ |
504 | ␊ |
505 | void display_map_info(vbios_map * map) {␊ |
506 | ␉printf("Chipset: %s\n", chipset_type_names[map->chipset]);␊ |
507 | ␉printf("BIOS: %s\n", bios_type_names[map->bios]);␊ |
508 | ␉␊ |
509 | ␉printf("Mode Table Offset: $C0000 + $%x\n", ((UInt32)map->mode_table) - ((UInt32)map->bios_ptr));␊ |
510 | ␉printf("Mode Table Entries: %u\n", map->mode_table_size);␊ |
511 | }␊ |
512 | ␊ |
513 | /*␊ |
514 | int parse_args(int argc, char *argv[], chipset_type *forced_chipset, UInt32 *list, UInt32 *mode, UInt32 *x, UInt32 *y, UInt32 *bp, UInt32 *raw, UInt32 *htotal, UInt32 *vtotal) {␊ |
515 | ␉UInt32 index = 0;␊ |
516 | ␉␊ |
517 | ␉*list = *mode = *x = *y = *raw = *htotal = *vtotal = 0;␊ |
518 | ␊ |
519 | ␉*forced_chipset = CT_UNKWN;␊ |
520 | ␉␊ |
521 | ␉if ((argc > index) && !strcmp(argv[index], "-c")) {␊ |
522 | ␉␉index++;␊ |
523 | ␉␉+␊ |
524 | ␉␉+ if(argc<=index) {␊ |
525 | ␉␉␉+ return 0;␊ |
526 | ␉␉␉+ }␊ |
527 | ␉␉+ ␊ |
528 | ␉␉+ if (!strcmp(argv[index], "845")) {␊ |
529 | ␉␉␉+ *forced_chipset = CT_845G;␊ |
530 | ␉␉␉+ }␊ |
531 | ␉␉+ else if (!strcmp(argv[index], "855")) {␊ |
532 | ␉␉␉+ *forced_chipset = CT_855GM;␊ |
533 | ␉␉␉+ }␊ |
534 | ␉␉+ else if (!strcmp(argv[index], "865")) {␊ |
535 | ␉␉␉+ *forced_chipset = CT_865G;␊ |
536 | ␉␉␉+ }␊ |
537 | ␉␉+ else if (!strcmp(argv[index], "915G")) {␊ |
538 | ␉␉␉+ *forced_chipset = CT_915G;␊ |
539 | ␉␉␉+ }␊ |
540 | ␉␉+ else if (!strcmp(argv[index], "915GM")) {␊ |
541 | ␉␉␉+ *forced_chipset = CT_915GM;␊ |
542 | ␉␉␉+ }␊ |
543 | ␉␉+ else if (!strcmp(argv[index], "945G")) {␊ |
544 | ␉␉␉+ *forced_chipset = CT_945G;␊ |
545 | ␉␉␉+ }␊ |
546 | ␉␉+ else if (!strcmp(argv[index], "945GM")) {␊ |
547 | ␉␉␉+ *forced_chipset = CT_945GM;␊ |
548 | ␉␉␉+ }␊ |
549 | ␉␉+ else if (!strcmp(argv[index], "945GME")) {␊ |
550 | ␉␉␉+ *forced_chipset = CT_945GME;␊ |
551 | ␉␉␉+ }␊ |
552 | ␉␉+ else if (!strcmp(argv[index], "946GZ")) {␊ |
553 | ␉␉␉+ *forced_chipset = CT_946GZ;␊ |
554 | ␉␉␉+ }␊ |
555 | ␉␉+ else if (!strcmp(argv[index], "G965")) {␊ |
556 | ␉␉␉+ *forced_chipset = CT_G965;␊ |
557 | ␉␉␉+ }␊ |
558 | ␉␉+ else if (!strcmp(argv[index], "Q965")) {␊ |
559 | ␉␉␉+ *forced_chipset = CT_Q965;␊ |
560 | ␉␉␉+ }␊ |
561 | ␉␉+ else if (!strcmp(argv[index], "500")) {␊ |
562 | ␉␉␉+ *forced_chipset = CT_500;␊ |
563 | ␉␉␉+ }␊ |
564 | ␉␉␊ |
565 | ␉␉+ else {␊ |
566 | ␉␉␉+␉ printf("No match for forced chipset: %s\n", argv[index]);␊ |
567 | ␉␉␉+ *forced_chipset = CT_UNKWN;␊ |
568 | ␉␉␉+ }␊ |
569 | ␉␉+ ␊ |
570 | ␉␉+ index++;␊ |
571 | ␉␉+ ␊ |
572 | ␉␉+ if (argc<=index) {␊ |
573 | ␉␉␉+ return 0;␊ |
574 | ␉␉␉+ }␊ |
575 | ␉␉+ }␊ |
576 | ␉+␊ |
577 | ␉+ if ((argc > index) && !strcmp(argv[index], "-l")) {␊ |
578 | ␉␉+ *list = 1;␊ |
579 | ␉␉+ index++;␊ |
580 | ␉␉+␊ |
581 | ␉␉+ if(argc<=index) {␊ |
582 | ␉␉␉+ return 0;␊ |
583 | ␉␉␉+ }␊ |
584 | ␉␉+ }␊ |
585 | ␉+ ␊ |
586 | ␉+ if ((argc > index) && !strcmp(argv[index], "-r")) {␊ |
587 | ␉␉+ *raw = 1;␊ |
588 | ␉␉+ index++;␊ |
589 | ␉␉+␊ |
590 | ␉␉+ if(argc<=index) {␊ |
591 | ␉␉␉+ return 0;␊ |
592 | ␉␉␉+ }␊ |
593 | ␉␉+ }␊ |
594 | ␉+ ␊ |
595 | ␉+ if (argc-index < 3 || argc-index > 6) {␊ |
596 | ␉␉+ return -1;␊ |
597 | ␉␉+ }␊ |
598 | ␉+␊ |
599 | ␉+ *mode = (UInt32) strtoul(argv[index], NULL, 16);␊ |
600 | ␉+ *x = (UInt32)strtoul(argv[index+1], NULL, 10);␊ |
601 | ␉+ *y = (UInt32)strtoul(argv[index+2], NULL, 10);␊ |
602 | ␉+␊ |
603 | ␉+␊ |
604 | ␉+ if (argc-index > 3) {␊ |
605 | ␉␉+ *bp = (UInt32)strtoul(argv[index+3], NULL, 10);␊ |
606 | ␉␉+ }␊ |
607 | ␉+ else {␊ |
608 | ␉␉+ *bp = 0;␊ |
609 | ␉␉+ }␊ |
610 | ␉+ ␊ |
611 | ␉+ if (argc-index > 4) {␊ |
612 | ␉␉+ *htotal = (UInt32)strtoul(argv[index+4], NULL, 10);␊ |
613 | ␉␉+ }␊ |
614 | ␉+ else {␊ |
615 | ␉␉+ *htotal = 0;␊ |
616 | ␉␉+ }␊ |
617 | ␉+␊ |
618 | ␉+ if (argc-index > 5) {␊ |
619 | ␉␉+ *vtotal = (UInt32)strtoul(argv[index+5], NULL, 10);␊ |
620 | ␉␉+ }␊ |
621 | ␉+ else {␊ |
622 | ␉␉+ *vtotal = 0;␊ |
623 | ␉␉+ }␊ |
624 | ␉+ ␊ |
625 | ␉+ return 0;␊ |
626 | ␉+}␊ |
627 | +␊ |
628 | ␊ |
629 | ␊ |
630 | */␊ |
631 | ␊ |
632 | ␊ |
633 | void list_modes(vbios_map *map, UInt32 raw) {␊ |
634 | UInt32 i, x, y;␊ |
635 | ␉␊ |
636 | for (i=0; i < map->mode_table_size; i++) {␊ |
637 | switch(map->bios) {␊ |
638 | ␉␉␉case BT_1:␊ |
639 | {␊ |
640 | vbios_resolution_type1 * res = map_type1_resolution(map, map->mode_table[i].resolution);␊ |
641 | ␊ |
642 | x = ((((UInt32) res->x2) & 0xf0) << 4) | res->x1;␊ |
643 | y = ((((UInt32) res->y2) & 0xf0) << 4) | res->y1;␊ |
644 | ␊ |
645 | if (x != 0 && y != 0) {␊ |
646 | printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);␊ |
647 | }␊ |
648 | ␉␉␉␉␊ |
649 | ␉␉␉␉if (raw)␊ |
650 | ␉␉␉␉{␊ |
651 | printf("Mode %02x (raw) :\n\t%02x %02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n\t%02x\n", map->mode_table[i].mode, res->unknow1[0],res->unknow1[1], res->x1,res->x_total,res->x2,res->y1,res->y_total,res->y2);␊ |
652 | ␉␉␉␉}␊ |
653 | ␉␉␉␉␊ |
654 | }␊ |
655 | ␉␉␉␉break;␊ |
656 | ␉␉␉case BT_2:␊ |
657 | {␊ |
658 | vbios_resolution_type2 * res = map_type2_resolution(map, map->mode_table[i].resolution);␊ |
659 | ␊ |
660 | x = res->modelines[0].x1+1;␊ |
661 | y = res->modelines[0].y1+1;␊ |
662 | ␉␉␉␉␊ |
663 | if (x != 0 && y != 0) {␊ |
664 | printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);␊ |
665 | }␊ |
666 | }␊ |
667 | ␉␉␉␉break;␊ |
668 | ␉␉␉case BT_3:␊ |
669 | {␊ |
670 | vbios_resolution_type3 * res = map_type3_resolution(map, map->mode_table[i].resolution);␊ |
671 | ␊ |
672 | x = res->modelines[0].x1+1;␊ |
673 | y = res->modelines[0].y1+1;␊ |
674 | ␊ |
675 | if (x != 0 && y != 0) {␊ |
676 | printf("Mode %02x : %dx%d, %d bits/pixel\n", map->mode_table[i].mode, x, y, map->mode_table[i].bits_per_pixel);␊ |
677 | }␊ |
678 | }␊ |
679 | ␉␉␉␉break;␊ |
680 | ␉␉␉case BT_UNKWN:␊ |
681 | ␉␉␉␉break;␊ |
682 | }␊ |
683 | }␊ |
684 | }␊ |
685 | ␊ |
686 | ␊ |
687 | void usage() {␊ |
688 | ␉printf("Usage: 915resolution [-c chipset] [-l] [mode X Y] [bits/pixel] [htotal] [vtotal]\n");␊ |
689 | ␉printf(" Set the resolution to XxY for a video mode\n");␊ |
690 | ␉printf(" Bits per pixel are optional. htotal/vtotal settings are additionally optional.\n");␊ |
691 | ␉printf(" Options:\n");␊ |
692 | ␉printf(" -c force chipset type (THIS IS USED FOR DEBUG PURPOSES)\n");␊ |
693 | ␉printf(" -l display the modes found in the video BIOS\n");␊ |
694 | ␉printf(" -r display the modes found in the video BIOS in raw mode (THIS IS USED FOR DEBUG PURPOSES)\n");␊ |
695 | }␊ |
696 | ␊ |
697 | /*␊ |
698 | static err_t␊ |
699 | cmd_915resolution (struct arg_list *state ,␊ |
700 | ␉␉␉␉ int argc ,␊ |
701 | ␉␉␉␉ char **argv )␊ |
702 | {␊ |
703 | ␉vbios_map * map;␊ |
704 | ␉UInt32 list, mode, x, y, bp, raw, htotal, vtotal;␊ |
705 | ␉chipset_type forced_chipset;␊ |
706 | ␉␊ |
707 | ␉printf("Intel 500/800/900 Series VBIOS Hack : version %s\n\n", VERSION);␊ |
708 | ␊ |
709 | ␉if (parse_args(argc, argv, &forced_chipset, &list, &mode, &x, &y, &bp, &raw, &htotal, &vtotal) == -1) {␊ |
710 | ␉␉␉usage();␊ |
711 | ␉␉␉return 2;␊ |
712 | ␉␉}␊ |
713 | ␊ |
714 | ␉map = open_vbios(forced_chipset);␊ |
715 | ␉display_map_info(map);␊ |
716 | ␊ |
717 | ␉printf("\n");␊ |
718 | ␊ |
719 | ␉if (list) {␊ |
720 | ␉␉list_modes(map, raw);␊ |
721 | ␉}␊ |
722 | ␊ |
723 | ␉if (mode!=0 && x!=0 && y!=0) {␊ |
724 | ␉␉unlock_vbios(map);␊ |
725 | ␉␉␊ |
726 | ␉␉set_mode(map, mode, x, y, bp, htotal, vtotal);␊ |
727 | ␉␉␊ |
728 | ␉␉relock_vbios(map);␊ |
729 | ␉␉␊ |
730 | ␉␉printf("Patch mode %02x to resolution %dx%d complete\n", mode, x, y);␊ |
731 | ␉␉ ␊ |
732 | ␉␉if (list) {␊ |
733 | ␉␉␉list_modes(map, raw);␊ |
734 | ␉␉}␊ |
735 | ␉}␊ |
736 | ␉␊ |
737 | ␉close_vbios(map);␊ |
738 | ␉ ␊ |
739 | ␉return 0;␊ |
740 | }␊ |
741 | */␊ |
742 | |