2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX"). PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING, AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES. IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES. THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.
11 COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED.
16 * Graphical routines for drawing solid scanlines.
41 int Gr_scanline_darkening_level = GR_FADE_LEVELS;
43 #if !defined(NO_ASM) && defined(__WATCOMC__)
45 void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table );
46 #pragma aux gr_linear_darken parm [edi] [eax] [ecx] [edx] modify exact [eax ebx ecx edx edi] = \
49 "gld_loop: mov bl, [edi] " \
50 " mov al, [ebx+edx] " \
56 #elif !defined(NO_ASM) && defined(__GNUC__)
58 static inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table ) {
60 __asm__ __volatile__ (
63 "0: movb (%%edi), %%bl;"
64 " movb (%%ebx, %%edx), %%al;"
65 " movb %%al, (%%edi);"
69 : "=D" (dummy[0]), "=a" (dummy[1]), "=c" (dummy[2]), "=d" (dummy[3])
70 : "0" (dest), "1" (darkening_level), "2" (count), "3" (fade_table)
74 #elif !defined(NO_ASM) && defined(_MSC_VER)
76 __inline void gr_linear_darken( ubyte * dest, int darkening_level, int count, ubyte * fade_table )
80 mov eax,[darkening_level]
95 #else // Unknown compiler, or no assembler. So we use C.
97 void gr_linear_darken(ubyte * dest, int darkening_level, int count, ubyte * fade_table) {
100 for (i=0;i<count;i++)
102 *dest = fade_table[(*dest)+(darkening_level*256)];
109 #ifdef NO_ASM // No Assembler. So we use C.
111 void gr_linear_stosd( ubyte * dest, ubyte color, unsigned short count )
116 while ((int)(dest) & 0x3) { *dest++ = color; count--; };
118 x = (color << 24) | (color << 16) | (color << 8) | color;
119 while (count > 4) { *(int *)dest = x; dest += 4; count -= 4; };
121 while (count > 0) { *dest++ = color; count--; };
123 for (i=0; i<count; i++ )
128 void gr_linear_stosd( ubyte * dest, unsigned char color, unsigned int nbytes) {
129 memset(dest,color,nbytes);
134 void gr_uscanline( int x1, int x2, int y )
136 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
141 ogl_ulinec(x1, y, x2, y, COLOR);
145 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
149 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
152 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
163 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
167 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
172 ubyte * vram = (ubyte *)0xA0000;
173 int VideoLocation,page,offset1, offset2;
175 VideoLocation = (ROWSIZE * y) + x1;
176 page = VideoLocation >> 16;
177 offset1 = VideoLocation & 0xFFFF;
178 offset2 = offset1 + (x2-x1+1);
180 gr_vesa_setpage( page );
181 if ( offset2 <= 0xFFFF ) {
182 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
184 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
186 gr_vesa_setpage(page);
187 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
191 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
199 void gr_scanline( int x1, int x2, int y )
201 if ((y<0)||(y>MAXY)) return;
203 if (x2 < x1 ) x2 ^= x1 ^= x2;
205 if (x1 > MAXX) return;
206 if (x2 < MINX) return;
208 if (x1 < MINX) x1 = MINX;
209 if (x2 > MAXX) x2 = MAXX;
211 if (Gr_scanline_darkening_level >= GR_FADE_LEVELS ) {
216 ogl_ulinec(x1, y, x2, y, COLOR);
220 gr_linear_stosd( DATA + ROWSIZE*y + x1, (unsigned char)COLOR, x2-x1+1);
224 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
227 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
238 gr_linear_darken( DATA + ROWSIZE*y + x1, Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
242 gr_modex_uscanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );
247 ubyte * vram = (ubyte *)0xA0000;
248 int VideoLocation,page,offset1, offset2;
250 VideoLocation = (ROWSIZE * y) + x1;
251 page = VideoLocation >> 16;
252 offset1 = VideoLocation & 0xFFFF;
253 offset2 = offset1 + (x2-x1+1);
255 gr_vesa_setpage( page );
256 if ( offset2 <= 0xFFFF ) {
257 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, x2-x1+1, gr_fade_table);
259 gr_linear_darken( &vram[offset1], Gr_scanline_darkening_level, 0xFFFF-offset1+1, gr_fade_table);
261 gr_vesa_setpage(page);
262 gr_linear_darken( vram, Gr_scanline_darkening_level, offset2 - 0xFFFF, gr_fade_table);
266 gr_vesa_scanline( x1+XOFFSET, x2+XOFFSET, y+YOFFSET, COLOR );