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