This commit was manufactured by cvs2svn to create tag 'd2x-0_1_2'. d2x-0_1_2
authornobody <nobody@nowhere>
Thu, 29 May 2003 06:26:29 +0000 (06:26 +0000)
committernobody <nobody@nowhere>
Thu, 29 May 2003 06:26:29 +0000 (06:26 +0000)
341 files changed:
.cvsignore [deleted file]
2d/.cvsignore [deleted file]
2d/2dsline.c
2d/Makefile.am
2d/bitblt.c
2d/bitmap.c
2d/bitmap.h
2d/box.c
2d/canvas.c
2d/circle.c
2d/clip.h
2d/disc.c
2d/font.c
2d/gpixel.c
2d/ibitblt.c
2d/line.c
2d/linear.asm
2d/linear.h [new file with mode: 0644]
2d/palette.c
2d/pcx.c
2d/pixel.c
2d/poly.c
2d/rect.c
2d/rle.c
2d/scale.c
2d/scalea.asm
2d/scalea.h
2d/scalec.c
2d/tmerge.c
2d/tmerge_a.asm
3d/.cvsignore [deleted file]
3d/Makefile.am
3d/clipper.c
3d/clipper.h
3d/draw.c
3d/globvars.c
3d/globvars.h
3d/instance.c
3d/interp.asm
3d/interp.c
3d/matrix.c
3d/points.c
3d/rod.c
3d/setup.c
COPYING
ChangeLog [deleted file]
Info.plist.in [deleted file]
Makefile.am
NEWS
README
README.utils [deleted file]
TODO [deleted file]
acconfig.h [new file with mode: 0644]
arch/.cvsignore [deleted file]
arch/dos/.cvsignore [deleted file]
arch/dos/Makefile.am
arch/dos/cdrom.c [moved from arch/dos/rbaudio.c with 81% similarity]
arch/dos/digimm.c
arch/ggi/.cvsignore [deleted file]
arch/ggi/Makefile.am
arch/ggi/key.c
arch/include/joy.h
arch/linux/.cvsignore [deleted file]
arch/linux/Makefile.am
arch/linux/alsadigi.c
arch/linux/findfile.c
arch/linux/hmiplay.c
arch/linux/include/ipx_bsd.h
arch/linux/include/ipx_drv.h [deleted file]
arch/linux/include/ipx_hlpr.h
arch/linux/include/ipx_kali.h
arch/linux/include/ipx_ld.h
arch/linux/include/ipx_lin.h
arch/linux/include/ipx_udp.h
arch/linux/include/joystick.h
arch/linux/include/music.h
arch/linux/include/serial.h
arch/linux/include/ukali.h
arch/linux/init.c
arch/linux/ipx_bsd.c
arch/linux/ipx_kali.c
arch/linux/ipx_lin.c
arch/linux/ipx_udp.c
arch/linux/joydefs.c
arch/linux/joystick.c
arch/linux/linuxnet.c
arch/linux/ukali.c
arch/ogl/.cvsignore [deleted file]
arch/ogl/Makefile.am
arch/ogl/glx.c
arch/ogl/gr.c
arch/ogl/ogl.c
arch/ogl/sdlgl.c
arch/ogl/wgl.c
arch/sdl/.cvsignore [deleted file]
arch/sdl/Makefile.am
arch/sdl/cdrom.c [new file with mode: 0644]
arch/sdl/digi.c
arch/sdl/event.c
arch/sdl/gr.c
arch/sdl/init.c
arch/sdl/joy.c
arch/sdl/joydefs.c
arch/sdl/key.c
arch/sdl/mouse.c
arch/sdl/rbaudio.c [deleted file]
arch/sdl/timer.c
arch/svgalib/.cvsignore [deleted file]
arch/svgalib/Makefile.am
arch/svgalib/key.c
arch/win32/.cvsignore [deleted file]
arch/win32/Makefile.am
arch/win32/digi.c
arch/win32/ipx_drv.h [deleted file]
arch/win32/ipx_win.c
arch/win32/mingw_init.c
arch/win32/winnet.c
autogen.sh
cfile/.cvsignore [deleted file]
cfile/Makefile.am
cfile/cfile.c
compilerdefs.txt
configure.ac
cvshowto.txt
d2x-gl.sh [deleted file]
d2x-sdl.sh [deleted file]
debian/changelog.in [deleted file]
debian/control [deleted file]
debian/d2x-gl.files [deleted file]
debian/d2x-gl.menu [deleted file]
debian/d2x-sdl.files [deleted file]
debian/d2x-sdl.menu [deleted file]
debian/rules [deleted file]
iff/.cvsignore [deleted file]
iff/Makefile.am
iff/iff.c
include/3d.h
include/byteswap.h
include/cfile.h
include/d1x.xpm [deleted file]
include/d_delay.h [new file with mode: 0644]
include/descent.xpm [deleted file]
include/error.h
include/gr.h
include/grdef.h
include/ibitblt.h
include/iff.h
include/interp.h [deleted file]
include/ipx.h
include/ipx_drv.h [new file with mode: 0644]
include/libmve.h [deleted file]
include/loadgl.h
include/maths.h
include/ogl_init.h
include/palette.h
include/pcx.h
include/pstypes.h
include/rle.h
include/strutil.h
include/texmap.h
include/timer.h
include/u_mem.h
include/vecmat.h
installation.txt
libmve/.cvsignore [deleted file]
libmve/Makefile.am [deleted file]
libmve/decoder16.c [deleted file]
libmve/decoder8.c [deleted file]
libmve/decoders.h [deleted file]
libmve/mve_audio.c [deleted file]
libmve/mve_audio.h [deleted file]
libmve/mve_main.c [deleted file]
libmve/mvelib.c [deleted file]
libmve/mvelib.h [deleted file]
libmve/mveplay.c [deleted file]
license.txt [moved from debian/copyright with 54% similarity]
main/.cvsignore [deleted file]
main/Makefile.am
main/ai.c
main/ai.h
main/automap.c
main/automap.h
main/bm.c
main/bm.h
main/cdrom.h [new file with mode: 0644]
main/cntrlcen.c
main/cntrlcen.h
main/collide.c
main/config.c
main/console.c
main/credits.c
main/crypt.c
main/digi.h
main/editor/.cvsignore [deleted file]
main/editor/Makefile.am
main/effects.c
main/effects.h
main/endlevel.c
main/endlevel.h
main/escort.c
main/escort.h [deleted file]
main/fuelcen.c
main/fuelcen.h
main/game.c
main/game.h
main/gamecntl.c
main/gamefont.c
main/gamefont.h
main/gamemine.c
main/gamemine.h
main/gamepal.c
main/gamerend.c
main/gamesave.c
main/gamesave.h
main/gameseq.c
main/gameseq.h
main/hud.c
main/inferno.c
main/ipx_drv.c [new file with mode: 0644]
main/joydefs.h
main/kconfig.c
main/kconfig.h
main/kludge.c
main/laser.c
main/laser.h
main/menu.c
main/menu.h
main/mission.c
main/mission.h
main/morph.c
main/movie.c
main/movie.h
main/multi.c
main/multi.h
main/netmisc.c
main/netmisc.h
main/network.c
main/network.h
main/newdemo.c
main/newdemo.h
main/newmenu.c
main/newmenu.h
main/object.h
main/old/joydefs.c [moved from main/joydefs.c with 71% similarity]
main/old/movie.c [new file with mode: 0644]
main/piggy.c
main/piggy.h
main/player.c [deleted file]
main/player.h
main/playsave.c
main/polyobj.c
main/polyobj.h
main/powerup.c
main/powerup.h
main/render.c
main/render.h
main/reorder.h [deleted file]
main/robot.c
main/robot.h
main/scores.c
main/scores.h
main/segment.c [deleted file]
main/segment.h
main/songs.c
main/sounds.h
main/state.c
main/switch.c
main/switch.h
main/terrain.c
main/texmerge.c
main/text.c
main/text.h
main/titles.c
main/titles.h
main/vclip.c
main/vclip.h
main/vers_id.h
main/wall.c
main/wall.h
main/weapon.c
main/weapon.h
maths/.cvsignore [deleted file]
maths/Makefile.am
maths/fix.asm
maths/fixc.c
maths/rand.c
maths/tables.c
maths/vecmat.c
maths/vecmata.asm
mem/.cvsignore [deleted file]
mem/Makefile.am
mem/mem.c
mingw32.txt [new file with mode: 0644]
misc/.cvsignore [deleted file]
misc/Makefile.am
misc/args.c
misc/byteswap.c
misc/d_delay.c [new file with mode: 0644]
misc/d_glob.c [new file with mode: 0644]
misc/d_io.c
misc/dos_disk.h
misc/error.c
misc/fileutil.c
misc/fileutil.h [moved from include/fileutil.h with 54% similarity]
misc/hash.c
misc/parsarg.c
misc/parsarg.h
misc/strio.c
misc/strutil.c
readme.txt
rpm/.cvsignore [deleted file]
rpm/d2x.spec.in [deleted file]
texmap/.cvsignore [deleted file]
texmap/Makefile.am
texmap/ntmap.c
texmap/scanline.c
texmap/scanline.h
texmap/texmapl.h
texmap/tmap_flt.asm
texmap/tmap_inc.asm
texmap/tmap_lin.asm
texmap/tmap_ll.asm
texmap/tmap_per.asm
texmap/tmapfade.asm
texmap/tmapflat.c
texmap/tmappent.S
texmap/tmapppro.S
tools/cvs2cl/cvs2cl.pl [new file with mode: 0644]
unused/bios/rbaudio.h [moved from include/rbaudio.h with 94% similarity]
unused/lib/fix.h [new file with mode: 0644]
unused/lib/rbaudio.h [new file with mode: 0644]
unused/novga/files.rc [new file with mode: 0644]
unused/novga/novesa.c [new file with mode: 0644]
utilities/.cvsignore [deleted file]
utilities/Makefile.am [deleted file]
utilities/hogcreate.c [deleted file]
utilities/hogextract.c [deleted file]
utilities/mvlcreate.c [deleted file]
utilities/mvlextract.c [deleted file]
utilities/tex2txb.c [deleted file]
utilities/txb2tex.c [deleted file]

diff --git a/.cvsignore b/.cvsignore
deleted file mode 100644 (file)
index 6440c0c..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-Makefile.in
-aclocal.m4
-autom4te.cache
-compile
-conf.h.in
-config.guess
-config.sub
-configure
-depcomp
-install-sh
-missing
-mkinstalldirs
-stamp-h.in
diff --git a/2d/.cvsignore b/2d/.cvsignore
deleted file mode 100644 (file)
index 70845e0..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Makefile.in
index 62f0a1c..c765cd8 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: 2dsline.c,v 1.10 2003-04-29 08:05:41 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,56 +7,19 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 /*
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 /*
+ * $Source: /cvs/cvsroot/d2x/2d/2dsline.c,v $
+ * $Revision: 1.3 $
+ * $Author: bradleyb $
+ * $Date: 2001-10-18 22:45:58 $
  *
  *
- * Graphical routines for drawing solid scanlines.
+ * FIXME: add description
  *
  *
- * Old Log:
- * Revision 1.6  1995/09/14  14:24:03  allender
- * fixed MW compile error
- *
- * Revision 1.5  1995/09/14  13:45:17  allender
- * quick optimization for scanline
- *
- * Revision 1.4  1995/04/27  07:36:05  allender
- * remove some memsets since all old is here now
- *
- * Revision 1.3  1995/04/19  14:35:33  allender
- * *** empty log message ***
- *
- * Revision 1.2  1995/04/18  12:03:40  allender
- * *** empty log message ***
- *
- * Revision 1.1  1995/03/09  09:24:06  allender
- * Initial revision
- *
- *
- * --- PC RCS information ---
- * Revision 1.7  1994/11/18  22:50:48  john
- * Changed a bunch of shorts to ints in calls.
- *
- * Revision 1.6  1994/09/02  11:40:32  john
- * fixed bug with urect scanline drakening still
- * only using 16 levels of fade.
- *
- * Revision 1.5  1994/04/08  16:59:12  john
- * Add fading poly's; Made palette fade 32 instead of 16.
- *
- * Revision 1.4  1994/03/22  18:36:27  john
- * Added darkening scanlines
- *
- * Revision 1.3  1993/10/15  16:22:52  john
- * y
- *
- * Revision 1.2  1993/09/08  11:56:29  john
- * neatened
- *
- * Revision 1.1  1993/09/08  11:44:27  john
- * Initial revision
+ * $Log: not supported by cvs2svn $
  *
  */
 
  *
  */
 
@@ -71,34 +33,28 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 
 #include "gr.h"
 #include "grdef.h"
 
 #include "gr.h"
 #include "grdef.h"
-#include "error.h"
 
 
-#ifdef __MSDOS__
+#ifdef __DJGPP__
 #include "modex.h"
 #include "vesa.h"
 #endif
 
 #include "modex.h"
 #include "vesa.h"
 #endif
 
-#if defined(POLY_ACC)
-#include "poly_acc.h"
-#endif
-
 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
 
 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
 
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
+#ifndef NO_ASM
+# ifdef __WATCOMC__
 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
-#pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
-"               xor ebx, ebx                "   \
-"               mov bh, al                  "   \
-"gld_loop:      mov bl, [edi]               "   \
-"               mov al, [ebx+edx]           "   \
-"               mov [edi], al               "   \
-"               inc edi                     "   \
-"               dec ecx                     "   \
-"               jnz gld_loop                "
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
+#  pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
+"                                      xor     ebx, ebx                                        "       \
+"                                      mov     bh, al                                  "  \
+"gld_loop:             mov     bl, [edi]                               "       \
+"                                      mov     al, [ebx+edx]                   "       \
+"                                      mov     [edi], al                               "       \
+"                                      inc     edi                                             "       \
+"                                      dec     ecx                                             "       \
+"                   jnz gld_loop                    "
+
+# elif defined __GNUC__
 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
    int dummy[4];
    __asm__ __volatile__ (
 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
    int dummy[4];
    __asm__ __volatile__ (
@@ -114,180 +70,82 @@ static inline void gr_linear_darken( ubyte * dest, int darkening_level, int coun
    : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
    : "%ebx");
 }
    : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
    : "%ebx");
 }
-
-#elif !defined(NO_ASM) && defined(_MSC_VER)
-
+# elif defined _MSC_VER
 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
 {
 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
 {
-       __asm {
+  __asm {
     mov edi,[dest]
     mov edi,[dest]
-    mov eax,[darkening_level]
-    mov ecx,[count]
-    mov edx,[fade_table]
-    xor ebx, ebx
-    mov bh, al
+       mov eax,[darkening_level]
+       mov ecx,[count]
+       mov edx,[fade_table]
+       xor ebx, ebx
+       mov bh, al
 gld_loop:
 gld_loop:
-    mov bl,[edi]
-    mov al,[ebx+edx]
-    mov [edi],al
-    inc edi
-    dec ecx
-    jnz gld_loop
-       }
-}
-
-#else // Unknown compiler, or no assembler. So we use C.
-
-void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
-       register int i;
-
-       for (i=0;i<count;i++)
-       {
-               *dest = fade_table[(*dest)+(darkening_level*256)];
-               dest++;
-       }
+       mov bl,[edi]
+       mov al,[ebx+edx]
+       mov [edi],al
+       inc edi
+       dec ecx
+       jnz gld_loop
+  }
 }
 }
+# else
+// Unknown compiler. So we use C rather than inline assembler.
+#  define USE_C_GR_LINEAR_DARKEN 1
+# endif
 
 
-#endif
-
-#ifdef NO_ASM // No Assembler. So we use C.
-#if 0
-void gr_linear_stosd( ubyte * dest, ubyte color, unsigned short count )
-{
-       int i, x;
-
-       if (count > 3) {
-               while ((int)(dest) & 0x3) { *dest++ = color; count--; };
-               if (count >= 4) {
-                       x = (color << 24) | (color << 16) | (color << 8) | color;
-                       while (count > 4) { *(int *)dest = x; dest += 4; count -= 4; };
-               }
-               while (count > 0) { *dest++ = color; count--; };
-       } else {
-               for (i=0; i<count; i++ )
-                       *dest++ = color;
-       }
-}
-#else
+#else // No Assembler. So we use C.
+# define USE_C_GR_LINEAR_DARKEN 1
 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
        memset(dest,color,nbytes);
 }
 #endif
 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
        memset(dest,color,nbytes);
 }
 #endif
-#endif
-
-#if defined(POLY_ACC)
-//$$ Note that this code WAS a virtual clone of the mac code and any changes to mac should be reflected here.
-void gr_linear15_darken( short * dest, int darkening_level, int count, ubyte * fade_table )
-{
-    //$$ this routine is a prime candidate for using the alpha blender.
-    int i;
-    unsigned short rt[32], gt[32], bt[32];
-    unsigned long level, int_level, dlevel;
-
-    dlevel = (darkening_level << 16) / GR_FADE_LEVELS;
-    level = int_level = 0;
-    for(i = 0; i != 32; ++i)
-    {
-        rt[i] = int_level << 10;
-        gt[i] = int_level << 5;
-        bt[i] = int_level;
 
 
-        level += dlevel;
-        int_level = level >> 16;
-    }
-
-    pa_flush();
-    for (i=0; i<count; i++ )    {
-        if(*dest & 0x8000)
-               *dest =
-                rt[((*dest >> 10) & 0x1f)] |
-             gt[((*dest >> 5) & 0x1f)] |
-                  bt[((*dest >> 0) & 0x1f)] |
-               0x8000;
-               dest++;
-       }
-}
+#ifdef USE_C_GR_LINEAR_DARKEN
+void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
+       register int i;
 
 
-void gr_linear15_stosd( short * dest, ubyte color, unsigned short count )
-{
-    //$$ this routine is a prime candidate for using the alpha blender.
-    short c = pa_clut[color];
-    pa_flush();
-    while(count--)
-        *dest++ = c;
+       for (i=0;i<count;i++)
+               *dest=fade_table[(*dest++)+(darkening_level*256)];
 }
 #endif
 
 void gr_uscanline( int x1, int x2, int y )
 {
 }
 #endif
 
 void gr_uscanline( int x1, int x2, int y )
 {
-       if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
+       if (Gr_scanline_darkening_level >= GR_FADE_LEVELS )     {
+#ifdef __DJGPP__
                switch(TYPE)
                {
                case BM_LINEAR:
                switch(TYPE)
                {
                case BM_LINEAR:
-#ifdef OGL
-               case BM_OGL:
 #endif
                        gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
 #endif
                        gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
-                       break;
-#ifdef __MSDOS__
+#ifdef __DJGPP__
+                        break;
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
-#endif
-#if defined(POLY_ACC)
-               case BM_LINEAR15:
-                       gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
-                       break;
-#endif
                }
                }
+#endif
        } else {
        } else {
+#ifdef __DJGPP__
                switch(TYPE)
                {
                case BM_LINEAR:
                switch(TYPE)
                {
                case BM_LINEAR:
-#ifdef OGL
-               case BM_OGL:
 #endif
                        gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
 #endif
                        gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
+#ifdef __DJGPP__
                        break;
                        break;
-#ifdef __MSDOS__
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
-#if 1
-                       {
-                               ubyte * vram = (ubyte *)0xA0000;
-                               int VideoLocation,page,offset1, offset2;
-
-                               VideoLocation = (ROWSIZE * y) + x1;
-                               page    = VideoLocation >> 16;
-                               offset1  = VideoLocation & 0xFFFF;
-                               offset2   = offset1 + (x2-x1+1);
-
-                               gr_vesa_setpage( page );
-                               if ( offset2 <= 0xFFFF ) {
-                                       gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
-                               } else {
-                                       gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
-                                       page++;
-                                       gr_vesa_setpage(page);
-                                       gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
-                               }
-                       }
-#else
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
-#endif
                        break;
                        break;
-#endif
-#if defined(POLY_ACC)
-               case BM_LINEAR15:
-                       gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
-                       break;
-#endif
                }
                }
+#endif
        }
 }
 
        }
 }
 
@@ -303,73 +161,39 @@ void gr_scanline( int x1, int x2, int y )
        if (x1 < MINX) x1 = MINX;
        if (x2 > MAXX) x2 = MAXX;
 
        if (x1 < MINX) x1 = MINX;
        if (x2 > MAXX) x2 = MAXX;
 
-       if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
+       if (Gr_scanline_darkening_level >= GR_FADE_LEVELS )     {
+#ifdef __DJGPP__
                switch(TYPE)
                {
                case BM_LINEAR:
                switch(TYPE)
                {
                case BM_LINEAR:
-#ifdef OGL
-               case BM_OGL:
 #endif
                        gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
 #endif
                        gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
+#ifdef __DJGPP__
                        break;
                        break;
-#ifdef __MSDOS__
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
-#endif
-#if defined(POLY_ACC)
-               case BM_LINEAR15:
-                       gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
-                       break;
-#endif
                }
                }
+#endif
        } else {
        } else {
+#ifdef __DJGPP__
                switch(TYPE)
                {
                case BM_LINEAR:
                switch(TYPE)
                {
                case BM_LINEAR:
-#ifdef OGL
-               case BM_OGL:
 #endif
                        gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
 #endif
                        gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
+#ifdef __DJGPP__
                        break;
                        break;
-#ifdef __MSDOS__
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
                case BM_MODEX:
                        gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        break;
                case BM_SVGA:
-#if 1
-                       {
-                               ubyte * vram = (ubyte *)0xA0000;
-                               int VideoLocation,page,offset1, offset2;
-
-                               VideoLocation = (ROWSIZE * y) + x1;
-                               page    = VideoLocation >> 16;
-                               offset1  = VideoLocation & 0xFFFF;
-                               offset2   = offset1 + (x2-x1+1);
-
-                               gr_vesa_setpage( page );
-                               if ( offset2 <= 0xFFFF )        {
-                                       gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
-                               } else {
-                                       gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
-                                       page++;
-                                       gr_vesa_setpage(page);
-                                       gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
-                               }
-                       }
-#else
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
                        gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
-#endif
                        break;
                        break;
-#endif
-#if defined(POLY_ACC)
-               case BM_LINEAR15:
-                       gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
-                       break;
-#endif
                }
                }
+#endif
        }
 }
        }
 }
index 298e9de..2ce85c7 100644 (file)
@@ -1,5 +1,5 @@
 noinst_LIBRARIES = lib2d.a
 noinst_LIBRARIES = lib2d.a
-INCLUDES = -I $(top_srcdir)/include
+INCLUDES = -I $(top_srcdir)/includes
 
 if USE_ASM
 ASM_SRCS =
 
 if USE_ASM
 ASM_SRCS =
@@ -7,12 +7,6 @@ else
 ASM_SRCS = tmerge.c
 endif
 
 ASM_SRCS = tmerge.c
 endif
 
-if MACDATA
-TRANSPARENCY_COLOR = 0
-else
-TRANSPARENCY_COLOR = 255
-endif
-
 lib2d_a_SOURCES = ${ASM_SRCS} \
 2dsline.c  box.c     disc.c    ibitblt.c  pcx.c    rect.c   scalec.c \
 bitblt.c   canvas.c  font.c    line.c    pixel.c  rle.c \
 lib2d_a_SOURCES = ${ASM_SRCS} \
 2dsline.c  box.c     disc.c    ibitblt.c  pcx.c    rect.c   scalec.c \
 bitblt.c   canvas.c  font.c    line.c    pixel.c  rle.c \
@@ -20,7 +14,7 @@ bitmap.c   circle.c  gpixel.c  palette.c  poly.c
 
 SUFFIXES = .asm
 %.o: %.asm
 
 SUFFIXES = .asm
 %.o: %.asm
-       $(NASM) -dTRANSPARENCY_COLOR=${TRANSPARENCY_COLOR} $(NASMFLAGS) $< -o $@
+       $(NASM) $(NASMFLAGS) $< -o $@
 
 if USE_ASM
 lib2d_a_LIBADD = linear.o tmerge_a.o
 
 if USE_ASM
 lib2d_a_LIBADD = linear.o tmerge_a.o
@@ -28,5 +22,5 @@ endif
 
 EXTRA_DIST = \
 linear.asm scalea.asm tmerge_a.asm \
 
 EXTRA_DIST = \
 linear.asm scalea.asm tmerge_a.asm \
-bitmap.h clip.h scalea.h \
+bitmap.h clip.h linear.h scalea.h \
 scale.c tmerge.c
 scale.c tmerge.c
index 0c6e7d8..ad8faba 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: bitblt.c,v 1.10 2002-09-07 07:15:50 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,643 +7,76 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
-COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
+COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 */
 
-/*
- *
- * Routines for bitblt's.
- *
- * Old Log:
- * Revision 1.29  1995/03/14  12:14:28  john
- * Added code to double horz/vert bitblts.
- *
- * Revision 1.28  1995/03/13  09:01:48  john
- * Fixed bug with VFX1 screen not tall enough.
- *
- * Revision 1.27  1995/03/01  15:38:10  john
- * Better ModeX support.
- *
- * Revision 1.26  1994/12/15  12:19:00  john
- * Added gr_bm_bitblt (clipped!) function.
- *
- * Revision 1.25  1994/12/09  18:58:42  matt
- * Took out include of 3d.h
- *
- * Revision 1.24  1994/11/28  17:08:32  john
- * Took out some unused functions in linear.asm, moved
- * gr_linear_movsd from linear.asm to bitblt.c, made sure that
- * the code in ibiblt.c sets the direction flags before rep movsing.
- *
- * Revision 1.22  1994/11/23  16:04:00  john
- * Fixed generic rle'ing to use new bit method.
- *
- * Revision 1.21  1994/11/18  22:51:03  john
- * Changed a bunch of shorts to ints in calls.
- *
- * Revision 1.20  1994/11/10  15:59:48  john
- * Fixed bugs with canvas's being created with bogus bm_flags.
- *
- * Revision 1.19  1994/11/09  21:03:35  john
- * Added RLE for svga gr_ubitmap.
- *
- * Revision 1.18  1994/11/09  17:41:29  john
- * Made a slow version of rle bitblt to svga, modex.
- *
- * Revision 1.17  1994/11/09  16:35:15  john
- * First version with working RLE bitmaps.
- *
- * Revision 1.16  1994/11/04  10:06:58  john
- * Added fade table for fading fonts. Made font that partially clips
- * not print a warning message.
- *
- * Revision 1.15  1994/09/22  16:08:38  john
- * Fixed some palette stuff.
- *
- * Revision 1.14  1994/09/19  11:44:27  john
- * Changed call to allocate selector to the dpmi module.
- *
- * Revision 1.13  1994/08/08  13:03:00  john
- * Fixed bug in gr_bitmap in modex
- *
- * Revision 1.12  1994/07/13  19:47:23  john
- * Fixed bug with modex bitblt to page 2 not working.
- *
- * Revision 1.11  1994/05/31  11:10:52  john
- * *** empty log message ***
- *
- * Revision 1.10  1994/03/18  15:24:34  matt
- * Removed interlace stuff
- *
- * Revision 1.9  1994/02/18  15:32:20  john
- * *** empty log message ***
- *
- * Revision 1.8  1994/02/01  13:22:54  john
- * *** empty log message ***
- *
- * Revision 1.7  1994/01/13  08:28:25  mike
- * Modify rect copy to copy alternate scanlines when in interlaced mode.
- *
- * Revision 1.6  1993/12/28  12:09:46  john
- * added lbitblt.asm
- *
- * Revision 1.5  1993/10/26  13:18:09  john
- * *** empty log message ***
- *
- * Revision 1.4  1993/10/15  16:23:30  john
- * y
- *
- * Revision 1.3  1993/09/13  17:52:58  john
- * Fixed bug in BitBlt linear to SVGA
- *
- * Revision 1.2  1993/09/08  14:47:00  john
- * Made bitmap00 add rowsize instead of bitmap width.
- * Other routines might have this problem too.
- *
- * Revision 1.1  1993/09/08  11:43:01  john
- * Initial revision
- *
- */
-
 #ifdef HAVE_CONFIG_H
 #include <conf.h>
 #endif
 
 #ifdef HAVE_CONFIG_H
 #include <conf.h>
 #endif
 
-#include "pa_enabl.h"                   //$$POLY_ACC
+#include <string.h>
 #include "u_mem.h"
 #include "gr.h"
 #include "grdef.h"
 #include "rle.h"
 #include "u_mem.h"
 #include "gr.h"
 #include "grdef.h"
 #include "rle.h"
-#include "mono.h"
-#include "byteswap.h"       // because of rle code that has short for row offsets
 #include "error.h"
 
 #ifdef OGL
 #include "ogl_init.h"
 #endif
 
 #include "error.h"
 
 #ifdef OGL
 #include "ogl_init.h"
 #endif
 
-#if defined(POLY_ACC)
-#include "poly_acc.h"
-#endif
-
 int gr_bitblt_dest_step_shift = 0;
 int gr_bitblt_double = 0;
 ubyte *gr_bitblt_fade_table=NULL;
 
 int gr_bitblt_dest_step_shift = 0;
 int gr_bitblt_double = 0;
 ubyte *gr_bitblt_fade_table=NULL;
 
-extern void gr_vesa_bitmap( grs_bitmap * source, grs_bitmap * dest, int x, int y );
-
-void gr_linear_movsd( ubyte * source, ubyte * dest, unsigned int nbytes);
-// This code aligns edi so that the destination is aligned to a dword boundry before rep movsd
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux gr_linear_movsd parm [esi] [edi] [ecx] modify exact [ecx esi edi eax ebx] = \
-" cld "                                        \
-" mov          ebx, ecx        "       \
-" mov          eax, edi"       \
-" and          eax, 011b"      \
-" jz           d_aligned"      \
-" mov          ecx, 4"         \
-" sub          ecx, eax"       \
-" sub          ebx, ecx"       \
-" rep          movsb"          \
-" d_aligned: "                 \
-" mov          ecx, ebx"       \
-" shr          ecx, 2"         \
-" rep  movsd"          \
-" mov          ecx, ebx"       \
-" and  ecx, 11b"       \
-" rep  movsb";
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
-inline void gr_linear_movsd(ubyte *src, ubyte *dest, unsigned int num_pixels) {
-       int dummy[3];
- __asm__ __volatile__ (
-" cld;"
-" movl      %%ecx, %%ebx;"
-" movl      %%edi, %%eax;"
-" andl      $3, %%eax;"
-" jz        0f;"
-" movl      $4, %%ecx;"
-" subl      %%eax,%%ecx;"
-" subl      %%ecx,%%ebx;"
-" rep;      movsb;"
-"0: ;"
-" movl      %%ebx, %%ecx;"
-" shrl      $2, %%ecx;"
-" rep;      movsl;"
-" movl      %%ebx, %%ecx;"
-" andl      $3, %%ecx;"
-" rep;      movsb"
- : "=S" (dummy[0]), "=D" (dummy[1]), "=c" (dummy[2])
- : "0" (src), "1" (dest), "2" (num_pixels)
- :     "%eax", "%ebx");
-}
-
-#elif !defined(NO_ASM) && defined(_MSC_VER)
-
-__inline void gr_linear_movsd(ubyte *src, ubyte *dest, unsigned int num_pixels)
-{
- __asm {
-   mov esi, [src]
-   mov edi, [dest]
-   mov ecx, [num_pixels]
-   cld
-   mov ebx, ecx
-   mov eax, edi
-   and eax, 011b
-   jz d_aligned
-   mov ecx, 4
-   sub ecx, eax
-   sub ebx, ecx
-   rep movsb
-d_aligned:
-   mov ecx, ebx
-   shr ecx, 2
-   rep movsd
-   mov ecx, ebx
-   and ecx, 11b
-   rep movsb
- }
-}
-
-#else // NO_ASM or unknown compiler
-
-#define THRESHOLD   8
-
-#ifdef RELEASE
-#define test_byteblit   0
-#else
-ubyte test_byteblit = 0;
-#endif
-
-void gr_linear_movsd(ubyte * src, ubyte * dest, unsigned int num_pixels )
-{
-       int i;
-       uint n, r;
-       double *d, *s;
-       ubyte *d1, *s1;
-
-// check to see if we are starting on an even byte boundry
-// if not, move appropriate number of bytes to even
-// 8 byte boundry
-
-       if ( (num_pixels < THRESHOLD) || (((int)src & 0x7) != ((int)dest & 0x7)) || test_byteblit ) {
-               for (i = 0; i < num_pixels; i++)
-                       *dest++ = *src++;
-               return;
-       }
-
-       i = 0;
-       if ((r = (int)src & 0x7)) {
-               for (i = 0; i < 8 - r; i++)
-                       *dest++ = *src++;
-       }
-       num_pixels -= i;
-
-       n = num_pixels / 8;
-       r = num_pixels % 8;
-       s = (double *)src;
-       d = (double *)dest;
-       for (i = 0; i < n; i++)
-               *d++ = *s++;
-       s1 = (ubyte *)s;
-       d1 = (ubyte *)d;
-       for (i = 0; i < r; i++)
-               *d1++ = *s1++;
-}
-
-#endif //#ifdef NO_ASM
-
-
-static void gr_linear_rep_movsdm(ubyte * src, ubyte * dest, unsigned int num_pixels );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux gr_linear_rep_movsdm parm [esi] [edi] [ecx] modify exact [ecx esi edi eax] = \
-"nextpixel:"                \
-    "mov    al,[esi]"       \
-    "inc    esi"            \
-    "cmp    al, " TRANSPARENCY_COLOR_STR   \
-    "je skip_it"            \
-    "mov    [edi], al"      \
-"skip_it:"                  \
-    "inc    edi"            \
-    "dec    ecx"            \
-    "jne    nextpixel";
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
-static inline void gr_linear_rep_movsdm(ubyte * src, ubyte * dest, unsigned int num_pixels ) {
-       int dummy[3];
- __asm__ __volatile__ (
-"0: ;"
-" movb  (%%esi), %%al;"
-" incl  %%esi;"
-" cmpb  $" TRANSPARENCY_COLOR_STR ", %%al;"
-" je    1f;"
-" movb  %%al,(%%edi);"
-"1: ;"
-" incl  %%edi;"
-" decl  %%ecx;"
-" jne   0b"
- : "=S" (dummy[0]), "=D" (dummy[1]), "=c" (dummy[2])
- : "0" (src), "1" (dest), "2" (num_pixels)
- : "%eax");
-}
-
-#elif !defined(NO_ASM) && defined(_MSC_VER)
-
-__inline void gr_linear_rep_movsdm(ubyte * src, ubyte * dest, unsigned int num_pixels )
-{
- __asm {
-  nextpixel:
-  mov esi, [src]
-  mov edi, [dest]
-  mov ecx, [num_pixels]
-  mov al,  [esi]
-  inc esi
-  cmp al,  TRANSPARENCY_COLOR
-  je skip_it
-  mov [edi], al
-  skip_it:
-  inc edi
-  dec ecx
-  jne nextpixel
- }
-}
-
-#else
-
-static void gr_linear_rep_movsdm(ubyte * src, ubyte * dest, unsigned int num_pixels )
-{
-       int i;
-       for (i=0; i<num_pixels; i++ ) {
-               if (*src != TRANSPARENCY_COLOR )
-                       *dest = *src;
-               dest++;
-               src++;
-       }
-}
-
-#endif
-
-static void gr_linear_rep_movsdm_faded(ubyte * src, ubyte * dest, unsigned int num_pixels, ubyte fade_value );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux gr_linear_rep_movsdm_faded parm [esi] [edi] [ecx] [ebx] modify exact [ecx esi edi eax ebx] = \
-"  xor eax, eax"                    \
-"  mov ah, bl"                      \
-"nextpixel:"                        \
-    "mov    al,[esi]"               \
-    "inc    esi"                    \
-    "cmp    al, " TRANSPARENCY_COLOR_STR     \
-    "je skip_it"                    \
-    "mov  al, gr_fade_table[eax]"   \
-    "mov    [edi], al"              \
-"skip_it:"                          \
-    "inc    edi"                    \
-    "dec    ecx"                    \
-    "jne    nextpixel";
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
-/* #pragma aux gr_linear_rep_movsdm_faded parm [esi] [edi] [ecx] [ebx] modify exact [ecx esi edi eax ebx] */
-static inline void gr_linear_rep_movsdm_faded(ubyte * src, ubyte * dest, unsigned int num_pixels, ubyte fade_value ) {
-       int dummy[4];
- __asm__ __volatile__ (
-"  xorl   %%eax, %%eax;"
-"  movb   %%bl, %%ah;"
-"0:;"
-"  movb   (%%esi), %%al;"
-"  incl   %%esi;"
-"  cmpb   $" TRANSPARENCY_COLOR_STR ", %%al;"
-"  je 1f;"
-#ifdef __linux__
-"  movb   gr_fade_table(%%eax), %%al;"
-#else
-"  movb   _gr_fade_table(%%eax), %%al;"
-#endif
-"  movb   %%al, (%%edi);"
-"1:"
-"  incl   %%edi;"
-"  decl   %%ecx;"
-"  jne    0b"
- : "=S" (dummy[0]), "=D" (dummy[1]), "=c" (dummy[2]), "=b" (dummy[3])
- : "0" (src), "1" (dest), "2" (num_pixels), "3" (fade_value)
- : "%eax");
-}
-
-#elif !defined(NO_ASM) && defined(_MSC_VER)
-
-__inline void gr_linear_rep_movsdm_faded(void * src, void * dest, unsigned int num_pixels, ubyte fade_value )
-{
- __asm {
-  mov esi, [src]
-  mov edi, [dest]
-  mov ecx, [num_pixels]
-  movzx ebx, byte ptr [fade_value]
-  xor eax, eax
-  mov ah, bl
-  nextpixel:
-  mov al, [esi]
-  inc esi
-  cmp al, TRANSPARENCY_COLOR
-  je skip_it
-  mov al, gr_fade_table[eax]
-  mov [edi], al
-  skip_it:
-  inc edi
-  dec ecx
-  jne nextpixel
- }
-}
-
-#else
-
-static void gr_linear_rep_movsdm_faded(ubyte * src, ubyte * dest, unsigned int num_pixels, ubyte fade_value )
-{
-       int i;
-       ubyte source;
-       ubyte *fade_base;
-
-       fade_base = gr_fade_table + (fade_value * 256);
-
-       for (i=num_pixels; i != 0; i-- )
-       {
-               source = *src;
-               if (source != (ubyte)TRANSPARENCY_COLOR )
-                       *dest = *(fade_base + source);
-               dest++;
-               src++;
-       }
-}
-
-#endif
-
-
-static void gr_linear_rep_movsd_2x(ubyte * src, ubyte * dest, unsigned int num_dest_pixels );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux gr_linear_rep_movsd_2x parm [esi] [edi] [ecx] modify exact [ecx esi edi eax ebx] = \
-    "shr    ecx, 1"             \
-    "jnc    nextpixel"          \
-    "mov    al, [esi]"          \
-    "mov    [edi], al"          \
-    "inc    esi"                \
-    "inc    edi"                \
-    "cmp    ecx, 0"             \
-    "je done"                   \
-"nextpixel:"                    \
-    "mov    al,[esi]"           \
-    "mov    ah, al"             \
-    "mov    [edi], ax"          \
-    "inc    esi"                \
-    "inc    edi"                \
-    "inc    edi"                \
-    "dec    ecx"                \
-    "jne    nextpixel"          \
-"done:"
-
-#elif !defined(NO_ASM) && defined (__GNUC__)
-
-static inline void gr_linear_rep_movsd_2x(ubyte * src, ubyte * dest, unsigned int num_dest_pixels ) {
-/* #pragma aux gr_linear_rep_movsd_2x parm [esi] [edi] [ecx] modify exact [ecx esi edi eax ebx] */
-       int dummy[3];
- __asm__ __volatile__ (
-    "shrl   $1, %%ecx;"
-    "jnc    0f;"
-    "movb   (%%esi), %%al;"
-    "movb   %%al, (%%edi);"
-    "incl   %%esi;"
-    "incl   %%edi;"
-    "cmpl   $0, %%ecx;"
-    "je 1f;"
-"0: ;"
-    "movb   (%%esi), %%al;"
-    "movb   %%al, %%ah;"
-    "movw   %%ax, (%%edi);"
-    "incl   %%esi;"
-    "incl   %%edi;"
-    "incl   %%edi;"
-    "decl   %%ecx;"
-    "jne    0b;"
-"1:"
- : "=S" (dummy[0]), "=D" (dummy[1]), "=c" (dummy[2])
- : "0" (src), "1" (dest), "2" (num_dest_pixels)
- :      "%eax");
-}
-
-#elif !defined(NO_ASM) && defined(_MSC_VER)
-
-__inline void gr_linear_rep_movsd_2x(ubyte * src, ubyte * dest, unsigned int num_dest_pixels )
-{
- __asm {
-  mov esi, [src]
-  mov edi, [dest]
-  mov ecx, [num_dest_pixels]
-  shr ecx, 1
-  jnc nextpixel
-  mov al, [esi]
-  mov [edi], al
-  inc esi
-  inc edi
-  cmp ecx, 0
-  je done
-nextpixel:
-  mov al, [esi]
-  mov ah, al
-  mov [edi], ax
-  inc esi
-  inc edi
-  inc edi
-  dec ecx
-  jne nextpixel
-done:
- }
-}
-
-#else
-
-static void gr_linear_rep_movsd_2x(ubyte *src, ubyte *dest, unsigned int num_pixels)
-{
-       double  *d = (double *)dest;
-       uint    *s = (uint *)src;
-       uint    doubletemp[2];
-       uint    temp, work;
-       int     i;
-
-       if (num_pixels & 0x3) {
-               // not a multiple of 4?  do single pixel at a time
-               for (i=0; i<num_pixels; i++) {
-                       *dest++ = *src;
-                       *dest++ = *src++;
+void gr_bm_ubitblt00_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
+void gr_bm_ubitblt00m_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
+void gr_bm_ubitblt0x_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest, int masked);
+
+void gr_bm_ubitblt01(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
+void gr_bm_ubitblt02(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
+
+#include "linear.h"
+#include "modex.h"
+#include "vesa.h"
+
+#ifdef NO_ASM
+void gr_linear_movsd( ubyte * source, ubyte * dest, unsigned int nbytes) {
+       memcpy(dest,source,nbytes);
+}
+
+void gr_linear_rep_movsdm(ubyte *src, ubyte *dest, int num_pixels) {
+       register ubyte c;
+       while (num_pixels--)
+               if ((c=*src++)!=255)
+                       *dest++=c;
+               else    dest++;
+}
+
+void gr_linear_rep_movsdm_faded(ubyte * src, ubyte * dest, int num_pixels, ubyte fade_value ) {
+       register ubyte c;
+       while (num_pixels--)
+               if ((c=*src++)!=255)
+                       *dest++=gr_fade_table[((int)fade_value<<8)|(int)c];
+               else    dest++;
+}
+void gr_linear_rep_movsd_2x(ubyte * source, ubyte * dest, uint nbytes ) {
+       register ubyte c;
+       while (nbytes--) {
+               if (nbytes&1)
+                       *dest++=*source++;
+               else {
+                       c=*source++;
+                       *((unsigned short *)dest)++=((short)c<<8)|(short)c;
                }
                }
-               return;
-       }
-
-       for (i = 0; i < num_pixels / 4; i++) {
-               temp = work = *s++;
-
-               temp = ((temp >> 8) & 0x00FFFF00) | (temp & 0xFF0000FF); // 0xABCDEFGH -> 0xABABCDEF
-               temp = ((temp >> 8) & 0x000000FF) | (temp & 0xFFFFFF00); // 0xABABCDEF -> 0xABABCDCD
-               doubletemp[0] = temp;
-
-               work = ((work << 8) & 0x00FFFF00) | (work & 0xFF0000FF); // 0xABCDEFGH -> 0xABEFGHGH
-               work = ((work << 8) & 0xFF000000) | (work & 0x00FFFFFF); // 0xABEFGHGH -> 0xEFEFGHGH
-               doubletemp[1] = work;
-
-               *d = *(double *) &(doubletemp[0]);
-               d++;
        }
 }
        }
 }
-
-#endif
-
-
-#ifdef __MSDOS__
-
-static void modex_copy_column(ubyte * src, ubyte * dest, int num_pixels, int src_rowsize, int dest_rowsize );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux modex_copy_column parm [esi] [edi] [ecx] [ebx] [edx] modify exact [ecx esi edi] = \
-"nextpixel:"            \
-    "mov    al,[esi]"   \
-    "add    esi, ebx"   \
-    "mov    [edi], al"  \
-    "add    edi, edx"   \
-    "dec    ecx"        \
-    "jne    nextpixel"
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
-static inline void modex_copy_column(ubyte * src, ubyte * dest, int num_pixels, int src_rowsize, int dest_rowsize ) {
-/*#pragma aux modex_copy_column parm [esi] [edi] [ecx] [ebx] [edx] modify exact [ecx esi edi] = */
- __asm__ __volatile__ (
-"0: ;"
-    "movb   (%%esi), %%al;"
-    "addl   %%ebx, %%esi;"
-    "movb   %%al, (%%edi);"
-    "addl   %%edx, %%edi;"
-    "decl   %%ecx;"
-    "jne    0b"
- : : "S" (src), "D" (dest), "c" (num_pixels), "b" (src_rowsize), "d" (dest_rowsize)
- : "%eax", "%ecx", "%esi", "%edi");
-}
-
-#else
-
-static void modex_copy_column(ubyte * src, ubyte * dest, int num_pixels, int src_rowsize, int dest_rowsize )
-{
-       src = src;
-       dest = dest;
-       num_pixels = num_pixels;
-       src_rowsize = src_rowsize;
-       dest_rowsize = dest_rowsize;
-       Int3();
-}
-
 #endif
 #endif
-
-
-static void modex_copy_column_m(ubyte * src, ubyte * dest, int num_pixels, int src_rowsize, int dest_rowsize );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux modex_copy_column_m parm [esi] [edi] [ecx] [ebx] [edx] modify exact [ecx esi edi] = \
-"nextpixel:"            \
-    "mov    al,[esi]"   \
-    "add    esi, ebx"   \
-    "cmp    al, " TRANSPARENCY_COLOR_STR   \
-    "je skip_itx"       \
-    "mov    [edi], al"  \
-"skip_itx:"             \
-    "add    edi, edx"   \
-    "dec    ecx"        \
-    "jne    nextpixel"
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
-static inline void modex_copy_column_m(ubyte * src, ubyte * dest, int num_pixels, int src_rowsize, int dest_rowsize ) {
-/* #pragma aux modex_copy_column_m parm [esi] [edi] [ecx] [ebx] [edx] modify exact [ecx esi edi] = */
- int dummy[3];
- __asm__ __volatile__ (
-"0: ;"
-    "movb    (%%esi), %%al;"
-    "addl    %%ebx, %%esi;"
-    "cmpb    $" TRANSPARENCY_COLOR_STR ", %%al;"
-    "je 1f;"
-    "movb   %%al, (%%edi);"
-"1: ;"
-    "addl   %%edx, %%edi;"
-    "decl   %%ecx;"
-    "jne    0b"
- : "=c" (dummy[0]), "=S" (dummy[1]), "=D" (dummy[2])
- : "1" (src), "2" (dest), "0" (num_pixels), "b" (src_rowsize), "d" (dest_rowsize)
- :      "%eax" );
-}
-
-#else
-
-static void modex_copy_column_m(ubyte * src, ubyte * dest, int num_pixels, int src_rowsize, int dest_rowsize )
-{
-       src = src;
-       dest = dest;
-       num_pixels = num_pixels;
-       src_rowsize = src_rowsize;
-       dest_rowsize = dest_rowsize;
-       Int3();
-}
-
+#ifdef D1XD3D
+#include "d3dhelp.h"
 #endif
 
 #endif
 
-#endif /* __MSDOS__ */
-
 void gr_ubitmap00( int x, int y, grs_bitmap *bm )
 {
        register int y1;
 void gr_ubitmap00( int x, int y, grs_bitmap *bm )
 {
        register int y1;
@@ -681,7 +113,7 @@ void gr_ubitmap00m( int x, int y, grs_bitmap *bm )
 
        src = bm->bm_data;
 
 
        src = bm->bm_data;
 
-       if (gr_bitblt_fade_table==NULL) {
+       if (gr_bitblt_fade_table==NULL) {
                for (y1=0; y1 < bm->bm_h; y1++ )    {
                        gr_linear_rep_movsdm( src, dest, bm->bm_w );
                        src += bm->bm_rowsize;
                for (y1=0; y1 < bm->bm_h; y1++ )    {
                        gr_linear_rep_movsdm( src, dest, bm->bm_w );
                        src += bm->bm_rowsize;
@@ -696,193 +128,23 @@ void gr_ubitmap00m( int x, int y, grs_bitmap *bm )
        }
 }
 
        }
 }
 
-#if 0
-"       jmp     aligned4        "   \
-"       mov eax, edi            "   \
-"       and eax, 11b            "   \
-"       jz      aligned4        "   \
-"       mov ebx, 4              "   \
-"       sub ebx, eax            "   \
-"       sub ecx, ebx            "   \
-"alignstart:                    "   \
-"       mov al, [esi]           "   \
-"       add esi, 4              "   \
-"       mov [edi], al           "   \
-"       inc edi                 "   \
-"       dec ebx                 "   \
-"       jne alignstart          "   \
-"aligned4:                      "
-#endif
-
-#ifdef __MSDOS__
-
-static void modex_copy_scanline( ubyte * src, ubyte * dest, int npixels );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux modex_copy_scanline parm [esi] [edi] [ecx] modify exact [ecx esi edi eax ebx edx] = \
-"       mov ebx, ecx            "   \
-"       and ebx, 11b            "   \
-"       shr ecx, 2              "   \
-"       cmp ecx, 0              "   \
-"       je      no2group        "   \
-"next4pixels:                   "   \
-"       mov al, [esi+8]         "   \
-"       mov ah, [esi+12]        "   \
-"       shl eax, 16             "   \
-"       mov al, [esi]           "   \
-"       mov ah, [esi+4]         "   \
-"       mov [edi], eax          "   \
-"       add esi, 16             "   \
-"       add edi, 4              "   \
-"       dec ecx                 "   \
-"       jne next4pixels         "   \
-"no2group:                      "   \
-"       cmp ebx, 0              "   \
-"       je      done2           "   \
-"finishend:                     "   \
-"       mov al, [esi]           "   \
-"       add esi, 4              "   \
-"       mov [edi], al           "   \
-"       inc edi                 "   \
-"       dec ebx                 "   \
-"       jne finishend           "   \
-"done2:                         ";
-
-#elif !defined (NO_ASM) && defined(__GNUC__)
-
-static inline void modex_copy_scanline( ubyte * src, ubyte * dest, int npixels ) {
-/* #pragma aux modex_copy_scanline parm [esi] [edi] [ecx] modify exact [ecx esi edi eax ebx edx] */
-int dummy[3];
- __asm__ __volatile__ (
-"       movl %%ecx, %%ebx;"
-"       andl $3, %%ebx;"
-"       shrl $2, %%ecx;"
-"       cmpl $0, %%ecx;"
-"       je   1f;"
-"0: ;"
-"       movb 8(%%esi), %%al;"
-"       movb 12(%%esi), %%ah;"
-"       shll $16, %%eax;"
-"       movb (%%esi), %%al;"
-"       movb 4(%%esi), %%ah;"
-"       movl %%eax, (%%edi);"
-"       addl $16, %%esi;"
-"       addl $4, %%edi;"
-"       decl %%ecx;"
-"       jne 0b;"
-"1: ;"
-"       cmpl $0, %%ebx;"
-"       je      3f;"
-"2: ;"
-"       movb (%%esi), %%al;"
-"       addl $4, %%esi;"
-"       movb %%al, (%%edi);"
-"       incl %%edi;"
-"       decl %%ebx;"
-"       jne 2b;"
-"3:"
- : "=c" (dummy[0]), "=S" (dummy[1]), "=D" (dummy[2])
- : "1" (src), "2" (dest), "0" (npixels)
- :      "%eax", "%ebx", "%edx" );
-}
-
-#else
-
-static void modex_copy_scanline( ubyte * src, ubyte * dest, int npixels )
-{
-       src = src;
-       dest = dest;
-       npixels = npixels;
-       Int3();
-}
-
-#endif
-
-static void modex_copy_scanline_2x( ubyte * src, ubyte * dest, int npixels );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux modex_copy_scanline_2x parm [esi] [edi] [ecx] modify exact [ecx esi edi eax ebx edx] = \
-"       mov ebx, ecx            "   \
-"       and ebx, 11b            "   \
-"       shr ecx, 2              "   \
-"       cmp ecx, 0              "   \
-"       je      no2group        "   \
-"next4pixels:                   "   \
-"       mov al, [esi+4]         "   \
-"       mov ah, [esi+6]         "   \
-"       shl eax, 16             "   \
-"       mov al, [esi]           "   \
-"       mov ah, [esi+2]         "   \
-"       mov [edi], eax          "   \
-"       add esi, 8              "   \
-"       add edi, 4              "   \
-"       dec ecx                 "   \
-"       jne next4pixels         "   \
-"no2group:                      "   \
-"       cmp ebx, 0              "   \
-"       je      done2           "   \
-"finishend:                     "   \
-"       mov al, [esi]           "   \
-"       add esi, 2              "   \
-"       mov [edi], al           "   \
-"       inc edi                 "   \
-"       dec ebx                 "   \
-"       jne finishend           "   \
-"done2:                         ";
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
-static inline void modex_copy_scanline_2x( ubyte * src, ubyte * dest, int npixels ) {
-/* #pragma aux modex_copy_scanline_2x parm [esi] [edi] [ecx] modify exact [ecx esi edi eax ebx edx] = */
-int dummy[3];
- __asm__ __volatile__ (
-"       movl %%ecx, %%ebx;"
-"       andl $3, %%ebx;"
-"       shrl $2, %%ecx;"
-"       cmpl $0, %%ecx;"
-"       je 1f;"
-"0: ;"
-"       movb 4(%%esi), %%al;"
-"       movb 6(%%esi), %%ah;"
-"       shll $16, %%eax;"
-"       movb (%%esi), %%al;"
-"       movb 2(%%esi), %%ah;"
-"       movl %%eax, (%%edi);"
-"       addl $8, %%esi;"
-"       addl $4, %%edi;"
-"       decl %%ecx;"
-"       jne 0b;"
-"1: ;"
-"       cmp $0, %%ebx;"
-"       je  3f;"
-"2:"
-"       movb (%%esi),%%al;"
-"       addl $2, %%esi;"
-"       movb %%al, (%%edi);"
-"       incl %%edi;"
-"       decl %%ebx;"
-"       jne 2b;"
-"3:"
- : "=c" (dummy[0]), "=S" (dummy[1]), "=D" (dummy[2])
- : "1" (src), "2" (dest), "0" (npixels)
- :      "%eax", "%ebx", "%edx" );
-}
-
-#else
-
-static void modex_copy_scanline_2x( ubyte * src, ubyte * dest, int npixels )
-{
-       src = src;
-       dest = dest;
-       npixels = npixels;
-       Int3();
-}
-
-#endif
-
-
+//"             jmp     aligned4                                "       
+//"             mov     eax, edi                                "       
+//"             and     eax, 11b                                "       
+//"             jz              aligned4                        "       
+//"             mov     ebx, 4                                  "       
+//"             sub     ebx, eax                                "       
+//"             sub     ecx, ebx                                "       
+//"alignstart:                                                  "       
+//"             mov     al, [esi]                               "       
+//"             add     esi, 4                                  "       
+//"             mov     [edi], al                               "       
+//"             inc     edi                                     "       
+//"             dec     ebx                                     "       
+//"             jne     alignstart                              "       
+//"aligned4:                                                    "       
+
+#ifdef __DJGPP__
 // From Linear to ModeX
 void gr_bm_ubitblt01(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
 // From Linear to ModeX
 void gr_bm_ubitblt01(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
@@ -897,28 +159,28 @@ void gr_bm_ubitblt01(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
        sstep = src->bm_rowsize;
        dstep = dest->bm_rowsize << gr_bitblt_dest_step_shift;
 
        sstep = src->bm_rowsize;
        dstep = dest->bm_rowsize << gr_bitblt_dest_step_shift;
 
-       if (!gr_bitblt_double) {
-               for (plane=0; plane<4; plane++ ) {
+       if (!gr_bitblt_double)  {
+               for (plane=0; plane<4; plane++ )        {
                        gr_modex_setplane( (plane+dx)&3 );
                        sbits = src->bm_data + (src->bm_rowsize * sy) + sx + plane;
                        dbits = &gr_video_memory[(dest->bm_rowsize * dy) + ((plane+dx)/4) ];
                        w1 = w >> 2;
                        if ( (w&3) > plane ) w1++;
                        gr_modex_setplane( (plane+dx)&3 );
                        sbits = src->bm_data + (src->bm_rowsize * sy) + sx + plane;
                        dbits = &gr_video_memory[(dest->bm_rowsize * dy) + ((plane+dx)/4) ];
                        w1 = w >> 2;
                        if ( (w&3) > plane ) w1++;
-                       for (y=dy; y < dy+h; y++ ) {
-                               modex_copy_scanline( sbits, dbits, w1 );
+                       for (y=dy; y < dy+h; y++ )              {
+                               modex_copy_scanline( sbits, dbits, w1 );                
                                dbits += dstep;
                                sbits += sstep;
                        }
                }
        } else {
                                dbits += dstep;
                                sbits += sstep;
                        }
                }
        } else {
-               for (plane=0; plane<4; plane++ ) {
+               for (plane=0; plane<4; plane++ )        {
                        gr_modex_setplane( (plane+dx)&3 );
                        sbits = src->bm_data + (src->bm_rowsize * sy) + sx + plane/2;
                        dbits = &gr_video_memory[(dest->bm_rowsize * dy) + ((plane+dx)/4) ];
                        w1 = w >> 2;
                        if ( (w&3) > plane ) w1++;
                        gr_modex_setplane( (plane+dx)&3 );
                        sbits = src->bm_data + (src->bm_rowsize * sy) + sx + plane/2;
                        dbits = &gr_video_memory[(dest->bm_rowsize * dy) + ((plane+dx)/4) ];
                        w1 = w >> 2;
                        if ( (w&3) > plane ) w1++;
-                       for (y=dy; y < dy+h; y++ ) {
-                               modex_copy_scanline_2x( sbits, dbits, w1 );
+                       for (y=dy; y < dy+h; y++ )              {
+                               modex_copy_scanline_2x( sbits, dbits, w1 );             
                                dbits += dstep;
                                sbits += sstep;
                        }
                                dbits += dstep;
                                sbits += sstep;
                        }
@@ -932,17 +194,17 @@ void gr_bm_ubitblt01m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
 {
        //ubyte * dbits1;
        //ubyte * sbits1;
 {
        //ubyte * dbits1;
        //ubyte * sbits1;
-
+       
        ubyte * dbits;
        ubyte * sbits;
 
        int x;
        ubyte * dbits;
        ubyte * sbits;
 
        int x;
-       //int y;
+//     int y;
 
        sbits =   src->bm_data  + (src->bm_rowsize * sy) + sx;
        dbits =   &gr_video_memory[(dest->bm_rowsize * dy) + dx/4];
 
 
        sbits =   src->bm_data  + (src->bm_rowsize * sy) + sx;
        dbits =   &gr_video_memory[(dest->bm_rowsize * dy) + dx/4];
 
-       for (x=dx; x < dx+w; x++ ) {
+       for (x=dx; x < dx+w; x++ )      {       
                gr_modex_setplane( x&3 );
 
                //sbits1 = sbits;
                gr_modex_setplane( x&3 );
 
                //sbits1 = sbits;
@@ -951,7 +213,7 @@ void gr_bm_ubitblt01m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
                //      *dbits1 = *sbits1;
                //      sbits1 += src_bm_rowsize;
                //      dbits1 += dest_bm_rowsize;
                //      *dbits1 = *sbits1;
                //      sbits1 += src_bm_rowsize;
                //      dbits1 += dest_bm_rowsize;
-               //}
+               //      }
                modex_copy_column_m(sbits, dbits, h, src->bm_rowsize, dest->bm_rowsize << gr_bitblt_dest_step_shift );
 
                sbits++;
                modex_copy_column_m(sbits, dbits, h, src->bm_rowsize, dest->bm_rowsize << gr_bitblt_dest_step_shift );
 
                sbits++;
@@ -960,7 +222,7 @@ void gr_bm_ubitblt01m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
        }
 }
 
        }
 }
 
-#endif /* __MSDOS__ */
+#endif
 
 
 void gr_ubitmap012( int x, int y, grs_bitmap *bm )
 
 
 void gr_ubitmap012( int x, int y, grs_bitmap *bm )
@@ -985,9 +247,9 @@ void gr_ubitmap012m( int x, int y, grs_bitmap *bm )
 
        src = bm->bm_data;
 
 
        src = bm->bm_data;
 
-       for (y1=y; y1 < (y+bm->bm_h); y1++ ) {
-               for (x1=x; x1 < (x+bm->bm_w); x1++ ) {
-                       if ( *src != TRANSPARENCY_COLOR ) {
+       for (y1=y; y1 < (y+bm->bm_h); y1++ )    {
+               for (x1=x; x1 < (x+bm->bm_w); x1++ )    {
+                       if ( *src != 255 )      {
                                gr_setcolor( *src );
                                gr_upixel( x1, y1 );
                        }
                                gr_setcolor( *src );
                                gr_upixel( x1, y1 );
                        }
@@ -996,146 +258,135 @@ void gr_ubitmap012m( int x, int y, grs_bitmap *bm )
        }
 }
 
        }
 }
 
-#if defined(POLY_ACC)
-void gr_ubitmap05( int x, int y, grs_bitmap *bm )
+
+void gr_ubitmapGENERIC(int x, int y, grs_bitmap * bm)
 {
        register int x1, y1;
 {
        register int x1, y1;
-       unsigned char *src;
-       short *dst;
-       int mod;
-
-       pa_flush();
-       src = bm->bm_data;
-       dst = (short *)(DATA + y * ROWSIZE + x * PA_BPP);
-       mod = ROWSIZE / 2 - bm->bm_w;
 
 
-       for (y1=y; y1 < (y+bm->bm_h); y1++ )    {
-               for (x1=x; x1 < (x+bm->bm_w); x1++ )    {
-                       *dst++ = pa_clut[*src++];
+       for (y1=0; y1 < bm->bm_h; y1++ )    {
+               for (x1=0; x1 < bm->bm_w; x1++ )    {
+                       gr_setcolor( gr_gpixel(bm,x1,y1) );
+                       gr_upixel( x+x1, y+y1 );
                }
                }
-               dst += mod;
        }
 }
 
        }
 }
 
-void gr_ubitmap05m( int x, int y, grs_bitmap *bm )
+void gr_ubitmapGENERICm(int x, int y, grs_bitmap * bm)
 {
        register int x1, y1;
 {
        register int x1, y1;
-       unsigned char *src;
-       short *dst;
-       int mod;
-
-       pa_flush();
-       src = bm->bm_data;
-       dst = (short *)(DATA + y * ROWSIZE + x * PA_BPP);
-       mod = ROWSIZE / 2 - bm->bm_w;
+       ubyte c;
 
 
-       for (y1=y; y1 < (y+bm->bm_h); y1++ )    {
-               for (x1=x; x1 < (x+bm->bm_w); x1++ )    {
-                       if ( *src != TRANSPARENCY_COLOR )   {
-                               *dst = pa_clut[*src];
+       for (y1=0; y1 < bm->bm_h; y1++ )    {
+               for (x1=0; x1 < bm->bm_w; x1++ )    {
+                       c = gr_gpixel(bm,x1,y1);
+                       if ( c != 255 ) {
+                               gr_setcolor( c );
+                               gr_upixel( x+x1, y+y1 );
                        }
                        }
-                       src++;
-                       ++dst;
                }
                }
-               dst += mod;
        }
 }
 
        }
 }
 
-void gr_bm_ubitblt05_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       unsigned short * dbits;
-       unsigned char * sbits, scanline[640];
-       int i, data_offset, j, nextrow;
-
-       pa_flush();
-       nextrow=dest->bm_rowsize/PA_BPP;
-
-       data_offset = 1;
-       if (src->bm_flags & BM_FLAG_RLE_BIG)
-               data_offset = 2;
-
-       sbits = &src->bm_data[4 + (src->bm_h*data_offset)];
-       for (i=0; i<sy; i++ )
-               sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)]));
+void gr_ubitmap( int x, int y, grs_bitmap *bm )
+{   int source, dest;
 
 
-       dbits = (unsigned short *)(dest->bm_data + (dest->bm_rowsize * dy) + dx*PA_BPP);
+       source = bm->bm_type;
+       dest = TYPE;
 
 
-       // No interlacing, copy the whole buffer.
-       for (i=0; i < h; i++ )    {
-               gr_rle_expand_scanline( scanline, sbits, sx, sx+w-1 );
-               for(j = 0; j != w; ++j)
-                       dbits[j] = pa_clut[scanline[j]];
-               if ( src->bm_flags & BM_FLAG_RLE_BIG )
-                       sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((i+sy)*data_offset)])));
-               else
-                       sbits += (int)(src->bm_data[4+i+sy]);
-               dbits += nextrow;
+       if (source==BM_LINEAR) {
+               switch( dest )
+               {
+               case BM_LINEAR:
+                       if ( bm->bm_flags & BM_FLAG_RLE )
+                               gr_bm_ubitblt00_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap );
+                       else
+                               gr_ubitmap00( x, y, bm );
+                       return;
+#ifdef OGL
+               case BM_OGL:
+                       ogl_ubitmapm(x,y,bm);
+                       return;
+#endif
+#ifdef D1XD3D
+               case BM_DIRECTX:
+                       Assert ((int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_RENDER || (int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_DISPLAY);
+                       Win32_BlitLinearToDirectX_bm(bm, 0, 0, bm->bm_w, bm->bm_h, x, y, 0);
+                       return;
+#endif
+#ifdef __DJGPP__
+               case BM_SVGA:
+                       if ( bm->bm_flags & BM_FLAG_RLE )
+                               gr_bm_ubitblt0x_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap, 0 );
+                       else
+                               gr_bm_ubitblt02( bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap);
+                       return;
+               case BM_MODEX:
+                       gr_bm_ubitblt01(bm->bm_w, bm->bm_h, x+XOFFSET, y+YOFFSET, 0, 0, bm, &grd_curcanv->cv_bitmap);
+                       return;
+#endif
+               default:
+                       gr_ubitmap012( x, y, bm );
+                       return;
+               }
+       } else  {
+               gr_ubitmapGENERIC(x, y, bm);
        }
 }
 
        }
 }
 
-void gr_bm_ubitblt05m_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       unsigned short * dbits;
-       unsigned char * sbits, scanline[640];
-       int i, data_offset, j, nextrow;
-
-       pa_flush();
-       nextrow=dest->bm_rowsize/PA_BPP;
-       data_offset = 1;
-       if (src->bm_flags & BM_FLAG_RLE_BIG)
-               data_offset = 2;
+void gr_ubitmapm( int x, int y, grs_bitmap *bm )
+{   int source, dest;
 
 
-       sbits = &src->bm_data[4 + (src->bm_h*data_offset)];
-       for (i=0; i<sy; i++ )
-               sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)]));
 
 
-       dbits = (unsigned short *)(dest->bm_data + (dest->bm_rowsize * dy) + dx*PA_BPP);
+       source = bm->bm_type;
+       dest = TYPE;
 
 
-       // No interlacing, copy the whole buffer.
-       for (i=0; i < h; i++ )    {
-               gr_rle_expand_scanline( scanline, sbits, sx, sx+w-1 );
-               for(j = 0; j != w; ++j)
-                       if(scanline[j] != TRANSPARENCY_COLOR)
-                               dbits[j] = pa_clut[scanline[j]];
-               if ( src->bm_flags & BM_FLAG_RLE_BIG )
-                       sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((i+sy)*data_offset)])));
-               else
-                       sbits += (int)(src->bm_data[4+i+sy]);
-               dbits += nextrow;
-       }
-}
+       if (source==BM_LINEAR) {
+               switch( dest )
+               {
+               case BM_LINEAR:
+                       if ( bm->bm_flags & BM_FLAG_RLE )
+                               gr_bm_ubitblt00m_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap );
+                       else
+                               gr_ubitmap00m( x, y, bm );
+                       return;
+#ifdef OGL
+               case BM_OGL:
+                       ogl_ubitmapm(x,y,bm);
+                       return;
 #endif
 #endif
-
-void gr_ubitmapGENERIC(int x, int y, grs_bitmap * bm)
-{
-       register int x1, y1;
-
-       for (y1=0; y1 < bm->bm_h; y1++ )    {
-               for (x1=0; x1 < bm->bm_w; x1++ )    {
-                       gr_setcolor( gr_gpixel(bm,x1,y1) );
-                       gr_upixel( x+x1, y+y1 );
-               }
-       }
-}
-
-void gr_ubitmapGENERICm(int x, int y, grs_bitmap * bm)
-{
-       register int x1, y1;
-       ubyte c;
-
-       for (y1=0; y1 < bm->bm_h; y1++ ) {
-               for (x1=0; x1 < bm->bm_w; x1++ ) {
-                       c = gr_gpixel(bm,x1,y1);
-                       if ( c != TRANSPARENCY_COLOR ) {
-                               gr_setcolor( c );
-                               gr_upixel( x+x1, y+y1 );
+#ifdef D1XD3D
+               case BM_DIRECTX:
+                       if (bm->bm_w < 35 && bm->bm_h < 35) {
+                               // ugly hack needed for reticle
+                               if ( bm->bm_flags & BM_FLAG_RLE )
+                                       gr_bm_ubitblt0x_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap, 1 );
+                               else
+                                       gr_ubitmapGENERICm(x, y, bm);
+                               return;
                        }
                        }
+                       Assert ((int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_RENDER || (int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_DISPLAY);
+                       Win32_BlitLinearToDirectX_bm(bm, 0, 0, bm->bm_w, bm->bm_h, x, y, 1);
+                       return;
+#endif
+#ifdef __DJGPP__
+               case BM_SVGA:
+                       gr_ubitmapGENERICm(x, y, bm);
+                       return;
+               case BM_MODEX:
+                       gr_bm_ubitblt01m(bm->bm_w, bm->bm_h, x+XOFFSET, y+YOFFSET, 0, 0, bm, &grd_curcanv->cv_bitmap);
+                       return;
+#endif
+               default:
+                       gr_ubitmap012m( x, y, bm );
+                       return;
                }
                }
+       } else  {
+               gr_ubitmapGENERICm(x, y, bm);
        }
 }
 
 
        }
 }
 
 
-#ifdef __MSDOS__
+#ifdef __DJGPP__
 // From linear to SVGA
 void gr_bm_ubitblt02(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
 // From linear to SVGA
 void gr_bm_ubitblt02(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
@@ -1165,9 +416,9 @@ void gr_bm_ubitblt02(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
                if ( EndingOffset <= 0xFFFF )
                {
                        if ( gr_bitblt_double )
                if ( EndingOffset <= 0xFFFF )
                {
                        if ( gr_bitblt_double )
-                               gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+0xA0000), w );
+                               gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+gr_video_memory), w );
                        else
                        else
-                               gr_linear_movsd( (void *)sbits, (void *)(offset+0xA0000), w );
+                               gr_linear_movsd( (void *)sbits, (void *)(offset+gr_video_memory), w );
 
                        VideoLocation += dbpr;
                        sbits += sbpr;
 
                        VideoLocation += dbpr;
                        sbits += sbpr;
@@ -1177,76 +428,23 @@ void gr_bm_ubitblt02(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
                        BytesToMove = 0xFFFF-offset+1;
 
                        if ( gr_bitblt_double )
                        BytesToMove = 0xFFFF-offset+1;
 
                        if ( gr_bitblt_double )
-                               gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+0xA0000), BytesToMove );
+                               gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+gr_video_memory), BytesToMove );
                        else
                        else
-                               gr_linear_movsd( (void *)sbits, (void *)(offset+0xA0000), BytesToMove );
+                               gr_linear_movsd( (void *)sbits, (void *)(offset+gr_video_memory), BytesToMove );
 
                        page++;
                        gr_vesa_setpage(page);
 
                        if ( gr_bitblt_double )
 
                        page++;
                        gr_vesa_setpage(page);
 
                        if ( gr_bitblt_double )
-                               gr_linear_rep_movsd_2x( (void *)(sbits+BytesToMove/2), (void *)0xA0000, EndingOffset - 0xFFFF );
+                               gr_linear_rep_movsd_2x( (void *)(sbits+BytesToMove/2), (void *)gr_video_memory, EndingOffset - 0xFFFF );
                        else
                        else
-                               gr_linear_movsd( (void *)(sbits+BytesToMove), (void *)0xA0000, EndingOffset - 0xFFFF );
+                               gr_linear_movsd( (void *)(sbits+BytesToMove), (void *)gr_video_memory, EndingOffset - 0xFFFF );
 
                        VideoLocation += dbpr;
                        sbits += sbpr;
                }
        }
 }
 
                        VideoLocation += dbpr;
                        sbits += sbpr;
                }
        }
 }
-#endif
-
-#ifdef __MSDOS__
-
-void gr_bm_ubitblt02m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       unsigned char * sbits;
-
-       unsigned int offset, EndingOffset, VideoLocation;
-
-       int sbpr, dbpr, y1, page, BytesToMove;
-
-       sbpr = src->bm_rowsize;
-
-       dbpr = dest->bm_rowsize << gr_bitblt_dest_step_shift;
-
-       VideoLocation = (unsigned int)dest->bm_data + (dest->bm_rowsize * dy) + dx;
-
-       sbits = src->bm_data + ( sbpr*sy ) + sx;
-
-       for (y1=0; y1 < h; y1++ )    {
-
-               page    = VideoLocation >> 16;
-               offset  = VideoLocation & 0xFFFF;
-
-               gr_vesa_setpage( page );
-
-               EndingOffset = offset+w-1;
-
-               if ( EndingOffset <= 0xFFFF )
-               {
-                       gr_linear_rep_movsdm( (void *)sbits, (void *)(offset+0xA0000), w );
-
-                       VideoLocation += dbpr;
-                       sbits += sbpr;
-               }
-               else
-               {
-                       BytesToMove = 0xFFFF-offset+1;
-
-                       gr_linear_rep_movsdm( (void *)sbits, (void *)(offset+0xA0000), BytesToMove );
-
-                       page++;
-                       gr_vesa_setpage(page);
-
-                       gr_linear_rep_movsdm( (void *)(sbits+BytesToMove), (void *)0xA0000, EndingOffset - 0xFFFF );
-
-                       VideoLocation += dbpr;
-                       sbits += sbpr;
-               }
-       }
-}
-
 
 // From SVGA to linear
 void gr_bm_ubitblt20(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 
 // From SVGA to linear
 void gr_bm_ubitblt20(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
@@ -1285,9 +483,7 @@ void gr_bm_ubitblt20(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
 
        }
 }
 
        }
 }
-
-#endif
-
+#endif // __DJGPP__
 //@extern int Interlacing_on;
 
 // From Linear to Linear
 //@extern int Interlacing_on;
 
 // From Linear to Linear
@@ -1295,32 +491,38 @@ void gr_bm_ubitblt00(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
 {
        unsigned char * dbits;
        unsigned char * sbits;
 {
        unsigned char * dbits;
        unsigned char * sbits;
-       //int src_bm_rowsize_2, dest_bm_rowsize_2;
+       //int   src_bm_rowsize_2, dest_bm_rowsize_2;
        int dstep;
 
        int i;
 
        int dstep;
 
        int i;
 
-       sbits =   src->bm_data  + (src->bm_rowsize * sy) + sx;
+       sbits =   src->bm_data  + (src->bm_rowsize * sy) + sx;
        dbits =   dest->bm_data + (dest->bm_rowsize * dy) + dx;
 
        dstep = dest->bm_rowsize << gr_bitblt_dest_step_shift;
 
        // No interlacing, copy the whole buffer.
        dbits =   dest->bm_data + (dest->bm_rowsize * dy) + dx;
 
        dstep = dest->bm_rowsize << gr_bitblt_dest_step_shift;
 
        // No interlacing, copy the whole buffer.
-       for (i=0; i < h; i++ )    {
-               if (gr_bitblt_double)
-                       gr_linear_rep_movsd_2x( sbits, dbits, w );
-               else
-                       gr_linear_movsd( sbits, dbits, w );
+       if (gr_bitblt_double)
+           for (i=0; i < h; i++ )    {
+               gr_linear_rep_movsd_2x( sbits, dbits, w );
                sbits += src->bm_rowsize;
                dbits += dstep;
                sbits += src->bm_rowsize;
                dbits += dstep;
-       }
+           }
+       else
+           for (i=0; i < h; i++ )    {
+               gr_linear_movsd( sbits, dbits, w );
+               //memcpy(dbits, sbits, w);
+               sbits += src->bm_rowsize;
+               dbits += dstep;
+           }
 }
 }
+
 // From Linear to Linear Masked
 void gr_bm_ubitblt00m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
        unsigned char * dbits;
        unsigned char * sbits;
 // From Linear to Linear Masked
 void gr_bm_ubitblt00m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
        unsigned char * dbits;
        unsigned char * sbits;
-       //int src_bm_rowsize_2, dest_bm_rowsize_2;
+       //int   src_bm_rowsize_2, dest_bm_rowsize_2;
 
        int i;
 
 
        int i;
 
@@ -1329,7 +531,7 @@ void gr_bm_ubitblt00m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
 
        // No interlacing, copy the whole buffer.
 
 
        // No interlacing, copy the whole buffer.
 
-       if (gr_bitblt_fade_table==NULL) {
+       if (gr_bitblt_fade_table==NULL) {
                for (i=0; i < h; i++ )    {
                        gr_linear_rep_movsdm( sbits, dbits, w );
                        sbits += src->bm_rowsize;
                for (i=0; i < h; i++ )    {
                        gr_linear_rep_movsdm( sbits, dbits, w );
                        sbits += src->bm_rowsize;
@@ -1345,153 +547,120 @@ void gr_bm_ubitblt00m(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *
 }
 
 
 }
 
 
-extern void gr_lbitblt( grs_bitmap * source, grs_bitmap * dest, int height, int width );
-
-#if 1 //def MACINTOSH
-
-// width == number of destination pixels
-
-void gr_linear_movsd_double(ubyte *src, ubyte *dest, int width)
+void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
 {
-       double  *d = (double *)dest;
-       uint    *s = (uint *)src;
-       uint    doubletemp[2];
-       uint    temp, work;
-       int     i, num_pixels;
-
-       num_pixels = width / 2;
-       if ( (num_pixels & 0x3) || (((int)src & 0x7) != ((int)dest & 0x7)) ) {
-               // not a multiple of 4?  do single pixel at a time
-               for (i=0; i<num_pixels; i++) {
-                       *dest++ = *src;
-                       *dest++ = *src++;
-               }
-               return;
-       }
-
-       for (i = 0; i < num_pixels / 4; i++) {
-               temp = work = *s++;
+       int dx1=dx, dx2=dx+dest->bm_w-1;
+       int dy1=dy, dy2=dy+dest->bm_h-1;
 
 
-               temp = ((temp >> 8) & 0x00FFFF00) | (temp & 0xFF0000FF); // 0xABCDEFGH -> 0xABABCDEF
-               temp = ((temp >> 8) & 0x000000FF) | (temp & 0xFFFFFF00); // 0xABABCDEF -> 0xABABCDCD
-               doubletemp[0] = temp;
+       int sx1=sx, sx2=sx+src->bm_w-1;
+       int sy1=sy, sy2=sy+src->bm_h-1;
 
 
-               work = ((work << 8) & 0x00FFFF00) | (work & 0xFF0000FF); // 0xABCDEFGH -> 0xABEFGHGH
-               work = ((work << 8) & 0xFF000000) | (work & 0x00FFFFFF); // 0xABEFGHGH -> 0xEFEFGHGH
-               doubletemp[1] = work;
+       if ((dx1 >= dest->bm_w ) || (dx2 < 0)) return;
+       if ((dy1 >= dest->bm_h ) || (dy2 < 0)) return;
+       if ( dx1 < 0 ) { sx1 += -dx1; dx1 = 0; }
+       if ( dy1 < 0 ) { sy1 += -dy1; dy1 = 0; }
+       if ( dx2 >= dest->bm_w )        { dx2 = dest->bm_w-1; }
+       if ( dy2 >= dest->bm_h )        { dy2 = dest->bm_h-1; }
 
 
-               *d = *(double *) &(doubletemp[0]);
-               d++;
-       }
-}
+       if ((sx1 >= src->bm_w ) || (sx2 < 0)) return;
+       if ((sy1 >= src->bm_h ) || (sy2 < 0)) return;
+       if ( sx1 < 0 ) { dx1 += -sx1; sx1 = 0; }
+       if ( sy1 < 0 ) { dy1 += -sy1; sy1 = 0; }
+       if ( sx2 >= src->bm_w ) { sx2 = src->bm_w-1; }
+       if ( sy2 >= src->bm_h ) { sy2 = src->bm_h-1; }
 
 
-//extern void BlitLargeAlign(ubyte *draw_buffer, int dstRowBytes, ubyte *dstPtr, int w, int h, int modulus);
+       // Draw bitmap bm[x,y] into (dx1,dy1)-(dx2,dy2)
+       if ( dx2-dx1+1 < w )
+               w = dx2-dx1+1;
+       if ( dy2-dy1+1 < h )
+               h = dy2-dy1+1;
+       if ( sx2-sx1+1 < w )
+               w = sx2-sx1+1;
+       if ( sy2-sy1+1 < h )
+               h = sy2-sy1+1;
 
 
-#ifdef MACINTOSH
-asm void BlitLargeAlign(ubyte *rSrcPtr, int rDblDStrd, ubyte *rDst1Ptr, int rWidth, int rHeight, int rModulus)
-{
-    stw     r31,-4(SP)          // store non-volatile reg in red zone
-    addi    r5,r5,-8            // subtract 8 from dst
-    stw     r30,-8(SP)          // store non-volatile reg in red zone
-
-    la      r30,-16(SP)         // calculate copy of local 8-byte variable
-    sub     r9,r8,r6
-                                // rSStrd = modulus - w
-    add     r31,r5,r4           // dst2 = dstRowBytes + dst1
-    sub     r4,r4,r6            // r4 = dstRowBytes - w
-    addi    r7,r7,-1            // subtract 1 from height count
-    srawi   r6,r6,2             // rWidth = w >> 2
-    addi    r3,r3,-4            // subtract 4 from src
-    addi    r6,r6,-1            // subtract 1 from width count
-    add     r4,r4,r4            // rDblDStrd = 2 * r4
-
-BlitLargeAlignY:                // y count is in r7
-    lwzu     r10,4(r3)          // load a long into r10
-    mr       r0,r10             // put a copy in r0
-    mr       r11,r10
-// these are simplified -- can't use 'em    inslwi   r0,r10,16,8
-// these are simplified -- can't use 'em    insrwi   r11,r10,16,8
-    rlwimi   r0,r10,24,8,31
-    rlwimi   r11,r10,8,8,23
-    rlwimi   r0,r10,16,24,31
-    stw      r0,0(r30)
-    rlwimi   r11,r10,16,0,7
-    stw      r11,4(r30)
-    mtctr       r6              // copy x count into the counter
-    lfd      fp0,0(r30)
-
-BlitLargeAlignX:
-    lwzu     r10,4(r3)          // load a long into r10
-    stfdu    fp0,8(r5)
-    mr       r0,r10             // put a copy in r0
-    mr       r11,r10
-// simplefied   inslwi   r0,r10,16,8
-// simplefied   insrwi   r11,r10,16,8
-    rlwimi   r0,r10,24,8,31
-    rlwimi   r11,r10,8,8,23
-    rlwimi   r0,r10,16,24,31
-    stw      r0,0(r30)
-    rlwimi   r11,r10,16,0,7
-    stw      r11,4(r30)
-    stfdu    fp0,8(r31)
-    lfd      fp0,0(r30)
-    bdnz     BlitLargeAlignX    // loop over all x
-
-    stfdu    fp0,8(r5)
-    addic.   r7,r7,-1           // decrement the counter
-    add      r3,r3,r9
-                                // src += sstride
-    add      r5,r5,r4
-                                // dst1 += dstride
-    stfdu    fp0,8(r31)
-    add      r31,r31,r4
-                                // dst2 += dstride
-    bne      BlitLargeAlignY    // loop for all y
-
-    lwz     r30,-8(SP)          // restore non-volatile regs
-    lwz     r31,-4(SP)          // restore non-volatile regs
-    blr                         // return to caller
+       gr_bm_ubitblt(w,h, dx1, dy1, sx1, sy1, src, dest );
 }
 
 }
 
-void gr_bm_ubitblt_double(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *src, grs_bitmap *dest)
+void gr_bm_ubitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 {
 {
-       ubyte * dbits;
-       ubyte * sbits;
-       int dstep, i;
-
-       sbits = src->bm_data  + (src->bm_rowsize * sy) + sx;
-       dbits = dest->bm_data + (dest->bm_rowsize * dy) + dx;
-       dstep = dest->bm_rowsize << gr_bitblt_dest_step_shift;
-       Assert( !((int)dbits & 0x7) );  // assert to check double word alignment
-       BlitLargeAlign(sbits, dstep, dbits, src->bm_w, src->bm_h, src->bm_rowsize);
-}
-#endif
+       register int x1, y1;
 
 
-// w and h are the doubled width and height
+       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_LINEAR ))
+       {
+               if ( src->bm_flags & BM_FLAG_RLE )      
+                       gr_bm_ubitblt00_rle( w, h, dx, dy, sx, sy, src, dest );
+               else
+                       gr_bm_ubitblt00( w, h, dx, dy, sx, sy, src, dest );
+               return;
+       }
 
 
-void gr_bm_ubitblt_double_slow(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *src, grs_bitmap *dest)
-{
-       ubyte * dbits;
-       ubyte * sbits;
-       int dstep, i;
+#ifdef OGL
+       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_OGL ))
+       {
+               ogl_ubitblt(w, h, dx, dy, sx, sy, src, dest);
+               return;
+       }
+       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_LINEAR ))
+       {
+               ogl_ubitblt_tolinear(w, h, dx, dy, sx, sy, src, dest);
+               return;
+       }
+       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_OGL ))
+       {
+               ogl_ubitblt_copy(w, h, dx, dy, sx, sy, src, dest);
+               return;
+       }
+#endif
 
 
-       sbits = src->bm_data  + (src->bm_rowsize * sy) + sx;
-       dbits = dest->bm_data + (dest->bm_rowsize * dy) + dx;
-       dstep = dest->bm_rowsize << gr_bitblt_dest_step_shift;
+#ifdef D1XD3D
+       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_DIRECTX ))
+       {
+               Assert ((int)dest->bm_data == BM_D3D_RENDER || (int)dest->bm_data == BM_D3D_DISPLAY);
+               Win32_BlitLinearToDirectX_bm (src, sx, sy, w, h, dx, dy, 0);
+               return;
+       }
+       if ( (src->bm_type == BM_DIRECTX) && (dest->bm_type == BM_LINEAR ))
+       {
+               return;
+       }
+       if ( (src->bm_type == BM_DIRECTX) && (dest->bm_type == BM_DIRECTX ))
+       {
+               return;
+       }
+#endif
 
 
-       for (i=0; i < h; i++ )    {
+       if ( (src->bm_flags & BM_FLAG_RLE ) && (src->bm_type == BM_LINEAR) )    {
+               gr_bm_ubitblt0x_rle(w, h, dx, dy, sx, sy, src, dest, 0 );
+               return;
+       }
+#ifdef __DJGPP__
+       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_SVGA ))
+       {
+               gr_bm_ubitblt02( w, h, dx, dy, sx, sy, src, dest );
+               return;
+       }
 
 
-               gr_linear_movsd_double(sbits, dbits, w);
-               dbits += dstep;
-               if (i & 1)
-                       sbits += src->bm_rowsize;
+       if ( (src->bm_type == BM_SVGA) && (dest->bm_type == BM_LINEAR ))
+       {
+               gr_bm_ubitblt20( w, h, dx, dy, sx, sy, src, dest );
+               return;
        }
        }
-}
 
 
+       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_MODEX ))
+       {
+               gr_bm_ubitblt01( w, h, dx+XOFFSET, dy+YOFFSET, sx, sy, src, dest );
+               return;
+       }
 #endif
 #endif
+       for (y1=0; y1 < h; y1++ )    {
+               for (x1=0; x1 < w; x1++ )    {
+                       gr_bm_pixel( dest, dx+x1, dy+y1, gr_gpixel(src,sx+x1,sy+y1) );
+               }
+       }
+}
 
 
-
-// Clipped bitmap ...
+// Clipped bitmap ... 
 
 void gr_bitmap( int x, int y, grs_bitmap *bm )
 {
 
 void gr_bitmap( int x, int y, grs_bitmap *bm )
 {
@@ -1503,64 +672,139 @@ void gr_bitmap( int x, int y, grs_bitmap *bm )
        if ((dy1 >= grd_curcanv->cv_bitmap.bm_h) || (dy2 < 0)) return;
        if ( dx1 < 0 ) { sx = -dx1; dx1 = 0; }
        if ( dy1 < 0 ) { sy = -dy1; dy1 = 0; }
        if ((dy1 >= grd_curcanv->cv_bitmap.bm_h) || (dy2 < 0)) return;
        if ( dx1 < 0 ) { sx = -dx1; dx1 = 0; }
        if ( dy1 < 0 ) { sy = -dy1; dy1 = 0; }
-       if ( dx2 >= grd_curcanv->cv_bitmap.bm_w ) { dx2 = grd_curcanv->cv_bitmap.bm_w-1; }
-       if ( dy2 >= grd_curcanv->cv_bitmap.bm_h ) { dy2 = grd_curcanv->cv_bitmap.bm_h-1; }
-
+       if ( dx2 >= grd_curcanv->cv_bitmap.bm_w )       { dx2 = grd_curcanv->cv_bitmap.bm_w-1; }
+       if ( dy2 >= grd_curcanv->cv_bitmap.bm_h )       { dy2 = grd_curcanv->cv_bitmap.bm_h-1; }
+               
        // Draw bitmap bm[x,y] into (dx1,dy1)-(dx2,dy2)
 
        gr_bm_ubitblt(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
 
 }
 
        // Draw bitmap bm[x,y] into (dx1,dy1)-(dx2,dy2)
 
        gr_bm_ubitblt(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
 
 }
 
+void gr_bitmapm( int x, int y, grs_bitmap *bm )
+{
+       int dx1=x, dx2=x+bm->bm_w-1;
+       int dy1=y, dy2=y+bm->bm_h-1;
+       int sx=0, sy=0;
+
+       if ((dx1 >= grd_curcanv->cv_bitmap.bm_w ) || (dx2 < 0)) return;
+       if ((dy1 >= grd_curcanv->cv_bitmap.bm_h) || (dy2 < 0)) return;
+       if ( dx1 < 0 ) { sx = -dx1; dx1 = 0; }
+       if ( dy1 < 0 ) { sy = -dy1; dy1 = 0; }
+       if ( dx2 >= grd_curcanv->cv_bitmap.bm_w )       { dx2 = grd_curcanv->cv_bitmap.bm_w-1; }
+       if ( dy2 >= grd_curcanv->cv_bitmap.bm_h )       { dy2 = grd_curcanv->cv_bitmap.bm_h-1; }
+               
+       // Draw bitmap bm[x,y] into (dx1,dy1)-(dx2,dy2)
+
+       if ( (bm->bm_type == BM_LINEAR) && (grd_curcanv->cv_bitmap.bm_type == BM_LINEAR ))
+       {
+               if ( bm->bm_flags & BM_FLAG_RLE )       
+                       gr_bm_ubitblt00m_rle(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
+               else
+                       gr_bm_ubitblt00m(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
+               return;
+       }
+
+       gr_bm_ubitbltm(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
+
+}
+
+void gr_bm_ubitbltm(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
+{
+       register int x1, y1;
+       ubyte c;
+
+#ifdef OGL
+       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_OGL ))
+       {
+               ogl_ubitblt(w, h, dx, dy, sx, sy, src, dest);
+               return;
+       }
+       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_LINEAR ))
+       {
+               ogl_ubitblt_tolinear(w, h, dx, dy, sx, sy, src, dest);
+               return;
+       }
+       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_OGL ))
+       {
+               ogl_ubitblt_copy(w, h, dx, dy, sx, sy, src, dest);
+               return;
+       }
+#endif
+#ifdef D1XD3D
+       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_DIRECTX ))
+       {
+               Assert ((int)dest->bm_data == BM_D3D_RENDER || (int)dest->bm_data == BM_D3D_DISPLAY);
+               Win32_BlitLinearToDirectX_bm (src, sx, sy, w, h, dx, dy, 1);
+               return;
+       }
+       if ( (src->bm_type == BM_DIRECTX) && (dest->bm_type == BM_DIRECTX ))
+       {
+               Assert ((int)src->bm_data == BM_D3D_RENDER || (int)src->bm_data == BM_D3D_DISPLAY);
+//             Win32_BlitDirectXToDirectX (w, h, dx, dy, sx, sy, src->bm_data, dest->bm_data, 0);
+               return;
+       }
+#endif
+
+
+       for (y1=0; y1 < h; y1++ )    {
+               for (x1=0; x1 < w; x1++ )    {
+                       if ((c=gr_gpixel(src,sx+x1,sy+y1))!=255)
+                               gr_bm_pixel( dest, dx+x1, dy+y1,c  );
+               }
+       }
+
+}
+
 //-NOT-used // From linear to SVGA
 //-NOT-used void gr_bm_ubitblt02_2x(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 //-NOT-used {
 //-NOT-used    unsigned char * sbits;
 //-NOT-used // From linear to SVGA
 //-NOT-used void gr_bm_ubitblt02_2x(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
 //-NOT-used {
 //-NOT-used    unsigned char * sbits;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    unsigned int offset, EndingOffset, VideoLocation;
 //-NOT-used    unsigned int offset, EndingOffset, VideoLocation;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    int sbpr, dbpr, y1, page, BytesToMove;
 //-NOT-used    int sbpr, dbpr, y1, page, BytesToMove;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    sbpr = src->bm_rowsize;
 //-NOT-used    sbpr = src->bm_rowsize;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    dbpr = dest->bm_rowsize << gr_bitblt_dest_step_shift;
 //-NOT-used    dbpr = dest->bm_rowsize << gr_bitblt_dest_step_shift;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    VideoLocation = (unsigned int)dest->bm_data + (dest->bm_rowsize * dy) + dx;
 //-NOT-used    VideoLocation = (unsigned int)dest->bm_data + (dest->bm_rowsize * dy) + dx;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    sbits = src->bm_data + ( sbpr*sy ) + sx;
 //-NOT-used    sbits = src->bm_data + ( sbpr*sy ) + sx;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    for (y1=0; y1 < h; y1++ )    {
 //-NOT-used    for (y1=0; y1 < h; y1++ )    {
-//-NOT-used
+//-NOT-used 
 //-NOT-used            page    = VideoLocation >> 16;
 //-NOT-used            offset  = VideoLocation & 0xFFFF;
 //-NOT-used            page    = VideoLocation >> 16;
 //-NOT-used            offset  = VideoLocation & 0xFFFF;
-//-NOT-used
+//-NOT-used 
 //-NOT-used            gr_vesa_setpage( page );
 //-NOT-used            gr_vesa_setpage( page );
-//-NOT-used
+//-NOT-used 
 //-NOT-used            EndingOffset = offset+w-1;
 //-NOT-used            EndingOffset = offset+w-1;
-//-NOT-used
+//-NOT-used 
 //-NOT-used            if ( EndingOffset <= 0xFFFF )
 //-NOT-used            {
 //-NOT-used            if ( EndingOffset <= 0xFFFF )
 //-NOT-used            {
-//-NOT-used                    gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+0xA0000), w );
-//-NOT-used
+//-NOT-used                    gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+gr_video_memory), w );
+//-NOT-used 
 //-NOT-used                    VideoLocation += dbpr;
 //-NOT-used                    sbits += sbpr;
 //-NOT-used            }
 //-NOT-used            else
 //-NOT-used            {
 //-NOT-used                    BytesToMove = 0xFFFF-offset+1;
 //-NOT-used                    VideoLocation += dbpr;
 //-NOT-used                    sbits += sbpr;
 //-NOT-used            }
 //-NOT-used            else
 //-NOT-used            {
 //-NOT-used                    BytesToMove = 0xFFFF-offset+1;
-//-NOT-used
-//-NOT-used                    gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+0xA0000), BytesToMove );
-//-NOT-used
+//-NOT-used 
+//-NOT-used                    gr_linear_rep_movsd_2x( (void *)sbits, (void *)(offset+gr_video_memory), BytesToMove );
+//-NOT-used 
 //-NOT-used                    page++;
 //-NOT-used                    gr_vesa_setpage(page);
 //-NOT-used                    page++;
 //-NOT-used                    gr_vesa_setpage(page);
-//-NOT-used
-//-NOT-used                    gr_linear_rep_movsd_2x( (void *)(sbits+BytesToMove/2), (void *)0xA0000, EndingOffset - 0xFFFF );
-//-NOT-used
+//-NOT-used 
+//-NOT-used                    gr_linear_rep_movsd_2x( (void *)(sbits+BytesToMove/2), (void *)gr_video_memory, EndingOffset - 0xFFFF );
+//-NOT-used 
 //-NOT-used                    VideoLocation += dbpr;
 //-NOT-used                    sbits += sbpr;
 //-NOT-used            }
 //-NOT-used                    VideoLocation += dbpr;
 //-NOT-used                    sbits += sbpr;
 //-NOT-used            }
-//-NOT-used
-//-NOT-used
+//-NOT-used 
+//-NOT-used 
 //-NOT-used    }
 //-NOT-used }
 
 //-NOT-used    }
 //-NOT-used }
 
@@ -1570,17 +814,17 @@ void gr_bitmap( int x, int y, grs_bitmap *bm )
 //-NOT-used {
 //-NOT-used    unsigned char * dbits;
 //-NOT-used    unsigned char * sbits;
 //-NOT-used {
 //-NOT-used    unsigned char * dbits;
 //-NOT-used    unsigned char * sbits;
-//-NOT-used    //int src_bm_rowsize_2, dest_bm_rowsize_2;
-//-NOT-used
+//-NOT-used    //int   src_bm_rowsize_2, dest_bm_rowsize_2;
+//-NOT-used 
 //-NOT-used    int i;
 //-NOT-used    int i;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    sbits =   src->bm_data  + (src->bm_rowsize * sy) + sx;
 //-NOT-used    dbits =   dest->bm_data + (dest->bm_rowsize * dy) + dx;
 //-NOT-used    sbits =   src->bm_data  + (src->bm_rowsize * sy) + sx;
 //-NOT-used    dbits =   dest->bm_data + (dest->bm_rowsize * dy) + dx;
-//-NOT-used
+//-NOT-used 
 //-NOT-used    // No interlacing, copy the whole buffer.
 //-NOT-used    for (i=0; i < h; i++ )    {
 //-NOT-used            gr_linear_rep_movsd_2x( sbits, dbits, w );
 //-NOT-used    // No interlacing, copy the whole buffer.
 //-NOT-used    for (i=0; i < h; i++ )    {
 //-NOT-used            gr_linear_rep_movsd_2x( sbits, dbits, w );
-//-NOT-used
+//-NOT-used 
 //-NOT-used            sbits += src->bm_rowsize;
 //-NOT-used            dbits += dest->bm_rowsize << gr_bitblt_dest_step_shift;
 //-NOT-used    }
 //-NOT-used            sbits += src->bm_rowsize;
 //-NOT-used            dbits += dest->bm_rowsize << gr_bitblt_dest_step_shift;
 //-NOT-used    }
@@ -1590,26 +834,19 @@ void gr_bm_ubitblt00_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitma
 {
        unsigned char * dbits;
        unsigned char * sbits;
 {
        unsigned char * dbits;
        unsigned char * sbits;
-       int i, data_offset;
-
-       data_offset = 1;
-       if (src->bm_flags & BM_FLAG_RLE_BIG)
-               data_offset = 2;
 
 
-       sbits = &src->bm_data[4 + (src->bm_h*data_offset)];
+       int i;
 
 
+       sbits = &src->bm_data[4 + src->bm_h];
        for (i=0; i<sy; i++ )
        for (i=0; i<sy; i++ )
-               sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)]));
+               sbits += (int)src->bm_data[4+i];
 
        dbits = dest->bm_data + (dest->bm_rowsize * dy) + dx;
 
        // No interlacing, copy the whole buffer.
        for (i=0; i < h; i++ )    {
                gr_rle_expand_scanline( dbits, sbits, sx, sx+w-1 );
 
        dbits = dest->bm_data + (dest->bm_rowsize * dy) + dx;
 
        // No interlacing, copy the whole buffer.
        for (i=0; i < h; i++ )    {
                gr_rle_expand_scanline( dbits, sbits, sx, sx+w-1 );
-               if ( src->bm_flags & BM_FLAG_RLE_BIG )
-                       sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((i+sy)*data_offset)])));
-               else
-                       sbits += (int)(src->bm_data[4+i+sy]);
+               sbits += (int)src->bm_data[4+i+sy];
                dbits += dest->bm_rowsize << gr_bitblt_dest_step_shift;
        }
 }
                dbits += dest->bm_rowsize << gr_bitblt_dest_step_shift;
        }
 }
@@ -1618,499 +855,47 @@ void gr_bm_ubitblt00m_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitm
 {
        unsigned char * dbits;
        unsigned char * sbits;
 {
        unsigned char * dbits;
        unsigned char * sbits;
-       int i, data_offset;
 
 
-       data_offset = 1;
-       if (src->bm_flags & BM_FLAG_RLE_BIG)
-               data_offset = 2;
+       int i;
 
 
-       sbits = &src->bm_data[4 + (src->bm_h*data_offset)];
+       sbits = &src->bm_data[4 + src->bm_h];
        for (i=0; i<sy; i++ )
        for (i=0; i<sy; i++ )
-               sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)]));
+               sbits += (int)src->bm_data[4+i];
 
        dbits = dest->bm_data + (dest->bm_rowsize * dy) + dx;
 
        // No interlacing, copy the whole buffer.
        for (i=0; i < h; i++ )    {
                gr_rle_expand_scanline_masked( dbits, sbits, sx, sx+w-1 );
 
        dbits = dest->bm_data + (dest->bm_rowsize * dy) + dx;
 
        // No interlacing, copy the whole buffer.
        for (i=0; i < h; i++ )    {
                gr_rle_expand_scanline_masked( dbits, sbits, sx, sx+w-1 );
-               if ( src->bm_flags & BM_FLAG_RLE_BIG )
-                       sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((i+sy)*data_offset)])));
-               else
-                       sbits += (int)(src->bm_data[4+i+sy]);
+               sbits += (int)src->bm_data[4+i+sy];
                dbits += dest->bm_rowsize << gr_bitblt_dest_step_shift;
        }
 }
 
 // in rle.c
 
                dbits += dest->bm_rowsize << gr_bitblt_dest_step_shift;
        }
 }
 
 // in rle.c
 
-extern void gr_rle_expand_scanline_generic( grs_bitmap * dest, int dx, int dy, ubyte *src, int x1, int x2  );
-extern void gr_rle_expand_scanline_generic_masked( grs_bitmap * dest, int dx, int dy, ubyte *src, int x1, int x2  );
-extern void gr_rle_expand_scanline_svga_masked( grs_bitmap * dest, int dx, int dy, ubyte *src, int x1, int x2  );
+extern void gr_rle_expand_scanline_generic( grs_bitmap * dest, int dx, int dy, ubyte *src, 
+       int x1, int x2, int masked );
 
 
-void gr_bm_ubitblt0x_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
+
+void gr_bm_ubitblt0x_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, 
+       grs_bitmap * dest, int masked )
 {
 {
-       int i, data_offset;
+       int i;
        register int y1;
        unsigned char * sbits;
 
        register int y1;
        unsigned char * sbits;
 
-       //mprintf( 0, "SVGA RLE!\n" );
-
-       data_offset = 1;
-       if (src->bm_flags & BM_FLAG_RLE_BIG)
-               data_offset = 2;
-
-       sbits = &src->bm_data[4 + (src->bm_h*data_offset)];
+       sbits = &src->bm_data[4 + src->bm_h];
        for (i=0; i<sy; i++ )
        for (i=0; i<sy; i++ )
-               sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)]));
+               sbits += (int)src->bm_data[4+i];
 
        for (y1=0; y1 < h; y1++ )    {
 
        for (y1=0; y1 < h; y1++ )    {
-               gr_rle_expand_scanline_generic( dest, dx, dy+y1,  sbits, sx, sx+w-1  );
-               if ( src->bm_flags & BM_FLAG_RLE_BIG )
-                       sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((y1+sy)*data_offset)])));
-               else
-                       sbits += (int)src->bm_data[4+y1+sy];
+               gr_rle_expand_scanline_generic( dest, dx, dy+y1,  sbits, sx, sx+w-1, 
+                       masked );
+               sbits += (int)src->bm_data[4+y1+sy];
        }
        }
-
 }
 
 }
 
-void gr_bm_ubitblt0xm_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       int i, data_offset;
-       register int y1;
-       unsigned char * sbits;
-
-       //mprintf( 0, "SVGA RLE!\n" );
-
-       data_offset = 1;
-       if (src->bm_flags & BM_FLAG_RLE_BIG)
-               data_offset = 2;
-
-       sbits = &src->bm_data[4 + (src->bm_h*data_offset)];
-       for (i=0; i<sy; i++ )
-               sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)]));
-
-       for (y1=0; y1 < h; y1++ )    {
-               gr_rle_expand_scanline_generic_masked( dest, dx, dy+y1,  sbits, sx, sx+w-1  );
-               if ( src->bm_flags & BM_FLAG_RLE_BIG )
-                       sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((y1+sy)*data_offset)])));
-               else
-                       sbits += (int)src->bm_data[4+y1+sy];
-       }
-
-}
-
-#ifdef __MSDOS__
-void gr_bm_ubitblt02m_rle(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       int i, data_offset;
-       register int y1;
-       unsigned char * sbits;
-
-       //mprintf( 0, "SVGA RLE!\n" );
-
-       data_offset = 1;
-       if (src->bm_flags & BM_FLAG_RLE_BIG)
-               data_offset = 2;
-
-       sbits = &src->bm_data[4 + (src->bm_h*data_offset)];
-       for (i=0; i<sy; i++ )
-               sbits += (int)(INTEL_SHORT(src->bm_data[4+(i*data_offset)]));
-
-       for (y1=0; y1 < h; y1++ )    {
-               gr_rle_expand_scanline_svga_masked( dest, dx, dy+y1,  sbits, sx, sx+w-1  );
-               if ( src->bm_flags & BM_FLAG_RLE_BIG )
-                       sbits += (int)INTEL_SHORT(*((short *)&(src->bm_data[4+((y1+sy)*data_offset)])));
-               else
-                       sbits += (int)src->bm_data[4+y1+sy];
-       }
-}
-#endif
-
-void gr_bm_ubitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       register int x1, y1;
-
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_LINEAR ))
-       {
-               if ( src->bm_flags & BM_FLAG_RLE )
-                       gr_bm_ubitblt00_rle( w, h, dx, dy, sx, sy, src, dest );
-               else
-                       gr_bm_ubitblt00( w, h, dx, dy, sx, sy, src, dest );
-               return;
-       }
-
-#ifdef OGL
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_OGL ))
-       {
-               ogl_ubitblt(w, h, dx, dy, sx, sy, src, dest);
-               return;
-       }
-       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_LINEAR ))
-       {
-               ogl_ubitblt_tolinear(w, h, dx, dy, sx, sy, src, dest);
-               return;
-       }
-       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_OGL ))
-       {
-               ogl_ubitblt_copy(w, h, dx, dy, sx, sy, src, dest);
-               return;
-       }
-#endif
-
-#ifdef D1XD3D
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_DIRECTX ))
-       {
-               Assert ((int)dest->bm_data == BM_D3D_RENDER || (int)dest->bm_data == BM_D3D_DISPLAY);
-               Win32_BlitLinearToDirectX_bm (src, sx, sy, w, h, dx, dy, 0);
-               return;
-       }
-       if ( (src->bm_type == BM_DIRECTX) && (dest->bm_type == BM_LINEAR ))
-       {
-               return;
-       }
-       if ( (src->bm_type == BM_DIRECTX) && (dest->bm_type == BM_DIRECTX ))
-       {
-               return;
-       }
-#endif
-
-       if ( (src->bm_flags & BM_FLAG_RLE ) && (src->bm_type == BM_LINEAR) ) {
-               gr_bm_ubitblt0x_rle(w, h, dx, dy, sx, sy, src, dest );
-               return;
-       }
-
-#ifdef __MSDOS__
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_SVGA ))
-       {
-               gr_bm_ubitblt02( w, h, dx, dy, sx, sy, src, dest );
-               return;
-       }
-
-       if ( (src->bm_type == BM_SVGA) && (dest->bm_type == BM_LINEAR ))
-       {
-               gr_bm_ubitblt20( w, h, dx, dy, sx, sy, src, dest );
-               return;
-       }
-
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_MODEX ))
-       {
-               gr_bm_ubitblt01( w, h, dx+XOFFSET, dy+YOFFSET, sx, sy, src, dest );
-               return;
-       }
-#endif
-
-#if defined(POLY_ACC)
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_LINEAR15 ))
-       {
-               ubyte *s = src->bm_data + sy * src->bm_rowsize + sx;
-               ushort *t = (ushort *)(dest->bm_data + dy * dest->bm_rowsize + dx * PA_BPP);
-               int x;
-               pa_flush();
-               for(;h--;)
-               {
-                       for(x = 0; x < w; x++)
-                               t[x] = pa_clut[s[x]];
-                       s += src->bm_rowsize;
-                       t += dest->bm_rowsize / PA_BPP;
-               }
-               return;
-       }
-
-       if ( (src->bm_type == BM_LINEAR15) && (dest->bm_type == BM_LINEAR15 ))
-       {
-               pa_blit(dest, dx, dy, src, sx, sy, w, h);
-               return;
-       }
-#endif
-
-       for (y1=0; y1 < h; y1++ )    {
-               for (x1=0; x1 < w; x1++ )    {
-                       gr_bm_pixel( dest, dx+x1, dy+y1, gr_gpixel(src,sx+x1,sy+y1) );
-               }
-       }
-}
-
-void gr_bm_bitblt(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       int dx1=dx, dx2=dx+dest->bm_w-1;
-       int dy1=dy, dy2=dy+dest->bm_h-1;
-
-       int sx1=sx, sx2=sx+src->bm_w-1;
-       int sy1=sy, sy2=sy+src->bm_h-1;
-
-       if ((dx1 >= dest->bm_w ) || (dx2 < 0)) return;
-       if ((dy1 >= dest->bm_h ) || (dy2 < 0)) return;
-       if ( dx1 < 0 ) { sx1 += -dx1; dx1 = 0; }
-       if ( dy1 < 0 ) { sy1 += -dy1; dy1 = 0; }
-       if ( dx2 >= dest->bm_w ) { dx2 = dest->bm_w-1; }
-       if ( dy2 >= dest->bm_h ) { dy2 = dest->bm_h-1; }
-
-       if ((sx1 >= src->bm_w ) || (sx2 < 0)) return;
-       if ((sy1 >= src->bm_h ) || (sy2 < 0)) return;
-       if ( sx1 < 0 ) { dx1 += -sx1; sx1 = 0; }
-       if ( sy1 < 0 ) { dy1 += -sy1; sy1 = 0; }
-       if ( sx2 >= src->bm_w ) { sx2 = src->bm_w-1; }
-       if ( sy2 >= src->bm_h ) { sy2 = src->bm_h-1; }
-
-       // Draw bitmap bm[x,y] into (dx1,dy1)-(dx2,dy2)
-       if ( dx2-dx1+1 < w )
-               w = dx2-dx1+1;
-       if ( dy2-dy1+1 < h )
-               h = dy2-dy1+1;
-       if ( sx2-sx1+1 < w )
-               w = sx2-sx1+1;
-       if ( sy2-sy1+1 < h )
-               h = sy2-sy1+1;
-
-       gr_bm_ubitblt(w,h, dx1, dy1, sx1, sy1, src, dest );
-}
-
-void gr_ubitmap( int x, int y, grs_bitmap *bm )
-{
-       int source, dest;
-
-       source = bm->bm_type;
-       dest = TYPE;
-
-       if (source==BM_LINEAR) {
-               switch( dest )
-               {
-               case BM_LINEAR:
-                       if ( bm->bm_flags & BM_FLAG_RLE )
-                               gr_bm_ubitblt00_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap );
-                       else
-                               gr_ubitmap00( x, y, bm );
-                       return;
-#ifdef OGL
-               case BM_OGL:
-                       ogl_ubitmapm(x,y,bm);
-                       return;
-#endif
-#ifdef D1XD3D
-               case BM_DIRECTX:
-                       Assert ((int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_RENDER || (int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_DISPLAY);
-                       Win32_BlitLinearToDirectX_bm(bm, 0, 0, bm->bm_w, bm->bm_h, x, y, 0);
-                       return;
-#endif
-#ifdef __MSDOS__
-               case BM_SVGA:
-                       if ( bm->bm_flags & BM_FLAG_RLE )
-                               gr_bm_ubitblt0x_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap );
-                       else
-                               gr_vesa_bitmap( bm, &grd_curcanv->cv_bitmap, x, y );
-                       return;
-               case BM_MODEX:
-                       gr_bm_ubitblt01(bm->bm_w, bm->bm_h, x+XOFFSET, y+YOFFSET, 0, 0, bm, &grd_curcanv->cv_bitmap);
-                       return;
-#endif
-#if defined(POLY_ACC)
-               case BM_LINEAR15:
-                       if ( bm->bm_flags & BM_FLAG_RLE )
-                               gr_bm_ubitblt05_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap );
-                       else
-                               gr_ubitmap05( x, y, bm);
-                       return;
-
-#endif
-               default:
-                       gr_ubitmap012( x, y, bm );
-                       return;
-               }
-       } else  {
-               gr_ubitmapGENERIC(x, y, bm);
-       }
-}
-
-
-void gr_ubitmapm( int x, int y, grs_bitmap *bm )
-{
-       int source, dest;
-
-       source = bm->bm_type;
-       dest = TYPE;
-
-       Assert(x+bm->bm_w <= grd_curcanv->cv_w);
-       Assert(y+bm->bm_h <= grd_curcanv->cv_h);
-
-#ifdef _3DFX
-       _3dfx_Blit( x, y, bm );
-       if ( _3dfx_skip_ddraw )
-               return;
-#endif
-
-       if (source==BM_LINEAR) {
-               switch( dest )
-               {
-               case BM_LINEAR:
-                       if ( bm->bm_flags & BM_FLAG_RLE )
-                               gr_bm_ubitblt00m_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap );
-                       else
-                               gr_ubitmap00m( x, y, bm );
-                       return;
-#ifdef OGL
-               case BM_OGL:
-                       ogl_ubitmapm(x,y,bm);
-                       return;
-#endif
-#ifdef D1XD3D
-               case BM_DIRECTX:
-                       if (bm->bm_w < 35 && bm->bm_h < 35) {
-                               // ugly hack needed for reticle
-                               if ( bm->bm_flags & BM_FLAG_RLE )
-                                       gr_bm_ubitblt0x_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap, 1 );
-                               else
-                                       gr_ubitmapGENERICm(x, y, bm);
-                               return;
-                       }
-                       Assert ((int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_RENDER || (int)grd_curcanv->cv_bitmap.bm_data == BM_D3D_DISPLAY);
-                       Win32_BlitLinearToDirectX_bm(bm, 0, 0, bm->bm_w, bm->bm_h, x, y, 1);
-                       return;
-#endif
-#ifdef __MSDOS__
-               case BM_SVGA:
-                       if (bm->bm_flags & BM_FLAG_RLE)
-                               gr_bm_ubitblt02m_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap);
-                       //gr_bm_ubitblt0xm_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap);
-                       else
-                               gr_bm_ubitblt02m(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap);
-                       //gr_ubitmapGENERICm(x, y, bm);
-                       return;
-               case BM_MODEX:
-                       gr_bm_ubitblt01m(bm->bm_w, bm->bm_h, x+XOFFSET, y+YOFFSET, 0, 0, bm, &grd_curcanv->cv_bitmap);
-                       return;
-#endif
-#if defined(POLY_ACC)
-               case BM_LINEAR15:
-                       if ( bm->bm_flags & BM_FLAG_RLE )
-                               gr_bm_ubitblt05m_rle(bm->bm_w, bm->bm_h, x, y, 0, 0, bm, &grd_curcanv->cv_bitmap );
-                       else
-                               gr_ubitmap05m( x, y, bm );
-                       return;
-#endif
-
-               default:
-                       gr_ubitmap012m( x, y, bm );
-                       return;
-               }
-       } else {
-               gr_ubitmapGENERICm(x, y, bm);
-       }
-}
-
-
-void gr_bitmapm( int x, int y, grs_bitmap *bm )
-{
-       int dx1=x, dx2=x+bm->bm_w-1;
-       int dy1=y, dy2=y+bm->bm_h-1;
-       int sx=0, sy=0;
-
-       if ((dx1 >= grd_curcanv->cv_bitmap.bm_w ) || (dx2 < 0)) return;
-       if ((dy1 >= grd_curcanv->cv_bitmap.bm_h) || (dy2 < 0)) return;
-       if ( dx1 < 0 ) { sx = -dx1; dx1 = 0; }
-       if ( dy1 < 0 ) { sy = -dy1; dy1 = 0; }
-       if ( dx2 >= grd_curcanv->cv_bitmap.bm_w ) { dx2 = grd_curcanv->cv_bitmap.bm_w-1; }
-       if ( dy2 >= grd_curcanv->cv_bitmap.bm_h ) { dy2 = grd_curcanv->cv_bitmap.bm_h-1; }
-
-       // Draw bitmap bm[x,y] into (dx1,dy1)-(dx2,dy2)
-
-       if ( (bm->bm_type == BM_LINEAR) && (grd_curcanv->cv_bitmap.bm_type == BM_LINEAR ))
-       {
-               if ( bm->bm_flags & BM_FLAG_RLE )
-                       gr_bm_ubitblt00m_rle(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
-               else
-                       gr_bm_ubitblt00m(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
-               return;
-       }
-#ifdef __MSDOS__
-       else if ( (bm->bm_type == BM_LINEAR) && (grd_curcanv->cv_bitmap.bm_type == BM_SVGA ))
-       {
-               gr_bm_ubitblt02m(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
-               return;
-       }
-#endif
-
-       gr_bm_ubitbltm(dx2-dx1+1,dy2-dy1+1, dx1, dy1, sx, sy, bm, &grd_curcanv->cv_bitmap );
-
-}
-
-void gr_bm_ubitbltm(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest)
-{
-       register int x1, y1;
-       ubyte c;
-
-#ifdef OGL
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_OGL ))
-       {
-               ogl_ubitblt(w, h, dx, dy, sx, sy, src, dest);
-               return;
-       }
-       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_LINEAR ))
-       {
-               ogl_ubitblt_tolinear(w, h, dx, dy, sx, sy, src, dest);
-               return;
-       }
-       if ( (src->bm_type == BM_OGL) && (dest->bm_type == BM_OGL ))
-       {
-               ogl_ubitblt_copy(w, h, dx, dy, sx, sy, src, dest);
-               return;
-       }
-#endif
-#ifdef D1XD3D
-       if ( (src->bm_type == BM_LINEAR) && (dest->bm_type == BM_DIRECTX ))
-       {
-               Assert ((int)dest->bm_data == BM_D3D_RENDER || (int)dest->bm_data == BM_D3D_DISPLAY);
-               Win32_BlitLinearToDirectX_bm (src, sx, sy, w, h, dx, dy, 1);
-               return;
-       }
-       if ( (src->bm_type == BM_DIRECTX) && (dest->bm_type == BM_DIRECTX ))
-       {
-               Assert ((int)src->bm_data == BM_D3D_RENDER || (int)src->bm_data == BM_D3D_DISPLAY);
-               //Win32_BlitDirectXToDirectX (w, h, dx, dy, sx, sy, src->bm_data, dest->bm_data, 0);
-               return;
-       }
-#endif
-#if defined(POLY_ACC)
-       if(src->bm_type == BM_LINEAR && dest->bm_type == BM_LINEAR15)
-       {
-               ubyte *s;
-               ushort *d;
-               ushort u;
-               int smod, dmod;
-
-               pa_flush();
-               s = (ubyte *)(src->bm_data + src->bm_rowsize * sy + sx);
-               smod = src->bm_rowsize - w;
-               d = (ushort *)(dest->bm_data + dest->bm_rowsize * dy + dx * PA_BPP);
-               dmod = dest->bm_rowsize / PA_BPP - w;
-               for (; h--;) {
-                       for (x1=w; x1--; ) {
-                               if ((u = *s) != TRANSPARENCY_COLOR)
-                                       *d = pa_clut[u];
-                               ++s;
-                               ++d;
-                       }
-                       s += smod;
-                       d += dmod;
-               }
-       }
-
-       if(src->bm_type == BM_LINEAR15)
-       {
-               Assert(src->bm_type == dest->bm_type);         // I don't support 15 to 8 yet.
-               pa_blit_transparent(dest, dx, dy, src, sx, sy, w, h);
-               return;
-       }
-#endif
-
-       for (y1=0; y1 < h; y1++ )    {
-               for (x1=0; x1 < w; x1++ )    {
-                       if ((c=gr_gpixel(src,sx+x1,sy+y1))!=TRANSPARENCY_COLOR)
-                               gr_bm_pixel( dest, dx+x1, dy+y1,c  );
-               }
-       }
-}
-
-
 // rescalling bitmaps, 10/14/99 Jan Bobrowski jb@wizard.ae.krakow.pl
 
 inline void scale_line(byte *in, byte *out, int ilen, int olen)
 // rescalling bitmaps, 10/14/99 Jan Bobrowski jb@wizard.ae.krakow.pl
 
 inline void scale_line(byte *in, byte *out, int ilen, int olen)
@@ -2126,7 +911,7 @@ inline void scale_line(byte *in, byte *out, int ilen, int olen)
                        goto inside;
                }
                while(--i>=0) {
                        goto inside;
                }
                while(--i>=0) {
-               inside:
+inside:
                        *out++ = *in;
                }
                in++;
                        *out++ = *in;
                }
                in++;
@@ -2149,7 +934,7 @@ void gr_bitmap_scale_to(grs_bitmap *src, grs_bitmap *dst)
                        goto inside;
                }
                while(--i>=0) {
                        goto inside;
                }
                while(--i>=0) {
-               inside:
+inside:
                        scale_line(s, d, src->bm_w, dst->bm_w);
                        d += dst->bm_rowsize;
                }
                        scale_line(s, d, src->bm_w, dst->bm_w);
                        d += dst->bm_rowsize;
                }
index 94660cb..92ec8a6 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: bitmap.c,v 1.5 2002-10-10 19:11:23 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,104 +7,10 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
-/*
- *
- * Graphical routines for manipulating grs_bitmaps.
- *
- * Old Log:
- * Revision 1.11  1995/08/23  18:46:06  allender
- * fixed compiler warning
- *
- * Revision 1.10  1995/08/14  14:25:45  allender
- * changed transparency color to 0
- *
- * Revision 1.9  1995/07/05  16:04:51  allender
- * transparency/game kitchen changes
- *
- * Revision 1.8  1995/06/15  09:50:48  allender
- * new malloc to align bitmap on 8 byte bountry
- *
- * Revision 1.7  1995/05/12  11:52:19  allender
- * changed memory stuff again
- *
- * Revision 1.6  1995/05/11  12:48:34  allender
- * nge transparency color
- *
- * Revision 1.5  1995/05/04  19:59:21  allender
- * use NewPtr instead of malloc
- *
- * Revision 1.4  1995/04/27  07:33:04  allender
- * rearrange functions
- *
- * Revision 1.3  1995/04/19  14:37:17  allender
- * removed dead asm code
- *
- * Revision 1.2  1995/04/18  12:04:51  allender
- * *** empty log message ***
- *
- * Revision 1.1  1995/03/09  08:48:06  allender
- * Initial revision
- *
- *
- * -------  PC version RCS information
- * Revision 1.17  1994/11/18  22:50:25  john
- * Changed shorts to ints in parameters.
- *
- * Revision 1.16  1994/11/10  15:59:46  john
- * Fixed bugs with canvas's being created with bogus bm_flags.
- *
- * Revision 1.15  1994/10/26  23:55:53  john
- * Took out roller; Took out inverse table.
- *
- * Revision 1.14  1994/09/19  14:40:21  john
- * Changed dpmi stuff.
- *
- * Revision 1.13  1994/09/19  11:44:04  john
- * Changed call to allocate selector to the dpmi module.
- *
- * Revision 1.12  1994/06/09  13:14:57  john
- * Made selectors zero our
- * out, I meant.
- *
- * Revision 1.11  1994/05/06  12:50:07  john
- * Added supertransparency; neatend things up; took out warnings.
- *
- * Revision 1.10  1994/04/08  16:59:39  john
- * Add fading poly's; Made palette fade 32 instead of 16.
- *
- * Revision 1.9  1994/03/16  17:21:09  john
- * Added slow palette searching options.
- *
- * Revision 1.8  1994/03/14  17:59:35  john
- * Added function to check bitmap's transparency.
- *
- * Revision 1.7  1994/03/14  17:16:21  john
- * fixed bug with counting freq of pixels.
- *
- * Revision 1.6  1994/03/14  16:55:47  john
- * Changed grs_bitmap structure to include bm_flags.
- *
- * Revision 1.5  1994/02/18  15:32:22  john
- * *** empty log message ***
- *
- * Revision 1.4  1993/10/15  16:22:49  john
- * *** empty log message ***
- *
- * Revision 1.3  1993/09/08  17:37:11  john
- * Checking for errors with Yuan...
- *
- * Revision 1.2  1993/09/08  14:46:27  john
- * looking for possible bugs...
- *
- * Revision 1.1  1993/09/08  11:43:05  john
- * Initial revision
- *
- */
-
 #ifdef HAVE_CONFIG_H
 #include <conf.h>
 #endif
 #ifdef HAVE_CONFIG_H
 #include <conf.h>
 #endif
@@ -119,16 +24,15 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #include "gr.h"
 #include "grdef.h"
 #include "u_dpmi.h"
 #include "gr.h"
 #include "grdef.h"
 #include "u_dpmi.h"
+#include "bitmap.h"
 #include "error.h"
 
 #include "error.h"
 
-#if defined(POLY_ACC)
-#include "poly_acc.h"
-#endif
-
 #ifdef OGL
 #include "ogl_init.h"
 #endif
 
 #ifdef OGL
 #include "ogl_init.h"
 #endif
 
+void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq );
+
 void gr_set_bitmap_data (grs_bitmap *bm, unsigned char *data)
 {
 #ifdef OGL
 void gr_set_bitmap_data (grs_bitmap *bm, unsigned char *data)
 {
 #ifdef OGL
@@ -142,59 +46,6 @@ void gr_set_bitmap_data (grs_bitmap *bm, unsigned char *data)
 #endif
 }
 
 #endif
 }
 
-grs_bitmap *gr_create_bitmap(int w, int h )
-{
-       return gr_create_bitmap_raw (w, h, d_malloc(w * h));
-}
-
-grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data )
-{
-    grs_bitmap *new;
-
-    new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
-       gr_init_bitmap (new, 0, 0, 0, w, h, w, raw_data);
-
-    return new;
-}
-
-
-#if defined(POLY_ACC)
-//
-//  Creates a bitmap of the requested size and type.
-//    w, and h are in pixels.
-//    type is a BM_... and is used to set the rowsize.
-//    if data is NULL, memory is allocated, otherwise data is used for bm_data.
-//
-//  This function is used only by the polygon accelerator code to handle the mixture of 15bit and
-//  8bit bitmaps.
-//
-grs_bitmap *gr_create_bitmap2(int w, int h, int type, void *data )
-{
-       grs_bitmap *new;
-
-       new = (grs_bitmap *)malloc( sizeof(grs_bitmap) );
-       new->bm_x = 0;
-       new->bm_y = 0;
-       new->bm_w = w;
-       new->bm_h = h;
-       new->bm_flags = 0;
-    new->bm_type = type;
-    switch(type)
-    {
-        case BM_LINEAR:     new->bm_rowsize = w;            break;
-        case BM_LINEAR15:   new->bm_rowsize = w*PA_BPP;     break;
-        default: Int3();    // unsupported type.
-    }
-    if(data)
-        new->bm_data = data;
-    else
-        new->bm_data = malloc(new->bm_rowsize * new->bm_h);
-       new->bm_handle = 0;
-
-       return new;
-}
-#endif
-
 void gr_init_bitmap( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline, unsigned char * data ) // TODO: virtualize
 {
 #ifdef D1XD3D
 void gr_init_bitmap( grs_bitmap *bm, int mode, int x, int y, int w, int h, int bytesperline, unsigned char * data ) // TODO: virtualize
 {
 #ifdef D1XD3D
@@ -254,16 +105,6 @@ void gr_init_bitmap_data (grs_bitmap *bm) // TODO: virtulize
 #endif
 }
 
 #endif
 }
 
-grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm, int x, int y, int w, int h )
-{
-    grs_bitmap *new;
-
-    new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
-       gr_init_sub_bitmap (new, bm, x, y, w, h);
-
-       return new;
-}
-
 void gr_free_bitmap(grs_bitmap *bm )
 {
        gr_free_bitmap_data (bm);
 void gr_free_bitmap(grs_bitmap *bm )
 {
        gr_free_bitmap_data (bm);
@@ -271,18 +112,6 @@ void gr_free_bitmap(grs_bitmap *bm )
                d_free(bm);
 }
 
                d_free(bm);
 }
 
-void gr_free_sub_bitmap(grs_bitmap *bm )
-{
-       if (bm!=NULL)
-       {
-#ifdef D1XD3D
-               bm->iMagic = 0;
-#endif
-               d_free(bm);
-       }
-}
-
-
 void gr_free_bitmap_data (grs_bitmap *bm) // TODO: virtulize
 {
 #ifdef D1XD3D
 void gr_free_bitmap_data (grs_bitmap *bm) // TODO: virtulize
 {
 #ifdef D1XD3D
@@ -331,77 +160,43 @@ void gr_init_sub_bitmap (grs_bitmap *bm, grs_bitmap *bmParent, int x, int y, int
 
 }
 
 
 }
 
-void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count );
-
-#if !defined(NO_ASM) && defined(__WATCOMC__)
-
-#pragma aux decode_data_asm parm [esi] [ecx] [edi] [ebx] modify exact [esi edi eax ebx ecx] = \
-"again_ddn:"                                                   \
-       "xor    eax,eax"                                \
-       "mov    al,[esi]"                       \
-       "inc    dword ptr [ebx+eax*4]"          \
-       "mov    al,[edi+eax]"           \
-       "mov    [esi],al"                       \
-       "inc    esi"                                    \
-       "dec    ecx"                                    \
-       "jne    again_ddn"
-
-#elif !defined(NO_ASM) && defined(__GNUC__)
-
-inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count ) {
-       int dummy[4];
-   __asm__ __volatile__ (
-    "xorl   %%eax,%%eax;"
-"0:;"
-    "movb   (%%esi), %%al;"
-    "incl   (%%ebx, %%eax, 4);"
-    "movb   (%%edi, %%eax), %%al;"
-    "movb   %%al, (%%esi);"
-    "incl   %%esi;"
-    "decl   %%ecx;"
-    "jne    0b"
-    : "=S" (dummy[0]), "=c" (dummy[1]), "=D" (dummy[2]), "=b" (dummy[3])
-       : "0" (data), "1" (num_pixels), "2" (colormap), "3" (count)
-       : "%eax");
+void gr_free_sub_bitmap(grs_bitmap *bm )
+{
+       if (bm!=NULL)
+       {
+#ifdef D1XD3D
+               bm->iMagic = 0;
+#endif
+               d_free(bm);
+       }
 }
 
 }
 
-#elif !defined(NO_ASM) && defined(_MSC_VER)
 
 
-__inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count )
+grs_bitmap *gr_create_bitmap(int w, int h )
 {
 {
-  __asm {
-       mov esi,[data]
-       mov ecx,[num_pixels]
-       mov edi,[colormap]
-       mov ebx,[count]
-again_ddn:
-       xor eax,eax
-       mov al,[esi]
-       inc dword ptr [ebx+eax*4]
-       mov al,[edi+eax]
-       mov [esi],al
-       inc esi
-       dec ecx
-       jne again_ddn
-  }
+       return gr_create_bitmap_raw (w, h, d_malloc(w * h));
 }
 
 }
 
-#else // NO_ASM or unknown compiler
-
-void decode_data_asm(ubyte *data, int num_pixels, ubyte *colormap, int *count)
+grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data )
 {
 {
-       int i;
-       ubyte mapped;
-
-       for (i = 0; i < num_pixels; i++) {
-               count[*data]++;
-               mapped = *data;
-               *data = colormap[mapped];
-               data++;
-       }
+    grs_bitmap *new;
+
+    new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
+       gr_init_bitmap (new, 0, 0, 0, w, h, w, raw_data);
+
+    return new;
 }
 
 }
 
-#endif
+
+grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm, int x, int y, int w, int h )
+{
+    grs_bitmap *new;
+
+    new = (grs_bitmap *)d_malloc( sizeof(grs_bitmap) );
+       gr_init_sub_bitmap (new, bm, x, y, w, h);
+
+       return new;
+}
 
 void gr_set_bitmap_flags (grs_bitmap *pbm, int flags)
 {
 
 void gr_set_bitmap_flags (grs_bitmap *pbm, int flags)
 {
@@ -443,27 +238,11 @@ void gr_set_super_transparent (grs_bitmap *pbm, int bTransparent)
        }
 }
 
        }
 }
 
-void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq )
-{
-       int i, r, g, b;
-
-       for (i=0; i<256; i++ )  {
-               r = *palette++;
-               g = *palette++;
-               b = *palette++;
-               *colormap++ = gr_find_closest_color( r, g, b );
-               *freq++ = 0;
-       }
-}
-
 void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
 {
        ubyte colormap[256];
        int freq[256];
 
 void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
 {
        ubyte colormap[256];
        int freq[256];
 
-       if (bmp->bm_type != BM_LINEAR)
-               return;  //can't do it
-
        // This should be build_colormap_asm, but we're not using invert table, so...
        build_colormap_good( palette, colormap, freq );
 
        // This should be build_colormap_asm, but we're not using invert table, so...
        build_colormap_good( palette, colormap, freq );
 
@@ -471,7 +250,7 @@ void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color,
                colormap[super_transparent_color] = 254;
 
        if ( (transparent_color>=0) && (transparent_color<=255))
                colormap[super_transparent_color] = 254;
 
        if ( (transparent_color>=0) && (transparent_color<=255))
-               colormap[transparent_color] = TRANSPARENCY_COLOR;
+               colormap[transparent_color] = 255;
 
        decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
 
 
        decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
 
@@ -482,26 +261,34 @@ void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color,
                gr_set_super_transparent (bmp, 0);
 }
 
                gr_set_super_transparent (bmp, 0);
 }
 
+void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq )
+{
+       int i, r, g, b;
+
+       for (i=0; i<256; i++ )  {
+               r = *palette++;         
+               g = *palette++;         
+               b = *palette++;         
+               *colormap++ = gr_find_closest_color( r, g, b );
+               *freq++ = 0;
+       }
+}
+
+
 void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
 {
        ubyte colormap[256];
        int freq[256];
 void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color )
 {
        ubyte colormap[256];
        int freq[256];
+   
        build_colormap_good( palette, colormap, freq );
 
        if ( (super_transparent_color>=0) && (super_transparent_color<=255))
                colormap[super_transparent_color] = 254;
 
        if ( (transparent_color>=0) && (transparent_color<=255))
        build_colormap_good( palette, colormap, freq );
 
        if ( (super_transparent_color>=0) && (super_transparent_color<=255))
                colormap[super_transparent_color] = 254;
 
        if ( (transparent_color>=0) && (transparent_color<=255))
-               colormap[transparent_color] = TRANSPARENCY_COLOR;
-
-       if (bmp->bm_w == bmp->bm_rowsize)
-               decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
-       else {
-               int y;
-               ubyte *p = bmp->bm_data;
-               for (y=0;y<bmp->bm_h;y++,p+=bmp->bm_rowsize)
-                       decode_data_asm(p, bmp->bm_w, colormap, freq );
-       }
+               colormap[transparent_color] = 255;
+
+       decode_data_asm(bmp->bm_data, bmp->bm_w * bmp->bm_h, colormap, freq );
 
        if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
                gr_set_transparent (bmp, 1);
 
        if ( (transparent_color>=0) && (transparent_color<=255) && (freq[transparent_color]>0) )
                gr_set_transparent (bmp, 1);
@@ -527,10 +314,10 @@ void gr_bitmap_check_transparency( grs_bitmap * bmp )
        ubyte * data;
 
        data = bmp->bm_data;
        ubyte * data;
 
        data = bmp->bm_data;
-
+       
        for (y=0; y<bmp->bm_h; y++ )    {
                for (x=0; x<bmp->bm_w; x++ )    {
        for (y=0; y<bmp->bm_h; y++ )    {
                for (x=0; x<bmp->bm_w; x++ )    {
-                       if (*data++ == TRANSPARENCY_COLOR )     {
+                       if (*data++ == 255 )    {
                                gr_set_transparent (bmp, 1);
                                return;
                        }
                                gr_set_transparent (bmp, 1);
                                return;
                        }
index 6d6996f..736ec58 100644 (file)
@@ -1,8 +1,72 @@
-/* $Id: bitmap.h,v 1.4 2002-09-05 07:55:20 btb Exp $ */
 #ifndef _BITMAP_H
 #define _BITMAP_H
 
 #ifndef _BITMAP_H
 #define _BITMAP_H
 
-void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq );
+#ifndef NO_ASM
+#ifdef __WATCOMC__
 void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count );
 void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count );
+#pragma aux decode_data_asm parm [esi] [ecx] [edi] [ebx] modify exact [esi edi eax ebx ecx] = \
+"again_ddn:"                            \
+    "xor    eax,eax"                \
+    "mov    al,[esi]"           \
+    "inc    dword ptr [ebx+eax*4]"      \
+    "mov    al,[edi+eax]"       \
+    "mov    [esi],al"           \
+    "inc    esi"                    \
+    "dec    ecx"                    \
+    "jne    again_ddn"
+#elif defined __GNUC__
+static inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count ) {
+       int dummy[4];
+   __asm__ __volatile__ (
+    "xorl   %%eax,%%eax;"
+"0:;"
+    "movb   (%%esi), %%al;"
+    "incl   (%%ebx, %%eax, 4);"
+    "movb   (%%edi, %%eax), %%al;"
+    "movb   %%al, (%%esi);"
+    "incl   %%esi;"
+    "decl   %%ecx;"
+    "jne    0b"
+    : "=S" (dummy[0]), "=c" (dummy[1]), "=D" (dummy[2]), "=b" (dummy[3])
+       : "0" (data), "1" (num_pixels), "2" (colormap), "3" (count)
+       : "%eax");
+}
+#elif defined _MSC_VER
+__inline void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count )
+{
+  __asm {
+       mov esi,[data]
+       mov ecx,[num_pixels]
+       mov edi,[colormap]
+       mov ebx,[count]
+again_ddn:
+       xor eax,eax
+       mov al,[esi]
+       inc dword ptr [ebx+eax*4]
+       mov al,[edi+eax]
+       mov [esi],al
+       inc esi
+       dec ecx
+       jne again_ddn
+  }
+}
+#else
+#define NO_ASM 1 // We really do want no assembler...
+#endif
+#endif
 
 
+#ifdef NO_ASM
+static void decode_data_asm(ubyte *data, int num_pixels, ubyte *colormap, int *count)
+{
+       int i;
+       ubyte mapped;
+       
+       for (i = 0; i < num_pixels; i++) {
+               count[*data]++;
+               mapped = *data;
+               *data = colormap[mapped];
+               data++;
+       }
+}
+#endif
 #endif
 #endif
index 7fddb41..a091c78 100644 (file)
--- a/2d/box.c
+++ b/2d/box.c
@@ -1,4 +1,3 @@
-/* $Id: box.c,v 1.4 2002-07-17 21:55:19 bradleyb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
index 9b40656..7a6aabf 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: canvas.c,v 1.5 2002-07-17 21:55:19 bradleyb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
index cd7f59d..42b7ff2 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: circle.c,v 1.4 2002-10-10 18:55:32 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,7 +7,7 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
@@ -17,7 +16,7 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 #endif
 
 #ifdef RCS
 #endif
 
 #ifdef RCS
-static char rcsid[] = "$Id: circle.c,v 1.4 2002-10-10 18:55:32 btb Exp $";
+static char rcsid[] = "$Id: circle.c,v 1.2 2001-01-31 15:17:47 bradleyb Exp $";
 #endif
 
 #include "u_mem.h"
 #endif
 
 #include "u_mem.h"
@@ -52,9 +51,9 @@ int gr_circle(fix xc1,fix yc1,fix r1)
                gr_pixel( xc-y, yc+x );
                gr_pixel( xc+y, yc+x );
 
                gr_pixel( xc-y, yc+x );
                gr_pixel( xc+y, yc+x );
 
-               if (p<0)
+               if (p<0) 
                        p=p+(x<<2)+6;
                        p=p+(x<<2)+6;
-               else {
+               else    {
                        // Draw the second octant
                        gr_pixel( xc-x, yc-y );
                        gr_pixel( xc+x, yc-y );
                        // Draw the second octant
                        gr_pixel( xc-x, yc-y );
                        gr_pixel( xc+x, yc-y );
@@ -65,7 +64,7 @@ int gr_circle(fix xc1,fix yc1,fix r1)
                }
                x++;
        }
                }
                x++;
        }
-       if(x==y) {
+       if(x==y)        {
                gr_pixel( xc-x, yc-y );
                gr_pixel( xc+x, yc-y );
                gr_pixel( xc-x, yc+y );
                gr_pixel( xc-x, yc-y );
                gr_pixel( xc+x, yc-y );
                gr_pixel( xc-x, yc+y );
@@ -93,9 +92,9 @@ int gr_ucircle(fix xc1,fix yc1,fix r1)
                gr_upixel( xc-y, yc+x );
                gr_upixel( xc+y, yc+x );
 
                gr_upixel( xc-y, yc+x );
                gr_upixel( xc+y, yc+x );
 
-               if (p<0)
+               if (p<0) 
                        p=p+(x<<2)+6;
                        p=p+(x<<2)+6;
-               else {
+               else    {
                        // Draw the second octant
                        gr_upixel( xc-x, yc-y );
                        gr_upixel( xc+x, yc-y );
                        // Draw the second octant
                        gr_upixel( xc-x, yc-y );
                        gr_upixel( xc+x, yc-y );
@@ -106,7 +105,7 @@ int gr_ucircle(fix xc1,fix yc1,fix r1)
                }
                x++;
        }
                }
                x++;
        }
-       if(x==y) {
+       if(x==y)        {
                gr_upixel( xc-x, yc-y );
                gr_upixel( xc+x, yc-y );
                gr_upixel( xc-x, yc+y );
                gr_upixel( xc-x, yc-y );
                gr_upixel( xc+x, yc-y );
                gr_upixel( xc-x, yc+y );
index 59919aa..b4bd2f1 100644 (file)
--- a/2d/clip.h
+++ b/2d/clip.h
@@ -1,4 +1,3 @@
-/* $Id: clip.h,v 1.3 2002-10-10 18:55:32 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,46 +7,52 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 /*
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 /*
+ * $Source: /cvs/cvsroot/d2x/2d/clip.h,v $
+ * $Revision: 1.1.1.1 $
+ * $Author: bradleyb $
+ * $Date: 2001-01-19 03:29:57 $
  *
  * Macros used for clipping
  *
  *
  * Macros used for clipping
  *
- * Old Log:
+ * $Log: not supported by cvs2svn $
+ * Revision 1.1.1.1  1999/06/14 21:57:39  donut
+ * Import of d1x 1.37 source.
  *
  * Revision 1.3  1993/10/15  16:22:28  john
  * *** empty log message ***
  *
  * Revision 1.3  1993/10/15  16:22:28  john
  * *** empty log message ***
- *
+ * 
  * Revision 1.2  1993/09/29  16:14:31  john
  * made work with fix point
  * Revision 1.2  1993/09/29  16:14:31  john
  * made work with fix point
- *
+ * 
  * Revision 1.1  1993/09/08  11:40:53  john
  * Initial revision
  * Revision 1.1  1993/09/08  11:40:53  john
  * Initial revision
- *
+ * 
  *
  */
 
 
  *
  */
 
 
-/*#define MIN(a,b)    (((a) < (b)) ? (a) : (b))
+/*#define MIN(a,b)       (((a) < (b)) ? (a) : (b))
 #define MAX(a,b)        (((a) > (b)) ? (a) : (b))
 */
 #define IABS(x)         (((x) < 0) ?  -(x) : (x))
 
 #define EXCHG(a,b) do {                                                 \
 #define MAX(a,b)        (((a) > (b)) ? (a) : (b))
 */
 #define IABS(x)         (((x) < 0) ?  -(x) : (x))
 
 #define EXCHG(a,b) do {                                                 \
-       int __temp__ = (a);                                                 \
-       (a) = (b);                                                          \
-       (b) = __temp__;                                                     \
+    int __temp__ = (a);                                                 \
+    (a) = (b);                                                          \
+    (b) = __temp__;                                                     \
 } while(0)
 
 // sort two values
 #define SORT2(a,b) do {                                                 \
 } while(0)
 
 // sort two values
 #define SORT2(a,b) do {                                                 \
-       if((a) > (b)) EXCHG(a,b);                                           \
+    if((a) > (b)) EXCHG(a,b);                                           \
 } while(0)
 
 # define SCALE(var,arg,num,den)                                         \
 } while(0)
 
 # define SCALE(var,arg,num,den)                                         \
-       ((var) = ((arg) * (num)) / (den))
+    ((var) = ((arg) * (num)) / (den))
 
 # define USCALE(var,arg,num,den)                                        \
        ((var) = ((unsigned)(arg) * (unsigned)(num)) / (unsigned)(den))
 
 # define USCALE(var,arg,num,den)                                        \
        ((var) = ((unsigned)(arg) * (unsigned)(num)) / (unsigned)(den))
@@ -55,99 +60,99 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 # define FSCALE(var,arg,num,den) ((var) = fixmuldiv((arg),(num),(den)))
 
 #define CLIPDOT(xx,yy,WHEN_OUTSIDE,WHEN_CLIPPED) {                      \
 # define FSCALE(var,arg,num,den) ((var) = fixmuldiv((arg),(num),(den)))
 
 #define CLIPDOT(xx,yy,WHEN_OUTSIDE,WHEN_CLIPPED) {                      \
-       if((xx > XMAX) || (xx < XMIN)) { WHEN_OUTSIDE; }                    \
-       if((yy > YMAX) || (yy < YMIN)) { WHEN_OUTSIDE; }                    \
+    if((xx > XMAX) || (xx < XMIN)) { WHEN_OUTSIDE; }                    \
+    if((yy > YMAX) || (yy < YMIN)) { WHEN_OUTSIDE; }                    \
 }
 
 #define CLIPHLINE(x1,x2,yy,WHEN_OUTSIDE,WHEN_CLIPPED) {                 \
 }
 
 #define CLIPHLINE(x1,x2,yy,WHEN_OUTSIDE,WHEN_CLIPPED) {                 \
-       if(x1 > x2) EXCHG(x1,x2);                                           \
-       if((x1 > XMAX) || (x2 < XMIN)) { WHEN_OUTSIDE; }                    \
-       if((yy > YMAX) || (yy < YMIN)) { WHEN_OUTSIDE; }                    \
-       if(x1 < XMIN) { x1 = XMIN; WHEN_CLIPPED; }                          \
-       if(x2 > XMAX) { x2 = XMAX; WHEN_CLIPPED; }                          \
+    if(x1 > x2) EXCHG(x1,x2);                                           \
+    if((x1 > XMAX) || (x2 < XMIN)) { WHEN_OUTSIDE; }                    \
+    if((yy > YMAX) || (yy < YMIN)) { WHEN_OUTSIDE; }                    \
+    if(x1 < XMIN) { x1 = XMIN; WHEN_CLIPPED; }                          \
+    if(x2 > XMAX) { x2 = XMAX; WHEN_CLIPPED; }                          \
 }
 
 #define CLIPVLINE(xx,y1,y2,WHEN_OUTSIDE,WHEN_CLIPPED) {                 \
 }
 
 #define CLIPVLINE(xx,y1,y2,WHEN_OUTSIDE,WHEN_CLIPPED) {                 \
-       if(y1 > y2) EXCHG(y1,y2);                                           \
-       if((xx > XMAX) || (xx < XMIN)) { WHEN_OUTSIDE; }                    \
-       if((y1 > YMAX) || (y2 < YMIN)) { WHEN_OUTSIDE; }                    \
-       if(y1 < YMIN) { y1 = YMIN; WHEN_CLIPPED; }                          \
-       if(y2 > YMAX) { y2 = YMAX; WHEN_CLIPPED; }                          \
+    if(y1 > y2) EXCHG(y1,y2);                                           \
+    if((xx > XMAX) || (xx < XMIN)) { WHEN_OUTSIDE; }                    \
+    if((y1 > YMAX) || (y2 < YMIN)) { WHEN_OUTSIDE; }                    \
+    if(y1 < YMIN) { y1 = YMIN; WHEN_CLIPPED; }                          \
+    if(y2 > YMAX) { y2 = YMAX; WHEN_CLIPPED; }                          \
 }
 
 #define CLIPBOX(x1,y1,x2,y2,WHEN_OUTSIDE,WHEN_CLIPPED) {                \
 }
 
 #define CLIPBOX(x1,y1,x2,y2,WHEN_OUTSIDE,WHEN_CLIPPED) {                \
-       if(x1 > x2) EXCHG(x1,x2);                                           \
-       if(y1 > y2) EXCHG(y1,y2);                                           \
-       if((x1 > XMAX) || (x2 < 0)) { WHEN_OUTSIDE; }                       \
-       if((y1 > YMAX) || (y2 < 0)) { WHEN_OUTSIDE; }                       \
-       if(x1 < 0) { x1 = 0; WHEN_CLIPPED; }                                \
-       if(y1 < 0) { y1 = 0; WHEN_CLIPPED; }                                \
-       if(x2 > XMAX) { x2 = XMAX; WHEN_CLIPPED; }                          \
-       if(y2 > YMAX) { y2 = YMAX; WHEN_CLIPPED; }                          \
+    if(x1 > x2) EXCHG(x1,x2);                                           \
+    if(y1 > y2) EXCHG(y1,y2);                                           \
+    if((x1 > XMAX) || (x2 < 0)) { WHEN_OUTSIDE; }                       \
+    if((y1 > YMAX) || (y2 < 0)) { WHEN_OUTSIDE; }                       \
+    if(x1 < 0) { x1 = 0; WHEN_CLIPPED; }                                \
+    if(y1 < 0) { y1 = 0; WHEN_CLIPPED; }                                \
+    if(x2 > XMAX) { x2 = XMAX; WHEN_CLIPPED; }                          \
+    if(y2 > YMAX) { y2 = YMAX; WHEN_CLIPPED; }                          \
 }
 }
-
+    
 #define CLIPLINE(x1,y1,x2,y2,XMIN,YMIN,XMAX,YMAX,WHEN_OUTSIDE,WHEN_CLIPPED,MY_SCALE) do {       \
 #define CLIPLINE(x1,y1,x2,y2,XMIN,YMIN,XMAX,YMAX,WHEN_OUTSIDE,WHEN_CLIPPED,MY_SCALE) do {       \
-       register int temp;                                                  \
-       if(y1 > y2)                                                         \
-               { EXCHG(y1,y2); EXCHG(x1,x2); }                                 \
-       if((y2 < YMIN) || (y1 > YMAX))                                      \
-               { WHEN_OUTSIDE; }                                               \
-       if(x1 < x2) {                                                       \
-               if((x2 < XMIN) || (x1 > XMAX)) {                                \
-                       WHEN_OUTSIDE;                                               \
-               }                                                               \
-               if(x1 < XMIN) {                                                 \
+    register int temp;                                                  \
+    if(y1 > y2)                                                         \
+        { EXCHG(y1,y2); EXCHG(x1,x2); }                                 \
+    if((y2 < YMIN) || (y1 > YMAX))                                      \
+        { WHEN_OUTSIDE; }                                               \
+    if(x1 < x2) {                                                       \
+        if((x2 < XMIN) || (x1 > XMAX)) {                                \
+            WHEN_OUTSIDE;                                               \
+        }                                                               \
+        if(x1 < XMIN) {                                                 \
                        MY_SCALE(temp,(y2 - y1),(XMIN - x1),(x2 - x1)); \
                        MY_SCALE(temp,(y2 - y1),(XMIN - x1),(x2 - x1)); \
-                       if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }                   \
-                       x1 = XMIN;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-               if(x2 > XMAX) {                                                 \
+            if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }                   \
+            x1 = XMIN;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+        if(x2 > XMAX) {                                                 \
                        MY_SCALE(temp,(y2 - y1),(x2 - XMAX),(x2 - x1)); \
                        MY_SCALE(temp,(y2 - y1),(x2 - XMAX),(x2 - x1)); \
-                       if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }                   \
-                       x2 = XMAX;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-               if(y1 < YMIN) {                                                 \
+            if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }                   \
+            x2 = XMAX;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+        if(y1 < YMIN) {                                                 \
                        MY_SCALE(temp,(x2 - x1),(YMIN - y1),(y2 - y1)); \
                        MY_SCALE(temp,(x2 - x1),(YMIN - y1),(y2 - y1)); \
-                       x1 += temp;                                                 \
-                       y1 = YMIN;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-               if(y2 > YMAX) {                                                 \
+            x1 += temp;                                                 \
+            y1 = YMIN;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+        if(y2 > YMAX) {                                                 \
                        MY_SCALE(temp,(x2 - x1),(y2 - YMAX),(y2 - y1)); \
                        MY_SCALE(temp,(x2 - x1),(y2 - YMAX),(y2 - y1)); \
-                       x2 -= temp;                                                 \
-                       y2 = YMAX;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-       }                                                                   \
-       else {                                                              \
-               if((x1 < XMIN) || (x2 > XMAX)) {                                \
-                       WHEN_OUTSIDE;                                               \
-               }                                                               \
-               if(x1 > XMAX) {                                                 \
+            x2 -= temp;                                                 \
+            y2 = YMAX;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+    }                                                                   \
+    else {                                                              \
+        if((x1 < XMIN) || (x2 > XMAX)) {                                \
+            WHEN_OUTSIDE;                                               \
+        }                                                               \
+        if(x1 > XMAX) {                                                 \
                        MY_SCALE(temp,(y2 - y1),(x1 - XMAX),(x1 - x2)); \
                        MY_SCALE(temp,(y2 - y1),(x1 - XMAX),(x1 - x2)); \
-                       if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }                   \
-                       x1 = XMAX;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-               if(x2 < XMIN) {                                                 \
+            if((y1 += temp) > YMAX) { WHEN_OUTSIDE; }                   \
+            x1 = XMAX;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+        if(x2 < XMIN) {                                                 \
                        MY_SCALE(temp,(y2 - y1),(XMIN - x2),(x1 - x2)); \
                        MY_SCALE(temp,(y2 - y1),(XMIN - x2),(x1 - x2)); \
-                       if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }                   \
-                       x2 = XMIN;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-               if(y1 < YMIN) {                                                 \
+            if((y2 -= temp) < YMIN) { WHEN_OUTSIDE; }                   \
+            x2 = XMIN;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+        if(y1 < YMIN) {                                                 \
                        MY_SCALE(temp,(x1 - x2),(YMIN - y1),(y2 - y1)); \
                        MY_SCALE(temp,(x1 - x2),(YMIN - y1),(y2 - y1)); \
-                       x1 -= temp;                                                 \
-                       y1 = YMIN;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-               if(y2 > YMAX) {                                                 \
+            x1 -= temp;                                                 \
+            y1 = YMIN;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+        if(y2 > YMAX) {                                                 \
                        MY_SCALE(temp,(x1 - x2),(y2 - YMAX),(y2 - y1)); \
                        MY_SCALE(temp,(x1 - x2),(y2 - YMAX),(y2 - y1)); \
-                       x2 += temp;                                                 \
-                       y2 = YMAX;                                                  \
-                       WHEN_CLIPPED;                                               \
-               }                                                               \
-       }                                                                   \
+            x2 += temp;                                                 \
+            y2 = YMAX;                                                  \
+            WHEN_CLIPPED;                                               \
+        }                                                               \
+    }                                                                   \
 } while(0)
 } while(0)
index 6638b3d..a8582ad 100644 (file)
--- a/2d/disc.c
+++ b/2d/disc.c
@@ -1,4 +1,3 @@
-/* $Id: disc.c,v 1.4 2002-10-10 18:55:32 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,7 +7,7 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
@@ -44,9 +43,9 @@ int gr_disk(fix xc1,fix yc1,fix r1)
                gr_scanline( xc-y, xc+y, yc-x );
                gr_scanline( xc-y, xc+y, yc+x );
 
                gr_scanline( xc-y, xc+y, yc-x );
                gr_scanline( xc-y, xc+y, yc+x );
 
-               if (p<0)
+               if (p<0) 
                        p=p+(x<<2)+6;
                        p=p+(x<<2)+6;
-               else {
+               else    {
                        // Draw the second octant
                        gr_scanline( xc-x, xc+x, yc-y );
                        gr_scanline( xc-x, xc+x, yc+y );
                        // Draw the second octant
                        gr_scanline( xc-x, xc+x, yc-y );
                        gr_scanline( xc-x, xc+x, yc+y );
@@ -55,7 +54,7 @@ int gr_disk(fix xc1,fix yc1,fix r1)
                }
                x++;
        }
                }
                x++;
        }
-       if(x==y) {
+       if(x==y)        {
                gr_scanline( xc-x, xc+x, yc-y );
                gr_scanline( xc-x, xc+x, yc+y );
        }
                gr_scanline( xc-x, xc+x, yc-y );
                gr_scanline( xc-x, xc+x, yc+y );
        }
@@ -79,9 +78,9 @@ int gr_udisk(fix xc1,fix yc1,fix r1)
                gr_uscanline( xc-y, xc+y, yc-x );
                gr_uscanline( xc-y, xc+y, yc+x );
 
                gr_uscanline( xc-y, xc+y, yc-x );
                gr_uscanline( xc-y, xc+y, yc+x );
 
-               if (p<0)
+               if (p<0) 
                        p=p+(x<<2)+6;
                        p=p+(x<<2)+6;
-               else {
+               else    {
                        // Draw the second octant
                        gr_uscanline( xc-x, xc+x, yc-y );
                        gr_uscanline( xc-x, xc+x, yc+y );
                        // Draw the second octant
                        gr_uscanline( xc-x, xc+x, yc-y );
                        gr_uscanline( xc-x, xc+x, yc+y );
@@ -90,7 +89,7 @@ int gr_udisk(fix xc1,fix yc1,fix r1)
                }
                x++;
        }
                }
                x++;
        }
-       if(x==y) {
+       if(x==y)        {
                gr_uscanline( xc-x, xc+x, yc-y );
                gr_uscanline( xc-x, xc+x, yc+y );
        }
                gr_uscanline( xc-x, xc+x, yc-y );
                gr_uscanline( xc-x, xc+x, yc+y );
        }
index eada64b..259f012 100644 (file)
--- a/2d/font.c
+++ b/2d/font.c
@@ -1,4 +1,3 @@
-/* $Id: font.c,v 1.25 2003-03-19 19:21:34 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,14 +7,31 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
-/*
+/* $Source: /cvs/cvsroot/d2x/2d/font.c,v $
+ * $Revision: 1.10 $
+ * $Author: bradleyb $
+ * $Date: 2001-11-14 09:34:32 $
  *
  * Graphical routines for drawing fonts.
  *
  *
  * Graphical routines for drawing fonts.
  *
+ * $Log: not supported by cvs2svn $
+ * Revision 1.9  2001/11/08 10:37:25  bradleyb
+ * free OGL font data when rereading
+ *
+ * Revision 1.8  2001/11/04 03:58:25  bradleyb
+ * re-init ogl fonts after remapping colors.
+ *
+ * Revision 1.7  2001/11/02 10:46:23  bradleyb
+ * fixed gr_remap_font, minor stuff
+ *
+ * Revision 1.6  2001/11/02 02:03:35  bradleyb
+ * Enable OpenGL fonts\!
+ *
+ *
  */
 
 #ifdef HAVE_CONFIG_H
  */
 
 #ifdef HAVE_CONFIG_H
@@ -54,7 +70,6 @@ COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 typedef struct openfont {
        char filename[FILENAME_LEN];
        grs_font *ptr;
 typedef struct openfont {
        char filename[FILENAME_LEN];
        grs_font *ptr;
-       char *dataptr;
 } openfont;
 
 //list of open fonts, for use (for now) for palette remapping
 } openfont;
 
 //list of open fonts, for use (for now) for palette remapping
@@ -1102,7 +1117,7 @@ int gr_internal_color_string(int x, int y, char *s )
 }
 
 #else //OGL
 }
 
 #else //OGL
-
+#include "../main/inferno.h"
 #include "ogl_init.h"
 #include "args.h"
 //font handling routines for OpenGL - Added 9/25/99 Matthew Mueller - they are here instead of in arch/ogl because they use all these defines
 #include "ogl_init.h"
 #include "args.h"
 //font handling routines for OpenGL - Added 9/25/99 Matthew Mueller - they are here instead of in arch/ogl because they use all these defines
@@ -1338,8 +1353,7 @@ int ogl_internal_string(int x, int y, char *s )
 //                     ogl_ubitblt(FONT->ft_bitmaps[letter].bm_w,FONT->ft_bitmaps[letter].bm_h,xx,yy,0,0,&FONT->ft_bitmaps[letter],NULL);
 //                     if (*text_ptr>='0' && *text_ptr<='9'){
                        if (FFLAGS&FT_COLOR)
 //                     ogl_ubitblt(FONT->ft_bitmaps[letter].bm_w,FONT->ft_bitmaps[letter].bm_h,xx,yy,0,0,&FONT->ft_bitmaps[letter],NULL);
 //                     if (*text_ptr>='0' && *text_ptr<='9'){
                        if (FFLAGS&FT_COLOR)
-                               //gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]);
-                               gr_bitmapm(xx,yy,&FONT->ft_bitmaps[letter]); // credits need clipping
+                               gr_ubitmapm(xx,yy,&FONT->ft_bitmaps[letter]);
                        else{
                                if (grd_curcanv->cv_bitmap.bm_type==BM_OGL)
                                        ogl_ubitmapm_c(xx,yy,&FONT->ft_bitmaps[letter],FG_COLOR);
                        else{
                                if (grd_curcanv->cv_bitmap.bm_type==BM_OGL)
                                        ogl_ubitmapm_c(xx,yy,&FONT->ft_bitmaps[letter],FG_COLOR);
@@ -1533,20 +1547,16 @@ void gr_close_font( grs_font * font )
        if (font)
        {
                int fontnum;
        if (font)
        {
                int fontnum;
-               char * font_data;
 
                //find font in list
                for (fontnum=0;fontnum<MAX_OPEN_FONTS && open_font[fontnum].ptr!=font;fontnum++);
                Assert(fontnum<MAX_OPEN_FONTS); //did we find slot?
 
 
                //find font in list
                for (fontnum=0;fontnum<MAX_OPEN_FONTS && open_font[fontnum].ptr!=font;fontnum++);
                Assert(fontnum<MAX_OPEN_FONTS); //did we find slot?
 
-               font_data = open_font[fontnum].dataptr;
-               d_free( font_data );
-
                open_font[fontnum].ptr = NULL;
                open_font[fontnum].ptr = NULL;
-               open_font[fontnum].dataptr = NULL;
 
                if ( font->ft_chars )
                        d_free( font->ft_chars );
 
                if ( font->ft_chars )
                        d_free( font->ft_chars );
+               d_free( font->oldfont );
 #ifdef OGL
                if (font->ft_bitmaps)
                        d_free( font->ft_bitmaps );
 #ifdef OGL
                if (font->ft_bitmaps)
                        d_free( font->ft_bitmaps );
@@ -1555,7 +1565,6 @@ void gr_close_font( grs_font * font )
 #endif
                d_free( font );
 
 #endif
                d_free( font );
 
-
        }
 }
 
        }
 }
 
@@ -1568,51 +1577,44 @@ void gr_remap_color_fonts()
                grs_font *font;
 
                font = open_font[fontnum].ptr;
                grs_font *font;
 
                font = open_font[fontnum].ptr;
-
+               
                if (font && (font->ft_flags & FT_COLOR))
                if (font && (font->ft_flags & FT_COLOR))
-                       gr_remap_font(font, open_font[fontnum].filename, open_font[fontnum].dataptr);
+                       gr_remap_font(font,open_font[fontnum].filename);
        }
 }
 
        }
 }
 
-#ifdef FAST_FILE_IO
-#define grs_font_read(gf, fp) cfread(gf, GRS_FONT_SIZE, 1, fp)
-#else
-/*
- * reads a grs_font structure from a CFILE
- */
-void grs_font_read(grs_font *gf, CFILE *fp)
-{
-       gf->ft_w = cfile_read_short(fp);
-       gf->ft_h = cfile_read_short(fp);
-       gf->ft_flags = cfile_read_short(fp);
-       gf->ft_baseline = cfile_read_short(fp);
-       gf->ft_minchar = cfile_read_byte(fp);
-       gf->ft_maxchar = cfile_read_byte(fp);
-       gf->ft_bytewidth = cfile_read_short(fp);
-       gf->ft_data = (ubyte *)cfile_read_int(fp);
-       gf->ft_chars = (ubyte **)cfile_read_int(fp);
-       gf->ft_widths = (short *)cfile_read_int(fp);
-       gf->ft_kerndata = (ubyte *)cfile_read_int(fp);
-}
+void build_colormap_good( ubyte * palette, ubyte * colormap, int * freq );
+void decode_data_asm(ubyte *data, int num_pixels, ubyte * colormap, int * count );
+#ifdef __WATCOMC__
+#pragma aux decode_data_asm parm [esi] [ecx] [edi] [ebx] modify exact [esi edi eax ebx ecx] = \
+"again_ddn:"                                                   \
+       "xor    eax,eax"                                \
+       "mov    al,[esi]"                       \
+       "inc    dword ptr [ebx+eax*4]"          \
+       "mov    al,[edi+eax]"           \
+       "mov    [esi],al"                       \
+       "inc    esi"                                    \
+       "dec    ecx"                                    \
+       "jne    again_ddn"
+
 #endif
 
 grs_font * gr_init_font( char * fontname )
 {
        static int first_time=1;
 #endif
 
 grs_font * gr_init_font( char * fontname )
 {
        static int first_time=1;
-       grs_font *font;
-       char *font_data;
+       old_grs_font *font;
+       grs_font *newfont;
        int i,fontnum;
        unsigned char * ptr;
        int nchars;
        CFILE *fontfile;
        int i,fontnum;
        unsigned char * ptr;
        int nchars;
        CFILE *fontfile;
-       char file_id[4];
-       int datasize;   //size up to (but not including) palette
+       u_int32_t file_id;
+       int32_t datasize;       //size up to (but not including) palette
 
        if (first_time) {
                int i;
                for (i=0;i<MAX_OPEN_FONTS;i++)
                        open_font[i].ptr = NULL;
 
        if (first_time) {
                int i;
                for (i=0;i<MAX_OPEN_FONTS;i++)
                        open_font[i].ptr = NULL;
-                       open_font[i].dataptr = NULL;
                first_time=0;
        }
 
                first_time=0;
        }
 
@@ -1624,73 +1626,71 @@ grs_font * gr_init_font( char * fontname )
 
        fontfile = cfopen(fontname, "rb");
 
 
        fontfile = cfopen(fontname, "rb");
 
-       if (!fontfile) {
-               con_printf(CON_VERBOSE, "Can't open font file %s\n", fontname);
-               return NULL;
-       }
+       if (!fontfile)
+               Error( "Can't open font file %s", fontname );
 
 
-       cfread(file_id, 4, 1, fontfile);
-       if ( !strncmp( file_id, "NFSP", 4 ) ) {
-               con_printf(CON_NORMAL, "File %s is not a font file\n", fontname );
-               return NULL;
-       }
+       cfread(&file_id,sizeof(file_id),1,fontfile);
+       file_id=swapint(file_id);
+       cfread(&datasize,sizeof(datasize),1,fontfile);
+       datasize=swapint(datasize);
 
 
-       datasize = cfile_read_int(fontfile);
-       datasize -= GRS_FONT_SIZE; // subtract the size of the header.
+       if (file_id != MAKE_SIG('N','F','S','P'))
+               Error( "File %s is not a font file", fontname );
 
 
-       MALLOC(font, grs_font, sizeof(grs_font));
-       grs_font_read(font, fontfile);
+       font = (old_grs_font *) d_malloc(datasize);
+       newfont = (grs_font *) d_malloc(sizeof(grs_font));
+       newfont->oldfont=font;
 
 
-       MALLOC(font_data, char, datasize);
-       cfread(font_data, 1, datasize, fontfile);
+       open_font[fontnum].ptr = newfont;
 
 
-       open_font[fontnum].ptr = font;
-       open_font[fontnum].dataptr = font_data;
+       cfread(font,1,datasize,fontfile);
 
 
-       // make these offsets relative to font_data
-       font->ft_data = (ubyte *)((int)font->ft_data - GRS_FONT_SIZE);
-       font->ft_widths = (short *)((int)font->ft_widths - GRS_FONT_SIZE);
-       font->ft_kerndata = (ubyte *)((int)font->ft_kerndata - GRS_FONT_SIZE);
+       newfont->ft_flags=swapint(font->ft_flags);
+       newfont->ft_w=swapshort(font->ft_w);
+       newfont->ft_h=swapshort(font->ft_h);
+       newfont->ft_baseline=swapshort(font->ft_baseline);
+       newfont->ft_maxchar=font->ft_maxchar;
+       newfont->ft_minchar=font->ft_minchar;
+       newfont->ft_bytewidth=swapshort(font->ft_bytewidth);
 
 
-       nchars = font->ft_maxchar - font->ft_minchar + 1;
+       nchars = newfont->ft_maxchar-newfont->ft_minchar+1;
 
 
-       if (font->ft_flags & FT_PROPORTIONAL) {
+       if (newfont->ft_flags & FT_PROPORTIONAL) {
 
 
-               font->ft_widths = (short *) &font_data[(int)font->ft_widths];
-               font->ft_data = &font_data[(int)font->ft_data];
-               font->ft_chars = (unsigned char **)d_malloc( nchars * sizeof(unsigned char *));
+               newfont->ft_widths = (short *) (swapint(font->ft_widths) + ((ubyte *) font));
+               newfont->ft_data = (swapint(font->ft_data)) + ((ubyte *) font);
+               newfont->ft_chars = (unsigned char **)d_malloc( nchars * sizeof(unsigned char *));
 
 
-               ptr = font->ft_data;
+               ptr = newfont->ft_data;
 
                for (i=0; i< nchars; i++ ) {
 
                for (i=0; i< nchars; i++ ) {
-                       font->ft_widths[i] = INTEL_SHORT(font->ft_widths[i]);
-                       font->ft_chars[i] = ptr;
-                       if (font->ft_flags & FT_COLOR)
-                               ptr += font->ft_widths[i] * font->ft_h;
+                       newfont->ft_chars[i] = ptr;
+                       if (newfont->ft_flags & FT_COLOR)
+                               ptr += newfont->ft_widths[i] * newfont->ft_h;
                        else
                        else
-                               ptr += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h;
+                               ptr += BITS_TO_BYTES(newfont->ft_widths[i]) * newfont->ft_h;
                }
 
        } else  {
 
                }
 
        } else  {
 
-               font->ft_data   = font_data;
-               font->ft_chars  = NULL;
-               font->ft_widths = NULL;
+               newfont->ft_data   = ((unsigned char *) font) + sizeof(*font);
+               newfont->ft_chars  = NULL;
+               newfont->ft_widths = NULL;
 
 
-               ptr = font->ft_data + (nchars * font->ft_w * font->ft_h);
+               ptr = newfont->ft_data + (nchars * newfont->ft_w * newfont->ft_h);
        }
 
        }
 
-       if (font->ft_flags & FT_KERNED)
-               font->ft_kerndata = &font_data[(int)font->ft_kerndata];
+       if (newfont->ft_flags & FT_KERNED)
+               newfont->ft_kerndata = swapint(font->ft_kerndata) + ((ubyte *) font);
 
 
-       if (font->ft_flags & FT_COLOR) {                //remap palette
+       if (newfont->ft_flags & FT_COLOR) {             //remap palette
                ubyte palette[256*3];
                ubyte colormap[256];
                int freq[256];
 
                cfread(palette,3,256,fontfile);         //read the palette
 
                ubyte palette[256*3];
                ubyte colormap[256];
                int freq[256];
 
                cfread(palette,3,256,fontfile);         //read the palette
 
-#ifdef SWAP_0_255                      // swap the first and last palette entries (black and white)
+#ifdef MACINTOSH                       // swap the first and last palette entries (black and white)
                {
                        int i;
                        ubyte c;
                {
                        int i;
                        ubyte c;
@@ -1703,11 +1703,11 @@ grs_font * gr_init_font( char * fontname )
 
 //  we also need to swap the data entries as well.  black is white and white is black
 
 
 //  we also need to swap the data entries as well.  black is white and white is black
 
-                       for (i = 0; i < ptr-font->ft_data; i++) {
-                               if (font->ft_data[i] == 0)
-                                       font->ft_data[i] = 255;
-                               else if (font->ft_data[i] == 255)
-                                       font->ft_data[i] = 0;
+                       for (i = 0; i < ptr-newfont->ft_data; i++) {
+                               if (newfont->ft_data[i] == 0)
+                                       newfont->ft_data[i] = 255;
+                               else if (newfont->ft_data[i] == 255)
+                                       newfont->ft_data[i] = 0;
                        }
 
                }
                        }
 
                }
@@ -1715,17 +1715,20 @@ grs_font * gr_init_font( char * fontname )
 
                build_colormap_good( (ubyte *)&palette, colormap, freq );
 
 
                build_colormap_good( (ubyte *)&palette, colormap, freq );
 
-               colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR;              // changed from colormap[255] = 255 to this for macintosh
+               colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR;              // chaged from colormap[255] = 255 to this for macintosh
 
 
-               decode_data_asm(font->ft_data, ptr - font->ft_data, colormap, freq );
+               decode_data_asm(newfont->ft_data, ptr-newfont->ft_data, colormap, freq );
 
        }
 
        cfclose(fontfile);
 
 
        }
 
        cfclose(fontfile);
 
+//     memcpy(newfont,font,(ubyte*)&newfont->oldfont-(ubyte*)newfont);//fill in newfont data from oldfont struct
+//     mprintf((0,"%i %i %i\n",sizeof(grs_font),sizeof(old_grs_font),(ubyte*)&newfont->oldfont-(ubyte*)newfont));
+
        //set curcanv vars
 
        //set curcanv vars
 
-       FONT        = font;
+       FONT        = newfont;
        FG_COLOR    = 0;
        BG_COLOR    = 0;
 
        FG_COLOR    = 0;
        BG_COLOR    = 0;
 
@@ -1737,22 +1740,22 @@ grs_font * gr_init_font( char * fontname )
        }
 
 #ifdef OGL
        }
 
 #ifdef OGL
-       ogl_init_font(font);
+       ogl_init_font(newfont);
 #endif
 
 #endif
 
-       return font;
+       return newfont;
 
 }
 
 //remap a font by re-reading its data & palette
 
 }
 
 //remap a font by re-reading its data & palette
-void gr_remap_font( grs_font *font, char * fontname, char *font_data )
+void gr_remap_font( grs_font *font, char * fontname )
 {
        int i;
        int nchars;
        CFILE *fontfile;
 {
        int i;
        int nchars;
        CFILE *fontfile;
-       char file_id[4];
-       int datasize;        //size up to (but not including) palette
-       unsigned char *ptr;
+       u_int32_t file_id;
+       int32_t datasize;        //size up to (but not including) palette
+       int data_len;
 
        if (! (font->ft_flags & FT_COLOR))
                return;
 
        if (! (font->ft_flags & FT_COLOR))
                return;
@@ -1762,62 +1765,40 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data )
        if (!fontfile)
                Error( "Can't open font file %s", fontname );
 
        if (!fontfile)
                Error( "Can't open font file %s", fontname );
 
-       cfread(file_id, 4, 1, fontfile);
-       if ( !strncmp( file_id, "NFSP", 4 ) )
-               Error( "File %s is not a font file", fontname );
-
+       file_id = cfile_read_int(fontfile);
        datasize = cfile_read_int(fontfile);
        datasize = cfile_read_int(fontfile);
-       datasize -= GRS_FONT_SIZE; // subtract the size of the header.
 
 
-       d_free(font->ft_chars);
-       grs_font_read(font, fontfile); // have to reread in case mission hogfile overrides font.
-
-       cfread(font_data, 1, datasize, fontfile);  //read raw data
-
-       // make these offsets relative to font_data
-       font->ft_data = (ubyte *)((int)font->ft_data - GRS_FONT_SIZE);
-       font->ft_widths = (short *)((int)font->ft_widths - GRS_FONT_SIZE);
-       font->ft_kerndata = (ubyte *)((int)font->ft_kerndata - GRS_FONT_SIZE);
+       if (file_id != MAKE_SIG('N','F','S','P'))
+               Error( "File %s is not a font file", fontname );
 
 
-       nchars = font->ft_maxchar - font->ft_minchar + 1;
+       nchars = font->ft_maxchar-font->ft_minchar+1;
 
 
+       //compute data length
+       data_len = 0;
        if (font->ft_flags & FT_PROPORTIONAL) {
 
        if (font->ft_flags & FT_PROPORTIONAL) {
 
-               font->ft_widths = (short *) &font_data[(int)font->ft_widths];
-               font->ft_data = &font_data[(int)font->ft_data];
-               font->ft_chars = (unsigned char **)d_malloc( nchars * sizeof(unsigned char *));
-
-               ptr = font->ft_data;
-
                for (i=0; i< nchars; i++ ) {
                for (i=0; i< nchars; i++ ) {
-                       font->ft_widths[i] = INTEL_SHORT(font->ft_widths[i]);
-                       font->ft_chars[i] = ptr;
                        if (font->ft_flags & FT_COLOR)
                        if (font->ft_flags & FT_COLOR)
-                               ptr += font->ft_widths[i] * font->ft_h;
+                               data_len += font->ft_widths[i] * font->ft_h;
                        else
                        else
-                               ptr += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h;
+                               data_len += BITS_TO_BYTES(font->ft_widths[i]) * font->ft_h;
                }
 
                }
 
-       } else  {
-
-               font->ft_data   = font_data;
-               font->ft_chars  = NULL;
-               font->ft_widths = NULL;
+       } else
+               data_len = nchars * font->ft_w * font->ft_h;
 
 
-               ptr = font->ft_data + (nchars * font->ft_w * font->ft_h);
-       }
-
-       if (font->ft_flags & FT_KERNED)
-               font->ft_kerndata = &font_data[(int)font->ft_kerndata];
+       cfread(font->oldfont, 1, datasize, fontfile);   //read raw data
 
        if (font->ft_flags & FT_COLOR) {                //remap palette
                ubyte palette[256*3];
                ubyte colormap[256];
                int freq[256];
 
 
        if (font->ft_flags & FT_COLOR) {                //remap palette
                ubyte palette[256*3];
                ubyte colormap[256];
                int freq[256];
 
+               cfseek(fontfile,-sizeof(palette),SEEK_END);
+
                cfread(palette,3,256,fontfile);         //read the palette
 
                cfread(palette,3,256,fontfile);         //read the palette
 
-#ifdef SWAP_0_255                      // swap the first and last palette entries (black and white)
+#ifdef MACINTOSH                       // swap the first and last palette entries (black and white)
                {
                        int i;
                        ubyte c;
                {
                        int i;
                        ubyte c;
@@ -1830,7 +1811,7 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data )
 
 //  we also need to swap the data entries as well.  black is white and white is black
 
 
 //  we also need to swap the data entries as well.  black is white and white is black
 
-                       for (i = 0; i < ptr-font->ft_data; i++) {
+                       for (i = 0; i < data_len; i++) {
                                if (font->ft_data[i] == 0)
                                        font->ft_data[i] = 255;
                                else if (font->ft_data[i] == 255)
                                if (font->ft_data[i] == 0)
                                        font->ft_data[i] = 255;
                                else if (font->ft_data[i] == 255)
@@ -1842,9 +1823,9 @@ void gr_remap_font( grs_font *font, char * fontname, char *font_data )
 
                build_colormap_good( (ubyte *)&palette, colormap, freq );
 
 
                build_colormap_good( (ubyte *)&palette, colormap, freq );
 
-               colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR;              // changed from colormap[255] = 255 to this for macintosh
+               colormap[TRANSPARENCY_COLOR] = TRANSPARENCY_COLOR;      // changed from         colormap[255] = 255;
 
 
-               decode_data_asm(font->ft_data, ptr - font->ft_data, colormap, freq );
+               decode_data_asm(font->ft_data, data_len, colormap, freq );
 
        }
 
 
        }
 
index 92e37aa..d8fb394 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: gpixel.c,v 1.5 2002-10-10 18:55:32 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,7 +7,7 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 
@@ -34,7 +33,7 @@ unsigned char gr_ugpixel( grs_bitmap * bitmap, int x, int y )
 #endif
                return bitmap->bm_data[ bitmap->bm_rowsize*y + x ];
 #ifdef __DJGPP__
 #endif
                return bitmap->bm_data[ bitmap->bm_rowsize*y + x ];
 #ifdef __DJGPP__
-       case BM_MODEX:
+        case BM_MODEX:
                x += bitmap->bm_x;
                y += bitmap->bm_y;
                gr_modex_setplane( x & 3 );
                x += bitmap->bm_x;
                y += bitmap->bm_y;
                gr_modex_setplane( x & 3 );
@@ -61,7 +60,7 @@ unsigned char gr_gpixel( grs_bitmap * bitmap, int x, int y )
 #endif
                return bitmap->bm_data[ bitmap->bm_rowsize*y + x ];
 #ifdef __DJGPP__
 #endif
                return bitmap->bm_data[ bitmap->bm_rowsize*y + x ];
 #ifdef __DJGPP__
-       case BM_MODEX:
+        case BM_MODEX:
                x += bitmap->bm_x;
                y += bitmap->bm_y;
                gr_modex_setplane( x & 3 );
                x += bitmap->bm_x;
                y += bitmap->bm_y;
                gr_modex_setplane( x & 3 );
@@ -77,3 +76,4 @@ unsigned char gr_gpixel( grs_bitmap * bitmap, int x, int y )
        return 0;
 #endif
 }
        return 0;
 #endif
 }
+
index ba3bc43..3d7099a 100644 (file)
@@ -1,4 +1,3 @@
-/* $Id: ibitblt.c,v 1.6 2002-09-04 22:18:43 btb Exp $ */
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
 /*
 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
@@ -8,675 +7,44 @@ IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
-AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
-COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
+AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
+COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
 */
 */
-
 /*
 /*
+ *  Routines to to inverse bitblitting -- well not really.
+ *  We don't inverse bitblt like in the PC, but this code
+ *  does set up a structure that blits around the cockpit
  *
  *
- * Mac Version:
- * Routines to to inverse bitblitting -- well not really.
- * We don't inverse bitblt like in the PC, but this code
- * does set up a structure that blits around the cockpit
- *
- * Old Log: ibitblt.c
- * Revision 1.3  1995/09/13  11:43:22  allender
- * start on optimizing cockpit copy code
- *
- * Revision 1.2  1995/09/07  10:16:57  allender
- * fixed up cockpit and rearview hole blitting
- *
- * Revision 1.1  1995/08/18  15:50:48  allender
- * Initial revision
- *
- * PC version:
- * Routines to copy a bitmap on top of another bitmap, but
- * only copying to pixels that are transparent.
- *
- * Old Log:
- * Revision 1.6  1994/11/28  17:07:29  john
- * Took out some unused functions in linear.asm, moved
- * gr_linear_movsd from linear.asm to bitblt.c, made sure that
- * the code in ibiblt.c sets the direction flags before rep movsing.
- *
- * Revision 1.5  1994/11/18  22:50:22  john
- * Changed shorts to ints in parameters.
- *
- * Revision 1.4  1994/11/09  16:35:16  john
- * First version with working RLE bitmaps.
- *
- * Revision 1.3  1994/10/03  17:18:05  john
- * Fixed bug with edi not getting intialized to zero
- * in create_mask.
- *
- * Revision 1.2  1994/05/31  11:10:55  john
- * *** empty log message ***
- *
- * Revision 1.1  1994/05/30  16:08:27  john
- * Initial revision
- *
- */
+*/
 
 #ifdef HAVE_CONFIG_H
 #include <conf.h>
 #endif
 
 
 #ifdef HAVE_CONFIG_H
 #include <conf.h>
 #endif
 
-#ifdef RCS
-static char rcsid[] = "$Id: ibitblt.c,v 1.6 2002-09-04 22:18:43 btb Exp $";
-#endif
-
-#ifdef __MSDOS__
-
-#include <conio.h>
-#include <dos.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <string.h>
-
-#include "pa_enabl.h"                   //$$POLY_ACC
-#include "types.h"
-#include "gr.h"
-#include "mem.h"
-#include "error.h"
-#include "ibitblt.h"
-#include "grdef.h"
-
-#if defined(POLY_ACC)
-#include "poly_acc.h"
-#endif
-
-#define MODE_NONE           0
-#define MODE_SKIP           1
-#define MODE_DRAW           2
-
-#define OPCODE_ADD          0x81
-#define OPCODE_ESI          0xC6        // Followed by a dword  (add esi, ????)
-#define OPCODE_EDI          0xC7        // Followed by a dword  (add edi, ????)
-#define OPCODE_MOV_ECX      0xB9        // Followed by a dword  (mov ecx,????)
-#define OPCODE_MOVSB        0xA4        // movsb
-#define OPCODE_16BIT        0x66        // movsw
-#define OPCODE_MOVSD        0xA5        // movsd
-#define OPCODE_REP          0xF3        // rep
-#define OPCODE_RET          0xC3        // ret
-#define OPCODE_MOV_EAX      0xB8        // mov eax, im dword
-#define OPCODE_MOV_EBX      0xBB        // mov ebx, im dword
-#define OPCODE_CALL_EBX1    0xFF        // call
-#define OPCODE_CALL_EBX2    0xD3        //      ebx
-#define OPCODE_MOV_EDI      0xBF        // mov edi, im dword
-
-
-ubyte *Code_pointer = NULL;
-int Code_counter = 0;
-int ibitblt_svga_page = 0;
-int is_svga = 0;
-uint linear_address;
-
-
-
-void count_block( int ecx )
-{
-       int blocks;
-
-       while ( ecx > 0 ) {
-               switch(ecx) {
-               case 1: Code_counter++; ecx = 0; break;     // MOVSB
-               case 2: Code_counter+=2; ecx = 0; break;    // MOVSW
-               case 3: Code_counter+=3; ecx = 0; break;    // MOVSW, MOVSB
-               case 4: Code_counter++; ecx = 0; break;     // MOVSD
-               default:
-                       blocks = ecx / 4;
-                       if ( blocks == 1 )
-                               Code_counter++; // MOVSD
-                       else
-                               Code_counter+=7;
-                       ecx -= blocks*4;
-               }
-       }
-}
-
-
-void move_and_count( int dsource, int ddest, int ecx )
-{
-       if ( ecx <= 0 )
-               return;
-
-       if ( dsource > 0 ) {
-               // ADD ESI, dsource
-               Code_counter += 6;
-       }
-       if ( !is_svga ) {
-               if ( ddest > 0 ) {
-                       // ADD EDI, ddest
-                       Code_counter += 6;
-               }
-               count_block( ecx );
-       } else {
-               int p1, p2, o1;
-
-               linear_address += ddest;        // Skip to next block
-
-               p1 = linear_address >> 16; o1 = linear_address & 0xFFFF;
-               p2 = (linear_address+ecx) >> 16;
-               if ( p1 != ibitblt_svga_page ) {
-                       // Set page
-                       // MOV EAX, ?, CALL EBX
-                       Code_counter += 7;
-                       ibitblt_svga_page = p1;
-               }
-
-               Code_counter += 5;  // mov edi, ????
-
-               if ( p1 == p2 ) {
-                       count_block( ecx );
-               } else {
-                       int nbytes;
-                       nbytes = 0xFFFF-o1+1;
-                       count_block( nbytes );
-                       // set page
-                       // MOV EAX, 0
-                       Code_counter += 7;  // mov eax,???? call ebx
-
-                       ibitblt_svga_page = p2;
-
-                       Code_counter += 5;  // mov edi, ????
-
-                       nbytes = ecx - nbytes;
-                       if (nbytes > 0 )
-                               count_block( nbytes );
-               }
-               linear_address += ecx;
-       }
-}
-
-
-
-void draw_block( int ecx )
-{
-       int blocks;
-       int * iptr;
-
-       while ( ecx > 0 )   {
-               switch( ecx )   {
-               case 1:
-                       // MOVSB
-                       *Code_pointer++ = OPCODE_MOVSB;
-                       ecx = 0;
-                       break;
-               case 2:
-                       // MOVSW
-                       *Code_pointer++ = OPCODE_16BIT;
-                       *Code_pointer++ = OPCODE_MOVSD;
-                       ecx = 0;
-                       break;
-               case 3:
-                       // MOVSW, MOVSB
-                       *Code_pointer++ = OPCODE_16BIT;
-                       *Code_pointer++ = OPCODE_MOVSD;
-                       *Code_pointer++ = OPCODE_MOVSB;
-                       ecx = 0;
-                       break;
-               case 4:
-                       // MOVSD
-                       *Code_pointer++ = OPCODE_MOVSD;
-                       ecx = 0;
-                       break;
-               default:
-                       blocks = ecx / 4;
-
-                       if ( blocks == 1 ) {
-                               // MOVSD
-                               *Code_pointer++ = OPCODE_MOVSD;
-                       } else {
-                               // MOV ECX, blocks
-                               *Code_pointer++ = OPCODE_MOV_ECX;
-                               iptr = (int *)Code_pointer;
-                               *iptr++ = blocks;
-                               Code_pointer = (ubyte *)iptr;
-                               // REP MOVSD
-                               *Code_pointer++ = OPCODE_REP;
-                               *Code_pointer++ = OPCODE_MOVSD;
-                       }
-                       ecx -= blocks*4;
-               }
-       }
-}
-
-
-void move_and_draw( int dsource, int ddest, int ecx )
-{
-       int * iptr;
-
-       if ( ecx <= 0 )
-               return;
-
-       if ( dsource > 0 ) {
-               // ADD ESI, dsource
-               *Code_pointer++ = OPCODE_ADD;
-               *Code_pointer++ = OPCODE_ESI;
-               iptr = (int *)Code_pointer;
-               *iptr++ = dsource;
-               Code_pointer = (ubyte *)iptr;
-       }
-       if ( !is_svga ) {
-               if ( ddest > 0 ) {
-                       // ADD EDI, ddest
-                       *Code_pointer++ = OPCODE_ADD;
-                       *Code_pointer++ = OPCODE_EDI;
-                       iptr = (int *)Code_pointer;
-                       *iptr++ = ddest;
-                       Code_pointer = (ubyte *)iptr;
-               }
-               draw_block( ecx );
-       } else {
-               unsigned int temp;
-               int temp_offset;
-               int p1, p2, o1;
-
-               linear_address += ddest;        // Skip to next block
-
-               p1 = linear_address >> 16; o1 = linear_address & 0xFFFF;
-               p2 = (linear_address+ecx) >> 16;
-               if ( p1 != ibitblt_svga_page ) {
-                       // Set page
-                       // MOV EAX, 0
-                       *Code_pointer++ = OPCODE_MOV_EAX;
-                       temp = p1;
-                       memcpy( Code_pointer, &temp, sizeof(int) );
-                       Code_pointer += sizeof(int);
-                       // CALL EBX
-                       *Code_pointer++ = OPCODE_CALL_EBX1;
-                       *Code_pointer++ = OPCODE_CALL_EBX2;
-                       ibitblt_svga_page = p1;
-               }
-
-               temp_offset = 0xA0000 + o1;
-               *Code_pointer++ = OPCODE_MOV_EDI;
-               iptr = (int *)Code_pointer;
-               *iptr++ = temp_offset;
-               Code_pointer = (ubyte *)iptr;
-
-               if ( p1 == p2 ) {
-                       draw_block( ecx );
-               } else {
-                       int nbytes;
-                       nbytes = 0xFFFF-o1+1;
-                       draw_block( nbytes );
-                       // set page
-                       // MOV EAX, 0
-                       *Code_pointer++ = OPCODE_MOV_EAX;
-                       temp = p2;
-                       memcpy( Code_pointer, &temp, sizeof(int) );
-                       Code_pointer += sizeof(int);
-                       // CALL EBX
-                       *Code_pointer++ = OPCODE_CALL_EBX1;
-                       *Code_pointer++ = OPCODE_CALL_EBX2;
-                       ibitblt_svga_page = p2;
-
-                       temp_offset = 0xA0000;
-                       *Code_pointer++ = OPCODE_MOV_EDI;
-                       iptr = (int *)Code_pointer;
-                       *iptr++ = temp_offset;
-                       Code_pointer = (ubyte *)iptr;
-
-                       nbytes = ecx - nbytes;
-                       if (nbytes > 0 )
-                               draw_block( nbytes );
-               }
-               linear_address += ecx;
-       }
-
-}
-
-//-----------------------------------------------------------------------------------------
-// Given bitmap, bmp, finds the size of the code
-
-int gr_ibitblt_find_code_size_sub( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize, int dest_type )
-{
-       int x,y;
-       ubyte pixel;
-       int draw_mode = MODE_NONE;
-       int source_offset = 0;
-       int dest_offset = 0;
-       int num_to_draw, draw_start_source, draw_start_dest;
-       int esi, edi;
-
-       Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
-
-       Code_counter = 0;
-
-       if ( dest_type == BM_SVGA ) {
-               Code_counter += 1+4;    // move ebx, gr_vesa_set_page
-               Code_counter += 1+4;    // move eax, 0
-               Code_counter += 2;      // call ebx
-               ibitblt_svga_page = 0;
-               linear_address = 0;
-               is_svga = 1;
-       } else {
-               is_svga = 0;
-       }
-
-       esi = source_offset = 0;
-       edi = dest_offset = 0;
-       draw_start_source = draw_start_dest = 0;
-
-       for ( y=sy; y<sy+sh; y++ ) {
-               for ( x=sx; x<sx+sw; x++ ) {
-                       dest_offset = y*mask_bmp->bm_rowsize+x;
-                       pixel = mask_bmp->bm_data[dest_offset];
-                       if ( pixel!=255 ) {
-                               switch ( draw_mode) {
-                               case MODE_DRAW:
-                                       move_and_count( draw_start_source-esi, draw_start_dest-edi, num_to_draw );
-                                       esi = draw_start_source + num_to_draw;
-                                       edi = draw_start_dest + num_to_draw;
-                                       // fall through!!!
-                               case MODE_NONE:
-                               case MODE_SKIP:
-                                       break;
-                               }
-                               draw_mode = MODE_SKIP;
-                       } else {
-                               switch ( draw_mode) {
-                               case MODE_SKIP:
-                               case MODE_NONE:
-                                       draw_start_source = source_offset;
-                                       draw_start_dest = dest_offset;
-                                       num_to_draw = 0;
-                                       // fall through
-                               case MODE_DRAW:
-                                       num_to_draw++;
-                                       break;
-                               }
-                               draw_mode = MODE_DRAW;
-                       }
-                       source_offset++;
-               }
-               if ( draw_mode == MODE_DRAW ) {
-                       move_and_count( draw_start_source-esi, draw_start_dest-edi, num_to_draw );
-                       esi = draw_start_source + num_to_draw;
-                       edi = draw_start_dest + num_to_draw;
-               }
-               draw_mode = MODE_NONE;
-               source_offset += (srowsize - sw);
-       }
-       Code_counter++;     // for return
-
-       //printf( "Code will be %d bytes\n", Code_counter );
-
-       Code_counter += 16; // for safety was 16
-
-       return Code_counter;
-}
-
-int gr_ibitblt_find_code_size( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize )
-{
-       return gr_ibitblt_find_code_size_sub( mask_bmp, sx, sy, sw, sh, srowsize, BM_LINEAR );
-}
-
-int gr_ibitblt_find_code_size_svga( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize )
-{
-       return gr_ibitblt_find_code_size_sub( mask_bmp, sx, sy, sw, sh, srowsize, BM_SVGA );
-}
-
-//-----------------------------------------------------------------------------------------
-// Given bitmap, bmp, create code that transfers a bitmap of size sw*sh to position
-// (sx,sy) on top of bmp, only overwritting transparent pixels of the bitmap.
-
-ubyte  *gr_ibitblt_create_mask_sub( grs_bitmap * mask_bmp, int sx, int sy, int sw, int sh, int srowsize, int dest_type )
-{
-       int x,y;
-       ubyte pixel;
-       int draw_mode = MODE_NONE;
-       int source_offset = 0;
-       int dest_offset = 0;
-       int num_to_draw, draw_start_source, draw_start_dest;
-       int esi, edi;
-       int code_size;
-       ubyte *code;
-       uint temp;
-
-       Assert( (!(mask_bmp->bm_flags&BM_FLAG_RLE)) );
-
-       if ( dest_type == BM_SVGA )
-               code_size = gr_ibitblt_find_code_size_svga( mask_bmp, sx, sy, sw, sh, srowsize );
-       else
-               code_size = gr_ibitblt_find_code_size( mask_bmp, sx, sy, sw, sh, srowsize );
-
-       code = malloc( code_size );
-       if ( code == NULL )
-      &nbs