1 /* $Id: 2dsline.c,v 1.11 2004-08-28 23:17:45 schaffner 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.
42 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
44 #if !defined(NO_ASM) && defined(__WATCOMC__)
46 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
47 #pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
50 "gld_loop: mov bl, [edi] " \
51 " mov al, [ebx+edx] " \
57 #elif !defined(NO_ASM) && defined(__GNUC__)
59 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
61 __asm__ __volatile__ (
64 "0: movb (%%edi), %%bl;"
65 " movb (%%ebx, %%edx), %%al;"
66 " movb %%al, (%%edi);"
70 : "=D" (dummy[0]), "=a" (dummy[1]), "=c" (dummy[2]), "=d" (dummy[3])
71 : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
75 #elif !defined(NO_ASM) && defined(_MSC_VER)
77 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
81 mov eax,[darkening_level]
96 #else // Unknown compiler, or no assembler. So we use C.
98 void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
101 for (i=0;i<count;i++)
103 *dest = fade_table[(*dest)+(darkening_level*256)];
110 #ifdef NO_ASM // No Assembler. So we use C.
112 void gr_linear_stosd( ubyte * dest, ubyte color, unsigned short count )
117 while ((int)(dest) & 0x3) { *dest++ = color; count--; };
119 x = (color << 24) | (color << 16) | (color << 8) | color;
120 while (count > 4) { *(int *)dest = x; dest += 4; count -= 4; };
122 while (count > 0) { *dest++ = color; count--; };
124 for (i=0; i<count; i++ )
129 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
130 memset(dest,color,nbytes);
135 #if defined(POLY_ACC)
136 //$$ Note that this code WAS a virtual clone of the mac code and any changes to mac should be reflected here.
137 void gr_linear15_darken( short * dest, int darkening_level, int count, ubyte * fade_table )
139 //$$ this routine is a prime candidate for using the alpha blender.
141 unsigned short rt[32], gt[32], bt[32];
142 unsigned long level, int_level, dlevel;
144 dlevel = (darkening_level << 16) / GR_FADE_LEVELS;
145 level = int_level = 0;
146 for(i = 0; i != 32; ++i)
148 rt[i] = int_level << 10;
149 gt[i] = int_level << 5;
153 int_level = level >> 16;
157 for (i=0; i<count; i++ ) {
160 rt[((*dest >> 10) & 0x1f)] |
161 gt[((*dest >> 5) & 0x1f)] |
162 bt[((*dest >> 0) & 0x1f)] |
168 void gr_linear15_stosd( short * dest, ubyte color, unsigned short count )
170 //$$ this routine is a prime candidate for using the alpha blender.
171 short c = pa_clut[color];
178 void gr_uscanline( int x1, int x2, int y )
180 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
187 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
191 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
194 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
197 #if defined(POLY_ACC)
199 gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
210 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
214 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
219 ubyte * vram = (ubyte *)0xA0000;
220 int VideoLocation,page,offset1, offset2;
222 VideoLocation = (ROWSIZE * y) + x1;
223 page = VideoLocation >> 16;
224 offset1 = VideoLocation & 0xFFFF;
225 offset2 = offset1 + (x2-x1+1);
227 gr_vesa_setpage( page );
228 if ( offset2 <= 0xFFFF ) {
229 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
231 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
233 gr_vesa_setpage(page);
234 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
238 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
242 #if defined(POLY_ACC)
244 gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
251 void gr_scanline( int x1, int x2, int y )
253 if ((y<0)||(y>MAXY)) return;
255 if (x2 < x1 ) x2 ^= x1 ^= x2;
257 if (x1 > MAXX) return;
258 if (x2 < MINX) return;
260 if (x1 < MINX) x1 = MINX;
261 if (x2 > MAXX) x2 = MAXX;
263 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
270 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
274 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
277 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
280 #if defined(POLY_ACC)
282 gr_linear15_stosd( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), COLOR, x2-x1+1);
293 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
297 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
302 ubyte * vram = (ubyte *)0xA0000;
303 int VideoLocation,page,offset1, offset2;
305 VideoLocation = (ROWSIZE * y) + x1;
306 page = VideoLocation >> 16;
307 offset1 = VideoLocation & 0xFFFF;
308 offset2 = offset1 + (x2-x1+1);
310 gr_vesa_setpage( page );
311 if ( offset2 <= 0xFFFF ) {
312 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
314 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
316 gr_vesa_setpage(page);
317 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
321 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
325 #if defined(POLY_ACC)
327 gr_linear15_darken( (short *)(DATA + ROWSIZE*y + x1 * PA_BPP), Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);