ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/rt/vga.c
Revision: 2.7
Committed: Tue Nov 11 20:03:01 1997 UTC (26 years, 5 months ago) by gregl
Content type: text/plain
Branch: MAIN
Changes since 2.6: +18 -14 lines
Log Message:
created erract structure containing error messages and actions

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