Root/
Source at commit 132 created 14 years 1 month ago. By diebuche, Adding lebidous latest changes | |
---|---|
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 | ␊ |
12 | vbios_map * open_nvidia_vbios(vbios_map *map)␊ |
13 | {␊ |
14 | ␉unsigned short nv_data_table_offset = 0;␊ |
15 | ␉unsigned short nv_modeline_2_offset = 0;␊ |
16 | ␉unsigned short * nv_data_table = NULL;␊ |
17 | ␉NV_VESA_TABLE * std_vesa;␊ |
18 | ␉␊ |
19 | ␉/*␊ |
20 | ␉ * Locate the VESA Tables␊ |
21 | ␉ */␊ |
22 | ␉␊ |
23 | ␉int i = 0;␊ |
24 | ␉␊ |
25 | ␉while (i < 0x300) { //We don't need to look for the table in the whole bios, the 768 first bytes only␊ |
26 | ␉␉if ((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)) {␊ |
30 | ␉␉␉nv_data_table_offset = (unsigned short) (map->bios_ptr[i+4] | (map->bios_ptr[i+5] << 8));␊ |
31 | ␉␉␉break;␊ |
32 | ␉␉}␊ |
33 | ␉␉i++;␊ |
34 | ␉}␊ |
35 | ␉//Second VESA Table on some nVidia 8xxx 9xxx and GT␊ |
36 | ␉while (i < VBIOS_SIZE) { //We don't know how to locate it other way␊ |
37 | ␉␉if ((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)) {␊ |
43 | ␉␉␉nv_modeline_2_offset = (unsigned short) i;␊ |
44 | ␉␉␉break;␊ |
45 | ␉␉}␊ |
46 | ␉␉i++;␊ |
47 | ␉}␊ |
48 | ␉␊ |
49 | ␉nv_data_table = (unsigned short *) (map->bios_ptr + (nv_data_table_offset + OFFSET_TO_VESA_TABLE_INDEX));␊ |
50 | ␉std_vesa = (NV_VESA_TABLE *) (map->bios_ptr + *nv_data_table);␊ |
51 | ␉map->mode_table = (char *) std_vesa->sModelines;␊ |
52 | ␉verbose("First Standard VESA Table at offset 0x%x\n", *nv_data_table);␊ |
53 | ␉␊ |
54 | ␉if (nv_modeline_2_offset == (VBIOS_SIZE-1) || nv_modeline_2_offset == 0) {␊ |
55 | ␉␉map->nv_mode_table_2 = NULL;␊ |
56 | ␉␉verbose("There is no Second Standard VESA Table to patch\n");␊ |
57 | ␉} else {␊ |
58 | ␉␉map->nv_mode_table_2 = (char*) map->bios_ptr + nv_modeline_2_offset;␊ |
59 | ␉␉verbose("Second Standard VESA Table at offset 0x%x\n", nv_modeline_2_offset);␊ |
60 | ␉}␊ |
61 | ␉␊ |
62 | ␉if (map->mode_table == NULL) {␊ |
63 | ␉␉verbose("Unable to locate the mode table.\n");␊ |
64 | ␉␉verbose("Please run the program 'dump_bios' as root and\n");␊ |
65 | ␉␉verbose("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");␊ |
66 | ␉␉␊ |
67 | ␉␉close_vbios(map);␊ |
68 | ␉␉return 0;␊ |
69 | ␉}␊ |
70 | ␉␊ |
71 | ␉//This won't be used as there is no garanty this is right␊ |
72 | ␉map->mode_table_size = std_vesa->sHeader.usTable_Size;␊ |
73 | ␊ |
74 | ␉return map;␊ |
75 | }␊ |
76 | ␊ |
77 | bool nvidia_set_mode(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y, char Type)␊ |
78 | {␊ |
79 | ␉if (Type == MAIN_VESA_TABLE) {␊ |
80 | ␉␉NV_MODELINE * mode_timing = (NV_MODELINE *) map->mode_table;␊ |
81 | ␉␉␊ |
82 | ␉␉if ((mode_timing[idx].reserved3 & 0xff) != 0xff) return FALSE;␊ |
83 | ␉␉␊ |
84 | ␉␉if ((*x != 0) && (*y != 0) && ( mode_timing[idx].usH_Active >= 640 )) {␊ |
85 | ␉␉␉␊ |
86 | ␉␉␉verbose("Mode %dx%d -> %dx%d ", mode_timing[idx].usH_Active, mode_timing[idx].usV_Active,␊ |
87 | ␉␉␉␉ *x, *y);␊ |
88 | ␉␉␉␊ |
89 | ␉␉␉mode_timing[idx].usH_Active = *x;␊ |
90 | ␉␉␉mode_timing[idx].usH_Active_minus_One = *x - 1;␊ |
91 | ␉␉␉mode_timing[idx].usH_Active_minus_One_ = *x - 1;␊ |
92 | ␉␉␉mode_timing[idx].usV_Active = *y;␊ |
93 | ␉␉␉mode_timing[idx].usV_Active_minus_One = *y - 1;␊ |
94 | ␉␉␉mode_timing[idx].usV_Active_minus_One_ = *y - 1;␊ |
95 | ␉␉}␊ |
96 | ␉␉␊ |
97 | ␉␉*x = mode_timing[idx + 1].usH_Active;␊ |
98 | ␉␉*y = mode_timing[idx + 1].usV_Active;␊ |
99 | ␉}␊ |
100 | ␉␊ |
101 | ␉if (Type == SECOND_VESA_TABLE) {␊ |
102 | ␉␉NV_MODELINE_2 * mode_timing = (NV_MODELINE_2 *) map->nv_mode_table_2;␊ |
103 | ␉␉␊ |
104 | ␉␉if (mode_timing[idx].h_disp > 0x800) return FALSE;␊ |
105 | ␉␉␊ |
106 | ␉␉if ((*x != 0) && (*y != 0) && ( mode_timing[idx].h_disp >= 640 )) {␊ |
107 | ␉␉␉␊ |
108 | ␉␉␉verbose("Mode %dx%d -> %dx%d ", mode_timing[idx].h_disp, mode_timing[idx].v_disp,␊ |
109 | ␉␉␉␉ *x, *y);␊ |
110 | ␉␉␉␊ |
111 | ␉␉␉mode_timing[idx].h_disp = *x;␊ |
112 | ␉␉␉mode_timing[idx].v_disp = *y;␊ |
113 | ␉␉}␊ |
114 | ␉␉␊ |
115 | ␉␉*x = mode_timing[idx + 1].h_disp;␊ |
116 | ␉␉*y = mode_timing[idx + 1].v_disp;␊ |
117 | ␉}␊ |
118 | ␉return TRUE;␊ |
119 | }␊ |
120 |