/* spritefx.cpp - Don Yang (uguu.org) 12/21/00 */ #include"global.h" #include"spritefx.h" static void DimSprite15(BYTE *image, int psize); static void DimSprite16(BYTE *image, int psize); static void DimSprite24(BYTE *image, int psize); static void DimSprite32(BYTE *image, int psize); static void MaskSprite16(BYTE *image, BYTE *timage, int psize); static void MaskSprite24(BYTE *image, BYTE *timage, int psize); static void MaskSprite32(BYTE *image, BYTE *timage, int psize); /************************************************************* PostProcess15 Prepare sprite for non-opaque modes. */ void PostProcess15(BYTE *image, BYTE *timage, int psize) { if( GameOptions & OPTION_SPR_TRANSLUCENT ) DimSprite15(image, psize); if( GameOptions & OPTION_SPR_TRANSPARENT ) MaskSprite16(image, timage, psize); } // PostProcess15() /************************************************************* PostProcess16 Prepare sprite for non-opaque modes. */ void PostProcess16(BYTE *image, BYTE *timage, int psize) { if( GameOptions & OPTION_SPR_TRANSLUCENT ) DimSprite16(image, psize); if( GameOptions & OPTION_SPR_TRANSPARENT ) MaskSprite16(image, timage, psize); } // PostProcess16() /************************************************************* PostProcess24 Prepare sprite for non-opaque modes. */ void PostProcess24(BYTE *image, BYTE *timage, int psize) { if( GameOptions & OPTION_SPR_TRANSLUCENT ) DimSprite24(image, psize); if( GameOptions & OPTION_SPR_TRANSPARENT ) MaskSprite24(image, timage, psize); } // PostProcess24() /************************************************************* PostProcess32 Prepare sprite for non-opaque modes. */ void PostProcess32(BYTE *image, BYTE *timage, int psize) { if( GameOptions & OPTION_SPR_TRANSLUCENT ) DimSprite32(image, psize); if( GameOptions & OPTION_SPR_TRANSPARENT ) MaskSprite32(image, timage, psize); } // PostProcess32() /*********************************************************** TDrawSprite15_2 Draw sprite (1:5:5:5, translucent) */ void TDrawSprite15_2(BYTE *src, BYTE *dst, int width, int height) { DWORD y, w0; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width shl eax, 1 mov edx, DDPitch sub edx, eax ; EDX = offset between scanlines shr eax, 2 mov w0, eax TDrawSprite15_2_yloop: mov ecx, w0 TDrawSprite15_2_xloop: lodsd mov ebx, [edi] shr ebx, 1 and ebx, 3def3defh ; 00rrrr0g ggg0bbbb 00rrrr0g ggg0bbbb add eax, ebx stosd loop TDrawSprite15_2_xloop add edi, edx dec dword ptr [y] jnz TDrawSprite15_2_yloop popf } } // TDrawSprite15_2() /*********************************************************** TDrawSprite15_3 Draw sprite (1:5:5:5, transparent/translucent) */ void TDrawSprite15_3(BYTE *src, BYTE *dst, int width, int height) { DWORD y; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width shl eax, 1 mov edx, DDPitch sub edx, eax ; EDX = offset between scanlines TDrawSprite15_3_yloop: mov ecx, width TDrawSprite15_3_xloop: lodsw cmp ax, 0ffffh je TDrawSprite15_3_t mov bx, [edi] shr bx, 1 and bx, 3defh ; 00rrrr0g ggg0bbbb add ax, bx stosw loop TDrawSprite15_3_xloop jmp TDrawSprite15_3_endx TDrawSprite15_3_t: add edi, 2 loop TDrawSprite15_3_xloop TDrawSprite15_3_endx: add edi, edx dec dword ptr [y] jnz TDrawSprite15_3_yloop popf } } // TDrawSprite15_3() /*********************************************************** TDrawSprite16_1 Draw sprite (5:6:5, transparent) */ void TDrawSprite16_1(BYTE *src, BYTE *dst, int width, int height) { __asm { pushf cld mov esi, src mov edi, dst mov ebx, height mov eax, width shl eax, 1 mov edx, DDPitch sub edx, eax ; EDX = offset between scanlines TDrawSprite16_1_yloop: mov ecx, width TDrawSprite16_1_xloop: lodsw cmp ax, 0ffffh je TDrawSprite16_1_t; stosw loop TDrawSprite16_1_xloop jmp TDrawSprite16_1_endx TDrawSprite16_1_t: add edi, 2 loop TDrawSprite16_1_xloop TDrawSprite16_1_endx: add edi, edx dec ebx jnz TDrawSprite16_1_yloop popf } } // TDrawSprite16_1() /*********************************************************** TDrawSprite16_2 Draw sprite (5:6:5, translucent) */ void TDrawSprite16_2(BYTE *src, BYTE *dst, int width, int height) { DWORD y, w0; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width shl eax, 1 mov edx, DDPitch sub edx, eax ; EDX = offset between scanlines shr eax, 2 mov w0, eax TDrawSprite16_2_yloop: mov ecx, w0 TDrawSprite16_2_xloop: lodsd mov ebx, [edi] shr ebx, 1 and ebx, 7bef7befh ; 0rrrr0gg ggg0bbbb 0rrrr0gg ggg0bbbb add eax, ebx stosd loop TDrawSprite16_2_xloop add edi, edx dec dword ptr [y] jnz TDrawSprite16_2_yloop popf } } // TDrawSprite16_2() /*********************************************************** TDrawSprite16_3 Draw sprite (5:6:5, transparent/translucent) */ void TDrawSprite16_3(BYTE *src, BYTE *dst, int width, int height) { DWORD y; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width shl eax, 1 mov edx, DDPitch sub edx, eax ; EDX = offset between scanlines TDrawSprite16_3_yloop: mov ecx, width TDrawSprite16_3_xloop: lodsw cmp ax, 0ffffh je TDrawSprite16_3_t mov bx, [edi] shr bx, 1 and bx, 7befh ; 0rrrr0gg ggg0bbbb add ax, bx stosw loop TDrawSprite16_3_xloop jmp TDrawSprite16_3_endx TDrawSprite16_3_t: add edi, 2 loop TDrawSprite16_3_xloop TDrawSprite16_3_endx: add edi, edx dec dword ptr [y] jnz TDrawSprite16_3_yloop popf } } // TDrawSprite16_3() /*********************************************************** TDrawSprite24_1 Draw sprite (8:8:8, transparent) */ void TDrawSprite24_1(BYTE *src, BYTE *dst, int width, int height) { __asm { pushf cld mov esi, src mov edi, dst mov ebx, height mov eax, width mov edx, DDPitch sub edx, eax shl eax, 1 sub edx, eax ; EDX = delta between scanlines TDrawSprite24_1_yloop: mov ecx, width TDrawSprite24_1_xloop: lodsw cmp ax, 0ffffh je TDrawSprite24_1_t stosw movsb loop TDrawSprite24_1_xloop jmp TDrawSprite24_1_endx TDrawSprite24_1_t: add edi, 3 inc esi loop TDrawSprite24_1_xloop TDrawSprite24_1_endx: add edi, edx dec ebx jnz TDrawSprite24_1_yloop popf } } // TDrawSprite24_1() /*********************************************************** TDrawSprite24_2 Draw sprite (8:8:8, translucent) */ void TDrawSprite24_2(BYTE *src, BYTE *dst, int width, int height) { DWORD w0, y; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width shl eax, 1 add eax, width mov edx, DDPitch sub edx, eax ; EDX = delta between scanlines shr eax, 1 mov w0, eax TDrawSprite24_2_yloop: mov ecx, w0 TDrawSprite24_2_xloop: lodsw mov bx, [edi] shr bx, 1 and bx, 7f7fh add ax, bx stosw loop TDrawSprite24_2_xloop add edi, edx dec dword ptr [y] jnz TDrawSprite24_2_yloop popf } } // TDrawSprite24_2() /*********************************************************** TDrawSprite24_3 Draw sprite (8:8:8, transparent/translucent) */ void TDrawSprite24_3(BYTE *src, BYTE *dst, int width, int height) { DWORD y; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width mov edx, DDPitch sub edx, eax shl eax, 1 sub edx, eax ; EDX = delta between scanlines TDrawSprite24_3_yloop: mov ecx, width TDrawSprite24_3_xloop: lodsw cmp ax, 0ffffh je TDrawSprite24_3_t mov bx, [edi] shr bx, 1 and bx, 7f7fh add ax, bx stosw lodsb mov bl, [edi] shr bl, 1 and bl, 7fh add al, bl stosb loop TDrawSprite24_3_xloop jmp TDrawSprite24_3_endx TDrawSprite24_3_t: add edi, 3 inc esi loop TDrawSprite24_3_xloop TDrawSprite24_3_endx: add edi, edx dec dword ptr [y] jnz TDrawSprite24_3_yloop popf } } // TDrawSprite24_3() /*********************************************************** TDrawSprite32_1 Draw sprite (8:8:8:8, transparent) */ void TDrawSprite32_1(BYTE *src, BYTE *dst, int width, int height) { __asm { pushf cld mov esi, src mov edi, dst mov ebx, height mov eax, width mov edx, DDPitch shl eax, 2 sub edx, eax ; EDX = delta between scanlines TDrawSprite32_1_yloop: mov ecx, width TDrawSprite32_1_xloop: lodsd cmp eax, 0ffffffffh je TDrawSprite32_1_t stosd loop TDrawSprite32_1_xloop jmp TDrawSprite32_1_endx TDrawSprite32_1_t: add edi, 4 loop TDrawSprite32_1_xloop TDrawSprite32_1_endx: add edi, edx dec ebx jnz TDrawSprite32_1_yloop popf } } // TDrawSprite32_1() /*********************************************************** TDrawSprite32_2 Draw sprite (8:8:8:8, translucent) */ void TDrawSprite32_2(BYTE *src, BYTE *dst, int width, int height) { DWORD y; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width mov edx, DDPitch shl eax, 2 sub edx, eax ; EDX = delta between scanlines TDrawSprite32_2_yloop: mov ecx, width TDrawSprite32_2_xloop: lodsd mov ebx, [edi] shr ebx, 1 and ebx, 7f7f7f7fh add eax, ebx stosd loop TDrawSprite32_2_xloop add edi, edx dec dword ptr [y] jnz TDrawSprite32_2_yloop popf } } // TDrawSprite32_2() /*********************************************************** TDrawSprite32_3 Draw sprite (8:8:8:8, transparent/trslucent) */ void TDrawSprite32_3(BYTE *src, BYTE *dst, int width, int height) { DWORD y; __asm { pushf cld mov esi, src mov edi, dst mov eax, height mov y, eax mov eax, width shl eax, 2 mov edx, DDPitch sub edx, eax ; EDX = delta between scanlines TDrawSprite32_3_yloop: mov ecx, width TDrawSprite32_3_xloop: lodsd cmp eax, 0ffffffffh je TDrawSprite32_3_t mov ebx, [edi] shr ebx, 1 and ebx, 7f7f7f7fh add eax, ebx stosd loop TDrawSprite32_3_xloop jmp TDrawSprite32_3_endx TDrawSprite32_3_t: add edi, 4 loop TDrawSprite32_3_xloop TDrawSprite32_3_endx: add edi, edx dec dword ptr [y] jnz TDrawSprite32_3_yloop popf } } // TDrawSprite32_3() /*************************************************************** DimSprite15 Prepare sprite for translucency. */ static void DimSprite15(BYTE *image, int psize) { __asm { pushf cld mov esi, image mov edi, esi mov ecx, psize shr ecx, 1 mov edx, 7def7defh ; 0rrrrr0g ggg0bbbb 0rrrrr0g ggg0bbbb DimSprite15_loop: lodsd shr eax, 1 and eax, edx stosd loop DimSprite15_loop popf } } // DimSprite15() /*************************************************************** DimSprite16 Prepare sprite for translucency. */ static void DimSprite16(BYTE *image, int psize) { __asm { pushf cld mov esi, image mov edi, esi mov ecx, psize shr ecx, 1 mov edx, 7bef7befh ; 0rrrr0gg ggg0bbbb 0rrrr0gg ggg0bbbb DimSprite16_loop: lodsd shr eax, 1 and eax, edx stosd loop DimSprite16_loop popf } } // DimSprite16() /*************************************************************** DimSprite24 Prepare sprite for translucency. */ static void DimSprite24(BYTE *image, int psize) { __asm { pushf cld mov esi, image mov edi, esi mov edx, 7f7f7f7fh mov eax, psize mov ecx, eax shl eax, 1 add ecx, eax shr ecx, 2 ; ECX = psize * 3 / 4 DimSprite24_loop: lodsd shr eax, 1 and eax, edx stosd loop DimSprite24_loop popf } } // DimSprite24() /*************************************************************** DimSprite32 Prepare sprite for translucency. */ static void DimSprite32(BYTE *image, int psize) { __asm { pushf cld mov esi, image mov edi, esi mov edx, 7f7f7f7fh mov ecx, psize DimSprite32_loop: lodsd shr eax, 1 and eax, edx stosd loop DimSprite32_loop popf } } // DimSprite32() /************************************************************** MaskSprite16 Mark regions of sprite as transparent. */ static void MaskSprite16(BYTE *image, BYTE *timage, int psize) { __asm { pushf cld mov esi, timage mov edi, image mov ecx, psize mov edx, 0ffffffffh MaskSprite16_loop: lodsb cmp al, TRANSPARENT_THRESHOLD ja MaskSprite16_mask add edi, 2 loop MaskSprite16_loop jmp MaskSprite16_end MaskSprite16_mask: mov eax, edx stosw loop MaskSprite16_loop MaskSprite16_end: popf } } // MaskSprite16() /************************************************************** MaskSprite24 Mark regions of sprite as transparent. */ static void MaskSprite24(BYTE *image, BYTE *timage, int psize) { __asm { pushf cld mov esi, timage mov edi, image mov ecx, psize mov edx, 0ffffffffh MaskSprite24_loop: lodsb cmp al, TRANSPARENT_THRESHOLD ja MaskSprite24_mask add edi, 3 loop MaskSprite24_loop jmp MaskSprite24_end MaskSprite24_mask: mov eax, edx stosw stosb loop MaskSprite24_loop MaskSprite24_end: popf } } // MaskSprite24() /************************************************************** MaskSprite32 Mark regions of sprite as transparent. */ static void MaskSprite32(BYTE *image, BYTE *timage, int psize) { __asm { pushf cld mov esi, timage mov edi, image mov ecx, psize mov edx, 0ffffffffh MaskSprite32_loop: lodsb cmp al, TRANSPARENT_THRESHOLD ja MaskSprite32_mask add edi, 4 loop MaskSprite32_loop jmp MaskSprite32_end MaskSprite32_mask: mov eax, edx stosd loop MaskSprite32_loop MaskSprite32_end: popf } } // MaskSprite32() char *SpritefxObjTime = __TIME__ " " __DATE__; int SpritefxObjLines = __LINE__;