--- /dev/null
+# Mesa 3-D graphics library
+# Version: 4.0
+#
+# Copyright (C) 1999 Brian Paul All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# DOS/DJGPP makefile v1.4 for Mesa
+#
+# Copyright (C) 2002 - Borca Daniel
+# Email : dborca@yahoo.com
+# Web : http://www.geocities.com/dborca
+
+
+#
+# Available options:
+#
+# Environment variables:
+# CPU optimize for the given processor.
+# default = k6
+# GLU=[mesa|sgi] specify GLU directory; can be `sgi' (requires GNU/C++)
+# or `mesa'.
+# default = mesa
+# GLIDE path to Glide3 SDK include files; used with FX.
+# default = $(TOP)/include/glide3
+# FX=1 build for 3dfx Glide3. Note that this disables
+# compilation of most DMesa code and requires fxMesa.
+# 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
+# supports MMX instruction set. However, the true CPU
+# capabilities are checked at run-time to avoid crashes.
+# default = no
+# HAVE_SSE=1 (see HAVE_MMX)
+# default = no
+# HAVE_3DNOW=1 (see HAVE_MMX)
+# default = no
+#
+# Targets:
+# all: build everything
+# libgl: build GL
+# libglu: build GLU
+# libglut: build GLUT
+# clean: remove object files
+# realclean: remove all generated files
+#
+
+
+
+.PHONY : all libgl libglu libglut clean realclean
+
+CPU ?= k6
+
+GLU ?= mesa
+
+CFLAGS = -Wall -W -pedantic
+CFLAGS += -O2 -ffast-math -mcpu=$(CPU)
+
+export CFLAGS
+
+ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)
+UNLINK = del $(subst /,\,$(1))
+else
+UNLINK = $(RM) $(1)
+endif
+
+all: libgl libglu libglut
+
+libgl: lib
+ $(MAKE) -f Makefile.DJ -C src/mesa
+libglu: lib
+ $(MAKE) -f Makefile.DJ -C src/glu/$(GLU)
+libglut: lib
+ $(MAKE) -f Makefile.DJ -C src/glut/dos
+
+lib:
+ mkdir lib
+
+clean:
+ $(MAKE) -f Makefile.DJ clean -C src/mesa
+ $(MAKE) -f Makefile.DJ clean -C src/glu/mesa
+ $(MAKE) -f Makefile.DJ clean -C src/glu/sgi
+ $(MAKE) -f Makefile.DJ clean -C src/glut/dos
+
+realclean: clean
+ -$(call UNLINK,lib/*.a)
+ -$(call UNLINK,lib/*.dxe)
- Mesa 5.0.1 DOS/DJGPP Port v1.3\r
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\r
-\r
-\r
-\r
-Description:\r
-~~~~~~~~~~~~\r
-\r
-Well, guess what... this is the DOS port of Mesa 5.0.1, for DJGPP fans... Whoa!\r
-The driver has its origins in ddsample.c, written by Brian Paul and found by me\r
-in Mesa 3.4.2.\r
-\r
-\r
-\r
-Legal:\r
-~~~~~~\r
-\r
-Mesa copyright applies, provided this package is used within Mesa. For anything\r
-else, see GPL.\r
-\r
-\r
-\r
-Installation:\r
-~~~~~~~~~~~~~\r
-\r
-Unzip and type:\r
-\r
- make -f Makefile.DJ [OPTIONS...]\r
-\r
-Available options:\r
-\r
- Environment variables:\r
- CPU optimize for the given processor.\r
- default = k6\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
- compilation of most DMesa code and requires fxMesa.\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
- supports MMX instruction set. However, the true CPU\r
- capabilities are checked at run-time to avoid crashes.\r
- default = no\r
- HAVE_SSE=1 (see HAVE_MMX)\r
- default = no\r
- HAVE_3DNOW=1 (see HAVE_MMX)\r
- default = no\r
-\r
- Targets:\r
- all: build everything\r
- libgl: build GL\r
- libglu: build GLU\r
- libglut: build GLUT\r
- clean: remove object files\r
- realclean: remove all generated files\r
-\r
-\r
-\r
-Tested on:\r
- CPU: K6-2 (CXT) @500(412.5) MHz\r
- Mainboard: ViA Apollo VP2/97 w/ 128 MB SDRAM\r
- Video card: PowerColor EvilKing3 (Voodoo3 3000 PCI) w/ 16 MB SDRAM\r
- DJGPP: djdev 2.04 + gcc v3.2.2 + make v3.79.1\r
- OS: DOS and Win9x\r
-\r
-\r
-\r
-FAQ:\r
-~~~~\r
-\r
-1. Compilation\r
-\r
- Q) I tried to run `make' and it exits because `gcc' complains it cannot find\r
- some stupid file.\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
- Q) `make' complains about DXE3 or something, yet it builds the libraries.\r
- A) DXE3 refers to the DJGPP dynamic modules. You'll need either the latest\r
- DJGPP distro, or download the separate package from my web page. Read the\r
- DXE3 documentation on how to use them. Hint: build your export object\r
- file; then link it with your application. For example:\r
- dxe3res -o dxe3tbl.c gl.dxe glu.dxe glut.dxe\r
- gcc -o dxe3tbl.o -c dxe3tbl.c\r
- gcc -o OUT.exe dxe3tbl.o IN.c -liglut -liglu -ligl -ldl\r
-\r
-2. 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 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
- Glide, see Glide info. If not, sorry!\r
-\r
- Q) I made a simple application and it does nothing. It exits right away. Not\r
- even a blank screen.\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
- 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
- his headers. The only workaround is to link GLUT the old way :-(\r
-\r
- Q) The GLUT is incomplete.\r
- A) See below.\r
-\r
-\r
-\r
-libGLUT (the toolkit):\r
-~~~~~~~~~~~~~~~~~~~~~~\r
-\r
-Well, this "skeletal" GLUT implementation was taken from AllegGL project and\r
-heavily changed. Thanks should go to Bernhard Tschirren, Mark Kilgard, Brian\r
-Paul and probably others (or probably not ;-). GLUT functionality will be\r
-extended only on an "as needed" basis.\r
-\r
-GLUT talks to hardware via PC_HW package which was put together from various\r
-pieces I wrote long time ago. It consists from the keyboard, mouse and timer\r
-drivers.\r
-\r
-My keyboard driver used only scancodes; as GLUT requires ASCII values for keys,\r
-I borrowed the translation tables (and maybe more) from Allegro -- many thanks\r
-to Shawn Hargreaves et co. Ctrl-Alt-Del (plus Ctrl-Alt-End, for Windows users)\r
-will shut down the GLUT engine unconditionally: it will raise SIGINT, which in\r
-turn will (hopefully) call the destructors, thus cleaning up your/my mess ;-)\r
-NB: since the DJGPP guys ensured signal handlers won't go beyond program's\r
-space (and since dynamic modules shall) the SIGINT can't be hooked (well, it\r
-can, but it is useless), therefore you must live with the 'Exiting due to\r
-signal SIGINT' message...\r
-\r
-The mouse driver is far from complete (lack of drawing, etc), but is enough to\r
-make almost all the demos work. Supports the CuteMouse WheelAPI.\r
-\r
-The timer is pretty versatile for it supports multiple timers with different\r
-frequencies. While not being the most accurate timer in the known universe, I\r
-think it's OK. Take this example: you have timer A with a very high rate, and\r
-then you have timer B with very low rate compared to A; now, A ticks OK, but\r
-timer B will probably loose precision!\r
-\r
-As an addition, stdout and stderr are redirected and dumped upon exit. This\r
-means that `printf' can be safely called during graphics. A bit of a hack, I\r
-know, because all messages come in bulk, but I think it's better than nothing.\r
-"Borrowed" from LIBRHUTI (Robert Hoehne).\r
-\r
-Window creating defaults: 300x300x16 at (0,0), 16-bit depth, 16-bit accum,\r
-8-bit stencil. However, the video mode is chosen in such a way that first\r
-window will fit. If you need high resolution with small windows, set initial\r
-position far to the right (or way down); then you can move them back to any\r
-position right before the main loop.\r
-\r
-The following environment variables can customize GLUT behaviour:\r
- DMESA_GLUT_REFRESH - set vertical screen refresh rate (VESA3)\r
- DMESA_GLUT_BPP - set default bits per pixel (VGA needs 8)\r
- GLUT_FPS - print frames/second statistics to stderr\r
-\r
-\r
-\r
-History:\r
-~~~~~~~~\r
-\r
-v1.0 (mar-2002)\r
- initial release\r
-\r
-v1.1 (sep-2002)\r
- + added 3dfx Glide3 support\r
- + added refresh rate control\r
- + added fonts in GLUT\r
- * lots of minor changes\r
-\r
-v1.2 (nov-2002)\r
- * synced w/ Mesa-4.1\r
- - removed dmesadxe.h\r
-\r
-v1.3 (mar-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 some compilation errors (reported by Chan Kar Heng)\r
- * optimized driver for faster callback access... yeah, right :)\r
- * overhauled virtual buffer and internal video drivers\r
- * better fxMesa integration\r
- * revamped GLUT\r
- * switched to DXE3\r
-\r
-\r
-\r
-Contact:\r
-~~~~~~~~\r
-\r
-Name: Borca Daniel\r
-E-mail: dborca@yahoo.com\r
-WWW: http://www.geocities.com/dborca/\r
+ Mesa 5.0.1 DOS/DJGPP Port v1.4
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+
+
+Description:
+~~~~~~~~~~~~
+
+Well, guess what... this is the DOS port of Mesa 5.0.1, for DJGPP fans... Whoa!
+The driver has its origins in ddsample.c, written by Brian Paul and found by me
+in Mesa 3.4.2.
+
+
+
+Legal:
+~~~~~~
+
+Mesa copyright applies, provided this package is used within Mesa. For anything
+else, see GPL.
+
+
+
+Installation:
+~~~~~~~~~~~~~
+
+Unzip and type:
+
+ make -f Makefile.DJ [OPTIONS...]
+
+Available options:
+
+ Environment variables:
+ CPU optimize for the given processor.
+ default = k6
+ GLU=[mesa|sgi] specify GLU directory; can be `sgi' (requires GNU/C++)
+ or `mesa'.
+ default = mesa
+ GLIDE path to Glide3 SDK include files; used with FX.
+ default = $(TOP)/include/glide3
+ FX=1 build for 3dfx Glide3. Note that this disables
+ compilation of most DMesa code and requires fxMesa.
+ 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
+ supports MMX instruction set. However, the true CPU
+ capabilities are checked at run-time to avoid crashes.
+ default = no
+ HAVE_SSE=1 (see HAVE_MMX)
+ default = no
+ HAVE_3DNOW=1 (see HAVE_MMX)
+ default = no
+
+ Targets:
+ all: build everything
+ libgl: build GL
+ libglu: build GLU
+ libglut: build GLUT
+ clean: remove object files
+ realclean: remove all generated files
+
+
+
+Tested on:
+ CPU: AMD Duron @800 MHz
+ Mainboard: EP-8KTA3 w/ 128 MB SDRAM
+ Video card: Voodoo5 5500 AGP w/ 64 MB SDRAM
+ DJGPP: djdev 2.04 + gcc v3.2.2 + make v3.79.1
+ OS: DOS and Win98SE
+
+
+
+FAQ:
+~~~~
+
+1. Compilation
+
+ Q) I tried to run `make' and it exits because `gcc' complains it cannot find
+ some stupid file.
+ 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)
+
+ Q) `make' complains about DXE3 or something, yet it builds the libraries.
+ A) DXE3 refers to the DJGPP dynamic modules. You'll need either the latest
+ DJGPP distro, or download the separate package from my web page. Read the
+ DXE3 documentation on how to use them.
+ A) When compiling for Glide (FX=1), make sure `glid3.dxe' can be found in
+ LD_LIBRARY_PATH (or top `lib' directory).
+
+2. 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 3dfx Voodoo Banshee or higher card,
+ you're lucky (check http://sourceforge.net/projects/glide for the DJGPP
+ port). 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
+ Glide, see Glide info. If not, sorry!
+
+ Q) I made a simple application and it does nothing. It exits right away. Not
+ even a blank screen.
+ 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!
+ 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
+ his headers. The only workaround is to link GLUT the old way :-(
+
+ Q) The GLUT is incomplete.
+ A) See below.
+
+
+
+libGLUT (the toolkit):
+~~~~~~~~~~~~~~~~~~~~~~
+
+Well, this "skeletal" GLUT implementation was taken from AllegGL project and
+heavily changed. Thanks should go to Bernhard Tschirren, Mark Kilgard, Brian
+Paul and probably others (or probably not ;-). GLUT functionality will be
+extended only on an "as needed" basis.
+
+GLUT talks to hardware via PC_HW package which was put together from various
+pieces I wrote long time ago. It consists from the keyboard, mouse and timer
+drivers.
+
+My keyboard driver used only scancodes; as GLUT requires ASCII values for keys,
+I borrowed the translation tables (and maybe more) from Allegro -- many thanks
+to Shawn Hargreaves et co. Ctrl-Alt-Del (plus Ctrl-Alt-End, for Windows users)
+will shut down the GLUT engine unconditionally: it will raise SIGINT, which in
+turn will (hopefully) call the destructors, thus cleaning up your/my mess ;-)
+NB: since the DJGPP guys ensured signal handlers won't go beyond program's
+space (and since dynamic modules shall) the SIGINT can't be hooked (well, it
+can, but it is useless), therefore you must live with the 'Exiting due to
+signal SIGINT' message...
+
+The mouse driver is far from complete (lack of drawing, etc), but is enough to
+make almost all the demos work. Supports the CuteMouse WheelAPI.
+
+The timer is pretty versatile for it supports multiple timers with different
+frequencies. While not being the most accurate timer in the known universe, I
+think it's OK. Take this example: you have timer A with a very high rate, and
+then you have timer B with very low rate compared to A; now, A ticks OK, but
+timer B will probably loose precision!
+
+As an addition, stdout and stderr are redirected and dumped upon exit. This
+means that `printf' can be safely called during graphics. A bit of a hack, I
+know, because all messages come in bulk, but I think it's better than nothing.
+"Borrowed" from LIBRHUTI (Robert Hoehne).
+
+Window creating defaults: 300x300x16 at (0,0), 16-bit depth, 16-bit accum,
+8-bit stencil. However, the video mode is chosen in such a way that first
+window will fit. If you need high resolution with small windows, set initial
+position far to the right (or way down); then you can move them back to any
+position right before the main loop.
+
+The following environment variables can customize GLUT behaviour:
+ DMESA_GLUT_REFRESH - set vertical screen refresh rate (VESA3)
+ DMESA_GLUT_BPP - set default bits per pixel (VGA needs 8)
+ GLUT_FPS - print frames/second statistics to stderr
+
+
+
+History:
+~~~~~~~~
+
+v1.0 (mar-2002)
+ initial release
+
+v1.1 (sep-2002)
+ + added 3dfx Glide3 support
+ + added refresh rate control
+ + added fonts in GLUT
+ * lots of minor changes
+
+v1.2 (nov-2002)
+ * synced w/ Mesa-4.1
+ - removed dmesadxe.h
+
+v1.3 (mar-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 some compilation errors (reported by Chan Kar Heng)
+ * optimized driver for faster callback access... yeah, right :)
+ * overhauled virtual buffer and internal video drivers
+ * better fxMesa integration
+ * revamped GLUT
+ * switched to DXE3
+
+v1.4 (jun-2003)
+ * accomodated makefiles with the new sourcetree
+
+
+
+Contact:
+~~~~~~~~
+
+Name: Borca Daniel
+E-mail: dborca@yahoo.com
+WWW: http://www.geocities.com/dborca/
-/*\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\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#ifndef DMESA_H_included\r
-#define DMESA_H_included\r
-\r
-#define DMESA_MAJOR_VERSION 5\r
-#define DMESA_MINOR_VERSION 0\r
-\r
-/* Sample Usage:\r
- *\r
- * 1. Call DMesaCreateVisual() to initialize graphics.\r
- * 2. Call DMesaCreateContext() to create a DMesa rendering context.\r
- * 3. Call DMesaCreateBuffer() to define the window.\r
- * 4. Call DMesaMakeCurrent() to bind the DMesaBuffer to a DMesaContext.\r
- * 5. Make gl* calls to render your graphics.\r
- * 6. Use DMesaSwapBuffers() when double buffering to swap front/back buffers.\r
- * 7. Before exiting, destroy DMesaBuffer, DMesaContext and DMesaVisual.\r
- */\r
-\r
-typedef struct dmesa_context *DMesaContext;\r
-typedef struct dmesa_visual *DMesaVisual;\r
-typedef struct dmesa_buffer *DMesaBuffer;\r
-\r
-#ifdef __cplusplus\r
-extern "C" {\r
-#endif\r
-\r
-/*\r
- * Create a new Visual and set graphics mode.\r
- */\r
-DMesaVisual DMesaCreateVisual (GLint width, /* X res */\r
- GLint height, /* Y res */\r
- GLint colDepth, /* BPP */\r
- GLint refresh, /* refresh rate: 0=default */\r
- GLboolean dbFlag, /* double-buffered */\r
- GLboolean rgbFlag, /* RGB mode */\r
- GLboolean alphaFlag,/* alpha buffer requested */\r
- GLint depthSize, /* requested bits/depth */\r
- GLint stencilSize, /* requested bits/stencil */\r
- GLint accumSize); /* requested bits/accum */\r
-\r
-/*\r
- * Destroy Visual and restore screen.\r
- */\r
-void DMesaDestroyVisual (DMesaVisual v);\r
-\r
-\r
-\r
-/*\r
- * Create a new Context for rendering.\r
- */\r
-DMesaContext DMesaCreateContext (DMesaVisual visual, DMesaContext share);\r
-\r
-/*\r
- * Destroy Context.\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
- * Create a new Buffer (window).\r
- */\r
-DMesaBuffer DMesaCreateBuffer (DMesaVisual visual,\r
- GLint xpos, GLint ypos,\r
- GLint width, GLint height);\r
-\r
-/*\r
- * Destroy Buffer.\r
- */\r
-void DMesaDestroyBuffer (DMesaBuffer b);\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
- * Move/Resize current Buffer.\r
- */\r
-GLboolean DMesaMoveBuffer (GLint xpos, GLint ypos);\r
-GLboolean DMesaResizeBuffer (GLint width, GLint height);\r
-\r
-/*\r
- * Set palette index, using normalized values.\r
- */\r
-void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue);\r
-\r
-/*\r
- * DMesa state retrieval.\r
- */\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
-#endif\r
-\r
-#endif\r
+/*
+ * 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
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef DMESA_H_included
+#define DMESA_H_included
+
+#define DMESA_MAJOR_VERSION 5
+#define DMESA_MINOR_VERSION 0
+
+/* Sample Usage:
+ *
+ * 1. Call DMesaCreateVisual() to initialize graphics.
+ * 2. Call DMesaCreateContext() to create a DMesa rendering context.
+ * 3. Call DMesaCreateBuffer() to define the window.
+ * 4. Call DMesaMakeCurrent() to bind the DMesaBuffer to a DMesaContext.
+ * 5. Make gl* calls to render your graphics.
+ * 6. Use DMesaSwapBuffers() when double buffering to swap front/back buffers.
+ * 7. Before exiting, destroy DMesaBuffer, DMesaContext and DMesaVisual.
+ */
+
+typedef struct dmesa_context *DMesaContext;
+typedef struct dmesa_visual *DMesaVisual;
+typedef struct dmesa_buffer *DMesaBuffer;
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Create a new Visual and set graphics mode.
+ */
+DMesaVisual DMesaCreateVisual (GLint width, /* X res */
+ GLint height, /* Y res */
+ GLint colDepth, /* BPP */
+ GLint refresh, /* refresh rate: 0=default */
+ GLboolean dbFlag, /* double-buffered */
+ GLboolean rgbFlag, /* RGB mode */
+ GLboolean alphaFlag,/* alpha buffer requested */
+ GLint depthSize, /* requested bits/depth */
+ GLint stencilSize, /* requested bits/stencil */
+ GLint accumSize); /* requested bits/accum */
+
+/*
+ * Destroy Visual and restore screen.
+ */
+void DMesaDestroyVisual (DMesaVisual v);
+
+
+
+/*
+ * Create a new Context for rendering.
+ */
+DMesaContext DMesaCreateContext (DMesaVisual visual, DMesaContext share);
+
+/*
+ * Destroy Context.
+ */
+void DMesaDestroyContext (DMesaContext c);
+
+/*
+ * Return a handle to the current context.
+ */
+DMesaContext DMesaGetCurrentContext (void);
+
+
+
+/*
+ * Create a new Buffer (window).
+ */
+DMesaBuffer DMesaCreateBuffer (DMesaVisual visual,
+ GLint xpos, GLint ypos,
+ GLint width, GLint height);
+
+/*
+ * Destroy Buffer.
+ */
+void DMesaDestroyBuffer (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);
+
+
+
+/*
+ * Move/Resize current Buffer.
+ */
+GLboolean DMesaMoveBuffer (GLint xpos, GLint ypos);
+GLboolean DMesaResizeBuffer (GLint width, GLint height);
+
+/*
+ * Set palette index, using normalized values.
+ */
+void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue);
+
+/*
+ * DMesa state retrieval.
+ */
+#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
+}
+#endif
+
+#endif
-# 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
-# DOS/DJGPP samples makefile v1.3 for Mesa\r
-#\r
-# Copyright (C) 2002 - Borca Daniel\r
-# Email : dborca@yahoo.com\r
-# Web : http://www.geocities.com/dborca\r
-\r
-\r
-#\r
-# Available options:\r
-#\r
-# Environment variables:\r
-# CPU optimize for the given processor.\r
-# default = k6\r
-# GLIDE path to Glide3 SDK library files; used with FX.\r
-# default = $(TOP)/lib/glide3\r
-# FX=1 build for 3dfx Glide3. Note that this disables\r
-# compilation of most DMesa code and requires fxMesa.\r
-# As a consequence, you'll need the DJGPP Glide3\r
-# library to build any application.\r
-# default = no\r
-# DXE=1 use DXE modules. The resolution object file must be\r
-# present in the `lib' directory in order to use this\r
-# option (see README.DJ for details).\r
-# default = no\r
-#\r
-# Targets:\r
-# <file.exe> build a specific file\r
-#\r
-\r
-\r
-\r
-.PHONY : all\r
-.SUFFIXES : .c .o .exe\r
-\r
-TOP = ..\r
-CPU ?= k6\r
-GLIDE ?= $(TOP)/lib/glide3\r
-\r
-CC = gcc\r
-CFLAGS = -Wall -W -pedantic\r
-CFLAGS += -O2 -ffast-math -mcpu=$(CPU)\r
-CFLAGS += -I$(TOP)/include\r
-\r
-LD = gxx\r
-LDFLAGS = -s -L$(TOP)/lib\r
-\r
-ifeq ($(DXE),1)\r
-DXE3TABLE = $(TOP)/lib/dxe3tbl.o\r
-LDLIBS += -liglut -liglu -ligl -ldl\r
-else\r
-LDLIBS = -lglut -lglu -lgl\r
-ifeq ($(FX),1)\r
-LDFLAGS += -L$(GLIDE)\r
-LDLIBS += -lglid3\r
-endif\r
-endif\r
-\r
-.c.o:\r
- $(CC) -o $@ $(CFLAGS) -c $<\r
-.o.exe:\r
- $(LD) -o $@ $(LDFLAGS) $(DXE3TABLE) $< $(LDLIBS)\r
-\r
-all:\r
- $(error Must specify <filename.exe> to build)\r
+# Mesa 3-D graphics library
+# Version: 4.0
+#
+# Copyright (C) 1999 Brian Paul All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# DOS/DJGPP samples makefile v1.4 for Mesa
+#
+# Copyright (C) 2002 - Borca Daniel
+# Email : dborca@yahoo.com
+# Web : http://www.geocities.com/dborca
+
+
+#
+# Available options:
+#
+# Environment variables:
+# CPU optimize for the given processor.
+# default = k6
+# GLIDE path to Glide3 SDK library files; used with FX.
+# default = $(TOP)/lib/glide3
+# FX=1 build for 3dfx Glide3. Note that this disables
+# compilation of most DMesa code and requires fxMesa.
+# As a consequence, you'll need the DJGPP Glide3
+# library to build any application.
+# default = no
+# DXE=1 use DXE modules (see README.DJ for details).
+# default = no
+#
+# Targets:
+# <file.exe> build a specific file
+#
+
+
+
+.PHONY : all
+.SUFFIXES : .c .o .exe
+
+TOP = ../..
+CPU ?= k6
+GLIDE ?= $(TOP)/lib/glide3
+
+CC = gcc
+CFLAGS = -Wall -W -pedantic
+CFLAGS += -O2 -ffast-math -mcpu=$(CPU)
+CFLAGS += -I$(TOP)/include -I../util
+
+LD = gxx
+LDFLAGS = -s -L$(TOP)/lib
+
+ifeq ($(DXE),1)
+LDLIBS += -liglut -liglu -ligl
+else
+LDLIBS = -lglut -lglu -lgl
+ifeq ($(FX),1)
+LDFLAGS += -L$(GLIDE)
+LDLIBS += -lglid3
+endif
+endif
+
+.c.o:
+ $(CC) -o $@ $(CFLAGS) -c $<
+.o.exe:
+ $(LD) -o $@ $(LDFLAGS) $< $(LDLIBS)
+
+all:
+ $(error Must specify <filename.exe> to build)
-# 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
-# DOS/DJGPP glu makefile v1.3 for Mesa\r
-#\r
-# Copyright (C) 2002 - Borca Daniel\r
-# Email : dborca@yahoo.com\r
-# Web : http://www.geocities.com/dborca\r
-\r
-\r
-#\r
-# Available options:\r
-#\r
-# Environment variables:\r
-# CFLAGS\r
-#\r
-# Targets:\r
-# all: build GLU\r
-# clean: remove object files\r
-#\r
-\r
-\r
-\r
-.PHONY: all clean\r
-\r
-TOP = ..\r
-LIBDIR = $(TOP)/lib\r
-GLU_LIB = libglu.a\r
-GLU_DXE = glu.dxe\r
-GLU_IMP = libiglu.a\r
-\r
-CC = gcc\r
-CFLAGS += -I$(TOP)/include\r
-\r
-AR = ar\r
-ARFLAGS = rus\r
-\r
-HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)\r
-\r
-ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)\r
-UNLINK = del $(subst /,\,$(1))\r
-else\r
-UNLINK = $(RM) $(1)\r
-endif\r
-\r
-CORE_SOURCES = \\r
- glu.c \\r
- mipmap.c \\r
- nurbs.c \\r
- nurbscrv.c \\r
- nurbssrf.c \\r
- nurbsutl.c \\r
- polytest.c \\r
- project.c \\r
- quadric.c \\r
- tess.c \\r
- tesselat.c\r
-\r
-SOURCES = $(CORE_SOURCES)\r
-\r
-OBJECTS = $(SOURCES:.c=.o)\r
-\r
-.c.o:\r
- $(CC) -o $@ $(CFLAGS) -c $<\r
-\r
-all: $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP)\r
-\r
-$(LIBDIR)/$(GLU_LIB): $(OBJECTS)\r
- $(AR) $(ARFLAGS) $(LIBDIR)/$(GLU_LIB) $(OBJECTS)\r
-\r
-$(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP): $(OBJECTS)\r
-ifeq ($(HAVEDXE3),)\r
- $(warning Missing DXE3 package... Skipping $(GLU_DXE))\r
-else\r
- -dxe3gen -o $(LIBDIR)/$(GLU_DXE) -I $(LIBDIR)/$(GLU_IMP) -D "MesaGLU DJGPP" -E _glu -P gl.dxe -U $(OBJECTS)\r
-endif\r
-\r
-clean:\r
- -$(call UNLINK,*.o)\r
-\r
--include depend\r
+# Mesa 3-D graphics library
+# Version: 4.0
+#
+# Copyright (C) 1999 Brian Paul All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# DOS/DJGPP glu makefile v1.4 for Mesa
+#
+# Copyright (C) 2002 - Borca Daniel
+# Email : dborca@yahoo.com
+# Web : http://www.geocities.com/dborca
+
+
+#
+# Available options:
+#
+# Environment variables:
+# CFLAGS
+#
+# Targets:
+# all: build GLU
+# clean: remove object files
+#
+
+
+
+.PHONY: all clean
+
+TOP = ../../..
+LIBDIR = $(TOP)/lib
+GLU_LIB = libglu.a
+GLU_DXE = glu.dxe
+GLU_IMP = libiglu.a
+
+export LD_LIBRARY_PATH := $(LD_LIBRARY_PATH);$(LIBDIR)
+
+CC = gcc
+CFLAGS += -I$(TOP)/include
+
+AR = ar
+ARFLAGS = rus
+
+HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)
+
+ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)
+UNLINK = del $(subst /,\,$(1))
+else
+UNLINK = $(RM) $(1)
+endif
+
+CORE_SOURCES = \
+ glu.c \
+ mipmap.c \
+ nurbs.c \
+ nurbscrv.c \
+ nurbssrf.c \
+ nurbsutl.c \
+ polytest.c \
+ project.c \
+ quadric.c \
+ tess.c \
+ tesselat.c
+
+SOURCES = $(CORE_SOURCES)
+
+OBJECTS = $(SOURCES:.c=.o)
+
+.c.o:
+ $(CC) -o $@ $(CFLAGS) -c $<
+
+all: $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP)
+
+$(LIBDIR)/$(GLU_LIB): $(OBJECTS)
+ $(AR) $(ARFLAGS) $(LIBDIR)/$(GLU_LIB) $(OBJECTS)
+
+$(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP): $(OBJECTS)
+ifeq ($(HAVEDXE3),)
+ $(warning Missing DXE3 package... Skipping $(GLU_DXE))
+else
+ -dxe3gen -o $(LIBDIR)/$(GLU_DXE) -Y $(LIBDIR)/$(GLU_IMP) -D "MesaGLU DJGPP" -E _glu -P gl.dxe -U $(OBJECTS)
+endif
+
+clean:
+ -$(call UNLINK,*.o)
+
+-include depend
-# 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
-# DOS/DJGPP glu makefile v1.3 for Mesa\r
-#\r
-# Copyright (C) 2002 - Borca Daniel\r
-# Email : dborca@yahoo.com\r
-# Web : http://www.geocities.com/dborca\r
-\r
-\r
-#\r
-# Available options:\r
-#\r
-# Environment variables:\r
-# CFLAGS\r
-#\r
-# Targets:\r
-# all: build GLU\r
-# clean: remove object files\r
-#\r
-\r
-\r
-\r
-.PHONY: all clean\r
-\r
-TOP = ..\r
-LIBDIR = $(TOP)/lib\r
-GLU_LIB = libglu.a\r
-GLU_DXE = glu.dxe\r
-GLU_IMP = libiglu.a\r
-\r
-CC = gcc\r
-CFLAGS += -DNDEBUG -DLIBRARYBUILD -I$(TOP)/include -Iinclude\r
-CXX = gpp\r
-CXXFLAGS = $(CFLAGS) -Ilibnurbs/internals -Ilibnurbs/interface -Ilibnurbs/nurbtess\r
-\r
-AR = ar\r
-ARFLAGS = rus\r
-\r
-HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)\r
-\r
-ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)\r
-UNLINK = del $(subst /,\,$(1))\r
-else\r
-UNLINK = $(RM) $(1)\r
-endif\r
-\r
-C_SOURCES = \\r
- libutil/error.c \\r
- libutil/glue.c \\r
- libutil/mipmap.c \\r
- libutil/project.c \\r
- libutil/quad.c \\r
- libutil/registry.c \\r
- libtess/dict.c \\r
- libtess/geom.c \\r
- libtess/memalloc.c \\r
- libtess/mesh.c \\r
- libtess/normal.c \\r
- libtess/priorityq.c \\r
- libtess/render.c \\r
- libtess/sweep.c \\r
- libtess/tess.c \\r
- libtess/tessmono.c\r
-\r
-CC_SOURCES = \\r
- libnurbs/interface/bezierEval.cc \\r
- libnurbs/interface/bezierPatch.cc \\r
- libnurbs/interface/bezierPatchMesh.cc \\r
- libnurbs/interface/glcurveval.cc \\r
- libnurbs/interface/glinterface.cc \\r
- libnurbs/interface/glrenderer.cc \\r
- libnurbs/interface/glsurfeval.cc \\r
- libnurbs/interface/incurveeval.cc \\r
- libnurbs/interface/insurfeval.cc \\r
- libnurbs/internals/arc.cc \\r
- libnurbs/internals/arcsorter.cc \\r
- libnurbs/internals/arctess.cc \\r
- libnurbs/internals/backend.cc \\r
- libnurbs/internals/basiccrveval.cc \\r
- libnurbs/internals/basicsurfeval.cc \\r
- libnurbs/internals/bin.cc \\r
- libnurbs/internals/bufpool.cc \\r
- libnurbs/internals/cachingeval.cc \\r
- libnurbs/internals/ccw.cc \\r
- libnurbs/internals/coveandtiler.cc \\r
- libnurbs/internals/curve.cc \\r
- libnurbs/internals/curvelist.cc \\r
- libnurbs/internals/curvesub.cc \\r
- libnurbs/internals/dataTransform.cc \\r
- libnurbs/internals/displaylist.cc \\r
- libnurbs/internals/flist.cc \\r
- libnurbs/internals/flistsorter.cc \\r
- libnurbs/internals/hull.cc \\r
- libnurbs/internals/intersect.cc \\r
- libnurbs/internals/knotvector.cc \\r
- libnurbs/internals/mapdesc.cc \\r
- libnurbs/internals/mapdescv.cc \\r
- libnurbs/internals/maplist.cc \\r
- libnurbs/internals/mesher.cc \\r
- libnurbs/internals/monoTriangulationBackend.cc \\r
- libnurbs/internals/monotonizer.cc \\r
- libnurbs/internals/mycode.cc \\r
- libnurbs/internals/nurbsinterfac.cc \\r
- libnurbs/internals/nurbstess.cc \\r
- libnurbs/internals/patch.cc \\r
- libnurbs/internals/patchlist.cc \\r
- libnurbs/internals/quilt.cc \\r
- libnurbs/internals/reader.cc \\r
- libnurbs/internals/renderhints.cc \\r
- libnurbs/internals/slicer.cc \\r
- libnurbs/internals/sorter.cc \\r
- libnurbs/internals/splitarcs.cc \\r
- libnurbs/internals/subdivider.cc \\r
- libnurbs/internals/tobezier.cc \\r
- libnurbs/internals/trimline.cc \\r
- libnurbs/internals/trimregion.cc \\r
- libnurbs/internals/trimvertpool.cc \\r
- libnurbs/internals/uarray.cc \\r
- libnurbs/internals/varray.cc \\r
- libnurbs/nurbtess/directedLine.cc \\r
- libnurbs/nurbtess/gridWrap.cc \\r
- libnurbs/nurbtess/monoChain.cc \\r
- libnurbs/nurbtess/monoPolyPart.cc \\r
- libnurbs/nurbtess/monoTriangulation.cc \\r
- libnurbs/nurbtess/partitionX.cc \\r
- libnurbs/nurbtess/partitionY.cc \\r
- libnurbs/nurbtess/polyDBG.cc \\r
- libnurbs/nurbtess/polyUtil.cc \\r
- libnurbs/nurbtess/primitiveStream.cc \\r
- libnurbs/nurbtess/quicksort.cc \\r
- libnurbs/nurbtess/rectBlock.cc \\r
- libnurbs/nurbtess/sampleComp.cc \\r
- libnurbs/nurbtess/sampleCompBot.cc \\r
- libnurbs/nurbtess/sampleCompRight.cc \\r
- libnurbs/nurbtess/sampleCompTop.cc \\r
- libnurbs/nurbtess/sampleMonoPoly.cc \\r
- libnurbs/nurbtess/sampledLine.cc \\r
- libnurbs/nurbtess/searchTree.cc\r
-\r
-SOURCES = $(C_SOURCES) $(CC_SOURCES)\r
-\r
-OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))\r
-\r
-.c.o:\r
- $(CC) -o $@ $(CFLAGS) -c $<\r
-.cc.o:\r
- $(CXX) -o $@ $(CXXFLAGS) -c $<\r
-\r
-all: $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP)\r
-\r
-$(LIBDIR)/$(GLU_LIB): $(OBJECTS)\r
- $(AR) $(ARFLAGS) $(LIBDIR)/$(GLU_LIB) $(OBJECTS)\r
-\r
-$(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP): $(OBJECTS)\r
-ifeq ($(HAVEDXE3),)\r
- $(warning Missing DXE3 package... Skipping $(GLU_DXE))\r
-else\r
- -dxe3gen -o $(LIBDIR)/$(GLU_DXE) -I $(LIBDIR)/$(GLU_IMP) -D "MesaGLU/SGI DJGPP" -E _glu -P gl.dxe -U $(OBJECTS)\r
-endif\r
-\r
-clean:\r
- -$(call UNLINK,libutil/*.o)\r
- -$(call UNLINK,libtess/*.o)\r
- -$(call UNLINK,libnurbs/interface/*.o)\r
- -$(call UNLINK,libnurbs/internals/*.o)\r
- -$(call UNLINK,libnurbs/nurbtess/*.o)\r
-\r
--include depend\r
+# Mesa 3-D graphics library
+# Version: 4.0
+#
+# Copyright (C) 1999 Brian Paul All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# DOS/DJGPP glu makefile v1.4 for Mesa
+#
+# Copyright (C) 2002 - Borca Daniel
+# Email : dborca@yahoo.com
+# Web : http://www.geocities.com/dborca
+
+
+#
+# Available options:
+#
+# Environment variables:
+# CFLAGS
+#
+# Targets:
+# all: build GLU
+# clean: remove object files
+#
+
+
+
+.PHONY: all clean
+
+TOP = ../../..
+LIBDIR = $(TOP)/lib
+GLU_LIB = libglu.a
+GLU_DXE = glu.dxe
+GLU_IMP = libiglu.a
+
+export LD_LIBRARY_PATH := $(LD_LIBRARY_PATH);$(LIBDIR)
+
+CC = gcc
+CFLAGS += -DNDEBUG -DLIBRARYBUILD -I$(TOP)/include -Iinclude
+CXX = gpp
+CXXFLAGS = $(CFLAGS) -Ilibnurbs/internals -Ilibnurbs/interface -Ilibnurbs/nurbtess
+
+AR = ar
+ARFLAGS = rus
+
+HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)
+
+ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)
+UNLINK = del $(subst /,\,$(1))
+else
+UNLINK = $(RM) $(1)
+endif
+
+C_SOURCES = \
+ libutil/error.c \
+ libutil/glue.c \
+ libutil/mipmap.c \
+ libutil/project.c \
+ libutil/quad.c \
+ libutil/registry.c \
+ libtess/dict.c \
+ libtess/geom.c \
+ libtess/memalloc.c \
+ libtess/mesh.c \
+ libtess/normal.c \
+ libtess/priorityq.c \
+ libtess/render.c \
+ libtess/sweep.c \
+ libtess/tess.c \
+ libtess/tessmono.c
+
+CC_SOURCES = \
+ libnurbs/interface/bezierEval.cc \
+ libnurbs/interface/bezierPatch.cc \
+ libnurbs/interface/bezierPatchMesh.cc \
+ libnurbs/interface/glcurveval.cc \
+ libnurbs/interface/glinterface.cc \
+ libnurbs/interface/glrenderer.cc \
+ libnurbs/interface/glsurfeval.cc \
+ libnurbs/interface/incurveeval.cc \
+ libnurbs/interface/insurfeval.cc \
+ libnurbs/internals/arc.cc \
+ libnurbs/internals/arcsorter.cc \
+ libnurbs/internals/arctess.cc \
+ libnurbs/internals/backend.cc \
+ libnurbs/internals/basiccrveval.cc \
+ libnurbs/internals/basicsurfeval.cc \
+ libnurbs/internals/bin.cc \
+ libnurbs/internals/bufpool.cc \
+ libnurbs/internals/cachingeval.cc \
+ libnurbs/internals/ccw.cc \
+ libnurbs/internals/coveandtiler.cc \
+ libnurbs/internals/curve.cc \
+ libnurbs/internals/curvelist.cc \
+ libnurbs/internals/curvesub.cc \
+ libnurbs/internals/dataTransform.cc \
+ libnurbs/internals/displaylist.cc \
+ libnurbs/internals/flist.cc \
+ libnurbs/internals/flistsorter.cc \
+ libnurbs/internals/hull.cc \
+ libnurbs/internals/intersect.cc \
+ libnurbs/internals/knotvector.cc \
+ libnurbs/internals/mapdesc.cc \
+ libnurbs/internals/mapdescv.cc \
+ libnurbs/internals/maplist.cc \
+ libnurbs/internals/mesher.cc \
+ libnurbs/internals/monoTriangulationBackend.cc \
+ libnurbs/internals/monotonizer.cc \
+ libnurbs/internals/mycode.cc \
+ libnurbs/internals/nurbsinterfac.cc \
+ libnurbs/internals/nurbstess.cc \
+ libnurbs/internals/patch.cc \
+ libnurbs/internals/patchlist.cc \
+ libnurbs/internals/quilt.cc \
+ libnurbs/internals/reader.cc \
+ libnurbs/internals/renderhints.cc \
+ libnurbs/internals/slicer.cc \
+ libnurbs/internals/sorter.cc \
+ libnurbs/internals/splitarcs.cc \
+ libnurbs/internals/subdivider.cc \
+ libnurbs/internals/tobezier.cc \
+ libnurbs/internals/trimline.cc \
+ libnurbs/internals/trimregion.cc \
+ libnurbs/internals/trimvertpool.cc \
+ libnurbs/internals/uarray.cc \
+ libnurbs/internals/varray.cc \
+ libnurbs/nurbtess/directedLine.cc \
+ libnurbs/nurbtess/gridWrap.cc \
+ libnurbs/nurbtess/monoChain.cc \
+ libnurbs/nurbtess/monoPolyPart.cc \
+ libnurbs/nurbtess/monoTriangulation.cc \
+ libnurbs/nurbtess/partitionX.cc \
+ libnurbs/nurbtess/partitionY.cc \
+ libnurbs/nurbtess/polyDBG.cc \
+ libnurbs/nurbtess/polyUtil.cc \
+ libnurbs/nurbtess/primitiveStream.cc \
+ libnurbs/nurbtess/quicksort.cc \
+ libnurbs/nurbtess/rectBlock.cc \
+ libnurbs/nurbtess/sampleComp.cc \
+ libnurbs/nurbtess/sampleCompBot.cc \
+ libnurbs/nurbtess/sampleCompRight.cc \
+ libnurbs/nurbtess/sampleCompTop.cc \
+ libnurbs/nurbtess/sampleMonoPoly.cc \
+ libnurbs/nurbtess/sampledLine.cc \
+ libnurbs/nurbtess/searchTree.cc
+
+SOURCES = $(C_SOURCES) $(CC_SOURCES)
+
+OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))
+
+.c.o:
+ $(CC) -o $@ $(CFLAGS) -c $<
+.cc.o:
+ $(CXX) -o $@ $(CXXFLAGS) -c $<
+
+all: $(LIBDIR)/$(GLU_LIB) $(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP)
+
+$(LIBDIR)/$(GLU_LIB): $(OBJECTS)
+ $(AR) $(ARFLAGS) $(LIBDIR)/$(GLU_LIB) $(OBJECTS)
+
+$(LIBDIR)/$(GLU_DXE) $(LIBDIR)/$(GLU_IMP): $(OBJECTS)
+ifeq ($(HAVEDXE3),)
+ $(warning Missing DXE3 package... Skipping $(GLU_DXE))
+else
+ -dxe3gen -o $(LIBDIR)/$(GLU_DXE) -Y $(LIBDIR)/$(GLU_IMP) -D "MesaGLU/SGI DJGPP" -E _glu -P gl.dxe -U $(OBJECTS)
+endif
+
+clean:
+ -$(call UNLINK,libutil/*.o)
+ -$(call UNLINK,libtess/*.o)
+ -$(call UNLINK,libnurbs/interface/*.o)
+ -$(call UNLINK,libnurbs/internals/*.o)
+ -$(call UNLINK,libnurbs/nurbtess/*.o)
+
+-include depend
-# 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
-# DOS/DJGPP glut makefile v1.3 for Mesa\r
-#\r
-# Copyright (C) 2002 - Borca Daniel\r
-# Email : dborca@yahoo.com\r
-# Web : http://www.geocities.com/dborca\r
-\r
-\r
-#\r
-# Available options:\r
-#\r
-# Environment variables:\r
-# CFLAGS\r
-#\r
-# MKGLUT absolute path to original GLUT.\r
-# default = $(TOP)/src-glut\r
-#\r
-# Targets:\r
-# all: build GLUT\r
-# clean: remove object files\r
-#\r
-\r
-\r
-\r
-.PHONY: all clean\r
-\r
-TOP = ..\r
-GLIDE ?= $(TOP)/include/glide3\r
-MKGLUT ?= $(TOP)/src-glut\r
-LIBDIR = $(TOP)/lib\r
-GLUT_LIB = libglut.a\r
-GLUT_DXE = glut.dxe\r
-GLUT_IMP = libiglut.a\r
-\r
-CC = gcc\r
-CFLAGS += -I- -I$(TOP)/include -I. -I$(MKGLUT) -IPC_HW\r
-\r
-AR = ar\r
-ARFLAGS = rus\r
-\r
-HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)\r
-\r
-ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)\r
-UNLINK = del $(subst /,\,$(1))\r
-else\r
-UNLINK = $(RM) $(1)\r
-endif\r
-\r
-CORE_SOURCES = \\r
- callback.c \\r
- color.c \\r
- extens.c \\r
- init.c \\r
- menu.c \\r
- mouse.c \\r
- overlay.c \\r
- state.c \\r
- window.c\r
-\r
-PC_HW_SOURCES = \\r
- PC_HW/pc_hw.c \\r
- PC_HW/pc_keyb.c \\r
- PC_HW/pc_mouse.c \\r
- PC_HW/pc_timer.c \\r
- PC_HW/pc_irq.S\r
-\r
-MKGLUT_SOURCES = \\r
- $(MKGLUT)/glut_bitmap.c \\r
- $(MKGLUT)/glut_bwidth.c \\r
- $(MKGLUT)/glut_stroke.c \\r
- $(MKGLUT)/glut_swidth.c \\r
- $(MKGLUT)/glut_shapes.c \\r
- $(MKGLUT)/glut_teapot.c \\r
- $(MKGLUT)/glut_8x13.c \\r
- $(MKGLUT)/glut_9x15.c \\r
- $(MKGLUT)/glut_hel10.c \\r
- $(MKGLUT)/glut_hel12.c \\r
- $(MKGLUT)/glut_hel18.c \\r
- $(MKGLUT)/glut_tr10.c \\r
- $(MKGLUT)/glut_tr24.c \\r
- $(MKGLUT)/glut_roman.c \\r
- $(MKGLUT)/glut_mroman.c \\r
- $(MKGLUT)/glut_util.c\r
-\r
-SOURCES = $(CORE_SOURCES) $(PC_HW_SOURCES) $(MKGLUT_SOURCES)\r
-\r
-OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))\r
-\r
-.c.o:\r
- $(CC) -o $@ $(CFLAGS) -c $<\r
-.S.o:\r
- $(CC) -o $@ $(CFLAGS) -c $<\r
-.s.o:\r
- $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $<\r
-\r
-all: $(LIBDIR)/$(GLUT_LIB) $(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP)\r
-\r
-$(LIBDIR)/$(GLUT_LIB): $(OBJECTS)\r
- $(AR) $(ARFLAGS) $(LIBDIR)/$(GLUT_LIB) $(OBJECTS)\r
-\r
-$(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP): $(OBJECTS)\r
-ifeq ($(HAVEDXE3),)\r
- $(warning Missing DXE3 package... Skipping $(GLUT_DXE))\r
-else\r
- -dxe3gen -o $(LIBDIR)/$(GLUT_DXE) -I $(LIBDIR)/$(GLUT_IMP) -D "MesaGLUT DJGPP" -E _glut -P gl.dxe -P glu.dxe -U $(OBJECTS)\r
-endif\r
-\r
-clean:\r
- -$(call UNLINK,*.o)\r
- -$(call UNLINK,PC_HW/*.o)\r
- -$(call UNLINK,$(MKGLUT)/*.o)\r
-\r
--include depend\r
+# Mesa 3-D graphics library
+# Version: 4.0
+#
+# Copyright (C) 1999 Brian Paul All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# DOS/DJGPP glut makefile v1.4 for Mesa
+#
+# Copyright (C) 2002 - Borca Daniel
+# Email : dborca@yahoo.com
+# Web : http://www.geocities.com/dborca
+
+
+#
+# Available options:
+#
+# Environment variables:
+# CFLAGS
+#
+# MKGLUT absolute path to original GLUT.
+# default = $(TOP)/src-glut
+#
+# Targets:
+# all: build GLUT
+# clean: remove object files
+#
+
+
+
+.PHONY: all clean
+
+TOP = ../../..
+GLIDE ?= $(TOP)/include/glide3
+MKGLUT ?= $(TOP)/src/glut/glx
+LIBDIR = $(TOP)/lib
+GLUT_LIB = libglut.a
+GLUT_DXE = glut.dxe
+GLUT_IMP = libiglut.a
+
+export LD_LIBRARY_PATH := $(LD_LIBRARY_PATH);$(LIBDIR)
+
+CC = gcc
+CFLAGS += -I- -I$(TOP)/include -I. -I$(MKGLUT) -IPC_HW
+
+AR = ar
+ARFLAGS = rus
+
+HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)
+
+ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)
+UNLINK = del $(subst /,\,$(1))
+else
+UNLINK = $(RM) $(1)
+endif
+
+CORE_SOURCES = \
+ callback.c \
+ color.c \
+ extens.c \
+ init.c \
+ menu.c \
+ mouse.c \
+ overlay.c \
+ state.c \
+ window.c
+
+PC_HW_SOURCES = \
+ PC_HW/pc_hw.c \
+ PC_HW/pc_keyb.c \
+ PC_HW/pc_mouse.c \
+ PC_HW/pc_timer.c \
+ PC_HW/pc_irq.S
+
+MKGLUT_SOURCES = \
+ $(MKGLUT)/glut_bitmap.c \
+ $(MKGLUT)/glut_bwidth.c \
+ $(MKGLUT)/glut_stroke.c \
+ $(MKGLUT)/glut_swidth.c \
+ $(MKGLUT)/glut_shapes.c \
+ $(MKGLUT)/glut_teapot.c \
+ $(MKGLUT)/glut_8x13.c \
+ $(MKGLUT)/glut_9x15.c \
+ $(MKGLUT)/glut_hel10.c \
+ $(MKGLUT)/glut_hel12.c \
+ $(MKGLUT)/glut_hel18.c \
+ $(MKGLUT)/glut_tr10.c \
+ $(MKGLUT)/glut_tr24.c \
+ $(MKGLUT)/glut_roman.c \
+ $(MKGLUT)/glut_mroman.c \
+ $(MKGLUT)/glut_util.c
+
+SOURCES = $(CORE_SOURCES) $(PC_HW_SOURCES) $(MKGLUT_SOURCES)
+
+OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))
+
+.c.o:
+ $(CC) -o $@ $(CFLAGS) -c $<
+.S.o:
+ $(CC) -o $@ $(CFLAGS) -c $<
+.s.o:
+ $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $<
+
+all: $(LIBDIR)/$(GLUT_LIB) $(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP)
+
+$(LIBDIR)/$(GLUT_LIB): $(OBJECTS)
+ $(AR) $(ARFLAGS) $(LIBDIR)/$(GLUT_LIB) $(OBJECTS)
+
+$(LIBDIR)/$(GLUT_DXE) $(LIBDIR)/$(GLUT_IMP): $(OBJECTS)
+ifeq ($(HAVEDXE3),)
+ $(warning Missing DXE3 package... Skipping $(GLUT_DXE))
+else
+ -dxe3gen -o $(LIBDIR)/$(GLUT_DXE) -Y $(LIBDIR)/$(GLUT_IMP) -D "MesaGLUT DJGPP" -E _glut -P gl.dxe -P glu.dxe -U $(OBJECTS)
+endif
+
+clean:
+ -$(call UNLINK,*.o)
+ -$(call UNLINK,PC_HW/*.o)
+ -$(call UNLINK,$(MKGLUT)/*.o)
+
+-include depend
-/*\r
- * PC/HW routine collection v1.3 for DOS/DJGPP\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 <fcntl.h>\r
-#include <sys/stat.h> /* for mode definitions */\r
-#include <stdio.h>\r
-#include <stdlib.h>\r
-#include <unistd.h>\r
-\r
-#include "pc_hw.h"\r
-\r
-/*\r
- * atexit\r
- */\r
-#define MAX_ATEXIT 32\r
-\r
-static volatile int atexitcnt;\r
-static VFUNC atexittbl[MAX_ATEXIT];\r
-\r
-static void __attribute__((destructor)) doexit (void)\r
-{\r
- while (atexitcnt) atexittbl[--atexitcnt]();\r
-}\r
-\r
-int pc_clexit (VFUNC f)\r
-{\r
- int i;\r
-\r
- for (i=0;i<atexitcnt;i++) {\r
- if (atexittbl[i]==f) {\r
- for (atexitcnt--;i<atexitcnt;i++) atexittbl[i] = atexittbl[i+1];\r
- atexittbl[i] = 0;\r
- return 0;\r
- }\r
- }\r
- return -1;\r
-}\r
-\r
-int pc_atexit (VFUNC f)\r
-{\r
- pc_clexit(f);\r
- if (atexitcnt<MAX_ATEXIT) {\r
- atexittbl[atexitcnt++] = f;\r
- return 0;\r
- }\r
- return -1;\r
-}\r
-\r
-/*\r
- * locked memory allocation\r
- */\r
-void *pc_malloc (size_t size)\r
-{\r
- void *p = malloc(size);\r
-\r
- if (p) {\r
- if (_go32_dpmi_lock_data(p, size)) {\r
- free(p);\r
- return NULL;\r
- }\r
- }\r
-\r
- return p;\r
-}\r
-\r
-/*\r
- * standard redirection\r
- */\r
-static char outname[L_tmpnam];\r
-static int h_out, h_outbak;\r
-static char errname[L_tmpnam];\r
-static int h_err, h_errbak;\r
-\r
-int pc_open_stdout (void)\r
-{\r
- tmpnam(outname);\r
-\r
- if ((h_out=open(outname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {\r
- h_outbak = dup(STDOUT_FILENO);\r
- fflush(stdout);\r
- dup2(h_out, STDOUT_FILENO);\r
- }\r
-\r
- return h_out;\r
-}\r
-\r
-void pc_close_stdout (void)\r
-{\r
- FILE *f;\r
- char *line = alloca(512);\r
-\r
- if (h_out > 0) {\r
- dup2(h_outbak, STDOUT_FILENO);\r
- close(h_out);\r
- close(h_outbak);\r
-\r
- f = fopen(outname, "rt");\r
- while (fgets(line, 512, f)) {\r
- fputs(line, stdout);\r
- }\r
- fclose(f);\r
-\r
- remove(outname);\r
- }\r
-}\r
-\r
-int pc_open_stderr (void)\r
-{\r
- tmpnam(errname);\r
-\r
- if ((h_err=open(errname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {\r
- h_errbak = dup(STDERR_FILENO);\r
- fflush(stderr);\r
- dup2(h_err, STDERR_FILENO);\r
- }\r
-\r
- return h_err;\r
-}\r
-\r
-void pc_close_stderr (void)\r
-{\r
- FILE *f;\r
- char *line = alloca(512);\r
-\r
- if (h_err > 0) {\r
- dup2(h_errbak, STDERR_FILENO);\r
- close(h_err);\r
- close(h_errbak);\r
-\r
- f = fopen(errname, "rt");\r
- while (fgets(line, 512, f)) {\r
- fputs(line, stderr);\r
- }\r
- fclose(f);\r
-\r
- remove(errname);\r
- }\r
-}\r
+/*
+ * PC/HW routine collection v1.3 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <dpmi.h>
+#include <fcntl.h>
+#include <sys/stat.h> /* for mode definitions */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include "pc_hw.h"
+
+/*
+ * atexit
+ */
+#define MAX_ATEXIT 32
+
+static volatile int atexitcnt;
+static VFUNC atexittbl[MAX_ATEXIT];
+
+static void __attribute__((destructor)) doexit (void)
+{
+ while (atexitcnt) atexittbl[--atexitcnt]();
+}
+
+int pc_clexit (VFUNC f)
+{
+ int i;
+
+ for (i=0;i<atexitcnt;i++) {
+ if (atexittbl[i]==f) {
+ for (atexitcnt--;i<atexitcnt;i++) atexittbl[i] = atexittbl[i+1];
+ atexittbl[i] = 0;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+int pc_atexit (VFUNC f)
+{
+ pc_clexit(f);
+ if (atexitcnt<MAX_ATEXIT) {
+ atexittbl[atexitcnt++] = f;
+ return 0;
+ }
+ return -1;
+}
+
+/*
+ * locked memory allocation
+ */
+void *pc_malloc (size_t size)
+{
+ void *p = malloc(size);
+
+ if (p) {
+ if (_go32_dpmi_lock_data(p, size)) {
+ free(p);
+ return NULL;
+ }
+ }
+
+ return p;
+}
+
+/*
+ * standard redirection
+ */
+static char outname[L_tmpnam];
+static int h_out, h_outbak;
+static char errname[L_tmpnam];
+static int h_err, h_errbak;
+
+int pc_open_stdout (void)
+{
+ tmpnam(outname);
+
+ if ((h_out=open(outname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {
+ h_outbak = dup(STDOUT_FILENO);
+ fflush(stdout);
+ dup2(h_out, STDOUT_FILENO);
+ }
+
+ return h_out;
+}
+
+void pc_close_stdout (void)
+{
+ FILE *f;
+ char *line = alloca(512);
+
+ if (h_out > 0) {
+ dup2(h_outbak, STDOUT_FILENO);
+ close(h_out);
+ close(h_outbak);
+
+ f = fopen(outname, "rt");
+ while (fgets(line, 512, f)) {
+ fputs(line, stdout);
+ }
+ fclose(f);
+
+ remove(outname);
+ }
+}
+
+int pc_open_stderr (void)
+{
+ tmpnam(errname);
+
+ if ((h_err=open(errname, O_WRONLY | O_CREAT | O_TEXT | O_TRUNC, S_IREAD | S_IWRITE)) > 0) {
+ h_errbak = dup(STDERR_FILENO);
+ fflush(stderr);
+ dup2(h_err, STDERR_FILENO);
+ }
+
+ return h_err;
+}
+
+void pc_close_stderr (void)
+{
+ FILE *f;
+ char *line = alloca(512);
+
+ if (h_err > 0) {
+ dup2(h_errbak, STDERR_FILENO);
+ close(h_err);
+ close(h_errbak);
+
+ f = fopen(errname, "rt");
+ while (fgets(line, 512, f)) {
+ fputs(line, stderr);
+ }
+ fclose(f);
+
+ remove(errname);
+ }
+}
-/*\r
- * PC/HW routine collection v1.3 for DOS/DJGPP\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#ifndef PC_HW_H_included\r
-#define PC_HW_H_included\r
-\r
-#include <dpmi.h>\r
-#include <stdlib.h>\r
-\r
-/*\r
- * misc C definitions\r
- */\r
-#define FALSE 0\r
-#define TRUE !FALSE\r
-\r
-#define MIN(x,y) (((x) < (y)) ? (x) : (y))\r
-#define MAX(x,y) (((x) > (y)) ? (x) : (y))\r
-#define MID(x,y,z) MAX((x), MIN((y), (z)))\r
-\r
-typedef void (*VFUNC) (void);\r
-typedef void (*PFUNC) (void *);\r
-typedef void (*MFUNC) (int x, int y, int z, int b);\r
-\r
-/*\r
- * atexit\r
- */\r
-int pc_atexit (VFUNC f);\r
-int pc_clexit (VFUNC f);\r
-\r
-/*\r
- * locked memory\r
- */\r
-#define ENDOFUNC(x) static void x##_end() { }\r
-#define LOCKFUNC(x) _go32_dpmi_lock_code((void *)x, (long)x##_end - (long)x)\r
-#define LOCKDATA(x) _go32_dpmi_lock_data((void *)&x, sizeof(x))\r
-#define LOCKBUFF(x, l) _go32_dpmi_lock_data((void *)x, l)\r
-\r
-void *pc_malloc (size_t size);\r
-\r
-/*\r
- * IRQ\r
- */\r
-#define ENABLE() __asm __volatile ("sti")\r
-#define DISABLE() __asm __volatile ("cli")\r
-\r
-extern int pc_install_irq (int i, int (*handler) ());\r
-extern int pc_remove_irq (int i);\r
-\r
-/*\r
- * keyboard\r
- */\r
-#define KB_SHIFT_FLAG 0x0001\r
-#define KB_CTRL_FLAG 0x0002\r
-#define KB_ALT_FLAG 0x0004\r
-#define KB_LWIN_FLAG 0x0008\r
-#define KB_RWIN_FLAG 0x0010\r
-#define KB_MENU_FLAG 0x0020\r
-#define KB_SCROLOCK_FLAG 0x0100\r
-#define KB_NUMLOCK_FLAG 0x0200\r
-#define KB_CAPSLOCK_FLAG 0x0400\r
-#define KB_INALTSEQ_FLAG 0x0800\r
-#define KB_ACCENT1_FLAG 0x1000\r
-#define KB_ACCENT2_FLAG 0x2000\r
-#define KB_ACCENT3_FLAG 0x4000\r
-#define KB_ACCENT4_FLAG 0x8000\r
-\r
-#define KEY_A 1\r
-#define KEY_B 2\r
-#define KEY_C 3\r
-#define KEY_D 4\r
-#define KEY_E 5\r
-#define KEY_F 6\r
-#define KEY_G 7\r
-#define KEY_H 8\r
-#define KEY_I 9\r
-#define KEY_J 10\r
-#define KEY_K 11\r
-#define KEY_L 12\r
-#define KEY_M 13\r
-#define KEY_N 14\r
-#define KEY_O 15\r
-#define KEY_P 16\r
-#define KEY_Q 17\r
-#define KEY_R 18\r
-#define KEY_S 19\r
-#define KEY_T 20\r
-#define KEY_U 21\r
-#define KEY_V 22\r
-#define KEY_W 23\r
-#define KEY_X 24\r
-#define KEY_Y 25\r
-#define KEY_Z 26\r
-#define KEY_0 27\r
-#define KEY_1 28\r
-#define KEY_2 29\r
-#define KEY_3 30\r
-#define KEY_4 31\r
-#define KEY_5 32\r
-#define KEY_6 33\r
-#define KEY_7 34\r
-#define KEY_8 35\r
-#define KEY_9 36\r
-#define KEY_0_PAD 37\r
-#define KEY_1_PAD 38\r
-#define KEY_2_PAD 39\r
-#define KEY_3_PAD 40\r
-#define KEY_4_PAD 41\r
-#define KEY_5_PAD 42\r
-#define KEY_6_PAD 43\r
-#define KEY_7_PAD 44\r
-#define KEY_8_PAD 45\r
-#define KEY_9_PAD 46\r
-#define KEY_F1 47\r
-#define KEY_F2 48\r
-#define KEY_F3 49\r
-#define KEY_F4 50\r
-#define KEY_F5 51\r
-#define KEY_F6 52\r
-#define KEY_F7 53\r
-#define KEY_F8 54\r
-#define KEY_F9 55\r
-#define KEY_F10 56\r
-#define KEY_F11 57\r
-#define KEY_F12 58\r
-#define KEY_ESC 59\r
-#define KEY_TILDE 60\r
-#define KEY_MINUS 61\r
-#define KEY_EQUALS 62\r
-#define KEY_BACKSPACE 63\r
-#define KEY_TAB 64\r
-#define KEY_OPENBRACE 65\r
-#define KEY_CLOSEBRACE 66\r
-#define KEY_ENTER 67\r
-#define KEY_COLON 68\r
-#define KEY_QUOTE 69\r
-#define KEY_BACKSLASH 70\r
-#define KEY_BACKSLASH2 71\r
-#define KEY_COMMA 72\r
-#define KEY_STOP 73\r
-#define KEY_SLASH 74\r
-#define KEY_SPACE 75\r
-#define KEY_INSERT 76\r
-#define KEY_DEL 77\r
-#define KEY_HOME 78\r
-#define KEY_END 79\r
-#define KEY_PGUP 80\r
-#define KEY_PGDN 81\r
-#define KEY_LEFT 82\r
-#define KEY_RIGHT 83\r
-#define KEY_UP 84\r
-#define KEY_DOWN 85\r
-#define KEY_SLASH_PAD 86\r
-#define KEY_ASTERISK 87\r
-#define KEY_MINUS_PAD 88\r
-#define KEY_PLUS_PAD 89\r
-#define KEY_DEL_PAD 90\r
-#define KEY_ENTER_PAD 91\r
-#define KEY_PRTSCR 92\r
-#define KEY_PAUSE 93\r
-#define KEY_ABNT_C1 94\r
-#define KEY_YEN 95\r
-#define KEY_KANA 96\r
-#define KEY_CONVERT 97\r
-#define KEY_NOCONVERT 98\r
-#define KEY_AT 99\r
-#define KEY_CIRCUMFLEX 100\r
-#define KEY_COLON2 101\r
-#define KEY_KANJI 102\r
-\r
-#define KEY_MODIFIERS 103\r
-\r
-#define KEY_LSHIFT 103\r
-#define KEY_RSHIFT 104\r
-#define KEY_LCONTROL 105\r
-#define KEY_RCONTROL 106\r
-#define KEY_ALT 107\r
-#define KEY_ALTGR 108\r
-#define KEY_LWIN 109\r
-#define KEY_RWIN 110\r
-#define KEY_MENU 111\r
-#define KEY_SCRLOCK 112\r
-#define KEY_NUMLOCK 113\r
-#define KEY_CAPSLOCK 114\r
-\r
-#define KEY_MAX 115\r
-\r
-int pc_install_keyb (void);\r
-void pc_remove_keyb (void);\r
-int pc_keypressed (void);\r
-int pc_readkey (void);\r
-int pc_keydown (int code);\r
-int pc_keyshifts (void);\r
-\r
-/*\r
- * timer\r
- */\r
-int pc_install_int (PFUNC func, void *parm, unsigned int freq);\r
-void pc_remove_timer (void);\r
-\r
-/*\r
- * mouse\r
- */\r
-int pc_install_mouse (void);\r
-void pc_remove_mouse (void);\r
-MFUNC pc_install_mouse_handler (MFUNC handler);\r
-void pc_mouse_area (int x1, int y1, int x2, int y2);\r
-void pc_mouse_speed (int xspeed, int yspeed);\r
-int pc_query_mouse (int *x, int *y, int *z);\r
-void pc_warp_mouse (int x, int y);\r
-\r
-/*\r
- * standard redirection\r
- */\r
-int pc_open_stdout (void);\r
-int pc_open_stderr (void);\r
-void pc_close_stdout (void);\r
-void pc_close_stderr (void);\r
-\r
-#endif\r
+/*
+ * PC/HW routine collection v1.3 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef PC_HW_H_included
+#define PC_HW_H_included
+
+#include <dpmi.h>
+#include <stdlib.h>
+
+/*
+ * misc C definitions
+ */
+#define FALSE 0
+#define TRUE !FALSE
+
+#define MIN(x,y) (((x) < (y)) ? (x) : (y))
+#define MAX(x,y) (((x) > (y)) ? (x) : (y))
+#define MID(x,y,z) MAX((x), MIN((y), (z)))
+
+typedef void (*VFUNC) (void);
+typedef void (*PFUNC) (void *);
+typedef void (*MFUNC) (int x, int y, int z, int b);
+
+/*
+ * atexit
+ */
+int pc_atexit (VFUNC f);
+int pc_clexit (VFUNC f);
+
+/*
+ * locked memory
+ */
+#define ENDOFUNC(x) static void x##_end() { }
+#define LOCKFUNC(x) _go32_dpmi_lock_code((void *)x, (long)x##_end - (long)x)
+#define LOCKDATA(x) _go32_dpmi_lock_data((void *)&x, sizeof(x))
+#define LOCKBUFF(x, l) _go32_dpmi_lock_data((void *)x, l)
+
+void *pc_malloc (size_t size);
+
+/*
+ * IRQ
+ */
+#define ENABLE() __asm __volatile ("sti")
+#define DISABLE() __asm __volatile ("cli")
+
+extern int pc_install_irq (int i, int (*handler) ());
+extern int pc_remove_irq (int i);
+
+/*
+ * keyboard
+ */
+#define KB_SHIFT_FLAG 0x0001
+#define KB_CTRL_FLAG 0x0002
+#define KB_ALT_FLAG 0x0004
+#define KB_LWIN_FLAG 0x0008
+#define KB_RWIN_FLAG 0x0010
+#define KB_MENU_FLAG 0x0020
+#define KB_SCROLOCK_FLAG 0x0100
+#define KB_NUMLOCK_FLAG 0x0200
+#define KB_CAPSLOCK_FLAG 0x0400
+#define KB_INALTSEQ_FLAG 0x0800
+#define KB_ACCENT1_FLAG 0x1000
+#define KB_ACCENT2_FLAG 0x2000
+#define KB_ACCENT3_FLAG 0x4000
+#define KB_ACCENT4_FLAG 0x8000
+
+#define KEY_A 1
+#define KEY_B 2
+#define KEY_C 3
+#define KEY_D 4
+#define KEY_E 5
+#define KEY_F 6
+#define KEY_G 7
+#define KEY_H 8
+#define KEY_I 9
+#define KEY_J 10
+#define KEY_K 11
+#define KEY_L 12
+#define KEY_M 13
+#define KEY_N 14
+#define KEY_O 15
+#define KEY_P 16
+#define KEY_Q 17
+#define KEY_R 18
+#define KEY_S 19
+#define KEY_T 20
+#define KEY_U 21
+#define KEY_V 22
+#define KEY_W 23
+#define KEY_X 24
+#define KEY_Y 25
+#define KEY_Z 26
+#define KEY_0 27
+#define KEY_1 28
+#define KEY_2 29
+#define KEY_3 30
+#define KEY_4 31
+#define KEY_5 32
+#define KEY_6 33
+#define KEY_7 34
+#define KEY_8 35
+#define KEY_9 36
+#define KEY_0_PAD 37
+#define KEY_1_PAD 38
+#define KEY_2_PAD 39
+#define KEY_3_PAD 40
+#define KEY_4_PAD 41
+#define KEY_5_PAD 42
+#define KEY_6_PAD 43
+#define KEY_7_PAD 44
+#define KEY_8_PAD 45
+#define KEY_9_PAD 46
+#define KEY_F1 47
+#define KEY_F2 48
+#define KEY_F3 49
+#define KEY_F4 50
+#define KEY_F5 51
+#define KEY_F6 52
+#define KEY_F7 53
+#define KEY_F8 54
+#define KEY_F9 55
+#define KEY_F10 56
+#define KEY_F11 57
+#define KEY_F12 58
+#define KEY_ESC 59
+#define KEY_TILDE 60
+#define KEY_MINUS 61
+#define KEY_EQUALS 62
+#define KEY_BACKSPACE 63
+#define KEY_TAB 64
+#define KEY_OPENBRACE 65
+#define KEY_CLOSEBRACE 66
+#define KEY_ENTER 67
+#define KEY_COLON 68
+#define KEY_QUOTE 69
+#define KEY_BACKSLASH 70
+#define KEY_BACKSLASH2 71
+#define KEY_COMMA 72
+#define KEY_STOP 73
+#define KEY_SLASH 74
+#define KEY_SPACE 75
+#define KEY_INSERT 76
+#define KEY_DEL 77
+#define KEY_HOME 78
+#define KEY_END 79
+#define KEY_PGUP 80
+#define KEY_PGDN 81
+#define KEY_LEFT 82
+#define KEY_RIGHT 83
+#define KEY_UP 84
+#define KEY_DOWN 85
+#define KEY_SLASH_PAD 86
+#define KEY_ASTERISK 87
+#define KEY_MINUS_PAD 88
+#define KEY_PLUS_PAD 89
+#define KEY_DEL_PAD 90
+#define KEY_ENTER_PAD 91
+#define KEY_PRTSCR 92
+#define KEY_PAUSE 93
+#define KEY_ABNT_C1 94
+#define KEY_YEN 95
+#define KEY_KANA 96
+#define KEY_CONVERT 97
+#define KEY_NOCONVERT 98
+#define KEY_AT 99
+#define KEY_CIRCUMFLEX 100
+#define KEY_COLON2 101
+#define KEY_KANJI 102
+
+#define KEY_MODIFIERS 103
+
+#define KEY_LSHIFT 103
+#define KEY_RSHIFT 104
+#define KEY_LCONTROL 105
+#define KEY_RCONTROL 106
+#define KEY_ALT 107
+#define KEY_ALTGR 108
+#define KEY_LWIN 109
+#define KEY_RWIN 110
+#define KEY_MENU 111
+#define KEY_SCRLOCK 112
+#define KEY_NUMLOCK 113
+#define KEY_CAPSLOCK 114
+
+#define KEY_MAX 115
+
+int pc_install_keyb (void);
+void pc_remove_keyb (void);
+int pc_keypressed (void);
+int pc_readkey (void);
+int pc_keydown (int code);
+int pc_keyshifts (void);
+
+/*
+ * timer
+ */
+int pc_install_int (PFUNC func, void *parm, unsigned int freq);
+void pc_remove_timer (void);
+
+/*
+ * mouse
+ */
+int pc_install_mouse (void);
+void pc_remove_mouse (void);
+MFUNC pc_install_mouse_handler (MFUNC handler);
+void pc_mouse_area (int x1, int y1, int x2, int y2);
+void pc_mouse_speed (int xspeed, int yspeed);
+int pc_query_mouse (int *x, int *y, int *z);
+void pc_warp_mouse (int x, int y);
+
+/*
+ * standard redirection
+ */
+int pc_open_stdout (void);
+int pc_open_stderr (void);
+void pc_close_stdout (void);
+void pc_close_stderr (void);
+
+#endif
-/*\r
- * PC/HW routine collection v1.3 for DOS/DJGPP\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
- .file "pc_irq.S"\r
-\r
- .text\r
-\r
-#define IRQ_STACK_SIZE 16384\r
-\r
-#define IRQ_WRAPPER_LEN (__irq_wrapper_1-__irq_wrapper_0)\r
-#define IRQ_OLD (__irq_old_0-__irq_wrapper_0)\r
-#define IRQ_HOOK (__irq_hook_0-__irq_wrapper_0)\r
-#define IRQ_STACK (__irq_stack_0-__irq_wrapper_0)\r
-\r
- .balign 4\r
-common:\r
- movw $0x0400, %ax\r
- int $0x31\r
-\r
- movl %ss:8(%ebp), %ebx\r
- cmpl $15, %ebx\r
- jbe 0f\r
- fail:\r
- orl $-1, %eax\r
- popl %edi\r
- popl %ebx\r
- leave\r
- ret\r
-\r
- 0:\r
- movl %ebx, %edi\r
- imull $IRQ_WRAPPER_LEN, %edi\r
- addl $__irq_wrapper_0, %edi\r
-\r
- cmpb $7, %bl\r
- jbe 1f\r
- movb %dl, %dh\r
- subb $8, %dh\r
- 1:\r
- addb %dh, %bl\r
- ret\r
-\r
- .balign 4\r
- .global _pc_install_irq\r
-_pc_install_irq:\r
- pushl %ebp\r
- movl %esp, %ebp\r
- pushl %ebx\r
- pushl %edi\r
-\r
- call common\r
-\r
- cmpl $0, IRQ_HOOK(%edi)\r
- jne fail\r
-\r
- pushl $IRQ_WRAPPER_LEN\r
- pushl %edi\r
- call __go32_dpmi_lock_code\r
- addl $8, %esp\r
- testl %eax, %eax\r
- jnz fail\r
-\r
- pushl $IRQ_STACK_SIZE\r
- call _pc_malloc\r
- popl %edx\r
- testl %eax, %eax\r
- jz fail\r
- addl %edx, %eax\r
- movl %eax, IRQ_STACK(%edi)\r
-\r
- movl ___djgpp_ds_alias, %eax\r
- movl %eax, IRQ_STACK+4(%edi)\r
-\r
- movl %ss:12(%ebp), %eax\r
- movl %eax, IRQ_HOOK(%edi)\r
-\r
- movw $0x0204, %ax\r
- int $0x31\r
- movl %edx, IRQ_OLD(%edi)\r
- movw %cx, IRQ_OLD+4(%edi)\r
- movw $0x0205, %ax\r
- movl %edi, %edx\r
- movl %cs, %ecx\r
- int $0x31\r
-\r
- done:\r
- xorl %eax, %eax\r
- popl %edi\r
- popl %ebx\r
- leave\r
- ret\r
-\r
- .balign 4\r
- .global _pc_remove_irq\r
-_pc_remove_irq:\r
- pushl %ebp\r
- movl %esp, %ebp\r
- pushl %ebx\r
- pushl %edi\r
-\r
- call common\r
-\r
- cmpl $0, IRQ_HOOK(%edi)\r
- je fail\r
-\r
- movl $0, IRQ_HOOK(%edi)\r
-\r
- movw $0x0205, %ax\r
- movl IRQ_OLD(%edi), %edx\r
- movl IRQ_OLD+4(%edi), %ecx\r
- int $0x31\r
-\r
- movl IRQ_STACK(%edi), %eax\r
- subl $IRQ_STACK_SIZE, %eax\r
- pushl %eax\r
- call _free\r
- popl %eax\r
-\r
- jmp done\r
-\r
-#define WRAPPER(x) ; \\r
- .balign 4 ; \\r
-__irq_wrapper_##x: ; \\r
- pushal ; \\r
- pushl %ds ; \\r
- pushl %es ; \\r
- pushl %fs ; \\r
- pushl %gs ; \\r
- movl %ss, %ebx ; \\r
- movl %esp, %esi ; \\r
- lss %cs:__irq_stack_##x, %esp ; \\r
- pushl %ss ; \\r
- pushl %ss ; \\r
- popl %es ; \\r
- popl %ds ; \\r
- movl ___djgpp_dos_sel, %fs ; \\r
- pushl %fs ; \\r
- popl %gs ; \\r
- call *__irq_hook_##x ; \\r
- movl %ebx, %ss ; \\r
- movl %esi, %esp ; \\r
- testl %eax, %eax ; \\r
- popl %gs ; \\r
- popl %fs ; \\r
- popl %es ; \\r
- popl %ds ; \\r
- popal ; \\r
- jz __irq_ignore_##x ; \\r
-__irq_bypass_##x: ; \\r
- ljmp *%cs:__irq_old_##x ; \\r
-__irq_ignore_##x: ; \\r
- iret ; \\r
- .balign 4 ; \\r
-__irq_old_##x: ; \\r
- .long 0, 0 ; \\r
-__irq_hook_##x: ; \\r
- .long 0 ; \\r
-__irq_stack_##x: ; \\r
- .long 0, 0\r
-\r
- WRAPPER(0);\r
- WRAPPER(1);\r
- WRAPPER(2);\r
- WRAPPER(3);\r
- WRAPPER(4);\r
- WRAPPER(5);\r
- WRAPPER(6);\r
- WRAPPER(7);\r
- WRAPPER(8);\r
- WRAPPER(9);\r
- WRAPPER(10);\r
- WRAPPER(11);\r
- WRAPPER(12);\r
- WRAPPER(13);\r
- WRAPPER(14);\r
- WRAPPER(15);\r
+/*
+ * PC/HW routine collection v1.3 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+ .file "pc_irq.S"
+
+ .text
+
+#define IRQ_STACK_SIZE 16384
+
+#define IRQ_WRAPPER_LEN (__irq_wrapper_1-__irq_wrapper_0)
+#define IRQ_OLD (__irq_old_0-__irq_wrapper_0)
+#define IRQ_HOOK (__irq_hook_0-__irq_wrapper_0)
+#define IRQ_STACK (__irq_stack_0-__irq_wrapper_0)
+
+ .balign 4
+common:
+ movw $0x0400, %ax
+ int $0x31
+
+ movl %ss:8(%ebp), %ebx
+ cmpl $15, %ebx
+ jbe 0f
+ fail:
+ orl $-1, %eax
+ popl %edi
+ popl %ebx
+ leave
+ ret
+
+ 0:
+ movl %ebx, %edi
+ imull $IRQ_WRAPPER_LEN, %edi
+ addl $__irq_wrapper_0, %edi
+
+ cmpb $7, %bl
+ jbe 1f
+ movb %dl, %dh
+ subb $8, %dh
+ 1:
+ addb %dh, %bl
+ ret
+
+ .balign 4
+ .global _pc_install_irq
+_pc_install_irq:
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %ebx
+ pushl %edi
+
+ call common
+
+ cmpl $0, IRQ_HOOK(%edi)
+ jne fail
+
+ pushl $IRQ_WRAPPER_LEN
+ pushl %edi
+ call __go32_dpmi_lock_code
+ addl $8, %esp
+ testl %eax, %eax
+ jnz fail
+
+ pushl $IRQ_STACK_SIZE
+ call _pc_malloc
+ popl %edx
+ testl %eax, %eax
+ jz fail
+ addl %edx, %eax
+ movl %eax, IRQ_STACK(%edi)
+
+ movl ___djgpp_ds_alias, %eax
+ movl %eax, IRQ_STACK+4(%edi)
+
+ movl %ss:12(%ebp), %eax
+ movl %eax, IRQ_HOOK(%edi)
+
+ movw $0x0204, %ax
+ int $0x31
+ movl %edx, IRQ_OLD(%edi)
+ movw %cx, IRQ_OLD+4(%edi)
+ movw $0x0205, %ax
+ movl %edi, %edx
+ movl %cs, %ecx
+ int $0x31
+
+ done:
+ xorl %eax, %eax
+ popl %edi
+ popl %ebx
+ leave
+ ret
+
+ .balign 4
+ .global _pc_remove_irq
+_pc_remove_irq:
+ pushl %ebp
+ movl %esp, %ebp
+ pushl %ebx
+ pushl %edi
+
+ call common
+
+ cmpl $0, IRQ_HOOK(%edi)
+ je fail
+
+ movl $0, IRQ_HOOK(%edi)
+
+ movw $0x0205, %ax
+ movl IRQ_OLD(%edi), %edx
+ movl IRQ_OLD+4(%edi), %ecx
+ int $0x31
+
+ movl IRQ_STACK(%edi), %eax
+ subl $IRQ_STACK_SIZE, %eax
+ pushl %eax
+ call _free
+ popl %eax
+
+ jmp done
+
+#define WRAPPER(x) ; \
+ .balign 4 ; \
+__irq_wrapper_##x: ; \
+ pushal ; \
+ pushl %ds ; \
+ pushl %es ; \
+ pushl %fs ; \
+ pushl %gs ; \
+ movl %ss, %ebx ; \
+ movl %esp, %esi ; \
+ lss %cs:__irq_stack_##x, %esp ; \
+ pushl %ss ; \
+ pushl %ss ; \
+ popl %es ; \
+ popl %ds ; \
+ movl ___djgpp_dos_sel, %fs ; \
+ pushl %fs ; \
+ popl %gs ; \
+ call *__irq_hook_##x ; \
+ movl %ebx, %ss ; \
+ movl %esi, %esp ; \
+ testl %eax, %eax ; \
+ popl %gs ; \
+ popl %fs ; \
+ popl %es ; \
+ popl %ds ; \
+ popal ; \
+ jz __irq_ignore_##x ; \
+__irq_bypass_##x: ; \
+ ljmp *%cs:__irq_old_##x ; \
+__irq_ignore_##x: ; \
+ iret ; \
+ .balign 4 ; \
+__irq_old_##x: ; \
+ .long 0, 0 ; \
+__irq_hook_##x: ; \
+ .long 0 ; \
+__irq_stack_##x: ; \
+ .long 0, 0
+
+ WRAPPER(0);
+ WRAPPER(1);
+ WRAPPER(2);
+ WRAPPER(3);
+ WRAPPER(4);
+ WRAPPER(5);
+ WRAPPER(6);
+ WRAPPER(7);
+ WRAPPER(8);
+ WRAPPER(9);
+ WRAPPER(10);
+ WRAPPER(11);
+ WRAPPER(12);
+ WRAPPER(13);
+ WRAPPER(14);
+ WRAPPER(15);
-/*\r
- * PC/HW routine collection v1.3 for DOS/DJGPP\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 <sys/exceptn.h>\r
-#include <sys/farptr.h>\r
-\r
-#include "pc_hw.h"\r
-\r
-\r
-\r
-#define KEYB_IRQ 1\r
-\r
-#define KEY_BUFFER_SIZE 64\r
-\r
-#define KB_MODIFIERS (KB_SHIFT_FLAG | KB_CTRL_FLAG | KB_ALT_FLAG | KB_LWIN_FLAG | KB_RWIN_FLAG | KB_MENU_FLAG)\r
-#define KB_LED_FLAGS (KB_SCROLOCK_FLAG | KB_NUMLOCK_FLAG | KB_CAPSLOCK_FLAG)\r
-\r
-static int keyboard_installed;\r
-\r
-static volatile struct {\r
- volatile int start, end;\r
- volatile int key[KEY_BUFFER_SIZE];\r
-} key_buffer;\r
-\r
-static volatile int key_enhanced, key_pause_loop, key_shifts;\r
-static int leds_ok = TRUE;\r
-static int in_a_terrupt = FALSE;\r
-static volatile char pc_key[KEY_MAX];\r
-\r
-\r
-\r
-/* convert Allegro format scancodes into key_shifts flag bits */\r
-static unsigned short modifier_table[KEY_MAX - KEY_MODIFIERS] =\r
-{\r
- KB_SHIFT_FLAG, KB_SHIFT_FLAG, KB_CTRL_FLAG,\r
- KB_CTRL_FLAG, KB_ALT_FLAG, KB_ALT_FLAG,\r
- KB_LWIN_FLAG, KB_RWIN_FLAG, KB_MENU_FLAG,\r
- KB_SCROLOCK_FLAG, KB_NUMLOCK_FLAG, KB_CAPSLOCK_FLAG\r
-};\r
-\r
-\r
-\r
-/* lookup table for converting hardware scancodes into Allegro format */\r
-static unsigned char hw_to_mycode[128] =\r
-{\r
- /* 0x00 */ 0, KEY_ESC, KEY_1, KEY_2, \r
- /* 0x04 */ KEY_3, KEY_4, KEY_5, KEY_6,\r
- /* 0x08 */ KEY_7, KEY_8, KEY_9, KEY_0, \r
- /* 0x0C */ KEY_MINUS, KEY_EQUALS, KEY_BACKSPACE, KEY_TAB,\r
- /* 0x10 */ KEY_Q, KEY_W, KEY_E, KEY_R, \r
- /* 0x14 */ KEY_T, KEY_Y, KEY_U, KEY_I,\r
- /* 0x18 */ KEY_O, KEY_P, KEY_OPENBRACE, KEY_CLOSEBRACE, \r
- /* 0x1C */ KEY_ENTER, KEY_LCONTROL, KEY_A, KEY_S,\r
- /* 0x20 */ KEY_D, KEY_F, KEY_G, KEY_H, \r
- /* 0x24 */ KEY_J, KEY_K, KEY_L, KEY_COLON,\r
- /* 0x28 */ KEY_QUOTE, KEY_TILDE, KEY_LSHIFT, KEY_BACKSLASH, \r
- /* 0x2C */ KEY_Z, KEY_X, KEY_C, KEY_V,\r
- /* 0x30 */ KEY_B, KEY_N, KEY_M, KEY_COMMA, \r
- /* 0x34 */ KEY_STOP, KEY_SLASH, KEY_RSHIFT, KEY_ASTERISK,\r
- /* 0x38 */ KEY_ALT, KEY_SPACE, KEY_CAPSLOCK, KEY_F1, \r
- /* 0x3C */ KEY_F2, KEY_F3, KEY_F4, KEY_F5,\r
- /* 0x40 */ KEY_F6, KEY_F7, KEY_F8, KEY_F9, \r
- /* 0x44 */ KEY_F10, KEY_NUMLOCK, KEY_SCRLOCK, KEY_7_PAD,\r
- /* 0x48 */ KEY_8_PAD, KEY_9_PAD, KEY_MINUS_PAD, KEY_4_PAD, \r
- /* 0x4C */ KEY_5_PAD, KEY_6_PAD, KEY_PLUS_PAD, KEY_1_PAD,\r
- /* 0x50 */ KEY_2_PAD, KEY_3_PAD, KEY_0_PAD, KEY_DEL_PAD, \r
- /* 0x54 */ KEY_PRTSCR, 0, KEY_BACKSLASH2, KEY_F11,\r
- /* 0x58 */ KEY_F12, 0, 0, KEY_LWIN, \r
- /* 0x5C */ KEY_RWIN, KEY_MENU, 0, 0,\r
- /* 0x60 */ 0, 0, 0, 0, \r
- /* 0x64 */ 0, 0, 0, 0,\r
- /* 0x68 */ 0, 0, 0, 0, \r
- /* 0x6C */ 0, 0, 0, 0,\r
- /* 0x70 */ KEY_KANA, 0, 0, KEY_ABNT_C1, \r
- /* 0x74 */ 0, 0, 0, 0,\r
- /* 0x78 */ 0, KEY_CONVERT, 0, KEY_NOCONVERT, \r
- /* 0x7C */ 0, KEY_YEN, 0, 0\r
-};\r
-\r
-\r
-\r
-/* lookup table for converting extended hardware codes into Allegro format */\r
-static unsigned char hw_to_mycode_ex[128] =\r
-{\r
- /* 0x00 */ 0, KEY_ESC, KEY_1, KEY_2,\r
- /* 0x04 */ KEY_3, KEY_4, KEY_5, KEY_6,\r
- /* 0x08 */ KEY_7, KEY_8, KEY_9, KEY_0,\r
- /* 0x0C */ KEY_MINUS, KEY_EQUALS, KEY_BACKSPACE, KEY_TAB,\r
- /* 0x10 */ KEY_CIRCUMFLEX, KEY_AT, KEY_COLON2, KEY_R,\r
- /* 0x14 */ KEY_KANJI, KEY_Y, KEY_U, KEY_I,\r
- /* 0x18 */ KEY_O, KEY_P, KEY_OPENBRACE, KEY_CLOSEBRACE,\r
- /* 0x1C */ KEY_ENTER_PAD, KEY_RCONTROL, KEY_A, KEY_S,\r
- /* 0x20 */ KEY_D, KEY_F, KEY_G, KEY_H,\r
- /* 0x24 */ KEY_J, KEY_K, KEY_L, KEY_COLON,\r
- /* 0x28 */ KEY_QUOTE, KEY_TILDE, 0, KEY_BACKSLASH,\r
- /* 0x2C */ KEY_Z, KEY_X, KEY_C, KEY_V,\r
- /* 0x30 */ KEY_B, KEY_N, KEY_M, KEY_COMMA,\r
- /* 0x34 */ KEY_STOP, KEY_SLASH_PAD, 0, KEY_PRTSCR,\r
- /* 0x38 */ KEY_ALTGR, KEY_SPACE, KEY_CAPSLOCK, KEY_F1,\r
- /* 0x3C */ KEY_F2, KEY_F3, KEY_F4, KEY_F5,\r
- /* 0x40 */ KEY_F6, KEY_F7, KEY_F8, KEY_F9,\r
- /* 0x44 */ KEY_F10, KEY_NUMLOCK, KEY_PAUSE, KEY_HOME,\r
- /* 0x48 */ KEY_UP, KEY_PGUP, KEY_MINUS_PAD, KEY_LEFT,\r
- /* 0x4C */ KEY_5_PAD, KEY_RIGHT, KEY_PLUS_PAD, KEY_END,\r
- /* 0x50 */ KEY_DOWN, KEY_PGDN, KEY_INSERT, KEY_DEL,\r
- /* 0x54 */ KEY_PRTSCR, 0, KEY_BACKSLASH2, KEY_F11,\r
- /* 0x58 */ KEY_F12, 0, 0, KEY_LWIN,\r
- /* 0x5C */ KEY_RWIN, KEY_MENU, 0, 0,\r
- /* 0x60 */ 0, 0, 0, 0,\r
- /* 0x64 */ 0, 0, 0, 0,\r
- /* 0x68 */ 0, 0, 0, 0,\r
- /* 0x6C */ 0, 0, 0, 0,\r
- /* 0x70 */ 0, 0, 0, 0,\r
- /* 0x74 */ 0, 0, 0, 0,\r
- /* 0x78 */ 0, 0, 0, 0,\r
- /* 0x7C */ 0, 0, 0, 0\r
-};\r
-\r
-\r
-\r
-/* default mapping table for the US keyboard layout */\r
-static unsigned short standard_key_ascii_table[KEY_MAX] =\r
-{\r
- /* start */ 0,\r
- /* alphabet */ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',\r
- /* numbers */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
- /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
- /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* misc chars */ 27, '`', '-', '=', 8, 9, '[', ']', 13, ';', '\'', '\\', '\\', ',', '.', '/', ' ',\r
- /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* numpad */ '/', '*', '-', '+', '.', 13,\r
- /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
-};\r
-\r
-\r
-\r
-/* capslock mapping table for the US keyboard layout */\r
-static unsigned short standard_key_capslock_table[KEY_MAX] =\r
-{\r
- /* start */ 0,\r
- /* alphabet */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\r
- /* numbers */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
- /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
- /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* misc chars */ 27, '`', '-', '=', 8, 9, '[', ']', 13, ';', '\'', '\\', '\\', ',', '.', '/', ' ',\r
- /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* numpad */ '/', '*', '-', '+', '.', 13,\r
- /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
-};\r
-\r
-\r
-\r
-/* shifted mapping table for the US keyboard layout */\r
-static unsigned short standard_key_shift_table[KEY_MAX] =\r
-{\r
- /* start */ 0,\r
- /* alphabet */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',\r
- /* numbers */ ')', '!', '@', '#', '$', '%', '^', '&', '*', '(',\r
- /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
- /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* misc chars */ 27, '~', '_', '+', 8, 9, '{', '}', 13, ':', '"', '|', '|', '<', '>', '?', ' ',\r
- /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* numpad */ '/', '*', '-', '+', '.', 13,\r
- /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
-};\r
-\r
-\r
-\r
-/* ctrl+key mapping table for the US keyboard layout */\r
-static unsigned short standard_key_control_table[KEY_MAX] =\r
-{\r
- /* start */ 0,\r
- /* alphabet */ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\r
- /* numbers */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,\r
- /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',\r
- /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* misc chars */ 27, 2, 2, 2, 127, 127, 2, 2, 10, 2, 2, 2, 2, 2, 2, 2, 2,\r
- /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,\r
- /* numpad */ 2, 2, 2, 2, 2, 10,\r
- /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0\r
-};\r
-\r
-\r
-\r
-/* convert numeric pad scancodes into arrow codes */\r
-static unsigned char numlock_table[10] =\r
-{\r
- KEY_INSERT, KEY_END, KEY_DOWN, KEY_PGDN, KEY_LEFT,\r
- KEY_5_PAD, KEY_RIGHT, KEY_HOME, KEY_UP, KEY_PGUP\r
-};\r
-\r
-\r
-\r
-/* kb_wait_for_write_ready:\r
- * Wait for the keyboard controller to set the ready-for-write bit.\r
- */\r
-static __inline int kb_wait_for_write_ready (void)\r
-{\r
- int timeout = 4096;\r
-\r
- while ((timeout>0) && (inportb(0x64)&2)) timeout--;\r
-\r
- return (timeout>0);\r
-}\r
-\r
-\r
-\r
-/* kb_wait_for_read_ready:\r
- * Wait for the keyboard controller to set the ready-for-read bit.\r
- */\r
-static __inline int kb_wait_for_read_ready (void)\r
-{\r
- int timeout = 16384;\r
-\r
- while ((timeout>0) && (!(inportb(0x64)&1))) timeout--;\r
-\r
- return (timeout>0);\r
-}\r
-\r
-\r
-\r
-/* kb_send_data:\r
- * Sends a byte to the keyboard controller. Returns 1 if all OK.\r
- */\r
-static __inline int kb_send_data (unsigned char data)\r
-{\r
- int resends = 4;\r
- int timeout, temp;\r
-\r
- do {\r
- if (!kb_wait_for_write_ready())\r
- return 0;\r
-\r
- outportb(0x60, data);\r
- timeout = 4096;\r
-\r
- while (--timeout>0) {\r
- if (!kb_wait_for_read_ready())\r
- return 0;\r
-\r
- temp = inportb(0x60);\r
-\r
- if (temp == 0xFA)\r
- return 1;\r
-\r
- if (temp == 0xFE)\r
- break;\r
- }\r
- } while ((resends-- > 0) && (timeout > 0));\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-static void update_leds (int leds)\r
-{\r
- if (leds_ok) {\r
- if (!in_a_terrupt)\r
- DISABLE();\r
-\r
- if (!kb_send_data(0xED)) {\r
- kb_send_data(0xF4);\r
- leds_ok = FALSE;\r
- } else if (!kb_send_data((leds>>8)&7)) {\r
- kb_send_data(0xF4);\r
- leds_ok = FALSE;\r
- }\r
-\r
- if (!in_a_terrupt)\r
- ENABLE();\r
- }\r
-} ENDOFUNC(update_leds)\r
-\r
-\r
-\r
-static void inject_key (int scancode)\r
-{\r
- unsigned short *table;\r
-\r
- if ((scancode >= KEY_0_PAD) && (scancode <= KEY_9_PAD)) {\r
- if (((key_shifts & KB_NUMLOCK_FLAG) != 0) == ((key_shifts & KB_SHIFT_FLAG) != 0)) {\r
- scancode = numlock_table[scancode - KEY_0_PAD];\r
- }\r
- table = standard_key_ascii_table;\r
- } else if (key_shifts & KB_CTRL_FLAG) {\r
- table = standard_key_control_table;\r
- } else if (key_shifts & KB_SHIFT_FLAG) {\r
- if (key_shifts & KB_CAPSLOCK_FLAG) {\r
- if (standard_key_ascii_table[scancode]==standard_key_capslock_table[scancode]) {\r
- table = standard_key_shift_table;\r
- } else {\r
- table = standard_key_ascii_table;\r
- }\r
- } else {\r
- table = standard_key_shift_table;\r
- }\r
- } else if (key_shifts & KB_CAPSLOCK_FLAG) {\r
- table = standard_key_capslock_table;\r
- } else {\r
- table = standard_key_ascii_table;\r
- }\r
-\r
- key_buffer.key[key_buffer.end++] = (scancode<<16)|table[scancode];\r
-\r
- if (key_buffer.end>=KEY_BUFFER_SIZE)\r
- key_buffer.end = 0;\r
- if (key_buffer.end==key_buffer.start) {\r
- key_buffer.start++;\r
- if (key_buffer.start>=KEY_BUFFER_SIZE)\r
- key_buffer.start = 0;\r
- }\r
-} ENDOFUNC(inject_key)\r
-\r
-static void handle_code (int scancode, int keycode)\r
-{\r
- in_a_terrupt++;\r
-\r
- if (keycode==0) { /* pause */\r
- inject_key(scancode);\r
- pc_key[KEY_PAUSE] ^= TRUE;\r
- } else if (scancode) {\r
- int flag;\r
- \r
- if (scancode>=KEY_MODIFIERS) {\r
- flag = modifier_table[scancode - KEY_MODIFIERS];\r
- } else {\r
- flag = 0;\r
- }\r
- if ((char)keycode<0) { /* release */\r
- pc_key[scancode] = FALSE;\r
- if (flag&KB_MODIFIERS) {\r
- key_shifts &= ~flag;\r
- }\r
- } else { /* keypress */\r
- pc_key[scancode] = TRUE;\r
- if (flag&KB_MODIFIERS) {\r
- key_shifts |= flag;\r
- }\r
- if (flag&KB_LED_FLAGS) {\r
- key_shifts ^= flag;\r
- update_leds(key_shifts);\r
- }\r
- if (scancode<KEY_MODIFIERS) {\r
- inject_key(scancode);\r
- }\r
- }\r
- }\r
-\r
- in_a_terrupt--;\r
-} ENDOFUNC(handle_code)\r
-\r
-static int keyboard ()\r
-{\r
- unsigned char temp, scancode;\r
-\r
- temp = inportb(0x60);\r
-\r
- if (temp<=0xe1) {\r
- if (key_pause_loop) {\r
- if (!--key_pause_loop) handle_code(KEY_PAUSE, 0);\r
- } else\r
- switch (temp) {\r
- case 0xe0:\r
- key_enhanced = TRUE;\r
- break;\r
- case 0xe1:\r
- key_pause_loop = 5;\r
- break;\r
- default:\r
- if (key_enhanced) {\r
- key_enhanced = FALSE;\r
- scancode = hw_to_mycode_ex[temp&0x7f];\r
- } else {\r
- scancode = hw_to_mycode[temp&0x7f];\r
- }\r
- handle_code(scancode, temp);\r
- }\r
- }\r
-\r
- if (((temp==0x4F)||(temp==0x53))&&(key_shifts&KB_CTRL_FLAG)&&(key_shifts&KB_ALT_FLAG)) {\r
- /* Hack alert:\r
- only SIGINT (but not Ctrl-Break)\r
- calls the destructors and will safely clean up\r
- */\r
- __asm("\n\\r
- movb $0x79, %%al \n\\r
- call ___djgpp_hw_exception \n\\r
- ":::"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");\r
- }\r
-\r
- __asm("\n\\r
- inb $0x61, %%al \n\\r
- movb %%al, %%ah \n\\r
- orb $0x80, %%al \n\\r
- outb %%al, $0x61 \n\\r
- xchgb %%al, %%ah \n\\r
- outb %%al, $0x61 \n\\r
- movb $0x20, %%al \n\\r
- outb %%al, $0x20 \n\\r
- ":::"%eax");\r
- return 0;\r
-} ENDOFUNC(keyboard)\r
-\r
-\r
-int pc_keypressed (void)\r
-{\r
- return (key_buffer.start!=key_buffer.end);\r
-}\r
-\r
-int pc_readkey (void)\r
-{\r
- if (keyboard_installed) {\r
- int key;\r
-\r
- while (key_buffer.start==key_buffer.end) {\r
- __dpmi_yield();\r
- }\r
-\r
- DISABLE();\r
- key = key_buffer.key[key_buffer.start++];\r
- if (key_buffer.start>=KEY_BUFFER_SIZE)\r
- key_buffer.start = 0;\r
- ENABLE();\r
-\r
- return key;\r
- } else {\r
- return 0;\r
- }\r
-}\r
-\r
-int pc_keydown (int code)\r
-{\r
- return pc_key[code];\r
-}\r
-\r
-int pc_keyshifts (void)\r
-{\r
- return key_shifts;\r
-}\r
-\r
-void pc_remove_keyb (void)\r
-{\r
- if (keyboard_installed) {\r
- int s1, s2, s3;\r
- \r
- keyboard_installed = FALSE;\r
- pc_clexit(pc_remove_keyb);\r
-\r
- DISABLE();\r
- _farsetsel(__djgpp_dos_sel);\r
- _farnspokew(0x41c, _farnspeekw(0x41a));\r
-\r
- s1 = _farnspeekb(0x417) & 0x80;\r
- s2 = _farnspeekb(0x418) & 0xFC;\r
- s3 = _farnspeekb(0x496) & 0xF3;\r
-\r
- if (pc_key[KEY_RSHIFT]) { s1 |= 1; }\r
- if (pc_key[KEY_LSHIFT]) { s1 |= 2; }\r
- if (pc_key[KEY_LCONTROL]) { s2 |= 1; s1 |= 4; }\r
- if (pc_key[KEY_ALT]) { s1 |= 8; s2 |= 2; }\r
- if (pc_key[KEY_RCONTROL]) { s1 |= 4; s3 |= 4; }\r
- if (pc_key[KEY_ALTGR]) { s1 |= 8; s3 |= 8; }\r
-\r
- if (key_shifts&KB_SCROLOCK_FLAG) s1 |= 16;\r
- if (key_shifts&KB_NUMLOCK_FLAG) s1 |= 32;\r
- if (key_shifts&KB_CAPSLOCK_FLAG) s1 |= 64;\r
-\r
- _farnspokeb(0x417, s1);\r
- _farnspokeb(0x418, s2);\r
- _farnspokeb(0x496, s3);\r
- update_leds(key_shifts);\r
-\r
- ENABLE();\r
- pc_remove_irq(KEYB_IRQ);\r
- }\r
-}\r
-\r
-int pc_install_keyb (void)\r
-{\r
- if (keyboard_installed||pc_install_irq(KEYB_IRQ, keyboard)) {\r
- return -1;\r
- } else {\r
- int s1, s2, s3;\r
-\r
- LOCKDATA(key_buffer);\r
- LOCKDATA(key_enhanced);\r
- LOCKDATA(key_pause_loop);\r
- LOCKDATA(key_shifts);\r
- LOCKDATA(leds_ok);\r
- LOCKDATA(in_a_terrupt);\r
- LOCKDATA(pc_key);\r
- LOCKDATA(modifier_table);\r
- LOCKDATA(hw_to_mycode);\r
- LOCKDATA(hw_to_mycode_ex);\r
- LOCKDATA(standard_key_ascii_table);\r
- LOCKDATA(standard_key_capslock_table);\r
- LOCKDATA(standard_key_shift_table);\r
- LOCKDATA(standard_key_control_table);\r
- LOCKDATA(numlock_table);\r
- LOCKFUNC(update_leds);\r
- LOCKFUNC(inject_key);\r
- LOCKFUNC(handle_code);\r
- LOCKFUNC(keyboard);\r
- \r
- DISABLE();\r
- _farsetsel(__djgpp_dos_sel);\r
- _farnspokew(0x41c, _farnspeekw(0x41a));\r
-\r
- key_shifts = 0;\r
- s1 = _farnspeekb(0x417);\r
- s2 = _farnspeekb(0x418);\r
- s3 = _farnspeekb(0x496);\r
-\r
- if (s1&1) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_RSHIFT] = TRUE; }\r
- if (s1&2) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_LSHIFT] = TRUE; }\r
- if (s2&1) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_LCONTROL] = TRUE; }\r
- if (s2&2) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALT] = TRUE; }\r
- if (s3&4) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_RCONTROL] = TRUE; }\r
- if (s3&8) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALTGR] = TRUE; }\r
-\r
- if (s1&16) key_shifts |= KB_SCROLOCK_FLAG;\r
- if (s1&32) key_shifts |= KB_NUMLOCK_FLAG;\r
- if (s1&64) key_shifts |= KB_CAPSLOCK_FLAG;\r
- update_leds(key_shifts);\r
-\r
- key_enhanced = key_pause_loop = 0;\r
- key_buffer.start = key_buffer.end = 0;\r
- ENABLE();\r
-\r
- pc_atexit(pc_remove_keyb);\r
- keyboard_installed = TRUE;\r
- return 0;\r
- }\r
-}\r
+/*
+ * PC/HW routine collection v1.3 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <pc.h>
+#include <sys/exceptn.h>
+#include <sys/farptr.h>
+
+#include "pc_hw.h"
+
+
+
+#define KEYB_IRQ 1
+
+#define KEY_BUFFER_SIZE 64
+
+#define KB_MODIFIERS (KB_SHIFT_FLAG | KB_CTRL_FLAG | KB_ALT_FLAG | KB_LWIN_FLAG | KB_RWIN_FLAG | KB_MENU_FLAG)
+#define KB_LED_FLAGS (KB_SCROLOCK_FLAG | KB_NUMLOCK_FLAG | KB_CAPSLOCK_FLAG)
+
+static int keyboard_installed;
+
+static volatile struct {
+ volatile int start, end;
+ volatile int key[KEY_BUFFER_SIZE];
+} key_buffer;
+
+static volatile int key_enhanced, key_pause_loop, key_shifts;
+static int leds_ok = TRUE;
+static int in_a_terrupt = FALSE;
+static volatile char pc_key[KEY_MAX];
+
+
+
+/* convert Allegro format scancodes into key_shifts flag bits */
+static unsigned short modifier_table[KEY_MAX - KEY_MODIFIERS] =
+{
+ KB_SHIFT_FLAG, KB_SHIFT_FLAG, KB_CTRL_FLAG,
+ KB_CTRL_FLAG, KB_ALT_FLAG, KB_ALT_FLAG,
+ KB_LWIN_FLAG, KB_RWIN_FLAG, KB_MENU_FLAG,
+ KB_SCROLOCK_FLAG, KB_NUMLOCK_FLAG, KB_CAPSLOCK_FLAG
+};
+
+
+
+/* lookup table for converting hardware scancodes into Allegro format */
+static unsigned char hw_to_mycode[128] =
+{
+ /* 0x00 */ 0, KEY_ESC, KEY_1, KEY_2,
+ /* 0x04 */ KEY_3, KEY_4, KEY_5, KEY_6,
+ /* 0x08 */ KEY_7, KEY_8, KEY_9, KEY_0,
+ /* 0x0C */ KEY_MINUS, KEY_EQUALS, KEY_BACKSPACE, KEY_TAB,
+ /* 0x10 */ KEY_Q, KEY_W, KEY_E, KEY_R,
+ /* 0x14 */ KEY_T, KEY_Y, KEY_U, KEY_I,
+ /* 0x18 */ KEY_O, KEY_P, KEY_OPENBRACE, KEY_CLOSEBRACE,
+ /* 0x1C */ KEY_ENTER, KEY_LCONTROL, KEY_A, KEY_S,
+ /* 0x20 */ KEY_D, KEY_F, KEY_G, KEY_H,
+ /* 0x24 */ KEY_J, KEY_K, KEY_L, KEY_COLON,
+ /* 0x28 */ KEY_QUOTE, KEY_TILDE, KEY_LSHIFT, KEY_BACKSLASH,
+ /* 0x2C */ KEY_Z, KEY_X, KEY_C, KEY_V,
+ /* 0x30 */ KEY_B, KEY_N, KEY_M, KEY_COMMA,
+ /* 0x34 */ KEY_STOP, KEY_SLASH, KEY_RSHIFT, KEY_ASTERISK,
+ /* 0x38 */ KEY_ALT, KEY_SPACE, KEY_CAPSLOCK, KEY_F1,
+ /* 0x3C */ KEY_F2, KEY_F3, KEY_F4, KEY_F5,
+ /* 0x40 */ KEY_F6, KEY_F7, KEY_F8, KEY_F9,
+ /* 0x44 */ KEY_F10, KEY_NUMLOCK, KEY_SCRLOCK, KEY_7_PAD,
+ /* 0x48 */ KEY_8_PAD, KEY_9_PAD, KEY_MINUS_PAD, KEY_4_PAD,
+ /* 0x4C */ KEY_5_PAD, KEY_6_PAD, KEY_PLUS_PAD, KEY_1_PAD,
+ /* 0x50 */ KEY_2_PAD, KEY_3_PAD, KEY_0_PAD, KEY_DEL_PAD,
+ /* 0x54 */ KEY_PRTSCR, 0, KEY_BACKSLASH2, KEY_F11,
+ /* 0x58 */ KEY_F12, 0, 0, KEY_LWIN,
+ /* 0x5C */ KEY_RWIN, KEY_MENU, 0, 0,
+ /* 0x60 */ 0, 0, 0, 0,
+ /* 0x64 */ 0, 0, 0, 0,
+ /* 0x68 */ 0, 0, 0, 0,
+ /* 0x6C */ 0, 0, 0, 0,
+ /* 0x70 */ KEY_KANA, 0, 0, KEY_ABNT_C1,
+ /* 0x74 */ 0, 0, 0, 0,
+ /* 0x78 */ 0, KEY_CONVERT, 0, KEY_NOCONVERT,
+ /* 0x7C */ 0, KEY_YEN, 0, 0
+};
+
+
+
+/* lookup table for converting extended hardware codes into Allegro format */
+static unsigned char hw_to_mycode_ex[128] =
+{
+ /* 0x00 */ 0, KEY_ESC, KEY_1, KEY_2,
+ /* 0x04 */ KEY_3, KEY_4, KEY_5, KEY_6,
+ /* 0x08 */ KEY_7, KEY_8, KEY_9, KEY_0,
+ /* 0x0C */ KEY_MINUS, KEY_EQUALS, KEY_BACKSPACE, KEY_TAB,
+ /* 0x10 */ KEY_CIRCUMFLEX, KEY_AT, KEY_COLON2, KEY_R,
+ /* 0x14 */ KEY_KANJI, KEY_Y, KEY_U, KEY_I,
+ /* 0x18 */ KEY_O, KEY_P, KEY_OPENBRACE, KEY_CLOSEBRACE,
+ /* 0x1C */ KEY_ENTER_PAD, KEY_RCONTROL, KEY_A, KEY_S,
+ /* 0x20 */ KEY_D, KEY_F, KEY_G, KEY_H,
+ /* 0x24 */ KEY_J, KEY_K, KEY_L, KEY_COLON,
+ /* 0x28 */ KEY_QUOTE, KEY_TILDE, 0, KEY_BACKSLASH,
+ /* 0x2C */ KEY_Z, KEY_X, KEY_C, KEY_V,
+ /* 0x30 */ KEY_B, KEY_N, KEY_M, KEY_COMMA,
+ /* 0x34 */ KEY_STOP, KEY_SLASH_PAD, 0, KEY_PRTSCR,
+ /* 0x38 */ KEY_ALTGR, KEY_SPACE, KEY_CAPSLOCK, KEY_F1,
+ /* 0x3C */ KEY_F2, KEY_F3, KEY_F4, KEY_F5,
+ /* 0x40 */ KEY_F6, KEY_F7, KEY_F8, KEY_F9,
+ /* 0x44 */ KEY_F10, KEY_NUMLOCK, KEY_PAUSE, KEY_HOME,
+ /* 0x48 */ KEY_UP, KEY_PGUP, KEY_MINUS_PAD, KEY_LEFT,
+ /* 0x4C */ KEY_5_PAD, KEY_RIGHT, KEY_PLUS_PAD, KEY_END,
+ /* 0x50 */ KEY_DOWN, KEY_PGDN, KEY_INSERT, KEY_DEL,
+ /* 0x54 */ KEY_PRTSCR, 0, KEY_BACKSLASH2, KEY_F11,
+ /* 0x58 */ KEY_F12, 0, 0, KEY_LWIN,
+ /* 0x5C */ KEY_RWIN, KEY_MENU, 0, 0,
+ /* 0x60 */ 0, 0, 0, 0,
+ /* 0x64 */ 0, 0, 0, 0,
+ /* 0x68 */ 0, 0, 0, 0,
+ /* 0x6C */ 0, 0, 0, 0,
+ /* 0x70 */ 0, 0, 0, 0,
+ /* 0x74 */ 0, 0, 0, 0,
+ /* 0x78 */ 0, 0, 0, 0,
+ /* 0x7C */ 0, 0, 0, 0
+};
+
+
+
+/* default mapping table for the US keyboard layout */
+static unsigned short standard_key_ascii_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
+ /* numbers */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, '`', '-', '=', 8, 9, '[', ']', 13, ';', '\'', '\\', '\\', ',', '.', '/', ' ',
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ '/', '*', '-', '+', '.', 13,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* capslock mapping table for the US keyboard layout */
+static unsigned short standard_key_capslock_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ /* numbers */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, '`', '-', '=', 8, 9, '[', ']', 13, ';', '\'', '\\', '\\', ',', '.', '/', ' ',
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ '/', '*', '-', '+', '.', 13,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* shifted mapping table for the US keyboard layout */
+static unsigned short standard_key_shift_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
+ /* numbers */ ')', '!', '@', '#', '$', '%', '^', '&', '*', '(',
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, '~', '_', '+', 8, 9, '{', '}', 13, ':', '"', '|', '|', '<', '>', '?', ' ',
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ '/', '*', '-', '+', '.', 13,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* ctrl+key mapping table for the US keyboard layout */
+static unsigned short standard_key_control_table[KEY_MAX] =
+{
+ /* start */ 0,
+ /* alphabet */ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,
+ /* numbers */ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
+ /* numpad */ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
+ /* func keys */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* misc chars */ 27, 2, 2, 2, 127, 127, 2, 2, 10, 2, 2, 2, 2, 2, 2, 2, 2,
+ /* controls */ 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF, 0xFFFF,
+ /* numpad */ 2, 2, 2, 2, 2, 10,
+ /* modifiers */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+
+
+/* convert numeric pad scancodes into arrow codes */
+static unsigned char numlock_table[10] =
+{
+ KEY_INSERT, KEY_END, KEY_DOWN, KEY_PGDN, KEY_LEFT,
+ KEY_5_PAD, KEY_RIGHT, KEY_HOME, KEY_UP, KEY_PGUP
+};
+
+
+
+/* kb_wait_for_write_ready:
+ * Wait for the keyboard controller to set the ready-for-write bit.
+ */
+static __inline int kb_wait_for_write_ready (void)
+{
+ int timeout = 4096;
+
+ while ((timeout>0) && (inportb(0x64)&2)) timeout--;
+
+ return (timeout>0);
+}
+
+
+
+/* kb_wait_for_read_ready:
+ * Wait for the keyboard controller to set the ready-for-read bit.
+ */
+static __inline int kb_wait_for_read_ready (void)
+{
+ int timeout = 16384;
+
+ while ((timeout>0) && (!(inportb(0x64)&1))) timeout--;
+
+ return (timeout>0);
+}
+
+
+
+/* kb_send_data:
+ * Sends a byte to the keyboard controller. Returns 1 if all OK.
+ */
+static __inline int kb_send_data (unsigned char data)
+{
+ int resends = 4;
+ int timeout, temp;
+
+ do {
+ if (!kb_wait_for_write_ready())
+ return 0;
+
+ outportb(0x60, data);
+ timeout = 4096;
+
+ while (--timeout>0) {
+ if (!kb_wait_for_read_ready())
+ return 0;
+
+ temp = inportb(0x60);
+
+ if (temp == 0xFA)
+ return 1;
+
+ if (temp == 0xFE)
+ break;
+ }
+ } while ((resends-- > 0) && (timeout > 0));
+
+ return 0;
+}
+
+
+
+static void update_leds (int leds)
+{
+ if (leds_ok) {
+ if (!in_a_terrupt)
+ DISABLE();
+
+ if (!kb_send_data(0xED)) {
+ kb_send_data(0xF4);
+ leds_ok = FALSE;
+ } else if (!kb_send_data((leds>>8)&7)) {
+ kb_send_data(0xF4);
+ leds_ok = FALSE;
+ }
+
+ if (!in_a_terrupt)
+ ENABLE();
+ }
+} ENDOFUNC(update_leds)
+
+
+
+static void inject_key (int scancode)
+{
+ unsigned short *table;
+
+ if ((scancode >= KEY_0_PAD) && (scancode <= KEY_9_PAD)) {
+ if (((key_shifts & KB_NUMLOCK_FLAG) != 0) == ((key_shifts & KB_SHIFT_FLAG) != 0)) {
+ scancode = numlock_table[scancode - KEY_0_PAD];
+ }
+ table = standard_key_ascii_table;
+ } else if (key_shifts & KB_CTRL_FLAG) {
+ table = standard_key_control_table;
+ } else if (key_shifts & KB_SHIFT_FLAG) {
+ if (key_shifts & KB_CAPSLOCK_FLAG) {
+ if (standard_key_ascii_table[scancode]==standard_key_capslock_table[scancode]) {
+ table = standard_key_shift_table;
+ } else {
+ table = standard_key_ascii_table;
+ }
+ } else {
+ table = standard_key_shift_table;
+ }
+ } else if (key_shifts & KB_CAPSLOCK_FLAG) {
+ table = standard_key_capslock_table;
+ } else {
+ table = standard_key_ascii_table;
+ }
+
+ key_buffer.key[key_buffer.end++] = (scancode<<16)|table[scancode];
+
+ if (key_buffer.end>=KEY_BUFFER_SIZE)
+ key_buffer.end = 0;
+ if (key_buffer.end==key_buffer.start) {
+ key_buffer.start++;
+ if (key_buffer.start>=KEY_BUFFER_SIZE)
+ key_buffer.start = 0;
+ }
+} ENDOFUNC(inject_key)
+
+static void handle_code (int scancode, int keycode)
+{
+ in_a_terrupt++;
+
+ if (keycode==0) { /* pause */
+ inject_key(scancode);
+ pc_key[KEY_PAUSE] ^= TRUE;
+ } else if (scancode) {
+ int flag;
+
+ if (scancode>=KEY_MODIFIERS) {
+ flag = modifier_table[scancode - KEY_MODIFIERS];
+ } else {
+ flag = 0;
+ }
+ if ((char)keycode<0) { /* release */
+ pc_key[scancode] = FALSE;
+ if (flag&KB_MODIFIERS) {
+ key_shifts &= ~flag;
+ }
+ } else { /* keypress */
+ pc_key[scancode] = TRUE;
+ if (flag&KB_MODIFIERS) {
+ key_shifts |= flag;
+ }
+ if (flag&KB_LED_FLAGS) {
+ key_shifts ^= flag;
+ update_leds(key_shifts);
+ }
+ if (scancode<KEY_MODIFIERS) {
+ inject_key(scancode);
+ }
+ }
+ }
+
+ in_a_terrupt--;
+} ENDOFUNC(handle_code)
+
+static int keyboard ()
+{
+ unsigned char temp, scancode;
+
+ temp = inportb(0x60);
+
+ if (temp<=0xe1) {
+ if (key_pause_loop) {
+ if (!--key_pause_loop) handle_code(KEY_PAUSE, 0);
+ } else
+ switch (temp) {
+ case 0xe0:
+ key_enhanced = TRUE;
+ break;
+ case 0xe1:
+ key_pause_loop = 5;
+ break;
+ default:
+ if (key_enhanced) {
+ key_enhanced = FALSE;
+ scancode = hw_to_mycode_ex[temp&0x7f];
+ } else {
+ scancode = hw_to_mycode[temp&0x7f];
+ }
+ handle_code(scancode, temp);
+ }
+ }
+
+ if (((temp==0x4F)||(temp==0x53))&&(key_shifts&KB_CTRL_FLAG)&&(key_shifts&KB_ALT_FLAG)) {
+ /* Hack alert:
+ only SIGINT (but not Ctrl-Break)
+ calls the destructors and will safely clean up
+ */
+ __asm("\n\
+ movb $0x79, %%al \n\
+ call ___djgpp_hw_exception \n\
+ ":::"%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory");
+ }
+
+ __asm("\n\
+ inb $0x61, %%al \n\
+ movb %%al, %%ah \n\
+ orb $0x80, %%al \n\
+ outb %%al, $0x61 \n\
+ xchgb %%al, %%ah \n\
+ outb %%al, $0x61 \n\
+ movb $0x20, %%al \n\
+ outb %%al, $0x20 \n\
+ ":::"%eax");
+ return 0;
+} ENDOFUNC(keyboard)
+
+
+int pc_keypressed (void)
+{
+ return (key_buffer.start!=key_buffer.end);
+}
+
+int pc_readkey (void)
+{
+ if (keyboard_installed) {
+ int key;
+
+ while (key_buffer.start==key_buffer.end) {
+ __dpmi_yield();
+ }
+
+ DISABLE();
+ key = key_buffer.key[key_buffer.start++];
+ if (key_buffer.start>=KEY_BUFFER_SIZE)
+ key_buffer.start = 0;
+ ENABLE();
+
+ return key;
+ } else {
+ return 0;
+ }
+}
+
+int pc_keydown (int code)
+{
+ return pc_key[code];
+}
+
+int pc_keyshifts (void)
+{
+ return key_shifts;
+}
+
+void pc_remove_keyb (void)
+{
+ if (keyboard_installed) {
+ int s1, s2, s3;
+
+ keyboard_installed = FALSE;
+ pc_clexit(pc_remove_keyb);
+
+ DISABLE();
+ _farsetsel(__djgpp_dos_sel);
+ _farnspokew(0x41c, _farnspeekw(0x41a));
+
+ s1 = _farnspeekb(0x417) & 0x80;
+ s2 = _farnspeekb(0x418) & 0xFC;
+ s3 = _farnspeekb(0x496) & 0xF3;
+
+ if (pc_key[KEY_RSHIFT]) { s1 |= 1; }
+ if (pc_key[KEY_LSHIFT]) { s1 |= 2; }
+ if (pc_key[KEY_LCONTROL]) { s2 |= 1; s1 |= 4; }
+ if (pc_key[KEY_ALT]) { s1 |= 8; s2 |= 2; }
+ if (pc_key[KEY_RCONTROL]) { s1 |= 4; s3 |= 4; }
+ if (pc_key[KEY_ALTGR]) { s1 |= 8; s3 |= 8; }
+
+ if (key_shifts&KB_SCROLOCK_FLAG) s1 |= 16;
+ if (key_shifts&KB_NUMLOCK_FLAG) s1 |= 32;
+ if (key_shifts&KB_CAPSLOCK_FLAG) s1 |= 64;
+
+ _farnspokeb(0x417, s1);
+ _farnspokeb(0x418, s2);
+ _farnspokeb(0x496, s3);
+ update_leds(key_shifts);
+
+ ENABLE();
+ pc_remove_irq(KEYB_IRQ);
+ }
+}
+
+int pc_install_keyb (void)
+{
+ if (keyboard_installed||pc_install_irq(KEYB_IRQ, keyboard)) {
+ return -1;
+ } else {
+ int s1, s2, s3;
+
+ LOCKDATA(key_buffer);
+ LOCKDATA(key_enhanced);
+ LOCKDATA(key_pause_loop);
+ LOCKDATA(key_shifts);
+ LOCKDATA(leds_ok);
+ LOCKDATA(in_a_terrupt);
+ LOCKDATA(pc_key);
+ LOCKDATA(modifier_table);
+ LOCKDATA(hw_to_mycode);
+ LOCKDATA(hw_to_mycode_ex);
+ LOCKDATA(standard_key_ascii_table);
+ LOCKDATA(standard_key_capslock_table);
+ LOCKDATA(standard_key_shift_table);
+ LOCKDATA(standard_key_control_table);
+ LOCKDATA(numlock_table);
+ LOCKFUNC(update_leds);
+ LOCKFUNC(inject_key);
+ LOCKFUNC(handle_code);
+ LOCKFUNC(keyboard);
+
+ DISABLE();
+ _farsetsel(__djgpp_dos_sel);
+ _farnspokew(0x41c, _farnspeekw(0x41a));
+
+ key_shifts = 0;
+ s1 = _farnspeekb(0x417);
+ s2 = _farnspeekb(0x418);
+ s3 = _farnspeekb(0x496);
+
+ if (s1&1) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_RSHIFT] = TRUE; }
+ if (s1&2) { key_shifts |= KB_SHIFT_FLAG; pc_key[KEY_LSHIFT] = TRUE; }
+ if (s2&1) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_LCONTROL] = TRUE; }
+ if (s2&2) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALT] = TRUE; }
+ if (s3&4) { key_shifts |= KB_CTRL_FLAG; pc_key[KEY_RCONTROL] = TRUE; }
+ if (s3&8) { key_shifts |= KB_ALT_FLAG; pc_key[KEY_ALTGR] = TRUE; }
+
+ if (s1&16) key_shifts |= KB_SCROLOCK_FLAG;
+ if (s1&32) key_shifts |= KB_NUMLOCK_FLAG;
+ if (s1&64) key_shifts |= KB_CAPSLOCK_FLAG;
+ update_leds(key_shifts);
+
+ key_enhanced = key_pause_loop = 0;
+ key_buffer.start = key_buffer.end = 0;
+ ENABLE();
+
+ pc_atexit(pc_remove_keyb);
+ keyboard_installed = TRUE;
+ return 0;
+ }
+}
-/*\r
- * PC/HW routine collection v1.3 for DOS/DJGPP\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 <sys/exceptn.h>\r
-#include <sys/segments.h>\r
-\r
-#include "pc_hw.h"\r
-\r
-\r
-\r
-#define PC_CUTE_WHEEL 1 /* CuteMouse WheelAPI */\r
-\r
-#define MOUSE_STACK_SIZE 16384\r
-\r
-#define CLEAR_MICKEYS() \\r
- do { \\r
- __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \\r
- ox = oy = 0; \\r
- } while (0)\r
-\r
-extern void mouse_wrap (void);\r
-extern int mouse_wrap_end[];\r
-\r
-static MFUNC mouse_func;\r
-static long mouse_callback;\r
-static __dpmi_regs mouse_regs;\r
-\r
-static volatile struct {\r
- volatile int x, y, z, b;\r
-} pc_mouse;\r
-\r
-static int minx = 0;\r
-static int maxx = 319;\r
-static int miny = 0;\r
-static int maxy = 199;\r
-static int minz = 0;\r
-static int maxz = 255;\r
-\r
-static int sx = 2;\r
-static int sy = 2;\r
-\r
-static int emulat3 = FALSE;\r
-\r
-static int ox, oy;\r
-\r
-\r
-static void mouse (__dpmi_regs *r)\r
-{\r
- int nx = (signed short)r->x.si / sx;\r
- int ny = (signed short)r->x.di / sy;\r
- int dx = nx - ox;\r
- int dy = ny - oy;\r
-#if PC_CUTE_WHEEL\r
- int dz = (signed char)r->h.bh;\r
-#endif\r
- ox = nx;\r
- oy = ny;\r
-\r
- pc_mouse.b = r->h.bl;\r
- pc_mouse.x = MID(minx, pc_mouse.x + dx, maxx);\r
- pc_mouse.y = MID(miny, pc_mouse.y + dy, maxy);\r
-#if PC_CUTE_WHEEL\r
- pc_mouse.z = MID(minz, pc_mouse.z + dz, maxz);\r
-#endif\r
-\r
- if (emulat3) {\r
- if ((pc_mouse.b&3)==3) {\r
- pc_mouse.b = 4;\r
- }\r
- }\r
-\r
- if (mouse_func) {\r
- mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);\r
- }\r
-} ENDOFUNC(mouse)\r
-\r
-void pc_remove_mouse (void)\r
-{\r
- if (mouse_callback) {\r
- pc_clexit(pc_remove_mouse);\r
- __asm("\n\\r
- movl %%edx, %%ecx \n\\r
- shrl $16, %%ecx \n\\r
- movw $0x0304, %%ax \n\\r
- int $0x31 \n\\r
- movw $0x000c, %%ax \n\\r
- xorl %%ecx, %%ecx \n\\r
- int $0x33 \n\\r
- "::"d"(mouse_callback):"%eax", "%ecx");\r
-\r
- mouse_callback = 0;\r
-\r
- free((void *)(mouse_wrap_end[0] - MOUSE_STACK_SIZE));\r
- }\r
-}\r
-\r
-int pc_install_mouse (void)\r
-{\r
- int buttons;\r
-\r
- /* fail if already call-backed */\r
- if (mouse_callback) {\r
- return 0;\r
- }\r
-\r
- /* reset mouse and get status */\r
- __asm("\n\\r
- xorl %%eax, %%eax \n\\r
- int $0x33 \n\\r
- andl %%ebx, %%eax \n\\r
- movl %%eax, %0 \n\\r
- ":"=g" (buttons)::"%eax", "%ebx");\r
- if (!buttons) {\r
- return 0;\r
- }\r
-\r
- /* lock wrapper */\r
- LOCKDATA(mouse_func);\r
- LOCKDATA(mouse_callback);\r
- LOCKDATA(mouse_regs);\r
- LOCKDATA(pc_mouse);\r
- LOCKDATA(minx);\r
- LOCKDATA(maxx);\r
- LOCKDATA(miny);\r
- LOCKDATA(maxy);\r
- LOCKDATA(minz);\r
- LOCKDATA(maxz);\r
- LOCKDATA(sx);\r
- LOCKDATA(sy);\r
- LOCKDATA(emulat3);\r
- LOCKDATA(ox);\r
- LOCKDATA(oy);\r
- LOCKFUNC(mouse);\r
- LOCKFUNC(mouse_wrap);\r
-\r
- mouse_wrap_end[1] = __djgpp_ds_alias;\r
- /* grab a locked stack */\r
- if ((mouse_wrap_end[0] = (int)pc_malloc(MOUSE_STACK_SIZE)) == NULL) {\r
- return 0;\r
- }\r
-\r
- /* try to hook a call-back */\r
- __asm("\n\\r
- pushl %%ds \n\\r
- pushl %%es \n\\r
- movw $0x0303, %%ax \n\\r
- pushl %%ds \n\\r
- pushl %%cs \n\\r
- popl %%ds \n\\r
- popl %%es \n\\r
- int $0x31 \n\\r
- popl %%es \n\\r
- popl %%ds \n\\r
- jc 0f \n\\r
- shll $16, %%ecx \n\\r
- movw %%dx, %%cx \n\\r
- movl %%ecx, %0 \n\\r
- 0: \n\\r
- ":"=g"(mouse_callback)\r
- :"S" (mouse_wrap), "D"(&mouse_regs)\r
- :"%eax", "%ecx", "%edx");\r
- if (!mouse_callback) {\r
- free((void *)mouse_wrap_end[0]);\r
- return 0;\r
- }\r
-\r
- /* adjust stack */\r
- mouse_wrap_end[0] += MOUSE_STACK_SIZE;\r
-\r
- /* install the handler */\r
- mouse_regs.x.ax = 0x000c;\r
-#if PC_CUTE_WHEEL\r
- mouse_regs.x.cx = 0x7f | 0x80;\r
-#else\r
- mouse_regs.x.cx = 0x7f;\r
-#endif\r
- mouse_regs.x.dx = mouse_callback&0xffff;\r
- mouse_regs.x.es = mouse_callback>>16;\r
- __dpmi_int(0x33, &mouse_regs);\r
-\r
- CLEAR_MICKEYS();\r
-\r
- emulat3 = buttons<3;\r
- pc_atexit(pc_remove_mouse);\r
- return buttons;\r
-}\r
-\r
-MFUNC pc_install_mouse_handler (MFUNC handler)\r
-{\r
- MFUNC old;\r
-\r
- if (!mouse_callback && !pc_install_mouse()) {\r
- return NULL;\r
- }\r
-\r
- old = mouse_func;\r
- mouse_func = handler;\r
- return old;\r
-}\r
-\r
-void pc_mouse_area (int x1, int y1, int x2, int y2)\r
-{\r
- minx = x1;\r
- maxx = x2;\r
- miny = y1;\r
- maxy = y2;\r
-}\r
-\r
-void pc_mouse_speed (int xspeed, int yspeed)\r
-{\r
- DISABLE();\r
-\r
- sx = MAX(1, xspeed);\r
- sy = MAX(1, yspeed);\r
-\r
- ENABLE();\r
-}\r
-\r
-int pc_query_mouse (int *x, int *y, int *z)\r
-{\r
- *x = pc_mouse.x;\r
- *y = pc_mouse.y;\r
- *z = pc_mouse.z;\r
- return pc_mouse.b;\r
-}\r
-\r
-void pc_warp_mouse (int x, int y)\r
-{\r
- CLEAR_MICKEYS();\r
-\r
- pc_mouse.x = MID(minx, x, maxx);\r
- pc_mouse.y = MID(miny, y, maxy);\r
-\r
- if (mouse_func) {\r
- mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);\r
- }\r
-}\r
-\r
-/* Hack alert:\r
- * `mouse_wrap_end' actually holds the\r
- * address of stack in a safe data selector.\r
- */\r
-__asm("\n\\r
- .text \n\\r
- .p2align 5,,31 \n\\r
- .global _mouse_wrap \n\\r
-_mouse_wrap: \n\\r
- cld \n\\r
- lodsl \n\\r
- movl %eax, %es:42(%edi) \n\\r
- addw $4, %es:46(%edi) \n\\r
- pushl %es \n\\r
- movl %ss, %ebx \n\\r
- movl %esp, %esi \n\\r
- lss %cs:_mouse_wrap_end, %esp\n\\r
- pushl %ss \n\\r
- pushl %ss \n\\r
- popl %es \n\\r
- popl %ds \n\\r
- movl ___djgpp_dos_sel, %fs \n\\r
- pushl %fs \n\\r
- popl %gs \n\\r
- pushl %edi \n\\r
- call _mouse \n\\r
- popl %edi \n\\r
- movl %ebx, %ss \n\\r
- movl %esi, %esp \n\\r
- popl %es \n\\r
- iret \n\\r
- .global _mouse_wrap_end \n\\r
-_mouse_wrap_end:.long 0, 0");\r
+/*
+ * PC/HW routine collection v1.3 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <dpmi.h>
+#include <sys/exceptn.h>
+#include <sys/segments.h>
+
+#include "pc_hw.h"
+
+
+
+#define PC_CUTE_WHEEL 1 /* CuteMouse WheelAPI */
+
+#define MOUSE_STACK_SIZE 16384
+
+#define CLEAR_MICKEYS() \
+ do { \
+ __asm __volatile ("movw $0xb, %%ax; int $0x33":::"%eax", "%ecx", "%edx"); \
+ ox = oy = 0; \
+ } while (0)
+
+extern void mouse_wrap (void);
+extern int mouse_wrap_end[];
+
+static MFUNC mouse_func;
+static long mouse_callback;
+static __dpmi_regs mouse_regs;
+
+static volatile struct {
+ volatile int x, y, z, b;
+} pc_mouse;
+
+static int minx = 0;
+static int maxx = 319;
+static int miny = 0;
+static int maxy = 199;
+static int minz = 0;
+static int maxz = 255;
+
+static int sx = 2;
+static int sy = 2;
+
+static int emulat3 = FALSE;
+
+static int ox, oy;
+
+
+static void mouse (__dpmi_regs *r)
+{
+ int nx = (signed short)r->x.si / sx;
+ int ny = (signed short)r->x.di / sy;
+ int dx = nx - ox;
+ int dy = ny - oy;
+#if PC_CUTE_WHEEL
+ int dz = (signed char)r->h.bh;
+#endif
+ ox = nx;
+ oy = ny;
+
+ pc_mouse.b = r->h.bl;
+ pc_mouse.x = MID(minx, pc_mouse.x + dx, maxx);
+ pc_mouse.y = MID(miny, pc_mouse.y + dy, maxy);
+#if PC_CUTE_WHEEL
+ pc_mouse.z = MID(minz, pc_mouse.z + dz, maxz);
+#endif
+
+ if (emulat3) {
+ if ((pc_mouse.b&3)==3) {
+ pc_mouse.b = 4;
+ }
+ }
+
+ if (mouse_func) {
+ mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);
+ }
+} ENDOFUNC(mouse)
+
+void pc_remove_mouse (void)
+{
+ if (mouse_callback) {
+ pc_clexit(pc_remove_mouse);
+ __asm("\n\
+ movl %%edx, %%ecx \n\
+ shrl $16, %%ecx \n\
+ movw $0x0304, %%ax \n\
+ int $0x31 \n\
+ movw $0x000c, %%ax \n\
+ xorl %%ecx, %%ecx \n\
+ int $0x33 \n\
+ "::"d"(mouse_callback):"%eax", "%ecx");
+
+ mouse_callback = 0;
+
+ free((void *)(mouse_wrap_end[0] - MOUSE_STACK_SIZE));
+ }
+}
+
+int pc_install_mouse (void)
+{
+ int buttons;
+
+ /* fail if already call-backed */
+ if (mouse_callback) {
+ return 0;
+ }
+
+ /* reset mouse and get status */
+ __asm("\n\
+ xorl %%eax, %%eax \n\
+ int $0x33 \n\
+ andl %%ebx, %%eax \n\
+ movl %%eax, %0 \n\
+ ":"=g" (buttons)::"%eax", "%ebx");
+ if (!buttons) {
+ return 0;
+ }
+
+ /* lock wrapper */
+ LOCKDATA(mouse_func);
+ LOCKDATA(mouse_callback);
+ LOCKDATA(mouse_regs);
+ LOCKDATA(pc_mouse);
+ LOCKDATA(minx);
+ LOCKDATA(maxx);
+ LOCKDATA(miny);
+ LOCKDATA(maxy);
+ LOCKDATA(minz);
+ LOCKDATA(maxz);
+ LOCKDATA(sx);
+ LOCKDATA(sy);
+ LOCKDATA(emulat3);
+ LOCKDATA(ox);
+ LOCKDATA(oy);
+ LOCKFUNC(mouse);
+ LOCKFUNC(mouse_wrap);
+
+ mouse_wrap_end[1] = __djgpp_ds_alias;
+ /* grab a locked stack */
+ if ((mouse_wrap_end[0] = (int)pc_malloc(MOUSE_STACK_SIZE)) == NULL) {
+ return 0;
+ }
+
+ /* try to hook a call-back */
+ __asm("\n\
+ pushl %%ds \n\
+ pushl %%es \n\
+ movw $0x0303, %%ax \n\
+ pushl %%ds \n\
+ pushl %%cs \n\
+ popl %%ds \n\
+ popl %%es \n\
+ int $0x31 \n\
+ popl %%es \n\
+ popl %%ds \n\
+ jc 0f \n\
+ shll $16, %%ecx \n\
+ movw %%dx, %%cx \n\
+ movl %%ecx, %0 \n\
+ 0: \n\
+ ":"=g"(mouse_callback)
+ :"S" (mouse_wrap), "D"(&mouse_regs)
+ :"%eax", "%ecx", "%edx");
+ if (!mouse_callback) {
+ free((void *)mouse_wrap_end[0]);
+ return 0;
+ }
+
+ /* adjust stack */
+ mouse_wrap_end[0] += MOUSE_STACK_SIZE;
+
+ /* install the handler */
+ mouse_regs.x.ax = 0x000c;
+#if PC_CUTE_WHEEL
+ mouse_regs.x.cx = 0x7f | 0x80;
+#else
+ mouse_regs.x.cx = 0x7f;
+#endif
+ mouse_regs.x.dx = mouse_callback&0xffff;
+ mouse_regs.x.es = mouse_callback>>16;
+ __dpmi_int(0x33, &mouse_regs);
+
+ CLEAR_MICKEYS();
+
+ emulat3 = buttons<3;
+ pc_atexit(pc_remove_mouse);
+ return buttons;
+}
+
+MFUNC pc_install_mouse_handler (MFUNC handler)
+{
+ MFUNC old;
+
+ if (!mouse_callback && !pc_install_mouse()) {
+ return NULL;
+ }
+
+ old = mouse_func;
+ mouse_func = handler;
+ return old;
+}
+
+void pc_mouse_area (int x1, int y1, int x2, int y2)
+{
+ minx = x1;
+ maxx = x2;
+ miny = y1;
+ maxy = y2;
+}
+
+void pc_mouse_speed (int xspeed, int yspeed)
+{
+ DISABLE();
+
+ sx = MAX(1, xspeed);
+ sy = MAX(1, yspeed);
+
+ ENABLE();
+}
+
+int pc_query_mouse (int *x, int *y, int *z)
+{
+ *x = pc_mouse.x;
+ *y = pc_mouse.y;
+ *z = pc_mouse.z;
+ return pc_mouse.b;
+}
+
+void pc_warp_mouse (int x, int y)
+{
+ CLEAR_MICKEYS();
+
+ pc_mouse.x = MID(minx, x, maxx);
+ pc_mouse.y = MID(miny, y, maxy);
+
+ if (mouse_func) {
+ mouse_func(pc_mouse.x, pc_mouse.y, pc_mouse.z, pc_mouse.b);
+ }
+}
+
+/* Hack alert:
+ * `mouse_wrap_end' actually holds the
+ * address of stack in a safe data selector.
+ */
+__asm("\n\
+ .text \n\
+ .p2align 5,,31 \n\
+ .global _mouse_wrap \n\
+_mouse_wrap: \n\
+ cld \n\
+ lodsl \n\
+ movl %eax, %es:42(%edi) \n\
+ addw $4, %es:46(%edi) \n\
+ pushl %es \n\
+ movl %ss, %ebx \n\
+ movl %esp, %esi \n\
+ lss %cs:_mouse_wrap_end, %esp\n\
+ pushl %ss \n\
+ pushl %ss \n\
+ popl %es \n\
+ popl %ds \n\
+ movl ___djgpp_dos_sel, %fs \n\
+ pushl %fs \n\
+ popl %gs \n\
+ pushl %edi \n\
+ call _mouse \n\
+ popl %edi \n\
+ movl %ebx, %ss \n\
+ movl %esi, %esp \n\
+ popl %es \n\
+ iret \n\
+ .global _mouse_wrap_end \n\
+_mouse_wrap_end:.long 0, 0");
-/*\r
- * PC/HW routine collection v1.3 for DOS/DJGPP\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
-\r
-#include "pc_hw.h"\r
-\r
-#define TIMER_IRQ 0\r
-\r
-#define MAX_TIMERS 8\r
-\r
-#define PIT_FREQ 0x1234DD\r
-\r
-#define unvolatile(__v, __t) __extension__ ({union { volatile __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})\r
-\r
-static int timer_installed;\r
-\r
-typedef struct {\r
- volatile unsigned int counter, clock_ticks, freq;\r
- volatile PFUNC func;\r
- volatile void *parm;\r
-} TIMER;\r
-\r
-static TIMER timer_main, timer_func[MAX_TIMERS];\r
-\r
-static int timer ()\r
-{\r
- int i;\r
-\r
- for (i=0;i<MAX_TIMERS;i++) {\r
- TIMER *t = &timer_func[i];\r
- if (t->func) {\r
- t->clock_ticks += t->counter;\r
- if (t->clock_ticks>=timer_main.counter) {\r
- t->clock_ticks -= timer_main.counter;\r
- t->func(unvolatile(t->parm, void *));\r
- }\r
- }\r
- }\r
-\r
- timer_main.clock_ticks += timer_main.counter;\r
- if (timer_main.clock_ticks>=0x10000) {\r
- timer_main.clock_ticks -= 0x10000;\r
- return 1;\r
- } else {\r
- outportb(0x20, 0x20);\r
- return 0;\r
- }\r
-} ENDOFUNC(timer)\r
-\r
-void pc_remove_timer (void)\r
-{\r
- if (timer_installed) {\r
- timer_installed = FALSE;\r
- pc_clexit(pc_remove_timer);\r
-\r
- DISABLE();\r
- outportb(0x43, 0x34);\r
- outportb(0x40, 0);\r
- outportb(0x40, 0);\r
- ENABLE();\r
-\r
- pc_remove_irq(TIMER_IRQ);\r
- }\r
-}\r
-\r
-static int install_timer (void)\r
-{\r
- if (timer_installed||pc_install_irq(TIMER_IRQ, timer)) {\r
- return -1;\r
- } else {\r
- LOCKDATA(timer_func);\r
- LOCKDATA(timer_main);\r
- LOCKFUNC(timer);\r
-\r
- timer_main.counter = 0x10000;\r
-\r
- DISABLE();\r
- outportb(0x43, 0x34);\r
- outportb(0x40, 0);\r
- outportb(0x40, 0);\r
- timer_main.clock_ticks = 0;\r
- ENABLE();\r
-\r
- pc_atexit(pc_remove_timer);\r
- timer_installed = TRUE;\r
- return 0;\r
- }\r
-}\r
-\r
-static TIMER *find_slot (PFUNC func)\r
-{\r
- int i;\r
-\r
- for (i=0;i<MAX_TIMERS;i++) {\r
- if (timer_func[i].func==func) {\r
- return &timer_func[i];\r
- }\r
- }\r
- for (i=0;i<MAX_TIMERS;i++) {\r
- if (!timer_func[i].func) {\r
- return &timer_func[i];\r
- }\r
- }\r
-\r
- return NULL;\r
-}\r
-\r
-int pc_install_int (PFUNC func, void *parm, unsigned int freq)\r
-{\r
- int i;\r
- TIMER *t;\r
-\r
- if (!timer_installed) {\r
- if (install_timer()) {\r
- return -1;\r
- }\r
- }\r
-\r
- if ((t=find_slot(func))!=NULL) {\r
- unsigned int new_counter = PIT_FREQ / freq;\r
-\r
- DISABLE();\r
-\r
- t->func = func;\r
- t->parm = parm;\r
- t->freq = freq;\r
- t->clock_ticks = 0;\r
-\r
- if (new_counter < timer_main.counter) {\r
- for (i=0;i<MAX_TIMERS;i++) {\r
- if (timer_func[i].func) {\r
- timer_func[i].counter = new_counter * timer_func[i].freq / freq;\r
- }\r
- }\r
- outportb(0x43, 0x34);\r
- outportb(0x40, (unsigned char)new_counter);\r
- outportb(0x40, (unsigned char)(new_counter>>8));\r
- timer_main.clock_ticks = 0;\r
- timer_main.counter = new_counter;\r
- timer_main.freq = freq;\r
- } else {\r
- t->counter = PIT_FREQ * freq / (timer_main.freq * timer_main.freq);\r
- }\r
-\r
- ENABLE();\r
-\r
- return 0;\r
- }\r
- \r
- return -1;\r
-}\r
+/*
+ * PC/HW routine collection v1.3 for DOS/DJGPP
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <pc.h>
+
+#include "pc_hw.h"
+
+#define TIMER_IRQ 0
+
+#define MAX_TIMERS 8
+
+#define PIT_FREQ 0x1234DD
+
+#define unvolatile(__v, __t) __extension__ ({union { volatile __t __cp; __t __p; } __q; __q.__cp = __v; __q.__p;})
+
+static int timer_installed;
+
+typedef struct {
+ volatile unsigned int counter, clock_ticks, freq;
+ volatile PFUNC func;
+ volatile void *parm;
+} TIMER;
+
+static TIMER timer_main, timer_func[MAX_TIMERS];
+
+static int timer ()
+{
+ int i;
+
+ for (i=0;i<MAX_TIMERS;i++) {
+ TIMER *t = &timer_func[i];
+ if (t->func) {
+ t->clock_ticks += t->counter;
+ if (t->clock_ticks>=timer_main.counter) {
+ t->clock_ticks -= timer_main.counter;
+ t->func(unvolatile(t->parm, void *));
+ }
+ }
+ }
+
+ timer_main.clock_ticks += timer_main.counter;
+ if (timer_main.clock_ticks>=0x10000) {
+ timer_main.clock_ticks -= 0x10000;
+ return 1;
+ } else {
+ outportb(0x20, 0x20);
+ return 0;
+ }
+} ENDOFUNC(timer)
+
+void pc_remove_timer (void)
+{
+ if (timer_installed) {
+ timer_installed = FALSE;
+ pc_clexit(pc_remove_timer);
+
+ DISABLE();
+ outportb(0x43, 0x34);
+ outportb(0x40, 0);
+ outportb(0x40, 0);
+ ENABLE();
+
+ pc_remove_irq(TIMER_IRQ);
+ }
+}
+
+static int install_timer (void)
+{
+ if (timer_installed||pc_install_irq(TIMER_IRQ, timer)) {
+ return -1;
+ } else {
+ LOCKDATA(timer_func);
+ LOCKDATA(timer_main);
+ LOCKFUNC(timer);
+
+ timer_main.counter = 0x10000;
+
+ DISABLE();
+ outportb(0x43, 0x34);
+ outportb(0x40, 0);
+ outportb(0x40, 0);
+ timer_main.clock_ticks = 0;
+ ENABLE();
+
+ pc_atexit(pc_remove_timer);
+ timer_installed = TRUE;
+ return 0;
+ }
+}
+
+static TIMER *find_slot (PFUNC func)
+{
+ int i;
+
+ for (i=0;i<MAX_TIMERS;i++) {
+ if (timer_func[i].func==func) {
+ return &timer_func[i];
+ }
+ }
+ for (i=0;i<MAX_TIMERS;i++) {
+ if (!timer_func[i].func) {
+ return &timer_func[i];
+ }
+ }
+
+ return NULL;
+}
+
+int pc_install_int (PFUNC func, void *parm, unsigned int freq)
+{
+ int i;
+ TIMER *t;
+
+ if (!timer_installed) {
+ if (install_timer()) {
+ return -1;
+ }
+ }
+
+ if ((t=find_slot(func))!=NULL) {
+ unsigned int new_counter = PIT_FREQ / freq;
+
+ DISABLE();
+
+ t->func = func;
+ t->parm = parm;
+ t->freq = freq;
+ t->clock_ticks = 0;
+
+ if (new_counter < timer_main.counter) {
+ for (i=0;i<MAX_TIMERS;i++) {
+ if (timer_func[i].func) {
+ timer_func[i].counter = new_counter * timer_func[i].freq / freq;
+ }
+ }
+ outportb(0x43, 0x34);
+ outportb(0x40, (unsigned char)new_counter);
+ outportb(0x40, (unsigned char)(new_counter>>8));
+ timer_main.clock_ticks = 0;
+ timer_main.counter = new_counter;
+ timer_main.freq = freq;
+ } else {
+ t->counter = PIT_FREQ * freq / (timer_main.freq * timer_main.freq);
+ }
+
+ ENABLE();
+
+ return 0;
+ }
+
+ return -1;
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 3.4\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include "glutint.h"\r
-\r
-\r
-\r
-GLUTidleCB g_idle_func = NULL;\r
-\r
-\r
-\r
-void APIENTRY glutDisplayFunc (GLUTdisplayCB func)\r
-{\r
- g_curwin->display = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutReshapeFunc (GLUTreshapeCB func)\r
-{\r
- g_curwin->reshape = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutKeyboardFunc (GLUTkeyboardCB func)\r
-{\r
- g_curwin->keyboard = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutMouseFunc (GLUTmouseCB func)\r
-{\r
- g_curwin->mouse = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutMotionFunc (GLUTmotionCB func)\r
-{\r
- g_curwin->motion = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutPassiveMotionFunc (GLUTpassiveCB func)\r
-{\r
- g_curwin->passive = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutEntryFunc (GLUTentryCB func)\r
-{\r
- g_curwin->entry = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutVisibilityFunc (GLUTvisibilityCB func)\r
-{\r
- g_curwin->visibility = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutWindowStatusFunc (GLUTwindowStatusCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutIdleFunc (GLUTidleCB func)\r
-{\r
- g_idle_func = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutTimerFunc (unsigned int millis, GLUTtimerCB func, int value)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSpecialFunc (GLUTspecialCB func)\r
-{\r
- g_curwin->special = func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSpaceballMotionFunc (GLUTspaceMotionCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSpaceballRotateFunc (GLUTspaceRotateCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSpaceballButtonFunc (GLUTspaceButtonCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutDialsFunc (GLUTdialsCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutButtonBoxFunc (GLUTbuttonBoxCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutTabletMotionFunc (GLUTtabletMotionCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutTabletButtonFunc (GLUTtabletButtonCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutJoystickFunc (GLUTjoystickCB func, int interval)\r
-{\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include "glutint.h"
+
+
+
+GLUTidleCB g_idle_func = NULL;
+
+
+
+void APIENTRY glutDisplayFunc (GLUTdisplayCB func)
+{
+ g_curwin->display = func;
+}
+
+
+
+void APIENTRY glutReshapeFunc (GLUTreshapeCB func)
+{
+ g_curwin->reshape = func;
+}
+
+
+
+void APIENTRY glutKeyboardFunc (GLUTkeyboardCB func)
+{
+ g_curwin->keyboard = func;
+}
+
+
+
+void APIENTRY glutMouseFunc (GLUTmouseCB func)
+{
+ g_curwin->mouse = func;
+}
+
+
+
+void APIENTRY glutMotionFunc (GLUTmotionCB func)
+{
+ g_curwin->motion = func;
+}
+
+
+
+void APIENTRY glutPassiveMotionFunc (GLUTpassiveCB func)
+{
+ g_curwin->passive = func;
+}
+
+
+
+void APIENTRY glutEntryFunc (GLUTentryCB func)
+{
+ g_curwin->entry = func;
+}
+
+
+
+void APIENTRY glutVisibilityFunc (GLUTvisibilityCB func)
+{
+ g_curwin->visibility = func;
+}
+
+
+
+void APIENTRY glutWindowStatusFunc (GLUTwindowStatusCB func)
+{
+}
+
+
+
+void APIENTRY glutIdleFunc (GLUTidleCB func)
+{
+ g_idle_func = func;
+}
+
+
+
+void APIENTRY glutTimerFunc (unsigned int millis, GLUTtimerCB func, int value)
+{
+}
+
+
+
+void APIENTRY glutSpecialFunc (GLUTspecialCB func)
+{
+ g_curwin->special = func;
+}
+
+
+
+void APIENTRY glutSpaceballMotionFunc (GLUTspaceMotionCB func)
+{
+}
+
+
+
+void APIENTRY glutSpaceballRotateFunc (GLUTspaceRotateCB func)
+{
+}
+
+
+
+void APIENTRY glutSpaceballButtonFunc (GLUTspaceButtonCB func)
+{
+}
+
+
+
+void APIENTRY glutDialsFunc (GLUTdialsCB func)
+{
+}
+
+
+
+void APIENTRY glutButtonBoxFunc (GLUTbuttonBoxCB func)
+{
+}
+
+
+
+void APIENTRY glutTabletMotionFunc (GLUTtabletMotionCB func)
+{
+}
+
+
+
+void APIENTRY glutTabletButtonFunc (GLUTtabletButtonCB func)
+{
+}
+
+
+
+void APIENTRY glutJoystickFunc (GLUTjoystickCB func, int interval)
+{
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 3.4\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include "glutint.h"\r
-#include "GL/dmesa.h"\r
-\r
-\r
-\r
-#define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))\r
-\r
-\r
-\r
-void APIENTRY glutSetColor (int ndx, GLfloat red, GLfloat green, GLfloat blue)\r
-{\r
- if (g_display_mode & GLUT_INDEX) {\r
- if ((ndx >= 0) && (ndx < (256 - RESERVED_COLORS))) {\r
- DMesaSetCI(ndx, CLAMP(red), CLAMP(green), CLAMP(blue));\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-GLfloat APIENTRY glutGetColor (int ndx, int component)\r
-{\r
- return 0.0;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutCopyColormap (int win)\r
-{\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include "glutint.h"
+#include "GL/dmesa.h"
+
+
+
+#define CLAMP(i) ((i) > 1.0 ? 1.0 : ((i) < 0.0 ? 0.0 : (i)))
+
+
+
+void APIENTRY glutSetColor (int ndx, GLfloat red, GLfloat green, GLfloat blue)
+{
+ if (g_display_mode & GLUT_INDEX) {
+ if ((ndx >= 0) && (ndx < (256 - RESERVED_COLORS))) {
+ DMesaSetCI(ndx, CLAMP(red), CLAMP(green), CLAMP(blue));
+ }
+ }
+}
+
+
+
+GLfloat APIENTRY glutGetColor (int ndx, int component)
+{
+ return 0.0;
+}
+
+
+
+void APIENTRY glutCopyColormap (int win)
+{
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 3.4\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include <string.h>\r
-\r
-#include "GL/glut.h"\r
-\r
-\r
-\r
-int APIENTRY glutExtensionSupported (const char *extension)\r
-{\r
- static const GLubyte *extensions = NULL;\r
- const GLubyte *last, *where;\r
-\r
- /* Extension names should not have spaces. */\r
- if (strchr(extension, ' ') || *extension == '\0') {\r
- return GL_FALSE;\r
- }\r
-\r
- /* Not my problem if you don't have a valid OpenGL context */\r
- if (!extensions) {\r
- extensions = glGetString(GL_EXTENSIONS);\r
- }\r
-\r
- /* Take care of sub-strings etc. */\r
- for (last = extensions;;) {\r
- if ((where = (GLubyte *)strstr((const char *)last, extension)) == NULL) {\r
- return GL_FALSE;\r
- }\r
- last = where + strlen(extension);\r
- if (where == extensions || *(where - 1) == ' ') {\r
- if (*last == ' ' || *last == '\0') {\r
- return GL_TRUE;\r
- }\r
- }\r
- }\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <string.h>
+
+#include "GL/glut.h"
+
+
+
+int APIENTRY glutExtensionSupported (const char *extension)
+{
+ static const GLubyte *extensions = NULL;
+ const GLubyte *last, *where;
+
+ /* Extension names should not have spaces. */
+ if (strchr(extension, ' ') || *extension == '\0') {
+ return GL_FALSE;
+ }
+
+ /* Not my problem if you don't have a valid OpenGL context */
+ if (!extensions) {
+ extensions = glGetString(GL_EXTENSIONS);
+ }
+
+ /* Take care of sub-strings etc. */
+ for (last = extensions;;) {
+ if ((where = (GLubyte *)strstr((const char *)last, extension)) == NULL) {
+ return GL_FALSE;
+ }
+ last = where + strlen(extension);
+ if (where == extensions || *(where - 1) == ' ') {
+ if (*last == ' ' || *last == '\0') {
+ return GL_TRUE;
+ }
+ }
+ }
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.0\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
- \r
-#ifndef __glutint_h__\r
-#define __glutint_h__\r
-\r
-#include <GL/glut.h>\r
-\r
-#include "GL/dmesa.h"\r
-\r
-\r
-\r
-/* GLUT function types */\r
-typedef void (GLUTCALLBACK *GLUTdisplayCB) (void);\r
-typedef void (GLUTCALLBACK *GLUTreshapeCB) (int, int);\r
-typedef void (GLUTCALLBACK *GLUTkeyboardCB) (unsigned char, int, int);\r
-typedef void (GLUTCALLBACK *GLUTmouseCB) (int, int, int, int);\r
-typedef void (GLUTCALLBACK *GLUTmotionCB) (int, int);\r
-typedef void (GLUTCALLBACK *GLUTpassiveCB) (int, int);\r
-typedef void (GLUTCALLBACK *GLUTentryCB) (int);\r
-typedef void (GLUTCALLBACK *GLUTvisibilityCB) (int);\r
-typedef void (GLUTCALLBACK *GLUTwindowStatusCB) (int);\r
-typedef void (GLUTCALLBACK *GLUTidleCB) (void);\r
-typedef void (GLUTCALLBACK *GLUTtimerCB) (int);\r
-typedef void (GLUTCALLBACK *GLUTmenuStateCB) (int); /* DEPRECATED. */\r
-typedef void (GLUTCALLBACK *GLUTmenuStatusCB) (int, int, int);\r
-typedef void (GLUTCALLBACK *GLUTselectCB) (int);\r
-typedef void (GLUTCALLBACK *GLUTspecialCB) (int, int, int);\r
-typedef void (GLUTCALLBACK *GLUTspaceMotionCB) (int, int, int);\r
-typedef void (GLUTCALLBACK *GLUTspaceRotateCB) (int, int, int);\r
-typedef void (GLUTCALLBACK *GLUTspaceButtonCB) (int, int);\r
-typedef void (GLUTCALLBACK *GLUTdialsCB) (int, int);\r
-typedef void (GLUTCALLBACK *GLUTbuttonBoxCB) (int, int);\r
-typedef void (GLUTCALLBACK *GLUTtabletMotionCB) (int, int);\r
-typedef void (GLUTCALLBACK *GLUTtabletButtonCB) (int, int, int, int);\r
-typedef void (GLUTCALLBACK *GLUTjoystickCB) (unsigned int, int, int, int);\r
-\r
-typedef struct GLUTwindow {\r
- int num; /* window id */\r
-\r
- DMesaBuffer buffer;\r
-\r
- int show_mouse;\r
-\r
- /* GLUT settable or visible window state. */\r
- int xpos;\r
- int ypos;\r
- int width; /* window width in pixels */\r
- int height; /* window height in pixels */\r
-\r
- /* Per-window callbacks. */\r
- GLUTdisplayCB display; /* redraw */\r
- GLUTreshapeCB reshape; /* resize (width,height) */\r
- GLUTmouseCB mouse; /* mouse (button,state,x,y) */\r
- GLUTmotionCB motion; /* motion (x,y) */\r
- GLUTpassiveCB passive; /* passive motion (x,y) */\r
- GLUTentryCB entry; /* window entry/exit (state) */\r
- GLUTkeyboardCB keyboard; /* keyboard (ASCII,x,y) */\r
- GLUTkeyboardCB keyboardUp; /* keyboard up (ASCII,x,y) */\r
- GLUTwindowStatusCB windowStatus; /* window status */\r
- GLUTvisibilityCB visibility; /* visibility */\r
- GLUTspecialCB special; /* special key */\r
- GLUTspecialCB specialUp; /* special up key */\r
- GLUTbuttonBoxCB buttonBox; /* button box */\r
- GLUTdialsCB dials; /* dials */\r
- GLUTspaceMotionCB spaceMotion; /* Spaceball motion */\r
- GLUTspaceRotateCB spaceRotate; /* Spaceball rotate */\r
- GLUTspaceButtonCB spaceButton; /* Spaceball button */\r
- GLUTtabletMotionCB tabletMotion; /* tablet motion */\r
- GLUTtabletButtonCB tabletButton; /* tablet button */\r
- GLUTjoystickCB joystick; /* joystick */\r
-} GLUTwindow;\r
-\r
-extern GLUTidleCB g_idle_func;\r
-extern GLUTmenuStatusCB g_menu_status_func;\r
-\r
-extern GLboolean g_redisplay;\r
-\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
-extern GLuint g_init_w, g_init_h; /* initial window size */\r
-\r
-extern int g_mouse; /* non-zero if mouse installed */\r
-extern int g_mouse_x, g_mouse_y; /* mouse coords, relative to current win */\r
-\r
-extern GLUTwindow *g_curwin; /* current window */\r
-\r
-extern char *__glutProgramName; /* program name */\r
-\r
-extern void __glutInitMouse (void);\r
-\r
-/* private routines from glut_util.c */\r
-extern char * __glutStrdup(const char *string);\r
-extern void __glutWarning(char *format,...);\r
-extern void __glutFatalError(char *format,...);\r
-extern void __glutFatalUsage(char *format,...);\r
-\r
-\r
-\r
-/* hmmm... */\r
-#include "pc_hw/pc_hw.h"\r
-\r
-\r
-\r
-#define MAX_WINDOWS 2\r
-\r
-#define DEFAULT_WIDTH 300\r
-#define DEFAULT_HEIGHT 300\r
-#define DEFAULT_BPP 16\r
-\r
-#define DEPTH_SIZE 16\r
-#define STENCIL_SIZE 8\r
-#define ACCUM_SIZE 16\r
-\r
-#define RESERVED_COLORS 0\r
-\r
-#endif /* __glutint_h__ */\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef __glutint_h__
+#define __glutint_h__
+
+#include <GL/glut.h>
+
+#include "GL/dmesa.h"
+
+
+
+/* GLUT function types */
+typedef void (GLUTCALLBACK *GLUTdisplayCB) (void);
+typedef void (GLUTCALLBACK *GLUTreshapeCB) (int, int);
+typedef void (GLUTCALLBACK *GLUTkeyboardCB) (unsigned char, int, int);
+typedef void (GLUTCALLBACK *GLUTmouseCB) (int, int, int, int);
+typedef void (GLUTCALLBACK *GLUTmotionCB) (int, int);
+typedef void (GLUTCALLBACK *GLUTpassiveCB) (int, int);
+typedef void (GLUTCALLBACK *GLUTentryCB) (int);
+typedef void (GLUTCALLBACK *GLUTvisibilityCB) (int);
+typedef void (GLUTCALLBACK *GLUTwindowStatusCB) (int);
+typedef void (GLUTCALLBACK *GLUTidleCB) (void);
+typedef void (GLUTCALLBACK *GLUTtimerCB) (int);
+typedef void (GLUTCALLBACK *GLUTmenuStateCB) (int); /* DEPRECATED. */
+typedef void (GLUTCALLBACK *GLUTmenuStatusCB) (int, int, int);
+typedef void (GLUTCALLBACK *GLUTselectCB) (int);
+typedef void (GLUTCALLBACK *GLUTspecialCB) (int, int, int);
+typedef void (GLUTCALLBACK *GLUTspaceMotionCB) (int, int, int);
+typedef void (GLUTCALLBACK *GLUTspaceRotateCB) (int, int, int);
+typedef void (GLUTCALLBACK *GLUTspaceButtonCB) (int, int);
+typedef void (GLUTCALLBACK *GLUTdialsCB) (int, int);
+typedef void (GLUTCALLBACK *GLUTbuttonBoxCB) (int, int);
+typedef void (GLUTCALLBACK *GLUTtabletMotionCB) (int, int);
+typedef void (GLUTCALLBACK *GLUTtabletButtonCB) (int, int, int, int);
+typedef void (GLUTCALLBACK *GLUTjoystickCB) (unsigned int, int, int, int);
+
+typedef struct GLUTwindow {
+ int num; /* window id */
+
+ DMesaBuffer buffer;
+
+ int show_mouse;
+
+ /* GLUT settable or visible window state. */
+ int xpos;
+ int ypos;
+ int width; /* window width in pixels */
+ int height; /* window height in pixels */
+
+ /* Per-window callbacks. */
+ GLUTdisplayCB display; /* redraw */
+ GLUTreshapeCB reshape; /* resize (width,height) */
+ GLUTmouseCB mouse; /* mouse (button,state,x,y) */
+ GLUTmotionCB motion; /* motion (x,y) */
+ GLUTpassiveCB passive; /* passive motion (x,y) */
+ GLUTentryCB entry; /* window entry/exit (state) */
+ GLUTkeyboardCB keyboard; /* keyboard (ASCII,x,y) */
+ GLUTkeyboardCB keyboardUp; /* keyboard up (ASCII,x,y) */
+ GLUTwindowStatusCB windowStatus; /* window status */
+ GLUTvisibilityCB visibility; /* visibility */
+ GLUTspecialCB special; /* special key */
+ GLUTspecialCB specialUp; /* special up key */
+ GLUTbuttonBoxCB buttonBox; /* button box */
+ GLUTdialsCB dials; /* dials */
+ GLUTspaceMotionCB spaceMotion; /* Spaceball motion */
+ GLUTspaceRotateCB spaceRotate; /* Spaceball rotate */
+ GLUTspaceButtonCB spaceButton; /* Spaceball button */
+ GLUTtabletMotionCB tabletMotion; /* tablet motion */
+ GLUTtabletButtonCB tabletButton; /* tablet button */
+ GLUTjoystickCB joystick; /* joystick */
+} GLUTwindow;
+
+extern GLUTidleCB g_idle_func;
+extern GLUTmenuStatusCB g_menu_status_func;
+
+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 */
+extern GLuint g_init_w, g_init_h; /* initial window size */
+
+extern int g_mouse; /* non-zero if mouse installed */
+extern int g_mouse_x, g_mouse_y; /* mouse coords, relative to current win */
+
+extern GLUTwindow *g_curwin; /* current window */
+
+extern char *__glutProgramName; /* program name */
+
+extern void __glutInitMouse (void);
+
+/* private routines from glut_util.c */
+extern char * __glutStrdup(const char *string);
+extern void __glutWarning(char *format,...);
+extern void __glutFatalError(char *format,...);
+extern void __glutFatalUsage(char *format,...);
+
+
+
+/* hmmm... */
+#include "pc_hw/pc_hw.h"
+
+
+
+#define MAX_WINDOWS 2
+
+#define DEFAULT_WIDTH 300
+#define DEFAULT_HEIGHT 300
+#define DEFAULT_BPP 16
+
+#define DEPTH_SIZE 16
+#define STENCIL_SIZE 8
+#define ACCUM_SIZE 16
+
+#define RESERVED_COLORS 0
+
+#endif /* __glutint_h__ */
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.0\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include <string.h>\r
-\r
-#include "glutint.h"\r
-\r
-\r
-\r
-GLboolean g_redisplay = GL_FALSE;\r
-\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
-GLuint g_init_w = DEFAULT_WIDTH, g_init_h = DEFAULT_HEIGHT;\r
-\r
-char *__glutProgramName = NULL;\r
-\r
-\r
-\r
-void APIENTRY glutInit (int *argc, char **argv)\r
-{\r
- char *str;\r
- const char *env;\r
-\r
- if ((env = getenv("DMESA_GLUT_BPP")) != NULL) {\r
- g_bpp = atoi(env);\r
- }\r
- if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) {\r
- g_refresh = atoi(env);\r
- }\r
-\r
- /* Determine program name. */\r
- str = strrchr(argv[0], '/');\r
- if (str == NULL) {\r
- str = argv[0];\r
- } else {\r
- str++;\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
-\r
-void APIENTRY glutInitDisplayMode (unsigned int mode)\r
-{\r
- g_display_mode = mode;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutInitWindowPosition (int x, int y)\r
-{\r
- g_init_x = x;\r
- g_init_y = y;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutInitWindowSize (int width, int height)\r
-{\r
- g_init_w = width;\r
- g_init_h = height;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutMainLoop (void)\r
-{\r
- GLboolean idle;\r
- static int old_mouse_x = 0;\r
- static int old_mouse_y = 0;\r
- static int old_mouse_b = 0;\r
-\r
- {\r
- GLint screen_size[2];\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
- __glutInitMouse();\r
-\r
- glutPostRedisplay();\r
- if (g_curwin->reshape) {\r
- g_curwin->reshape(g_curwin->width, g_curwin->height);\r
- }\r
- if (g_curwin->visibility) {\r
- g_curwin->visibility(GLUT_VISIBLE);\r
- }\r
-\r
- while (GL_TRUE) {\r
- idle = GL_TRUE;\r
-\r
- if (g_redisplay && g_curwin->display) {\r
- idle = GL_FALSE;\r
- g_redisplay = GL_FALSE;\r
-\r
- if (g_curwin->show_mouse && !(g_display_mode & GLUT_DOUBLE)) {\r
- /* XXX scare mouse */\r
- g_curwin->display();\r
- /* XXX unscare mouse */\r
- } else {\r
- g_curwin->display();\r
- }\r
- }\r
-\r
- if (g_mouse) {\r
- int mouse_x;\r
- int mouse_y;\r
- int mouse_z;\r
- int mouse_b;\r
-\r
- /* query mouse */\r
- mouse_b = pc_query_mouse(&mouse_x, &mouse_y, &mouse_z);\r
-\r
- /* relative to window coordinates */\r
- g_mouse_x = mouse_x - g_curwin->xpos;\r
- g_mouse_y = mouse_y - g_curwin->ypos;\r
-\r
- /* mouse was moved? */\r
- if ((mouse_x != old_mouse_x) || (mouse_y != old_mouse_y)) {\r
- idle = GL_FALSE;\r
- old_mouse_x = mouse_x;\r
- old_mouse_y = mouse_y;\r
-\r
- if (mouse_b) {\r
- /* any button pressed */\r
- if (g_curwin->motion) {\r
- g_curwin->motion(g_mouse_x, g_mouse_y);\r
- }\r
- } else {\r
- /* no button pressed */\r
- if (g_curwin->passive) {\r
- g_curwin->passive(g_mouse_x, g_mouse_y);\r
- }\r
- }\r
- }\r
-\r
- /* button state changed? */\r
- if (mouse_b != old_mouse_b) {\r
- GLUTmouseCB mouse_func;\r
-\r
- if ((mouse_func = g_curwin->mouse)) {\r
- if ((old_mouse_b & 1) && !(mouse_b & 1))\r
- mouse_func(GLUT_LEFT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);\r
- else if (!(old_mouse_b & 1) && (mouse_b & 1))\r
- mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);\r
-\r
- if ((old_mouse_b & 2) && !(mouse_b & 2))\r
- mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);\r
- else if (!(old_mouse_b & 2) && (mouse_b & 2))\r
- mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);\r
-\r
- if ((old_mouse_b & 4) && !(mouse_b & 4))\r
- mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);\r
- else if (!(old_mouse_b & 3) && (mouse_b & 4))\r
- mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);\r
- }\r
-\r
- idle = GL_FALSE;\r
- old_mouse_b = mouse_b;\r
- }\r
- }\r
-\r
- if (pc_keypressed()) {\r
- int key;\r
- int glut_key;\r
-\r
- idle = GL_FALSE;\r
- key = pc_readkey();\r
-\r
- switch (key>>16) {\r
- case KEY_F1: glut_key = GLUT_KEY_F1; goto special;\r
- case KEY_F2: glut_key = GLUT_KEY_F2; goto special;\r
- case KEY_F3: glut_key = GLUT_KEY_F3; goto special;\r
- case KEY_F4: glut_key = GLUT_KEY_F4; goto special;\r
- case KEY_F5: glut_key = GLUT_KEY_F5; goto special;\r
- case KEY_F6: glut_key = GLUT_KEY_F6; goto special;\r
- case KEY_F7: glut_key = GLUT_KEY_F7; goto special;\r
- case KEY_F8: glut_key = GLUT_KEY_F8; goto special;\r
- case KEY_F9: glut_key = GLUT_KEY_F9; goto special;\r
- case KEY_F10: glut_key = GLUT_KEY_F10; goto special;\r
- case KEY_F11: glut_key = GLUT_KEY_F11; goto special;\r
- case KEY_F12: glut_key = GLUT_KEY_F12; goto special;\r
- case KEY_LEFT: glut_key = GLUT_KEY_LEFT; goto special;\r
- case KEY_UP: glut_key = GLUT_KEY_UP; goto special;\r
- case KEY_RIGHT: glut_key = GLUT_KEY_RIGHT; goto special;\r
- case KEY_DOWN: glut_key = GLUT_KEY_DOWN; goto special;\r
- case KEY_PGUP: glut_key = GLUT_KEY_PAGE_UP; goto special;\r
- case KEY_PGDN: glut_key = GLUT_KEY_PAGE_DOWN; goto special;\r
- case KEY_HOME: glut_key = GLUT_KEY_HOME; goto special;\r
- case KEY_END: glut_key = GLUT_KEY_END; goto special;\r
- case KEY_INSERT: glut_key = GLUT_KEY_INSERT; goto special;\r
- special:\r
- if (g_curwin->special) {\r
- g_curwin->special(glut_key, g_mouse_x, g_mouse_y);\r
- }\r
- break;\r
- default:\r
- if (g_curwin->keyboard) {\r
- g_curwin->keyboard(key & 0xFF, g_mouse_x, g_mouse_y);\r
- }\r
- }\r
- }\r
-\r
- if (idle && g_idle_func)\r
- g_idle_func();\r
- }\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <string.h>
+
+#include "glutint.h"
+
+
+
+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;
+GLuint g_init_w = DEFAULT_WIDTH, g_init_h = DEFAULT_HEIGHT;
+
+char *__glutProgramName = NULL;
+
+
+
+void APIENTRY glutInit (int *argc, char **argv)
+{
+ char *str;
+ const char *env;
+
+ if ((env = getenv("DMESA_GLUT_BPP")) != NULL) {
+ g_bpp = atoi(env);
+ }
+ if ((env = getenv("DMESA_GLUT_REFRESH")) != NULL) {
+ g_refresh = atoi(env);
+ }
+
+ /* Determine program name. */
+ str = strrchr(argv[0], '/');
+ if (str == NULL) {
+ str = argv[0];
+ } else {
+ str++;
+ }
+ __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);
+}
+
+
+
+void APIENTRY glutInitDisplayMode (unsigned int mode)
+{
+ g_display_mode = mode;
+}
+
+
+
+void APIENTRY glutInitWindowPosition (int x, int y)
+{
+ g_init_x = x;
+ g_init_y = y;
+}
+
+
+
+void APIENTRY glutInitWindowSize (int width, int height)
+{
+ g_init_w = width;
+ g_init_h = height;
+}
+
+
+
+void APIENTRY glutMainLoop (void)
+{
+ GLboolean idle;
+ static int old_mouse_x = 0;
+ static int old_mouse_y = 0;
+ static int old_mouse_b = 0;
+
+ {
+ GLint screen_size[2];
+ 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();
+ __glutInitMouse();
+
+ glutPostRedisplay();
+ if (g_curwin->reshape) {
+ g_curwin->reshape(g_curwin->width, g_curwin->height);
+ }
+ if (g_curwin->visibility) {
+ g_curwin->visibility(GLUT_VISIBLE);
+ }
+
+ while (GL_TRUE) {
+ idle = GL_TRUE;
+
+ if (g_redisplay && g_curwin->display) {
+ idle = GL_FALSE;
+ g_redisplay = GL_FALSE;
+
+ if (g_curwin->show_mouse && !(g_display_mode & GLUT_DOUBLE)) {
+ /* XXX scare mouse */
+ g_curwin->display();
+ /* XXX unscare mouse */
+ } else {
+ g_curwin->display();
+ }
+ }
+
+ if (g_mouse) {
+ int mouse_x;
+ int mouse_y;
+ int mouse_z;
+ int mouse_b;
+
+ /* query mouse */
+ mouse_b = pc_query_mouse(&mouse_x, &mouse_y, &mouse_z);
+
+ /* relative to window coordinates */
+ g_mouse_x = mouse_x - g_curwin->xpos;
+ g_mouse_y = mouse_y - g_curwin->ypos;
+
+ /* mouse was moved? */
+ if ((mouse_x != old_mouse_x) || (mouse_y != old_mouse_y)) {
+ idle = GL_FALSE;
+ old_mouse_x = mouse_x;
+ old_mouse_y = mouse_y;
+
+ if (mouse_b) {
+ /* any button pressed */
+ if (g_curwin->motion) {
+ g_curwin->motion(g_mouse_x, g_mouse_y);
+ }
+ } else {
+ /* no button pressed */
+ if (g_curwin->passive) {
+ g_curwin->passive(g_mouse_x, g_mouse_y);
+ }
+ }
+ }
+
+ /* button state changed? */
+ if (mouse_b != old_mouse_b) {
+ GLUTmouseCB mouse_func;
+
+ if ((mouse_func = g_curwin->mouse)) {
+ if ((old_mouse_b & 1) && !(mouse_b & 1))
+ mouse_func(GLUT_LEFT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
+ else if (!(old_mouse_b & 1) && (mouse_b & 1))
+ mouse_func(GLUT_LEFT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
+
+ if ((old_mouse_b & 2) && !(mouse_b & 2))
+ mouse_func(GLUT_RIGHT_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
+ else if (!(old_mouse_b & 2) && (mouse_b & 2))
+ mouse_func(GLUT_RIGHT_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
+
+ if ((old_mouse_b & 4) && !(mouse_b & 4))
+ mouse_func(GLUT_MIDDLE_BUTTON, GLUT_UP, g_mouse_x, g_mouse_y);
+ else if (!(old_mouse_b & 3) && (mouse_b & 4))
+ mouse_func(GLUT_MIDDLE_BUTTON, GLUT_DOWN, g_mouse_x, g_mouse_y);
+ }
+
+ idle = GL_FALSE;
+ old_mouse_b = mouse_b;
+ }
+ }
+
+ if (pc_keypressed()) {
+ int key;
+ int glut_key;
+
+ idle = GL_FALSE;
+ key = pc_readkey();
+
+ switch (key>>16) {
+ case KEY_F1: glut_key = GLUT_KEY_F1; goto special;
+ case KEY_F2: glut_key = GLUT_KEY_F2; goto special;
+ case KEY_F3: glut_key = GLUT_KEY_F3; goto special;
+ case KEY_F4: glut_key = GLUT_KEY_F4; goto special;
+ case KEY_F5: glut_key = GLUT_KEY_F5; goto special;
+ case KEY_F6: glut_key = GLUT_KEY_F6; goto special;
+ case KEY_F7: glut_key = GLUT_KEY_F7; goto special;
+ case KEY_F8: glut_key = GLUT_KEY_F8; goto special;
+ case KEY_F9: glut_key = GLUT_KEY_F9; goto special;
+ case KEY_F10: glut_key = GLUT_KEY_F10; goto special;
+ case KEY_F11: glut_key = GLUT_KEY_F11; goto special;
+ case KEY_F12: glut_key = GLUT_KEY_F12; goto special;
+ case KEY_LEFT: glut_key = GLUT_KEY_LEFT; goto special;
+ case KEY_UP: glut_key = GLUT_KEY_UP; goto special;
+ case KEY_RIGHT: glut_key = GLUT_KEY_RIGHT; goto special;
+ case KEY_DOWN: glut_key = GLUT_KEY_DOWN; goto special;
+ case KEY_PGUP: glut_key = GLUT_KEY_PAGE_UP; goto special;
+ case KEY_PGDN: glut_key = GLUT_KEY_PAGE_DOWN; goto special;
+ case KEY_HOME: glut_key = GLUT_KEY_HOME; goto special;
+ case KEY_END: glut_key = GLUT_KEY_END; goto special;
+ case KEY_INSERT: glut_key = GLUT_KEY_INSERT; goto special;
+ special:
+ if (g_curwin->special) {
+ g_curwin->special(glut_key, g_mouse_x, g_mouse_y);
+ }
+ break;
+ default:
+ if (g_curwin->keyboard) {
+ g_curwin->keyboard(key & 0xFF, g_mouse_x, g_mouse_y);
+ }
+ }
+ }
+
+ if (idle && g_idle_func)
+ g_idle_func();
+ }
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 3.4\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include "glutint.h"\r
-\r
-\r
-\r
-GLUTmenuStatusCB g_menu_status_func = NULL;\r
-\r
-\r
-\r
-void APIENTRY glutMenuStateFunc (GLUTmenuStateCB func)\r
-{\r
- g_menu_status_func = (GLUTmenuStatusCB)func;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutMenuStatusFunc (GLUTmenuStatusCB func)\r
-{\r
- g_menu_status_func = func;\r
-}\r
-\r
-\r
-\r
-int APIENTRY glutCreateMenu (GLUTselectCB func)\r
-{\r
- return 0;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutDestroyMenu (int menu)\r
-{\r
-}\r
-\r
-\r
-\r
-int APIENTRY glutGetMenu (void)\r
-{\r
- return 0;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSetMenu (int menu)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutAddMenuEntry (const char *label, int value)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutAddSubMenu (const char *label, int submenu)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutChangeToMenuEntry (int item, const char *label, int value)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutChangeToSubMenu (int item, const char *label, int submenu)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutRemoveMenuItem (int item)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutAttachMenu (int button)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutDetachMenu (int button)\r
-{\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include "glutint.h"
+
+
+
+GLUTmenuStatusCB g_menu_status_func = NULL;
+
+
+
+void APIENTRY glutMenuStateFunc (GLUTmenuStateCB func)
+{
+ g_menu_status_func = (GLUTmenuStatusCB)func;
+}
+
+
+
+void APIENTRY glutMenuStatusFunc (GLUTmenuStatusCB func)
+{
+ g_menu_status_func = func;
+}
+
+
+
+int APIENTRY glutCreateMenu (GLUTselectCB func)
+{
+ return 0;
+}
+
+
+
+void APIENTRY glutDestroyMenu (int menu)
+{
+}
+
+
+
+int APIENTRY glutGetMenu (void)
+{
+ return 0;
+}
+
+
+
+void APIENTRY glutSetMenu (int menu)
+{
+}
+
+
+
+void APIENTRY glutAddMenuEntry (const char *label, int value)
+{
+}
+
+
+
+void APIENTRY glutAddSubMenu (const char *label, int submenu)
+{
+}
+
+
+
+void APIENTRY glutChangeToMenuEntry (int item, const char *label, int value)
+{
+}
+
+
+
+void APIENTRY glutChangeToSubMenu (int item, const char *label, int submenu)
+{
+}
+
+
+
+void APIENTRY glutRemoveMenuItem (int item)
+{
+}
+
+
+
+void APIENTRY glutAttachMenu (int button)
+{
+}
+
+
+
+void APIENTRY glutDetachMenu (int button)
+{
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 3.4\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include "glutint.h"\r
-\r
-\r
-\r
-int g_mouse;\r
-int g_mouse_x = 0, g_mouse_y = 0;\r
-\r
-\r
-\r
-void __glutInitMouse (void)\r
-{\r
- if ((g_mouse = pc_install_mouse())) {\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
-\r
-void APIENTRY glutSetCursor (int cursor)\r
-{\r
- /* XXX completely futile until full mouse support (maybe never) */\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutWarpPointer (int x, int y)\r
-{\r
- pc_warp_mouse(x, y);\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include "glutint.h"
+
+
+
+int g_mouse;
+int g_mouse_x = 0, g_mouse_y = 0;
+
+
+
+void __glutInitMouse (void)
+{
+ if ((g_mouse = pc_install_mouse())) {
+ 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);
+ }
+}
+
+
+
+void APIENTRY glutSetCursor (int cursor)
+{
+ /* XXX completely futile until full mouse support (maybe never) */
+}
+
+
+
+void APIENTRY glutWarpPointer (int x, int y)
+{
+ pc_warp_mouse(x, y);
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 3.4\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include "glutint.h"\r
-\r
-\r
-\r
-int APIENTRY glutLayerGet (GLenum info)\r
-{\r
- switch (info) {\r
- case GLUT_OVERLAY_POSSIBLE:\r
- case GLUT_HAS_OVERLAY:\r
- return GL_FALSE;\r
- case GLUT_LAYER_IN_USE:\r
- return GLUT_NORMAL;\r
- case GLUT_NORMAL_DAMAGED:\r
- return GL_FALSE;\r
- case GLUT_OVERLAY_DAMAGED:\r
- case GLUT_TRANSPARENT_INDEX:\r
- default:\r
- return -1;\r
- }\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutOverlayDisplayFunc (GLUTdisplayCB func)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutEstablishOverlay (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutRemoveOverlay (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutUseLayer (GLenum layer)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutPostOverlayRedisplay (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutShowOverlay (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutHideOverlay (void)\r
-{\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include "glutint.h"
+
+
+
+int APIENTRY glutLayerGet (GLenum info)
+{
+ switch (info) {
+ case GLUT_OVERLAY_POSSIBLE:
+ case GLUT_HAS_OVERLAY:
+ return GL_FALSE;
+ case GLUT_LAYER_IN_USE:
+ return GLUT_NORMAL;
+ case GLUT_NORMAL_DAMAGED:
+ return GL_FALSE;
+ case GLUT_OVERLAY_DAMAGED:
+ case GLUT_TRANSPARENT_INDEX:
+ default:
+ return -1;
+ }
+}
+
+
+
+void APIENTRY glutOverlayDisplayFunc (GLUTdisplayCB func)
+{
+}
+
+
+
+void APIENTRY glutEstablishOverlay (void)
+{
+}
+
+
+
+void APIENTRY glutRemoveOverlay (void)
+{
+}
+
+
+
+void APIENTRY glutUseLayer (GLenum layer)
+{
+}
+
+
+
+void APIENTRY glutPostOverlayRedisplay (void)
+{
+}
+
+
+
+void APIENTRY glutShowOverlay (void)
+{
+}
+
+
+
+void APIENTRY glutHideOverlay (void)
+{
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 3.4\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#include "glutint.h"\r
-\r
-\r
-\r
-#define FREQUENCY 100\r
-\r
-\r
-\r
-static int timer_installed;\r
-static volatile int ticks;\r
-\r
-\r
-\r
-static void ticks_timer (void *p)\r
-{\r
- (void)p;\r
- ticks++;\r
-} ENDOFUNC(ticks_timer)\r
-\r
-\r
-\r
-int APIENTRY glutGet (GLenum type)\r
-{\r
- switch (type) {\r
- case GLUT_WINDOW_X:\r
- return g_curwin->xpos;\r
- case GLUT_WINDOW_Y:\r
- return g_curwin->ypos;\r
- case GLUT_WINDOW_WIDTH:\r
- return g_curwin->width;\r
- case GLUT_WINDOW_HEIGHT:\r
- return g_curwin->height;\r
- case GLUT_WINDOW_STENCIL_SIZE:\r
- return STENCIL_SIZE;\r
- case GLUT_WINDOW_DEPTH_SIZE:\r
- return DEPTH_SIZE;\r
- case GLUT_WINDOW_RGBA:\r
- return !(g_display_mode & GLUT_INDEX);\r
- case GLUT_WINDOW_COLORMAP_SIZE:\r
- return (g_display_mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0;\r
- case GLUT_SCREEN_WIDTH:\r
- return g_screen_w;\r
- case GLUT_SCREEN_HEIGHT:\r
- return g_screen_h;\r
- case GLUT_INIT_WINDOW_X:\r
- return g_init_x;\r
- case GLUT_INIT_WINDOW_Y:\r
- return g_init_y;\r
- case GLUT_INIT_WINDOW_WIDTH:\r
- return g_init_w;\r
- case GLUT_INIT_WINDOW_HEIGHT:\r
- return g_init_h;\r
- case GLUT_INIT_DISPLAY_MODE:\r
- return g_display_mode;\r
- case GLUT_ELAPSED_TIME:\r
- if (!timer_installed) {\r
- timer_installed = GL_TRUE;\r
- LOCKDATA(ticks);\r
- LOCKFUNC(ticks_timer);\r
- pc_install_int(ticks_timer, NULL, FREQUENCY);\r
- }\r
- return ticks*1000/FREQUENCY;\r
- default:\r
- return -1;\r
- }\r
-}\r
-\r
-\r
-\r
-int APIENTRY glutDeviceGet (GLenum type)\r
-{\r
- switch (type) {\r
- case GLUT_HAS_KEYBOARD:\r
- return GL_TRUE;\r
- case GLUT_HAS_MOUSE:\r
- return (g_mouse != 0);\r
- case GLUT_NUM_MOUSE_BUTTONS:\r
- return g_mouse;\r
- case GLUT_HAS_SPACEBALL:\r
- case GLUT_HAS_DIAL_AND_BUTTON_BOX:\r
- case GLUT_HAS_TABLET:\r
- return GL_FALSE;\r
- case GLUT_NUM_SPACEBALL_BUTTONS:\r
- case GLUT_NUM_BUTTON_BOX_BUTTONS:\r
- case GLUT_NUM_DIALS:\r
- case GLUT_NUM_TABLET_BUTTONS:\r
- return 0;\r
- default:\r
- return -1;\r
- }\r
-}\r
-\r
-\r
-\r
-int APIENTRY glutGetModifiers (void)\r
-{\r
- int mod = 0;\r
- int shifts = pc_keyshifts();\r
-\r
- if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) {\r
- mod |= GLUT_ACTIVE_SHIFT;\r
- }\r
-\r
- if (shifts & KB_ALT_FLAG) {\r
- mod |= GLUT_ACTIVE_ALT;\r
- }\r
-\r
- if (shifts & KB_CTRL_FLAG) {\r
- mod |= GLUT_ACTIVE_CTRL;\r
- }\r
-\r
- return mod;\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 3.4
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include "glutint.h"
+
+
+
+#define FREQUENCY 100
+
+
+
+static int timer_installed;
+static volatile int ticks;
+
+
+
+static void ticks_timer (void *p)
+{
+ (void)p;
+ ticks++;
+} ENDOFUNC(ticks_timer)
+
+
+
+int APIENTRY glutGet (GLenum type)
+{
+ switch (type) {
+ case GLUT_WINDOW_X:
+ return g_curwin->xpos;
+ case GLUT_WINDOW_Y:
+ return g_curwin->ypos;
+ case GLUT_WINDOW_WIDTH:
+ return g_curwin->width;
+ case GLUT_WINDOW_HEIGHT:
+ return g_curwin->height;
+ case GLUT_WINDOW_STENCIL_SIZE:
+ return STENCIL_SIZE;
+ case GLUT_WINDOW_DEPTH_SIZE:
+ return DEPTH_SIZE;
+ case GLUT_WINDOW_RGBA:
+ return !(g_display_mode & GLUT_INDEX);
+ case GLUT_WINDOW_COLORMAP_SIZE:
+ return (g_display_mode & GLUT_INDEX) ? (256 - RESERVED_COLORS) : 0;
+ case GLUT_SCREEN_WIDTH:
+ return g_screen_w;
+ case GLUT_SCREEN_HEIGHT:
+ return g_screen_h;
+ case GLUT_INIT_WINDOW_X:
+ return g_init_x;
+ case GLUT_INIT_WINDOW_Y:
+ return g_init_y;
+ case GLUT_INIT_WINDOW_WIDTH:
+ return g_init_w;
+ case GLUT_INIT_WINDOW_HEIGHT:
+ return g_init_h;
+ case GLUT_INIT_DISPLAY_MODE:
+ return g_display_mode;
+ case GLUT_ELAPSED_TIME:
+ if (!timer_installed) {
+ timer_installed = GL_TRUE;
+ LOCKDATA(ticks);
+ LOCKFUNC(ticks_timer);
+ pc_install_int(ticks_timer, NULL, FREQUENCY);
+ }
+ return ticks*1000/FREQUENCY;
+ default:
+ return -1;
+ }
+}
+
+
+
+int APIENTRY glutDeviceGet (GLenum type)
+{
+ switch (type) {
+ case GLUT_HAS_KEYBOARD:
+ return GL_TRUE;
+ case GLUT_HAS_MOUSE:
+ return (g_mouse != 0);
+ case GLUT_NUM_MOUSE_BUTTONS:
+ return g_mouse;
+ case GLUT_HAS_SPACEBALL:
+ case GLUT_HAS_DIAL_AND_BUTTON_BOX:
+ case GLUT_HAS_TABLET:
+ return GL_FALSE;
+ case GLUT_NUM_SPACEBALL_BUTTONS:
+ case GLUT_NUM_BUTTON_BOX_BUTTONS:
+ case GLUT_NUM_DIALS:
+ case GLUT_NUM_TABLET_BUTTONS:
+ return 0;
+ default:
+ return -1;
+ }
+}
+
+
+
+int APIENTRY glutGetModifiers (void)
+{
+ int mod = 0;
+ int shifts = pc_keyshifts();
+
+ if (shifts & (KB_SHIFT_FLAG | KB_CAPSLOCK_FLAG)) {
+ mod |= GLUT_ACTIVE_SHIFT;
+ }
+
+ if (shifts & KB_ALT_FLAG) {
+ mod |= GLUT_ACTIVE_ALT;
+ }
+
+ if (shifts & KB_CTRL_FLAG) {
+ mod |= GLUT_ACTIVE_CTRL;
+ }
+
+ return mod;
+}
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 4.1\r
- * Copyright (C) 1995-1998 Brian Paul\r
- *\r
- * This library is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU Library General Public\r
- * License as published by the Free Software Foundation; either\r
- * version 2 of the License, or (at your option) any later version.\r
- *\r
- * This library is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
- * Library General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU Library General Public\r
- * License along with this library; if not, write to the Free\r
- * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- */\r
-\r
-/*\r
- * DOS/DJGPP glut driver v1.3 for Mesa\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\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
-static GLUTwindow *windows[MAX_WINDOWS];\r
-\r
-\r
-\r
-static void clean (void)\r
-{\r
- int i;\r
-\r
- for (i=1; i<=MAX_WINDOWS; i++) {\r
- glutDestroyWindow(i);\r
- }\r
- if (context) DMesaDestroyContext(context);\r
- if (visual) DMesaDestroyVisual(visual);\r
-\r
- pc_close_stdout();\r
- pc_close_stderr();\r
-}\r
-\r
-\r
-\r
-int APIENTRY glutCreateWindow (const char *title)\r
-{\r
- int i;\r
- int m8width = (g_init_w + 7) & ~7;\r
-\r
- if (!visual) {\r
- if ((visual=DMesaCreateVisual(g_init_x + m8width, g_init_y + g_init_h, g_bpp, g_refresh,\r
- g_display_mode & GLUT_DOUBLE,\r
- !(g_display_mode & GLUT_INDEX),\r
- g_display_mode & GLUT_ALPHA,\r
- g_display_mode & GLUT_DEPTH ?DEPTH_SIZE :0,\r
- g_display_mode & GLUT_STENCIL?STENCIL_SIZE:0,\r
- g_display_mode & GLUT_ACCUM ?ACCUM_SIZE :0))==NULL) {\r
- return 0;\r
- }\r
-\r
- if ((context=DMesaCreateContext(visual, NULL))==NULL) {\r
- DMesaDestroyVisual(visual);\r
- return 0;\r
- }\r
-\r
- pc_open_stdout();\r
- pc_open_stderr();\r
- pc_atexit(clean);\r
- }\r
-\r
- for (i=0; i<MAX_WINDOWS; i++) {\r
- if (windows[i] == NULL) {\r
- DMesaBuffer b;\r
- GLUTwindow *w;\r
-\r
- if ((w=(GLUTwindow *)calloc(1, sizeof(GLUTwindow))) == NULL) {\r
- return 0;\r
- }\r
-\r
- if ((b=DMesaCreateBuffer(visual, g_init_x, g_init_y, m8width, g_init_h))==NULL) {\r
- free(w);\r
- return 0;\r
- }\r
- if (!DMesaMakeCurrent(context, b)) {\r
- DMesaDestroyBuffer(b);\r
- free(w);\r
- return 0;\r
- }\r
-\r
- g_curwin = windows[i] = w;\r
-\r
- w->num = ++i;\r
- w->xpos = g_init_x;\r
- w->ypos = g_init_y;\r
- w->width = m8width;\r
- w->height = g_init_h;\r
- w->buffer = b;\r
-\r
- return i;\r
- }\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-int APIENTRY glutCreateSubWindow (int win, int x, int y, int width, int height)\r
-{\r
- return GL_FALSE;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutDestroyWindow (int win)\r
-{\r
- if (windows[--win]) {\r
- DMesaDestroyBuffer(windows[win]->buffer);\r
- free(windows[win]);\r
- windows[win] = NULL;\r
- }\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutPostRedisplay (void)\r
-{\r
- g_redisplay = GL_TRUE;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSwapBuffers (void)\r
-{\r
- if (g_curwin->show_mouse) {\r
- /* XXX scare mouse */\r
- DMesaSwapBuffers(g_curwin->buffer);\r
- /* XXX unscare mouse */\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
-\r
-int APIENTRY glutGetWindow (void)\r
-{\r
- return g_curwin->num;\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSetWindow (int win)\r
-{\r
- g_curwin = windows[win - 1];\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSetWindowTitle (const char *title)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutSetIconTitle (const char *title)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutPositionWindow (int x, int y)\r
-{\r
- if (DMesaMoveBuffer(x, y)) {\r
- g_curwin->xpos = x;\r
- g_curwin->ypos = y;\r
- }\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutReshapeWindow (int width, int height)\r
-{ \r
- if (DMesaResizeBuffer(width, height)) {\r
- g_curwin->width = width;\r
- g_curwin->height = height;\r
- if (g_curwin->reshape) {\r
- g_curwin->reshape(width, height);\r
- } else {\r
- glViewport(0, 0, width, height);\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutFullScreen (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutPopWindow (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutPushWindow (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutIconifyWindow (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutShowWindow (void)\r
-{\r
-}\r
-\r
-\r
-\r
-void APIENTRY glutHideWindow (void)\r
-{\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.1
+ * Copyright (C) 1995-1998 Brian Paul
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free
+ * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+/*
+ * DOS/DJGPP glut driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#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;
+static GLUTwindow *windows[MAX_WINDOWS];
+
+
+
+static void clean (void)
+{
+ int i;
+
+ for (i=1; i<=MAX_WINDOWS; i++) {
+ glutDestroyWindow(i);
+ }
+ if (context) DMesaDestroyContext(context);
+ if (visual) DMesaDestroyVisual(visual);
+
+ pc_close_stdout();
+ pc_close_stderr();
+}
+
+
+
+int APIENTRY glutCreateWindow (const char *title)
+{
+ int i;
+ int m8width = (g_init_w + 7) & ~7;
+
+ if (!visual) {
+ if ((visual=DMesaCreateVisual(g_init_x + m8width, g_init_y + g_init_h, g_bpp, g_refresh,
+ g_display_mode & GLUT_DOUBLE,
+ !(g_display_mode & GLUT_INDEX),
+ g_display_mode & GLUT_ALPHA,
+ g_display_mode & GLUT_DEPTH ?DEPTH_SIZE :0,
+ g_display_mode & GLUT_STENCIL?STENCIL_SIZE:0,
+ g_display_mode & GLUT_ACCUM ?ACCUM_SIZE :0))==NULL) {
+ return 0;
+ }
+
+ if ((context=DMesaCreateContext(visual, NULL))==NULL) {
+ DMesaDestroyVisual(visual);
+ return 0;
+ }
+
+ pc_open_stdout();
+ pc_open_stderr();
+ pc_atexit(clean);
+ }
+
+ for (i=0; i<MAX_WINDOWS; i++) {
+ if (windows[i] == NULL) {
+ DMesaBuffer b;
+ GLUTwindow *w;
+
+ if ((w=(GLUTwindow *)calloc(1, sizeof(GLUTwindow))) == NULL) {
+ return 0;
+ }
+
+ if ((b=DMesaCreateBuffer(visual, g_init_x, g_init_y, m8width, g_init_h))==NULL) {
+ free(w);
+ return 0;
+ }
+ if (!DMesaMakeCurrent(context, b)) {
+ DMesaDestroyBuffer(b);
+ free(w);
+ return 0;
+ }
+
+ g_curwin = windows[i] = w;
+
+ w->num = ++i;
+ w->xpos = g_init_x;
+ w->ypos = g_init_y;
+ w->width = m8width;
+ w->height = g_init_h;
+ w->buffer = b;
+
+ return i;
+ }
+ }
+
+ return 0;
+}
+
+
+
+int APIENTRY glutCreateSubWindow (int win, int x, int y, int width, int height)
+{
+ return GL_FALSE;
+}
+
+
+
+void APIENTRY glutDestroyWindow (int win)
+{
+ if (windows[--win]) {
+ DMesaDestroyBuffer(windows[win]->buffer);
+ free(windows[win]);
+ windows[win] = NULL;
+ }
+}
+
+
+
+void APIENTRY glutPostRedisplay (void)
+{
+ g_redisplay = GL_TRUE;
+}
+
+
+
+void APIENTRY glutSwapBuffers (void)
+{
+ if (g_curwin->show_mouse) {
+ /* XXX scare mouse */
+ DMesaSwapBuffers(g_curwin->buffer);
+ /* XXX unscare mouse */
+ } 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;
+ }
+ }
+}
+
+
+
+int APIENTRY glutGetWindow (void)
+{
+ return g_curwin->num;
+}
+
+
+
+void APIENTRY glutSetWindow (int win)
+{
+ g_curwin = windows[win - 1];
+}
+
+
+
+void APIENTRY glutSetWindowTitle (const char *title)
+{
+}
+
+
+
+void APIENTRY glutSetIconTitle (const char *title)
+{
+}
+
+
+
+void APIENTRY glutPositionWindow (int x, int y)
+{
+ if (DMesaMoveBuffer(x, y)) {
+ g_curwin->xpos = x;
+ g_curwin->ypos = y;
+ }
+}
+
+
+
+void APIENTRY glutReshapeWindow (int width, int height)
+{
+ if (DMesaResizeBuffer(width, height)) {
+ g_curwin->width = width;
+ g_curwin->height = height;
+ if (g_curwin->reshape) {
+ g_curwin->reshape(width, height);
+ } else {
+ glViewport(0, 0, width, height);
+ }
+ }
+}
+
+
+
+void APIENTRY glutFullScreen (void)
+{
+}
+
+
+
+void APIENTRY glutPopWindow (void)
+{
+}
+
+
+
+void APIENTRY glutPushWindow (void)
+{
+}
+
+
+
+void APIENTRY glutIconifyWindow (void)
+{
+}
+
+
+
+void APIENTRY glutShowWindow (void)
+{
+}
+
+
+
+void APIENTRY glutHideWindow (void)
+{
+}
--- /dev/null
+# Mesa 3-D graphics library
+# Version: 5.1
+#
+# Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+#
+# Permission is hereby granted, free of charge, to any person obtaining a
+# copy of this software and associated documentation files (the "Software"),
+# to deal in the Software without restriction, including without limitation
+# the rights to use, copy, modify, merge, publish, distribute, sublicense,
+# and/or sell copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included
+# in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+# BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+# DOS/DJGPP core makefile v1.4 for Mesa
+#
+# Copyright (C) 2002 - Borca Daniel
+# Email : dborca@yahoo.com
+# Web : http://www.geocities.com/dborca
+
+
+#
+# Available options:
+#
+# Environment variables:
+# CFLAGS
+#
+# GLIDE path to Glide3 SDK include files; used with FX.
+# default = $(TOP)/include/glide3
+# FX=1 build for 3dfx Glide3. Note that this disables
+# compilation of most DMesa code and requires fxMesa.
+# 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
+# supports MMX instruction set. However, the true CPU
+# capabilities are checked at run-time to avoid crashes.
+# default = no
+# HAVE_SSE=1 (see HAVE_MMX)
+# default = no
+# HAVE_3DNOW=1 (see HAVE_MMX)
+# default = no
+#
+# Targets:
+# all: build GL
+# clean: remove object files
+#
+
+
+
+.PHONY: all clean
+.INTERMEDIATE: x86/gen_matypes.exe
+
+TOP = ../..
+GLIDE ?= $(TOP)/include/glide3
+LIBDIR = $(TOP)/lib
+GL_LIB = libgl.a
+GL_DXE = gl.dxe
+GL_IMP = libigl.a
+
+export LD_LIBRARY_PATH := $(LD_LIBRARY_PATH);$(LIBDIR)
+
+CC = gcc
+CFLAGS += -I$(TOP)/include -I. -Imain -Iglapi
+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
+ARFLAGS = rus
+
+HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)
+
+ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)
+UNLINK = del $(subst /,\,$(1))
+else
+UNLINK = $(RM) $(1)
+endif
+
+MAIN_SOURCES = \
+ main/api_arrayelt.c \
+ main/api_loopback.c \
+ main/api_noop.c \
+ main/api_validate.c \
+ main/accum.c \
+ main/arbprogram.c \
+ main/attrib.c \
+ main/blend.c \
+ main/bufferobj.c \
+ main/buffers.c \
+ main/clip.c \
+ main/colortab.c \
+ main/context.c \
+ main/convolve.c \
+ main/debug.c \
+ main/depth.c \
+ main/dispatch.c \
+ main/dlist.c \
+ main/drawpix.c \
+ main/enable.c \
+ main/enums.c \
+ main/eval.c \
+ main/extensions.c \
+ main/feedback.c \
+ main/fog.c \
+ main/get.c \
+ main/hash.c \
+ main/hint.c \
+ main/histogram.c \
+ main/image.c \
+ main/imports.c \
+ main/light.c \
+ main/lines.c \
+ main/matrix.c \
+ main/nvprogram.c \
+ main/nvfragparse.c \
+ main/nvvertexec.c \
+ main/nvvertparse.c \
+ main/occlude.c \
+ main/pixel.c \
+ main/points.c \
+ main/polygon.c \
+ main/rastpos.c \
+ main/state.c \
+ main/stencil.c \
+ main/texcompress.c \
+ main/texformat.c \
+ main/teximage.c \
+ main/texobj.c \
+ main/texstate.c \
+ main/texstore.c \
+ main/texutil.c \
+ main/varray.c \
+ main/vtxfmt.c
+
+GLAPI_SOURCES = \
+ glapi/glapi.c \
+ glapi/glthread.c
+
+MATH_SOURCES = \
+ math/m_debug_clip.c \
+ math/m_debug_norm.c \
+ math/m_debug_xform.c \
+ math/m_eval.c \
+ math/m_matrix.c \
+ math/m_translate.c \
+ math/m_vector.c \
+ math/m_xform.c
+
+ARRAY_CACHE_SOURCES = \
+ array_cache/ac_context.c \
+ array_cache/ac_import.c
+
+SWRAST_SOURCES = \
+ swrast/s_aaline.c \
+ swrast/s_aatriangle.c \
+ swrast/s_accum.c \
+ swrast/s_alpha.c \
+ swrast/s_alphabuf.c \
+ swrast/s_bitmap.c \
+ swrast/s_blend.c \
+ swrast/s_buffers.c \
+ swrast/s_copypix.c \
+ swrast/s_context.c \
+ swrast/s_depth.c \
+ swrast/s_drawpix.c \
+ swrast/s_feedback.c \
+ swrast/s_fog.c \
+ swrast/s_imaging.c \
+ swrast/s_lines.c \
+ swrast/s_logic.c \
+ swrast/s_masking.c \
+ swrast/s_nvfragprog.c \
+ swrast/s_pixeltex.c \
+ swrast/s_points.c \
+ swrast/s_readpix.c \
+ swrast/s_span.c \
+ swrast/s_stencil.c \
+ swrast/s_texture.c \
+ swrast/s_texstore.c \
+ swrast/s_triangle.c \
+ swrast/s_zoom.c
+
+SWRAST_SETUP_SOURCES = \
+ swrast_setup/ss_context.c \
+ swrast_setup/ss_triangle.c \
+ swrast_setup/ss_vb.c
+
+TNL_SOURCES = \
+ tnl/t_array_api.c \
+ tnl/t_array_import.c \
+ tnl/t_context.c \
+ tnl/t_eval_api.c \
+ tnl/t_imm_alloc.c \
+ tnl/t_imm_api.c \
+ tnl/t_imm_debug.c \
+ tnl/t_imm_dlist.c \
+ tnl/t_imm_elt.c \
+ tnl/t_imm_eval.c \
+ tnl/t_imm_exec.c \
+ tnl/t_imm_fixup.c \
+ tnl/t_pipeline.c \
+ tnl/t_vb_fog.c \
+ tnl/t_vb_light.c \
+ tnl/t_vb_normals.c \
+ tnl/t_vb_points.c \
+ tnl/t_vb_program.c \
+ tnl/t_vb_render.c \
+ tnl/t_vb_texgen.c \
+ tnl/t_vb_texmat.c \
+ tnl/t_vb_vertex.c
+
+X86_SOURCES = \
+ x86/x86.c \
+ x86/glapi_x86.S \
+ x86/common_x86.c \
+ x86/common_x86_asm.S \
+ x86/x86_xform2.S \
+ x86/x86_xform3.S \
+ x86/x86_xform4.S \
+ x86/x86_cliptest.S
+
+MMX_SOURCES = \
+ x86/mmx_blend.S
+
+SSE_SOURCES = \
+ x86/sse.c \
+ x86/sse_xform2.S \
+ x86/sse_xform3.S \
+ x86/sse_xform4.S \
+ x86/sse_normal.S
+
+K3D_SOURCES = \
+ x86/3dnow.c \
+ x86/3dnow_xform2.S \
+ x86/3dnow_xform3.S \
+ x86/3dnow_xform4.S \
+ x86/3dnow_normal.S
+
+CORE_SOURCES = \
+ $(MAIN_SOURCES) \
+ $(GLAPI_SOURCES) \
+ $(MATH_SOURCES) \
+ $(ARRAY_CACHE_SOURCES) \
+ $(SWRAST_SOURCES) \
+ $(SWRAST_SETUP_SOURCES) \
+ $(TNL_SOURCES)
+
+ifeq ($(HAVE_MMX),1)
+X86_SOURCES += $(MMX_SOURCES)
+CFLAGS += -DUSE_MMX_ASM
+HAVE_X86 = 1
+endif
+ifeq ($(HAVE_SSE),1)
+X86_SOURCES += $(SSE_SOURCES)
+CFLAGS += -DUSE_SSE_ASM
+HAVE_X86 = 1
+endif
+ifeq ($(HAVE_3DNOW),1)
+X86_SOURCES += $(K3D_SOURCES)
+CFLAGS += -DUSE_3DNOW_ASM
+HAVE_X86 = 1
+endif
+ifeq ($(HAVE_X86),1)
+CFLAGS += -DUSE_X86_ASM
+else
+X86_SOURCES =
+endif
+
+DRIVER_SOURCES = \
+ drivers/dos/dmesa.c
+ifeq ($(FX),1)
+DRIVER_SOURCES += \
+ drivers/glide/fxapi.c \
+ drivers/glide/fxdd.c \
+ drivers/glide/fxddspan.c \
+ drivers/glide/fxddtex.c \
+ drivers/glide/fxsetup.c \
+ drivers/glide/fxtexman.c \
+ drivers/glide/fxtris.c \
+ drivers/glide/fxvb.c \
+ drivers/glide/fxglidew.c
+else
+ifeq ($(MATROX),1)
+DRIVER_SOURCES += \
+ drivers/dos/mga/mga.c \
+ drivers/dos/mga/mga_hw.c \
+ drivers/dos/mga/mga_mode.c \
+ drivers/dos/dpmi.c
+else
+DRIVER_SOURCES += \
+ drivers/dos/video.c \
+ drivers/dos/virtual.S \
+ drivers/dos/vesa.c \
+ drivers/dos/blit.S \
+ drivers/dos/vga.c \
+ drivers/dos/dpmi.c
+endif
+endif
+
+SOURCES = $(CORE_SOURCES) $(X86_SOURCES) $(DRIVER_SOURCES)
+
+OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))
+
+X86_OBJECTS = $(addsuffix .o,$(basename $(X86_SOURCES)))
+
+.c.o:
+ $(CC) -o $@ $(CFLAGS) -c $<
+.S.o:
+ $(CC) -o $@ $(CFLAGS) -c $<
+.s.o:
+ $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $<
+
+all: $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GL_DXE) $(LIBDIR)/$(GL_IMP)
+
+$(LIBDIR)/$(GL_LIB): $(OBJECTS)
+ $(AR) $(ARFLAGS) $(LIBDIR)/$(GL_LIB) $(OBJECTS)
+
+$(LIBDIR)/$(GL_DXE) $(LIBDIR)/$(GL_IMP): $(OBJECTS)
+ifeq ($(HAVEDXE3),)
+ $(warning Missing DXE3 package... Skipping $(GL_DXE))
+else
+ifeq ($(FX),1)
+ -dxe3gen -o $(LIBDIR)/$(GL_DXE) -Y $(LIBDIR)/$(GL_IMP) -D $(LIBNAME) -E _gl -E _DMesa -P glid3.dxe -U $(OBJECTS)
+else
+ -dxe3gen -o $(LIBDIR)/$(GL_DXE) -Y $(LIBDIR)/$(GL_IMP) -D $(LIBNAME) -E _gl -E _DMesa -U $(OBJECTS)
+endif
+endif
+
+$(X86_OBJECTS): x86/matypes.h
+
+x86/matypes.h: x86/gen_matypes.exe
+ $< > $@
+
+x86/gen_matypes.exe: x86/gen_matypes.c
+ $(CC) -o $@ $(CFLAGS) -s $<
+
+clean:
+ -$(call UNLINK,array_cache/*.o)
+ -$(call UNLINK,glapi/*.o)
+ -$(call UNLINK,main/*.o)
+ -$(call UNLINK,math/*.o)
+ -$(call UNLINK,swrast/*.o)
+ -$(call UNLINK,swrast_setup/*.o)
+ -$(call UNLINK,tnl/*.o)
+ -$(call UNLINK,x86/*.o)
+ -$(call UNLINK,drivers/dos/*.o)
+ -$(call UNLINK,drivers/dos/mga/*.o)
+ -$(call UNLINK,drivers/glide/*.o)
+
+-include depend
-/*\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\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
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+ .file "blit.S"
+
+/*
+ * extern unsigned int vesa_gran_mask, vesa_gran_shift;
+ * extern int vl_video_selector;
+
+ * extern void *vl_current_draw_buffer;
+ * extern int vl_current_stride, vl_current_height;
+ * extern int vl_current_offset, vl_current_delta;
+ */
+
+ .text
+
+/* Desc: VESA bank switching routine (BIOS)
+ *
+ * In : EBX=0, EDX = bank number
+ * Out : -
+ *
+ * Note: thrashes EAX
+ */
+ .p2align 5,,31
+_vesa_swbankBIOS:
+ movw $0x4f05, %ax
+ int $0x10
+ ret
+
+ .p2align 2,,3
+ .global _vesa_swbank
+_vesa_swbank: .long _vesa_swbankBIOS
+
+/* Desc: void vesa_b_dump_virtual (void);
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _vesa_b_dump_virtual
+_vesa_b_dump_virtual:
+ cld
+ pushl %es
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ pushl %ebp
+ movl _vl_video_selector, %es
+ movl _vl_current_draw_buffer, %esi
+ movl _vl_current_offset, %edi
+ movl _vesa_gran_shift, %ecx
+ movl _vesa_gran_mask, %ebp
+ movl %edi, %edx
+ xorl %ebx, %ebx
+ andl %ebp, %edi
+ shrl %cl, %edx
+ incl %ebp
+ call *_vesa_swbank
+ movl _vl_current_stride, %ecx
+ movl _vl_current_height, %eax
+ movl _vl_current_delta, %ebx
+ shrl $2, %ecx
+ .balign 4
+ 0:
+ pushl %ecx
+ .balign 4
+ 1:
+ cmpl %ebp, %edi
+ jb 2f
+ pushl %eax
+ pushl %ebx
+ incl %edx
+ xorl %ebx, %ebx
+ call *_vesa_swbank
+ popl %ebx
+ popl %eax
+ subl %ebp, %edi
+ .balign 4
+ 2:
+ movsl
+ decl %ecx
+ jnz 1b
+ popl %ecx
+ addl %ebx, %edi
+ decl %eax
+ jnz 0b
+ popl %ebp
+ popl %edi
+ popl %esi
+ popl %ebx
+ popl %es
+ ret
+
+/* Desc: void vesa_l_dump_virtual (void);
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _vesa_l_dump_virtual
+_vesa_l_dump_virtual:
+ cld
+ pushl %es
+ pushl %esi
+ pushl %edi
+ movl _vl_video_selector, %es
+ movl _vl_current_draw_buffer, %esi
+ movl _vl_current_offset, %edi
+ movl _vl_current_stride, %ecx
+ movl _vl_current_height, %edx
+ movl _vl_current_delta, %eax
+ shrl $2, %ecx
+ .balign 4
+ 0:
+ pushl %ecx
+ rep; movsl
+ popl %ecx
+ addl %eax, %edi
+ decl %edx
+ jnz 0b
+ popl %edi
+ popl %esi
+ popl %es
+ ret
+
+/* Desc: void vesa_l_dump_virtual_mmx (void);
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _vesa_l_dump_virtual_mmx
+_vesa_l_dump_virtual_mmx:
+#ifdef USE_MMX_ASM
+ pushl %esi
+ pushl %edi
+ movl _vl_video_selector, %fs
+ movl _vl_current_draw_buffer, %esi
+ movl _vl_current_offset, %edi
+ movl _vl_current_stride, %ecx
+ movl _vl_current_height, %edx
+ movl _vl_current_delta, %eax
+ shrl $3, %ecx
+ .balign 4
+ 0:
+ pushl %ecx
+ .balign 4
+ 1:
+ movq (%esi), %mm0
+ addl $8, %esi
+ movq %mm0, %fs:(%edi)
+ addl $8, %edi
+ decl %ecx
+ jnz 1b
+ popl %ecx
+ addl %eax, %edi
+ decl %edx
+ jnz 0b
+ popl %edi
+ popl %esi
+ emms
+#endif
+ ret
-/*\r
- * Mesa 3-D graphics library\r
- * Version: 5.0.1\r
- * \r
- * Copyright (C) 1999-2003 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\r
- *\r
- * Copyright (c) 2003 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#ifndef FX\r
-#include "glheader.h"\r
-#include "context.h"\r
-#include "extensions.h"\r
-#include "macros.h"\r
-#include "matrix.h"\r
-#include "mmath.h"\r
-#include "texformat.h"\r
-#include "texstore.h"\r
-#include "array_cache/acache.h"\r
-#include "swrast/s_context.h"\r
-#include "swrast/s_depth.h"\r
-#include "swrast/s_lines.h"\r
-#include "swrast/s_triangle.h"\r
-#include "swrast/s_trispan.h"\r
-#include "swrast/swrast.h"\r
-#include "swrast_setup/swrast_setup.h"\r
-#include "tnl/tnl.h"\r
-#include "tnl/t_context.h"\r
-#include "tnl/t_pipeline.h"\r
-#ifndef MATROX\r
-#include "video.h"\r
-#else /* MATROX */\r
-#include "mga/mga.h"\r
-#endif /* MATROX */\r
-#else /* FX */\r
-#include "../FX/fxdrv.h"\r
-#endif /* FX */\r
-\r
-#include "GL/dmesa.h"\r
-\r
-\r
-\r
-/*\r
- * In C++ terms, this class derives from the GLvisual class.\r
- * Add system-specific fields to it.\r
- */\r
-struct dmesa_visual {\r
- GLvisual gl_visual;\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
- * In C++ terms, this class derives from the GLframebuffer class.\r
- * Add system-specific fields to it.\r
- */\r
-struct dmesa_buffer {\r
- GLframebuffer gl_buffer; /* The depth, stencil, accum, etc buffers */\r
- void *the_window; /* your window handle, etc */\r
-\r
- int xpos, ypos; /* position */\r
- int width, height; /* size in pixels */\r
-};\r
-\r
-/*\r
- * In C++ terms, this class derives from the GLcontext class.\r
- * Add system-specific fields to it.\r
- */\r
-struct dmesa_context {\r
- GLcontext gl_ctx; /* the core library context */\r
- DMesaVisual visual;\r
- DMesaBuffer Buffer;\r
- GLuint ClearColor;\r
- GLuint ClearIndex;\r
- /* etc... */\r
-};\r
-\r
-\r
-\r
-#ifndef FX\r
-/****************************************************************************\r
- * Read/Write pixels\r
- ***************************************************************************/\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
- ***************************************************************************/\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 dmesa = (DMesaContext)ctx;\r
- GLuint i, offset;\r
-\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
- if (mask[i]) {\r
- vl_putpixel(offset, vl_mixrgba(rgba[i]));\r
- }\r
- }\r
- } else {\r
- /* draw all 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
-\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 dmesa = (DMesaContext)ctx;\r
- GLuint i, offset;\r
-\r
- offset = DSTRIDE * FLIP(y) + x;\r
- if (mask) {\r
- /* draw some pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- if (mask[i]) {\r
- vl_putpixel(offset, vl_mixrgb(rgb[i]));\r
- }\r
- }\r
- } else {\r
- /* draw all pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- vl_putpixel(offset, vl_mixrgb(rgb[i]));\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void write_mono_rgba_span (const GLcontext *ctx,\r
- GLuint n, GLint x, GLint y,\r
- const GLchan color[4], const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\r
- GLuint i, offset, rgba = vl_mixrgba(color);\r
-\r
- offset = DSTRIDE * FLIP(y) + x;\r
- if (mask) {\r
- /* draw some pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- if (mask[i]) {\r
- vl_putpixel(offset, rgba);\r
- }\r
- }\r
- } else {\r
- /* draw all pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- vl_putpixel(offset, rgba);\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void read_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
- GLubyte rgba[][4])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\r
- GLuint i, offset;\r
-\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
- }\r
-}\r
-\r
-\r
-\r
-static void write_rgba_pixels (const GLcontext *ctx,\r
- GLuint n, const GLint x[], const GLint y[],\r
- const GLubyte rgba[][4], const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\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
- }\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
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void write_mono_rgba_pixels (const GLcontext *ctx,\r
- GLuint n, const GLint x[], const GLint y[],\r
- const GLchan color[4], const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\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
- }\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
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void read_rgba_pixels (const GLcontext *ctx,\r
- GLuint n, const GLint x[], const GLint y[],\r
- GLubyte rgba[][4], const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\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
- }\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
- }\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 dmesa = (DMesaContext)ctx;\r
- GLuint i, offset;\r
-\r
- offset = DSTRIDE * FLIP(y) + x;\r
- if (mask) {\r
- /* draw some pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- if (mask[i]) {\r
- vl_putpixel(offset, index[i]);\r
- }\r
- }\r
- } else {\r
- /* draw all pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- vl_putpixel(offset, index[i]);\r
- }\r
- }\r
-}\r
-\r
-\r
-\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 dmesa = (DMesaContext)ctx;\r
- GLuint i, offset;\r
-\r
- offset = DSTRIDE * FLIP(y) + x;\r
- if (mask) {\r
- /* draw some pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- if (mask[i]) {\r
- vl_putpixel(offset, index[i]);\r
- }\r
- }\r
- } else {\r
- /* draw all pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- vl_putpixel(offset, index[i]);\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void write_mono_index_span (const GLcontext *ctx,\r
- GLuint n, GLint x, GLint y,\r
- GLuint colorIndex, const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\r
- GLuint i, offset;\r
-\r
- offset = DSTRIDE * FLIP(y) + x;\r
- if (mask) {\r
- /* draw some pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- if (mask[i]) {\r
- vl_putpixel(offset, colorIndex);\r
- }\r
- }\r
- } else {\r
- /* draw all pixels */\r
- for (i=0; i<n; i++, offset++) {\r
- vl_putpixel(offset, colorIndex);\r
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void read_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,\r
- GLuint index[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\r
- GLuint i, offset;\r
-\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
- }\r
-}\r
-\r
-\r
-\r
-static void write_index_pixels (const GLcontext *ctx,\r
- GLuint n, const GLint x[], const GLint y[],\r
- const GLuint index[], const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\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
- }\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
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void write_mono_index_pixels (const GLcontext *ctx,\r
- GLuint n, const GLint x[], const GLint y[],\r
- GLuint colorIndex, const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\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
- }\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
- }\r
- }\r
-}\r
-\r
-\r
-\r
-static void read_index_pixels (const GLcontext *ctx,\r
- GLuint n, const GLint x[], const GLint y[],\r
- GLuint index[], const GLubyte mask[])\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\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
- }\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
- }\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;\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;\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;\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;\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
- * Optimized triangle rendering\r
- ***************************************************************************/\r
-\r
-/*\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 dmesa = (DMesaContext)ctx;\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
- }\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
- * Z-less flat triangle.\r
- */\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 dmesa = (DMesaContext)ctx;\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
- }\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
- * NON-depth-buffered iterated triangle.\r
- */\r
-static void tri_rgb_iter (GLcontext *ctx,\r
- const SWvertex *v0,\r
- const SWvertex *v1,\r
- const SWvertex *v2)\r
-{\r
- const DMesaContext dmesa = (DMesaContext)ctx;\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
- 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
- span.green += span.greenStep; \\r
- span.blue += span.blueStep; \\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
- * Z-less iterated triangle.\r
- */\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 dmesa = (DMesaContext)ctx;\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
- 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, vl_mixfix(span.red, span.green, span.blue));\\r
- zRow[i] = z; \\r
- } \\r
- span.red += span.redStep; \\r
- span.green += span.greenStep; \\r
- span.blue += span.blueStep; \\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 *)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
-\r
-/*\r
- * Analyze context state to see if we can provide a fast triangle function\r
- * Otherwise, return NULL.\r
- */\r
-static swrast_tri_func dmesa_choose_tri_function (GLcontext *ctx)\r
-{\r
- const SWcontext *swrast = SWRAST_CONTEXT(ctx);\r
-\r
- if ((ctx->RenderMode != GL_RENDER)\r
- || (ctx->Polygon.SmoothFlag)\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
- return (swrast_tri_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) ? 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_iter : tri_rgb_flat;\r
- }\r
-\r
- return (swrast_tri_func)NULL;\r
-}\r
-\r
-\r
-\r
-/* Override for the swrast triangle-selection function. Try to use one\r
- * of our internal triangle functions, otherwise fall back to the\r
- * standard swrast functions.\r
- */\r
-static void dmesa_choose_tri (GLcontext *ctx)\r
-{\r
- SWcontext *swrast = SWRAST_CONTEXT(ctx);\r
-\r
- if (!(swrast->Triangle=dmesa_choose_tri_function(ctx)))\r
- _swrast_choose_triangle(ctx);\r
-}\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;\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;\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;\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;\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)ctx)->ClearIndex = index;\r
-}\r
-\r
-static void clear_color (GLcontext *ctx, const GLfloat color[4])\r
-{\r
- GLubyte col[4];\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
- ((DMesaContext)ctx)->ClearColor = vl_mixrgba(col);\r
-}\r
-\r
-\r
-\r
-static void clear (GLcontext *ctx, GLbitfield mask, GLboolean all,\r
- GLint x, GLint y, GLint width, GLint height)\r
-{\r
- const DMesaContext c = (DMesaContext)ctx;\r
- const GLuint *colorMask = (GLuint *)&ctx->Color.ColorMask;\r
-\r
-/*\r
- * Clear the specified region of the buffers indicated by 'mask'\r
- * using the clear color or index as specified by one of the two\r
- * functions above.\r
- * If all==GL_TRUE, clear whole buffer, else just clear region defined\r
- * by x,y,width,height\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
- if (all) {\r
- vl_clear(color);\r
- } else {\r
- vl_rect(x, y, width, height, color);\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
- _swrast_Clear(ctx, mask, all, x, y, width, height);\r
- }\r
-}\r
-\r
-\r
-\r
-static void set_buffer (GLcontext *ctx, GLframebuffer *colorBuffer, GLuint bufferBit)\r
-{\r
- /*\r
- * XXX todo - examine bufferBit and set read/write pointers\r
- */\r
-}\r
-\r
-\r
-\r
-/*\r
- * Return the width and height of the current buffer.\r
- * If anything special has to been done when the buffer/window is\r
- * resized, do it now.\r
- */\r
-static void get_buffer_size (GLframebuffer *buffer, GLuint *width, GLuint *height)\r
-{\r
- DMesaBuffer b = (DMesaBuffer)buffer;\r
-\r
- *width = b->width;\r
- *height = b->height;\r
-}\r
-\r
-\r
-\r
-static const GLubyte* get_string (GLcontext *ctx, GLenum name)\r
-{\r
- switch (name) {\r
- case GL_RENDERER:\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 mar-2003";\r
- default:\r
- return NULL;\r
- }\r
-}\r
-\r
-\r
-\r
-static void finish (GLcontext *ctx)\r
-{\r
- /*\r
- * XXX todo - OPTIONAL FUNCTION: implements glFinish if possible\r
- */\r
-}\r
-\r
-\r
-\r
-static void flush (GLcontext *ctx)\r
-{\r
- /*\r
- * XXX todo - OPTIONAL FUNCTION: implements glFlush if possible\r
- */\r
-}\r
-\r
-\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
- _NEW_DEPTH | \\r
- _NEW_RENDERMODE | \\r
- _SWRAST_NEW_RASTERMASK)\r
-\r
-/* Extend the software rasterizer with our line and triangle\r
- * functions.\r
- */\r
-static void dmesa_register_swrast_functions (GLcontext *ctx)\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
-\r
-\r
-/* Setup pointers and other driver state that is constant for the life\r
- * of a context.\r
- */\r
-static void dmesa_init_pointers (GLcontext *ctx)\r
-{\r
- TNLcontext *tnl;\r
- struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx);\r
-\r
- ctx->Driver.GetString = get_string;\r
- ctx->Driver.GetBufferSize = get_buffer_size;\r
- ctx->Driver.Flush = flush;\r
- ctx->Driver.Finish = finish;\r
- \r
- /* Software rasterizer pixel paths:\r
- */\r
- ctx->Driver.Accum = _swrast_Accum;\r
- ctx->Driver.Bitmap = _swrast_Bitmap;\r
- ctx->Driver.Clear = clear;\r
- ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;\r
- ctx->Driver.CopyPixels = _swrast_CopyPixels;\r
- ctx->Driver.DrawPixels = _swrast_DrawPixels;\r
- ctx->Driver.ReadPixels = _swrast_ReadPixels;\r
- ctx->Driver.DrawBuffer = _swrast_DrawBuffer;\r
-\r
- /* Software texture functions:\r
- */\r
- ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;\r
- ctx->Driver.TexImage1D = _mesa_store_teximage1d;\r
- ctx->Driver.TexImage2D = _mesa_store_teximage2d;\r
- ctx->Driver.TexImage3D = _mesa_store_teximage3d;\r
- ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;\r
- ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;\r
- ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;\r
- ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;\r
-\r
- ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;\r
- ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;\r
- ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;\r
- ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;\r
- ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;\r
-\r
- ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;\r
- ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;\r
- ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;\r
- ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;\r
- ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;\r
- ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;\r
-\r
- /* Swrast hooks for imaging extensions:\r
- */\r
- ctx->Driver.CopyColorTable = _swrast_CopyColorTable;\r
- ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;\r
- ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;\r
- ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;\r
-\r
- /* Statechange callbacks:\r
- */\r
- ctx->Driver.ClearColor = clear_color;\r
- ctx->Driver.ClearIndex = clear_index;\r
-\r
- /* Initialize the TNL driver interface:\r
- */\r
- tnl = TNL_CONTEXT(ctx);\r
- tnl->Driver.RunPipeline = _tnl_run_pipeline;\r
-\r
- dd->SetBuffer = set_buffer;\r
- \r
- /* Install swsetup for tnl->Driver.Render.*:\r
- */\r
- _swsetup_Wakeup(ctx);\r
-\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
-#ifdef MATROX\r
- if (((DMesaContext)ctx)->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->WriteMonoCISpan = write_mono_index_span;\r
- dd->WriteCI32Pixels = write_index_pixels;\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->WriteRGBSpan = write_rgb_span;\r
- dd->WriteMonoRGBASpan = write_mono_rgba_span;\r
- dd->WriteRGBAPixels = write_rgba_pixels;\r
- dd->WriteMonoRGBAPixels = write_mono_rgba_pixels;\r
- dd->ReadRGBASpan = read_rgba_span;\r
- dd->ReadRGBAPixels = read_rgba_pixels;\r
-}\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
-/****************************************************************************\r
- * DMesa Public API Functions\r
- ***************************************************************************/\r
-\r
-/*\r
- * The exact arguments to this function will depend on your window system\r
- */\r
-DMesaVisual DMesaCreateVisual (GLint width,\r
- GLint height,\r
- GLint colDepth,\r
- GLint refresh,\r
- GLboolean dbFlag,\r
- GLboolean rgbFlag,\r
- GLboolean alphaFlag,\r
- GLint depthSize,\r
- GLint stencilSize,\r
- GLint accumSize)\r
-{\r
-#ifndef FX\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
- if (!rgbFlag) {\r
- indexBits = 8;\r
- redBits = 0;\r
- greenBits = 0;\r
- blueBits = 0;\r
- } else {\r
- indexBits = 0;\r
- switch (colDepth) {\r
- case 8:\r
- redBits = 8;\r
- greenBits = 8;\r
- blueBits = 8;\r
- break;\r
- case 15:\r
- redBits = 5;\r
- greenBits = 5;\r
- blueBits = 5;\r
- break;\r
- case 16:\r
- redBits = 5;\r
- greenBits = 6;\r
- blueBits = 5;\r
- break;\r
- case 32:\r
- alphaBits = 8;\r
- case 24:\r
- redBits = 8;\r
- greenBits = 8;\r
- blueBits = 8;\r
- break;\r
- default:\r
- return NULL;\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
- }\r
-\r
- if ((v=(DMesaVisual)CALLOC_STRUCT(dmesa_visual)) != NULL) {\r
- /* Create core visual */\r
- _mesa_initialize_visual((GLvisual *)v,\r
- rgbFlag, /* rgb */\r
- dbFlag,\r
- GL_FALSE, /* stereo */\r
- redBits,\r
- greenBits,\r
- blueBits,\r
- alphaBits,\r
- indexBits, /* indexBits */\r
- depthSize,\r
- stencilSize,\r
- accumSize, /* accumRed */\r
- accumSize, /* accumGreen */\r
- accumSize, /* accumBlue */\r
- alphaFlag?accumSize:0, /* accumAlpha */\r
- 1); /* numSamples */\r
-\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 /* FX */\r
-\r
- int i = 0, fx_attrib[32];\r
-\r
- if (!rgbFlag) {\r
- return NULL;\r
- }\r
-\r
- if (dbFlag) fx_attrib[i++] = FXMESA_DOUBLEBUFFER;\r
- if (depthSize > 0) { fx_attrib[i++] = FXMESA_DEPTH_SIZE; fx_attrib[i++] = depthSize; }\r
- if (stencilSize > 0) { fx_attrib[i++] = FXMESA_STENCIL_SIZE; fx_attrib[i++] = stencilSize; }\r
- if (accumSize > 0) { fx_attrib[i++] = FXMESA_ACCUM_SIZE; fx_attrib[i++] = accumSize; }\r
- if (alphaFlag) { fx_attrib[i++] = FXMESA_ALPHA_SIZE; fx_attrib[i++] = 1; }\r
- fx_attrib[i] = FXMESA_NONE;\r
-\r
- return (DMesaVisual)fxMesaCreateBestContext(-1, width, height, fx_attrib);\r
-#endif /* FX */\r
-}\r
-\r
-\r
-\r
-void DMesaDestroyVisual (DMesaVisual v)\r
-{\r
-#ifndef FX\r
- _mesa_destroy_visual((GLvisual *)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
-\r
-\r
-\r
-DMesaBuffer DMesaCreateBuffer (DMesaVisual visual,\r
- GLint xpos, GLint ypos,\r
- GLint width, GLint height)\r
-{\r
-#ifndef FX\r
- DMesaBuffer b;\r
-\r
- if ((b=(DMesaBuffer)CALLOC_STRUCT(dmesa_buffer)) != NULL) {\r
- _mesa_initialize_framebuffer((GLframebuffer *)b,\r
- (GLvisual *)visual,\r
- visual->zbuffer == 1,\r
- ((GLvisual *)visual)->stencilBits > 0,\r
- ((GLvisual *)visual)->accumRedBits > 0,\r
- ((GLvisual *)visual)->alphaBits > 0);\r
- b->xpos = xpos;\r
- b->ypos = ypos;\r
- b->width = width;\r
- b->height = height;\r
- }\r
-\r
- return b;\r
-#else\r
- return (DMesaBuffer)visual;\r
-#endif\r
-}\r
-\r
-\r
-\r
-void DMesaDestroyBuffer (DMesaBuffer b)\r
-{\r
-#ifndef FX\r
-#ifndef MATROX\r
- free(b->the_window);\r
-#endif\r
- _mesa_destroy_framebuffer((GLframebuffer *)b);\r
-#endif\r
-}\r
-\r
-\r
-\r
-DMesaContext DMesaCreateContext (DMesaVisual visual,\r
- DMesaContext share)\r
-{\r
-#ifndef FX\r
- DMesaContext c;\r
- GLboolean direct = GL_FALSE;\r
-\r
- if ((c=(DMesaContext)CALLOC_STRUCT(dmesa_context)) != NULL) {\r
- _mesa_initialize_context((GLcontext *)c,\r
- (GLvisual *)visual,\r
- (GLcontext *)share,\r
- (void *)c, direct);\r
-\r
- _mesa_enable_sw_extensions((GLcontext *)c);\r
- _mesa_enable_1_3_extensions((GLcontext *)c);\r
- _mesa_enable_1_4_extensions((GLcontext *)c);\r
-\r
- /* you probably have to do a bunch of other initializations here. */\r
- c->visual = visual;\r
-\r
- ((GLcontext *)c)->Driver.UpdateState = dmesa_update_state;\r
-\r
- /* Initialize the software rasterizer and helper modules.\r
- */\r
- _swrast_CreateContext((GLcontext *)c);\r
- _ac_CreateContext((GLcontext *)c);\r
- _tnl_CreateContext((GLcontext *)c);\r
- _swsetup_CreateContext((GLcontext *)c);\r
- if (visual->rgb_flag) dmesa_register_swrast_functions((GLcontext *)c);\r
- dmesa_init_pointers((GLcontext *)c);\r
- }\r
-\r
- return c;\r
-\r
-#else /* FX */\r
- return (DMesaContext)visual;\r
-#endif /* FX */\r
-}\r
-\r
-\r
-\r
-void DMesaDestroyContext (DMesaContext c)\r
-{\r
-#ifndef FX\r
- if (c) {\r
- _swsetup_DestroyContext((GLcontext *)c);\r
- _swrast_DestroyContext((GLcontext *)c);\r
- _tnl_DestroyContext((GLcontext *)c);\r
- _ac_DestroyContext((GLcontext *)c);\r
- _mesa_destroy_context((GLcontext *)c);\r
- }\r
-#endif\r
-}\r
-\r
-\r
-\r
-GLboolean DMesaMoveBuffer (GLint xpos, GLint ypos)\r
-{\r
-#if !defined(FX) && !defined(MATROX)\r
- GET_CURRENT_CONTEXT(ctx);\r
- DMesaBuffer b = ((DMesaContext)ctx)->Buffer;\r
-\r
- if (vl_sync_buffer(&b->the_window, xpos, ypos, b->width, b->height) != 0) {\r
- return GL_FALSE;\r
- } else {\r
- b->xpos = xpos;\r
- b->ypos = ypos;\r
- return GL_TRUE;\r
- }\r
-\r
-#else\r
- return GL_FALSE;\r
-#endif\r
-}\r
-\r
-\r
-\r
-GLboolean DMesaResizeBuffer (GLint width, GLint height)\r
-{\r
-#if !defined(FX) && !defined(MATROX)\r
- GET_CURRENT_CONTEXT(ctx);\r
- DMesaBuffer b = ((DMesaContext)ctx)->Buffer;\r
-\r
- if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, width, height) != 0) {\r
- return GL_FALSE;\r
- } else {\r
- b->width = width;\r
- b->height = height;\r
- return GL_TRUE;\r
- }\r
-\r
-#else\r
- return GL_FALSE;\r
-#endif\r
-}\r
-\r
-\r
-\r
-/*\r
- * Make the specified context and buffer the current one.\r
- */\r
-GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b)\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
- _mesa_make_current((GLcontext *)c, (GLframebuffer *)b);\r
- if (((GLcontext *)c)->Viewport.Width == 0) {\r
- /* initialize viewport to window size */\r
- _mesa_Viewport(0, 0, b->width, b->height);\r
- }\r
- } else {\r
- /* Detach */\r
- _mesa_make_current(NULL, NULL);\r
- }\r
-\r
-#else\r
- fxMesaMakeCurrent((fxMesaContext)c);\r
-#endif\r
-\r
- return GL_TRUE;\r
-}\r
-\r
-\r
-\r
-void DMesaSwapBuffers (DMesaBuffer b)\r
-{\r
- /* copy/swap back buffer to front if applicable */\r
-#ifndef FX\r
- GET_CURRENT_CONTEXT(ctx);\r
- _mesa_notifySwapBuffers(ctx);\r
-#ifndef MATROX\r
- vl_flip();\r
-#else\r
- if (((DMesaContext)ctx)->visual->db_flag) {\r
- mga_swapbuffers(1);\r
- }\r
-#endif\r
-#else\r
- fxMesaSwapBuffers();\r
-#endif\r
-}\r
-\r
-\r
-\r
-void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue)\r
-{\r
-#if !defined(FX) && !defined(MATROX)\r
- vl_setCI(ndx, red, green, blue);\r
-#endif\r
-}\r
-\r
-\r
-\r
-DMesaContext DMesaGetCurrentContext (void)\r
-{\r
-#ifndef FX\r
- GET_CURRENT_CONTEXT(ctx);\r
- return (DMesaContext)ctx;\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
- const DMesaContext c = (DMesaContext)ctx;\r
-#else\r
- const fxMesaContext c = fxMesaGetCurrentContext();\r
-#endif\r
-\r
- if (c == NULL) {\r
- return -1;\r
- }\r
-\r
- switch (pname) {\r
- case DMESA_GET_SCREEN_SIZE:\r
- #ifndef FX\r
- #ifndef MATROX\r
- vl_get(VL_GET_SCREEN_SIZE, params);\r
- #else\r
- mga_get(MGA_GET_SCREEN_SIZE, params);\r
- #endif\r
- #else\r
- params[0] = c->screen_width;\r
- params[1] = c->screen_height;\r
- #endif\r
- break;\r
- case DMESA_GET_DRIVER_CAPS:\r
- #ifndef FX\r
- #ifndef MATROX\r
- params[0] = DMESA_DRIVER_SWDB_BIT;\r
- #else\r
- params[0] = 0;\r
- #endif\r
- #else\r
- params[0] = DMESA_DRIVER_LLWO_BIT;\r
- #endif\r
- break;\r
- default:\r
- return -1;\r
- }\r
-\r
- return 0;\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0.1
+ *
+ * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.4 for Mesa
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef FX
+#include "glheader.h"
+#include "context.h"
+#include "extensions.h"
+#include "macros.h"
+#include "matrix.h"
+#include "mtypes.h"
+#include "texformat.h"
+#include "teximage.h"
+#include "texstore.h"
+#include "imports.h"
+#include "array_cache/acache.h"
+#include "swrast/s_context.h"
+#include "swrast/s_depth.h"
+#include "swrast/s_lines.h"
+#include "swrast/s_triangle.h"
+#include "swrast/swrast.h"
+#include "swrast_setup/swrast_setup.h"
+#include "tnl/tnl.h"
+#include "tnl/t_context.h"
+#include "tnl/t_pipeline.h"
+#ifndef MATROX
+#include "video.h"
+#else /* MATROX */
+#include "mga/mga.h"
+#endif /* MATROX */
+#else /* FX */
+#include "../glide/fxdrv.h"
+#endif /* FX */
+
+#include "GL/dmesa.h"
+
+
+
+/*
+ * In C++ terms, this class derives from the GLvisual class.
+ * Add system-specific fields to it.
+ */
+struct dmesa_visual {
+ GLvisual gl_visual;
+ GLboolean db_flag; /* double buffered? */
+ GLboolean rgb_flag; /* RGB mode? */
+ GLuint depth; /* bits per pixel (1, 8, 24, etc) */
+#ifdef MATROX
+ int stride_in_pixels;
+#endif
+ int zbuffer; /* Z=buffer: 0=no, 1=SW, -1=HW */
+};
+
+/*
+ * In C++ terms, this class derives from the GLframebuffer class.
+ * Add system-specific fields to it.
+ */
+struct dmesa_buffer {
+ GLframebuffer gl_buffer; /* The depth, stencil, accum, etc buffers */
+ void *the_window; /* your window handle, etc */
+
+ int xpos, ypos; /* position */
+ int width, height; /* size in pixels */
+};
+
+/*
+ * In C++ terms, this class derives from the GLcontext class.
+ * Add system-specific fields to it.
+ */
+struct dmesa_context {
+ GLcontext gl_ctx; /* the core library context */
+ DMesaVisual visual;
+ DMesaBuffer Buffer;
+ GLuint ClearColor;
+ GLuint ClearIndex;
+ /* etc... */
+};
+
+
+
+#ifndef FX
+/****************************************************************************
+ * Read/Write pixels
+ ***************************************************************************/
+#define FLIP(y) (dmesa->Buffer->height - (y) - 1)
+#define FLIP2(y) (_b_ - (y))
+
+
+#ifndef MATROX
+#define DSTRIDE dmesa->Buffer->width
+#else
+#define DSTRIDE dmesa->visual->stride_in_pixels
+#define vl_putpixel mga_putpixel
+#define vl_mixrgba mga_mixrgb
+#define vl_mixrgb mga_mixrgb
+#define vl_getrgba mga_getrgba
+#define vl_setz mga_setz
+#define vl_getz mga_getz
+#endif
+
+/****************************************************************************
+ * RGB[A]
+ ***************************************************************************/
+static void write_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
+ const GLubyte rgba[][4], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+#ifndef MATROX
+ offset = DSTRIDE * FLIP(y) + x;
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++, offset++) {
+ if (mask[i]) {
+ vl_putpixel(offset, vl_mixrgba(rgba[i]));
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++, offset++) {
+ vl_putpixel(offset, vl_mixrgba(rgba[i]));
+ }
+ }
+#else /* MATROX */
+ y = FLIP(y);
+ if (mask) {
+ /* draw some pixels */
+ offset = 0;
+ for (i = 0; i < n; i++) {
+ if (mask[i]) {
+ ++offset;
+ } else {
+ if (offset != 0) {
+ mga_draw_span_rgb_tx32(x + i - offset, y, offset, (const unsigned long *)(&rgba[i-offset]));
+ offset = 0;
+ }
+ }
+ }
+ if (offset != 0) {
+ mga_draw_span_rgb_tx32(x + n - offset, y, offset, (const unsigned long *)(&rgba[n-offset]));
+ }
+ } else {
+ /* draw all pixels */
+ mga_draw_span_rgb_tx32(x, y, n, (const unsigned long *)rgba);
+ }
+#endif /* MATROX */
+}
+
+
+
+static void write_rgb_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
+ const GLubyte rgb[][3], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++, offset++) {
+ if (mask[i]) {
+ vl_putpixel(offset, vl_mixrgb(rgb[i]));
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++, offset++) {
+ vl_putpixel(offset, vl_mixrgb(rgb[i]));
+ }
+ }
+}
+
+
+
+static void write_mono_rgba_span (const GLcontext *ctx,
+ GLuint n, GLint x, GLint y,
+ const GLchan color[4], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset, rgba = vl_mixrgba(color);
+
+ offset = DSTRIDE * FLIP(y) + x;
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++, offset++) {
+ if (mask[i]) {
+ vl_putpixel(offset, rgba);
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++, offset++) {
+ vl_putpixel(offset, rgba);
+ }
+ }
+}
+
+
+
+static void read_rgba_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
+ GLubyte rgba[][4])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ /* read all pixels */
+ for (i=0; i<n; i++, offset++) {
+ vl_getrgba(offset, rgba[i]);
+ }
+}
+
+
+
+static void write_rgba_pixels (const GLcontext *ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLubyte rgba[][4], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
+
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i]));
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], vl_mixrgba(rgba[i]));
+ }
+ }
+}
+
+
+
+static void write_mono_rgba_pixels (const GLcontext *ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLchan color[4], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1, rgba = vl_mixrgba(color);
+
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba);
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], rgba);
+ }
+ }
+}
+
+
+
+static void read_rgba_pixels (const GLcontext *ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLubyte rgba[][4], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
+
+ if (mask) {
+ /* read some pixels */
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]);
+ }
+ }
+ } else {
+ /* read all pixels */
+ for (i=0; i<n; i++) {
+ vl_getrgba(FLIP2(y[i])*_w_ + x[i], rgba[i]);
+ }
+ }
+}
+
+
+
+/****************************************************************************
+ * Index
+ ***************************************************************************/
+#ifndef MATROX
+static void write_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
+ const GLuint index[], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++, offset++) {
+ if (mask[i]) {
+ vl_putpixel(offset, index[i]);
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++, offset++) {
+ vl_putpixel(offset, index[i]);
+ }
+ }
+}
+
+
+
+static void write_index8_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
+ const GLubyte index[], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++, offset++) {
+ if (mask[i]) {
+ vl_putpixel(offset, index[i]);
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++, offset++) {
+ vl_putpixel(offset, index[i]);
+ }
+ }
+}
+
+
+
+static void write_mono_index_span (const GLcontext *ctx,
+ GLuint n, GLint x, GLint y,
+ GLuint colorIndex, const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++, offset++) {
+ if (mask[i]) {
+ vl_putpixel(offset, colorIndex);
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++, offset++) {
+ vl_putpixel(offset, colorIndex);
+ }
+ }
+}
+
+
+
+static void read_index_span (const GLcontext *ctx, GLuint n, GLint x, GLint y,
+ GLuint index[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ /* read all pixels */
+ for (i=0; i<n; i++, offset++) {
+ index[i] = vl_getpixel(offset);
+ }
+}
+
+
+
+static void write_index_pixels (const GLcontext *ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ const GLuint index[], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
+
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]);
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], index[i]);
+ }
+ }
+}
+
+
+
+static void write_mono_index_pixels (const GLcontext *ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLuint colorIndex, const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
+
+ if (mask) {
+ /* draw some pixels */
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex);
+ }
+ }
+ } else {
+ /* draw all pixels */
+ for (i=0; i<n; i++) {
+ vl_putpixel(FLIP2(y[i])*_w_ + x[i], colorIndex);
+ }
+ }
+}
+
+
+
+static void read_index_pixels (const GLcontext *ctx,
+ GLuint n, const GLint x[], const GLint y[],
+ GLuint index[], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
+
+ if (mask) {
+ /* read some pixels */
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]);
+ }
+ }
+ } else {
+ /* read all pixels */
+ for (i=0; i<n; i++) {
+ index[i] = vl_getpixel(FLIP2(y[i])*_w_ + x[i]);
+ }
+ }
+}
+#endif /* !MATROX */
+
+
+
+/****************************************************************************
+ * Z-buffer
+ ***************************************************************************/
+#ifdef MATROX
+static void write_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y,
+ const GLdepth depth[], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ if (mask) {
+ /* draw some values */
+ for (i=0; i<n; i++, offset++) {
+ if (mask[i]) {
+ vl_setz(offset, depth[i]);
+ }
+ }
+ } else {
+ /* draw all values */
+ for (i=0; i<n; i++, offset++) {
+ vl_setz(offset, depth[i]);
+ }
+ }
+}
+
+
+
+static void read_depth_span (GLcontext *ctx, GLuint n, GLint x, GLint y,
+ GLdepth depth[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, offset;
+
+ offset = DSTRIDE * FLIP(y) + x;
+ /* read all values */
+ for (i=0; i<n; i++, offset++) {
+ depth[i] = vl_getz(offset);
+ }
+}
+
+
+
+static void write_depth_pixels (GLcontext *ctx, GLuint n,
+ const GLint x[], const GLint y[],
+ const GLdepth depth[], const GLubyte mask[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
+
+ if (mask) {
+ /* draw some values */
+ for (i=0; i<n; i++) {
+ if (mask[i]) {
+ vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]);
+ }
+ }
+ } else {
+ /* draw all values */
+ for (i=0; i<n; i++) {
+ vl_setz(FLIP2(y[i])*_w_ + x[i], depth[i]);
+ }
+ }
+}
+
+
+
+static void read_depth_pixels (GLcontext *ctx, GLuint n,
+ const GLint x[], const GLint y[],
+ GLdepth depth[])
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint i, _w_ = DSTRIDE, _b_ = dmesa->Buffer->height - 1;
+
+ /* read all values */
+ for (i=0; i<n; i++) {
+ depth[i] = vl_getz(FLIP2(y[i])*_w_ + x[i]);
+ }
+}
+#endif /* MATROX */
+
+
+
+/****************************************************************************
+ * Optimized triangle rendering
+ ***************************************************************************/
+
+/*
+ * NON-depth-buffered flat triangle.
+ */
+#ifndef MATROX
+
+#define NAME tri_rgb_flat
+
+#define SETUP_CODE \
+ const DMesaContext dmesa = (DMesaContext)ctx; \
+ GLuint _b_ = dmesa->Buffer->height - 1; \
+ GLuint _w_ = dmesa->Buffer->width; \
+ GLuint rgb = vl_mixrgb(v2->color);
+
+#define RENDER_SPAN(span) \
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
+ for (i = 0; i < span.end; i++, offset++) { \
+ vl_putpixel(offset, rgb); \
+ }
+
+#include "swrast/s_tritemp.h"
+
+#else /* MATROX */
+
+static void tri_rgb_flat (GLcontext *ctx,
+ const SWvertex *v0,
+ const SWvertex *v1,
+ const SWvertex *v2)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1, m2;
+ m0.win[0] = v0->win[0];
+ m0.win[1] = FLIP2(v0->win[1]);
+ m1.win[0] = v1->win[0];
+ m1.win[1] = FLIP2(v1->win[1]);
+ m2.win[0] = v2->win[0];
+ m2.win[1] = FLIP2(v2->win[1]);
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;
+ mga_draw_tri_rgb_flat((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
+}
+#endif /* MATROX */
+
+
+
+/*
+ * Z-less flat triangle.
+ */
+#ifndef MATROX
+
+#define NAME tri_rgb_flat_zless
+
+#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
+
+#define SETUP_CODE \
+ const DMesaContext dmesa = (DMesaContext)ctx; \
+ GLuint _b_ = dmesa->Buffer->height - 1; \
+ GLuint _w_ = dmesa->Buffer->width; \
+ GLuint rgb = vl_mixrgb(v2->color);
+
+#define RENDER_SPAN(span) \
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
+ for (i = 0; i < span.end; i++, offset++) { \
+ const DEPTH_TYPE z = FixedToDepth(span.z); \
+ if (z < zRow[i]) { \
+ vl_putpixel(offset, rgb); \
+ zRow[i] = z; \
+ } \
+ span.z += span.zStep; \
+ }
+
+#include "swrast/s_tritemp.h"
+
+#else /* MATROX */
+
+static void tri_rgb_flat_zless (GLcontext *ctx,
+ const SWvertex *v0,
+ const SWvertex *v1,
+ const SWvertex *v2)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1, m2;
+ m0.win[0] = v0->win[0];
+ m0.win[1] = FLIP2(v0->win[1]);
+ m0.win[2] = v0->win[2];
+ m1.win[0] = v1->win[0];
+ m1.win[1] = FLIP2(v1->win[1]);
+ m1.win[2] = v1->win[2];
+ m2.win[0] = v2->win[0];
+ m2.win[1] = FLIP2(v2->win[1]);
+ m2.win[2] = v2->win[2];
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;
+ mga_draw_tri_rgb_flat_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
+}
+#endif /* MATROX */
+
+
+
+/*
+ * NON-depth-buffered iterated triangle.
+ */
+#ifndef MATROX
+
+#define NAME tri_rgb_iter
+
+#define INTERP_RGB 1
+
+#define SETUP_CODE \
+ const DMesaContext dmesa = (DMesaContext)ctx; \
+ GLuint _b_ = dmesa->Buffer->height - 1; \
+ GLuint _w_ = dmesa->Buffer->width;
+
+#define RENDER_SPAN(span) \
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
+ for (i = 0; i < span.end; i++, offset++) { \
+ vl_putpixel(offset, vl_mixfix(span.red, span.green, span.blue)); \
+ span.red += span.redStep; \
+ span.green += span.greenStep; \
+ span.blue += span.blueStep; \
+ }
+
+#include "swrast/s_tritemp.h"
+
+#else /* MATROX */
+
+static void tri_rgb_iter (GLcontext *ctx,
+ const SWvertex *v0,
+ const SWvertex *v1,
+ const SWvertex *v2)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1, m2;
+ m0.win[0] = v0->win[0];
+ m0.win[1] = FLIP2(v0->win[1]);
+ m1.win[0] = v1->win[0];
+ m1.win[1] = FLIP2(v1->win[1]);
+ m2.win[0] = v2->win[0];
+ m2.win[1] = FLIP2(v2->win[1]);
+ *(unsigned long *)m0.color = *(unsigned long *)v0->color;
+ *(unsigned long *)m1.color = *(unsigned long *)v1->color;
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;
+ mga_draw_tri_rgb_iter((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
+}
+#endif /* MATROX */
+
+
+
+/*
+ * Z-less iterated triangle.
+ */
+#ifndef MATROX
+
+#define NAME tri_rgb_iter_zless
+
+#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
+#define INTERP_RGB 1
+
+#define SETUP_CODE \
+ const DMesaContext dmesa = (DMesaContext)ctx; \
+ GLuint _b_ = dmesa->Buffer->height - 1; \
+ GLuint _w_ = dmesa->Buffer->width;
+
+#define RENDER_SPAN(span) \
+ GLuint i, offset = FLIP2(span.y)*_w_ + span.x; \
+ for (i = 0; i < span.end; i++, offset++) { \
+ const DEPTH_TYPE z = FixedToDepth(span.z); \
+ if (z < zRow[i]) { \
+ vl_putpixel(offset, vl_mixfix(span.red, span.green, span.blue));\
+ zRow[i] = z; \
+ } \
+ span.red += span.redStep; \
+ span.green += span.greenStep; \
+ span.blue += span.blueStep; \
+ span.z += span.zStep; \
+ }
+
+#include "swrast/s_tritemp.h"
+
+#else /* MATROX */
+
+static void tri_rgb_iter_zless (GLcontext *ctx,
+ const SWvertex *v0,
+ const SWvertex *v1,
+ const SWvertex *v2)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1, m2;
+ m0.win[0] = v0->win[0];
+ m0.win[1] = FLIP2(v0->win[1]);
+ m0.win[2] = v0->win[2];
+ m1.win[0] = v1->win[0];
+ m1.win[1] = FLIP2(v1->win[1]);
+ m1.win[2] = v1->win[2];
+ m2.win[0] = v2->win[0];
+ m2.win[1] = FLIP2(v2->win[1]);
+ m2.win[2] = v2->win[2];
+ *(unsigned long *)m0.color = *(unsigned long *)v0->color;
+ *(unsigned long *)m1.color = *(unsigned long *)v1->color;
+ *(unsigned long *)m2.color = *(unsigned long *)v2->color;
+ mga_draw_tri_rgb_iter_zless((int)SWRAST_CONTEXT(ctx)->_backface_sign, &m0, &m1, &m2);
+}
+#endif /* MATROX */
+
+
+
+/*
+ * Analyze context state to see if we can provide a fast triangle function
+ * Otherwise, return NULL.
+ */
+static swrast_tri_func dmesa_choose_tri_function (GLcontext *ctx)
+{
+ const SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ if ((ctx->RenderMode != GL_RENDER)
+ || (ctx->Polygon.SmoothFlag)
+ || (ctx->Polygon.StippleFlag)
+ || (ctx->Texture._EnabledUnits)
+ || (swrast->_RasterMask & MULTI_DRAW_BIT)
+ || (ctx->Polygon.CullFlag && ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK)) {
+ return (swrast_tri_func)NULL;
+ }
+
+ if (swrast->_RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter_zless : tri_rgb_flat_zless;
+ }
+
+ if (swrast->_RasterMask==0) { /* no depth test */
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? tri_rgb_iter : tri_rgb_flat;
+ }
+
+ return (swrast_tri_func)NULL;
+}
+
+
+
+/* Override for the swrast triangle-selection function. Try to use one
+ * of our internal triangle functions, otherwise fall back to the
+ * standard swrast functions.
+ */
+static void dmesa_choose_tri (GLcontext *ctx)
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ if (!(swrast->Triangle=dmesa_choose_tri_function(ctx)))
+ _swrast_choose_triangle(ctx);
+}
+
+
+
+/****************************************************************************
+ * Optimized line rendering
+ ***************************************************************************/
+
+#ifdef MATROX
+static __inline void matrox_line_clip_hack (GLcontext *ctx, int _b_, MGAvertex *m0, const SWvertex *vert0, MGAvertex *m1, const SWvertex *vert1)
+{
+ int x0 = vert0->win[0];
+ int y0 = vert0->win[1];
+ int x1 = vert1->win[0];
+ int y1 = vert1->win[1];
+ /* s_linetemp.h { */
+ GLint w = ctx->DrawBuffer->Width;
+ GLint h = ctx->DrawBuffer->Height;
+ if ((x0==w) | (x1==w)) {
+ if ((x0==w) & (x1==w))
+ return;
+ x0 -= x0==w;
+ x1 -= x1==w;
+ }
+ if ((y0==h) | (y1==h)) {
+ if ((y0==h) & (y1==h))
+ return;
+ y0 -= y0==h;
+ y1 -= y1==h;
+ }
+ /* } s_linetemp.h */
+ m0->win[0] = x0;
+ m0->win[1] = FLIP2(y0);
+ m1->win[0] = x1;
+ m1->win[1] = FLIP2(y1);
+}
+#endif
+
+/*
+ * NON-depth-buffered flat line.
+ */
+#ifndef MATROX
+
+#define NAME line_rgb_flat
+
+#define INTERP_XY 1
+#define CLIP_HACK 1
+
+#define SETUP_CODE \
+ const DMesaContext dmesa = (DMesaContext)ctx; \
+ GLuint _b_ = dmesa->Buffer->height - 1; \
+ GLuint _w_ = dmesa->Buffer->width; \
+ GLuint rgb = vl_mixrgb(vert1->color);
+
+#define PLOT(X,Y) vl_putpixel(FLIP2(Y) * _w_ + X, rgb);
+
+#include "swrast/s_linetemp.h"
+
+#else /* MATROX */
+
+static void line_rgb_flat (GLcontext *ctx,
+ const SWvertex *vert0,
+ const SWvertex *vert1)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1;
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
+ mga_draw_line_rgb_flat(&m0, &m1);
+}
+#endif /* MATROX */
+
+
+
+/*
+ * Z-less flat line.
+ */
+#ifndef MATROX
+
+#define NAME line_rgb_flat_zless
+
+#define INTERP_XY 1
+#define INTERP_Z 1
+#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE
+#define CLIP_HACK 1
+
+#define SETUP_CODE \
+ const DMesaContext dmesa = (DMesaContext)ctx; \
+ GLuint _b_ = dmesa->Buffer->height - 1; \
+ GLuint _w_ = dmesa->Buffer->width; \
+ GLuint rgb = vl_mixrgb(vert1->color);
+
+#define PLOT(X,Y) \
+ if (Z < *zPtr) { \
+ *zPtr = Z; \
+ vl_putpixel(FLIP2(Y) * _w_ + X, rgb); \
+ }
+
+#include "swrast/s_linetemp.h"
+
+#else /* MATROX */
+
+static void line_rgb_flat_zless (GLcontext *ctx,
+ const SWvertex *vert0,
+ const SWvertex *vert1)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1;
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
+ m0.win[2] = vert0->win[2];
+ m1.win[2] = vert1->win[2];
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
+ mga_draw_line_rgb_flat_zless(&m0, &m1);
+}
+#endif /* MATROX */
+
+
+
+#ifndef MATROX
+#define line_rgb_iter NULL
+#define line_rgb_iter_zless NULL
+#else /* MATROX */
+/*
+ * NON-depth-buffered iterated line.
+ */
+static void line_rgb_iter (GLcontext *ctx,
+ const SWvertex *vert0,
+ const SWvertex *vert1)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1;
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
+ *(unsigned long *)m0.color = *(unsigned long *)vert0->color;
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
+ mga_draw_line_rgb_iter(&m0, &m1);
+}
+
+
+
+/*
+ * Z-less iterated line.
+ */
+static void line_rgb_iter_zless (GLcontext *ctx,
+ const SWvertex *vert0,
+ const SWvertex *vert1)
+{
+ const DMesaContext dmesa = (DMesaContext)ctx;
+ GLuint _b_ = dmesa->Buffer->height - 1;
+ MGAvertex m0, m1;
+ matrox_line_clip_hack(ctx, _b_, &m0, vert0, &m1, vert1);
+ m0.win[2] = vert0->win[2];
+ m1.win[2] = vert1->win[2];
+ *(unsigned long *)m0.color = *(unsigned long *)vert0->color;
+ *(unsigned long *)m1.color = *(unsigned long *)vert1->color;
+ mga_draw_line_rgb_iter_zless(&m0, &m1);
+}
+#endif /* MATROX */
+
+
+
+/*
+ * Analyze context state to see if we can provide a fast line function
+ * Otherwise, return NULL.
+ */
+static swrast_line_func dmesa_choose_line_function (GLcontext *ctx)
+{
+ const SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ if ((ctx->RenderMode != GL_RENDER)
+ || (ctx->Line.SmoothFlag)
+ || (ctx->Texture._EnabledUnits)
+ || (ctx->Line.StippleFlag)
+ || (swrast->_RasterMask & MULTI_DRAW_BIT)
+ || (ctx->Line.Width!=1.0F)) {
+ return (swrast_line_func)NULL;
+ }
+
+ if (swrast->_RasterMask==DEPTH_BIT
+ && ctx->Depth.Func==GL_LESS
+ && ctx->Depth.Mask==GL_TRUE
+ && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS) {
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter_zless : line_rgb_flat_zless;
+ }
+
+ if (swrast->_RasterMask==0) { /* no depth test */
+ return (ctx->Light.ShadeModel==GL_SMOOTH) ? line_rgb_iter : line_rgb_flat;
+ }
+
+ return (swrast_line_func)NULL;
+}
+
+
+
+/* Override for the swrast line-selection function. Try to use one
+ * of our internal line functions, otherwise fall back to the
+ * standard swrast functions.
+ */
+static void dmesa_choose_line (GLcontext *ctx)
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ if (!(swrast->Line=dmesa_choose_line_function(ctx)))
+ _swrast_choose_line(ctx);
+}
+
+
+
+/****************************************************************************
+ * Miscellaneous device driver funcs
+ ***************************************************************************/
+
+static void clear_index (GLcontext *ctx, GLuint index)
+{
+ ((DMesaContext)ctx)->ClearIndex = index;
+}
+
+static void clear_color (GLcontext *ctx, const GLfloat color[4])
+{
+ GLubyte col[4];
+ CLAMPED_FLOAT_TO_UBYTE(col[0], color[0]);
+ CLAMPED_FLOAT_TO_UBYTE(col[1], color[1]);
+ CLAMPED_FLOAT_TO_UBYTE(col[2], color[2]);
+ CLAMPED_FLOAT_TO_UBYTE(col[3], color[3]);
+ ((DMesaContext)ctx)->ClearColor = vl_mixrgba(col);
+}
+
+
+
+static void clear (GLcontext *ctx, GLbitfield mask, GLboolean all,
+ GLint x, GLint y, GLint width, GLint height)
+{
+ const DMesaContext c = (DMesaContext)ctx;
+ const GLuint *colorMask = (GLuint *)&ctx->Color.ColorMask;
+
+/*
+ * Clear the specified region of the buffers indicated by 'mask'
+ * using the clear color or index as specified by one of the two
+ * functions above.
+ * If all==GL_TRUE, clear whole buffer, else just clear region defined
+ * by x,y,width,height
+ */
+
+ /* we can't handle color or index masking */
+ if ((*colorMask == 0xffffffff) && (ctx->Color.IndexMask == 0xffffffff)) {
+#ifndef MATROX
+ if (mask & DD_BACK_LEFT_BIT) {
+ int color = c->visual->rgb_flag ? c->ClearColor : c->ClearIndex;
+
+ if (all) {
+ vl_clear(color);
+ } else {
+ vl_rect(x, y, width, height, color);
+ }
+
+ mask &= ~DD_BACK_LEFT_BIT;
+ }
+#else /* MATROX */
+ unsigned short z = -1;
+ int color = c->ClearColor;
+ if (mask & DD_DEPTH_BIT) {
+ z = ctx->Depth.Clear * 0xffff;
+ }
+ if (all) {
+ mga_clear(mask & DD_FRONT_LEFT_BIT,
+ mask & DD_BACK_LEFT_BIT,
+ mask & DD_DEPTH_BIT,
+ 0, 0, c->Buffer->width, c->Buffer->height,
+ color, z);
+ } else {
+ mga_clear(mask & DD_FRONT_LEFT_BIT,
+ mask & DD_BACK_LEFT_BIT,
+ mask & DD_DEPTH_BIT,
+ x, y, width, height,
+ color, z);
+ }
+ mask &= ~(DD_FRONT_LEFT_BIT | DD_BACK_LEFT_BIT | DD_DEPTH_BIT);
+#endif /* MATROX */
+ }
+
+ if (mask) {
+ _swrast_Clear(ctx, mask, all, x, y, width, height);
+ }
+}
+
+
+
+static void set_buffer (GLcontext *ctx, GLframebuffer *colorBuffer, GLuint bufferBit)
+{
+ /*
+ * XXX todo - examine bufferBit and set read/write pointers
+ */
+}
+
+
+
+/*
+ * Return the width and height of the current buffer.
+ * If anything special has to been done when the buffer/window is
+ * resized, do it now.
+ */
+static void get_buffer_size (GLframebuffer *buffer, GLuint *width, GLuint *height)
+{
+ DMesaBuffer b = (DMesaBuffer)buffer;
+
+ *width = b->width;
+ *height = b->height;
+}
+
+
+
+static const GLubyte* get_string (GLcontext *ctx, GLenum name)
+{
+ switch (name) {
+ case GL_RENDERER:
+ return (const GLubyte *)"Mesa DJGPP"
+ #ifdef FX
+ " (FX)"
+ #endif
+ #ifdef MATROX
+ " (MGA)"
+ #endif
+ "\0port (c) Borca Daniel mar-2003";
+ default:
+ return NULL;
+ }
+}
+
+
+
+static void finish (GLcontext *ctx)
+{
+ /*
+ * XXX todo - OPTIONAL FUNCTION: implements glFinish if possible
+ */
+}
+
+
+
+static void flush (GLcontext *ctx)
+{
+ /*
+ * XXX todo - OPTIONAL FUNCTION: implements glFlush if possible
+ */
+}
+
+
+
+/****************************************************************************
+ * State
+ ***************************************************************************/
+#define DMESA_NEW_LINE (_NEW_LINE | \
+ _NEW_TEXTURE | \
+ _NEW_LIGHT | \
+ _NEW_DEPTH | \
+ _NEW_RENDERMODE | \
+ _SWRAST_NEW_RASTERMASK)
+
+#define DMESA_NEW_TRIANGLE (_NEW_POLYGON | \
+ _NEW_TEXTURE | \
+ _NEW_LIGHT | \
+ _NEW_DEPTH | \
+ _NEW_RENDERMODE | \
+ _SWRAST_NEW_RASTERMASK)
+
+/* Extend the software rasterizer with our line and triangle
+ * functions.
+ */
+static void dmesa_register_swrast_functions (GLcontext *ctx)
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+
+ swrast->choose_line = dmesa_choose_line;
+ swrast->choose_triangle = dmesa_choose_tri;
+
+ swrast->invalidate_line |= DMESA_NEW_LINE;
+ swrast->invalidate_triangle |= DMESA_NEW_TRIANGLE;
+}
+
+
+
+/* Setup pointers and other driver state that is constant for the life
+ * of a context.
+ */
+static void dmesa_init_pointers (GLcontext *ctx)
+{
+ TNLcontext *tnl;
+ struct swrast_device_driver *dd = _swrast_GetDeviceDriverReference(ctx);
+
+ ctx->Driver.GetString = get_string;
+ ctx->Driver.GetBufferSize = get_buffer_size;
+ ctx->Driver.Flush = flush;
+ ctx->Driver.Finish = finish;
+
+ /* Software rasterizer pixel paths:
+ */
+ ctx->Driver.Accum = _swrast_Accum;
+ ctx->Driver.Bitmap = _swrast_Bitmap;
+ ctx->Driver.Clear = clear;
+ ctx->Driver.ResizeBuffers = _swrast_alloc_buffers;
+ ctx->Driver.CopyPixels = _swrast_CopyPixels;
+ ctx->Driver.DrawPixels = _swrast_DrawPixels;
+ ctx->Driver.ReadPixels = _swrast_ReadPixels;
+ ctx->Driver.DrawBuffer = _swrast_DrawBuffer;
+
+ /* Software texture functions:
+ */
+ ctx->Driver.ChooseTextureFormat = _mesa_choose_tex_format;
+ ctx->Driver.TexImage1D = _mesa_store_teximage1d;
+ ctx->Driver.TexImage2D = _mesa_store_teximage2d;
+ ctx->Driver.TexImage3D = _mesa_store_teximage3d;
+ ctx->Driver.TexSubImage1D = _mesa_store_texsubimage1d;
+ ctx->Driver.TexSubImage2D = _mesa_store_texsubimage2d;
+ ctx->Driver.TexSubImage3D = _mesa_store_texsubimage3d;
+ ctx->Driver.TestProxyTexImage = _mesa_test_proxy_teximage;
+
+ ctx->Driver.CopyTexImage1D = _swrast_copy_teximage1d;
+ ctx->Driver.CopyTexImage2D = _swrast_copy_teximage2d;
+ ctx->Driver.CopyTexSubImage1D = _swrast_copy_texsubimage1d;
+ ctx->Driver.CopyTexSubImage2D = _swrast_copy_texsubimage2d;
+ ctx->Driver.CopyTexSubImage3D = _swrast_copy_texsubimage3d;
+
+ ctx->Driver.CompressedTexImage1D = _mesa_store_compressed_teximage1d;
+ ctx->Driver.CompressedTexImage2D = _mesa_store_compressed_teximage2d;
+ ctx->Driver.CompressedTexImage3D = _mesa_store_compressed_teximage3d;
+ ctx->Driver.CompressedTexSubImage1D = _mesa_store_compressed_texsubimage1d;
+ ctx->Driver.CompressedTexSubImage2D = _mesa_store_compressed_texsubimage2d;
+ ctx->Driver.CompressedTexSubImage3D = _mesa_store_compressed_texsubimage3d;
+
+ /* Swrast hooks for imaging extensions:
+ */
+ ctx->Driver.CopyColorTable = _swrast_CopyColorTable;
+ ctx->Driver.CopyColorSubTable = _swrast_CopyColorSubTable;
+ ctx->Driver.CopyConvolutionFilter1D = _swrast_CopyConvolutionFilter1D;
+ ctx->Driver.CopyConvolutionFilter2D = _swrast_CopyConvolutionFilter2D;
+
+ /* Statechange callbacks:
+ */
+ ctx->Driver.ClearColor = clear_color;
+ ctx->Driver.ClearIndex = clear_index;
+
+ /* Initialize the TNL driver interface:
+ */
+ tnl = TNL_CONTEXT(ctx);
+ tnl->Driver.RunPipeline = _tnl_run_pipeline;
+
+ dd->SetBuffer = set_buffer;
+
+ /* Install swsetup for tnl->Driver.Render.*:
+ */
+ _swsetup_Wakeup(ctx);
+
+ /* The span functions should be in `dmesa_update_state', but I'm
+ * pretty sure they will never change during the life of the Visual
+ */
+#ifdef MATROX
+ if (((DMesaContext)ctx)->visual->zbuffer == -1) {
+ /* Depth span/pixel functions */
+ dd->WriteDepthSpan = write_depth_span;
+ dd->WriteDepthPixels = write_depth_pixels;
+ dd->ReadDepthSpan = read_depth_span;
+ dd->ReadDepthPixels = read_depth_pixels;
+ }
+#endif
+
+#ifndef MATROX
+ /* Index span/pixel functions */
+ dd->WriteCI32Span = write_index_span;
+ dd->WriteCI8Span = write_index8_span;
+ dd->WriteMonoCISpan = write_mono_index_span;
+ dd->WriteCI32Pixels = write_index_pixels;
+ dd->WriteMonoCIPixels = write_mono_index_pixels;
+ dd->ReadCI32Span = read_index_span;
+ dd->ReadCI32Pixels = read_index_pixels;
+#endif
+
+ /* RGB(A) span/pixel functions */
+ dd->WriteRGBASpan = write_rgba_span;
+ dd->WriteRGBSpan = write_rgb_span;
+ dd->WriteMonoRGBASpan = write_mono_rgba_span;
+ dd->WriteRGBAPixels = write_rgba_pixels;
+ dd->WriteMonoRGBAPixels = write_mono_rgba_pixels;
+ dd->ReadRGBASpan = read_rgba_span;
+ dd->ReadRGBAPixels = read_rgba_pixels;
+}
+
+
+
+static void dmesa_update_state (GLcontext *ctx, GLuint new_state)
+{
+ /* Propogate statechange information to swrast and swrast_setup
+ * modules. The DMesa driver has no internal GL-dependent state.
+ */
+ _swrast_InvalidateState( ctx, new_state );
+ _ac_InvalidateState( ctx, new_state );
+ _tnl_InvalidateState( ctx, new_state );
+ _swsetup_InvalidateState( ctx, new_state );
+}
+#endif /* FX */
+
+
+
+/****************************************************************************
+ * DMesa Public API Functions
+ ***************************************************************************/
+
+/*
+ * The exact arguments to this function will depend on your window system
+ */
+DMesaVisual DMesaCreateVisual (GLint width,
+ GLint height,
+ GLint colDepth,
+ GLint refresh,
+ GLboolean dbFlag,
+ GLboolean rgbFlag,
+ GLboolean alphaFlag,
+ GLint depthSize,
+ GLint stencilSize,
+ GLint accumSize)
+{
+#ifndef FX
+ DMesaVisual v;
+ GLint redBits, greenBits, blueBits, alphaBits, indexBits;
+
+#ifndef MATROX
+ if (!dbFlag) {
+ return NULL;
+ }
+#else
+ if (!rgbFlag) {
+ return NULL;
+ }
+#endif
+
+ alphaBits = 0;
+
+ if (!rgbFlag) {
+ indexBits = 8;
+ redBits = 0;
+ greenBits = 0;
+ blueBits = 0;
+ } else {
+ indexBits = 0;
+ switch (colDepth) {
+ case 8:
+ redBits = 8;
+ greenBits = 8;
+ blueBits = 8;
+ break;
+ case 15:
+ redBits = 5;
+ greenBits = 5;
+ blueBits = 5;
+ break;
+ case 16:
+ redBits = 5;
+ greenBits = 6;
+ blueBits = 5;
+ break;
+ case 32:
+ alphaBits = 8;
+ case 24:
+ redBits = 8;
+ greenBits = 8;
+ blueBits = 8;
+ break;
+ default:
+ return NULL;
+ }
+ }
+
+#ifndef MATROX
+ if ((colDepth=vl_video_init(width, height, colDepth, rgbFlag, refresh)) <= 0) {
+ return NULL;
+ }
+#else
+ if (mga_open(width, height, colDepth, dbFlag ? 2 : 1, depthSize == 16, refresh) < 0) {
+ return NULL;
+ }
+#endif
+
+ if (alphaFlag && (alphaBits==0)) {
+ alphaBits = 8;
+ }
+
+ if ((v=(DMesaVisual)CALLOC_STRUCT(dmesa_visual)) != NULL) {
+ /* Create core visual */
+ _mesa_initialize_visual((GLvisual *)v,
+ rgbFlag, /* rgb */
+ dbFlag,
+ GL_FALSE, /* stereo */
+ redBits,
+ greenBits,
+ blueBits,
+ alphaBits,
+ indexBits, /* indexBits */
+ depthSize,
+ stencilSize,
+ accumSize, /* accumRed */
+ accumSize, /* accumGreen */
+ accumSize, /* accumBlue */
+ alphaFlag?accumSize:0, /* accumAlpha */
+ 1); /* numSamples */
+
+ v->depth = colDepth;
+ v->db_flag = dbFlag;
+ v->rgb_flag = rgbFlag;
+
+ v->zbuffer = (depthSize > 0) ? 1 : 0;
+#ifdef MATROX
+ mga_get(MGA_GET_HPIXELS, &v->stride_in_pixels);
+ if (depthSize == 16) {
+ v->zbuffer = -1;
+ }
+#endif
+ }
+
+ return v;
+
+#else /* FX */
+
+ int i = 0, fx_attrib[32];
+
+ if (!rgbFlag) {
+ return NULL;
+ }
+
+ if (dbFlag) fx_attrib[i++] = FXMESA_DOUBLEBUFFER;
+ if (depthSize > 0) { fx_attrib[i++] = FXMESA_DEPTH_SIZE; fx_attrib[i++] = depthSize; }
+ if (stencilSize > 0) { fx_attrib[i++] = FXMESA_STENCIL_SIZE; fx_attrib[i++] = stencilSize; }
+ if (accumSize > 0) { fx_attrib[i++] = FXMESA_ACCUM_SIZE; fx_attrib[i++] = accumSize; }
+ if (alphaFlag) { fx_attrib[i++] = FXMESA_ALPHA_SIZE; fx_attrib[i++] = 1; }
+ fx_attrib[i] = FXMESA_NONE;
+
+ return (DMesaVisual)fxMesaCreateBestContext(-1, width, height, fx_attrib);
+#endif /* FX */
+}
+
+
+
+void DMesaDestroyVisual (DMesaVisual v)
+{
+#ifndef FX
+ _mesa_destroy_visual((GLvisual *)v);
+
+#ifndef MATROX
+ vl_video_exit();
+#else
+ mga_close(1, 1);
+#endif
+
+#else
+ fxMesaDestroyContext((fxMesaContext)v);
+#endif
+}
+
+
+
+DMesaBuffer DMesaCreateBuffer (DMesaVisual visual,
+ GLint xpos, GLint ypos,
+ GLint width, GLint height)
+{
+#ifndef FX
+ DMesaBuffer b;
+
+ if ((b=(DMesaBuffer)CALLOC_STRUCT(dmesa_buffer)) != NULL) {
+ _mesa_initialize_framebuffer((GLframebuffer *)b,
+ (GLvisual *)visual,
+ visual->zbuffer == 1,
+ ((GLvisual *)visual)->stencilBits > 0,
+ ((GLvisual *)visual)->accumRedBits > 0,
+ ((GLvisual *)visual)->alphaBits > 0);
+ b->xpos = xpos;
+ b->ypos = ypos;
+ b->width = width;
+ b->height = height;
+ }
+
+ return b;
+#else
+ return (DMesaBuffer)visual;
+#endif
+}
+
+
+
+void DMesaDestroyBuffer (DMesaBuffer b)
+{
+#ifndef FX
+#ifndef MATROX
+ free(b->the_window);
+#endif
+ _mesa_destroy_framebuffer((GLframebuffer *)b);
+#endif
+}
+
+
+
+DMesaContext DMesaCreateContext (DMesaVisual visual,
+ DMesaContext share)
+{
+#ifndef FX
+ DMesaContext c;
+ GLboolean direct = GL_FALSE;
+
+ if ((c=(DMesaContext)CALLOC_STRUCT(dmesa_context)) != NULL) {
+ _mesa_initialize_context((GLcontext *)c,
+ (GLvisual *)visual,
+ (GLcontext *)share,
+ (void *)c, direct);
+
+ _mesa_enable_sw_extensions((GLcontext *)c);
+ _mesa_enable_1_3_extensions((GLcontext *)c);
+ _mesa_enable_1_4_extensions((GLcontext *)c);
+
+ /* you probably have to do a bunch of other initializations here. */
+ c->visual = visual;
+
+ ((GLcontext *)c)->Driver.UpdateState = dmesa_update_state;
+
+ /* Initialize the software rasterizer and helper modules.
+ */
+ _swrast_CreateContext((GLcontext *)c);
+ _ac_CreateContext((GLcontext *)c);
+ _tnl_CreateContext((GLcontext *)c);
+ _swsetup_CreateContext((GLcontext *)c);
+ if (visual->rgb_flag) dmesa_register_swrast_functions((GLcontext *)c);
+ dmesa_init_pointers((GLcontext *)c);
+ }
+
+ return c;
+
+#else /* FX */
+ return (DMesaContext)visual;
+#endif /* FX */
+}
+
+
+
+void DMesaDestroyContext (DMesaContext c)
+{
+#ifndef FX
+ if (c) {
+ _swsetup_DestroyContext((GLcontext *)c);
+ _swrast_DestroyContext((GLcontext *)c);
+ _tnl_DestroyContext((GLcontext *)c);
+ _ac_DestroyContext((GLcontext *)c);
+ _mesa_destroy_context((GLcontext *)c);
+ }
+#endif
+}
+
+
+
+GLboolean DMesaMoveBuffer (GLint xpos, GLint ypos)
+{
+#if !defined(FX) && !defined(MATROX)
+ GET_CURRENT_CONTEXT(ctx);
+ DMesaBuffer b = ((DMesaContext)ctx)->Buffer;
+
+ if (vl_sync_buffer(&b->the_window, xpos, ypos, b->width, b->height) != 0) {
+ return GL_FALSE;
+ } else {
+ b->xpos = xpos;
+ b->ypos = ypos;
+ return GL_TRUE;
+ }
+
+#else
+ return GL_FALSE;
+#endif
+}
+
+
+
+GLboolean DMesaResizeBuffer (GLint width, GLint height)
+{
+#if !defined(FX) && !defined(MATROX)
+ GET_CURRENT_CONTEXT(ctx);
+ DMesaBuffer b = ((DMesaContext)ctx)->Buffer;
+
+ if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, width, height) != 0) {
+ return GL_FALSE;
+ } else {
+ b->width = width;
+ b->height = height;
+ return GL_TRUE;
+ }
+
+#else
+ return GL_FALSE;
+#endif
+}
+
+
+
+/*
+ * Make the specified context and buffer the current one.
+ */
+GLboolean DMesaMakeCurrent (DMesaContext c, DMesaBuffer b)
+{
+#ifndef FX
+ if ((c != NULL) && (b != NULL)) {
+#ifndef MATROX
+ if (vl_sync_buffer(&b->the_window, b->xpos, b->ypos, b->width, b->height) != 0) {
+ return GL_FALSE;
+ }
+#endif
+
+ c->Buffer = b;
+
+ _mesa_make_current((GLcontext *)c, (GLframebuffer *)b);
+ if (((GLcontext *)c)->Viewport.Width == 0) {
+ /* initialize viewport to window size */
+ _mesa_Viewport(0, 0, b->width, b->height);
+ }
+ } else {
+ /* Detach */
+ _mesa_make_current(NULL, NULL);
+ }
+
+#else
+ fxMesaMakeCurrent((fxMesaContext)c);
+#endif
+
+ return GL_TRUE;
+}
+
+
+
+void DMesaSwapBuffers (DMesaBuffer b)
+{
+ /* copy/swap back buffer to front if applicable */
+#ifndef FX
+ GET_CURRENT_CONTEXT(ctx);
+ _mesa_notifySwapBuffers(ctx);
+#ifndef MATROX
+ vl_flip();
+#else
+ if (((DMesaContext)ctx)->visual->db_flag) {
+ mga_swapbuffers(1);
+ }
+#endif
+#else
+ fxMesaSwapBuffers();
+#endif
+}
+
+
+
+void DMesaSetCI (int ndx, GLfloat red, GLfloat green, GLfloat blue)
+{
+#if !defined(FX) && !defined(MATROX)
+ vl_setCI(ndx, red, green, blue);
+#endif
+}
+
+
+
+DMesaContext DMesaGetCurrentContext (void)
+{
+#ifndef FX
+ GET_CURRENT_CONTEXT(ctx);
+ return (DMesaContext)ctx;
+#else
+ return (DMesaContext)fxMesaGetCurrentContext();
+#endif
+}
+
+
+
+int DMesaGetIntegerv (GLenum pname, GLint *params)
+{
+#ifndef FX
+ GET_CURRENT_CONTEXT(ctx);
+ const DMesaContext c = (DMesaContext)ctx;
+#else
+ const fxMesaContext c = fxMesaGetCurrentContext();
+#endif
+
+ if (c == NULL) {
+ return -1;
+ }
+
+ switch (pname) {
+ case DMESA_GET_SCREEN_SIZE:
+ #ifndef FX
+ #ifndef MATROX
+ vl_get(VL_GET_SCREEN_SIZE, params);
+ #else
+ mga_get(MGA_GET_SCREEN_SIZE, params);
+ #endif
+ #else
+ params[0] = c->screen_width;
+ params[1] = c->screen_height;
+ #endif
+ break;
+ case DMESA_GET_DRIVER_CAPS:
+ #ifndef FX
+ #ifndef MATROX
+ params[0] = DMESA_DRIVER_SWDB_BIT;
+ #else
+ params[0] = 0;
+ #endif
+ #else
+ params[0] = DMESA_DRIVER_LLWO_BIT;
+ #endif
+ break;
+ default:
+ return -1;
+ }
+
+ return 0;
+}
-/*\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\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
-\r
-#include "internal.h"\r
-\r
-\r
-\r
-#ifndef MAX\r
-#define MAX(x, y) (((x)<(y))?(y):(x))\r
-#endif\r
-\r
-\r
-\r
-/* _create_linear_mapping:\r
- * Maps a physical address range into linear memory.\r
- */\r
-int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)\r
-{\r
- __dpmi_meminfo meminfo;\r
-\r
- if (physaddr >= 0x100000) {\r
- /* map into linear memory */\r
- meminfo.address = physaddr;\r
- meminfo.size = size;\r
- if (__dpmi_physical_address_mapping(&meminfo) != 0)\r
- return -1;\r
-\r
- *linear = meminfo.address;\r
- } else {\r
- /* exploit 1 -> 1 physical to linear mapping in low megabyte */\r
- *linear = physaddr;\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* _remove_linear_mapping:\r
- * Frees the DPMI resources being used to map a linear address range.\r
- */\r
-void _remove_linear_mapping (unsigned long *linear)\r
-{\r
- __dpmi_meminfo meminfo;\r
-\r
- if (*linear) {\r
- if (*linear >= 0x100000) {\r
- meminfo.address = *linear;\r
- __dpmi_free_physical_address_mapping(&meminfo);\r
- }\r
-\r
- *linear = 0;\r
- }\r
-}\r
-\r
-\r
-\r
-/* _create_selector:\r
- * Allocates a selector to access a region of linear memory.\r
- */\r
-int _create_selector (int *segment, unsigned long base, int size)\r
-{\r
- /* allocate an ldt descriptor */\r
- if ((*segment=__dpmi_allocate_ldt_descriptors(1)) < 0) {\r
- *segment = 0;\r
- return -1;\r
- }\r
-\r
- /* create the linear mapping */\r
- if (_create_linear_mapping(&base, base, size)) {\r
- __dpmi_free_ldt_descriptor(*segment);\r
- *segment = 0;\r
- return -1;\r
- }\r
-\r
- /* set the descriptor base and limit */\r
- __dpmi_set_segment_base_address(*segment, base);\r
- __dpmi_set_segment_limit(*segment, MAX(size-1, 0xFFFF));\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* _remove_selector:\r
- * Frees a DPMI segment selector.\r
- */\r
-void _remove_selector (int *segment)\r
-{\r
- if (*segment) {\r
- unsigned long base;\r
- __dpmi_get_segment_base_address(*segment, &base);\r
- _remove_linear_mapping(&base);\r
- __dpmi_free_ldt_descriptor(*segment);\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
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.4 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <dpmi.h>
+
+#include "internal.h"
+
+
+
+#ifndef MAX
+#define MAX(x, y) (((x)<(y))?(y):(x))
+#endif
+
+
+
+/* _create_linear_mapping:
+ * Maps a physical address range into linear memory.
+ */
+int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size)
+{
+ __dpmi_meminfo meminfo;
+
+ if (physaddr >= 0x100000) {
+ /* map into linear memory */
+ meminfo.address = physaddr;
+ meminfo.size = size;
+ if (__dpmi_physical_address_mapping(&meminfo) != 0)
+ return -1;
+
+ *linear = meminfo.address;
+ } else {
+ /* exploit 1 -> 1 physical to linear mapping in low megabyte */
+ *linear = physaddr;
+ }
+
+ return 0;
+}
+
+
+
+/* _remove_linear_mapping:
+ * Frees the DPMI resources being used to map a linear address range.
+ */
+void _remove_linear_mapping (unsigned long *linear)
+{
+ __dpmi_meminfo meminfo;
+
+ if (*linear) {
+ if (*linear >= 0x100000) {
+ meminfo.address = *linear;
+ __dpmi_free_physical_address_mapping(&meminfo);
+ }
+
+ *linear = 0;
+ }
+}
+
+
+
+/* _create_selector:
+ * Allocates a selector to access a region of linear memory.
+ */
+int _create_selector (int *segment, unsigned long base, int size)
+{
+ /* allocate an ldt descriptor */
+ if ((*segment=__dpmi_allocate_ldt_descriptors(1)) < 0) {
+ *segment = 0;
+ return -1;
+ }
+
+ /* create the linear mapping */
+ if (_create_linear_mapping(&base, base, size)) {
+ __dpmi_free_ldt_descriptor(*segment);
+ *segment = 0;
+ return -1;
+ }
+
+ /* set the descriptor base and limit */
+ __dpmi_set_segment_base_address(*segment, base);
+ __dpmi_set_segment_limit(*segment, MAX(size-1, 0xFFFF));
+
+ return 0;
+}
+
+
+
+/* _remove_selector:
+ * Frees a DPMI segment selector.
+ */
+void _remove_selector (int *segment)
+{
+ if (*segment) {
+ unsigned long base;
+ __dpmi_get_segment_base_address(*segment, &base);
+ _remove_linear_mapping(&base);
+ __dpmi_free_ldt_descriptor(*segment);
+ *segment = 0;
+ }
+}
+
+
+
+/* Desc: retrieve CPU MMX capability
+ *
+ * In : -
+ * Out : FALSE if CPU cannot do MMX
+ *
+ * Note: -
+ */
+int _can_mmx (void)
+{
+#ifdef USE_MMX_ASM
+ extern int _mesa_x86_cpu_features;
+ return (_mesa_x86_cpu_features & 0x00800000);
+#else
+ return 0;
+#endif
+}
-/*\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\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#ifndef INTERNAL_H_included\r
-#define INTERNAL_H_included\r
-\r
-#include "../mmath.h"\r
-\r
-/*\r
- * general purpose defines, etc.\r
- */\r
-#ifndef FALSE\r
-#define FALSE 0\r
-#define TRUE !FALSE\r
-#endif\r
-\r
-#define __PACKED__ __attribute__((packed))\r
-\r
-typedef unsigned char word8;\r
-typedef unsigned short word16;\r
-typedef unsigned long word32;\r
-\r
-#define _16_ *(word16 *)&\r
-#define _32_ *(word32 *)&\r
-\r
-\r
-\r
-/*\r
- * video mode structure\r
- */\r
-typedef struct vl_mode {\r
- int mode;\r
- int xres, yres;\r
- int scanlen;\r
- int bpp;\r
-\r
- int sel;\r
- int gran;\r
-} vl_mode;\r
-\r
-\r
-\r
-/*\r
- * video driver structure\r
- */\r
-typedef struct {\r
- vl_mode *(*init) (void);\r
- int (*entermode) (vl_mode *p, int refresh);\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 (*get) (int pname, int *params);\r
- void (*restore) (void);\r
- void (*fini) (void);\r
-} vl_driver;\r
-\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 _can_mmx (void);\r
-\r
-/*\r
- * asm routines to deal with virtual buffering\r
- */\r
-extern void v_clear8 (int color);\r
-#define v_clear15 v_clear16\r
-extern void v_clear16 (int color);\r
-extern void v_clear24 (int color);\r
-extern void v_clear32 (int color);\r
-\r
-extern void v_clear8_mmx (int color);\r
-#define v_clear15_mmx v_clear16_mmx\r
-extern void v_clear16_mmx (int color);\r
-extern void v_clear24_mmx (int color);\r
-extern void v_clear32_mmx (int color);\r
-\r
-extern void v_rect8 (int x, int y, int width, int height, int color);\r
-#define v_rect15 v_rect16\r
-extern void v_rect16 (int x, int y, int width, int height, int color);\r
-extern void v_rect24 (int x, int y, int width, int height, int color);\r
-extern void v_rect32 (int x, int y, int width, int height, int color);\r
-\r
-extern void v_putpixel8 (unsigned int offset, int color);\r
-#define v_putpixel15 v_putpixel16\r
-extern void v_putpixel16 (unsigned int offset, int color);\r
-extern void v_putpixel24 (unsigned int offset, int color);\r
-extern void v_putpixel32 (unsigned int offset, int color);\r
-\r
-#endif\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.4 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef INTERNAL_H_included
+#define INTERNAL_H_included
+
+#include "../main/mtypes.h"
+
+/*
+ * general purpose defines, etc.
+ */
+#ifndef FALSE
+#define FALSE 0
+#define TRUE !FALSE
+#endif
+
+#define __PACKED__ __attribute__((packed))
+
+typedef unsigned char word8;
+typedef unsigned short word16;
+typedef unsigned long word32;
+
+#define _16_ *(word16 *)&
+#define _32_ *(word32 *)&
+
+
+
+/*
+ * video mode structure
+ */
+typedef struct vl_mode {
+ int mode;
+ int xres, yres;
+ int scanlen;
+ int bpp;
+
+ int sel;
+ int gran;
+} vl_mode;
+
+
+
+/*
+ * video driver structure
+ */
+typedef struct {
+ vl_mode *(*init) (void);
+ int (*entermode) (vl_mode *p, int refresh);
+ void (*blit) (void);
+ void (*setCI_f) (int index, float red, float green, float blue);
+ void (*setCI_i) (int index, int red, int green, int blue);
+ int (*get) (int pname, int *params);
+ void (*restore) (void);
+ void (*fini) (void);
+} vl_driver;
+
+
+
+/*
+ * memory mapping
+ */
+int _create_linear_mapping (unsigned long *linear, unsigned long physaddr, int size);
+void _remove_linear_mapping (unsigned long *linear);
+int _create_selector (int *segment, unsigned long base, int size);
+void _remove_selector (int *segment);
+
+/*
+ * system routines
+ */
+int _can_mmx (void);
+
+/*
+ * asm routines to deal with virtual buffering
+ */
+extern void v_clear8 (int color);
+#define v_clear15 v_clear16
+extern void v_clear16 (int color);
+extern void v_clear24 (int color);
+extern void v_clear32 (int color);
+
+extern void v_clear8_mmx (int color);
+#define v_clear15_mmx v_clear16_mmx
+extern void v_clear16_mmx (int color);
+extern void v_clear24_mmx (int color);
+extern void v_clear32_mmx (int color);
+
+extern void v_rect8 (int x, int y, int width, int height, int color);
+#define v_rect15 v_rect16
+extern void v_rect16 (int x, int y, int width, int height, int color);
+extern void v_rect24 (int x, int y, int width, int height, int color);
+extern void v_rect32 (int x, int y, int width, int height, int color);
+
+extern void v_putpixel8 (unsigned int offset, int color);
+#define v_putpixel15 v_putpixel16
+extern void v_putpixel16 (unsigned int offset, int color);
+extern void v_putpixel24 (unsigned int offset, int color);
+extern void v_putpixel32 (unsigned int offset, int color);
+
+#endif
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W triangle template
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W triangle template
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ *
+ * Thanks to Shawn Hargreaves for FreeBE/AF
+ */
+
+
+#include <dpmi.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "../internal.h"
+#include "mga_reg.h"
+#include "mga_hw.h"
+#include "mga_mode.h"
+#include "mga.h"
+
+
+
+/* cached drawing engine state */
+#define OP_NONE 0
+
+#define OP_DRAWRECT (\
+ M_DWG_TRAP | /* opcod */ \
+ M_DWG_BLK | /* atype */ \
+ /* linear */ \
+ M_DWG_NOZCMP | /* zmode */ \
+ M_DWG_SOLID | /* solid */ \
+ M_DWG_ARZERO | /* arzero */ \
+ M_DWG_SGNZERO | /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC /* bop */ \
+ /* trans */ \
+ /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWRECT_TX32BGR (\
+ M_DWG_TEXTURE_TRAP | /* opcod */ \
+ M_DWG_I | /* atype */ \
+ /* linear */ \
+ M_DWG_NOZCMP | /* zmode */ \
+ /* solid */ \
+ M_DWG_ARZERO | /* arzero */ \
+ M_DWG_SGNZERO | /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC | /* bop */ \
+ /* trans */ \
+ M_DWG_BU32BGR /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWRECT_TX24BGR (\
+ M_DWG_TEXTURE_TRAP | /* opcod */ \
+ M_DWG_I | /* atype */ \
+ /* linear */ \
+ M_DWG_NOZCMP | /* zmode */ \
+ /* solid */ \
+ M_DWG_ARZERO | /* arzero */ \
+ M_DWG_SGNZERO | /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC | /* bop */ \
+ /* trans */ \
+ M_DWG_BU24BGR /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWLINE (\
+ M_DWG_AUTOLINE_CLOSE | /* opcod */ \
+ M_DWG_RPL | /* atype */ \
+ /* linear */ \
+ M_DWG_NOZCMP | /* zmode */ \
+ M_DWG_SOLID | /* solid */ \
+ /* arzero */ \
+ /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC | /* bop */ \
+ /* trans */ \
+ M_DWG_BFCOL /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWLINE_I (\
+ M_DWG_AUTOLINE_CLOSE | /* opcod */ \
+ M_DWG_I | /* atype */ \
+ /* linear */ \
+ M_DWG_NOZCMP | /* zmode */ \
+ /* solid */ \
+ /* arzero */ \
+ /* sgnzero */ \
+ /* shftzero */ \
+ M_DWG_BOP_SRC | /* bop */ \
+ /* trans */ \
+ M_DWG_BFCOL /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWLINE_ZI (\
+ M_DWG_AUTOLINE_CLOSE | /* opcod */ \
+ M_DWG_ZI | /* atype */ \
+ /* linear */ \
+ M_DWG_ZLT | /* zmode */ \
+ /* solid */ \
+ /* arzero */ \
+ /* sgnzero */ \
+ /* shftzero */ \
+ M_DWG_BOP_SRC | /* bop */ \
+ /* trans */ \
+ M_DWG_BFCOL /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWTRAP (\
+ M_DWG_TRAP | /* opcod */ \
+ M_DWG_BLK | /* atype */ \
+ /* linear */ \
+ M_DWG_NOZCMP | /* zmode */ \
+ M_DWG_SOLID | /* solid */ \
+ /* arzero */ \
+ /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC /* bop */ \
+ /* trans */ \
+ /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWTRAP_I (\
+ M_DWG_TRAP | /* opcod */ \
+ M_DWG_I | /* atype */ \
+ /* linear */ \
+ M_DWG_NOZCMP | /* zmode */ \
+ /* solid */ \
+ /* arzero */ \
+ /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC /* bop */ \
+ /* trans */ \
+ /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_DRAWTRAP_ZI (\
+ M_DWG_TRAP | /* opcod */ \
+ M_DWG_ZI | /* atype */ \
+ /* linear */ \
+ M_DWG_ZLT | /* zmode */ \
+ /* solid */ \
+ /* arzero */ \
+ /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC /* bop */ \
+ /* trans */ \
+ /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_ILOAD_32BGR (\
+ M_DWG_ILOAD | /* opcod */ \
+ M_DWG_RPL | /* atype */ \
+ /* linear */ \
+ /* zmode */ \
+ /* solid */ \
+ /* arzero */ \
+ M_DWG_SGNZERO | /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC | /* bop */ \
+ /* trans */ \
+ M_DWG_BU32BGR /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+#define OP_ILOAD_24BGR (\
+ M_DWG_ILOAD | /* opcod */ \
+ M_DWG_RPL | /* atype */ \
+ /* linear */ \
+ /* zmode */ \
+ /* solid */ \
+ /* arzero */ \
+ M_DWG_SGNZERO | /* sgnzero */ \
+ M_DWG_SHFTZERO | /* shftzero */ \
+ M_DWG_BOP_SRC | /* bop */ \
+ /* trans */ \
+ M_DWG_BU24BGR /* bltmod */ \
+ /* pattern */ \
+ /* transc */ )
+
+
+
+/* internal hardware data structures */
+static int interleave;
+static unsigned long zorg;
+static unsigned long vram;
+static char card_name[80];
+
+
+
+/* some info about current mode */
+static int __bpp, __bypp;
+static int __pixwidth, __bytwidth, __pagewidth, __width, __height, __zheight;
+static int __operation;
+static int __scrollx, __scrolly;
+
+
+
+/* buffers */
+static int mga_readbuffer, mga_writebuffer;
+static long mga_readbuffer_ptr, mga_writebuffer_ptr;
+static long mga_backbuffer_ptr, mga_frontbuffer_ptr;
+
+
+
+/* lookup table for scaling 2 bit colors up to 8 bits */
+static int _rgb_scale_2[4] = {
+ 0, 85, 170, 255
+};
+
+/* lookup table for scaling 3 bit colors up to 8 bits */
+static int _rgb_scale_3[8] = {
+ 0, 36, 73, 109, 146, 182, 219, 255
+};
+
+/* lookup table for scaling 5 bit colors up to 8 bits */
+static int _rgb_scale_5[32] = {
+ 0, 8, 16, 25, 33, 41, 49, 58,
+ 66, 74, 82, 90, 99, 107, 115, 123,
+ 132, 140, 148, 156, 165, 173, 181, 189,
+ 197, 206, 214, 222, 230, 239, 247, 255
+};
+
+/* lookup table for scaling 6 bit colors up to 8 bits */
+static int _rgb_scale_6[64] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 36, 40, 45, 49, 53, 57, 61,
+ 65, 69, 73, 77, 81, 85, 89, 93,
+ 97, 101, 105, 109, 113, 117, 121, 125,
+ 130, 134, 138, 142, 146, 150, 154, 158,
+ 162, 166, 170, 174, 178, 182, 186, 190,
+ 194, 198, 202, 206, 210, 215, 219, 223,
+ 227, 231, 235, 239, 243, 247, 251, 255
+};
+
+
+
+/*
+ * pixel/color routines
+ */
+void (*mga_putpixel) (unsigned int offset, int color);
+int (*mga_getpixel) (unsigned int offset);
+void (*mga_getrgba) (unsigned int offset, unsigned char rgba[4]);
+int (*mga_mixrgb) (const unsigned char rgb[]);
+static int (*mga_mixrgb_full) (const unsigned char rgb[]);
+
+
+
+/* mga_fifo:
+ * Waits until there are at least <n> free slots in the FIFO buffer.
+ */
+#define mga_fifo(n) do { } while (mga_inb(M_FIFOSTATUS) < (n))
+
+
+
+static int _mga_rread (int port, int index)
+{
+ mga_select();
+ mga_outb(port, index);
+ return mga_inb(port+1);
+}
+
+
+
+static void _mga_rwrite (int port, int index, int v)
+{
+ mga_select();
+ mga_outb(port, index);
+ mga_outb(port+1, v);
+}
+
+
+
+static void _mga_ralter (int port, int index, int mask, int v)
+{
+ int temp;
+ temp = _mga_rread(port, index);
+ temp &= (~mask);
+ temp |= (v & mask);
+ _mga_rwrite(port, index, temp);
+}
+
+
+
+/* WaitTillIdle:
+ * Delay until the hardware controller has finished drawing.
+ */
+void mga_wait_idle (void)
+{
+ int tries = 2;
+
+ /*hwptr_unselect(oldptr);*/
+
+ mga_select();
+
+ while (tries--) {
+ do {
+ } while (!(mga_inl(M_FIFOSTATUS) & 0x200));
+
+ do {
+ } while (mga_inl(M_STATUS) & 0x10000);
+
+ mga_outb(M_CRTC_INDEX, 0);
+ }
+
+ /*hwptr_select(oldptr);*/
+}
+
+
+
+/* Desc: Waits for the next vertical sync period.
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+static void _mga_wait_retrace (void)
+{
+ int t1 = 0;
+ int t2 = 0;
+
+ do {
+ t1 = t2;
+ t2 = mga_inl(M_VCOUNT);
+ } while (t2 >= t1);
+}
+
+
+
+/* Desc: fix scan lines
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+static unsigned long _mga_fix_scans (unsigned long l)
+{
+ unsigned long m = 0;
+
+ switch (__bpp) {
+ case 8:
+ m = interleave?128:64;
+ break;
+ case 15:
+ case 16:
+ m = interleave?64:32;
+ break;
+ case 24:
+ m = interleave?128:64;
+ break;
+ case 32:
+ m = 32;
+ break;
+ }
+
+ m -= 1;
+ return (l + m) & ~m;
+}
+
+
+
+/* Desc: HW scrolling function
+ *
+ * In :
+ * Out :
+ *
+ * Note: view Z-buffer in 16bit modes: _mga_display_start(0, 0, __height, 1)
+ */
+void mga_display_start (long boffset, long x, long y, long waitVRT)
+{
+ long addr;
+
+ mga_select();
+
+ if (waitVRT >= 0) {
+
+ addr = __bytwidth * y + (boffset + x) * __bypp;
+
+ if (interleave) {
+ addr /= 8;
+ } else {
+ addr /= 4;
+ }
+
+ _mga_rwrite(M_CRTC_INDEX, 0x0D, (addr)&0xFF);
+ _mga_rwrite(M_CRTC_INDEX, 0x0C, (addr>>8)&0xFF);
+ _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x0F, (addr>>16)&0x0F);
+
+ while (waitVRT--) {
+ _mga_wait_retrace();
+ }
+ }
+
+ __scrollx = x;
+ __scrolly = y;
+}
+
+
+
+/* Desc: set READ buffer
+ *
+ * In : either FRONT or BACK buffer
+ * Out :
+ *
+ * Note:
+ */
+void mga_set_readbuffer (int buffer)
+{
+ mga_readbuffer = buffer;
+
+ mga_readbuffer_ptr = (mga_readbuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr;
+}
+
+
+
+/* Desc: set WRITE buffer
+ *
+ * In : either FRONT or BACK buffer
+ * Out :
+ *
+ * Note:
+ */
+void mga_set_writebuffer (int buffer)
+{
+ mga_writebuffer = buffer;
+
+ mga_writebuffer_ptr = (mga_writebuffer == MGA_FRONTBUFFER) ? mga_frontbuffer_ptr : mga_backbuffer_ptr;
+
+ mga_select();
+ mga_fifo(1);
+ mga_outl(M_YDSTORG, mga_writebuffer_ptr);
+
+ __operation = OP_NONE;
+}
+
+
+
+/* Desc: swap buffers
+ *
+ * In : number of vertical retraces to wait
+ * Out :
+ *
+ * Note:
+ */
+void mga_swapbuffers (int swapinterval)
+{
+ /* flip the buffers */
+ mga_backbuffer_ptr ^= __pagewidth;
+ mga_frontbuffer_ptr ^= __pagewidth;
+
+ /* update READ/WRITE pointers */
+ mga_set_readbuffer(mga_readbuffer);
+ mga_set_writebuffer(mga_writebuffer);
+
+ /* make sure we always see the FRONT buffer */
+ mga_display_start(mga_frontbuffer_ptr, __scrollx, __scrolly, swapinterval);
+}
+
+
+
+/* Desc: color composition (w/o ALPHA)
+ *
+ * In : array of integers (R, G, B)
+ * Out : color
+ *
+ * Note: -
+ */
+static __inline int _mga_mixrgb8 (const unsigned char rgb[])
+{
+ return (rgb[0]&0xe0)|((rgb[1]>>5)<<2)|(rgb[2]>>6);
+}
+static __inline int _mga_mixrgb15 (const unsigned char rgb[])
+{
+ return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3);
+}
+static __inline int _mga_mixrgb16 (const unsigned char rgb[])
+{
+ return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3);
+}
+static __inline int _mga_mixrgb32 (const unsigned char rgb[])
+{
+ return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);
+}
+
+
+
+/* Desc: color composition (w/o ALPHA) + replication
+ *
+ * In : array of integers (R, G, B)
+ * Out : color
+ *
+ * Note: -
+ */
+static int _mga_mixrgb8_full (const unsigned char rgb[])
+{
+ int color = _mga_mixrgb8(rgb);
+ color |= color<<8;
+ return (color<<16) | color;
+}
+static int _mga_mixrgb15_full (const unsigned char rgb[])
+{
+ int color = _mga_mixrgb15(rgb);
+ return (color<<16) | color;
+}
+static int _mga_mixrgb16_full (const unsigned char rgb[])
+{
+ int color = _mga_mixrgb16(rgb);
+ return (color<<16) | color;
+}
+#define _mga_mixrgb32_full _mga_mixrgb32
+
+
+
+/* Desc: putpixel
+ *
+ * In : pixel offset, pixel value
+ * Out : -
+ *
+ * Note: uses current write buffer
+ */
+static void _mga_putpixel8 (unsigned int offset, int color)
+{
+ hwptr_pokeb(mgaptr.linear_map, mga_writebuffer_ptr + offset, color);
+}
+#define _mga_putpixel15 _mga_putpixel16
+static void _mga_putpixel16 (unsigned int offset, int color)
+{
+ hwptr_pokew(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 2, color);
+}
+static void _mga_putpixel32 (unsigned int offset, int color)
+{
+ hwptr_pokel(mgaptr.linear_map, (mga_writebuffer_ptr + offset) * 4, color);
+}
+
+
+
+/* Desc: pixel retrieval
+ *
+ * In : pixel offset
+ * Out : pixel value
+ *
+ * Note: uses current read buffer
+ */
+static __inline int _mga_getpixel8 (unsigned int offset)
+{
+ return hwptr_peekb(mgaptr.linear_map, mga_readbuffer_ptr + offset);
+}
+#define _mga_getpixel15 _mga_getpixel16
+static __inline int _mga_getpixel16 (unsigned int offset)
+{
+ return hwptr_peekw(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 2);
+}
+static __inline int _mga_getpixel32 (unsigned int offset)
+{
+ return hwptr_peekl(mgaptr.linear_map, (mga_readbuffer_ptr + offset) * 4);
+}
+
+
+
+/* Desc: color decomposition
+ *
+ * In : pixel offset, array of integers to hold color components (R, G, B, A)
+ * Out : -
+ *
+ * Note: uses current read buffer
+ */
+static void _mga_getrgba8 (unsigned int offset, unsigned char rgba[4])
+{
+ int c = _mga_getpixel8(offset);
+ rgba[0] = _rgb_scale_3[(c >> 5) & 0x7];
+ rgba[1] = _rgb_scale_3[(c >> 2) & 0x7];
+ rgba[2] = _rgb_scale_2[c & 0x3];
+ rgba[3] = 255;
+}
+static void _mga_getrgba15 (unsigned int offset, unsigned char rgba[4])
+{
+ int c = _mga_getpixel15(offset);
+ rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F];
+ rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F];
+ rgba[2] = _rgb_scale_5[c & 0x1F];
+ rgba[3] = 255;
+}
+static void _mga_getrgba16 (unsigned int offset, unsigned char rgba[4])
+{
+ int c = _mga_getpixel16(offset);
+ rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F];
+ rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F];
+ rgba[2] = _rgb_scale_5[c & 0x1F];
+ rgba[3] = 255;
+}
+static void _mga_getrgba32 (unsigned int offset, unsigned char rgba[4])
+{
+ int c = _mga_getpixel32(offset);
+ rgba[0] = c >> 16;
+ rgba[1] = c >> 8;
+ rgba[2] = c;
+ rgba[3] = c >> 24;
+}
+
+
+
+/* Desc: RGB flat line
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_draw_line_rgb_flat (const MGAvertex *v1, const MGAvertex *v2)
+{
+ unsigned long color;
+ int x1 = v1->win[0];
+ int y1 = v1->win[1];
+ int x2 = v2->win[0];
+ int y2 = v2->win[1];
+
+ if ((x1 == x2) && (y1 == y2)) {
+ return;
+ }
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWLINE) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWLINE);
+ __operation = OP_DRAWLINE;
+ }
+
+ color = mga_mixrgb_full(v2->color);
+
+ /* draw the line */
+ mga_fifo(3);
+ mga_outl(M_FCOL, color);
+ mga_outl(M_XYSTRT, (y1<<16) | x1);
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
+}
+
+
+
+/* Desc: RGB flat Z-less line
+ *
+ * In :
+ * Out :
+ *
+ * Note: I never figured out "diagonal increments"
+ */
+void mga_draw_line_rgb_flat_zless (const MGAvertex *v1, const MGAvertex *v2)
+{
+ int z1, dz;
+ int x1 = v1->win[0];
+ int y1 = v1->win[1];
+ int x2 = v2->win[0];
+ int y2 = v2->win[1];
+ int dx = abs(x2 - x1);
+ int dy = abs(y2 - y1);
+
+ if ((dx == 0) && (dy == 0)) {
+ return;
+ }
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWLINE_ZI) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWLINE_ZI);
+ __operation = OP_DRAWLINE_ZI;
+ }
+
+ if (dx < dy) {
+ dx = dy;
+ }
+
+ z1 = v1->win[2] << 15;
+ dz = ((v2->win[2] << 15) - z1) / dx;
+
+ /* draw the line */
+ mga_fifo(14);
+ mga_outl(M_DR0, z1);
+ mga_outl(M_DR2, dz);
+ mga_outl(M_DR3, dz);
+ mga_outl(M_DR4, v2->color[0] << 15);
+ mga_outl(M_DR6, 0);
+ mga_outl(M_DR7, 0);
+ mga_outl(M_DR8, v2->color[1] << 15);
+ mga_outl(M_DR10, 0);
+ mga_outl(M_DR11, 0);
+ mga_outl(M_DR12, v2->color[2] << 15);
+ mga_outl(M_DR14, 0);
+ mga_outl(M_DR15, 0);
+ mga_outl(M_XYSTRT, (y1<<16) | x1);
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
+}
+
+
+
+/* Desc: RGB iterated line
+ *
+ * In :
+ * Out :
+ *
+ * Note: I never figured out "diagonal increments"
+ */
+void mga_draw_line_rgb_iter (const MGAvertex *v1, const MGAvertex *v2)
+{
+ int r1, g1, b1;
+ int dr, dg, db;
+ int x1 = v1->win[0];
+ int y1 = v1->win[1];
+ int x2 = v2->win[0];
+ int y2 = v2->win[1];
+ int dx = abs(x2 - x1);
+ int dy = abs(y2 - y1);
+
+ if ((dx == 0) && (dy == 0)) {
+ return;
+ }
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWLINE_I) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWLINE_I);
+ __operation = OP_DRAWLINE_I;
+ }
+
+ if (dx < dy) {
+ dx = dy;
+ }
+
+ r1 = v1->color[0] << 15;
+ g1 = v1->color[1] << 15;
+ b1 = v1->color[2] << 15;
+ dr = ((v2->color[0] << 15) - r1) / dx;
+ dg = ((v2->color[1] << 15) - g1) / dx;
+ db = ((v2->color[2] << 15) - b1) / dx;
+
+ /* draw the line */
+ mga_fifo(11);
+ mga_outl(M_DR4, r1);
+ mga_outl(M_DR6, dr);
+ mga_outl(M_DR7, dr);
+ mga_outl(M_DR8, g1);
+ mga_outl(M_DR10, dg);
+ mga_outl(M_DR11, dg);
+ mga_outl(M_DR12, b1);
+ mga_outl(M_DR14, db);
+ mga_outl(M_DR15, db);
+ mga_outl(M_XYSTRT, (y1<<16) | x1);
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
+}
+
+
+
+/* Desc: RGB iterated Z-less line
+ *
+ * In :
+ * Out :
+ *
+ * Note: I never figured out "diagonal increments"
+ */
+void mga_draw_line_rgb_iter_zless (const MGAvertex *v1, const MGAvertex *v2)
+{
+ int z1, dz;
+ int r1, g1, b1;
+ int dr, dg, db;
+ int x1 = v1->win[0];
+ int y1 = v1->win[1];
+ int x2 = v2->win[0];
+ int y2 = v2->win[1];
+ int dx = abs(x2 - x1);
+ int dy = abs(y2 - y1);
+
+ if ((dx == 0) && (dy == 0)) {
+ return;
+ }
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWLINE_ZI) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWLINE_ZI);
+ __operation = OP_DRAWLINE_ZI;
+ }
+
+ if (dx < dy) {
+ dx = dy;
+ }
+
+ z1 = v1->win[2] << 15;
+ dz = ((v2->win[2] << 15) - z1) / dx;
+
+ r1 = v1->color[0] << 15;
+ g1 = v1->color[1] << 15;
+ b1 = v1->color[2] << 15;
+ dr = ((v2->color[0] << 15) - r1) / dx;
+ dg = ((v2->color[1] << 15) - g1) / dx;
+ db = ((v2->color[2] << 15) - b1) / dx;
+
+ /* draw the line */
+ mga_fifo(14);
+ mga_outl(M_DR0, z1);
+ mga_outl(M_DR2, dz);
+ mga_outl(M_DR3, dz);
+ mga_outl(M_DR4, r1);
+ mga_outl(M_DR6, dr);
+ mga_outl(M_DR7, dr);
+ mga_outl(M_DR8, g1);
+ mga_outl(M_DR10, dg);
+ mga_outl(M_DR11, dg);
+ mga_outl(M_DR12, b1);
+ mga_outl(M_DR14, db);
+ mga_outl(M_DR15, db);
+ mga_outl(M_XYSTRT, (y1<<16) | x1);
+ mga_outl(M_XYEND | M_EXEC, (y2<<16) | x2);
+}
+
+
+
+/* Desc: RGB flat triangle
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+#define TAG mga_draw_tri_rgb_flat
+#define CULL
+#define SETUP_CODE \
+ if (__operation != OP_DRAWTRAP) { \
+ mga_fifo(1); \
+ mga_outl(M_DWGCTL, OP_DRAWTRAP); \
+ __operation = OP_DRAWTRAP; \
+ }
+#include "m_ttemp.h"
+
+
+
+/* Desc: RGB flat Z-less triangle
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+#define TAG mga_draw_tri_rgb_flat_zless
+#define CULL
+#define INTERP_Z
+#define SETUP_CODE \
+ if (__operation != OP_DRAWTRAP_ZI) { \
+ mga_fifo(1); \
+ mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \
+ __operation = OP_DRAWTRAP_ZI; \
+ }
+#include "m_ttemp.h"
+
+
+
+/* Desc: RGB iterated triangle
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+#define TAG mga_draw_tri_rgb_iter
+#define CULL
+#define INTERP_RGB
+#define SETUP_CODE \
+ if (__operation != OP_DRAWTRAP_I) { \
+ mga_fifo(1); \
+ mga_outl(M_DWGCTL, OP_DRAWTRAP_I); \
+ __operation = OP_DRAWTRAP_I; \
+ }
+#include "m_ttemp.h"
+
+
+
+/* Desc: RGB iterated Z-less triangle
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+#define TAG mga_draw_tri_rgb_iter_zless
+#define CULL
+#define INTERP_Z
+#define INTERP_RGB
+#define SETUP_CODE \
+ if (__operation != OP_DRAWTRAP_ZI) { \
+ mga_fifo(1); \
+ mga_outl(M_DWGCTL, OP_DRAWTRAP_ZI); \
+ __operation = OP_DRAWTRAP_ZI; \
+ }
+#include "m_ttemp.h"
+
+
+
+/* Desc: RGB flat rectangle
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_draw_rect_rgb_flat (int left, int top, int width, int height, int color)
+{
+ if (__bpp == 8) {
+ color |= color << 8;
+ }
+ if (__bpp <= 16) {
+ color |= color << 16;
+ }
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWRECT) {
+
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWRECT);
+ __operation = OP_DRAWRECT;
+ }
+
+ /* draw the rectangle */
+ mga_fifo(3);
+ mga_outl(M_FCOL, color);
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
+}
+
+
+
+/* Desc: 32RGB textured span
+ *
+ * In :
+ * Out :
+ *
+ * Note: 0 <= width <= 7*1024
+ */
+void mga_draw_span_rgb_tx32 (int left, int top, int width, const unsigned long *bitmap)
+{
+ int i;
+
+ if (!width) {
+ return;
+ }
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWRECT_TX32BGR) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR);
+ __operation = OP_DRAWRECT_TX32BGR;
+ }
+
+ /* draw the rectangle */
+ mga_fifo(2);
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1);
+
+ /* copy data to the pseudo-dma window */
+ i = 0;
+ do {
+ mga_outl(i, *bitmap);
+ bitmap++;
+ i += 4;
+ } while (--width);
+}
+
+
+
+/* Desc: 24RGB textured span
+ *
+ * In :
+ * Out :
+ *
+ * Note: 0 <= width <= 7*1024
+ */
+void mga_draw_span_rgb_tx24 (int left, int top, int width, const unsigned long *bitmap)
+{
+ int i;
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWRECT_TX24BGR) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR);
+ __operation = OP_DRAWRECT_TX24BGR;
+ }
+
+ /* draw the rectangle */
+ mga_fifo(2);
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | 1);
+
+ /* copy data to the pseudo-dma window */
+ i = 0;
+ width = (width * 3 + 3) / 4;
+ while (width) {
+ mga_outl(i & (7 * 1024 - 1), *bitmap);
+ bitmap++;
+ i += 4;
+ width--;
+ }
+}
+
+
+
+/* Desc: 32RGB textured rectangle
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_draw_rect_rgb_tx32 (int left, int top, int width, int height, const unsigned long *bitmap)
+{
+ int i;
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWRECT_TX32BGR) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX32BGR);
+ __operation = OP_DRAWRECT_TX32BGR;
+ }
+
+ /* draw the rectangle */
+ mga_fifo(2);
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
+
+ /* copy data to the pseudo-dma window */
+ i = 0;
+ width *= height;
+ while (width) {
+ mga_outl(i & (7 * 1024 - 1), *bitmap);
+ bitmap++;
+ i += 4;
+ width--;
+ }
+}
+
+
+
+/* Desc: 24RGB textured rectangle
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_draw_rect_rgb_tx24 (int left, int top, int width, int height, const unsigned long *bitmap)
+{
+ int i;
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_DRAWRECT_TX24BGR) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_DRAWRECT_TX24BGR);
+ __operation = OP_DRAWRECT_TX24BGR;
+ }
+
+ /* draw the rectangle */
+ mga_fifo(2);
+ mga_outl(M_FXBNDRY, ((left+width)<<16) | left);
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
+
+ /* copy data to the pseudo-dma window */
+ i = 0;
+ width = (width * height * 3 + 3) / 4;
+ while (width) {
+ mga_outl(i & (7 * 1024 - 1), *bitmap);
+ bitmap++;
+ i += 4;
+ width--;
+ }
+}
+
+
+
+/* Desc: copy 32RGB image to screen
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_iload_32RGB (int left, int top, int width, int height, const unsigned long *bitmap)
+{
+ int i;
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_ILOAD_32BGR) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_ILOAD_32BGR);
+ __operation = OP_ILOAD_32BGR;
+ }
+
+ /* draw the bitmap */
+ mga_fifo(5);
+ mga_outl(M_AR0, width-1);
+ mga_outl(M_AR3, 0);
+ mga_outl(M_AR5, 0);
+ mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left);
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
+
+ /* copy data to the pseudo-dma window */
+ i = 0;
+ width *= height;
+ while (width) {
+ mga_outl(i & (7 * 1024 - 1), *bitmap);
+ bitmap++;
+ i += 4;
+ width--;
+ }
+}
+
+
+
+/* Desc: copy 24RGB image to screen
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_iload_24RGB (int left, int top, int width, int height, const unsigned long *bitmap)
+{
+ int i;
+
+ mga_select();
+
+ /* set engine state */
+ if (__operation != OP_ILOAD_24BGR) {
+ mga_fifo(1);
+ mga_outl(M_DWGCTL, OP_ILOAD_24BGR);
+ __operation = OP_ILOAD_24BGR;
+ }
+
+ /* draw the bitmap */
+ mga_fifo(5);
+ mga_outl(M_AR0, width-1);
+ mga_outl(M_AR3, 0);
+ mga_outl(M_AR5, 0);
+ mga_outl(M_FXBNDRY, ((left+width-1)<<16) | left);
+ mga_outl(M_YDSTLEN | M_EXEC, (top<<16) | height);
+
+ /* copy data to the pseudo-dma window */
+ i = 0;
+ width = (width * height * 3 + 3) / 4;
+ while (width) {
+ mga_outl(i & (7 * 1024 - 1), *bitmap);
+ bitmap++;
+ i += 4;
+ width--;
+ }
+}
+
+
+
+/* Desc: get Z-buffer value
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+unsigned short mga_getz (int offset)
+{
+ return hwptr_peekw(mgaptr.linear_map, zorg + (mga_readbuffer_ptr + offset) * 2);
+}
+
+
+
+/* Desc: put Z-buffer value
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_setz (int offset, unsigned short z)
+{
+ hwptr_pokew(mgaptr.linear_map, zorg + (mga_writebuffer_ptr + offset) * 2, z);
+}
+
+
+
+/* Desc: clear Z-buffer
+ *
+ * In :
+ * Out :
+ *
+ * Note: uses current write buffer
+ */
+static void _mga_clear_zed (int left, int top, int width, int height, unsigned short z)
+{
+ if (__bpp == 16) {
+ /* GPU store (high bandwidth)
+ * Hack alert:
+ * can cause problems with concurrent FB accesses
+ */
+ mga_select();
+ mga_fifo(1);
+ mga_outl(M_YDSTORG, mga_writebuffer_ptr + zorg/2);
+ mga_draw_rect_rgb_flat(left, top, width, height, z);
+ mga_fifo(1);
+ mga_outl(M_YDSTORG, mga_writebuffer_ptr);
+ } else {
+ /* CPU store */
+ unsigned long i, zz = (z<<16) | z;
+ unsigned long ofs = zorg + (top * __pixwidth + left + mga_writebuffer_ptr) * 2;
+ hwptr_select(mgaptr.linear_map);
+ while (height--) {
+ i = width/2;
+ while (i--) {
+ hwptr_nspokel(mgaptr.linear_map, ofs, zz);
+ ofs += 4;
+ }
+ if (width & 1) {
+ hwptr_nspokew(mgaptr.linear_map, ofs, z);
+ ofs += 2;
+ }
+ ofs += (__pixwidth - width) * 2;
+ }
+ }
+}
+
+
+
+/* Desc: clear color- and Z-buffer
+ *
+ * In : front = clear front buffer
+ * back = clear back buffer
+ * zed = clear depth buffer
+ * left = leftmost pixel to be cleared
+ * top = starting line
+ * width = number of pixels
+ * height = number of lines
+ * color = color to clear to
+ * z = z value (ignored if zed==0)
+ * Out :
+ *
+ * Note:
+ */
+void mga_clear (int front, int back, int zed, int left, int top, int width, int height, int color, unsigned short z)
+{
+ if (front) {
+ if (mga_writebuffer == MGA_FRONTBUFFER) {
+ mga_draw_rect_rgb_flat(left, top, width, height, color);
+ if (zed) {
+ _mga_clear_zed(left, top, width, height, z);
+ }
+ front = 0;
+ }
+ }
+ if (back) {
+ if (mga_writebuffer == MGA_BACKBUFFER) {
+ mga_draw_rect_rgb_flat(left, top, width, height, color);
+ if (zed) {
+ _mga_clear_zed(left, top, width, height, z);
+ }
+ back = 0;
+ }
+ }
+ if (front) {
+ int old = mga_writebuffer;
+ mga_set_writebuffer(MGA_FRONTBUFFER);
+ mga_draw_rect_rgb_flat(left, top, width, height, color);
+ if (zed) {
+ _mga_clear_zed(left, top, width, height, z);
+ }
+ mga_set_writebuffer(old);
+ front = 0;
+ }
+ if (back) {
+ int old = mga_writebuffer;
+ mga_set_writebuffer(MGA_BACKBUFFER);
+ mga_draw_rect_rgb_flat(left, top, width, height, color);
+ if (zed) {
+ _mga_clear_zed(left, top, width, height, z);
+ }
+ mga_set_writebuffer(old);
+ back = 0;
+ }
+}
+
+
+
+/* Desc: Attempts to enter specified video mode.
+ *
+ * In : ptr to mode structure, number of pages, Z-buffer request, refresh rate
+ * Out : 0 if success
+ *
+ * Note: also set up the accelerator engine
+ */
+int mga_open (int width, int height, int bpp, int buffers, int zbuffer, int refresh)
+{
+ static int mill_strides[] = { 640, 768, 800, 960, 1024, 1152, 1280, 1600, 1920, 2048, 0 };
+ unsigned int i, used;
+ MGA_MODE *p;
+
+ if (mga_hw_init(&vram, &interleave, card_name) == 0) {
+ return -1;
+ }
+
+ if ((p = mga_mode_find(width, height, bpp)) == NULL) {
+ return -1;
+ }
+
+ __bpp = p->bpp;
+ __width = __pagewidth = p->xres;
+ __height = p->yres;
+
+ if (buffers > 1) {
+ __pagewidth = _mga_fix_scans(__pagewidth);
+ __pixwidth = __pagewidth * buffers;
+ } else {
+ __pixwidth = __pagewidth;
+ __pixwidth = _mga_fix_scans(__pixwidth);
+ }
+
+ for (i=0; mill_strides[i]; i++) {
+ if (__pixwidth <= mill_strides[i]) {
+ __pixwidth = mill_strides[i];
+ break;
+ }
+ }
+
+ __bypp = (__bpp+7)/8;
+ __bytwidth = __pixwidth * __bypp;
+
+ /* compute used memory: framebuffer + zbuffer */
+ used = __bytwidth * __height;
+ if (zbuffer) {
+ zorg = (used + 511) & ~511;
+ /* Hack alert:
+ * a 16-bit Z-buffer size is (stride_in_pixels * number_of_lines * 2)
+ * We cannot mess with the Z-buffer width, but we might decrease the
+ * number of lines, if the user requests less than (screen_height). For
+ * example with a 2MB card, one can have 640x480x16 display with 2 color
+ * buffers and Z-buffer if the maximum requested height is 339:
+ * Total = (640*480 * 2 + 640*339 * 2) * 2
+ * However, this means the user must not write beyond the window's height
+ * and if we'll ever implement moveable windows, we'll have to reconsider
+ * this hack.
+ */
+#if 1
+ __zheight = height; /* smaller */
+ used = zorg + __pixwidth * 2 * __zheight;
+#else
+ __zheight = __height;
+ used = zorg + __pixwidth * 2 * __zheight;
+#endif
+ }
+
+ if (mill_strides[i] && (vram>=used)) {
+ /* enter mode */
+ mga_mode_switch(p, refresh);
+ /* change the scan line length */
+ _mga_ralter(M_CRTC_INDEX, 0x14, 0x40, 0); /* disable DWORD */
+ _mga_ralter(M_CRTC_INDEX, 0x17, 0x40, 0x40); /* wbmode = BYTE */
+ if (interleave) {
+ _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/16);
+ _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/16)>>4)&0x30);
+ } else {
+ _mga_rwrite(M_CRTC_INDEX, 0x13, __bytwidth/8);
+ _mga_ralter(M_CRTC_EXT_INDEX, 0, 0x30, ((__bytwidth/8)>>4)&0x30);
+ }
+ } else {
+ return -1;
+ }
+
+ /* setup buffers */
+ mga_frontbuffer_ptr = 0;
+ if (buffers > 1) {
+ mga_backbuffer_ptr = __pagewidth;
+ mga_set_readbuffer(MGA_BACKBUFFER);
+ mga_set_writebuffer(MGA_BACKBUFFER);
+ } else {
+ mga_backbuffer_ptr = 0;
+ mga_set_readbuffer(MGA_FRONTBUFFER);
+ mga_set_writebuffer(MGA_FRONTBUFFER);
+ }
+ mga_display_start(mga_frontbuffer_ptr, __scrollx = 0, __scrolly = 0, 1);
+
+ /* set up the accelerator engine */
+ mga_select();
+
+ mga_fifo(8);
+ mga_outl(M_PITCH, __pixwidth);
+ mga_outl(M_PLNWT, 0xFFFFFFFF);
+ mga_outl(M_OPMODE, M_DMA_BLIT);
+ mga_outl(M_CXBNDRY, 0xFFFF0000);
+ mga_outl(M_YTOP, 0x00000000);
+ mga_outl(M_YBOT, 0x007FFFFF);
+ mga_outl(M_ZORG, zorg);
+
+#define INITPTR(bpp) \
+ mga_putpixel = _mga_putpixel##bpp; \
+ mga_getrgba = _mga_getrgba##bpp; \
+ mga_getpixel = _mga_getpixel##bpp; \
+ mga_mixrgb = _mga_mixrgb##bpp; \
+ mga_mixrgb_full = _mga_mixrgb##bpp##_full
+
+ switch (__bpp) {
+ case 8:
+ mga_outl(M_MACCESS, 0);
+ INITPTR(8);
+ break;
+ case 15:
+ mga_outl(M_MACCESS, 0x80000001);
+ INITPTR(15);
+ break;
+ case 16:
+ mga_outl(M_MACCESS, 1);
+ INITPTR(16);
+ break;
+ case 32:
+ mga_outl(M_MACCESS, 2);
+ INITPTR(32);
+ break;
+ }
+
+#undef INITPTR
+
+ /* disable VGA aperture */
+ i = mga_inb(M_MISC_R);
+ mga_outb(M_MISC_W, i & ~2);
+
+ /* clear Z-buffer (if any) */
+ if (zbuffer) {
+ unsigned long ofs = zorg;
+ unsigned long len = zorg + __pixwidth * 2 * __zheight;
+
+ hwptr_select(mgaptr.linear_map);
+ for (; ofs<len; ofs+=4) {
+ hwptr_nspokel(mgaptr.linear_map, ofs, -1);
+ }
+ }
+
+ return 0;
+}
+
+
+
+/* Desc:
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+void mga_close (int restore, int unmap)
+{
+ if (restore) {
+ mga_mode_restore();
+ }
+ if (unmap) {
+ mga_hw_fini();
+ }
+}
+
+
+
+/* Desc: state retrieval
+ *
+ * In : parameter name, ptr to storage
+ * Out : 0 if request successfully processed
+ *
+ * Note: -
+ */
+int mga_get (int pname, int *params)
+{
+ switch (pname) {
+ case MGA_GET_CARD_NAME:
+ strcat(strcpy((char *)params, "Matrox "), card_name);
+ break;
+ case MGA_GET_VRAM:
+ params[0] = vram;
+ break;
+ case MGA_GET_CI_PREC:
+ params[0] = 0;
+ break;
+ case MGA_GET_HPIXELS:
+ params[0] = __pixwidth;
+ break;
+ case MGA_GET_SCREEN_SIZE:
+ params[0] = __width;
+ params[1] = __height;
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.4 for Mesa -- MGA2064W HW mapping
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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 0;
+
+ dirty = TRUE;
+ }
+#endif
+
+ /* find PCI device */
+ matrox_id = 0;
+
+ for (bus_id=0, i=0; matrox_id_list[i]; i++) {
+ if (pci_find_device(matrox_id_list[i], MATROX_VENDOR_ID, 0, &bus_id)) {
+ matrox_id = matrox_id_list[i];
+ break;
+ }
+ }
+
+ /* set up the card name */
+ switch (matrox_id) {
+ case MATROX_MILL_ID:
+ if (name) strcpy(name, "Millennium");
+ break;
+ default:
+ matrox_id = 0;
+ return -1;
+ }
+
+ reg40 = pci_read_long(bus_id, 0x40);
+#if 0 /* overclock a little :) */
+ {
+ int rfhcnt = (reg40 >> 16) & 0xF;
+ if ((reg40 & 0x200000) && (rfhcnt < 0xC)) {
+ pci_write_long(bus_id, 0x40, (reg40 & 0xFFF0FFFF) | 0x000C0000);
+ }
+ }
+#endif
+
+ /* read hardware configuration data */
+ for (i=0; i<2; i++)
+ pci_base[i] = pci_read_long(bus_id, 16+i*4);
+
+ /* work out the linear framebuffer and MMIO addresses */
+ if (matrox_id == MATROX_MILL_ID) {
+ if (pci_base[0])
+ io_mem_base[0] = pci_base[0] & 0xFFFFC000;
+
+ if (pci_base[1])
+ linear_base = pci_base[1] & 0xFF800000;
+ }
+
+ if (!linear_base || !io_mem_base[0])
+ return 0;
+
+ /* deal with the memory mapping crap */
+ io_mem_size[0] = 0x4000;
+
+ for (i=0; i<4; i++) {
+ if (io_mem_base[i]) {
+ if (_create_mmap(&mgaptr.io_mem_map[i], io_mem_base[i], io_mem_size[i])) {
+ mga_hw_fini();
+ return 0;
+ }
+ }
+ }
+
+ *vram = linear_size = _mga_get_vram(matrox_id, linear_base);
+
+ if (_create_mmap(&mgaptr.linear_map, linear_base, linear_size)) {
+ mga_hw_fini();
+ return 0;
+ }
+
+ /* fill in user data */
+ *interleave = linear_size > 2*1024*1024;
+
+ return matrox_id;
+}
+
+
+
+/* PCI routines added by SET */
+#define PCIAddr 0xCF8
+#define PCIData 0xCFC
+#define PCIEnable 0x80000000
+
+
+
+/* FindPCIDevice:
+ * Replacement for the INT 1A - PCI BIOS v2.0c+ - FIND PCI DEVICE, AX = B102h
+ *
+ * Note: deviceIndex is because a card can hold more than one PCI chip.
+ *
+ * Searches the board of the vendor supplied in vendorID with
+ * identification number deviceID and index deviceIndex (normally 0).
+ * The value returned in handle can be used to access the PCI registers
+ * of this board.
+ *
+ * Return: 1 if found 0 if not found.
+ */
+static int pci_find_device (int deviceID, int vendorID, int deviceIndex, int *handle)
+{
+ int model, vendor, card, device;
+ unsigned value, full_id, bus, busMax;
+
+ deviceIndex <<= 8;
+
+ /* for each PCI bus */
+ for (bus=0, busMax=0x10000; bus<busMax; bus+=0x10000) {
+
+ /* for each hardware device */
+ for (device=0, card=0; card<32; card++, device+=0x800) {
+ value = PCIEnable | bus | deviceIndex | device;
+ outportl(PCIAddr, value);
+ full_id = inportl(PCIData);
+
+ /* get the vendor and model ID */
+ vendor = full_id & 0xFFFF;
+ model = full_id >> 16;
+
+ if (vendor != 0xFFFF) {
+ /* is this the one we want? */
+ if ((deviceID == model) && (vendorID == vendor)) {
+ *handle = value;
+ return 1;
+ }
+
+ /* is it a bridge to a secondary bus? */
+ outportl(PCIAddr, value | 8);
+
+ if (((inportl(PCIData) >> 16) == 0x0600) || (full_id==0x00011011))
+ busMax += 0x10000;
+ }
+ }
+ }
+
+ return 0;
+}
+
+
+
+/* Desc:
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+static unsigned long pci_read_long (int handle, int index)
+{
+ outportl(PCIAddr, PCIEnable | handle | index);
+ return inportl(PCIData);
+}
+
+
+
+/* Desc:
+ *
+ * In :
+ * Out :
+ *
+ * Note:
+ */
+static void pci_write_long (int handle, int index, unsigned long value)
+{
+ outportl(PCIAddr, PCIEnable | handle | index);
+ outportl(PCIData, value);
+}
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W HW mapping
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W mode switching
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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;
+}
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W mode switching
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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
-/*\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 -- 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
+/*
+ * Mesa 3-D graphics library
+ * Version: 5.0
+ *
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa -- MGA2064W register mnemonics
+ *
+ * Copyright (c) 2003 - Borca Daniel
+ * Email : 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
-/*\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\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
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.1
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <dpmi.h>
+#include <pc.h>
+#include <stdlib.h>
+#include <stubinfo.h>
+#include <sys/exceptn.h>
+#include <sys/segments.h>
+#include <sys/farptr.h>
+#include <sys/movedata.h>
+
+#include "video.h"
+#include "vesa.h"
+
+
+
+static vl_mode modes[128];
+
+static word16 vesa_ver;
+static int banked_selector, linear_selector;
+static int oldmode = -1;
+
+static int vesa_color_precision = 6;
+
+static word16 *vesa_pmcode;
+unsigned int vesa_gran_mask, vesa_gran_shift;
+
+
+
+/*
+ * VESA info
+ */
+#define V_SIGN 0
+#define V_MINOR 4
+#define V_MAJOR 5
+#define V_OEM_OFS 6
+#define V_OEM_SEG 8
+#define V_MODE_OFS 14
+#define V_MODE_SEG 16
+#define V_MEMORY 18
+
+/*
+ * mode info
+ */
+#define M_ATTR 0
+#define M_GRAN 4
+#define M_SCANLEN 16
+#define M_XRES 18
+#define M_YRES 20
+#define M_BPP 25
+#define M_RED 31
+#define M_GREEN 33
+#define M_BLUE 35
+#define M_PHYS_PTR 40
+
+/*
+ * VESA 3.0 CRTC timings structure
+ */
+typedef struct CRTCInfoBlock {
+ unsigned short HorizontalTotal;
+ unsigned short HorizontalSyncStart;
+ unsigned short HorizontalSyncEnd;
+ unsigned short VerticalTotal;
+ unsigned short VerticalSyncStart;
+ unsigned short VerticalSyncEnd;
+ unsigned char Flags;
+ unsigned long PixelClock; /* units of Hz */
+ unsigned short RefreshRate; /* units of 0.01 Hz */
+ unsigned char reserved[40];
+} __PACKED__ CRTCInfoBlock;
+
+#define HNEG (1 << 2)
+#define VNEG (1 << 3)
+#define DOUBLESCAN (1 << 0)
+
+
+
+/* Desc: Attempts to detect VESA, check video modes and create selectors.
+ *
+ * In : -
+ * Out : mode array
+ *
+ * Note: -
+ */
+static vl_mode *vesa_init (void)
+{
+ __dpmi_regs r;
+ word16 *p;
+ vl_mode *q;
+ char vesa_info[512], tmp[512];
+ int maxsize = 0;
+ word32 linearfb = 0;
+
+ if (vesa_ver) {
+ return modes;
+ }
+
+ _farpokel(_stubinfo->ds_selector, 0, 0x32454256);
+ r.x.ax = 0x4f00;
+ r.x.di = 0;
+ r.x.es = _stubinfo->ds_segment;
+ __dpmi_int(0x10, &r);
+ movedata(_stubinfo->ds_selector, 0, _my_ds(), (unsigned)vesa_info, 512);
+ if ((r.x.ax!=0x004f) || ((_32_ vesa_info[V_SIGN])!=0x41534556)) {
+ return NULL;
+ }
+
+ p = (word16 *)(((_16_ vesa_info[V_MODE_SEG])<<4) + (_16_ vesa_info[V_MODE_OFS]));
+ q = modes;
+ do {
+ if ((q->mode=_farpeekw(__djgpp_dos_sel, (unsigned long)(p++)))==0xffff) {
+ break;
+ }
+
+ r.x.ax = 0x4f01;
+ r.x.cx = q->mode;
+ r.x.di = 512;
+ r.x.es = _stubinfo->ds_segment;
+ __dpmi_int(0x10, &r);
+ movedata(_stubinfo->ds_selector, 512, _my_ds(), (unsigned)tmp, 256);
+ switch (tmp[M_BPP]) {
+ case 16:
+ q->bpp = tmp[M_RED] + tmp[M_GREEN] + tmp[M_BLUE];
+ break;
+ case 8:
+ case 15:
+ case 24:
+ case 32:
+ q->bpp = tmp[M_BPP];
+ break;
+ default:
+ q->bpp = 0;
+ }
+ if ((r.x.ax==0x004f) && ((tmp[M_ATTR]&0x11)==0x11) && q->bpp) {
+ q->xres = _16_ tmp[M_XRES];
+ q->yres = _16_ tmp[M_YRES];
+ q->scanlen = _16_ tmp[M_SCANLEN];
+ q->gran = (_16_ tmp[M_GRAN])<<10;
+ if (tmp[M_ATTR]&0x80) {
+#if 0
+ *(q+1) = *q++;
+#else
+ vl_mode *q1 = q + 1;
+ *q1 = *q++;
+#endif
+ linearfb = _32_ tmp[M_PHYS_PTR];
+ q->mode |= 0x4000;
+ }
+ if (maxsize<(q->scanlen*q->yres)) {
+ maxsize = q->scanlen*q->yres;
+ }
+ q++;
+ }
+ } while (TRUE);
+
+ if (q==modes) {
+ return NULL;
+ }
+ if (linearfb) {
+ maxsize = ((maxsize+0xfffUL)&~0xfffUL);
+ if (_create_selector(&linear_selector, linearfb, maxsize)) {
+ return NULL;
+ }
+ }
+ if (_create_selector(&banked_selector, 0xa0000, modes[0].gran)) {
+ _remove_selector(&linear_selector);
+ return NULL;
+ }
+
+ for (q=modes; q->mode!=0xffff; q++) {
+ q->sel = (q->mode&0x4000) ? linear_selector : banked_selector;
+ }
+
+ if (vesa_info[V_MAJOR] >= 2) {
+ r.x.ax = 0x4f0a;
+ r.x.bx = 0;
+ __dpmi_int(0x10, &r);
+ if (r.x.ax == 0x004f) {
+ vesa_pmcode = (word16 *)malloc(r.x.cx);
+ movedata(__djgpp_dos_sel, (r.x.es << 4) + r.x.di, _my_ds(), (unsigned)vesa_pmcode, r.x.cx);
+ if (vesa_pmcode[3]) {
+ p = (word16 *)((long)vesa_pmcode + vesa_pmcode[3]);
+ while (*p++ != 0xffff) ;
+ } else {
+ p = NULL;
+ }
+ if (p && (*p != 0xffff)) {
+ free(vesa_pmcode);
+ vesa_pmcode = NULL;
+ } else {
+ vesa_swbank = (void *)((long)vesa_pmcode + vesa_pmcode[0]);
+ }
+ }
+ }
+
+ vesa_ver = _16_ vesa_info[V_MINOR];
+ return modes;
+}
+
+
+
+/* Desc: Frees all resources allocated by VESA init code.
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: -
+ */
+static void vesa_fini (void)
+{
+ if (vesa_ver) {
+ _remove_selector(&linear_selector);
+ _remove_selector(&banked_selector);
+ if (vesa_pmcode != NULL) {
+ free(vesa_pmcode);
+ vesa_pmcode = NULL;
+ }
+ }
+}
+
+
+
+/* Desc: Uses VESA 3.0 function 0x4F0B to find the closest pixel clock to the requested value.
+ *
+ * In : mode, clock
+ * Out : desired clock
+ *
+ * Note: -
+ */
+static unsigned long _closest_pixclk (int mode_no, unsigned long vclk)
+{
+ __dpmi_regs r;
+
+ r.x.ax = 0x4F0B;
+ r.h.bl = 0;
+ r.d.ecx = vclk;
+ r.x.dx = mode_no;
+ __dpmi_int(0x10, &r);
+
+ return (r.x.ax==0x004f) ? r.d.ecx : 0;
+}
+
+
+
+/* Desc: Calculates CRTC mode timings.
+ *
+ * In : crtc block, geometry, adjust
+ * Out :
+ *
+ * Note:
+ */
+static void _crtc_timing (CRTCInfoBlock *crtc, int xres, int yres, int xadjust, int yadjust)
+{
+ int HTotal, VTotal;
+ int HDisp, VDisp;
+ int HSS, VSS;
+ int HSE, VSE;
+ int HSWidth, VSWidth;
+ int SS, SE;
+ int doublescan = FALSE;
+
+ if (yres < 400) {
+ doublescan = TRUE;
+ yres *= 2;
+ }
+
+ HDisp = xres;
+ HTotal = (int)(HDisp * 1.27) & ~0x7;
+ HSWidth = (int)((HTotal - HDisp) / 5) & ~0x7;
+ HSS = HDisp + 16;
+ HSE = HSS + HSWidth;
+ VDisp = yres;
+ VTotal = VDisp * 1.07;
+ VSWidth = (VTotal / 100) + 1;
+ VSS = VDisp + ((int)(VTotal - VDisp) / 5) + 1;
+ VSE = VSS + VSWidth;
+
+ SS = HSS + xadjust;
+ SE = HSE + xadjust;
+
+ if (xadjust < 0) {
+ if (SS < (HDisp + 8)) {
+ SS = HDisp + 8;
+ SE = SS + HSWidth;
+ }
+ } else {
+ if ((HTotal - 24) < SE) {
+ SE = HTotal - 24;
+ SS = SE - HSWidth;
+ }
+ }
+
+ HSS = SS;
+ HSE = SE;
+
+ SS = VSS + yadjust;
+ SE = VSE + yadjust;
+
+ if (yadjust < 0) {
+ if (SS < (VDisp + 3)) {
+ SS = VDisp + 3;
+ SE = SS + VSWidth;
+ }
+ } else {
+ if ((VTotal - 4) < SE) {
+ SE = VTotal - 4;
+ SS = SE - VSWidth;
+ }
+ }
+
+ VSS = SS;
+ VSE = SE;
+
+ crtc->HorizontalTotal = HTotal;
+ crtc->HorizontalSyncStart = HSS;
+ crtc->HorizontalSyncEnd = HSE;
+ crtc->VerticalTotal = VTotal;
+ crtc->VerticalSyncStart = VSS;
+ crtc->VerticalSyncEnd = VSE;
+ crtc->Flags = HNEG | VNEG;
+
+ if (doublescan)
+ crtc->Flags |= DOUBLESCAN;
+}
+
+
+
+/* Desc: Attempts to enter specified video mode.
+ *
+ * In : ptr to mode structure, refresh rate
+ * Out : 0 if success
+ *
+ * Note: -
+ */
+static int vesa_entermode (vl_mode *p, int refresh)
+{
+ __dpmi_regs r;
+
+ if (p->mode & 0x4000) {
+ VESA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
+ } else {
+ VESA.blit = vesa_b_dump_virtual;
+ { int n; for (vesa_gran_shift=0, n=p->gran; n; vesa_gran_shift++, n>>=1) ; }
+ vesa_gran_mask = (1<<(--vesa_gran_shift)) - 1;
+ if ((unsigned)p->gran != (vesa_gran_mask+1)) {
+ return !0;
+ }
+ }
+
+ if (oldmode == -1) {
+ r.x.ax = 0x4f03;
+ __dpmi_int(0x10, &r);
+ oldmode = r.x.bx;
+ }
+
+ r.x.ax = 0x4f02;
+ r.x.bx = p->mode;
+
+ if (refresh && ((vesa_ver>>8) >= 3)) {
+ /* VESA 3.0 stuff for controlling the refresh rate */
+ CRTCInfoBlock crtc;
+ unsigned long vclk;
+ double f0;
+
+ _crtc_timing(&crtc, p->xres, p->yres, 0, 0);
+
+ vclk = (double)crtc.HorizontalTotal * crtc.VerticalTotal * refresh;
+ vclk = _closest_pixclk(p->mode, vclk);
+
+ if (vclk != 0) {
+ f0 = (double)vclk / (crtc.HorizontalTotal * crtc.VerticalTotal);
+ /*_current_refresh_rate = (int)(f0 + 0.5);*/
+
+ crtc.PixelClock = vclk;
+ crtc.RefreshRate = refresh * 100;
+
+ movedata(_my_ds(), (unsigned)&crtc, _stubinfo->ds_selector, 0, sizeof(crtc));
+
+ r.x.di = 0;
+ r.x.es = _stubinfo->ds_segment;
+ r.x.bx |= 0x0800;
+ }
+ }
+
+ __dpmi_int(0x10, &r);
+ if (r.x.ax != 0x004f) {
+ return !0;
+ }
+
+ if (p->bpp == 8) {
+ r.x.ax = 0x4f08;
+ r.x.bx = 0x0800;
+ __dpmi_int(0x10, &r);
+ if (r.x.ax == 0x004f) {
+ r.x.ax = 0x4f08;
+ r.h.bl = 0x01;
+ __dpmi_int(0x10, &r);
+ vesa_color_precision = r.h.bh;
+ }
+ }
+
+ return 0;
+}
+
+
+
+/* Desc: Restores to the mode prior to first call to vesa_entermode.
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: -
+ */
+static void vesa_restore (void)
+{
+ __dpmi_regs r;
+
+ if (oldmode != -1) {
+ r.x.ax = 0x4f02;
+ r.x.bx = oldmode;
+ __dpmi_int(0x10, &r);
+ }
+}
+
+
+
+/* Desc: set one palette entry
+ *
+ * In : color index, R, G, B
+ * Out : -
+ *
+ * Note: uses integer values
+ */
+static void vesa_setCI_i (int index, int red, int green, int blue)
+{
+#if 0
+ __asm("\n\
+ movw $0x1010, %%ax \n\
+ movb %1, %%dh \n\
+ movb %2, %%ch \n\
+ int $0x10 \n\
+ "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");
+#else
+ outportb(0x03C8, index);
+ outportb(0x03C9, red);
+ outportb(0x03C9, green);
+ outportb(0x03C9, blue);
+#endif
+}
+
+
+
+/* Desc: set one palette entry
+ *
+ * In : color index, R, G, B
+ * Out : -
+ *
+ * Note: uses normalized values
+ */
+static void vesa_setCI_f (int index, float red, float green, float blue)
+{
+ float max = (1 << vesa_color_precision) - 1;
+
+ vesa_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));
+}
+
+
+
+/* Desc: state retrieval
+ *
+ * In : parameter name, ptr to storage
+ * Out : 0 if request successfully processed
+ *
+ * Note: -
+ */
+static int vesa_get (int pname, int *params)
+{
+ switch (pname) {
+ case VL_GET_CI_PREC:
+ params[0] = vesa_color_precision;
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+
+
+/*
+ * the driver
+ */
+vl_driver VESA = {
+ vesa_init,
+ vesa_entermode,
+ NULL,
+ vesa_setCI_f,
+ vesa_setCI_i,
+ vesa_get,
+ vesa_restore,
+ vesa_fini
+};
-/*\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\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
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef VESA_H_included
+#define VESA_H_included
+
+#include "internal.h"
+
+extern void *vesa_swbank;
+
+extern void vesa_b_dump_virtual (void);
+extern void vesa_l_dump_virtual (void);
+extern void vesa_l_dump_virtual_mmx (void);
+
+extern vl_driver VESA;
+
+#endif
-/*\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\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
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.1
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#include <pc.h>
+#include <stdlib.h>
+
+#include "video.h"
+#include "vga.h"
+
+
+
+static vl_mode modes[] = {
+ {0x13 | 0x4000, 320, 200, 320, 8, -1, 320*200},
+ {0xffff, -1, -1, -1, -1, -1, -1}
+};
+
+static word16 vga_ver;
+static int linear_selector;
+static int oldmode = -1;
+
+#define vga_color_precision 6
+
+
+
+/* Desc: Attempts to detect VGA, check video modes and create selectors.
+ *
+ * In : -
+ * Out : mode array
+ *
+ * Note: -
+ */
+static vl_mode *vga_init (void)
+{
+ int rv = 0;
+
+ if (vga_ver) {
+ return modes;
+ }
+
+ __asm("\n\
+ movw $0x1a00, %%ax \n\
+ int $0x10 \n\
+ cmpb $0x1a, %%al \n\
+ jne 0f \n\
+ cmpb $0x07, %%bl \n\
+ jb 0f \n\
+ andl $0xff, %%ebx \n\
+ movl %%ebx, %0 \n\
+ 0:":"=g"(rv)::"%eax", "%ebx");
+ if (rv == 0) {
+ return NULL;
+ }
+
+ if (_create_selector(&linear_selector, 0xa0000, 0x10000)) {
+ return NULL;
+ }
+
+ modes[0].sel = linear_selector;
+
+ vga_ver = rv;
+ return modes;
+}
+
+
+
+/* Desc: Frees all resources allocated by VGA init code.
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: -
+ */
+static void vga_fini (void)
+{
+ if (vga_ver) {
+ _remove_selector(&linear_selector);
+ }
+}
+
+
+
+/* Desc: Attempts to enter specified video mode.
+ *
+ * In : ptr to mode structure, refresh rate
+ * Out : 0 if success
+ *
+ * Note: -
+ */
+static int vga_entermode (vl_mode *p, int refresh)
+{
+ if (!(p->mode & 0x4000)) {
+ return -1;
+ }
+ VGA.blit = _can_mmx() ? vesa_l_dump_virtual_mmx : vesa_l_dump_virtual;
+
+ if (oldmode == -1) {
+ __asm("\n\
+ movb $0x0f, %%ah \n\
+ int $0x10 \n\
+ andl $0xff, %%eax \n\
+ movl %%eax, %0 \n\
+ ":"=g"(oldmode)::"%eax", "%ebx");
+ }
+
+ __asm("int $0x10"::"a"(p->mode&0xff));
+
+ return 0;
+
+ (void)refresh; /* silence compiler warning */
+}
+
+
+
+/* Desc: Restores to the mode prior to first call to vga_entermode.
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: -
+ */
+static void vga_restore (void)
+{
+ if (oldmode != -1) {
+ __asm("int $0x10"::"a"(oldmode));
+ }
+}
+
+
+
+/* Desc: set one palette entry
+ *
+ * In : color index, R, G, B
+ * Out : -
+ *
+ * Note: uses integer values
+ */
+static void vga_setCI_i (int index, int red, int green, int blue)
+{
+#if 0
+ __asm("\n\
+ movw $0x1010, %%ax \n\
+ movb %1, %%dh \n\
+ movb %2, %%ch \n\
+ int $0x10 \n\
+ "::"b"(index), "m"(red), "m"(green), "c"(blue):"%eax", "%edx");
+#else
+ outportb(0x03C8, index);
+ outportb(0x03C9, red);
+ outportb(0x03C9, green);
+ outportb(0x03C9, blue);
+#endif
+}
+
+
+
+/* Desc: set one palette entry
+ *
+ * In : color index, R, G, B
+ * Out : -
+ *
+ * Note: uses normalized values
+ */
+static void vga_setCI_f (int index, float red, float green, float blue)
+{
+ float max = (1 << vga_color_precision) - 1;
+
+ vga_setCI_i(index, (int)(red * max), (int)(green * max), (int)(blue * max));
+}
+
+
+
+/* Desc: state retrieval
+ *
+ * In : parameter name, ptr to storage
+ * Out : 0 if request successfully processed
+ *
+ * Note: -
+ */
+static int vga_get (int pname, int *params)
+{
+ switch (pname) {
+ case VL_GET_CI_PREC:
+ params[0] = vga_color_precision;
+ break;
+ default:
+ return -1;
+ }
+ return 0;
+}
+
+
+
+/*
+ * the driver
+ */
+vl_driver VGA = {
+ vga_init,
+ vga_entermode,
+ NULL,
+ vga_setCI_f,
+ vga_setCI_i,
+ vga_get,
+ vga_restore,
+ vga_fini
+};
-/*\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\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
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef VGA_H_included
+#define VGA_H_included
+
+#include "internal.h"
+#include "vesa.h"
+
+extern vl_driver VGA;
+
+#endif
-/*\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\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- *\r
- * Thanks to CrazyPyro (Neil Funk) for FakeColor\r
- */\r
-\r
-\r
-#include <stdlib.h>\r
-\r
-#include "internal.h"\r
-#include "vesa.h"\r
-#include "vga.h"\r
-#include "video.h"\r
-\r
-\r
-\r
-static vl_driver *drv;\r
-/* based upon mode specific data: valid entire session */\r
-int vl_video_selector;\r
-static vl_mode *video_mode;\r
-static int video_scanlen, video_bypp;\r
-/* valid until next buffer */\r
-void *vl_current_draw_buffer, *vl_current_read_buffer;\r
-int vl_current_stride, vl_current_width, vl_current_height, vl_current_bytes;\r
-int vl_current_offset, vl_current_delta;\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, 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
-/* FakeColor data */\r
-#define R_CNT 6\r
-#define G_CNT 6\r
-#define B_CNT 6\r
-\r
-#define R_BIAS 7\r
-#define G_BIAS 7\r
-#define B_BIAS 7\r
-\r
-static word32 VGAPalette[256];\r
-static word8 array_r[256];\r
-static word8 array_g[256];\r
-static word8 array_b[256];\r
-\r
-\r
-\r
-int (*vl_mixfix) (fixed r, fixed g, fixed b);\r
-int (*vl_mixrgb) (const unsigned char rgb[]);\r
-int (*vl_mixrgba) (const unsigned char rgba[]);\r
-void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]);\r
-int (*vl_getpixel) (unsigned int offset);\r
-void (*vl_clear) (int color);\r
-void (*vl_rect) (int x, int y, int width, int height, int color);\r
-void (*vl_flip) (void);\r
-void (*vl_putpixel) (unsigned int offset, int color);\r
-\r
-\r
-\r
-/* Desc: color composition (w/o ALPHA)\r
- *\r
- * In : R, G, B\r
- * Out : color\r
- *\r
- * Note: -\r
- */\r
-static int vl_mixfix8fake (fixed r, fixed g, fixed b)\r
-{\r
- return array_b[b>>FIXED_SHIFT]*G_CNT*R_CNT\r
- + array_g[g>>FIXED_SHIFT]*R_CNT\r
- + array_r[r>>FIXED_SHIFT];\r
-}\r
-#define vl_mixfix8 vl_mixfix8fake\r
-static int vl_mixfix15 (fixed r, fixed g, fixed b)\r
-{\r
- return ((r>>(3+FIXED_SHIFT))<<10)\r
- |((g>>(3+FIXED_SHIFT))<<5)\r
- |(b>>(3+FIXED_SHIFT));\r
-}\r
-static int vl_mixfix16 (fixed r, fixed g, fixed b)\r
-{\r
- return ((r>>(3+FIXED_SHIFT))<<11)\r
- |((g>>(2+FIXED_SHIFT))<<5)\r
- |(b>>(3+FIXED_SHIFT));\r
-}\r
-#define vl_mixfix24 vl_mixfix32\r
-static int vl_mixfix32 (fixed r, fixed g, fixed b)\r
-{\r
- return ((r>>FIXED_SHIFT)<<16)\r
- |((g>>FIXED_SHIFT)<<8)\r
- |(b>>FIXED_SHIFT);\r
-}\r
-\r
-\r
-\r
-/* Desc: color composition (w/ ALPHA)\r
- *\r
- * In : array of integers (R, G, B, A)\r
- * Out : color\r
- *\r
- * Note: -\r
- */\r
-#define vl_mixrgba8 vl_mixrgb8fake\r
-#define vl_mixrgba15 vl_mixrgb15\r
-#define vl_mixrgba16 vl_mixrgb16\r
-#define vl_mixrgba24 vl_mixrgb24\r
-static int vl_mixrgba32 (const unsigned char rgba[])\r
-{\r
- return (rgba[3]<<24)|(rgba[0]<<16)|(rgba[1]<<8)|(rgba[2]);\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 int vl_mixrgb8fake (const unsigned char rgba[])\r
-{\r
- return array_b[rgba[2]]*G_CNT*R_CNT\r
- + array_g[rgba[1]]*R_CNT\r
- + array_r[rgba[0]];\r
-}\r
-#define vl_mixrgb8 vl_mixrgb8fake\r
-static int vl_mixrgb15 (const unsigned char rgb[])\r
-{\r
- return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3);\r
-}\r
-static int vl_mixrgb16 (const unsigned char rgb[])\r
-{\r
- return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3);\r
-}\r
-#define vl_mixrgb24 vl_mixrgb32\r
-static int vl_mixrgb32 (const unsigned char rgb[])\r
-{\r
- return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);\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 v_getrgba8fake6 (unsigned int offset, unsigned char rgba[])\r
-{\r
- word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]];\r
- rgba[0] = _rgb_scale_6[(c >> 16) & 0x3F];\r
- rgba[1] = _rgb_scale_6[(c >> 8) & 0x3F];\r
- rgba[2] = _rgb_scale_6[c & 0x3F];\r
- rgba[3] = c >> 24;\r
-}\r
-static void v_getrgba8fake8 (unsigned int offset, unsigned char rgba[])\r
-{\r
- word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]];\r
- rgba[0] = c >> 16;\r
- rgba[1] = c >> 8;\r
- rgba[2] = c;\r
- rgba[3] = c >> 24;\r
-}\r
-#define v_getrgba8 v_getrgba8fake6\r
-static void v_getrgba15 (unsigned int offset, unsigned char rgba[4])\r
-{\r
- word32 c = ((word16 *)vl_current_read_buffer)[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 v_getrgba16 (unsigned int offset, unsigned char rgba[4])\r
-{\r
- word32 c = ((word16 *)vl_current_read_buffer)[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 v_getrgba24 (unsigned int offset, unsigned char rgba[4])\r
-{\r
- word32 c = *(word32 *)((long)vl_current_read_buffer+offset*3);\r
- rgba[0] = c >> 16;\r
- rgba[1] = c >> 8;\r
- rgba[2] = c;\r
- rgba[3] = 255;\r
-}\r
-static void v_getrgba32 (unsigned int offset, unsigned char rgba[4])\r
-{\r
- word32 c = ((word32 *)vl_current_read_buffer)[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: pixel retrieval\r
- *\r
- * In : pixel offset\r
- * Out : pixel value\r
- *\r
- * Note: uses current read buffer\r
- */\r
-static int v_getpixel8 (unsigned int offset)\r
-{\r
- return ((word8 *)vl_current_read_buffer)[offset];\r
-}\r
-#define v_getpixel15 v_getpixel16\r
-static int v_getpixel16 (unsigned int offset)\r
-{\r
- return ((word16 *)vl_current_read_buffer)[offset];\r
-}\r
-static int v_getpixel24 (unsigned int offset)\r
-{\r
- return *(word32 *)((long)vl_current_read_buffer+offset*3);\r
-}\r
-static int v_getpixel32 (unsigned int offset)\r
-{\r
- return ((word32 *)vl_current_read_buffer)[offset];\r
-}\r
-\r
-\r
-\r
-/* Desc: set one palette entry\r
- *\r
- * In : index, R, G, B\r
- * Out : -\r
- *\r
- * Note: color components are in range [0.0 .. 1.0]\r
- */\r
-void vl_setCI (int index, float red, float green, float blue)\r
-{\r
- drv->setCI_f(index, red, green, blue);\r
-}\r
-\r
-\r
-\r
-/* Desc: set one palette entry\r
- *\r
- * In : color, R, G, B\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-static void fake_setcolor (int c, int r, int g, int b)\r
-{\r
- VGAPalette[c] = 0xff000000 | (r<<16) | (g<<8) | b;\r
-\r
- drv->setCI_i(c, r, g, b);\r
-}\r
-\r
-\r
-\r
-/* Desc: build FakeColor palette\r
- *\r
- * In : CI precision in bits\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-static void fake_buildpalette (int bits)\r
-{\r
- double c_r, c_g, c_b;\r
- int r, g, b, color = 0;\r
-\r
- double max = (1 << bits) - 1;\r
-\r
- for (b=0; b<B_CNT; ++b) {\r
- for (g=0; g<G_CNT; ++g) {\r
- for (r=0; r<R_CNT; ++r) {\r
- c_r = 0.5 + (double)r*(max-R_BIAS)/(R_CNT-1.) + R_BIAS;\r
- c_g = 0.5 + (double)g*(max-G_BIAS)/(G_CNT-1.) + G_BIAS;\r
- c_b = 0.5 + (double)b*(max-B_BIAS)/(B_CNT-1.) + B_BIAS;\r
- fake_setcolor(color++, (int)c_r, (int)c_g, (int)c_b);\r
- }\r
- }\r
- }\r
-\r
- for (color=0; color<256; color++) {\r
- c_r = (double)color*R_CNT/256.;\r
- c_g = (double)color*G_CNT/256.;\r
- c_b = (double)color*B_CNT/256.;\r
- array_r[color] = (int)c_r;\r
- array_g[color] = (int)c_g;\r
- array_b[color] = (int)c_b;\r
- }\r
-}\r
-\r
-\r
-\r
-/* Desc: sync buffer with video hardware\r
- *\r
- * In : ptr to old buffer, position, size\r
- * Out : 0 if success\r
- *\r
- * Note: -\r
- */\r
-int vl_sync_buffer (void **buffer, int x, int y, int width, int height)\r
-{\r
- if ((width & 7) || (x < 0) || (y < 0) || (x+width > video_mode->xres) || (y+height > video_mode->yres)) {\r
- return -1;\r
- } else {\r
- void *newbuf = *buffer;\r
-\r
- if ((newbuf == NULL) || (vl_current_width != width) || (vl_current_height != height)) {\r
- newbuf = realloc(newbuf, width * height * video_bypp);\r
- }\r
-\r
- if (newbuf == NULL) {\r
- return -2;\r
- }\r
-\r
- vl_current_width = width;\r
- vl_current_height = height;\r
- vl_current_stride = vl_current_width * video_bypp;\r
- vl_current_bytes = vl_current_stride * height;\r
-\r
- vl_current_offset = video_scanlen * y + video_bypp * x;\r
- vl_current_delta = video_scanlen - vl_current_stride;\r
-\r
- vl_current_draw_buffer = vl_current_read_buffer = *buffer = newbuf;\r
- return 0;\r
- }\r
-}\r
-\r
-\r
-\r
-/* Desc: state retrieval\r
- *\r
- * In : name, storage\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-int vl_get (int pname, int *params)\r
-{\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
-}\r
-\r
-\r
-\r
-/* Desc: setup mode\r
- *\r
- * In : ptr to mode definition\r
- * Out : 0 if success\r
- *\r
- * Note: -\r
- */\r
-static int vl_setup_mode (vl_mode *p)\r
-{\r
- if (p == NULL) {\r
- return -1;\r
- }\r
-\r
-#define INITPTR(bpp) \\r
- vl_putpixel = v_putpixel##bpp; \\r
- vl_getrgba = v_getrgba##bpp; \\r
- vl_getpixel = v_getpixel##bpp; \\r
- vl_rect = v_rect##bpp; \\r
- vl_mixfix = vl_mixfix##bpp; \\r
- vl_mixrgb = vl_mixrgb##bpp; \\r
- vl_mixrgba = vl_mixrgba##bpp; \\r
- vl_clear = _can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp\r
- \r
- switch (p->bpp) {\r
- case 8:\r
- INITPTR(8);\r
- break;\r
- case 15:\r
- INITPTR(15);\r
- break;\r
- case 16:\r
- INITPTR(16);\r
- break;\r
- case 24:\r
- INITPTR(24);\r
- break;\r
- case 32:\r
- INITPTR(32);\r
- break;\r
- default:\r
- return -1;\r
- }\r
-\r
-#undef INITPTR\r
-\r
- video_mode = p;\r
- video_bypp = (p->bpp+7)/8;\r
- video_scanlen = p->scanlen;\r
- vl_video_selector = p->sel;\r
-\r
- return 0;\r
-}\r
-\r
-\r
-\r
-/* Desc: restore to the mode prior to first call to `vl_video_init'.\r
- *\r
- * In : -\r
- * Out : -\r
- *\r
- * Note: -\r
- */\r
-void vl_video_exit (void)\r
-{\r
- drv->restore();\r
- drv->fini();\r
-}\r
-\r
-\r
-\r
-/* Desc: enter mode\r
- *\r
- * In : xres, yres, bits/pixel, RGB, refresh rate\r
- * Out : pixel width in bits if success\r
- *\r
- * Note: -\r
- */\r
-int vl_video_init (int width, int height, int bpp, int rgb, int refresh)\r
-{\r
- int fake;\r
- vl_mode *p, *q;\r
- unsigned int min;\r
-\r
- fake = 0;\r
- if (!rgb) {\r
- bpp = 8;\r
- } else if (bpp == 8) {\r
- fake = 1;\r
- }\r
-\r
- /* initialize hardware */\r
- drv = &VESA;\r
- if ((q=drv->init()) == NULL) {\r
- drv = &VGA;\r
- if ((q=drv->init()) == NULL) {\r
- return 0;\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
- /* setup and enter mode */\r
- if ((vl_setup_mode(p) == 0) && (drv->entermode(p, refresh) == 0)) {\r
- vl_flip = drv->blit;\r
- if (fake) {\r
- drv->get(VL_GET_CI_PREC, (int *)(&min));\r
- fake_buildpalette(min);\r
- if (min == 8) {\r
- vl_getrgba = v_getrgba8fake8;\r
- }\r
- }\r
- return bpp;\r
- }\r
-\r
- /* abort */\r
- return 0;\r
-}\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ *
+ * Thanks to CrazyPyro (Neil Funk) for FakeColor
+ */
+
+
+#include <stdlib.h>
+
+#include "internal.h"
+#include "vesa.h"
+#include "vga.h"
+#include "video.h"
+
+
+
+static vl_driver *drv;
+/* based upon mode specific data: valid entire session */
+int vl_video_selector;
+static vl_mode *video_mode;
+static int video_scanlen, video_bypp;
+/* valid until next buffer */
+void *vl_current_draw_buffer, *vl_current_read_buffer;
+int vl_current_stride, vl_current_width, vl_current_height, vl_current_bytes;
+int vl_current_offset, vl_current_delta;
+
+
+
+/* lookup table for scaling 5 bit colors up to 8 bits */
+static int _rgb_scale_5[32] = {
+ 0, 8, 16, 25, 33, 41, 49, 58,
+ 66, 74, 82, 90, 99, 107, 115, 123,
+ 132, 140, 148, 156, 165, 173, 181, 189,
+ 197, 206, 214, 222, 230, 239, 247, 255
+};
+
+/* lookup table for scaling 6 bit colors up to 8 bits */
+static int _rgb_scale_6[64] = {
+ 0, 4, 8, 12, 16, 20, 24, 28,
+ 32, 36, 40, 45, 49, 53, 57, 61,
+ 65, 69, 73, 77, 81, 85, 89, 93,
+ 97, 101, 105, 109, 113, 117, 121, 125,
+ 130, 134, 138, 142, 146, 150, 154, 158,
+ 162, 166, 170, 174, 178, 182, 186, 190,
+ 194, 198, 202, 206, 210, 215, 219, 223,
+ 227, 231, 235, 239, 243, 247, 251, 255
+};
+
+/* FakeColor data */
+#define R_CNT 6
+#define G_CNT 6
+#define B_CNT 6
+
+#define R_BIAS 7
+#define G_BIAS 7
+#define B_BIAS 7
+
+static word32 VGAPalette[256];
+static word8 array_r[256];
+static word8 array_g[256];
+static word8 array_b[256];
+
+
+
+int (*vl_mixfix) (fixed r, fixed g, fixed b);
+int (*vl_mixrgb) (const unsigned char rgb[]);
+int (*vl_mixrgba) (const unsigned char rgba[]);
+void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]);
+int (*vl_getpixel) (unsigned int offset);
+void (*vl_clear) (int color);
+void (*vl_rect) (int x, int y, int width, int height, int color);
+void (*vl_flip) (void);
+void (*vl_putpixel) (unsigned int offset, int color);
+
+
+
+/* Desc: color composition (w/o ALPHA)
+ *
+ * In : R, G, B
+ * Out : color
+ *
+ * Note: -
+ */
+static int vl_mixfix8fake (fixed r, fixed g, fixed b)
+{
+ return array_b[b>>FIXED_SHIFT]*G_CNT*R_CNT
+ + array_g[g>>FIXED_SHIFT]*R_CNT
+ + array_r[r>>FIXED_SHIFT];
+}
+#define vl_mixfix8 vl_mixfix8fake
+static int vl_mixfix15 (fixed r, fixed g, fixed b)
+{
+ return ((r>>(3+FIXED_SHIFT))<<10)
+ |((g>>(3+FIXED_SHIFT))<<5)
+ |(b>>(3+FIXED_SHIFT));
+}
+static int vl_mixfix16 (fixed r, fixed g, fixed b)
+{
+ return ((r>>(3+FIXED_SHIFT))<<11)
+ |((g>>(2+FIXED_SHIFT))<<5)
+ |(b>>(3+FIXED_SHIFT));
+}
+#define vl_mixfix24 vl_mixfix32
+static int vl_mixfix32 (fixed r, fixed g, fixed b)
+{
+ return ((r>>FIXED_SHIFT)<<16)
+ |((g>>FIXED_SHIFT)<<8)
+ |(b>>FIXED_SHIFT);
+}
+
+
+
+/* Desc: color composition (w/ ALPHA)
+ *
+ * In : array of integers (R, G, B, A)
+ * Out : color
+ *
+ * Note: -
+ */
+#define vl_mixrgba8 vl_mixrgb8fake
+#define vl_mixrgba15 vl_mixrgb15
+#define vl_mixrgba16 vl_mixrgb16
+#define vl_mixrgba24 vl_mixrgb24
+static int vl_mixrgba32 (const unsigned char rgba[])
+{
+ return (rgba[3]<<24)|(rgba[0]<<16)|(rgba[1]<<8)|(rgba[2]);
+}
+
+
+
+/* Desc: color composition (w/o ALPHA)
+ *
+ * In : array of integers (R, G, B)
+ * Out : color
+ *
+ * Note: -
+ */
+static int vl_mixrgb8fake (const unsigned char rgba[])
+{
+ return array_b[rgba[2]]*G_CNT*R_CNT
+ + array_g[rgba[1]]*R_CNT
+ + array_r[rgba[0]];
+}
+#define vl_mixrgb8 vl_mixrgb8fake
+static int vl_mixrgb15 (const unsigned char rgb[])
+{
+ return ((rgb[0]>>3)<<10)|((rgb[1]>>3)<<5)|(rgb[2]>>3);
+}
+static int vl_mixrgb16 (const unsigned char rgb[])
+{
+ return ((rgb[0]>>3)<<11)|((rgb[1]>>2)<<5)|(rgb[2]>>3);
+}
+#define vl_mixrgb24 vl_mixrgb32
+static int vl_mixrgb32 (const unsigned char rgb[])
+{
+ return (rgb[0]<<16)|(rgb[1]<<8)|(rgb[2]);
+}
+
+
+
+/* Desc: color decomposition
+ *
+ * In : pixel offset, array of integers to hold color components (R, G, B, A)
+ * Out : -
+ *
+ * Note: uses current read buffer
+ */
+static void v_getrgba8fake6 (unsigned int offset, unsigned char rgba[])
+{
+ word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]];
+ rgba[0] = _rgb_scale_6[(c >> 16) & 0x3F];
+ rgba[1] = _rgb_scale_6[(c >> 8) & 0x3F];
+ rgba[2] = _rgb_scale_6[c & 0x3F];
+ rgba[3] = c >> 24;
+}
+static void v_getrgba8fake8 (unsigned int offset, unsigned char rgba[])
+{
+ word32 c = VGAPalette[((word8 *)vl_current_read_buffer)[offset]];
+ rgba[0] = c >> 16;
+ rgba[1] = c >> 8;
+ rgba[2] = c;
+ rgba[3] = c >> 24;
+}
+#define v_getrgba8 v_getrgba8fake6
+static void v_getrgba15 (unsigned int offset, unsigned char rgba[4])
+{
+ word32 c = ((word16 *)vl_current_read_buffer)[offset];
+ rgba[0] = _rgb_scale_5[(c >> 10) & 0x1F];
+ rgba[1] = _rgb_scale_5[(c >> 5) & 0x1F];
+ rgba[2] = _rgb_scale_5[c & 0x1F];
+ rgba[3] = 255;
+}
+static void v_getrgba16 (unsigned int offset, unsigned char rgba[4])
+{
+ word32 c = ((word16 *)vl_current_read_buffer)[offset];
+ rgba[0] = _rgb_scale_5[(c >> 11) & 0x1F];
+ rgba[1] = _rgb_scale_6[(c >> 5) & 0x3F];
+ rgba[2] = _rgb_scale_5[c & 0x1F];
+ rgba[3] = 255;
+}
+static void v_getrgba24 (unsigned int offset, unsigned char rgba[4])
+{
+ word32 c = *(word32 *)((long)vl_current_read_buffer+offset*3);
+ rgba[0] = c >> 16;
+ rgba[1] = c >> 8;
+ rgba[2] = c;
+ rgba[3] = 255;
+}
+static void v_getrgba32 (unsigned int offset, unsigned char rgba[4])
+{
+ word32 c = ((word32 *)vl_current_read_buffer)[offset];
+ rgba[0] = c >> 16;
+ rgba[1] = c >> 8;
+ rgba[2] = c;
+ rgba[3] = c >> 24;
+}
+
+
+
+/* Desc: pixel retrieval
+ *
+ * In : pixel offset
+ * Out : pixel value
+ *
+ * Note: uses current read buffer
+ */
+static int v_getpixel8 (unsigned int offset)
+{
+ return ((word8 *)vl_current_read_buffer)[offset];
+}
+#define v_getpixel15 v_getpixel16
+static int v_getpixel16 (unsigned int offset)
+{
+ return ((word16 *)vl_current_read_buffer)[offset];
+}
+static int v_getpixel24 (unsigned int offset)
+{
+ return *(word32 *)((long)vl_current_read_buffer+offset*3);
+}
+static int v_getpixel32 (unsigned int offset)
+{
+ return ((word32 *)vl_current_read_buffer)[offset];
+}
+
+
+
+/* Desc: set one palette entry
+ *
+ * In : index, R, G, B
+ * Out : -
+ *
+ * Note: color components are in range [0.0 .. 1.0]
+ */
+void vl_setCI (int index, float red, float green, float blue)
+{
+ drv->setCI_f(index, red, green, blue);
+}
+
+
+
+/* Desc: set one palette entry
+ *
+ * In : color, R, G, B
+ * Out : -
+ *
+ * Note: -
+ */
+static void fake_setcolor (int c, int r, int g, int b)
+{
+ VGAPalette[c] = 0xff000000 | (r<<16) | (g<<8) | b;
+
+ drv->setCI_i(c, r, g, b);
+}
+
+
+
+/* Desc: build FakeColor palette
+ *
+ * In : CI precision in bits
+ * Out : -
+ *
+ * Note: -
+ */
+static void fake_buildpalette (int bits)
+{
+ double c_r, c_g, c_b;
+ int r, g, b, color = 0;
+
+ double max = (1 << bits) - 1;
+
+ for (b=0; b<B_CNT; ++b) {
+ for (g=0; g<G_CNT; ++g) {
+ for (r=0; r<R_CNT; ++r) {
+ c_r = 0.5 + (double)r*(max-R_BIAS)/(R_CNT-1.) + R_BIAS;
+ c_g = 0.5 + (double)g*(max-G_BIAS)/(G_CNT-1.) + G_BIAS;
+ c_b = 0.5 + (double)b*(max-B_BIAS)/(B_CNT-1.) + B_BIAS;
+ fake_setcolor(color++, (int)c_r, (int)c_g, (int)c_b);
+ }
+ }
+ }
+
+ for (color=0; color<256; color++) {
+ c_r = (double)color*R_CNT/256.;
+ c_g = (double)color*G_CNT/256.;
+ c_b = (double)color*B_CNT/256.;
+ array_r[color] = (int)c_r;
+ array_g[color] = (int)c_g;
+ array_b[color] = (int)c_b;
+ }
+}
+
+
+
+/* Desc: sync buffer with video hardware
+ *
+ * In : ptr to old buffer, position, size
+ * Out : 0 if success
+ *
+ * Note: -
+ */
+int vl_sync_buffer (void **buffer, int x, int y, int width, int height)
+{
+ if ((width & 7) || (x < 0) || (y < 0) || (x+width > video_mode->xres) || (y+height > video_mode->yres)) {
+ return -1;
+ } else {
+ void *newbuf = *buffer;
+
+ if ((newbuf == NULL) || (vl_current_width != width) || (vl_current_height != height)) {
+ newbuf = realloc(newbuf, width * height * video_bypp);
+ }
+
+ if (newbuf == NULL) {
+ return -2;
+ }
+
+ vl_current_width = width;
+ vl_current_height = height;
+ vl_current_stride = vl_current_width * video_bypp;
+ vl_current_bytes = vl_current_stride * height;
+
+ vl_current_offset = video_scanlen * y + video_bypp * x;
+ vl_current_delta = video_scanlen - vl_current_stride;
+
+ vl_current_draw_buffer = vl_current_read_buffer = *buffer = newbuf;
+ return 0;
+ }
+}
+
+
+
+/* Desc: state retrieval
+ *
+ * In : name, storage
+ * Out : -
+ *
+ * Note: -
+ */
+int vl_get (int pname, int *params)
+{
+ switch (pname) {
+ case VL_GET_SCREEN_SIZE:
+ params[0] = video_mode->xres;
+ params[1] = video_mode->yres;
+ break;
+ default:
+ return drv->get(pname, params);
+ }
+ return 0;
+}
+
+
+
+/* Desc: setup mode
+ *
+ * In : ptr to mode definition
+ * Out : 0 if success
+ *
+ * Note: -
+ */
+static int vl_setup_mode (vl_mode *p)
+{
+ if (p == NULL) {
+ return -1;
+ }
+
+#define INITPTR(bpp) \
+ vl_putpixel = v_putpixel##bpp; \
+ vl_getrgba = v_getrgba##bpp; \
+ vl_getpixel = v_getpixel##bpp; \
+ vl_rect = v_rect##bpp; \
+ vl_mixfix = vl_mixfix##bpp; \
+ vl_mixrgb = vl_mixrgb##bpp; \
+ vl_mixrgba = vl_mixrgba##bpp; \
+ vl_clear = _can_mmx() ? v_clear##bpp##_mmx : v_clear##bpp
+
+ switch (p->bpp) {
+ case 8:
+ INITPTR(8);
+ break;
+ case 15:
+ INITPTR(15);
+ break;
+ case 16:
+ INITPTR(16);
+ break;
+ case 24:
+ INITPTR(24);
+ break;
+ case 32:
+ INITPTR(32);
+ break;
+ default:
+ return -1;
+ }
+
+#undef INITPTR
+
+ video_mode = p;
+ video_bypp = (p->bpp+7)/8;
+ video_scanlen = p->scanlen;
+ vl_video_selector = p->sel;
+
+ return 0;
+}
+
+
+
+/* Desc: restore to the mode prior to first call to `vl_video_init'.
+ *
+ * In : -
+ * Out : -
+ *
+ * Note: -
+ */
+void vl_video_exit (void)
+{
+ drv->restore();
+ drv->fini();
+}
+
+
+
+/* Desc: enter mode
+ *
+ * In : xres, yres, bits/pixel, RGB, refresh rate
+ * Out : pixel width in bits if success
+ *
+ * Note: -
+ */
+int vl_video_init (int width, int height, int bpp, int rgb, int refresh)
+{
+ int fake;
+ vl_mode *p, *q;
+ unsigned int min;
+
+ fake = 0;
+ if (!rgb) {
+ bpp = 8;
+ } else if (bpp == 8) {
+ fake = 1;
+ }
+
+ /* initialize hardware */
+ drv = &VESA;
+ if ((q=drv->init()) == NULL) {
+ drv = &VGA;
+ if ((q=drv->init()) == NULL) {
+ return 0;
+ }
+ }
+
+ /* search for a mode that fits our request */
+ for (min=-1, p=NULL; q->mode!=0xffff; q++) {
+ if ((q->xres>=width) && (q->yres>=height) && (q->bpp==bpp)) {
+ if (min>=(unsigned)(q->xres*q->yres)) {
+ min = q->xres*q->yres;
+ p = q;
+ }
+ }
+ }
+
+ /* setup and enter mode */
+ if ((vl_setup_mode(p) == 0) && (drv->entermode(p, refresh) == 0)) {
+ vl_flip = drv->blit;
+ if (fake) {
+ drv->get(VL_GET_CI_PREC, (int *)(&min));
+ fake_buildpalette(min);
+ if (min == 8) {
+ vl_getrgba = v_getrgba8fake8;
+ }
+ }
+ return bpp;
+ }
+
+ /* abort */
+ return 0;
+}
-/*\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\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
-#ifndef VIDEO_H_included\r
-#define VIDEO_H_included\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
-extern void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]);\r
-\r
-extern void (*vl_clear) (int color);\r
-extern void (*vl_rect) (int x, int y, int width, int height, int color);\r
-extern void (*vl_flip) (void);\r
-extern void (*vl_putpixel) (unsigned int offset, int color);\r
-extern int (*vl_getpixel) (unsigned int offset);\r
-\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
-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
-\r
-#endif\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+#ifndef VIDEO_H_included
+#define VIDEO_H_included
+
+typedef int fixed;
+
+#define VL_GET_CARD_NAME 0x0100
+#define VL_GET_VRAM 0x0101
+#define VL_GET_CI_PREC 0x0200
+#define VL_GET_HPIXELS 0x0201
+#define VL_GET_SCREEN_SIZE 0x0202
+
+extern int (*vl_mixfix) (fixed r, fixed g, fixed b);
+extern int (*vl_mixrgb) (const unsigned char rgb[]);
+extern int (*vl_mixrgba) (const unsigned char rgba[]);
+extern void (*vl_getrgba) (unsigned int offset, unsigned char rgba[4]);
+
+extern void (*vl_clear) (int color);
+extern void (*vl_rect) (int x, int y, int width, int height, int color);
+extern void (*vl_flip) (void);
+extern void (*vl_putpixel) (unsigned int offset, int color);
+extern int (*vl_getpixel) (unsigned int offset);
+
+void vl_setCI (int index, float red, float green, float blue);
+
+int vl_sync_buffer (void **buffer, int x, int y, int width, int height);
+int vl_get (int pname, int *params);
+
+void vl_video_exit (void);
+int vl_video_init (int width, int height, int bpp, int rgb, int refresh);
+
+#endif
-/*\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\r
- *\r
- * Copyright (C) 2002 - Borca Daniel\r
- * Email : dborca@yahoo.com\r
- * Web : http://www.geocities.com/dborca\r
- */\r
-\r
-\r
- .file "virtual.S"\r
-\r
-/*\r
- * extern void *vl_current_draw_buffer;\r
- * extern int vl_current_width, vl_current_bytes;\r
- */\r
-\r
- .text\r
-\r
-/* Desc: void v_clear8 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear8\r
-_v_clear8:\r
- movl 4(%esp), %eax\r
- movb %al, %ah\r
- pushw %ax\r
- pushw %ax\r
- popl %eax\r
- jmp _v_clear_common\r
-\r
-/* Desc: void v_clear16 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear16\r
-_v_clear16:\r
- movl 4(%esp), %eax\r
- pushw %ax\r
- pushw %ax\r
- popl %eax\r
- jmp _v_clear_common\r
-\r
-/* Desc: void v_clear32 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear32\r
-_v_clear32:\r
- movl 4(%esp), %eax\r
- .balign 4\r
-_v_clear_common:\r
- movl _vl_current_bytes, %ecx\r
- movl _vl_current_draw_buffer, %edx\r
- shrl $2, %ecx\r
- .balign 4\r
- 0:\r
- movl %eax, (%edx)\r
- addl $4, %edx\r
- decl %ecx\r
- jnz 0b\r
- ret\r
-\r
-/* Desc: void v_clear8_mmx (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear8_mmx\r
-_v_clear8_mmx:\r
-#ifdef USE_MMX_ASM\r
- movd 4(%esp), %mm0\r
- punpcklbw %mm0, %mm0\r
- punpcklwd %mm0, %mm0\r
- jmp _v_clear_common_mmx\r
-#endif\r
-\r
-/* Desc: void v_clear16_mmx (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear16_mmx\r
-_v_clear16_mmx:\r
-#ifdef USE_MMX_ASM\r
- movd 4(%esp), %mm0\r
- punpcklwd %mm0, %mm0\r
- jmp _v_clear_common_mmx\r
-#endif\r
-\r
-/* Desc: void v_clear32_mmx (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear32_mmx\r
-_v_clear32_mmx:\r
-#ifdef USE_MMX_ASM\r
- movd 4(%esp), %mm0\r
- .balign 4\r
-_v_clear_common_mmx:\r
- punpckldq %mm0, %mm0\r
- movl _vl_current_bytes, %ecx\r
- movl _vl_current_draw_buffer, %edx\r
- shrl $3, %ecx\r
- .balign 4\r
- 0:\r
- movq %mm0, (%edx)\r
- addl $8, %edx\r
- decl %ecx\r
- jnz 0b\r
- emms\r
-#endif\r
- ret\r
-\r
-/* Desc: void v_clear24 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear24\r
-_v_clear24:\r
- movl $0xaaaaaaab, %eax\r
- mull _vl_current_bytes\r
- movl 4(%esp), %eax\r
- movl %edx, %ecx\r
- pushl %ebx\r
- movl _vl_current_draw_buffer, %edx\r
- shrl %ecx\r
- movb 10(%esp), %bl\r
- .balign 4\r
- 0:\r
- movw %ax, (%edx)\r
- movb %bl, 2(%edx)\r
- addl $3, %edx\r
- decl %ecx\r
- jnz 0b\r
- popl %ebx\r
- ret\r
-\r
-/* Desc: void v_clear24_mmx (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_clear24_mmx\r
-_v_clear24_mmx:\r
-#ifdef USE_MMX_ASM\r
- movl 4(%esp), %eax\r
- movl %eax, %edx\r
- movl %eax, %ecx\r
- shll $16, %edx\r
- rorl $8, %ecx\r
- movw %cx, %dx\r
- rorl $16, %ecx\r
- movb %dh, %cl\r
- shll $8, %eax\r
- movb %ch, %al\r
- rorl $8, %eax\r
-\r
- pushl %edx\r
- pushl %eax\r
- movq (%esp), %mm0\r
- pushl %ecx\r
- movq (%esp), %mm1\r
- pushl %edx\r
- movq (%esp), %mm2\r
-\r
- movl $0xaaaaaaab, %eax\r
- mull _vl_current_bytes\r
- movl %edx, %ecx\r
- movl _vl_current_draw_buffer, %edx\r
- shrl $4, %ecx\r
- .balign 4\r
- 0:\r
- movq %mm0, (%edx)\r
- movq %mm1, 8(%edx)\r
- movq %mm2, 16(%edx)\r
- addl $24, %edx\r
- decl %ecx\r
- jnz 0b\r
- emms\r
- addl $16, %esp\r
-#endif\r
- ret\r
-\r
-/* Desc: void v_rect8 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_rect8\r
-_v_rect8:\r
- cld\r
- pushl %esi\r
- pushl %edi\r
- movl 28(%esp), %eax\r
- movl _vl_current_width, %esi\r
- movl 16(%esp), %edi\r
- movb %al, %ah\r
- movl 20(%esp), %ecx\r
- imull %esi, %edi\r
- movl 24(%esp), %edx\r
- subl %ecx, %esi\r
- addl 12(%esp), %edi\r
- pushw %ax\r
- pushw %ax\r
- pushl %ds\r
- popl %es\r
- addl _vl_current_draw_buffer, %edi\r
- popl %eax\r
- pushl %ebx\r
- movl %ecx, %ebx\r
- andl $3, %ebx\r
- .balign 4\r
- 0:\r
- pushl %ecx\r
- .balign 4\r
- 1:\r
- shrl $2, %ecx\r
- rep; stosl\r
- testl %ebx, %ebx\r
- jz 2f\r
- movl %ebx, %ecx\r
- rep; stosb\r
- .balign 4\r
- 2:\r
- popl %ecx\r
- addl %esi, %edi\r
- decl %edx\r
- jnz 0b\r
- popl %ebx\r
- popl %edi\r
- popl %esi\r
- ret\r
-\r
-/* Desc: void v_rect16 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_rect16\r
-_v_rect16:\r
- cld\r
- pushl %esi\r
- pushl %edi\r
- movl 28(%esp), %eax\r
- movl _vl_current_width, %esi\r
- movl 16(%esp), %edi\r
- movl 20(%esp), %ecx\r
- imull %esi, %edi\r
- movl 24(%esp), %edx\r
- subl %ecx, %esi\r
- addl 12(%esp), %edi\r
- pushw %ax\r
- shll %esi\r
- pushw %ax\r
- shll %edi\r
- pushl %ds\r
- popl %es\r
- addl _vl_current_draw_buffer, %edi\r
- popl %eax\r
- .balign 4\r
- 0:\r
- pushl %ecx\r
- .balign 4\r
- 1:\r
- shrl %ecx\r
- rep; stosl\r
- jnc 2f\r
- stosw\r
- .balign 4\r
- 2:\r
- popl %ecx\r
- addl %esi, %edi\r
- decl %edx\r
- jnz 0b\r
- popl %edi\r
- popl %esi\r
- ret\r
-\r
-/* Desc: void v_rect24 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_rect24\r
-_v_rect24:\r
- pushl %esi\r
- pushl %edi\r
- movl 28(%esp), %eax\r
- movl _vl_current_width, %esi\r
- movl 16(%esp), %edi\r
- movl 20(%esp), %ecx\r
- imull %esi, %edi\r
- movl 24(%esp), %edx\r
- subl %ecx, %esi\r
- addl 12(%esp), %edi\r
- leal (%esi, %esi, 2), %esi\r
- pushl %ebx\r
- leal (%edi, %edi, 2), %edi\r
- movl %eax, %ebx\r
- addl _vl_current_draw_buffer, %edi\r
- shrl $16, %ebx\r
- .balign 4\r
- 0:\r
- pushl %ecx\r
- .balign 4\r
- 1:\r
- movw %ax, (%edi)\r
- movb %bl, 2(%edi)\r
- addl $3, %edi\r
- decl %ecx\r
- jnz 1b\r
- popl %ecx\r
- addl %esi, %edi\r
- decl %edx\r
- jnz 0b\r
- popl %ebx\r
- popl %edi\r
- popl %esi\r
- ret\r
-\r
-/* Desc: void v_rect32 (int color);\r
- *\r
- * In : color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_rect32\r
-_v_rect32:\r
- pushl %esi\r
- pushl %edi\r
- movl _vl_current_width, %esi\r
- movl 16(%esp), %edi\r
- movl 20(%esp), %ecx\r
- imull %esi, %edi\r
- movl 24(%esp), %edx\r
- subl %ecx, %esi\r
- addl 12(%esp), %edi\r
- shll $2, %esi\r
- shll $2, %edi\r
- movl 28(%esp), %eax\r
- addl _vl_current_draw_buffer, %edi\r
- .balign 4\r
- 0:\r
- pushl %ecx\r
- .balign 4\r
- 1:\r
- movl %eax, (%edi)\r
- addl $4, %edi\r
- decl %ecx\r
- jnz 1b\r
- popl %ecx\r
- addl %esi, %edi\r
- decl %edx\r
- jnz 0b\r
- popl %edi\r
- popl %esi\r
- ret\r
-\r
-/* Desc: void v_putpixel8 (unsigned int offset, int color);\r
- *\r
- * In : offset within buffer, color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_putpixel8\r
-_v_putpixel8:\r
- movl 8(%esp), %ecx\r
- movl 4(%esp), %edx\r
- movl _vl_current_draw_buffer, %eax\r
- movb %cl, (%eax,%edx)\r
- ret\r
-\r
-/* Desc: void v_putpixel16 (unsigned int offset, int color);\r
- *\r
- * In : offset within buffer, color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_putpixel16\r
-_v_putpixel16:\r
- movl 8(%esp), %ecx\r
- movl 4(%esp), %edx\r
- movl _vl_current_draw_buffer, %eax\r
- movw %cx, (%eax,%edx,2)\r
- ret\r
-\r
-/* Desc: void v_putpixel24 (unsigned int offset, int color);\r
- *\r
- * In : offset within buffer, color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_putpixel24\r
-_v_putpixel24:\r
- movl 4(%esp), %eax\r
- movl 8(%esp), %edx\r
- movl _vl_current_draw_buffer, %ecx\r
- leal (%eax,%eax,2), %eax\r
- movw %dx, (%ecx,%eax)\r
- shrl $16, %edx\r
- movb %dl, 2(%ecx,%eax)\r
- ret\r
-\r
-/* Desc: void v_putpixel32 (unsigned int offset, int color);\r
- *\r
- * In : offset within buffer, color\r
- * Out : -\r
- *\r
- * Note: uses current draw buffer\r
- */\r
- .p2align 5,,31\r
- .global _v_putpixel32\r
-_v_putpixel32:\r
- movl 8(%esp), %ecx\r
- movl 4(%esp), %edx\r
- movl _vl_current_draw_buffer, %eax\r
- movl %ecx, (%eax,%edx,4)\r
- ret\r
+/*
+ * Mesa 3-D graphics library
+ * Version: 4.0
+ *
+ * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/*
+ * DOS/DJGPP device driver v1.3 for Mesa
+ *
+ * Copyright (C) 2002 - Borca Daniel
+ * Email : dborca@yahoo.com
+ * Web : http://www.geocities.com/dborca
+ */
+
+
+ .file "virtual.S"
+
+/*
+ * extern void *vl_current_draw_buffer;
+ * extern int vl_current_width, vl_current_bytes;
+ */
+
+ .text
+
+/* Desc: void v_clear8 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear8
+_v_clear8:
+ movl 4(%esp), %eax
+ movb %al, %ah
+ pushw %ax
+ pushw %ax
+ popl %eax
+ jmp _v_clear_common
+
+/* Desc: void v_clear16 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear16
+_v_clear16:
+ movl 4(%esp), %eax
+ pushw %ax
+ pushw %ax
+ popl %eax
+ jmp _v_clear_common
+
+/* Desc: void v_clear32 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear32
+_v_clear32:
+ movl 4(%esp), %eax
+ .balign 4
+_v_clear_common:
+ movl _vl_current_bytes, %ecx
+ movl _vl_current_draw_buffer, %edx
+ shrl $2, %ecx
+ .balign 4
+ 0:
+ movl %eax, (%edx)
+ addl $4, %edx
+ decl %ecx
+ jnz 0b
+ ret
+
+/* Desc: void v_clear8_mmx (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear8_mmx
+_v_clear8_mmx:
+#ifdef USE_MMX_ASM
+ movd 4(%esp), %mm0
+ punpcklbw %mm0, %mm0
+ punpcklwd %mm0, %mm0
+ jmp _v_clear_common_mmx
+#endif
+
+/* Desc: void v_clear16_mmx (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear16_mmx
+_v_clear16_mmx:
+#ifdef USE_MMX_ASM
+ movd 4(%esp), %mm0
+ punpcklwd %mm0, %mm0
+ jmp _v_clear_common_mmx
+#endif
+
+/* Desc: void v_clear32_mmx (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear32_mmx
+_v_clear32_mmx:
+#ifdef USE_MMX_ASM
+ movd 4(%esp), %mm0
+ .balign 4
+_v_clear_common_mmx:
+ punpckldq %mm0, %mm0
+ movl _vl_current_bytes, %ecx
+ movl _vl_current_draw_buffer, %edx
+ shrl $3, %ecx
+ .balign 4
+ 0:
+ movq %mm0, (%edx)
+ addl $8, %edx
+ decl %ecx
+ jnz 0b
+ emms
+#endif
+ ret
+
+/* Desc: void v_clear24 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear24
+_v_clear24:
+ movl $0xaaaaaaab, %eax
+ mull _vl_current_bytes
+ movl 4(%esp), %eax
+ movl %edx, %ecx
+ pushl %ebx
+ movl _vl_current_draw_buffer, %edx
+ shrl %ecx
+ movb 10(%esp), %bl
+ .balign 4
+ 0:
+ movw %ax, (%edx)
+ movb %bl, 2(%edx)
+ addl $3, %edx
+ decl %ecx
+ jnz 0b
+ popl %ebx
+ ret
+
+/* Desc: void v_clear24_mmx (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_clear24_mmx
+_v_clear24_mmx:
+#ifdef USE_MMX_ASM
+ movl 4(%esp), %eax
+ movl %eax, %edx
+ movl %eax, %ecx
+ shll $16, %edx
+ rorl $8, %ecx
+ movw %cx, %dx
+ rorl $16, %ecx
+ movb %dh, %cl
+ shll $8, %eax
+ movb %ch, %al
+ rorl $8, %eax
+
+ pushl %edx
+ pushl %eax
+ movq (%esp), %mm0
+ pushl %ecx
+ movq (%esp), %mm1
+ pushl %edx
+ movq (%esp), %mm2
+
+ movl $0xaaaaaaab, %eax
+ mull _vl_current_bytes
+ movl %edx, %ecx
+ movl _vl_current_draw_buffer, %edx
+ shrl $4, %ecx
+ .balign 4
+ 0:
+ movq %mm0, (%edx)
+ movq %mm1, 8(%edx)
+ movq %mm2, 16(%edx)
+ addl $24, %edx
+ decl %ecx
+ jnz 0b
+ emms
+ addl $16, %esp
+#endif
+ ret
+
+/* Desc: void v_rect8 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_rect8
+_v_rect8:
+ cld
+ pushl %esi
+ pushl %edi
+ movl 28(%esp), %eax
+ movl _vl_current_width, %esi
+ movl 16(%esp), %edi
+ movb %al, %ah
+ movl 20(%esp), %ecx
+ imull %esi, %edi
+ movl 24(%esp), %edx
+ subl %ecx, %esi
+ addl 12(%esp), %edi
+ pushw %ax
+ pushw %ax
+ pushl %ds
+ popl %es
+ addl _vl_current_draw_buffer, %edi
+ popl %eax
+ pushl %ebx
+ movl %ecx, %ebx
+ andl $3, %ebx
+ .balign 4
+ 0:
+ pushl %ecx
+ .balign 4
+ 1:
+ shrl $2, %ecx
+ rep; stosl
+ testl %ebx, %ebx
+ jz 2f
+ movl %ebx, %ecx
+ rep; stosb
+ .balign 4
+ 2:
+ popl %ecx
+ addl %esi, %edi
+ decl %edx
+ jnz 0b
+ popl %ebx
+ popl %edi
+ popl %esi
+ ret
+
+/* Desc: void v_rect16 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_rect16
+_v_rect16:
+ cld
+ pushl %esi
+ pushl %edi
+ movl 28(%esp), %eax
+ movl _vl_current_width, %esi
+ movl 16(%esp), %edi
+ movl 20(%esp), %ecx
+ imull %esi, %edi
+ movl 24(%esp), %edx
+ subl %ecx, %esi
+ addl 12(%esp), %edi
+ pushw %ax
+ shll %esi
+ pushw %ax
+ shll %edi
+ pushl %ds
+ popl %es
+ addl _vl_current_draw_buffer, %edi
+ popl %eax
+ .balign 4
+ 0:
+ pushl %ecx
+ .balign 4
+ 1:
+ shrl %ecx
+ rep; stosl
+ jnc 2f
+ stosw
+ .balign 4
+ 2:
+ popl %ecx
+ addl %esi, %edi
+ decl %edx
+ jnz 0b
+ popl %edi
+ popl %esi
+ ret
+
+/* Desc: void v_rect24 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_rect24
+_v_rect24:
+ pushl %esi
+ pushl %edi
+ movl 28(%esp), %eax
+ movl _vl_current_width, %esi
+ movl 16(%esp), %edi
+ movl 20(%esp), %ecx
+ imull %esi, %edi
+ movl 24(%esp), %edx
+ subl %ecx, %esi
+ addl 12(%esp), %edi
+ leal (%esi, %esi, 2), %esi
+ pushl %ebx
+ leal (%edi, %edi, 2), %edi
+ movl %eax, %ebx
+ addl _vl_current_draw_buffer, %edi
+ shrl $16, %ebx
+ .balign 4
+ 0:
+ pushl %ecx
+ .balign 4
+ 1:
+ movw %ax, (%edi)
+ movb %bl, 2(%edi)
+ addl $3, %edi
+ decl %ecx
+ jnz 1b
+ popl %ecx
+ addl %esi, %edi
+ decl %edx
+ jnz 0b
+ popl %ebx
+ popl %edi
+ popl %esi
+ ret
+
+/* Desc: void v_rect32 (int color);
+ *
+ * In : color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_rect32
+_v_rect32:
+ pushl %esi
+ pushl %edi
+ movl _vl_current_width, %esi
+ movl 16(%esp), %edi
+ movl 20(%esp), %ecx
+ imull %esi, %edi
+ movl 24(%esp), %edx
+ subl %ecx, %esi
+ addl 12(%esp), %edi
+ shll $2, %esi
+ shll $2, %edi
+ movl 28(%esp), %eax
+ addl _vl_current_draw_buffer, %edi
+ .balign 4
+ 0:
+ pushl %ecx
+ .balign 4
+ 1:
+ movl %eax, (%edi)
+ addl $4, %edi
+ decl %ecx
+ jnz 1b
+ popl %ecx
+ addl %esi, %edi
+ decl %edx
+ jnz 0b
+ popl %edi
+ popl %esi
+ ret
+
+/* Desc: void v_putpixel8 (unsigned int offset, int color);
+ *
+ * In : offset within buffer, color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_putpixel8
+_v_putpixel8:
+ movl 8(%esp), %ecx
+ movl 4(%esp), %edx
+ movl _vl_current_draw_buffer, %eax
+ movb %cl, (%eax,%edx)
+ ret
+
+/* Desc: void v_putpixel16 (unsigned int offset, int color);
+ *
+ * In : offset within buffer, color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_putpixel16
+_v_putpixel16:
+ movl 8(%esp), %ecx
+ movl 4(%esp), %edx
+ movl _vl_current_draw_buffer, %eax
+ movw %cx, (%eax,%edx,2)
+ ret
+
+/* Desc: void v_putpixel24 (unsigned int offset, int color);
+ *
+ * In : offset within buffer, color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_putpixel24
+_v_putpixel24:
+ movl 4(%esp), %eax
+ movl 8(%esp), %edx
+ movl _vl_current_draw_buffer, %ecx
+ leal (%eax,%eax,2), %eax
+ movw %dx, (%ecx,%eax)
+ shrl $16, %edx
+ movb %dl, 2(%ecx,%eax)
+ ret
+
+/* Desc: void v_putpixel32 (unsigned int offset, int color);
+ *
+ * In : offset within buffer, color
+ * Out : -
+ *
+ * Note: uses current draw buffer
+ */
+ .p2align 5,,31
+ .global _v_putpixel32
+_v_putpixel32:
+ movl 8(%esp), %ecx
+ movl 4(%esp), %edx
+ movl _vl_current_draw_buffer, %eax
+ movl %ecx, (%eax,%edx,4)
+ ret
+++ /dev/null
-# Mesa 3-D graphics library\r
-# Version: 5.1\r
-# \r
-# Copyright (C) 1999-2003 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
-# DOS/DJGPP core makefile v1.3 for Mesa\r
-#\r
-# Copyright (C) 2002 - Borca Daniel\r
-# Email : dborca@yahoo.com\r
-# Web : http://www.geocities.com/dborca\r
-\r
-\r
-#\r
-# Available options:\r
-#\r
-# Environment variables:\r
-# CFLAGS\r
-#\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
-# compilation of most DMesa code and requires fxMesa.\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
-# supports MMX instruction set. However, the true CPU\r
-# capabilities are checked at run-time to avoid crashes.\r
-# default = no\r
-# HAVE_SSE=1 (see HAVE_MMX)\r
-# default = no\r
-# HAVE_3DNOW=1 (see HAVE_MMX)\r
-# default = no\r
-#\r
-# Targets:\r
-# all: build GL\r
-# clean: remove object files\r
-#\r
-\r
-\r
-\r
-.PHONY: all clean\r
-.INTERMEDIATE: X86/gen_matypes.exe\r
-\r
-TOP = ..\r
-GLIDE ?= $(TOP)/include/glide3\r
-LIBDIR = $(TOP)/lib\r
-GL_LIB = libgl.a\r
-GL_DXE = gl.dxe\r
-GL_IMP = libigl.a\r
-\r
-CC = gcc\r
-CFLAGS += -I$(TOP)/include -I.\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
-ARFLAGS = rus\r
-\r
-HAVEDXE3 = $(wildcard $(DJDIR)/bin/dxe3gen.exe)\r
-\r
-ifeq ($(wildcard $(addsuffix /rm.exe,$(subst ;, ,$(PATH)))),)\r
-UNLINK = del $(subst /,\,$(1))\r
-else\r
-UNLINK = $(RM) $(1)\r
-endif\r
-\r
-CORE_SOURCES = \\r
- api_arrayelt.c \\r
- api_loopback.c \\r
- api_noop.c \\r
- api_validate.c \\r
- accum.c \\r
- arbprogram.c \\r
- attrib.c \\r
- blend.c \\r
- bufferobj.c \\r
- buffers.c \\r
- clip.c \\r
- colortab.c \\r
- context.c \\r
- convolve.c \\r
- debug.c \\r
- depth.c \\r
- dispatch.c \\r
- dlist.c \\r
- drawpix.c \\r
- enable.c \\r
- enums.c \\r
- eval.c \\r
- extensions.c \\r
- feedback.c \\r
- fog.c \\r
- get.c \\r
- glapi.c \\r
- glthread.c \\r
- hash.c \\r
- hint.c \\r
- histogram.c \\r
- image.c \\r
- imports.c \\r
- light.c \\r
- lines.c \\r
- matrix.c \\r
- mmath.c \\r
- pixel.c \\r
- points.c \\r
- polygon.c \\r
- rastpos.c \\r
- state.c \\r
- stencil.c \\r
- texcompress.c \\r
- texformat.c \\r
- teximage.c \\r
- texobj.c \\r
- texstate.c \\r
- texstore.c \\r
- texutil.c \\r
- varray.c \\r
- vpexec.c \\r
- vpparse.c \\r
- vpstate.c \\r
- vtxfmt.c \\r
- math/m_debug_clip.c \\r
- math/m_debug_norm.c \\r
- math/m_debug_xform.c \\r
- math/m_eval.c \\r
- math/m_matrix.c \\r
- math/m_translate.c \\r
- math/m_vector.c \\r
- math/m_xform.c \\r
- array_cache/ac_context.c \\r
- array_cache/ac_import.c \\r
- swrast/s_aaline.c \\r
- swrast/s_aatriangle.c \\r
- swrast/s_accum.c \\r
- swrast/s_alpha.c \\r
- swrast/s_alphabuf.c \\r
- swrast/s_bitmap.c \\r
- swrast/s_blend.c \\r
- swrast/s_buffers.c \\r
- swrast/s_copypix.c \\r
- swrast/s_context.c \\r
- swrast/s_depth.c \\r
- swrast/s_drawpix.c \\r
- swrast/s_feedback.c \\r
- swrast/s_fog.c \\r
- swrast/s_histogram.c \\r
- swrast/s_imaging.c \\r
- swrast/s_lines.c \\r
- swrast/s_logic.c \\r
- swrast/s_masking.c \\r
- swrast/s_pixeltex.c \\r
- swrast/s_points.c \\r
- swrast/s_readpix.c \\r
- swrast/s_span.c \\r
- swrast/s_stencil.c \\r
- swrast/s_texture.c \\r
- swrast/s_texstore.c \\r
- swrast/s_triangle.c \\r
- swrast/s_zoom.c \\r
- swrast_setup/ss_context.c \\r
- swrast_setup/ss_triangle.c \\r
- swrast_setup/ss_vb.c \\r
- tnl/t_array_api.c \\r
- tnl/t_array_import.c \\r
- tnl/t_context.c \\r
- tnl/t_eval_api.c \\r
- tnl/t_imm_alloc.c \\r
- tnl/t_imm_api.c \\r
- tnl/t_imm_debug.c \\r
- tnl/t_imm_dlist.c \\r
- tnl/t_imm_elt.c \\r
- tnl/t_imm_eval.c \\r
- tnl/t_imm_exec.c \\r
- tnl/t_imm_fixup.c \\r
- tnl/t_pipeline.c \\r
- tnl/t_vb_fog.c \\r
- tnl/t_vb_light.c \\r
- tnl/t_vb_normals.c \\r
- tnl/t_vb_points.c \\r
- tnl/t_vb_program.c \\r
- tnl/t_vb_render.c \\r
- tnl/t_vb_texgen.c \\r
- tnl/t_vb_texmat.c \\r
- tnl/t_vb_vertex.c\r
-\r
-X86_SOURCES = \\r
- X86/x86.c \\r
- X86/glapi_x86.S \\r
- X86/common_x86.c \\r
- X86/common_x86_asm.S \\r
- X86/x86_xform2.S \\r
- X86/x86_xform3.S \\r
- X86/x86_xform4.S \\r
- X86/x86_cliptest.S\r
-\r
-MMX_SOURCES = \\r
- X86/mmx_blend.S\r
-\r
-SSE_SOURCES = \\r
- X86/sse.c \\r
- X86/sse_xform2.S \\r
- X86/sse_xform3.S \\r
- X86/sse_xform4.S \\r
- X86/sse_normal.S\r
-\r
-K3D_SOURCES = \\r
- X86/3dnow.c \\r
- X86/3dnow_xform2.S \\r
- X86/3dnow_xform3.S \\r
- X86/3dnow_xform4.S \\r
- X86/3dnow_normal.S\r
-\r
-ifeq ($(HAVE_MMX),1)\r
-X86_SOURCES += $(MMX_SOURCES)\r
-CFLAGS += -DUSE_MMX_ASM\r
-HAVE_X86 = 1\r
-endif\r
-ifeq ($(HAVE_SSE),1)\r
-X86_SOURCES += $(SSE_SOURCES)\r
-CFLAGS += -DUSE_SSE_ASM\r
-HAVE_X86 = 1\r
-endif\r
-ifeq ($(HAVE_3DNOW),1)\r
-X86_SOURCES += $(K3D_SOURCES)\r
-CFLAGS += -DUSE_3DNOW_ASM\r
-HAVE_X86 = 1\r
-endif\r
-ifeq ($(HAVE_X86),1)\r
-CFLAGS += -DUSE_X86_ASM\r
-else\r
-X86_SOURCES =\r
-endif\r
-\r
-DRIVER_SOURCES = \\r
- DOS/dmesa.c\r
-ifeq ($(FX),1)\r
-DRIVER_SOURCES += \\r
- FX/fxapi.c \\r
- FX/fxdd.c \\r
- FX/fxddspan.c \\r
- FX/fxddtex.c \\r
- FX/fxsetup.c \\r
- FX/fxtexman.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
-\r
-OBJECTS = $(addsuffix .o,$(basename $(SOURCES)))\r
-\r
-X86_OBJECTS = $(addsuffix .o,$(basename $(X86_SOURCES)))\r
-\r
-.c.o:\r
- $(CC) -o $@ $(CFLAGS) -c $<\r
-.S.o:\r
- $(CC) -o $@ $(CFLAGS) -c $<\r
-.s.o:\r
- $(CC) -o $@ $(CFLAGS) -x assembler-with-cpp -c $<\r
-\r
-all: $(LIBDIR)/$(GL_LIB) $(LIBDIR)/$(GL_DXE) $(LIBDIR)/$(GL_IMP)\r
-\r
-$(LIBDIR)/$(GL_LIB): $(OBJECTS)\r
- $(AR) $(ARFLAGS) $(LIBDIR)/$(GL_LIB) $(OBJECTS)\r
-\r
-$(LIBDIR)/$(GL_DXE) $(LIBDIR)/$(GL_IMP): $(OBJECTS)\r
-ifeq ($(HAVEDXE3),)\r
- $(warning Missing DXE3 package... Skipping $(GL_DXE))\r
-else\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 $(LIBNAME) -E _gl -E _DMesa -U $(OBJECTS)\r
-endif\r
-endif\r
-\r
-$(X86_OBJECTS): X86/matypes.h\r
-\r
-X86/matypes.h: X86/gen_matypes.exe\r
- $< > $@\r
-\r
-X86/gen_matypes.exe: X86/gen_matypes.c\r
- $(CC) -o $@ $(CFLAGS) -s $<\r
-\r
-clean:\r
- -$(call UNLINK,*.o)\r
- -$(call UNLINK,array_cache/*.o)\r
- -$(call UNLINK,math/*.o)\r
- -$(call UNLINK,swrast/*.o)\r
- -$(call UNLINK,swrast_setup/*.o)\r
- -$(call UNLINK,tnl/*.o)\r
- -$(call UNLINK,X86/*.o)\r
- -$(call UNLINK,DOS/*.o)\r
- -$(call UNLINK,DOS/mga/*.o)\r
- -$(call UNLINK,FX/*.o)\r
-\r
--include depend\r