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 <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_comin(); |
23 |
|
24 |
static struct driver vga_driver = { |
25 |
vga_close, vga_clear, vga_paintr, NULL, |
26 |
vga_comout, vga_comin, NULL |
27 |
}; |
28 |
|
29 |
static struct videoconfig config; |
30 |
|
31 |
|
32 |
struct driver * |
33 |
vga_init(name, id) /* open VGA */ |
34 |
char *name, *id; |
35 |
{ |
36 |
if (_setvideomode(_MRES256COLOR) == 0) |
37 |
return(NULL); |
38 |
_getvideoconfig(&config); |
39 |
_settextwindow(config.numtextrows-2, 1, |
40 |
config.numtextrows, config.numtextcols); |
41 |
vga_driver.xsiz = config.numxpixels; |
42 |
vga_driver.ysiz = config.numypixels*(config.numtextrows-3) |
43 |
/config.numtextrows; |
44 |
vga_driver.pixaspect = .75*config.numxpixels/config.numypixels; |
45 |
_setviewport(0, 0, vga_driver.xsiz, vga_driver.ysiz); |
46 |
make_gmap(GAMMA); /* make color map */ |
47 |
_remappalette(1, 0x303030L); |
48 |
_settextcolor(1); |
49 |
errvec = vga_comout; |
50 |
cmdvec = vga_comout; |
51 |
if (wrnvec != NULL) |
52 |
wrnvec = vga_comout; |
53 |
return(&vga_driver); |
54 |
} |
55 |
|
56 |
|
57 |
static |
58 |
vga_close() /* close VGA */ |
59 |
{ |
60 |
errvec = stderr_v; /* reset error vector */ |
61 |
cmdvec = NULL; |
62 |
if (wrnvec != NULL) |
63 |
wrnvec = stderr_v; |
64 |
_setvideomode(_DEFAULTMODE); |
65 |
} |
66 |
|
67 |
|
68 |
static |
69 |
vga_clear(x, y) /* clear VGA */ |
70 |
int x, y; |
71 |
{ |
72 |
_clearscreen(_GCLEARSCREEN); |
73 |
new_ctab(config.numcolors-2); /* init color table */ |
74 |
} |
75 |
|
76 |
|
77 |
static |
78 |
vga_paintr(col, xmin, ymin, xmax, ymax) /* paint a rectangle */ |
79 |
COLOR col; |
80 |
int xmin, ymin, xmax, ymax; |
81 |
{ |
82 |
extern int vgacolr(); |
83 |
|
84 |
_setcolor(get_pixel(col, vgacolr)+2); |
85 |
_rectangle(_GFILLINTERIOR, xmin, vga_driver.ysiz-ymax, |
86 |
xmax-1, vga_driver.ysiz-1-ymin); |
87 |
vga_driver.inpready = kbhit(); |
88 |
} |
89 |
|
90 |
|
91 |
static |
92 |
vga_comout(s) /* put s to text output */ |
93 |
register char *s; |
94 |
{ |
95 |
struct rccoord tpos; |
96 |
char buf[128]; |
97 |
register char *cp; |
98 |
|
99 |
for (cp = buf; ; s++) { |
100 |
switch (*s) { |
101 |
case '\b': |
102 |
case '\r': |
103 |
case '\0': |
104 |
if (cp > buf) { |
105 |
*cp = '\0'; |
106 |
_outtext(cp = buf); |
107 |
} |
108 |
if (*s == '\0') |
109 |
break; |
110 |
tpos = _gettextposition(); |
111 |
_settextposition(tpos.row, *s=='\r' ? 0 : tpos.col-1); |
112 |
continue; |
113 |
default: |
114 |
*cp++ = *s; |
115 |
continue; |
116 |
} |
117 |
return(0); |
118 |
} |
119 |
} |
120 |
|
121 |
|
122 |
static |
123 |
vga_comin(buf, prompt) /* get input line from console */ |
124 |
char *buf; |
125 |
char *prompt; |
126 |
{ |
127 |
extern int getch(); |
128 |
|
129 |
if (prompt != NULL) |
130 |
_outtext(prompt); |
131 |
editline(buf, getch, vga_comout); |
132 |
vga_driver.inpready = kbhit(); |
133 |
} |
134 |
|
135 |
|
136 |
static |
137 |
vgacolr(index, r, g, b) /* enter a color into our table */ |
138 |
int index; |
139 |
int r, g, b; |
140 |
{ |
141 |
register long cl; |
142 |
|
143 |
cl = (long)b<<14 & 0x3f0000L; |
144 |
cl |= g<<6 & 0x3f00; |
145 |
cl |= r>>2; |
146 |
_remappalette(index+2, cl); |
147 |
} |