#resize TRUE
#jumptomain SHORT

#define SCREENSIZE 64000
#define MEMBLOCKSIZE SCREENSIZE/16

#include "RANDOM.H--"

word screen;

void setrgbpalette(char color,r,g,b);

main()
{
	@RANDOMIZE();
	@SETVIDEOMODE(byte 0x13);
	setcolortable();
	screen=GETMEM(MEMBLOCKSIZE);
	CLEARBLOCK();
	fillscreen();
	WHILE(!@KBHIT()){
		lavascreen();
		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(CX=0;CX<=255;CX++)setrgbpalette(CL,63,CL/4,0);
}

void fillscreen()
int i;
{
	ES=screen;
	DI=321;
	FOR(i=1;i<199;i++){
		FOR(SI=1;SI<319;SI++){
			@RAND();
			$stosb
		}
		DI++;
		DI++;
	}
}

void lavascreen()
{
	ES=screen;
	DI=321;
	FOR(SI=1;SI<199;SI++){
		FOR(BX=1;BX<319;BX++){
			AX=ESBYTE[DI-320]+ESBYTE[DI-1]+ESBYTE[DI+1]+ESBYTE[DI+320]>>2+2;
			$stosb
		}
		DI++;
		DI++;
	}
}

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

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

