Chameleon

Chameleon Commit Details

Date:2010-05-09 07:55:20 (13 years 11 months ago)
Author:Evan Lojewski
Commit:147
Parents: 146
Message:EDID: reads edid from monitor to determine best resolution for main screen.
Changes:
A/branches/meklort/i386/libsaio/edid.c
A/branches/meklort/i386/libsaio/edid.h
M/branches/meklort/i386/boot2/gui.c
M/branches/meklort/i386/libsaio/vbe.c
M/branches/meklort/i386/libsaio/vbe.h

File differences

branches/meklort/i386/libsaio/vbe.c
105105
106106
107107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
108125
109126
110127
return(bb.eax.r.h);
}
int getEDID( void * edidBlock, UInt8 block)
{
bzero(&bb, sizeof(bb));
bb.intno = 0x10;
bb.eax.rr = funcGetEDID;
bb.ebx.r.l= 0x01;
bb.edx.rr = block;
bb.es = SEG( edidBlock );
bb.edi.rr = OFF( edidBlock );
bios( &bb );
return(bb.eax.r.h);
}
/*
* Default GTF parameter values.
*/
branches/meklort/i386/libsaio/vbe.h
6868
6969
7070
71
71
72
73
7274
7375
7476
......
269271
270272
271273
274
272275
273276
274277
funcGetSetPaletteFormat = 0x4F08,
funcGetSetPaletteData = 0x4F09,
funcGetProtModeInterdace = 0x4F0A,
funcGetSetPixelClock = 0x4F0B
funcGetSetPixelClock = 0x4F0B,
funcGetEDID = 0x4F15
};
enum {
typedef unsigned long VBEPalette[256];
extern int getVBEInfo(void *vinfo_p);
extern int getEDID( void * edidBlock, UInt8 block);
extern int getVBEModeInfo(int mode, void *minfo_p);
extern int getVBEDACFormat(unsigned char *format);
extern int setVBEDACFormat(unsigned char format);
branches/meklort/i386/libsaio/edid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* edid.c
*
*
* Created by Evan Lojewski on 12/1/09.
* Copyright 2009. All rights reserved.
*
*/
#include "libsaio.h"
#include "edid.h"
#include "vbe.h"
#include "graphics.h"
#include "boot.h"
void getResolution(UInt32* x, UInt32* y, UInt32* bp)
{
int val;
static UInt32 xResolution, yResolution, bpResolution;
if(getIntForKey(kScreenWidth, &val, &bootInfo->bootConfig))
{
xResolution = val;
}
if(getIntForKey(kScreenHeight, &val, &bootInfo->bootConfig))
{
yResolution = val;
}
bpResolution = 32;// assume 32bits
if(!xResolution || !yResolution || !bpResolution)
{
char* edidInfo = readEDID();
if(!edidInfo) return;
// TODO: check *all* resolutions reported and either use the highest, or the native resolution (if there is a flag for that)
xResolution = edidInfo[56] | ((edidInfo[58] & 0xF0) << 4);
yResolution = edidInfo[59] | ((edidInfo[61] & 0xF0) << 4);
//printf("H Active = %d", edidInfo[56] | ((edidInfo[58] & 0xF0) << 4) );
//printf("V Active = %d", edidInfo[59] | ((edidInfo[61] & 0xF0) << 4) );
free( edidInfo );
if(!xResolution) xResolution = DEFAULT_SCREEN_WIDTH;
if(!yResolution) yResolution = DEFAULT_SCREEN_HEIGHT;
}
*x = xResolution;
*y = yResolution;
*bp = bpResolution;
}
char* readEDID()
{
SInt16 last_reported = -1;
UInt8 edidInfo[EDID_BLOCK_SIZE];
UInt8 header1[] = {0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00};
UInt8 header2[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
SInt16 status;
UInt16 blocks_left = 1;
do
{
// TODO: This currently only retrieves the *last* block, make the block buffer expand as needed / calculated from the first block
bzero( edidInfo, EDID_BLOCK_SIZE);
status = getEDID(edidInfo, blocks_left);
//printf("Buffer location: 0x%X\n", SEG(buffer) << 16 | OFF(buffer));
/*
int j, i;
for (j = 0; j < 8; j++) {
for(i = 0; i < 16; i++) printf("0x%X ", ebiosInfo[((i+1) * (j + 1)) - 1]);
}
printf("\n");
*/
if(status == 0)
{
//if( edidInfo[0] == 0x00 || edidInfo[0] == 0xFF)
if((memcmp(edidInfo, header1, sizeof(header1)) != 0) ||
(memcmp(edidInfo, header2, sizeof(header2)) != 0) )
{
blocks_left--;
int reported = edidInfo[ EDID_V1_BLOCKS_TO_GO_OFFSET ];
if ( reported > blocks_left )
{
printf("EDID claims %d more blocks left\n", reported);
}
if ( (last_reported <= reported && last_reported != -1)
|| reported == 0xff
/* 0xff frequently comes up in corrupt edids */
//|| reported == MAGIC
)
{
printf("Last reported %d\n", last_reported);
printf( "EDID blocks left is wrong.\n"
"Your EDID is probably invalid.\n");
return 0;
}
else
{
//printf("Reading EDID block\n");
//printf("H Active = %d", ebiosInfo[56] | ((ebiosInfo[58] & 0xF0) << 4) );
//printf("V Active = %d", ebiosInfo[59] | ((ebiosInfo[61] & 0xF0) << 4) );
last_reported = reported;
blocks_left = reported;
}
}
else
{
printf("Invalid block %d\n", blocks_left);
printf("Header1 = %d", memcmp(edidInfo, header1, sizeof(header1)) );
printf("Header2 = %d", memcmp(edidInfo, header2, sizeof(header2)) );
return 0;
}
}
blocks_left = 0;
} while(blocks_left);
char* ret = malloc(sizeof(edidInfo));
memcpy(ret, edidInfo, sizeof(edidInfo));
return ret;
}
branches/meklort/i386/libsaio/edid.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/*
* edid.h
*
*
* Created by Evan Lojewski on 12/1/09.
* Copyright 2009. All rights reserved.
*
*/
#define EDID_BLOCK_SIZE128
#define EDID_V1_BLOCKS_TO_GO_OFFSET 126
char* readEDID();
void getResolution(UInt32* x, UInt32* y, UInt32* bp);
branches/meklort/i386/boot2/gui.c
1111
1212
1313
14
1415
1516
1617
......
556557
557558
558559
559
560
560561
561562
562563
......
577578
578579
579580
581
580582
581583
582584
......
585587
586588
587589
590
591
588592
593
589594
590595
591596
......
16851690
16861691
16871692
1688
1693
16891694
16901695
16911696
......
16971702
16981703
16991704
1705
17001706
17011707
17021708
......
17091715
17101716
17111717
1718
1719
1720
17121721
1722
17131723
17141724
17151725
#include "gui.h"
#include "appleboot.h"
#include "vers.h"
#include "edid.h"
#define THEME_NAME_DEFAULT"Default"
static const char *theme_name = THEME_NAME_DEFAULT;
int initGUI(void)
{
intval;
//intval;
#ifdef EMBED_THEME
config_file_t*config;
return 1;
}
#endif
/*
// parse display size parameters
if (getIntForKey("screen_width", &val, &bootInfo->themeConfig)) {
screen_params[0] = val;
screen_params[1] = val;
}
screen_params[2] = 32;
*/
getResolution(&screen_params[0], &screen_params[1], &screen_params[2]);
// Initalizing GUI strucutre.
bzero(&gui, sizeof(gui_t));
// drawBootGraphics
void drawBootGraphics(void)
{
int pos;
//int pos;
int length;
const char *dummyVal;
bool legacy_logo;
loadBootGraphics();
}
/*
// parse screen size parameters
if (getIntForKey("boot_width", &pos, &bootInfo->themeConfig)) {
screen_params[0] = pos;
screen_params[1] = DEFAULT_SCREEN_HEIGHT;
}
screen_params[2] = 32;
*/
getResolution(&screen_params[0], &screen_params[1], &screen_params[2]);
gui.screen.width = screen_params[0];
gui.screen.height = screen_params[1];

Archive Download the corresponding diff file

Revision: 147