DOS updates from Daniel Borca.
[mesa.git] / src / mesa / drivers / dos / virtual.S
1 /*
2 * Mesa 3-D graphics library
3 * Version: 4.0
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 5.0
27 *
28 * Copyright (C) 2002 - Borca Daniel
29 * Email : dborca@yahoo.com
30 * Web : http://www.geocities.com/dborca
31 */
32
33
34 .file "virtual.S"
35
36 /*
37 * extern void *vl_current_draw_buffer;
38 * extern int vl_current_width, vl_current_bytes;
39 */
40
41 .text
42
43 /* Desc: void v_clear8 (int color);
44 *
45 * In : color
46 * Out : -
47 *
48 * Note: uses current draw buffer
49 */
50 .p2align 5,,31
51 .global _v_clear8
52 _v_clear8:
53 movl 4(%esp), %eax
54 movb %al, %ah
55 pushw %ax
56 pushw %ax
57 popl %eax
58 jmp _v_clear_common
59
60 /* Desc: void v_clear16 (int color);
61 *
62 * In : color
63 * Out : -
64 *
65 * Note: uses current draw buffer
66 */
67 .p2align 5,,31
68 .global _v_clear16
69 _v_clear16:
70 movl 4(%esp), %eax
71 pushw %ax
72 pushw %ax
73 popl %eax
74 jmp _v_clear_common
75
76 /* Desc: void v_clear32 (int color);
77 *
78 * In : color
79 * Out : -
80 *
81 * Note: uses current draw buffer
82 */
83 .p2align 5,,31
84 .global _v_clear32
85 _v_clear32:
86 movl 4(%esp), %eax
87 .balign 4
88 _v_clear_common:
89 movl _vl_current_bytes, %ecx
90 movl _vl_current_draw_buffer, %edx
91 shrl $2, %ecx
92 .balign 4
93 0:
94 movl %eax, (%edx)
95 addl $4, %edx
96 decl %ecx
97 jnz 0b
98 ret
99
100 /* Desc: void v_clear8_mmx (int color);
101 *
102 * In : color
103 * Out : -
104 *
105 * Note: uses current draw buffer
106 */
107 .p2align 5,,31
108 .global _v_clear8_mmx
109 _v_clear8_mmx:
110 movl 4(%esp), %eax
111 movb %al, %ah
112 pushw %ax
113 pushw %ax
114 pushw %ax
115 pushw %ax
116 jmp _v_clear_common_mmx
117
118 /* Desc: void v_clear16_mmx (int color);
119 *
120 * In : color
121 * Out : -
122 *
123 * Note: uses current draw buffer
124 */
125 .p2align 5,,31
126 .global _v_clear16_mmx
127 _v_clear16_mmx:
128 movl 4(%esp), %eax
129 pushw %ax
130 pushw %ax
131 pushw %ax
132 pushw %ax
133 jmp _v_clear_common_mmx
134
135 /* Desc: void v_clear32_mmx (int color);
136 *
137 * In : color
138 * Out : -
139 *
140 * Note: uses current draw buffer
141 */
142 .p2align 5,,31
143 .global _v_clear32_mmx
144 _v_clear32_mmx:
145 movl 4(%esp), %eax
146 pushl %eax
147 pushl %eax
148 .balign 4
149 _v_clear_common_mmx:
150 #ifdef USE_MMX_ASM
151 movl _vl_current_bytes, %ecx
152 movl _vl_current_draw_buffer, %edx
153 movq (%esp), %mm0
154 shrl $3, %ecx
155 .balign 4
156 0:
157 movq %mm0, (%edx)
158 addl $8, %edx
159 decl %ecx
160 jnz 0b
161 emms
162 #endif
163 addl $8, %esp
164 ret
165
166 /* Desc: void v_clear24 (int color);
167 *
168 * In : color
169 * Out : -
170 *
171 * Note: uses current draw buffer
172 */
173 .p2align 5,,31
174 .global _v_clear24
175 _v_clear24:
176 movl $0xaaaaaaab, %eax
177 mull _vl_current_bytes
178 movl 4(%esp), %eax
179 movl %edx, %ecx
180 pushl %ebx
181 movl _vl_current_draw_buffer, %edx
182 shrl %ecx
183 movb 10(%esp), %bl
184 .balign 4
185 0:
186 movw %ax, (%edx)
187 movb %bl, 2(%edx)
188 addl $3, %edx
189 decl %ecx
190 jnz 0b
191 popl %ebx
192 ret
193
194 /* Desc: void v_clear24_mmx (int color);
195 *
196 * In : color
197 * Out : -
198 *
199 * Note: uses current draw buffer
200 */
201 .p2align 5,,31
202 .global _v_clear24_mmx
203 _v_clear24_mmx:
204 #ifdef USE_MMX_ASM
205 movl 4(%esp), %eax
206 movl %eax, %edx
207 movl %eax, %ecx
208 shll $16, %edx
209 rorl $8, %ecx
210 movw %cx, %dx
211 rorl $16, %ecx
212 movb %dh, %cl
213 shll $8, %eax
214 movb %ch, %al
215 rorl $8, %eax
216
217 pushl %edx
218 pushl %eax
219 movq (%esp), %mm0
220 pushl %ecx
221 movq (%esp), %mm1
222 pushl %edx
223 movq (%esp), %mm2
224
225 movl $0xaaaaaaab, %eax
226 mull _vl_current_bytes
227 movl %edx, %ecx
228 movl _vl_current_draw_buffer, %edx
229 shrl $4, %ecx
230 .balign 4
231 0:
232 movq %mm0, (%edx)
233 movq %mm1, 8(%edx)
234 movq %mm2, 16(%edx)
235 addl $24, %edx
236 decl %ecx
237 jnz 0b
238 emms
239 addl $16, %esp
240 #endif
241 ret
242
243 /* Desc: void v_rect8 (int color);
244 *
245 * In : color
246 * Out : -
247 *
248 * Note: uses current draw buffer
249 */
250 .p2align 5,,31
251 .global _v_rect8
252 _v_rect8:
253 cld
254 pushl %esi
255 pushl %edi
256 movl 28(%esp), %eax
257 movl _vl_current_width, %esi
258 movl 16(%esp), %edi
259 movb %al, %ah
260 movl 20(%esp), %ecx
261 imull %esi, %edi
262 movl 24(%esp), %edx
263 subl %ecx, %esi
264 addl 12(%esp), %edi
265 pushw %ax
266 pushw %ax
267 pushl %ds
268 popl %es
269 addl _vl_current_draw_buffer, %edi
270 popl %eax
271 pushl %ebx
272 movl %ecx, %ebx
273 andl $3, %ebx
274 .balign 4
275 0:
276 pushl %ecx
277 .balign 4
278 1:
279 shrl $2, %ecx
280 rep; stosl
281 testl %ebx, %ebx
282 jz 2f
283 movl %ebx, %ecx
284 rep; stosb
285 .balign 4
286 2:
287 popl %ecx
288 addl %esi, %edi
289 decl %edx
290 jnz 0b
291 popl %ebx
292 popl %edi
293 popl %esi
294 ret
295
296 /* Desc: void v_rect16 (int color);
297 *
298 * In : color
299 * Out : -
300 *
301 * Note: uses current draw buffer
302 */
303 .p2align 5,,31
304 .global _v_rect16
305 _v_rect16:
306 cld
307 pushl %esi
308 pushl %edi
309 movl 28(%esp), %eax
310 movl _vl_current_width, %esi
311 movl 16(%esp), %edi
312 movl 20(%esp), %ecx
313 imull %esi, %edi
314 movl 24(%esp), %edx
315 subl %ecx, %esi
316 addl 12(%esp), %edi
317 pushw %ax
318 shll %esi
319 pushw %ax
320 shll %edi
321 pushl %ds
322 popl %es
323 addl _vl_current_draw_buffer, %edi
324 popl %eax
325 .balign 4
326 0:
327 pushl %ecx
328 .balign 4
329 1:
330 shrl %ecx
331 rep; stosl
332 jnc 2f
333 stosw
334 .balign 4
335 2:
336 popl %ecx
337 addl %esi, %edi
338 decl %edx
339 jnz 0b
340 popl %edi
341 popl %esi
342 ret
343
344 /* Desc: void v_rect24 (int color);
345 *
346 * In : color
347 * Out : -
348 *
349 * Note: uses current draw buffer
350 */
351 .p2align 5,,31
352 .global _v_rect24
353 _v_rect24:
354 pushl %esi
355 pushl %edi
356 movl 28(%esp), %eax
357 movl _vl_current_width, %esi
358 movl 16(%esp), %edi
359 movl 20(%esp), %ecx
360 imull %esi, %edi
361 movl 24(%esp), %edx
362 subl %ecx, %esi
363 addl 12(%esp), %edi
364 leal (%esi, %esi, 2), %esi
365 pushl %ebx
366 leal (%edi, %edi, 2), %edi
367 movl %eax, %ebx
368 addl _vl_current_draw_buffer, %edi
369 shrl $16, %ebx
370 .balign 4
371 0:
372 pushl %ecx
373 .balign 4
374 1:
375 movw %ax, (%edi)
376 movb %bl, 2(%edi)
377 addl $3, %edi
378 decl %ecx
379 jnz 1b
380 popl %ecx
381 addl %esi, %edi
382 decl %edx
383 jnz 0b
384 popl %ebx
385 popl %edi
386 popl %esi
387 ret
388
389 /* Desc: void v_rect32 (int color);
390 *
391 * In : color
392 * Out : -
393 *
394 * Note: uses current draw buffer
395 */
396 .p2align 5,,31
397 .global _v_rect32
398 _v_rect32:
399 pushl %esi
400 pushl %edi
401 movl _vl_current_width, %esi
402 movl 16(%esp), %edi
403 movl 20(%esp), %ecx
404 imull %esi, %edi
405 movl 24(%esp), %edx
406 subl %ecx, %esi
407 addl 12(%esp), %edi
408 shll $2, %esi
409 shll $2, %edi
410 movl 28(%esp), %eax
411 addl _vl_current_draw_buffer, %edi
412 .balign 4
413 0:
414 pushl %ecx
415 .balign 4
416 1:
417 movl %eax, (%edi)
418 addl $4, %edi
419 decl %ecx
420 jnz 1b
421 popl %ecx
422 addl %esi, %edi
423 decl %edx
424 jnz 0b
425 popl %edi
426 popl %esi
427 ret
428
429 /* Desc: void v_putpixel8 (unsigned int offset, int color);
430 *
431 * In : offset within buffer, color
432 * Out : -
433 *
434 * Note: uses current draw buffer
435 */
436 .p2align 5,,31
437 .global _v_putpixel8
438 _v_putpixel8:
439 movl 8(%esp), %ecx
440 movl 4(%esp), %edx
441 movl _vl_current_draw_buffer, %eax
442 movb %cl, (%eax,%edx)
443 ret
444
445 /* Desc: void v_putpixel16 (unsigned int offset, int color);
446 *
447 * In : offset within buffer, color
448 * Out : -
449 *
450 * Note: uses current draw buffer
451 */
452 .p2align 5,,31
453 .global _v_putpixel16
454 _v_putpixel16:
455 movl 8(%esp), %ecx
456 movl 4(%esp), %edx
457 movl _vl_current_draw_buffer, %eax
458 movw %cx, (%eax,%edx,2)
459 ret
460
461 /* Desc: void v_putpixel24 (unsigned int offset, int color);
462 *
463 * In : offset within buffer, color
464 * Out : -
465 *
466 * Note: uses current draw buffer
467 */
468 .p2align 5,,31
469 .global _v_putpixel24
470 _v_putpixel24:
471 movl 4(%esp), %eax
472 movl 8(%esp), %edx
473 movl _vl_current_draw_buffer, %ecx
474 leal (%eax,%eax,2), %eax
475 movw %dx, (%ecx,%eax)
476 shrl $16, %edx
477 movb %dl, 2(%ecx,%eax)
478 ret
479
480 /* Desc: void v_putpixel32 (unsigned int offset, int color);
481 *
482 * In : offset within buffer, color
483 * Out : -
484 *
485 * Note: uses current draw buffer
486 */
487 .p2align 5,,31
488 .global _v_putpixel32
489 _v_putpixel32:
490 movl 8(%esp), %ecx
491 movl 4(%esp), %edx
492 movl _vl_current_draw_buffer, %eax
493 movl %ecx, (%eax,%edx,4)
494 ret