1 /* $Id: 2dsline.c,v 1.10 2003-04-29 08:05:41 btb Exp $ */
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.
17 * Graphical routines for drawing solid scanlines.
20 * Revision 1.6 1995/09/14 14:24:03 allender
21 * fixed MW compile error
23 * Revision 1.5 1995/09/14 13:45:17 allender
24 * quick optimization for scanline
26 * Revision 1.4 1995/04/27 07:36:05 allender
27 * remove some memsets since all old is here now
29 * Revision 1.3 1995/04/19 14:35:33 allender
30 * *** empty log message ***
32 * Revision 1.2 1995/04/18 12:03:40 allender
33 * *** empty log message ***
35 * Revision 1.1 1995/03/09 09:24:06 allender
39 * --- PC RCS information ---
40 * Revision 1.7 1994/11/18 22:50:48 john
41 * Changed a bunch of shorts to ints in calls.
43 * Revision 1.6 1994/09/02 11:40:32 john
44 * fixed bug with urect scanline drakening still
45 * only using 16 levels of fade.
47 * Revision 1.5 1994/04/08 16:59:12 john
48 * Add fading poly's; Made palette fade 32 instead of 16.
50 * Revision 1.4 1994/03/22 18:36:27 john
51 * Added darkening scanlines
53 * Revision 1.3 1993/10/15 16:22:52 john
56 * Revision 1.2 1993/09/08 11:56:29 john
59 * Revision 1.1 1993/09/08 11:44:27 john
85 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
87 #if !defined(NO_ASM) && defined(__WATCOMC__)
89 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
90 #pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
93 "gld_loop: mov bl, [edi] " \
94 " mov al, [ebx+edx] " \
100 #elif !defined(NO_ASM) && defined(__GNUC__)
102 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
104 __asm__ __volatile__ (
105 " xorl %%ebx, %%ebx;"
107 "0: movb (%%edi), %%bl;"
108 " movb (%%ebx, %%edx), %%al;"
109 " movb %%al, (%%edi);"
113 : "=D" (dummy[0]), "=a" (dummy[1]), "=c" (dummy[2]), "=d" (dummy[3])
114 : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
118 #elif !defined(NO_ASM) && defined(_MSC_VER)
120 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
124 mov eax,[darkening_level]
139 #else // Unknown compiler, or no assembler. So we use C.
141 void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
144 for (i=0;i<count;i++)
146 *dest = fade_table[(*dest)+(darkening_level*256)];
153 #ifdef NO_ASM // No Assembler. So we use C.
155 void gr_linear_stosd( ubyte * dest, ubyte color, unsigned short count )
160 while ((int)(dest) & 0x3) { *dest++ = color; count--; };
162 x = (color << 24) | (color << 16) | (color << 8) | color;
163 while (count > 4) { *(int *)dest = x; dest += 4; count -= 4; };
165 while (count > 0) { *dest++ = color; count--; };
167 for (i=0; i<count; i++ )
172 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
173 memset(dest,color,nbytes);
178 #if defined(POLY_ACC)
179 //$$ Note that this code WAS a virtual clone of the mac code and any changes to mac should be reflected here.
180 void gr_linear15_darken( short * dest, int darkening_level, int count, ubyte * fade_table )
182 //$$ this routine is a prime candidate for using the alpha blender.
184 unsigned short rt[32], gt[32], bt[32];
185 unsigned long level, int_level, dlevel;
187 dlevel = (darkening_level << 16) / GR_FADE_LEVELS;
188 level = int_level = 0;
189 for(i = 0; i != 32; ++i)
191 rt[i] = int_level << 10;
192 gt[i] = int_level << 5;
196 int_level = level >> 16;
200 for (i=0; i<count; i++ ) {
203 rt[((*dest >> 10) & 0x1f)] |
204 gt[((*dest >> 5) & 0x1f)] |
205 bt[((*dest >> 0) & 0x1f)] |
211 void gr_linear15_stosd( short * dest, ubyte color, unsigned short count )
213 //$$ this routine is a prime candidate for using the alpha blender.
214 short c = pa_clut[color];
221 void gr_uscanline( int x1, int x2, int y )
223 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
230 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
234 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
237 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
240 #if defined(POLY_ACC)
242 gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
253 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
257 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
262 ubyte * vram = (ubyte *)0xA0000;
263 int VideoLocation,page,offset1, offset2;
265 VideoLocation = (ROWSIZE * y) + x1;
266 page = VideoLocation >> 16;
267 offset1 = VideoLocation & 0xFFFF;
268 offset2 = offset1 + (x2-x1+1);
270 gr_vesa_setpage( page );
271 if ( offset2 <= 0xFFFF ) {
272 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
274 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
276 gr_vesa_setpage(page);
277 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
281 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
285 #if defined(POLY_ACC)
287 gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
294 void gr_scanline( int x1, int x2, int y )
296 if ((y<0)||(y>MAXY)) return;
298 if (x2 < x1 ) x2 ^= x1 ^= x2;
300 if (x1 > MAXX) return;
301 if (x2 < MINX) return;
303 if (x1 < MINX) x1 = MINX;
304 if (x2 > MAXX) x2 = MAXX;
306 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
313 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
317 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
320 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
323 #if defined(POLY_ACC)
325 gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
336 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
340 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
345 ubyte * vram = (ubyte *)0xA0000;
346 int VideoLocation,page,offset1, offset2;
348 VideoLocation = (ROWSIZE * y) + x1;
349 page = VideoLocation >> 16;
350 offset1 = VideoLocation & 0xFFFF;
351 offset2 = offset1 + (x2-x1+1);
353 gr_vesa_setpage( page );
354 if ( offset2 <= 0xFFFF ) {
355 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
357 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
359 gr_vesa_setpage(page);
360 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
364 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
368 #if defined(POLY_ACC)
370 gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);