Chameleon

Chameleon Svn Source Tree

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

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

Archive Download this file

Revision: 132