diff options
Diffstat (limited to 'xc/programs/Xserver/hw/xfree86/ddc/edid.c')
-rw-r--r-- | xc/programs/Xserver/hw/xfree86/ddc/edid.c | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/xc/programs/Xserver/hw/xfree86/ddc/edid.c b/xc/programs/Xserver/hw/xfree86/ddc/edid.c new file mode 100644 index 000000000..6b2a909e1 --- /dev/null +++ b/xc/programs/Xserver/hw/xfree86/ddc/edid.c @@ -0,0 +1,127 @@ +/* $XFree86: xc/programs/Xserver/hw/xfree86/ddc/edid.c,v 1.2 1999/01/14 13:04:14 dawes Exp $ */ + +/* edid.c: retrieve EDID record from raw DDC1 data stream: data + * is contained in an array of unsigned int each unsigned int + * contains one bit if bit is 0 unsigned int has to be zero else + * unsigned int > 0 + * + * Copyright 1998 by Egbert Eich <Egbert.Eich@Physik.TU-Darmstadt.DE> + */ +#include "misc.h" +#include "xf86.h" +#include "xf86_ansic.h" +#include "xf86_OSproc.h" +#include "xf86DDC.h" + +int checksum(unsigned char *, int); +static int find_start(unsigned int *); +static unsigned char * find_header(unsigned char *); +static unsigned char * resort(unsigned char *); + +unsigned char * +GetEDID_DDC1(unsigned int *s_ptr) +{ + unsigned char *d_block, *d_pos; + unsigned int *s_pos, *s_end; + int s_start; + int i,j; + s_start = find_start(s_ptr); + if (s_start==-1) return NULL; + s_end = s_ptr + NUM; + s_pos = s_ptr + s_start; + d_block=xalloc(EDID1_LEN); + if (!d_block) return NULL; + d_pos = d_block; + for (i=0;i<EDID1_LEN;i++) { + for (j=0;j<8;j++) { + *d_pos <<= 1; + if (*s_pos) { + *d_pos |= 0x01; + } + s_pos++; if (s_pos == s_end) s_pos=s_ptr; + }; + s_pos++; if (s_pos == s_end) s_pos=s_ptr; + d_pos++; + } + xfree(s_ptr); + if (d_block && checksum(d_block,EDID1_LEN)) return NULL; + return (resort(d_block)); +} + +int +checksum(unsigned char *block, int len) +{ + int i, result = 0; + for (i=0;i<len;i++) + result += block[i]; +#ifdef DEBUG + if (result & 0xFF) ErrorF("DDC checksum not correct\n"); +#endif + return (result&0xFF); +} + +static int +find_start(unsigned int *ptr) +{ + unsigned int comp[9], test[9]; + int i,j; + + for (i=0;i<9;i++){ + comp[i] = *(ptr++); + test[i] = 1; + } + for (i=0;i<127;i++){ + for (j=0;j<9;j++){ + test[j] = test[j] & !(comp[j] ^ *(ptr++)); + } + } + for (i=0;i<9;i++) + if (test[i]) return (i+1); + return (-1); +} + +static unsigned char * +find_header(unsigned char *block) +{ + unsigned char *ptr, *head_ptr, *end; + unsigned char header[]={0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00}; + + ptr = block; + end = block + EDID1_LEN; + while (ptr<end) { + int i; + head_ptr = ptr; + for (i=0;i<8;i++){ + if (header[i] != *(head_ptr++)) break; + if (head_ptr == end) head_ptr = block; + } + if (i==8) break; + ptr++; + } + if (ptr == end) return (NULL); + return (ptr); +} + +static unsigned char * +resort(unsigned char *s_block) +{ + unsigned char *d_new, *d_ptr, *d_end, *s_ptr, *s_end; + unsigned char tmp; + + s_end = s_block + EDID1_LEN; + d_new = xalloc(EDID1_LEN); + if (!d_new) return NULL; + d_end = d_new + EDID1_LEN; + + s_ptr = find_header(s_block); + if (!s_ptr) return NULL; + for (d_ptr=d_new;d_ptr<d_end;d_ptr++){ + tmp = *(s_ptr++); + *d_ptr = tmp; + if (s_ptr == s_end) s_ptr = s_block; + } + xfree(s_block); + return (d_new); +} + + |