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