8 |
|
* vga.c - driver for VGA graphics adaptor under MS-DOS |
9 |
|
*/ |
10 |
|
|
11 |
< |
#include <stdio.h> |
11 |
> |
#include "standard.h" |
12 |
|
|
13 |
|
#include <graph.h> |
14 |
|
|
19 |
|
#define GAMMA 2.2 /* exponent for color correction */ |
20 |
|
|
21 |
|
|
22 |
< |
int vga_close(), vga_clear(), vga_paintr(), vga_comout(), vga_comin(); |
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 |
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 |
< |
if (_setvideomode(_MRES256COLOR) == 0) |
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 = config.numypixels*(config.numtextrows-3) |
61 |
> |
vga_driver.ysiz = (long)config.numypixels*(config.numtextrows-3) |
62 |
|
/config.numtextrows; |
63 |
< |
vga_driver.pixaspect = .75*config.numxpixels/config.numypixels; |
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 |
< |
make_gmap(GAMMA); /* make color map */ |
73 |
< |
_remappalette(1, 0x303030L); |
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 |
< |
errvec = vga_comout; |
79 |
< |
cmdvec = vga_comout; |
80 |
< |
if (wrnvec != NULL) |
81 |
< |
wrnvec = vga_comout; |
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 |
|
|
90 |
|
static |
91 |
|
vga_close() /* close VGA */ |
92 |
|
{ |
93 |
< |
errvec = stderr_v; /* reset error vector */ |
61 |
< |
cmdvec = NULL; |
62 |
< |
if (wrnvec != NULL) |
63 |
< |
wrnvec = stderr_v; |
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 |
|
|
147 |
|
if (*s == '\0') |
148 |
|
break; |
149 |
|
tpos = _gettextposition(); |
150 |
< |
_settextposition(tpos.row, *s=='\r' ? 0 : tpos.col-1); |
150 |
> |
_settextposition(tpos.row, *s=='\r' ? 1 : tpos.col-1); |
151 |
|
continue; |
152 |
|
default: |
153 |
|
*cp++ = *s; |
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 |
|
|