Environment variables:\r
CPU optimize for the given processor.\r
default = k6\r
- SGI_GLU=1 build SGI's GLU instead of Mesa's.\r
- default = no\r
+ GLU=[src|si] specify GLU directory; can be `src' (src-glu = Mesa)\r
+ or `si' (si-glu = SGI's GLU -- requires GNU/C++).\r
+ default = src\r
GLIDE path to Glide3 SDK include files; used with FX.\r
default = $(TOP)/include/glide3\r
FX=1 build for 3dfx Glide3. Note that this disables\r
As a consequence, you'll need the DJGPP Glide3\r
library to build any application.\r
default = no\r
+ MATROX=1 build for Matrox Millennium I (MGA2064W) cards.\r
+ This is experimental and not intensively tested.\r
+ default = no\r
HAVE_X86=1 optimize for i386.\r
default = no\r
HAVE_MMX=1 allow MMX specializations, provided your assembler\r
A) You need LFN support.\r
A) When compiling for Glide (FX=1), pay attention to Glide path.\r
\r
+ Q) Libraries built OK, but linker complains about `vsnprintf' every time I\r
+ compile some demo.\r
+ A) Upgrade to DJGPP 2.04.\r
+ A) Add `vsnprintf.c' to the CORE_SOURCES in `src/Makefile.DJ' (untested!).\r
+ A) The following hack should be safe in 90% of the cases, but if anything\r
+ goes wrong, don't come back to me crying. Anyway, patch `src/imports.c'\r
+ with the following line:\r
+ #define vsnprintf(buf, max, fmt, arg) vsprintf(buf, fmt, arg)\r
+\r
2. Dynamic modules\r
\r
Q) What are you mumbling about dynamic modules?\r
3. Using Mesa for DJGPP\r
\r
Q) DMesa is so SLOOOW! The Win32 OpenGL performs so much better...\r
- A) Is that a question? If you have a Voodoo3/Banshee card, you're lucky. The\r
- Glide port is on my web page. If you haven't, sorry; everything is done\r
- in software. Suggestions?\r
+ A) Is that a question? If you have a Voodoo3/Banshee card, you're lucky (the\r
+ Glide port is on my web page). If you have a Matrox Millennium I card,\r
+ you just MIGHT be lucky... If you haven't, sorry; everything is done in\r
+ software. Suggestions?\r
\r
Q) I tried to set refresh rate w/ DMesa, but without success.\r
A) Refresh rate control works only for VESA 3.0. If you were compiling for\r
\r
Q) I made a simple application and it does nothing. It exits right away. Not\r
even a blank screen.\r
- A) Only DMesa+FX supports single-buffered. The standard VESA/VGA drivers\r
- will always work in double-buffered modes. If/When I will find a way to\r
- use *REAL* hardware acceleration for a specific card, it might or might\r
- not support single-buffered modes.\r
+ A) The pure software drivers (VESA/VGA) support only double-buffered modes.\r
A) Another weird "feature" is that buffer width must be multiple of 8 (I'm a\r
lazy programmer and I found that the easiest way to keep buffer handling\r
at peak performance ;-).\r
\r
- Q) My demo doesn't display text. I know I used the glut font routines!\r
+ Q) My demo doesn't display text. I know I used the GLUT font routines!\r
A) Then you probably use GLUT as a DXE. Well, there is no direct access to\r
variables due to the way DXE works. Read the documentation. The author of\r
GLUT took this into account for _WIN32 DLL's only; I don't want to modify\r
* synced w/ Mesa-4.1\r
- removed dmesadxe.h\r
\r
-v1.3 (jan-2003)\r
+v1.3 (feb-2003)\r
+ enabled OpenGL 1.4 support\r
+ added MMX clear/blit routines\r
+ enabled SGI's GLU compilation\r
+ + added samples makefile\r
+ added new GLUT functions\r
+ added color-index modes\r
+ + added Matrox Millennium MGA2064W driver\r
+ added 8bit FakeColor (thanks to Neil Funk)\r
+ added VGA support (to keep Ben Decker happy)\r
- * fixed GLUT compilation error (reported by Chan Kar Heng)\r
+ ! fixed GLUT compilation error (reported by Chan Kar Heng)\r
* overhauled virtual buffer and internal video drivers\r
* better fxMesa integration\r
* revamped GLUT\r
*/\r
void DMesaDestroyContext (DMesaContext c);\r
\r
+/*\r
+ * Return a handle to the current context.\r
+ */\r
+DMesaContext DMesaGetCurrentContext (void);\r
+\r
\r
\r
/*\r
*/\r
void DMesaDestroyBuffer (DMesaBuffer b);\r
\r
-\r
-\r
-/*\r
- * Bind Buffer to Context and make the Context the current one.\r
- */\r
-GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b);\r
-\r
-\r
-\r
/*\r
* Swap the front and back buffers for the given Buffer.\r
* No action is taken if the buffer is not double buffered.\r
*/\r
void DMesaSwapBuffers (DMesaBuffer b);\r
\r
+/*\r
+ * Bind Buffer to Context and make the Context the current one.\r
+ */\r
+GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b);\r
+\r
\r
\r
/*\r
/*\r
* DMesa state retrieval.\r
*/\r
-#define DMESA_Y_ORIGIN 0x0100\r
-#define DMESA_SCREEN_SIZE 0x0101\r
-#define DMESA_ARGB_ORDER 0x0200\r
-void DMesaGetIntegerv (GLenum pname, GLint *params);\r
+#define DMESA_GET_SCREEN_SIZE 0x0100\r
+#define DMESA_GET_DRIVER_CAPS 0x0200\r
+\r
+#define DMESA_DRIVER_SWDB_BIT 0x1 /* software double-buffered */\r
+#define DMESA_DRIVER_LLWO_BIT 0x2 /* lower-left window origin */\r
+int DMesaGetIntegerv (GLenum pname, GLint *params);\r
\r
#ifdef __cplusplus\r
}\r
\r
LDFLAGS = -s -L$(TOP)/lib\r
\r
-ifdef DXE\r
+ifeq ($(DXE),1)\r
DMESADXE = $(TOP)/lib/dmesadxe.o\r
-LDLIBS += -liglut -liglu -ligl\r
-ifdef FX\r
-LDFLAGS += -L$(GLIDE)\r
-endif\r
-LDLIBS += -ldl\r
+LDLIBS += -liglut -liglu -ligl -ldl\r
else\r
LDLIBS = -lglut -lglu -lgl\r
-ifdef FX\r
+ifeq ($(FX),1)\r
LDFLAGS += -L$(GLIDE)\r
LDLIBS += -lglid3\r
endif\r
extern GLuint g_bpp; /* HW: bits per pixel */\r
extern GLuint g_refresh; /* HW: vertical refresh rate */\r
extern GLuint g_screen_w, g_screen_h; /* HW: physical screen size */\r
+extern GLint g_driver_caps;\r
+\r
+extern GLuint g_fps;\r
\r
extern GLuint g_display_mode; /* display bits */\r
extern int g_init_x, g_init_y; /* initial window position */\r
\r
\r
\r
-#define MAX_WINDOWS 2\r
+#define MAX_WINDOWS 2\r
\r
#define DEFAULT_WIDTH 300\r
#define DEFAULT_HEIGHT 300\r
GLuint g_bpp = DEFAULT_BPP;\r
GLuint g_refresh = 0;\r
GLuint g_screen_w, g_screen_h;\r
+GLint g_driver_caps;\r
+\r
+GLuint g_fps = 0;\r
\r
GLuint g_display_mode = 0;\r
int g_init_x = 0, g_init_y = 0;\r
}\r
__glutProgramName = __glutStrdup(str);\r
\r
+ /* check if GLUT_FPS env var is set */\r
+ if ((env = getenv("GLUT_FPS")) != NULL) {\r
+ if ((g_fps = atoi(env)) <= 0) {\r
+ g_fps = 5000; /* 5000 milliseconds */\r
+ }\r
+ }\r
+\r
/* Initialize timer */\r
glutGet(GLUT_ELAPSED_TIME);\r
}\r
\r
{\r
GLint screen_size[2];\r
- DMesaGetIntegerv(DMESA_SCREEN_SIZE, screen_size);\r
+ DMesaGetIntegerv(DMESA_GET_SCREEN_SIZE, screen_size);\r
g_screen_w = screen_size[0];\r
g_screen_h = screen_size[1];\r
+ DMesaGetIntegerv(DMESA_GET_DRIVER_CAPS, &g_driver_caps);\r
}\r
\r
pc_install_keyb();\r
void __glutInitMouse (void)\r
{\r
if ((g_mouse = pc_install_mouse())) {\r
- GLint yorg;\r
- GLint rect[4];\r
-\r
- DMesaGetIntegerv(DMESA_Y_ORIGIN, &yorg);\r
- if (yorg) {\r
- rect[1] = g_screen_h - g_curwin->height;\r
- } else {\r
- rect[1] = g_curwin->ypos;\r
- }\r
- rect[0] = g_curwin->xpos;\r
- rect[2] = rect[0] + g_curwin->width - 1;\r
- rect[3] = rect[1] + g_curwin->height - 1;\r
- pc_mouse_area(rect[0], rect[1], rect[2], rect[3]);\r
+ pc_mouse_area(g_curwin->xpos, g_curwin->ypos, g_curwin->xpos + g_curwin->width - 1, g_curwin->ypos + g_curwin->height - 1);\r
\r
g_curwin->show_mouse = (g_curwin->mouse || g_curwin->motion || g_curwin->passive);\r
}\r
*/\r
\r
\r
+#include <stdio.h>\r
+\r
#include "glutint.h"\r
#include "GL/dmesa.h"\r
\r
\r
\r
GLUTwindow *g_curwin;\r
+static GLuint swaptime, swapcount;\r
\r
static DMesaVisual visual = NULL;\r
static DMesaContext context = NULL;\r
int APIENTRY glutCreateWindow (const char *title)\r
{\r
int i;\r
- GLint screen_size[2];\r
int m8width = (g_init_w + 7) & ~7;\r
\r
if (!visual) {\r
} else {\r
DMesaSwapBuffers(g_curwin->buffer);\r
}\r
+\r
+ if (g_fps) {\r
+ GLint t = glutGet(GLUT_ELAPSED_TIME);\r
+ swapcount++;\r
+ if (swaptime == 0)\r
+ swaptime = t;\r
+ else if (t - swaptime > g_fps) {\r
+ double time = 0.001 * (t - swaptime);\r
+ double fps = (double)swapcount / time;\r
+ fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount, time, fps);\r
+ swaptime = t;\r
+ swapcount = 0;\r
+ }\r
+ }\r
}\r
\r
\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 4.0\r
+ * \r
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
+ *\r
+ * Copyright (C) 2002 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+ .file "blit.S"\r
+\r
+/*\r
+ * extern unsigned int vesa_gran_mask, vesa_gran_shift;\r
+ * extern int vl_video_selector;\r
+\r
+ * extern void *vl_current_draw_buffer;\r
+ * extern int vl_current_stride, vl_current_height;\r
+ * extern int vl_current_offset, vl_current_delta;\r
+ */\r
+\r
+ .text\r
+\r
+/* Desc: VESA bank switching routine (BIOS)\r
+ *\r
+ * In : EBX=0, EDX = bank number\r
+ * Out : -\r
+ *\r
+ * Note: thrashes EAX\r
+ */\r
+ .p2align 5,,31\r
+_vesa_swbankBIOS:\r
+ movw $0x4f05, %ax\r
+ int $0x10\r
+ ret\r
+\r
+ .p2align 2,,3\r
+ .global _vesa_swbank\r
+_vesa_swbank: .long _vesa_swbankBIOS\r
+\r
+/* Desc: void vesa_b_dump_virtual (void);\r
+ *\r
+ * In : -\r
+ * Out : -\r
+ *\r
+ * Note: uses current draw buffer\r
+ */\r
+ .p2align 5,,31\r
+ .global _vesa_b_dump_virtual\r
+_vesa_b_dump_virtual:\r
+ cld\r
+ pushl %es\r
+ pushl %ebx\r
+ pushl %esi\r
+ pushl %edi\r
+ pushl %ebp\r
+ movl _vl_video_selector, %es\r
+ movl _vl_current_draw_buffer, %esi\r
+ movl _vl_current_offset, %edi\r
+ movl _vesa_gran_shift, %ecx\r
+ movl _vesa_gran_mask, %ebp\r
+ movl %edi, %edx\r
+ xorl %ebx, %ebx\r
+ andl %ebp, %edi\r
+ shrl %cl, %edx\r
+ incl %ebp\r
+ call *_vesa_swbank\r
+ movl _vl_current_stride, %ecx\r
+ movl _vl_current_height, %eax\r
+ movl _vl_current_delta, %ebx\r
+ shrl $2, %ecx\r
+ .balign 4\r
+ 0:\r
+ pushl %ecx\r
+ .balign 4\r
+ 1:\r
+ cmpl %ebp, %edi\r
+ jb 2f\r
+ pushl %eax\r
+ pushl %ebx\r
+ incl %edx\r
+ xorl %ebx, %ebx\r
+ call *_vesa_swbank\r
+ popl %ebx\r
+ popl %eax\r
+ subl %ebp, %edi\r
+ .balign 4\r
+ 2:\r
+ movsl\r
+ decl %ecx\r
+ jnz 1b\r
+ popl %ecx\r
+ addl %ebx, %edi\r
+ decl %eax\r
+ jnz 0b\r
+ popl %ebp\r
+ popl %edi\r
+ popl %esi\r
+ popl %ebx\r
+ popl %es\r
+ ret\r
+\r
+/* Desc: void vesa_l_dump_virtual (void);\r
+ *\r
+ * In : -\r
+ * Out : -\r
+ *\r
+ * Note: uses current draw buffer\r
+ */\r
+ .p2align 5,,31\r
+ .global _vesa_l_dump_virtual\r
+_vesa_l_dump_virtual:\r
+ cld\r
+ pushl %es\r
+ pushl %esi\r
+ pushl %edi\r
+ movl _vl_video_selector, %es\r
+ movl _vl_current_draw_buffer, %esi\r
+ movl _vl_current_offset, %edi\r
+ movl _vl_current_stride, %ecx\r
+ movl _vl_current_height, %edx\r
+ movl _vl_current_delta, %eax\r
+ shrl $2, %ecx\r
+ .balign 4\r
+ 0:\r
+ pushl %ecx\r
+ rep; movsl\r
+ popl %ecx\r
+ addl %eax, %edi\r
+ decl %edx\r
+ jnz 0b\r
+ popl %edi\r
+ popl %esi\r
+ popl %es\r
+ ret\r
+\r
+/* Desc: void vesa_l_dump_virtual_mmx (void);\r
+ *\r
+ * In : -\r
+ * Out : -\r
+ *\r
+ * Note: uses current draw buffer\r
+ */\r
+ .p2align 5,,31\r
+ .global _vesa_l_dump_virtual_mmx\r
+_vesa_l_dump_virtual_mmx:\r
+#ifdef USE_MMX_ASM\r
+ pushl %esi\r
+ pushl %edi\r
+ movl _vl_video_selector, %fs\r
+ movl _vl_current_draw_buffer, %esi\r
+ movl _vl_current_offset, %edi\r
+ movl _vl_current_stride, %ecx\r
+ movl _vl_current_height, %edx\r
+ movl _vl_current_delta, %eax\r
+ shrl $3, %ecx\r
+ .balign 4\r
+ 0:\r
+ pushl %ecx\r
+ .balign 4\r
+ 1:\r
+ movq (%esi), %mm0\r
+ addl $8, %esi\r
+ movq %mm0, %fs:(%edi)\r
+ addl $8, %edi\r
+ decl %ecx\r
+ jnz 1b\r
+ popl %ecx\r
+ addl %eax, %edi\r
+ decl %edx\r
+ jnz 0b\r
+ popl %edi\r
+ popl %esi\r
+ emms\r
+#endif\r
+ ret\r
#include "tnl/t_context.h"\r
#include "tnl/t_pipeline.h"\r
\r
+#ifndef MATROX\r
+\r
#include "video.h"\r
\r
-#else\r
+#else /* MATROX */\r
+\r
+#include "mga/mga.h"\r
+\r
+#endif /* MATROX */\r
+\r
+#else /* FX */\r
\r
#include "../FX/fxdrv.h"\r
#include "GL/dmesa.h"\r
\r
-#endif\r
+#endif /* FX */\r
\r
\r
\r
GLboolean db_flag; /* double buffered? */\r
GLboolean rgb_flag; /* RGB mode? */\r
GLuint depth; /* bits per pixel (1, 8, 24, etc) */\r
+#ifdef MATROX\r
+ int stride_in_pixels;\r
+#endif\r
+ int zbuffer; /* Z=buffer: 0=no, 1=SW, -1=HW */\r
};\r
\r
/*\r
/****************************************************************************\r
* Read/Write pixels\r
***************************************************************************/\r
-#define FLIP(y) (c->Buffer->height - (y) - 1)\r
-#define FLIP2(y) (b - (y))\r
+#define FLIP(y) (dmesa->Buffer->height - (y) - 1)\r
+#define FLIP2(y) (_b_ - (y))\r
+\r
+\r
+#ifndef MATROX\r
+#define DSTRIDE dmesa->Buffer->width\r
+#else\r
+#define DSTRIDE dmesa->visual->stride_in_pixels\r
+#define vl_putpixel mga_putpixel\r
+#define vl_mixrgba mga_mixrgb\r
+#define vl_mixrgb mga_mixrgb\r
+#define vl_getrgba mga_getrgba\r
+#define vl_setz mga_setz\r
+#define vl_getz mga_getz\r
+#endif\r
\r
/****************************************************************************\r
* RGB[A]\r
static void write_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
const GLubyte rgba[][4], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset;\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+#ifndef MATROX\r
+ offset = DSTRIDE * FLIP(y) + x;\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++, offset++) {\r
vl_putpixel(offset, vl_mixrgba(rgba[i]));\r
}\r
}\r
+#else /* MATROX */\r
+ y = FLIP(y);\r
+ if (mask) {\r
+ /* draw some pixels */\r
+ offset = 0;\r
+ for (i = 0; i < n; i++) {\r
+ if (mask[i]) {\r
+ ++offset;\r
+ } else {\r
+ if (offset != 0) {\r
+ mga_draw_span_rgb_tx32(x + i - offset, y, offset, (const unsigned long *)(&rgba[i-offset]));\r
+ offset = 0;\r
+ }\r
+ }\r
+ }\r
+ if (offset != 0) {\r
+ mga_draw_span_rgb_tx32(x + n - offset, y, offset, (const unsigned long *)(&rgba[n-offset]));\r
+ }\r
+ } else {\r
+ /* draw all pixels */\r
+ mga_draw_span_rgb_tx32(x, y, n, (const unsigned long *)rgba);\r
+ }\r
+#endif /* MATROX */\r
}\r
\r
\r
static void write_rgb_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
const GLubyte rgb[][3], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset;\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+ offset = DSTRIDE * FLIP(y) + x;\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++, offset++) {\r
GLuint n, GLint x, GLint y,\r
const GLchan color[4], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset, rgba = vl_mixrgba(color);\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+ offset = DSTRIDE * FLIP(y) + x;\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++, offset++) {\r
static void read_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
GLubyte rgba[][4])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset;\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+ offset = DSTRIDE * FLIP(y) + x;\r
/* read all pixels */\r
for (i=0; i<n; i++, offset++) {\r
vl_getrgba(offset, rgba[i]);\r
GLuint n, const GLint x[], const GLint y[],\r
const GLubyte rgba[][4], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint i, w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;\r
\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++) {\r
if (mask[i]) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], vl_mixrgba(rgba[i]));\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i]));\r
}\r
}\r
} else {\r
/* draw all pixels */\r
for (i=0; i<n; i++) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], vl_mixrgba(rgba[i]));\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i]));\r
}\r
}\r
}\r
GLuint n, const GLint x[], const GLint y[],\r
const GLchan color[4], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint i, w = c->Buffer->width, b = c->Buffer->height - 1, rgba = vl_mixrgba(color);\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1, rgba = vl_mixrgba(color);\r
\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++) {\r
if (mask[i]) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], rgba);\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba);\r
}\r
}\r
} else {\r
/* draw all pixels */\r
for (i=0; i<n; i++) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], rgba);\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba);\r
}\r
}\r
}\r
GLuint n, const GLint x[], const GLint y[],\r
GLubyte rgba[][4], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint i, w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;\r
\r
if (mask) {\r
/* read some pixels */\r
for (i=0; i<n; i++) {\r
if (mask[i]) {\r
- vl_getrgba(FLIP2(y[i])*w + x[i], rgba[i]);\r
+ vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]);\r
}\r
}\r
} else {\r
/* read all pixels */\r
for (i=0; i<n; i++) {\r
- vl_getrgba(FLIP2(y[i])*w + x[i], rgba[i]);\r
+ vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]);\r
}\r
}\r
}\r
\r
+\r
+\r
/****************************************************************************\r
* Index\r
***************************************************************************/\r
+#ifndef MATROX\r
static void write_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
const GLuint index[], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset;\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+ offset = DSTRIDE * FLIP(y) + x;\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++, offset++) {\r
static void write_index8_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
const GLubyte index[], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset;\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+ offset = DSTRIDE * FLIP(y) + x;\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++, offset++) {\r
GLuint n, GLint x, GLint y,\r
GLuint colorIndex, const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset;\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+ offset = DSTRIDE * FLIP(y) + x;\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++, offset++) {\r
static void read_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
GLuint index[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
GLuint i, offset;\r
\r
- offset = c->Buffer->width * FLIP(y) + x;\r
+ offset = DSTRIDE * FLIP(y) + x;\r
/* read all pixels */\r
for (i=0; i<n; i++, offset++) {\r
index[i] = vl_getpixel(offset);\r
GLuint n, const GLint x[], const GLint y[],\r
const GLuint index[], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint i, w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;\r
\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++) {\r
if (mask[i]) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], index[i]);\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]);\r
}\r
}\r
} else {\r
/* draw all pixels */\r
for (i=0; i<n; i++) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], index[i]);\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]);\r
}\r
}\r
}\r
GLuint n, const GLint x[], const GLint y[],\r
GLuint colorIndex, const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint i, w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;\r
\r
if (mask) {\r
/* draw some pixels */\r
for (i=0; i<n; i++) {\r
if (mask[i]) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], colorIndex);\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex);\r
}\r
}\r
} else {\r
/* draw all pixels */\r
for (i=0; i<n; i++) {\r
- vl_putpixel(FLIP2(y[i])*w + x[i], colorIndex);\r
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex);\r
}\r
}\r
}\r
GLuint n, const GLint x[], const GLint y[],\r
GLuint index[], const GLubyte mask[])\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint i, w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;\r
\r
if (mask) {\r
/* read some pixels */\r
for (i=0; i<n; i++) {\r
if (mask[i]) {\r
- index[i] = vl_getpixel(FLIP2(y[i])*w + x[i]);\r
+ index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]);\r
}\r
}\r
} else {\r
/* read all pixels */\r
for (i=0; i<n; i++) {\r
- index[i] = vl_getpixel(FLIP2(y[i])*w + x[i]);\r
+ index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]);\r
}\r
}\r
}\r
+#endif /* !MATROX */\r
+\r
+\r
+\r
+/****************************************************************************\r
+ * Z-buffer\r
+ ***************************************************************************/\r
+#ifdef MATROX\r
+static void write_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y,\r
+ const GLdepth depth[], const GLubyte mask[])\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, offset;\r
+\r
+ offset = DSTRIDE * FLIP(y) + x;\r
+ if (mask) {\r
+ /* draw some values */\r
+ for (i=0; i<n; i++, offset++) {\r
+ if (mask[i]) {\r
+ vl_setz(offset, depth[i]);\r
+ }\r
+ }\r
+ } else {\r
+ /* draw all values */\r
+ for (i=0; i<n; i++, offset++) {\r
+ vl_setz(offset, depth[i]);\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r
+static void read_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y,\r
+ GLdepth depth[])\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, offset;\r
+\r
+ offset = DSTRIDE * FLIP(y) + x;\r
+ /* read all values */\r
+ for (i=0; i<n; i++, offset++) {\r
+ depth[i] = vl_getz(offset);\r
+ }\r
+}\r
+\r
+\r
+\r
+static void write_depth_pixels (GLcontext *ctx, GLuint n,\r
+ const GLint x[], const GLint y[],\r
+ const GLdepth depth[], const GLubyte mask[])\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;\r
+\r
+ if (mask) {\r
+ /* draw some values */\r
+ for (i=0; i<n; i++) {\r
+ if (mask[i]) {\r
+ vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]);\r
+ }\r
+ }\r
+ } else {\r
+ /* draw all values */\r
+ for (i=0; i<n; i++) {\r
+ vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]);\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r
+static void read_depth_pixels (GLcontext *ctx, GLuint n,\r
+ const GLint x[], const GLint y[],\r
+ GLdepth depth[])\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;\r
+\r
+ /* read all values */\r
+ for (i=0; i<n; i++) {\r
+ depth[i] = vl_getz(FLIP2(y[i])*_w_ + x[i]);\r
+ }\r
+}\r
+#endif /* MATROX */\r
\r
\r
\r
***************************************************************************/\r
\r
/*\r
- * flat, NON-depth-buffered, triangle.\r
+ * NON-depth-buffered flat triangle.\r
*/\r
static void tri_rgb_flat (GLcontext *ctx,\r
const SWvertex *v0,\r
const SWvertex *v1,\r
const SWvertex *v2)\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+#ifndef MATROX\r
+ GLuint _w_ = dmesa->Buffer->width;\r
\r
#define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);\r
\r
-#define RENDER_SPAN(span) \\r
- GLuint i, offset = FLIP2(span.y)*w + span.x; \\r
- for (i = 0; i < span.end; i++, offset++) { \\r
- vl_putpixel(offset, rgb); \\r
+#define RENDER_SPAN(span) \\r
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \\r
+ for (i = 0; i < span.end; i++, offset++) { \\r
+ vl_putpixel(offset, rgb); \\r
}\r
\r
#include "swrast/s_tritemp.h"\r
+#else /* MATROX */\r
+ MGAvertex m0, m1, m2;\r
+ m0.win[0] = v0->win[0];\r
+ m0.win[1] = FLIP2(v0->win[1]);\r
+ m1.win[0] = v1->win[0];\r
+ m1.win[1] = FLIP2(v1->win[1]);\r
+ m2.win[0] = v2->win[0];\r
+ m2.win[1] = FLIP2(v2->win[1]);\r
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;\r
+ mga_draw_tri_rgb_flat((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);\r
+#endif /* MATROX */\r
}\r
\r
\r
\r
/*\r
- * flat, depth-buffered, triangle.\r
+ * Z-less flat triangle.\r
*/\r
-static void tri_rgb_flat_z (GLcontext *ctx,\r
- const SWvertex *v0,\r
- const SWvertex *v1,\r
- const SWvertex *v2)\r
+static void tri_rgb_flat_zless (GLcontext *ctx,\r
+ const SWvertex *v0,\r
+ const SWvertex *v1,\r
+ const SWvertex *v2)\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+#ifndef MATROX\r
+ GLuint _w_ = dmesa->Buffer->width;\r
\r
#define INTERP_Z 1\r
#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE\r
#define SETUP_CODE GLuint rgb = vl_mixrgb(v2->color);\r
\r
-#define RENDER_SPAN(span) \\r
- GLuint i, offset = FLIP2(span.y)*w + span.x; \\r
- for (i = 0; i < span.end; i++, offset++) { \\r
- const DEPTH_TYPE z = FixedToDepth(span.z); \\r
- if (z < zRow[i]) { \\r
- vl_putpixel(offset, rgb); \\r
- zRow[i] = z; \\r
- } \\r
- span.z += span.zStep; \\r
+#define RENDER_SPAN(span) \\r
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \\r
+ for (i = 0; i < span.end; i++, offset++) { \\r
+ const DEPTH_TYPE z = FixedToDepth(span.z); \\r
+ if (z < zRow[i]) { \\r
+ vl_putpixel(offset, rgb); \\r
+ zRow[i] = z; \\r
+ } \\r
+ span.z += span.zStep; \\r
}\r
\r
#include "swrast/s_tritemp.h"\r
+#else /* MATROX */\r
+ MGAvertex m0, m1, m2;\r
+ m0.win[0] = v0->win[0];\r
+ m0.win[1] = FLIP2(v0->win[1]);\r
+ m0.win[2] = v0->win[2];\r
+ m1.win[0] = v1->win[0];\r
+ m1.win[1] = FLIP2(v1->win[1]);\r
+ m1.win[2] = v1->win[2];\r
+ m2.win[0] = v2->win[0];\r
+ m2.win[1] = FLIP2(v2->win[1]);\r
+ m2.win[2] = v2->win[2];\r
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;\r
+ mga_draw_tri_rgb_flat_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);\r
+#endif /* MATROX */\r
}\r
\r
\r
\r
/*\r
- * smooth, NON-depth-buffered, triangle.\r
+ * NON-depth-buffered iterated triangle.\r
*/\r
-static void tri_rgb_smooth (GLcontext *ctx,\r
- const SWvertex *v0,\r
- const SWvertex *v1,\r
- const SWvertex *v2)\r
+static void tri_rgb_iter (GLcontext *ctx,\r
+ const SWvertex *v0,\r
+ const SWvertex *v1,\r
+ const SWvertex *v2)\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+#ifndef MATROX\r
+ GLuint _w_ = dmesa->Buffer->width;\r
\r
#define INTERP_RGB 1\r
-#define RENDER_SPAN(span) \\r
- GLuint i, offset = FLIP2(span.y)*w + span.x; \\r
+#define RENDER_SPAN(span) \\r
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \\r
for (i = 0; i < span.end; i++, offset++) { \\r
vl_putpixel(offset, vl_mixfix(span.red, span.green, span.blue)); \\r
span.red += span.redStep; \\r
}\r
\r
#include "swrast/s_tritemp.h"\r
+#else /* MATROX */\r
+ MGAvertex m0, m1, m2;\r
+ m0.win[0] = v0->win[0];\r
+ m0.win[1] = FLIP2(v0->win[1]);\r
+ m1.win[0] = v1->win[0];\r
+ m1.win[1] = FLIP2(v1->win[1]);\r
+ m2.win[0] = v2->win[0];\r
+ m2.win[1] = FLIP2(v2->win[1]);\r
+ *(unsigned long *)m0.color = *(unsigned long *)v0->color;\r
+ *(unsigned long *)m1.color = *(unsigned long *)v1->color;\r
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;\r
+ mga_draw_tri_rgb_iter((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);\r
+#endif /* MATROX */\r
}\r
\r
\r
\r
/*\r
- * smooth, depth-buffered, triangle.\r
+ * Z-less iterated triangle.\r
*/\r
-static void tri_rgb_smooth_z (GLcontext *ctx,\r
- const SWvertex *v0,\r
- const SWvertex *v1,\r
- const SWvertex *v2)\r
+static void tri_rgb_iter_zless (GLcontext *ctx,\r
+ const SWvertex *v0,\r
+ const SWvertex *v1,\r
+ const SWvertex *v2)\r
{\r
- const DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
- GLuint w = c->Buffer->width, b = c->Buffer->height - 1;\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+#ifndef MATROX\r
+ GLuint _w_ = dmesa->Buffer->width;\r
\r
#define INTERP_Z 1\r
#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE\r
#define INTERP_RGB 1\r
\r
-#define RENDER_SPAN(span) \\r
- GLuint i, offset = FLIP2(span.y)*w + span.x; \\r
+#define RENDER_SPAN(span) \\r
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \\r
for (i = 0; i < span.end; i++, offset++) { \\r
const DEPTH_TYPE z = FixedToDepth(span.z); \\r
if (z < zRow[i]) { \\r
}\r
\r
#include "swrast/s_tritemp.h"\r
+#else /* MATROX */\r
+ MGAvertex m0, m1, m2;\r
+ m0.win[0] = v0->win[0];\r
+ m0.win[1] = FLIP2(v0->win[1]);\r
+ m0.win[2] = v0->win[2];\r
+ m1.win[0] = v1->win[0];\r
+ m1.win[1] = FLIP2(v1->win[1]);\r
+ m1.win[2] = v1->win[2];\r
+ m2.win[0] = v2->win[0];\r
+ m2.win[1] = FLIP2(v2->win[1]);\r
+ m2.win[2] = v2->win[2];\r
+ *(unsigned long *)m0.color = *(unsigned long *)v0->color;\r
+ *(unsigned long *)m1.color = *(unsigned long *)v1->color;\r
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;\r
+ mga_draw_tri_rgb_iter_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);\r
+#endif /* MATROX */\r
}\r
\r
\r
|| (ctx->Polygon.StippleFlag)\r
|| (ctx->Texture._EnabledUnits)\r
|| (swrast->_RasterMask & MULTI_DRAW_BIT)\r
- || ((ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK))) {\r
+ || (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)) {\r
return (swrast_tri_func)NULL;\r
}\r
\r
&& ctx->Depth.Func==GL_LESS\r
&& ctx->Depth.Mask==GL_TRUE\r
&& ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {\r
- return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_smooth_z : tri_rgb_flat_z;\r
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter_zless : tri_rgb_flat_zless;\r
}\r
\r
if (swrast->_RasterMask==0) { /* no depth test */\r
- return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_smooth : tri_rgb_flat;\r
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter : tri_rgb_flat;\r
}\r
\r
return (swrast_tri_func)NULL;\r
\r
\r
\r
+/****************************************************************************\r
+ * Optimized line rendering\r
+ ***************************************************************************/\r
+\r
+#ifdef MATROX\r
+static __inline void matrox_line_clip_hack (GLcontext *ctx, int _b_, MGAvertex *m0, const SWvertex *vert0, MGAvertex *m1, const SWvertex *vert1)\r
+{\r
+ int x0 = vert0->win[0];\r
+ int y0 = vert0->win[1];\r
+ int x1 = vert1->win[0];\r
+ int y1 = vert1->win[1];\r
+ /* s_linetemp.h { */\r
+ GLint w = ctx->DrawBuffer->Width;\r
+ GLint h = ctx->DrawBuffer->Height;\r
+ if ((x0==w) | (x1==w)) {\r
+ if ((x0==w) & (x1==w))\r
+ return;\r
+ x0 -= x0==w;\r
+ x1 -= x1==w;\r
+ }\r
+ if ((y0==h) | (y1==h)) {\r
+ if ((y0==h) & (y1==h))\r
+ return;\r
+ y0 -= y0==h;\r
+ y1 -= y1==h;\r
+ }\r
+ /* } s_linetemp.h */\r
+ m0->win[0] = x0;\r
+ m0->win[1] = FLIP2(y0);\r
+ m1->win[0] = x1;\r
+ m1->win[1] = FLIP2(y1);\r
+}\r
+#endif\r
+\r
+/*\r
+ * NON-depth-buffered flat line.\r
+ */\r
+static void line_rgb_flat (GLcontext *ctx,\r
+ const SWvertex *vert0,\r
+ const SWvertex *vert1)\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+#ifndef MATROX\r
+ GLuint _w_ = dmesa->Buffer->width;\r
+ GLuint rgb = vl_mixrgb(vert1->color);\r
+\r
+#define INTERP_XY 1\r
+#define CLIP_HACK 1\r
+#define PLOT(X,Y) vl_putpixel(FLIP2(Y) * _w_ + X, rgb);\r
+\r
+#include "swrast/s_linetemp.h"\r
+#else\r
+ MGAvertex m0, m1;\r
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);\r
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;\r
+ mga_draw_line_rgb_flat(&m0, &m1);\r
+#endif\r
+}\r
+\r
+\r
+\r
+/*\r
+ * Z-less flat line.\r
+ */\r
+static void line_rgb_flat_zless (GLcontext *ctx,\r
+ const SWvertex *vert0,\r
+ const SWvertex *vert1)\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+#ifndef MATROX\r
+ GLuint _w_ = dmesa->Buffer->width;\r
+ GLuint rgb = vl_mixrgb(vert1->color);\r
+\r
+#define INTERP_XY 1\r
+#define INTERP_Z 1\r
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE\r
+#define CLIP_HACK 1\r
+#define PLOT(X,Y) \\r
+ if (Z < *zPtr) { \\r
+ *zPtr = Z; \\r
+ vl_putpixel(FLIP2(Y) * _w_ + X, rgb); \\r
+ }\r
+\r
+#include "swrast/s_linetemp.h"\r
+#else\r
+ MGAvertex m0, m1;\r
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);\r
+ m0.win[2] = vert0->win[2];\r
+ m1.win[2] = vert1->win[2];\r
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;\r
+ mga_draw_line_rgb_flat_zless(&m0, &m1);\r
+#endif\r
+}\r
+\r
+\r
+\r
+#ifndef MATROX\r
+#define line_rgb_iter NULL\r
+#define line_rgb_iter_zless NULL\r
+#else /* MATROX */\r
+/*\r
+ * NON-depth-buffered iterated line.\r
+ */\r
+static void line_rgb_iter (GLcontext *ctx,\r
+ const SWvertex *vert0,\r
+ const SWvertex *vert1)\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+ MGAvertex m0, m1;\r
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);\r
+ *(unsigned long *)m0.color = *(unsigned long *)vert0->color;\r
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;\r
+ mga_draw_line_rgb_iter(&m0, &m1);\r
+}\r
+\r
+\r
+\r
+/*\r
+ * Z-less iterated line.\r
+ */\r
+static void line_rgb_iter_zless (GLcontext *ctx,\r
+ const SWvertex *vert0,\r
+ const SWvertex *vert1)\r
+{\r
+ const DMesaContext dmesa = (DMesaContext)ctx->DriverCtx;\r
+ GLuint _b_ = dmesa->Buffer->height - 1;\r
+ MGAvertex m0, m1;\r
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);\r
+ m0.win[2] = vert0->win[2];\r
+ m1.win[2] = vert1->win[2];\r
+ *(unsigned long *)m0.color = *(unsigned long *)vert0->color;\r
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;\r
+ mga_draw_line_rgb_iter_zless(&m0, &m1);\r
+}\r
+#endif /* MATROX */\r
+\r
+\r
+\r
+/*\r
+ * Analyze context state to see if we can provide a fast line function\r
+ * Otherwise, return NULL.\r
+ */\r
+static swrast_line_func dmesa_choose_line_function (GLcontext *ctx)\r
+{\r
+ const SWcontext *swrast = SWRAST_CONTEXT(ctx);\r
+\r
+ if ((ctx->RenderMode != GL_RENDER)\r
+ || (ctx->Line.SmoothFlag)\r
+ || (ctx->Texture._EnabledUnits)\r
+ || (ctx->Line.StippleFlag)\r
+ || (swrast->_RasterMask & MULTI_DRAW_BIT)\r
+ || (ctx->Line.Width!=1.0F)) {\r
+ return (swrast_line_func)NULL;\r
+ }\r
+\r
+ if (swrast->_RasterMask==DEPTH_BIT\r
+ && ctx->Depth.Func==GL_LESS\r
+ && ctx->Depth.Mask==GL_TRUE\r
+ && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {\r
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter_zless : line_rgb_flat_zless;\r
+ }\r
+\r
+ if (swrast->_RasterMask==0) { /* no depth test */\r
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter : line_rgb_flat;\r
+ }\r
+\r
+ return (swrast_line_func)NULL;\r
+}\r
+\r
+\r
+\r
+/* Override for the swrast line-selection function. Try to use one\r
+ * of our internal line functions, otherwise fall back to the\r
+ * standard swrast functions.\r
+ */\r
+static void dmesa_choose_line (GLcontext *ctx)\r
+{\r
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);\r
+\r
+ if (!(swrast->Line=dmesa_choose_line_function(ctx)))\r
+ _swrast_choose_line(ctx);\r
+}\r
+\r
+\r
+\r
/****************************************************************************\r
* Miscellaneous device driver funcs\r
***************************************************************************/\r
\r
static void clear_index (GLcontext *ctx, GLuint index)\r
{\r
- DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
-\r
- c->ClearIndex = index;\r
+ ((DMesaContext)ctx->DriverCtx)->ClearIndex = index;\r
}\r
\r
static void clear_color (GLcontext *ctx, const GLfloat color[4])\r
{\r
GLubyte col[4];\r
- DMesaContext c = (DMesaContext)ctx->DriverCtx;\r
CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);\r
CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);\r
CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);\r
CLAMPED_FLOAT_TO_UBYTE(col[3], color[3]);\r
- c->ClearColor = vl_mixrgba(col);\r
+ ((DMesaContext)ctx->DriverCtx)->ClearColor = vl_mixrgba(col);\r
}\r
\r
\r
\r
/* we can't handle color or index masking */\r
if ((*colorMask == 0xffffffff) && (ctx->Color.IndexMask == 0xffffffff)) {\r
+#ifndef MATROX\r
if (mask & DD_BACK_LEFT_BIT) {\r
int color = c->visual->rgb_flag ? c->ClearColor : c->ClearIndex;\r
\r
\r
mask &= ~DD_BACK_LEFT_BIT;\r
}\r
+#else /* MATROX */\r
+ unsigned short z = -1;\r
+ int color = c->ClearColor;\r
+ if (mask & DD_DEPTH_BIT) {\r
+ z = ctx->Depth.Clear * 0xffff;\r
+ }\r
+ if (all) {\r
+ mga_clear(mask & DD_FRONT_LEFT_BIT,\r
+ mask & DD_BACK_LEFT_BIT,\r
+ mask & DD_DEPTH_BIT,\r
+ 0, 0, c->Buffer->width, c->Buffer->height,\r
+ color, z);\r
+ } else {\r
+ mga_clear(mask & DD_FRONT_LEFT_BIT,\r
+ mask & DD_BACK_LEFT_BIT,\r
+ mask & DD_DEPTH_BIT,\r
+ x, y, width, height,\r
+ color, z);\r
+ }\r
+ mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT);\r
+#endif /* MATROX */\r
}\r
\r
if (mask) {\r
{\r
switch (name) {\r
case GL_RENDERER:\r
- return (const GLubyte *)"Mesa DJGPP\0port (c) Borca Daniel dec-2002";\r
+ return (const GLubyte *)"Mesa DJGPP"\r
+ #ifdef FX\r
+ " (FX)"\r
+ #endif\r
+ #ifdef MATROX\r
+ " (MGA)"\r
+ #endif\r
+ "\0port (c) Borca Daniel feb-2003";\r
default:\r
return NULL;\r
}\r
/****************************************************************************\r
* State\r
***************************************************************************/\r
+#define DMESA_NEW_LINE (_NEW_LINE | \\r
+ _NEW_TEXTURE | \\r
+ _NEW_LIGHT | \\r
+ _NEW_DEPTH | \\r
+ _NEW_RENDERMODE | \\r
+ _SWRAST_NEW_RASTERMASK)\r
+\r
#define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \\r
_NEW_TEXTURE | \\r
_NEW_LIGHT | \\r
{\r
SWcontext *swrast = SWRAST_CONTEXT(ctx);\r
\r
+ swrast->choose_line = dmesa_choose_line;\r
swrast->choose_triangle = dmesa_choose_tri;\r
\r
+ swrast->invalidate_line |= DMESA_NEW_LINE;\r
swrast->invalidate_triangle |= DMESA_NEW_TRIANGLE;\r
}\r
\r
/* Install swsetup for tnl->Driver.Render.*:\r
*/\r
_swsetup_Wakeup(ctx);\r
-}\r
-\r
\r
-\r
-static void dmesa_update_state (GLcontext *ctx, GLuint new_state)\r
-{\r
- struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx);\r
-\r
- /* Propogate statechange information to swrast and swrast_setup\r
- * modules. The DMesa driver has no internal GL-dependent state.\r
+ /* The span functions should be in `dmesa_update_state', but I'm\r
+ * pretty sure they will never change during the life of the Visual\r
*/\r
- _swrast_InvalidateState( ctx, new_state );\r
- _ac_InvalidateState( ctx, new_state );\r
- _tnl_InvalidateState( ctx, new_state );\r
- _swsetup_InvalidateState( ctx, new_state );\r
+#ifdef MATROX\r
+ if (((DMesaContext)ctx->DriverCtx)->visual->zbuffer == -1) {\r
+ /* Depth span/pixel functions */\r
+ dd->WriteDepthSpan = write_depth_span;\r
+ dd->WriteDepthPixels = write_depth_pixels;\r
+ dd->ReadDepthSpan = read_depth_span;\r
+ dd->ReadDepthPixels = read_depth_pixels;\r
+ }\r
+#endif\r
\r
+#ifndef MATROX\r
/* Index span/pixel functions */\r
dd->WriteCI32Span = write_index_span;\r
dd->WriteCI8Span = write_index8_span;\r
dd->WriteMonoCIPixels = write_mono_index_pixels;\r
dd->ReadCI32Span = read_index_span;\r
dd->ReadCI32Pixels = read_index_pixels;\r
+#endif\r
\r
/* RGB(A) span/pixel functions */\r
dd->WriteRGBASpan = write_rgba_span;\r
dd->ReadRGBASpan = read_rgba_span;\r
dd->ReadRGBAPixels = read_rgba_pixels;\r
}\r
-#endif\r
+\r
+\r
+\r
+static void dmesa_update_state (GLcontext *ctx, GLuint new_state)\r
+{\r
+ /* Propogate statechange information to swrast and swrast_setup\r
+ * modules. The DMesa driver has no internal GL-dependent state.\r
+ */\r
+ _swrast_InvalidateState( ctx, new_state );\r
+ _ac_InvalidateState( ctx, new_state );\r
+ _tnl_InvalidateState( ctx, new_state );\r
+ _swsetup_InvalidateState( ctx, new_state );\r
+}\r
+#endif /* FX */\r
\r
\r
\r
DMesaVisual v;\r
GLint redBits, greenBits, blueBits, alphaBits, indexBits;\r
\r
+#ifndef MATROX\r
if (!dbFlag) {\r
return NULL;\r
}\r
+#else\r
+ if (!rgbFlag) {\r
+ return NULL;\r
+ }\r
+#endif\r
\r
alphaBits = 0;\r
\r
}\r
}\r
\r
+#ifndef MATROX\r
if ((colDepth=vl_video_init(width, height, colDepth, rgbFlag, refresh)) <= 0) {\r
return NULL;\r
}\r
+#else\r
+ if (mga_open(width, height, colDepth, dbFlag ? 2 : 1, depthSize == 16, refresh) < 0) {\r
+ return NULL;\r
+ }\r
+#endif\r
\r
if (alphaFlag && (alphaBits==0)) {\r
alphaBits = 8;\r
v->depth = colDepth;\r
v->db_flag = dbFlag;\r
v->rgb_flag = rgbFlag;\r
+\r
+ v->zbuffer = (depthSize > 0) ? 1 : 0;\r
+#ifdef MATROX\r
+ mga_get(MGA_GET_HPIXELS, &v->stride_in_pixels);\r
+ if (depthSize == 16) {\r
+ v->zbuffer = -1;\r
+ }\r
+#endif\r
}\r
\r
return v;\r
\r
-#else\r
+#else /* FX */\r
\r
int i = 0, fx_attrib[32];\r
\r
fx_attrib[i] = FXMESA_NONE;\r
\r
return (DMesaVisual)fxMesaCreateBestContext(-1, width, height, fx_attrib);\r
-#endif\r
+#endif /* FX */\r
}\r
\r
\r
_mesa_destroy_visual(v->gl_visual);\r
free(v);\r
\r
+#ifndef MATROX\r
vl_video_exit();\r
+#else\r
+ mga_close(1, 1);\r
+#endif\r
+\r
#else\r
fxMesaDestroyContext((fxMesaContext)v);\r
#endif\r
\r
_mesa_initialize_framebuffer(&b->gl_buffer,\r
visual->gl_visual,\r
- visual->gl_visual->depthBits > 0,\r
+ visual->zbuffer == 1,\r
visual->gl_visual->stencilBits > 0,\r
visual->gl_visual->accumRedBits > 0,\r
visual->gl_visual->alphaBits > 0);\r
void DMesaDestroyBuffer (DMesaBuffer b)\r
{\r
#ifndef FX\r
+#ifndef MATROX\r
free(b->the_window);\r
+#endif\r
_mesa_free_framebuffer_data(&b->gl_buffer);\r
free(b);\r
#endif\r
\r
return c;\r
\r
-#else\r
-\r
+#else /* FX */\r
return (DMesaContext)visual;\r
-#endif\r
+#endif /* FX */\r
}\r
\r
\r
\r
GLboolean DMesaMoveBuffer (GLint xpos, GLint ypos)\r
{\r
-#ifndef FX\r
+#if !defined(FX) && !defined(MATROX)\r
GET_CURRENT_CONTEXT(ctx);\r
DMesaBuffer b = ((DMesaContext)ctx->DriverCtx)->Buffer;\r
\r
}\r
\r
#else\r
-\r
return GL_FALSE;\r
#endif\r
}\r
\r
GLboolean DMesaResizeBuffer (GLint width, GLint height)\r
{\r
-#ifndef FX\r
+#if !defined(FX) && !defined(MATROX)\r
GET_CURRENT_CONTEXT(ctx);\r
DMesaBuffer b = ((DMesaContext)ctx->DriverCtx)->Buffer;\r
\r
}\r
\r
#else\r
-\r
return GL_FALSE;\r
#endif\r
}\r
{\r
#ifndef FX\r
if ((c != NULL) && (b != NULL)) {\r
+#ifndef MATROX\r
if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, b->width, b->height) != 0) {\r
return GL_FALSE;\r
}\r
+#endif\r
\r
c->Buffer = b;\r
\r
}\r
\r
#else\r
-\r
fxMesaMakeCurrent((fxMesaContext)c);\r
#endif\r
\r
#ifndef FX\r
GET_CURRENT_CONTEXT(ctx);\r
_mesa_notifySwapBuffers(ctx);\r
+#ifndef MATROX\r
vl_flip();\r
+#else\r
+ if (((DMesaContext)ctx->DriverCtx)->visual->db_flag) {\r
+ mga_swapbuffers(1);\r
+ }\r
+#endif\r
#else\r
fxMesaSwapBuffers();\r
#endif\r
\r
void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue)\r
{\r
-#ifndef FX\r
+#if !defined(FX) && !defined(MATROX)\r
vl_setCI(ndx, red, green, blue);\r
#endif\r
}\r
\r
\r
\r
-void DMesaGetIntegerv (GLenum pname, GLint *params)\r
+DMesaContext DMesaGetCurrentContext (void)\r
+{\r
+#ifndef FX\r
+ GET_CURRENT_CONTEXT(ctx);\r
+ return (ctx == NULL) ? NULL : (DMesaContext)ctx->DriverCtx;\r
+#else\r
+ return (DMesaContext)fxMesaGetCurrentContext();\r
+#endif\r
+}\r
+\r
+\r
+\r
+int DMesaGetIntegerv (GLenum pname, GLint *params)\r
{\r
#ifndef FX\r
GET_CURRENT_CONTEXT(ctx);\r
#endif\r
\r
if (c == NULL) {\r
- return;\r
+ return -1;\r
}\r
\r
switch (pname) {\r
- case DMESA_Y_ORIGIN:\r
+ case DMESA_GET_SCREEN_SIZE:\r
#ifndef FX\r
- params[0] = GL_FALSE;\r
+ #ifndef MATROX\r
+ vl_get(VL_GET_SCREEN_SIZE, params);\r
#else\r
- params[0] = GL_TRUE;\r
+ mga_get(MGA_GET_SCREEN_SIZE, params);\r
#endif\r
- break;\r
- case DMESA_SCREEN_SIZE:\r
- #ifndef FX\r
- vl_get_screen_size(¶ms[0], ¶ms[1]);\r
#else\r
params[0] = c->screen_width;\r
params[1] = c->screen_height;\r
#endif\r
break;\r
- case DMESA_ARGB_ORDER:\r
+ case DMESA_GET_DRIVER_CAPS:\r
#ifndef FX\r
- params[0] = GL_FALSE;\r
+ #ifndef MATROX\r
+ params[0] = DMESA_DRIVER_SWDB_BIT;\r
#else\r
- params[0] = !c->bgrOrder;\r
+ params[0] = 0;\r
+ #endif\r
+ #else\r
+ params[0] = DMESA_DRIVER_LLWO_BIT;\r
#endif\r
break;\r
default:\r
- break;\r
+ return -1;\r
}\r
+\r
+ return 0;\r
}\r
/* _create_linear_mapping:\r
* Maps a physical address range into linear memory.\r
*/\r
-static int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)\r
+int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)\r
{\r
__dpmi_meminfo meminfo;\r
\r
/* _remove_linear_mapping:\r
* Frees the DPMI resources being used to map a linear address range.\r
*/\r
-static void _remove_linear_mapping (unsigned long *linear)\r
+void _remove_linear_mapping (unsigned long *linear)\r
{\r
__dpmi_meminfo meminfo;\r
\r
*segment = 0;\r
}\r
}\r
+\r
+\r
+\r
+/* Desc: retrieve CPU MMX capability\r
+ *\r
+ * In : -\r
+ * Out : FALSE if CPU cannot do MMX\r
+ *\r
+ * Note: -\r
+ */\r
+int _can_mmx (void)\r
+{\r
+#ifdef USE_MMX_ASM\r
+ extern int _mesa_identify_x86_cpu_features (void);\r
+ return (_mesa_identify_x86_cpu_features() & 0x00800000);\r
+#else\r
+ return 0;\r
+#endif\r
+}\r
void (*blit) (void);\r
void (*setCI_f) (int index, float red, float green, float blue);\r
void (*setCI_i) (int index, int red, int green, int blue);\r
- int (*getCIprec) (void);\r
+ int (*get) (int pname, int *params);\r
void (*restore) (void);\r
- void (*finit) (void);\r
+ void (*fini) (void);\r
} vl_driver;\r
\r
\r
/*\r
* memory mapping\r
*/\r
+int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size);\r
+void _remove_linear_mapping (unsigned long *linear);\r
int _create_selector (int *segment, unsigned long base, int size);\r
void _remove_selector (int *segment);\r
\r
/*\r
* system routines\r
*/\r
-int vl_can_mmx (void);\r
+int _can_mmx (void);\r
\r
/*\r
* asm routines to deal with virtual buffering\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W triangle template\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+/*\r
+ * Triangle Rasterizer Template\r
+ *\r
+ * This file is #include'd to generate custom triangle rasterizers.\r
+ *\r
+ * The following macros may be defined to indicate what auxillary information\r
+ * must be interplated across the triangle:\r
+ * INTERP_Z - if defined, interpolate Z values\r
+ * INTERP_RGB - if defined, interpolate RGB values\r
+ *\r
+ * TAG - function name\r
+ * CULL - enable culling for: 0=no, 1=back, -1=front\r
+ *\r
+ * SETUP_CODE - to be executed once per triangle (usually HW init)\r
+ *\r
+ * For flatshaded primitives, the provoking vertex is the final one.\r
+ * This code was designed for the origin to be in the upper-left corner.\r
+ *\r
+ * Inspired by triangle rasterizer code written by Brian Paul.\r
+ */\r
+\r
+\r
+\r
+#define TRI_SWAP(a, b) \\r
+do { \\r
+ const MGAvertex *tmp = a; \\r
+ a = b; \\r
+ b = tmp; \\r
+} while (0)\r
+\r
+void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3)\r
+{\r
+ int area;\r
+ int x1, y1, x2, y2, x3, y3;\r
+ int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy;\r
+#ifdef INTERP_RGB\r
+#define FIFO_CNT_RGB 3\r
+ int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db;\r
+ int drdx, drdy, dgdx, dgdy, dbdx, dbdy;\r
+#else\r
+#define FIFO_CNT_RGB 0\r
+#endif\r
+#ifdef INTERP_Z\r
+#define FIFO_CNT_Z 1\r
+ int dzdx, dzdy;\r
+ int eMaj_dz, eBot_dz;\r
+ int z1, z2, z3;\r
+#else\r
+#define FIFO_CNT_Z 0\r
+#endif\r
+\r
+#if defined(INTERP_Z) || defined(INTERP_RGB)\r
+ double one_area;\r
+#ifndef INTERP_RGB\r
+ int red = v3->color[0];\r
+ int green = v3->color[1];\r
+ int blue = v3->color[2];\r
+#endif\r
+#else\r
+ unsigned long color = mga_mixrgb_full(v3->color);\r
+#endif\r
+\r
+ int sgn = 0;\r
+\r
+ /* sort along the vertical axis */\r
+ if (v2->win[1] < v1->win[1]) {\r
+ TRI_SWAP(v1, v2);\r
+#ifdef CULL\r
+ cull = -cull;\r
+#endif\r
+ }\r
+\r
+ if (v3->win[1] < v1->win[1]) {\r
+ TRI_SWAP(v1, v3);\r
+ TRI_SWAP(v2, v3);\r
+ } else if (v3->win[1] < v2->win[1]) {\r
+ TRI_SWAP(v2, v3);\r
+#ifdef CULL\r
+ cull = -cull;\r
+#endif \r
+ }\r
+\r
+ x1 = v1->win[0];\r
+ y1 = v1->win[1];\r
+ x2 = v2->win[0];\r
+ y2 = v2->win[1];\r
+ x3 = v3->win[0];\r
+ y3 = v3->win[1];\r
+\r
+ /* compute deltas for each edge */\r
+ eMaj_dx = x3 - x1;\r
+ eMaj_dy = y3 - y1;\r
+ eBot_dx = x2 - x1;\r
+ eBot_dy = y2 - y1;\r
+ eTop_dx = x3 - x2;\r
+ eTop_dy = y3 - y2;\r
+\r
+ /* compute area */\r
+ if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) {\r
+ return;\r
+ }\r
+#ifdef CULL\r
+ if ((area * cull) > 0) {\r
+ return;\r
+ }\r
+#endif\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+#ifdef SETUP_CODE\r
+ SETUP_CODE\r
+#endif\r
+\r
+ /* draw lower triangle */\r
+#if defined(INTERP_Z) || defined(INTERP_RGB)\r
+ one_area = (double)(1<<15) / (double)area;\r
+ mga_fifo(1);\r
+#else\r
+ mga_fifo(2);\r
+ mga_outl(M_FCOL, color);\r
+#endif\r
+ mga_outl(M_YDST, y1);\r
+\r
+#ifdef INTERP_Z\r
+ z1 = v1->win[2];\r
+ z2 = v2->win[2];\r
+ z3 = v3->win[2];\r
+\r
+ /* compute d?/dx and d?/dy derivatives */\r
+ eMaj_dz = z3 - z1;\r
+ eBot_dz = z2 - z1;\r
+ dzdx = (eMaj_dz * eBot_dy - eMaj_dy * eBot_dz) * one_area;\r
+ dzdy = (eMaj_dx * eBot_dz - eMaj_dz * eBot_dx) * one_area;\r
+\r
+#ifndef INTERP_RGB\r
+ mga_fifo(11);\r
+ mga_outl(M_DR2, dzdx);\r
+ mga_outl(M_DR3, dzdy);\r
+ mga_outl(M_DR4, red<<15);\r
+ mga_outl(M_DR6, 0);\r
+ mga_outl(M_DR7, 0);\r
+ mga_outl(M_DR8, green<<15);\r
+ mga_outl(M_DR10, 0);\r
+ mga_outl(M_DR11, 0);\r
+ mga_outl(M_DR12, blue<<15);\r
+ mga_outl(M_DR14, 0);\r
+ mga_outl(M_DR15, 0);\r
+#else\r
+ mga_fifo(2);\r
+ mga_outl(M_DR2, dzdx);\r
+ mga_outl(M_DR3, dzdy);\r
+#endif\r
+#endif\r
+\r
+#ifdef INTERP_RGB\r
+ /* compute color deltas */\r
+ eMaj_dr = v3->color[0] - v1->color[0];\r
+ eBot_dr = v2->color[0] - v1->color[0];\r
+ eMaj_dg = v3->color[1] - v1->color[1];\r
+ eBot_dg = v2->color[1] - v1->color[1];\r
+ eMaj_db = v3->color[2] - v1->color[2];\r
+ eBot_db = v2->color[2] - v1->color[2];\r
+\r
+ /* compute color increments */\r
+ drdx = (eMaj_dr * eBot_dy - eMaj_dy * eBot_dr) * one_area;\r
+ drdy = (eMaj_dx * eBot_dr - eMaj_dr * eBot_dx) * one_area;\r
+ dgdx = (eMaj_dg * eBot_dy - eMaj_dy * eBot_dg) * one_area;\r
+ dgdy = (eMaj_dx * eBot_dg - eMaj_dg * eBot_dx) * one_area;\r
+ dbdx = (eMaj_db * eBot_dy - eMaj_dy * eBot_db) * one_area;\r
+ dbdy = (eMaj_dx * eBot_db - eMaj_db * eBot_dx) * one_area;\r
+\r
+ mga_fifo(6);\r
+ mga_outl(M_DR6, drdx);\r
+ mga_outl(M_DR7, drdy);\r
+ mga_outl(M_DR10, dgdx);\r
+ mga_outl(M_DR11, dgdy);\r
+ mga_outl(M_DR14, dbdx);\r
+ mga_outl(M_DR15, dbdy);\r
+#endif\r
+\r
+ if (area > 0) { /* major edge on the right */\r
+ if (eBot_dy) { /* have lower triangle */\r
+ mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR0, eBot_dy);\r
+ if (x2 < x1) {\r
+ mga_outl(M_AR1, eBot_dx + eBot_dy - 1);\r
+ mga_outl(M_AR2, eBot_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eBot_dx);\r
+ mga_outl(M_AR2, -eBot_dx);\r
+ }\r
+\r
+ mga_outl(M_AR6, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR5, eMaj_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eMaj_dx);\r
+ mga_outl(M_AR5, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x1<<16) | x1);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z1<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v1->color[0]<<15);\r
+ mga_outl(M_DR8, v1->color[1]<<15);\r
+ mga_outl(M_DR12, v1->color[2]<<15);\r
+#endif\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eBot_dy);\r
+ } else { /* no lower triangle */\r
+ mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR6, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR5, eMaj_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eMaj_dx);\r
+ mga_outl(M_AR5, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x1<<16) | x2);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z2<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v2->color[0]<<15);\r
+ mga_outl(M_DR8, v2->color[1]<<15);\r
+ mga_outl(M_DR12, v2->color[2]<<15);\r
+#endif\r
+ }\r
+\r
+ /* draw upper triangle */\r
+ if (eTop_dy) {\r
+ mga_fifo(5);\r
+ mga_outl(M_AR0, eTop_dy);\r
+ if (x3 < x2) {\r
+ mga_outl(M_AR1, eTop_dx + eTop_dy - 1);\r
+ mga_outl(M_AR2, eTop_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eTop_dx);\r
+ mga_outl(M_AR2, -eTop_dx);\r
+ sgn &= ~M_SDXL;\r
+ }\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eTop_dy);\r
+ }\r
+ } else { /* major edge on the left */\r
+ if (eBot_dy) { /* have lower triangle */\r
+ mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR0, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR2, eMaj_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eMaj_dx);\r
+ mga_outl(M_AR2, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_AR6, eBot_dy);\r
+ if (x2 < x1) {\r
+ mga_outl(M_AR4, eBot_dx + eBot_dy - 1);\r
+ mga_outl(M_AR5, eBot_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eBot_dx);\r
+ mga_outl(M_AR5, -eBot_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x1<<16) | x1);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z1<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v1->color[0]<<15);\r
+ mga_outl(M_DR8, v1->color[1]<<15);\r
+ mga_outl(M_DR12, v1->color[2]<<15);\r
+#endif\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eBot_dy);\r
+ } else { /* no lower triangle */\r
+ mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR0, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR2, eMaj_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eMaj_dx);\r
+ mga_outl(M_AR2, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x2<<16) | x1);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z1<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v1->color[0]<<15);\r
+ mga_outl(M_DR8, v1->color[1]<<15);\r
+ mga_outl(M_DR12, v1->color[2]<<15);\r
+#endif\r
+ }\r
+\r
+ /* draw upper triangle */\r
+ if (eTop_dy) {\r
+ mga_fifo(5);\r
+ mga_outl(M_AR6, eTop_dy);\r
+ if (x3 < x2) {\r
+ mga_outl(M_AR4, eTop_dx + eTop_dy - 1);\r
+ mga_outl(M_AR5, eTop_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eTop_dx);\r
+ mga_outl(M_AR5, -eTop_dx);\r
+ sgn &= ~M_SDXR;\r
+ }\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eTop_dy);\r
+ }\r
+ }\r
+}\r
+\r
+#undef FIFO_CNT_RGB\r
+#undef FIFO_CNT_Z\r
+\r
+#undef TRI_SWAP\r
+\r
+#undef SETUP_CODE\r
+#undef INTERP_RGB\r
+#undef INTERP_Z\r
+#undef CULL\r
+#undef TAG\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W triangle template\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+/*\r
+ * Triangle Rasterizer Template\r
+ *\r
+ * This file is #include'd to generate custom triangle rasterizers.\r
+ *\r
+ * The following macros may be defined to indicate what auxillary information\r
+ * must be interplated across the triangle:\r
+ * INTERP_Z - if defined, interpolate Z values\r
+ * INTERP_RGB - if defined, interpolate RGB values\r
+ *\r
+ * TAG - function name\r
+ * CULL - enable culling for: 0=no, 1=back, -1=front\r
+ *\r
+ * SETUP_CODE - to be executed once per triangle (usually HW init)\r
+ *\r
+ * For flatshaded primitives, the provoking vertex is the final one.\r
+ * This code was designed for the origin to be in the upper-left corner.\r
+ *\r
+ * Inspired by triangle rasterizer code written by Brian Paul.\r
+ */\r
+\r
+\r
+\r
+#define TRI_SWAP(a, b) \\r
+do { \\r
+ const MGAvertex *tmp = a; \\r
+ a = b; \\r
+ b = tmp; \\r
+} while (0)\r
+\r
+void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3)\r
+{\r
+ int area;\r
+ int x1, y1, x2, y2, x3, y3;\r
+ int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy;\r
+#ifdef INTERP_RGB\r
+#define FIFO_CNT_RGB 3\r
+ int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db;\r
+ int drdx, drdy, dgdx, dgdy, dbdx, dbdy;\r
+#else\r
+#define FIFO_CNT_RGB 0\r
+#endif\r
+#ifdef INTERP_Z\r
+#define FIFO_CNT_Z 1\r
+ int dzdx, dzdy;\r
+ int eMaj_dz, eBot_dz;\r
+ int z1, z2, z3;\r
+#else\r
+#define FIFO_CNT_Z 0\r
+#endif\r
+\r
+#if defined(INTERP_Z) || defined(INTERP_RGB)\r
+#ifndef INTERP_RGB\r
+ int red = v3->color[0];\r
+ int green = v3->color[1];\r
+ int blue = v3->color[2];\r
+#endif\r
+#else\r
+ unsigned long color = mga_mixrgb_full(v3->color);\r
+#endif\r
+\r
+ int sgn = 0;\r
+\r
+ /* sort along the vertical axis */\r
+ if (v2->win[1] < v1->win[1]) {\r
+ TRI_SWAP(v1, v2);\r
+#ifdef CULL\r
+ cull = -cull;\r
+#endif\r
+ }\r
+\r
+ if (v3->win[1] < v1->win[1]) {\r
+ TRI_SWAP(v1, v3);\r
+ TRI_SWAP(v2, v3);\r
+ } else if (v3->win[1] < v2->win[1]) {\r
+ TRI_SWAP(v2, v3);\r
+#ifdef CULL\r
+ cull = -cull;\r
+#endif \r
+ }\r
+\r
+ x1 = v1->win[0];\r
+ y1 = v1->win[1];\r
+ x2 = v2->win[0];\r
+ y2 = v2->win[1];\r
+ x3 = v3->win[0];\r
+ y3 = v3->win[1];\r
+\r
+ /* compute deltas for each edge */\r
+ eMaj_dx = x3 - x1;\r
+ eMaj_dy = y3 - y1;\r
+ eBot_dx = x2 - x1;\r
+ eBot_dy = y2 - y1;\r
+ eTop_dx = x3 - x2;\r
+ eTop_dy = y3 - y2;\r
+\r
+ /* compute area */\r
+ if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) {\r
+ return;\r
+ }\r
+#ifdef CULL\r
+ if ((area * cull) > 0) {\r
+ return;\r
+ }\r
+#endif\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+#ifdef SETUP_CODE\r
+ SETUP_CODE\r
+#endif\r
+\r
+ /* draw lower triangle */\r
+#if defined(INTERP_Z) || defined(INTERP_RGB)\r
+ mga_fifo(1);\r
+#else\r
+ mga_fifo(2);\r
+ mga_outl(M_FCOL, color);\r
+#endif\r
+ mga_outl(M_YDST, y1);\r
+\r
+#ifdef INTERP_Z\r
+ z1 = v1->win[2];\r
+ z2 = v2->win[2];\r
+ z3 = v3->win[2];\r
+\r
+ /* compute d?/dx and d?/dy derivatives */\r
+ eMaj_dz = z3 - z1;\r
+ eBot_dz = z2 - z1;\r
+ dzdx = ((long long)(eMaj_dz * eBot_dy - eMaj_dy * eBot_dz)<<15) / area;\r
+ dzdy = ((long long)(eMaj_dx * eBot_dz - eMaj_dz * eBot_dx)<<15) / area;\r
+\r
+#ifndef INTERP_RGB\r
+ mga_fifo(11);\r
+ mga_outl(M_DR2, dzdx);\r
+ mga_outl(M_DR3, dzdy);\r
+ mga_outl(M_DR4, red<<15);\r
+ mga_outl(M_DR6, 0);\r
+ mga_outl(M_DR7, 0);\r
+ mga_outl(M_DR8, green<<15);\r
+ mga_outl(M_DR10, 0);\r
+ mga_outl(M_DR11, 0);\r
+ mga_outl(M_DR12, blue<<15);\r
+ mga_outl(M_DR14, 0);\r
+ mga_outl(M_DR15, 0);\r
+#else\r
+ mga_fifo(2);\r
+ mga_outl(M_DR2, dzdx);\r
+ mga_outl(M_DR3, dzdy);\r
+#endif\r
+#endif\r
+\r
+#ifdef INTERP_RGB\r
+ /* compute color deltas */\r
+ eMaj_dr = v3->color[0] - v1->color[0];\r
+ eBot_dr = v2->color[0] - v1->color[0];\r
+ eMaj_dg = v3->color[1] - v1->color[1];\r
+ eBot_dg = v2->color[1] - v1->color[1];\r
+ eMaj_db = v3->color[2] - v1->color[2];\r
+ eBot_db = v2->color[2] - v1->color[2];\r
+\r
+ /* compute color increments */\r
+ drdx = ((long long)(eMaj_dr * eBot_dy - eMaj_dy * eBot_dr)<<15) / area;\r
+ drdy = ((long long)(eMaj_dx * eBot_dr - eMaj_dr * eBot_dx)<<15) / area;\r
+ dgdx = ((long long)(eMaj_dg * eBot_dy - eMaj_dy * eBot_dg)<<15) / area;\r
+ dgdy = ((long long)(eMaj_dx * eBot_dg - eMaj_dg * eBot_dx)<<15) / area;\r
+ dbdx = ((long long)(eMaj_db * eBot_dy - eMaj_dy * eBot_db)<<15) / area;\r
+ dbdy = ((long long)(eMaj_dx * eBot_db - eMaj_db * eBot_dx)<<15) / area;\r
+\r
+ mga_fifo(6);\r
+ mga_outl(M_DR6, drdx);\r
+ mga_outl(M_DR7, drdy);\r
+ mga_outl(M_DR10, dgdx);\r
+ mga_outl(M_DR11, dgdy);\r
+ mga_outl(M_DR14, dbdx);\r
+ mga_outl(M_DR15, dbdy);\r
+#endif\r
+\r
+ if (area > 0) { /* major edge on the right */\r
+ if (eBot_dy) { /* have lower triangle */\r
+ mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR0, eBot_dy);\r
+ if (x2 < x1) {\r
+ mga_outl(M_AR1, eBot_dx + eBot_dy - 1);\r
+ mga_outl(M_AR2, eBot_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eBot_dx);\r
+ mga_outl(M_AR2, -eBot_dx);\r
+ }\r
+\r
+ mga_outl(M_AR6, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR5, eMaj_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eMaj_dx);\r
+ mga_outl(M_AR5, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x1<<16) | x1);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z1<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v1->color[0]<<15);\r
+ mga_outl(M_DR8, v1->color[1]<<15);\r
+ mga_outl(M_DR12, v1->color[2]<<15);\r
+#endif\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eBot_dy);\r
+ } else { /* no lower triangle */\r
+ mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR6, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR5, eMaj_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eMaj_dx);\r
+ mga_outl(M_AR5, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x1<<16) | x2);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z2<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v2->color[0]<<15);\r
+ mga_outl(M_DR8, v2->color[1]<<15);\r
+ mga_outl(M_DR12, v2->color[2]<<15);\r
+#endif\r
+ }\r
+\r
+ /* draw upper triangle */\r
+ if (eTop_dy) {\r
+ mga_fifo(5);\r
+ mga_outl(M_AR0, eTop_dy);\r
+ if (x3 < x2) {\r
+ mga_outl(M_AR1, eTop_dx + eTop_dy - 1);\r
+ mga_outl(M_AR2, eTop_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eTop_dx);\r
+ mga_outl(M_AR2, -eTop_dx);\r
+ sgn &= ~M_SDXL;\r
+ }\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eTop_dy);\r
+ }\r
+ } else { /* major edge on the left */\r
+ if (eBot_dy) { /* have lower triangle */\r
+ mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR0, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR2, eMaj_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eMaj_dx);\r
+ mga_outl(M_AR2, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_AR6, eBot_dy);\r
+ if (x2 < x1) {\r
+ mga_outl(M_AR4, eBot_dx + eBot_dy - 1);\r
+ mga_outl(M_AR5, eBot_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eBot_dx);\r
+ mga_outl(M_AR5, -eBot_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x1<<16) | x1);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z1<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v1->color[0]<<15);\r
+ mga_outl(M_DR8, v1->color[1]<<15);\r
+ mga_outl(M_DR12, v1->color[2]<<15);\r
+#endif\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eBot_dy);\r
+ } else { /* no lower triangle */\r
+ mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);\r
+\r
+ mga_outl(M_AR0, eMaj_dy);\r
+ if (x3 < x1) {\r
+ mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);\r
+ mga_outl(M_AR2, eMaj_dx);\r
+ sgn |= M_SDXL;\r
+ } else {\r
+ mga_outl(M_AR1, -eMaj_dx);\r
+ mga_outl(M_AR2, -eMaj_dx);\r
+ }\r
+\r
+ mga_outl(M_FXBNDRY, (x2<<16) | x1);\r
+#ifdef INTERP_Z\r
+ mga_outl(M_DR0, z1<<15);\r
+#endif\r
+#ifdef INTERP_RGB\r
+ mga_outl(M_DR4, v1->color[0]<<15);\r
+ mga_outl(M_DR8, v1->color[1]<<15);\r
+ mga_outl(M_DR12, v1->color[2]<<15);\r
+#endif\r
+ }\r
+\r
+ /* draw upper triangle */\r
+ if (eTop_dy) {\r
+ mga_fifo(5);\r
+ mga_outl(M_AR6, eTop_dy);\r
+ if (x3 < x2) {\r
+ mga_outl(M_AR4, eTop_dx + eTop_dy - 1);\r
+ mga_outl(M_AR5, eTop_dx);\r
+ sgn |= M_SDXR;\r
+ } else {\r
+ mga_outl(M_AR4, -eTop_dx);\r
+ mga_outl(M_AR5, -eTop_dx);\r
+ sgn &= ~M_SDXR;\r
+ }\r
+ mga_outl(M_SGN, sgn);\r
+ mga_outl(M_LEN | M_EXEC, eTop_dy);\r
+ }\r
+ }\r
+}\r
+\r
+#undef FIFO_CNT_RGB\r
+#undef FIFO_CNT_Z\r
+\r
+#undef TRI_SWAP\r
+\r
+#undef SETUP_CODE\r
+#undef INTERP_RGB\r
+#undef INTERP_Z\r
+#undef CULL\r
+#undef TAG\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ *\r
+ * Thanks to Shawn Hargreaves for FreeBE/AF\r
+ */\r
+\r
+\r
+#include <dpmi.h>\r
+#include <stdlib.h>\r
+#include <string.h>\r
+\r
+#include "../internal.h"\r
+#include "mga_reg.h"\r
+#include "mga_hw.h"\r
+#include "mga_mode.h"\r
+#include "mga.h"\r
+\r
+\r
+\r
+/* cached drawing engine state */\r
+#define OP_NONE 0\r
+\r
+#define OP_DRAWRECT (\\r
+ M_DWG_TRAP | /* opcod */ \\r
+ M_DWG_BLK | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_NOZCMP | /* zmode */ \\r
+ M_DWG_SOLID | /* solid */ \\r
+ M_DWG_ARZERO | /* arzero */ \\r
+ M_DWG_SGNZERO | /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC /* bop */ \\r
+ /* trans */ \\r
+ /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWRECT_TX32BGR (\\r
+ M_DWG_TEXTURE_TRAP | /* opcod */ \\r
+ M_DWG_I | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_NOZCMP | /* zmode */ \\r
+ /* solid */ \\r
+ M_DWG_ARZERO | /* arzero */ \\r
+ M_DWG_SGNZERO | /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC | /* bop */ \\r
+ /* trans */ \\r
+ M_DWG_BU32BGR /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWRECT_TX24BGR (\\r
+ M_DWG_TEXTURE_TRAP | /* opcod */ \\r
+ M_DWG_I | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_NOZCMP | /* zmode */ \\r
+ /* solid */ \\r
+ M_DWG_ARZERO | /* arzero */ \\r
+ M_DWG_SGNZERO | /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC | /* bop */ \\r
+ /* trans */ \\r
+ M_DWG_BU24BGR /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWLINE (\\r
+ M_DWG_AUTOLINE_CLOSE | /* opcod */ \\r
+ M_DWG_RPL | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_NOZCMP | /* zmode */ \\r
+ M_DWG_SOLID | /* solid */ \\r
+ /* arzero */ \\r
+ /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC | /* bop */ \\r
+ /* trans */ \\r
+ M_DWG_BFCOL /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWLINE_I (\\r
+ M_DWG_AUTOLINE_CLOSE | /* opcod */ \\r
+ M_DWG_I | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_NOZCMP | /* zmode */ \\r
+ /* solid */ \\r
+ /* arzero */ \\r
+ /* sgnzero */ \\r
+ /* shftzero */ \\r
+ M_DWG_BOP_SRC | /* bop */ \\r
+ /* trans */ \\r
+ M_DWG_BFCOL /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWLINE_ZI (\\r
+ M_DWG_AUTOLINE_CLOSE | /* opcod */ \\r
+ M_DWG_ZI | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_ZLT | /* zmode */ \\r
+ /* solid */ \\r
+ /* arzero */ \\r
+ /* sgnzero */ \\r
+ /* shftzero */ \\r
+ M_DWG_BOP_SRC | /* bop */ \\r
+ /* trans */ \\r
+ M_DWG_BFCOL /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWTRAP (\\r
+ M_DWG_TRAP | /* opcod */ \\r
+ M_DWG_BLK | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_NOZCMP | /* zmode */ \\r
+ M_DWG_SOLID | /* solid */ \\r
+ /* arzero */ \\r
+ /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC /* bop */ \\r
+ /* trans */ \\r
+ /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWTRAP_I (\\r
+ M_DWG_TRAP | /* opcod */ \\r
+ M_DWG_I | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_NOZCMP | /* zmode */ \\r
+ /* solid */ \\r
+ /* arzero */ \\r
+ /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC /* bop */ \\r
+ /* trans */ \\r
+ /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_DRAWTRAP_ZI (\\r
+ M_DWG_TRAP | /* opcod */ \\r
+ M_DWG_ZI | /* atype */ \\r
+ /* linear */ \\r
+ M_DWG_ZLT | /* zmode */ \\r
+ /* solid */ \\r
+ /* arzero */ \\r
+ /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC /* bop */ \\r
+ /* trans */ \\r
+ /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_ILOAD_32BGR (\\r
+ M_DWG_ILOAD | /* opcod */ \\r
+ M_DWG_RPL | /* atype */ \\r
+ /* linear */ \\r
+ /* zmode */ \\r
+ /* solid */ \\r
+ /* arzero */ \\r
+ M_DWG_SGNZERO | /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC | /* bop */ \\r
+ /* trans */ \\r
+ M_DWG_BU32BGR /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+#define OP_ILOAD_24BGR (\\r
+ M_DWG_ILOAD | /* opcod */ \\r
+ M_DWG_RPL | /* atype */ \\r
+ /* linear */ \\r
+ /* zmode */ \\r
+ /* solid */ \\r
+ /* arzero */ \\r
+ M_DWG_SGNZERO | /* sgnzero */ \\r
+ M_DWG_SHFTZERO | /* shftzero */ \\r
+ M_DWG_BOP_SRC | /* bop */ \\r
+ /* trans */ \\r
+ M_DWG_BU24BGR /* bltmod */ \\r
+ /* pattern */ \\r
+ /* transc */ )\r
+\r
+\r
+\r
+/* internal hardware data structures */\r
+static int interleave;\r
+static unsigned long zorg;\r
+static unsigned long vram;\r
+static char card_name[80];\r
+\r
+\r
+\r
+/* some info about current mode */\r
+static int __bpp, __bypp;\r
+static int __pixwidth, __bytwidth, __pagewidth, __width, __height, __zheight;\r
+static int __operation;\r
+static int __scrollx, __scrolly;\r
+\r
+\r
+\r
+/* buffers */\r
+static int mga_readbuffer, mga_writebuffer;\r
+static long mga_readbuffer_ptr, mga_writebuffer_ptr;\r
+static long mga_backbuffer_ptr, mga_frontbuffer_ptr;\r
+\r
+\r
+\r
+/* lookup table for scaling 2 bit colors up to 8 bits */\r
+static int _rgb_scale_2[4] = {\r
+ 0, 85, 170, 255\r
+};\r
+\r
+/* lookup table for scaling 3 bit colors up to 8 bits */\r
+static int _rgb_scale_3[8] = {\r
+ 0, 36, 73, 109, 146, 182, 219, 255\r
+};\r
+\r
+/* lookup table for scaling 5 bit colors up to 8 bits */\r
+static int _rgb_scale_5[32] = {\r
+ 0, 8, 16, 25, 33, 41, 49, 58,\r
+ 66, 74, 82, 90, 99, 107, 115, 123,\r
+ 132, 140, 148, 156, 165, 173, 181, 189,\r
+ 197, 206, 214, 222, 230, 239, 247, 255\r
+};\r
+\r
+/* lookup table for scaling 6 bit colors up to 8 bits */\r
+static int _rgb_scale_6[64] = {\r
+ 0, 4, 8, 12, 16, 20, 24, 28,\r
+ 32, 36, 40, 45, 49, 53, 57, 61,\r
+ 65, 69, 73, 77, 81, 85, 89, 93,\r
+ 97, 101, 105, 109, 113, 117, 121, 125,\r
+ 130, 134, 138, 142, 146, 150, 154, 158,\r
+ 162, 166, 170, 174, 178, 182, 186, 190,\r
+ 194, 198, 202, 206, 210, 215, 219, 223,\r
+ 227, 231, 235, 239, 243, 247, 251, 255\r
+};\r
+\r
+\r
+\r
+/*\r
+ * pixel/color routines\r
+ */\r
+void (*mga_putpixel) (unsigned int offset, int color);\r
+int (*mga_getpixel) (unsigned int offset);\r
+void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]);\r
+int (*mga_mixrgb) (const unsigned char rgb[]);\r
+static int (*mga_mixrgb_full) (const unsigned char rgb[]);\r
+\r
+\r
+\r
+/* mga_fifo:\r
+ * Waits until there are at least <n> free slots in the FIFO buffer.\r
+ */\r
+#define mga_fifo(n) do { } while (mga_inb(M_FIFOSTATUS) < (n))\r
+\r
+\r
+\r
+static int _mga_rread (int port, int index)\r
+{\r
+ mga_select();\r
+ mga_outb(port, index);\r
+ return mga_inb(port+1);\r
+}\r
+\r
+\r
+\r
+static void _mga_rwrite (int port, int index, int v)\r
+{\r
+ mga_select();\r
+ mga_outb(port, index);\r
+ mga_outb(port+1, v);\r
+}\r
+\r
+\r
+\r
+static void _mga_ralter (int port, int index, int mask, int v)\r
+{\r
+ int temp;\r
+ temp = _mga_rread(port, index);\r
+ temp &= (~mask);\r
+ temp |= (v & mask);\r
+ _mga_rwrite(port, index, temp);\r
+}\r
+\r
+\r
+\r
+/* WaitTillIdle:\r
+ * Delay until the hardware controller has finished drawing.\r
+ */\r
+void mga_wait_idle (void)\r
+{\r
+ int tries = 2;\r
+\r
+ /*hwptr_unselect(oldptr);*/\r
+\r
+ mga_select();\r
+\r
+ while (tries--) {\r
+ do {\r
+ } while (!(mga_inl(M_FIFOSTATUS) & 0x200));\r
+\r
+ do {\r
+ } while (mga_inl(M_STATUS) & 0x10000);\r
+\r
+ mga_outb(M_CRTC_INDEX, 0);\r
+ }\r
+\r
+ /*hwptr_select(oldptr);*/\r
+}\r
+\r
+\r
+\r
+/* Desc: Waits for the next vertical sync period.\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static void _mga_wait_retrace (void)\r
+{\r
+ int t1 = 0;\r
+ int t2 = 0;\r
+\r
+ do {\r
+ t1 = t2;\r
+ t2 = mga_inl(M_VCOUNT);\r
+ } while (t2 >= t1);\r
+}\r
+\r
+\r
+\r
+/* Desc: fix scan lines\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static unsigned long _mga_fix_scans (unsigned long l)\r
+{\r
+ unsigned long m = 0;\r
+\r
+ switch (__bpp) {\r
+ case 8:\r
+ m = interleave?128:64;\r
+ break;\r
+ case 15:\r
+ case 16:\r
+ m = interleave?64:32;\r
+ break;\r
+ case 24:\r
+ m = interleave?128:64;\r
+ break;\r
+ case 32:\r
+ m = 32;\r
+ break;\r
+ }\r
+\r
+ m -= 1;\r
+ return (l + m) & ~m;\r
+}\r
+\r
+\r
+\r
+/* Desc: HW scrolling function\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: view Z-buffer in 16bit modes: _mga_display_start(0, 0, __height, 1)\r
+ */\r
+void mga_display_start (long boffset, long x, long y, long waitVRT)\r
+{\r
+ long addr;\r
+\r
+ mga_select();\r
+\r
+ if (waitVRT >= 0) {\r
+\r
+ addr = __bytwidth * y + (boffset + x) * __bypp;\r
+\r
+ if (interleave) {\r
+ addr /= 8;\r
+ } else {\r
+ addr /= 4;\r
+ }\r
+\r
+ _mga_rwrite(M_CRTC_INDEX, 0x0D, (addr)&0xFF);\r
+ _mga_rwrite(M_CRTC_INDEX, 0x0C, (addr>>8)&0xFF);\r
+ _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x0F, (addr>>16)&0x0F);\r
+\r
+ while (waitVRT--) {\r
+ _mga_wait_retrace();\r
+ }\r
+ }\r
+\r
+ __scrollx = x;\r
+ __scrolly = y;\r
+}\r
+\r
+\r
+\r
+/* Desc: set READ buffer\r
+ *\r
+ * In : either FRONT or BACK buffer\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_set_readbuffer (int buffer)\r
+{\r
+ mga_readbuffer = buffer;\r
+\r
+ mga_readbuffer_ptr = (mga_readbuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr;\r
+}\r
+\r
+\r
+\r
+/* Desc: set WRITE buffer\r
+ *\r
+ * In : either FRONT or BACK buffer\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_set_writebuffer (int buffer)\r
+{\r
+ mga_writebuffer = buffer;\r
+\r
+ mga_writebuffer_ptr = (mga_writebuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr;\r
+\r
+ mga_select();\r
+ mga_fifo(1);\r
+ mga_outl(M_YDSTORG, mga_writebuffer_ptr);\r
+\r
+ __operation = OP_NONE;\r
+}\r
+\r
+\r
+\r
+/* Desc: swap buffers\r
+ *\r
+ * In : number of vertical retraces to wait\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_swapbuffers (int swapinterval)\r
+{\r
+ /* flip the buffers */\r
+ mga_backbuffer_ptr ^= __pagewidth;\r
+ mga_frontbuffer_ptr ^= __pagewidth;\r
+\r
+ /* update READ/WRITE pointers */\r
+ mga_set_readbuffer(mga_readbuffer);\r
+ mga_set_writebuffer(mga_writebuffer);\r
+\r
+ /* make sure we always see the FRONT buffer */\r
+ mga_display_start(mga_frontbuffer_ptr, __scrollx, __scrolly, swapinterval);\r
+}\r
+\r
+\r
+\r
+/* Desc: color composition (w/o ALPHA)\r
+ *\r
+ * In : array of integers (R, G, B)\r
+ * Out : color\r
+ *\r
+ * Note: -\r
+ */\r
+static __inline int _mga_mixrgb8 (const unsigned char rgb[])\r
+{\r
+ return (rgb[0]&0xe0)|((rgb[1]>>5)<<2)|(rgb[2]>>6);\r
+}\r
+static __inline int _mga_mixrgb15 (const unsigned char rgb[])\r
+{\r
+ return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3);\r
+}\r
+static __inline int _mga_mixrgb16 (const unsigned char rgb[])\r
+{\r
+ return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3);\r
+}\r
+static __inline int _mga_mixrgb32 (const unsigned char rgb[])\r
+{\r
+ return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);\r
+}\r
+\r
+\r
+\r
+/* Desc: color composition (w/o ALPHA) + replication\r
+ *\r
+ * In : array of integers (R, G, B)\r
+ * Out : color\r
+ *\r
+ * Note: -\r
+ */\r
+static int _mga_mixrgb8_full (const unsigned char rgb[])\r
+{\r
+ int color = _mga_mixrgb8(rgb);\r
+ color |= color<<8;\r
+ return (color<<16) | color;\r
+}\r
+static int _mga_mixrgb15_full (const unsigned char rgb[])\r
+{\r
+ int color = _mga_mixrgb15(rgb);\r
+ return (color<<16) | color;\r
+}\r
+static int _mga_mixrgb16_full (const unsigned char rgb[])\r
+{\r
+ int color = _mga_mixrgb16(rgb);\r
+ return (color<<16) | color;\r
+}\r
+#define _mga_mixrgb32_full _mga_mixrgb32\r
+\r
+\r
+\r
+/* Desc: putpixel\r
+ *\r
+ * In : pixel offset, pixel value\r
+ * Out : -\r
+ *\r
+ * Note: uses current write buffer\r
+ */\r
+static void _mga_putpixel8 (unsigned int offset, int color)\r
+{\r
+ hwptr_pokeb(mgaptr.linear_map, mga_writebuffer_ptr + offset, color);\r
+}\r
+#define _mga_putpixel15 _mga_putpixel16\r
+static void _mga_putpixel16 (unsigned int offset, int color)\r
+{\r
+ hwptr_pokew(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 2, color);\r
+}\r
+static void _mga_putpixel32 (unsigned int offset, int color)\r
+{\r
+ hwptr_pokel(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 4, color);\r
+}\r
+\r
+\r
+\r
+/* Desc: pixel retrieval\r
+ *\r
+ * In : pixel offset\r
+ * Out : pixel value\r
+ *\r
+ * Note: uses current read buffer\r
+ */\r
+static __inline int _mga_getpixel8 (unsigned int offset)\r
+{\r
+ return hwptr_peekb(mgaptr.linear_map, mga_readbuffer_ptr + offset);\r
+}\r
+#define _mga_getpixel15 _mga_getpixel16\r
+static __inline int _mga_getpixel16 (unsigned int offset)\r
+{\r
+ return hwptr_peekw(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 2);\r
+}\r
+static __inline int _mga_getpixel32 (unsigned int offset)\r
+{\r
+ return hwptr_peekl(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 4);\r
+}\r
+\r
+\r
+\r
+/* Desc: color decomposition\r
+ *\r
+ * In : pixel offset, array of integers to hold color components (R, G, B, A)\r
+ * Out : -\r
+ *\r
+ * Note: uses current read buffer\r
+ */\r
+static void _mga_getrgba8 (unsigned int offset, unsigned char rgba[4])\r
+{\r
+ int c = _mga_getpixel8(offset);\r
+ rgba[0] = _rgb_scale_3[(c >> 5) & 0x7];\r
+ rgba[1] = _rgb_scale_3[(c >> 2) & 0x7];\r
+ rgba[2] = _rgb_scale_2[c & 0x3];\r
+ rgba[3] = 255;\r
+}\r
+static void _mga_getrgba15 (unsigned int offset, unsigned char rgba[4])\r
+{\r
+ int c = _mga_getpixel15(offset);\r
+ rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F];\r
+ rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F];\r
+ rgba[2] = _rgb_scale_5[c & 0x1F];\r
+ rgba[3] = 255;\r
+}\r
+static void _mga_getrgba16 (unsigned int offset, unsigned char rgba[4])\r
+{\r
+ int c = _mga_getpixel16(offset);\r
+ rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F];\r
+ rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F];\r
+ rgba[2] = _rgb_scale_5[c & 0x1F];\r
+ rgba[3] = 255;\r
+}\r
+static void _mga_getrgba32 (unsigned int offset, unsigned char rgba[4])\r
+{\r
+ int c = _mga_getpixel32(offset);\r
+ rgba[0] = c >> 16;\r
+ rgba[1] = c >> 8;\r
+ rgba[2] = c; \r
+ rgba[3] = c >> 24;\r
+}\r
+\r
+\r
+\r
+/* Desc: RGB flat line\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2)\r
+{\r
+ unsigned long color;\r
+ int x1 = v1->win[0];\r
+ int y1 = v1->win[1];\r
+ int x2 = v2->win[0];\r
+ int y2 = v2->win[1];\r
+\r
+ if ((x1 == x2) && (y1 == y2)) {\r
+ return;\r
+ }\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWLINE) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWLINE);\r
+ __operation = OP_DRAWLINE;\r
+ }\r
+\r
+ color = mga_mixrgb_full(v2->color);\r
+\r
+ /* draw the line */\r
+ mga_fifo(3);\r
+ mga_outl(M_FCOL, color);\r
+ mga_outl(M_XYSTRT, (y1<<16) | x1);\r
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);\r
+}\r
+\r
+\r
+\r
+/* Desc: RGB flat Z-less line\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: I never figured out "diagonal increments"\r
+ */\r
+void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2)\r
+{\r
+ int z1, dz;\r
+ int x1 = v1->win[0];\r
+ int y1 = v1->win[1];\r
+ int x2 = v2->win[0];\r
+ int y2 = v2->win[1];\r
+ int dx = abs(x2 - x1);\r
+ int dy = abs(y2 - y1);\r
+\r
+ if ((dx == 0) && (dy == 0)) {\r
+ return;\r
+ }\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWLINE_ZI) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWLINE_ZI);\r
+ __operation = OP_DRAWLINE_ZI;\r
+ }\r
+\r
+ if (dx < dy) {\r
+ dx = dy;\r
+ }\r
+\r
+ z1 = v1->win[2] << 15;\r
+ dz = ((v2->win[2] << 15) - z1) / dx;\r
+\r
+ /* draw the line */\r
+ mga_fifo(14);\r
+ mga_outl(M_DR0, z1);\r
+ mga_outl(M_DR2, dz);\r
+ mga_outl(M_DR3, dz);\r
+ mga_outl(M_DR4, v2->color[0] << 15);\r
+ mga_outl(M_DR6, 0);\r
+ mga_outl(M_DR7, 0);\r
+ mga_outl(M_DR8, v2->color[1] << 15);\r
+ mga_outl(M_DR10, 0);\r
+ mga_outl(M_DR11, 0);\r
+ mga_outl(M_DR12, v2->color[2] << 15);\r
+ mga_outl(M_DR14, 0);\r
+ mga_outl(M_DR15, 0);\r
+ mga_outl(M_XYSTRT, (y1<<16) | x1);\r
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);\r
+}\r
+\r
+\r
+\r
+/* Desc: RGB iterated line\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: I never figured out "diagonal increments"\r
+ */\r
+void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2)\r
+{\r
+ int r1, g1, b1;\r
+ int dr, dg, db;\r
+ int x1 = v1->win[0];\r
+ int y1 = v1->win[1];\r
+ int x2 = v2->win[0];\r
+ int y2 = v2->win[1];\r
+ int dx = abs(x2 - x1);\r
+ int dy = abs(y2 - y1);\r
+\r
+ if ((dx == 0) && (dy == 0)) {\r
+ return;\r
+ }\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWLINE_I) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWLINE_I);\r
+ __operation = OP_DRAWLINE_I;\r
+ }\r
+\r
+ if (dx < dy) {\r
+ dx = dy;\r
+ }\r
+\r
+ r1 = v1->color[0] << 15;\r
+ g1 = v1->color[1] << 15;\r
+ b1 = v1->color[2] << 15;\r
+ dr = ((v2->color[0] << 15) - r1) / dx;\r
+ dg = ((v2->color[1] << 15) - g1) / dx;\r
+ db = ((v2->color[2] << 15) - b1) / dx;\r
+\r
+ /* draw the line */\r
+ mga_fifo(11);\r
+ mga_outl(M_DR4, r1);\r
+ mga_outl(M_DR6, dr);\r
+ mga_outl(M_DR7, dr);\r
+ mga_outl(M_DR8, g1);\r
+ mga_outl(M_DR10, dg);\r
+ mga_outl(M_DR11, dg);\r
+ mga_outl(M_DR12, b1);\r
+ mga_outl(M_DR14, db);\r
+ mga_outl(M_DR15, db);\r
+ mga_outl(M_XYSTRT, (y1<<16) | x1);\r
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);\r
+}\r
+\r
+\r
+\r
+/* Desc: RGB iterated Z-less line\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: I never figured out "diagonal increments"\r
+ */\r
+void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2)\r
+{\r
+ int z1, dz;\r
+ int r1, g1, b1;\r
+ int dr, dg, db;\r
+ int x1 = v1->win[0];\r
+ int y1 = v1->win[1];\r
+ int x2 = v2->win[0];\r
+ int y2 = v2->win[1];\r
+ int dx = abs(x2 - x1);\r
+ int dy = abs(y2 - y1);\r
+\r
+ if ((dx == 0) && (dy == 0)) {\r
+ return;\r
+ }\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWLINE_ZI) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWLINE_ZI);\r
+ __operation = OP_DRAWLINE_ZI;\r
+ }\r
+\r
+ if (dx < dy) {\r
+ dx = dy;\r
+ }\r
+\r
+ z1 = v1->win[2] << 15;\r
+ dz = ((v2->win[2] << 15) - z1) / dx;\r
+\r
+ r1 = v1->color[0] << 15;\r
+ g1 = v1->color[1] << 15;\r
+ b1 = v1->color[2] << 15;\r
+ dr = ((v2->color[0] << 15) - r1) / dx;\r
+ dg = ((v2->color[1] << 15) - g1) / dx;\r
+ db = ((v2->color[2] << 15) - b1) / dx;\r
+\r
+ /* draw the line */\r
+ mga_fifo(14);\r
+ mga_outl(M_DR0, z1);\r
+ mga_outl(M_DR2, dz);\r
+ mga_outl(M_DR3, dz);\r
+ mga_outl(M_DR4, r1);\r
+ mga_outl(M_DR6, dr);\r
+ mga_outl(M_DR7, dr);\r
+ mga_outl(M_DR8, g1);\r
+ mga_outl(M_DR10, dg);\r
+ mga_outl(M_DR11, dg);\r
+ mga_outl(M_DR12, b1);\r
+ mga_outl(M_DR14, db);\r
+ mga_outl(M_DR15, db);\r
+ mga_outl(M_XYSTRT, (y1<<16) | x1);\r
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);\r
+}\r
+\r
+\r
+\r
+/* Desc: RGB flat triangle\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+#define TAG mga_draw_tri_rgb_flat\r
+#define CULL\r
+#define SETUP_CODE \\r
+ if (__operation != OP_DRAWTRAP) { \\r
+ mga_fifo(1); \\r
+ mga_outl(M_DWGCTL, OP_DRAWTRAP); \\r
+ __operation = OP_DRAWTRAP; \\r
+ }\r
+#include "m_ttemp.h"\r
+\r
+\r
+\r
+/* Desc: RGB flat Z-less triangle\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+#define TAG mga_draw_tri_rgb_flat_zless\r
+#define CULL\r
+#define INTERP_Z\r
+#define SETUP_CODE \\r
+ if (__operation != OP_DRAWTRAP_ZI) { \\r
+ mga_fifo(1); \\r
+ mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \\r
+ __operation = OP_DRAWTRAP_ZI; \\r
+ }\r
+#include "m_ttemp.h"\r
+\r
+\r
+\r
+/* Desc: RGB iterated triangle\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+#define TAG mga_draw_tri_rgb_iter\r
+#define CULL\r
+#define INTERP_RGB\r
+#define SETUP_CODE \\r
+ if (__operation != OP_DRAWTRAP_I) { \\r
+ mga_fifo(1); \\r
+ mga_outl(M_DWGCTL, OP_DRAWTRAP_I); \\r
+ __operation = OP_DRAWTRAP_I; \\r
+ }\r
+#include "m_ttemp.h"\r
+\r
+\r
+\r
+/* Desc: RGB iterated Z-less triangle\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+#define TAG mga_draw_tri_rgb_iter_zless\r
+#define CULL\r
+#define INTERP_Z\r
+#define INTERP_RGB\r
+#define SETUP_CODE \\r
+ if (__operation != OP_DRAWTRAP_ZI) { \\r
+ mga_fifo(1); \\r
+ mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \\r
+ __operation = OP_DRAWTRAP_ZI; \\r
+ }\r
+#include "m_ttemp.h"\r
+\r
+\r
+\r
+/* Desc: RGB flat rectangle\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color)\r
+{\r
+ if (__bpp == 8) {\r
+ color |= color << 8;\r
+ }\r
+ if (__bpp <= 16) {\r
+ color |= color << 16;\r
+ }\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWRECT) {\r
+\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWRECT);\r
+ __operation = OP_DRAWRECT;\r
+ }\r
+\r
+ /* draw the rectangle */\r
+ mga_fifo(3);\r
+ mga_outl(M_FCOL, color);\r
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);\r
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);\r
+}\r
+\r
+\r
+\r
+/* Desc: 32RGB textured span\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: 0 <= width <= 7*1024\r
+ */\r
+void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap)\r
+{\r
+ int i;\r
+\r
+ if (!width) {\r
+ return;\r
+ }\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWRECT_TX32BGR) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR);\r
+ __operation = OP_DRAWRECT_TX32BGR;\r
+ }\r
+\r
+ /* draw the rectangle */\r
+ mga_fifo(2);\r
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);\r
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1);\r
+\r
+ /* copy data to the pseudo-dma window */\r
+ i = 0;\r
+ do {\r
+ mga_outl(i, *bitmap);\r
+ bitmap++;\r
+ i += 4;\r
+ } while (--width);\r
+}\r
+\r
+\r
+\r
+/* Desc: 24RGB textured span\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: 0 <= width <= 7*1024\r
+ */\r
+void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap)\r
+{\r
+ int i;\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWRECT_TX24BGR) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR);\r
+ __operation = OP_DRAWRECT_TX24BGR;\r
+ }\r
+\r
+ /* draw the rectangle */\r
+ mga_fifo(2);\r
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);\r
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1);\r
+\r
+ /* copy data to the pseudo-dma window */\r
+ i = 0;\r
+ width = (width * 3 + 3) / 4;\r
+ while (width) {\r
+ mga_outl(i & (7 * 1024 - 1), *bitmap);\r
+ bitmap++;\r
+ i += 4;\r
+ width--;\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: 32RGB textured rectangle\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap)\r
+{\r
+ int i;\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWRECT_TX32BGR) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR);\r
+ __operation = OP_DRAWRECT_TX32BGR;\r
+ }\r
+\r
+ /* draw the rectangle */\r
+ mga_fifo(2);\r
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);\r
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);\r
+\r
+ /* copy data to the pseudo-dma window */\r
+ i = 0;\r
+ width *= height;\r
+ while (width) {\r
+ mga_outl(i & (7 * 1024 - 1), *bitmap);\r
+ bitmap++;\r
+ i += 4;\r
+ width--;\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: 24RGB textured rectangle\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap)\r
+{\r
+ int i;\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_DRAWRECT_TX24BGR) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR);\r
+ __operation = OP_DRAWRECT_TX24BGR;\r
+ }\r
+\r
+ /* draw the rectangle */\r
+ mga_fifo(2);\r
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);\r
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);\r
+\r
+ /* copy data to the pseudo-dma window */\r
+ i = 0;\r
+ width = (width * height * 3 + 3) / 4;\r
+ while (width) {\r
+ mga_outl(i & (7 * 1024 - 1), *bitmap);\r
+ bitmap++;\r
+ i += 4;\r
+ width--;\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: copy 32RGB image to screen\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap)\r
+{\r
+ int i;\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_ILOAD_32BGR) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_ILOAD_32BGR);\r
+ __operation = OP_ILOAD_32BGR;\r
+ }\r
+\r
+ /* draw the bitmap */\r
+ mga_fifo(5);\r
+ mga_outl(M_AR0, width-1);\r
+ mga_outl(M_AR3, 0);\r
+ mga_outl(M_AR5, 0);\r
+ mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left);\r
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);\r
+\r
+ /* copy data to the pseudo-dma window */\r
+ i = 0;\r
+ width *= height;\r
+ while (width) {\r
+ mga_outl(i & (7 * 1024 - 1), *bitmap);\r
+ bitmap++;\r
+ i += 4;\r
+ width--;\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: copy 24RGB image to screen\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap)\r
+{\r
+ int i;\r
+\r
+ mga_select();\r
+\r
+ /* set engine state */\r
+ if (__operation != OP_ILOAD_24BGR) {\r
+ mga_fifo(1);\r
+ mga_outl(M_DWGCTL, OP_ILOAD_24BGR);\r
+ __operation = OP_ILOAD_24BGR;\r
+ }\r
+\r
+ /* draw the bitmap */\r
+ mga_fifo(5);\r
+ mga_outl(M_AR0, width-1);\r
+ mga_outl(M_AR3, 0);\r
+ mga_outl(M_AR5, 0);\r
+ mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left);\r
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);\r
+\r
+ /* copy data to the pseudo-dma window */\r
+ i = 0;\r
+ width = (width * height * 3 + 3) / 4;\r
+ while (width) {\r
+ mga_outl(i & (7 * 1024 - 1), *bitmap);\r
+ bitmap++;\r
+ i += 4;\r
+ width--;\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: get Z-buffer value\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+unsigned short mga_getz (int offset)\r
+{\r
+ return hwptr_peekw(mgaptr.linear_map, zorg + (mga_readbuffer_ptr + offset) * 2);\r
+}\r
+\r
+\r
+\r
+/* Desc: put Z-buffer value\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_setz (int offset, unsigned short z)\r
+{\r
+ hwptr_pokew(mgaptr.linear_map, zorg + (mga_writebuffer_ptr + offset) * 2, z);\r
+}\r
+\r
+\r
+\r
+/* Desc: clear Z-buffer\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: uses current write buffer\r
+ */\r
+static void _mga_clear_zed (int left, int top, int width, int height, unsigned short z)\r
+{\r
+ if (__bpp == 16) {\r
+ /* GPU store (high bandwidth)\r
+ * Hack alert:\r
+ * can cause problems with concurrent FB accesses\r
+ */\r
+ mga_select();\r
+ mga_fifo(1);\r
+ mga_outl(M_YDSTORG, mga_writebuffer_ptr + zorg/2);\r
+ mga_draw_rect_rgb_flat(left, top, width, height, z);\r
+ mga_fifo(1);\r
+ mga_outl(M_YDSTORG, mga_writebuffer_ptr);\r
+ } else {\r
+ /* CPU store */\r
+ unsigned long i, zz = (z<<16) | z;\r
+ unsigned long ofs = zorg + (top * __pixwidth + left + mga_writebuffer_ptr) * 2;\r
+ hwptr_select(mgaptr.linear_map);\r
+ while (height--) {\r
+ i = width/2;\r
+ while (i--) {\r
+ hwptr_nspokel(mgaptr.linear_map, ofs, zz);\r
+ ofs += 4;\r
+ }\r
+ if (width & 1) {\r
+ hwptr_nspokew(mgaptr.linear_map, ofs, z);\r
+ ofs += 2;\r
+ }\r
+ ofs += (__pixwidth - width) * 2;\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: clear color- and Z-buffer\r
+ *\r
+ * In : front = clear front buffer\r
+ * back = clear back buffer\r
+ * zed = clear depth buffer\r
+ * left = leftmost pixel to be cleared\r
+ * top = starting line\r
+ * width = number of pixels\r
+ * height = number of lines\r
+ * color = color to clear to\r
+ * z = z value (ignored if zed==0)\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z)\r
+{\r
+ if (front) {\r
+ if (mga_writebuffer == MGA_FRONTBUFFER) {\r
+ mga_draw_rect_rgb_flat(left, top, width, height, color);\r
+ if (zed) {\r
+ _mga_clear_zed(left, top, width, height, z);\r
+ }\r
+ front = 0;\r
+ }\r
+ }\r
+ if (back) {\r
+ if (mga_writebuffer == MGA_BACKBUFFER) {\r
+ mga_draw_rect_rgb_flat(left, top, width, height, color);\r
+ if (zed) {\r
+ _mga_clear_zed(left, top, width, height, z);\r
+ }\r
+ back = 0;\r
+ }\r
+ }\r
+ if (front) {\r
+ int old = mga_writebuffer;\r
+ mga_set_writebuffer(MGA_FRONTBUFFER);\r
+ mga_draw_rect_rgb_flat(left, top, width, height, color);\r
+ if (zed) {\r
+ _mga_clear_zed(left, top, width, height, z);\r
+ }\r
+ mga_set_writebuffer(old);\r
+ front = 0;\r
+ }\r
+ if (back) {\r
+ int old = mga_writebuffer;\r
+ mga_set_writebuffer(MGA_BACKBUFFER);\r
+ mga_draw_rect_rgb_flat(left, top, width, height, color);\r
+ if (zed) {\r
+ _mga_clear_zed(left, top, width, height, z);\r
+ }\r
+ mga_set_writebuffer(old);\r
+ back = 0;\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: Attempts to enter specified video mode.\r
+ *\r
+ * In : ptr to mode structure, number of pages, Z-buffer request, refresh rate\r
+ * Out : 0 if success\r
+ *\r
+ * Note: also set up the accelerator engine\r
+ */\r
+int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh)\r
+{\r
+ static int mill_strides[] = { 640, 768, 800, 960, 1024, 1152, 1280, 1600, 1920, 2048, 0 };\r
+ unsigned int i, used;\r
+ MGA_MODE *p;\r
+\r
+ if (mga_hw_init(&vram, &interleave, card_name) == 0) {\r
+ return -1;\r
+ }\r
+\r
+ if ((p = mga_mode_find(width, height, bpp)) == NULL) {\r
+ return -1;\r
+ }\r
+\r
+ __bpp = p->bpp;\r
+ __width = __pagewidth = p->xres;\r
+ __height = p->yres;\r
+\r
+ if (buffers > 1) {\r
+ __pagewidth = _mga_fix_scans(__pagewidth);\r
+ __pixwidth = __pagewidth * buffers;\r
+ } else {\r
+ __pixwidth = __pagewidth;\r
+ __pixwidth = _mga_fix_scans(__pixwidth);\r
+ }\r
+\r
+ for (i=0; mill_strides[i]; i++) {\r
+ if (__pixwidth <= mill_strides[i]) {\r
+ __pixwidth = mill_strides[i];\r
+ break;\r
+ }\r
+ }\r
+\r
+ __bypp = (__bpp+7)/8;\r
+ __bytwidth = __pixwidth * __bypp;\r
+\r
+ /* compute used memory: framebuffer + zbuffer */\r
+ used = __bytwidth * __height;\r
+ if (zbuffer) {\r
+ zorg = (used + 511) & ~511;\r
+ /* Hack alert:\r
+ * a 16-bit Z-buffer size is (stride_in_pixels * number_of_lines * 2)\r
+ * We cannot mess with the Z-buffer width, but we might decrease the\r
+ * number of lines, if the user requests less than (screen_height). For\r
+ * example with a 2MB card, one can have 640x480x16 display with 2 color\r
+ * buffers and Z-buffer if the maximum requested height is 339:\r
+ * Total = (640*480 * 2 + 640*339 * 2) * 2\r
+ * However, this means the user must not write beyond the window's height\r
+ * and if we'll ever implement moveable windows, we'll have to reconsider\r
+ * this hack.\r
+ */\r
+#if 1\r
+ __zheight = height; /* smaller */\r
+ used = zorg + __pixwidth * 2 * __zheight;\r
+#else\r
+ __zheight = __height;\r
+ used = zorg + __pixwidth * 2 * __zheight;\r
+#endif\r
+ }\r
+\r
+ if (mill_strides[i] && (vram>=used)) {\r
+ /* enter mode */\r
+ mga_mode_switch(p, refresh);\r
+ /* change the scan line length */\r
+ _mga_ralter(M_CRTC_INDEX, 0x14, 0x40, 0); /* disable DWORD */\r
+ _mga_ralter(M_CRTC_INDEX, 0x17, 0x40, 0x40); /* wbmode = BYTE */\r
+ if (interleave) {\r
+ _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/16);\r
+ _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/16)>>4)&0x30);\r
+ } else {\r
+ _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/8);\r
+ _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/8)>>4)&0x30);\r
+ }\r
+ } else {\r
+ return -1;\r
+ }\r
+\r
+ /* setup buffers */\r
+ mga_frontbuffer_ptr = 0;\r
+ if (buffers > 1) {\r
+ mga_backbuffer_ptr = __pagewidth;\r
+ mga_set_readbuffer(MGA_BACKBUFFER);\r
+ mga_set_writebuffer(MGA_BACKBUFFER);\r
+ } else {\r
+ mga_backbuffer_ptr = 0;\r
+ mga_set_readbuffer(MGA_FRONTBUFFER);\r
+ mga_set_writebuffer(MGA_FRONTBUFFER);\r
+ }\r
+ mga_display_start(mga_frontbuffer_ptr, __scrollx = 0, __scrolly = 0, 1);\r
+\r
+ /* set up the accelerator engine */\r
+ mga_select();\r
+\r
+ mga_fifo(8);\r
+ mga_outl(M_PITCH, __pixwidth);\r
+ mga_outl(M_PLNWT, 0xFFFFFFFF);\r
+ mga_outl(M_OPMODE, M_DMA_BLIT);\r
+ mga_outl(M_CXBNDRY, 0xFFFF0000);\r
+ mga_outl(M_YTOP, 0x00000000);\r
+ mga_outl(M_YBOT, 0x007FFFFF);\r
+ mga_outl(M_ZORG, zorg);\r
+\r
+#define INITPTR(bpp) \\r
+ mga_putpixel = _mga_putpixel##bpp; \\r
+ mga_getrgba = _mga_getrgba##bpp; \\r
+ mga_getpixel = _mga_getpixel##bpp; \\r
+ mga_mixrgb = _mga_mixrgb##bpp; \\r
+ mga_mixrgb_full = _mga_mixrgb##bpp##_full\r
+\r
+ switch (__bpp) {\r
+ case 8:\r
+ mga_outl(M_MACCESS, 0);\r
+ INITPTR(8);\r
+ break;\r
+ case 15:\r
+ mga_outl(M_MACCESS, 0x80000001);\r
+ INITPTR(15);\r
+ break;\r
+ case 16:\r
+ mga_outl(M_MACCESS, 1);\r
+ INITPTR(16);\r
+ break;\r
+ case 32:\r
+ mga_outl(M_MACCESS, 2);\r
+ INITPTR(32);\r
+ break;\r
+ }\r
+\r
+#undef INITPTR\r
+\r
+ /* disable VGA aperture */\r
+ i = mga_inb(M_MISC_R);\r
+ mga_outb(M_MISC_W, i & ~2);\r
+\r
+ /* clear Z-buffer (if any) */\r
+ if (zbuffer) {\r
+ unsigned long ofs = zorg;\r
+ unsigned long len = zorg + __pixwidth * 2 * __zheight;\r
+\r
+ hwptr_select(mgaptr.linear_map);\r
+ for (; ofs<len; ofs+=4) {\r
+ hwptr_nspokel(mgaptr.linear_map, ofs, -1);\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/* Desc:\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_close (int restore, int unmap)\r
+{\r
+ if (restore) {\r
+ mga_mode_restore();\r
+ }\r
+ if (unmap) {\r
+ mga_hw_fini();\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: state retrieval\r
+ *\r
+ * In : parameter name, ptr to storage\r
+ * Out : 0 if request successfully processed\r
+ *\r
+ * Note: -\r
+ */\r
+int mga_get (int pname, int *params)\r
+{\r
+ switch (pname) {\r
+ case MGA_GET_CARD_NAME:\r
+ strcat(strcpy((char *)params, "Matrox "), card_name);\r
+ break;\r
+ case MGA_GET_VRAM:\r
+ params[0] = vram;\r
+ break;\r
+ case MGA_GET_CI_PREC:\r
+ params[0] = 0;\r
+ break;\r
+ case MGA_GET_HPIXELS:\r
+ params[0] = __pixwidth;\r
+ break;\r
+ case MGA_GET_SCREEN_SIZE:\r
+ params[0] = __width;\r
+ params[1] = __height;\r
+ break;\r
+ default:\r
+ return -1;\r
+ }\r
+ return 0;\r
+}\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#ifndef MGA_H_included\r
+#define MGA_H_included\r
+\r
+#define MGA_GET_CARD_NAME 0x0100\r
+#define MGA_GET_VRAM 0x0101\r
+#define MGA_GET_CI_PREC 0x0200\r
+#define MGA_GET_HPIXELS 0x0201\r
+#define MGA_GET_SCREEN_SIZE 0x0202\r
+\r
+int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh);\r
+void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z);\r
+int mga_get (int pname, int *params);\r
+void mga_close (int restore, int unmap);\r
+\r
+extern void (*mga_putpixel) (unsigned int offset, int color);\r
+extern int (*mga_getpixel) (unsigned int offset);\r
+extern void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]);\r
+extern int (*mga_mixrgb) (const unsigned char rgb[]);\r
+\r
+#define MGA_BACKBUFFER !0\r
+#define MGA_FRONTBUFFER 0\r
+void mga_set_readbuffer (int buffer);\r
+void mga_set_writebuffer (int buffer);\r
+void mga_swapbuffers (int swapinterval);\r
+\r
+unsigned short mga_getz (int offset);\r
+void mga_setz (int offset, unsigned short z);\r
+\r
+void mga_wait_idle (void);\r
+\r
+/*\r
+ * vertex structure, used for primitive rendering\r
+ */\r
+typedef struct {\r
+ int win[4]; /* X, Y, Z, ? */\r
+ unsigned char color[4]; /* R, G, B, A */\r
+} MGAvertex;\r
+\r
+void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2);\r
+void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2);\r
+void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2);\r
+void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2);\r
+\r
+void mga_draw_tri_rgb_flat (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);\r
+void mga_draw_tri_rgb_flat_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);\r
+void mga_draw_tri_rgb_iter (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);\r
+void mga_draw_tri_rgb_iter_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);\r
+\r
+void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color);\r
+void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap);\r
+void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap);\r
+void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap);\r
+void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap);\r
+\r
+void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap);\r
+void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap);\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W HW mapping\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#include <crt0.h>\r
+#include <dpmi.h>\r
+#include <pc.h>\r
+#include <string.h>\r
+#include <sys/nearptr.h>\r
+#include <sys/segments.h>\r
+\r
+#include "../internal.h"\r
+#include "mga_reg.h"\r
+#include "mga_hw.h"\r
+\r
+\r
+\r
+/* Hack alert:\r
+ * these should really be externs\r
+ */\r
+/* PCI access routines */\r
+static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle);\r
+static unsigned long pci_read_long (int handle, int index);\r
+static void pci_write_long (int handle, int index, unsigned long value);\r
+\r
+\r
+\r
+/* PCI device identifiers */\r
+#define MATROX_VENDOR_ID 0x102B\r
+\r
+typedef enum {\r
+ MATROX_MILL_ID = 0x0519\r
+} MATROX_ID;\r
+\r
+static MATROX_ID matrox_id_list[] = {\r
+ MATROX_MILL_ID,\r
+ 0\r
+};\r
+\r
+\r
+\r
+/* internal hardware data structures */\r
+#if !MGA_FARPTR\r
+static int dirty;\r
+#endif\r
+static int bus_id;\r
+static unsigned long reg40;\r
+static unsigned long io_mem_base[4], linear_base;\r
+static unsigned long io_mem_size[4], linear_size;\r
+static MATROX_ID matrox_id;\r
+\r
+\r
+\r
+/* interface structures containing hardware pointer data */\r
+MGA_HWPTR mgaptr;\r
+\r
+\r
+\r
+/* Desc: create MMAP\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static int _create_mmap (__dpmi_paddr *m, unsigned long base, unsigned long size)\r
+{\r
+#if MGA_FARPTR\r
+ int sel;\r
+ if (_create_selector(&sel, base, size)) {\r
+ return -1;\r
+ }\r
+ m->selector = sel;\r
+ m->offset32 = 0;\r
+#else\r
+ m->selector = _my_ds();\r
+ if (_create_linear_mapping(&m->offset32, base, size)) {\r
+ return -1;\r
+ }\r
+ m->offset32 -= __djgpp_base_address;\r
+#endif\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/* Desc: destroy MMAP\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static void _destroy_mmap (__dpmi_paddr *m)\r
+{\r
+#if MGA_FARPTR\r
+ int sel = m->selector;\r
+ _remove_selector(&sel);\r
+#else\r
+ m->offset32 += __djgpp_base_address;\r
+ _remove_linear_mapping(&m->offset32);\r
+#endif\r
+ m->selector = 0;\r
+ m->offset32 = 0;\r
+}\r
+\r
+\r
+\r
+/* Desc: Counts amount of installed RAM\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static int _mga_get_vram (MATROX_ID chip, unsigned long base)\r
+{\r
+ int ProbeSize = 8;\r
+ int SizeFound = 2;\r
+ unsigned char tmp;\r
+ int i;\r
+ __dpmi_paddr fb;\r
+\r
+ switch (chip) {\r
+ case MATROX_MILL_ID:\r
+ ProbeSize = 8;\r
+ break;\r
+ }\r
+\r
+ if (_create_mmap(&fb, base, ProbeSize*1024*1024)) {\r
+ return 0;\r
+ }\r
+\r
+ /* turn MGA mode on - enable linear frame buffer (CRTCEXT3) */\r
+ mga_select();\r
+ mga_outb(M_CRTC_EXT_INDEX, 3);\r
+ tmp = mga_inb(M_CRTC_EXT_DATA);\r
+ mga_outb(M_CRTC_EXT_DATA, tmp | M_MGAMODE);\r
+\r
+ /* write, read and compare method */\r
+ for (i=ProbeSize; i>2; i-= 2) {\r
+ hwptr_pokeb(fb, i*1024*1024 - 1, 0xAA);\r
+ mga_select();\r
+ mga_outb(M_CRTC_INDEX, 0); /* flush the cache */\r
+ mga_inl(M_STATUS); /* delay */\r
+ mga_inl(M_STATUS); /* delay */\r
+ mga_inl(M_STATUS); /* delay */\r
+ if (hwptr_peekb(fb, i*1024*1024 - 1) == 0xAA) {\r
+ SizeFound = i;\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* restore CRTCEXT3 state */\r
+ mga_select();\r
+ mga_outb(M_CRTC_EXT_INDEX, 3);\r
+ mga_outb(M_CRTC_EXT_DATA, tmp);\r
+\r
+ _destroy_mmap(&fb);\r
+\r
+ return SizeFound*1024*1024;\r
+}\r
+\r
+\r
+\r
+/* Desc: Frees all resources allocated by MGA init code.\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+void mga_hw_fini (void)\r
+{\r
+ int i;\r
+\r
+ pci_write_long(bus_id, 0x40, reg40);\r
+\r
+ for (i=0; i<4; i++) {\r
+ _destroy_mmap(&mgaptr.io_mem_map[i]);\r
+ }\r
+\r
+ _destroy_mmap(&mgaptr.linear_map);\r
+\r
+#if !MGA_FARPTR\r
+ if (dirty) {\r
+ __djgpp_nearptr_disable();\r
+ dirty = FALSE;\r
+ }\r
+#endif\r
+\r
+ matrox_id = 0;\r
+}\r
+\r
+\r
+\r
+/* Desc: Attempts to detect MGA.\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note: The first thing ever to be called. This is in charge of filling in\r
+ * the driver header with all the required information and function\r
+ * pointers. We do not yet have access to the video memory, so we can't\r
+ * talk directly to the card.\r
+ */\r
+int mga_hw_init (unsigned long *vram, int *interleave, char *name)\r
+{\r
+ int i;\r
+ unsigned long pci_base[2];\r
+\r
+ if (matrox_id) {\r
+ return matrox_id;\r
+ }\r
+\r
+#if !MGA_FARPTR\r
+ /* enable nearptr access */\r
+ if (_crt0_startup_flags & _CRT0_FLAG_NEARPTR) {\r
+ dirty = FALSE;\r
+ } else {\r
+ if (__djgpp_nearptr_enable() == 0)\r
+ return NULL;\r
+\r
+ dirty = TRUE;\r
+ }\r
+#endif\r
+\r
+ /* find PCI device */\r
+ matrox_id = 0;\r
+\r
+ for (bus_id=0, i=0; matrox_id_list[i]; i++) {\r
+ if (pci_find_device(matrox_id_list[i], MATROX_VENDOR_ID, 0, &bus_id)) {\r
+ matrox_id = matrox_id_list[i];\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* set up the card name */\r
+ switch (matrox_id) {\r
+ case MATROX_MILL_ID:\r
+ if (name) strcpy(name, "Millennium");\r
+ break;\r
+ default:\r
+ matrox_id = 0;\r
+ return -1;\r
+ }\r
+\r
+ reg40 = pci_read_long(bus_id, 0x40);\r
+#if 0 /* overclock a little :) */\r
+ {\r
+ int rfhcnt = (reg40 >> 16) & 0xF;\r
+ if ((reg40 & 0x200000) && (rfhcnt < 0xC)) {\r
+ pci_write_long(bus_id, 0x40, (reg40 & 0xFFF0FFFF) | 0x000C0000);\r
+ }\r
+ }\r
+#endif\r
+\r
+ /* read hardware configuration data */\r
+ for (i=0; i<2; i++)\r
+ pci_base[i] = pci_read_long(bus_id, 16+i*4);\r
+\r
+ /* work out the linear framebuffer and MMIO addresses */\r
+ if (matrox_id == MATROX_MILL_ID) {\r
+ if (pci_base[0])\r
+ io_mem_base[0] = pci_base[0] & 0xFFFFC000;\r
+\r
+ if (pci_base[1])\r
+ linear_base = pci_base[1] & 0xFF800000;\r
+ }\r
+\r
+ if (!linear_base || !io_mem_base[0])\r
+ return NULL;\r
+\r
+ /* deal with the memory mapping crap */\r
+ io_mem_size[0] = 0x4000;\r
+\r
+ for (i=0; i<4; i++) {\r
+ if (io_mem_base[i]) {\r
+ if (_create_mmap(&mgaptr.io_mem_map[i], io_mem_base[i], io_mem_size[i])) {\r
+ mga_hw_fini();\r
+ return NULL;\r
+ }\r
+ }\r
+ }\r
+\r
+ *vram = linear_size = _mga_get_vram(matrox_id, linear_base);\r
+\r
+ if (_create_mmap(&mgaptr.linear_map, linear_base, linear_size)) {\r
+ mga_hw_fini();\r
+ return NULL;\r
+ }\r
+\r
+ /* fill in user data */\r
+ *interleave = linear_size > 2*1024*1024;\r
+\r
+ return matrox_id;\r
+}\r
+\r
+\r
+\r
+/* PCI routines added by SET */\r
+#define PCIAddr 0xCF8\r
+#define PCIData 0xCFC\r
+#define PCIEnable 0x80000000\r
+\r
+\r
+\r
+/* FindPCIDevice:\r
+ * Replacement for the INT 1A - PCI BIOS v2.0c+ - FIND PCI DEVICE, AX = B102h\r
+ *\r
+ * Note: deviceIndex is because a card can hold more than one PCI chip.\r
+ * \r
+ * Searches the board of the vendor supplied in vendorID with \r
+ * identification number deviceID and index deviceIndex (normally 0). \r
+ * The value returned in handle can be used to access the PCI registers \r
+ * of this board.\r
+ *\r
+ * Return: 1 if found 0 if not found.\r
+ */\r
+static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle)\r
+{\r
+ int model, vendor, card, device;\r
+ unsigned value, full_id, bus, busMax;\r
+\r
+ deviceIndex <<= 8;\r
+\r
+ /* for each PCI bus */\r
+ for (bus=0, busMax=0x10000; bus<busMax; bus+=0x10000) {\r
+\r
+ /* for each hardware device */\r
+ for (device=0, card=0; card<32; card++, device+=0x800) {\r
+ value = PCIEnable | bus | deviceIndex | device;\r
+ outportl(PCIAddr, value);\r
+ full_id = inportl(PCIData);\r
+\r
+ /* get the vendor and model ID */\r
+ vendor = full_id & 0xFFFF;\r
+ model = full_id >> 16;\r
+\r
+ if (vendor != 0xFFFF) {\r
+ /* is this the one we want? */\r
+ if ((deviceID == model) && (vendorID == vendor)) {\r
+ *handle = value;\r
+ return 1;\r
+ }\r
+\r
+ /* is it a bridge to a secondary bus? */\r
+ outportl(PCIAddr, value | 8);\r
+\r
+ if (((inportl(PCIData) >> 16) == 0x0600) || (full_id==0x00011011))\r
+ busMax += 0x10000;\r
+ }\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/* Desc:\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static unsigned long pci_read_long (int handle, int index)\r
+{\r
+ outportl(PCIAddr, PCIEnable | handle | index);\r
+ return inportl(PCIData);\r
+}\r
+\r
+\r
+\r
+/* Desc:\r
+ *\r
+ * In :\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static void pci_write_long (int handle, int index, unsigned long value)\r
+{\r
+ outportl(PCIAddr, PCIEnable | handle | index);\r
+ outportl(PCIData, value);\r
+}\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W HW mapping\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#ifndef MGA_HW_included\r
+#define MGA_HW_included\r
+\r
+\r
+\r
+/* set this to zero to use near pointers */\r
+#define MGA_FARPTR 1\r
+\r
+\r
+\r
+/* access macros */\r
+#if MGA_FARPTR\r
+\r
+#include <sys/farptr.h>\r
+\r
+#define hwptr_pokeb(ptr, off, val) _farpokeb((ptr).selector, (ptr).offset32+(off), (val))\r
+#define hwptr_pokew(ptr, off, val) _farpokew((ptr).selector, (ptr).offset32+(off), (val))\r
+#define hwptr_pokel(ptr, off, val) _farpokel((ptr).selector, (ptr).offset32+(off), (val))\r
+\r
+#define hwptr_peekb(ptr, off) _farpeekb((ptr).selector, (ptr).offset32+(off))\r
+#define hwptr_peekw(ptr, off) _farpeekw((ptr).selector, (ptr).offset32+(off))\r
+#define hwptr_peekl(ptr, off) _farpeekl((ptr).selector, (ptr).offset32+(off))\r
+\r
+#define hwptr_select(ptr) _farsetsel((ptr).selector)\r
+#define hwptr_unselect(ptr) (ptr).selector = _fargetsel()\r
+\r
+#define hwptr_nspokeb(ptr, off, val) _farnspokeb((ptr).offset32+(off), (val))\r
+#define hwptr_nspokew(ptr, off, val) _farnspokew((ptr).offset32+(off), (val))\r
+#define hwptr_nspokel(ptr, off, val) _farnspokel((ptr).offset32+(off), (val))\r
+\r
+#define hwptr_nspeekb(ptr, off) _farnspeekb((ptr).offset32+(off))\r
+#define hwptr_nspeekw(ptr, off) _farnspeekw((ptr).offset32+(off))\r
+#define hwptr_nspeekl(ptr, off) _farnspeekl((ptr).offset32+(off))\r
+\r
+#else\r
+\r
+#define hwptr_pokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val)\r
+#define hwptr_pokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val)\r
+#define hwptr_pokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val)\r
+\r
+#define hwptr_peekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off))))\r
+#define hwptr_peekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off))))\r
+#define hwptr_peekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off))))\r
+\r
+#define hwptr_select(ptr)\r
+#define hwptr_unselect(ptr)\r
+\r
+#define hwptr_nspokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val)\r
+#define hwptr_nspokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val)\r
+#define hwptr_nspokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val)\r
+\r
+#define hwptr_nspeekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off))))\r
+#define hwptr_nspeekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off))))\r
+#define hwptr_nspeekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off))))\r
+\r
+#endif\r
+\r
+\r
+\r
+/* helpers for accessing the Matrox registers */\r
+#define mga_select() hwptr_select(mgaptr.io_mem_map[0])\r
+#define mga_inb(addr) hwptr_nspeekb(mgaptr.io_mem_map[0], addr)\r
+#define mga_inw(addr) hwptr_nspeekw(mgaptr.io_mem_map[0], addr)\r
+#define mga_inl(addr) hwptr_nspeekl(mgaptr.io_mem_map[0], addr)\r
+#define mga_outb(addr, val) hwptr_nspokeb(mgaptr.io_mem_map[0], addr, val)\r
+#define mga_outw(addr, val) hwptr_nspokew(mgaptr.io_mem_map[0], addr, val)\r
+#define mga_outl(addr, val) hwptr_nspokel(mgaptr.io_mem_map[0], addr, val)\r
+\r
+\r
+\r
+typedef struct MGA_HWPTR {\r
+ __dpmi_paddr io_mem_map[4], linear_map;\r
+} MGA_HWPTR;\r
+\r
+extern MGA_HWPTR mgaptr;\r
+\r
+void mga_hw_fini (void);\r
+int mga_hw_init (unsigned long *vram, int *interleave, char *name);\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W mode switching\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#include <dpmi.h>\r
+#include <string.h>\r
+#include <stubinfo.h>\r
+#include <sys/exceptn.h>\r
+#include <sys/farptr.h>\r
+#include <sys/movedata.h>\r
+#include <sys/segments.h>\r
+\r
+#include "../internal.h"\r
+#include "mga_mode.h"\r
+\r
+\r
+\r
+static MGA_MODE oldmode;\r
+static MGA_MODE modes[64];\r
+\r
+\r
+\r
+/*\r
+ * VESA info\r
+ */\r
+#define V_SIGN 0\r
+#define V_MINOR 4\r
+#define V_MAJOR 5\r
+#define V_OEM_OFS 6\r
+#define V_OEM_SEG 8\r
+#define V_MODE_OFS 14\r
+#define V_MODE_SEG 16\r
+#define V_MEMORY 18\r
+\r
+/*\r
+ * mode info\r
+ */\r
+#define M_ATTR 0\r
+#define M_GRAN 4\r
+#define M_SCANLEN 16\r
+#define M_XRES 18\r
+#define M_YRES 20\r
+#define M_BPP 25\r
+#define M_RED 31\r
+#define M_GREEN 33\r
+#define M_BLUE 35\r
+#define M_PHYS_PTR 40\r
+\r
+\r
+\r
+/* Desc: get available modes\r
+ *\r
+ * In : -\r
+ * Out : linear modes list ptr\r
+ *\r
+ * Note: shouldn't use VESA...\r
+ */\r
+static MGA_MODE *_mga_mode_check (void)\r
+{\r
+ __dpmi_regs r;\r
+ word16 *p;\r
+ MGA_MODE *q;\r
+ char vesa_info[512], tmp[512];\r
+\r
+ _farpokel(_stubinfo->ds_selector, 0, 0x32454256);\r
+ r.x.ax = 0x4f00;\r
+ r.x.di = 0;\r
+ r.x.es = _stubinfo->ds_segment;\r
+ __dpmi_int(0x10, &r);\r
+ movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);\r
+ if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) {\r
+ return NULL;\r
+ }\r
+\r
+ p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS]));\r
+ q = modes;\r
+ do {\r
+ if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {\r
+ break;\r
+ }\r
+\r
+ r.x.ax = 0x4f01;\r
+ r.x.cx = q->mode;\r
+ r.x.di = 512;\r
+ r.x.es = _stubinfo->ds_segment;\r
+ __dpmi_int(0x10, &r);\r
+ movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);\r
+ switch (tmp[M_BPP]) {\r
+ case 16:\r
+ q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE];\r
+ break;\r
+ case 8:\r
+ case 15:\r
+ case 24:\r
+ case 32:\r
+ q->bpp = tmp[M_BPP];\r
+ break;\r
+ default:\r
+ q->bpp = 0;\r
+ }\r
+ if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp && (tmp[M_ATTR]&0x80)) {\r
+ q->xres = _16_ tmp[M_XRES];\r
+ q->yres = _16_ tmp[M_YRES];\r
+ q->mode |= 0x4000;\r
+ q++;\r
+ }\r
+ } while (TRUE);\r
+\r
+ return modes;\r
+}\r
+\r
+\r
+\r
+/* Desc: save current mode\r
+ *\r
+ * In : ptr to mode structure\r
+ * Out : 0 if success\r
+ *\r
+ * Note: shouldn't use VESA...\r
+ */\r
+static int _mga_mode_save (MGA_MODE *p)\r
+{\r
+ __asm("\n\\r
+ movw $0x4f03, %%ax \n\\r
+ int $0x10 \n\\r
+ movl %%ebx, %0 \n\\r
+ ":"=g"(p->mode)::"%eax", "%ebx");\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/* Desc: switch to specified mode\r
+ *\r
+ * In : ptr to mode structure, refresh rate\r
+ * Out : 0 if success\r
+ *\r
+ * Note: shouldn't use VESA...\r
+ */\r
+int mga_mode_switch (MGA_MODE *p, int refresh)\r
+{\r
+ if (oldmode.mode == 0) {\r
+ _mga_mode_save(&oldmode);\r
+ }\r
+ __asm("movw $0x4f02, %%ax; int $0x10"::"b"(p->mode):"%eax");\r
+ return 0;\r
+\r
+ (void)refresh; /* silence compiler warning */\r
+}\r
+\r
+\r
+\r
+/* Desc: restore to the mode prior to first call to `mga_switch'\r
+ *\r
+ * In : -\r
+ * Out : 0 if success\r
+ *\r
+ * Note: shouldn't use VESA...\r
+ */\r
+int mga_mode_restore (void)\r
+{\r
+ if (oldmode.mode != 0) {\r
+ __asm("movw $0x4f02, %%ax; int $0x10"::"b"(oldmode.mode):"%eax");\r
+ oldmode.mode = 0;\r
+ }\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/* Desc: return suitable mode\r
+ *\r
+ * In : width, height, bpp\r
+ * Out : ptr to mode structure\r
+ *\r
+ * Note: -\r
+ */\r
+MGA_MODE *mga_mode_find (int width, int height, int bpp)\r
+{\r
+ static MGA_MODE *q = NULL;\r
+\r
+ MGA_MODE *p;\r
+ unsigned int min;\r
+\r
+ if (q == NULL) {\r
+ if ((q = _mga_mode_check()) == NULL) {\r
+ return NULL;\r
+ }\r
+ }\r
+\r
+ /* search for a mode that fits our request */\r
+ for (min=-1, p=NULL; q->mode!=0xffff; q++) {\r
+ if ((q->xres>=width) && (q->yres>=height) && (q->bpp==bpp)) {\r
+ if (min>=(unsigned)(q->xres*q->yres)) {\r
+ min = q->xres*q->yres;\r
+ p = q;\r
+ }\r
+ }\r
+ }\r
+\r
+ return p;\r
+}\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W mode switching\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#ifndef MGA_MODE_included\r
+#define MGA_MODE_included\r
+\r
+typedef struct MGA_MODE {\r
+ int mode;\r
+ int xres, yres;\r
+ int bpp;\r
+} MGA_MODE;\r
+\r
+int mga_mode_switch (MGA_MODE *p, int refresh);\r
+int mga_mode_restore (void);\r
+MGA_MODE *mga_mode_find (int width, int height, int bpp);\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 5.0\r
+ * \r
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W register mnemonics\r
+ *\r
+ * Copyright (c) 2003 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#ifndef MGA_REG_H_included\r
+#define MGA_REG_H_included\r
+\r
+/* Matrox hardware registers: */\r
+#define M_AR0 0x1C60\r
+#define M_AR1 0x1C64\r
+#define M_AR2 0x1C68\r
+#define M_AR3 0x1C6C\r
+#define M_AR4 0x1C70\r
+#define M_AR5 0x1C74\r
+#define M_AR6 0x1C78\r
+#define M_BCOL 0x1C20\r
+#define M_CXBNDRY 0x1C80\r
+#define M_CXLEFT 0x1CA0\r
+#define M_CXRIGHT 0x1CA4\r
+#define M_DR0 0x1CC0\r
+#define M_DR2 0x1CC8\r
+#define M_DR3 0x1CCC\r
+#define M_DR4 0x1CD0\r
+#define M_DR6 0x1CD8\r
+#define M_DR7 0x1CDC\r
+#define M_DR8 0x1CE0\r
+#define M_DR10 0x1CE8\r
+#define M_DR11 0x1CEC\r
+#define M_DR12 0x1CF0\r
+#define M_DR14 0x1CF8\r
+#define M_DR15 0x1CFC\r
+#define M_DWGCTL 0x1C00\r
+#define M_FCOL 0x1C24\r
+#define M_FIFOSTATUS 0x1E10\r
+#define M_FXBNDRY 0x1C84\r
+#define M_FXLEFT 0x1CA8\r
+#define M_FXRIGHT 0x1CAC\r
+#define M_ICLEAR 0x1E18\r
+#define M_IEN 0x1E1C\r
+#define M_LEN 0x1C5C\r
+#define M_MACCESS 0x1C04\r
+#define M_OPMODE 0x1E54\r
+#define M_PAT0 0x1C10\r
+#define M_PAT1 0x1C14\r
+#define M_PITCH 0x1C8C\r
+#define M_PLNWT 0x1C1C\r
+#define M_RESET 0x1E40\r
+#define M_SGN 0x1C58\r
+#define M_SHIFT 0x1C50\r
+#define M_SRC0 0x1C30\r
+#define M_SRC1 0x1C34\r
+#define M_SRC2 0x1C38\r
+#define M_SRC3 0x1C3C\r
+#define M_STATUS 0x1E14\r
+#define M_VCOUNT 0x1E20\r
+#define M_XDST 0x1CB0\r
+#define M_XYEND 0x1C44\r
+#define M_XYSTRT 0x1C40\r
+#define M_YBOT 0x1C9C\r
+#define M_YDST 0x1C90\r
+#define M_YDSTLEN 0x1C88\r
+#define M_YDSTORG 0x1C94\r
+#define M_YTOP 0x1C98\r
+#define M_ZORG 0x1C0C\r
+\r
+#define M_EXEC 0x0100\r
+\r
+/* DWGCTL: opcod */\r
+#define M_DWG_LINE_OPEN 0x0\r
+#define M_DWG_AUTOLINE_OPEN 0x1\r
+#define M_DWG_LINE_CLOSE 0x2\r
+#define M_DWG_AUTOLINE_CLOSE 0x3\r
+#define M_DWG_TRAP 0x4\r
+#define M_DWG_TEXTURE_TRAP 0x5\r
+#define M_DWG_BITBLT 0x8\r
+#define M_DWG_FBITBLT 0xC\r
+#define M_DWG_ILOAD 0x9\r
+#define M_DWG_ILOAD_SCALE 0xD\r
+#define M_DWG_ILOAD_FILTER 0xF\r
+#define M_DWG_IDUMP 0xA\r
+\r
+/* DWGCTL: atype */\r
+#define M_DWG_RPL (0x0 << 4)\r
+#define M_DWG_RSTR (0x1 << 4)\r
+#define M_DWG_ZI (0x3 << 4)\r
+#define M_DWG_BLK (0x4 << 4)\r
+#define M_DWG_I (0x7 << 4)\r
+\r
+/* DWGCTL: linear */\r
+#define M_DWG_LINEAR (0x1 << 7)\r
+\r
+/* DWGCTL: zmode */\r
+#define M_DWG_NOZCMP (0x0 << 8)\r
+#define M_DWG_ZE (0x2 << 8)\r
+#define M_DWG_ZNE (0x3 << 8)\r
+#define M_DWG_ZLT (0x4 << 8)\r
+#define M_DWG_ZLTE (0x5 << 8)\r
+#define M_DWG_ZGT (0x6 << 8)\r
+#define M_DWG_ZGTE (0x7 << 8)\r
+\r
+/* DWGCTL: solid */\r
+#define M_DWG_SOLID (0x1 << 11)\r
+\r
+/* DWGCTL: arzero */\r
+#define M_DWG_ARZERO (0x1 << 12)\r
+\r
+/* DWGCTL: sgnzero */\r
+#define M_DWG_SGNZERO (0x1 << 13)\r
+\r
+/* DWGCTL: shiftzero */\r
+#define M_DWG_SHFTZERO (0x1 << 14)\r
+\r
+/* DWGCTL: bop */\r
+#define M_DWG_BOP_XOR (0x6 << 16)\r
+#define M_DWG_BOP_AND (0x8 << 16)\r
+#define M_DWG_BOP_SRC (0xC << 16)\r
+#define M_DWG_BOP_OR (0xE << 16)\r
+\r
+/* DWGCTL: trans */\r
+#define M_DWG_TRANS_0 (0x0 << 20)\r
+#define M_DWG_TRANS_1 (0x1 << 20)\r
+#define M_DWG_TRANS_2 (0x2 << 20)\r
+#define M_DWG_TRANS_3 (0x3 << 20)\r
+#define M_DWG_TRANS_4 (0x4 << 20)\r
+#define M_DWG_TRANS_5 (0x5 << 20)\r
+#define M_DWG_TRANS_6 (0x6 << 20)\r
+#define M_DWG_TRANS_7 (0x7 << 20)\r
+#define M_DWG_TRANS_8 (0x8 << 20)\r
+#define M_DWG_TRANS_9 (0x9 << 20)\r
+#define M_DWG_TRANS_A (0xA << 20)\r
+#define M_DWG_TRANS_B (0xB << 20)\r
+#define M_DWG_TRANS_C (0xC << 20)\r
+#define M_DWG_TRANS_D (0xD << 20)\r
+#define M_DWG_TRANS_E (0xE << 20)\r
+#define M_DWG_TRANS_F (0xF << 20)\r
+\r
+/* DWGCTL: bltmod */\r
+#define M_DWG_BMONOLEF (0x0 << 25)\r
+#define M_DWG_BMONOWF (0x4 << 25)\r
+#define M_DWG_BPLAN (0x1 << 25)\r
+#define M_DWG_BFCOL (0x2 << 25)\r
+#define M_DWG_BUYUV (0xE << 25)\r
+#define M_DWG_BU32BGR (0x3 << 25)\r
+#define M_DWG_BU32RGB (0x7 << 25)\r
+#define M_DWG_BU24BGR (0xB << 25)\r
+#define M_DWG_BU24RGB (0xF << 25)\r
+\r
+/* DWGCTL: pattern */\r
+#define M_DWG_PATTERN (0x1 << 29)\r
+\r
+/* DWGCTL: transc */\r
+#define M_DWG_TRANSC (0x1 << 30)\r
+\r
+/* OPMODE: */\r
+#define M_DMA_GENERAL (0x0 << 2)\r
+#define M_DMA_BLIT (0x1 << 2)\r
+#define M_DMA_VECTOR (0x2 << 2)\r
+\r
+/* SGN: */\r
+#define M_SDXL (0x1 << 1)\r
+#define M_SDXR (0x1 << 5)\r
+\r
+\r
+\r
+/* VGAREG */\r
+#define M_CRTC_INDEX 0x1FD4\r
+#define M_CRTC_DATA 0x1FD5\r
+\r
+#define M_CRTC_EXT_INDEX 0x1FDE\r
+#define M_CRTC_EXT_DATA 0x1FDF\r
+\r
+#define M_MISC_R 0x1FCC\r
+#define M_MISC_W 0x1FC2\r
+\r
+/* CRTCEXT3: */\r
+#define M_MGAMODE (0x1 << 7)\r
+\r
+#endif\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 4.1\r
+ * \r
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
+ *\r
+ * Copyright (C) 2002 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#include <dpmi.h>\r
+#include <pc.h>\r
+#include <stdlib.h>\r
+#include <stubinfo.h>\r
+#include <sys/exceptn.h>\r
+#include <sys/segments.h>\r
+#include <sys/farptr.h>\r
+#include <sys/movedata.h>\r
+\r
+#include "video.h"\r
+#include "vesa.h"\r
+\r
+\r
+\r
+static vl_mode modes[128];\r
+\r
+static word16 vesa_ver;\r
+static int banked_selector, linear_selector;\r
+static int oldmode = -1;\r
+\r
+static int vesa_color_precision = 6;\r
+\r
+static word16 *vesa_pmcode;\r
+unsigned int vesa_gran_mask, vesa_gran_shift;\r
+\r
+\r
+\r
+/*\r
+ * VESA info\r
+ */\r
+#define V_SIGN 0\r
+#define V_MINOR 4\r
+#define V_MAJOR 5\r
+#define V_OEM_OFS 6\r
+#define V_OEM_SEG 8\r
+#define V_MODE_OFS 14\r
+#define V_MODE_SEG 16\r
+#define V_MEMORY 18\r
+\r
+/*\r
+ * mode info\r
+ */\r
+#define M_ATTR 0\r
+#define M_GRAN 4\r
+#define M_SCANLEN 16\r
+#define M_XRES 18\r
+#define M_YRES 20\r
+#define M_BPP 25\r
+#define M_RED 31\r
+#define M_GREEN 33\r
+#define M_BLUE 35\r
+#define M_PHYS_PTR 40\r
+\r
+/*\r
+ * VESA 3.0 CRTC timings structure\r
+ */\r
+typedef struct CRTCInfoBlock {\r
+ unsigned short HorizontalTotal;\r
+ unsigned short HorizontalSyncStart;\r
+ unsigned short HorizontalSyncEnd;\r
+ unsigned short VerticalTotal;\r
+ unsigned short VerticalSyncStart;\r
+ unsigned short VerticalSyncEnd;\r
+ unsigned char Flags;\r
+ unsigned long PixelClock; /* units of Hz */\r
+ unsigned short RefreshRate; /* units of 0.01 Hz */\r
+ unsigned char reserved[40];\r
+} __PACKED__ CRTCInfoBlock;\r
+\r
+#define HNEG (1 << 2)\r
+#define VNEG (1 << 3)\r
+#define DOUBLESCAN (1 << 0)\r
+\r
+\r
+\r
+/* Desc: Attempts to detect VESA, check video modes and create selectors.\r
+ *\r
+ * In : -\r
+ * Out : mode array\r
+ *\r
+ * Note: -\r
+ */\r
+static vl_mode *vesa_init (void)\r
+{\r
+ __dpmi_regs r;\r
+ word16 *p;\r
+ vl_mode *q;\r
+ char vesa_info[512], tmp[512];\r
+ int maxsize = 0;\r
+ word32 linearfb = 0;\r
+\r
+ if (vesa_ver) {\r
+ return modes;\r
+ }\r
+\r
+ _farpokel(_stubinfo->ds_selector, 0, 0x32454256);\r
+ r.x.ax = 0x4f00;\r
+ r.x.di = 0;\r
+ r.x.es = _stubinfo->ds_segment;\r
+ __dpmi_int(0x10, &r);\r
+ movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);\r
+ if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) {\r
+ return NULL;\r
+ }\r
+\r
+ p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS]));\r
+ q = modes;\r
+ do {\r
+ if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {\r
+ break;\r
+ }\r
+\r
+ r.x.ax = 0x4f01;\r
+ r.x.cx = q->mode;\r
+ r.x.di = 512;\r
+ r.x.es = _stubinfo->ds_segment;\r
+ __dpmi_int(0x10, &r);\r
+ movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);\r
+ switch (tmp[M_BPP]) {\r
+ case 16:\r
+ q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE];\r
+ break;\r
+ case 8:\r
+ case 15:\r
+ case 24:\r
+ case 32:\r
+ q->bpp = tmp[M_BPP];\r
+ break;\r
+ default:\r
+ q->bpp = 0;\r
+ }\r
+ if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp) {\r
+ q->xres = _16_ tmp[M_XRES];\r
+ q->yres = _16_ tmp[M_YRES];\r
+ q->scanlen = _16_ tmp[M_SCANLEN];\r
+ q->gran = (_16_ tmp[M_GRAN])<<10;\r
+ if (tmp[M_ATTR]&0x80) {\r
+#if 0\r
+ *(q+1) = *q++;\r
+#else\r
+ vl_mode *q1 = q + 1;\r
+ *q1 = *q++;\r
+#endif\r
+ linearfb = _32_ tmp[M_PHYS_PTR];\r
+ q->mode |= 0x4000;\r
+ }\r
+ if (maxsize<(q->scanlen*q->yres)) {\r
+ maxsize = q->scanlen*q->yres;\r
+ }\r
+ q++;\r
+ }\r
+ } while (TRUE);\r
+\r
+ if (q==modes) {\r
+ return NULL;\r
+ }\r
+ if (linearfb) {\r
+ maxsize = ((maxsize+0xfffUL)&~0xfffUL);\r
+ if (_create_selector(&linear_selector, linearfb, maxsize)) {\r
+ return NULL;\r
+ }\r
+ }\r
+ if (_create_selector(&banked_selector, 0xa0000, modes[0].gran)) {\r
+ _remove_selector(&linear_selector);\r
+ return NULL;\r
+ }\r
+\r
+ for (q=modes; q->mode!=0xffff; q++) {\r
+ q->sel = (q->mode&0x4000) ? linear_selector : banked_selector;\r
+ }\r
+\r
+ if (vesa_info[V_MAJOR] >= 2) {\r
+ r.x.ax = 0x4f0a;\r
+ r.x.bx = 0;\r
+ __dpmi_int(0x10, &r);\r
+ if (r.x.ax == 0x004f) {\r
+ vesa_pmcode = (word16 *)malloc(r.x.cx);\r
+ movedata(__djgpp_dos_sel, (r.x.es << 4) + r.x.di, _my_ds(), (unsigned)vesa_pmcode, r.x.cx);\r
+ if (vesa_pmcode[3]) {\r
+ p = (word16 *)((long)vesa_pmcode + vesa_pmcode[3]);\r
+ while (*p++ != 0xffff) ;\r
+ } else {\r
+ p = NULL;\r
+ }\r
+ if (p && (*p != 0xffff)) {\r
+ free(vesa_pmcode);\r
+ vesa_pmcode = NULL;\r
+ } else {\r
+ vesa_swbank = (void *)((long)vesa_pmcode + vesa_pmcode[0]);\r
+ }\r
+ }\r
+ }\r
+\r
+ vesa_ver = _16_ vesa_info[V_MINOR];\r
+ return modes;\r
+}\r
+\r
+\r
+\r
+/* Desc: Frees all resources allocated by VESA init code.\r
+ *\r
+ * In : -\r
+ * Out : -\r
+ *\r
+ * Note: -\r
+ */\r
+static void vesa_fini (void)\r
+{\r
+ if (vesa_ver) {\r
+ _remove_selector(&linear_selector);\r
+ _remove_selector(&banked_selector);\r
+ if (vesa_pmcode != NULL) {\r
+ free(vesa_pmcode);\r
+ vesa_pmcode = NULL;\r
+ }\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: Uses VESA 3.0 function 0x4F0B to find the closest pixel clock to the requested value.\r
+ *\r
+ * In : mode, clock\r
+ * Out : desired clock\r
+ *\r
+ * Note: -\r
+ */\r
+static unsigned long _closest_pixclk (int mode_no, unsigned long vclk)\r
+{\r
+ __dpmi_regs r;\r
+\r
+ r.x.ax = 0x4F0B;\r
+ r.h.bl = 0;\r
+ r.d.ecx = vclk;\r
+ r.x.dx = mode_no;\r
+ __dpmi_int(0x10, &r);\r
+\r
+ return (r.x.ax==0x004f) ? r.d.ecx : 0;\r
+}\r
+\r
+\r
+\r
+/* Desc: Calculates CRTC mode timings.\r
+ *\r
+ * In : crtc block, geometry, adjust\r
+ * Out :\r
+ *\r
+ * Note:\r
+ */\r
+static void _crtc_timing (CRTCInfoBlock *crtc, int xres, int yres, int xadjust, int yadjust)\r
+{\r
+ int HTotal, VTotal;\r
+ int HDisp, VDisp;\r
+ int HSS, VSS;\r
+ int HSE, VSE;\r
+ int HSWidth, VSWidth;\r
+ int SS, SE;\r
+ int doublescan = FALSE;\r
+\r
+ if (yres < 400) {\r
+ doublescan = TRUE;\r
+ yres *= 2;\r
+ }\r
+\r
+ HDisp = xres;\r
+ HTotal = (int)(HDisp * 1.27) & ~0x7;\r
+ HSWidth = (int)((HTotal - HDisp) / 5) & ~0x7;\r
+ HSS = HDisp + 16;\r
+ HSE = HSS + HSWidth;\r
+ VDisp = yres;\r
+ VTotal = VDisp * 1.07;\r
+ VSWidth = (VTotal / 100) + 1;\r
+ VSS = VDisp + ((int)(VTotal - VDisp) / 5) + 1;\r
+ VSE = VSS + VSWidth;\r
+\r
+ SS = HSS + xadjust;\r
+ SE = HSE + xadjust;\r
+\r
+ if (xadjust < 0) {\r
+ if (SS < (HDisp + 8)) {\r
+ SS = HDisp + 8;\r
+ SE = SS + HSWidth;\r
+ }\r
+ } else {\r
+ if ((HTotal - 24) < SE) {\r
+ SE = HTotal - 24;\r
+ SS = SE - HSWidth;\r
+ }\r
+ }\r
+\r
+ HSS = SS;\r
+ HSE = SE;\r
+\r
+ SS = VSS + yadjust;\r
+ SE = VSE + yadjust;\r
+\r
+ if (yadjust < 0) {\r
+ if (SS < (VDisp + 3)) {\r
+ SS = VDisp + 3;\r
+ SE = SS + VSWidth;\r
+ }\r
+ } else {\r
+ if ((VTotal - 4) < SE) {\r
+ SE = VTotal - 4;\r
+ SS = SE - VSWidth;\r
+ }\r
+ }\r
+\r
+ VSS = SS;\r
+ VSE = SE;\r
+\r
+ crtc->HorizontalTotal = HTotal;\r
+ crtc->HorizontalSyncStart = HSS;\r
+ crtc->HorizontalSyncEnd = HSE;\r
+ crtc->VerticalTotal = VTotal;\r
+ crtc->VerticalSyncStart = VSS;\r
+ crtc->VerticalSyncEnd = VSE;\r
+ crtc->Flags = HNEG | VNEG;\r
+\r
+ if (doublescan)\r
+ crtc->Flags |= DOUBLESCAN;\r
+}\r
+\r
+\r
+\r
+/* Desc: Attempts to enter specified video mode.\r
+ *\r
+ * In : ptr to mode structure, refresh rate\r
+ * Out : 0 if success\r
+ *\r
+ * Note: -\r
+ */\r
+static int vesa_entermode (vl_mode *p, int refresh)\r
+{\r
+ __dpmi_regs r;\r
+\r
+ if (p->mode & 0x4000) {\r
+ VESA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;\r
+ } else {\r
+ VESA.blit = vesa_b_dump_virtual;\r
+ { int n; for (vesa_gran_shift=0, n=p->gran; n; vesa_gran_shift++, n>>=1) ; }\r
+ vesa_gran_mask = (1<<(--vesa_gran_shift)) - 1;\r
+ if ((unsigned)p->gran != (vesa_gran_mask+1)) {\r
+ return !0;\r
+ }\r
+ }\r
+\r
+ if (oldmode == -1) {\r
+ r.x.ax = 0x4f03;\r
+ __dpmi_int(0x10, &r);\r
+ oldmode = r.x.bx;\r
+ }\r
+\r
+ r.x.ax = 0x4f02;\r
+ r.x.bx = p->mode;\r
+\r
+ if (refresh && ((vesa_ver>>8) >= 3)) {\r
+ /* VESA 3.0 stuff for controlling the refresh rate */\r
+ CRTCInfoBlock crtc;\r
+ unsigned long vclk;\r
+ double f0;\r
+\r
+ _crtc_timing(&crtc, p->xres, p->yres, 0, 0);\r
+\r
+ vclk = (double)crtc.HorizontalTotal * crtc.VerticalTotal * refresh;\r
+ vclk = _closest_pixclk(p->mode, vclk);\r
+\r
+ if (vclk != 0) {\r
+ f0 = (double)vclk / (crtc.HorizontalTotal * crtc.VerticalTotal);\r
+ /*_current_refresh_rate = (int)(f0 + 0.5);*/\r
+\r
+ crtc.PixelClock = vclk;\r
+ crtc.RefreshRate = refresh * 100;\r
+\r
+ movedata(_my_ds(), (unsigned)&crtc, _stubinfo->ds_selector, 0, sizeof(crtc));\r
+\r
+ r.x.di = 0;\r
+ r.x.es = _stubinfo->ds_segment;\r
+ r.x.bx |= 0x0800;\r
+ }\r
+ }\r
+\r
+ __dpmi_int(0x10, &r);\r
+ if (r.x.ax != 0x004f) {\r
+ return !0;\r
+ }\r
+\r
+ if (p->bpp == 8) {\r
+ r.x.ax = 0x4f08;\r
+ r.x.bx = 0x0800;\r
+ __dpmi_int(0x10, &r);\r
+ if (r.x.ax == 0x004f) {\r
+ r.x.ax = 0x4f08;\r
+ r.h.bl = 0x01;\r
+ __dpmi_int(0x10, &r);\r
+ vesa_color_precision = r.h.bh;\r
+ }\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/* Desc: Restores to the mode prior to first call to vesa_entermode.\r
+ *\r
+ * In : -\r
+ * Out : -\r
+ *\r
+ * Note: -\r
+ */\r
+static void vesa_restore (void)\r
+{\r
+ __dpmi_regs r;\r
+\r
+ if (oldmode != -1) {\r
+ r.x.ax = 0x4f02;\r
+ r.x.bx = oldmode;\r
+ __dpmi_int(0x10, &r);\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: set one palette entry\r
+ *\r
+ * In : color index, R, G, B\r
+ * Out : -\r
+ *\r
+ * Note: uses integer values\r
+ */\r
+static void vesa_setCI_i (int index, int red, int green, int blue)\r
+{\r
+#if 0\r
+ __asm("\n\\r
+ movw $0x1010, %%ax \n\\r
+ movb %1, %%dh \n\\r
+ movb %2, %%ch \n\\r
+ int $0x10 \n\\r
+ "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");\r
+#else\r
+ outportb(0x03C8, index);\r
+ outportb(0x03C9, red);\r
+ outportb(0x03C9, green);\r
+ outportb(0x03C9, blue);\r
+#endif\r
+}\r
+\r
+\r
+\r
+/* Desc: set one palette entry\r
+ *\r
+ * In : color index, R, G, B\r
+ * Out : -\r
+ *\r
+ * Note: uses normalized values\r
+ */\r
+static void vesa_setCI_f (int index, float red, float green, float blue)\r
+{\r
+ float max = (1 << vesa_color_precision) - 1;\r
+\r
+ vesa_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));\r
+}\r
+\r
+\r
+\r
+/* Desc: state retrieval\r
+ *\r
+ * In : parameter name, ptr to storage\r
+ * Out : 0 if request successfully processed\r
+ *\r
+ * Note: -\r
+ */\r
+static int vesa_get (int pname, int *params)\r
+{\r
+ switch (pname) {\r
+ case VL_GET_CI_PREC:\r
+ params[0] = vesa_color_precision;\r
+ break;\r
+ default:\r
+ return -1;\r
+ }\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/*\r
+ * the driver\r
+ */\r
+vl_driver VESA = {\r
+ vesa_init,\r
+ vesa_entermode,\r
+ NULL,\r
+ vesa_setCI_f,\r
+ vesa_setCI_i,\r
+ vesa_get,\r
+ vesa_restore,\r
+ vesa_fini\r
+};\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 4.0\r
+ * \r
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
+ *\r
+ * Copyright (C) 2002 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#ifndef VESA_H_included\r
+#define VESA_H_included\r
+\r
+#include "internal.h"\r
+\r
+extern void *vesa_swbank;\r
+\r
+extern void vesa_b_dump_virtual (void);\r
+extern void vesa_l_dump_virtual (void);\r
+extern void vesa_l_dump_virtual_mmx (void);\r
+\r
+extern vl_driver VESA;\r
+\r
+#endif\r
+++ /dev/null
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.0\r
- * \r
- * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
- .file "blit.S"\r
-\r
-/*\r
- * extern unsigned int vesa_gran_mask, vesa_gran_shift;\r
- * extern int vl_video_selector;\r
-\r
- * extern void *vl_current_draw_buffer;\r
- * extern int vl_current_stride, vl_current_height;\r
- * extern int vl_current_offset, vl_current_delta;\r
- */\r
-\r
- .text\r
-\r
-/* Desc: VESA bank switching routine (BIOS)\r
- *\r
- * In : EBX=0, EDX = bank number\r
- * Out : -\r
- *\r
- * Note: thrashes EAX\r
- */\r
- .p2align 5,,31\r
-_vesa_swbankBIOS:\r
- movw $0x4f05, %ax\r
- int $0x10\r
- ret\r
-\r
- .p2align 2,,3\r
- .global _vesa_swbank\r
-_vesa_swbank: .long _vesa_swbankBIOS\r
-\r
-/* Desc: void vesa_b_dump_virtual (void);\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _vesa_b_dump_virtual\r
-_vesa_b_dump_virtual:\r
- cld\r
- pushl %es\r
- pushl %ebx\r
- pushl %esi\r
- pushl %edi\r
- pushl %ebp\r
- movl _vl_video_selector, %es\r
- movl _vl_current_draw_buffer, %esi\r
- movl _vl_current_offset, %edi\r
- movl _vesa_gran_shift, %ecx\r
- movl _vesa_gran_mask, %ebp\r
- movl %edi, %edx\r
- xorl %ebx, %ebx\r
- andl %ebp, %edi\r
- shrl %cl, %edx\r
- incl %ebp\r
- call *_vesa_swbank\r
- movl _vl_current_stride, %ecx\r
- movl _vl_current_height, %eax\r
- movl _vl_current_delta, %ebx\r
- shrl $2, %ecx\r
- .balign 4\r
- 0:\r
- pushl %ecx\r
- .balign 4\r
- 1:\r
- cmpl %ebp, %edi\r
- jb 2f\r
- pushl %eax\r
- pushl %ebx\r
- incl %edx\r
- xorl %ebx, %ebx\r
- call *_vesa_swbank\r
- popl %ebx\r
- popl %eax\r
- subl %ebp, %edi\r
- .balign 4\r
- 2:\r
- movsl\r
- decl %ecx\r
- jnz 1b\r
- popl %ecx\r
- addl %ebx, %edi\r
- decl %eax\r
- jnz 0b\r
- popl %ebp\r
- popl %edi\r
- popl %esi\r
- popl %ebx\r
- popl %es\r
- ret\r
-\r
-/* Desc: void vesa_l_dump_virtual (void);\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _vesa_l_dump_virtual\r
-_vesa_l_dump_virtual:\r
- cld\r
- pushl %es\r
- pushl %esi\r
- pushl %edi\r
- movl _vl_video_selector, %es\r
- movl _vl_current_draw_buffer, %esi\r
- movl _vl_current_offset, %edi\r
- movl _vl_current_stride, %ecx\r
- movl _vl_current_height, %edx\r
- movl _vl_current_delta, %eax\r
- shrl $2, %ecx\r
- .balign 4\r
- 0:\r
- pushl %ecx\r
- rep; movsl\r
- popl %ecx\r
- addl %eax, %edi\r
- decl %edx\r
- jnz 0b\r
- popl %edi\r
- popl %esi\r
- popl %es\r
- ret\r
-\r
-/* Desc: void vesa_l_dump_virtual_mmx (void);\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _vesa_l_dump_virtual_mmx\r
-_vesa_l_dump_virtual_mmx:\r
-#ifdef USE_MMX_ASM\r
- pushl %esi\r
- pushl %edi\r
- movl _vl_video_selector, %fs\r
- movl _vl_current_draw_buffer, %esi\r
- movl _vl_current_offset, %edi\r
- movl _vl_current_stride, %ecx\r
- movl _vl_current_height, %edx\r
- movl _vl_current_delta, %eax\r
- shrl $3, %ecx\r
- .balign 4\r
- 0:\r
- pushl %ecx\r
- .balign 4\r
- 1:\r
- movq (%esi), %mm0\r
- addl $8, %esi\r
- movq %mm0, %fs:(%edi)\r
- addl $8, %edi\r
- decl %ecx\r
- jnz 1b\r
- popl %ecx\r
- addl %eax, %edi\r
- decl %edx\r
- jnz 0b\r
- popl %edi\r
- popl %esi\r
- emms\r
-#endif\r
- ret\r
+++ /dev/null
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.1\r
- * \r
- * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include <dpmi.h>\r
-#include <pc.h>\r
-#include <stdlib.h>\r
-#include <stubinfo.h>\r
-#include <sys/exceptn.h>\r
-#include <sys/segments.h>\r
-#include <sys/farptr.h>\r
-#include <sys/movedata.h>\r
-\r
-#include "vesa.h"\r
-\r
-\r
-\r
-static vl_mode modes[64];\r
-\r
-static word16 vesa_ver;\r
-static int banked_selector, linear_selector;\r
-static int oldmode = -1;\r
-\r
-static int vesa_color_precision = 6;\r
-\r
-static void *vesa_pmcode;\r
-unsigned int vesa_gran_mask, vesa_gran_shift;\r
-\r
-\r
-\r
-/*\r
- * VESA info\r
- */\r
-#define V_SIGN 0\r
-#define V_MINOR 4\r
-#define V_MAJOR 5\r
-#define V_OEM_OFS 6\r
-#define V_OEM_SEG 8\r
-#define V_MODE_OFS 14\r
-#define V_MODE_SEG 16\r
-#define V_MEMORY 18\r
-\r
-/*\r
- * mode info\r
- */\r
-#define M_ATTR 0\r
-#define M_GRAN 4\r
-#define M_SCANLEN 16\r
-#define M_XRES 18\r
-#define M_YRES 20\r
-#define M_BPP 25\r
-#define M_RED 31\r
-#define M_GREEN 33\r
-#define M_BLUE 35\r
-#define M_PHYS_PTR 40\r
-\r
-/*\r
- * VESA 3.0 CRTC timings structure\r
- */\r
-typedef struct CRTCInfoBlock {\r
- unsigned short HorizontalTotal;\r
- unsigned short HorizontalSyncStart;\r
- unsigned short HorizontalSyncEnd;\r
- unsigned short VerticalTotal;\r
- unsigned short VerticalSyncStart;\r
- unsigned short VerticalSyncEnd;\r
- unsigned char Flags;\r
- unsigned long PixelClock; /* units of Hz */\r
- unsigned short RefreshRate; /* units of 0.01 Hz */\r
- unsigned char reserved[40];\r
-} __PACKED__ CRTCInfoBlock;\r
-\r
-#define HNEG (1 << 2)\r
-#define VNEG (1 << 3)\r
-#define DOUBLESCAN (1 << 0)\r
-\r
-\r
-\r
-/* Desc: Attempts to detect VESA, check video modes and create selectors.\r
- *\r
- * In : -\r
- * Out : mode array\r
- *\r
- * Note: -\r
- */\r
-static vl_mode *vesa_init (void)\r
-{\r
- __dpmi_regs r;\r
- word16 *p;\r
- vl_mode *q;\r
- char vesa_info[512], tmp[512];\r
- int maxsize = 0;\r
- word32 linearfb = 0;\r
-\r
- if (vesa_ver) {\r
- return modes;\r
- }\r
-\r
- _farpokel(_stubinfo->ds_selector, 0, 0x32454256);\r
- r.x.ax = 0x4f00;\r
- r.x.di = 0;\r
- r.x.es = _stubinfo->ds_segment;\r
- __dpmi_int(0x10, &r);\r
- movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);\r
- if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) {\r
- return NULL;\r
- }\r
-\r
- p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS]));\r
- q = modes;\r
- do {\r
- if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {\r
- break;\r
- }\r
-\r
- r.x.ax = 0x4f01;\r
- r.x.cx = q->mode;\r
- r.x.di = 512;\r
- r.x.es = _stubinfo->ds_segment;\r
- __dpmi_int(0x10, &r);\r
- movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);\r
- switch (tmp[M_BPP]) {\r
- case 16:\r
- q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE];\r
- break;\r
- case 8:\r
- case 15:\r
- case 24:\r
- case 32:\r
- q->bpp = tmp[M_BPP];\r
- break;\r
- default:\r
- q->bpp = 0;\r
- }\r
- if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp) {\r
- q->xres = _16_ tmp[M_XRES];\r
- q->yres = _16_ tmp[M_YRES];\r
- q->scanlen = _16_ tmp[M_SCANLEN];\r
- q->gran = (_16_ tmp[M_GRAN])<<10;\r
- if (tmp[M_ATTR]&0x80) {\r
-#if 0\r
- *(q+1) = *q++;\r
-#else\r
- vl_mode *q1 = q + 1;\r
- *q1 = *q++;\r
-#endif\r
- linearfb = _32_ tmp[M_PHYS_PTR];\r
- q->mode |= 0x4000;\r
- }\r
- if (maxsize<(q->scanlen*q->yres)) {\r
- maxsize = q->scanlen*q->yres;\r
- }\r
- q++;\r
- }\r
- } while (TRUE);\r
-\r
- if (q==modes) {\r
- return NULL;\r
- }\r
- if (linearfb) {\r
- maxsize = ((maxsize+0xfffUL)&~0xfffUL);\r
- if (_create_selector(&linear_selector, linearfb, maxsize)) {\r
- return NULL;\r
- }\r
- }\r
- if (_create_selector(&banked_selector, 0xa0000, modes[0].gran)) {\r
- _remove_selector(&linear_selector);\r
- return NULL;\r
- }\r
-\r
- for (q=modes; q->mode!=0xffff; q++) {\r
- q->sel = (q->mode&0x4000) ? linear_selector : banked_selector;\r
- }\r
-\r
- if (vesa_info[V_MAJOR] >= 2) {\r
- r.x.ax = 0x4f0a;\r
- r.h.bl = 0;\r
- __dpmi_int(0x10, &r);\r
- if (r.x.ax == 0x004f) {\r
- vesa_pmcode = malloc(r.x.cx);\r
- movedata(__djgpp_dos_sel, (r.x.es << 4) + r.x.di, _my_ds(), (unsigned)vesa_pmcode, r.x.cx);\r
- p = (word16 *)((long)vesa_pmcode + ((word16 *)vesa_pmcode)[3]);\r
- while (*p++ != 0xffff) ;\r
- if (*p != 0xffff) {\r
- free(vesa_pmcode);\r
- vesa_pmcode = NULL;\r
- } else {\r
- vesa_swbank = (char *)vesa_pmcode + ((word16 *)vesa_pmcode)[0];\r
- }\r
- }\r
- }\r
-\r
- vesa_ver = _16_ vesa_info[V_MINOR];\r
- return modes;\r
-}\r
-\r
-\r
-\r
-/* Desc: Frees all resources allocated by VESA init code.\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-static void vesa_finit (void)\r
-{\r
- if (vesa_ver) {\r
- _remove_selector(&linear_selector);\r
- _remove_selector(&banked_selector);\r
- if (vesa_pmcode != NULL) {\r
- free(vesa_pmcode);\r
- vesa_pmcode = NULL;\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-/* Desc: Uses VESA 3.0 function 0x4F0B to find the closest pixel clock to the requested value.\r
- *\r
- * In : mode, clock\r
- * Out : desired clock\r
- *\r
- * Note: -\r
- */\r
-static unsigned long _closest_pixclk (int mode_no, unsigned long vclk)\r
-{\r
- __dpmi_regs r;\r
-\r
- r.x.ax = 0x4F0B;\r
- r.h.bl = 0;\r
- r.d.ecx = vclk;\r
- r.x.dx = mode_no;\r
- __dpmi_int(0x10, &r);\r
-\r
- return (r.x.ax==0x004f) ? r.d.ecx : 0;\r
-}\r
-\r
-\r
-\r
-/* Desc: Calculates CRTC mode timings.\r
- *\r
- * In : crtc block, geometry, adjust\r
- * Out :\r
- *\r
- * Note:\r
- */\r
-static void _crtc_timing (CRTCInfoBlock *crtc, int xres, int yres, int xadjust, int yadjust)\r
-{\r
- int HTotal, VTotal;\r
- int HDisp, VDisp;\r
- int HSS, VSS;\r
- int HSE, VSE;\r
- int HSWidth, VSWidth;\r
- int SS, SE;\r
- int doublescan = FALSE;\r
-\r
- if (yres < 400) {\r
- doublescan = TRUE;\r
- yres *= 2;\r
- }\r
-\r
- HDisp = xres;\r
- HTotal = (int)(HDisp * 1.27) & ~0x7;\r
- HSWidth = (int)((HTotal - HDisp) / 5) & ~0x7;\r
- HSS = HDisp + 16;\r
- HSE = HSS + HSWidth;\r
- VDisp = yres;\r
- VTotal = VDisp * 1.07;\r
- VSWidth = (VTotal / 100) + 1;\r
- VSS = VDisp + ((int)(VTotal - VDisp) / 5) + 1;\r
- VSE = VSS + VSWidth;\r
-\r
- SS = HSS + xadjust;\r
- SE = HSE + xadjust;\r
-\r
- if (xadjust < 0) {\r
- if (SS < (HDisp + 8)) {\r
- SS = HDisp + 8;\r
- SE = SS + HSWidth;\r
- }\r
- } else {\r
- if ((HTotal - 24) < SE) {\r
- SE = HTotal - 24;\r
- SS = SE - HSWidth;\r
- }\r
- }\r
-\r
- HSS = SS;\r
- HSE = SE;\r
-\r
- SS = VSS + yadjust;\r
- SE = VSE + yadjust;\r
-\r
- if (yadjust < 0) {\r
- if (SS < (VDisp + 3)) {\r
- SS = VDisp + 3;\r
- SE = SS + VSWidth;\r
- }\r
- } else {\r
- if ((VTotal - 4) < SE) {\r
- SE = VTotal - 4;\r
- SS = SE - VSWidth;\r
- }\r
- }\r
-\r
- VSS = SS;\r
- VSE = SE;\r
-\r
- crtc->HorizontalTotal = HTotal;\r
- crtc->HorizontalSyncStart = HSS;\r
- crtc->HorizontalSyncEnd = HSE;\r
- crtc->VerticalTotal = VTotal;\r
- crtc->VerticalSyncStart = VSS;\r
- crtc->VerticalSyncEnd = VSE;\r
- crtc->Flags = HNEG | VNEG;\r
-\r
- if (doublescan)\r
- crtc->Flags |= DOUBLESCAN;\r
-}\r
-\r
-\r
-\r
-/* Desc: Attempts to enter specified video mode.\r
- *\r
- * In : ptr to mode structure, refresh rate\r
- * Out : 0 if success\r
- *\r
- * Note: -\r
- */\r
-static int vesa_entermode (vl_mode *p, int refresh)\r
-{\r
- __dpmi_regs r;\r
-\r
- if (p->mode & 0x4000) {\r
- VESA.blit = vl_can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;\r
- } else {\r
- VESA.blit = vesa_b_dump_virtual;\r
- { int n; for (vesa_gran_shift=0, n=p->gran; n; vesa_gran_shift++, n>>=1) ; }\r
- vesa_gran_mask = (1<<(--vesa_gran_shift)) - 1;\r
- if ((unsigned)p->gran != (vesa_gran_mask+1)) {\r
- return !0;\r
- }\r
- }\r
-\r
- if (oldmode == -1) {\r
- r.x.ax = 0x4f03;\r
- __dpmi_int(0x10, &r);\r
- oldmode = r.x.bx;\r
- }\r
-\r
- r.x.ax = 0x4f02;\r
- r.x.bx = p->mode;\r
-\r
- if (refresh && ((vesa_ver>>8) >= 3)) {\r
- /* VESA 3.0 stuff for controlling the refresh rate */\r
- CRTCInfoBlock crtc;\r
- unsigned long vclk;\r
- double f0;\r
-\r
- _crtc_timing(&crtc, p->xres, p->yres, 0, 0);\r
-\r
- vclk = (double)crtc.HorizontalTotal * crtc.VerticalTotal * refresh;\r
- vclk = _closest_pixclk(p->mode, vclk);\r
-\r
- if (vclk != 0) {\r
- f0 = (double)vclk / (crtc.HorizontalTotal * crtc.VerticalTotal);\r
- /*_current_refresh_rate = (int)(f0 + 0.5);*/\r
-\r
- crtc.PixelClock = vclk;\r
- crtc.RefreshRate = refresh * 100;\r
-\r
- movedata(_my_ds(), (unsigned)&crtc, _stubinfo->ds_selector, 0, sizeof(crtc));\r
-\r
- r.x.di = 0;\r
- r.x.es = _stubinfo->ds_segment;\r
- r.x.bx |= 0x0800;\r
- }\r
- }\r
-\r
- __dpmi_int(0x10, &r);\r
- if (r.x.ax != 0x004f) {\r
- return !0;\r
- }\r
-\r
- if (p->bpp == 8) {\r
- r.x.ax = 0x4f08;\r
- r.x.bx = 0x0800;\r
- __dpmi_int(0x10, &r);\r
- if (r.x.ax == 0x004f) {\r
- r.x.ax = 0x4f08;\r
- r.h.bl = 0x01;\r
- __dpmi_int(0x10, &r);\r
- vesa_color_precision = r.h.bh;\r
- }\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* Desc: Restores to the mode prior to first call to vesa_entermode.\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-static void vesa_restore (void)\r
-{\r
- __dpmi_regs r;\r
-\r
- if (oldmode != -1) {\r
- r.x.ax = 0x4f02;\r
- r.x.bx = oldmode;\r
- __dpmi_int(0x10, &r);\r
- }\r
-}\r
-\r
-\r
-\r
-/* Desc: set one palette entry\r
- *\r
- * In : color index, R, G, B\r
- * Out : -\r
- *\r
- * Note: uses integer values\r
- */\r
-static void vesa_setCI_i (int index, int red, int green, int blue)\r
-{\r
-#if 0\r
- __asm("\n\\r
- movw $0x1010, %%ax \n\\r
- movb %1, %%dh \n\\r
- movb %2, %%ch \n\\r
- int $0x10 \n\\r
- "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");\r
-#else\r
- outportb(0x03C8, index);\r
- outportb(0x03C9, red);\r
- outportb(0x03C9, green);\r
- outportb(0x03C9, blue);\r
-#endif\r
-}\r
-\r
-\r
-\r
-/* Desc: set one palette entry\r
- *\r
- * In : color index, R, G, B\r
- * Out : -\r
- *\r
- * Note: uses normalized values\r
- */\r
-static void vesa_setCI_f (int index, float red, float green, float blue)\r
-{\r
- float max = (1 << vesa_color_precision) - 1;\r
-\r
- vesa_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));\r
-}\r
-\r
-\r
-\r
-/* Desc: retrieve CI precision\r
- *\r
- * In : -\r
- * Out : precision in bits\r
- *\r
- * Note: -\r
- */\r
-static int vesa_getCIprec (void)\r
-{\r
- return vesa_color_precision;\r
-}\r
-\r
-\r
-\r
-/*\r
- * the driver\r
- */\r
-vl_driver VESA = {\r
- vesa_init,\r
- vesa_entermode,\r
- NULL,\r
- vesa_setCI_f,\r
- vesa_setCI_i,\r
- vesa_getCIprec,\r
- vesa_restore,\r
- vesa_finit\r
-};\r
+++ /dev/null
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.0\r
- * \r
- * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#ifndef VESA_H_included\r
-#define VESA_H_included\r
-\r
-#include "../internal.h"\r
-\r
-extern void *vesa_swbank;\r
-\r
-extern void vesa_b_dump_virtual (void);\r
-extern void vesa_l_dump_virtual (void);\r
-extern void vesa_l_dump_virtual_mmx (void);\r
-\r
-extern vl_driver VESA;\r
-\r
-#endif\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 4.1\r
+ * \r
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
+ *\r
+ * Copyright (C) 2002 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#include <pc.h>\r
+#include <stdlib.h>\r
+\r
+#include "video.h"\r
+#include "vga.h"\r
+\r
+\r
+\r
+static vl_mode modes[] = {\r
+ {0x13 | 0x4000, 320, 200, 320, 8, -1, 320*200},\r
+ {0xffff, -1, -1, -1, -1, -1, -1}\r
+};\r
+\r
+static word16 vga_ver;\r
+static int linear_selector;\r
+static int oldmode = -1;\r
+\r
+#define vga_color_precision 6\r
+\r
+\r
+\r
+/* Desc: Attempts to detect VGA, check video modes and create selectors.\r
+ *\r
+ * In : -\r
+ * Out : mode array\r
+ *\r
+ * Note: -\r
+ */\r
+static vl_mode *vga_init (void)\r
+{\r
+ int rv = 0;\r
+\r
+ if (vga_ver) {\r
+ return modes;\r
+ }\r
+\r
+ __asm("\n\\r
+ movw $0x1a00, %%ax \n\\r
+ int $0x10 \n\\r
+ cmpb $0x1a, %%al \n\\r
+ jne 0f \n\\r
+ cmpb $0x07, %%bl \n\\r
+ jb 0f \n\\r
+ andl $0xff, %%ebx \n\\r
+ movl %%ebx, %0 \n\\r
+ 0:":"=g"(rv)::"%eax", "%ebx");\r
+ if (rv == 0) {\r
+ return NULL;\r
+ }\r
+\r
+ if (_create_selector(&linear_selector, 0xa0000, 0x10000)) {\r
+ return NULL;\r
+ }\r
+\r
+ modes[0].sel = linear_selector;\r
+\r
+ vga_ver = rv;\r
+ return modes;\r
+}\r
+\r
+\r
+\r
+/* Desc: Frees all resources allocated by VGA init code.\r
+ *\r
+ * In : -\r
+ * Out : -\r
+ *\r
+ * Note: -\r
+ */\r
+static void vga_fini (void)\r
+{\r
+ if (vga_ver) {\r
+ _remove_selector(&linear_selector);\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: Attempts to enter specified video mode.\r
+ *\r
+ * In : ptr to mode structure, refresh rate\r
+ * Out : 0 if success\r
+ *\r
+ * Note: -\r
+ */\r
+static int vga_entermode (vl_mode *p, int refresh)\r
+{\r
+ if (!(p->mode & 0x4000)) {\r
+ return -1;\r
+ }\r
+ VGA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;\r
+\r
+ if (oldmode == -1) {\r
+ __asm("\n\\r
+ movb $0x0f, %%ah \n\\r
+ int $0x10 \n\\r
+ andl $0xff, %%eax \n\\r
+ movl %%eax, %0 \n\\r
+ ":"=g"(oldmode)::"%eax", "%ebx");\r
+ }\r
+\r
+ __asm("int $0x10"::"a"(p->mode&0xff));\r
+\r
+ return 0;\r
+\r
+ (void)refresh; /* silence compiler warning */\r
+}\r
+\r
+\r
+\r
+/* Desc: Restores to the mode prior to first call to vga_entermode.\r
+ *\r
+ * In : -\r
+ * Out : -\r
+ *\r
+ * Note: -\r
+ */\r
+static void vga_restore (void)\r
+{\r
+ if (oldmode != -1) {\r
+ __asm("int $0x10"::"a"(oldmode));\r
+ }\r
+}\r
+\r
+\r
+\r
+/* Desc: set one palette entry\r
+ *\r
+ * In : color index, R, G, B\r
+ * Out : -\r
+ *\r
+ * Note: uses integer values\r
+ */\r
+static void vga_setCI_i (int index, int red, int green, int blue)\r
+{\r
+#if 0\r
+ __asm("\n\\r
+ movw $0x1010, %%ax \n\\r
+ movb %1, %%dh \n\\r
+ movb %2, %%ch \n\\r
+ int $0x10 \n\\r
+ "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");\r
+#else\r
+ outportb(0x03C8, index);\r
+ outportb(0x03C9, red);\r
+ outportb(0x03C9, green);\r
+ outportb(0x03C9, blue);\r
+#endif\r
+}\r
+\r
+\r
+\r
+/* Desc: set one palette entry\r
+ *\r
+ * In : color index, R, G, B\r
+ * Out : -\r
+ *\r
+ * Note: uses normalized values\r
+ */\r
+static void vga_setCI_f (int index, float red, float green, float blue)\r
+{\r
+ float max = (1 << vga_color_precision) - 1;\r
+\r
+ vga_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));\r
+}\r
+\r
+\r
+\r
+/* Desc: state retrieval\r
+ *\r
+ * In : parameter name, ptr to storage\r
+ * Out : 0 if request successfully processed\r
+ *\r
+ * Note: -\r
+ */\r
+static int vga_get (int pname, int *params)\r
+{\r
+ switch (pname) {\r
+ case VL_GET_CI_PREC:\r
+ params[0] = vga_color_precision;\r
+ break;\r
+ default:\r
+ return -1;\r
+ }\r
+ return 0;\r
+}\r
+\r
+\r
+\r
+/*\r
+ * the driver\r
+ */\r
+vl_driver VGA = {\r
+ vga_init,\r
+ vga_entermode,\r
+ NULL,\r
+ vga_setCI_f,\r
+ vga_setCI_i,\r
+ vga_get,\r
+ vga_restore,\r
+ vga_fini\r
+};\r
--- /dev/null
+/*\r
+ * Mesa 3-D graphics library\r
+ * Version: 4.0\r
+ * \r
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
+ * \r
+ * Permission is hereby granted, free of charge, to any person obtaining a\r
+ * copy of this software and associated documentation files (the "Software"),\r
+ * to deal in the Software without restriction, including without limitation\r
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
+ * and/or sell copies of the Software, and to permit persons to whom the\r
+ * Software is furnished to do so, subject to the following conditions:\r
+ * \r
+ * The above copyright notice and this permission notice shall be included\r
+ * in all copies or substantial portions of the Software.\r
+ * \r
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
+ */\r
+\r
+/*\r
+ * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
+ *\r
+ * Copyright (C) 2002 - Borca Daniel\r
+ * Email : dborca@yahoo.com\r
+ * Web : http://www.geocities.com/dborca\r
+ */\r
+\r
+\r
+#ifndef VGA_H_included\r
+#define VGA_H_included\r
+\r
+#include "internal.h"\r
+#include "vesa.h"\r
+\r
+extern vl_driver VGA;\r
+\r
+#endif\r
+++ /dev/null
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.1\r
- * \r
- * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include <pc.h>\r
-#include <stdlib.h>\r
-\r
-#include "vga.h"\r
-\r
-\r
-\r
-static vl_mode modes[4] = {\r
- {0x13 | 0x4000, 320, 200, 320, 8, -1, 320*200},\r
- {0xffff, -1, -1, -1, -1, -1, -1}\r
-};\r
-\r
-static word16 vga_ver;\r
-static int linear_selector;\r
-static int oldmode = -1;\r
-\r
-#define vga_color_precision 6\r
-\r
-\r
-\r
-/* Desc: Attempts to detect VGA, check video modes and create selectors.\r
- *\r
- * In : -\r
- * Out : mode array\r
- *\r
- * Note: -\r
- */\r
-static vl_mode *vga_init (void)\r
-{\r
- int rv = 0;\r
-\r
- if (vga_ver) {\r
- return modes;\r
- }\r
-\r
- __asm("\n\\r
- movw $0x1a00, %%ax \n\\r
- int $0x10 \n\\r
- cmpb $0x1a, %%al \n\\r
- jne 0f \n\\r
- cmpb $0x07, %%bl \n\\r
- jb 0f \n\\r
- andl $0xff, %%ebx \n\\r
- movl %%ebx, %0 \n\\r
- 0:":"=g"(rv)::"%eax", "%ebx");\r
- if (rv == 0) {\r
- return NULL;\r
- }\r
-\r
- if (_create_selector(&linear_selector, 0xa0000, 0x10000)) {\r
- return NULL;\r
- }\r
-\r
- modes[0].sel = linear_selector;\r
-\r
- vga_ver = rv;\r
- return modes;\r
-}\r
-\r
-\r
-\r
-/* Desc: Frees all resources allocated by VGA init code.\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-static void vga_finit (void)\r
-{\r
- if (vga_ver) {\r
- _remove_selector(&linear_selector);\r
- }\r
-}\r
-\r
-\r
-\r
-/* Desc: Attempts to enter specified video mode.\r
- *\r
- * In : ptr to mode structure, refresh rate\r
- * Out : 0 if success\r
- *\r
- * Note: -\r
- */\r
-static int vga_entermode (vl_mode *p, int refresh)\r
-{\r
- if (!(p->mode & 0x4000)) {\r
- return -1;\r
- }\r
- VGA.blit = vl_can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;\r
-\r
- if (oldmode == -1) {\r
- __asm("\n\\r
- movb $0x0f, %%ah \n\\r
- int $0x10 \n\\r
- andl $0xff, %%eax \n\\r
- movl %%eax, %0 \n\\r
- ":"=g"(oldmode)::"%eax", "%ebx");\r
- }\r
-\r
- __asm("int $0x10"::"a"(p->mode&0xff));\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* Desc: Restores to the mode prior to first call to vga_entermode.\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-static void vga_restore (void)\r
-{\r
- if (oldmode != -1) {\r
- __asm("int $0x10"::"a"(oldmode));\r
- }\r
-}\r
-\r
-\r
-\r
-/* Desc: set one palette entry\r
- *\r
- * In : color index, R, G, B\r
- * Out : -\r
- *\r
- * Note: uses integer values\r
- */\r
-static void vga_setCI_i (int index, int red, int green, int blue)\r
-{\r
-#if 0\r
- __asm("\n\\r
- movw $0x1010, %%ax \n\\r
- movb %1, %%dh \n\\r
- movb %2, %%ch \n\\r
- int $0x10 \n\\r
- "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");\r
-#else\r
- outportb(0x03C8, index);\r
- outportb(0x03C9, red);\r
- outportb(0x03C9, green);\r
- outportb(0x03C9, blue);\r
-#endif\r
-}\r
-\r
-\r
-\r
-/* Desc: set one palette entry\r
- *\r
- * In : color index, R, G, B\r
- * Out : -\r
- *\r
- * Note: uses normalized values\r
- */\r
-static void vga_setCI_f (int index, float red, float green, float blue)\r
-{\r
- float max = (1 << vga_color_precision) - 1;\r
-\r
- vga_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));\r
-}\r
-\r
-\r
-\r
-/* Desc: retrieve CI precision\r
- *\r
- * In : -\r
- * Out : precision in bits\r
- *\r
- * Note: -\r
- */\r
-static int vga_getCIprec (void)\r
-{\r
- return vga_color_precision;\r
-}\r
-\r
-\r
-\r
-/*\r
- * the driver\r
- */\r
-vl_driver VGA = {\r
- vga_init,\r
- vga_entermode,\r
- NULL,\r
- vga_setCI_f,\r
- vga_setCI_i,\r
- vga_getCIprec,\r
- vga_restore,\r
- vga_finit\r
-};\r
+++ /dev/null
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.0\r
- * \r
- * Copyright (C) 1999 Brian Paul All Rights Reserved.\r
- * \r
- * Permission is hereby granted, free of charge, to any person obtaining a\r
- * copy of this software and associated documentation files (the "Software"),\r
- * to deal in the Software without restriction, including without limitation\r
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,\r
- * and/or sell copies of the Software, and to permit persons to whom the\r
- * Software is furnished to do so, subject to the following conditions:\r
- * \r
- * The above copyright notice and this permission notice shall be included\r
- * in all copies or substantial portions of the Software.\r
- * \r
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS\r
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL\r
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN\r
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP device driver v1.3 for Mesa 5.0\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#ifndef VGA_H_included\r
-#define VGA_H_included\r
-\r
-#include "../internal.h"\r
-#include "../vesa/vesa.h"\r
-\r
-extern vl_driver VGA;\r
-\r
-#endif\r
\r
#include <stdlib.h>\r
\r
-#include "video.h"\r
#include "internal.h"\r
-#include "vesa/vesa.h"\r
-#include "vga/vga.h"\r
+#include "vesa.h"\r
+#include "vga.h"\r
+#include "video.h"\r
\r
\r
\r
\r
/* lookup table for scaling 5 bit colors up to 8 bits */\r
static int _rgb_scale_5[32] = {\r
- 0, 8, 16, 24, 32, 41, 49, 57,\r
- 65, 74, 82, 90, 98, 106, 115, 123,\r
- 131, 139, 148, 156, 164, 172, 180, 189,\r
- 197, 205, 213, 222, 230, 238, 246, 255\r
+ 0, 8, 16, 25, 33, 41, 49, 58,\r
+ 66, 74, 82, 90, 99, 107, 115, 123,\r
+ 132, 140, 148, 156, 165, 173, 181, 189,\r
+ 197, 206, 214, 222, 230, 239, 247, 255\r
};\r
\r
/* lookup table for scaling 6 bit colors up to 8 bits */\r
static int _rgb_scale_6[64] = {\r
0, 4, 8, 12, 16, 20, 24, 28,\r
- 32, 36, 40, 44, 48, 52, 56, 60,\r
- 64, 68, 72, 76, 80, 85, 89, 93,\r
+ 32, 36, 40, 45, 49, 53, 57, 61,\r
+ 65, 69, 73, 77, 81, 85, 89, 93,\r
97, 101, 105, 109, 113, 117, 121, 125,\r
- 129, 133, 137, 141, 145, 149, 153, 157,\r
- 161, 165, 170, 174, 178, 182, 186, 190,\r
- 194, 198, 202, 206, 210, 214, 218, 222,\r
- 226, 230, 234, 238, 242, 246, 250, 255\r
+ 130, 134, 138, 142, 146, 150, 154, 158,\r
+ 162, 166, 170, 174, 178, 182, 186, 190,\r
+ 194, 198, 202, 206, 210, 215, 219, 223,\r
+ 227, 231, 235, 239, 243, 247, 251, 255\r
};\r
\r
/* FakeColor data */\r
\r
\r
\r
-/* Desc: get screen geometry\r
+/* Desc: state retrieval\r
*\r
- * In : ptr to WIDTH, ptr to HEIGHT\r
+ * In : name, storage\r
* Out : -\r
*\r
* Note: -\r
*/\r
-void vl_get_screen_size (int *width, int *height)\r
+int vl_get (int pname, int *params)\r
{\r
- *width = video_mode->xres;\r
- *height = video_mode->yres;\r
-}\r
-\r
-\r
-\r
-/* Desc: retrieve CPU MMX capability\r
- *\r
- * In : -\r
- * Out : FALSE if CPU cannot do MMX\r
- *\r
- * Note: -\r
- */\r
-int vl_can_mmx (void)\r
-{\r
-#ifdef USE_MMX_ASM\r
- extern int _mesa_identify_x86_cpu_features (void);\r
- return (_mesa_identify_x86_cpu_features() & 0x00800000);\r
-#else\r
+ switch (pname) {\r
+ case VL_GET_SCREEN_SIZE:\r
+ params[0] = video_mode->xres;\r
+ params[1] = video_mode->yres;\r
+ break;\r
+ default:\r
+ return drv->get(pname, params);\r
+ }\r
return 0;\r
-#endif\r
}\r
\r
\r
vl_mixfix = vl_mixfix##bpp; \\r
vl_mixrgb = vl_mixrgb##bpp; \\r
vl_mixrgba = vl_mixrgba##bpp; \\r
- vl_clear = vl_can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp\r
+ vl_clear = _can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp\r
\r
switch (p->bpp) {\r
case 8:\r
void vl_video_exit (void)\r
{\r
drv->restore();\r
- drv->finit();\r
+ drv->fini();\r
}\r
\r
\r
if ((vl_setup_mode(p) == 0) && (drv->entermode(p, refresh) == 0)) {\r
vl_flip = drv->blit;\r
if (fake) {\r
- min = drv->getCIprec();\r
+ drv->get(VL_GET_CI_PREC, (int *)(&min));\r
fake_buildpalette(min);\r
if (min == 8) {\r
vl_getrgba = v_getrgba8fake8;\r
\r
typedef int fixed;\r
\r
+#define VL_GET_CARD_NAME 0x0100\r
+#define VL_GET_VRAM 0x0101\r
+#define VL_GET_CI_PREC 0x0200\r
+#define VL_GET_HPIXELS 0x0201\r
+#define VL_GET_SCREEN_SIZE 0x0202\r
+\r
extern int (*vl_mixfix) (fixed r, fixed g, fixed b);\r
extern int (*vl_mixrgb) (const unsigned char rgb[]);\r
extern int (*vl_mixrgba) (const unsigned char rgba[]);\r
void vl_setCI (int index, float red, float green, float blue);\r
\r
int vl_sync_buffer (void **buffer, int x, int y, int width, int height);\r
-void vl_get_screen_size (int *width, int *height);\r
+int vl_get (int pname, int *params);\r
\r
void vl_video_exit (void);\r
int vl_video_init (int width, int height, int bpp, int rgb, int refresh);\r
.global _v_clear8_mmx\r
_v_clear8_mmx:\r
#ifdef USE_MMX_ASM\r
- movq 4(%esp), %mm0\r
+ movd 4(%esp), %mm0\r
punpcklbw %mm0, %mm0\r
punpcklwd %mm0, %mm0\r
jmp _v_clear_common_mmx\r
.global _v_clear16_mmx\r
_v_clear16_mmx:\r
#ifdef USE_MMX_ASM\r
- movq 4(%esp), %mm0\r
+ movd 4(%esp), %mm0\r
punpcklwd %mm0, %mm0\r
jmp _v_clear_common_mmx\r
#endif\r
.global _v_clear32_mmx\r
_v_clear32_mmx:\r
#ifdef USE_MMX_ASM\r
- movq 4(%esp), %mm0\r
+ movd 4(%esp), %mm0\r
.balign 4\r
_v_clear_common_mmx:\r
punpckldq %mm0, %mm0\r
# As a consequence, you'll need the DJGPP Glide3\r
# library to build any application.\r
# default = no\r
+# MATROX=1 build for Matrox Millennium I (MGA2064W) cards.\r
+# This is experimental and not intensively tested.\r
+# default = no\r
# HAVE_X86=1 optimize for i386.\r
# default = no\r
# HAVE_MMX=1 allow MMX specializations, provided your assembler\r
\r
CC = gcc\r
CFLAGS += -I$(TOP)/include -I.\r
-ifdef FX\r
-CFLAGS += -D__DOS__ -I$(GLIDE) -DFX -DFX_GLIDE3 -DFXMESA_USE_ARGB\r
+ifeq ($(FX),1)\r
+CFLAGS += -D__DOS__ -DH3\r
+CFLAGS += -I$(GLIDE) -DFX -DFX_GLIDE3 -DFXMESA_USE_ARGB\r
+LIBNAME = "MesaGL/FX DJGPP"\r
+else\r
+ifeq ($(MATROX),1)\r
+CFLAGS += -DMATROX\r
+LIBNAME = "MesaGL/MGA DJGPP"\r
+else\r
+LIBNAME = "MesaGL DJGPP"\r
+endif\r
endif\r
\r
AR = ar\r
X86/3dnow_xform4.S \\r
X86/3dnow_normal.S\r
\r
-ifdef HAVE_MMX\r
+ifeq ($(HAVE_MMX),1)\r
X86_SOURCES += $(MMX_SOURCES)\r
CFLAGS += -DUSE_MMX_ASM\r
HAVE_X86 = 1\r
endif\r
-ifdef HAVE_SSE\r
+ifeq ($(HAVE_SSE),1)\r
X86_SOURCES += $(SSE_SOURCES)\r
CFLAGS += -DUSE_SSE_ASM\r
HAVE_X86 = 1\r
endif\r
-ifdef HAVE_3DNOW\r
+ifeq ($(HAVE_3DNOW),1)\r
X86_SOURCES += $(K3D_SOURCES)\r
CFLAGS += -DUSE_3DNOW_ASM\r
HAVE_X86 = 1\r
endif\r
-ifdef HAVE_X86\r
+ifeq ($(HAVE_X86),1)\r
CFLAGS += -DUSE_X86_ASM\r
else\r
X86_SOURCES =\r
\r
DRIVER_SOURCES = \\r
DOS/dmesa.c\r
-ifndef FX\r
-DRIVER_SOURCES += \\r
- DOS/video.c \\r
- DOS/virtual.S \\r
- DOS/vesa/vesa.c \\r
- DOS/vesa/blit.S \\r
- DOS/vga/vga.c \\r
- DOS/dpmi.c\r
-else\r
+ifeq ($(FX),1)\r
DRIVER_SOURCES += \\r
FX/fxapi.c \\r
FX/fxdd.c \\r
FX/fxtris.c \\r
FX/fxvb.c \\r
FX/fxglidew.c\r
+else\r
+ifeq ($(MATROX),1)\r
+DRIVER_SOURCES += \\r
+ DOS/mga/mga.c \\r
+ DOS/mga/mga_hw.c \\r
+ DOS/mga/mga_mode.c \\r
+ DOS/dpmi.c\r
+else\r
+DRIVER_SOURCES += \\r
+ DOS/video.c \\r
+ DOS/virtual.S \\r
+ DOS/vesa.c \\r
+ DOS/blit.S \\r
+ DOS/vga.c \\r
+ DOS/dpmi.c\r
+endif\r
endif\r
\r
SOURCES = $(CORE_SOURCES) $(X86_SOURCES) $(DRIVER_SOURCES)\r
$(warning Missing DXE3GEN and/or DXE3.LD! You must have DXE3GEN)\r
$(warning somewhere in PATH, and DXE3.LD in DJGPP/LIB directory.)\r
else\r
-ifdef FX\r
- -dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D "MesaGL/FX DJGPP" -E _gl -E _DMesa -P glid3.dxe -U $(OBJECTS)\r
+ifeq ($(FX),1)\r
+ -dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D $(LIBNAME) -E _gl -E _DMesa -P glid3.dxe -U $(OBJECTS)\r
else\r
- -dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D "MesaGL DJGPP" -E _gl -E _DMesa -U $(OBJECTS)\r
+ -dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D $(LIBNAME) -E _gl -E _DMesa -U $(OBJECTS)\r
endif\r
endif\r
\r
-$(RM) $(subst /,\,tnl/*.o)\r
-$(RM) $(subst /,\,X86/*.o)\r
-$(RM) $(subst /,\,DOS/*.o)\r
- -$(RM) $(subst /,\,DOS/vesa/*.o)\r
- -$(RM) $(subst /,\,DOS/vga/*.o)\r
+ -$(RM) $(subst /,\,DOS/mga/*.o)\r
-$(RM) $(subst /,\,FX/*.o)\r
\r
-include depend\r