Chameleon

Chameleon Svn Source Tree

Root/branches/autoResolution/i386/libsaio/gma_resolution.c

1/*
2 * gma_resolution.c
3 *
4 *
5 * Created by Le Bidou on 19/03/10.
6 * Copyright 2010 ---. All rights reserved.
7 *
8 */
9
10#include "gma_resolution.h"
11
12char * bios_type_names[] = {"UNKNOWN", "TYPE 1", "TYPE 2", "TYPE 3"};
13int freqs[] = { 60, 75, 85 };
14
15
16vbios_resolution_type1 * map_type1_resolution(vbios_map * map, UInt16 res) {
17vbios_resolution_type1 * ptr = ((vbios_resolution_type1*)(map->bios_ptr + res));
18return ptr;
19}
20
21vbios_resolution_type2 * map_type2_resolution(vbios_map * map, UInt16 res) {
22vbios_resolution_type2 * ptr = ((vbios_resolution_type2*)(map->bios_ptr + res));
23return ptr;
24}
25
26vbios_resolution_type3 * map_type3_resolution(vbios_map * map, UInt16 res) {
27vbios_resolution_type3 * ptr = ((vbios_resolution_type3*)(map->bios_ptr + res));
28return ptr;
29}
30
31char detect_bios_type(vbios_map * map, char modeline, int entry_size) {
32UInt32 i;
33UInt16 r1, r2;
34
35vbios_mode * mode_table = (vbios_mode *)map->mode_table;
36
37r1 = r2 = 32000;
38
39for (i=0; i < map->mode_table_size; i++) {
40if (mode_table[i].resolution <= r1) {
41r1 = mode_table[i].resolution;
42}
43else {
44if (mode_table[i].resolution <= r2) {
45r2 = mode_table[i].resolution;
46}
47}
48
49/*PRINT("r1 = %d r2 = %d\n", r1, r2);*/
50}
51
52return (r2-r1-6) % entry_size == 0;
53}
54
55vbios_map * open_intel_vbios(vbios_map *map)
56{
57/*
58 * Find the location of the Mode Table
59 */
60unsigned char* p = map->bios_ptr + 16;
61unsigned char* limit = map->bios_ptr + VBIOS_SIZE - (3 * sizeof(vbios_mode));
62
63while (p < limit && map->mode_table == 0) {
64vbios_mode* mode_ptr = (vbios_mode*) p;
65
66if (((mode_ptr[0].mode & 0xf0) == 0x30) && ((mode_ptr[1].mode & 0xf0) == 0x30) &&
67((mode_ptr[2].mode & 0xf0) == 0x30) && ((mode_ptr[3].mode & 0xf0) == 0x30)) {
68
69map->mode_table = (char *)mode_ptr;
70}
71
72p++;
73}
74
75if (map->mode_table == 0) {
76PRINT("Unable to locate the mode table.\n");
77PRINT("Please run the program 'dump_bios' as root and\n");
78PRINT("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");
79
80close_vbios(map);
81return 0;
82}
83
84PRINT("Mode Table at offset : 0x%x\n", ((unsigned char *)map->mode_table) - map->bios_ptr);
85
86/*
87 * Determine size of mode table
88 */
89
90vbios_mode * mode_ptr = (vbios_mode *)map->mode_table;
91
92while (mode_ptr->mode != 0xff) {
93map->mode_table_size++;
94mode_ptr++;
95}
96
97map->modeline_num = map->mode_table_size;
98PRINT("Mode Table size : %d\n", map->modeline_num);
99
100/*
101 * Figure out what type of bios we have
102 * order of detection is important
103 */
104
105if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type3))) {
106map->bios = BT_3;
107PRINT("Bios Type : BT_3\n");
108}
109else if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type2))) {
110map->bios = BT_2;
111PRINT("Bios Type : BT_2\n");
112}
113else if (detect_bios_type(map, FALSE, sizeof(vbios_resolution_type1))) {
114map->bios = BT_1;
115PRINT("Bios Type : BT_1\n");
116}
117else {
118PRINT("Unable to determine bios type.\n");
119PRINT("Please run the program 'dump_bios' as root and\n");
120PRINT("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");
121
122return 0;
123}
124
125return map;
126}
127
128
129
130bool intel_set_mode_1(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y)
131{
132vbios_mode *mode_timing = (vbios_mode *) map->mode_table;
133vbios_resolution_type1 * res = map_type1_resolution(map, mode_timing[idx].resolution);
134
135UInt32 actual_x = ((res->x2 & 0xf0) << 4) | (res->x1 & 0xff);
136UInt32 actual_y = ((res->y2 & 0xf0) << 4) | (res->y1 & 0xff);
137
138if ((*x != 0) && (*y != 0) && ( actual_x >= 640 )) {
139
140PRINT("Mode %dx%d -> %dx%d \n", actual_x, actual_y, *x, *y);
141
142res->x2 = (res->x2 & 0x0f) | ((*x >> 4) & 0xf0);
143res->x1 = (*x & 0xff);
144
145res->y2 = ((*y >> 4) & 0xf0);
146res->y1 = (*y & 0xff);
147}
148
149res = map_type1_resolution(map, mode_timing[idx + 1].resolution);
150
151actual_x = ((res->x2 & 0xf0) << 4) | (res->x1 & 0xff);
152actual_y = ((res->y2 & 0xf0) << 4) | (res->y1 & 0xff);
153
154*x = actual_x;
155*y = actual_y;
156
157return TRUE;
158}
159
160bool intel_set_mode_2(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y)
161{
162UInt32 xprev, yprev, j = 0;
163
164vbios_mode *mode_timing = (vbios_mode *) map->mode_table;
165vbios_resolution_type2 * res = map_type2_resolution(map, mode_timing[idx].resolution);
166
167if ((*x != 0) && (*y != 0) && ((res->modelines[0].x1 + 1) >= 640 )) {
168
169PRINT("Mode %dx%d -> %dx%d \n", res->modelines[0].x1 + 1, res->modelines[0].y1 + 1, *x, *y);
170
171res->xchars = *x / 8;
172res->ychars = *y / 16 - 1;
173xprev = res->modelines[0].x1;
174yprev = res->modelines[0].y1;
175
176for(j = 0; j < 3; j++) {
177vbios_modeline_type2 * mode = &res->modelines[j];
178
179if (mode->x1 == xprev && mode->y1 == yprev) {
180mode->x1 = mode->x2 = *x-1;
181mode->y1 = mode->y2 = *y-1;
182
183gtf_timings(*x, *y, freqs[j], &mode->clock,
184&mode->hsyncstart, &mode->hsyncend,
185&mode->hblank, &mode->vsyncstart,
186&mode->vsyncend, &mode->vblank);
187
188mode->htotal = mode->hblank;
189mode->vtotal = mode->vblank;
190}
191}
192}
193
194res = map_type2_resolution(map, mode_timing[idx + 1].resolution);
195
196*x = res->modelines[0].x1 + 1;
197*y = res->modelines[0].y1 + 1;
198
199return TRUE;
200}
201
202bool intel_set_mode_3(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y)
203{
204UInt32 xprev, yprev, j = 0;
205
206vbios_mode *mode_timing = (vbios_mode *) map->mode_table;
207vbios_resolution_type3 * res = map_type3_resolution(map, mode_timing[idx].resolution);
208
209if ((*x != 0) && (*y != 0) && ((res->modelines[0].x1 + 1) >= 640 )) {
210
211PRINT("Mode %dx%d -> %dx%d \n", res->modelines[0].x1 + 1, res->modelines[0].y1 + 1, *x, *y);
212
213xprev = res->modelines[0].x1;
214yprev = res->modelines[0].y1;
215
216for(j = 0; j < 3; j++) {
217vbios_modeline_type3 * mode = &res->modelines[j];
218
219if (mode->x1 == xprev && mode->y1 == yprev) {
220mode->x1 = mode->x2 = *x-1;
221mode->y1 = mode->y2 = *y-1;
222
223gtf_timings(*x, *y, freqs[j], &mode->clock,
224&mode->hsyncstart, &mode->hsyncend,
225&mode->hblank, &mode->vsyncstart,
226&mode->vsyncend, &mode->vblank);
227
228mode->htotal = mode->hblank;
229mode->vtotal = mode->vblank;
230
231mode->timing_h = *y-1;
232mode->timing_v = *x-1;
233}
234}
235}
236res = map_type3_resolution(map, mode_timing[idx + 1].resolution);
237
238*x = res->modelines[0].x1 + 1;
239*y = res->modelines[0].y1 + 1;
240
241return TRUE;
242}

Archive Download this file

Revision: 137