#include "clip.h"

#define HES_FNAME	"C:\\Documents and Settings\\Administrator\\ƒfƒXƒNƒgƒbƒv\\hes\\Aero Blasters.hes"

HESDRIVER hes;
unsigned char hes_data[1024 * 1024];
int hes_size;
short wbuff[HESBUFLEN];

void
init()
{
	int retval;
	FILE* fp;

	fp = fopen(HES_FNAME, "rb");
	if(!fp) DIE();
	hes_size = fread(hes_data, 1, sizeof hes_data, fp);
	fclose(fp);

	retval = hes_init(&hes, hes_data, hes_size, 0x30);
	if(retval != 0) DIE();

//	fp = fopen("dump.bin", "wb");
//	fwrite(&hes.mem[0xe000], 1, 0x2000, fp);
//	fclose(fp);
}

int
main(int argc, char* argv[])
{
	HUC6280* huc6280 = &hes.huc6280;
	unsigned char* mem = hes.mem;

	init();

//	for(;;) {
//		hes_mix(&hes, wbuff);
//	}

#define INTERVAL	(HES_CPU_CLOCK / 60)
	for(;;) {
static double SUM;
static double N;
		huc6280_run(huc6280, INTERVAL);
//		mem[0x1403] |= 7;
		huc6280_irq1(huc6280);
SUM += INTERVAL - huc6280->cycle;
N++;
printf("%f\n", 100.0 * SUM / N / INTERVAL);
//printf("%d\n", NTSC_COLOR_SUBCARRIER / 512 / mem[0xc00]);
	}

	return 0;
}

