diff options
Diffstat (limited to 'src/mesa/drivers')
-rw-r--r-- | src/mesa/drivers/dos/blit.S | 398 | ||||
-rw-r--r-- | src/mesa/drivers/dos/dmesa.c | 3421 | ||||
-rw-r--r-- | src/mesa/drivers/dos/dpmi.c | 296 | ||||
-rw-r--r-- | src/mesa/drivers/dos/internal.h | 258 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/m_ttemp.h | 754 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/m_ttemp2.h | 750 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/mga.c | 3072 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/mga.h | 182 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/mga_hw.c | 832 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/mga_hw.h | 226 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/mga_mode.c | 462 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/mga_mode.h | 94 | ||||
-rw-r--r-- | src/mesa/drivers/dos/mga/mga_reg.h | 414 | ||||
-rw-r--r-- | src/mesa/drivers/dos/vesa.c | 1066 | ||||
-rw-r--r-- | src/mesa/drivers/dos/vesa.h | 94 | ||||
-rw-r--r-- | src/mesa/drivers/dos/vga.c | 470 | ||||
-rw-r--r-- | src/mesa/drivers/dos/vga.h | 84 | ||||
-rw-r--r-- | src/mesa/drivers/dos/video.c | 1050 | ||||
-rw-r--r-- | src/mesa/drivers/dos/video.h | 128 | ||||
-rw-r--r-- | src/mesa/drivers/dos/virtual.S | 978 |
20 files changed, 7540 insertions, 7489 deletions
diff --git a/src/mesa/drivers/dos/blit.S b/src/mesa/drivers/dos/blit.S index 7d0da5da289..f5888c7e395 100644 --- a/src/mesa/drivers/dos/blit.S +++ b/src/mesa/drivers/dos/blit.S @@ -1,199 +1,199 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
- .file "blit.S"
-
-/*
- * extern unsigned int vesa_gran_mask, vesa_gran_shift;
- * extern int vl_video_selector;
-
- * extern void *vl_current_draw_buffer;
- * extern int vl_current_stride, vl_current_height;
- * extern int vl_current_offset, vl_current_delta;
- */
-
- .text
-
-/* Desc: VESA bank switching routine (BIOS)
- *
- * In : EBX=0, EDX = bank number
- * Out : -
- *
- * Note: thrashes EAX
- */
- .p2align 5,,31
-_vesa_swbankBIOS:
- movw $0x4f05, %ax
- int $0x10
- ret
-
- .p2align 2,,3
- .global _vesa_swbank
-_vesa_swbank: .long _vesa_swbankBIOS
-
-/* Desc: void vesa_b_dump_virtual (void);
- *
- * In : -
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _vesa_b_dump_virtual
-_vesa_b_dump_virtual:
- cld
- pushl %es
- pushl %ebx
- pushl %esi
- pushl %edi
- pushl %ebp
- movl _vl_video_selector, %es
- movl _vl_current_draw_buffer, %esi
- movl _vl_current_offset, %edi
- movl _vesa_gran_shift, %ecx
- movl _vesa_gran_mask, %ebp
- movl %edi, %edx
- xorl %ebx, %ebx
- andl %ebp, %edi
- shrl %cl, %edx
- incl %ebp
- call *_vesa_swbank
- movl _vl_current_stride, %ecx
- movl _vl_current_height, %eax
- movl _vl_current_delta, %ebx
- shrl $2, %ecx
- .balign 4
- 0:
- pushl %ecx
- .balign 4
- 1:
- cmpl %ebp, %edi
- jb 2f
- pushl %eax
- pushl %ebx
- incl %edx
- xorl %ebx, %ebx
- call *_vesa_swbank
- popl %ebx
- popl %eax
- subl %ebp, %edi
- .balign 4
- 2:
- movsl
- decl %ecx
- jnz 1b
- popl %ecx
- addl %ebx, %edi
- decl %eax
- jnz 0b
- popl %ebp
- popl %edi
- popl %esi
- popl %ebx
- popl %es
- ret
-
-/* Desc: void vesa_l_dump_virtual (void);
- *
- * In : -
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _vesa_l_dump_virtual
-_vesa_l_dump_virtual:
- cld
- pushl %es
- pushl %esi
- pushl %edi
- movl _vl_video_selector, %es
- movl _vl_current_draw_buffer, %esi
- movl _vl_current_offset, %edi
- movl _vl_current_stride, %ecx
- movl _vl_current_height, %edx
- movl _vl_current_delta, %eax
- shrl $2, %ecx
- .balign 4
- 0:
- pushl %ecx
- rep; movsl
- popl %ecx
- addl %eax, %edi
- decl %edx
- jnz 0b
- popl %edi
- popl %esi
- popl %es
- ret
-
-/* Desc: void vesa_l_dump_virtual_mmx (void);
- *
- * In : -
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _vesa_l_dump_virtual_mmx
-_vesa_l_dump_virtual_mmx:
-#ifdef USE_MMX_ASM
- pushl %esi
- pushl %edi
- movl _vl_video_selector, %fs
- movl _vl_current_draw_buffer, %esi
- movl _vl_current_offset, %edi
- movl _vl_current_stride, %ecx
- movl _vl_current_height, %edx
- movl _vl_current_delta, %eax
- shrl $3, %ecx
- .balign 4
- 0:
- pushl %ecx
- .balign 4
- 1:
- movq (%esi), %mm0
- addl $8, %esi
- movq %mm0, %fs:(%edi)
- addl $8, %edi
- decl %ecx
- jnz 1b
- popl %ecx
- addl %eax, %edi
- decl %edx
- jnz 0b
- popl %edi
- popl %esi
- emms
-#endif
- ret
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + + .file "blit.S" + +/* + * extern unsigned int vesa_gran_mask, vesa_gran_shift; + * extern int vl_video_selector; + + * extern void *vl_current_draw_buffer; + * extern int vl_current_stride, vl_current_height; + * extern int vl_current_offset, vl_current_delta; + */ + + .text + +/* Desc: VESA bank switching routine (BIOS) + * + * In : EBX=0, EDX = bank number + * Out : - + * + * Note: thrashes EAX + */ + .p2align 5,,31 +_vesa_swbankBIOS: + movw $0x4f05, %ax + int $0x10 + ret + + .p2align 2,,3 + .global _vesa_swbank +_vesa_swbank: .long _vesa_swbankBIOS + +/* Desc: void vesa_b_dump_virtual (void); + * + * In : - + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _vesa_b_dump_virtual +_vesa_b_dump_virtual: + cld + pushl %es + pushl %ebx + pushl %esi + pushl %edi + pushl %ebp + movl _vl_video_selector, %es + movl _vl_current_draw_buffer, %esi + movl _vl_current_offset, %edi + movl _vesa_gran_shift, %ecx + movl _vesa_gran_mask, %ebp + movl %edi, %edx + xorl %ebx, %ebx + andl %ebp, %edi + shrl %cl, %edx + incl %ebp + call *_vesa_swbank + movl _vl_current_stride, %ecx + movl _vl_current_height, %eax + movl _vl_current_delta, %ebx + shrl $2, %ecx + .balign 4 + 0: + pushl %ecx + .balign 4 + 1: + cmpl %ebp, %edi + jb 2f + pushl %eax + pushl %ebx + incl %edx + xorl %ebx, %ebx + call *_vesa_swbank + popl %ebx + popl %eax + subl %ebp, %edi + .balign 4 + 2: + movsl + decl %ecx + jnz 1b + popl %ecx + addl %ebx, %edi + decl %eax + jnz 0b + popl %ebp + popl %edi + popl %esi + popl %ebx + popl %es + ret + +/* Desc: void vesa_l_dump_virtual (void); + * + * In : - + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _vesa_l_dump_virtual +_vesa_l_dump_virtual: + cld + pushl %es + pushl %esi + pushl %edi + movl _vl_video_selector, %es + movl _vl_current_draw_buffer, %esi + movl _vl_current_offset, %edi + movl _vl_current_stride, %ecx + movl _vl_current_height, %edx + movl _vl_current_delta, %eax + shrl $2, %ecx + .balign 4 + 0: + pushl %ecx + rep; movsl + popl %ecx + addl %eax, %edi + decl %edx + jnz 0b + popl %edi + popl %esi + popl %es + ret + +/* Desc: void vesa_l_dump_virtual_mmx (void); + * + * In : - + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _vesa_l_dump_virtual_mmx +_vesa_l_dump_virtual_mmx: +#ifdef USE_MMX_ASM + pushl %esi + pushl %edi + movl _vl_video_selector, %fs + movl _vl_current_draw_buffer, %esi + movl _vl_current_offset, %edi + movl _vl_current_stride, %ecx + movl _vl_current_height, %edx + movl _vl_current_delta, %eax + shrl $3, %ecx + .balign 4 + 0: + pushl %ecx + .balign 4 + 1: + movq (%esi), %mm0 + addl $8, %esi + movq %mm0, %fs:(%edi) + addl $8, %edi + decl %ecx + jnz 1b + popl %ecx + addl %eax, %edi + decl %edx + jnz 0b + popl %edi + popl %esi + emms +#endif + ret diff --git a/src/mesa/drivers/dos/dmesa.c b/src/mesa/drivers/dos/dmesa.c index a389e3d3397..9ec0036176a 100644 --- a/src/mesa/drivers/dos/dmesa.c +++ b/src/mesa/drivers/dos/dmesa.c @@ -1,1685 +1,1736 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0.1
- *
- * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef FX
-#include "glheader.h"
-#include "context.h"
-#include "extensions.h"
-#include "macros.h"
-#include "matrix.h"
-#include "mmath.h"
-#include "texformat.h"
-#include "texstore.h"
-#include "array_cache/acache.h"
-#include "swrast/s_context.h"
-#include "swrast/s_depth.h"
-#include "swrast/s_lines.h"
-#include "swrast/s_triangle.h"
-#include "swrast/s_trispan.h"
-#include "swrast/swrast.h"
-#include "swrast_setup/swrast_setup.h"
-#include "tnl/tnl.h"
-#include "tnl/t_context.h"
-#include "tnl/t_pipeline.h"
-#ifndef MATROX
-#include "video.h"
-#else /* MATROX */
-#include "mga/mga.h"
-#endif /* MATROX */
-#else /* FX */
-#include "../FX/fxdrv.h"
-#endif /* FX */
-
-#include "GL/dmesa.h"
-
-
-
-/*
- * In C++ terms, this class derives from the GLvisual class.
- * Add system-specific fields to it.
- */
-struct dmesa_visual {
- GLvisual gl_visual;
- GLboolean db_flag; /* double buffered? */
- GLboolean rgb_flag; /* RGB mode? */
- GLuint depth; /* bits per pixel (1, 8, 24, etc) */
-#ifdef MATROX
- int stride_in_pixels;
-#endif
- int zbuffer; /* Z=buffer: 0=no, 1=SW, -1=HW */
-};
-
-/*
- * In C++ terms, this class derives from the GLframebuffer class.
- * Add system-specific fields to it.
- */
-struct dmesa_buffer {
- GLframebuffer gl_buffer; /* The depth, stencil, accum, etc buffers */
- void *the_window; /* your window handle, etc */
-
- int xpos, ypos; /* position */
- int width, height; /* size in pixels */
-};
-
-/*
- * In C++ terms, this class derives from the GLcontext class.
- * Add system-specific fields to it.
- */
-struct dmesa_context {
- GLcontext gl_ctx; /* the core library context */
- DMesaVisual visual;
- DMesaBuffer Buffer;
- GLuint ClearColor;
- GLuint ClearIndex;
- /* etc... */
-};
-
-
-
-#ifndef FX
-/****************************************************************************
- * Read/Write pixels
- ***************************************************************************/
-#define FLIP(y) (dmesa->Buffer->height - (y) - 1)
-#define FLIP2(y) (_b_ - (y))
-
-
-#ifndef MATROX
-#define DSTRIDE dmesa->Buffer->width
-#else
-#define DSTRIDE dmesa->visual->stride_in_pixels
-#define vl_putpixel mga_putpixel
-#define vl_mixrgba mga_mixrgb
-#define vl_mixrgb mga_mixrgb
-#define vl_getrgba mga_getrgba
-#define vl_setz mga_setz
-#define vl_getz mga_getz
-#endif
-
-/****************************************************************************
- * RGB[A]
- ***************************************************************************/
-static void write_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
- const GLubyte rgba[][4], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
-#ifndef MATROX
- offset = DSTRIDE * FLIP(y) + x;
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++, offset++) {
- if (mask[i]) {
- vl_putpixel(offset, vl_mixrgba(rgba[i]));
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++, offset++) {
- vl_putpixel(offset, vl_mixrgba(rgba[i]));
- }
- }
-#else /* MATROX */
- y = FLIP(y);
- if (mask) {
- /* draw some pixels */
- offset = 0;
- for (i = 0; i < n; i++) {
- if (mask[i]) {
- ++offset;
- } else {
- if (offset != 0) {
- mga_draw_span_rgb_tx32(x + i - offset, y, offset, (const unsigned long *)(&rgba[i-offset]));
- offset = 0;
- }
- }
- }
- if (offset != 0) {
- mga_draw_span_rgb_tx32(x + n - offset, y, offset, (const unsigned long *)(&rgba[n-offset]));
- }
- } else {
- /* draw all pixels */
- mga_draw_span_rgb_tx32(x, y, n, (const unsigned long *)rgba);
- }
-#endif /* MATROX */
-}
-
-
-
-static void write_rgb_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
- const GLubyte rgb[][3], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++, offset++) {
- if (mask[i]) {
- vl_putpixel(offset, vl_mixrgb(rgb[i]));
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++, offset++) {
- vl_putpixel(offset, vl_mixrgb(rgb[i]));
- }
- }
-}
-
-
-
-static void write_mono_rgba_span (const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- const GLchan color[4], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset, rgba = vl_mixrgba(color);
-
- offset = DSTRIDE * FLIP(y) + x;
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++, offset++) {
- if (mask[i]) {
- vl_putpixel(offset, rgba);
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++, offset++) {
- vl_putpixel(offset, rgba);
- }
- }
-}
-
-
-
-static void read_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
- GLubyte rgba[][4])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- /* read all pixels */
- for (i=0; i<n; i++, offset++) {
- vl_getrgba(offset, rgba[i]);
- }
-}
-
-
-
-static void write_rgba_pixels (const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- const GLubyte rgba[][4], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
-
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++) {
- if (mask[i]) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i]));
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i]));
- }
- }
-}
-
-
-
-static void write_mono_rgba_pixels (const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- const GLchan color[4], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1, rgba = vl_mixrgba(color);
-
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++) {
- if (mask[i]) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba);
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba);
- }
- }
-}
-
-
-
-static void read_rgba_pixels (const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- GLubyte rgba[][4], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
-
- if (mask) {
- /* read some pixels */
- for (i=0; i<n; i++) {
- if (mask[i]) {
- vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]);
- }
- }
- } else {
- /* read all pixels */
- for (i=0; i<n; i++) {
- vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]);
- }
- }
-}
-
-
-
-/****************************************************************************
- * Index
- ***************************************************************************/
-#ifndef MATROX
-static void write_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
- const GLuint index[], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++, offset++) {
- if (mask[i]) {
- vl_putpixel(offset, index[i]);
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++, offset++) {
- vl_putpixel(offset, index[i]);
- }
- }
-}
-
-
-
-static void write_index8_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
- const GLubyte index[], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++, offset++) {
- if (mask[i]) {
- vl_putpixel(offset, index[i]);
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++, offset++) {
- vl_putpixel(offset, index[i]);
- }
- }
-}
-
-
-
-static void write_mono_index_span (const GLcontext *ctx,
- GLuint n, GLint x, GLint y,
- GLuint colorIndex, const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++, offset++) {
- if (mask[i]) {
- vl_putpixel(offset, colorIndex);
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++, offset++) {
- vl_putpixel(offset, colorIndex);
- }
- }
-}
-
-
-
-static void read_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
- GLuint index[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- /* read all pixels */
- for (i=0; i<n; i++, offset++) {
- index[i] = vl_getpixel(offset);
- }
-}
-
-
-
-static void write_index_pixels (const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- const GLuint index[], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
-
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++) {
- if (mask[i]) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]);
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]);
- }
- }
-}
-
-
-
-static void write_mono_index_pixels (const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- GLuint colorIndex, const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
-
- if (mask) {
- /* draw some pixels */
- for (i=0; i<n; i++) {
- if (mask[i]) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex);
- }
- }
- } else {
- /* draw all pixels */
- for (i=0; i<n; i++) {
- vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex);
- }
- }
-}
-
-
-
-static void read_index_pixels (const GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- GLuint index[], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
-
- if (mask) {
- /* read some pixels */
- for (i=0; i<n; i++) {
- if (mask[i]) {
- index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]);
- }
- }
- } else {
- /* read all pixels */
- for (i=0; i<n; i++) {
- index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]);
- }
- }
-}
-#endif /* !MATROX */
-
-
-
-/****************************************************************************
- * Z-buffer
- ***************************************************************************/
-#ifdef MATROX
-static void write_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y,
- const GLdepth depth[], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- if (mask) {
- /* draw some values */
- for (i=0; i<n; i++, offset++) {
- if (mask[i]) {
- vl_setz(offset, depth[i]);
- }
- }
- } else {
- /* draw all values */
- for (i=0; i<n; i++, offset++) {
- vl_setz(offset, depth[i]);
- }
- }
-}
-
-
-
-static void read_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y,
- GLdepth depth[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, offset;
-
- offset = DSTRIDE * FLIP(y) + x;
- /* read all values */
- for (i=0; i<n; i++, offset++) {
- depth[i] = vl_getz(offset);
- }
-}
-
-
-
-static void write_depth_pixels (GLcontext *ctx, GLuint n,
- const GLint x[], const GLint y[],
- const GLdepth depth[], const GLubyte mask[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
-
- if (mask) {
- /* draw some values */
- for (i=0; i<n; i++) {
- if (mask[i]) {
- vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]);
- }
- }
- } else {
- /* draw all values */
- for (i=0; i<n; i++) {
- vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]);
- }
- }
-}
-
-
-
-static void read_depth_pixels (GLcontext *ctx, GLuint n,
- const GLint x[], const GLint y[],
- GLdepth depth[])
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
-
- /* read all values */
- for (i=0; i<n; i++) {
- depth[i] = vl_getz(FLIP2(y[i])*_w_ + x[i]);
- }
-}
-#endif /* MATROX */
-
-
-
-/****************************************************************************
- * Optimized triangle rendering
- ***************************************************************************/
-
-/*
- * NON-depth-buffered flat triangle.
- */
-static void tri_rgb_flat (GLcontext *ctx,
- const SWvertex *v0,
- const SWvertex *v1,
- const SWvertex *v2)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
-#ifndef MATROX
- GLuint _w_ = dmesa->Buffer->width;
-
-#define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
-
-#define RENDER_SPAN(span) \
- GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
- for (i = 0; i < span.end; i++, offset++) { \
- vl_putpixel(offset, rgb); \
- }
-
-#include "swrast/s_tritemp.h"
-#else /* MATROX */
- MGAvertex m0, m1, m2;
- m0.win[0] = v0->win[0];
- m0.win[1] = FLIP2(v0->win[1]);
- m1.win[0] = v1->win[0];
- m1.win[1] = FLIP2(v1->win[1]);
- m2.win[0] = v2->win[0];
- m2.win[1] = FLIP2(v2->win[1]);
- *(unsigned long *)m2.color = *(unsigned long *)v2->color;
- mga_draw_tri_rgb_flat((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
-#endif /* MATROX */
-}
-
-
-
-/*
- * Z-less flat triangle.
- */
-static void tri_rgb_flat_zless (GLcontext *ctx,
- const SWvertex *v0,
- const SWvertex *v1,
- const SWvertex *v2)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
-#ifndef MATROX
- GLuint _w_ = dmesa->Buffer->width;
-
-#define INTERP_Z 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
-#define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);
-
-#define RENDER_SPAN(span) \
- GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
- for (i = 0; i < span.end; i++, offset++) { \
- const DEPTH_TYPE z = FixedToDepth(span.z); \
- if (z < zRow[i]) { \
- vl_putpixel(offset, rgb); \
- zRow[i] = z; \
- } \
- span.z += span.zStep; \
- }
-
-#include "swrast/s_tritemp.h"
-#else /* MATROX */
- MGAvertex m0, m1, m2;
- m0.win[0] = v0->win[0];
- m0.win[1] = FLIP2(v0->win[1]);
- m0.win[2] = v0->win[2];
- m1.win[0] = v1->win[0];
- m1.win[1] = FLIP2(v1->win[1]);
- m1.win[2] = v1->win[2];
- m2.win[0] = v2->win[0];
- m2.win[1] = FLIP2(v2->win[1]);
- m2.win[2] = v2->win[2];
- *(unsigned long *)m2.color = *(unsigned long *)v2->color;
- mga_draw_tri_rgb_flat_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
-#endif /* MATROX */
-}
-
-
-
-/*
- * NON-depth-buffered iterated triangle.
- */
-static void tri_rgb_iter (GLcontext *ctx,
- const SWvertex *v0,
- const SWvertex *v1,
- const SWvertex *v2)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
-#ifndef MATROX
- GLuint _w_ = dmesa->Buffer->width;
-
-#define INTERP_RGB 1
-#define RENDER_SPAN(span) \
- GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
- for (i = 0; i < span.end; i++, offset++) { \
- vl_putpixel(offset, vl_mixfix(span.red, span.green, span.blue)); \
- span.red += span.redStep; \
- span.green += span.greenStep; \
- span.blue += span.blueStep; \
- }
-
-#include "swrast/s_tritemp.h"
-#else /* MATROX */
- MGAvertex m0, m1, m2;
- m0.win[0] = v0->win[0];
- m0.win[1] = FLIP2(v0->win[1]);
- m1.win[0] = v1->win[0];
- m1.win[1] = FLIP2(v1->win[1]);
- m2.win[0] = v2->win[0];
- m2.win[1] = FLIP2(v2->win[1]);
- *(unsigned long *)m0.color = *(unsigned long *)v0->color;
- *(unsigned long *)m1.color = *(unsigned long *)v1->color;
- *(unsigned long *)m2.color = *(unsigned long *)v2->color;
- mga_draw_tri_rgb_iter((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
-#endif /* MATROX */
-}
-
-
-
-/*
- * Z-less iterated triangle.
- */
-static void tri_rgb_iter_zless (GLcontext *ctx,
- const SWvertex *v0,
- const SWvertex *v1,
- const SWvertex *v2)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
-#ifndef MATROX
- GLuint _w_ = dmesa->Buffer->width;
-
-#define INTERP_Z 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
-#define INTERP_RGB 1
-
-#define RENDER_SPAN(span) \
- GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
- for (i = 0; i < span.end; i++, offset++) { \
- const DEPTH_TYPE z = FixedToDepth(span.z); \
- if (z < zRow[i]) { \
- vl_putpixel(offset, vl_mixfix(span.red, span.green, span.blue));\
- zRow[i] = z; \
- } \
- span.red += span.redStep; \
- span.green += span.greenStep; \
- span.blue += span.blueStep; \
- span.z += span.zStep; \
- }
-
-#include "swrast/s_tritemp.h"
-#else /* MATROX */
- MGAvertex m0, m1, m2;
- m0.win[0] = v0->win[0];
- m0.win[1] = FLIP2(v0->win[1]);
- m0.win[2] = v0->win[2];
- m1.win[0] = v1->win[0];
- m1.win[1] = FLIP2(v1->win[1]);
- m1.win[2] = v1->win[2];
- m2.win[0] = v2->win[0];
- m2.win[1] = FLIP2(v2->win[1]);
- m2.win[2] = v2->win[2];
- *(unsigned long *)m0.color = *(unsigned long *)v0->color;
- *(unsigned long *)m1.color = *(unsigned long *)v1->color;
- *(unsigned long *)m2.color = *(unsigned long *)v2->color;
- mga_draw_tri_rgb_iter_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
-#endif /* MATROX */
-}
-
-
-
-/*
- * Analyze context state to see if we can provide a fast triangle function
- * Otherwise, return NULL.
- */
-static swrast_tri_func dmesa_choose_tri_function (GLcontext *ctx)
-{
- const SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- if ((ctx->RenderMode != GL_RENDER)
- || (ctx->Polygon.SmoothFlag)
- || (ctx->Polygon.StippleFlag)
- || (ctx->Texture._EnabledUnits)
- || (swrast->_RasterMask & MULTI_DRAW_BIT)
- || (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)) {
- return (swrast_tri_func)NULL;
- }
-
- if (swrast->_RasterMask==DEPTH_BIT
- && ctx->Depth.Func==GL_LESS
- && ctx->Depth.Mask==GL_TRUE
- && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {
- return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter_zless : tri_rgb_flat_zless;
- }
-
- if (swrast->_RasterMask==0) { /* no depth test */
- return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter : tri_rgb_flat;
- }
-
- return (swrast_tri_func)NULL;
-}
-
-
-
-/* Override for the swrast triangle-selection function. Try to use one
- * of our internal triangle functions, otherwise fall back to the
- * standard swrast functions.
- */
-static void dmesa_choose_tri (GLcontext *ctx)
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- if (!(swrast->Triangle=dmesa_choose_tri_function(ctx)))
- _swrast_choose_triangle(ctx);
-}
-
-
-
-/****************************************************************************
- * Optimized line rendering
- ***************************************************************************/
-
-#ifdef MATROX
-static __inline void matrox_line_clip_hack (GLcontext *ctx, int _b_, MGAvertex *m0, const SWvertex *vert0, MGAvertex *m1, const SWvertex *vert1)
-{
- int x0 = vert0->win[0];
- int y0 = vert0->win[1];
- int x1 = vert1->win[0];
- int y1 = vert1->win[1];
- /* s_linetemp.h { */
- GLint w = ctx->DrawBuffer->Width;
- GLint h = ctx->DrawBuffer->Height;
- if ((x0==w) | (x1==w)) {
- if ((x0==w) & (x1==w))
- return;
- x0 -= x0==w;
- x1 -= x1==w;
- }
- if ((y0==h) | (y1==h)) {
- if ((y0==h) & (y1==h))
- return;
- y0 -= y0==h;
- y1 -= y1==h;
- }
- /* } s_linetemp.h */
- m0->win[0] = x0;
- m0->win[1] = FLIP2(y0);
- m1->win[0] = x1;
- m1->win[1] = FLIP2(y1);
-}
-#endif
-
-/*
- * NON-depth-buffered flat line.
- */
-static void line_rgb_flat (GLcontext *ctx,
- const SWvertex *vert0,
- const SWvertex *vert1)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
-#ifndef MATROX
- GLuint _w_ = dmesa->Buffer->width;
- GLuint rgb = vl_mixrgb(vert1->color);
-
-#define INTERP_XY 1
-#define CLIP_HACK 1
-#define PLOT(X,Y) vl_putpixel(FLIP2(Y) * _w_ + X, rgb);
-
-#include "swrast/s_linetemp.h"
-#else
- MGAvertex m0, m1;
- matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
- *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
- mga_draw_line_rgb_flat(&m0, &m1);
-#endif
-}
-
-
-
-/*
- * Z-less flat line.
- */
-static void line_rgb_flat_zless (GLcontext *ctx,
- const SWvertex *vert0,
- const SWvertex *vert1)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
-#ifndef MATROX
- GLuint _w_ = dmesa->Buffer->width;
- GLuint rgb = vl_mixrgb(vert1->color);
-
-#define INTERP_XY 1
-#define INTERP_Z 1
-#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
-#define CLIP_HACK 1
-#define PLOT(X,Y) \
- if (Z < *zPtr) { \
- *zPtr = Z; \
- vl_putpixel(FLIP2(Y) * _w_ + X, rgb); \
- }
-
-#include "swrast/s_linetemp.h"
-#else
- MGAvertex m0, m1;
- matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
- m0.win[2] = vert0->win[2];
- m1.win[2] = vert1->win[2];
- *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
- mga_draw_line_rgb_flat_zless(&m0, &m1);
-#endif
-}
-
-
-
-#ifndef MATROX
-#define line_rgb_iter NULL
-#define line_rgb_iter_zless NULL
-#else /* MATROX */
-/*
- * NON-depth-buffered iterated line.
- */
-static void line_rgb_iter (GLcontext *ctx,
- const SWvertex *vert0,
- const SWvertex *vert1)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
- MGAvertex m0, m1;
- matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
- *(unsigned long *)m0.color = *(unsigned long *)vert0->color;
- *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
- mga_draw_line_rgb_iter(&m0, &m1);
-}
-
-
-
-/*
- * Z-less iterated line.
- */
-static void line_rgb_iter_zless (GLcontext *ctx,
- const SWvertex *vert0,
- const SWvertex *vert1)
-{
- const DMesaContext dmesa = (DMesaContext)ctx;
- GLuint _b_ = dmesa->Buffer->height - 1;
- MGAvertex m0, m1;
- matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
- m0.win[2] = vert0->win[2];
- m1.win[2] = vert1->win[2];
- *(unsigned long *)m0.color = *(unsigned long *)vert0->color;
- *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
- mga_draw_line_rgb_iter_zless(&m0, &m1);
-}
-#endif /* MATROX */
-
-
-
-/*
- * Analyze context state to see if we can provide a fast line function
- * Otherwise, return NULL.
- */
-static swrast_line_func dmesa_choose_line_function (GLcontext *ctx)
-{
- const SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- if ((ctx->RenderMode != GL_RENDER)
- || (ctx->Line.SmoothFlag)
- || (ctx->Texture._EnabledUnits)
- || (ctx->Line.StippleFlag)
- || (swrast->_RasterMask & MULTI_DRAW_BIT)
- || (ctx->Line.Width!=1.0F)) {
- return (swrast_line_func)NULL;
- }
-
- if (swrast->_RasterMask==DEPTH_BIT
- && ctx->Depth.Func==GL_LESS
- && ctx->Depth.Mask==GL_TRUE
- && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {
- return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter_zless : line_rgb_flat_zless;
- }
-
- if (swrast->_RasterMask==0) { /* no depth test */
- return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter : line_rgb_flat;
- }
-
- return (swrast_line_func)NULL;
-}
-
-
-
-/* Override for the swrast line-selection function. Try to use one
- * of our internal line functions, otherwise fall back to the
- * standard swrast functions.
- */
-static void dmesa_choose_line (GLcontext *ctx)
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- if (!(swrast->Line=dmesa_choose_line_function(ctx)))
- _swrast_choose_line(ctx);
-}
-
-
-
-/****************************************************************************
- * Miscellaneous device driver funcs
- ***************************************************************************/
-
-static void clear_index (GLcontext *ctx, GLuint index)
-{
- ((DMesaContext)ctx)->ClearIndex = index;
-}
-
-static void clear_color (GLcontext *ctx, const GLfloat color[4])
-{
- GLubyte col[4];
- CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
- CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
- CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
- CLAMPED_FLOAT_TO_UBYTE(col[3], color[3]);
- ((DMesaContext)ctx)->ClearColor = vl_mixrgba(col);
-}
-
-
-
-static void clear (GLcontext *ctx, GLbitfield mask, GLboolean all,
- GLint x, GLint y, GLint width, GLint height)
-{
- const DMesaContext c = (DMesaContext)ctx;
- const GLuint *colorMask = (GLuint *)&ctx->Color.ColorMask;
-
-/*
- * Clear the specified region of the buffers indicated by 'mask'
- * using the clear color or index as specified by one of the two
- * functions above.
- * If all==GL_TRUE, clear whole buffer, else just clear region defined
- * by x,y,width,height
- */
-
- /* we can't handle color or index masking */
- if ((*colorMask == 0xffffffff) && (ctx->Color.IndexMask == 0xffffffff)) {
-#ifndef MATROX
- if (mask & DD_BACK_LEFT_BIT) {
- int color = c->visual->rgb_flag ? c->ClearColor : c->ClearIndex;
-
- if (all) {
- vl_clear(color);
- } else {
- vl_rect(x, y, width, height, color);
- }
-
- mask &= ~DD_BACK_LEFT_BIT;
- }
-#else /* MATROX */
- unsigned short z = -1;
- int color = c->ClearColor;
- if (mask & DD_DEPTH_BIT) {
- z = ctx->Depth.Clear * 0xffff;
- }
- if (all) {
- mga_clear(mask & DD_FRONT_LEFT_BIT,
- mask & DD_BACK_LEFT_BIT,
- mask & DD_DEPTH_BIT,
- 0, 0, c->Buffer->width, c->Buffer->height,
- color, z);
- } else {
- mga_clear(mask & DD_FRONT_LEFT_BIT,
- mask & DD_BACK_LEFT_BIT,
- mask & DD_DEPTH_BIT,
- x, y, width, height,
- color, z);
- }
- mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT);
-#endif /* MATROX */
- }
-
- if (mask) {
- _swrast_Clear(ctx, mask, all, x, y, width, height);
- }
-}
-
-
-
-static void set_buffer (GLcontext *ctx, GLframebuffer *colorBuffer, GLuint bufferBit)
-{
- /*
- * XXX todo - examine bufferBit and set read/write pointers
- */
-}
-
-
-
-/*
- * Return the width and height of the current buffer.
- * If anything special has to been done when the buffer/window is
- * resized, do it now.
- */
-static void get_buffer_size (GLframebuffer *buffer, GLuint *width, GLuint *height)
-{
- DMesaBuffer b = (DMesaBuffer)buffer;
-
- *width = b->width;
- *height = b->height;
-}
-
-
-
-static const GLubyte* get_string (GLcontext *ctx, GLenum name)
-{
- switch (name) {
- case GL_RENDERER:
- return (const GLubyte *)"Mesa DJGPP"
- #ifdef FX
- " (FX)"
- #endif
- #ifdef MATROX
- " (MGA)"
- #endif
- "\0port (c) Borca Daniel mar-2003";
- default:
- return NULL;
- }
-}
-
-
-
-static void finish (GLcontext *ctx)
-{
- /*
- * XXX todo - OPTIONAL FUNCTION: implements glFinish if possible
- */
-}
-
-
-
-static void flush (GLcontext *ctx)
-{
- /*
- * XXX todo - OPTIONAL FUNCTION: implements glFlush if possible
- */
-}
-
-
-
-/****************************************************************************
- * State
- ***************************************************************************/
-#define DMESA_NEW_LINE (_NEW_LINE | \
- _NEW_TEXTURE | \
- _NEW_LIGHT | \
- _NEW_DEPTH | \
- _NEW_RENDERMODE | \
- _SWRAST_NEW_RASTERMASK)
-
-#define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \
- _NEW_TEXTURE | \
- _NEW_LIGHT | \
- _NEW_DEPTH | \
- _NEW_RENDERMODE | \
- _SWRAST_NEW_RASTERMASK)
-
-/* Extend the software rasterizer with our line and triangle
- * functions.
- */
-static void dmesa_register_swrast_functions (GLcontext *ctx)
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- swrast->choose_line = dmesa_choose_line;
- swrast->choose_triangle = dmesa_choose_tri;
-
- swrast->invalidate_line |= DMESA_NEW_LINE;
- swrast->invalidate_triangle |= DMESA_NEW_TRIANGLE;
-}
-
-
-
-/* Setup pointers and other driver state that is constant for the life
- * of a context.
- */
-static void dmesa_init_pointers (GLcontext *ctx)
-{
- TNLcontext *tnl;
- struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx);
-
- ctx->Driver.GetString = get_string;
- ctx->Driver.GetBufferSize = get_buffer_size;
- ctx->Driver.Flush = flush;
- ctx->Driver.Finish = finish;
-
- /* Software rasterizer pixel paths:
- */
- ctx->Driver.Accum = _swrast_Accum;
- ctx->Driver.Bitmap = _swrast_Bitmap;
- ctx->Driver.Clear = clear;
- ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
- ctx->Driver.CopyPixels = _swrast_CopyPixels;
- ctx->Driver.DrawPixels = _swrast_DrawPixels;
- ctx->Driver.ReadPixels = _swrast_ReadPixels;
- ctx->Driver.DrawBuffer = _swrast_DrawBuffer;
-
- /* Software texture functions:
- */
- ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
- ctx->Driver.TexImage1D = _mesa_store_teximage1d;
- ctx->Driver.TexImage2D = _mesa_store_teximage2d;
- ctx->Driver.TexImage3D = _mesa_store_teximage3d;
- ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
- ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
- ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
- ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
-
- ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
- ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
- ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
- ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
- ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
-
- ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;
- ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;
- ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;
- ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
- ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
- ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
-
- /* Swrast hooks for imaging extensions:
- */
- ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
- ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
- ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
- ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
-
- /* Statechange callbacks:
- */
- ctx->Driver.ClearColor = clear_color;
- ctx->Driver.ClearIndex = clear_index;
-
- /* Initialize the TNL driver interface:
- */
- tnl = TNL_CONTEXT(ctx);
- tnl->Driver.RunPipeline = _tnl_run_pipeline;
-
- dd->SetBuffer = set_buffer;
-
- /* Install swsetup for tnl->Driver.Render.*:
- */
- _swsetup_Wakeup(ctx);
-
- /* The span functions should be in `dmesa_update_state', but I'm
- * pretty sure they will never change during the life of the Visual
- */
-#ifdef MATROX
- if (((DMesaContext)ctx)->visual->zbuffer == -1) {
- /* Depth span/pixel functions */
- dd->WriteDepthSpan = write_depth_span;
- dd->WriteDepthPixels = write_depth_pixels;
- dd->ReadDepthSpan = read_depth_span;
- dd->ReadDepthPixels = read_depth_pixels;
- }
-#endif
-
-#ifndef MATROX
- /* Index span/pixel functions */
- dd->WriteCI32Span = write_index_span;
- dd->WriteCI8Span = write_index8_span;
- dd->WriteMonoCISpan = write_mono_index_span;
- dd->WriteCI32Pixels = write_index_pixels;
- dd->WriteMonoCIPixels = write_mono_index_pixels;
- dd->ReadCI32Span = read_index_span;
- dd->ReadCI32Pixels = read_index_pixels;
-#endif
-
- /* RGB(A) span/pixel functions */
- dd->WriteRGBASpan = write_rgba_span;
- dd->WriteRGBSpan = write_rgb_span;
- dd->WriteMonoRGBASpan = write_mono_rgba_span;
- dd->WriteRGBAPixels = write_rgba_pixels;
- dd->WriteMonoRGBAPixels = write_mono_rgba_pixels;
- dd->ReadRGBASpan = read_rgba_span;
- dd->ReadRGBAPixels = read_rgba_pixels;
-}
-
-
-
-static void dmesa_update_state (GLcontext *ctx, GLuint new_state)
-{
- /* Propogate statechange information to swrast and swrast_setup
- * modules. The DMesa driver has no internal GL-dependent state.
- */
- _swrast_InvalidateState( ctx, new_state );
- _ac_InvalidateState( ctx, new_state );
- _tnl_InvalidateState( ctx, new_state );
- _swsetup_InvalidateState( ctx, new_state );
-}
-#endif /* FX */
-
-
-
-/****************************************************************************
- * DMesa Public API Functions
- ***************************************************************************/
-
-/*
- * The exact arguments to this function will depend on your window system
- */
-DMesaVisual DMesaCreateVisual (GLint width,
- GLint height,
- GLint colDepth,
- GLint refresh,
- GLboolean dbFlag,
- GLboolean rgbFlag,
- GLboolean alphaFlag,
- GLint depthSize,
- GLint stencilSize,
- GLint accumSize)
-{
-#ifndef FX
- DMesaVisual v;
- GLint redBits, greenBits, blueBits, alphaBits, indexBits;
-
-#ifndef MATROX
- if (!dbFlag) {
- return NULL;
- }
-#else
- if (!rgbFlag) {
- return NULL;
- }
-#endif
-
- alphaBits = 0;
-
- if (!rgbFlag) {
- indexBits = 8;
- redBits = 0;
- greenBits = 0;
- blueBits = 0;
- } else {
- indexBits = 0;
- switch (colDepth) {
- case 8:
- redBits = 8;
- greenBits = 8;
- blueBits = 8;
- break;
- case 15:
- redBits = 5;
- greenBits = 5;
- blueBits = 5;
- break;
- case 16:
- redBits = 5;
- greenBits = 6;
- blueBits = 5;
- break;
- case 32:
- alphaBits = 8;
- case 24:
- redBits = 8;
- greenBits = 8;
- blueBits = 8;
- break;
- default:
- return NULL;
- }
- }
-
-#ifndef MATROX
- if ((colDepth=vl_video_init(width, height, colDepth, rgbFlag, refresh)) <= 0) {
- return NULL;
- }
-#else
- if (mga_open(width, height, colDepth, dbFlag ? 2 : 1, depthSize == 16, refresh) < 0) {
- return NULL;
- }
-#endif
-
- if (alphaFlag && (alphaBits==0)) {
- alphaBits = 8;
- }
-
- if ((v=(DMesaVisual)CALLOC_STRUCT(dmesa_visual)) != NULL) {
- /* Create core visual */
- _mesa_initialize_visual((GLvisual *)v,
- rgbFlag, /* rgb */
- dbFlag,
- GL_FALSE, /* stereo */
- redBits,
- greenBits,
- blueBits,
- alphaBits,
- indexBits, /* indexBits */
- depthSize,
- stencilSize,
- accumSize, /* accumRed */
- accumSize, /* accumGreen */
- accumSize, /* accumBlue */
- alphaFlag?accumSize:0, /* accumAlpha */
- 1); /* numSamples */
-
- v->depth = colDepth;
- v->db_flag = dbFlag;
- v->rgb_flag = rgbFlag;
-
- v->zbuffer = (depthSize > 0) ? 1 : 0;
-#ifdef MATROX
- mga_get(MGA_GET_HPIXELS, &v->stride_in_pixels);
- if (depthSize == 16) {
- v->zbuffer = -1;
- }
-#endif
- }
-
- return v;
-
-#else /* FX */
-
- int i = 0, fx_attrib[32];
-
- if (!rgbFlag) {
- return NULL;
- }
-
- if (dbFlag) fx_attrib[i++] = FXMESA_DOUBLEBUFFER;
- if (depthSize > 0) { fx_attrib[i++] = FXMESA_DEPTH_SIZE; fx_attrib[i++] = depthSize; }
- if (stencilSize > 0) { fx_attrib[i++] = FXMESA_STENCIL_SIZE; fx_attrib[i++] = stencilSize; }
- if (accumSize > 0) { fx_attrib[i++] = FXMESA_ACCUM_SIZE; fx_attrib[i++] = accumSize; }
- if (alphaFlag) { fx_attrib[i++] = FXMESA_ALPHA_SIZE; fx_attrib[i++] = 1; }
- fx_attrib[i] = FXMESA_NONE;
-
- return (DMesaVisual)fxMesaCreateBestContext(-1, width, height, fx_attrib);
-#endif /* FX */
-}
-
-
-
-void DMesaDestroyVisual (DMesaVisual v)
-{
-#ifndef FX
- _mesa_destroy_visual((GLvisual *)v);
-
-#ifndef MATROX
- vl_video_exit();
-#else
- mga_close(1, 1);
-#endif
-
-#else
- fxMesaDestroyContext((fxMesaContext)v);
-#endif
-}
-
-
-
-DMesaBuffer DMesaCreateBuffer (DMesaVisual visual,
- GLint xpos, GLint ypos,
- GLint width, GLint height)
-{
-#ifndef FX
- DMesaBuffer b;
-
- if ((b=(DMesaBuffer)CALLOC_STRUCT(dmesa_buffer)) != NULL) {
- _mesa_initialize_framebuffer((GLframebuffer *)b,
- (GLvisual *)visual,
- visual->zbuffer == 1,
- ((GLvisual *)visual)->stencilBits > 0,
- ((GLvisual *)visual)->accumRedBits > 0,
- ((GLvisual *)visual)->alphaBits > 0);
- b->xpos = xpos;
- b->ypos = ypos;
- b->width = width;
- b->height = height;
- }
-
- return b;
-#else
- return (DMesaBuffer)visual;
-#endif
-}
-
-
-
-void DMesaDestroyBuffer (DMesaBuffer b)
-{
-#ifndef FX
-#ifndef MATROX
- free(b->the_window);
-#endif
- _mesa_destroy_framebuffer((GLframebuffer *)b);
-#endif
-}
-
-
-
-DMesaContext DMesaCreateContext (DMesaVisual visual,
- DMesaContext share)
-{
-#ifndef FX
- DMesaContext c;
- GLboolean direct = GL_FALSE;
-
- if ((c=(DMesaContext)CALLOC_STRUCT(dmesa_context)) != NULL) {
- _mesa_initialize_context((GLcontext *)c,
- (GLvisual *)visual,
- (GLcontext *)share,
- (void *)c, direct);
-
- _mesa_enable_sw_extensions((GLcontext *)c);
- _mesa_enable_1_3_extensions((GLcontext *)c);
- _mesa_enable_1_4_extensions((GLcontext *)c);
-
- /* you probably have to do a bunch of other initializations here. */
- c->visual = visual;
-
- ((GLcontext *)c)->Driver.UpdateState = dmesa_update_state;
-
- /* Initialize the software rasterizer and helper modules.
- */
- _swrast_CreateContext((GLcontext *)c);
- _ac_CreateContext((GLcontext *)c);
- _tnl_CreateContext((GLcontext *)c);
- _swsetup_CreateContext((GLcontext *)c);
- if (visual->rgb_flag) dmesa_register_swrast_functions((GLcontext *)c);
- dmesa_init_pointers((GLcontext *)c);
- }
-
- return c;
-
-#else /* FX */
- return (DMesaContext)visual;
-#endif /* FX */
-}
-
-
-
-void DMesaDestroyContext (DMesaContext c)
-{
-#ifndef FX
- if (c) {
- _swsetup_DestroyContext((GLcontext *)c);
- _swrast_DestroyContext((GLcontext *)c);
- _tnl_DestroyContext((GLcontext *)c);
- _ac_DestroyContext((GLcontext *)c);
- _mesa_destroy_context((GLcontext *)c);
- }
-#endif
-}
-
-
-
-GLboolean DMesaMoveBuffer (GLint xpos, GLint ypos)
-{
-#if !defined(FX) && !defined(MATROX)
- GET_CURRENT_CONTEXT(ctx);
- DMesaBuffer b = ((DMesaContext)ctx)->Buffer;
-
- if (vl_sync_buffer(&b->the_window, xpos, ypos, b->width, b->height) != 0) {
- return GL_FALSE;
- } else {
- b->xpos = xpos;
- b->ypos = ypos;
- return GL_TRUE;
- }
-
-#else
- return GL_FALSE;
-#endif
-}
-
-
-
-GLboolean DMesaResizeBuffer (GLint width, GLint height)
-{
-#if !defined(FX) && !defined(MATROX)
- GET_CURRENT_CONTEXT(ctx);
- DMesaBuffer b = ((DMesaContext)ctx)->Buffer;
-
- if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, width, height) != 0) {
- return GL_FALSE;
- } else {
- b->width = width;
- b->height = height;
- return GL_TRUE;
- }
-
-#else
- return GL_FALSE;
-#endif
-}
-
-
-
-/*
- * Make the specified context and buffer the current one.
- */
-GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b)
-{
-#ifndef FX
- if ((c != NULL) && (b != NULL)) {
-#ifndef MATROX
- if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, b->width, b->height) != 0) {
- return GL_FALSE;
- }
-#endif
-
- c->Buffer = b;
-
- _mesa_make_current((GLcontext *)c, (GLframebuffer *)b);
- if (((GLcontext *)c)->Viewport.Width == 0) {
- /* initialize viewport to window size */
- _mesa_Viewport(0, 0, b->width, b->height);
- }
- } else {
- /* Detach */
- _mesa_make_current(NULL, NULL);
- }
-
-#else
- fxMesaMakeCurrent((fxMesaContext)c);
-#endif
-
- return GL_TRUE;
-}
-
-
-
-void DMesaSwapBuffers (DMesaBuffer b)
-{
- /* copy/swap back buffer to front if applicable */
-#ifndef FX
- GET_CURRENT_CONTEXT(ctx);
- _mesa_notifySwapBuffers(ctx);
-#ifndef MATROX
- vl_flip();
-#else
- if (((DMesaContext)ctx)->visual->db_flag) {
- mga_swapbuffers(1);
- }
-#endif
-#else
- fxMesaSwapBuffers();
-#endif
-}
-
-
-
-void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue)
-{
-#if !defined(FX) && !defined(MATROX)
- vl_setCI(ndx, red, green, blue);
-#endif
-}
-
-
-
-DMesaContext DMesaGetCurrentContext (void)
-{
-#ifndef FX
- GET_CURRENT_CONTEXT(ctx);
- return (DMesaContext)ctx;
-#else
- return (DMesaContext)fxMesaGetCurrentContext();
-#endif
-}
-
-
-
-int DMesaGetIntegerv (GLenum pname, GLint *params)
-{
-#ifndef FX
- GET_CURRENT_CONTEXT(ctx);
- const DMesaContext c = (DMesaContext)ctx;
-#else
- const fxMesaContext c = fxMesaGetCurrentContext();
-#endif
-
- if (c == NULL) {
- return -1;
- }
-
- switch (pname) {
- case DMESA_GET_SCREEN_SIZE:
- #ifndef FX
- #ifndef MATROX
- vl_get(VL_GET_SCREEN_SIZE, params);
- #else
- mga_get(MGA_GET_SCREEN_SIZE, params);
- #endif
- #else
- params[0] = c->screen_width;
- params[1] = c->screen_height;
- #endif
- break;
- case DMESA_GET_DRIVER_CAPS:
- #ifndef FX
- #ifndef MATROX
- params[0] = DMESA_DRIVER_SWDB_BIT;
- #else
- params[0] = 0;
- #endif
- #else
- params[0] = DMESA_DRIVER_LLWO_BIT;
- #endif
- break;
- default:
- return -1;
- }
-
- return 0;
-}
+/* + * Mesa 3-D graphics library + * Version: 5.0.1 + * + * Copyright (C) 1999-2003 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.4 for Mesa + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef FX +#include "glheader.h" +#include "context.h" +#include "extensions.h" +#include "macros.h" +#include "matrix.h" +#include "mtypes.h" +#include "texformat.h" +#include "teximage.h" +#include "texstore.h" +#include "imports.h" +#include "array_cache/acache.h" +#include "swrast/s_context.h" +#include "swrast/s_depth.h" +#include "swrast/s_lines.h" +#include "swrast/s_triangle.h" +#include "swrast/swrast.h" +#include "swrast_setup/swrast_setup.h" +#include "tnl/tnl.h" +#include "tnl/t_context.h" +#include "tnl/t_pipeline.h" +#ifndef MATROX +#include "video.h" +#else /* MATROX */ +#include "mga/mga.h" +#endif /* MATROX */ +#else /* FX */ +#include "../glide/fxdrv.h" +#endif /* FX */ + +#include "GL/dmesa.h" + + + +/* + * In C++ terms, this class derives from the GLvisual class. + * Add system-specific fields to it. + */ +struct dmesa_visual { + GLvisual gl_visual; + GLboolean db_flag; /* double buffered? */ + GLboolean rgb_flag; /* RGB mode? */ + GLuint depth; /* bits per pixel (1, 8, 24, etc) */ +#ifdef MATROX + int stride_in_pixels; +#endif + int zbuffer; /* Z=buffer: 0=no, 1=SW, -1=HW */ +}; + +/* + * In C++ terms, this class derives from the GLframebuffer class. + * Add system-specific fields to it. + */ +struct dmesa_buffer { + GLframebuffer gl_buffer; /* The depth, stencil, accum, etc buffers */ + void *the_window; /* your window handle, etc */ + + int xpos, ypos; /* position */ + int width, height; /* size in pixels */ +}; + +/* + * In C++ terms, this class derives from the GLcontext class. + * Add system-specific fields to it. + */ +struct dmesa_context { + GLcontext gl_ctx; /* the core library context */ + DMesaVisual visual; + DMesaBuffer Buffer; + GLuint ClearColor; + GLuint ClearIndex; + /* etc... */ +}; + + + +#ifndef FX +/**************************************************************************** + * Read/Write pixels + ***************************************************************************/ +#define FLIP(y) (dmesa->Buffer->height - (y) - 1) +#define FLIP2(y) (_b_ - (y)) + + +#ifndef MATROX +#define DSTRIDE dmesa->Buffer->width +#else +#define DSTRIDE dmesa->visual->stride_in_pixels +#define vl_putpixel mga_putpixel +#define vl_mixrgba mga_mixrgb +#define vl_mixrgb mga_mixrgb +#define vl_getrgba mga_getrgba +#define vl_setz mga_setz +#define vl_getz mga_getz +#endif + +/**************************************************************************** + * RGB[A] + ***************************************************************************/ +static void write_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLubyte rgba[][4], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + +#ifndef MATROX + offset = DSTRIDE * FLIP(y) + x; + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++, offset++) { + if (mask[i]) { + vl_putpixel(offset, vl_mixrgba(rgba[i])); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++, offset++) { + vl_putpixel(offset, vl_mixrgba(rgba[i])); + } + } +#else /* MATROX */ + y = FLIP(y); + if (mask) { + /* draw some pixels */ + offset = 0; + for (i = 0; i < n; i++) { + if (mask[i]) { + ++offset; + } else { + if (offset != 0) { + mga_draw_span_rgb_tx32(x + i - offset, y, offset, (const unsigned long *)(&rgba[i-offset])); + offset = 0; + } + } + } + if (offset != 0) { + mga_draw_span_rgb_tx32(x + n - offset, y, offset, (const unsigned long *)(&rgba[n-offset])); + } + } else { + /* draw all pixels */ + mga_draw_span_rgb_tx32(x, y, n, (const unsigned long *)rgba); + } +#endif /* MATROX */ +} + + + +static void write_rgb_span (const GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLubyte rgb[][3], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++, offset++) { + if (mask[i]) { + vl_putpixel(offset, vl_mixrgb(rgb[i])); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++, offset++) { + vl_putpixel(offset, vl_mixrgb(rgb[i])); + } + } +} + + + +static void write_mono_rgba_span (const GLcontext *ctx, + GLuint n, GLint x, GLint y, + const GLchan color[4], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset, rgba = vl_mixrgba(color); + + offset = DSTRIDE * FLIP(y) + x; + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++, offset++) { + if (mask[i]) { + vl_putpixel(offset, rgba); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++, offset++) { + vl_putpixel(offset, rgba); + } + } +} + + + +static void read_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y, + GLubyte rgba[][4]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + /* read all pixels */ + for (i=0; i<n; i++, offset++) { + vl_getrgba(offset, rgba[i]); + } +} + + + +static void write_rgba_pixels (const GLcontext *ctx, + GLuint n, const GLint x[], const GLint y[], + const GLubyte rgba[][4], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1; + + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++) { + if (mask[i]) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i])); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i])); + } + } +} + + + +static void write_mono_rgba_pixels (const GLcontext *ctx, + GLuint n, const GLint x[], const GLint y[], + const GLchan color[4], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1, rgba = vl_mixrgba(color); + + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++) { + if (mask[i]) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba); + } + } +} + + + +static void read_rgba_pixels (const GLcontext *ctx, + GLuint n, const GLint x[], const GLint y[], + GLubyte rgba[][4], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1; + + if (mask) { + /* read some pixels */ + for (i=0; i<n; i++) { + if (mask[i]) { + vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]); + } + } + } else { + /* read all pixels */ + for (i=0; i<n; i++) { + vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]); + } + } +} + + + +/**************************************************************************** + * Index + ***************************************************************************/ +#ifndef MATROX +static void write_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLuint index[], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++, offset++) { + if (mask[i]) { + vl_putpixel(offset, index[i]); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++, offset++) { + vl_putpixel(offset, index[i]); + } + } +} + + + +static void write_index8_span (const GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLubyte index[], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++, offset++) { + if (mask[i]) { + vl_putpixel(offset, index[i]); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++, offset++) { + vl_putpixel(offset, index[i]); + } + } +} + + + +static void write_mono_index_span (const GLcontext *ctx, + GLuint n, GLint x, GLint y, + GLuint colorIndex, const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++, offset++) { + if (mask[i]) { + vl_putpixel(offset, colorIndex); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++, offset++) { + vl_putpixel(offset, colorIndex); + } + } +} + + + +static void read_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y, + GLuint index[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + /* read all pixels */ + for (i=0; i<n; i++, offset++) { + index[i] = vl_getpixel(offset); + } +} + + + +static void write_index_pixels (const GLcontext *ctx, + GLuint n, const GLint x[], const GLint y[], + const GLuint index[], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1; + + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++) { + if (mask[i]) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]); + } + } +} + + + +static void write_mono_index_pixels (const GLcontext *ctx, + GLuint n, const GLint x[], const GLint y[], + GLuint colorIndex, const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1; + + if (mask) { + /* draw some pixels */ + for (i=0; i<n; i++) { + if (mask[i]) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex); + } + } + } else { + /* draw all pixels */ + for (i=0; i<n; i++) { + vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex); + } + } +} + + + +static void read_index_pixels (const GLcontext *ctx, + GLuint n, const GLint x[], const GLint y[], + GLuint index[], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1; + + if (mask) { + /* read some pixels */ + for (i=0; i<n; i++) { + if (mask[i]) { + index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]); + } + } + } else { + /* read all pixels */ + for (i=0; i<n; i++) { + index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]); + } + } +} +#endif /* !MATROX */ + + + +/**************************************************************************** + * Z-buffer + ***************************************************************************/ +#ifdef MATROX +static void write_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y, + const GLdepth depth[], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + if (mask) { + /* draw some values */ + for (i=0; i<n; i++, offset++) { + if (mask[i]) { + vl_setz(offset, depth[i]); + } + } + } else { + /* draw all values */ + for (i=0; i<n; i++, offset++) { + vl_setz(offset, depth[i]); + } + } +} + + + +static void read_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y, + GLdepth depth[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, offset; + + offset = DSTRIDE * FLIP(y) + x; + /* read all values */ + for (i=0; i<n; i++, offset++) { + depth[i] = vl_getz(offset); + } +} + + + +static void write_depth_pixels (GLcontext *ctx, GLuint n, + const GLint x[], const GLint y[], + const GLdepth depth[], const GLubyte mask[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1; + + if (mask) { + /* draw some values */ + for (i=0; i<n; i++) { + if (mask[i]) { + vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]); + } + } + } else { + /* draw all values */ + for (i=0; i<n; i++) { + vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]); + } + } +} + + + +static void read_depth_pixels (GLcontext *ctx, GLuint n, + const GLint x[], const GLint y[], + GLdepth depth[]) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1; + + /* read all values */ + for (i=0; i<n; i++) { + depth[i] = vl_getz(FLIP2(y[i])*_w_ + x[i]); + } +} +#endif /* MATROX */ + + + +/**************************************************************************** + * Optimized triangle rendering + ***************************************************************************/ + +/* + * NON-depth-buffered flat triangle. + */ +#ifndef MATROX + +#define NAME tri_rgb_flat + +#define SETUP_CODE \ + const DMesaContext dmesa = (DMesaContext)ctx; \ + GLuint _b_ = dmesa->Buffer->height - 1; \ + GLuint _w_ = dmesa->Buffer->width; \ + GLuint rgb = vl_mixrgb(v2->color); + +#define RENDER_SPAN(span) \ + GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \ + for (i = 0; i < span.end; i++, offset++) { \ + vl_putpixel(offset, rgb); \ + } + +#include "swrast/s_tritemp.h" + +#else /* MATROX */ + +static void tri_rgb_flat (GLcontext *ctx, + const SWvertex *v0, + const SWvertex *v1, + const SWvertex *v2) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1, m2; + m0.win[0] = v0->win[0]; + m0.win[1] = FLIP2(v0->win[1]); + m1.win[0] = v1->win[0]; + m1.win[1] = FLIP2(v1->win[1]); + m2.win[0] = v2->win[0]; + m2.win[1] = FLIP2(v2->win[1]); + *(unsigned long *)m2.color = *(unsigned long *)v2->color; + mga_draw_tri_rgb_flat((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2); +} +#endif /* MATROX */ + + + +/* + * Z-less flat triangle. + */ +#ifndef MATROX + +#define NAME tri_rgb_flat_zless + +#define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE + +#define SETUP_CODE \ + const DMesaContext dmesa = (DMesaContext)ctx; \ + GLuint _b_ = dmesa->Buffer->height - 1; \ + GLuint _w_ = dmesa->Buffer->width; \ + GLuint rgb = vl_mixrgb(v2->color); + +#define RENDER_SPAN(span) \ + GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \ + for (i = 0; i < span.end; i++, offset++) { \ + const DEPTH_TYPE z = FixedToDepth(span.z); \ + if (z < zRow[i]) { \ + vl_putpixel(offset, rgb); \ + zRow[i] = z; \ + } \ + span.z += span.zStep; \ + } + +#include "swrast/s_tritemp.h" + +#else /* MATROX */ + +static void tri_rgb_flat_zless (GLcontext *ctx, + const SWvertex *v0, + const SWvertex *v1, + const SWvertex *v2) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1, m2; + m0.win[0] = v0->win[0]; + m0.win[1] = FLIP2(v0->win[1]); + m0.win[2] = v0->win[2]; + m1.win[0] = v1->win[0]; + m1.win[1] = FLIP2(v1->win[1]); + m1.win[2] = v1->win[2]; + m2.win[0] = v2->win[0]; + m2.win[1] = FLIP2(v2->win[1]); + m2.win[2] = v2->win[2]; + *(unsigned long *)m2.color = *(unsigned long *)v2->color; + mga_draw_tri_rgb_flat_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2); +} +#endif /* MATROX */ + + + +/* + * NON-depth-buffered iterated triangle. + */ +#ifndef MATROX + +#define NAME tri_rgb_iter + +#define INTERP_RGB 1 + +#define SETUP_CODE \ + const DMesaContext dmesa = (DMesaContext)ctx; \ + GLuint _b_ = dmesa->Buffer->height - 1; \ + GLuint _w_ = dmesa->Buffer->width; + +#define RENDER_SPAN(span) \ + GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \ + for (i = 0; i < span.end; i++, offset++) { \ + vl_putpixel(offset, vl_mixfix(span.red, span.green, span.blue)); \ + span.red += span.redStep; \ + span.green += span.greenStep; \ + span.blue += span.blueStep; \ + } + +#include "swrast/s_tritemp.h" + +#else /* MATROX */ + +static void tri_rgb_iter (GLcontext *ctx, + const SWvertex *v0, + const SWvertex *v1, + const SWvertex *v2) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1, m2; + m0.win[0] = v0->win[0]; + m0.win[1] = FLIP2(v0->win[1]); + m1.win[0] = v1->win[0]; + m1.win[1] = FLIP2(v1->win[1]); + m2.win[0] = v2->win[0]; + m2.win[1] = FLIP2(v2->win[1]); + *(unsigned long *)m0.color = *(unsigned long *)v0->color; + *(unsigned long *)m1.color = *(unsigned long *)v1->color; + *(unsigned long *)m2.color = *(unsigned long *)v2->color; + mga_draw_tri_rgb_iter((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2); +} +#endif /* MATROX */ + + + +/* + * Z-less iterated triangle. + */ +#ifndef MATROX + +#define NAME tri_rgb_iter_zless + +#define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE +#define INTERP_RGB 1 + +#define SETUP_CODE \ + const DMesaContext dmesa = (DMesaContext)ctx; \ + GLuint _b_ = dmesa->Buffer->height - 1; \ + GLuint _w_ = dmesa->Buffer->width; + +#define RENDER_SPAN(span) \ + GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \ + for (i = 0; i < span.end; i++, offset++) { \ + const DEPTH_TYPE z = FixedToDepth(span.z); \ + if (z < zRow[i]) { \ + vl_putpixel(offset, vl_mixfix(span.red, span.green, span.blue));\ + zRow[i] = z; \ + } \ + span.red += span.redStep; \ + span.green += span.greenStep; \ + span.blue += span.blueStep; \ + span.z += span.zStep; \ + } + +#include "swrast/s_tritemp.h" + +#else /* MATROX */ + +static void tri_rgb_iter_zless (GLcontext *ctx, + const SWvertex *v0, + const SWvertex *v1, + const SWvertex *v2) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1, m2; + m0.win[0] = v0->win[0]; + m0.win[1] = FLIP2(v0->win[1]); + m0.win[2] = v0->win[2]; + m1.win[0] = v1->win[0]; + m1.win[1] = FLIP2(v1->win[1]); + m1.win[2] = v1->win[2]; + m2.win[0] = v2->win[0]; + m2.win[1] = FLIP2(v2->win[1]); + m2.win[2] = v2->win[2]; + *(unsigned long *)m0.color = *(unsigned long *)v0->color; + *(unsigned long *)m1.color = *(unsigned long *)v1->color; + *(unsigned long *)m2.color = *(unsigned long *)v2->color; + mga_draw_tri_rgb_iter_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2); +} +#endif /* MATROX */ + + + +/* + * Analyze context state to see if we can provide a fast triangle function + * Otherwise, return NULL. + */ +static swrast_tri_func dmesa_choose_tri_function (GLcontext *ctx) +{ + const SWcontext *swrast = SWRAST_CONTEXT(ctx); + + if ((ctx->RenderMode != GL_RENDER) + || (ctx->Polygon.SmoothFlag) + || (ctx->Polygon.StippleFlag) + || (ctx->Texture._EnabledUnits) + || (swrast->_RasterMask & MULTI_DRAW_BIT) + || (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)) { + return (swrast_tri_func)NULL; + } + + if (swrast->_RasterMask==DEPTH_BIT + && ctx->Depth.Func==GL_LESS + && ctx->Depth.Mask==GL_TRUE + && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) { + return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter_zless : tri_rgb_flat_zless; + } + + if (swrast->_RasterMask==0) { /* no depth test */ + return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter : tri_rgb_flat; + } + + return (swrast_tri_func)NULL; +} + + + +/* Override for the swrast triangle-selection function. Try to use one + * of our internal triangle functions, otherwise fall back to the + * standard swrast functions. + */ +static void dmesa_choose_tri (GLcontext *ctx) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + if (!(swrast->Triangle=dmesa_choose_tri_function(ctx))) + _swrast_choose_triangle(ctx); +} + + + +/**************************************************************************** + * Optimized line rendering + ***************************************************************************/ + +#ifdef MATROX +static __inline void matrox_line_clip_hack (GLcontext *ctx, int _b_, MGAvertex *m0, const SWvertex *vert0, MGAvertex *m1, const SWvertex *vert1) +{ + int x0 = vert0->win[0]; + int y0 = vert0->win[1]; + int x1 = vert1->win[0]; + int y1 = vert1->win[1]; + /* s_linetemp.h { */ + GLint w = ctx->DrawBuffer->Width; + GLint h = ctx->DrawBuffer->Height; + if ((x0==w) | (x1==w)) { + if ((x0==w) & (x1==w)) + return; + x0 -= x0==w; + x1 -= x1==w; + } + if ((y0==h) | (y1==h)) { + if ((y0==h) & (y1==h)) + return; + y0 -= y0==h; + y1 -= y1==h; + } + /* } s_linetemp.h */ + m0->win[0] = x0; + m0->win[1] = FLIP2(y0); + m1->win[0] = x1; + m1->win[1] = FLIP2(y1); +} +#endif + +/* + * NON-depth-buffered flat line. + */ +#ifndef MATROX + +#define NAME line_rgb_flat + +#define INTERP_XY 1 +#define CLIP_HACK 1 + +#define SETUP_CODE \ + const DMesaContext dmesa = (DMesaContext)ctx; \ + GLuint _b_ = dmesa->Buffer->height - 1; \ + GLuint _w_ = dmesa->Buffer->width; \ + GLuint rgb = vl_mixrgb(vert1->color); + +#define PLOT(X,Y) vl_putpixel(FLIP2(Y) * _w_ + X, rgb); + +#include "swrast/s_linetemp.h" + +#else /* MATROX */ + +static void line_rgb_flat (GLcontext *ctx, + const SWvertex *vert0, + const SWvertex *vert1) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1; + matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1); + *(unsigned long *)m1.color = *(unsigned long *)vert1->color; + mga_draw_line_rgb_flat(&m0, &m1); +} +#endif /* MATROX */ + + + +/* + * Z-less flat line. + */ +#ifndef MATROX + +#define NAME line_rgb_flat_zless + +#define INTERP_XY 1 +#define INTERP_Z 1 +#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE +#define CLIP_HACK 1 + +#define SETUP_CODE \ + const DMesaContext dmesa = (DMesaContext)ctx; \ + GLuint _b_ = dmesa->Buffer->height - 1; \ + GLuint _w_ = dmesa->Buffer->width; \ + GLuint rgb = vl_mixrgb(vert1->color); + +#define PLOT(X,Y) \ + if (Z < *zPtr) { \ + *zPtr = Z; \ + vl_putpixel(FLIP2(Y) * _w_ + X, rgb); \ + } + +#include "swrast/s_linetemp.h" + +#else /* MATROX */ + +static void line_rgb_flat_zless (GLcontext *ctx, + const SWvertex *vert0, + const SWvertex *vert1) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1; + matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1); + m0.win[2] = vert0->win[2]; + m1.win[2] = vert1->win[2]; + *(unsigned long *)m1.color = *(unsigned long *)vert1->color; + mga_draw_line_rgb_flat_zless(&m0, &m1); +} +#endif /* MATROX */ + + + +#ifndef MATROX +#define line_rgb_iter NULL +#define line_rgb_iter_zless NULL +#else /* MATROX */ +/* + * NON-depth-buffered iterated line. + */ +static void line_rgb_iter (GLcontext *ctx, + const SWvertex *vert0, + const SWvertex *vert1) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1; + matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1); + *(unsigned long *)m0.color = *(unsigned long *)vert0->color; + *(unsigned long *)m1.color = *(unsigned long *)vert1->color; + mga_draw_line_rgb_iter(&m0, &m1); +} + + + +/* + * Z-less iterated line. + */ +static void line_rgb_iter_zless (GLcontext *ctx, + const SWvertex *vert0, + const SWvertex *vert1) +{ + const DMesaContext dmesa = (DMesaContext)ctx; + GLuint _b_ = dmesa->Buffer->height - 1; + MGAvertex m0, m1; + matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1); + m0.win[2] = vert0->win[2]; + m1.win[2] = vert1->win[2]; + *(unsigned long *)m0.color = *(unsigned long *)vert0->color; + *(unsigned long *)m1.color = *(unsigned long *)vert1->color; + mga_draw_line_rgb_iter_zless(&m0, &m1); +} +#endif /* MATROX */ + + + +/* + * Analyze context state to see if we can provide a fast line function + * Otherwise, return NULL. + */ +static swrast_line_func dmesa_choose_line_function (GLcontext *ctx) +{ + const SWcontext *swrast = SWRAST_CONTEXT(ctx); + + if ((ctx->RenderMode != GL_RENDER) + || (ctx->Line.SmoothFlag) + || (ctx->Texture._EnabledUnits) + || (ctx->Line.StippleFlag) + || (swrast->_RasterMask & MULTI_DRAW_BIT) + || (ctx->Line.Width!=1.0F)) { + return (swrast_line_func)NULL; + } + + if (swrast->_RasterMask==DEPTH_BIT + && ctx->Depth.Func==GL_LESS + && ctx->Depth.Mask==GL_TRUE + && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) { + return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter_zless : line_rgb_flat_zless; + } + + if (swrast->_RasterMask==0) { /* no depth test */ + return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter : line_rgb_flat; + } + + return (swrast_line_func)NULL; +} + + + +/* Override for the swrast line-selection function. Try to use one + * of our internal line functions, otherwise fall back to the + * standard swrast functions. + */ +static void dmesa_choose_line (GLcontext *ctx) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + if (!(swrast->Line=dmesa_choose_line_function(ctx))) + _swrast_choose_line(ctx); +} + + + +/**************************************************************************** + * Miscellaneous device driver funcs + ***************************************************************************/ + +static void clear_index (GLcontext *ctx, GLuint index) +{ + ((DMesaContext)ctx)->ClearIndex = index; +} + +static void clear_color (GLcontext *ctx, const GLfloat color[4]) +{ + GLubyte col[4]; + CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]); + CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]); + CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]); + CLAMPED_FLOAT_TO_UBYTE(col[3], color[3]); + ((DMesaContext)ctx)->ClearColor = vl_mixrgba(col); +} + + + +static void clear (GLcontext *ctx, GLbitfield mask, GLboolean all, + GLint x, GLint y, GLint width, GLint height) +{ + const DMesaContext c = (DMesaContext)ctx; + const GLuint *colorMask = (GLuint *)&ctx->Color.ColorMask; + +/* + * Clear the specified region of the buffers indicated by 'mask' + * using the clear color or index as specified by one of the two + * functions above. + * If all==GL_TRUE, clear whole buffer, else just clear region defined + * by x,y,width,height + */ + + /* we can't handle color or index masking */ + if ((*colorMask == 0xffffffff) && (ctx->Color.IndexMask == 0xffffffff)) { +#ifndef MATROX + if (mask & DD_BACK_LEFT_BIT) { + int color = c->visual->rgb_flag ? c->ClearColor : c->ClearIndex; + + if (all) { + vl_clear(color); + } else { + vl_rect(x, y, width, height, color); + } + + mask &= ~DD_BACK_LEFT_BIT; + } +#else /* MATROX */ + unsigned short z = -1; + int color = c->ClearColor; + if (mask & DD_DEPTH_BIT) { + z = ctx->Depth.Clear * 0xffff; + } + if (all) { + mga_clear(mask & DD_FRONT_LEFT_BIT, + mask & DD_BACK_LEFT_BIT, + mask & DD_DEPTH_BIT, + 0, 0, c->Buffer->width, c->Buffer->height, + color, z); + } else { + mga_clear(mask & DD_FRONT_LEFT_BIT, + mask & DD_BACK_LEFT_BIT, + mask & DD_DEPTH_BIT, + x, y, width, height, + color, z); + } + mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT); +#endif /* MATROX */ + } + + if (mask) { + _swrast_Clear(ctx, mask, all, x, y, width, height); + } +} + + + +static void set_buffer (GLcontext *ctx, GLframebuffer *colorBuffer, GLuint bufferBit) +{ + /* + * XXX todo - examine bufferBit and set read/write pointers + */ +} + + + +/* + * Return the width and height of the current buffer. + * If anything special has to been done when the buffer/window is + * resized, do it now. + */ +static void get_buffer_size (GLframebuffer *buffer, GLuint *width, GLuint *height) +{ + DMesaBuffer b = (DMesaBuffer)buffer; + + *width = b->width; + *height = b->height; +} + + + +static const GLubyte* get_string (GLcontext *ctx, GLenum name) +{ + switch (name) { + case GL_RENDERER: + return (const GLubyte *)"Mesa DJGPP" + #ifdef FX + " (FX)" + #endif + #ifdef MATROX + " (MGA)" + #endif + "\0port (c) Borca Daniel mar-2003"; + default: + return NULL; + } +} + + + +static void finish (GLcontext *ctx) +{ + /* + * XXX todo - OPTIONAL FUNCTION: implements glFinish if possible + */ +} + + + +static void flush (GLcontext *ctx) +{ + /* + * XXX todo - OPTIONAL FUNCTION: implements glFlush if possible + */ +} + + + +/**************************************************************************** + * State + ***************************************************************************/ +#define DMESA_NEW_LINE (_NEW_LINE | \ + _NEW_TEXTURE | \ + _NEW_LIGHT | \ + _NEW_DEPTH | \ + _NEW_RENDERMODE | \ + _SWRAST_NEW_RASTERMASK) + +#define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \ + _NEW_TEXTURE | \ + _NEW_LIGHT | \ + _NEW_DEPTH | \ + _NEW_RENDERMODE | \ + _SWRAST_NEW_RASTERMASK) + +/* Extend the software rasterizer with our line and triangle + * functions. + */ +static void dmesa_register_swrast_functions (GLcontext *ctx) +{ + SWcontext *swrast = SWRAST_CONTEXT(ctx); + + swrast->choose_line = dmesa_choose_line; + swrast->choose_triangle = dmesa_choose_tri; + + swrast->invalidate_line |= DMESA_NEW_LINE; + swrast->invalidate_triangle |= DMESA_NEW_TRIANGLE; +} + + + +/* Setup pointers and other driver state that is constant for the life + * of a context. + */ +static void dmesa_init_pointers (GLcontext *ctx) +{ + TNLcontext *tnl; + struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx); + + ctx->Driver.GetString = get_string; + ctx->Driver.GetBufferSize = get_buffer_size; + ctx->Driver.Flush = flush; + ctx->Driver.Finish = finish; + + /* Software rasterizer pixel paths: + */ + ctx->Driver.Accum = _swrast_Accum; + ctx->Driver.Bitmap = _swrast_Bitmap; + ctx->Driver.Clear = clear; + ctx->Driver.ResizeBuffers = _swrast_alloc_buffers; + ctx->Driver.CopyPixels = _swrast_CopyPixels; + ctx->Driver.DrawPixels = _swrast_DrawPixels; + ctx->Driver.ReadPixels = _swrast_ReadPixels; + ctx->Driver.DrawBuffer = _swrast_DrawBuffer; + + /* Software texture functions: + */ + ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format; + ctx->Driver.TexImage1D = _mesa_store_teximage1d; + ctx->Driver.TexImage2D = _mesa_store_teximage2d; + ctx->Driver.TexImage3D = _mesa_store_teximage3d; + ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d; + ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d; + ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d; + ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage; + + ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d; + ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d; + ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d; + ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d; + ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d; + + ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d; + ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d; + ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d; + ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d; + ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d; + ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d; + + /* Swrast hooks for imaging extensions: + */ + ctx->Driver.CopyColorTable = _swrast_CopyColorTable; + ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable; + ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D; + ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D; + + /* Statechange callbacks: + */ + ctx->Driver.ClearColor = clear_color; + ctx->Driver.ClearIndex = clear_index; + + /* Initialize the TNL driver interface: + */ + tnl = TNL_CONTEXT(ctx); + tnl->Driver.RunPipeline = _tnl_run_pipeline; + + dd->SetBuffer = set_buffer; + + /* Install swsetup for tnl->Driver.Render.*: + */ + _swsetup_Wakeup(ctx); + + /* The span functions should be in `dmesa_update_state', but I'm + * pretty sure they will never change during the life of the Visual + */ +#ifdef MATROX + if (((DMesaContext)ctx)->visual->zbuffer == -1) { + /* Depth span/pixel functions */ + dd->WriteDepthSpan = write_depth_span; + dd->WriteDepthPixels = write_depth_pixels; + dd->ReadDepthSpan = read_depth_span; + dd->ReadDepthPixels = read_depth_pixels; + } +#endif + +#ifndef MATROX + /* Index span/pixel functions */ + dd->WriteCI32Span = write_index_span; + dd->WriteCI8Span = write_index8_span; + dd->WriteMonoCISpan = write_mono_index_span; + dd->WriteCI32Pixels = write_index_pixels; + dd->WriteMonoCIPixels = write_mono_index_pixels; + dd->ReadCI32Span = read_index_span; + dd->ReadCI32Pixels = read_index_pixels; +#endif + + /* RGB(A) span/pixel functions */ + dd->WriteRGBASpan = write_rgba_span; + dd->WriteRGBSpan = write_rgb_span; + dd->WriteMonoRGBASpan = write_mono_rgba_span; + dd->WriteRGBAPixels = write_rgba_pixels; + dd->WriteMonoRGBAPixels = write_mono_rgba_pixels; + dd->ReadRGBASpan = read_rgba_span; + dd->ReadRGBAPixels = read_rgba_pixels; +} + + + +static void dmesa_update_state (GLcontext *ctx, GLuint new_state) +{ + /* Propogate statechange information to swrast and swrast_setup + * modules. The DMesa driver has no internal GL-dependent state. + */ + _swrast_InvalidateState( ctx, new_state ); + _ac_InvalidateState( ctx, new_state ); + _tnl_InvalidateState( ctx, new_state ); + _swsetup_InvalidateState( ctx, new_state ); +} +#endif /* FX */ + + + +/**************************************************************************** + * DMesa Public API Functions + ***************************************************************************/ + +/* + * The exact arguments to this function will depend on your window system + */ +DMesaVisual DMesaCreateVisual (GLint width, + GLint height, + GLint colDepth, + GLint refresh, + GLboolean dbFlag, + GLboolean rgbFlag, + GLboolean alphaFlag, + GLint depthSize, + GLint stencilSize, + GLint accumSize) +{ +#ifndef FX + DMesaVisual v; + GLint redBits, greenBits, blueBits, alphaBits, indexBits; + +#ifndef MATROX + if (!dbFlag) { + return NULL; + } +#else + if (!rgbFlag) { + return NULL; + } +#endif + + alphaBits = 0; + + if (!rgbFlag) { + indexBits = 8; + redBits = 0; + greenBits = 0; + blueBits = 0; + } else { + indexBits = 0; + switch (colDepth) { + case 8: + redBits = 8; + greenBits = 8; + blueBits = 8; + break; + case 15: + redBits = 5; + greenBits = 5; + blueBits = 5; + break; + case 16: + redBits = 5; + greenBits = 6; + blueBits = 5; + break; + case 32: + alphaBits = 8; + case 24: + redBits = 8; + greenBits = 8; + blueBits = 8; + break; + default: + return NULL; + } + } + +#ifndef MATROX + if ((colDepth=vl_video_init(width, height, colDepth, rgbFlag, refresh)) <= 0) { + return NULL; + } +#else + if (mga_open(width, height, colDepth, dbFlag ? 2 : 1, depthSize == 16, refresh) < 0) { + return NULL; + } +#endif + + if (alphaFlag && (alphaBits==0)) { + alphaBits = 8; + } + + if ((v=(DMesaVisual)CALLOC_STRUCT(dmesa_visual)) != NULL) { + /* Create core visual */ + _mesa_initialize_visual((GLvisual *)v, + rgbFlag, /* rgb */ + dbFlag, + GL_FALSE, /* stereo */ + redBits, + greenBits, + blueBits, + alphaBits, + indexBits, /* indexBits */ + depthSize, + stencilSize, + accumSize, /* accumRed */ + accumSize, /* accumGreen */ + accumSize, /* accumBlue */ + alphaFlag?accumSize:0, /* accumAlpha */ + 1); /* numSamples */ + + v->depth = colDepth; + v->db_flag = dbFlag; + v->rgb_flag = rgbFlag; + + v->zbuffer = (depthSize > 0) ? 1 : 0; +#ifdef MATROX + mga_get(MGA_GET_HPIXELS, &v->stride_in_pixels); + if (depthSize == 16) { + v->zbuffer = -1; + } +#endif + } + + return v; + +#else /* FX */ + + int i = 0, fx_attrib[32]; + + if (!rgbFlag) { + return NULL; + } + + if (dbFlag) fx_attrib[i++] = FXMESA_DOUBLEBUFFER; + if (depthSize > 0) { fx_attrib[i++] = FXMESA_DEPTH_SIZE; fx_attrib[i++] = depthSize; } + if (stencilSize > 0) { fx_attrib[i++] = FXMESA_STENCIL_SIZE; fx_attrib[i++] = stencilSize; } + if (accumSize > 0) { fx_attrib[i++] = FXMESA_ACCUM_SIZE; fx_attrib[i++] = accumSize; } + if (alphaFlag) { fx_attrib[i++] = FXMESA_ALPHA_SIZE; fx_attrib[i++] = 1; } + fx_attrib[i] = FXMESA_NONE; + + return (DMesaVisual)fxMesaCreateBestContext(-1, width, height, fx_attrib); +#endif /* FX */ +} + + + +void DMesaDestroyVisual (DMesaVisual v) +{ +#ifndef FX + _mesa_destroy_visual((GLvisual *)v); + +#ifndef MATROX + vl_video_exit(); +#else + mga_close(1, 1); +#endif + +#else + fxMesaDestroyContext((fxMesaContext)v); +#endif +} + + + +DMesaBuffer DMesaCreateBuffer (DMesaVisual visual, + GLint xpos, GLint ypos, + GLint width, GLint height) +{ +#ifndef FX + DMesaBuffer b; + + if ((b=(DMesaBuffer)CALLOC_STRUCT(dmesa_buffer)) != NULL) { + _mesa_initialize_framebuffer((GLframebuffer *)b, + (GLvisual *)visual, + visual->zbuffer == 1, + ((GLvisual *)visual)->stencilBits > 0, + ((GLvisual *)visual)->accumRedBits > 0, + ((GLvisual *)visual)->alphaBits > 0); + b->xpos = xpos; + b->ypos = ypos; + b->width = width; + b->height = height; + } + + return b; +#else + return (DMesaBuffer)visual; +#endif +} + + + +void DMesaDestroyBuffer (DMesaBuffer b) +{ +#ifndef FX +#ifndef MATROX + free(b->the_window); +#endif + _mesa_destroy_framebuffer((GLframebuffer *)b); +#endif +} + + + +DMesaContext DMesaCreateContext (DMesaVisual visual, + DMesaContext share) +{ +#ifndef FX + DMesaContext c; + GLboolean direct = GL_FALSE; + + if ((c=(DMesaContext)CALLOC_STRUCT(dmesa_context)) != NULL) { + _mesa_initialize_context((GLcontext *)c, + (GLvisual *)visual, + (GLcontext *)share, + (void *)c, direct); + + _mesa_enable_sw_extensions((GLcontext *)c); + _mesa_enable_1_3_extensions((GLcontext *)c); + _mesa_enable_1_4_extensions((GLcontext *)c); + + /* you probably have to do a bunch of other initializations here. */ + c->visual = visual; + + ((GLcontext *)c)->Driver.UpdateState = dmesa_update_state; + + /* Initialize the software rasterizer and helper modules. + */ + _swrast_CreateContext((GLcontext *)c); + _ac_CreateContext((GLcontext *)c); + _tnl_CreateContext((GLcontext *)c); + _swsetup_CreateContext((GLcontext *)c); + if (visual->rgb_flag) dmesa_register_swrast_functions((GLcontext *)c); + dmesa_init_pointers((GLcontext *)c); + } + + return c; + +#else /* FX */ + return (DMesaContext)visual; +#endif /* FX */ +} + + + +void DMesaDestroyContext (DMesaContext c) +{ +#ifndef FX + if (c) { + _swsetup_DestroyContext((GLcontext *)c); + _swrast_DestroyContext((GLcontext *)c); + _tnl_DestroyContext((GLcontext *)c); + _ac_DestroyContext((GLcontext *)c); + _mesa_destroy_context((GLcontext *)c); + } +#endif +} + + + +GLboolean DMesaMoveBuffer (GLint xpos, GLint ypos) +{ +#if !defined(FX) && !defined(MATROX) + GET_CURRENT_CONTEXT(ctx); + DMesaBuffer b = ((DMesaContext)ctx)->Buffer; + + if (vl_sync_buffer(&b->the_window, xpos, ypos, b->width, b->height) != 0) { + return GL_FALSE; + } else { + b->xpos = xpos; + b->ypos = ypos; + return GL_TRUE; + } + +#else + return GL_FALSE; +#endif +} + + + +GLboolean DMesaResizeBuffer (GLint width, GLint height) +{ +#if !defined(FX) && !defined(MATROX) + GET_CURRENT_CONTEXT(ctx); + DMesaBuffer b = ((DMesaContext)ctx)->Buffer; + + if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, width, height) != 0) { + return GL_FALSE; + } else { + b->width = width; + b->height = height; + return GL_TRUE; + } + +#else + return GL_FALSE; +#endif +} + + + +/* + * Make the specified context and buffer the current one. + */ +GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b) +{ +#ifndef FX + if ((c != NULL) && (b != NULL)) { +#ifndef MATROX + if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, b->width, b->height) != 0) { + return GL_FALSE; + } +#endif + + c->Buffer = b; + + _mesa_make_current((GLcontext *)c, (GLframebuffer *)b); + if (((GLcontext *)c)->Viewport.Width == 0) { + /* initialize viewport to window size */ + _mesa_Viewport(0, 0, b->width, b->height); + } + } else { + /* Detach */ + _mesa_make_current(NULL, NULL); + } + +#else + fxMesaMakeCurrent((fxMesaContext)c); +#endif + + return GL_TRUE; +} + + + +void DMesaSwapBuffers (DMesaBuffer b) +{ + /* copy/swap back buffer to front if applicable */ +#ifndef FX + GET_CURRENT_CONTEXT(ctx); + _mesa_notifySwapBuffers(ctx); +#ifndef MATROX + vl_flip(); +#else + if (((DMesaContext)ctx)->visual->db_flag) { + mga_swapbuffers(1); + } +#endif +#else + fxMesaSwapBuffers(); +#endif +} + + + +void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue) +{ +#if !defined(FX) && !defined(MATROX) + vl_setCI(ndx, red, green, blue); +#endif +} + + + +DMesaContext DMesaGetCurrentContext (void) +{ +#ifndef FX + GET_CURRENT_CONTEXT(ctx); + return (DMesaContext)ctx; +#else + return (DMesaContext)fxMesaGetCurrentContext(); +#endif +} + + + +int DMesaGetIntegerv (GLenum pname, GLint *params) +{ +#ifndef FX + GET_CURRENT_CONTEXT(ctx); + const DMesaContext c = (DMesaContext)ctx; +#else + const fxMesaContext c = fxMesaGetCurrentContext(); +#endif + + if (c == NULL) { + return -1; + } + + switch (pname) { + case DMESA_GET_SCREEN_SIZE: + #ifndef FX + #ifndef MATROX + vl_get(VL_GET_SCREEN_SIZE, params); + #else + mga_get(MGA_GET_SCREEN_SIZE, params); + #endif + #else + params[0] = c->screen_width; + params[1] = c->screen_height; + #endif + break; + case DMESA_GET_DRIVER_CAPS: + #ifndef FX + #ifndef MATROX + params[0] = DMESA_DRIVER_SWDB_BIT; + #else + params[0] = 0; + #endif + #else + params[0] = DMESA_DRIVER_LLWO_BIT; + #endif + break; + default: + return -1; + } + + return 0; +} diff --git a/src/mesa/drivers/dos/dpmi.c b/src/mesa/drivers/dos/dpmi.c index 17c005a9e58..f9943ea60bf 100644 --- a/src/mesa/drivers/dos/dpmi.c +++ b/src/mesa/drivers/dos/dpmi.c @@ -1,148 +1,148 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <dpmi.h>
-
-#include "internal.h"
-
-
-
-#ifndef MAX
-#define MAX(x, y) (((x)<(y))?(y):(x))
-#endif
-
-
-
-/* _create_linear_mapping:
- * Maps a physical address range into linear memory.
- */
-int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)
-{
- __dpmi_meminfo meminfo;
-
- if (physaddr >= 0x100000) {
- /* map into linear memory */
- meminfo.address = physaddr;
- meminfo.size = size;
- if (__dpmi_physical_address_mapping(&meminfo) != 0)
- return -1;
-
- *linear = meminfo.address;
- } else {
- /* exploit 1 -> 1 physical to linear mapping in low megabyte */
- *linear = physaddr;
- }
-
- return 0;
-}
-
-
-
-/* _remove_linear_mapping:
- * Frees the DPMI resources being used to map a linear address range.
- */
-void _remove_linear_mapping (unsigned long *linear)
-{
- __dpmi_meminfo meminfo;
-
- if (*linear) {
- if (*linear >= 0x100000) {
- meminfo.address = *linear;
- __dpmi_free_physical_address_mapping(&meminfo);
- }
-
- *linear = 0;
- }
-}
-
-
-
-/* _create_selector:
- * Allocates a selector to access a region of linear memory.
- */
-int _create_selector (int *segment, unsigned long base, int size)
-{
- /* allocate an ldt descriptor */
- if ((*segment=__dpmi_allocate_ldt_descriptors(1)) < 0) {
- *segment = 0;
- return -1;
- }
-
- /* create the linear mapping */
- if (_create_linear_mapping(&base, base, size)) {
- __dpmi_free_ldt_descriptor(*segment);
- *segment = 0;
- return -1;
- }
-
- /* set the descriptor base and limit */
- __dpmi_set_segment_base_address(*segment, base);
- __dpmi_set_segment_limit(*segment, MAX(size-1, 0xFFFF));
-
- return 0;
-}
-
-
-
-/* _remove_selector:
- * Frees a DPMI segment selector.
- */
-void _remove_selector (int *segment)
-{
- if (*segment) {
- unsigned long base;
- __dpmi_get_segment_base_address(*segment, &base);
- _remove_linear_mapping(&base);
- __dpmi_free_ldt_descriptor(*segment);
- *segment = 0;
- }
-}
-
-
-
-/* Desc: retrieve CPU MMX capability
- *
- * In : -
- * Out : FALSE if CPU cannot do MMX
- *
- * Note: -
- */
-int _can_mmx (void)
-{
-#ifdef USE_MMX_ASM
- extern int _mesa_identify_x86_cpu_features (void);
- return (_mesa_identify_x86_cpu_features() & 0x00800000);
-#else
- return 0;
-#endif
-}
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.4 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <dpmi.h> + +#include "internal.h" + + + +#ifndef MAX +#define MAX(x, y) (((x)<(y))?(y):(x)) +#endif + + + +/* _create_linear_mapping: + * Maps a physical address range into linear memory. + */ +int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size) +{ + __dpmi_meminfo meminfo; + + if (physaddr >= 0x100000) { + /* map into linear memory */ + meminfo.address = physaddr; + meminfo.size = size; + if (__dpmi_physical_address_mapping(&meminfo) != 0) + return -1; + + *linear = meminfo.address; + } else { + /* exploit 1 -> 1 physical to linear mapping in low megabyte */ + *linear = physaddr; + } + + return 0; +} + + + +/* _remove_linear_mapping: + * Frees the DPMI resources being used to map a linear address range. + */ +void _remove_linear_mapping (unsigned long *linear) +{ + __dpmi_meminfo meminfo; + + if (*linear) { + if (*linear >= 0x100000) { + meminfo.address = *linear; + __dpmi_free_physical_address_mapping(&meminfo); + } + + *linear = 0; + } +} + + + +/* _create_selector: + * Allocates a selector to access a region of linear memory. + */ +int _create_selector (int *segment, unsigned long base, int size) +{ + /* allocate an ldt descriptor */ + if ((*segment=__dpmi_allocate_ldt_descriptors(1)) < 0) { + *segment = 0; + return -1; + } + + /* create the linear mapping */ + if (_create_linear_mapping(&base, base, size)) { + __dpmi_free_ldt_descriptor(*segment); + *segment = 0; + return -1; + } + + /* set the descriptor base and limit */ + __dpmi_set_segment_base_address(*segment, base); + __dpmi_set_segment_limit(*segment, MAX(size-1, 0xFFFF)); + + return 0; +} + + + +/* _remove_selector: + * Frees a DPMI segment selector. + */ +void _remove_selector (int *segment) +{ + if (*segment) { + unsigned long base; + __dpmi_get_segment_base_address(*segment, &base); + _remove_linear_mapping(&base); + __dpmi_free_ldt_descriptor(*segment); + *segment = 0; + } +} + + + +/* Desc: retrieve CPU MMX capability + * + * In : - + * Out : FALSE if CPU cannot do MMX + * + * Note: - + */ +int _can_mmx (void) +{ +#ifdef USE_MMX_ASM + extern int _mesa_x86_cpu_features; + return (_mesa_x86_cpu_features & 0x00800000); +#else + return 0; +#endif +} diff --git a/src/mesa/drivers/dos/internal.h b/src/mesa/drivers/dos/internal.h index 6860ef35840..dfb9274ecc7 100644 --- a/src/mesa/drivers/dos/internal.h +++ b/src/mesa/drivers/dos/internal.h @@ -1,129 +1,129 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef INTERNAL_H_included
-#define INTERNAL_H_included
-
-#include "../mmath.h"
-
-/*
- * general purpose defines, etc.
- */
-#ifndef FALSE
-#define FALSE 0
-#define TRUE !FALSE
-#endif
-
-#define __PACKED__ __attribute__((packed))
-
-typedef unsigned char word8;
-typedef unsigned short word16;
-typedef unsigned long word32;
-
-#define _16_ *(word16 *)&
-#define _32_ *(word32 *)&
-
-
-
-/*
- * video mode structure
- */
-typedef struct vl_mode {
- int mode;
- int xres, yres;
- int scanlen;
- int bpp;
-
- int sel;
- int gran;
-} vl_mode;
-
-
-
-/*
- * video driver structure
- */
-typedef struct {
- vl_mode *(*init) (void);
- int (*entermode) (vl_mode *p, int refresh);
- void (*blit) (void);
- void (*setCI_f) (int index, float red, float green, float blue);
- void (*setCI_i) (int index, int red, int green, int blue);
- int (*get) (int pname, int *params);
- void (*restore) (void);
- void (*fini) (void);
-} vl_driver;
-
-
-
-/*
- * memory mapping
- */
-int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size);
-void _remove_linear_mapping (unsigned long *linear);
-int _create_selector (int *segment, unsigned long base, int size);
-void _remove_selector (int *segment);
-
-/*
- * system routines
- */
-int _can_mmx (void);
-
-/*
- * asm routines to deal with virtual buffering
- */
-extern void v_clear8 (int color);
-#define v_clear15 v_clear16
-extern void v_clear16 (int color);
-extern void v_clear24 (int color);
-extern void v_clear32 (int color);
-
-extern void v_clear8_mmx (int color);
-#define v_clear15_mmx v_clear16_mmx
-extern void v_clear16_mmx (int color);
-extern void v_clear24_mmx (int color);
-extern void v_clear32_mmx (int color);
-
-extern void v_rect8 (int x, int y, int width, int height, int color);
-#define v_rect15 v_rect16
-extern void v_rect16 (int x, int y, int width, int height, int color);
-extern void v_rect24 (int x, int y, int width, int height, int color);
-extern void v_rect32 (int x, int y, int width, int height, int color);
-
-extern void v_putpixel8 (unsigned int offset, int color);
-#define v_putpixel15 v_putpixel16
-extern void v_putpixel16 (unsigned int offset, int color);
-extern void v_putpixel24 (unsigned int offset, int color);
-extern void v_putpixel32 (unsigned int offset, int color);
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.4 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef INTERNAL_H_included +#define INTERNAL_H_included + +#include "../main/mtypes.h" + +/* + * general purpose defines, etc. + */ +#ifndef FALSE +#define FALSE 0 +#define TRUE !FALSE +#endif + +#define __PACKED__ __attribute__((packed)) + +typedef unsigned char word8; +typedef unsigned short word16; +typedef unsigned long word32; + +#define _16_ *(word16 *)& +#define _32_ *(word32 *)& + + + +/* + * video mode structure + */ +typedef struct vl_mode { + int mode; + int xres, yres; + int scanlen; + int bpp; + + int sel; + int gran; +} vl_mode; + + + +/* + * video driver structure + */ +typedef struct { + vl_mode *(*init) (void); + int (*entermode) (vl_mode *p, int refresh); + void (*blit) (void); + void (*setCI_f) (int index, float red, float green, float blue); + void (*setCI_i) (int index, int red, int green, int blue); + int (*get) (int pname, int *params); + void (*restore) (void); + void (*fini) (void); +} vl_driver; + + + +/* + * memory mapping + */ +int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size); +void _remove_linear_mapping (unsigned long *linear); +int _create_selector (int *segment, unsigned long base, int size); +void _remove_selector (int *segment); + +/* + * system routines + */ +int _can_mmx (void); + +/* + * asm routines to deal with virtual buffering + */ +extern void v_clear8 (int color); +#define v_clear15 v_clear16 +extern void v_clear16 (int color); +extern void v_clear24 (int color); +extern void v_clear32 (int color); + +extern void v_clear8_mmx (int color); +#define v_clear15_mmx v_clear16_mmx +extern void v_clear16_mmx (int color); +extern void v_clear24_mmx (int color); +extern void v_clear32_mmx (int color); + +extern void v_rect8 (int x, int y, int width, int height, int color); +#define v_rect15 v_rect16 +extern void v_rect16 (int x, int y, int width, int height, int color); +extern void v_rect24 (int x, int y, int width, int height, int color); +extern void v_rect32 (int x, int y, int width, int height, int color); + +extern void v_putpixel8 (unsigned int offset, int color); +#define v_putpixel15 v_putpixel16 +extern void v_putpixel16 (unsigned int offset, int color); +extern void v_putpixel24 (unsigned int offset, int color); +extern void v_putpixel32 (unsigned int offset, int color); + +#endif diff --git a/src/mesa/drivers/dos/mga/m_ttemp.h b/src/mesa/drivers/dos/mga/m_ttemp.h index 1c5fbda29af..90d9de35642 100644 --- a/src/mesa/drivers/dos/mga/m_ttemp.h +++ b/src/mesa/drivers/dos/mga/m_ttemp.h @@ -1,377 +1,377 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W triangle template
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-/*
- * Triangle Rasterizer Template
- *
- * This file is #include'd to generate custom triangle rasterizers.
- *
- * The following macros may be defined to indicate what auxillary information
- * must be interplated across the triangle:
- * INTERP_Z - if defined, interpolate Z values
- * INTERP_RGB - if defined, interpolate RGB values
- *
- * TAG - function name
- * CULL - enable culling for: 0=no, 1=back, -1=front
- *
- * SETUP_CODE - to be executed once per triangle (usually HW init)
- *
- * For flatshaded primitives, the provoking vertex is the final one.
- * This code was designed for the origin to be in the upper-left corner.
- *
- * Inspired by triangle rasterizer code written by Brian Paul.
- */
-
-
-
-#define TRI_SWAP(a, b) \
-do { \
- const MGAvertex *tmp = a; \
- a = b; \
- b = tmp; \
-} while (0)
-
-void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3)
-{
- int area;
- int x1, y1, x2, y2, x3, y3;
- int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy;
-#ifdef INTERP_RGB
-#define FIFO_CNT_RGB 3
- int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db;
- int drdx, drdy, dgdx, dgdy, dbdx, dbdy;
-#else
-#define FIFO_CNT_RGB 0
-#endif
-#ifdef INTERP_Z
-#define FIFO_CNT_Z 1
- int dzdx, dzdy;
- int eMaj_dz, eBot_dz;
- int z1, z2, z3;
-#else
-#define FIFO_CNT_Z 0
-#endif
-
-#if defined(INTERP_Z) || defined(INTERP_RGB)
- double one_area;
-#ifndef INTERP_RGB
- int red = v3->color[0];
- int green = v3->color[1];
- int blue = v3->color[2];
-#endif
-#else
- unsigned long color = mga_mixrgb_full(v3->color);
-#endif
-
- int sgn = 0;
-
- /* sort along the vertical axis */
- if (v2->win[1] < v1->win[1]) {
- TRI_SWAP(v1, v2);
-#ifdef CULL
- cull = -cull;
-#endif
- }
-
- if (v3->win[1] < v1->win[1]) {
- TRI_SWAP(v1, v3);
- TRI_SWAP(v2, v3);
- } else if (v3->win[1] < v2->win[1]) {
- TRI_SWAP(v2, v3);
-#ifdef CULL
- cull = -cull;
-#endif
- }
-
- x1 = v1->win[0];
- y1 = v1->win[1];
- x2 = v2->win[0];
- y2 = v2->win[1];
- x3 = v3->win[0];
- y3 = v3->win[1];
-
- /* compute deltas for each edge */
- eMaj_dx = x3 - x1;
- eMaj_dy = y3 - y1;
- eBot_dx = x2 - x1;
- eBot_dy = y2 - y1;
- eTop_dx = x3 - x2;
- eTop_dy = y3 - y2;
-
- /* compute area */
- if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) {
- return;
- }
-#ifdef CULL
- if ((area * cull) > 0) {
- return;
- }
-#endif
-
- mga_select();
-
- /* set engine state */
-#ifdef SETUP_CODE
- SETUP_CODE
-#endif
-
- /* draw lower triangle */
-#if defined(INTERP_Z) || defined(INTERP_RGB)
- one_area = (double)(1<<15) / (double)area;
- mga_fifo(1);
-#else
- mga_fifo(2);
- mga_outl(M_FCOL, color);
-#endif
- mga_outl(M_YDST, y1);
-
-#ifdef INTERP_Z
- z1 = v1->win[2];
- z2 = v2->win[2];
- z3 = v3->win[2];
-
- /* compute d?/dx and d?/dy derivatives */
- eMaj_dz = z3 - z1;
- eBot_dz = z2 - z1;
- dzdx = (eMaj_dz * eBot_dy - eMaj_dy * eBot_dz) * one_area;
- dzdy = (eMaj_dx * eBot_dz - eMaj_dz * eBot_dx) * one_area;
-
-#ifndef INTERP_RGB
- mga_fifo(11);
- mga_outl(M_DR2, dzdx);
- mga_outl(M_DR3, dzdy);
- mga_outl(M_DR4, red<<15);
- mga_outl(M_DR6, 0);
- mga_outl(M_DR7, 0);
- mga_outl(M_DR8, green<<15);
- mga_outl(M_DR10, 0);
- mga_outl(M_DR11, 0);
- mga_outl(M_DR12, blue<<15);
- mga_outl(M_DR14, 0);
- mga_outl(M_DR15, 0);
-#else
- mga_fifo(2);
- mga_outl(M_DR2, dzdx);
- mga_outl(M_DR3, dzdy);
-#endif
-#endif
-
-#ifdef INTERP_RGB
- /* compute color deltas */
- eMaj_dr = v3->color[0] - v1->color[0];
- eBot_dr = v2->color[0] - v1->color[0];
- eMaj_dg = v3->color[1] - v1->color[1];
- eBot_dg = v2->color[1] - v1->color[1];
- eMaj_db = v3->color[2] - v1->color[2];
- eBot_db = v2->color[2] - v1->color[2];
-
- /* compute color increments */
- drdx = (eMaj_dr * eBot_dy - eMaj_dy * eBot_dr) * one_area;
- drdy = (eMaj_dx * eBot_dr - eMaj_dr * eBot_dx) * one_area;
- dgdx = (eMaj_dg * eBot_dy - eMaj_dy * eBot_dg) * one_area;
- dgdy = (eMaj_dx * eBot_dg - eMaj_dg * eBot_dx) * one_area;
- dbdx = (eMaj_db * eBot_dy - eMaj_dy * eBot_db) * one_area;
- dbdy = (eMaj_dx * eBot_db - eMaj_db * eBot_dx) * one_area;
-
- mga_fifo(6);
- mga_outl(M_DR6, drdx);
- mga_outl(M_DR7, drdy);
- mga_outl(M_DR10, dgdx);
- mga_outl(M_DR11, dgdy);
- mga_outl(M_DR14, dbdx);
- mga_outl(M_DR15, dbdy);
-#endif
-
- if (area > 0) { /* major edge on the right */
- if (eBot_dy) { /* have lower triangle */
- mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR0, eBot_dy);
- if (x2 < x1) {
- mga_outl(M_AR1, eBot_dx + eBot_dy - 1);
- mga_outl(M_AR2, eBot_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eBot_dx);
- mga_outl(M_AR2, -eBot_dx);
- }
-
- mga_outl(M_AR6, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR5, eMaj_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eMaj_dx);
- mga_outl(M_AR5, -eMaj_dx);
- }
-
- mga_outl(M_FXBNDRY, (x1<<16) | x1);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z1<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v1->color[0]<<15);
- mga_outl(M_DR8, v1->color[1]<<15);
- mga_outl(M_DR12, v1->color[2]<<15);
-#endif
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eBot_dy);
- } else { /* no lower triangle */
- mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR6, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR5, eMaj_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eMaj_dx);
- mga_outl(M_AR5, -eMaj_dx);
- }
-
- mga_outl(M_FXBNDRY, (x1<<16) | x2);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z2<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v2->color[0]<<15);
- mga_outl(M_DR8, v2->color[1]<<15);
- mga_outl(M_DR12, v2->color[2]<<15);
-#endif
- }
-
- /* draw upper triangle */
- if (eTop_dy) {
- mga_fifo(5);
- mga_outl(M_AR0, eTop_dy);
- if (x3 < x2) {
- mga_outl(M_AR1, eTop_dx + eTop_dy - 1);
- mga_outl(M_AR2, eTop_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eTop_dx);
- mga_outl(M_AR2, -eTop_dx);
- sgn &= ~M_SDXL;
- }
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eTop_dy);
- }
- } else { /* major edge on the left */
- if (eBot_dy) { /* have lower triangle */
- mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR0, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR2, eMaj_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eMaj_dx);
- mga_outl(M_AR2, -eMaj_dx);
- }
-
- mga_outl(M_AR6, eBot_dy);
- if (x2 < x1) {
- mga_outl(M_AR4, eBot_dx + eBot_dy - 1);
- mga_outl(M_AR5, eBot_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eBot_dx);
- mga_outl(M_AR5, -eBot_dx);
- }
-
- mga_outl(M_FXBNDRY, (x1<<16) | x1);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z1<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v1->color[0]<<15);
- mga_outl(M_DR8, v1->color[1]<<15);
- mga_outl(M_DR12, v1->color[2]<<15);
-#endif
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eBot_dy);
- } else { /* no lower triangle */
- mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR0, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR2, eMaj_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eMaj_dx);
- mga_outl(M_AR2, -eMaj_dx);
- }
-
- mga_outl(M_FXBNDRY, (x2<<16) | x1);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z1<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v1->color[0]<<15);
- mga_outl(M_DR8, v1->color[1]<<15);
- mga_outl(M_DR12, v1->color[2]<<15);
-#endif
- }
-
- /* draw upper triangle */
- if (eTop_dy) {
- mga_fifo(5);
- mga_outl(M_AR6, eTop_dy);
- if (x3 < x2) {
- mga_outl(M_AR4, eTop_dx + eTop_dy - 1);
- mga_outl(M_AR5, eTop_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eTop_dx);
- mga_outl(M_AR5, -eTop_dx);
- sgn &= ~M_SDXR;
- }
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eTop_dy);
- }
- }
-}
-
-#undef FIFO_CNT_RGB
-#undef FIFO_CNT_Z
-
-#undef TRI_SWAP
-
-#undef SETUP_CODE
-#undef INTERP_RGB
-#undef INTERP_Z
-#undef CULL
-#undef TAG
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W triangle template + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +/* + * Triangle Rasterizer Template + * + * This file is #include'd to generate custom triangle rasterizers. + * + * The following macros may be defined to indicate what auxillary information + * must be interplated across the triangle: + * INTERP_Z - if defined, interpolate Z values + * INTERP_RGB - if defined, interpolate RGB values + * + * TAG - function name + * CULL - enable culling for: 0=no, 1=back, -1=front + * + * SETUP_CODE - to be executed once per triangle (usually HW init) + * + * For flatshaded primitives, the provoking vertex is the final one. + * This code was designed for the origin to be in the upper-left corner. + * + * Inspired by triangle rasterizer code written by Brian Paul. + */ + + + +#define TRI_SWAP(a, b) \ +do { \ + const MGAvertex *tmp = a; \ + a = b; \ + b = tmp; \ +} while (0) + +void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3) +{ + int area; + int x1, y1, x2, y2, x3, y3; + int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy; +#ifdef INTERP_RGB +#define FIFO_CNT_RGB 3 + int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db; + int drdx, drdy, dgdx, dgdy, dbdx, dbdy; +#else +#define FIFO_CNT_RGB 0 +#endif +#ifdef INTERP_Z +#define FIFO_CNT_Z 1 + int dzdx, dzdy; + int eMaj_dz, eBot_dz; + int z1, z2, z3; +#else +#define FIFO_CNT_Z 0 +#endif + +#if defined(INTERP_Z) || defined(INTERP_RGB) + double one_area; +#ifndef INTERP_RGB + int red = v3->color[0]; + int green = v3->color[1]; + int blue = v3->color[2]; +#endif +#else + unsigned long color = mga_mixrgb_full(v3->color); +#endif + + int sgn = 0; + + /* sort along the vertical axis */ + if (v2->win[1] < v1->win[1]) { + TRI_SWAP(v1, v2); +#ifdef CULL + cull = -cull; +#endif + } + + if (v3->win[1] < v1->win[1]) { + TRI_SWAP(v1, v3); + TRI_SWAP(v2, v3); + } else if (v3->win[1] < v2->win[1]) { + TRI_SWAP(v2, v3); +#ifdef CULL + cull = -cull; +#endif + } + + x1 = v1->win[0]; + y1 = v1->win[1]; + x2 = v2->win[0]; + y2 = v2->win[1]; + x3 = v3->win[0]; + y3 = v3->win[1]; + + /* compute deltas for each edge */ + eMaj_dx = x3 - x1; + eMaj_dy = y3 - y1; + eBot_dx = x2 - x1; + eBot_dy = y2 - y1; + eTop_dx = x3 - x2; + eTop_dy = y3 - y2; + + /* compute area */ + if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) { + return; + } +#ifdef CULL + if ((area * cull) > 0) { + return; + } +#endif + + mga_select(); + + /* set engine state */ +#ifdef SETUP_CODE + SETUP_CODE +#endif + + /* draw lower triangle */ +#if defined(INTERP_Z) || defined(INTERP_RGB) + one_area = (double)(1<<15) / (double)area; + mga_fifo(1); +#else + mga_fifo(2); + mga_outl(M_FCOL, color); +#endif + mga_outl(M_YDST, y1); + +#ifdef INTERP_Z + z1 = v1->win[2]; + z2 = v2->win[2]; + z3 = v3->win[2]; + + /* compute d?/dx and d?/dy derivatives */ + eMaj_dz = z3 - z1; + eBot_dz = z2 - z1; + dzdx = (eMaj_dz * eBot_dy - eMaj_dy * eBot_dz) * one_area; + dzdy = (eMaj_dx * eBot_dz - eMaj_dz * eBot_dx) * one_area; + +#ifndef INTERP_RGB + mga_fifo(11); + mga_outl(M_DR2, dzdx); + mga_outl(M_DR3, dzdy); + mga_outl(M_DR4, red<<15); + mga_outl(M_DR6, 0); + mga_outl(M_DR7, 0); + mga_outl(M_DR8, green<<15); + mga_outl(M_DR10, 0); + mga_outl(M_DR11, 0); + mga_outl(M_DR12, blue<<15); + mga_outl(M_DR14, 0); + mga_outl(M_DR15, 0); +#else + mga_fifo(2); + mga_outl(M_DR2, dzdx); + mga_outl(M_DR3, dzdy); +#endif +#endif + +#ifdef INTERP_RGB + /* compute color deltas */ + eMaj_dr = v3->color[0] - v1->color[0]; + eBot_dr = v2->color[0] - v1->color[0]; + eMaj_dg = v3->color[1] - v1->color[1]; + eBot_dg = v2->color[1] - v1->color[1]; + eMaj_db = v3->color[2] - v1->color[2]; + eBot_db = v2->color[2] - v1->color[2]; + + /* compute color increments */ + drdx = (eMaj_dr * eBot_dy - eMaj_dy * eBot_dr) * one_area; + drdy = (eMaj_dx * eBot_dr - eMaj_dr * eBot_dx) * one_area; + dgdx = (eMaj_dg * eBot_dy - eMaj_dy * eBot_dg) * one_area; + dgdy = (eMaj_dx * eBot_dg - eMaj_dg * eBot_dx) * one_area; + dbdx = (eMaj_db * eBot_dy - eMaj_dy * eBot_db) * one_area; + dbdy = (eMaj_dx * eBot_db - eMaj_db * eBot_dx) * one_area; + + mga_fifo(6); + mga_outl(M_DR6, drdx); + mga_outl(M_DR7, drdy); + mga_outl(M_DR10, dgdx); + mga_outl(M_DR11, dgdy); + mga_outl(M_DR14, dbdx); + mga_outl(M_DR15, dbdy); +#endif + + if (area > 0) { /* major edge on the right */ + if (eBot_dy) { /* have lower triangle */ + mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR0, eBot_dy); + if (x2 < x1) { + mga_outl(M_AR1, eBot_dx + eBot_dy - 1); + mga_outl(M_AR2, eBot_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eBot_dx); + mga_outl(M_AR2, -eBot_dx); + } + + mga_outl(M_AR6, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR5, eMaj_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eMaj_dx); + mga_outl(M_AR5, -eMaj_dx); + } + + mga_outl(M_FXBNDRY, (x1<<16) | x1); +#ifdef INTERP_Z + mga_outl(M_DR0, z1<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v1->color[0]<<15); + mga_outl(M_DR8, v1->color[1]<<15); + mga_outl(M_DR12, v1->color[2]<<15); +#endif + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eBot_dy); + } else { /* no lower triangle */ + mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR6, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR5, eMaj_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eMaj_dx); + mga_outl(M_AR5, -eMaj_dx); + } + + mga_outl(M_FXBNDRY, (x1<<16) | x2); +#ifdef INTERP_Z + mga_outl(M_DR0, z2<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v2->color[0]<<15); + mga_outl(M_DR8, v2->color[1]<<15); + mga_outl(M_DR12, v2->color[2]<<15); +#endif + } + + /* draw upper triangle */ + if (eTop_dy) { + mga_fifo(5); + mga_outl(M_AR0, eTop_dy); + if (x3 < x2) { + mga_outl(M_AR1, eTop_dx + eTop_dy - 1); + mga_outl(M_AR2, eTop_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eTop_dx); + mga_outl(M_AR2, -eTop_dx); + sgn &= ~M_SDXL; + } + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eTop_dy); + } + } else { /* major edge on the left */ + if (eBot_dy) { /* have lower triangle */ + mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR0, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR2, eMaj_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eMaj_dx); + mga_outl(M_AR2, -eMaj_dx); + } + + mga_outl(M_AR6, eBot_dy); + if (x2 < x1) { + mga_outl(M_AR4, eBot_dx + eBot_dy - 1); + mga_outl(M_AR5, eBot_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eBot_dx); + mga_outl(M_AR5, -eBot_dx); + } + + mga_outl(M_FXBNDRY, (x1<<16) | x1); +#ifdef INTERP_Z + mga_outl(M_DR0, z1<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v1->color[0]<<15); + mga_outl(M_DR8, v1->color[1]<<15); + mga_outl(M_DR12, v1->color[2]<<15); +#endif + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eBot_dy); + } else { /* no lower triangle */ + mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR0, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR2, eMaj_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eMaj_dx); + mga_outl(M_AR2, -eMaj_dx); + } + + mga_outl(M_FXBNDRY, (x2<<16) | x1); +#ifdef INTERP_Z + mga_outl(M_DR0, z1<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v1->color[0]<<15); + mga_outl(M_DR8, v1->color[1]<<15); + mga_outl(M_DR12, v1->color[2]<<15); +#endif + } + + /* draw upper triangle */ + if (eTop_dy) { + mga_fifo(5); + mga_outl(M_AR6, eTop_dy); + if (x3 < x2) { + mga_outl(M_AR4, eTop_dx + eTop_dy - 1); + mga_outl(M_AR5, eTop_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eTop_dx); + mga_outl(M_AR5, -eTop_dx); + sgn &= ~M_SDXR; + } + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eTop_dy); + } + } +} + +#undef FIFO_CNT_RGB +#undef FIFO_CNT_Z + +#undef TRI_SWAP + +#undef SETUP_CODE +#undef INTERP_RGB +#undef INTERP_Z +#undef CULL +#undef TAG diff --git a/src/mesa/drivers/dos/mga/m_ttemp2.h b/src/mesa/drivers/dos/mga/m_ttemp2.h index 2933f2b1a95..13ca87d348a 100644 --- a/src/mesa/drivers/dos/mga/m_ttemp2.h +++ b/src/mesa/drivers/dos/mga/m_ttemp2.h @@ -1,375 +1,375 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W triangle template
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-/*
- * Triangle Rasterizer Template
- *
- * This file is #include'd to generate custom triangle rasterizers.
- *
- * The following macros may be defined to indicate what auxillary information
- * must be interplated across the triangle:
- * INTERP_Z - if defined, interpolate Z values
- * INTERP_RGB - if defined, interpolate RGB values
- *
- * TAG - function name
- * CULL - enable culling for: 0=no, 1=back, -1=front
- *
- * SETUP_CODE - to be executed once per triangle (usually HW init)
- *
- * For flatshaded primitives, the provoking vertex is the final one.
- * This code was designed for the origin to be in the upper-left corner.
- *
- * Inspired by triangle rasterizer code written by Brian Paul.
- */
-
-
-
-#define TRI_SWAP(a, b) \
-do { \
- const MGAvertex *tmp = a; \
- a = b; \
- b = tmp; \
-} while (0)
-
-void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3)
-{
- int area;
- int x1, y1, x2, y2, x3, y3;
- int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy;
-#ifdef INTERP_RGB
-#define FIFO_CNT_RGB 3
- int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db;
- int drdx, drdy, dgdx, dgdy, dbdx, dbdy;
-#else
-#define FIFO_CNT_RGB 0
-#endif
-#ifdef INTERP_Z
-#define FIFO_CNT_Z 1
- int dzdx, dzdy;
- int eMaj_dz, eBot_dz;
- int z1, z2, z3;
-#else
-#define FIFO_CNT_Z 0
-#endif
-
-#if defined(INTERP_Z) || defined(INTERP_RGB)
-#ifndef INTERP_RGB
- int red = v3->color[0];
- int green = v3->color[1];
- int blue = v3->color[2];
-#endif
-#else
- unsigned long color = mga_mixrgb_full(v3->color);
-#endif
-
- int sgn = 0;
-
- /* sort along the vertical axis */
- if (v2->win[1] < v1->win[1]) {
- TRI_SWAP(v1, v2);
-#ifdef CULL
- cull = -cull;
-#endif
- }
-
- if (v3->win[1] < v1->win[1]) {
- TRI_SWAP(v1, v3);
- TRI_SWAP(v2, v3);
- } else if (v3->win[1] < v2->win[1]) {
- TRI_SWAP(v2, v3);
-#ifdef CULL
- cull = -cull;
-#endif
- }
-
- x1 = v1->win[0];
- y1 = v1->win[1];
- x2 = v2->win[0];
- y2 = v2->win[1];
- x3 = v3->win[0];
- y3 = v3->win[1];
-
- /* compute deltas for each edge */
- eMaj_dx = x3 - x1;
- eMaj_dy = y3 - y1;
- eBot_dx = x2 - x1;
- eBot_dy = y2 - y1;
- eTop_dx = x3 - x2;
- eTop_dy = y3 - y2;
-
- /* compute area */
- if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) {
- return;
- }
-#ifdef CULL
- if ((area * cull) > 0) {
- return;
- }
-#endif
-
- mga_select();
-
- /* set engine state */
-#ifdef SETUP_CODE
- SETUP_CODE
-#endif
-
- /* draw lower triangle */
-#if defined(INTERP_Z) || defined(INTERP_RGB)
- mga_fifo(1);
-#else
- mga_fifo(2);
- mga_outl(M_FCOL, color);
-#endif
- mga_outl(M_YDST, y1);
-
-#ifdef INTERP_Z
- z1 = v1->win[2];
- z2 = v2->win[2];
- z3 = v3->win[2];
-
- /* compute d?/dx and d?/dy derivatives */
- eMaj_dz = z3 - z1;
- eBot_dz = z2 - z1;
- dzdx = ((long long)(eMaj_dz * eBot_dy - eMaj_dy * eBot_dz)<<15) / area;
- dzdy = ((long long)(eMaj_dx * eBot_dz - eMaj_dz * eBot_dx)<<15) / area;
-
-#ifndef INTERP_RGB
- mga_fifo(11);
- mga_outl(M_DR2, dzdx);
- mga_outl(M_DR3, dzdy);
- mga_outl(M_DR4, red<<15);
- mga_outl(M_DR6, 0);
- mga_outl(M_DR7, 0);
- mga_outl(M_DR8, green<<15);
- mga_outl(M_DR10, 0);
- mga_outl(M_DR11, 0);
- mga_outl(M_DR12, blue<<15);
- mga_outl(M_DR14, 0);
- mga_outl(M_DR15, 0);
-#else
- mga_fifo(2);
- mga_outl(M_DR2, dzdx);
- mga_outl(M_DR3, dzdy);
-#endif
-#endif
-
-#ifdef INTERP_RGB
- /* compute color deltas */
- eMaj_dr = v3->color[0] - v1->color[0];
- eBot_dr = v2->color[0] - v1->color[0];
- eMaj_dg = v3->color[1] - v1->color[1];
- eBot_dg = v2->color[1] - v1->color[1];
- eMaj_db = v3->color[2] - v1->color[2];
- eBot_db = v2->color[2] - v1->color[2];
-
- /* compute color increments */
- drdx = ((long long)(eMaj_dr * eBot_dy - eMaj_dy * eBot_dr)<<15) / area;
- drdy = ((long long)(eMaj_dx * eBot_dr - eMaj_dr * eBot_dx)<<15) / area;
- dgdx = ((long long)(eMaj_dg * eBot_dy - eMaj_dy * eBot_dg)<<15) / area;
- dgdy = ((long long)(eMaj_dx * eBot_dg - eMaj_dg * eBot_dx)<<15) / area;
- dbdx = ((long long)(eMaj_db * eBot_dy - eMaj_dy * eBot_db)<<15) / area;
- dbdy = ((long long)(eMaj_dx * eBot_db - eMaj_db * eBot_dx)<<15) / area;
-
- mga_fifo(6);
- mga_outl(M_DR6, drdx);
- mga_outl(M_DR7, drdy);
- mga_outl(M_DR10, dgdx);
- mga_outl(M_DR11, dgdy);
- mga_outl(M_DR14, dbdx);
- mga_outl(M_DR15, dbdy);
-#endif
-
- if (area > 0) { /* major edge on the right */
- if (eBot_dy) { /* have lower triangle */
- mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR0, eBot_dy);
- if (x2 < x1) {
- mga_outl(M_AR1, eBot_dx + eBot_dy - 1);
- mga_outl(M_AR2, eBot_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eBot_dx);
- mga_outl(M_AR2, -eBot_dx);
- }
-
- mga_outl(M_AR6, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR5, eMaj_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eMaj_dx);
- mga_outl(M_AR5, -eMaj_dx);
- }
-
- mga_outl(M_FXBNDRY, (x1<<16) | x1);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z1<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v1->color[0]<<15);
- mga_outl(M_DR8, v1->color[1]<<15);
- mga_outl(M_DR12, v1->color[2]<<15);
-#endif
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eBot_dy);
- } else { /* no lower triangle */
- mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR6, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR5, eMaj_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eMaj_dx);
- mga_outl(M_AR5, -eMaj_dx);
- }
-
- mga_outl(M_FXBNDRY, (x1<<16) | x2);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z2<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v2->color[0]<<15);
- mga_outl(M_DR8, v2->color[1]<<15);
- mga_outl(M_DR12, v2->color[2]<<15);
-#endif
- }
-
- /* draw upper triangle */
- if (eTop_dy) {
- mga_fifo(5);
- mga_outl(M_AR0, eTop_dy);
- if (x3 < x2) {
- mga_outl(M_AR1, eTop_dx + eTop_dy - 1);
- mga_outl(M_AR2, eTop_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eTop_dx);
- mga_outl(M_AR2, -eTop_dx);
- sgn &= ~M_SDXL;
- }
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eTop_dy);
- }
- } else { /* major edge on the left */
- if (eBot_dy) { /* have lower triangle */
- mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR0, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR2, eMaj_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eMaj_dx);
- mga_outl(M_AR2, -eMaj_dx);
- }
-
- mga_outl(M_AR6, eBot_dy);
- if (x2 < x1) {
- mga_outl(M_AR4, eBot_dx + eBot_dy - 1);
- mga_outl(M_AR5, eBot_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eBot_dx);
- mga_outl(M_AR5, -eBot_dx);
- }
-
- mga_outl(M_FXBNDRY, (x1<<16) | x1);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z1<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v1->color[0]<<15);
- mga_outl(M_DR8, v1->color[1]<<15);
- mga_outl(M_DR12, v1->color[2]<<15);
-#endif
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eBot_dy);
- } else { /* no lower triangle */
- mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
-
- mga_outl(M_AR0, eMaj_dy);
- if (x3 < x1) {
- mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
- mga_outl(M_AR2, eMaj_dx);
- sgn |= M_SDXL;
- } else {
- mga_outl(M_AR1, -eMaj_dx);
- mga_outl(M_AR2, -eMaj_dx);
- }
-
- mga_outl(M_FXBNDRY, (x2<<16) | x1);
-#ifdef INTERP_Z
- mga_outl(M_DR0, z1<<15);
-#endif
-#ifdef INTERP_RGB
- mga_outl(M_DR4, v1->color[0]<<15);
- mga_outl(M_DR8, v1->color[1]<<15);
- mga_outl(M_DR12, v1->color[2]<<15);
-#endif
- }
-
- /* draw upper triangle */
- if (eTop_dy) {
- mga_fifo(5);
- mga_outl(M_AR6, eTop_dy);
- if (x3 < x2) {
- mga_outl(M_AR4, eTop_dx + eTop_dy - 1);
- mga_outl(M_AR5, eTop_dx);
- sgn |= M_SDXR;
- } else {
- mga_outl(M_AR4, -eTop_dx);
- mga_outl(M_AR5, -eTop_dx);
- sgn &= ~M_SDXR;
- }
- mga_outl(M_SGN, sgn);
- mga_outl(M_LEN | M_EXEC, eTop_dy);
- }
- }
-}
-
-#undef FIFO_CNT_RGB
-#undef FIFO_CNT_Z
-
-#undef TRI_SWAP
-
-#undef SETUP_CODE
-#undef INTERP_RGB
-#undef INTERP_Z
-#undef CULL
-#undef TAG
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W triangle template + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +/* + * Triangle Rasterizer Template + * + * This file is #include'd to generate custom triangle rasterizers. + * + * The following macros may be defined to indicate what auxillary information + * must be interplated across the triangle: + * INTERP_Z - if defined, interpolate Z values + * INTERP_RGB - if defined, interpolate RGB values + * + * TAG - function name + * CULL - enable culling for: 0=no, 1=back, -1=front + * + * SETUP_CODE - to be executed once per triangle (usually HW init) + * + * For flatshaded primitives, the provoking vertex is the final one. + * This code was designed for the origin to be in the upper-left corner. + * + * Inspired by triangle rasterizer code written by Brian Paul. + */ + + + +#define TRI_SWAP(a, b) \ +do { \ + const MGAvertex *tmp = a; \ + a = b; \ + b = tmp; \ +} while (0) + +void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3) +{ + int area; + int x1, y1, x2, y2, x3, y3; + int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy; +#ifdef INTERP_RGB +#define FIFO_CNT_RGB 3 + int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db; + int drdx, drdy, dgdx, dgdy, dbdx, dbdy; +#else +#define FIFO_CNT_RGB 0 +#endif +#ifdef INTERP_Z +#define FIFO_CNT_Z 1 + int dzdx, dzdy; + int eMaj_dz, eBot_dz; + int z1, z2, z3; +#else +#define FIFO_CNT_Z 0 +#endif + +#if defined(INTERP_Z) || defined(INTERP_RGB) +#ifndef INTERP_RGB + int red = v3->color[0]; + int green = v3->color[1]; + int blue = v3->color[2]; +#endif +#else + unsigned long color = mga_mixrgb_full(v3->color); +#endif + + int sgn = 0; + + /* sort along the vertical axis */ + if (v2->win[1] < v1->win[1]) { + TRI_SWAP(v1, v2); +#ifdef CULL + cull = -cull; +#endif + } + + if (v3->win[1] < v1->win[1]) { + TRI_SWAP(v1, v3); + TRI_SWAP(v2, v3); + } else if (v3->win[1] < v2->win[1]) { + TRI_SWAP(v2, v3); +#ifdef CULL + cull = -cull; +#endif + } + + x1 = v1->win[0]; + y1 = v1->win[1]; + x2 = v2->win[0]; + y2 = v2->win[1]; + x3 = v3->win[0]; + y3 = v3->win[1]; + + /* compute deltas for each edge */ + eMaj_dx = x3 - x1; + eMaj_dy = y3 - y1; + eBot_dx = x2 - x1; + eBot_dy = y2 - y1; + eTop_dx = x3 - x2; + eTop_dy = y3 - y2; + + /* compute area */ + if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) { + return; + } +#ifdef CULL + if ((area * cull) > 0) { + return; + } +#endif + + mga_select(); + + /* set engine state */ +#ifdef SETUP_CODE + SETUP_CODE +#endif + + /* draw lower triangle */ +#if defined(INTERP_Z) || defined(INTERP_RGB) + mga_fifo(1); +#else + mga_fifo(2); + mga_outl(M_FCOL, color); +#endif + mga_outl(M_YDST, y1); + +#ifdef INTERP_Z + z1 = v1->win[2]; + z2 = v2->win[2]; + z3 = v3->win[2]; + + /* compute d?/dx and d?/dy derivatives */ + eMaj_dz = z3 - z1; + eBot_dz = z2 - z1; + dzdx = ((long long)(eMaj_dz * eBot_dy - eMaj_dy * eBot_dz)<<15) / area; + dzdy = ((long long)(eMaj_dx * eBot_dz - eMaj_dz * eBot_dx)<<15) / area; + +#ifndef INTERP_RGB + mga_fifo(11); + mga_outl(M_DR2, dzdx); + mga_outl(M_DR3, dzdy); + mga_outl(M_DR4, red<<15); + mga_outl(M_DR6, 0); + mga_outl(M_DR7, 0); + mga_outl(M_DR8, green<<15); + mga_outl(M_DR10, 0); + mga_outl(M_DR11, 0); + mga_outl(M_DR12, blue<<15); + mga_outl(M_DR14, 0); + mga_outl(M_DR15, 0); +#else + mga_fifo(2); + mga_outl(M_DR2, dzdx); + mga_outl(M_DR3, dzdy); +#endif +#endif + +#ifdef INTERP_RGB + /* compute color deltas */ + eMaj_dr = v3->color[0] - v1->color[0]; + eBot_dr = v2->color[0] - v1->color[0]; + eMaj_dg = v3->color[1] - v1->color[1]; + eBot_dg = v2->color[1] - v1->color[1]; + eMaj_db = v3->color[2] - v1->color[2]; + eBot_db = v2->color[2] - v1->color[2]; + + /* compute color increments */ + drdx = ((long long)(eMaj_dr * eBot_dy - eMaj_dy * eBot_dr)<<15) / area; + drdy = ((long long)(eMaj_dx * eBot_dr - eMaj_dr * eBot_dx)<<15) / area; + dgdx = ((long long)(eMaj_dg * eBot_dy - eMaj_dy * eBot_dg)<<15) / area; + dgdy = ((long long)(eMaj_dx * eBot_dg - eMaj_dg * eBot_dx)<<15) / area; + dbdx = ((long long)(eMaj_db * eBot_dy - eMaj_dy * eBot_db)<<15) / area; + dbdy = ((long long)(eMaj_dx * eBot_db - eMaj_db * eBot_dx)<<15) / area; + + mga_fifo(6); + mga_outl(M_DR6, drdx); + mga_outl(M_DR7, drdy); + mga_outl(M_DR10, dgdx); + mga_outl(M_DR11, dgdy); + mga_outl(M_DR14, dbdx); + mga_outl(M_DR15, dbdy); +#endif + + if (area > 0) { /* major edge on the right */ + if (eBot_dy) { /* have lower triangle */ + mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR0, eBot_dy); + if (x2 < x1) { + mga_outl(M_AR1, eBot_dx + eBot_dy - 1); + mga_outl(M_AR2, eBot_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eBot_dx); + mga_outl(M_AR2, -eBot_dx); + } + + mga_outl(M_AR6, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR5, eMaj_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eMaj_dx); + mga_outl(M_AR5, -eMaj_dx); + } + + mga_outl(M_FXBNDRY, (x1<<16) | x1); +#ifdef INTERP_Z + mga_outl(M_DR0, z1<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v1->color[0]<<15); + mga_outl(M_DR8, v1->color[1]<<15); + mga_outl(M_DR12, v1->color[2]<<15); +#endif + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eBot_dy); + } else { /* no lower triangle */ + mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR6, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR5, eMaj_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eMaj_dx); + mga_outl(M_AR5, -eMaj_dx); + } + + mga_outl(M_FXBNDRY, (x1<<16) | x2); +#ifdef INTERP_Z + mga_outl(M_DR0, z2<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v2->color[0]<<15); + mga_outl(M_DR8, v2->color[1]<<15); + mga_outl(M_DR12, v2->color[2]<<15); +#endif + } + + /* draw upper triangle */ + if (eTop_dy) { + mga_fifo(5); + mga_outl(M_AR0, eTop_dy); + if (x3 < x2) { + mga_outl(M_AR1, eTop_dx + eTop_dy - 1); + mga_outl(M_AR2, eTop_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eTop_dx); + mga_outl(M_AR2, -eTop_dx); + sgn &= ~M_SDXL; + } + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eTop_dy); + } + } else { /* major edge on the left */ + if (eBot_dy) { /* have lower triangle */ + mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR0, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR2, eMaj_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eMaj_dx); + mga_outl(M_AR2, -eMaj_dx); + } + + mga_outl(M_AR6, eBot_dy); + if (x2 < x1) { + mga_outl(M_AR4, eBot_dx + eBot_dy - 1); + mga_outl(M_AR5, eBot_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eBot_dx); + mga_outl(M_AR5, -eBot_dx); + } + + mga_outl(M_FXBNDRY, (x1<<16) | x1); +#ifdef INTERP_Z + mga_outl(M_DR0, z1<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v1->color[0]<<15); + mga_outl(M_DR8, v1->color[1]<<15); + mga_outl(M_DR12, v1->color[2]<<15); +#endif + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eBot_dy); + } else { /* no lower triangle */ + mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB); + + mga_outl(M_AR0, eMaj_dy); + if (x3 < x1) { + mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1); + mga_outl(M_AR2, eMaj_dx); + sgn |= M_SDXL; + } else { + mga_outl(M_AR1, -eMaj_dx); + mga_outl(M_AR2, -eMaj_dx); + } + + mga_outl(M_FXBNDRY, (x2<<16) | x1); +#ifdef INTERP_Z + mga_outl(M_DR0, z1<<15); +#endif +#ifdef INTERP_RGB + mga_outl(M_DR4, v1->color[0]<<15); + mga_outl(M_DR8, v1->color[1]<<15); + mga_outl(M_DR12, v1->color[2]<<15); +#endif + } + + /* draw upper triangle */ + if (eTop_dy) { + mga_fifo(5); + mga_outl(M_AR6, eTop_dy); + if (x3 < x2) { + mga_outl(M_AR4, eTop_dx + eTop_dy - 1); + mga_outl(M_AR5, eTop_dx); + sgn |= M_SDXR; + } else { + mga_outl(M_AR4, -eTop_dx); + mga_outl(M_AR5, -eTop_dx); + sgn &= ~M_SDXR; + } + mga_outl(M_SGN, sgn); + mga_outl(M_LEN | M_EXEC, eTop_dy); + } + } +} + +#undef FIFO_CNT_RGB +#undef FIFO_CNT_Z + +#undef TRI_SWAP + +#undef SETUP_CODE +#undef INTERP_RGB +#undef INTERP_Z +#undef CULL +#undef TAG diff --git a/src/mesa/drivers/dos/mga/mga.c b/src/mesa/drivers/dos/mga/mga.c index 27afba0ba04..5b0ee6437ef 100644 --- a/src/mesa/drivers/dos/mga/mga.c +++ b/src/mesa/drivers/dos/mga/mga.c @@ -1,1536 +1,1536 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- *
- * Thanks to Shawn Hargreaves for FreeBE/AF
- */
-
-
-#include <dpmi.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "../internal.h"
-#include "mga_reg.h"
-#include "mga_hw.h"
-#include "mga_mode.h"
-#include "mga.h"
-
-
-
-/* cached drawing engine state */
-#define OP_NONE 0
-
-#define OP_DRAWRECT (\
- M_DWG_TRAP | /* opcod */ \
- M_DWG_BLK | /* atype */ \
- /* linear */ \
- M_DWG_NOZCMP | /* zmode */ \
- M_DWG_SOLID | /* solid */ \
- M_DWG_ARZERO | /* arzero */ \
- M_DWG_SGNZERO | /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC /* bop */ \
- /* trans */ \
- /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWRECT_TX32BGR (\
- M_DWG_TEXTURE_TRAP | /* opcod */ \
- M_DWG_I | /* atype */ \
- /* linear */ \
- M_DWG_NOZCMP | /* zmode */ \
- /* solid */ \
- M_DWG_ARZERO | /* arzero */ \
- M_DWG_SGNZERO | /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC | /* bop */ \
- /* trans */ \
- M_DWG_BU32BGR /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWRECT_TX24BGR (\
- M_DWG_TEXTURE_TRAP | /* opcod */ \
- M_DWG_I | /* atype */ \
- /* linear */ \
- M_DWG_NOZCMP | /* zmode */ \
- /* solid */ \
- M_DWG_ARZERO | /* arzero */ \
- M_DWG_SGNZERO | /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC | /* bop */ \
- /* trans */ \
- M_DWG_BU24BGR /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWLINE (\
- M_DWG_AUTOLINE_CLOSE | /* opcod */ \
- M_DWG_RPL | /* atype */ \
- /* linear */ \
- M_DWG_NOZCMP | /* zmode */ \
- M_DWG_SOLID | /* solid */ \
- /* arzero */ \
- /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC | /* bop */ \
- /* trans */ \
- M_DWG_BFCOL /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWLINE_I (\
- M_DWG_AUTOLINE_CLOSE | /* opcod */ \
- M_DWG_I | /* atype */ \
- /* linear */ \
- M_DWG_NOZCMP | /* zmode */ \
- /* solid */ \
- /* arzero */ \
- /* sgnzero */ \
- /* shftzero */ \
- M_DWG_BOP_SRC | /* bop */ \
- /* trans */ \
- M_DWG_BFCOL /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWLINE_ZI (\
- M_DWG_AUTOLINE_CLOSE | /* opcod */ \
- M_DWG_ZI | /* atype */ \
- /* linear */ \
- M_DWG_ZLT | /* zmode */ \
- /* solid */ \
- /* arzero */ \
- /* sgnzero */ \
- /* shftzero */ \
- M_DWG_BOP_SRC | /* bop */ \
- /* trans */ \
- M_DWG_BFCOL /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWTRAP (\
- M_DWG_TRAP | /* opcod */ \
- M_DWG_BLK | /* atype */ \
- /* linear */ \
- M_DWG_NOZCMP | /* zmode */ \
- M_DWG_SOLID | /* solid */ \
- /* arzero */ \
- /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC /* bop */ \
- /* trans */ \
- /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWTRAP_I (\
- M_DWG_TRAP | /* opcod */ \
- M_DWG_I | /* atype */ \
- /* linear */ \
- M_DWG_NOZCMP | /* zmode */ \
- /* solid */ \
- /* arzero */ \
- /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC /* bop */ \
- /* trans */ \
- /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_DRAWTRAP_ZI (\
- M_DWG_TRAP | /* opcod */ \
- M_DWG_ZI | /* atype */ \
- /* linear */ \
- M_DWG_ZLT | /* zmode */ \
- /* solid */ \
- /* arzero */ \
- /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC /* bop */ \
- /* trans */ \
- /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_ILOAD_32BGR (\
- M_DWG_ILOAD | /* opcod */ \
- M_DWG_RPL | /* atype */ \
- /* linear */ \
- /* zmode */ \
- /* solid */ \
- /* arzero */ \
- M_DWG_SGNZERO | /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC | /* bop */ \
- /* trans */ \
- M_DWG_BU32BGR /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-#define OP_ILOAD_24BGR (\
- M_DWG_ILOAD | /* opcod */ \
- M_DWG_RPL | /* atype */ \
- /* linear */ \
- /* zmode */ \
- /* solid */ \
- /* arzero */ \
- M_DWG_SGNZERO | /* sgnzero */ \
- M_DWG_SHFTZERO | /* shftzero */ \
- M_DWG_BOP_SRC | /* bop */ \
- /* trans */ \
- M_DWG_BU24BGR /* bltmod */ \
- /* pattern */ \
- /* transc */ )
-
-
-
-/* internal hardware data structures */
-static int interleave;
-static unsigned long zorg;
-static unsigned long vram;
-static char card_name[80];
-
-
-
-/* some info about current mode */
-static int __bpp, __bypp;
-static int __pixwidth, __bytwidth, __pagewidth, __width, __height, __zheight;
-static int __operation;
-static int __scrollx, __scrolly;
-
-
-
-/* buffers */
-static int mga_readbuffer, mga_writebuffer;
-static long mga_readbuffer_ptr, mga_writebuffer_ptr;
-static long mga_backbuffer_ptr, mga_frontbuffer_ptr;
-
-
-
-/* lookup table for scaling 2 bit colors up to 8 bits */
-static int _rgb_scale_2[4] = {
- 0, 85, 170, 255
-};
-
-/* lookup table for scaling 3 bit colors up to 8 bits */
-static int _rgb_scale_3[8] = {
- 0, 36, 73, 109, 146, 182, 219, 255
-};
-
-/* lookup table for scaling 5 bit colors up to 8 bits */
-static int _rgb_scale_5[32] = {
- 0, 8, 16, 25, 33, 41, 49, 58,
- 66, 74, 82, 90, 99, 107, 115, 123,
- 132, 140, 148, 156, 165, 173, 181, 189,
- 197, 206, 214, 222, 230, 239, 247, 255
-};
-
-/* lookup table for scaling 6 bit colors up to 8 bits */
-static int _rgb_scale_6[64] = {
- 0, 4, 8, 12, 16, 20, 24, 28,
- 32, 36, 40, 45, 49, 53, 57, 61,
- 65, 69, 73, 77, 81, 85, 89, 93,
- 97, 101, 105, 109, 113, 117, 121, 125,
- 130, 134, 138, 142, 146, 150, 154, 158,
- 162, 166, 170, 174, 178, 182, 186, 190,
- 194, 198, 202, 206, 210, 215, 219, 223,
- 227, 231, 235, 239, 243, 247, 251, 255
-};
-
-
-
-/*
- * pixel/color routines
- */
-void (*mga_putpixel) (unsigned int offset, int color);
-int (*mga_getpixel) (unsigned int offset);
-void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]);
-int (*mga_mixrgb) (const unsigned char rgb[]);
-static int (*mga_mixrgb_full) (const unsigned char rgb[]);
-
-
-
-/* mga_fifo:
- * Waits until there are at least <n> free slots in the FIFO buffer.
- */
-#define mga_fifo(n) do { } while (mga_inb(M_FIFOSTATUS) < (n))
-
-
-
-static int _mga_rread (int port, int index)
-{
- mga_select();
- mga_outb(port, index);
- return mga_inb(port+1);
-}
-
-
-
-static void _mga_rwrite (int port, int index, int v)
-{
- mga_select();
- mga_outb(port, index);
- mga_outb(port+1, v);
-}
-
-
-
-static void _mga_ralter (int port, int index, int mask, int v)
-{
- int temp;
- temp = _mga_rread(port, index);
- temp &= (~mask);
- temp |= (v & mask);
- _mga_rwrite(port, index, temp);
-}
-
-
-
-/* WaitTillIdle:
- * Delay until the hardware controller has finished drawing.
- */
-void mga_wait_idle (void)
-{
- int tries = 2;
-
- /*hwptr_unselect(oldptr);*/
-
- mga_select();
-
- while (tries--) {
- do {
- } while (!(mga_inl(M_FIFOSTATUS) & 0x200));
-
- do {
- } while (mga_inl(M_STATUS) & 0x10000);
-
- mga_outb(M_CRTC_INDEX, 0);
- }
-
- /*hwptr_select(oldptr);*/
-}
-
-
-
-/* Desc: Waits for the next vertical sync period.
- *
- * In :
- * Out :
- *
- * Note:
- */
-static void _mga_wait_retrace (void)
-{
- int t1 = 0;
- int t2 = 0;
-
- do {
- t1 = t2;
- t2 = mga_inl(M_VCOUNT);
- } while (t2 >= t1);
-}
-
-
-
-/* Desc: fix scan lines
- *
- * In :
- * Out :
- *
- * Note:
- */
-static unsigned long _mga_fix_scans (unsigned long l)
-{
- unsigned long m = 0;
-
- switch (__bpp) {
- case 8:
- m = interleave?128:64;
- break;
- case 15:
- case 16:
- m = interleave?64:32;
- break;
- case 24:
- m = interleave?128:64;
- break;
- case 32:
- m = 32;
- break;
- }
-
- m -= 1;
- return (l + m) & ~m;
-}
-
-
-
-/* Desc: HW scrolling function
- *
- * In :
- * Out :
- *
- * Note: view Z-buffer in 16bit modes: _mga_display_start(0, 0, __height, 1)
- */
-void mga_display_start (long boffset, long x, long y, long waitVRT)
-{
- long addr;
-
- mga_select();
-
- if (waitVRT >= 0) {
-
- addr = __bytwidth * y + (boffset + x) * __bypp;
-
- if (interleave) {
- addr /= 8;
- } else {
- addr /= 4;
- }
-
- _mga_rwrite(M_CRTC_INDEX, 0x0D, (addr)&0xFF);
- _mga_rwrite(M_CRTC_INDEX, 0x0C, (addr>>8)&0xFF);
- _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x0F, (addr>>16)&0x0F);
-
- while (waitVRT--) {
- _mga_wait_retrace();
- }
- }
-
- __scrollx = x;
- __scrolly = y;
-}
-
-
-
-/* Desc: set READ buffer
- *
- * In : either FRONT or BACK buffer
- * Out :
- *
- * Note:
- */
-void mga_set_readbuffer (int buffer)
-{
- mga_readbuffer = buffer;
-
- mga_readbuffer_ptr = (mga_readbuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr;
-}
-
-
-
-/* Desc: set WRITE buffer
- *
- * In : either FRONT or BACK buffer
- * Out :
- *
- * Note:
- */
-void mga_set_writebuffer (int buffer)
-{
- mga_writebuffer = buffer;
-
- mga_writebuffer_ptr = (mga_writebuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr;
-
- mga_select();
- mga_fifo(1);
- mga_outl(M_YDSTORG, mga_writebuffer_ptr);
-
- __operation = OP_NONE;
-}
-
-
-
-/* Desc: swap buffers
- *
- * In : number of vertical retraces to wait
- * Out :
- *
- * Note:
- */
-void mga_swapbuffers (int swapinterval)
-{
- /* flip the buffers */
- mga_backbuffer_ptr ^= __pagewidth;
- mga_frontbuffer_ptr ^= __pagewidth;
-
- /* update READ/WRITE pointers */
- mga_set_readbuffer(mga_readbuffer);
- mga_set_writebuffer(mga_writebuffer);
-
- /* make sure we always see the FRONT buffer */
- mga_display_start(mga_frontbuffer_ptr, __scrollx, __scrolly, swapinterval);
-}
-
-
-
-/* Desc: color composition (w/o ALPHA)
- *
- * In : array of integers (R, G, B)
- * Out : color
- *
- * Note: -
- */
-static __inline int _mga_mixrgb8 (const unsigned char rgb[])
-{
- return (rgb[0]&0xe0)|((rgb[1]>>5)<<2)|(rgb[2]>>6);
-}
-static __inline int _mga_mixrgb15 (const unsigned char rgb[])
-{
- return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3);
-}
-static __inline int _mga_mixrgb16 (const unsigned char rgb[])
-{
- return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3);
-}
-static __inline int _mga_mixrgb32 (const unsigned char rgb[])
-{
- return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);
-}
-
-
-
-/* Desc: color composition (w/o ALPHA) + replication
- *
- * In : array of integers (R, G, B)
- * Out : color
- *
- * Note: -
- */
-static int _mga_mixrgb8_full (const unsigned char rgb[])
-{
- int color = _mga_mixrgb8(rgb);
- color |= color<<8;
- return (color<<16) | color;
-}
-static int _mga_mixrgb15_full (const unsigned char rgb[])
-{
- int color = _mga_mixrgb15(rgb);
- return (color<<16) | color;
-}
-static int _mga_mixrgb16_full (const unsigned char rgb[])
-{
- int color = _mga_mixrgb16(rgb);
- return (color<<16) | color;
-}
-#define _mga_mixrgb32_full _mga_mixrgb32
-
-
-
-/* Desc: putpixel
- *
- * In : pixel offset, pixel value
- * Out : -
- *
- * Note: uses current write buffer
- */
-static void _mga_putpixel8 (unsigned int offset, int color)
-{
- hwptr_pokeb(mgaptr.linear_map, mga_writebuffer_ptr + offset, color);
-}
-#define _mga_putpixel15 _mga_putpixel16
-static void _mga_putpixel16 (unsigned int offset, int color)
-{
- hwptr_pokew(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 2, color);
-}
-static void _mga_putpixel32 (unsigned int offset, int color)
-{
- hwptr_pokel(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 4, color);
-}
-
-
-
-/* Desc: pixel retrieval
- *
- * In : pixel offset
- * Out : pixel value
- *
- * Note: uses current read buffer
- */
-static __inline int _mga_getpixel8 (unsigned int offset)
-{
- return hwptr_peekb(mgaptr.linear_map, mga_readbuffer_ptr + offset);
-}
-#define _mga_getpixel15 _mga_getpixel16
-static __inline int _mga_getpixel16 (unsigned int offset)
-{
- return hwptr_peekw(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 2);
-}
-static __inline int _mga_getpixel32 (unsigned int offset)
-{
- return hwptr_peekl(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 4);
-}
-
-
-
-/* Desc: color decomposition
- *
- * In : pixel offset, array of integers to hold color components (R, G, B, A)
- * Out : -
- *
- * Note: uses current read buffer
- */
-static void _mga_getrgba8 (unsigned int offset, unsigned char rgba[4])
-{
- int c = _mga_getpixel8(offset);
- rgba[0] = _rgb_scale_3[(c >> 5) & 0x7];
- rgba[1] = _rgb_scale_3[(c >> 2) & 0x7];
- rgba[2] = _rgb_scale_2[c & 0x3];
- rgba[3] = 255;
-}
-static void _mga_getrgba15 (unsigned int offset, unsigned char rgba[4])
-{
- int c = _mga_getpixel15(offset);
- rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F];
- rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F];
- rgba[2] = _rgb_scale_5[c & 0x1F];
- rgba[3] = 255;
-}
-static void _mga_getrgba16 (unsigned int offset, unsigned char rgba[4])
-{
- int c = _mga_getpixel16(offset);
- rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F];
- rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F];
- rgba[2] = _rgb_scale_5[c & 0x1F];
- rgba[3] = 255;
-}
-static void _mga_getrgba32 (unsigned int offset, unsigned char rgba[4])
-{
- int c = _mga_getpixel32(offset);
- rgba[0] = c >> 16;
- rgba[1] = c >> 8;
- rgba[2] = c;
- rgba[3] = c >> 24;
-}
-
-
-
-/* Desc: RGB flat line
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2)
-{
- unsigned long color;
- int x1 = v1->win[0];
- int y1 = v1->win[1];
- int x2 = v2->win[0];
- int y2 = v2->win[1];
-
- if ((x1 == x2) && (y1 == y2)) {
- return;
- }
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWLINE) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWLINE);
- __operation = OP_DRAWLINE;
- }
-
- color = mga_mixrgb_full(v2->color);
-
- /* draw the line */
- mga_fifo(3);
- mga_outl(M_FCOL, color);
- mga_outl(M_XYSTRT, (y1<<16) | x1);
- mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
-}
-
-
-
-/* Desc: RGB flat Z-less line
- *
- * In :
- * Out :
- *
- * Note: I never figured out "diagonal increments"
- */
-void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2)
-{
- int z1, dz;
- int x1 = v1->win[0];
- int y1 = v1->win[1];
- int x2 = v2->win[0];
- int y2 = v2->win[1];
- int dx = abs(x2 - x1);
- int dy = abs(y2 - y1);
-
- if ((dx == 0) && (dy == 0)) {
- return;
- }
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWLINE_ZI) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWLINE_ZI);
- __operation = OP_DRAWLINE_ZI;
- }
-
- if (dx < dy) {
- dx = dy;
- }
-
- z1 = v1->win[2] << 15;
- dz = ((v2->win[2] << 15) - z1) / dx;
-
- /* draw the line */
- mga_fifo(14);
- mga_outl(M_DR0, z1);
- mga_outl(M_DR2, dz);
- mga_outl(M_DR3, dz);
- mga_outl(M_DR4, v2->color[0] << 15);
- mga_outl(M_DR6, 0);
- mga_outl(M_DR7, 0);
- mga_outl(M_DR8, v2->color[1] << 15);
- mga_outl(M_DR10, 0);
- mga_outl(M_DR11, 0);
- mga_outl(M_DR12, v2->color[2] << 15);
- mga_outl(M_DR14, 0);
- mga_outl(M_DR15, 0);
- mga_outl(M_XYSTRT, (y1<<16) | x1);
- mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
-}
-
-
-
-/* Desc: RGB iterated line
- *
- * In :
- * Out :
- *
- * Note: I never figured out "diagonal increments"
- */
-void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2)
-{
- int r1, g1, b1;
- int dr, dg, db;
- int x1 = v1->win[0];
- int y1 = v1->win[1];
- int x2 = v2->win[0];
- int y2 = v2->win[1];
- int dx = abs(x2 - x1);
- int dy = abs(y2 - y1);
-
- if ((dx == 0) && (dy == 0)) {
- return;
- }
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWLINE_I) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWLINE_I);
- __operation = OP_DRAWLINE_I;
- }
-
- if (dx < dy) {
- dx = dy;
- }
-
- r1 = v1->color[0] << 15;
- g1 = v1->color[1] << 15;
- b1 = v1->color[2] << 15;
- dr = ((v2->color[0] << 15) - r1) / dx;
- dg = ((v2->color[1] << 15) - g1) / dx;
- db = ((v2->color[2] << 15) - b1) / dx;
-
- /* draw the line */
- mga_fifo(11);
- mga_outl(M_DR4, r1);
- mga_outl(M_DR6, dr);
- mga_outl(M_DR7, dr);
- mga_outl(M_DR8, g1);
- mga_outl(M_DR10, dg);
- mga_outl(M_DR11, dg);
- mga_outl(M_DR12, b1);
- mga_outl(M_DR14, db);
- mga_outl(M_DR15, db);
- mga_outl(M_XYSTRT, (y1<<16) | x1);
- mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
-}
-
-
-
-/* Desc: RGB iterated Z-less line
- *
- * In :
- * Out :
- *
- * Note: I never figured out "diagonal increments"
- */
-void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2)
-{
- int z1, dz;
- int r1, g1, b1;
- int dr, dg, db;
- int x1 = v1->win[0];
- int y1 = v1->win[1];
- int x2 = v2->win[0];
- int y2 = v2->win[1];
- int dx = abs(x2 - x1);
- int dy = abs(y2 - y1);
-
- if ((dx == 0) && (dy == 0)) {
- return;
- }
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWLINE_ZI) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWLINE_ZI);
- __operation = OP_DRAWLINE_ZI;
- }
-
- if (dx < dy) {
- dx = dy;
- }
-
- z1 = v1->win[2] << 15;
- dz = ((v2->win[2] << 15) - z1) / dx;
-
- r1 = v1->color[0] << 15;
- g1 = v1->color[1] << 15;
- b1 = v1->color[2] << 15;
- dr = ((v2->color[0] << 15) - r1) / dx;
- dg = ((v2->color[1] << 15) - g1) / dx;
- db = ((v2->color[2] << 15) - b1) / dx;
-
- /* draw the line */
- mga_fifo(14);
- mga_outl(M_DR0, z1);
- mga_outl(M_DR2, dz);
- mga_outl(M_DR3, dz);
- mga_outl(M_DR4, r1);
- mga_outl(M_DR6, dr);
- mga_outl(M_DR7, dr);
- mga_outl(M_DR8, g1);
- mga_outl(M_DR10, dg);
- mga_outl(M_DR11, dg);
- mga_outl(M_DR12, b1);
- mga_outl(M_DR14, db);
- mga_outl(M_DR15, db);
- mga_outl(M_XYSTRT, (y1<<16) | x1);
- mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
-}
-
-
-
-/* Desc: RGB flat triangle
- *
- * In :
- * Out :
- *
- * Note:
- */
-#define TAG mga_draw_tri_rgb_flat
-#define CULL
-#define SETUP_CODE \
- if (__operation != OP_DRAWTRAP) { \
- mga_fifo(1); \
- mga_outl(M_DWGCTL, OP_DRAWTRAP); \
- __operation = OP_DRAWTRAP; \
- }
-#include "m_ttemp.h"
-
-
-
-/* Desc: RGB flat Z-less triangle
- *
- * In :
- * Out :
- *
- * Note:
- */
-#define TAG mga_draw_tri_rgb_flat_zless
-#define CULL
-#define INTERP_Z
-#define SETUP_CODE \
- if (__operation != OP_DRAWTRAP_ZI) { \
- mga_fifo(1); \
- mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \
- __operation = OP_DRAWTRAP_ZI; \
- }
-#include "m_ttemp.h"
-
-
-
-/* Desc: RGB iterated triangle
- *
- * In :
- * Out :
- *
- * Note:
- */
-#define TAG mga_draw_tri_rgb_iter
-#define CULL
-#define INTERP_RGB
-#define SETUP_CODE \
- if (__operation != OP_DRAWTRAP_I) { \
- mga_fifo(1); \
- mga_outl(M_DWGCTL, OP_DRAWTRAP_I); \
- __operation = OP_DRAWTRAP_I; \
- }
-#include "m_ttemp.h"
-
-
-
-/* Desc: RGB iterated Z-less triangle
- *
- * In :
- * Out :
- *
- * Note:
- */
-#define TAG mga_draw_tri_rgb_iter_zless
-#define CULL
-#define INTERP_Z
-#define INTERP_RGB
-#define SETUP_CODE \
- if (__operation != OP_DRAWTRAP_ZI) { \
- mga_fifo(1); \
- mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \
- __operation = OP_DRAWTRAP_ZI; \
- }
-#include "m_ttemp.h"
-
-
-
-/* Desc: RGB flat rectangle
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color)
-{
- if (__bpp == 8) {
- color |= color << 8;
- }
- if (__bpp <= 16) {
- color |= color << 16;
- }
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWRECT) {
-
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWRECT);
- __operation = OP_DRAWRECT;
- }
-
- /* draw the rectangle */
- mga_fifo(3);
- mga_outl(M_FCOL, color);
- mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
- mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
-}
-
-
-
-/* Desc: 32RGB textured span
- *
- * In :
- * Out :
- *
- * Note: 0 <= width <= 7*1024
- */
-void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap)
-{
- int i;
-
- if (!width) {
- return;
- }
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWRECT_TX32BGR) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR);
- __operation = OP_DRAWRECT_TX32BGR;
- }
-
- /* draw the rectangle */
- mga_fifo(2);
- mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
- mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1);
-
- /* copy data to the pseudo-dma window */
- i = 0;
- do {
- mga_outl(i, *bitmap);
- bitmap++;
- i += 4;
- } while (--width);
-}
-
-
-
-/* Desc: 24RGB textured span
- *
- * In :
- * Out :
- *
- * Note: 0 <= width <= 7*1024
- */
-void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap)
-{
- int i;
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWRECT_TX24BGR) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR);
- __operation = OP_DRAWRECT_TX24BGR;
- }
-
- /* draw the rectangle */
- mga_fifo(2);
- mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
- mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1);
-
- /* copy data to the pseudo-dma window */
- i = 0;
- width = (width * 3 + 3) / 4;
- while (width) {
- mga_outl(i & (7 * 1024 - 1), *bitmap);
- bitmap++;
- i += 4;
- width--;
- }
-}
-
-
-
-/* Desc: 32RGB textured rectangle
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap)
-{
- int i;
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWRECT_TX32BGR) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR);
- __operation = OP_DRAWRECT_TX32BGR;
- }
-
- /* draw the rectangle */
- mga_fifo(2);
- mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
- mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
-
- /* copy data to the pseudo-dma window */
- i = 0;
- width *= height;
- while (width) {
- mga_outl(i & (7 * 1024 - 1), *bitmap);
- bitmap++;
- i += 4;
- width--;
- }
-}
-
-
-
-/* Desc: 24RGB textured rectangle
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap)
-{
- int i;
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_DRAWRECT_TX24BGR) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR);
- __operation = OP_DRAWRECT_TX24BGR;
- }
-
- /* draw the rectangle */
- mga_fifo(2);
- mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
- mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
-
- /* copy data to the pseudo-dma window */
- i = 0;
- width = (width * height * 3 + 3) / 4;
- while (width) {
- mga_outl(i & (7 * 1024 - 1), *bitmap);
- bitmap++;
- i += 4;
- width--;
- }
-}
-
-
-
-/* Desc: copy 32RGB image to screen
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap)
-{
- int i;
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_ILOAD_32BGR) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_ILOAD_32BGR);
- __operation = OP_ILOAD_32BGR;
- }
-
- /* draw the bitmap */
- mga_fifo(5);
- mga_outl(M_AR0, width-1);
- mga_outl(M_AR3, 0);
- mga_outl(M_AR5, 0);
- mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left);
- mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
-
- /* copy data to the pseudo-dma window */
- i = 0;
- width *= height;
- while (width) {
- mga_outl(i & (7 * 1024 - 1), *bitmap);
- bitmap++;
- i += 4;
- width--;
- }
-}
-
-
-
-/* Desc: copy 24RGB image to screen
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap)
-{
- int i;
-
- mga_select();
-
- /* set engine state */
- if (__operation != OP_ILOAD_24BGR) {
- mga_fifo(1);
- mga_outl(M_DWGCTL, OP_ILOAD_24BGR);
- __operation = OP_ILOAD_24BGR;
- }
-
- /* draw the bitmap */
- mga_fifo(5);
- mga_outl(M_AR0, width-1);
- mga_outl(M_AR3, 0);
- mga_outl(M_AR5, 0);
- mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left);
- mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
-
- /* copy data to the pseudo-dma window */
- i = 0;
- width = (width * height * 3 + 3) / 4;
- while (width) {
- mga_outl(i & (7 * 1024 - 1), *bitmap);
- bitmap++;
- i += 4;
- width--;
- }
-}
-
-
-
-/* Desc: get Z-buffer value
- *
- * In :
- * Out :
- *
- * Note:
- */
-unsigned short mga_getz (int offset)
-{
- return hwptr_peekw(mgaptr.linear_map, zorg + (mga_readbuffer_ptr + offset) * 2);
-}
-
-
-
-/* Desc: put Z-buffer value
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_setz (int offset, unsigned short z)
-{
- hwptr_pokew(mgaptr.linear_map, zorg + (mga_writebuffer_ptr + offset) * 2, z);
-}
-
-
-
-/* Desc: clear Z-buffer
- *
- * In :
- * Out :
- *
- * Note: uses current write buffer
- */
-static void _mga_clear_zed (int left, int top, int width, int height, unsigned short z)
-{
- if (__bpp == 16) {
- /* GPU store (high bandwidth)
- * Hack alert:
- * can cause problems with concurrent FB accesses
- */
- mga_select();
- mga_fifo(1);
- mga_outl(M_YDSTORG, mga_writebuffer_ptr + zorg/2);
- mga_draw_rect_rgb_flat(left, top, width, height, z);
- mga_fifo(1);
- mga_outl(M_YDSTORG, mga_writebuffer_ptr);
- } else {
- /* CPU store */
- unsigned long i, zz = (z<<16) | z;
- unsigned long ofs = zorg + (top * __pixwidth + left + mga_writebuffer_ptr) * 2;
- hwptr_select(mgaptr.linear_map);
- while (height--) {
- i = width/2;
- while (i--) {
- hwptr_nspokel(mgaptr.linear_map, ofs, zz);
- ofs += 4;
- }
- if (width & 1) {
- hwptr_nspokew(mgaptr.linear_map, ofs, z);
- ofs += 2;
- }
- ofs += (__pixwidth - width) * 2;
- }
- }
-}
-
-
-
-/* Desc: clear color- and Z-buffer
- *
- * In : front = clear front buffer
- * back = clear back buffer
- * zed = clear depth buffer
- * left = leftmost pixel to be cleared
- * top = starting line
- * width = number of pixels
- * height = number of lines
- * color = color to clear to
- * z = z value (ignored if zed==0)
- * Out :
- *
- * Note:
- */
-void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z)
-{
- if (front) {
- if (mga_writebuffer == MGA_FRONTBUFFER) {
- mga_draw_rect_rgb_flat(left, top, width, height, color);
- if (zed) {
- _mga_clear_zed(left, top, width, height, z);
- }
- front = 0;
- }
- }
- if (back) {
- if (mga_writebuffer == MGA_BACKBUFFER) {
- mga_draw_rect_rgb_flat(left, top, width, height, color);
- if (zed) {
- _mga_clear_zed(left, top, width, height, z);
- }
- back = 0;
- }
- }
- if (front) {
- int old = mga_writebuffer;
- mga_set_writebuffer(MGA_FRONTBUFFER);
- mga_draw_rect_rgb_flat(left, top, width, height, color);
- if (zed) {
- _mga_clear_zed(left, top, width, height, z);
- }
- mga_set_writebuffer(old);
- front = 0;
- }
- if (back) {
- int old = mga_writebuffer;
- mga_set_writebuffer(MGA_BACKBUFFER);
- mga_draw_rect_rgb_flat(left, top, width, height, color);
- if (zed) {
- _mga_clear_zed(left, top, width, height, z);
- }
- mga_set_writebuffer(old);
- back = 0;
- }
-}
-
-
-
-/* Desc: Attempts to enter specified video mode.
- *
- * In : ptr to mode structure, number of pages, Z-buffer request, refresh rate
- * Out : 0 if success
- *
- * Note: also set up the accelerator engine
- */
-int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh)
-{
- static int mill_strides[] = { 640, 768, 800, 960, 1024, 1152, 1280, 1600, 1920, 2048, 0 };
- unsigned int i, used;
- MGA_MODE *p;
-
- if (mga_hw_init(&vram, &interleave, card_name) == 0) {
- return -1;
- }
-
- if ((p = mga_mode_find(width, height, bpp)) == NULL) {
- return -1;
- }
-
- __bpp = p->bpp;
- __width = __pagewidth = p->xres;
- __height = p->yres;
-
- if (buffers > 1) {
- __pagewidth = _mga_fix_scans(__pagewidth);
- __pixwidth = __pagewidth * buffers;
- } else {
- __pixwidth = __pagewidth;
- __pixwidth = _mga_fix_scans(__pixwidth);
- }
-
- for (i=0; mill_strides[i]; i++) {
- if (__pixwidth <= mill_strides[i]) {
- __pixwidth = mill_strides[i];
- break;
- }
- }
-
- __bypp = (__bpp+7)/8;
- __bytwidth = __pixwidth * __bypp;
-
- /* compute used memory: framebuffer + zbuffer */
- used = __bytwidth * __height;
- if (zbuffer) {
- zorg = (used + 511) & ~511;
- /* Hack alert:
- * a 16-bit Z-buffer size is (stride_in_pixels * number_of_lines * 2)
- * We cannot mess with the Z-buffer width, but we might decrease the
- * number of lines, if the user requests less than (screen_height). For
- * example with a 2MB card, one can have 640x480x16 display with 2 color
- * buffers and Z-buffer if the maximum requested height is 339:
- * Total = (640*480 * 2 + 640*339 * 2) * 2
- * However, this means the user must not write beyond the window's height
- * and if we'll ever implement moveable windows, we'll have to reconsider
- * this hack.
- */
-#if 1
- __zheight = height; /* smaller */
- used = zorg + __pixwidth * 2 * __zheight;
-#else
- __zheight = __height;
- used = zorg + __pixwidth * 2 * __zheight;
-#endif
- }
-
- if (mill_strides[i] && (vram>=used)) {
- /* enter mode */
- mga_mode_switch(p, refresh);
- /* change the scan line length */
- _mga_ralter(M_CRTC_INDEX, 0x14, 0x40, 0); /* disable DWORD */
- _mga_ralter(M_CRTC_INDEX, 0x17, 0x40, 0x40); /* wbmode = BYTE */
- if (interleave) {
- _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/16);
- _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/16)>>4)&0x30);
- } else {
- _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/8);
- _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/8)>>4)&0x30);
- }
- } else {
- return -1;
- }
-
- /* setup buffers */
- mga_frontbuffer_ptr = 0;
- if (buffers > 1) {
- mga_backbuffer_ptr = __pagewidth;
- mga_set_readbuffer(MGA_BACKBUFFER);
- mga_set_writebuffer(MGA_BACKBUFFER);
- } else {
- mga_backbuffer_ptr = 0;
- mga_set_readbuffer(MGA_FRONTBUFFER);
- mga_set_writebuffer(MGA_FRONTBUFFER);
- }
- mga_display_start(mga_frontbuffer_ptr, __scrollx = 0, __scrolly = 0, 1);
-
- /* set up the accelerator engine */
- mga_select();
-
- mga_fifo(8);
- mga_outl(M_PITCH, __pixwidth);
- mga_outl(M_PLNWT, 0xFFFFFFFF);
- mga_outl(M_OPMODE, M_DMA_BLIT);
- mga_outl(M_CXBNDRY, 0xFFFF0000);
- mga_outl(M_YTOP, 0x00000000);
- mga_outl(M_YBOT, 0x007FFFFF);
- mga_outl(M_ZORG, zorg);
-
-#define INITPTR(bpp) \
- mga_putpixel = _mga_putpixel##bpp; \
- mga_getrgba = _mga_getrgba##bpp; \
- mga_getpixel = _mga_getpixel##bpp; \
- mga_mixrgb = _mga_mixrgb##bpp; \
- mga_mixrgb_full = _mga_mixrgb##bpp##_full
-
- switch (__bpp) {
- case 8:
- mga_outl(M_MACCESS, 0);
- INITPTR(8);
- break;
- case 15:
- mga_outl(M_MACCESS, 0x80000001);
- INITPTR(15);
- break;
- case 16:
- mga_outl(M_MACCESS, 1);
- INITPTR(16);
- break;
- case 32:
- mga_outl(M_MACCESS, 2);
- INITPTR(32);
- break;
- }
-
-#undef INITPTR
-
- /* disable VGA aperture */
- i = mga_inb(M_MISC_R);
- mga_outb(M_MISC_W, i & ~2);
-
- /* clear Z-buffer (if any) */
- if (zbuffer) {
- unsigned long ofs = zorg;
- unsigned long len = zorg + __pixwidth * 2 * __zheight;
-
- hwptr_select(mgaptr.linear_map);
- for (; ofs<len; ofs+=4) {
- hwptr_nspokel(mgaptr.linear_map, ofs, -1);
- }
- }
-
- return 0;
-}
-
-
-
-/* Desc:
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_close (int restore, int unmap)
-{
- if (restore) {
- mga_mode_restore();
- }
- if (unmap) {
- mga_hw_fini();
- }
-}
-
-
-
-/* Desc: state retrieval
- *
- * In : parameter name, ptr to storage
- * Out : 0 if request successfully processed
- *
- * Note: -
- */
-int mga_get (int pname, int *params)
-{
- switch (pname) {
- case MGA_GET_CARD_NAME:
- strcat(strcpy((char *)params, "Matrox "), card_name);
- break;
- case MGA_GET_VRAM:
- params[0] = vram;
- break;
- case MGA_GET_CI_PREC:
- params[0] = 0;
- break;
- case MGA_GET_HPIXELS:
- params[0] = __pixwidth;
- break;
- case MGA_GET_SCREEN_SIZE:
- params[0] = __width;
- params[1] = __height;
- break;
- default:
- return -1;
- }
- return 0;
-}
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + * + * Thanks to Shawn Hargreaves for FreeBE/AF + */ + + +#include <dpmi.h> +#include <stdlib.h> +#include <string.h> + +#include "../internal.h" +#include "mga_reg.h" +#include "mga_hw.h" +#include "mga_mode.h" +#include "mga.h" + + + +/* cached drawing engine state */ +#define OP_NONE 0 + +#define OP_DRAWRECT (\ + M_DWG_TRAP | /* opcod */ \ + M_DWG_BLK | /* atype */ \ + /* linear */ \ + M_DWG_NOZCMP | /* zmode */ \ + M_DWG_SOLID | /* solid */ \ + M_DWG_ARZERO | /* arzero */ \ + M_DWG_SGNZERO | /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC /* bop */ \ + /* trans */ \ + /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWRECT_TX32BGR (\ + M_DWG_TEXTURE_TRAP | /* opcod */ \ + M_DWG_I | /* atype */ \ + /* linear */ \ + M_DWG_NOZCMP | /* zmode */ \ + /* solid */ \ + M_DWG_ARZERO | /* arzero */ \ + M_DWG_SGNZERO | /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC | /* bop */ \ + /* trans */ \ + M_DWG_BU32BGR /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWRECT_TX24BGR (\ + M_DWG_TEXTURE_TRAP | /* opcod */ \ + M_DWG_I | /* atype */ \ + /* linear */ \ + M_DWG_NOZCMP | /* zmode */ \ + /* solid */ \ + M_DWG_ARZERO | /* arzero */ \ + M_DWG_SGNZERO | /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC | /* bop */ \ + /* trans */ \ + M_DWG_BU24BGR /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWLINE (\ + M_DWG_AUTOLINE_CLOSE | /* opcod */ \ + M_DWG_RPL | /* atype */ \ + /* linear */ \ + M_DWG_NOZCMP | /* zmode */ \ + M_DWG_SOLID | /* solid */ \ + /* arzero */ \ + /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC | /* bop */ \ + /* trans */ \ + M_DWG_BFCOL /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWLINE_I (\ + M_DWG_AUTOLINE_CLOSE | /* opcod */ \ + M_DWG_I | /* atype */ \ + /* linear */ \ + M_DWG_NOZCMP | /* zmode */ \ + /* solid */ \ + /* arzero */ \ + /* sgnzero */ \ + /* shftzero */ \ + M_DWG_BOP_SRC | /* bop */ \ + /* trans */ \ + M_DWG_BFCOL /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWLINE_ZI (\ + M_DWG_AUTOLINE_CLOSE | /* opcod */ \ + M_DWG_ZI | /* atype */ \ + /* linear */ \ + M_DWG_ZLT | /* zmode */ \ + /* solid */ \ + /* arzero */ \ + /* sgnzero */ \ + /* shftzero */ \ + M_DWG_BOP_SRC | /* bop */ \ + /* trans */ \ + M_DWG_BFCOL /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWTRAP (\ + M_DWG_TRAP | /* opcod */ \ + M_DWG_BLK | /* atype */ \ + /* linear */ \ + M_DWG_NOZCMP | /* zmode */ \ + M_DWG_SOLID | /* solid */ \ + /* arzero */ \ + /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC /* bop */ \ + /* trans */ \ + /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWTRAP_I (\ + M_DWG_TRAP | /* opcod */ \ + M_DWG_I | /* atype */ \ + /* linear */ \ + M_DWG_NOZCMP | /* zmode */ \ + /* solid */ \ + /* arzero */ \ + /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC /* bop */ \ + /* trans */ \ + /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_DRAWTRAP_ZI (\ + M_DWG_TRAP | /* opcod */ \ + M_DWG_ZI | /* atype */ \ + /* linear */ \ + M_DWG_ZLT | /* zmode */ \ + /* solid */ \ + /* arzero */ \ + /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC /* bop */ \ + /* trans */ \ + /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_ILOAD_32BGR (\ + M_DWG_ILOAD | /* opcod */ \ + M_DWG_RPL | /* atype */ \ + /* linear */ \ + /* zmode */ \ + /* solid */ \ + /* arzero */ \ + M_DWG_SGNZERO | /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC | /* bop */ \ + /* trans */ \ + M_DWG_BU32BGR /* bltmod */ \ + /* pattern */ \ + /* transc */ ) +#define OP_ILOAD_24BGR (\ + M_DWG_ILOAD | /* opcod */ \ + M_DWG_RPL | /* atype */ \ + /* linear */ \ + /* zmode */ \ + /* solid */ \ + /* arzero */ \ + M_DWG_SGNZERO | /* sgnzero */ \ + M_DWG_SHFTZERO | /* shftzero */ \ + M_DWG_BOP_SRC | /* bop */ \ + /* trans */ \ + M_DWG_BU24BGR /* bltmod */ \ + /* pattern */ \ + /* transc */ ) + + + +/* internal hardware data structures */ +static int interleave; +static unsigned long zorg; +static unsigned long vram; +static char card_name[80]; + + + +/* some info about current mode */ +static int __bpp, __bypp; +static int __pixwidth, __bytwidth, __pagewidth, __width, __height, __zheight; +static int __operation; +static int __scrollx, __scrolly; + + + +/* buffers */ +static int mga_readbuffer, mga_writebuffer; +static long mga_readbuffer_ptr, mga_writebuffer_ptr; +static long mga_backbuffer_ptr, mga_frontbuffer_ptr; + + + +/* lookup table for scaling 2 bit colors up to 8 bits */ +static int _rgb_scale_2[4] = { + 0, 85, 170, 255 +}; + +/* lookup table for scaling 3 bit colors up to 8 bits */ +static int _rgb_scale_3[8] = { + 0, 36, 73, 109, 146, 182, 219, 255 +}; + +/* lookup table for scaling 5 bit colors up to 8 bits */ +static int _rgb_scale_5[32] = { + 0, 8, 16, 25, 33, 41, 49, 58, + 66, 74, 82, 90, 99, 107, 115, 123, + 132, 140, 148, 156, 165, 173, 181, 189, + 197, 206, 214, 222, 230, 239, 247, 255 +}; + +/* lookup table for scaling 6 bit colors up to 8 bits */ +static int _rgb_scale_6[64] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 45, 49, 53, 57, 61, + 65, 69, 73, 77, 81, 85, 89, 93, + 97, 101, 105, 109, 113, 117, 121, 125, + 130, 134, 138, 142, 146, 150, 154, 158, + 162, 166, 170, 174, 178, 182, 186, 190, + 194, 198, 202, 206, 210, 215, 219, 223, + 227, 231, 235, 239, 243, 247, 251, 255 +}; + + + +/* + * pixel/color routines + */ +void (*mga_putpixel) (unsigned int offset, int color); +int (*mga_getpixel) (unsigned int offset); +void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]); +int (*mga_mixrgb) (const unsigned char rgb[]); +static int (*mga_mixrgb_full) (const unsigned char rgb[]); + + + +/* mga_fifo: + * Waits until there are at least <n> free slots in the FIFO buffer. + */ +#define mga_fifo(n) do { } while (mga_inb(M_FIFOSTATUS) < (n)) + + + +static int _mga_rread (int port, int index) +{ + mga_select(); + mga_outb(port, index); + return mga_inb(port+1); +} + + + +static void _mga_rwrite (int port, int index, int v) +{ + mga_select(); + mga_outb(port, index); + mga_outb(port+1, v); +} + + + +static void _mga_ralter (int port, int index, int mask, int v) +{ + int temp; + temp = _mga_rread(port, index); + temp &= (~mask); + temp |= (v & mask); + _mga_rwrite(port, index, temp); +} + + + +/* WaitTillIdle: + * Delay until the hardware controller has finished drawing. + */ +void mga_wait_idle (void) +{ + int tries = 2; + + /*hwptr_unselect(oldptr);*/ + + mga_select(); + + while (tries--) { + do { + } while (!(mga_inl(M_FIFOSTATUS) & 0x200)); + + do { + } while (mga_inl(M_STATUS) & 0x10000); + + mga_outb(M_CRTC_INDEX, 0); + } + + /*hwptr_select(oldptr);*/ +} + + + +/* Desc: Waits for the next vertical sync period. + * + * In : + * Out : + * + * Note: + */ +static void _mga_wait_retrace (void) +{ + int t1 = 0; + int t2 = 0; + + do { + t1 = t2; + t2 = mga_inl(M_VCOUNT); + } while (t2 >= t1); +} + + + +/* Desc: fix scan lines + * + * In : + * Out : + * + * Note: + */ +static unsigned long _mga_fix_scans (unsigned long l) +{ + unsigned long m = 0; + + switch (__bpp) { + case 8: + m = interleave?128:64; + break; + case 15: + case 16: + m = interleave?64:32; + break; + case 24: + m = interleave?128:64; + break; + case 32: + m = 32; + break; + } + + m -= 1; + return (l + m) & ~m; +} + + + +/* Desc: HW scrolling function + * + * In : + * Out : + * + * Note: view Z-buffer in 16bit modes: _mga_display_start(0, 0, __height, 1) + */ +void mga_display_start (long boffset, long x, long y, long waitVRT) +{ + long addr; + + mga_select(); + + if (waitVRT >= 0) { + + addr = __bytwidth * y + (boffset + x) * __bypp; + + if (interleave) { + addr /= 8; + } else { + addr /= 4; + } + + _mga_rwrite(M_CRTC_INDEX, 0x0D, (addr)&0xFF); + _mga_rwrite(M_CRTC_INDEX, 0x0C, (addr>>8)&0xFF); + _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x0F, (addr>>16)&0x0F); + + while (waitVRT--) { + _mga_wait_retrace(); + } + } + + __scrollx = x; + __scrolly = y; +} + + + +/* Desc: set READ buffer + * + * In : either FRONT or BACK buffer + * Out : + * + * Note: + */ +void mga_set_readbuffer (int buffer) +{ + mga_readbuffer = buffer; + + mga_readbuffer_ptr = (mga_readbuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr; +} + + + +/* Desc: set WRITE buffer + * + * In : either FRONT or BACK buffer + * Out : + * + * Note: + */ +void mga_set_writebuffer (int buffer) +{ + mga_writebuffer = buffer; + + mga_writebuffer_ptr = (mga_writebuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr; + + mga_select(); + mga_fifo(1); + mga_outl(M_YDSTORG, mga_writebuffer_ptr); + + __operation = OP_NONE; +} + + + +/* Desc: swap buffers + * + * In : number of vertical retraces to wait + * Out : + * + * Note: + */ +void mga_swapbuffers (int swapinterval) +{ + /* flip the buffers */ + mga_backbuffer_ptr ^= __pagewidth; + mga_frontbuffer_ptr ^= __pagewidth; + + /* update READ/WRITE pointers */ + mga_set_readbuffer(mga_readbuffer); + mga_set_writebuffer(mga_writebuffer); + + /* make sure we always see the FRONT buffer */ + mga_display_start(mga_frontbuffer_ptr, __scrollx, __scrolly, swapinterval); +} + + + +/* Desc: color composition (w/o ALPHA) + * + * In : array of integers (R, G, B) + * Out : color + * + * Note: - + */ +static __inline int _mga_mixrgb8 (const unsigned char rgb[]) +{ + return (rgb[0]&0xe0)|((rgb[1]>>5)<<2)|(rgb[2]>>6); +} +static __inline int _mga_mixrgb15 (const unsigned char rgb[]) +{ + return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3); +} +static __inline int _mga_mixrgb16 (const unsigned char rgb[]) +{ + return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3); +} +static __inline int _mga_mixrgb32 (const unsigned char rgb[]) +{ + return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]); +} + + + +/* Desc: color composition (w/o ALPHA) + replication + * + * In : array of integers (R, G, B) + * Out : color + * + * Note: - + */ +static int _mga_mixrgb8_full (const unsigned char rgb[]) +{ + int color = _mga_mixrgb8(rgb); + color |= color<<8; + return (color<<16) | color; +} +static int _mga_mixrgb15_full (const unsigned char rgb[]) +{ + int color = _mga_mixrgb15(rgb); + return (color<<16) | color; +} +static int _mga_mixrgb16_full (const unsigned char rgb[]) +{ + int color = _mga_mixrgb16(rgb); + return (color<<16) | color; +} +#define _mga_mixrgb32_full _mga_mixrgb32 + + + +/* Desc: putpixel + * + * In : pixel offset, pixel value + * Out : - + * + * Note: uses current write buffer + */ +static void _mga_putpixel8 (unsigned int offset, int color) +{ + hwptr_pokeb(mgaptr.linear_map, mga_writebuffer_ptr + offset, color); +} +#define _mga_putpixel15 _mga_putpixel16 +static void _mga_putpixel16 (unsigned int offset, int color) +{ + hwptr_pokew(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 2, color); +} +static void _mga_putpixel32 (unsigned int offset, int color) +{ + hwptr_pokel(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 4, color); +} + + + +/* Desc: pixel retrieval + * + * In : pixel offset + * Out : pixel value + * + * Note: uses current read buffer + */ +static __inline int _mga_getpixel8 (unsigned int offset) +{ + return hwptr_peekb(mgaptr.linear_map, mga_readbuffer_ptr + offset); +} +#define _mga_getpixel15 _mga_getpixel16 +static __inline int _mga_getpixel16 (unsigned int offset) +{ + return hwptr_peekw(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 2); +} +static __inline int _mga_getpixel32 (unsigned int offset) +{ + return hwptr_peekl(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 4); +} + + + +/* Desc: color decomposition + * + * In : pixel offset, array of integers to hold color components (R, G, B, A) + * Out : - + * + * Note: uses current read buffer + */ +static void _mga_getrgba8 (unsigned int offset, unsigned char rgba[4]) +{ + int c = _mga_getpixel8(offset); + rgba[0] = _rgb_scale_3[(c >> 5) & 0x7]; + rgba[1] = _rgb_scale_3[(c >> 2) & 0x7]; + rgba[2] = _rgb_scale_2[c & 0x3]; + rgba[3] = 255; +} +static void _mga_getrgba15 (unsigned int offset, unsigned char rgba[4]) +{ + int c = _mga_getpixel15(offset); + rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F]; + rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F]; + rgba[2] = _rgb_scale_5[c & 0x1F]; + rgba[3] = 255; +} +static void _mga_getrgba16 (unsigned int offset, unsigned char rgba[4]) +{ + int c = _mga_getpixel16(offset); + rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F]; + rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F]; + rgba[2] = _rgb_scale_5[c & 0x1F]; + rgba[3] = 255; +} +static void _mga_getrgba32 (unsigned int offset, unsigned char rgba[4]) +{ + int c = _mga_getpixel32(offset); + rgba[0] = c >> 16; + rgba[1] = c >> 8; + rgba[2] = c; + rgba[3] = c >> 24; +} + + + +/* Desc: RGB flat line + * + * In : + * Out : + * + * Note: + */ +void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2) +{ + unsigned long color; + int x1 = v1->win[0]; + int y1 = v1->win[1]; + int x2 = v2->win[0]; + int y2 = v2->win[1]; + + if ((x1 == x2) && (y1 == y2)) { + return; + } + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWLINE) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWLINE); + __operation = OP_DRAWLINE; + } + + color = mga_mixrgb_full(v2->color); + + /* draw the line */ + mga_fifo(3); + mga_outl(M_FCOL, color); + mga_outl(M_XYSTRT, (y1<<16) | x1); + mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2); +} + + + +/* Desc: RGB flat Z-less line + * + * In : + * Out : + * + * Note: I never figured out "diagonal increments" + */ +void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2) +{ + int z1, dz; + int x1 = v1->win[0]; + int y1 = v1->win[1]; + int x2 = v2->win[0]; + int y2 = v2->win[1]; + int dx = abs(x2 - x1); + int dy = abs(y2 - y1); + + if ((dx == 0) && (dy == 0)) { + return; + } + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWLINE_ZI) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWLINE_ZI); + __operation = OP_DRAWLINE_ZI; + } + + if (dx < dy) { + dx = dy; + } + + z1 = v1->win[2] << 15; + dz = ((v2->win[2] << 15) - z1) / dx; + + /* draw the line */ + mga_fifo(14); + mga_outl(M_DR0, z1); + mga_outl(M_DR2, dz); + mga_outl(M_DR3, dz); + mga_outl(M_DR4, v2->color[0] << 15); + mga_outl(M_DR6, 0); + mga_outl(M_DR7, 0); + mga_outl(M_DR8, v2->color[1] << 15); + mga_outl(M_DR10, 0); + mga_outl(M_DR11, 0); + mga_outl(M_DR12, v2->color[2] << 15); + mga_outl(M_DR14, 0); + mga_outl(M_DR15, 0); + mga_outl(M_XYSTRT, (y1<<16) | x1); + mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2); +} + + + +/* Desc: RGB iterated line + * + * In : + * Out : + * + * Note: I never figured out "diagonal increments" + */ +void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2) +{ + int r1, g1, b1; + int dr, dg, db; + int x1 = v1->win[0]; + int y1 = v1->win[1]; + int x2 = v2->win[0]; + int y2 = v2->win[1]; + int dx = abs(x2 - x1); + int dy = abs(y2 - y1); + + if ((dx == 0) && (dy == 0)) { + return; + } + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWLINE_I) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWLINE_I); + __operation = OP_DRAWLINE_I; + } + + if (dx < dy) { + dx = dy; + } + + r1 = v1->color[0] << 15; + g1 = v1->color[1] << 15; + b1 = v1->color[2] << 15; + dr = ((v2->color[0] << 15) - r1) / dx; + dg = ((v2->color[1] << 15) - g1) / dx; + db = ((v2->color[2] << 15) - b1) / dx; + + /* draw the line */ + mga_fifo(11); + mga_outl(M_DR4, r1); + mga_outl(M_DR6, dr); + mga_outl(M_DR7, dr); + mga_outl(M_DR8, g1); + mga_outl(M_DR10, dg); + mga_outl(M_DR11, dg); + mga_outl(M_DR12, b1); + mga_outl(M_DR14, db); + mga_outl(M_DR15, db); + mga_outl(M_XYSTRT, (y1<<16) | x1); + mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2); +} + + + +/* Desc: RGB iterated Z-less line + * + * In : + * Out : + * + * Note: I never figured out "diagonal increments" + */ +void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2) +{ + int z1, dz; + int r1, g1, b1; + int dr, dg, db; + int x1 = v1->win[0]; + int y1 = v1->win[1]; + int x2 = v2->win[0]; + int y2 = v2->win[1]; + int dx = abs(x2 - x1); + int dy = abs(y2 - y1); + + if ((dx == 0) && (dy == 0)) { + return; + } + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWLINE_ZI) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWLINE_ZI); + __operation = OP_DRAWLINE_ZI; + } + + if (dx < dy) { + dx = dy; + } + + z1 = v1->win[2] << 15; + dz = ((v2->win[2] << 15) - z1) / dx; + + r1 = v1->color[0] << 15; + g1 = v1->color[1] << 15; + b1 = v1->color[2] << 15; + dr = ((v2->color[0] << 15) - r1) / dx; + dg = ((v2->color[1] << 15) - g1) / dx; + db = ((v2->color[2] << 15) - b1) / dx; + + /* draw the line */ + mga_fifo(14); + mga_outl(M_DR0, z1); + mga_outl(M_DR2, dz); + mga_outl(M_DR3, dz); + mga_outl(M_DR4, r1); + mga_outl(M_DR6, dr); + mga_outl(M_DR7, dr); + mga_outl(M_DR8, g1); + mga_outl(M_DR10, dg); + mga_outl(M_DR11, dg); + mga_outl(M_DR12, b1); + mga_outl(M_DR14, db); + mga_outl(M_DR15, db); + mga_outl(M_XYSTRT, (y1<<16) | x1); + mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2); +} + + + +/* Desc: RGB flat triangle + * + * In : + * Out : + * + * Note: + */ +#define TAG mga_draw_tri_rgb_flat +#define CULL +#define SETUP_CODE \ + if (__operation != OP_DRAWTRAP) { \ + mga_fifo(1); \ + mga_outl(M_DWGCTL, OP_DRAWTRAP); \ + __operation = OP_DRAWTRAP; \ + } +#include "m_ttemp.h" + + + +/* Desc: RGB flat Z-less triangle + * + * In : + * Out : + * + * Note: + */ +#define TAG mga_draw_tri_rgb_flat_zless +#define CULL +#define INTERP_Z +#define SETUP_CODE \ + if (__operation != OP_DRAWTRAP_ZI) { \ + mga_fifo(1); \ + mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \ + __operation = OP_DRAWTRAP_ZI; \ + } +#include "m_ttemp.h" + + + +/* Desc: RGB iterated triangle + * + * In : + * Out : + * + * Note: + */ +#define TAG mga_draw_tri_rgb_iter +#define CULL +#define INTERP_RGB +#define SETUP_CODE \ + if (__operation != OP_DRAWTRAP_I) { \ + mga_fifo(1); \ + mga_outl(M_DWGCTL, OP_DRAWTRAP_I); \ + __operation = OP_DRAWTRAP_I; \ + } +#include "m_ttemp.h" + + + +/* Desc: RGB iterated Z-less triangle + * + * In : + * Out : + * + * Note: + */ +#define TAG mga_draw_tri_rgb_iter_zless +#define CULL +#define INTERP_Z +#define INTERP_RGB +#define SETUP_CODE \ + if (__operation != OP_DRAWTRAP_ZI) { \ + mga_fifo(1); \ + mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \ + __operation = OP_DRAWTRAP_ZI; \ + } +#include "m_ttemp.h" + + + +/* Desc: RGB flat rectangle + * + * In : + * Out : + * + * Note: + */ +void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color) +{ + if (__bpp == 8) { + color |= color << 8; + } + if (__bpp <= 16) { + color |= color << 16; + } + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWRECT) { + + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWRECT); + __operation = OP_DRAWRECT; + } + + /* draw the rectangle */ + mga_fifo(3); + mga_outl(M_FCOL, color); + mga_outl(M_FXBNDRY, ((left+width)<<16) | left); + mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height); +} + + + +/* Desc: 32RGB textured span + * + * In : + * Out : + * + * Note: 0 <= width <= 7*1024 + */ +void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap) +{ + int i; + + if (!width) { + return; + } + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWRECT_TX32BGR) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR); + __operation = OP_DRAWRECT_TX32BGR; + } + + /* draw the rectangle */ + mga_fifo(2); + mga_outl(M_FXBNDRY, ((left+width)<<16) | left); + mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1); + + /* copy data to the pseudo-dma window */ + i = 0; + do { + mga_outl(i, *bitmap); + bitmap++; + i += 4; + } while (--width); +} + + + +/* Desc: 24RGB textured span + * + * In : + * Out : + * + * Note: 0 <= width <= 7*1024 + */ +void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap) +{ + int i; + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWRECT_TX24BGR) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR); + __operation = OP_DRAWRECT_TX24BGR; + } + + /* draw the rectangle */ + mga_fifo(2); + mga_outl(M_FXBNDRY, ((left+width)<<16) | left); + mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1); + + /* copy data to the pseudo-dma window */ + i = 0; + width = (width * 3 + 3) / 4; + while (width) { + mga_outl(i & (7 * 1024 - 1), *bitmap); + bitmap++; + i += 4; + width--; + } +} + + + +/* Desc: 32RGB textured rectangle + * + * In : + * Out : + * + * Note: + */ +void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap) +{ + int i; + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWRECT_TX32BGR) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR); + __operation = OP_DRAWRECT_TX32BGR; + } + + /* draw the rectangle */ + mga_fifo(2); + mga_outl(M_FXBNDRY, ((left+width)<<16) | left); + mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height); + + /* copy data to the pseudo-dma window */ + i = 0; + width *= height; + while (width) { + mga_outl(i & (7 * 1024 - 1), *bitmap); + bitmap++; + i += 4; + width--; + } +} + + + +/* Desc: 24RGB textured rectangle + * + * In : + * Out : + * + * Note: + */ +void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap) +{ + int i; + + mga_select(); + + /* set engine state */ + if (__operation != OP_DRAWRECT_TX24BGR) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR); + __operation = OP_DRAWRECT_TX24BGR; + } + + /* draw the rectangle */ + mga_fifo(2); + mga_outl(M_FXBNDRY, ((left+width)<<16) | left); + mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height); + + /* copy data to the pseudo-dma window */ + i = 0; + width = (width * height * 3 + 3) / 4; + while (width) { + mga_outl(i & (7 * 1024 - 1), *bitmap); + bitmap++; + i += 4; + width--; + } +} + + + +/* Desc: copy 32RGB image to screen + * + * In : + * Out : + * + * Note: + */ +void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap) +{ + int i; + + mga_select(); + + /* set engine state */ + if (__operation != OP_ILOAD_32BGR) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_ILOAD_32BGR); + __operation = OP_ILOAD_32BGR; + } + + /* draw the bitmap */ + mga_fifo(5); + mga_outl(M_AR0, width-1); + mga_outl(M_AR3, 0); + mga_outl(M_AR5, 0); + mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left); + mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height); + + /* copy data to the pseudo-dma window */ + i = 0; + width *= height; + while (width) { + mga_outl(i & (7 * 1024 - 1), *bitmap); + bitmap++; + i += 4; + width--; + } +} + + + +/* Desc: copy 24RGB image to screen + * + * In : + * Out : + * + * Note: + */ +void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap) +{ + int i; + + mga_select(); + + /* set engine state */ + if (__operation != OP_ILOAD_24BGR) { + mga_fifo(1); + mga_outl(M_DWGCTL, OP_ILOAD_24BGR); + __operation = OP_ILOAD_24BGR; + } + + /* draw the bitmap */ + mga_fifo(5); + mga_outl(M_AR0, width-1); + mga_outl(M_AR3, 0); + mga_outl(M_AR5, 0); + mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left); + mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height); + + /* copy data to the pseudo-dma window */ + i = 0; + width = (width * height * 3 + 3) / 4; + while (width) { + mga_outl(i & (7 * 1024 - 1), *bitmap); + bitmap++; + i += 4; + width--; + } +} + + + +/* Desc: get Z-buffer value + * + * In : + * Out : + * + * Note: + */ +unsigned short mga_getz (int offset) +{ + return hwptr_peekw(mgaptr.linear_map, zorg + (mga_readbuffer_ptr + offset) * 2); +} + + + +/* Desc: put Z-buffer value + * + * In : + * Out : + * + * Note: + */ +void mga_setz (int offset, unsigned short z) +{ + hwptr_pokew(mgaptr.linear_map, zorg + (mga_writebuffer_ptr + offset) * 2, z); +} + + + +/* Desc: clear Z-buffer + * + * In : + * Out : + * + * Note: uses current write buffer + */ +static void _mga_clear_zed (int left, int top, int width, int height, unsigned short z) +{ + if (__bpp == 16) { + /* GPU store (high bandwidth) + * Hack alert: + * can cause problems with concurrent FB accesses + */ + mga_select(); + mga_fifo(1); + mga_outl(M_YDSTORG, mga_writebuffer_ptr + zorg/2); + mga_draw_rect_rgb_flat(left, top, width, height, z); + mga_fifo(1); + mga_outl(M_YDSTORG, mga_writebuffer_ptr); + } else { + /* CPU store */ + unsigned long i, zz = (z<<16) | z; + unsigned long ofs = zorg + (top * __pixwidth + left + mga_writebuffer_ptr) * 2; + hwptr_select(mgaptr.linear_map); + while (height--) { + i = width/2; + while (i--) { + hwptr_nspokel(mgaptr.linear_map, ofs, zz); + ofs += 4; + } + if (width & 1) { + hwptr_nspokew(mgaptr.linear_map, ofs, z); + ofs += 2; + } + ofs += (__pixwidth - width) * 2; + } + } +} + + + +/* Desc: clear color- and Z-buffer + * + * In : front = clear front buffer + * back = clear back buffer + * zed = clear depth buffer + * left = leftmost pixel to be cleared + * top = starting line + * width = number of pixels + * height = number of lines + * color = color to clear to + * z = z value (ignored if zed==0) + * Out : + * + * Note: + */ +void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z) +{ + if (front) { + if (mga_writebuffer == MGA_FRONTBUFFER) { + mga_draw_rect_rgb_flat(left, top, width, height, color); + if (zed) { + _mga_clear_zed(left, top, width, height, z); + } + front = 0; + } + } + if (back) { + if (mga_writebuffer == MGA_BACKBUFFER) { + mga_draw_rect_rgb_flat(left, top, width, height, color); + if (zed) { + _mga_clear_zed(left, top, width, height, z); + } + back = 0; + } + } + if (front) { + int old = mga_writebuffer; + mga_set_writebuffer(MGA_FRONTBUFFER); + mga_draw_rect_rgb_flat(left, top, width, height, color); + if (zed) { + _mga_clear_zed(left, top, width, height, z); + } + mga_set_writebuffer(old); + front = 0; + } + if (back) { + int old = mga_writebuffer; + mga_set_writebuffer(MGA_BACKBUFFER); + mga_draw_rect_rgb_flat(left, top, width, height, color); + if (zed) { + _mga_clear_zed(left, top, width, height, z); + } + mga_set_writebuffer(old); + back = 0; + } +} + + + +/* Desc: Attempts to enter specified video mode. + * + * In : ptr to mode structure, number of pages, Z-buffer request, refresh rate + * Out : 0 if success + * + * Note: also set up the accelerator engine + */ +int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh) +{ + static int mill_strides[] = { 640, 768, 800, 960, 1024, 1152, 1280, 1600, 1920, 2048, 0 }; + unsigned int i, used; + MGA_MODE *p; + + if (mga_hw_init(&vram, &interleave, card_name) == 0) { + return -1; + } + + if ((p = mga_mode_find(width, height, bpp)) == NULL) { + return -1; + } + + __bpp = p->bpp; + __width = __pagewidth = p->xres; + __height = p->yres; + + if (buffers > 1) { + __pagewidth = _mga_fix_scans(__pagewidth); + __pixwidth = __pagewidth * buffers; + } else { + __pixwidth = __pagewidth; + __pixwidth = _mga_fix_scans(__pixwidth); + } + + for (i=0; mill_strides[i]; i++) { + if (__pixwidth <= mill_strides[i]) { + __pixwidth = mill_strides[i]; + break; + } + } + + __bypp = (__bpp+7)/8; + __bytwidth = __pixwidth * __bypp; + + /* compute used memory: framebuffer + zbuffer */ + used = __bytwidth * __height; + if (zbuffer) { + zorg = (used + 511) & ~511; + /* Hack alert: + * a 16-bit Z-buffer size is (stride_in_pixels * number_of_lines * 2) + * We cannot mess with the Z-buffer width, but we might decrease the + * number of lines, if the user requests less than (screen_height). For + * example with a 2MB card, one can have 640x480x16 display with 2 color + * buffers and Z-buffer if the maximum requested height is 339: + * Total = (640*480 * 2 + 640*339 * 2) * 2 + * However, this means the user must not write beyond the window's height + * and if we'll ever implement moveable windows, we'll have to reconsider + * this hack. + */ +#if 1 + __zheight = height; /* smaller */ + used = zorg + __pixwidth * 2 * __zheight; +#else + __zheight = __height; + used = zorg + __pixwidth * 2 * __zheight; +#endif + } + + if (mill_strides[i] && (vram>=used)) { + /* enter mode */ + mga_mode_switch(p, refresh); + /* change the scan line length */ + _mga_ralter(M_CRTC_INDEX, 0x14, 0x40, 0); /* disable DWORD */ + _mga_ralter(M_CRTC_INDEX, 0x17, 0x40, 0x40); /* wbmode = BYTE */ + if (interleave) { + _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/16); + _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/16)>>4)&0x30); + } else { + _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/8); + _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/8)>>4)&0x30); + } + } else { + return -1; + } + + /* setup buffers */ + mga_frontbuffer_ptr = 0; + if (buffers > 1) { + mga_backbuffer_ptr = __pagewidth; + mga_set_readbuffer(MGA_BACKBUFFER); + mga_set_writebuffer(MGA_BACKBUFFER); + } else { + mga_backbuffer_ptr = 0; + mga_set_readbuffer(MGA_FRONTBUFFER); + mga_set_writebuffer(MGA_FRONTBUFFER); + } + mga_display_start(mga_frontbuffer_ptr, __scrollx = 0, __scrolly = 0, 1); + + /* set up the accelerator engine */ + mga_select(); + + mga_fifo(8); + mga_outl(M_PITCH, __pixwidth); + mga_outl(M_PLNWT, 0xFFFFFFFF); + mga_outl(M_OPMODE, M_DMA_BLIT); + mga_outl(M_CXBNDRY, 0xFFFF0000); + mga_outl(M_YTOP, 0x00000000); + mga_outl(M_YBOT, 0x007FFFFF); + mga_outl(M_ZORG, zorg); + +#define INITPTR(bpp) \ + mga_putpixel = _mga_putpixel##bpp; \ + mga_getrgba = _mga_getrgba##bpp; \ + mga_getpixel = _mga_getpixel##bpp; \ + mga_mixrgb = _mga_mixrgb##bpp; \ + mga_mixrgb_full = _mga_mixrgb##bpp##_full + + switch (__bpp) { + case 8: + mga_outl(M_MACCESS, 0); + INITPTR(8); + break; + case 15: + mga_outl(M_MACCESS, 0x80000001); + INITPTR(15); + break; + case 16: + mga_outl(M_MACCESS, 1); + INITPTR(16); + break; + case 32: + mga_outl(M_MACCESS, 2); + INITPTR(32); + break; + } + +#undef INITPTR + + /* disable VGA aperture */ + i = mga_inb(M_MISC_R); + mga_outb(M_MISC_W, i & ~2); + + /* clear Z-buffer (if any) */ + if (zbuffer) { + unsigned long ofs = zorg; + unsigned long len = zorg + __pixwidth * 2 * __zheight; + + hwptr_select(mgaptr.linear_map); + for (; ofs<len; ofs+=4) { + hwptr_nspokel(mgaptr.linear_map, ofs, -1); + } + } + + return 0; +} + + + +/* Desc: + * + * In : + * Out : + * + * Note: + */ +void mga_close (int restore, int unmap) +{ + if (restore) { + mga_mode_restore(); + } + if (unmap) { + mga_hw_fini(); + } +} + + + +/* Desc: state retrieval + * + * In : parameter name, ptr to storage + * Out : 0 if request successfully processed + * + * Note: - + */ +int mga_get (int pname, int *params) +{ + switch (pname) { + case MGA_GET_CARD_NAME: + strcat(strcpy((char *)params, "Matrox "), card_name); + break; + case MGA_GET_VRAM: + params[0] = vram; + break; + case MGA_GET_CI_PREC: + params[0] = 0; + break; + case MGA_GET_HPIXELS: + params[0] = __pixwidth; + break; + case MGA_GET_SCREEN_SIZE: + params[0] = __width; + params[1] = __height; + break; + default: + return -1; + } + return 0; +} diff --git a/src/mesa/drivers/dos/mga/mga.h b/src/mesa/drivers/dos/mga/mga.h index d84fe72e269..0c074fa978f 100644 --- a/src/mesa/drivers/dos/mga/mga.h +++ b/src/mesa/drivers/dos/mga/mga.h @@ -1,91 +1,91 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef MGA_H_included
-#define MGA_H_included
-
-#define MGA_GET_CARD_NAME 0x0100
-#define MGA_GET_VRAM 0x0101
-#define MGA_GET_CI_PREC 0x0200
-#define MGA_GET_HPIXELS 0x0201
-#define MGA_GET_SCREEN_SIZE 0x0202
-
-int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh);
-void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z);
-int mga_get (int pname, int *params);
-void mga_close (int restore, int unmap);
-
-extern void (*mga_putpixel) (unsigned int offset, int color);
-extern int (*mga_getpixel) (unsigned int offset);
-extern void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]);
-extern int (*mga_mixrgb) (const unsigned char rgb[]);
-
-#define MGA_BACKBUFFER !0
-#define MGA_FRONTBUFFER 0
-void mga_set_readbuffer (int buffer);
-void mga_set_writebuffer (int buffer);
-void mga_swapbuffers (int swapinterval);
-
-unsigned short mga_getz (int offset);
-void mga_setz (int offset, unsigned short z);
-
-void mga_wait_idle (void);
-
-/*
- * vertex structure, used for primitive rendering
- */
-typedef struct {
- int win[4]; /* X, Y, Z, ? */
- unsigned char color[4]; /* R, G, B, A */
-} MGAvertex;
-
-void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2);
-void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2);
-void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2);
-void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2);
-
-void mga_draw_tri_rgb_flat (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
-void mga_draw_tri_rgb_flat_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
-void mga_draw_tri_rgb_iter (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
-void mga_draw_tri_rgb_iter_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
-
-void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color);
-void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap);
-void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap);
-void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap);
-void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap);
-
-void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap);
-void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap);
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef MGA_H_included +#define MGA_H_included + +#define MGA_GET_CARD_NAME 0x0100 +#define MGA_GET_VRAM 0x0101 +#define MGA_GET_CI_PREC 0x0200 +#define MGA_GET_HPIXELS 0x0201 +#define MGA_GET_SCREEN_SIZE 0x0202 + +int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh); +void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z); +int mga_get (int pname, int *params); +void mga_close (int restore, int unmap); + +extern void (*mga_putpixel) (unsigned int offset, int color); +extern int (*mga_getpixel) (unsigned int offset); +extern void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]); +extern int (*mga_mixrgb) (const unsigned char rgb[]); + +#define MGA_BACKBUFFER !0 +#define MGA_FRONTBUFFER 0 +void mga_set_readbuffer (int buffer); +void mga_set_writebuffer (int buffer); +void mga_swapbuffers (int swapinterval); + +unsigned short mga_getz (int offset); +void mga_setz (int offset, unsigned short z); + +void mga_wait_idle (void); + +/* + * vertex structure, used for primitive rendering + */ +typedef struct { + int win[4]; /* X, Y, Z, ? */ + unsigned char color[4]; /* R, G, B, A */ +} MGAvertex; + +void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2); +void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2); +void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2); +void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2); + +void mga_draw_tri_rgb_flat (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3); +void mga_draw_tri_rgb_flat_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3); +void mga_draw_tri_rgb_iter (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3); +void mga_draw_tri_rgb_iter_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3); + +void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color); +void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap); +void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap); +void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap); +void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap); + +void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap); +void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap); + +#endif diff --git a/src/mesa/drivers/dos/mga/mga_hw.c b/src/mesa/drivers/dos/mga/mga_hw.c index 08c1d7e54a4..b2e7d5cc925 100644 --- a/src/mesa/drivers/dos/mga/mga_hw.c +++ b/src/mesa/drivers/dos/mga/mga_hw.c @@ -1,416 +1,416 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W HW mapping
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <crt0.h>
-#include <dpmi.h>
-#include <pc.h>
-#include <string.h>
-#include <sys/nearptr.h>
-#include <sys/segments.h>
-
-#include "../internal.h"
-#include "mga_reg.h"
-#include "mga_hw.h"
-
-
-
-/* Hack alert:
- * these should really be externs
- */
-/* PCI access routines */
-static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle);
-static unsigned long pci_read_long (int handle, int index);
-static void pci_write_long (int handle, int index, unsigned long value);
-
-
-
-/* PCI device identifiers */
-#define MATROX_VENDOR_ID 0x102B
-
-typedef enum {
- MATROX_MILL_ID = 0x0519
-} MATROX_ID;
-
-static MATROX_ID matrox_id_list[] = {
- MATROX_MILL_ID,
- 0
-};
-
-
-
-/* internal hardware data structures */
-#if !MGA_FARPTR
-static int dirty;
-#endif
-static int bus_id;
-static unsigned long reg40;
-static unsigned long io_mem_base[4], linear_base;
-static unsigned long io_mem_size[4], linear_size;
-static MATROX_ID matrox_id;
-
-
-
-/* interface structures containing hardware pointer data */
-MGA_HWPTR mgaptr;
-
-
-
-/* Desc: create MMAP
- *
- * In :
- * Out :
- *
- * Note:
- */
-static int _create_mmap (__dpmi_paddr *m, unsigned long base, unsigned long size)
-{
-#if MGA_FARPTR
- int sel;
- if (_create_selector(&sel, base, size)) {
- return -1;
- }
- m->selector = sel;
- m->offset32 = 0;
-#else
- m->selector = _my_ds();
- if (_create_linear_mapping(&m->offset32, base, size)) {
- return -1;
- }
- m->offset32 -= __djgpp_base_address;
-#endif
- return 0;
-}
-
-
-
-/* Desc: destroy MMAP
- *
- * In :
- * Out :
- *
- * Note:
- */
-static void _destroy_mmap (__dpmi_paddr *m)
-{
-#if MGA_FARPTR
- int sel = m->selector;
- _remove_selector(&sel);
-#else
- m->offset32 += __djgpp_base_address;
- _remove_linear_mapping(&m->offset32);
-#endif
- m->selector = 0;
- m->offset32 = 0;
-}
-
-
-
-/* Desc: Counts amount of installed RAM
- *
- * In :
- * Out :
- *
- * Note:
- */
-static int _mga_get_vram (MATROX_ID chip, unsigned long base)
-{
- int ProbeSize = 8;
- int SizeFound = 2;
- unsigned char tmp;
- int i;
- __dpmi_paddr fb;
-
- switch (chip) {
- case MATROX_MILL_ID:
- ProbeSize = 8;
- break;
- }
-
- if (_create_mmap(&fb, base, ProbeSize*1024*1024)) {
- return 0;
- }
-
- /* turn MGA mode on - enable linear frame buffer (CRTCEXT3) */
- mga_select();
- mga_outb(M_CRTC_EXT_INDEX, 3);
- tmp = mga_inb(M_CRTC_EXT_DATA);
- mga_outb(M_CRTC_EXT_DATA, tmp | M_MGAMODE);
-
- /* write, read and compare method */
- for (i=ProbeSize; i>2; i-= 2) {
- hwptr_pokeb(fb, i*1024*1024 - 1, 0xAA);
- mga_select();
- mga_outb(M_CRTC_INDEX, 0); /* flush the cache */
- mga_inl(M_STATUS); /* delay */
- mga_inl(M_STATUS); /* delay */
- mga_inl(M_STATUS); /* delay */
- if (hwptr_peekb(fb, i*1024*1024 - 1) == 0xAA) {
- SizeFound = i;
- break;
- }
- }
-
- /* restore CRTCEXT3 state */
- mga_select();
- mga_outb(M_CRTC_EXT_INDEX, 3);
- mga_outb(M_CRTC_EXT_DATA, tmp);
-
- _destroy_mmap(&fb);
-
- return SizeFound*1024*1024;
-}
-
-
-
-/* Desc: Frees all resources allocated by MGA init code.
- *
- * In :
- * Out :
- *
- * Note:
- */
-void mga_hw_fini (void)
-{
- int i;
-
- pci_write_long(bus_id, 0x40, reg40);
-
- for (i=0; i<4; i++) {
- _destroy_mmap(&mgaptr.io_mem_map[i]);
- }
-
- _destroy_mmap(&mgaptr.linear_map);
-
-#if !MGA_FARPTR
- if (dirty) {
- __djgpp_nearptr_disable();
- dirty = FALSE;
- }
-#endif
-
- matrox_id = 0;
-}
-
-
-
-/* Desc: Attempts to detect MGA.
- *
- * In :
- * Out :
- *
- * Note: The first thing ever to be called. This is in charge of filling in
- * the driver header with all the required information and function
- * pointers. We do not yet have access to the video memory, so we can't
- * talk directly to the card.
- */
-int mga_hw_init (unsigned long *vram, int *interleave, char *name)
-{
- int i;
- unsigned long pci_base[2];
-
- if (matrox_id) {
- return matrox_id;
- }
-
-#if !MGA_FARPTR
- /* enable nearptr access */
- if (_crt0_startup_flags & _CRT0_FLAG_NEARPTR) {
- dirty = FALSE;
- } else {
- if (__djgpp_nearptr_enable() == 0)
- return NULL;
-
- dirty = TRUE;
- }
-#endif
-
- /* find PCI device */
- matrox_id = 0;
-
- for (bus_id=0, i=0; matrox_id_list[i]; i++) {
- if (pci_find_device(matrox_id_list[i], MATROX_VENDOR_ID, 0, &bus_id)) {
- matrox_id = matrox_id_list[i];
- break;
- }
- }
-
- /* set up the card name */
- switch (matrox_id) {
- case MATROX_MILL_ID:
- if (name) strcpy(name, "Millennium");
- break;
- default:
- matrox_id = 0;
- return -1;
- }
-
- reg40 = pci_read_long(bus_id, 0x40);
-#if 0 /* overclock a little :) */
- {
- int rfhcnt = (reg40 >> 16) & 0xF;
- if ((reg40 & 0x200000) && (rfhcnt < 0xC)) {
- pci_write_long(bus_id, 0x40, (reg40 & 0xFFF0FFFF) | 0x000C0000);
- }
- }
-#endif
-
- /* read hardware configuration data */
- for (i=0; i<2; i++)
- pci_base[i] = pci_read_long(bus_id, 16+i*4);
-
- /* work out the linear framebuffer and MMIO addresses */
- if (matrox_id == MATROX_MILL_ID) {
- if (pci_base[0])
- io_mem_base[0] = pci_base[0] & 0xFFFFC000;
-
- if (pci_base[1])
- linear_base = pci_base[1] & 0xFF800000;
- }
-
- if (!linear_base || !io_mem_base[0])
- return NULL;
-
- /* deal with the memory mapping crap */
- io_mem_size[0] = 0x4000;
-
- for (i=0; i<4; i++) {
- if (io_mem_base[i]) {
- if (_create_mmap(&mgaptr.io_mem_map[i], io_mem_base[i], io_mem_size[i])) {
- mga_hw_fini();
- return NULL;
- }
- }
- }
-
- *vram = linear_size = _mga_get_vram(matrox_id, linear_base);
-
- if (_create_mmap(&mgaptr.linear_map, linear_base, linear_size)) {
- mga_hw_fini();
- return NULL;
- }
-
- /* fill in user data */
- *interleave = linear_size > 2*1024*1024;
-
- return matrox_id;
-}
-
-
-
-/* PCI routines added by SET */
-#define PCIAddr 0xCF8
-#define PCIData 0xCFC
-#define PCIEnable 0x80000000
-
-
-
-/* FindPCIDevice:
- * Replacement for the INT 1A - PCI BIOS v2.0c+ - FIND PCI DEVICE, AX = B102h
- *
- * Note: deviceIndex is because a card can hold more than one PCI chip.
- *
- * Searches the board of the vendor supplied in vendorID with
- * identification number deviceID and index deviceIndex (normally 0).
- * The value returned in handle can be used to access the PCI registers
- * of this board.
- *
- * Return: 1 if found 0 if not found.
- */
-static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle)
-{
- int model, vendor, card, device;
- unsigned value, full_id, bus, busMax;
-
- deviceIndex <<= 8;
-
- /* for each PCI bus */
- for (bus=0, busMax=0x10000; bus<busMax; bus+=0x10000) {
-
- /* for each hardware device */
- for (device=0, card=0; card<32; card++, device+=0x800) {
- value = PCIEnable | bus | deviceIndex | device;
- outportl(PCIAddr, value);
- full_id = inportl(PCIData);
-
- /* get the vendor and model ID */
- vendor = full_id & 0xFFFF;
- model = full_id >> 16;
-
- if (vendor != 0xFFFF) {
- /* is this the one we want? */
- if ((deviceID == model) && (vendorID == vendor)) {
- *handle = value;
- return 1;
- }
-
- /* is it a bridge to a secondary bus? */
- outportl(PCIAddr, value | 8);
-
- if (((inportl(PCIData) >> 16) == 0x0600) || (full_id==0x00011011))
- busMax += 0x10000;
- }
- }
- }
-
- return 0;
-}
-
-
-
-/* Desc:
- *
- * In :
- * Out :
- *
- * Note:
- */
-static unsigned long pci_read_long (int handle, int index)
-{
- outportl(PCIAddr, PCIEnable | handle | index);
- return inportl(PCIData);
-}
-
-
-
-/* Desc:
- *
- * In :
- * Out :
- *
- * Note:
- */
-static void pci_write_long (int handle, int index, unsigned long value)
-{
- outportl(PCIAddr, PCIEnable | handle | index);
- outportl(PCIData, value);
-}
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.4 for Mesa -- MGA2064W HW mapping + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <crt0.h> +#include <dpmi.h> +#include <pc.h> +#include <string.h> +#include <sys/nearptr.h> +#include <sys/segments.h> + +#include "../internal.h" +#include "mga_reg.h" +#include "mga_hw.h" + + + +/* Hack alert: + * these should really be externs + */ +/* PCI access routines */ +static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle); +static unsigned long pci_read_long (int handle, int index); +static void pci_write_long (int handle, int index, unsigned long value); + + + +/* PCI device identifiers */ +#define MATROX_VENDOR_ID 0x102B + +typedef enum { + MATROX_MILL_ID = 0x0519 +} MATROX_ID; + +static MATROX_ID matrox_id_list[] = { + MATROX_MILL_ID, + 0 +}; + + + +/* internal hardware data structures */ +#if !MGA_FARPTR +static int dirty; +#endif +static int bus_id; +static unsigned long reg40; +static unsigned long io_mem_base[4], linear_base; +static unsigned long io_mem_size[4], linear_size; +static MATROX_ID matrox_id; + + + +/* interface structures containing hardware pointer data */ +MGA_HWPTR mgaptr; + + + +/* Desc: create MMAP + * + * In : + * Out : + * + * Note: + */ +static int _create_mmap (__dpmi_paddr *m, unsigned long base, unsigned long size) +{ +#if MGA_FARPTR + int sel; + if (_create_selector(&sel, base, size)) { + return -1; + } + m->selector = sel; + m->offset32 = 0; +#else + m->selector = _my_ds(); + if (_create_linear_mapping(&m->offset32, base, size)) { + return -1; + } + m->offset32 -= __djgpp_base_address; +#endif + return 0; +} + + + +/* Desc: destroy MMAP + * + * In : + * Out : + * + * Note: + */ +static void _destroy_mmap (__dpmi_paddr *m) +{ +#if MGA_FARPTR + int sel = m->selector; + _remove_selector(&sel); +#else + m->offset32 += __djgpp_base_address; + _remove_linear_mapping(&m->offset32); +#endif + m->selector = 0; + m->offset32 = 0; +} + + + +/* Desc: Counts amount of installed RAM + * + * In : + * Out : + * + * Note: + */ +static int _mga_get_vram (MATROX_ID chip, unsigned long base) +{ + int ProbeSize = 8; + int SizeFound = 2; + unsigned char tmp; + int i; + __dpmi_paddr fb; + + switch (chip) { + case MATROX_MILL_ID: + ProbeSize = 8; + break; + } + + if (_create_mmap(&fb, base, ProbeSize*1024*1024)) { + return 0; + } + + /* turn MGA mode on - enable linear frame buffer (CRTCEXT3) */ + mga_select(); + mga_outb(M_CRTC_EXT_INDEX, 3); + tmp = mga_inb(M_CRTC_EXT_DATA); + mga_outb(M_CRTC_EXT_DATA, tmp | M_MGAMODE); + + /* write, read and compare method */ + for (i=ProbeSize; i>2; i-= 2) { + hwptr_pokeb(fb, i*1024*1024 - 1, 0xAA); + mga_select(); + mga_outb(M_CRTC_INDEX, 0); /* flush the cache */ + mga_inl(M_STATUS); /* delay */ + mga_inl(M_STATUS); /* delay */ + mga_inl(M_STATUS); /* delay */ + if (hwptr_peekb(fb, i*1024*1024 - 1) == 0xAA) { + SizeFound = i; + break; + } + } + + /* restore CRTCEXT3 state */ + mga_select(); + mga_outb(M_CRTC_EXT_INDEX, 3); + mga_outb(M_CRTC_EXT_DATA, tmp); + + _destroy_mmap(&fb); + + return SizeFound*1024*1024; +} + + + +/* Desc: Frees all resources allocated by MGA init code. + * + * In : + * Out : + * + * Note: + */ +void mga_hw_fini (void) +{ + int i; + + pci_write_long(bus_id, 0x40, reg40); + + for (i=0; i<4; i++) { + _destroy_mmap(&mgaptr.io_mem_map[i]); + } + + _destroy_mmap(&mgaptr.linear_map); + +#if !MGA_FARPTR + if (dirty) { + __djgpp_nearptr_disable(); + dirty = FALSE; + } +#endif + + matrox_id = 0; +} + + + +/* Desc: Attempts to detect MGA. + * + * In : + * Out : + * + * Note: The first thing ever to be called. This is in charge of filling in + * the driver header with all the required information and function + * pointers. We do not yet have access to the video memory, so we can't + * talk directly to the card. + */ +int mga_hw_init (unsigned long *vram, int *interleave, char *name) +{ + int i; + unsigned long pci_base[2]; + + if (matrox_id) { + return matrox_id; + } + +#if !MGA_FARPTR + /* enable nearptr access */ + if (_crt0_startup_flags & _CRT0_FLAG_NEARPTR) { + dirty = FALSE; + } else { + if (__djgpp_nearptr_enable() == 0) + return 0; + + dirty = TRUE; + } +#endif + + /* find PCI device */ + matrox_id = 0; + + for (bus_id=0, i=0; matrox_id_list[i]; i++) { + if (pci_find_device(matrox_id_list[i], MATROX_VENDOR_ID, 0, &bus_id)) { + matrox_id = matrox_id_list[i]; + break; + } + } + + /* set up the card name */ + switch (matrox_id) { + case MATROX_MILL_ID: + if (name) strcpy(name, "Millennium"); + break; + default: + matrox_id = 0; + return -1; + } + + reg40 = pci_read_long(bus_id, 0x40); +#if 0 /* overclock a little :) */ + { + int rfhcnt = (reg40 >> 16) & 0xF; + if ((reg40 & 0x200000) && (rfhcnt < 0xC)) { + pci_write_long(bus_id, 0x40, (reg40 & 0xFFF0FFFF) | 0x000C0000); + } + } +#endif + + /* read hardware configuration data */ + for (i=0; i<2; i++) + pci_base[i] = pci_read_long(bus_id, 16+i*4); + + /* work out the linear framebuffer and MMIO addresses */ + if (matrox_id == MATROX_MILL_ID) { + if (pci_base[0]) + io_mem_base[0] = pci_base[0] & 0xFFFFC000; + + if (pci_base[1]) + linear_base = pci_base[1] & 0xFF800000; + } + + if (!linear_base || !io_mem_base[0]) + return 0; + + /* deal with the memory mapping crap */ + io_mem_size[0] = 0x4000; + + for (i=0; i<4; i++) { + if (io_mem_base[i]) { + if (_create_mmap(&mgaptr.io_mem_map[i], io_mem_base[i], io_mem_size[i])) { + mga_hw_fini(); + return 0; + } + } + } + + *vram = linear_size = _mga_get_vram(matrox_id, linear_base); + + if (_create_mmap(&mgaptr.linear_map, linear_base, linear_size)) { + mga_hw_fini(); + return 0; + } + + /* fill in user data */ + *interleave = linear_size > 2*1024*1024; + + return matrox_id; +} + + + +/* PCI routines added by SET */ +#define PCIAddr 0xCF8 +#define PCIData 0xCFC +#define PCIEnable 0x80000000 + + + +/* FindPCIDevice: + * Replacement for the INT 1A - PCI BIOS v2.0c+ - FIND PCI DEVICE, AX = B102h + * + * Note: deviceIndex is because a card can hold more than one PCI chip. + * + * Searches the board of the vendor supplied in vendorID with + * identification number deviceID and index deviceIndex (normally 0). + * The value returned in handle can be used to access the PCI registers + * of this board. + * + * Return: 1 if found 0 if not found. + */ +static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle) +{ + int model, vendor, card, device; + unsigned value, full_id, bus, busMax; + + deviceIndex <<= 8; + + /* for each PCI bus */ + for (bus=0, busMax=0x10000; bus<busMax; bus+=0x10000) { + + /* for each hardware device */ + for (device=0, card=0; card<32; card++, device+=0x800) { + value = PCIEnable | bus | deviceIndex | device; + outportl(PCIAddr, value); + full_id = inportl(PCIData); + + /* get the vendor and model ID */ + vendor = full_id & 0xFFFF; + model = full_id >> 16; + + if (vendor != 0xFFFF) { + /* is this the one we want? */ + if ((deviceID == model) && (vendorID == vendor)) { + *handle = value; + return 1; + } + + /* is it a bridge to a secondary bus? */ + outportl(PCIAddr, value | 8); + + if (((inportl(PCIData) >> 16) == 0x0600) || (full_id==0x00011011)) + busMax += 0x10000; + } + } + } + + return 0; +} + + + +/* Desc: + * + * In : + * Out : + * + * Note: + */ +static unsigned long pci_read_long (int handle, int index) +{ + outportl(PCIAddr, PCIEnable | handle | index); + return inportl(PCIData); +} + + + +/* Desc: + * + * In : + * Out : + * + * Note: + */ +static void pci_write_long (int handle, int index, unsigned long value) +{ + outportl(PCIAddr, PCIEnable | handle | index); + outportl(PCIData, value); +} diff --git a/src/mesa/drivers/dos/mga/mga_hw.h b/src/mesa/drivers/dos/mga/mga_hw.h index c6575b97f88..8cc266b49e7 100644 --- a/src/mesa/drivers/dos/mga/mga_hw.h +++ b/src/mesa/drivers/dos/mga/mga_hw.h @@ -1,113 +1,113 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W HW mapping
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef MGA_HW_included
-#define MGA_HW_included
-
-
-
-/* set this to zero to use near pointers */
-#define MGA_FARPTR 1
-
-
-
-/* access macros */
-#if MGA_FARPTR
-
-#include <sys/farptr.h>
-
-#define hwptr_pokeb(ptr, off, val) _farpokeb((ptr).selector, (ptr).offset32+(off), (val))
-#define hwptr_pokew(ptr, off, val) _farpokew((ptr).selector, (ptr).offset32+(off), (val))
-#define hwptr_pokel(ptr, off, val) _farpokel((ptr).selector, (ptr).offset32+(off), (val))
-
-#define hwptr_peekb(ptr, off) _farpeekb((ptr).selector, (ptr).offset32+(off))
-#define hwptr_peekw(ptr, off) _farpeekw((ptr).selector, (ptr).offset32+(off))
-#define hwptr_peekl(ptr, off) _farpeekl((ptr).selector, (ptr).offset32+(off))
-
-#define hwptr_select(ptr) _farsetsel((ptr).selector)
-#define hwptr_unselect(ptr) (ptr).selector = _fargetsel()
-
-#define hwptr_nspokeb(ptr, off, val) _farnspokeb((ptr).offset32+(off), (val))
-#define hwptr_nspokew(ptr, off, val) _farnspokew((ptr).offset32+(off), (val))
-#define hwptr_nspokel(ptr, off, val) _farnspokel((ptr).offset32+(off), (val))
-
-#define hwptr_nspeekb(ptr, off) _farnspeekb((ptr).offset32+(off))
-#define hwptr_nspeekw(ptr, off) _farnspeekw((ptr).offset32+(off))
-#define hwptr_nspeekl(ptr, off) _farnspeekl((ptr).offset32+(off))
-
-#else
-
-#define hwptr_pokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val)
-#define hwptr_pokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val)
-#define hwptr_pokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val)
-
-#define hwptr_peekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off))))
-#define hwptr_peekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off))))
-#define hwptr_peekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off))))
-
-#define hwptr_select(ptr)
-#define hwptr_unselect(ptr)
-
-#define hwptr_nspokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val)
-#define hwptr_nspokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val)
-#define hwptr_nspokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val)
-
-#define hwptr_nspeekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off))))
-#define hwptr_nspeekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off))))
-#define hwptr_nspeekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off))))
-
-#endif
-
-
-
-/* helpers for accessing the Matrox registers */
-#define mga_select() hwptr_select(mgaptr.io_mem_map[0])
-#define mga_inb(addr) hwptr_nspeekb(mgaptr.io_mem_map[0], addr)
-#define mga_inw(addr) hwptr_nspeekw(mgaptr.io_mem_map[0], addr)
-#define mga_inl(addr) hwptr_nspeekl(mgaptr.io_mem_map[0], addr)
-#define mga_outb(addr, val) hwptr_nspokeb(mgaptr.io_mem_map[0], addr, val)
-#define mga_outw(addr, val) hwptr_nspokew(mgaptr.io_mem_map[0], addr, val)
-#define mga_outl(addr, val) hwptr_nspokel(mgaptr.io_mem_map[0], addr, val)
-
-
-
-typedef struct MGA_HWPTR {
- __dpmi_paddr io_mem_map[4], linear_map;
-} MGA_HWPTR;
-
-extern MGA_HWPTR mgaptr;
-
-void mga_hw_fini (void);
-int mga_hw_init (unsigned long *vram, int *interleave, char *name);
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W HW mapping + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef MGA_HW_included +#define MGA_HW_included + + + +/* set this to zero to use near pointers */ +#define MGA_FARPTR 1 + + + +/* access macros */ +#if MGA_FARPTR + +#include <sys/farptr.h> + +#define hwptr_pokeb(ptr, off, val) _farpokeb((ptr).selector, (ptr).offset32+(off), (val)) +#define hwptr_pokew(ptr, off, val) _farpokew((ptr).selector, (ptr).offset32+(off), (val)) +#define hwptr_pokel(ptr, off, val) _farpokel((ptr).selector, (ptr).offset32+(off), (val)) + +#define hwptr_peekb(ptr, off) _farpeekb((ptr).selector, (ptr).offset32+(off)) +#define hwptr_peekw(ptr, off) _farpeekw((ptr).selector, (ptr).offset32+(off)) +#define hwptr_peekl(ptr, off) _farpeekl((ptr).selector, (ptr).offset32+(off)) + +#define hwptr_select(ptr) _farsetsel((ptr).selector) +#define hwptr_unselect(ptr) (ptr).selector = _fargetsel() + +#define hwptr_nspokeb(ptr, off, val) _farnspokeb((ptr).offset32+(off), (val)) +#define hwptr_nspokew(ptr, off, val) _farnspokew((ptr).offset32+(off), (val)) +#define hwptr_nspokel(ptr, off, val) _farnspokel((ptr).offset32+(off), (val)) + +#define hwptr_nspeekb(ptr, off) _farnspeekb((ptr).offset32+(off)) +#define hwptr_nspeekw(ptr, off) _farnspeekw((ptr).offset32+(off)) +#define hwptr_nspeekl(ptr, off) _farnspeekl((ptr).offset32+(off)) + +#else + +#define hwptr_pokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val) +#define hwptr_pokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val) +#define hwptr_pokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val) + +#define hwptr_peekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off)))) +#define hwptr_peekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off)))) +#define hwptr_peekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off)))) + +#define hwptr_select(ptr) +#define hwptr_unselect(ptr) + +#define hwptr_nspokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val) +#define hwptr_nspokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val) +#define hwptr_nspokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val) + +#define hwptr_nspeekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off)))) +#define hwptr_nspeekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off)))) +#define hwptr_nspeekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off)))) + +#endif + + + +/* helpers for accessing the Matrox registers */ +#define mga_select() hwptr_select(mgaptr.io_mem_map[0]) +#define mga_inb(addr) hwptr_nspeekb(mgaptr.io_mem_map[0], addr) +#define mga_inw(addr) hwptr_nspeekw(mgaptr.io_mem_map[0], addr) +#define mga_inl(addr) hwptr_nspeekl(mgaptr.io_mem_map[0], addr) +#define mga_outb(addr, val) hwptr_nspokeb(mgaptr.io_mem_map[0], addr, val) +#define mga_outw(addr, val) hwptr_nspokew(mgaptr.io_mem_map[0], addr, val) +#define mga_outl(addr, val) hwptr_nspokel(mgaptr.io_mem_map[0], addr, val) + + + +typedef struct MGA_HWPTR { + __dpmi_paddr io_mem_map[4], linear_map; +} MGA_HWPTR; + +extern MGA_HWPTR mgaptr; + +void mga_hw_fini (void); +int mga_hw_init (unsigned long *vram, int *interleave, char *name); + +#endif diff --git a/src/mesa/drivers/dos/mga/mga_mode.c b/src/mesa/drivers/dos/mga/mga_mode.c index 4c6d926111d..efba24ca691 100644 --- a/src/mesa/drivers/dos/mga/mga_mode.c +++ b/src/mesa/drivers/dos/mga/mga_mode.c @@ -1,231 +1,231 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W mode switching
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <dpmi.h>
-#include <string.h>
-#include <stubinfo.h>
-#include <sys/exceptn.h>
-#include <sys/farptr.h>
-#include <sys/movedata.h>
-#include <sys/segments.h>
-
-#include "../internal.h"
-#include "mga_mode.h"
-
-
-
-static MGA_MODE oldmode;
-static MGA_MODE modes[64];
-
-
-
-/*
- * VESA info
- */
-#define V_SIGN 0
-#define V_MINOR 4
-#define V_MAJOR 5
-#define V_OEM_OFS 6
-#define V_OEM_SEG 8
-#define V_MODE_OFS 14
-#define V_MODE_SEG 16
-#define V_MEMORY 18
-
-/*
- * mode info
- */
-#define M_ATTR 0
-#define M_GRAN 4
-#define M_SCANLEN 16
-#define M_XRES 18
-#define M_YRES 20
-#define M_BPP 25
-#define M_RED 31
-#define M_GREEN 33
-#define M_BLUE 35
-#define M_PHYS_PTR 40
-
-
-
-/* Desc: get available modes
- *
- * In : -
- * Out : linear modes list ptr
- *
- * Note: shouldn't use VESA...
- */
-static MGA_MODE *_mga_mode_check (void)
-{
- __dpmi_regs r;
- word16 *p;
- MGA_MODE *q;
- char vesa_info[512], tmp[512];
-
- _farpokel(_stubinfo->ds_selector, 0, 0x32454256);
- r.x.ax = 0x4f00;
- r.x.di = 0;
- r.x.es = _stubinfo->ds_segment;
- __dpmi_int(0x10, &r);
- movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);
- if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) {
- return NULL;
- }
-
- p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS]));
- q = modes;
- do {
- if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {
- break;
- }
-
- r.x.ax = 0x4f01;
- r.x.cx = q->mode;
- r.x.di = 512;
- r.x.es = _stubinfo->ds_segment;
- __dpmi_int(0x10, &r);
- movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);
- switch (tmp[M_BPP]) {
- case 16:
- q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE];
- break;
- case 8:
- case 15:
- case 24:
- case 32:
- q->bpp = tmp[M_BPP];
- break;
- default:
- q->bpp = 0;
- }
- if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp && (tmp[M_ATTR]&0x80)) {
- q->xres = _16_ tmp[M_XRES];
- q->yres = _16_ tmp[M_YRES];
- q->mode |= 0x4000;
- q++;
- }
- } while (TRUE);
-
- return modes;
-}
-
-
-
-/* Desc: save current mode
- *
- * In : ptr to mode structure
- * Out : 0 if success
- *
- * Note: shouldn't use VESA...
- */
-static int _mga_mode_save (MGA_MODE *p)
-{
- __asm("\n\
- movw $0x4f03, %%ax \n\
- int $0x10 \n\
- movl %%ebx, %0 \n\
- ":"=g"(p->mode)::"%eax", "%ebx");
- return 0;
-}
-
-
-
-/* Desc: switch to specified mode
- *
- * In : ptr to mode structure, refresh rate
- * Out : 0 if success
- *
- * Note: shouldn't use VESA...
- */
-int mga_mode_switch (MGA_MODE *p, int refresh)
-{
- if (oldmode.mode == 0) {
- _mga_mode_save(&oldmode);
- }
- __asm("movw $0x4f02, %%ax; int $0x10"::"b"(p->mode):"%eax");
- return 0;
-
- (void)refresh; /* silence compiler warning */
-}
-
-
-
-/* Desc: restore to the mode prior to first call to `mga_switch'
- *
- * In : -
- * Out : 0 if success
- *
- * Note: shouldn't use VESA...
- */
-int mga_mode_restore (void)
-{
- if (oldmode.mode != 0) {
- __asm("movw $0x4f02, %%ax; int $0x10"::"b"(oldmode.mode):"%eax");
- oldmode.mode = 0;
- }
- return 0;
-}
-
-
-
-/* Desc: return suitable mode
- *
- * In : width, height, bpp
- * Out : ptr to mode structure
- *
- * Note: -
- */
-MGA_MODE *mga_mode_find (int width, int height, int bpp)
-{
- static MGA_MODE *q = NULL;
-
- MGA_MODE *p;
- unsigned int min;
-
- if (q == NULL) {
- if ((q = _mga_mode_check()) == NULL) {
- return NULL;
- }
- }
-
- /* search for a mode that fits our request */
- for (min=-1, p=NULL; q->mode!=0xffff; q++) {
- if ((q->xres>=width) && (q->yres>=height) && (q->bpp==bpp)) {
- if (min>=(unsigned)(q->xres*q->yres)) {
- min = q->xres*q->yres;
- p = q;
- }
- }
- }
-
- return p;
-}
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W mode switching + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <dpmi.h> +#include <string.h> +#include <stubinfo.h> +#include <sys/exceptn.h> +#include <sys/farptr.h> +#include <sys/movedata.h> +#include <sys/segments.h> + +#include "../internal.h" +#include "mga_mode.h" + + + +static MGA_MODE oldmode; +static MGA_MODE modes[64]; + + + +/* + * VESA info + */ +#define V_SIGN 0 +#define V_MINOR 4 +#define V_MAJOR 5 +#define V_OEM_OFS 6 +#define V_OEM_SEG 8 +#define V_MODE_OFS 14 +#define V_MODE_SEG 16 +#define V_MEMORY 18 + +/* + * mode info + */ +#define M_ATTR 0 +#define M_GRAN 4 +#define M_SCANLEN 16 +#define M_XRES 18 +#define M_YRES 20 +#define M_BPP 25 +#define M_RED 31 +#define M_GREEN 33 +#define M_BLUE 35 +#define M_PHYS_PTR 40 + + + +/* Desc: get available modes + * + * In : - + * Out : linear modes list ptr + * + * Note: shouldn't use VESA... + */ +static MGA_MODE *_mga_mode_check (void) +{ + __dpmi_regs r; + word16 *p; + MGA_MODE *q; + char vesa_info[512], tmp[512]; + + _farpokel(_stubinfo->ds_selector, 0, 0x32454256); + r.x.ax = 0x4f00; + r.x.di = 0; + r.x.es = _stubinfo->ds_segment; + __dpmi_int(0x10, &r); + movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512); + if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) { + return NULL; + } + + p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS])); + q = modes; + do { + if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) { + break; + } + + r.x.ax = 0x4f01; + r.x.cx = q->mode; + r.x.di = 512; + r.x.es = _stubinfo->ds_segment; + __dpmi_int(0x10, &r); + movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256); + switch (tmp[M_BPP]) { + case 16: + q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE]; + break; + case 8: + case 15: + case 24: + case 32: + q->bpp = tmp[M_BPP]; + break; + default: + q->bpp = 0; + } + if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp && (tmp[M_ATTR]&0x80)) { + q->xres = _16_ tmp[M_XRES]; + q->yres = _16_ tmp[M_YRES]; + q->mode |= 0x4000; + q++; + } + } while (TRUE); + + return modes; +} + + + +/* Desc: save current mode + * + * In : ptr to mode structure + * Out : 0 if success + * + * Note: shouldn't use VESA... + */ +static int _mga_mode_save (MGA_MODE *p) +{ + __asm("\n\ + movw $0x4f03, %%ax \n\ + int $0x10 \n\ + movl %%ebx, %0 \n\ + ":"=g"(p->mode)::"%eax", "%ebx"); + return 0; +} + + + +/* Desc: switch to specified mode + * + * In : ptr to mode structure, refresh rate + * Out : 0 if success + * + * Note: shouldn't use VESA... + */ +int mga_mode_switch (MGA_MODE *p, int refresh) +{ + if (oldmode.mode == 0) { + _mga_mode_save(&oldmode); + } + __asm("movw $0x4f02, %%ax; int $0x10"::"b"(p->mode):"%eax"); + return 0; + + (void)refresh; /* silence compiler warning */ +} + + + +/* Desc: restore to the mode prior to first call to `mga_switch' + * + * In : - + * Out : 0 if success + * + * Note: shouldn't use VESA... + */ +int mga_mode_restore (void) +{ + if (oldmode.mode != 0) { + __asm("movw $0x4f02, %%ax; int $0x10"::"b"(oldmode.mode):"%eax"); + oldmode.mode = 0; + } + return 0; +} + + + +/* Desc: return suitable mode + * + * In : width, height, bpp + * Out : ptr to mode structure + * + * Note: - + */ +MGA_MODE *mga_mode_find (int width, int height, int bpp) +{ + static MGA_MODE *q = NULL; + + MGA_MODE *p; + unsigned int min; + + if (q == NULL) { + if ((q = _mga_mode_check()) == NULL) { + return NULL; + } + } + + /* search for a mode that fits our request */ + for (min=-1, p=NULL; q->mode!=0xffff; q++) { + if ((q->xres>=width) && (q->yres>=height) && (q->bpp==bpp)) { + if (min>=(unsigned)(q->xres*q->yres)) { + min = q->xres*q->yres; + p = q; + } + } + } + + return p; +} diff --git a/src/mesa/drivers/dos/mga/mga_mode.h b/src/mesa/drivers/dos/mga/mga_mode.h index b458d00d802..c9e04bc2ea2 100644 --- a/src/mesa/drivers/dos/mga/mga_mode.h +++ b/src/mesa/drivers/dos/mga/mga_mode.h @@ -1,47 +1,47 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W mode switching
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef MGA_MODE_included
-#define MGA_MODE_included
-
-typedef struct MGA_MODE {
- int mode;
- int xres, yres;
- int bpp;
-} MGA_MODE;
-
-int mga_mode_switch (MGA_MODE *p, int refresh);
-int mga_mode_restore (void);
-MGA_MODE *mga_mode_find (int width, int height, int bpp);
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W mode switching + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef MGA_MODE_included +#define MGA_MODE_included + +typedef struct MGA_MODE { + int mode; + int xres, yres; + int bpp; +} MGA_MODE; + +int mga_mode_switch (MGA_MODE *p, int refresh); +int mga_mode_restore (void); +MGA_MODE *mga_mode_find (int width, int height, int bpp); + +#endif diff --git a/src/mesa/drivers/dos/mga/mga_reg.h b/src/mesa/drivers/dos/mga/mga_reg.h index 4cd664ff967..11db81886b6 100644 --- a/src/mesa/drivers/dos/mga/mga_reg.h +++ b/src/mesa/drivers/dos/mga/mga_reg.h @@ -1,207 +1,207 @@ -/*
- * Mesa 3-D graphics library
- * Version: 5.0
- *
- * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W register mnemonics
- *
- * Copyright (c) 2003 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef MGA_REG_H_included
-#define MGA_REG_H_included
-
-/* Matrox hardware registers: */
-#define M_AR0 0x1C60
-#define M_AR1 0x1C64
-#define M_AR2 0x1C68
-#define M_AR3 0x1C6C
-#define M_AR4 0x1C70
-#define M_AR5 0x1C74
-#define M_AR6 0x1C78
-#define M_BCOL 0x1C20
-#define M_CXBNDRY 0x1C80
-#define M_CXLEFT 0x1CA0
-#define M_CXRIGHT 0x1CA4
-#define M_DR0 0x1CC0
-#define M_DR2 0x1CC8
-#define M_DR3 0x1CCC
-#define M_DR4 0x1CD0
-#define M_DR6 0x1CD8
-#define M_DR7 0x1CDC
-#define M_DR8 0x1CE0
-#define M_DR10 0x1CE8
-#define M_DR11 0x1CEC
-#define M_DR12 0x1CF0
-#define M_DR14 0x1CF8
-#define M_DR15 0x1CFC
-#define M_DWGCTL 0x1C00
-#define M_FCOL 0x1C24
-#define M_FIFOSTATUS 0x1E10
-#define M_FXBNDRY 0x1C84
-#define M_FXLEFT 0x1CA8
-#define M_FXRIGHT 0x1CAC
-#define M_ICLEAR 0x1E18
-#define M_IEN 0x1E1C
-#define M_LEN 0x1C5C
-#define M_MACCESS 0x1C04
-#define M_OPMODE 0x1E54
-#define M_PAT0 0x1C10
-#define M_PAT1 0x1C14
-#define M_PITCH 0x1C8C
-#define M_PLNWT 0x1C1C
-#define M_RESET 0x1E40
-#define M_SGN 0x1C58
-#define M_SHIFT 0x1C50
-#define M_SRC0 0x1C30
-#define M_SRC1 0x1C34
-#define M_SRC2 0x1C38
-#define M_SRC3 0x1C3C
-#define M_STATUS 0x1E14
-#define M_VCOUNT 0x1E20
-#define M_XDST 0x1CB0
-#define M_XYEND 0x1C44
-#define M_XYSTRT 0x1C40
-#define M_YBOT 0x1C9C
-#define M_YDST 0x1C90
-#define M_YDSTLEN 0x1C88
-#define M_YDSTORG 0x1C94
-#define M_YTOP 0x1C98
-#define M_ZORG 0x1C0C
-
-#define M_EXEC 0x0100
-
-/* DWGCTL: opcod */
-#define M_DWG_LINE_OPEN 0x0
-#define M_DWG_AUTOLINE_OPEN 0x1
-#define M_DWG_LINE_CLOSE 0x2
-#define M_DWG_AUTOLINE_CLOSE 0x3
-#define M_DWG_TRAP 0x4
-#define M_DWG_TEXTURE_TRAP 0x5
-#define M_DWG_BITBLT 0x8
-#define M_DWG_FBITBLT 0xC
-#define M_DWG_ILOAD 0x9
-#define M_DWG_ILOAD_SCALE 0xD
-#define M_DWG_ILOAD_FILTER 0xF
-#define M_DWG_IDUMP 0xA
-
-/* DWGCTL: atype */
-#define M_DWG_RPL (0x0 << 4)
-#define M_DWG_RSTR (0x1 << 4)
-#define M_DWG_ZI (0x3 << 4)
-#define M_DWG_BLK (0x4 << 4)
-#define M_DWG_I (0x7 << 4)
-
-/* DWGCTL: linear */
-#define M_DWG_LINEAR (0x1 << 7)
-
-/* DWGCTL: zmode */
-#define M_DWG_NOZCMP (0x0 << 8)
-#define M_DWG_ZE (0x2 << 8)
-#define M_DWG_ZNE (0x3 << 8)
-#define M_DWG_ZLT (0x4 << 8)
-#define M_DWG_ZLTE (0x5 << 8)
-#define M_DWG_ZGT (0x6 << 8)
-#define M_DWG_ZGTE (0x7 << 8)
-
-/* DWGCTL: solid */
-#define M_DWG_SOLID (0x1 << 11)
-
-/* DWGCTL: arzero */
-#define M_DWG_ARZERO (0x1 << 12)
-
-/* DWGCTL: sgnzero */
-#define M_DWG_SGNZERO (0x1 << 13)
-
-/* DWGCTL: shiftzero */
-#define M_DWG_SHFTZERO (0x1 << 14)
-
-/* DWGCTL: bop */
-#define M_DWG_BOP_XOR (0x6 << 16)
-#define M_DWG_BOP_AND (0x8 << 16)
-#define M_DWG_BOP_SRC (0xC << 16)
-#define M_DWG_BOP_OR (0xE << 16)
-
-/* DWGCTL: trans */
-#define M_DWG_TRANS_0 (0x0 << 20)
-#define M_DWG_TRANS_1 (0x1 << 20)
-#define M_DWG_TRANS_2 (0x2 << 20)
-#define M_DWG_TRANS_3 (0x3 << 20)
-#define M_DWG_TRANS_4 (0x4 << 20)
-#define M_DWG_TRANS_5 (0x5 << 20)
-#define M_DWG_TRANS_6 (0x6 << 20)
-#define M_DWG_TRANS_7 (0x7 << 20)
-#define M_DWG_TRANS_8 (0x8 << 20)
-#define M_DWG_TRANS_9 (0x9 << 20)
-#define M_DWG_TRANS_A (0xA << 20)
-#define M_DWG_TRANS_B (0xB << 20)
-#define M_DWG_TRANS_C (0xC << 20)
-#define M_DWG_TRANS_D (0xD << 20)
-#define M_DWG_TRANS_E (0xE << 20)
-#define M_DWG_TRANS_F (0xF << 20)
-
-/* DWGCTL: bltmod */
-#define M_DWG_BMONOLEF (0x0 << 25)
-#define M_DWG_BMONOWF (0x4 << 25)
-#define M_DWG_BPLAN (0x1 << 25)
-#define M_DWG_BFCOL (0x2 << 25)
-#define M_DWG_BUYUV (0xE << 25)
-#define M_DWG_BU32BGR (0x3 << 25)
-#define M_DWG_BU32RGB (0x7 << 25)
-#define M_DWG_BU24BGR (0xB << 25)
-#define M_DWG_BU24RGB (0xF << 25)
-
-/* DWGCTL: pattern */
-#define M_DWG_PATTERN (0x1 << 29)
-
-/* DWGCTL: transc */
-#define M_DWG_TRANSC (0x1 << 30)
-
-/* OPMODE: */
-#define M_DMA_GENERAL (0x0 << 2)
-#define M_DMA_BLIT (0x1 << 2)
-#define M_DMA_VECTOR (0x2 << 2)
-
-/* SGN: */
-#define M_SDXL (0x1 << 1)
-#define M_SDXR (0x1 << 5)
-
-
-
-/* VGAREG */
-#define M_CRTC_INDEX 0x1FD4
-#define M_CRTC_DATA 0x1FD5
-
-#define M_CRTC_EXT_INDEX 0x1FDE
-#define M_CRTC_EXT_DATA 0x1FDF
-
-#define M_MISC_R 0x1FCC
-#define M_MISC_W 0x1FC2
-
-/* CRTCEXT3: */
-#define M_MGAMODE (0x1 << 7)
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 5.0 + * + * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W register mnemonics + * + * Copyright (c) 2003 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef MGA_REG_H_included +#define MGA_REG_H_included + +/* Matrox hardware registers: */ +#define M_AR0 0x1C60 +#define M_AR1 0x1C64 +#define M_AR2 0x1C68 +#define M_AR3 0x1C6C +#define M_AR4 0x1C70 +#define M_AR5 0x1C74 +#define M_AR6 0x1C78 +#define M_BCOL 0x1C20 +#define M_CXBNDRY 0x1C80 +#define M_CXLEFT 0x1CA0 +#define M_CXRIGHT 0x1CA4 +#define M_DR0 0x1CC0 +#define M_DR2 0x1CC8 +#define M_DR3 0x1CCC +#define M_DR4 0x1CD0 +#define M_DR6 0x1CD8 +#define M_DR7 0x1CDC +#define M_DR8 0x1CE0 +#define M_DR10 0x1CE8 +#define M_DR11 0x1CEC +#define M_DR12 0x1CF0 +#define M_DR14 0x1CF8 +#define M_DR15 0x1CFC +#define M_DWGCTL 0x1C00 +#define M_FCOL 0x1C24 +#define M_FIFOSTATUS 0x1E10 +#define M_FXBNDRY 0x1C84 +#define M_FXLEFT 0x1CA8 +#define M_FXRIGHT 0x1CAC +#define M_ICLEAR 0x1E18 +#define M_IEN 0x1E1C +#define M_LEN 0x1C5C +#define M_MACCESS 0x1C04 +#define M_OPMODE 0x1E54 +#define M_PAT0 0x1C10 +#define M_PAT1 0x1C14 +#define M_PITCH 0x1C8C +#define M_PLNWT 0x1C1C +#define M_RESET 0x1E40 +#define M_SGN 0x1C58 +#define M_SHIFT 0x1C50 +#define M_SRC0 0x1C30 +#define M_SRC1 0x1C34 +#define M_SRC2 0x1C38 +#define M_SRC3 0x1C3C +#define M_STATUS 0x1E14 +#define M_VCOUNT 0x1E20 +#define M_XDST 0x1CB0 +#define M_XYEND 0x1C44 +#define M_XYSTRT 0x1C40 +#define M_YBOT 0x1C9C +#define M_YDST 0x1C90 +#define M_YDSTLEN 0x1C88 +#define M_YDSTORG 0x1C94 +#define M_YTOP 0x1C98 +#define M_ZORG 0x1C0C + +#define M_EXEC 0x0100 + +/* DWGCTL: opcod */ +#define M_DWG_LINE_OPEN 0x0 +#define M_DWG_AUTOLINE_OPEN 0x1 +#define M_DWG_LINE_CLOSE 0x2 +#define M_DWG_AUTOLINE_CLOSE 0x3 +#define M_DWG_TRAP 0x4 +#define M_DWG_TEXTURE_TRAP 0x5 +#define M_DWG_BITBLT 0x8 +#define M_DWG_FBITBLT 0xC +#define M_DWG_ILOAD 0x9 +#define M_DWG_ILOAD_SCALE 0xD +#define M_DWG_ILOAD_FILTER 0xF +#define M_DWG_IDUMP 0xA + +/* DWGCTL: atype */ +#define M_DWG_RPL (0x0 << 4) +#define M_DWG_RSTR (0x1 << 4) +#define M_DWG_ZI (0x3 << 4) +#define M_DWG_BLK (0x4 << 4) +#define M_DWG_I (0x7 << 4) + +/* DWGCTL: linear */ +#define M_DWG_LINEAR (0x1 << 7) + +/* DWGCTL: zmode */ +#define M_DWG_NOZCMP (0x0 << 8) +#define M_DWG_ZE (0x2 << 8) +#define M_DWG_ZNE (0x3 << 8) +#define M_DWG_ZLT (0x4 << 8) +#define M_DWG_ZLTE (0x5 << 8) +#define M_DWG_ZGT (0x6 << 8) +#define M_DWG_ZGTE (0x7 << 8) + +/* DWGCTL: solid */ +#define M_DWG_SOLID (0x1 << 11) + +/* DWGCTL: arzero */ +#define M_DWG_ARZERO (0x1 << 12) + +/* DWGCTL: sgnzero */ +#define M_DWG_SGNZERO (0x1 << 13) + +/* DWGCTL: shiftzero */ +#define M_DWG_SHFTZERO (0x1 << 14) + +/* DWGCTL: bop */ +#define M_DWG_BOP_XOR (0x6 << 16) +#define M_DWG_BOP_AND (0x8 << 16) +#define M_DWG_BOP_SRC (0xC << 16) +#define M_DWG_BOP_OR (0xE << 16) + +/* DWGCTL: trans */ +#define M_DWG_TRANS_0 (0x0 << 20) +#define M_DWG_TRANS_1 (0x1 << 20) +#define M_DWG_TRANS_2 (0x2 << 20) +#define M_DWG_TRANS_3 (0x3 << 20) +#define M_DWG_TRANS_4 (0x4 << 20) +#define M_DWG_TRANS_5 (0x5 << 20) +#define M_DWG_TRANS_6 (0x6 << 20) +#define M_DWG_TRANS_7 (0x7 << 20) +#define M_DWG_TRANS_8 (0x8 << 20) +#define M_DWG_TRANS_9 (0x9 << 20) +#define M_DWG_TRANS_A (0xA << 20) +#define M_DWG_TRANS_B (0xB << 20) +#define M_DWG_TRANS_C (0xC << 20) +#define M_DWG_TRANS_D (0xD << 20) +#define M_DWG_TRANS_E (0xE << 20) +#define M_DWG_TRANS_F (0xF << 20) + +/* DWGCTL: bltmod */ +#define M_DWG_BMONOLEF (0x0 << 25) +#define M_DWG_BMONOWF (0x4 << 25) +#define M_DWG_BPLAN (0x1 << 25) +#define M_DWG_BFCOL (0x2 << 25) +#define M_DWG_BUYUV (0xE << 25) +#define M_DWG_BU32BGR (0x3 << 25) +#define M_DWG_BU32RGB (0x7 << 25) +#define M_DWG_BU24BGR (0xB << 25) +#define M_DWG_BU24RGB (0xF << 25) + +/* DWGCTL: pattern */ +#define M_DWG_PATTERN (0x1 << 29) + +/* DWGCTL: transc */ +#define M_DWG_TRANSC (0x1 << 30) + +/* OPMODE: */ +#define M_DMA_GENERAL (0x0 << 2) +#define M_DMA_BLIT (0x1 << 2) +#define M_DMA_VECTOR (0x2 << 2) + +/* SGN: */ +#define M_SDXL (0x1 << 1) +#define M_SDXR (0x1 << 5) + + + +/* VGAREG */ +#define M_CRTC_INDEX 0x1FD4 +#define M_CRTC_DATA 0x1FD5 + +#define M_CRTC_EXT_INDEX 0x1FDE +#define M_CRTC_EXT_DATA 0x1FDF + +#define M_MISC_R 0x1FCC +#define M_MISC_W 0x1FC2 + +/* CRTCEXT3: */ +#define M_MGAMODE (0x1 << 7) + +#endif diff --git a/src/mesa/drivers/dos/vesa.c b/src/mesa/drivers/dos/vesa.c index cb8c29dfc71..ea5bcb7a86e 100644 --- a/src/mesa/drivers/dos/vesa.c +++ b/src/mesa/drivers/dos/vesa.c @@ -1,533 +1,533 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.1
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <dpmi.h>
-#include <pc.h>
-#include <stdlib.h>
-#include <stubinfo.h>
-#include <sys/exceptn.h>
-#include <sys/segments.h>
-#include <sys/farptr.h>
-#include <sys/movedata.h>
-
-#include "video.h"
-#include "vesa.h"
-
-
-
-static vl_mode modes[128];
-
-static word16 vesa_ver;
-static int banked_selector, linear_selector;
-static int oldmode = -1;
-
-static int vesa_color_precision = 6;
-
-static word16 *vesa_pmcode;
-unsigned int vesa_gran_mask, vesa_gran_shift;
-
-
-
-/*
- * VESA info
- */
-#define V_SIGN 0
-#define V_MINOR 4
-#define V_MAJOR 5
-#define V_OEM_OFS 6
-#define V_OEM_SEG 8
-#define V_MODE_OFS 14
-#define V_MODE_SEG 16
-#define V_MEMORY 18
-
-/*
- * mode info
- */
-#define M_ATTR 0
-#define M_GRAN 4
-#define M_SCANLEN 16
-#define M_XRES 18
-#define M_YRES 20
-#define M_BPP 25
-#define M_RED 31
-#define M_GREEN 33
-#define M_BLUE 35
-#define M_PHYS_PTR 40
-
-/*
- * VESA 3.0 CRTC timings structure
- */
-typedef struct CRTCInfoBlock {
- unsigned short HorizontalTotal;
- unsigned short HorizontalSyncStart;
- unsigned short HorizontalSyncEnd;
- unsigned short VerticalTotal;
- unsigned short VerticalSyncStart;
- unsigned short VerticalSyncEnd;
- unsigned char Flags;
- unsigned long PixelClock; /* units of Hz */
- unsigned short RefreshRate; /* units of 0.01 Hz */
- unsigned char reserved[40];
-} __PACKED__ CRTCInfoBlock;
-
-#define HNEG (1 << 2)
-#define VNEG (1 << 3)
-#define DOUBLESCAN (1 << 0)
-
-
-
-/* Desc: Attempts to detect VESA, check video modes and create selectors.
- *
- * In : -
- * Out : mode array
- *
- * Note: -
- */
-static vl_mode *vesa_init (void)
-{
- __dpmi_regs r;
- word16 *p;
- vl_mode *q;
- char vesa_info[512], tmp[512];
- int maxsize = 0;
- word32 linearfb = 0;
-
- if (vesa_ver) {
- return modes;
- }
-
- _farpokel(_stubinfo->ds_selector, 0, 0x32454256);
- r.x.ax = 0x4f00;
- r.x.di = 0;
- r.x.es = _stubinfo->ds_segment;
- __dpmi_int(0x10, &r);
- movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);
- if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) {
- return NULL;
- }
-
- p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS]));
- q = modes;
- do {
- if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {
- break;
- }
-
- r.x.ax = 0x4f01;
- r.x.cx = q->mode;
- r.x.di = 512;
- r.x.es = _stubinfo->ds_segment;
- __dpmi_int(0x10, &r);
- movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);
- switch (tmp[M_BPP]) {
- case 16:
- q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE];
- break;
- case 8:
- case 15:
- case 24:
- case 32:
- q->bpp = tmp[M_BPP];
- break;
- default:
- q->bpp = 0;
- }
- if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp) {
- q->xres = _16_ tmp[M_XRES];
- q->yres = _16_ tmp[M_YRES];
- q->scanlen = _16_ tmp[M_SCANLEN];
- q->gran = (_16_ tmp[M_GRAN])<<10;
- if (tmp[M_ATTR]&0x80) {
-#if 0
- *(q+1) = *q++;
-#else
- vl_mode *q1 = q + 1;
- *q1 = *q++;
-#endif
- linearfb = _32_ tmp[M_PHYS_PTR];
- q->mode |= 0x4000;
- }
- if (maxsize<(q->scanlen*q->yres)) {
- maxsize = q->scanlen*q->yres;
- }
- q++;
- }
- } while (TRUE);
-
- if (q==modes) {
- return NULL;
- }
- if (linearfb) {
- maxsize = ((maxsize+0xfffUL)&~0xfffUL);
- if (_create_selector(&linear_selector, linearfb, maxsize)) {
- return NULL;
- }
- }
- if (_create_selector(&banked_selector, 0xa0000, modes[0].gran)) {
- _remove_selector(&linear_selector);
- return NULL;
- }
-
- for (q=modes; q->mode!=0xffff; q++) {
- q->sel = (q->mode&0x4000) ? linear_selector : banked_selector;
- }
-
- if (vesa_info[V_MAJOR] >= 2) {
- r.x.ax = 0x4f0a;
- r.x.bx = 0;
- __dpmi_int(0x10, &r);
- if (r.x.ax == 0x004f) {
- vesa_pmcode = (word16 *)malloc(r.x.cx);
- movedata(__djgpp_dos_sel, (r.x.es << 4) + r.x.di, _my_ds(), (unsigned)vesa_pmcode, r.x.cx);
- if (vesa_pmcode[3]) {
- p = (word16 *)((long)vesa_pmcode + vesa_pmcode[3]);
- while (*p++ != 0xffff) ;
- } else {
- p = NULL;
- }
- if (p && (*p != 0xffff)) {
- free(vesa_pmcode);
- vesa_pmcode = NULL;
- } else {
- vesa_swbank = (void *)((long)vesa_pmcode + vesa_pmcode[0]);
- }
- }
- }
-
- vesa_ver = _16_ vesa_info[V_MINOR];
- return modes;
-}
-
-
-
-/* Desc: Frees all resources allocated by VESA init code.
- *
- * In : -
- * Out : -
- *
- * Note: -
- */
-static void vesa_fini (void)
-{
- if (vesa_ver) {
- _remove_selector(&linear_selector);
- _remove_selector(&banked_selector);
- if (vesa_pmcode != NULL) {
- free(vesa_pmcode);
- vesa_pmcode = NULL;
- }
- }
-}
-
-
-
-/* Desc: Uses VESA 3.0 function 0x4F0B to find the closest pixel clock to the requested value.
- *
- * In : mode, clock
- * Out : desired clock
- *
- * Note: -
- */
-static unsigned long _closest_pixclk (int mode_no, unsigned long vclk)
-{
- __dpmi_regs r;
-
- r.x.ax = 0x4F0B;
- r.h.bl = 0;
- r.d.ecx = vclk;
- r.x.dx = mode_no;
- __dpmi_int(0x10, &r);
-
- return (r.x.ax==0x004f) ? r.d.ecx : 0;
-}
-
-
-
-/* Desc: Calculates CRTC mode timings.
- *
- * In : crtc block, geometry, adjust
- * Out :
- *
- * Note:
- */
-static void _crtc_timing (CRTCInfoBlock *crtc, int xres, int yres, int xadjust, int yadjust)
-{
- int HTotal, VTotal;
- int HDisp, VDisp;
- int HSS, VSS;
- int HSE, VSE;
- int HSWidth, VSWidth;
- int SS, SE;
- int doublescan = FALSE;
-
- if (yres < 400) {
- doublescan = TRUE;
- yres *= 2;
- }
-
- HDisp = xres;
- HTotal = (int)(HDisp * 1.27) & ~0x7;
- HSWidth = (int)((HTotal - HDisp) / 5) & ~0x7;
- HSS = HDisp + 16;
- HSE = HSS + HSWidth;
- VDisp = yres;
- VTotal = VDisp * 1.07;
- VSWidth = (VTotal / 100) + 1;
- VSS = VDisp + ((int)(VTotal - VDisp) / 5) + 1;
- VSE = VSS + VSWidth;
-
- SS = HSS + xadjust;
- SE = HSE + xadjust;
-
- if (xadjust < 0) {
- if (SS < (HDisp + 8)) {
- SS = HDisp + 8;
- SE = SS + HSWidth;
- }
- } else {
- if ((HTotal - 24) < SE) {
- SE = HTotal - 24;
- SS = SE - HSWidth;
- }
- }
-
- HSS = SS;
- HSE = SE;
-
- SS = VSS + yadjust;
- SE = VSE + yadjust;
-
- if (yadjust < 0) {
- if (SS < (VDisp + 3)) {
- SS = VDisp + 3;
- SE = SS + VSWidth;
- }
- } else {
- if ((VTotal - 4) < SE) {
- SE = VTotal - 4;
- SS = SE - VSWidth;
- }
- }
-
- VSS = SS;
- VSE = SE;
-
- crtc->HorizontalTotal = HTotal;
- crtc->HorizontalSyncStart = HSS;
- crtc->HorizontalSyncEnd = HSE;
- crtc->VerticalTotal = VTotal;
- crtc->VerticalSyncStart = VSS;
- crtc->VerticalSyncEnd = VSE;
- crtc->Flags = HNEG | VNEG;
-
- if (doublescan)
- crtc->Flags |= DOUBLESCAN;
-}
-
-
-
-/* Desc: Attempts to enter specified video mode.
- *
- * In : ptr to mode structure, refresh rate
- * Out : 0 if success
- *
- * Note: -
- */
-static int vesa_entermode (vl_mode *p, int refresh)
-{
- __dpmi_regs r;
-
- if (p->mode & 0x4000) {
- VESA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
- } else {
- VESA.blit = vesa_b_dump_virtual;
- { int n; for (vesa_gran_shift=0, n=p->gran; n; vesa_gran_shift++, n>>=1) ; }
- vesa_gran_mask = (1<<(--vesa_gran_shift)) - 1;
- if ((unsigned)p->gran != (vesa_gran_mask+1)) {
- return !0;
- }
- }
-
- if (oldmode == -1) {
- r.x.ax = 0x4f03;
- __dpmi_int(0x10, &r);
- oldmode = r.x.bx;
- }
-
- r.x.ax = 0x4f02;
- r.x.bx = p->mode;
-
- if (refresh && ((vesa_ver>>8) >= 3)) {
- /* VESA 3.0 stuff for controlling the refresh rate */
- CRTCInfoBlock crtc;
- unsigned long vclk;
- double f0;
-
- _crtc_timing(&crtc, p->xres, p->yres, 0, 0);
-
- vclk = (double)crtc.HorizontalTotal * crtc.VerticalTotal * refresh;
- vclk = _closest_pixclk(p->mode, vclk);
-
- if (vclk != 0) {
- f0 = (double)vclk / (crtc.HorizontalTotal * crtc.VerticalTotal);
- /*_current_refresh_rate = (int)(f0 + 0.5);*/
-
- crtc.PixelClock = vclk;
- crtc.RefreshRate = refresh * 100;
-
- movedata(_my_ds(), (unsigned)&crtc, _stubinfo->ds_selector, 0, sizeof(crtc));
-
- r.x.di = 0;
- r.x.es = _stubinfo->ds_segment;
- r.x.bx |= 0x0800;
- }
- }
-
- __dpmi_int(0x10, &r);
- if (r.x.ax != 0x004f) {
- return !0;
- }
-
- if (p->bpp == 8) {
- r.x.ax = 0x4f08;
- r.x.bx = 0x0800;
- __dpmi_int(0x10, &r);
- if (r.x.ax == 0x004f) {
- r.x.ax = 0x4f08;
- r.h.bl = 0x01;
- __dpmi_int(0x10, &r);
- vesa_color_precision = r.h.bh;
- }
- }
-
- return 0;
-}
-
-
-
-/* Desc: Restores to the mode prior to first call to vesa_entermode.
- *
- * In : -
- * Out : -
- *
- * Note: -
- */
-static void vesa_restore (void)
-{
- __dpmi_regs r;
-
- if (oldmode != -1) {
- r.x.ax = 0x4f02;
- r.x.bx = oldmode;
- __dpmi_int(0x10, &r);
- }
-}
-
-
-
-/* Desc: set one palette entry
- *
- * In : color index, R, G, B
- * Out : -
- *
- * Note: uses integer values
- */
-static void vesa_setCI_i (int index, int red, int green, int blue)
-{
-#if 0
- __asm("\n\
- movw $0x1010, %%ax \n\
- movb %1, %%dh \n\
- movb %2, %%ch \n\
- int $0x10 \n\
- "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");
-#else
- outportb(0x03C8, index);
- outportb(0x03C9, red);
- outportb(0x03C9, green);
- outportb(0x03C9, blue);
-#endif
-}
-
-
-
-/* Desc: set one palette entry
- *
- * In : color index, R, G, B
- * Out : -
- *
- * Note: uses normalized values
- */
-static void vesa_setCI_f (int index, float red, float green, float blue)
-{
- float max = (1 << vesa_color_precision) - 1;
-
- vesa_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));
-}
-
-
-
-/* Desc: state retrieval
- *
- * In : parameter name, ptr to storage
- * Out : 0 if request successfully processed
- *
- * Note: -
- */
-static int vesa_get (int pname, int *params)
-{
- switch (pname) {
- case VL_GET_CI_PREC:
- params[0] = vesa_color_precision;
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-
-
-/*
- * the driver
- */
-vl_driver VESA = {
- vesa_init,
- vesa_entermode,
- NULL,
- vesa_setCI_f,
- vesa_setCI_i,
- vesa_get,
- vesa_restore,
- vesa_fini
-};
+/* + * Mesa 3-D graphics library + * Version: 4.1 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <dpmi.h> +#include <pc.h> +#include <stdlib.h> +#include <stubinfo.h> +#include <sys/exceptn.h> +#include <sys/segments.h> +#include <sys/farptr.h> +#include <sys/movedata.h> + +#include "video.h" +#include "vesa.h" + + + +static vl_mode modes[128]; + +static word16 vesa_ver; +static int banked_selector, linear_selector; +static int oldmode = -1; + +static int vesa_color_precision = 6; + +static word16 *vesa_pmcode; +unsigned int vesa_gran_mask, vesa_gran_shift; + + + +/* + * VESA info + */ +#define V_SIGN 0 +#define V_MINOR 4 +#define V_MAJOR 5 +#define V_OEM_OFS 6 +#define V_OEM_SEG 8 +#define V_MODE_OFS 14 +#define V_MODE_SEG 16 +#define V_MEMORY 18 + +/* + * mode info + */ +#define M_ATTR 0 +#define M_GRAN 4 +#define M_SCANLEN 16 +#define M_XRES 18 +#define M_YRES 20 +#define M_BPP 25 +#define M_RED 31 +#define M_GREEN 33 +#define M_BLUE 35 +#define M_PHYS_PTR 40 + +/* + * VESA 3.0 CRTC timings structure + */ +typedef struct CRTCInfoBlock { + unsigned short HorizontalTotal; + unsigned short HorizontalSyncStart; + unsigned short HorizontalSyncEnd; + unsigned short VerticalTotal; + unsigned short VerticalSyncStart; + unsigned short VerticalSyncEnd; + unsigned char Flags; + unsigned long PixelClock; /* units of Hz */ + unsigned short RefreshRate; /* units of 0.01 Hz */ + unsigned char reserved[40]; +} __PACKED__ CRTCInfoBlock; + +#define HNEG (1 << 2) +#define VNEG (1 << 3) +#define DOUBLESCAN (1 << 0) + + + +/* Desc: Attempts to detect VESA, check video modes and create selectors. + * + * In : - + * Out : mode array + * + * Note: - + */ +static vl_mode *vesa_init (void) +{ + __dpmi_regs r; + word16 *p; + vl_mode *q; + char vesa_info[512], tmp[512]; + int maxsize = 0; + word32 linearfb = 0; + + if (vesa_ver) { + return modes; + } + + _farpokel(_stubinfo->ds_selector, 0, 0x32454256); + r.x.ax = 0x4f00; + r.x.di = 0; + r.x.es = _stubinfo->ds_segment; + __dpmi_int(0x10, &r); + movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512); + if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) { + return NULL; + } + + p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS])); + q = modes; + do { + if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) { + break; + } + + r.x.ax = 0x4f01; + r.x.cx = q->mode; + r.x.di = 512; + r.x.es = _stubinfo->ds_segment; + __dpmi_int(0x10, &r); + movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256); + switch (tmp[M_BPP]) { + case 16: + q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE]; + break; + case 8: + case 15: + case 24: + case 32: + q->bpp = tmp[M_BPP]; + break; + default: + q->bpp = 0; + } + if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp) { + q->xres = _16_ tmp[M_XRES]; + q->yres = _16_ tmp[M_YRES]; + q->scanlen = _16_ tmp[M_SCANLEN]; + q->gran = (_16_ tmp[M_GRAN])<<10; + if (tmp[M_ATTR]&0x80) { +#if 0 + *(q+1) = *q++; +#else + vl_mode *q1 = q + 1; + *q1 = *q++; +#endif + linearfb = _32_ tmp[M_PHYS_PTR]; + q->mode |= 0x4000; + } + if (maxsize<(q->scanlen*q->yres)) { + maxsize = q->scanlen*q->yres; + } + q++; + } + } while (TRUE); + + if (q==modes) { + return NULL; + } + if (linearfb) { + maxsize = ((maxsize+0xfffUL)&~0xfffUL); + if (_create_selector(&linear_selector, linearfb, maxsize)) { + return NULL; + } + } + if (_create_selector(&banked_selector, 0xa0000, modes[0].gran)) { + _remove_selector(&linear_selector); + return NULL; + } + + for (q=modes; q->mode!=0xffff; q++) { + q->sel = (q->mode&0x4000) ? linear_selector : banked_selector; + } + + if (vesa_info[V_MAJOR] >= 2) { + r.x.ax = 0x4f0a; + r.x.bx = 0; + __dpmi_int(0x10, &r); + if (r.x.ax == 0x004f) { + vesa_pmcode = (word16 *)malloc(r.x.cx); + movedata(__djgpp_dos_sel, (r.x.es << 4) + r.x.di, _my_ds(), (unsigned)vesa_pmcode, r.x.cx); + if (vesa_pmcode[3]) { + p = (word16 *)((long)vesa_pmcode + vesa_pmcode[3]); + while (*p++ != 0xffff) ; + } else { + p = NULL; + } + if (p && (*p != 0xffff)) { + free(vesa_pmcode); + vesa_pmcode = NULL; + } else { + vesa_swbank = (void *)((long)vesa_pmcode + vesa_pmcode[0]); + } + } + } + + vesa_ver = _16_ vesa_info[V_MINOR]; + return modes; +} + + + +/* Desc: Frees all resources allocated by VESA init code. + * + * In : - + * Out : - + * + * Note: - + */ +static void vesa_fini (void) +{ + if (vesa_ver) { + _remove_selector(&linear_selector); + _remove_selector(&banked_selector); + if (vesa_pmcode != NULL) { + free(vesa_pmcode); + vesa_pmcode = NULL; + } + } +} + + + +/* Desc: Uses VESA 3.0 function 0x4F0B to find the closest pixel clock to the requested value. + * + * In : mode, clock + * Out : desired clock + * + * Note: - + */ +static unsigned long _closest_pixclk (int mode_no, unsigned long vclk) +{ + __dpmi_regs r; + + r.x.ax = 0x4F0B; + r.h.bl = 0; + r.d.ecx = vclk; + r.x.dx = mode_no; + __dpmi_int(0x10, &r); + + return (r.x.ax==0x004f) ? r.d.ecx : 0; +} + + + +/* Desc: Calculates CRTC mode timings. + * + * In : crtc block, geometry, adjust + * Out : + * + * Note: + */ +static void _crtc_timing (CRTCInfoBlock *crtc, int xres, int yres, int xadjust, int yadjust) +{ + int HTotal, VTotal; + int HDisp, VDisp; + int HSS, VSS; + int HSE, VSE; + int HSWidth, VSWidth; + int SS, SE; + int doublescan = FALSE; + + if (yres < 400) { + doublescan = TRUE; + yres *= 2; + } + + HDisp = xres; + HTotal = (int)(HDisp * 1.27) & ~0x7; + HSWidth = (int)((HTotal - HDisp) / 5) & ~0x7; + HSS = HDisp + 16; + HSE = HSS + HSWidth; + VDisp = yres; + VTotal = VDisp * 1.07; + VSWidth = (VTotal / 100) + 1; + VSS = VDisp + ((int)(VTotal - VDisp) / 5) + 1; + VSE = VSS + VSWidth; + + SS = HSS + xadjust; + SE = HSE + xadjust; + + if (xadjust < 0) { + if (SS < (HDisp + 8)) { + SS = HDisp + 8; + SE = SS + HSWidth; + } + } else { + if ((HTotal - 24) < SE) { + SE = HTotal - 24; + SS = SE - HSWidth; + } + } + + HSS = SS; + HSE = SE; + + SS = VSS + yadjust; + SE = VSE + yadjust; + + if (yadjust < 0) { + if (SS < (VDisp + 3)) { + SS = VDisp + 3; + SE = SS + VSWidth; + } + } else { + if ((VTotal - 4) < SE) { + SE = VTotal - 4; + SS = SE - VSWidth; + } + } + + VSS = SS; + VSE = SE; + + crtc->HorizontalTotal = HTotal; + crtc->HorizontalSyncStart = HSS; + crtc->HorizontalSyncEnd = HSE; + crtc->VerticalTotal = VTotal; + crtc->VerticalSyncStart = VSS; + crtc->VerticalSyncEnd = VSE; + crtc->Flags = HNEG | VNEG; + + if (doublescan) + crtc->Flags |= DOUBLESCAN; +} + + + +/* Desc: Attempts to enter specified video mode. + * + * In : ptr to mode structure, refresh rate + * Out : 0 if success + * + * Note: - + */ +static int vesa_entermode (vl_mode *p, int refresh) +{ + __dpmi_regs r; + + if (p->mode & 0x4000) { + VESA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual; + } else { + VESA.blit = vesa_b_dump_virtual; + { int n; for (vesa_gran_shift=0, n=p->gran; n; vesa_gran_shift++, n>>=1) ; } + vesa_gran_mask = (1<<(--vesa_gran_shift)) - 1; + if ((unsigned)p->gran != (vesa_gran_mask+1)) { + return !0; + } + } + + if (oldmode == -1) { + r.x.ax = 0x4f03; + __dpmi_int(0x10, &r); + oldmode = r.x.bx; + } + + r.x.ax = 0x4f02; + r.x.bx = p->mode; + + if (refresh && ((vesa_ver>>8) >= 3)) { + /* VESA 3.0 stuff for controlling the refresh rate */ + CRTCInfoBlock crtc; + unsigned long vclk; + double f0; + + _crtc_timing(&crtc, p->xres, p->yres, 0, 0); + + vclk = (double)crtc.HorizontalTotal * crtc.VerticalTotal * refresh; + vclk = _closest_pixclk(p->mode, vclk); + + if (vclk != 0) { + f0 = (double)vclk / (crtc.HorizontalTotal * crtc.VerticalTotal); + /*_current_refresh_rate = (int)(f0 + 0.5);*/ + + crtc.PixelClock = vclk; + crtc.RefreshRate = refresh * 100; + + movedata(_my_ds(), (unsigned)&crtc, _stubinfo->ds_selector, 0, sizeof(crtc)); + + r.x.di = 0; + r.x.es = _stubinfo->ds_segment; + r.x.bx |= 0x0800; + } + } + + __dpmi_int(0x10, &r); + if (r.x.ax != 0x004f) { + return !0; + } + + if (p->bpp == 8) { + r.x.ax = 0x4f08; + r.x.bx = 0x0800; + __dpmi_int(0x10, &r); + if (r.x.ax == 0x004f) { + r.x.ax = 0x4f08; + r.h.bl = 0x01; + __dpmi_int(0x10, &r); + vesa_color_precision = r.h.bh; + } + } + + return 0; +} + + + +/* Desc: Restores to the mode prior to first call to vesa_entermode. + * + * In : - + * Out : - + * + * Note: - + */ +static void vesa_restore (void) +{ + __dpmi_regs r; + + if (oldmode != -1) { + r.x.ax = 0x4f02; + r.x.bx = oldmode; + __dpmi_int(0x10, &r); + } +} + + + +/* Desc: set one palette entry + * + * In : color index, R, G, B + * Out : - + * + * Note: uses integer values + */ +static void vesa_setCI_i (int index, int red, int green, int blue) +{ +#if 0 + __asm("\n\ + movw $0x1010, %%ax \n\ + movb %1, %%dh \n\ + movb %2, %%ch \n\ + int $0x10 \n\ + "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx"); +#else + outportb(0x03C8, index); + outportb(0x03C9, red); + outportb(0x03C9, green); + outportb(0x03C9, blue); +#endif +} + + + +/* Desc: set one palette entry + * + * In : color index, R, G, B + * Out : - + * + * Note: uses normalized values + */ +static void vesa_setCI_f (int index, float red, float green, float blue) +{ + float max = (1 << vesa_color_precision) - 1; + + vesa_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max)); +} + + + +/* Desc: state retrieval + * + * In : parameter name, ptr to storage + * Out : 0 if request successfully processed + * + * Note: - + */ +static int vesa_get (int pname, int *params) +{ + switch (pname) { + case VL_GET_CI_PREC: + params[0] = vesa_color_precision; + break; + default: + return -1; + } + return 0; +} + + + +/* + * the driver + */ +vl_driver VESA = { + vesa_init, + vesa_entermode, + NULL, + vesa_setCI_f, + vesa_setCI_i, + vesa_get, + vesa_restore, + vesa_fini +}; diff --git a/src/mesa/drivers/dos/vesa.h b/src/mesa/drivers/dos/vesa.h index 030c816f080..9287697c370 100644 --- a/src/mesa/drivers/dos/vesa.h +++ b/src/mesa/drivers/dos/vesa.h @@ -1,47 +1,47 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef VESA_H_included
-#define VESA_H_included
-
-#include "internal.h"
-
-extern void *vesa_swbank;
-
-extern void vesa_b_dump_virtual (void);
-extern void vesa_l_dump_virtual (void);
-extern void vesa_l_dump_virtual_mmx (void);
-
-extern vl_driver VESA;
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef VESA_H_included +#define VESA_H_included + +#include "internal.h" + +extern void *vesa_swbank; + +extern void vesa_b_dump_virtual (void); +extern void vesa_l_dump_virtual (void); +extern void vesa_l_dump_virtual_mmx (void); + +extern vl_driver VESA; + +#endif diff --git a/src/mesa/drivers/dos/vga.c b/src/mesa/drivers/dos/vga.c index 4fe8773243f..9de32f0cd5e 100644 --- a/src/mesa/drivers/dos/vga.c +++ b/src/mesa/drivers/dos/vga.c @@ -1,235 +1,235 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.1
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#include <pc.h>
-#include <stdlib.h>
-
-#include "video.h"
-#include "vga.h"
-
-
-
-static vl_mode modes[] = {
- {0x13 | 0x4000, 320, 200, 320, 8, -1, 320*200},
- {0xffff, -1, -1, -1, -1, -1, -1}
-};
-
-static word16 vga_ver;
-static int linear_selector;
-static int oldmode = -1;
-
-#define vga_color_precision 6
-
-
-
-/* Desc: Attempts to detect VGA, check video modes and create selectors.
- *
- * In : -
- * Out : mode array
- *
- * Note: -
- */
-static vl_mode *vga_init (void)
-{
- int rv = 0;
-
- if (vga_ver) {
- return modes;
- }
-
- __asm("\n\
- movw $0x1a00, %%ax \n\
- int $0x10 \n\
- cmpb $0x1a, %%al \n\
- jne 0f \n\
- cmpb $0x07, %%bl \n\
- jb 0f \n\
- andl $0xff, %%ebx \n\
- movl %%ebx, %0 \n\
- 0:":"=g"(rv)::"%eax", "%ebx");
- if (rv == 0) {
- return NULL;
- }
-
- if (_create_selector(&linear_selector, 0xa0000, 0x10000)) {
- return NULL;
- }
-
- modes[0].sel = linear_selector;
-
- vga_ver = rv;
- return modes;
-}
-
-
-
-/* Desc: Frees all resources allocated by VGA init code.
- *
- * In : -
- * Out : -
- *
- * Note: -
- */
-static void vga_fini (void)
-{
- if (vga_ver) {
- _remove_selector(&linear_selector);
- }
-}
-
-
-
-/* Desc: Attempts to enter specified video mode.
- *
- * In : ptr to mode structure, refresh rate
- * Out : 0 if success
- *
- * Note: -
- */
-static int vga_entermode (vl_mode *p, int refresh)
-{
- if (!(p->mode & 0x4000)) {
- return -1;
- }
- VGA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
-
- if (oldmode == -1) {
- __asm("\n\
- movb $0x0f, %%ah \n\
- int $0x10 \n\
- andl $0xff, %%eax \n\
- movl %%eax, %0 \n\
- ":"=g"(oldmode)::"%eax", "%ebx");
- }
-
- __asm("int $0x10"::"a"(p->mode&0xff));
-
- return 0;
-
- (void)refresh; /* silence compiler warning */
-}
-
-
-
-/* Desc: Restores to the mode prior to first call to vga_entermode.
- *
- * In : -
- * Out : -
- *
- * Note: -
- */
-static void vga_restore (void)
-{
- if (oldmode != -1) {
- __asm("int $0x10"::"a"(oldmode));
- }
-}
-
-
-
-/* Desc: set one palette entry
- *
- * In : color index, R, G, B
- * Out : -
- *
- * Note: uses integer values
- */
-static void vga_setCI_i (int index, int red, int green, int blue)
-{
-#if 0
- __asm("\n\
- movw $0x1010, %%ax \n\
- movb %1, %%dh \n\
- movb %2, %%ch \n\
- int $0x10 \n\
- "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");
-#else
- outportb(0x03C8, index);
- outportb(0x03C9, red);
- outportb(0x03C9, green);
- outportb(0x03C9, blue);
-#endif
-}
-
-
-
-/* Desc: set one palette entry
- *
- * In : color index, R, G, B
- * Out : -
- *
- * Note: uses normalized values
- */
-static void vga_setCI_f (int index, float red, float green, float blue)
-{
- float max = (1 << vga_color_precision) - 1;
-
- vga_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));
-}
-
-
-
-/* Desc: state retrieval
- *
- * In : parameter name, ptr to storage
- * Out : 0 if request successfully processed
- *
- * Note: -
- */
-static int vga_get (int pname, int *params)
-{
- switch (pname) {
- case VL_GET_CI_PREC:
- params[0] = vga_color_precision;
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-
-
-/*
- * the driver
- */
-vl_driver VGA = {
- vga_init,
- vga_entermode,
- NULL,
- vga_setCI_f,
- vga_setCI_i,
- vga_get,
- vga_restore,
- vga_fini
-};
+/* + * Mesa 3-D graphics library + * Version: 4.1 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#include <pc.h> +#include <stdlib.h> + +#include "video.h" +#include "vga.h" + + + +static vl_mode modes[] = { + {0x13 | 0x4000, 320, 200, 320, 8, -1, 320*200}, + {0xffff, -1, -1, -1, -1, -1, -1} +}; + +static word16 vga_ver; +static int linear_selector; +static int oldmode = -1; + +#define vga_color_precision 6 + + + +/* Desc: Attempts to detect VGA, check video modes and create selectors. + * + * In : - + * Out : mode array + * + * Note: - + */ +static vl_mode *vga_init (void) +{ + int rv = 0; + + if (vga_ver) { + return modes; + } + + __asm("\n\ + movw $0x1a00, %%ax \n\ + int $0x10 \n\ + cmpb $0x1a, %%al \n\ + jne 0f \n\ + cmpb $0x07, %%bl \n\ + jb 0f \n\ + andl $0xff, %%ebx \n\ + movl %%ebx, %0 \n\ + 0:":"=g"(rv)::"%eax", "%ebx"); + if (rv == 0) { + return NULL; + } + + if (_create_selector(&linear_selector, 0xa0000, 0x10000)) { + return NULL; + } + + modes[0].sel = linear_selector; + + vga_ver = rv; + return modes; +} + + + +/* Desc: Frees all resources allocated by VGA init code. + * + * In : - + * Out : - + * + * Note: - + */ +static void vga_fini (void) +{ + if (vga_ver) { + _remove_selector(&linear_selector); + } +} + + + +/* Desc: Attempts to enter specified video mode. + * + * In : ptr to mode structure, refresh rate + * Out : 0 if success + * + * Note: - + */ +static int vga_entermode (vl_mode *p, int refresh) +{ + if (!(p->mode & 0x4000)) { + return -1; + } + VGA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual; + + if (oldmode == -1) { + __asm("\n\ + movb $0x0f, %%ah \n\ + int $0x10 \n\ + andl $0xff, %%eax \n\ + movl %%eax, %0 \n\ + ":"=g"(oldmode)::"%eax", "%ebx"); + } + + __asm("int $0x10"::"a"(p->mode&0xff)); + + return 0; + + (void)refresh; /* silence compiler warning */ +} + + + +/* Desc: Restores to the mode prior to first call to vga_entermode. + * + * In : - + * Out : - + * + * Note: - + */ +static void vga_restore (void) +{ + if (oldmode != -1) { + __asm("int $0x10"::"a"(oldmode)); + } +} + + + +/* Desc: set one palette entry + * + * In : color index, R, G, B + * Out : - + * + * Note: uses integer values + */ +static void vga_setCI_i (int index, int red, int green, int blue) +{ +#if 0 + __asm("\n\ + movw $0x1010, %%ax \n\ + movb %1, %%dh \n\ + movb %2, %%ch \n\ + int $0x10 \n\ + "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx"); +#else + outportb(0x03C8, index); + outportb(0x03C9, red); + outportb(0x03C9, green); + outportb(0x03C9, blue); +#endif +} + + + +/* Desc: set one palette entry + * + * In : color index, R, G, B + * Out : - + * + * Note: uses normalized values + */ +static void vga_setCI_f (int index, float red, float green, float blue) +{ + float max = (1 << vga_color_precision) - 1; + + vga_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max)); +} + + + +/* Desc: state retrieval + * + * In : parameter name, ptr to storage + * Out : 0 if request successfully processed + * + * Note: - + */ +static int vga_get (int pname, int *params) +{ + switch (pname) { + case VL_GET_CI_PREC: + params[0] = vga_color_precision; + break; + default: + return -1; + } + return 0; +} + + + +/* + * the driver + */ +vl_driver VGA = { + vga_init, + vga_entermode, + NULL, + vga_setCI_f, + vga_setCI_i, + vga_get, + vga_restore, + vga_fini +}; diff --git a/src/mesa/drivers/dos/vga.h b/src/mesa/drivers/dos/vga.h index f1bc62bbe73..aeb8faddaed 100644 --- a/src/mesa/drivers/dos/vga.h +++ b/src/mesa/drivers/dos/vga.h @@ -1,42 +1,42 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef VGA_H_included
-#define VGA_H_included
-
-#include "internal.h"
-#include "vesa.h"
-
-extern vl_driver VGA;
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef VGA_H_included +#define VGA_H_included + +#include "internal.h" +#include "vesa.h" + +extern vl_driver VGA; + +#endif diff --git a/src/mesa/drivers/dos/video.c b/src/mesa/drivers/dos/video.c index 297c9d56624..a2524e052c2 100644 --- a/src/mesa/drivers/dos/video.c +++ b/src/mesa/drivers/dos/video.c @@ -1,525 +1,525 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- *
- * Thanks to CrazyPyro (Neil Funk) for FakeColor
- */
-
-
-#include <stdlib.h>
-
-#include "internal.h"
-#include "vesa.h"
-#include "vga.h"
-#include "video.h"
-
-
-
-static vl_driver *drv;
-/* based upon mode specific data: valid entire session */
-int vl_video_selector;
-static vl_mode *video_mode;
-static int video_scanlen, video_bypp;
-/* valid until next buffer */
-void *vl_current_draw_buffer, *vl_current_read_buffer;
-int vl_current_stride, vl_current_width, vl_current_height, vl_current_bytes;
-int vl_current_offset, vl_current_delta;
-
-
-
-/* lookup table for scaling 5 bit colors up to 8 bits */
-static int _rgb_scale_5[32] = {
- 0, 8, 16, 25, 33, 41, 49, 58,
- 66, 74, 82, 90, 99, 107, 115, 123,
- 132, 140, 148, 156, 165, 173, 181, 189,
- 197, 206, 214, 222, 230, 239, 247, 255
-};
-
-/* lookup table for scaling 6 bit colors up to 8 bits */
-static int _rgb_scale_6[64] = {
- 0, 4, 8, 12, 16, 20, 24, 28,
- 32, 36, 40, 45, 49, 53, 57, 61,
- 65, 69, 73, 77, 81, 85, 89, 93,
- 97, 101, 105, 109, 113, 117, 121, 125,
- 130, 134, 138, 142, 146, 150, 154, 158,
- 162, 166, 170, 174, 178, 182, 186, 190,
- 194, 198, 202, 206, 210, 215, 219, 223,
- 227, 231, 235, 239, 243, 247, 251, 255
-};
-
-/* FakeColor data */
-#define R_CNT 6
-#define G_CNT 6
-#define B_CNT 6
-
-#define R_BIAS 7
-#define G_BIAS 7
-#define B_BIAS 7
-
-static word32 VGAPalette[256];
-static word8 array_r[256];
-static word8 array_g[256];
-static word8 array_b[256];
-
-
-
-int (*vl_mixfix) (fixed r, fixed g, fixed b);
-int (*vl_mixrgb) (const unsigned char rgb[]);
-int (*vl_mixrgba) (const unsigned char rgba[]);
-void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]);
-int (*vl_getpixel) (unsigned int offset);
-void (*vl_clear) (int color);
-void (*vl_rect) (int x, int y, int width, int height, int color);
-void (*vl_flip) (void);
-void (*vl_putpixel) (unsigned int offset, int color);
-
-
-
-/* Desc: color composition (w/o ALPHA)
- *
- * In : R, G, B
- * Out : color
- *
- * Note: -
- */
-static int vl_mixfix8fake (fixed r, fixed g, fixed b)
-{
- return array_b[b>>FIXED_SHIFT]*G_CNT*R_CNT
- + array_g[g>>FIXED_SHIFT]*R_CNT
- + array_r[r>>FIXED_SHIFT];
-}
-#define vl_mixfix8 vl_mixfix8fake
-static int vl_mixfix15 (fixed r, fixed g, fixed b)
-{
- return ((r>>(3+FIXED_SHIFT))<<10)
- |((g>>(3+FIXED_SHIFT))<<5)
- |(b>>(3+FIXED_SHIFT));
-}
-static int vl_mixfix16 (fixed r, fixed g, fixed b)
-{
- return ((r>>(3+FIXED_SHIFT))<<11)
- |((g>>(2+FIXED_SHIFT))<<5)
- |(b>>(3+FIXED_SHIFT));
-}
-#define vl_mixfix24 vl_mixfix32
-static int vl_mixfix32 (fixed r, fixed g, fixed b)
-{
- return ((r>>FIXED_SHIFT)<<16)
- |((g>>FIXED_SHIFT)<<8)
- |(b>>FIXED_SHIFT);
-}
-
-
-
-/* Desc: color composition (w/ ALPHA)
- *
- * In : array of integers (R, G, B, A)
- * Out : color
- *
- * Note: -
- */
-#define vl_mixrgba8 vl_mixrgb8fake
-#define vl_mixrgba15 vl_mixrgb15
-#define vl_mixrgba16 vl_mixrgb16
-#define vl_mixrgba24 vl_mixrgb24
-static int vl_mixrgba32 (const unsigned char rgba[])
-{
- return (rgba[3]<<24)|(rgba[0]<<16)|(rgba[1]<<8)|(rgba[2]);
-}
-
-
-
-/* Desc: color composition (w/o ALPHA)
- *
- * In : array of integers (R, G, B)
- * Out : color
- *
- * Note: -
- */
-static int vl_mixrgb8fake (const unsigned char rgba[])
-{
- return array_b[rgba[2]]*G_CNT*R_CNT
- + array_g[rgba[1]]*R_CNT
- + array_r[rgba[0]];
-}
-#define vl_mixrgb8 vl_mixrgb8fake
-static int vl_mixrgb15 (const unsigned char rgb[])
-{
- return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3);
-}
-static int vl_mixrgb16 (const unsigned char rgb[])
-{
- return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3);
-}
-#define vl_mixrgb24 vl_mixrgb32
-static int vl_mixrgb32 (const unsigned char rgb[])
-{
- return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);
-}
-
-
-
-/* Desc: color decomposition
- *
- * In : pixel offset, array of integers to hold color components (R, G, B, A)
- * Out : -
- *
- * Note: uses current read buffer
- */
-static void v_getrgba8fake6 (unsigned int offset, unsigned char rgba[])
-{
- word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]];
- rgba[0] = _rgb_scale_6[(c >> 16) & 0x3F];
- rgba[1] = _rgb_scale_6[(c >> 8) & 0x3F];
- rgba[2] = _rgb_scale_6[c & 0x3F];
- rgba[3] = c >> 24;
-}
-static void v_getrgba8fake8 (unsigned int offset, unsigned char rgba[])
-{
- word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]];
- rgba[0] = c >> 16;
- rgba[1] = c >> 8;
- rgba[2] = c;
- rgba[3] = c >> 24;
-}
-#define v_getrgba8 v_getrgba8fake6
-static void v_getrgba15 (unsigned int offset, unsigned char rgba[4])
-{
- word32 c = ((word16 *)vl_current_read_buffer)[offset];
- rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F];
- rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F];
- rgba[2] = _rgb_scale_5[c & 0x1F];
- rgba[3] = 255;
-}
-static void v_getrgba16 (unsigned int offset, unsigned char rgba[4])
-{
- word32 c = ((word16 *)vl_current_read_buffer)[offset];
- rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F];
- rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F];
- rgba[2] = _rgb_scale_5[c & 0x1F];
- rgba[3] = 255;
-}
-static void v_getrgba24 (unsigned int offset, unsigned char rgba[4])
-{
- word32 c = *(word32 *)((long)vl_current_read_buffer+offset*3);
- rgba[0] = c >> 16;
- rgba[1] = c >> 8;
- rgba[2] = c;
- rgba[3] = 255;
-}
-static void v_getrgba32 (unsigned int offset, unsigned char rgba[4])
-{
- word32 c = ((word32 *)vl_current_read_buffer)[offset];
- rgba[0] = c >> 16;
- rgba[1] = c >> 8;
- rgba[2] = c;
- rgba[3] = c >> 24;
-}
-
-
-
-/* Desc: pixel retrieval
- *
- * In : pixel offset
- * Out : pixel value
- *
- * Note: uses current read buffer
- */
-static int v_getpixel8 (unsigned int offset)
-{
- return ((word8 *)vl_current_read_buffer)[offset];
-}
-#define v_getpixel15 v_getpixel16
-static int v_getpixel16 (unsigned int offset)
-{
- return ((word16 *)vl_current_read_buffer)[offset];
-}
-static int v_getpixel24 (unsigned int offset)
-{
- return *(word32 *)((long)vl_current_read_buffer+offset*3);
-}
-static int v_getpixel32 (unsigned int offset)
-{
- return ((word32 *)vl_current_read_buffer)[offset];
-}
-
-
-
-/* Desc: set one palette entry
- *
- * In : index, R, G, B
- * Out : -
- *
- * Note: color components are in range [0.0 .. 1.0]
- */
-void vl_setCI (int index, float red, float green, float blue)
-{
- drv->setCI_f(index, red, green, blue);
-}
-
-
-
-/* Desc: set one palette entry
- *
- * In : color, R, G, B
- * Out : -
- *
- * Note: -
- */
-static void fake_setcolor (int c, int r, int g, int b)
-{
- VGAPalette[c] = 0xff000000 | (r<<16) | (g<<8) | b;
-
- drv->setCI_i(c, r, g, b);
-}
-
-
-
-/* Desc: build FakeColor palette
- *
- * In : CI precision in bits
- * Out : -
- *
- * Note: -
- */
-static void fake_buildpalette (int bits)
-{
- double c_r, c_g, c_b;
- int r, g, b, color = 0;
-
- double max = (1 << bits) - 1;
-
- for (b=0; b<B_CNT; ++b) {
- for (g=0; g<G_CNT; ++g) {
- for (r=0; r<R_CNT; ++r) {
- c_r = 0.5 + (double)r*(max-R_BIAS)/(R_CNT-1.) + R_BIAS;
- c_g = 0.5 + (double)g*(max-G_BIAS)/(G_CNT-1.) + G_BIAS;
- c_b = 0.5 + (double)b*(max-B_BIAS)/(B_CNT-1.) + B_BIAS;
- fake_setcolor(color++, (int)c_r, (int)c_g, (int)c_b);
- }
- }
- }
-
- for (color=0; color<256; color++) {
- c_r = (double)color*R_CNT/256.;
- c_g = (double)color*G_CNT/256.;
- c_b = (double)color*B_CNT/256.;
- array_r[color] = (int)c_r;
- array_g[color] = (int)c_g;
- array_b[color] = (int)c_b;
- }
-}
-
-
-
-/* Desc: sync buffer with video hardware
- *
- * In : ptr to old buffer, position, size
- * Out : 0 if success
- *
- * Note: -
- */
-int vl_sync_buffer (void **buffer, int x, int y, int width, int height)
-{
- if ((width & 7) || (x < 0) || (y < 0) || (x+width > video_mode->xres) || (y+height > video_mode->yres)) {
- return -1;
- } else {
- void *newbuf = *buffer;
-
- if ((newbuf == NULL) || (vl_current_width != width) || (vl_current_height != height)) {
- newbuf = realloc(newbuf, width * height * video_bypp);
- }
-
- if (newbuf == NULL) {
- return -2;
- }
-
- vl_current_width = width;
- vl_current_height = height;
- vl_current_stride = vl_current_width * video_bypp;
- vl_current_bytes = vl_current_stride * height;
-
- vl_current_offset = video_scanlen * y + video_bypp * x;
- vl_current_delta = video_scanlen - vl_current_stride;
-
- vl_current_draw_buffer = vl_current_read_buffer = *buffer = newbuf;
- return 0;
- }
-}
-
-
-
-/* Desc: state retrieval
- *
- * In : name, storage
- * Out : -
- *
- * Note: -
- */
-int vl_get (int pname, int *params)
-{
- switch (pname) {
- case VL_GET_SCREEN_SIZE:
- params[0] = video_mode->xres;
- params[1] = video_mode->yres;
- break;
- default:
- return drv->get(pname, params);
- }
- return 0;
-}
-
-
-
-/* Desc: setup mode
- *
- * In : ptr to mode definition
- * Out : 0 if success
- *
- * Note: -
- */
-static int vl_setup_mode (vl_mode *p)
-{
- if (p == NULL) {
- return -1;
- }
-
-#define INITPTR(bpp) \
- vl_putpixel = v_putpixel##bpp; \
- vl_getrgba = v_getrgba##bpp; \
- vl_getpixel = v_getpixel##bpp; \
- vl_rect = v_rect##bpp; \
- vl_mixfix = vl_mixfix##bpp; \
- vl_mixrgb = vl_mixrgb##bpp; \
- vl_mixrgba = vl_mixrgba##bpp; \
- vl_clear = _can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp
-
- switch (p->bpp) {
- case 8:
- INITPTR(8);
- break;
- case 15:
- INITPTR(15);
- break;
- case 16:
- INITPTR(16);
- break;
- case 24:
- INITPTR(24);
- break;
- case 32:
- INITPTR(32);
- break;
- default:
- return -1;
- }
-
-#undef INITPTR
-
- video_mode = p;
- video_bypp = (p->bpp+7)/8;
- video_scanlen = p->scanlen;
- vl_video_selector = p->sel;
-
- return 0;
-}
-
-
-
-/* Desc: restore to the mode prior to first call to `vl_video_init'.
- *
- * In : -
- * Out : -
- *
- * Note: -
- */
-void vl_video_exit (void)
-{
- drv->restore();
- drv->fini();
-}
-
-
-
-/* Desc: enter mode
- *
- * In : xres, yres, bits/pixel, RGB, refresh rate
- * Out : pixel width in bits if success
- *
- * Note: -
- */
-int vl_video_init (int width, int height, int bpp, int rgb, int refresh)
-{
- int fake;
- vl_mode *p, *q;
- unsigned int min;
-
- fake = 0;
- if (!rgb) {
- bpp = 8;
- } else if (bpp == 8) {
- fake = 1;
- }
-
- /* initialize hardware */
- drv = &VESA;
- if ((q=drv->init()) == NULL) {
- drv = &VGA;
- if ((q=drv->init()) == NULL) {
- return 0;
- }
- }
-
- /* search for a mode that fits our request */
- for (min=-1, p=NULL; q->mode!=0xffff; q++) {
- if ((q->xres>=width) && (q->yres>=height) && (q->bpp==bpp)) {
- if (min>=(unsigned)(q->xres*q->yres)) {
- min = q->xres*q->yres;
- p = q;
- }
- }
- }
-
- /* setup and enter mode */
- if ((vl_setup_mode(p) == 0) && (drv->entermode(p, refresh) == 0)) {
- vl_flip = drv->blit;
- if (fake) {
- drv->get(VL_GET_CI_PREC, (int *)(&min));
- fake_buildpalette(min);
- if (min == 8) {
- vl_getrgba = v_getrgba8fake8;
- }
- }
- return bpp;
- }
-
- /* abort */
- return 0;
-}
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + * + * Thanks to CrazyPyro (Neil Funk) for FakeColor + */ + + +#include <stdlib.h> + +#include "internal.h" +#include "vesa.h" +#include "vga.h" +#include "video.h" + + + +static vl_driver *drv; +/* based upon mode specific data: valid entire session */ +int vl_video_selector; +static vl_mode *video_mode; +static int video_scanlen, video_bypp; +/* valid until next buffer */ +void *vl_current_draw_buffer, *vl_current_read_buffer; +int vl_current_stride, vl_current_width, vl_current_height, vl_current_bytes; +int vl_current_offset, vl_current_delta; + + + +/* lookup table for scaling 5 bit colors up to 8 bits */ +static int _rgb_scale_5[32] = { + 0, 8, 16, 25, 33, 41, 49, 58, + 66, 74, 82, 90, 99, 107, 115, 123, + 132, 140, 148, 156, 165, 173, 181, 189, + 197, 206, 214, 222, 230, 239, 247, 255 +}; + +/* lookup table for scaling 6 bit colors up to 8 bits */ +static int _rgb_scale_6[64] = { + 0, 4, 8, 12, 16, 20, 24, 28, + 32, 36, 40, 45, 49, 53, 57, 61, + 65, 69, 73, 77, 81, 85, 89, 93, + 97, 101, 105, 109, 113, 117, 121, 125, + 130, 134, 138, 142, 146, 150, 154, 158, + 162, 166, 170, 174, 178, 182, 186, 190, + 194, 198, 202, 206, 210, 215, 219, 223, + 227, 231, 235, 239, 243, 247, 251, 255 +}; + +/* FakeColor data */ +#define R_CNT 6 +#define G_CNT 6 +#define B_CNT 6 + +#define R_BIAS 7 +#define G_BIAS 7 +#define B_BIAS 7 + +static word32 VGAPalette[256]; +static word8 array_r[256]; +static word8 array_g[256]; +static word8 array_b[256]; + + + +int (*vl_mixfix) (fixed r, fixed g, fixed b); +int (*vl_mixrgb) (const unsigned char rgb[]); +int (*vl_mixrgba) (const unsigned char rgba[]); +void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]); +int (*vl_getpixel) (unsigned int offset); +void (*vl_clear) (int color); +void (*vl_rect) (int x, int y, int width, int height, int color); +void (*vl_flip) (void); +void (*vl_putpixel) (unsigned int offset, int color); + + + +/* Desc: color composition (w/o ALPHA) + * + * In : R, G, B + * Out : color + * + * Note: - + */ +static int vl_mixfix8fake (fixed r, fixed g, fixed b) +{ + return array_b[b>>FIXED_SHIFT]*G_CNT*R_CNT + + array_g[g>>FIXED_SHIFT]*R_CNT + + array_r[r>>FIXED_SHIFT]; +} +#define vl_mixfix8 vl_mixfix8fake +static int vl_mixfix15 (fixed r, fixed g, fixed b) +{ + return ((r>>(3+FIXED_SHIFT))<<10) + |((g>>(3+FIXED_SHIFT))<<5) + |(b>>(3+FIXED_SHIFT)); +} +static int vl_mixfix16 (fixed r, fixed g, fixed b) +{ + return ((r>>(3+FIXED_SHIFT))<<11) + |((g>>(2+FIXED_SHIFT))<<5) + |(b>>(3+FIXED_SHIFT)); +} +#define vl_mixfix24 vl_mixfix32 +static int vl_mixfix32 (fixed r, fixed g, fixed b) +{ + return ((r>>FIXED_SHIFT)<<16) + |((g>>FIXED_SHIFT)<<8) + |(b>>FIXED_SHIFT); +} + + + +/* Desc: color composition (w/ ALPHA) + * + * In : array of integers (R, G, B, A) + * Out : color + * + * Note: - + */ +#define vl_mixrgba8 vl_mixrgb8fake +#define vl_mixrgba15 vl_mixrgb15 +#define vl_mixrgba16 vl_mixrgb16 +#define vl_mixrgba24 vl_mixrgb24 +static int vl_mixrgba32 (const unsigned char rgba[]) +{ + return (rgba[3]<<24)|(rgba[0]<<16)|(rgba[1]<<8)|(rgba[2]); +} + + + +/* Desc: color composition (w/o ALPHA) + * + * In : array of integers (R, G, B) + * Out : color + * + * Note: - + */ +static int vl_mixrgb8fake (const unsigned char rgba[]) +{ + return array_b[rgba[2]]*G_CNT*R_CNT + + array_g[rgba[1]]*R_CNT + + array_r[rgba[0]]; +} +#define vl_mixrgb8 vl_mixrgb8fake +static int vl_mixrgb15 (const unsigned char rgb[]) +{ + return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3); +} +static int vl_mixrgb16 (const unsigned char rgb[]) +{ + return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3); +} +#define vl_mixrgb24 vl_mixrgb32 +static int vl_mixrgb32 (const unsigned char rgb[]) +{ + return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]); +} + + + +/* Desc: color decomposition + * + * In : pixel offset, array of integers to hold color components (R, G, B, A) + * Out : - + * + * Note: uses current read buffer + */ +static void v_getrgba8fake6 (unsigned int offset, unsigned char rgba[]) +{ + word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]]; + rgba[0] = _rgb_scale_6[(c >> 16) & 0x3F]; + rgba[1] = _rgb_scale_6[(c >> 8) & 0x3F]; + rgba[2] = _rgb_scale_6[c & 0x3F]; + rgba[3] = c >> 24; +} +static void v_getrgba8fake8 (unsigned int offset, unsigned char rgba[]) +{ + word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]]; + rgba[0] = c >> 16; + rgba[1] = c >> 8; + rgba[2] = c; + rgba[3] = c >> 24; +} +#define v_getrgba8 v_getrgba8fake6 +static void v_getrgba15 (unsigned int offset, unsigned char rgba[4]) +{ + word32 c = ((word16 *)vl_current_read_buffer)[offset]; + rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F]; + rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F]; + rgba[2] = _rgb_scale_5[c & 0x1F]; + rgba[3] = 255; +} +static void v_getrgba16 (unsigned int offset, unsigned char rgba[4]) +{ + word32 c = ((word16 *)vl_current_read_buffer)[offset]; + rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F]; + rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F]; + rgba[2] = _rgb_scale_5[c & 0x1F]; + rgba[3] = 255; +} +static void v_getrgba24 (unsigned int offset, unsigned char rgba[4]) +{ + word32 c = *(word32 *)((long)vl_current_read_buffer+offset*3); + rgba[0] = c >> 16; + rgba[1] = c >> 8; + rgba[2] = c; + rgba[3] = 255; +} +static void v_getrgba32 (unsigned int offset, unsigned char rgba[4]) +{ + word32 c = ((word32 *)vl_current_read_buffer)[offset]; + rgba[0] = c >> 16; + rgba[1] = c >> 8; + rgba[2] = c; + rgba[3] = c >> 24; +} + + + +/* Desc: pixel retrieval + * + * In : pixel offset + * Out : pixel value + * + * Note: uses current read buffer + */ +static int v_getpixel8 (unsigned int offset) +{ + return ((word8 *)vl_current_read_buffer)[offset]; +} +#define v_getpixel15 v_getpixel16 +static int v_getpixel16 (unsigned int offset) +{ + return ((word16 *)vl_current_read_buffer)[offset]; +} +static int v_getpixel24 (unsigned int offset) +{ + return *(word32 *)((long)vl_current_read_buffer+offset*3); +} +static int v_getpixel32 (unsigned int offset) +{ + return ((word32 *)vl_current_read_buffer)[offset]; +} + + + +/* Desc: set one palette entry + * + * In : index, R, G, B + * Out : - + * + * Note: color components are in range [0.0 .. 1.0] + */ +void vl_setCI (int index, float red, float green, float blue) +{ + drv->setCI_f(index, red, green, blue); +} + + + +/* Desc: set one palette entry + * + * In : color, R, G, B + * Out : - + * + * Note: - + */ +static void fake_setcolor (int c, int r, int g, int b) +{ + VGAPalette[c] = 0xff000000 | (r<<16) | (g<<8) | b; + + drv->setCI_i(c, r, g, b); +} + + + +/* Desc: build FakeColor palette + * + * In : CI precision in bits + * Out : - + * + * Note: - + */ +static void fake_buildpalette (int bits) +{ + double c_r, c_g, c_b; + int r, g, b, color = 0; + + double max = (1 << bits) - 1; + + for (b=0; b<B_CNT; ++b) { + for (g=0; g<G_CNT; ++g) { + for (r=0; r<R_CNT; ++r) { + c_r = 0.5 + (double)r*(max-R_BIAS)/(R_CNT-1.) + R_BIAS; + c_g = 0.5 + (double)g*(max-G_BIAS)/(G_CNT-1.) + G_BIAS; + c_b = 0.5 + (double)b*(max-B_BIAS)/(B_CNT-1.) + B_BIAS; + fake_setcolor(color++, (int)c_r, (int)c_g, (int)c_b); + } + } + } + + for (color=0; color<256; color++) { + c_r = (double)color*R_CNT/256.; + c_g = (double)color*G_CNT/256.; + c_b = (double)color*B_CNT/256.; + array_r[color] = (int)c_r; + array_g[color] = (int)c_g; + array_b[color] = (int)c_b; + } +} + + + +/* Desc: sync buffer with video hardware + * + * In : ptr to old buffer, position, size + * Out : 0 if success + * + * Note: - + */ +int vl_sync_buffer (void **buffer, int x, int y, int width, int height) +{ + if ((width & 7) || (x < 0) || (y < 0) || (x+width > video_mode->xres) || (y+height > video_mode->yres)) { + return -1; + } else { + void *newbuf = *buffer; + + if ((newbuf == NULL) || (vl_current_width != width) || (vl_current_height != height)) { + newbuf = realloc(newbuf, width * height * video_bypp); + } + + if (newbuf == NULL) { + return -2; + } + + vl_current_width = width; + vl_current_height = height; + vl_current_stride = vl_current_width * video_bypp; + vl_current_bytes = vl_current_stride * height; + + vl_current_offset = video_scanlen * y + video_bypp * x; + vl_current_delta = video_scanlen - vl_current_stride; + + vl_current_draw_buffer = vl_current_read_buffer = *buffer = newbuf; + return 0; + } +} + + + +/* Desc: state retrieval + * + * In : name, storage + * Out : - + * + * Note: - + */ +int vl_get (int pname, int *params) +{ + switch (pname) { + case VL_GET_SCREEN_SIZE: + params[0] = video_mode->xres; + params[1] = video_mode->yres; + break; + default: + return drv->get(pname, params); + } + return 0; +} + + + +/* Desc: setup mode + * + * In : ptr to mode definition + * Out : 0 if success + * + * Note: - + */ +static int vl_setup_mode (vl_mode *p) +{ + if (p == NULL) { + return -1; + } + +#define INITPTR(bpp) \ + vl_putpixel = v_putpixel##bpp; \ + vl_getrgba = v_getrgba##bpp; \ + vl_getpixel = v_getpixel##bpp; \ + vl_rect = v_rect##bpp; \ + vl_mixfix = vl_mixfix##bpp; \ + vl_mixrgb = vl_mixrgb##bpp; \ + vl_mixrgba = vl_mixrgba##bpp; \ + vl_clear = _can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp + + switch (p->bpp) { + case 8: + INITPTR(8); + break; + case 15: + INITPTR(15); + break; + case 16: + INITPTR(16); + break; + case 24: + INITPTR(24); + break; + case 32: + INITPTR(32); + break; + default: + return -1; + } + +#undef INITPTR + + video_mode = p; + video_bypp = (p->bpp+7)/8; + video_scanlen = p->scanlen; + vl_video_selector = p->sel; + + return 0; +} + + + +/* Desc: restore to the mode prior to first call to `vl_video_init'. + * + * In : - + * Out : - + * + * Note: - + */ +void vl_video_exit (void) +{ + drv->restore(); + drv->fini(); +} + + + +/* Desc: enter mode + * + * In : xres, yres, bits/pixel, RGB, refresh rate + * Out : pixel width in bits if success + * + * Note: - + */ +int vl_video_init (int width, int height, int bpp, int rgb, int refresh) +{ + int fake; + vl_mode *p, *q; + unsigned int min; + + fake = 0; + if (!rgb) { + bpp = 8; + } else if (bpp == 8) { + fake = 1; + } + + /* initialize hardware */ + drv = &VESA; + if ((q=drv->init()) == NULL) { + drv = &VGA; + if ((q=drv->init()) == NULL) { + return 0; + } + } + + /* search for a mode that fits our request */ + for (min=-1, p=NULL; q->mode!=0xffff; q++) { + if ((q->xres>=width) && (q->yres>=height) && (q->bpp==bpp)) { + if (min>=(unsigned)(q->xres*q->yres)) { + min = q->xres*q->yres; + p = q; + } + } + } + + /* setup and enter mode */ + if ((vl_setup_mode(p) == 0) && (drv->entermode(p, refresh) == 0)) { + vl_flip = drv->blit; + if (fake) { + drv->get(VL_GET_CI_PREC, (int *)(&min)); + fake_buildpalette(min); + if (min == 8) { + vl_getrgba = v_getrgba8fake8; + } + } + return bpp; + } + + /* abort */ + return 0; +} diff --git a/src/mesa/drivers/dos/video.h b/src/mesa/drivers/dos/video.h index bb40fd00dfb..55560ee25b8 100644 --- a/src/mesa/drivers/dos/video.h +++ b/src/mesa/drivers/dos/video.h @@ -1,64 +1,64 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
-#ifndef VIDEO_H_included
-#define VIDEO_H_included
-
-typedef int fixed;
-
-#define VL_GET_CARD_NAME 0x0100
-#define VL_GET_VRAM 0x0101
-#define VL_GET_CI_PREC 0x0200
-#define VL_GET_HPIXELS 0x0201
-#define VL_GET_SCREEN_SIZE 0x0202
-
-extern int (*vl_mixfix) (fixed r, fixed g, fixed b);
-extern int (*vl_mixrgb) (const unsigned char rgb[]);
-extern int (*vl_mixrgba) (const unsigned char rgba[]);
-extern void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]);
-
-extern void (*vl_clear) (int color);
-extern void (*vl_rect) (int x, int y, int width, int height, int color);
-extern void (*vl_flip) (void);
-extern void (*vl_putpixel) (unsigned int offset, int color);
-extern int (*vl_getpixel) (unsigned int offset);
-
-void vl_setCI (int index, float red, float green, float blue);
-
-int vl_sync_buffer (void **buffer, int x, int y, int width, int height);
-int vl_get (int pname, int *params);
-
-void vl_video_exit (void);
-int vl_video_init (int width, int height, int bpp, int rgb, int refresh);
-
-#endif
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + +#ifndef VIDEO_H_included +#define VIDEO_H_included + +typedef int fixed; + +#define VL_GET_CARD_NAME 0x0100 +#define VL_GET_VRAM 0x0101 +#define VL_GET_CI_PREC 0x0200 +#define VL_GET_HPIXELS 0x0201 +#define VL_GET_SCREEN_SIZE 0x0202 + +extern int (*vl_mixfix) (fixed r, fixed g, fixed b); +extern int (*vl_mixrgb) (const unsigned char rgb[]); +extern int (*vl_mixrgba) (const unsigned char rgba[]); +extern void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]); + +extern void (*vl_clear) (int color); +extern void (*vl_rect) (int x, int y, int width, int height, int color); +extern void (*vl_flip) (void); +extern void (*vl_putpixel) (unsigned int offset, int color); +extern int (*vl_getpixel) (unsigned int offset); + +void vl_setCI (int index, float red, float green, float blue); + +int vl_sync_buffer (void **buffer, int x, int y, int width, int height); +int vl_get (int pname, int *params); + +void vl_video_exit (void); +int vl_video_init (int width, int height, int bpp, int rgb, int refresh); + +#endif diff --git a/src/mesa/drivers/dos/virtual.S b/src/mesa/drivers/dos/virtual.S index 0df584150f3..c5cc1fe86f8 100644 --- a/src/mesa/drivers/dos/virtual.S +++ b/src/mesa/drivers/dos/virtual.S @@ -1,489 +1,489 @@ -/*
- * Mesa 3-D graphics library
- * Version: 4.0
- *
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included
- * in all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
-
-/*
- * DOS/DJGPP device driver v1.3 for Mesa
- *
- * Copyright (C) 2002 - Borca Daniel
- * Email : [email protected]
- * Web : http://www.geocities.com/dborca
- */
-
-
- .file "virtual.S"
-
-/*
- * extern void *vl_current_draw_buffer;
- * extern int vl_current_width, vl_current_bytes;
- */
-
- .text
-
-/* Desc: void v_clear8 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear8
-_v_clear8:
- movl 4(%esp), %eax
- movb %al, %ah
- pushw %ax
- pushw %ax
- popl %eax
- jmp _v_clear_common
-
-/* Desc: void v_clear16 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear16
-_v_clear16:
- movl 4(%esp), %eax
- pushw %ax
- pushw %ax
- popl %eax
- jmp _v_clear_common
-
-/* Desc: void v_clear32 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear32
-_v_clear32:
- movl 4(%esp), %eax
- .balign 4
-_v_clear_common:
- movl _vl_current_bytes, %ecx
- movl _vl_current_draw_buffer, %edx
- shrl $2, %ecx
- .balign 4
- 0:
- movl %eax, (%edx)
- addl $4, %edx
- decl %ecx
- jnz 0b
- ret
-
-/* Desc: void v_clear8_mmx (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear8_mmx
-_v_clear8_mmx:
-#ifdef USE_MMX_ASM
- movd 4(%esp), %mm0
- punpcklbw %mm0, %mm0
- punpcklwd %mm0, %mm0
- jmp _v_clear_common_mmx
-#endif
-
-/* Desc: void v_clear16_mmx (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear16_mmx
-_v_clear16_mmx:
-#ifdef USE_MMX_ASM
- movd 4(%esp), %mm0
- punpcklwd %mm0, %mm0
- jmp _v_clear_common_mmx
-#endif
-
-/* Desc: void v_clear32_mmx (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear32_mmx
-_v_clear32_mmx:
-#ifdef USE_MMX_ASM
- movd 4(%esp), %mm0
- .balign 4
-_v_clear_common_mmx:
- punpckldq %mm0, %mm0
- movl _vl_current_bytes, %ecx
- movl _vl_current_draw_buffer, %edx
- shrl $3, %ecx
- .balign 4
- 0:
- movq %mm0, (%edx)
- addl $8, %edx
- decl %ecx
- jnz 0b
- emms
-#endif
- ret
-
-/* Desc: void v_clear24 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear24
-_v_clear24:
- movl $0xaaaaaaab, %eax
- mull _vl_current_bytes
- movl 4(%esp), %eax
- movl %edx, %ecx
- pushl %ebx
- movl _vl_current_draw_buffer, %edx
- shrl %ecx
- movb 10(%esp), %bl
- .balign 4
- 0:
- movw %ax, (%edx)
- movb %bl, 2(%edx)
- addl $3, %edx
- decl %ecx
- jnz 0b
- popl %ebx
- ret
-
-/* Desc: void v_clear24_mmx (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_clear24_mmx
-_v_clear24_mmx:
-#ifdef USE_MMX_ASM
- movl 4(%esp), %eax
- movl %eax, %edx
- movl %eax, %ecx
- shll $16, %edx
- rorl $8, %ecx
- movw %cx, %dx
- rorl $16, %ecx
- movb %dh, %cl
- shll $8, %eax
- movb %ch, %al
- rorl $8, %eax
-
- pushl %edx
- pushl %eax
- movq (%esp), %mm0
- pushl %ecx
- movq (%esp), %mm1
- pushl %edx
- movq (%esp), %mm2
-
- movl $0xaaaaaaab, %eax
- mull _vl_current_bytes
- movl %edx, %ecx
- movl _vl_current_draw_buffer, %edx
- shrl $4, %ecx
- .balign 4
- 0:
- movq %mm0, (%edx)
- movq %mm1, 8(%edx)
- movq %mm2, 16(%edx)
- addl $24, %edx
- decl %ecx
- jnz 0b
- emms
- addl $16, %esp
-#endif
- ret
-
-/* Desc: void v_rect8 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_rect8
-_v_rect8:
- cld
- pushl %esi
- pushl %edi
- movl 28(%esp), %eax
- movl _vl_current_width, %esi
- movl 16(%esp), %edi
- movb %al, %ah
- movl 20(%esp), %ecx
- imull %esi, %edi
- movl 24(%esp), %edx
- subl %ecx, %esi
- addl 12(%esp), %edi
- pushw %ax
- pushw %ax
- pushl %ds
- popl %es
- addl _vl_current_draw_buffer, %edi
- popl %eax
- pushl %ebx
- movl %ecx, %ebx
- andl $3, %ebx
- .balign 4
- 0:
- pushl %ecx
- .balign 4
- 1:
- shrl $2, %ecx
- rep; stosl
- testl %ebx, %ebx
- jz 2f
- movl %ebx, %ecx
- rep; stosb
- .balign 4
- 2:
- popl %ecx
- addl %esi, %edi
- decl %edx
- jnz 0b
- popl %ebx
- popl %edi
- popl %esi
- ret
-
-/* Desc: void v_rect16 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_rect16
-_v_rect16:
- cld
- pushl %esi
- pushl %edi
- movl 28(%esp), %eax
- movl _vl_current_width, %esi
- movl 16(%esp), %edi
- movl 20(%esp), %ecx
- imull %esi, %edi
- movl 24(%esp), %edx
- subl %ecx, %esi
- addl 12(%esp), %edi
- pushw %ax
- shll %esi
- pushw %ax
- shll %edi
- pushl %ds
- popl %es
- addl _vl_current_draw_buffer, %edi
- popl %eax
- .balign 4
- 0:
- pushl %ecx
- .balign 4
- 1:
- shrl %ecx
- rep; stosl
- jnc 2f
- stosw
- .balign 4
- 2:
- popl %ecx
- addl %esi, %edi
- decl %edx
- jnz 0b
- popl %edi
- popl %esi
- ret
-
-/* Desc: void v_rect24 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_rect24
-_v_rect24:
- pushl %esi
- pushl %edi
- movl 28(%esp), %eax
- movl _vl_current_width, %esi
- movl 16(%esp), %edi
- movl 20(%esp), %ecx
- imull %esi, %edi
- movl 24(%esp), %edx
- subl %ecx, %esi
- addl 12(%esp), %edi
- leal (%esi, %esi, 2), %esi
- pushl %ebx
- leal (%edi, %edi, 2), %edi
- movl %eax, %ebx
- addl _vl_current_draw_buffer, %edi
- shrl $16, %ebx
- .balign 4
- 0:
- pushl %ecx
- .balign 4
- 1:
- movw %ax, (%edi)
- movb %bl, 2(%edi)
- addl $3, %edi
- decl %ecx
- jnz 1b
- popl %ecx
- addl %esi, %edi
- decl %edx
- jnz 0b
- popl %ebx
- popl %edi
- popl %esi
- ret
-
-/* Desc: void v_rect32 (int color);
- *
- * In : color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_rect32
-_v_rect32:
- pushl %esi
- pushl %edi
- movl _vl_current_width, %esi
- movl 16(%esp), %edi
- movl 20(%esp), %ecx
- imull %esi, %edi
- movl 24(%esp), %edx
- subl %ecx, %esi
- addl 12(%esp), %edi
- shll $2, %esi
- shll $2, %edi
- movl 28(%esp), %eax
- addl _vl_current_draw_buffer, %edi
- .balign 4
- 0:
- pushl %ecx
- .balign 4
- 1:
- movl %eax, (%edi)
- addl $4, %edi
- decl %ecx
- jnz 1b
- popl %ecx
- addl %esi, %edi
- decl %edx
- jnz 0b
- popl %edi
- popl %esi
- ret
-
-/* Desc: void v_putpixel8 (unsigned int offset, int color);
- *
- * In : offset within buffer, color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_putpixel8
-_v_putpixel8:
- movl 8(%esp), %ecx
- movl 4(%esp), %edx
- movl _vl_current_draw_buffer, %eax
- movb %cl, (%eax,%edx)
- ret
-
-/* Desc: void v_putpixel16 (unsigned int offset, int color);
- *
- * In : offset within buffer, color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_putpixel16
-_v_putpixel16:
- movl 8(%esp), %ecx
- movl 4(%esp), %edx
- movl _vl_current_draw_buffer, %eax
- movw %cx, (%eax,%edx,2)
- ret
-
-/* Desc: void v_putpixel24 (unsigned int offset, int color);
- *
- * In : offset within buffer, color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_putpixel24
-_v_putpixel24:
- movl 4(%esp), %eax
- movl 8(%esp), %edx
- movl _vl_current_draw_buffer, %ecx
- leal (%eax,%eax,2), %eax
- movw %dx, (%ecx,%eax)
- shrl $16, %edx
- movb %dl, 2(%ecx,%eax)
- ret
-
-/* Desc: void v_putpixel32 (unsigned int offset, int color);
- *
- * In : offset within buffer, color
- * Out : -
- *
- * Note: uses current draw buffer
- */
- .p2align 5,,31
- .global _v_putpixel32
-_v_putpixel32:
- movl 8(%esp), %ecx
- movl 4(%esp), %edx
- movl _vl_current_draw_buffer, %eax
- movl %ecx, (%eax,%edx,4)
- ret
+/* + * Mesa 3-D graphics library + * Version: 4.0 + * + * Copyright (C) 1999 Brian Paul All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included + * in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN + * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +/* + * DOS/DJGPP device driver v1.3 for Mesa + * + * Copyright (C) 2002 - Borca Daniel + * Email : [email protected] + * Web : http://www.geocities.com/dborca + */ + + + .file "virtual.S" + +/* + * extern void *vl_current_draw_buffer; + * extern int vl_current_width, vl_current_bytes; + */ + + .text + +/* Desc: void v_clear8 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear8 +_v_clear8: + movl 4(%esp), %eax + movb %al, %ah + pushw %ax + pushw %ax + popl %eax + jmp _v_clear_common + +/* Desc: void v_clear16 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear16 +_v_clear16: + movl 4(%esp), %eax + pushw %ax + pushw %ax + popl %eax + jmp _v_clear_common + +/* Desc: void v_clear32 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear32 +_v_clear32: + movl 4(%esp), %eax + .balign 4 +_v_clear_common: + movl _vl_current_bytes, %ecx + movl _vl_current_draw_buffer, %edx + shrl $2, %ecx + .balign 4 + 0: + movl %eax, (%edx) + addl $4, %edx + decl %ecx + jnz 0b + ret + +/* Desc: void v_clear8_mmx (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear8_mmx +_v_clear8_mmx: +#ifdef USE_MMX_ASM + movd 4(%esp), %mm0 + punpcklbw %mm0, %mm0 + punpcklwd %mm0, %mm0 + jmp _v_clear_common_mmx +#endif + +/* Desc: void v_clear16_mmx (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear16_mmx +_v_clear16_mmx: +#ifdef USE_MMX_ASM + movd 4(%esp), %mm0 + punpcklwd %mm0, %mm0 + jmp _v_clear_common_mmx +#endif + +/* Desc: void v_clear32_mmx (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear32_mmx +_v_clear32_mmx: +#ifdef USE_MMX_ASM + movd 4(%esp), %mm0 + .balign 4 +_v_clear_common_mmx: + punpckldq %mm0, %mm0 + movl _vl_current_bytes, %ecx + movl _vl_current_draw_buffer, %edx + shrl $3, %ecx + .balign 4 + 0: + movq %mm0, (%edx) + addl $8, %edx + decl %ecx + jnz 0b + emms +#endif + ret + +/* Desc: void v_clear24 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear24 +_v_clear24: + movl $0xaaaaaaab, %eax + mull _vl_current_bytes + movl 4(%esp), %eax + movl %edx, %ecx + pushl %ebx + movl _vl_current_draw_buffer, %edx + shrl %ecx + movb 10(%esp), %bl + .balign 4 + 0: + movw %ax, (%edx) + movb %bl, 2(%edx) + addl $3, %edx + decl %ecx + jnz 0b + popl %ebx + ret + +/* Desc: void v_clear24_mmx (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_clear24_mmx +_v_clear24_mmx: +#ifdef USE_MMX_ASM + movl 4(%esp), %eax + movl %eax, %edx + movl %eax, %ecx + shll $16, %edx + rorl $8, %ecx + movw %cx, %dx + rorl $16, %ecx + movb %dh, %cl + shll $8, %eax + movb %ch, %al + rorl $8, %eax + + pushl %edx + pushl %eax + movq (%esp), %mm0 + pushl %ecx + movq (%esp), %mm1 + pushl %edx + movq (%esp), %mm2 + + movl $0xaaaaaaab, %eax + mull _vl_current_bytes + movl %edx, %ecx + movl _vl_current_draw_buffer, %edx + shrl $4, %ecx + .balign 4 + 0: + movq %mm0, (%edx) + movq %mm1, 8(%edx) + movq %mm2, 16(%edx) + addl $24, %edx + decl %ecx + jnz 0b + emms + addl $16, %esp +#endif + ret + +/* Desc: void v_rect8 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_rect8 +_v_rect8: + cld + pushl %esi + pushl %edi + movl 28(%esp), %eax + movl _vl_current_width, %esi + movl 16(%esp), %edi + movb %al, %ah + movl 20(%esp), %ecx + imull %esi, %edi + movl 24(%esp), %edx + subl %ecx, %esi + addl 12(%esp), %edi + pushw %ax + pushw %ax + pushl %ds + popl %es + addl _vl_current_draw_buffer, %edi + popl %eax + pushl %ebx + movl %ecx, %ebx + andl $3, %ebx + .balign 4 + 0: + pushl %ecx + .balign 4 + 1: + shrl $2, %ecx + rep; stosl + testl %ebx, %ebx + jz 2f + movl %ebx, %ecx + rep; stosb + .balign 4 + 2: + popl %ecx + addl %esi, %edi + decl %edx + jnz 0b + popl %ebx + popl %edi + popl %esi + ret + +/* Desc: void v_rect16 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_rect16 +_v_rect16: + cld + pushl %esi + pushl %edi + movl 28(%esp), %eax + movl _vl_current_width, %esi + movl 16(%esp), %edi + movl 20(%esp), %ecx + imull %esi, %edi + movl 24(%esp), %edx + subl %ecx, %esi + addl 12(%esp), %edi + pushw %ax + shll %esi + pushw %ax + shll %edi + pushl %ds + popl %es + addl _vl_current_draw_buffer, %edi + popl %eax + .balign 4 + 0: + pushl %ecx + .balign 4 + 1: + shrl %ecx + rep; stosl + jnc 2f + stosw + .balign 4 + 2: + popl %ecx + addl %esi, %edi + decl %edx + jnz 0b + popl %edi + popl %esi + ret + +/* Desc: void v_rect24 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_rect24 +_v_rect24: + pushl %esi + pushl %edi + movl 28(%esp), %eax + movl _vl_current_width, %esi + movl 16(%esp), %edi + movl 20(%esp), %ecx + imull %esi, %edi + movl 24(%esp), %edx + subl %ecx, %esi + addl 12(%esp), %edi + leal (%esi, %esi, 2), %esi + pushl %ebx + leal (%edi, %edi, 2), %edi + movl %eax, %ebx + addl _vl_current_draw_buffer, %edi + shrl $16, %ebx + .balign 4 + 0: + pushl %ecx + .balign 4 + 1: + movw %ax, (%edi) + movb %bl, 2(%edi) + addl $3, %edi + decl %ecx + jnz 1b + popl %ecx + addl %esi, %edi + decl %edx + jnz 0b + popl %ebx + popl %edi + popl %esi + ret + +/* Desc: void v_rect32 (int color); + * + * In : color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_rect32 +_v_rect32: + pushl %esi + pushl %edi + movl _vl_current_width, %esi + movl 16(%esp), %edi + movl 20(%esp), %ecx + imull %esi, %edi + movl 24(%esp), %edx + subl %ecx, %esi + addl 12(%esp), %edi + shll $2, %esi + shll $2, %edi + movl 28(%esp), %eax + addl _vl_current_draw_buffer, %edi + .balign 4 + 0: + pushl %ecx + .balign 4 + 1: + movl %eax, (%edi) + addl $4, %edi + decl %ecx + jnz 1b + popl %ecx + addl %esi, %edi + decl %edx + jnz 0b + popl %edi + popl %esi + ret + +/* Desc: void v_putpixel8 (unsigned int offset, int color); + * + * In : offset within buffer, color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_putpixel8 +_v_putpixel8: + movl 8(%esp), %ecx + movl 4(%esp), %edx + movl _vl_current_draw_buffer, %eax + movb %cl, (%eax,%edx) + ret + +/* Desc: void v_putpixel16 (unsigned int offset, int color); + * + * In : offset within buffer, color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_putpixel16 +_v_putpixel16: + movl 8(%esp), %ecx + movl 4(%esp), %edx + movl _vl_current_draw_buffer, %eax + movw %cx, (%eax,%edx,2) + ret + +/* Desc: void v_putpixel24 (unsigned int offset, int color); + * + * In : offset within buffer, color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_putpixel24 +_v_putpixel24: + movl 4(%esp), %eax + movl 8(%esp), %edx + movl _vl_current_draw_buffer, %ecx + leal (%eax,%eax,2), %eax + movw %dx, (%ecx,%eax) + shrl $16, %edx + movb %dl, 2(%ecx,%eax) + ret + +/* Desc: void v_putpixel32 (unsigned int offset, int color); + * + * In : offset within buffer, color + * Out : - + * + * Note: uses current draw buffer + */ + .p2align 5,,31 + .global _v_putpixel32 +_v_putpixel32: + movl 8(%esp), %ecx + movl 4(%esp), %edx + movl _vl_current_draw_buffer, %eax + movl %ecx, (%eax,%edx,4) + ret |