
#include	"stdafx.h"
#include	<math.h>
#include	<stdlib.h>

#include    "_blur.h"

#include    "common.h"

int     plappz;
static  float fade = 0.0;
static  float fadespeed = 0.000;
static  float startp = 560.0;
static  float movep = 0.0;

unsigned char    mtab[64*256*2];

void    shit_init(void)
{
//    mtab = new unsigned char[64*256*2];  // 64 bilinear levels.-- 6 bits
//    if (!mtab) return;

    unsigned char *moo = mtab;
    for (int i=0; i<64; i++)
    {
        for (int c=-256; c<256; c++)
        {
            *moo++ = (int)((c*i)/64.0 );
        }
    }

    BILTAB = mtab+256;
}

int xTab[320];
int yTab[200];

void    RadialBlur(unsigned char *dest, float fx, float fy, float f, float zoom)
{
    float dmx = zoom;
    float dmy = zoom;


    int *boo = xTab;
    for (int x=0; x<320; x++)
    {
        float dist = (float)x-fx;
        int d = (int)(dist*64.0*dmx);
        *boo++ = d;
    }

    boo = yTab;
    for (int y=0; y<200; y++)
    {
        float dist = (float)y-fy;
        int d = (int)(dist*64.0*dmy);
        *boo++ = d;
    }

    int ix = (int)(fx);
    int iy = (int)(fy);
	__asm
	{
		//#pragma aux RADIALBLUR parm [edi][eax][ebx][esi][ecx][edx]

		mov edi,dest
		mov eax,ix
		mov ebx,iy
		lea esi,f
		mov ecx,offset xTab
		mov edx,offset yTab

		call RADIALBLUR
	}

    //RADIALBLUR(dest, ix, iy, &f, xTab, yTab);
}


void shit(void)
{

    float tomppo = 0;

    for (int c1=0;c1<768;c1++) mypal[0][c1]=c1/12;
    setpal(mypal);


    shit_init();

    while (!kbhit())
    {
        startp += movep*tomppo;

        unsigned char *paa = (unsigned char *)screenbuf;
        for (int i=0; i<64000; i++)
        {
            if ((rand()&31)<3)
                *paa++ = rand();
            else
                *paa++ = 0;
        }
//        float x = startp;
//        float yy = 100.0+sin(tomppo*0.004)*60.0;

/*      float koo = fabs(x-160);
        koo = 1.f/(koo*0.003+1.f);
        koo*=0.96;*/

        float x = 160.0;
        float yy= 100.0;
        float koo = 0.8;

        RadialBlur((unsigned char *)screenbuf, x, yy, koo, -0.025);
        swapscreens();

    }
}


