#resize TRUE
#jumptomain SHORT

word screen;	//адрес буфера экрана
word blow;	//адрес буфера спрайта

void setrgbpalette(char color,r,g,b);
void drawblow(int dx,int dy);

float const1=0.5;
float const2=1.0;
float const3=1.5;
float const4=2.0;
float const5=2.5;
float const6=3.0;
float const7=58;
float const8=92;

void main()
long x,y;
float time=0;
{
	initblow();
	@SETVIDEOMODE(byte 0x13);
	setcolortable();
	while(!@KBHIT()){
		clearvirtualscreen();
		asm{
			fld time
			fmul const1
			fadd const2
			fsin
			fmul const8
			fistp x
			fwait
		}
		x+=32;
//		x=32+92*sin(time*0.5+1.0);
		asm{
			fld time
			fmul const3
			fadd const4
			fcos
			fmul const7
			fistp y
			fwait
		}
		y-=28;
//		y=-28+58*cos(time*1.5+2.0);
		drawblow(x,y);
		asm{
			fld time
			fmul const2
			fadd const3
			fsin
			fmul const8
			fistp x
			fwait
		}
		x+=32;
//		x=32+92*sin(time*1.0+1.5);
		asm{
			fld time
			fmul const4
			fadd const5
			fcos
			fmul const7
			fistp y
			fwait
		}
		y-=28;
//		y=-28+58*cos(time*2.0+2.5);
		drawblow(x,y);
		asm{
			fld time
			fmul const3
			fadd const4
			fsin
			fmul const8
			fistp x
			fwait
		}
		x+=32;
//		x=32+92*sin(time*1.5+2.0);
		asm{
			fld time
			fmul const5
			fadd const6
			fcos
			fmul const7
			fistp y
			fwait
		}
		y-=28;
//		y=-28+58*cos(time*2.5+3.0);
		drawblow(x,y);
		asm{
			fld time
			fmul const4
			fadd const5
			fsin
			fmul const8
			fistp x
			fwait
		}
		x+=32;
//		x=32+92*sin(time*2.0+2.5);
		asm{
			fld time
			fmul const6
			fadd const1
			fcos
			fmul const7
			fistp y
			fwait
		}
		y-=28;
//		y=-28+58*cos(time*3.0+0.5);
		drawblow(x,y);
		asm{
			fld time
			fmul const5
			fadd const6
			fsin
			fmul const8
			fistp x
			fwait
		}
		x+=32;
//		x=32+92*sin(time*2.5+3.0);
		asm{
			fld time
			fmul const1
			fadd const2
			fcos
			fmul const7
			fistp y
			fwait
		}
		y-=28;
//		y=-28+58*cos(time*0.5+1.0);
		drawblow(x,y);
		asm{
			fld time
			fmul const6
			fadd const1
			fsin
			fmul const8
			fistp x
			fwait
		}
		x+=32;
//		x=32+92*sin(time*3.0+0.5);
		asm{
			fld time
			fmul const2
			fadd const3
			fcos
			fmul const7
			fistp y
			fwait
		}
		y-=28;
//		y=-28+58*cos(time*1.0+1.5);
		drawblow(x,y);
		time+=0.02;
		copyvirtualscreen();
	}
	@SETVIDEOMODE(byte 0x3);
	@BIOSREADKEY();
}

void setrgbpalette(char color,r,g,b)
{
	DX=0x3C8;
	outp(color,DX);
	DX++;
	outp(r,DX);
	outp(g,DX);
	outp(b,DX);
}

void setcolortable()
{
	FOR(CL=0;CL<64;CL++)setrgbpalette(CL,0,CL,0);
}

void copyvirtualscreen()
{
	@WAITVSYNC();
	copyfard(0xA000,0,screen,0,16000);
}

void clearvirtualscreen()
{
	ES=screen;
	CX=16000;
	EAX=0;
	DI=0;
	$rep $stosd
}

void initblow()
int x,y;
{
	screen=GETMEM(64000/16);
	blow=GETMEM(65536/16);
	ES=AX;
	FOR(y=-128;y<128;y++){
		AX=y*y;
		DI><AX;
		FOR(x=-128;x<128;x++){
			AX=int x*x+DI+256;
			AX><BX;
			AX=16384/BX;
			IF(AL>63)AL=63;
			ESBYTE[y+128*256+x+128]=AL;
		}
	}
}

void drawblow(int dx,int dy)
int s;
int x=0;
int y=0;
int maxx,maxy;
{
	IF(dx<0)x=-dx;
	IF(dy<0)y=-dy;
	AX=320-dx;
	IF(AX>255)AX=255;
	maxx=AX;
	AX=200-dy;
	IF(AX>255)AX=255;
	maxy=AX;
	ES=screen;
	FS=blow;
	FOR(;y<maxy;y++){
		BX=y+dy<<6;
		CX=BX<<2;
		FOR(DI=x;DI<maxx;DI++){
			s=DI+dx+BX+CX;
			AL=ESBYTE[s]+FSBYTE[y*256+DI];
			IF(AL>63)AL=63;
			ESBYTE[s]=AL;
		}
	}
}
