]> icculus.org git repositories - btb/d2x.git/blob - 2d/2dsline.c
merged endlevel stuff to non-shareware, more fast i/o macros, use global Piggy_hamfil...
[btb/d2x.git] / 2d / 2dsline.c
1 /* $Id: 2dsline.c,v 1.5 2002-07-17 21:10:38 bradleyb Exp $ */
2 /*
3 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
4 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
5 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
6 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
7 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
8 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
9 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
10 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
11 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
12 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
13 */
14
15 #ifdef HAVE_CONFIG_H
16 #include <conf.h>
17 #endif
18
19 #include <string.h>
20
21 #include "u_mem.h"
22
23 #include "gr.h"
24 #include "grdef.h"
25
26 #ifdef __DJGPP__
27 #include "modex.h"
28 #include "vesa.h"
29 #endif
30
31 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
32
33 #ifndef NO_ASM
34 # ifdef __WATCOMC__
35 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
36 #  pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
37 "                                       xor     ebx, ebx                                        "       \
38 "                                       mov     bh, al                                  "  \
39 "gld_loop:              mov     bl, [edi]                               "       \
40 "                                       mov     al, [ebx+edx]                   "       \
41 "                                       mov     [edi], al                               "       \
42 "                                       inc     edi                                             "       \
43 "                                       dec     ecx                                             "       \
44 "                   jnz gld_loop                    "
45
46 # elif defined __GNUC__
47 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
48    int dummy[4];
49    __asm__ __volatile__ (
50 "               xorl %%ebx, %%ebx;"
51 "               movb %%al, %%bh;"
52 "0:             movb (%%edi), %%bl;"
53 "               movb (%%ebx, %%edx), %%al;"
54 "               movb %%al, (%%edi);"
55 "               incl %%edi;"
56 "               decl %%ecx;"
57 "               jnz 0b"
58    : "=D" (dummy[0]), "=a" (dummy[1]), "=c" (dummy[2]), "=d" (dummy[3])
59    : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
60    : "%ebx");
61 }
62 # elif defined _MSC_VER
63 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
64 {
65   __asm {
66     mov edi,[dest]
67         mov eax,[darkening_level]
68         mov ecx,[count]
69         mov edx,[fade_table]
70         xor ebx, ebx
71         mov bh, al
72 gld_loop:
73         mov bl,[edi]
74         mov al,[ebx+edx]
75         mov [edi],al
76         inc edi
77         dec ecx
78         jnz gld_loop
79   }
80 }
81 # else
82 // Unknown compiler. So we use C rather than inline assembler.
83 #  define USE_C_GR_LINEAR_DARKEN 1
84 # endif
85
86 #else // No Assembler. So we use C.
87 # define USE_C_GR_LINEAR_DARKEN 1
88 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
89         memset(dest,color,nbytes);
90 }
91 #endif
92
93 #ifdef USE_C_GR_LINEAR_DARKEN
94 void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
95         register int i;
96
97         for (i=0;i<count;i++)
98                 *dest=fade_table[(*dest++)+(darkening_level*256)];
99 }
100 #endif
101
102 void gr_uscanline( int x1, int x2, int y )
103 {
104         if (Gr_scanline_darkening_level >= GR_FADE_LEVELS )     {
105 #ifdef __DJGPP__
106                 switch(TYPE)
107                 {
108                 case BM_LINEAR:
109 #endif
110                         gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
111 #ifdef __DJGPP__
112                         break;
113                 case BM_MODEX:
114                         gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
115                         break;
116                 case BM_SVGA:
117                         gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
118                         break;
119                 }
120 #endif
121         } else {
122 #ifdef __DJGPP__
123                 switch(TYPE)
124                 {
125                 case BM_LINEAR:
126 #endif
127                         gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
128 #ifdef __DJGPP__
129                         break;
130                 case BM_MODEX:
131                         gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
132                         break;
133                 case BM_SVGA:
134                         gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
135                         break;
136                 }
137 #endif
138         }
139 }
140
141 void gr_scanline( int x1, int x2, int y )
142 {
143         if ((y<0)||(y>MAXY)) return;
144
145         if (x2 < x1 ) x2 ^= x1 ^= x2;
146
147         if (x1 > MAXX) return;
148         if (x2 < MINX) return;
149
150         if (x1 < MINX) x1 = MINX;
151         if (x2 > MAXX) x2 = MAXX;
152
153         if (Gr_scanline_darkening_level >= GR_FADE_LEVELS )     {
154 #ifdef __DJGPP__
155                 switch(TYPE)
156                 {
157                 case BM_LINEAR:
158 #endif
159                         gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
160 #ifdef __DJGPP__
161                         break;
162                 case BM_MODEX:
163                         gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
164                         break;
165                 case BM_SVGA:
166                         gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
167                         break;
168                 }
169 #endif
170         } else {
171 #ifdef __DJGPP__
172                 switch(TYPE)
173                 {
174                 case BM_LINEAR:
175 #endif
176                         gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
177 #ifdef __DJGPP__
178                         break;
179                 case BM_MODEX:
180                         gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
181                         break;
182                 case BM_SVGA:
183                         gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
184                         break;
185                 }
186 #endif
187         }
188 }