Chameleon

Chameleon Svn Source Tree

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

Source at commit 106 created 10 years 10 months ago.
By diebuche, Adding 915patch and edid
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);
34
35
36//printf("H Active = %d", edidInfo[56] | ((edidInfo[58] & 0xF0) << 4) );
37//printf("V Active = %d", edidInfo[59] | ((edidInfo[61] & 0xF0) << 4) );
38
39
40bpResolution = 32;// assume 32bits
41
42
43free( edidInfo );
44
45if(!xResolution) xResolution = 1024; //DEFAULT_SCREEN_WIDTH;
46if(!yResolution) yResolution = 768; //DEFAULT_SCREEN_HEIGTH;
47
48}
49
50*x = xResolution;
51*y = yResolution;
52*bp = bpResolution;
53
54}
55
56char* readEDID()
57{
58SInt16 last_reported = -1;
59UInt8 edidInfo[EDID_BLOCK_SIZE];
60
61UInt8 pointer;
62
63UInt8 header1[] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
64UInt8 header2[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
65
66int status;
67unsigned int blocks_left = 1;
68
69do
70{
71// TODO: This currently only retrieves the *last* block, make the block buffer expand as needed / calculated from the first block
72
73bzero( edidInfo, EDID_BLOCK_SIZE);
74
75status = getEDID(edidInfo, blocks_left);
76
77//printf("Buffer location: 0x%X\n", SEG(buffer) << 16 | OFF(buffer));
78
79/*
80int j, i;
81for (j = 0; j < 8; j++) {
82for(i = 0; i < 16; i++) printf("0x%X ", ebiosInfo[((i+1) * (j + 1)) - 1]);
83
84}
85printf("\n");
86*/
87
88if(status == 0)
89{
90//if( edidInfo[0] == 0x00 || edidInfo[0] == 0xFF)
91if((memcmp(edidInfo, header1, sizeof(header1)) != 0) ||
92 (memcmp(edidInfo, header2, sizeof(header2)) != 0) )
93{
94blocks_left--;
95int reported = edidInfo[ EDID_V1_BLOCKS_TO_GO_OFFSET ];
96
97if ( reported > blocks_left )
98{
99
100printf("EDID claims %d more blocks left\n", reported);
101}
102
103if ( (last_reported <= reported && last_reported != -1)
104|| reported == 0xff
105/* 0xff frequently comes up in corrupt edids */
106//|| reported == MAGIC
107)
108{
109printf("Last reported %d\n", last_reported);
110printf( "EDID blocks left is wrong.\n"
111 "Your EDID is probably invalid.\n");
112return 0;
113}
114else
115{
116//printf("Reading EDID block\n");
117//printf("H Active = %d", ebiosInfo[56] | ((ebiosInfo[58] & 0xF0) << 4) );
118//printf("V Active = %d", ebiosInfo[59] | ((ebiosInfo[61] & 0xF0) << 4) );
119
120last_reported = reported;
121blocks_left = reported;
122}
123}
124else
125{
126printf("Invalid block %d\n", blocks_left);
127printf("Header1 = %d", memcmp(edidInfo, header1, sizeof(header1)) );
128printf("Header2 = %d", memcmp(edidInfo, header2, sizeof(header2)) );
129return 0;
130}
131}
132blocks_left = 0;
133} while(blocks_left);
134
135UInt8* ret = malloc(sizeof(edidInfo));
136memcpy(ret, edidInfo, sizeof(edidInfo));
137return ret;
138}
139

Archive Download this file

Revision: 106