ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/vga.c
Revision: 2.6
Committed: Fri Jun 4 14:49:08 1993 UTC (30 years, 11 months ago) by greg
Content type: text/plain
Branch: MAIN
Changes since 2.5: +2 -0 lines
Log Message:
added math.h for atof() usage

File Contents

# Content
1 /* Copyright (c) 1992 Regents of the University of California */
2
3 #ifndef lint
4 static char SCCSid[] = "$SunId$ LBL";
5 #endif
6
7 /*
8 * vga.c - driver for VGA graphics adaptor under MS-DOS
9 */
10
11 #include <stdio.h>
12
13 #include <math.h>
14
15 #include <graph.h>
16
17 #include "driver.h"
18
19 #include "color.h"
20
21 #define GAMMA 2.2 /* exponent for color correction */
22
23
24 int vga_close(), vga_clear(), vga_paintr(), vga_comout(), vga_errout(),
25 vga_comin();
26
27 static struct driver vga_driver = {
28 vga_close, vga_clear, vga_paintr, NULL,
29 vga_comout, vga_comin, NULL, 1.0
30 };
31
32 static char fatalerr[128];
33
34 static struct videoconfig config;
35
36 extern char *getenv();
37
38
39 struct driver *
40 vga_init(name, id) /* open VGA */
41 char *name, *id;
42 {
43 static short mode_pref[] = {_MRES256COLOR, -1};
44 static short smode_pref[] = {_XRES256COLOR, _SVRES256COLOR,
45 _VRES256COLOR, _MRES256COLOR, -1};
46 char *ep;
47 register short *mp;
48
49 mp = !strcmp(name, "vga") ? mode_pref : smode_pref;
50 for ( ; *mp != -1; mp++)
51 if (_setvideomode(*mp))
52 break;
53 if (*mp == -1) {
54 _setvideomode(_DEFAULTMODE);
55 stderr_v(name);
56 stderr_v(": card not present or insufficient VGA memory\n");
57 return(NULL);
58 }
59 _getvideoconfig(&config);
60 _settextwindow(config.numtextrows-2, 1,
61 config.numtextrows, config.numtextcols);
62 vga_driver.xsiz = config.numxpixels;
63 vga_driver.ysiz = (long)config.numypixels*(config.numtextrows-3)
64 /config.numtextrows;
65 switch (config.mode) { /* correct problems */
66 case _XRES256COLOR:
67 vga_driver.ysiz -= 16;
68 break;
69 case _MRES256COLOR:
70 vga_driver.pixaspect = 1.2;
71 break;
72 }
73 _setviewport(0, 0, vga_driver.xsiz, vga_driver.ysiz);
74 if ((ep = getenv("GAMMA")) != NULL) /* make gamma map */
75 make_gmap(atof(ep));
76 else
77 make_gmap(GAMMA);
78 _remappalette(1, _BRIGHTWHITE);
79 _settextcolor(1);
80 ms_gcinit(&vga_driver);
81 errvec = vga_errout;
82 cmdvec = vga_comout;
83 if (wrnvec != NULL)
84 wrnvec = vga_comout;
85 return(&vga_driver);
86 }
87
88
89 static
90 vga_close() /* close VGA */
91 {
92 ms_gcdone(&vga_driver);
93 _setvideomode(_DEFAULTMODE);
94 errvec = stderr_v; /* reset error vectors */
95 cmdvec = NULL;
96 if (wrnvec != NULL)
97 wrnvec = stderr_v;
98 if (fatalerr[0])
99 stderr_v(fatalerr); /* repeat error message */
100 }
101
102
103 static
104 vga_clear(x, y) /* clear VGA */
105 int x, y;
106 {
107 _clearscreen(_GCLEARSCREEN);
108 new_ctab(config.numcolors-2); /* init color table */
109 }
110
111
112 static
113 vga_paintr(col, xmin, ymin, xmax, ymax) /* paint a rectangle */
114 COLOR col;
115 int xmin, ymin, xmax, ymax;
116 {
117 extern int vgacolr();
118
119 _setcolor(get_pixel(col, vgacolr)+2);
120 _rectangle(_GFILLINTERIOR, xmin, vga_driver.ysiz-ymax,
121 xmax-1, vga_driver.ysiz-1-ymin);
122 vga_driver.inpready = kbhit();
123 }
124
125
126 static
127 vga_comout(s) /* put s to text output */
128 register char *s;
129 {
130 struct rccoord tpos;
131 char buf[128];
132 register char *cp;
133
134 for (cp = buf; ; s++) {
135 switch (*s) {
136 case '\b':
137 case '\r':
138 case '\0':
139 if (cp > buf) {
140 *cp = '\0';
141 _outtext(cp = buf);
142 }
143 if (*s == '\0')
144 break;
145 tpos = _gettextposition();
146 _settextposition(tpos.row, *s=='\r' ? 1 : tpos.col-1);
147 continue;
148 default:
149 *cp++ = *s;
150 continue;
151 }
152 return(0);
153 }
154 fatalerr[0] = '\0';
155 }
156
157
158 static
159 vga_errout(msg)
160 register char *msg;
161 {
162 static char *fep = fatalerr;
163
164 _outtext(msg);
165 while (*msg)
166 *fep++ = *msg++;
167 *fep = '\0';
168 if (fep > fatalerr && fep[-1] == '\n')
169 fep = fatalerr;
170 }
171
172
173 static
174 vga_comin(buf, prompt) /* get input line from console */
175 char *buf;
176 char *prompt;
177 {
178 extern int getch();
179
180 if (prompt != NULL)
181 _outtext(prompt);
182 editline(buf, getch, vga_comout);
183 vga_driver.inpready = kbhit();
184 }
185
186
187 static
188 vgacolr(index, r, g, b) /* enter a color into our table */
189 int index;
190 int r, g, b;
191 {
192 register long cl;
193
194 cl = (long)b<<14 & 0x3f0000L;
195 cl |= g<<6 & 0x3f00;
196 cl |= r>>2;
197 _remappalette(index+2, cl);
198 }