Chameleon

Chameleon Svn Source Tree

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

Source at commit 113 created 14 years 2 months ago.
By diebuche, working on ati res.
1/*
2 * edid.c
3 *
4 *
5 * Created by Evan Lojewski on 12/1/09.
6 * Copyright 2009. All rights reserved.
7 *
8 */
9
10
11#include "libsaio.h"
12#include "edid.h"
13#include "vbe.h"
14//#include "graphics.h"
15
16static biosBuf_t bb;
17
18UInt32 xResolution = 0;
19UInt32 yResolution = 0;
20UInt32 bpResolution = 0;
21
22void getResolution(UInt32* x, UInt32* y, UInt32* bp)
23{
24if(!xResolution && !yResolution && !bpResolution)
25{
26
27char* edidInfo = readEDID();
28
29if(!edidInfo) return;
30
31// TODO: check *all* resolutions reported and eithe ruse the highest, or the native resolution (if there is a flag for that)
32xResolution = edidInfo[56] | ((edidInfo[58] & 0xF0) << 4);
33yResolution = edidInfo[59] | ((edidInfo[61] & 0xF0) << 4); //1050
34
35
36printf("EDID from 56 = %d \n", edidInfo[56]);
37printf("EDID from 56 = %d \n", edidInfo[57]);
38printf("EDID from 56 = %d \n", edidInfo[58]);
39printf("EDID from 56 = %d \n", edidInfo[59]);
40printf("EDID from 56 = %d \n", edidInfo[60]);
41printf("EDID from 56 = %d \n", edidInfo[61]);
42printf("EDID from 56 = %d \n", edidInfo[62]);
43
44
45printf("H Active = %d \n", edidInfo[56] | ((edidInfo[58] & 0xF0) << 4) );
46printf("H Active = %d \n", edidInfo[57] | ((edidInfo[58] & 0xF0) << 4) );
47printf("H Active = %d \n", edidInfo[57] | ((edidInfo[59] & 0xF0) << 4) );
48printf("H Active = %d \n", edidInfo[55] | ((edidInfo[57] & 0xF0) << 4) );
49
50printf("V Active = %d \n", edidInfo[59] | ((edidInfo[61] & 0xF0) << 4) );
51
52
53bpResolution = 32;// assume 32bits
54
55
56free( edidInfo );
57
58if(!xResolution) xResolution = 1024; //DEFAULT_SCREEN_WIDTH;
59if(!yResolution) yResolution = 768; //DEFAULT_SCREEN_HEIGTH;
60
61}
62
63*x = xResolution;
64*y = yResolution;
65*bp = bpResolution;
66
67}
68
69char* readEDID()
70{
71SInt16 last_reported = -1;
72UInt8 edidInfo[EDID_BLOCK_SIZE];
73
74UInt8 pointer;
75
76UInt8 header1[] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
77UInt8 header2[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
78
79int status;
80unsigned int blocks_left = 1;
81
82do
83{
84// TODO: This currently only retrieves the *last* block, make the block buffer expand as needed / calculated from the first block
85
86bzero( edidInfo, EDID_BLOCK_SIZE);
87
88status = getEDID(edidInfo, blocks_left);
89
90//printf("Buffer location: 0x%X\n", SEG(buffer) << 16 | OFF(buffer));
91
92/*
93int j, i;
94for (j = 0; j < 8; j++) {
95for(i = 0; i < 16; i++) printf("0x%X ", ebiosInfo[((i+1) * (j + 1)) - 1]);
96
97}
98printf("\n");
99*/
100
101if(status == 0)
102{
103//if( edidInfo[0] == 0x00 || edidInfo[0] == 0xFF)
104if((memcmp(edidInfo, header1, sizeof(header1)) != 0) ||
105 (memcmp(edidInfo, header2, sizeof(header2)) != 0) )
106{
107blocks_left--;
108int reported = edidInfo[ EDID_V1_BLOCKS_TO_GO_OFFSET ];
109
110if ( reported > blocks_left )
111{
112
113printf("EDID claims %d more blocks left\n", reported);
114}
115
116if ( (last_reported <= reported && last_reported != -1)
117|| reported == 0xff
118/* 0xff frequently comes up in corrupt edids */
119//|| reported == MAGIC
120)
121{
122printf("Last reported %d\n", last_reported);
123printf( "EDID blocks left is wrong.\n"
124 "Your EDID is probably invalid.\n");
125return 0;
126}
127else
128{
129//printf("Reading EDID block\n");
130//printf("H Active = %d", ebiosInfo[56] | ((ebiosInfo[58] & 0xF0) << 4) );
131//printf("V Active = %d", ebiosInfo[59] | ((ebiosInfo[61] & 0xF0) << 4) );
132
133last_reported = reported;
134blocks_left = reported;
135}
136}
137else
138{
139printf("Invalid block %d\n", blocks_left);
140printf("Header1 = %d", memcmp(edidInfo, header1, sizeof(header1)) );
141printf("Header2 = %d", memcmp(edidInfo, header2, sizeof(header2)) );
142return 0;
143}
144}
145blocks_left = 0;
146} while(blocks_left);
147
148UInt8* ret = malloc(sizeof(edidInfo));
149memcpy(ret, edidInfo, sizeof(edidInfo));
150return ret;
151}
152

Archive Download this file

Revision: 113