1 /*
2 * vgadump.c:
3 *
4 * Dump vga registers.
5 *
6 * Rewritten Feb 1996 by Stephen Lee. Copyright 1996 Stephen Lee.
7 * This file is part of SVGAlib. Original copyrights:
8 *
9 * VGAlib version 1.2 - (c) 1993 Tommy Frandsen
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it without any restrictions. This library is distributed
13 * in the hope that it will be useful, but without any warranty.
14 *
15 * Multi-chipset support Copyright 1993 Harm Hanemaayer
16 */
17
18 #include <stdio.h>
19 #include <stdarg.h>
20 #include "vga.h"
21 #include "libvga.h"
22 #include "driver.h"
23
dumpregs(const unsigned char regs[],int n,const char * fmt,...)24 static void dumpregs(const unsigned char regs[], int n, const char *fmt, ...)
25 {
26 int i;
27 va_list ap;
28
29 if (!n)
30 return;
31 i = 0;
32 printf(" ");
33 while (i < n) {
34 printf("0x%02X,", regs[i]);
35 i++;
36 if (i % 8 == 0 || i == n) {
37 if (i <= 8) {
38 va_start(ap, fmt);
39 vprintf(fmt, ap);
40 va_end(ap);
41 }
42 printf("\n");
43 if (i != n)
44 printf(" ");
45 }
46 }
47 }
48
49 /*
50 * dump VGA registers. Note the output has a comma at the end
51 * (it's simpler to code and the standard allows it)
52 */
__svgalib_dumpregs(const unsigned char regs[],int n)53 void __svgalib_dumpregs(const unsigned char regs[], int n)
54 {
55 printf("static unsigned char regs[%d] = {\n", n);
56
57 dumpregs(regs + CRT, CRT_C, "\t/* CR00-CR%02x */", CRT_C);
58 dumpregs(regs + ATT, ATT_C, "\t/* AR00-AR%02x */", ATT_C);
59 dumpregs(regs + GRA, GRA_C, "\t/* GR00-GR%02x */", SEQ_C);
60 dumpregs(regs + SEQ, SEQ_C, "\t\t\t/* SR00-SR%02x */", SEQ_C);
61 dumpregs(regs + MIS, MIS_C, "\t\t\t\t\t\t/* MISC_OUT */");
62 n -= EXT;
63 if (n) {
64 printf(" /* Extended (count = 0x%02x) */\n", n);
65 dumpregs(regs + EXT, n, "");
66 }
67 printf("};\n");
68 }
69
vga_dumpregs(void)70 int vga_dumpregs(void)
71 {
72 unsigned char regs[MAX_REGS];
73 int n;
74
75 __svgalib_getchipset();
76
77 n = __svgalib_saveregs(regs);
78 __svgalib_dumpregs(regs, n);
79
80 return 0;
81 }
82