latest DOS updates (Daniel Borca)

This commit is contained in:
Brian Paul 2003-02-20 15:43:52 +00:00
parent 449e47f06a
commit 60f84fcc91
28 changed files with 4238 additions and 279 deletions

View file

@ -32,8 +32,9 @@ Available options:
Environment variables:
CPU optimize for the given processor.
default = k6
SGI_GLU=1 build SGI's GLU instead of Mesa's.
default = no
GLU=[src|si] specify GLU directory; can be `src' (src-glu = Mesa)
or `si' (si-glu = SGI's GLU -- requires GNU/C++).
default = src
GLIDE path to Glide3 SDK include files; used with FX.
default = $(TOP)/include/glide3
FX=1 build for 3dfx Glide3. Note that this disables
@ -41,6 +42,9 @@ Available options:
As a consequence, you'll need the DJGPP Glide3
library to build any application.
default = no
MATROX=1 build for Matrox Millennium I (MGA2064W) cards.
This is experimental and not intensively tested.
default = no
HAVE_X86=1 optimize for i386.
default = no
HAVE_MMX=1 allow MMX specializations, provided your assembler
@ -81,6 +85,15 @@ FAQ:
A) You need LFN support.
A) When compiling for Glide (FX=1), pay attention to Glide path.
Q) Libraries built OK, but linker complains about `vsnprintf' every time I
compile some demo.
A) Upgrade to DJGPP 2.04.
A) Add `vsnprintf.c' to the CORE_SOURCES in `src/Makefile.DJ' (untested!).
A) The following hack should be safe in 90% of the cases, but if anything
goes wrong, don't come back to me crying. Anyway, patch `src/imports.c'
with the following line:
#define vsnprintf(buf, max, fmt, arg) vsprintf(buf, fmt, arg)
2. Dynamic modules
Q) What are you mumbling about dynamic modules?
@ -103,9 +116,10 @@ FAQ:
3. Using Mesa for DJGPP
Q) DMesa is so SLOOOW! The Win32 OpenGL performs so much better...
A) Is that a question? If you have a Voodoo3/Banshee card, you're lucky. The
Glide port is on my web page. If you haven't, sorry; everything is done
in software. Suggestions?
A) Is that a question? If you have a Voodoo3/Banshee card, you're lucky (the
Glide port is on my web page). If you have a Matrox Millennium I card,
you just MIGHT be lucky... If you haven't, sorry; everything is done in
software. Suggestions?
Q) I tried to set refresh rate w/ DMesa, but without success.
A) Refresh rate control works only for VESA 3.0. If you were compiling for
@ -113,15 +127,12 @@ FAQ:
Q) I made a simple application and it does nothing. It exits right away. Not
even a blank screen.
A) Only DMesa+FX supports single-buffered. The standard VESA/VGA drivers
will always work in double-buffered modes. If/When I will find a way to
use *REAL* hardware acceleration for a specific card, it might or might
not support single-buffered modes.
A) The pure software drivers (VESA/VGA) support only double-buffered modes.
A) Another weird "feature" is that buffer width must be multiple of 8 (I'm a
lazy programmer and I found that the easiest way to keep buffer handling
at peak performance ;-).
Q) My demo doesn't display text. I know I used the glut font routines!
Q) My demo doesn't display text. I know I used the GLUT font routines!
A) Then you probably use GLUT as a DXE. Well, there is no direct access to
variables due to the way DXE works. Read the documentation. The author of
GLUT took this into account for _WIN32 DLL's only; I don't want to modify
@ -196,15 +207,17 @@ v1.2 (nov-2002)
* synced w/ Mesa-4.1
- removed dmesadxe.h
v1.3 (jan-2003)
v1.3 (feb-2003)
+ enabled OpenGL 1.4 support
+ added MMX clear/blit routines
+ enabled SGI's GLU compilation
+ added samples makefile
+ added new GLUT functions
+ added color-index modes
+ added Matrox Millennium MGA2064W driver
+ added 8bit FakeColor (thanks to Neil Funk)
+ added VGA support (to keep Ben Decker happy)
* fixed GLUT compilation error (reported by Chan Kar Heng)
! fixed GLUT compilation error (reported by Chan Kar Heng)
* overhauled virtual buffer and internal video drivers
* better fxMesa integration
* revamped GLUT

View file

@ -87,6 +87,11 @@ DMesaContext DMesaCreateContext (DMesaVisual visual, DMesaContext share);
*/
void DMesaDestroyContext (DMesaContext c);
/*
* Return a handle to the current context.
*/
DMesaContext DMesaGetCurrentContext (void);
/*
@ -101,21 +106,17 @@ DMesaBuffer DMesaCreateBuffer (DMesaVisual visual,
*/
void DMesaDestroyBuffer (DMesaBuffer b);
/*
* Bind Buffer to Context and make the Context the current one.
*/
GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b);
/*
* Swap the front and back buffers for the given Buffer.
* No action is taken if the buffer is not double buffered.
*/
void DMesaSwapBuffers (DMesaBuffer b);
/*
* Bind Buffer to Context and make the Context the current one.
*/
GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b);
/*
@ -132,10 +133,12 @@ void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue);
/*
* DMesa state retrieval.
*/
#define DMESA_Y_ORIGIN 0x0100
#define DMESA_SCREEN_SIZE 0x0101
#define DMESA_ARGB_ORDER 0x0200
void DMesaGetIntegerv (GLenum pname, GLint *params);
#define DMESA_GET_SCREEN_SIZE 0x0100
#define DMESA_GET_DRIVER_CAPS 0x0200
#define DMESA_DRIVER_SWDB_BIT 0x1 /* software double-buffered */
#define DMESA_DRIVER_LLWO_BIT 0x2 /* lower-left window origin */
int DMesaGetIntegerv (GLenum pname, GLint *params);
#ifdef __cplusplus
}

View file

@ -65,16 +65,12 @@ CFLAGS += -I$(TOP)/include
LDFLAGS = -s -L$(TOP)/lib
ifdef DXE
ifeq ($(DXE),1)
DMESADXE = $(TOP)/lib/dmesadxe.o
LDLIBS += -liglut -liglu -ligl
ifdef FX
LDFLAGS += -L$(GLIDE)
endif
LDLIBS += -ldl
LDLIBS += -liglut -liglu -ligl -ldl
else
LDLIBS = -lglut -lglu -lgl
ifdef FX
ifeq ($(FX),1)
LDFLAGS += -L$(GLIDE)
LDLIBS += -lglid3
endif

View file

@ -105,6 +105,9 @@ extern GLboolean g_redisplay;
extern GLuint g_bpp; /* HW: bits per pixel */
extern GLuint g_refresh; /* HW: vertical refresh rate */
extern GLuint g_screen_w, g_screen_h; /* HW: physical screen size */
extern GLint g_driver_caps;
extern GLuint g_fps;
extern GLuint g_display_mode; /* display bits */
extern int g_init_x, g_init_y; /* initial window position */
@ -132,7 +135,7 @@ extern void __glutFatalUsage(char *format,...);
#define MAX_WINDOWS 2
#define MAX_WINDOWS 2
#define DEFAULT_WIDTH 300
#define DEFAULT_HEIGHT 300

View file

@ -38,6 +38,9 @@ GLboolean g_redisplay = GL_FALSE;
GLuint g_bpp = DEFAULT_BPP;
GLuint g_refresh = 0;
GLuint g_screen_w, g_screen_h;
GLint g_driver_caps;
GLuint g_fps = 0;
GLuint g_display_mode = 0;
int g_init_x = 0, g_init_y = 0;
@ -68,6 +71,13 @@ void APIENTRY glutInit (int *argc, char **argv)
}
__glutProgramName = __glutStrdup(str);
/* check if GLUT_FPS env var is set */
if ((env = getenv("GLUT_FPS")) != NULL) {
if ((g_fps = atoi(env)) <= 0) {
g_fps = 5000; /* 5000 milliseconds */
}
}
/* Initialize timer */
glutGet(GLUT_ELAPSED_TIME);
}
@ -106,9 +116,10 @@ void APIENTRY glutMainLoop (void)
{
GLint screen_size[2];
DMesaGetIntegerv(DMESA_SCREEN_SIZE, screen_size);
DMesaGetIntegerv(DMESA_GET_SCREEN_SIZE, screen_size);
g_screen_w = screen_size[0];
g_screen_h = screen_size[1];
DMesaGetIntegerv(DMESA_GET_DRIVER_CAPS, &g_driver_caps);
}
pc_install_keyb();

View file

@ -39,19 +39,7 @@ int g_mouse_x = 0, g_mouse_y = 0;
void __glutInitMouse (void)
{
if ((g_mouse = pc_install_mouse())) {
GLint yorg;
GLint rect[4];
DMesaGetIntegerv(DMESA_Y_ORIGIN, &yorg);
if (yorg) {
rect[1] = g_screen_h - g_curwin->height;
} else {
rect[1] = g_curwin->ypos;
}
rect[0] = g_curwin->xpos;
rect[2] = rect[0] + g_curwin->width - 1;
rect[3] = rect[1] + g_curwin->height - 1;
pc_mouse_area(rect[0], rect[1], rect[2], rect[3]);
pc_mouse_area(g_curwin->xpos, g_curwin->ypos, g_curwin->xpos + g_curwin->width - 1, g_curwin->ypos + g_curwin->height - 1);
g_curwin->show_mouse = (g_curwin->mouse || g_curwin->motion || g_curwin->passive);
}

View file

@ -27,12 +27,15 @@
*/
#include <stdio.h>
#include "glutint.h"
#include "GL/dmesa.h"
GLUTwindow *g_curwin;
static GLuint swaptime, swapcount;
static DMesaVisual visual = NULL;
static DMesaContext context = NULL;
@ -59,7 +62,6 @@ static void clean (void)
int APIENTRY glutCreateWindow (const char *title)
{
int i;
GLint screen_size[2];
int m8width = (g_init_w + 7) & ~7;
if (!visual) {
@ -154,6 +156,20 @@ void APIENTRY glutSwapBuffers (void)
} else {
DMesaSwapBuffers(g_curwin->buffer);
}
if (g_fps) {
GLint t = glutGet(GLUT_ELAPSED_TIME);
swapcount++;
if (swaptime == 0)
swaptime = t;
else if (t - swaptime > g_fps) {
double time = 0.001 * (t - swaptime);
double fps = (double)swapcount / time;
fprintf(stderr, "GLUT: %d frames in %.2f seconds = %.2f FPS\n", swapcount, time, fps);
swaptime = t;
swapcount = 0;
}
}
}

File diff suppressed because it is too large Load diff

View file

@ -46,7 +46,7 @@
/* _create_linear_mapping:
* Maps a physical address range into linear memory.
*/
static int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)
int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)
{
__dpmi_meminfo meminfo;
@ -71,7 +71,7 @@ static int _create_linear_mapping (unsigned long *linear, unsigned long physaddr
/* _remove_linear_mapping:
* Frees the DPMI resources being used to map a linear address range.
*/
static void _remove_linear_mapping (unsigned long *linear)
void _remove_linear_mapping (unsigned long *linear)
{
__dpmi_meminfo meminfo;
@ -127,3 +127,22 @@ void _remove_selector (int *segment)
*segment = 0;
}
}
/* Desc: retrieve CPU MMX capability
*
* In : -
* Out : FALSE if CPU cannot do MMX
*
* Note: -
*/
int _can_mmx (void)
{
#ifdef USE_MMX_ASM
extern int _mesa_identify_x86_cpu_features (void);
return (_mesa_identify_x86_cpu_features() & 0x00800000);
#else
return 0;
#endif
}

View file

@ -79,9 +79,9 @@ typedef struct {
void (*blit) (void);
void (*setCI_f) (int index, float red, float green, float blue);
void (*setCI_i) (int index, int red, int green, int blue);
int (*getCIprec) (void);
int (*get) (int pname, int *params);
void (*restore) (void);
void (*finit) (void);
void (*fini) (void);
} vl_driver;
@ -89,13 +89,15 @@ typedef struct {
/*
* memory mapping
*/
int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size);
void _remove_linear_mapping (unsigned long *linear);
int _create_selector (int *segment, unsigned long base, int size);
void _remove_selector (int *segment);
/*
* system routines
*/
int vl_can_mmx (void);
int _can_mmx (void);
/*
* asm routines to deal with virtual buffering

View file

@ -0,0 +1,377 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W triangle template
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
/*
* Triangle Rasterizer Template
*
* This file is #include'd to generate custom triangle rasterizers.
*
* The following macros may be defined to indicate what auxillary information
* must be interplated across the triangle:
* INTERP_Z - if defined, interpolate Z values
* INTERP_RGB - if defined, interpolate RGB values
*
* TAG - function name
* CULL - enable culling for: 0=no, 1=back, -1=front
*
* SETUP_CODE - to be executed once per triangle (usually HW init)
*
* For flatshaded primitives, the provoking vertex is the final one.
* This code was designed for the origin to be in the upper-left corner.
*
* Inspired by triangle rasterizer code written by Brian Paul.
*/
#define TRI_SWAP(a, b) \
do { \
const MGAvertex *tmp = a; \
a = b; \
b = tmp; \
} while (0)
void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3)
{
int area;
int x1, y1, x2, y2, x3, y3;
int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy;
#ifdef INTERP_RGB
#define FIFO_CNT_RGB 3
int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db;
int drdx, drdy, dgdx, dgdy, dbdx, dbdy;
#else
#define FIFO_CNT_RGB 0
#endif
#ifdef INTERP_Z
#define FIFO_CNT_Z 1
int dzdx, dzdy;
int eMaj_dz, eBot_dz;
int z1, z2, z3;
#else
#define FIFO_CNT_Z 0
#endif
#if defined(INTERP_Z) || defined(INTERP_RGB)
double one_area;
#ifndef INTERP_RGB
int red = v3->color[0];
int green = v3->color[1];
int blue = v3->color[2];
#endif
#else
unsigned long color = mga_mixrgb_full(v3->color);
#endif
int sgn = 0;
/* sort along the vertical axis */
if (v2->win[1] < v1->win[1]) {
TRI_SWAP(v1, v2);
#ifdef CULL
cull = -cull;
#endif
}
if (v3->win[1] < v1->win[1]) {
TRI_SWAP(v1, v3);
TRI_SWAP(v2, v3);
} else if (v3->win[1] < v2->win[1]) {
TRI_SWAP(v2, v3);
#ifdef CULL
cull = -cull;
#endif
}
x1 = v1->win[0];
y1 = v1->win[1];
x2 = v2->win[0];
y2 = v2->win[1];
x3 = v3->win[0];
y3 = v3->win[1];
/* compute deltas for each edge */
eMaj_dx = x3 - x1;
eMaj_dy = y3 - y1;
eBot_dx = x2 - x1;
eBot_dy = y2 - y1;
eTop_dx = x3 - x2;
eTop_dy = y3 - y2;
/* compute area */
if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) {
return;
}
#ifdef CULL
if ((area * cull) > 0) {
return;
}
#endif
mga_select();
/* set engine state */
#ifdef SETUP_CODE
SETUP_CODE
#endif
/* draw lower triangle */
#if defined(INTERP_Z) || defined(INTERP_RGB)
one_area = (double)(1<<15) / (double)area;
mga_fifo(1);
#else
mga_fifo(2);
mga_outl(M_FCOL, color);
#endif
mga_outl(M_YDST, y1);
#ifdef INTERP_Z
z1 = v1->win[2];
z2 = v2->win[2];
z3 = v3->win[2];
/* compute d?/dx and d?/dy derivatives */
eMaj_dz = z3 - z1;
eBot_dz = z2 - z1;
dzdx = (eMaj_dz * eBot_dy - eMaj_dy * eBot_dz) * one_area;
dzdy = (eMaj_dx * eBot_dz - eMaj_dz * eBot_dx) * one_area;
#ifndef INTERP_RGB
mga_fifo(11);
mga_outl(M_DR2, dzdx);
mga_outl(M_DR3, dzdy);
mga_outl(M_DR4, red<<15);
mga_outl(M_DR6, 0);
mga_outl(M_DR7, 0);
mga_outl(M_DR8, green<<15);
mga_outl(M_DR10, 0);
mga_outl(M_DR11, 0);
mga_outl(M_DR12, blue<<15);
mga_outl(M_DR14, 0);
mga_outl(M_DR15, 0);
#else
mga_fifo(2);
mga_outl(M_DR2, dzdx);
mga_outl(M_DR3, dzdy);
#endif
#endif
#ifdef INTERP_RGB
/* compute color deltas */
eMaj_dr = v3->color[0] - v1->color[0];
eBot_dr = v2->color[0] - v1->color[0];
eMaj_dg = v3->color[1] - v1->color[1];
eBot_dg = v2->color[1] - v1->color[1];
eMaj_db = v3->color[2] - v1->color[2];
eBot_db = v2->color[2] - v1->color[2];
/* compute color increments */
drdx = (eMaj_dr * eBot_dy - eMaj_dy * eBot_dr) * one_area;
drdy = (eMaj_dx * eBot_dr - eMaj_dr * eBot_dx) * one_area;
dgdx = (eMaj_dg * eBot_dy - eMaj_dy * eBot_dg) * one_area;
dgdy = (eMaj_dx * eBot_dg - eMaj_dg * eBot_dx) * one_area;
dbdx = (eMaj_db * eBot_dy - eMaj_dy * eBot_db) * one_area;
dbdy = (eMaj_dx * eBot_db - eMaj_db * eBot_dx) * one_area;
mga_fifo(6);
mga_outl(M_DR6, drdx);
mga_outl(M_DR7, drdy);
mga_outl(M_DR10, dgdx);
mga_outl(M_DR11, dgdy);
mga_outl(M_DR14, dbdx);
mga_outl(M_DR15, dbdy);
#endif
if (area > 0) { /* major edge on the right */
if (eBot_dy) { /* have lower triangle */
mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR0, eBot_dy);
if (x2 < x1) {
mga_outl(M_AR1, eBot_dx + eBot_dy - 1);
mga_outl(M_AR2, eBot_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eBot_dx);
mga_outl(M_AR2, -eBot_dx);
}
mga_outl(M_AR6, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR5, eMaj_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eMaj_dx);
mga_outl(M_AR5, -eMaj_dx);
}
mga_outl(M_FXBNDRY, (x1<<16) | x1);
#ifdef INTERP_Z
mga_outl(M_DR0, z1<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v1->color[0]<<15);
mga_outl(M_DR8, v1->color[1]<<15);
mga_outl(M_DR12, v1->color[2]<<15);
#endif
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eBot_dy);
} else { /* no lower triangle */
mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR6, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR5, eMaj_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eMaj_dx);
mga_outl(M_AR5, -eMaj_dx);
}
mga_outl(M_FXBNDRY, (x1<<16) | x2);
#ifdef INTERP_Z
mga_outl(M_DR0, z2<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v2->color[0]<<15);
mga_outl(M_DR8, v2->color[1]<<15);
mga_outl(M_DR12, v2->color[2]<<15);
#endif
}
/* draw upper triangle */
if (eTop_dy) {
mga_fifo(5);
mga_outl(M_AR0, eTop_dy);
if (x3 < x2) {
mga_outl(M_AR1, eTop_dx + eTop_dy - 1);
mga_outl(M_AR2, eTop_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eTop_dx);
mga_outl(M_AR2, -eTop_dx);
sgn &= ~M_SDXL;
}
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eTop_dy);
}
} else { /* major edge on the left */
if (eBot_dy) { /* have lower triangle */
mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR0, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR2, eMaj_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eMaj_dx);
mga_outl(M_AR2, -eMaj_dx);
}
mga_outl(M_AR6, eBot_dy);
if (x2 < x1) {
mga_outl(M_AR4, eBot_dx + eBot_dy - 1);
mga_outl(M_AR5, eBot_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eBot_dx);
mga_outl(M_AR5, -eBot_dx);
}
mga_outl(M_FXBNDRY, (x1<<16) | x1);
#ifdef INTERP_Z
mga_outl(M_DR0, z1<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v1->color[0]<<15);
mga_outl(M_DR8, v1->color[1]<<15);
mga_outl(M_DR12, v1->color[2]<<15);
#endif
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eBot_dy);
} else { /* no lower triangle */
mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR0, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR2, eMaj_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eMaj_dx);
mga_outl(M_AR2, -eMaj_dx);
}
mga_outl(M_FXBNDRY, (x2<<16) | x1);
#ifdef INTERP_Z
mga_outl(M_DR0, z1<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v1->color[0]<<15);
mga_outl(M_DR8, v1->color[1]<<15);
mga_outl(M_DR12, v1->color[2]<<15);
#endif
}
/* draw upper triangle */
if (eTop_dy) {
mga_fifo(5);
mga_outl(M_AR6, eTop_dy);
if (x3 < x2) {
mga_outl(M_AR4, eTop_dx + eTop_dy - 1);
mga_outl(M_AR5, eTop_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eTop_dx);
mga_outl(M_AR5, -eTop_dx);
sgn &= ~M_SDXR;
}
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eTop_dy);
}
}
}
#undef FIFO_CNT_RGB
#undef FIFO_CNT_Z
#undef TRI_SWAP
#undef SETUP_CODE
#undef INTERP_RGB
#undef INTERP_Z
#undef CULL
#undef TAG

View file

@ -0,0 +1,375 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W triangle template
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
/*
* Triangle Rasterizer Template
*
* This file is #include'd to generate custom triangle rasterizers.
*
* The following macros may be defined to indicate what auxillary information
* must be interplated across the triangle:
* INTERP_Z - if defined, interpolate Z values
* INTERP_RGB - if defined, interpolate RGB values
*
* TAG - function name
* CULL - enable culling for: 0=no, 1=back, -1=front
*
* SETUP_CODE - to be executed once per triangle (usually HW init)
*
* For flatshaded primitives, the provoking vertex is the final one.
* This code was designed for the origin to be in the upper-left corner.
*
* Inspired by triangle rasterizer code written by Brian Paul.
*/
#define TRI_SWAP(a, b) \
do { \
const MGAvertex *tmp = a; \
a = b; \
b = tmp; \
} while (0)
void TAG (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3)
{
int area;
int x1, y1, x2, y2, x3, y3;
int eMaj_dx, eMaj_dy, eBot_dx, eBot_dy, eTop_dx, eTop_dy;
#ifdef INTERP_RGB
#define FIFO_CNT_RGB 3
int eMaj_dr, eBot_dr, eMaj_dg, eBot_dg, eMaj_db, eBot_db;
int drdx, drdy, dgdx, dgdy, dbdx, dbdy;
#else
#define FIFO_CNT_RGB 0
#endif
#ifdef INTERP_Z
#define FIFO_CNT_Z 1
int dzdx, dzdy;
int eMaj_dz, eBot_dz;
int z1, z2, z3;
#else
#define FIFO_CNT_Z 0
#endif
#if defined(INTERP_Z) || defined(INTERP_RGB)
#ifndef INTERP_RGB
int red = v3->color[0];
int green = v3->color[1];
int blue = v3->color[2];
#endif
#else
unsigned long color = mga_mixrgb_full(v3->color);
#endif
int sgn = 0;
/* sort along the vertical axis */
if (v2->win[1] < v1->win[1]) {
TRI_SWAP(v1, v2);
#ifdef CULL
cull = -cull;
#endif
}
if (v3->win[1] < v1->win[1]) {
TRI_SWAP(v1, v3);
TRI_SWAP(v2, v3);
} else if (v3->win[1] < v2->win[1]) {
TRI_SWAP(v2, v3);
#ifdef CULL
cull = -cull;
#endif
}
x1 = v1->win[0];
y1 = v1->win[1];
x2 = v2->win[0];
y2 = v2->win[1];
x3 = v3->win[0];
y3 = v3->win[1];
/* compute deltas for each edge */
eMaj_dx = x3 - x1;
eMaj_dy = y3 - y1;
eBot_dx = x2 - x1;
eBot_dy = y2 - y1;
eTop_dx = x3 - x2;
eTop_dy = y3 - y2;
/* compute area */
if ((area = eMaj_dx * eBot_dy - eBot_dx * eMaj_dy) == 0) {
return;
}
#ifdef CULL
if ((area * cull) > 0) {
return;
}
#endif
mga_select();
/* set engine state */
#ifdef SETUP_CODE
SETUP_CODE
#endif
/* draw lower triangle */
#if defined(INTERP_Z) || defined(INTERP_RGB)
mga_fifo(1);
#else
mga_fifo(2);
mga_outl(M_FCOL, color);
#endif
mga_outl(M_YDST, y1);
#ifdef INTERP_Z
z1 = v1->win[2];
z2 = v2->win[2];
z3 = v3->win[2];
/* compute d?/dx and d?/dy derivatives */
eMaj_dz = z3 - z1;
eBot_dz = z2 - z1;
dzdx = ((long long)(eMaj_dz * eBot_dy - eMaj_dy * eBot_dz)<<15) / area;
dzdy = ((long long)(eMaj_dx * eBot_dz - eMaj_dz * eBot_dx)<<15) / area;
#ifndef INTERP_RGB
mga_fifo(11);
mga_outl(M_DR2, dzdx);
mga_outl(M_DR3, dzdy);
mga_outl(M_DR4, red<<15);
mga_outl(M_DR6, 0);
mga_outl(M_DR7, 0);
mga_outl(M_DR8, green<<15);
mga_outl(M_DR10, 0);
mga_outl(M_DR11, 0);
mga_outl(M_DR12, blue<<15);
mga_outl(M_DR14, 0);
mga_outl(M_DR15, 0);
#else
mga_fifo(2);
mga_outl(M_DR2, dzdx);
mga_outl(M_DR3, dzdy);
#endif
#endif
#ifdef INTERP_RGB
/* compute color deltas */
eMaj_dr = v3->color[0] - v1->color[0];
eBot_dr = v2->color[0] - v1->color[0];
eMaj_dg = v3->color[1] - v1->color[1];
eBot_dg = v2->color[1] - v1->color[1];
eMaj_db = v3->color[2] - v1->color[2];
eBot_db = v2->color[2] - v1->color[2];
/* compute color increments */
drdx = ((long long)(eMaj_dr * eBot_dy - eMaj_dy * eBot_dr)<<15) / area;
drdy = ((long long)(eMaj_dx * eBot_dr - eMaj_dr * eBot_dx)<<15) / area;
dgdx = ((long long)(eMaj_dg * eBot_dy - eMaj_dy * eBot_dg)<<15) / area;
dgdy = ((long long)(eMaj_dx * eBot_dg - eMaj_dg * eBot_dx)<<15) / area;
dbdx = ((long long)(eMaj_db * eBot_dy - eMaj_dy * eBot_db)<<15) / area;
dbdy = ((long long)(eMaj_dx * eBot_db - eMaj_db * eBot_dx)<<15) / area;
mga_fifo(6);
mga_outl(M_DR6, drdx);
mga_outl(M_DR7, drdy);
mga_outl(M_DR10, dgdx);
mga_outl(M_DR11, dgdy);
mga_outl(M_DR14, dbdx);
mga_outl(M_DR15, dbdy);
#endif
if (area > 0) { /* major edge on the right */
if (eBot_dy) { /* have lower triangle */
mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR0, eBot_dy);
if (x2 < x1) {
mga_outl(M_AR1, eBot_dx + eBot_dy - 1);
mga_outl(M_AR2, eBot_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eBot_dx);
mga_outl(M_AR2, -eBot_dx);
}
mga_outl(M_AR6, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR5, eMaj_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eMaj_dx);
mga_outl(M_AR5, -eMaj_dx);
}
mga_outl(M_FXBNDRY, (x1<<16) | x1);
#ifdef INTERP_Z
mga_outl(M_DR0, z1<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v1->color[0]<<15);
mga_outl(M_DR8, v1->color[1]<<15);
mga_outl(M_DR12, v1->color[2]<<15);
#endif
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eBot_dy);
} else { /* no lower triangle */
mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR6, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR4, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR5, eMaj_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eMaj_dx);
mga_outl(M_AR5, -eMaj_dx);
}
mga_outl(M_FXBNDRY, (x1<<16) | x2);
#ifdef INTERP_Z
mga_outl(M_DR0, z2<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v2->color[0]<<15);
mga_outl(M_DR8, v2->color[1]<<15);
mga_outl(M_DR12, v2->color[2]<<15);
#endif
}
/* draw upper triangle */
if (eTop_dy) {
mga_fifo(5);
mga_outl(M_AR0, eTop_dy);
if (x3 < x2) {
mga_outl(M_AR1, eTop_dx + eTop_dy - 1);
mga_outl(M_AR2, eTop_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eTop_dx);
mga_outl(M_AR2, -eTop_dx);
sgn &= ~M_SDXL;
}
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eTop_dy);
}
} else { /* major edge on the left */
if (eBot_dy) { /* have lower triangle */
mga_fifo(9 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR0, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR2, eMaj_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eMaj_dx);
mga_outl(M_AR2, -eMaj_dx);
}
mga_outl(M_AR6, eBot_dy);
if (x2 < x1) {
mga_outl(M_AR4, eBot_dx + eBot_dy - 1);
mga_outl(M_AR5, eBot_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eBot_dx);
mga_outl(M_AR5, -eBot_dx);
}
mga_outl(M_FXBNDRY, (x1<<16) | x1);
#ifdef INTERP_Z
mga_outl(M_DR0, z1<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v1->color[0]<<15);
mga_outl(M_DR8, v1->color[1]<<15);
mga_outl(M_DR12, v1->color[2]<<15);
#endif
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eBot_dy);
} else { /* no lower triangle */
mga_fifo(4 + FIFO_CNT_Z + FIFO_CNT_RGB);
mga_outl(M_AR0, eMaj_dy);
if (x3 < x1) {
mga_outl(M_AR1, eMaj_dx + eMaj_dy - 1);
mga_outl(M_AR2, eMaj_dx);
sgn |= M_SDXL;
} else {
mga_outl(M_AR1, -eMaj_dx);
mga_outl(M_AR2, -eMaj_dx);
}
mga_outl(M_FXBNDRY, (x2<<16) | x1);
#ifdef INTERP_Z
mga_outl(M_DR0, z1<<15);
#endif
#ifdef INTERP_RGB
mga_outl(M_DR4, v1->color[0]<<15);
mga_outl(M_DR8, v1->color[1]<<15);
mga_outl(M_DR12, v1->color[2]<<15);
#endif
}
/* draw upper triangle */
if (eTop_dy) {
mga_fifo(5);
mga_outl(M_AR6, eTop_dy);
if (x3 < x2) {
mga_outl(M_AR4, eTop_dx + eTop_dy - 1);
mga_outl(M_AR5, eTop_dx);
sgn |= M_SDXR;
} else {
mga_outl(M_AR4, -eTop_dx);
mga_outl(M_AR5, -eTop_dx);
sgn &= ~M_SDXR;
}
mga_outl(M_SGN, sgn);
mga_outl(M_LEN | M_EXEC, eTop_dy);
}
}
}
#undef FIFO_CNT_RGB
#undef FIFO_CNT_Z
#undef TRI_SWAP
#undef SETUP_CODE
#undef INTERP_RGB
#undef INTERP_Z
#undef CULL
#undef TAG

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,91 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
#ifndef MGA_H_included
#define MGA_H_included
#define MGA_GET_CARD_NAME 0x0100
#define MGA_GET_VRAM 0x0101
#define MGA_GET_CI_PREC 0x0200
#define MGA_GET_HPIXELS 0x0201
#define MGA_GET_SCREEN_SIZE 0x0202
int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh);
void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z);
int mga_get (int pname, int *params);
void mga_close (int restore, int unmap);
extern void (*mga_putpixel) (unsigned int offset, int color);
extern int (*mga_getpixel) (unsigned int offset);
extern void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]);
extern int (*mga_mixrgb) (const unsigned char rgb[]);
#define MGA_BACKBUFFER !0
#define MGA_FRONTBUFFER 0
void mga_set_readbuffer (int buffer);
void mga_set_writebuffer (int buffer);
void mga_swapbuffers (int swapinterval);
unsigned short mga_getz (int offset);
void mga_setz (int offset, unsigned short z);
void mga_wait_idle (void);
/*
* vertex structure, used for primitive rendering
*/
typedef struct {
int win[4]; /* X, Y, Z, ? */
unsigned char color[4]; /* R, G, B, A */
} MGAvertex;
void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2);
void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2);
void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2);
void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2);
void mga_draw_tri_rgb_flat (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
void mga_draw_tri_rgb_flat_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
void mga_draw_tri_rgb_iter (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
void mga_draw_tri_rgb_iter_zless (int cull, const MGAvertex *v1, const MGAvertex *v2, const MGAvertex *v3);
void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color);
void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap);
void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap);
void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap);
void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap);
void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap);
void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap);
#endif

View file

@ -0,0 +1,416 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W HW mapping
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
#include <crt0.h>
#include <dpmi.h>
#include <pc.h>
#include <string.h>
#include <sys/nearptr.h>
#include <sys/segments.h>
#include "../internal.h"
#include "mga_reg.h"
#include "mga_hw.h"
/* Hack alert:
* these should really be externs
*/
/* PCI access routines */
static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle);
static unsigned long pci_read_long (int handle, int index);
static void pci_write_long (int handle, int index, unsigned long value);
/* PCI device identifiers */
#define MATROX_VENDOR_ID 0x102B
typedef enum {
MATROX_MILL_ID = 0x0519
} MATROX_ID;
static MATROX_ID matrox_id_list[] = {
MATROX_MILL_ID,
0
};
/* internal hardware data structures */
#if !MGA_FARPTR
static int dirty;
#endif
static int bus_id;
static unsigned long reg40;
static unsigned long io_mem_base[4], linear_base;
static unsigned long io_mem_size[4], linear_size;
static MATROX_ID matrox_id;
/* interface structures containing hardware pointer data */
MGA_HWPTR mgaptr;
/* Desc: create MMAP
*
* In :
* Out :
*
* Note:
*/
static int _create_mmap (__dpmi_paddr *m, unsigned long base, unsigned long size)
{
#if MGA_FARPTR
int sel;
if (_create_selector(&sel, base, size)) {
return -1;
}
m->selector = sel;
m->offset32 = 0;
#else
m->selector = _my_ds();
if (_create_linear_mapping(&m->offset32, base, size)) {
return -1;
}
m->offset32 -= __djgpp_base_address;
#endif
return 0;
}
/* Desc: destroy MMAP
*
* In :
* Out :
*
* Note:
*/
static void _destroy_mmap (__dpmi_paddr *m)
{
#if MGA_FARPTR
int sel = m->selector;
_remove_selector(&sel);
#else
m->offset32 += __djgpp_base_address;
_remove_linear_mapping(&m->offset32);
#endif
m->selector = 0;
m->offset32 = 0;
}
/* Desc: Counts amount of installed RAM
*
* In :
* Out :
*
* Note:
*/
static int _mga_get_vram (MATROX_ID chip, unsigned long base)
{
int ProbeSize = 8;
int SizeFound = 2;
unsigned char tmp;
int i;
__dpmi_paddr fb;
switch (chip) {
case MATROX_MILL_ID:
ProbeSize = 8;
break;
}
if (_create_mmap(&fb, base, ProbeSize*1024*1024)) {
return 0;
}
/* turn MGA mode on - enable linear frame buffer (CRTCEXT3) */
mga_select();
mga_outb(M_CRTC_EXT_INDEX, 3);
tmp = mga_inb(M_CRTC_EXT_DATA);
mga_outb(M_CRTC_EXT_DATA, tmp | M_MGAMODE);
/* write, read and compare method */
for (i=ProbeSize; i>2; i-= 2) {
hwptr_pokeb(fb, i*1024*1024 - 1, 0xAA);
mga_select();
mga_outb(M_CRTC_INDEX, 0); /* flush the cache */
mga_inl(M_STATUS); /* delay */
mga_inl(M_STATUS); /* delay */
mga_inl(M_STATUS); /* delay */
if (hwptr_peekb(fb, i*1024*1024 - 1) == 0xAA) {
SizeFound = i;
break;
}
}
/* restore CRTCEXT3 state */
mga_select();
mga_outb(M_CRTC_EXT_INDEX, 3);
mga_outb(M_CRTC_EXT_DATA, tmp);
_destroy_mmap(&fb);
return SizeFound*1024*1024;
}
/* Desc: Frees all resources allocated by MGA init code.
*
* In :
* Out :
*
* Note:
*/
void mga_hw_fini (void)
{
int i;
pci_write_long(bus_id, 0x40, reg40);
for (i=0; i<4; i++) {
_destroy_mmap(&mgaptr.io_mem_map[i]);
}
_destroy_mmap(&mgaptr.linear_map);
#if !MGA_FARPTR
if (dirty) {
__djgpp_nearptr_disable();
dirty = FALSE;
}
#endif
matrox_id = 0;
}
/* Desc: Attempts to detect MGA.
*
* In :
* Out :
*
* Note: The first thing ever to be called. This is in charge of filling in
* the driver header with all the required information and function
* pointers. We do not yet have access to the video memory, so we can't
* talk directly to the card.
*/
int mga_hw_init (unsigned long *vram, int *interleave, char *name)
{
int i;
unsigned long pci_base[2];
if (matrox_id) {
return matrox_id;
}
#if !MGA_FARPTR
/* enable nearptr access */
if (_crt0_startup_flags & _CRT0_FLAG_NEARPTR) {
dirty = FALSE;
} else {
if (__djgpp_nearptr_enable() == 0)
return NULL;
dirty = TRUE;
}
#endif
/* find PCI device */
matrox_id = 0;
for (bus_id=0, i=0; matrox_id_list[i]; i++) {
if (pci_find_device(matrox_id_list[i], MATROX_VENDOR_ID, 0, &bus_id)) {
matrox_id = matrox_id_list[i];
break;
}
}
/* set up the card name */
switch (matrox_id) {
case MATROX_MILL_ID:
if (name) strcpy(name, "Millennium");
break;
default:
matrox_id = 0;
return -1;
}
reg40 = pci_read_long(bus_id, 0x40);
#if 0 /* overclock a little :) */
{
int rfhcnt = (reg40 >> 16) & 0xF;
if ((reg40 & 0x200000) && (rfhcnt < 0xC)) {
pci_write_long(bus_id, 0x40, (reg40 & 0xFFF0FFFF) | 0x000C0000);
}
}
#endif
/* read hardware configuration data */
for (i=0; i<2; i++)
pci_base[i] = pci_read_long(bus_id, 16+i*4);
/* work out the linear framebuffer and MMIO addresses */
if (matrox_id == MATROX_MILL_ID) {
if (pci_base[0])
io_mem_base[0] = pci_base[0] & 0xFFFFC000;
if (pci_base[1])
linear_base = pci_base[1] & 0xFF800000;
}
if (!linear_base || !io_mem_base[0])
return NULL;
/* deal with the memory mapping crap */
io_mem_size[0] = 0x4000;
for (i=0; i<4; i++) {
if (io_mem_base[i]) {
if (_create_mmap(&mgaptr.io_mem_map[i], io_mem_base[i], io_mem_size[i])) {
mga_hw_fini();
return NULL;
}
}
}
*vram = linear_size = _mga_get_vram(matrox_id, linear_base);
if (_create_mmap(&mgaptr.linear_map, linear_base, linear_size)) {
mga_hw_fini();
return NULL;
}
/* fill in user data */
*interleave = linear_size > 2*1024*1024;
return matrox_id;
}
/* PCI routines added by SET */
#define PCIAddr 0xCF8
#define PCIData 0xCFC
#define PCIEnable 0x80000000
/* FindPCIDevice:
* Replacement for the INT 1A - PCI BIOS v2.0c+ - FIND PCI DEVICE, AX = B102h
*
* Note: deviceIndex is because a card can hold more than one PCI chip.
*
* Searches the board of the vendor supplied in vendorID with
* identification number deviceID and index deviceIndex (normally 0).
* The value returned in handle can be used to access the PCI registers
* of this board.
*
* Return: 1 if found 0 if not found.
*/
static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle)
{
int model, vendor, card, device;
unsigned value, full_id, bus, busMax;
deviceIndex <<= 8;
/* for each PCI bus */
for (bus=0, busMax=0x10000; bus<busMax; bus+=0x10000) {
/* for each hardware device */
for (device=0, card=0; card<32; card++, device+=0x800) {
value = PCIEnable | bus | deviceIndex | device;
outportl(PCIAddr, value);
full_id = inportl(PCIData);
/* get the vendor and model ID */
vendor = full_id & 0xFFFF;
model = full_id >> 16;
if (vendor != 0xFFFF) {
/* is this the one we want? */
if ((deviceID == model) && (vendorID == vendor)) {
*handle = value;
return 1;
}
/* is it a bridge to a secondary bus? */
outportl(PCIAddr, value | 8);
if (((inportl(PCIData) >> 16) == 0x0600) || (full_id==0x00011011))
busMax += 0x10000;
}
}
}
return 0;
}
/* Desc:
*
* In :
* Out :
*
* Note:
*/
static unsigned long pci_read_long (int handle, int index)
{
outportl(PCIAddr, PCIEnable | handle | index);
return inportl(PCIData);
}
/* Desc:
*
* In :
* Out :
*
* Note:
*/
static void pci_write_long (int handle, int index, unsigned long value)
{
outportl(PCIAddr, PCIEnable | handle | index);
outportl(PCIData, value);
}

View file

@ -0,0 +1,113 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W HW mapping
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
#ifndef MGA_HW_included
#define MGA_HW_included
/* set this to zero to use near pointers */
#define MGA_FARPTR 1
/* access macros */
#if MGA_FARPTR
#include <sys/farptr.h>
#define hwptr_pokeb(ptr, off, val) _farpokeb((ptr).selector, (ptr).offset32+(off), (val))
#define hwptr_pokew(ptr, off, val) _farpokew((ptr).selector, (ptr).offset32+(off), (val))
#define hwptr_pokel(ptr, off, val) _farpokel((ptr).selector, (ptr).offset32+(off), (val))
#define hwptr_peekb(ptr, off) _farpeekb((ptr).selector, (ptr).offset32+(off))
#define hwptr_peekw(ptr, off) _farpeekw((ptr).selector, (ptr).offset32+(off))
#define hwptr_peekl(ptr, off) _farpeekl((ptr).selector, (ptr).offset32+(off))
#define hwptr_select(ptr) _farsetsel((ptr).selector)
#define hwptr_unselect(ptr) (ptr).selector = _fargetsel()
#define hwptr_nspokeb(ptr, off, val) _farnspokeb((ptr).offset32+(off), (val))
#define hwptr_nspokew(ptr, off, val) _farnspokew((ptr).offset32+(off), (val))
#define hwptr_nspokel(ptr, off, val) _farnspokel((ptr).offset32+(off), (val))
#define hwptr_nspeekb(ptr, off) _farnspeekb((ptr).offset32+(off))
#define hwptr_nspeekw(ptr, off) _farnspeekw((ptr).offset32+(off))
#define hwptr_nspeekl(ptr, off) _farnspeekl((ptr).offset32+(off))
#else
#define hwptr_pokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val)
#define hwptr_pokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val)
#define hwptr_pokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val)
#define hwptr_peekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off))))
#define hwptr_peekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off))))
#define hwptr_peekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off))))
#define hwptr_select(ptr)
#define hwptr_unselect(ptr)
#define hwptr_nspokeb(ptr, off, val) *((volatile unsigned char *)((ptr).offset32+(off))) = (val)
#define hwptr_nspokew(ptr, off, val) *((volatile unsigned short *)((ptr).offset32+(off))) = (val)
#define hwptr_nspokel(ptr, off, val) *((volatile unsigned long *)((ptr).offset32+(off))) = (val)
#define hwptr_nspeekb(ptr, off) (*((volatile unsigned char *)((ptr).offset32+(off))))
#define hwptr_nspeekw(ptr, off) (*((volatile unsigned short *)((ptr).offset32+(off))))
#define hwptr_nspeekl(ptr, off) (*((volatile unsigned long *)((ptr).offset32+(off))))
#endif
/* helpers for accessing the Matrox registers */
#define mga_select() hwptr_select(mgaptr.io_mem_map[0])
#define mga_inb(addr) hwptr_nspeekb(mgaptr.io_mem_map[0], addr)
#define mga_inw(addr) hwptr_nspeekw(mgaptr.io_mem_map[0], addr)
#define mga_inl(addr) hwptr_nspeekl(mgaptr.io_mem_map[0], addr)
#define mga_outb(addr, val) hwptr_nspokeb(mgaptr.io_mem_map[0], addr, val)
#define mga_outw(addr, val) hwptr_nspokew(mgaptr.io_mem_map[0], addr, val)
#define mga_outl(addr, val) hwptr_nspokel(mgaptr.io_mem_map[0], addr, val)
typedef struct MGA_HWPTR {
__dpmi_paddr io_mem_map[4], linear_map;
} MGA_HWPTR;
extern MGA_HWPTR mgaptr;
void mga_hw_fini (void);
int mga_hw_init (unsigned long *vram, int *interleave, char *name);
#endif

View file

@ -0,0 +1,231 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W mode switching
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
#include <dpmi.h>
#include <string.h>
#include <stubinfo.h>
#include <sys/exceptn.h>
#include <sys/farptr.h>
#include <sys/movedata.h>
#include <sys/segments.h>
#include "../internal.h"
#include "mga_mode.h"
static MGA_MODE oldmode;
static MGA_MODE modes[64];
/*
* VESA info
*/
#define V_SIGN 0
#define V_MINOR 4
#define V_MAJOR 5
#define V_OEM_OFS 6
#define V_OEM_SEG 8
#define V_MODE_OFS 14
#define V_MODE_SEG 16
#define V_MEMORY 18
/*
* mode info
*/
#define M_ATTR 0
#define M_GRAN 4
#define M_SCANLEN 16
#define M_XRES 18
#define M_YRES 20
#define M_BPP 25
#define M_RED 31
#define M_GREEN 33
#define M_BLUE 35
#define M_PHYS_PTR 40
/* Desc: get available modes
*
* In : -
* Out : linear modes list ptr
*
* Note: shouldn't use VESA...
*/
static MGA_MODE *_mga_mode_check (void)
{
__dpmi_regs r;
word16 *p;
MGA_MODE *q;
char vesa_info[512], tmp[512];
_farpokel(_stubinfo->ds_selector, 0, 0x32454256);
r.x.ax = 0x4f00;
r.x.di = 0;
r.x.es = _stubinfo->ds_segment;
__dpmi_int(0x10, &r);
movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);
if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) {
return NULL;
}
p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS]));
q = modes;
do {
if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {
break;
}
r.x.ax = 0x4f01;
r.x.cx = q->mode;
r.x.di = 512;
r.x.es = _stubinfo->ds_segment;
__dpmi_int(0x10, &r);
movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);
switch (tmp[M_BPP]) {
case 16:
q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE];
break;
case 8:
case 15:
case 24:
case 32:
q->bpp = tmp[M_BPP];
break;
default:
q->bpp = 0;
}
if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp && (tmp[M_ATTR]&0x80)) {
q->xres = _16_ tmp[M_XRES];
q->yres = _16_ tmp[M_YRES];
q->mode |= 0x4000;
q++;
}
} while (TRUE);
return modes;
}
/* Desc: save current mode
*
* In : ptr to mode structure
* Out : 0 if success
*
* Note: shouldn't use VESA...
*/
static int _mga_mode_save (MGA_MODE *p)
{
__asm("\n\
movw $0x4f03, %%ax \n\
int $0x10 \n\
movl %%ebx, %0 \n\
":"=g"(p->mode)::"%eax", "%ebx");
return 0;
}
/* Desc: switch to specified mode
*
* In : ptr to mode structure, refresh rate
* Out : 0 if success
*
* Note: shouldn't use VESA...
*/
int mga_mode_switch (MGA_MODE *p, int refresh)
{
if (oldmode.mode == 0) {
_mga_mode_save(&oldmode);
}
__asm("movw $0x4f02, %%ax; int $0x10"::"b"(p->mode):"%eax");
return 0;
(void)refresh; /* silence compiler warning */
}
/* Desc: restore to the mode prior to first call to `mga_switch'
*
* In : -
* Out : 0 if success
*
* Note: shouldn't use VESA...
*/
int mga_mode_restore (void)
{
if (oldmode.mode != 0) {
__asm("movw $0x4f02, %%ax; int $0x10"::"b"(oldmode.mode):"%eax");
oldmode.mode = 0;
}
return 0;
}
/* Desc: return suitable mode
*
* In : width, height, bpp
* Out : ptr to mode structure
*
* Note: -
*/
MGA_MODE *mga_mode_find (int width, int height, int bpp)
{
static MGA_MODE *q = NULL;
MGA_MODE *p;
unsigned int min;
if (q == NULL) {
if ((q = _mga_mode_check()) == NULL) {
return NULL;
}
}
/* search for a mode that fits our request */
for (min=-1, p=NULL; q->mode!=0xffff; q++) {
if ((q->xres>=width) && (q->yres>=height) && (q->bpp==bpp)) {
if (min>=(unsigned)(q->xres*q->yres)) {
min = q->xres*q->yres;
p = q;
}
}
}
return p;
}

View file

@ -0,0 +1,47 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W mode switching
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
#ifndef MGA_MODE_included
#define MGA_MODE_included
typedef struct MGA_MODE {
int mode;
int xres, yres;
int bpp;
} MGA_MODE;
int mga_mode_switch (MGA_MODE *p, int refresh);
int mga_mode_restore (void);
MGA_MODE *mga_mode_find (int width, int height, int bpp);
#endif

View file

@ -0,0 +1,207 @@
/*
* Mesa 3-D graphics library
* Version: 5.0
*
* Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
/*
* DOS/DJGPP device driver v1.3 for Mesa 5.0 -- MGA2064W register mnemonics
*
* Copyright (c) 2003 - Borca Daniel
* Email : dborca@yahoo.com
* Web : http://www.geocities.com/dborca
*/
#ifndef MGA_REG_H_included
#define MGA_REG_H_included
/* Matrox hardware registers: */
#define M_AR0 0x1C60
#define M_AR1 0x1C64
#define M_AR2 0x1C68
#define M_AR3 0x1C6C
#define M_AR4 0x1C70
#define M_AR5 0x1C74
#define M_AR6 0x1C78
#define M_BCOL 0x1C20
#define M_CXBNDRY 0x1C80
#define M_CXLEFT 0x1CA0
#define M_CXRIGHT 0x1CA4
#define M_DR0 0x1CC0
#define M_DR2 0x1CC8
#define M_DR3 0x1CCC
#define M_DR4 0x1CD0
#define M_DR6 0x1CD8
#define M_DR7 0x1CDC
#define M_DR8 0x1CE0
#define M_DR10 0x1CE8
#define M_DR11 0x1CEC
#define M_DR12 0x1CF0
#define M_DR14 0x1CF8
#define M_DR15 0x1CFC
#define M_DWGCTL 0x1C00
#define M_FCOL 0x1C24
#define M_FIFOSTATUS 0x1E10
#define M_FXBNDRY 0x1C84
#define M_FXLEFT 0x1CA8
#define M_FXRIGHT 0x1CAC
#define M_ICLEAR 0x1E18
#define M_IEN 0x1E1C
#define M_LEN 0x1C5C
#define M_MACCESS 0x1C04
#define M_OPMODE 0x1E54
#define M_PAT0 0x1C10
#define M_PAT1 0x1C14
#define M_PITCH 0x1C8C
#define M_PLNWT 0x1C1C
#define M_RESET 0x1E40
#define M_SGN 0x1C58
#define M_SHIFT 0x1C50
#define M_SRC0 0x1C30
#define M_SRC1 0x1C34
#define M_SRC2 0x1C38
#define M_SRC3 0x1C3C
#define M_STATUS 0x1E14
#define M_VCOUNT 0x1E20
#define M_XDST 0x1CB0
#define M_XYEND 0x1C44
#define M_XYSTRT 0x1C40
#define M_YBOT 0x1C9C
#define M_YDST 0x1C90
#define M_YDSTLEN 0x1C88
#define M_YDSTORG 0x1C94
#define M_YTOP 0x1C98
#define M_ZORG 0x1C0C
#define M_EXEC 0x0100
/* DWGCTL: opcod */
#define M_DWG_LINE_OPEN 0x0
#define M_DWG_AUTOLINE_OPEN 0x1
#define M_DWG_LINE_CLOSE 0x2
#define M_DWG_AUTOLINE_CLOSE 0x3
#define M_DWG_TRAP 0x4
#define M_DWG_TEXTURE_TRAP 0x5
#define M_DWG_BITBLT 0x8
#define M_DWG_FBITBLT 0xC
#define M_DWG_ILOAD 0x9
#define M_DWG_ILOAD_SCALE 0xD
#define M_DWG_ILOAD_FILTER 0xF
#define M_DWG_IDUMP 0xA
/* DWGCTL: atype */
#define M_DWG_RPL (0x0 << 4)
#define M_DWG_RSTR (0x1 << 4)
#define M_DWG_ZI (0x3 << 4)
#define M_DWG_BLK (0x4 << 4)
#define M_DWG_I (0x7 << 4)
/* DWGCTL: linear */
#define M_DWG_LINEAR (0x1 << 7)
/* DWGCTL: zmode */
#define M_DWG_NOZCMP (0x0 << 8)
#define M_DWG_ZE (0x2 << 8)
#define M_DWG_ZNE (0x3 << 8)
#define M_DWG_ZLT (0x4 << 8)
#define M_DWG_ZLTE (0x5 << 8)
#define M_DWG_ZGT (0x6 << 8)
#define M_DWG_ZGTE (0x7 << 8)
/* DWGCTL: solid */
#define M_DWG_SOLID (0x1 << 11)
/* DWGCTL: arzero */
#define M_DWG_ARZERO (0x1 << 12)
/* DWGCTL: sgnzero */
#define M_DWG_SGNZERO (0x1 << 13)
/* DWGCTL: shiftzero */
#define M_DWG_SHFTZERO (0x1 << 14)
/* DWGCTL: bop */
#define M_DWG_BOP_XOR (0x6 << 16)
#define M_DWG_BOP_AND (0x8 << 16)
#define M_DWG_BOP_SRC (0xC << 16)
#define M_DWG_BOP_OR (0xE << 16)
/* DWGCTL: trans */
#define M_DWG_TRANS_0 (0x0 << 20)
#define M_DWG_TRANS_1 (0x1 << 20)
#define M_DWG_TRANS_2 (0x2 << 20)
#define M_DWG_TRANS_3 (0x3 << 20)
#define M_DWG_TRANS_4 (0x4 << 20)
#define M_DWG_TRANS_5 (0x5 << 20)
#define M_DWG_TRANS_6 (0x6 << 20)
#define M_DWG_TRANS_7 (0x7 << 20)
#define M_DWG_TRANS_8 (0x8 << 20)
#define M_DWG_TRANS_9 (0x9 << 20)
#define M_DWG_TRANS_A (0xA << 20)
#define M_DWG_TRANS_B (0xB << 20)
#define M_DWG_TRANS_C (0xC << 20)
#define M_DWG_TRANS_D (0xD << 20)
#define M_DWG_TRANS_E (0xE << 20)
#define M_DWG_TRANS_F (0xF << 20)
/* DWGCTL: bltmod */
#define M_DWG_BMONOLEF (0x0 << 25)
#define M_DWG_BMONOWF (0x4 << 25)
#define M_DWG_BPLAN (0x1 << 25)
#define M_DWG_BFCOL (0x2 << 25)
#define M_DWG_BUYUV (0xE << 25)
#define M_DWG_BU32BGR (0x3 << 25)
#define M_DWG_BU32RGB (0x7 << 25)
#define M_DWG_BU24BGR (0xB << 25)
#define M_DWG_BU24RGB (0xF << 25)
/* DWGCTL: pattern */
#define M_DWG_PATTERN (0x1 << 29)
/* DWGCTL: transc */
#define M_DWG_TRANSC (0x1 << 30)
/* OPMODE: */
#define M_DMA_GENERAL (0x0 << 2)
#define M_DMA_BLIT (0x1 << 2)
#define M_DMA_VECTOR (0x2 << 2)
/* SGN: */
#define M_SDXL (0x1 << 1)
#define M_SDXR (0x1 << 5)
/* VGAREG */
#define M_CRTC_INDEX 0x1FD4
#define M_CRTC_DATA 0x1FD5
#define M_CRTC_EXT_INDEX 0x1FDE
#define M_CRTC_EXT_DATA 0x1FDF
#define M_MISC_R 0x1FCC
#define M_MISC_W 0x1FC2
/* CRTCEXT3: */
#define M_MGAMODE (0x1 << 7)
#endif

View file

@ -40,11 +40,12 @@
#include <sys/farptr.h>
#include <sys/movedata.h>
#include "video.h"
#include "vesa.h"
static vl_mode modes[64];
static vl_mode modes[128];
static word16 vesa_ver;
static int banked_selector, linear_selector;
@ -52,7 +53,7 @@ static int oldmode = -1;
static int vesa_color_precision = 6;
static void *vesa_pmcode;
static word16 *vesa_pmcode;
unsigned int vesa_gran_mask, vesa_gran_shift;
@ -203,18 +204,22 @@ static vl_mode *vesa_init (void)
if (vesa_info[V_MAJOR] >= 2) {
r.x.ax = 0x4f0a;
r.h.bl = 0;
r.x.bx = 0;
__dpmi_int(0x10, &r);
if (r.x.ax == 0x004f) {
vesa_pmcode = malloc(r.x.cx);
vesa_pmcode = (word16 *)malloc(r.x.cx);
movedata(__djgpp_dos_sel, (r.x.es << 4) + r.x.di, _my_ds(), (unsigned)vesa_pmcode, r.x.cx);
p = (word16 *)((long)vesa_pmcode + ((word16 *)vesa_pmcode)[3]);
while (*p++ != 0xffff) ;
if (*p != 0xffff) {
if (vesa_pmcode[3]) {
p = (word16 *)((long)vesa_pmcode + vesa_pmcode[3]);
while (*p++ != 0xffff) ;
} else {
p = NULL;
}
if (p && (*p != 0xffff)) {
free(vesa_pmcode);
vesa_pmcode = NULL;
} else {
vesa_swbank = (char *)vesa_pmcode + ((word16 *)vesa_pmcode)[0];
vesa_swbank = (void *)((long)vesa_pmcode + vesa_pmcode[0]);
}
}
}
@ -232,7 +237,7 @@ static vl_mode *vesa_init (void)
*
* Note: -
*/
static void vesa_finit (void)
static void vesa_fini (void)
{
if (vesa_ver) {
_remove_selector(&linear_selector);
@ -363,7 +368,7 @@ static int vesa_entermode (vl_mode *p, int refresh)
__dpmi_regs r;
if (p->mode & 0x4000) {
VESA.blit = vl_can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
VESA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
} else {
VESA.blit = vesa_b_dump_virtual;
{ int n; for (vesa_gran_shift=0, n=p->gran; n; vesa_gran_shift++, n>>=1) ; }
@ -492,16 +497,23 @@ static void vesa_setCI_f (int index, float red, float green, float blue)
/* Desc: retrieve CI precision
/* Desc: state retrieval
*
* In : -
* Out : precision in bits
* In : parameter name, ptr to storage
* Out : 0 if request successfully processed
*
* Note: -
*/
static int vesa_getCIprec (void)
static int vesa_get (int pname, int *params)
{
return vesa_color_precision;
switch (pname) {
case VL_GET_CI_PREC:
params[0] = vesa_color_precision;
break;
default:
return -1;
}
return 0;
}
@ -515,7 +527,7 @@ vl_driver VESA = {
NULL,
vesa_setCI_f,
vesa_setCI_i,
vesa_getCIprec,
vesa_get,
vesa_restore,
vesa_finit
vesa_fini
};

View file

@ -34,7 +34,7 @@
#ifndef VESA_H_included
#define VESA_H_included
#include "../internal.h"
#include "internal.h"
extern void *vesa_swbank;

View file

@ -34,11 +34,12 @@
#include <pc.h>
#include <stdlib.h>
#include "video.h"
#include "vga.h"
static vl_mode modes[4] = {
static vl_mode modes[] = {
{0x13 | 0x4000, 320, 200, 320, 8, -1, 320*200},
{0xffff, -1, -1, -1, -1, -1, -1}
};
@ -99,7 +100,7 @@ static vl_mode *vga_init (void)
*
* Note: -
*/
static void vga_finit (void)
static void vga_fini (void)
{
if (vga_ver) {
_remove_selector(&linear_selector);
@ -120,7 +121,7 @@ static int vga_entermode (vl_mode *p, int refresh)
if (!(p->mode & 0x4000)) {
return -1;
}
VGA.blit = vl_can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
VGA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
if (oldmode == -1) {
__asm("\n\
@ -134,6 +135,8 @@ static int vga_entermode (vl_mode *p, int refresh)
__asm("int $0x10"::"a"(p->mode&0xff));
return 0;
(void)refresh; /* silence compiler warning */
}
@ -196,16 +199,23 @@ static void vga_setCI_f (int index, float red, float green, float blue)
/* Desc: retrieve CI precision
/* Desc: state retrieval
*
* In : -
* Out : precision in bits
* In : parameter name, ptr to storage
* Out : 0 if request successfully processed
*
* Note: -
*/
static int vga_getCIprec (void)
static int vga_get (int pname, int *params)
{
return vga_color_precision;
switch (pname) {
case VL_GET_CI_PREC:
params[0] = vga_color_precision;
break;
default:
return -1;
}
return 0;
}
@ -219,7 +229,7 @@ vl_driver VGA = {
NULL,
vga_setCI_f,
vga_setCI_i,
vga_getCIprec,
vga_get,
vga_restore,
vga_finit
vga_fini
};

View file

@ -34,8 +34,8 @@
#ifndef VGA_H_included
#define VGA_H_included
#include "../internal.h"
#include "../vesa/vesa.h"
#include "internal.h"
#include "vesa.h"
extern vl_driver VGA;

View file

@ -35,10 +35,10 @@
#include <stdlib.h>
#include "video.h"
#include "internal.h"
#include "vesa/vesa.h"
#include "vga/vga.h"
#include "vesa.h"
#include "vga.h"
#include "video.h"
@ -56,22 +56,22 @@ int vl_current_offset, vl_current_delta;
/* lookup table for scaling 5 bit colors up to 8 bits */
static int _rgb_scale_5[32] = {
0, 8, 16, 24, 32, 41, 49, 57,
65, 74, 82, 90, 98, 106, 115, 123,
131, 139, 148, 156, 164, 172, 180, 189,
197, 205, 213, 222, 230, 238, 246, 255
0, 8, 16, 25, 33, 41, 49, 58,
66, 74, 82, 90, 99, 107, 115, 123,
132, 140, 148, 156, 165, 173, 181, 189,
197, 206, 214, 222, 230, 239, 247, 255
};
/* lookup table for scaling 6 bit colors up to 8 bits */
static int _rgb_scale_6[64] = {
0, 4, 8, 12, 16, 20, 24, 28,
32, 36, 40, 44, 48, 52, 56, 60,
64, 68, 72, 76, 80, 85, 89, 93,
32, 36, 40, 45, 49, 53, 57, 61,
65, 69, 73, 77, 81, 85, 89, 93,
97, 101, 105, 109, 113, 117, 121, 125,
129, 133, 137, 141, 145, 149, 153, 157,
161, 165, 170, 174, 178, 182, 186, 190,
194, 198, 202, 206, 210, 214, 218, 222,
226, 230, 234, 238, 242, 246, 250, 255
130, 134, 138, 142, 146, 150, 154, 158,
162, 166, 170, 174, 178, 182, 186, 190,
194, 198, 202, 206, 210, 215, 219, 223,
227, 231, 235, 239, 243, 247, 251, 255
};
/* FakeColor data */
@ -376,36 +376,24 @@ int vl_sync_buffer (void **buffer, int x, int y, int width, int height)
/* Desc: get screen geometry
/* Desc: state retrieval
*
* In : ptr to WIDTH, ptr to HEIGHT
* In : name, storage
* Out : -
*
* Note: -
*/
void vl_get_screen_size (int *width, int *height)
int vl_get (int pname, int *params)
{
*width = video_mode->xres;
*height = video_mode->yres;
}
/* Desc: retrieve CPU MMX capability
*
* In : -
* Out : FALSE if CPU cannot do MMX
*
* Note: -
*/
int vl_can_mmx (void)
{
#ifdef USE_MMX_ASM
extern int _mesa_identify_x86_cpu_features (void);
return (_mesa_identify_x86_cpu_features() & 0x00800000);
#else
switch (pname) {
case VL_GET_SCREEN_SIZE:
params[0] = video_mode->xres;
params[1] = video_mode->yres;
break;
default:
return drv->get(pname, params);
}
return 0;
#endif
}
@ -431,7 +419,7 @@ static int vl_setup_mode (vl_mode *p)
vl_mixfix = vl_mixfix##bpp; \
vl_mixrgb = vl_mixrgb##bpp; \
vl_mixrgba = vl_mixrgba##bpp; \
vl_clear = vl_can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp
vl_clear = _can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp
switch (p->bpp) {
case 8:
@ -475,7 +463,7 @@ static int vl_setup_mode (vl_mode *p)
void vl_video_exit (void)
{
drv->restore();
drv->finit();
drv->fini();
}
@ -523,7 +511,7 @@ int vl_video_init (int width, int height, int bpp, int rgb, int refresh)
if ((vl_setup_mode(p) == 0) && (drv->entermode(p, refresh) == 0)) {
vl_flip = drv->blit;
if (fake) {
min = drv->getCIprec();
drv->get(VL_GET_CI_PREC, (int *)(&min));
fake_buildpalette(min);
if (min == 8) {
vl_getrgba = v_getrgba8fake8;

View file

@ -36,6 +36,12 @@
typedef int fixed;
#define VL_GET_CARD_NAME 0x0100
#define VL_GET_VRAM 0x0101
#define VL_GET_CI_PREC 0x0200
#define VL_GET_HPIXELS 0x0201
#define VL_GET_SCREEN_SIZE 0x0202
extern int (*vl_mixfix) (fixed r, fixed g, fixed b);
extern int (*vl_mixrgb) (const unsigned char rgb[]);
extern int (*vl_mixrgba) (const unsigned char rgba[]);
@ -50,7 +56,7 @@ extern int (*vl_getpixel) (unsigned int offset);
void vl_setCI (int index, float red, float green, float blue);
int vl_sync_buffer (void **buffer, int x, int y, int width, int height);
void vl_get_screen_size (int *width, int *height);
int vl_get (int pname, int *params);
void vl_video_exit (void);
int vl_video_init (int width, int height, int bpp, int rgb, int refresh);

View file

@ -108,7 +108,7 @@ _v_clear_common:
.global _v_clear8_mmx
_v_clear8_mmx:
#ifdef USE_MMX_ASM
movq 4(%esp), %mm0
movd 4(%esp), %mm0
punpcklbw %mm0, %mm0
punpcklwd %mm0, %mm0
jmp _v_clear_common_mmx
@ -125,7 +125,7 @@ _v_clear8_mmx:
.global _v_clear16_mmx
_v_clear16_mmx:
#ifdef USE_MMX_ASM
movq 4(%esp), %mm0
movd 4(%esp), %mm0
punpcklwd %mm0, %mm0
jmp _v_clear_common_mmx
#endif
@ -141,7 +141,7 @@ _v_clear16_mmx:
.global _v_clear32_mmx
_v_clear32_mmx:
#ifdef USE_MMX_ASM
movq 4(%esp), %mm0
movd 4(%esp), %mm0
.balign 4
_v_clear_common_mmx:
punpckldq %mm0, %mm0

View file

@ -40,6 +40,9 @@
# As a consequence, you'll need the DJGPP Glide3
# library to build any application.
# default = no
# MATROX=1 build for Matrox Millennium I (MGA2064W) cards.
# This is experimental and not intensively tested.
# default = no
# HAVE_X86=1 optimize for i386.
# default = no
# HAVE_MMX=1 allow MMX specializations, provided your assembler
@ -70,8 +73,17 @@ GL_IMP = libigl.a
CC = gcc
CFLAGS += -I$(TOP)/include -I.
ifdef FX
CFLAGS += -D__DOS__ -I$(GLIDE) -DFX -DFX_GLIDE3 -DFXMESA_USE_ARGB
ifeq ($(FX),1)
CFLAGS += -D__DOS__ -DH3
CFLAGS += -I$(GLIDE) -DFX -DFX_GLIDE3 -DFXMESA_USE_ARGB
LIBNAME = "MesaGL/FX DJGPP"
else
ifeq ($(MATROX),1)
CFLAGS += -DMATROX
LIBNAME = "MesaGL/MGA DJGPP"
else
LIBNAME = "MesaGL DJGPP"
endif
endif
AR = ar
@ -228,22 +240,22 @@ K3D_SOURCES = \
X86/3dnow_xform4.S \
X86/3dnow_normal.S
ifdef HAVE_MMX
ifeq ($(HAVE_MMX),1)
X86_SOURCES += $(MMX_SOURCES)
CFLAGS += -DUSE_MMX_ASM
HAVE_X86 = 1
endif
ifdef HAVE_SSE
ifeq ($(HAVE_SSE),1)
X86_SOURCES += $(SSE_SOURCES)
CFLAGS += -DUSE_SSE_ASM
HAVE_X86 = 1
endif
ifdef HAVE_3DNOW
ifeq ($(HAVE_3DNOW),1)
X86_SOURCES += $(K3D_SOURCES)
CFLAGS += -DUSE_3DNOW_ASM
HAVE_X86 = 1
endif
ifdef HAVE_X86
ifeq ($(HAVE_X86),1)
CFLAGS += -DUSE_X86_ASM
else
X86_SOURCES =
@ -251,15 +263,7 @@ endif
DRIVER_SOURCES = \
DOS/dmesa.c
ifndef FX
DRIVER_SOURCES += \
DOS/video.c \
DOS/virtual.S \
DOS/vesa/vesa.c \
DOS/vesa/blit.S \
DOS/vga/vga.c \
DOS/dpmi.c
else
ifeq ($(FX),1)
DRIVER_SOURCES += \
FX/fxapi.c \
FX/fxdd.c \
@ -270,6 +274,22 @@ DRIVER_SOURCES += \
FX/fxtris.c \
FX/fxvb.c \
FX/fxglidew.c
else
ifeq ($(MATROX),1)
DRIVER_SOURCES += \
DOS/mga/mga.c \
DOS/mga/mga_hw.c \
DOS/mga/mga_mode.c \
DOS/dpmi.c
else
DRIVER_SOURCES += \
DOS/video.c \
DOS/virtual.S \
DOS/vesa.c \
DOS/blit.S \
DOS/vga.c \
DOS/dpmi.c
endif
endif
SOURCES = $(CORE_SOURCES) $(X86_SOURCES) $(DRIVER_SOURCES)
@ -295,10 +315,10 @@ ifeq ($(DXE3GEN),)
$(warning Missing DXE3GEN and/or DXE3.LD! You must have DXE3GEN)
$(warning somewhere in PATH, and DXE3.LD in DJGPP/LIB directory.)
else
ifdef FX
-dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D "MesaGL/FX DJGPP" -E _gl -E _DMesa -P glid3.dxe -U $(OBJECTS)
ifeq ($(FX),1)
-dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D $(LIBNAME) -E _gl -E _DMesa -P glid3.dxe -U $(OBJECTS)
else
-dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D "MesaGL DJGPP" -E _gl -E _DMesa -U $(OBJECTS)
-dxe3gen -o $(LIBDIR)/$(GL_DXE) -I $(LIBDIR)/$(GL_IMP) -D $(LIBNAME) -E _gl -E _DMesa -U $(OBJECTS)
endif
endif
@ -319,8 +339,7 @@ clean:
-$(RM) $(subst /,\,tnl/*.o)
-$(RM) $(subst /,\,X86/*.o)
-$(RM) $(subst /,\,DOS/*.o)
-$(RM) $(subst /,\,DOS/vesa/*.o)
-$(RM) $(subst /,\,DOS/vga/*.o)
-$(RM) $(subst /,\,DOS/mga/*.o)
-$(RM) $(subst /,\,FX/*.o)
-include depend