#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <msdos.cf>

#include <snd.h>
#include <egb.h>

#include <..\concorde.h>

#define XBUF 16
#define SRAND 79154726  /* wДԍ(^_^;) */
#define TIMES 2000

int vx1=10;
int vy1=10;
int vx2=309;
int vy2=229;

char EGB_work[EgbWorkSize];

struct {
	char *dat;
	short seg;
	short x1,y1,x2,y2;
} para;



char dat[]=
{
	0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,
	0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,
	0x00,0x00,0x00,0x07,0xc0,0x00,0x00,0x00,
	0x00,0x00,0x01,0xff,0xff,0x00,0x00,0x00,
	0x00,0x00,0x00,0xff,0xfe,0x00,0x00,0x00,
	0x00,0x00,0x00,0x3f,0xf8,0x00,0x00,0x00,
	0x00,0x00,0x00,0x1f,0xf0,0x00,0x00,0x00,
	0x00,0x00,0x00,0x0f,0xe0,0x00,0x00,0x00,
	0x00,0x00,0x00,0x1e,0xf0,0x00,0x00,0x00,
	0x00,0x00,0x00,0x1c,0x70,0x00,0x00,0x00,
	0xff,0xff,0xf8,0x38,0x38,0x3f,0xff,0xff,
	0x80,0x60,0x0e,0x70,0x1c,0xe0,0x0c,0x01,
	0x80,0x60,0x0b,0xff,0xff,0xa0,0x0c,0x01,
	0x40,0x30,0x08,0x00,0x00,0x20,0x18,0x02,
	0x3f,0xdc,0x0a,0x27,0x11,0x20,0x77,0xfc,
	0x10,0x0f,0xfa,0x28,0xb3,0x3f,0xe0,0x08,
	0x10,0x03,0xf9,0x48,0x11,0x3f,0x80,0x08,
	0x08,0x00,0x09,0x48,0x11,0x20,0x00,0x10,
	0x07,0xff,0xf8,0x87,0x11,0x3f,0xff,0xe0,
	0x02,0x00,0x08,0x80,0x91,0x20,0x00,0x40,
	0x02,0x00,0x08,0x80,0x91,0x20,0x00,0x40,
	0x01,0x00,0x08,0x88,0x91,0x20,0x00,0x80,
	0x00,0xff,0xf8,0x87,0x3b,0xbf,0xff,0x00,
	0x00,0x00,0x08,0x00,0x00,0x20,0x00,0x00,
	0x00,0x00,0x07,0xff,0xff,0xc0,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
	0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};


void frame()
{
	short para[64];

	EGB_clearScreen(EGB_work);
	EGB_paintMode(EGB_work,0x22);

	EGB_color(EGB_work,0,32767);
	EGB_color(EGB_work,2,32767);
	para[0]=0;
	para[1]=0;
	para[2]=319;
	para[3]=239;
	EGB_viewport(EGB_work,(char *)para);
	EGB_rectangle(EGB_work,(char *)para);

	EGB_color(EGB_work,0,0);
	EGB_color(EGB_work,2,0);
	para[0]=vx1;
	para[1]=vy1;
	para[2]=vx2;
	para[3]=vy2;
	EGB_rectangle(EGB_work,(char *)para);
	EGB_viewport(EGB_work,(char *)para);
}



void main()
{
	int x,y,ms,j;
	PAGE p;


	EGB_init(EGB_work,EgbWorkSize);
	EGB_resolution(EGB_work,0,10);
	EGB_resolution(EGB_work,1,10);

	EGB_writePage(EGB_work,0);
	EGB_displayStart(EGB_work,0,0,0);
	EGB_displayStart(EGB_work,2,2,2);
	EGB_displayStart(EGB_work,3,320,240);
	EGB_clearScreen(EGB_work);

	EGB_writePage(EGB_work,1);
	EGB_displayStart(EGB_work,0,0,0);
	EGB_displayStart(EGB_work,2,2,2);
	EGB_displayStart(EGB_work,3,320,240);
	EGB_clearScreen(EGB_work);

	EGB_displayPage(EGB_work,1,2);

	YGH_initPage(&p,SEG_VRAMP,0x40000,512,256);
	YGH_viewPort(&p,vx1,vy1,vx2,vy2);


	srand(SRAND);

	frame();

	EGB_paintMode(EGB_work,0x02);
	EGB_writeMode(EGB_work,6);
	para.dat=dat;
	para.seg=getds();

	ms=clock();
	for(j=0; j<TIMES; j++)
	{
		EGB_color(EGB_work,0,rand()%32768);
		para.x1=rand()%256;
		para.y1=rand()%208;
		para.x2=para.x1+63;
		para.y2=para.y1+31;
		EGB_putBlockColor(EGB_work,1,(char *)&para);
	}
	ms=(clock()-ms)*1000/CLOCKS_PER_SEC;

	printf("EGB\n");
	printf("%d ms as %d patterns.\n",ms,TIMES);
	printf("%d ms as a pattern.\n",ms/TIMES);
	printf("%d clocks as a pattern.\n",16000*ms/TIMES);



	srand(SRAND);

	frame();

	ms=clock();
	for(j=0; j<TIMES; j++)
	{
		YGH_color(&p,rand()%32768);
		x=rand()%256;
		y=rand()%208;
		YGH_putMono(&p,dat,x,y,x+63,y+31);
	}
	ms=(clock()-ms)*1000/CLOCKS_PER_SEC;

	printf("YGHIGH\n");
	printf("%d ms as %d patterns.\n",ms,TIMES);
	printf("%d ms as a pattern.\n",ms/TIMES);
	printf("%d clocks as a pattern.\n",16000*ms/TIMES);
}
