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