Chameleon

Chameleon Svn Source Tree

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

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
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;
52verbose("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;
56verbose("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;
59verbose("Second Standard VESA Table at offset 0x%x\n", nv_modeline_2_offset);
60}
61
62if (map->mode_table == NULL) {
63verbose("Unable to locate the mode table.\n");
64verbose("Please run the program 'dump_bios' as root and\n");
65verbose("email the file 'vbios.dmp' to gaeloulacuisse@yahoo.fr.\n");
66
67close_vbios(map);
68return 0;
69}
70
71//This won't be used as there is no garanty this is right
72map->mode_table_size = std_vesa->sHeader.usTable_Size;
73
74return map;
75}
76
77bool nvidia_set_mode(vbios_map* map, UInt8 idx, UInt32* x, UInt32* y, char Type)
78{
79if (Type == MAIN_VESA_TABLE) {
80NV_MODELINE * mode_timing = (NV_MODELINE *) map->mode_table;
81
82if ((mode_timing[idx].reserved3 & 0xff) != 0xff) return FALSE;
83
84if ((*x != 0) && (*y != 0) && ( mode_timing[idx].usH_Active >= 640 )) {
85
86verbose("Mode %dx%d -> %dx%d ", mode_timing[idx].usH_Active, mode_timing[idx].usV_Active,
87 *x, *y);
88
89mode_timing[idx].usH_Active = *x;
90mode_timing[idx].usH_Active_minus_One = *x - 1;
91mode_timing[idx].usH_Active_minus_One_ = *x - 1;
92mode_timing[idx].usV_Active = *y;
93mode_timing[idx].usV_Active_minus_One = *y - 1;
94mode_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
101if (Type == SECOND_VESA_TABLE) {
102NV_MODELINE_2 * mode_timing = (NV_MODELINE_2 *) map->nv_mode_table_2;
103
104if (mode_timing[idx].h_disp > 0x800) return FALSE;
105
106if ((*x != 0) && (*y != 0) && ( mode_timing[idx].h_disp >= 640 )) {
107
108verbose("Mode %dx%d -> %dx%d ", mode_timing[idx].h_disp, mode_timing[idx].v_disp,
109 *x, *y);
110
111mode_timing[idx].h_disp = *x;
112mode_timing[idx].v_disp = *y;
113}
114
115*x = mode_timing[idx + 1].h_disp;
116*y = mode_timing[idx + 1].v_disp;
117}
118return TRUE;
119}
120

Archive Download this file

Revision: 132