Chameleon

Chameleon Svn Source Tree

Root/branches/azimutz/Chazi/i386/libsaio/edid.c

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 "bootstruct.h"
13#include "graphics.h"
14#include "boot.h"
15
16
17//static biosBuf_t bb;
18
19UInt32 xResolution = 0;
20UInt32 yResolution = 0;
21UInt32 bpResolution = 0;
22
23
24void getResolution(UInt32* params)
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// Mode Sanity check
44if ((xResolution < 1024) || !yResolution || !xResolution)
45{
46xResolution = 1024;
47yResolution = 768;
48}
49
50params[0] = xResolution;
51params[1] = yResolution;
52params[2] = bpResolution;
53}
54}
55
56
57unsigned char* readEDID()
58{
59SInt16 last_reported = -1;
60UInt8 edidInfo[EDID_BLOCK_SIZE];
61
62//UInt8 pointer;
63
64UInt8 header1[] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
65UInt8 header2[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
66
67int status;
68unsigned int blocks_left = 1;
69
70do
71{
72// TODO: This currently only retrieves the *last* block, make the block buffer expand as needed / calculated from the first block
73
74bzero( edidInfo, EDID_BLOCK_SIZE);
75
76status = getEDID(edidInfo, blocks_left);
77
78//printf("Buffer location: 0x%X\n", SEG(buffer) << 16 | OFF(buffer));
79
80/*
81int j, i;
82for (j = 0; j < 8; j++) {
83for(i = 0; i < 16; i++) printf("0x%X ", ebiosInfo[((i+1) * (j + 1)) - 1]);
84
85}
86printf("\n");
87*/
88
89if(status == 0)
90{
91//if( edidInfo[0] == 0x00 || edidInfo[0] == 0xFF)
92if((memcmp(edidInfo, header1, sizeof(header1)) != 0) ||
93 (memcmp(edidInfo, header2, sizeof(header2)) != 0) )
94{
95blocks_left--;
96int reported = edidInfo[ EDID_V1_BLOCKS_TO_GO_OFFSET ];
97
98if ( reported > blocks_left )
99{
100
101printf("EDID claims %d more blocks left\n", reported);
102}
103
104if ( (last_reported <= reported && last_reported != -1)
105|| reported == 0xff
106/* 0xff frequently comes up in corrupt edids */
107//|| reported == MAGIC
108)
109{
110printf("Last reported %d\n", last_reported);
111printf( "EDID blocks left is wrong.\n"
112 "Your EDID is probably invalid.\n");
113return 0;
114}
115else
116{
117//printf("Reading EDID block\n");
118//printf("H Active = %d", ebiosInfo[56] | ((ebiosInfo[58] & 0xF0) << 4) );
119//printf("V Active = %d", ebiosInfo[59] | ((ebiosInfo[61] & 0xF0) << 4) );
120
121last_reported = reported;
122blocks_left = reported;
123}
124}
125else
126{
127printf("Invalid block %d\n", blocks_left);
128printf("Header1 = %d", memcmp(edidInfo, header1, sizeof(header1)) );
129printf("Header2 = %d", memcmp(edidInfo, header2, sizeof(header2)) );
130return 0;
131}
132} else {
133return 0;
134}
135
136
137blocks_left = 0;
138} while(blocks_left);
139
140UInt8* ret = malloc(sizeof(edidInfo));
141memcpy(ret, edidInfo, sizeof(edidInfo));
142return (ret);
143}
144

Archive Download this file

Revision: 470