aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2005-02-25 09:30:33 +0000
committerPascal Rigaux <pixel@mandriva.com>2005-02-25 09:30:33 +0000
commit59b3868214a40e1cacf62c5f097d228310cd9eeb (patch)
tree06167d5246f5a1f93806a7e730f313af1e2b69fd
parent8c463e6886ec1c4d9b337a1922cd52df5d7f9120 (diff)
downloadmonitor-edid-59b3868214a40e1cacf62c5f097d228310cd9eeb.tar
monitor-edid-59b3868214a40e1cacf62c5f097d228310cd9eeb.tar.gz
monitor-edid-59b3868214a40e1cacf62c5f097d228310cd9eeb.tar.bz2
monitor-edid-59b3868214a40e1cacf62c5f097d228310cd9eeb.tar.xz
monitor-edid-59b3868214a40e1cacf62c5f097d228310cd9eeb.zip
- get rid of compile time DEBUG using runtime variable "verbose" instead
=> allow accessing memory size as ddcxinfos used to do - struct vbe_info really is unused, dropping it - simplify canon_str (it doesn't malloc anymore) - new function get_str() to factorize code
-rw-r--r--Makefile2
-rw-r--r--get-edid.h1
-rw-r--r--monitor-get-edid.c7
-rw-r--r--vbe.c102
4 files changed, 38 insertions, 74 deletions
diff --git a/Makefile b/Makefile
index 8e97468..b788e35 100644
--- a/Makefile
+++ b/Makefile
@@ -27,7 +27,7 @@ HAS_OPEN_FIRMWARE = y
TARGETS = monitor-get-edid
-CFLAGS = -O -Wall # -g -DDEBUG
+CFLAGS = -O -Wall # -g
OBJS = monitor-get-edid.c
ifeq (y,$(HAS_VBE))
diff --git a/get-edid.h b/get-edid.h
index 34bad70..d13aa3b 100644
--- a/get-edid.h
+++ b/get-edid.h
@@ -1 +1,2 @@
+int verbose;
int get_edid(char *edid);
diff --git a/monitor-get-edid.c b/monitor-get-edid.c
index ed5b480..781684c 100644
--- a/monitor-get-edid.c
+++ b/monitor-get-edid.c
@@ -9,9 +9,14 @@
#include <stdarg.h>
#include "get-edid.h"
-int main(void)
+int verbose = 0;
+
+int main(int argc, char **argv)
{
char edid[256];
+
+ if (argc > 1 && strcmp(argv[1], "-v") == 0) verbose = 1;
+
int size = get_edid(edid);
if (size) write(1, edid, size);
diff --git a/vbe.c b/vbe.c
index eb6c918..4e289ca 100644
--- a/vbe.c
+++ b/vbe.c
@@ -23,29 +23,17 @@
#include <stdarg.h>
-/* used by libint10 */
+/* also used by libint10 */
void log_err(char *format, ...)
{
- va_list args;
- va_start(args, format);
- vfprintf(stderr, format, args);
- va_end(args);
+ if (verbose) {
+ va_list args;
+ va_start(args, format);
+ vfprintf(stderr, format, args);
+ va_end(args);
+ }
}
-#ifdef DEBUG
-/* Record returned by int 0x10, function 0x4f, subfunction 0x00. */
-struct vbe_info {
- unsigned int version;
- unsigned int oem_version;
- unsigned int memory_size;
- char *oem_name;
- char *vendor_name;
- char *product_name;
- char *product_revision;
- unsigned int modes;
- unsigned int mode_list[0x100];
-};
-
/*
* Create a 'canonical' version, i.e. no spaces at start and end.
*
@@ -54,22 +42,16 @@ struct vbe_info {
*/
static char *canon_str(char *s, int len)
{
- char *m2, *m1, *m0 = malloc(len + 1);
- int i;
+ char *start, *end;
- for(m1 = m0, i = 0; i < len; i++) {
- if(m1 == m0 && s[i] <= ' ') continue;
- *m1++ = s[i];
- }
- *m1 = 0;
- while(m1 > m0 && m1[-1] <= ' ') {
- *--m1 = 0;
- }
+ for (start = s; start < s + len; start++) if (start[0] > ' ') break;
- m2 = strdup(m0);
- free(m0);
+ for (end = &s[len - 1]; end >= start; end--) {
+ if (end[0] > ' ') break;
+ end[0] = 0;
+ }
- return m2;
+ return start;
}
static unsigned segofs2addr(unsigned char *segofs)
@@ -101,7 +83,12 @@ static unsigned get_data(unsigned char *buf, unsigned buf_size, unsigned addr)
return len;
}
-#endif
+
+static char *get_str(unsigned char *buf, unsigned buf_size, char *v)
+{
+ int len = get_data(buf, buf_size, segofs2addr(v));
+ return canon_str(buf, len);
+}
#define GET_WORD(ADDR, OFS) ((ADDR)[OFS] + ((ADDR)[(OFS) + 1] << 8))
@@ -121,53 +108,26 @@ int vbe_check_vbe_info(void)
/* Get VBE block */
i = CallInt10(&ax, &bx, &cx, v, sizeof(v), cpuemu) & 0xffff;
if (i != 0x4f) {
-#ifdef DEBUG
log_err("VBE: Error (0x4f00): 0x%04x\n", i);
-#endif
return 0;
}
-#ifdef DEBUG
{
- int l, u;
unsigned char tmp[1024];
- struct vbe_info vbe;
/* Parse VBE block */
- vbe.version = GET_WORD(v, 0x04);
- vbe.oem_version = GET_WORD(v, 0x14);
- vbe.memory_size = GET_WORD(v, 0x12) << 16;
+ int version = GET_WORD(v, 0x04);
+ int oem_version = GET_WORD(v, 0x14);
+ int memory_size = GET_WORD(v, 0x12) << 16;
log_err("version = %u.%u, oem version = %u.%u\n",
- vbe.version >> 8, vbe.version & 0xff, vbe.oem_version >> 8, vbe.oem_version & 0xff);
- log_err("memory = %uk\n", vbe.memory_size >> 10);
-
- l = get_data(tmp, sizeof tmp, u = segofs2addr(v + 0x06));
- vbe.oem_name = canon_str(tmp, l);
- log_err("oem name [0x%05x] = \"%s\"\n", u, vbe.oem_name);
-
- l = get_data(tmp, sizeof tmp, u = segofs2addr(v + 0x16));
- vbe.vendor_name = canon_str(tmp, l);
- log_err("vendor name [0x%05x] = \"%s\"\n", u, vbe.vendor_name);
-
- l = get_data(tmp, sizeof tmp, u = segofs2addr(v + 0x1a));
- vbe.product_name = canon_str(tmp, l);
- log_err("product name [0x%05x] = \"%s\"\n", u, vbe.product_name);
-
- l = get_data(tmp, sizeof tmp, u = segofs2addr(v + 0x1e));
- vbe.product_revision = canon_str(tmp, l);
- log_err("product revision [0x%05x] = \"%s\"\n", u, vbe.product_revision);
-
- l = get_data(tmp, sizeof tmp, u = segofs2addr(v + 0x0e)) >> 1;
- for(i = vbe.modes = 0; i < l && i < sizeof vbe.mode_list / sizeof *vbe.mode_list; i++) {
- u = GET_WORD(tmp, 2 * i);
- if(u != 0xffff)
- vbe.mode_list[vbe.modes++] = u;
- else
- break;
- }
- log_err("%u video modes\n", vbe.modes);
+ version >> 8, version & 0xff, oem_version >> 8, oem_version & 0xff);
+ log_err("memory = %uk\n", memory_size >> 10);
+
+ log_err("oem name = %s\n", get_str(tmp, sizeof tmp, v + 0x06));
+ log_err("vendor name = %s\n", get_str(tmp, sizeof tmp, v + 0x16));
+ log_err("product name = %s\n", get_str(tmp, sizeof tmp, v + 0x1a));
+ log_err("product revision = %s\n", get_str(tmp, sizeof tmp, v + 0x1e));
}
-#endif
return 1;
}
@@ -185,9 +145,7 @@ int vbe_get_edid_info(char *edid)
/* Get EDID block */
i = CallInt10(&ax, &bx, &cx, edid, 256, cpuemu) & 0xffff;
if (i != 0x4f) {
-#ifdef DEBUG
log_err("EDID: Error (0x4f15): 0x%04x\n", i);
-#endif
return 0;
}