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