bits 32




;include "pmode.idl"
;include "macros.inc"

global _RADIALBLUR
global _BILTAB
global _divide21
global _mytab

section .data

align 16


times 1024 db 0
global _divide21
_divide21:
		%assign n 0
		%rep 21*256
		db n/21
		%assign n n+1
		%endrep
times 1024 db 0

_BILTAB dd      0

dir     dd      0
xfrac   dd      0
yfrac   dd      0
buff	dd	0
xtab	dd	0
ytab	dd	0
freq	dd	0
xc	dd	0
yc	dd	0
fbktab  times 256 db      0

hoax            dd      0

m1              dd      -256.0
one		dd	1.0
zero		dd	0.0

global _cliptab

_cliptab:
cliptab:

%assign n 0
%rep 256
db n
%assign n n+1
%endrep

times 256 db 255

global _cliptab128
_cliptab128:
cliptab128:
%assign n 0
%rep 128
db n
%assign n n+1
%endrep
times 128 db (127)

	


_mytab:
%assign n 0
%assign n2 420
%rep 256
db n/256
%assign n n+n2
%if n > 255*256
%assign n 255*256
%assign n2 -n2
%endif
%if n < 0
%assign n 0
%endif
%endrep





align 16

section .text



align 16

_start_code:

        ;public  _BILTAB

%macro @INNER 0
        mov     ebp, [xtab]

        mov     edx, [ebp+ecx*4]

        mov     ebx, edx
        and     ebx, 63
        shl     ebx, 9
        mov     [xfrac], ebx

        sar     edx, 6

        xor     eax, eax
        xor     ebx, ebx
        mov     al, [esi+edx]        ; n
        mov     bl, [esi+edx+320]  ; n+320

        push    ecx
        push    edx

        @BILZOO [yfrac]

        pop     edx

        push    eax

        mov     al, [esi+edx+1]        ; n
        mov     bl, [esi+edx+1+320]  ; n+320

        @BILZOO [yfrac]

        mov     ebx, eax
        pop     eax

        @BILZOO [xfrac]

        pop     ecx

        mov     dl, [edi]

        xor     ebx, ebx

        mov     bl, al
        add     dl, [fbktab + ebx]
        sbb     bl, bl
        or      dl, bl

;        mov     bl, ah
;        add     dh, [fbktab + ebx]
;        sbb     bl, bl
;        or      dh, bl
;
;        ror     eax, 8
;        ror     edx, 8
;
;        mov     bl, ah
;        add     dh, [fbktab + ebx]
;        sbb     bl, bl
;        or      dh, bl
;
;        rol     edx, 8

        mov     [edi], dl

%endmacro


%macro @BILZOO 1


        xor     ecx, ecx
        xor     edx, edx
        mov     dl, bl
        mov     cl, al
        sub     edx, ecx

        mov     ebp, %1
        add     ebp, [_BILTAB]

        add     al, [ebp+edx]

;        xor     edx, edx
;        mov     dl, bh
;        mov     cl, ah
;        sub     edx, ecx
;
;        add     ah, [ebp+edx]
;
;        ror     ebx, 8
;        ror     eax, 8
;
;        xor     ecx, ecx
;        xor     edx, edx
;        mov     dl, bh
;        mov     cl, ah
;        sub     edx, ecx
;
;        add     ah, [ebp+edx]
;
;        rol     eax, 8

%endmacro

	;public	RADIALBLUR_
_RADIALBLUR:

;	edi - dest
;	eax - x center
;	ebx - y center
;	esi - float * to freq
;	ecx - int * to xtab
;	edx - int * to ytab


;#pragma aux RADIALBLUR parm [edi][eax][ebx][esi][ecx][edx]

	pushad

	mov	[buff], edi
	mov	[xtab], ecx
	mov	[ytab], edx

	cmp	eax, 0
	jge	@@xok1
	xor	eax, eax
@@xok1:
	cmp	eax, 319
	jle	@@xok2
	mov	eax, 319
@@xok2:

	cmp	ebx, 0
	jge	@@yok1
	xor	ebx, ebx
@@yok1:

	cmp	ebx, 199
	jle	@@yok2
	mov	ebx, 199
@@yok2:

	mov	[xc], eax
	mov	[yc], ebx

        fld     dword [esi]
        fldz
        xor     ecx, ecx
@@kers:
        fist    dword [hoax]
        mov     al, byte [hoax]
        mov     [fbktab + ecx], al

        fadd    st0, st1
        inc     cl
        jnz     @@kers

        fcompp



;;;;;;;;;;;;;;;;; t„h„n loppu setupit



        mov     dword [dir], -1
        call    DRAW_L
        call    DRAW_R

        inc     dword [yc]

        mov     dword [dir], 1
        call    DRAW_L
        call    DRAW_R

	popa
	ret
;	ENDP

;PROC    DRAW_L
DRAW_L:
        pusha
	mov	ebp, [yc]
	mov	ecx, [xc]
        dec     ecx

        cmp     ecx, 0
        jl      near skip_ul1

	mov	edi, ebp
	imul	edi, 320 
	add	edi, ecx
        add     edi, [buff]
align 16
@@ul_yloop1:
        push    edi 
		push	ecx 
		push	ebp

        mov     esi, [ytab]
        mov     esi, [esi+ebp*4]
        mov     ebx, esi
        and     ebx, 63
        shl     ebx, 9
        mov     [yfrac], ebx
        sar     esi, 6
        imul    esi, 320
        add     esi, edi

align 16
@@ul_xloop1:

        @INNER

        dec     esi
        dec     edi

	dec	ecx
        jns     near @@ul_xloop1

        pop     ebp 
		pop		ecx 
		pop		edi

        mov     eax, 320
        imul    eax, [dir]
        add     edi, eax

        add     ebp, [dir]
        cmp     ebp, 0
        jl      skip_ul1
        cmp     ebp, 200
        jge     skip_ul1
        jmp     @@ul_yloop1

skip_ul1:
        popa
        ret
;ENDP

;PROC    DRAW_R
DRAW_R:
        pusha
;;; paaa
	mov	ebp, [yc]
	mov	ecx, [xc]

        cmp     ecx, 319
        jg      near skip_ul

	mov	edi, ebp
	imul	edi, 320
	add	edi, ecx
        add     edi, [buff]
align 16
@@ul_yloop:
        push    edi 
		push	ecx 
		push	ebp

        mov     esi, [ytab]
        mov     esi, [esi+ebp*4]
        mov     ebx, esi
        and     ebx, 63
        shl     ebx, 9
        mov     [yfrac], ebx
        sar     esi, 6
        imul    esi, 320
        add     esi, edi

align 16
@@ul_xloop:
        @INNER

        inc     esi
        inc     edi

        inc     ecx
        cmp     ecx, 320
        jl      near @@ul_xloop

        pop     ebp 
		pop		ecx 
		pop		edi

        mov     eax, 320
        imul    eax, [dir]
        add     edi, eax

        add     ebp, [dir]
        cmp     ebp, 0
        jl      skip_ul
        cmp     ebp, 200
        jge     skip_ul
        jmp     @@ul_yloop

skip_ul:

        popad
        ret
;ENDP

;@end_code


;@start_data


;@end_data

END

