01#include"main.h"
#include"phong.h"
#include"phong2.h"


//asmcopyfontschweif(); hat noch probleme, hssliche blur streifen


int ccx=110,ccy=110,ccxadd=-3,ccyadd=-1;        //
int ccx1=40,ccy1=110,ccxadd1=2,ccyadd1=3;
int ccx2=210,ccy2=40,ccxadd2=-4,ccyadd2=-2;      //
int ccx3=240,ccy3=60,ccxadd3=2,ccyadd3=4;
int ccx4=60,ccy4=140,ccxadd4=-4,ccyadd4=-3;     //
int ccx5=160,ccy5=160,ccxadd5=3,ccyadd5=5;
int smok_shak=0;
int smok_x=0;

/* ==(procedures)======================================================================= */
/* ===================================================================================== */
void put_pixel(int x,int y,char r,char g,char b){
  buffer[y*(X_RES<<2)+(x<<2)]=r;
  buffer[y*(X_RES<<2)+(x<<2)+1]=g;
  buffer[y*(X_RES<<2)+(x<<2)+2]=b;
}

void put_pixel_sw(int x,int y,char r,char g,char b){
  schweif[y*(X_RES<<2)+(x<<2)]=r;
  schweif[y*(X_RES<<2)+(x<<2)+1]=g;
  schweif[y*(X_RES<<2)+(x<<2)+2]=b;
}


void init_demo(){
int x,i;
unsigned char r,g,b;
float v,vadd;
	v=0.0;
	vadd=(2.0*PI/256.0);
        for (x=0;x<256;x++){
                cosine[x] =(cos(v)*75);
                sine[x]   =(sin(v)*75);
                cosine2[x]=cos(v)*47;   //kreisradius des sternes (NICHT metastuff)
                sine2[x]  =sin(v)*47;
                cosine3[x]=cos(v)*25;
                sine3[x]  =sin(v)*25;
                v+=vadd;
        }
	for (i=0; i<256; i++){
            if (phong[i*3+0]>5)  phong[i*3+0]-= 5; else phong[i*3+0]=0;
            if (phong[i*3+1]>5)  phong[i*3+1]-= 5; else phong[i*3+1]=0;
            if (phong[i*3+2]>5)  phong[i*3+2]-= 5; else phong[i*3+2]=0;

            phong[i*3+2]+=25;

            testpal2[i]=((phong2[i*3+2]<<16)+(phong2[i*3+1]<<8)+(phong2[i*3+0]));
            testpal[i]=((phong[i*3+2]<<16)+(phong[i*3+1]<<8)+(phong[i*3+0]));
        }

        for (x=0;x<Y_RES;x++) xtab[x]=x*1280;
}


void do_metastuff(int originx,int originy,unsigned char color){
int x,y,a,b;
for (x=0;x<127;x++){
           a=originx+cosine2[x];
           b=originy+sine2[x];
           line(originx,originy,a,b,color,phong2);
         }
}

void do_metastuffMMX(int originx,int originy,unsigned char color){
int x,y,a,b;
for (x=0;x<127;x++){
           a=originx+cosine2[x];
           b=originy+sine2[x];
           lineimp(originx,originy,a,b,color,1);
//              line(originx,originy,a,b,color,phong2);
         }
}


void do_starstuff(int originx,int originy,int staerke){
int x,y,a,b;
         for (x=0;x<127;x+=staerke){
           a=originx+cosine2[x];
           b=originy+sine2[x];
           line(originx,originy,a,b,random()%255,phong);
         }

}

void do_starstuffMMX(int originx,int originy,int staerke){
int x,y,a,b;
         for (x=0;x<127;x+=staerke){
           a=originx+cosine2[x];
           b=originy+sine2[x];
           lineimp(originx,originy,a,b,random()%255,0);
         }

}


void draw_nd_update_stuff(unsigned char bb, unsigned char bb1, unsigned char bb2){
do_starstuff(ccx,                       ccy,2);
do_metastuff(ccx+cosine3[bb],           ccy+sine3[bb],120);
do_metastuff(ccx+cosine3[(bb+128)%255], ccy+sine3[(bb+128)%255],100);

do_starstuff(ccx1,ccy1,1);

do_starstuff(ccx2,                        ccy2,2);
do_metastuff(ccx2+cosine3[bb1],           ccy2+sine3[bb1],120);
do_metastuff(ccx2+cosine3[(bb1+128)%255], ccy2+sine3[(bb1+128)%255],110);

do_starstuff(ccx3,ccy3,1);

do_starstuff(ccx4,                       ccy4,2);
do_metastuff(ccx4+cosine3[bb2],           ccy4+sine3[bb2],130);
do_metastuff(ccx4+cosine3[(bb2+128)%255], ccy4+sine3[(bb2+128)%255],110);

do_starstuff(ccx5,ccy5,1);

ccx+=ccxadd;
if ((ccx>280)||(ccx<35)) ccxadd=0-ccxadd;
ccy+=ccyadd;
if ((ccy>170)||(ccy<35)) ccyadd=0-ccyadd;

ccx1+=ccxadd1;
if ((ccx1>280)||(ccx1<35)) ccxadd1=0-ccxadd1;
ccy1+=ccyadd1;
if ((ccy1>170)||(ccy1<35)) ccyadd1=0-ccyadd1;

ccx2+=ccxadd2;
if ((ccx2>280)||(ccx2<35)) ccxadd2=0-ccxadd2;
ccy2+=ccyadd2;
if ((ccy2>170)||(ccy2<35)) ccyadd2=0-ccyadd2;

ccx4+=ccxadd4;
if ((ccx4>280)||(ccx4<35)) ccxadd4=0-ccxadd4;
ccy4+=ccyadd4;
if ((ccy4>170)||(ccy4<35)) ccyadd4=0-ccyadd4;

ccx3+=ccxadd3;
if ((ccx3>280)||(ccx3<35)) ccxadd3=0-ccxadd3;
ccy3+=ccyadd3;
if ((ccy3>170)||(ccy3<35)) ccyadd3=0-ccyadd3;

ccx5+=ccxadd5;
if ((ccx5>280)||(ccx5<35)) ccxadd5=0-ccxadd5;
ccy5+=ccyadd5;
if ((ccy5>170)||(ccy5<35)) ccyadd5=0-ccyadd5;

}

void fill_exc_logo(){
            ccx =88;
            ccy =87;
            ccx1=127;
            ccy1=87;
            ccx2=165;
            ccy2=87;
            ccx3=196;
            ccy3=65;
            ccx5=218;
            ccy5=87;
            ccx4=253;
            ccy4=87;
}


void crediz_part(int wahl){
int fntx,x;
long l;
            if ((fntx=random()%15+2)<5) fnty=random()%10;//10
            if ((wahl%100)<50){
                for (x=0;x<20;x++)
                    do_metastuffMMX(10+random()%240,15+fnty+random()%80,(random()%120)+80);
                __write13h2(0,"`D[[\0",fntx,(25+fnty)<<2);
                __write13h2(0,"\\CODE\\[[\0",fntx,(50+fnty)<<2);
                __write13h (0,"IQUITO[[[[[[\0",fntx,(75+fnty)<<2);
            } else
            if ((wahl%100)<100){
                for (x=0;x<20;x++)
                    do_metastuffMMX(60+random()%240,90+fnty+random()%80,(random()%120)+80);
                __write13h2(0,"[_D\0",fntx,(100+fnty)<<2);
                __write13h2(0,"[\\CODE\\\0",fntx,(125+fnty)<<2);
                __write13h (0,"[[GENOZ[TASH\0",fntx,(150+fnty)<<2);
            }/**/
            do_plasma();
            asmcopyfontschweif();
            asmblurscreenrgbmmx(0x070503);/**/

}




void smokepart(){
signed short rndm,rndmor;
rndm=0;//random()%2;

/*     do_fire(151+rndm, 171,234+smok_x    ,26+(sine[(smok_shak+222)%256]>>3)  ,8, 140-(sine2[(smok_shak    )%256]>>3),21000);
     do_fire(151+rndm, 171,128+smok_x    ,45+(sine[smok_shak%256]>>2)        ,8, 152-(sine2[(smok_shak+32 )%256]>>3),21000);
     do_fire(151+rndm, 171,98+smok_x     ,60+(sine[(smok_shak+44)%256]>>1)   ,8, 140+(sine2[(smok_shak+64 )%256]>>2),21000);
     do_fire(152+rndm, 171,(smok_x>>1)   ,28+(sine[(smok_shak+122)%256]>>3)  ,7, 140+(sine2[(smok_shak+96 )%256]>>3),21000);
     do_fire(152, 171,smok_x        ,44+(sine3[(smok_shak+222)%256]>>1) ,7, 140-(sine2[(smok_shak+128)%256]>>2),21000);
     do_fire(152, 171,234+smok_x    ,10                                 ,6, 150+(sine2[(smok_shak+160)%256]>>3),21000);
     do_fire(153, 171,158+smok_x    ,162+(sine[    (smok_shak)%256]>>2) ,6, 165+(sine2[(smok_shak+192)%256]>>3),21000);
     do_fire(153, 171,58+(smok_x>>1),148+(sine[(smok_shak+142)%256]>>2) ,5, 140+(sine3[(smok_shak+224)%256]>>1),21000);
/**/

//   do_fire(233, 120,158+smok_x   , 8 ,2, 199, 50, 19000);
     do_fire(233, 121,smok_x>>1, 8 ,3, 199, 64-(sine2[(smok_shak<<1)%256]>>2),33000);
     do_fire(233, 121,smok_x   , 6 ,2, 199,128-(sine2[(smok_shak+32 )%256]>>2),30000);
     do_fire(231, 122,smok_x>>1, 5 ,3, 199,256-(sine2[(smok_shak+64 )%256]>>2),31000);
     do_fire(232, 122,smok_x   , 7 ,3, 199,196-(sine2[(smok_shak+96 )%256]>>2),32000);
     do_fire(231, 123,smok_x   , 9 ,3, 199, 64+(sine2[(smok_shak+128)%256]>>2),53000);
     do_fire(232, 123,smok_x   , 7 ,2, 199,256+(sine2[(smok_shak+160)%256]>>3),40000);
     do_fire(233, 123,smok_x,    6 ,3, 199,128+(sine2[(smok_shak+192)%256]>>3),47000);
     do_fire(231, 123,smok_x,    8 ,2, 199,196+(sine3[(smok_shak+224)%256]>>2),44000);

/**/

//     do_fire(293, 171,234+smok_x    ,10                                 ,6, 150+(sine2[(smok_shak+160)%256]>>3),21000);
//     smok_x+=rndm;
//1x+
//2y position
//4neigung, wenn wert 100+ ist neigung nach rechts
//5speed der drehung
//speed, welcher rauch nach oben zieht
//ab welcher y pos kann rauch seitlich ausbrechen
//konstante fr radius berechnung
/**/
     smok_x+=14;          //16
     smok_shak+=5;  //6
}



int main(int argc,char *argv[])
{
        int x,y;
        long frames=0,l;
        unsigned char bb=60,bb1=4,bb2=44;
        double fps;

        time_t tim2;
        time_t tim;
        int a=25;

        int f_x,f_y,f_a,f_b;
        int f_x1,f_y1,f_a1,f_b1;

        __djgpp_nearptr_enable();
        textmode(C80);
        printf("\nblured sigth (c) by excite");
        printf("\n\n=>search a mmx processor: ");
        mmxdetection();
        if (mmxdetected==1) printf("found"); else
                            printf("not found");
        fflush(stdout);
//      sleep(3);

        init_demo_system(X_RES,Y_RES,BPP);
	srand(0x46c);
        init_demo();
        memset(buffer,0,320*200*4);
        memset(schweif,0,320*200*4);
//        convert2432(logo,logo32,320*200);
        convert2432(smokelogo,smokelogo32,320*200);
        convert2432(spr,spr32,136*67);
        initasmcode();                    //buffers auf 0 setzen
        memset(screen,0,X_RES*Y_RES*4);
        do_plasma_precalc();
        x=y=p1=p2=p3=p4=fnty=0;


        for (x=0;x<320*200*4;x++) {
          logo32[x]>>=1;
//          smokelogo32[x]>>=2;
        }
        memset(blur_buffer,0,21*320*4);
        tim = time (NULL);
        sleep(1);

        x=30;
        f_y=f_x=random()%100;
        f_a=4;
        f_y1=f_x1=random()%100;
        f_a1=4;

        while( (!kbhit()) /*(frames<100)/*/ ){

//  write_time();
//  memset(schweif,0,320*200*4);
  f_x-=f_a;
  if (f_x<30) f_a=-4;
  if ((f_x>f_y))
  {     f_y=random()%238;
        f_a=4;  }

  f_x1-=f_a1;
  if (f_x1<30) f_a1=-3;
  if ((f_x1>f_y1))
  {     f_y1=random()%134;
        f_a1=3;  }
//  f_x=f_x1=132;

f_x=136;
f_x1=67;
//  draw_texture2(schweif,1000-(f_x<<1),40+f_x,f_x-1,0);
//  draw_texture(schweif,f_x,f_x1,sine2[(frames+frames)%256]);
//    draw_texture(schweif,40+f_x,40+f_x,22);//((f_x+f_x1)%110)-55);

/*  asmblurscreenrgbmmx(0x030006);   //060402
  asmblurscreenrgbmmx(0x020304);   //060402            /**/


/*  for (y=0;y<15;y++)
        for (x=0;x<15;x++)
            do_metastuffMMX(10+random()%290,10+random()%170,(random()%150)+5);

    asmblurscreenrgbmmx(0x060504);/**/


/*          draw_nd_update_stuff(bb,bb1,bb2);
          asmblurscreenrgbmmx(0x080602);   //060402
          bb-=9;
          bb1+=8;
          bb2-=7;/**/


//          memcpy(schweif,smokelogo32+4,320*200*4);
          smokepart();
          asmblurscreenrgbmmx(0x0a0a0a);   //060402

for (x=0;x<320*200*4;x++){
    if (smokelogo32[x]!=0) schweif[x-8]=smokelogo32[x];
}

/*            for (l=0;l<320*100*4;l+=4){ //bertrgt das logo wenn screen!=0 ist
                if ((long)schweif[l]!=0) schweif[l]+=(long)smokelogo32[l];
            }/**/

//      crediz_part(frames);

          do_timestuff(frames,tim);

        blitscreen3216(schweif,vid_point,X_RES*Y_RES);
//memcpy(vid_point,schweif,320*200*4);

            frames++;
        }

        tim2 = time(NULL);

/*for (x=1;x<200;x++){
            asmblurscreenrgbmmx(0);
            blitscreen3216(schweif,vid_point,X_RES*Y_RES);
}/**/

  exit_demo_system();

  fps=frames/difftime(tim2,tim);

  printf("\nfps: %f (%u frames in %f seconds)",fps,frames,difftime(tim2,tim));

  return 0;
}
/* ===================================================================================== */

/*
            if (a>0){
               fill_exc_logo();
               a--;
            }
            draw_nd_update_stuff(bb,bb1,bb2);
            bb-=9;
            bb1+=8;
            bb2-=7;

/**/
/*
do_fire(151, 171,234+x    ,26+(sine[(smok_shak+222)%256]>>3)  ,8, 160-(sine2[(smok_shak    )%256]>>3));
do_fire(151, 171,128+x    ,45+(sine[smok_shak%256]>>2)        ,8, 160-(sine2[(smok_shak+32 )%256]>>3));
do_fire(152, 171,98+x     ,60+(sine[(smok_shak+44)%256]>>1)   ,8, 160+(sine2[(smok_shak+64 )%256]>>2));
do_fire(152, 171,(x>>1)   ,28+(sine[(smok_shak+122)%256]>>3)  ,7, 160+(sine2[(smok_shak+96 )%256]>>3));
do_fire(153, 171,x        ,44+(sine3[(smok_shak+222)%256]>>1) ,7, 160-(sine2[(smok_shak+128)%256]>>2));
do_fire(153, 171,234+x    ,10                                 ,6, 160+(sine2[(smok_shak+160)%256]>>3));
do_fire(154, 171,158+x    ,162+(sine[    (smok_shak)%256]>>2) ,6, 160+(sine2[(smok_shak+192)%256]>>3));
do_fire(154, 171,58+(x>>1),148+(sine[(smok_shak+142)%256]>>2) ,5, 160+(sine3[(smok_shak+224)%256]>>1));

do_metastuff(70,180,180);
do_metastuff(30+((frames)%100),180,180);
do_starstuff(220,40,3);
//schweif

x+=16;          //16
smok_shak+=5;  //6
*/


/*            for (l=0;l<320*100*4;l+=4){ //bertrgt das logo wenn screen!=0 ist
                if ((long)schweif[l]!=0) schweif[l]+=(long)smokelogo32[l];
            }
/**/

