DOS update (Daniel Borca)
[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.3 for Mesa
27 *
28 * Copyright (C) 2002 - Borca Daniel
29 * Email : dborca@yahoo.com
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 {0x13 | 0x4000, 320, 200, 320, 8, -1, 320*200},
44 {0xffff, -1, -1, -1, -1, -1, -1}
45 };
46
47 static word16 vga_ver;
48 static int linear_selector;
49 static int oldmode = -1;
50
51 #define vga_color_precision 6
52
53
54
55 /* Desc: Attempts to detect VGA, check video modes and create selectors.
56 *
57 * In : -
58 * Out : mode array
59 *
60 * Note: -
61 */
62 static vl_mode *vga_init (void)
63 {
64 int rv = 0;
65
66 if (vga_ver) {
67 return modes;
68 }
69
70 __asm("\n\
71 movw $0x1a00, %%ax \n\
72 int $0x10 \n\
73 cmpb $0x1a, %%al \n\
74 jne 0f \n\
75 cmpb $0x07, %%bl \n\
76 jb 0f \n\
77 andl $0xff, %%ebx \n\
78 movl %%ebx, %0 \n\
79 0:":"=g"(rv)::"%eax", "%ebx");
80 if (rv == 0) {
81 return NULL;
82 }
83
84 if (_create_selector(&linear_selector, 0xa0000, 0x10000)) {
85 return NULL;
86 }
87
88 modes[0].sel = linear_selector;
89
90 vga_ver = rv;
91 return modes;
92 }
93
94
95
96 /* Desc: Frees all resources allocated by VGA init code.
97 *
98 * In : -
99 * Out : -
100 *
101 * Note: -
102 */
103 static void vga_fini (void)
104 {
105 if (vga_ver) {
106 _remove_selector(&linear_selector);
107 }
108 }
109
110
111
112 /* Desc: Attempts to enter specified video mode.
113 *
114 * In : ptr to mode structure, refresh rate
115 * Out : 0 if success
116 *
117 * Note: -
118 */
119 static int vga_entermode (vl_mode *p, int refresh)
120 {
121 if (!(p->mode & 0x4000)) {
122 return -1;
123 }
124 VGA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
125
126 if (oldmode == -1) {
127 __asm("\n\
128 movb $0x0f, %%ah \n\
129 int $0x10 \n\
130 andl $0xff, %%eax \n\
131 movl %%eax, %0 \n\
132 ":"=g"(oldmode)::"%eax", "%ebx");
133 }
134
135 __asm("int $0x10"::"a"(p->mode&0xff));
136
137 return 0;
138
139 (void)refresh; /* silence compiler warning */
140 }
141
142
143
144 /* Desc: Restores to the mode prior to first call to vga_entermode.
145 *
146 * In : -
147 * Out : -
148 *
149 * Note: -
150 */
151 static void vga_restore (void)
152 {
153 if (oldmode != -1) {
154 __asm("int $0x10"::"a"(oldmode));
155 }
156 }
157
158
159
160 /* Desc: set one palette entry
161 *
162 * In : color index, R, G, B
163 * Out : -
164 *
165 * Note: uses integer values
166 */
167 static void vga_setCI_i (int index, int red, int green, int blue)
168 {
169 #if 0
170 __asm("\n\
171 movw $0x1010, %%ax \n\
172 movb %1, %%dh \n\
173 movb %2, %%ch \n\
174 int $0x10 \n\
175 "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");
176 #else
177 outportb(0x03C8, index);
178 outportb(0x03C9, red);
179 outportb(0x03C9, green);
180 outportb(0x03C9, blue);
181 #endif
182 }
183
184
185
186 /* Desc: set one palette entry
187 *
188 * In : color index, R, G, B
189 * Out : -
190 *
191 * Note: uses normalized values
192 */
193 static void vga_setCI_f (int index, float red, float green, float blue)
194 {
195 float max = (1 << vga_color_precision) - 1;
196
197 vga_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));
198 }
199
200
201
202 /* Desc: state retrieval
203 *
204 * In : parameter name, ptr to storage
205 * Out : 0 if request successfully processed
206 *
207 * Note: -
208 */
209 static int vga_get (int pname, int *params)
210 {
211 switch (pname) {
212 case VL_GET_CI_PREC:
213 params[0] = vga_color_precision;
214 break;
215 default:
216 return -1;
217 }
218 return 0;
219 }
220
221
222
223 /*
224 * the driver
225 */
226 vl_driver VGA = {
227 vga_init,
228 vga_entermode,
229 NULL,
230 vga_setCI_f,
231 vga_setCI_i,
232 vga_get,
233 vga_restore,
234 vga_fini
235 };