screen_savers/Nebula: Convert draw.S to C.
Hand-translated. I left the assembly in as comments for easy analysis, I'll remove it in the next commit. (I didn't do this on my own, I had help.)
This commit is contained in:
@@ -0,0 +1,148 @@
|
|||||||
|
// Hand-translated from x86 assembly.
|
||||||
|
|
||||||
|
/* memshset (char *dst, int center_shade,int fixed_shade, int length_2) */
|
||||||
|
/* dst is the *center* of the dst segment */
|
||||||
|
/* center shade is the initial color (at center) (!! 8:8 also) */
|
||||||
|
/* fixed_shade is the fixed point increment (8:8) */
|
||||||
|
/* length_2 is the 1/2 length to set (to the left, and to the right) */
|
||||||
|
|
||||||
|
/* a memaddshadedset function (or something like that ) */
|
||||||
|
|
||||||
|
void memshset(char* dstParam, int center_shade, int fixed_shade, int half_length)
|
||||||
|
{
|
||||||
|
unsigned char* dst;
|
||||||
|
unsigned char* source;
|
||||||
|
int offset;
|
||||||
|
|
||||||
|
if (half_length == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// movl 8(%ebp),%edi /* dst */
|
||||||
|
// movl 12(%ebp),%eax /* center_shade*/
|
||||||
|
// movl 16(%ebp),%ebx /* fixed_shade */
|
||||||
|
// movl 20(%ebp),%ecx /* half_length */
|
||||||
|
//
|
||||||
|
//@ orl %ecx,%ecx
|
||||||
|
//@ jz 2f
|
||||||
|
//
|
||||||
|
|
||||||
|
dst = (unsigned char*)dstParam;
|
||||||
|
source = dst;
|
||||||
|
// movl %edi,%esi
|
||||||
|
dst -= half_length; // Left segment
|
||||||
|
// subl %ecx,%edi /* %edi left segment */
|
||||||
|
source += half_length; // Right segment
|
||||||
|
// addl %ecx,%esi /* %esi right segment */
|
||||||
|
source++; // Don't overlap at middle
|
||||||
|
// incl %esi /* dont overlap at middle */
|
||||||
|
//
|
||||||
|
offset = half_length;
|
||||||
|
// movl %ecx,%edx
|
||||||
|
offset = -offset;
|
||||||
|
// negl %edx
|
||||||
|
offset--; // For in-advance incl in loop
|
||||||
|
// decl %edx /* for in-advance incl in loop */
|
||||||
|
|
||||||
|
do {
|
||||||
|
int tmp;
|
||||||
|
//1:
|
||||||
|
center_shade += fixed_shade; // Increment color.
|
||||||
|
center_shade &= 0xFFFF; // Mask so we can do overflow tests.
|
||||||
|
// addl %ebx,%eax /* increment color */
|
||||||
|
offset++;
|
||||||
|
// incl %edx
|
||||||
|
|
||||||
|
tmp = dst[half_length] + (center_shade >> 8); // Increment left pixel.
|
||||||
|
// addb %ah,(%edi,%ecx) /* increment left pixel */
|
||||||
|
// Did it overflow?
|
||||||
|
if (tmp & 0xFF00) {
|
||||||
|
// jc 3f /* did overflow ? */
|
||||||
|
dst[half_length] = 255;
|
||||||
|
//3:
|
||||||
|
// movb $255,(%edi,%ecx)
|
||||||
|
} else {
|
||||||
|
dst[half_length] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
tmp = source[offset] + (center_shade >> 8); // Increment right pixel.
|
||||||
|
// Did it overflow?
|
||||||
|
if (tmp & 0xFF00) {
|
||||||
|
source[offset] = 255;
|
||||||
|
//4:
|
||||||
|
// movb $255,(%esi,%edx)
|
||||||
|
// decl %ecx
|
||||||
|
// jnz 1b
|
||||||
|
//
|
||||||
|
// popl %ebx
|
||||||
|
// popl %esi
|
||||||
|
// popl %edi
|
||||||
|
//
|
||||||
|
// leave
|
||||||
|
// ret
|
||||||
|
} else {
|
||||||
|
source[offset] = tmp;
|
||||||
|
}
|
||||||
|
// addb %ah,(%esi,%edx) /* increment right pixel */
|
||||||
|
// jc 4f
|
||||||
|
//
|
||||||
|
} while (--half_length != 0);
|
||||||
|
// decl %ecx
|
||||||
|
// jnz 1b
|
||||||
|
//
|
||||||
|
//2:
|
||||||
|
// popl %ebx
|
||||||
|
// popl %esi
|
||||||
|
// popl %edi
|
||||||
|
//
|
||||||
|
// leave
|
||||||
|
// ret
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* do the "motion blur" (actually the pixel fading) */
|
||||||
|
void mblur(char* srcParam, int nbpixels)
|
||||||
|
{
|
||||||
|
// movl 8(%ebp),%edi /* dst */
|
||||||
|
// movl 12(%ebp),%ecx /* number */
|
||||||
|
unsigned int clear1UpperBit = 0x7f7f7f7f;
|
||||||
|
unsigned int clear3UpperBits = 0x1f1f1f1f;
|
||||||
|
unsigned long* src = (unsigned long*)srcParam;
|
||||||
|
// movl $0x7f7f7f7f,%edx /* clear 1 upper bits */
|
||||||
|
// movl $0x1f1f1f1f,%esi /* clear 3 upper bits */
|
||||||
|
|
||||||
|
if ((nbpixels >>= 2) == 0)
|
||||||
|
// shrl $2,%ecx
|
||||||
|
return;
|
||||||
|
// jz 2f
|
||||||
|
//
|
||||||
|
do {
|
||||||
|
//1:
|
||||||
|
long eax, ebx;
|
||||||
|
eax = *src;
|
||||||
|
// movl (%edi),%eax
|
||||||
|
src++;
|
||||||
|
// addl $4,%edi
|
||||||
|
//
|
||||||
|
ebx = eax;
|
||||||
|
// movl %eax,%ebx
|
||||||
|
eax >>= 1;
|
||||||
|
// shrl $1,%eax
|
||||||
|
//
|
||||||
|
//
|
||||||
|
ebx >>= 3;
|
||||||
|
// shrl $3,%ebx
|
||||||
|
eax &= clear1UpperBit;
|
||||||
|
// andl %edx,%eax
|
||||||
|
//
|
||||||
|
ebx &= clear3UpperBits;
|
||||||
|
// andl %esi,%ebx
|
||||||
|
eax += ebx;
|
||||||
|
// addl %ebx,%eax
|
||||||
|
//
|
||||||
|
src[-1] = eax;
|
||||||
|
// movl %eax,-4(%edi)
|
||||||
|
} while (--nbpixels != 0);
|
||||||
|
// decl %ecx
|
||||||
|
// jnz 1b
|
||||||
|
}
|
||||||
@@ -33,8 +33,7 @@ float presin[512];
|
|||||||
typedef unsigned short word;
|
typedef unsigned short word;
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
void memshset(char *dst, int center_shade,int fixed_shade, int length_2);
|
#include "Draw.c"
|
||||||
void mblur(char *src, int nbpixels);
|
|
||||||
|
|
||||||
void draw_stars320(char *, char);
|
void draw_stars320(char *, char);
|
||||||
void draw_stars512(char *, char);
|
void draw_stars512(char *, char);
|
||||||
|
|||||||
@@ -1,136 +0,0 @@
|
|||||||
|
|
||||||
.text
|
|
||||||
|
|
||||||
/* memshset (char *dst, int center_shade,int fixed_shade, int length_2) */
|
|
||||||
/* dst is the *center* of the dst segment */
|
|
||||||
/* center shade is the initial color (at center) (!! 8:8 also) */
|
|
||||||
/* fixed_shade is the fixed point increment (8:8) */
|
|
||||||
/* length_2 is the 1/2 length to set (to the left, and to the right) */
|
|
||||||
|
|
||||||
/* a memaddshadedset function (or something like that ) */
|
|
||||||
|
|
||||||
.globl memshset
|
|
||||||
.type memshset,@function
|
|
||||||
|
|
||||||
|
|
||||||
memshset:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
|
|
||||||
pushl %edi /* registres a sauvegarder (convention gcc) */
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
|
|
||||||
movl 8(%ebp),%edi /* dst */
|
|
||||||
movl 12(%ebp),%eax
|
|
||||||
movl 16(%ebp),%ebx /* fixed point */
|
|
||||||
movl 20(%ebp),%ecx /* half length */
|
|
||||||
|
|
||||||
orl %ecx,%ecx
|
|
||||||
jz 2f
|
|
||||||
|
|
||||||
movl %edi,%esi
|
|
||||||
subl %ecx,%edi /* %edi left segment */
|
|
||||||
addl %ecx,%esi /* %esi right segment */
|
|
||||||
incl %esi /* dont overlap at middle */
|
|
||||||
|
|
||||||
movl %ecx,%edx
|
|
||||||
negl %edx
|
|
||||||
decl %edx /* for in-advance incl in loop */
|
|
||||||
1:
|
|
||||||
addl %ebx,%eax /* increment color */
|
|
||||||
incl %edx
|
|
||||||
|
|
||||||
addb %ah,(%edi,%ecx) /* increment left pixel */
|
|
||||||
jc 3f /* did overflow ? */
|
|
||||||
|
|
||||||
addb %ah,(%esi,%edx) /* increment right pixel */
|
|
||||||
jc 4f
|
|
||||||
|
|
||||||
decl %ecx
|
|
||||||
jnz 1b
|
|
||||||
|
|
||||||
2:
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
/* function goes on (several exit points): */
|
|
||||||
3:
|
|
||||||
movb $255,(%edi,%ecx)
|
|
||||||
addb %ah,(%esi,%edx) /* we recopy all the code.. to avoid jmps (hmm some asm guru here : is it really efficient ?.. */
|
|
||||||
jc 4f
|
|
||||||
decl %ecx
|
|
||||||
jnz 1b
|
|
||||||
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
|
|
||||||
4:
|
|
||||||
movb $255,(%esi,%edx)
|
|
||||||
decl %ecx
|
|
||||||
jnz 1b
|
|
||||||
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
/* function really stops here */
|
|
||||||
|
|
||||||
|
|
||||||
/*********************************** motion blur **********************************/
|
|
||||||
|
|
||||||
/* do the "motion blur" (actually the pixel fading) */
|
|
||||||
.globl mblur
|
|
||||||
.type mblur,@function
|
|
||||||
|
|
||||||
mblur:
|
|
||||||
pushl %ebp
|
|
||||||
movl %esp,%ebp
|
|
||||||
|
|
||||||
pushl %edi
|
|
||||||
pushl %esi
|
|
||||||
pushl %ebx
|
|
||||||
|
|
||||||
movl 8(%ebp),%edi /* dst */
|
|
||||||
movl 12(%ebp),%ecx /* number */
|
|
||||||
movl $0x7f7f7f7f,%edx /* clear 1 upper bits */
|
|
||||||
movl $0x1f1f1f1f,%esi /* clear 3 upper bits */
|
|
||||||
shrl $2,%ecx
|
|
||||||
jz 2f
|
|
||||||
|
|
||||||
1:
|
|
||||||
movl (%edi),%eax
|
|
||||||
addl $4,%edi
|
|
||||||
|
|
||||||
movl %eax,%ebx
|
|
||||||
shrl $1,%eax
|
|
||||||
|
|
||||||
|
|
||||||
shrl $3,%ebx
|
|
||||||
andl %edx,%eax
|
|
||||||
|
|
||||||
andl %esi,%ebx
|
|
||||||
addl %ebx,%eax
|
|
||||||
|
|
||||||
decl %ecx
|
|
||||||
movl %eax,-4(%edi)
|
|
||||||
|
|
||||||
|
|
||||||
jnz 1b
|
|
||||||
|
|
||||||
|
|
||||||
2:
|
|
||||||
popl %ebx
|
|
||||||
popl %esi
|
|
||||||
popl %edi
|
|
||||||
leave
|
|
||||||
ret
|
|
||||||
@@ -6,7 +6,7 @@ CFLAGS = -O3 -ffast-math -funroll-loops -fomit-frame-pointer -fexpensive-optimiz
|
|||||||
LIBS = -lbe -lscreensaver
|
LIBS = -lbe -lscreensaver
|
||||||
NAME = Nebula
|
NAME = Nebula
|
||||||
FILES = Nebula
|
FILES = Nebula
|
||||||
ASMFILES = draw
|
ASMFILES =
|
||||||
STARFILE = draw_stars
|
STARFILE = draw_stars
|
||||||
STARWIDTHS = 320 512 576 640 800 1024 1152 1280 1400 1600
|
STARWIDTHS = 320 512 576 640 800 1024 1152 1280 1400 1600
|
||||||
OBJDIR = obj.x86
|
OBJDIR = obj.x86
|
||||||
|
|||||||
Reference in New Issue
Block a user