Adjust mga drivers to remove redundant h file for sarea and IOCTLs
[mesa.git] / src / mesa / drivers / dos / vga.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 4.1
4 *
5 * Copyright (C) 1999 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /*
26 * DOS/DJGPP device driver v1.6 for Mesa
27 *
28 * Copyright (C) 2002 - Borca Daniel
29 * Email : dborca@users.sourceforge.net
30 * Web : http://www.geocities.com/dborca
31 */
32
33
34 #include <pc.h>
35 #include <stdlib.h>
36
37 #include "video.h"
38 #include "vga.h"
39
40
41
42 static vl_mode modes[] = {
43 {
44 /* .xres = */ 320,
45 /* .yres = */ 200,
46 /* .bpp = */ 8,
47 /* .mode = */ 0x13 | 0x4000,
48 /* .scanlen = */ 320,
49 /* .sel = */ -1,
50 /* .gran = */ 320*200
51 },
52 {
53 /* .xres = */ -1,
54 /* .yres = */ -1,
55 /* .bpp = */ -1,
56 /* .mode = */ 0xffff,
57 /* .scanlen = */ -1,
58 /* .sel = */ -1,
59 /* .gran = */ -1
60 }
61 };
62
63 static word16 vga_ver;
64 static int linear_selector;
65 static int oldmode = -1;
66
67 #define vga_color_precision 6
68
69
70
71 /* Desc: Attempts to detect VGA, check video modes and create selectors.
72 *
73 * In : -
74 * Out : mode array
75 *
76 * Note: -
77 */
78 static vl_mode *vga_init (void)
79 {
80 int rv = 0;
81
82 if (vga_ver) {
83 return modes;
84 }
85
86 __asm("\n\
87 movw $0x1a00, %%ax \n\
88 int $0x10 \n\
89 cmpb $0x1a, %%al \n\
90 jne 0f \n\
91 cmpb $0x07, %%bl \n\
92 jb 0f \n\
93 andl $0xff, %%ebx \n\
94 movl %%ebx, %0 \n\
95 0:":"=g"(rv)::"%eax", "%ebx");
96 if (rv == 0) {
97 return NULL;
98 }
99
100 if (_create_selector(&linear_selector, 0xa0000, 0x10000)) {
101 return NULL;
102 }
103
104 modes[0].sel = linear_selector;
105
106 vga_ver = rv;
107 return modes;
108 }
109
110
111
112 /* Desc: Frees all resources allocated by VGA init code.
113 *
114 * In : -
115 * Out : -
116 *
117 * Note: -
118 */
119 static void vga_fini (void)
120 {
121 if (vga_ver) {
122 _remove_selector(&linear_selector);
123 }
124 }
125
126
127
128 /* Desc: Attempts to enter specified video mode.
129 *
130 * In : ptr to mode structure, refresh rate
131 * Out : 0 if success
132 *
133 * Note: -
134 */
135 static int vga_entermode (vl_mode *p, int refresh)
136 {
137 if (!(p->mode & 0x4000)) {
138 return -1;
139 }
140 VGA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
141
142 if (oldmode == -1) {
143 __asm("\n\
144 movb $0x0f, %%ah \n\
145 int $0x10 \n\
146 andl $0xff, %%eax \n\
147 movl %%eax, %0 \n\
148 ":"=g"(oldmode)::"%eax", "%ebx");
149 }
150
151 __asm("int $0x10"::"a"(p->mode&0xff));
152
153 return 0;
154
155 (void)refresh; /* silence compiler warning */
156 }
157
158
159
160 /* Desc: Restores to the mode prior to first call to vga_entermode.
161 *
162 * In : -
163 * Out : -
164 *
165 * Note: -
166 */
167 static void vga_restore (void)
168 {
169 if (oldmode != -1) {
170 __asm("int $0x10"::"a"(oldmode));
171 oldmode = -1;
172 }
173 }
174
175
176
177 /* Desc: set one palette entry
178 *
179 * In : color index, R, G, B
180 * Out : -
181 *
182 * Note: uses integer values
183 */
184 static void vga_setCI_i (int index, int red, int green, int blue)
185 {
186 #if 0
187 __asm("\n\
188 movw $0x1010, %%ax \n\
189 movb %1, %%dh \n\
190 movb %2, %%ch \n\
191 int $0x10 \n\
192 "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");
193 #else
194 outportb(0x03C8, index);
195 outportb(0x03C9, red);
196 outportb(0x03C9, green);
197 outportb(0x03C9, blue);
198 #endif
199 }
200
201
202
203 /* Desc: set one palette entry
204 *
205 * In : color index, R, G, B
206 * Out : -
207 *
208 * Note: uses normalized values
209 */
210 static void vga_setCI_f (int index, float red, float green, float blue)
211 {
212 float max = (1 << vga_color_precision) - 1;
213
214 vga_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));
215 }
216
217
218
219 /* Desc: state retrieval
220 *
221 * In : parameter name, ptr to storage
222 * Out : 0 if request successfully processed
223 *
224 * Note: -
225 */
226 static int vga_get (int pname, int *params)
227 {
228 switch (pname) {
229 case VL_GET_CI_PREC:
230 params[0] = vga_color_precision;
231 break;
232 default:
233 return -1;
234 }
235 return 0;
236 }
237
238
239
240 /*
241 * the driver
242 */
243 vl_driver VGA = {
244 vga_init,
245 vga_entermode,
246 NULL,
247 vga_setCI_f,
248 vga_setCI_i,
249 vga_get,
250 vga_restore,
251 vga_fini
252 };