Chameleon

Chameleon Svn Source Tree

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

Source at commit 132 created 14 years 1 month ago.
By diebuche, Adding lebidous latest changes
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/*printf("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) {
76verbose("Unable to locate the mode table.\n");
77verbose("Please run the program 'dump_bios' as root and\n");
78verbose("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");
79
80close_vbios(map);
81return 0;
82}
83
84/*
85 * Determine size of mode table
86 */
87
88vbios_mode * mode_ptr = (vbios_mode *)map->mode_table;
89
90while (mode_ptr->mode != 0xff) {
91map->mode_table_size++;
92mode_ptr++;
93}
94
95map->modeline_num = map->mode_table_size;
96
97/*
98 * Figure out what type of bios we have
99 * order of detection is important
100 */
101
102if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type3))) {
103map->bios = BT_3;
104}
105else if (detect_bios_type(map, TRUE, sizeof(vbios_modeline_type2))) {
106map->bios = BT_2;
107}
108else if (detect_bios_type(map, FALSE, sizeof(vbios_resolution_type1))) {
109map->bios = BT_1;
110}
111else {
112verbose("Unable to determine bios type.\n");
113verbose("Please run the program 'dump_bios' as root and\n");
114verbose("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");
115
116return 0;
117}
118
119return map;
120}
121
122
123
124bool intel_set_mode_1(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y)
125{
126vbios_mode *mode_timing = (vbios_mode *) map->mode_table;
127vbios_resolution_type1 * res = map_type1_resolution(map, mode_timing[idx].resolution);
128
129UInt32 actual_x = ((res->x2 & 0xf0) << 4) | (res->x1 & 0xff);
130UInt32 actual_y = ((res->y2 & 0xf0) << 4) | (res->y1 & 0xff);
131
132if ((*x != 0) && (*y != 0) && ( actual_x >= 640 )) {
133
134printf("Mode %dx%d -> %dx%d ", actual_x, actual_y, *x, *y);
135
136res->x2 = (res->x2 & 0x0f) | ((*x >> 4) & 0xf0);
137res->x1 = (*x & 0xff);
138
139res->y2 = ((*y >> 4) & 0xf0);
140res->y1 = (*y & 0xff);
141}
142
143res = map_type1_resolution(map, mode_timing[idx + 1].resolution);
144
145actual_x = ((res->x2 & 0xf0) << 4) | (res->x1 & 0xff);
146actual_y = ((res->y2 & 0xf0) << 4) | (res->y1 & 0xff);
147
148*x = actual_x;
149*y = actual_y;
150
151return TRUE;
152}
153
154bool intel_set_mode_2(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y)
155{
156UInt32 xprev, yprev, j = 0;
157
158vbios_mode *mode_timing = (vbios_mode *) map->mode_table;
159vbios_resolution_type2 * res = map_type2_resolution(map, mode_timing[idx].resolution);
160
161if ((*x != 0) && (*y != 0) && ((res->modelines[0].x1 + 1) >= 640 )) {
162
163printf("Mode %dx%d -> %dx%d ", res->modelines[0].x1 + 1, res->modelines[0].y1 + 1, *x, *y);
164
165res->xchars = *x / 8;
166res->ychars = *y / 16 - 1;
167xprev = res->modelines[0].x1;
168yprev = res->modelines[0].y1;
169
170for(j = 0; j < 3; j++) {
171vbios_modeline_type2 * mode = &res->modelines[j];
172
173if (mode->x1 == xprev && mode->y1 == yprev) {
174mode->x1 = mode->x2 = *x-1;
175mode->y1 = mode->y2 = *y-1;
176
177gtf_timings(*x, *y, freqs[j], &mode->clock,
178&mode->hsyncstart, &mode->hsyncend,
179&mode->hblank, &mode->vsyncstart,
180&mode->vsyncend, &mode->vblank);
181
182mode->htotal = mode->hblank;
183mode->vtotal = mode->vblank;
184}
185}
186}
187
188res = map_type2_resolution(map, mode_timing[idx + 1].resolution);
189
190*x = res->modelines[0].x1 + 1;
191*y = res->modelines[0].y1 + 1;
192
193return TRUE;
194}
195
196bool intel_set_mode_3(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y)
197{
198UInt32 xprev, yprev, j = 0;
199
200vbios_mode *mode_timing = (vbios_mode *) map->mode_table;
201vbios_resolution_type3 * res = map_type3_resolution(map, mode_timing[idx].resolution);
202
203if ((*x != 0) && (*y != 0) && ((res->modelines[0].x1 + 1) >= 640 )) {
204
205printf("Mode %dx%d -> %dx%d ", res->modelines[0].x1 + 1, res->modelines[0].y1 + 1, *x, *y);
206
207xprev = res->modelines[0].x1;
208yprev = res->modelines[0].y1;
209
210for(j = 0; j < 3; j++) {
211vbios_modeline_type3 * mode = &res->modelines[j];
212
213if (mode->x1 == xprev && mode->y1 == yprev) {
214mode->x1 = mode->x2 = *x-1;
215mode->y1 = mode->y2 = *y-1;
216
217gtf_timings(*x, *y, freqs[j], &mode->clock,
218&mode->hsyncstart, &mode->hsyncend,
219&mode->hblank, &mode->vsyncstart,
220&mode->vsyncend, &mode->vblank);
221
222mode->htotal = mode->hblank;
223mode->vtotal = mode->vblank;
224
225mode->timing_h = *y-1;
226mode->timing_v = *x-1;
227}
228}
229}
230res = map_type3_resolution(map, mode_timing[idx + 1].resolution);
231
232*x = res->modelines[0].x1 + 1;
233*y = res->modelines[0].y1 + 1;
234
235return TRUE;
236}

Archive Download this file

Revision: 132