Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 148