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