1 /* From VGAlib, changed for svgalib */
2 /* partially copyrighted (C) 1993,1995 by Hartmut Schirmer */
3
4
5 #include <stdio.h>
6 #include <string.h>
7 #include "libbcc.h"
8 #include "stdfun.h"
9
testmode(int mode)10 static void testmode(int mode) {
11 int xmax, ymax;
12 int i, oldmode;
13 int x, y, yw;
14 int c;
15
16 if (graphresult() == grNoInitGraph)
17 return;
18 #ifdef __GNUC__
19 if (getmodemaxcolor(mode)+1 < 256)
20 return;
21 #endif
22 oldmode = getgraphmode();
23 if (mode != oldmode) {
24 graphresult();
25 setgraphmode(mode);
26 if (graphresult() != grOk)
27 return;
28 }
29 if (getmaxcolor() < 255) {
30 if (oldmode != mode)
31 setgraphmode(oldmode);
32 return;
33 }
34 xmax = getmaxx();
35 ymax = getmaxy();
36
37 yw = (ymax - 0) / 4;
38 switch (getmaxcolor()+1) {
39 case 256:
40 #define std_c (16)
41 #define free_c (256-std_c)
42 #define avail (free_c / 4)
43 #define nrval (256/4)
44 for (i = 0; i < avail; ++i) {
45 c = (i * nrval) / avail;
46 setrgbpalette(i + std_c + (0 * avail), c, c, c);
47 setrgbpalette(i + std_c + (1 * avail), c, 0, 0);
48 setrgbpalette(i + std_c + (2 * avail), 0, c, 0);
49 setrgbpalette(i + std_c + (3 * avail), 0, 0, c);
50 }
51 for (x = 2; x < xmax - 1; ++x) {
52 c = (((x-2)*avail) / (xmax-3)) + std_c;
53 for (i=0; i < 4; ++i) {
54 setcolor(c+(avail*i));
55 line( x, i*yw, x, (i+1)*yw);
56 }
57 }
58 break;
59 #ifdef __GNUC__
60 case 1 << 15:
61 case 1 << 16:
62 case 1 << 24:
63 for (x = 2; x < xmax - 1; ++x) {
64 c = ((x - 2) * 256) / (xmax - 3);
65 y = 0;
66 setrgbcolor(c, c, c);
67 line(x, y, x, y + yw - 1);
68 y += yw;
69 setrgbcolor(c, 0, 0);
70 line(x, y, x, y + yw - 1);
71 y += yw;
72 setrgbcolor(0, c, 0);
73 line(x, y, x, y + yw - 1);
74 y += yw;
75 setrgbcolor(0, 0, c);
76 line(x, y, x, y + yw - 1);
77 }
78 break;
79 #endif
80 default:
81 if (oldmode != mode)
82 setgraphmode(oldmode);
83 return;
84 }
85 {
86 char *mn = getmodename(mode);
87 setcolor(WHITE);
88 settextjustify( CENTER_TEXT, BOTTOM_TEXT );
89 outtextxy(getmaxx()/2, getmaxy(), mn);
90 }
91 getch();
92
93 if (oldmode != mode)
94 setgraphmode(oldmode);
95 }
96
main(void)97 int main(void)
98 {
99 int gd, gm;
100 int err;
101 int lomode, himode;
102
103 gd = DETECT;
104 #if defined(__MSDOS__) || defined(__WIN32__)
105 initgraph(&gd,&gm,"..\\..\\chr");
106 #else
107 initgraph(&gd,&gm,"../../chr");
108 #endif
109 err = graphresult();
110 if (err != grOk) {
111 fprintf(stderr, "Couldn't initialize graphics\n");
112 return 1;
113 }
114 getmoderange(gd, &lomode, &himode);
115 gm = lomode;
116 #ifdef __GNUC__
117 if (gm < __FIRST_DRIVER_SPECIFIC_MODE)
118 gm = __FIRST_DRIVER_SPECIFIC_MODE;
119 #endif
120 for ( ; gm <= himode; ++gm)
121 testmode(gm);
122 closegraph();
123 return 0;
124 }
125