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