#include <stdio.h>
#include "apilib.h"

void HariMain(void)
{
	int *buf, s[32], s2[32];
	int win, count = 0;
	int timer;
	int sec = 0, min = 0;
	api_initmalloc();
	buf = api_malloc(170 * 80 * 4);
	win = api_openwin(buf, 170, 80, -1, "ベンチMark v0.0");
	timer = api_alloctimer();
	api_inittimer(timer, 128);
	api_settimer(timer, 100);/* 0.1秒間 */
	for (;;) {
		sprintf(s, "%014d", count);
		api_boxfilwin(win + 1, 22, 27, 145, 41, api_getint(7) /* 白 */);
		api_putstrwin(win + 1, 28, 27, api_getint(0) /* 黒 */, 32, s);
		if (count == 1000000) { break; }
		count++;
		sprintf(s2, "%02d:%02d", min, sec);
		api_boxfilwin(win + 1, 22, 56, 145, 70, api_getint(7) /* 白 */);
		api_putstrwin(win + 1, 28, 56, api_getint(0) /* 黒 */, 32, s2);
		if(api_getkey(0) == 128)
		{
			sec++;
			if (sec == 60) {
				sec = 0;
				min++;
			}
			api_settimer(timer, 100);	/* 0.01秒間 */
		}
		api_refreshwin(win, 0, 0, 170, 80);
	}
	api_refreshwin(win, 0, 0, 170, 80);
	for(;;) {
		if (api_getkey(1) == 0x0a) { break; }
	}
	api_end();
}
