Chameleon

Chameleon Svn Source Tree

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

1/*
2 * nvidia_resolution.c
3 *
4 *
5 * Created by Le Bidou on 19/03/10.
6 * Copyright 2010 ---. All rights reserved.
7 *
8 */
9
10#include "nvidia_resolution.h"
11
12vbios_map * open_nvidia_vbios(vbios_map *map)
13{
14unsigned short nv_data_table_offset = 0;
15unsigned short nv_modeline_2_offset = 0;
16unsigned short * nv_data_table = NULL;
17NV_VESA_TABLE * std_vesa;
18
19/*
20 * Locate the VESA Tables
21 */
22
23int i = 0;
24
25while (i < 0x300) { //We don't need to look for the table in the whole bios, the 768 first bytes only
26if ((map->bios_ptr[i] == 0x44)
27&& (map->bios_ptr[i+1] == 0x01)
28&& (map->bios_ptr[i+2] == 0x04)
29&& (map->bios_ptr[i+3] == 0x00)) {
30nv_data_table_offset = (unsigned short) (map->bios_ptr[i+4] | (map->bios_ptr[i+5] << 8));
31break;
32}
33i++;
34}
35//Second VESA Table on some nVidia 8xxx 9xxx and GT
36while (i < VBIOS_SIZE) { //We don't know how to locate it other way
37if ((map->bios_ptr[i] == 0x40) && (map->bios_ptr[i+1] == 0x01) //this is the first 320x200 modeline.
38&& (map->bios_ptr[i+2] == 0xC8) && (map->bios_ptr[i+3] == 0x00)
39&& (map->bios_ptr[i+4] == 0x28)
40&& (map->bios_ptr[i+5] == 0x18)
41&& (map->bios_ptr[i+6] == 0x08)
42&& (map->bios_ptr[i+7] == 0x08)) {
43nv_modeline_2_offset = (unsigned short) i;
44break;
45}
46i++;
47}
48
49nv_data_table = (unsigned short *) (map->bios_ptr + (nv_data_table_offset + OFFSET_TO_VESA_TABLE_INDEX));
50std_vesa = (NV_VESA_TABLE *) (map->bios_ptr + *nv_data_table);
51map->mode_table = (char *) std_vesa->sModelines;
52PRINT("First Standard VESA Table at offset 0x%x\n", *nv_data_table);
53
54if (nv_modeline_2_offset == (VBIOS_SIZE-1) || nv_modeline_2_offset == 0) {
55map->nv_mode_table_2 = NULL;
56PRINT("There is no Second Standard VESA Table to patch\n");
57} else {
58map->nv_mode_table_2 = (char*) map->bios_ptr + nv_modeline_2_offset;
59PRINT("Second Standard VESA Table at offset 0x%x\n", nv_modeline_2_offset);
60}
61
62if (map->mode_table == NULL) {
63PRINT("Unable to locate the mode table.\n");
64PRINT("Please run the program 'dump_bios' as root and\n");
65PRINT("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");
66
67close_vbios(map);
68return 0;
69}
70
71/*
72 * Having trouble determining the number of table
73 * so it's hardcode to 16 and 31 for the First VESA table
74 * and the Second Vesa Table respectively
75 */
76
77map->modeline_num = 16;
78map->nv_modeline_num_2 = 31;
79
80/*NV_MODELINE_2 *mode_2_ptr =(NV_MODELINE_2 *)map->nv_mode_table_2;
81map->modeline_num = map->nv_modeline_num_2 = 0;
82
83//First Table
84map->modeline_num = std_vesa->sHeader.usTableSize;
85
86PRINT("First VESA Table has %d modes\n",map->modeline_num);
87if (map->modeline_num == 0) {
88PRINT("%d is incorrect, make it a 16\n",map->modeline_num);
89map->modeline_num = 16;
90}
91map->mode_table_size = map->modeline_num * sizeof(NV_MODELINE);
92
93//Second Table
94map->nv_modeline_num_2 = *((UInt8 *)(mode_2_ptr - 2)) - 32;
95
96PRINT("Second VESA Table has %d modes\n",map->nv_modeline_num_2);
97if (map->nv_modeline_num_2 == 0) {
98PRINT("%d is incorrect, make it a 32\n",map->nv_modeline_num_2);
99map->nv_modeline_num_2 = 32;
100}
101map->nv_mode_table_2_size = map->nv_modeline_num_2 * sizeof(NV_MODELINE_2);*/
102
103return map;
104}
105
106bool nvidia_set_mode(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y, char Type)
107{
108if (Type == MAIN_VESA_TABLE) {
109NV_MODELINE * mode_timing = (NV_MODELINE *) map->mode_table;
110
111if ((*x != 0) && (*y != 0) && ( mode_timing[idx].usH_Active >= 640 )) {
112
113PRINT("Mode %dx%d -> %dx%d ", mode_timing[idx].usH_Active, mode_timing[idx].usV_Active,
114*x, *y);
115
116generic_modeline modeline;
117
118cvt_timings(*x, *y, 60, &modeline.clock,
119&modeline.hsyncstart, &modeline.hsyncend,
120&modeline.htotal, &modeline.vsyncstart,
121&modeline.vsyncend, &modeline.vtotal, FALSE);
122
123mode_timing[idx].usH_Active = *x;
124mode_timing[idx].usH_Active_minus_One = *x - 1;
125mode_timing[idx].usH_Active_minus_One_ = *x - 1;
126
127mode_timing[idx].usV_Active = *y;
128mode_timing[idx].usV_Active_minus_One = *y - 1;
129mode_timing[idx].usV_Active_minus_One_ = *y - 1;
130
131mode_timing[idx].usH_Total = modeline.htotal;
132mode_timing[idx].usH_SyncStart = modeline.hsyncstart;
133mode_timing[idx].usH_SyncEnd = modeline.hsyncend;
134
135mode_timing[idx].usV_Total = modeline.vtotal;
136mode_timing[idx].usV_SyncStart = modeline.vsyncstart;
137mode_timing[idx].usV_SyncEnd = modeline.vsyncend;
138
139mode_timing[idx].usPixel_Clock = modeline.clock;
140}
141
142*x = mode_timing[idx + 1].usH_Active;
143*y = mode_timing[idx + 1].usV_Active;
144}
145
146if (Type == SECOND_VESA_TABLE) {
147NV_MODELINE_2 * mode_timing = (NV_MODELINE_2 *) map->nv_mode_table_2;
148
149if (mode_timing[idx].h_disp > 0x800) return FALSE;
150
151if ((*x != 0) && (*y != 0) && ( mode_timing[idx].h_disp >= 640 )) {
152
153PRINT("Mode %dx%d -> %dx%d ", mode_timing[idx].h_disp, mode_timing[idx].v_disp,
154*x, *y);
155
156generic_modeline modeline;
157
158cvt_timings(*x, *y, 60, &modeline.clock,
159&modeline.hsyncstart, &modeline.hsyncend,
160&modeline.htotal, &modeline.vsyncstart,
161&modeline.vsyncend, &modeline.vtotal, TRUE);
162
163mode_timing[idx].h_disp = *x;
164mode_timing[idx].v_disp = *y;
165mode_timing[idx].h_blank = modeline.htotal - *x;
166mode_timing[idx].h_syncoffset = modeline.hsyncstart - *x;
167mode_timing[idx].h_syncwidth = modeline.hsyncend - modeline.hsyncstart;
168mode_timing[idx].v_blank = modeline.vtotal - *y;
169}
170
171*x = mode_timing[idx + 1].h_disp;
172*y = mode_timing[idx + 1].v_disp;
173}
174return TRUE;
175}
176

Archive Download this file

Revision: 137