Пример #1
0
void HariMain(void)
{
	char *buffer, string[12];
	int window, timer, second = 0, minute = 0, hour = 0;
	api_initmalloc();
	buffer = api_malloc(150 * 100);
	window = api_create_window(buffer, 150, 100, -1, "clock");
	timer = api_alloctimer();
	api_inittimer(timer, 128);
	for(;;)
	{
		sprintf(string, "%5d:%02d:%02d", hour, minute, second);
		api_drawrectangle_onwindow(window, 28, 27, 115, 41, 7);
		api_putstring_onwindow(window, 28, 27, 0, 11, string);
		api_settimer(timer, 100);
		if(128 != api_get_fifodata(1))
		{
			break;
		}
		second++;
		if(second == 60)
		{
			second = 0;
			if(minute == 60)
			{
				minute = 0;
				hour++;
			}
		}
	}
	api_end();
}
Пример #2
0
void HariMain(void)
{
	char buf[152 * 100], col;
	int win, timer;
	int bpx = 8, bpy = 26;

	win = api_openwin(buf, 152, 100, -1, "Mt.orz");
	timer = api_alloctimer();
	api_inittimer(timer, 128);

	for (;;) {
		for (col = 8; col < 16; col++) {
			if (col == 8) { col = 0; }	/* OSASKのパレットとは微妙に違うため */
			api_putstrwin(win, 7 * 8 + bpx, 0      + bpy, col,  3, "orz");
			api_putstrwin(win, 5 * 8 + bpx,     16 + bpy, col,  7, "orz orz");
			api_putstrwin(win, 3 * 8 + bpx, 2 * 16 + bpy, col, 11, "orz orz orz");
			api_putstrwin(win,     8 + bpx, 3 * 16 + bpy, col, 15, "orz orz orz orz");
			if (col == 0) { col = 8; }	/* 上と同じ */
			api_settimer(timer, 50);	/* 0.5秒 */
			if (api_getkey(1) != 128) {
				goto end;
			}
		}
	}

end:
	api_closewin(win);
	api_end();
}
Пример #3
0
int main() {
  const int W = 160 + 8 * 2, H = 160 + 20 + 16 + 8 * 2;
  unsigned char* buf = api_malloc(W * H);
  int win = api_openwin(buf, W, H, -1, "clock");
  TIMER* timer = api_alloctimer();
  api_inittimer(timer, 128);
  for (;;) {
    unsigned char now[7];
    api_now(now);
    int year = (now[0] << 8) | now[1];
    int month = now[2];
    int day = now[3];
    int hour = now[4];
    int minute = now[5];
    int second = now[6];

    char s[24];
    snprintf(s, sizeof(s), "%d/%02d/%02d %02d:%02d:%02d", year, month, day, hour, minute, second);
    api_boxfilwin(win | 1, 8, 20 + 8, W - 8, H - 8, COL8_DARK_GRAY);
    draw_poly_circle(win | 1, 160 / 2 + 8, 160 / 2 + 8 + 20, 78, 12, COL8_BLACK);
    draw_clock_line(win | 1, second, 60, 70, COL8_DARK_BLUE);
    draw_clock_line(win | 1, minute * 60 + second, 60 * 60, 60, COL8_GREEN);
    draw_clock_line(win | 1, ((hour % 12) * 60 + minute) * 60 + second, 12 * 60 * 60, 40, COL8_RED);
    api_putstrwin(win | 1, (W - 19 * 8) / 2, H - 8 - 16, COL8_WHITE, 19, s);
    api_refreshwin(win, 8, 20 + 8, W - 8, H - 8);

    api_settimer(timer, 100);
    if (api_getkey(1) == 0x1b)
      break;
  }
  return 0;
}
Пример #4
0
void HariMain(void)
{
  char *buf, s[12];
  int win, timer, sec = 0, min = 0, hou = 0;
  api_initmalloc();
  buf = api_malloc(150 * 50);
  win = api_openwin(buf, 150, 50, -1, "noodle");
  timer = api_alloctimer();
  api_inittimer(timer, 128);
  for (;;) {
	sprintf(s, "%d:%d:%d", hou, min, sec);
	api_boxfilwin (win, 28, 27, 115, 41, 7 /* White */);
	api_putstrwin (win, 28, 27, 0 /* Black */, 11, s);
	api_settimer (timer, 100); /* 1 second */
	if (api_getkey(1) != 128) {
	  break;
	}
	sec++;
	if (sec == 60) {
	  sec = 0;
	  min++;
	  if (min == 60) {
		min = 0;
		hou++;
	  }
	}
  }
  api_end();
}
Пример #5
0
void HariMain()
{
	char buf[496 * 340];
	int i;

	win = api_openwin(buf, 480 + 16, 304 + 36, -1, "kuha");
	api_boxfilwin(win, 6, 26, 480 + 6, 304 + 26, 0);
	timer = api_alloctimer();
	api_inittimer(timer, 128);

reboot:
	api_boxfilwin(win, 6, 26, 25 * 8 + 6, 32 + 26, 0);
	wait(100);

	api_beep(2001000);
	wait(5);
	api_beep(1000500);
	wait(5);
	api_beep(0);
	wait(25);

	putstr("CPU MODE  High", 0, 0, 14);
	wait(10);
	putstr("MEMORY 128KB OK", 0, 1, 15);
	wait(15);
	putstr("256", 7, 1, 3);
	wait(15);
	putstr("384", 7, 1, 3);
	wait(15);
	putstr("512", 7, 1, 3);
	wait(15);
	putstr("640", 7, 1, 3);
	wait(15);

	putstr( "+     KB OK", 13, 1, 14);

	for (i = 1; i <= 40; i++) {
		char s[5];
		int j = 3, ic = i * 128;

		do {
			s[j--] = (ic % 10) + '0';
			if ((ic /= 10) == 0)
				break;
		} while (j >= 0);
		while (j >= 0)
			s[j--] = ' ';

		putstr(s, 15, 1, 4);
		wait(75 / 10);
	}
	wait(200);

	goto reboot;
}
Пример #6
0
void HariMain(void)
{
    int i, timer;
    timer = api_alloctimer();
    api_inittimer(timer, 128);
    for (i = 20000000; i >= 20000; i -= i / 100) {

	api_beep(i);
	api_settimer(timer, 1);
	if (api_getkey(1) != 128) {
	   break;
	}
    }
    api_beep(0);
    api_end();
}
Пример #7
0
void HariMain(void)
{
	int i, timer;
	timer = api_alloctimer();
	api_inittimer(timer, 128);
	for(i = 20000000; i >= 20000; i-= i / 100)
	{
		/*20KHz~20Hz是人类可以听到的范围*/
		api_beep(i);		//让蜂鸣器以iHz的频率进行发声
		if(128 != api_get_fifodata(1))		//接收用户任何键盘输入都会关闭程序
		{
			break;
		}
	}
	api_beep(0);			//关闭蜂鸣器
	api_end();
}
Пример #8
0
void HariMain(void)
{
	int i, timer;
	timer = api_alloctimer();
	api_inittimer(timer, 128);
	for (i = 20000000; i >= 20000; i -= i / 100) {
		/* 20KHz~20Hz ,即人类可以听到的声音范围 */
		/* i以1%的速度递减 */
		api_beep(i);
		api_settimer(timer, 1);		/* 0.01秒 */
		if (api_getkey(1) != 128) {
			break;
		}
	}
	api_beep(0);
	api_end();
}
Пример #9
0
void HariMain(void)
{
    int i, timer;
    timer = api_alloctimer();
    api_inittimer(timer, 128);
    for (i = 20000000; i >= 20000; i -= i / 100) {
        /* 20KHz〜20Hz : 人間に聞こえる音の範囲 */
        /* iは1%ずつ減らされていく */
        api_beep(i);
        api_settimer(timer, 1);     /* 0.01秒 */
        if (api_getkey(1) != 128) {
            break;
        }
    }
    api_beep(0);
    api_end();
}
Пример #10
0
void HariMain(void)
{
	char buf[416 * 52 * osak_getbuflen()], s[2];
	int win, timer, i, curc = 0, curx = 8;
	win = api_openwin(buf, 416, 50, -1, "1Line");
	timer = api_alloctimer();
	api_inittimer(timer, 128);
	make_textbox(win, 8, 28, 400, 16);
	s[1] = '\0';
	api_settimer(timer, 50);	/* 0.5•b */
	for (;;) {
		i = api_getkey(1);
		if (i == 128) {
			if (curc == 0) {
				/* On */
				curc = 7;
			} else {
				/* Off */
				curc = 0;
			}
			api_boxfilwin(win, curx, 43, 7 + curx, 43, curc);
			api_settimer(timer, 50);	/* 0.5•b */
		}
		if (i == 0x08) {
			/* BackSpace */
			if (8 < curx) {
				api_boxfilwin(win, curx - 8, 28, curx + 7, 43, 7);
				curx -= 8;
				api_boxfilwin(win, curx, 43, 7 + curx, 43, curc);
			}
		}
		if (0x20 <= i && i <= 'z') {
			if (curx < 400) {
				api_boxfilwin(win, curx, 28 + 15, 7 + curx, 28 + 15,  7);
				s[0] = i;
				api_putstrwin(win, curx, 28, 0, 1, s);
				curx += 8;
				api_boxfilwin(win, curx, 28 + 15, 7 + curx, 28 + 15,  curc);
			}
		}
	}
	api_closewin(win);
	api_end();
}
Пример #11
0
void HariMain(void)
{
	char winbuf[256 * 112], txtbuf[100 * 1024];
	char s[32], *p, *r;
	int win, timer, i, j, t = 120, l = 192 / 4, o = 4, q = 7, note_old = 0;

	/* 音番号と周波数(mHz)の対応表 */
	/* たとえば、O4Aは440Hzなので、440000 */
	/* オクターブ16のAは1802240Hzなので、1802240000 */
	/* 以下はオクターブ16のリスト(C〜B) */
	static int tonetable[12] = {
		1071618315, 1135340056, 1202850889, 1274376125, 1350154473, 1430438836,
		1515497155, 1605613306, 1701088041, 1802240000, 1909406767, 2022946002
	};
	static int notetable[7] = { +9, +11, +0 /* C */, +2, +4, +5, +7 };

	/* コマンドライン解析 */
	api_cmdline(s, 30);
	for (p = s; *p > ' '; p++) { }	/* スペースが来るまで読み飛ばす */
	for (; *p == ' '; p++) { }	/* スペースを読み飛ばす */
	i = strlen(p);
	if (i > 12) {
file_error:
		end("file open error.\n");
	}
	if (i == 0) {
		end(0);
	}

	/* ウィンドウの準備 */
	win = api_openwin(winbuf, 256, 112, -1, "mmlplay");
	api_putstrwin(win, 128, 32, 0, i, p);
	api_boxfilwin(win, 8, 60, 247,  76, 7);
	api_boxfilwin(win, 6, 86, 249, 105, 7);

	/* ファイル読み込み */
	i = api_fopen(p);
	if (i == 0) {
		goto file_error;
	}
	j = api_fsize(i, 0);
	if (j >= 100 * 1024) {
		j = 100 * 1024 - 1;
	}
	api_fread(txtbuf, j, i);
	api_fclose(i);
	txtbuf[j] = 0;
	r = txtbuf;
	i = 0; /* 通常モード */
	for (p = txtbuf; *p != 0; p++) {	/* 処理を簡単にするためにコメントや空白を消す */
		if (i == 0 && *p > ' ') {	/* スペースや改行コードなどではない */
			if (*p == '/') {
				if (p[1] == '*') {
					i = 1;
				} else if (p[1] == '/') {
					i = 2;
				} else {
					*r = *p;
					if ('a' <= *p && *p <= 'z') {
						*r += 'A' - 'a';	/* 小文字は大文字に変換 */
					}
					r++;
				}
			} else if (*p == 0x22) {
				*r = *p;
				r++;
				i = 3;
			} else {
				*r = *p;
				r++;
			}
		} else if (i == 1 && *p == '*' && p[1] == '/') {	/* ブロックコメント */
			p++;
			i = 0;
		} else if (i == 2 && *p == 0x0a) {	/* 行コメント */
			i = 0;
		} else if (i == 3) {	/* 文字列 */
			*r = *p;
			r++;
			if (*p == 0x22) {
				i = 0;
			} else if (*p == '%') {
				p++;
				*r = *p;
				r++;
			}
		}
	}
	*r = 0;

	/* タイマの準備 */
	timer = api_alloctimer();
	api_inittimer(timer, 128);

	/* メイン */
	p = txtbuf;
	for (;;) {
		if (('A' <= *p && *p <= 'G') || *p == 'R') {	/* 音符・休符 */
			/* 周波数計算 */
			if (*p == 'R') {
				i = 0;
				s[0] = 0;
			} else {
				i = o * 12 + notetable[*p - 'A'] + 12;
				s[0] = 'O';
				s[1] = '0' + o;
				s[2] = *p;
				s[3] = ' ';
				s[4] = 0;
			}
			p++;
			if (*p == '+' || *p == '-' || *p == '#') {
				s[3] = *p;
				if (*p == '-') {
					i--;
				} else {
					i++;
				}
				p++;
			}
			if (i != note_old) {
				api_boxfilwin(win + 1, 32, 36, 63, 51, 8);
				if (s[0] != 0) {
					api_putstrwin(win + 1, 32, 36, 10, 4, s);
				}
				api_refreshwin(win, 32, 36, 64, 52);
				if (28 <= note_old && note_old <= 107) {
					api_boxfilwin(win, (note_old - 28) * 3 + 8, 60, (note_old - 28) * 3 + 10,  76, 7);
				}
				if (28 <= i && i <= 107) {
					api_boxfilwin(win, (i - 28) * 3 + 8, 60, (i - 28) * 3 + 10,  76, 4);
				}
				if (s[0] != 0) {
					api_beep(tonetable[i % 12] >> (17 - i / 12));
				} else {
					api_beep(0);
				}
				note_old = i;
			}
Пример #12
0
void HariMain(void)
{
	int win, timer, i, j, fx, laserwait, lx = 0, ly; //laserwait: time to wait before loaded again
	int ix, iy, movewait0, movewait, idir;//movewait ==0, invaders move one step further
	int invline, score, high, point;//invline: lines of invaders, point: unit value for killing one invader
	char winbuf[336 * 261], invstr[32 * 6], s[12], keyflag[4], *p;
	static char invstr0[32] = " abcd abcd abcd abcd abcd ";

	win = api_openwin(winbuf, 336, 261, -1, "invader");
	api_boxfilwin(win, 6, 27, 329, 254, 0);
	timer = api_alloctimer();
	api_inittimer(timer, 128);

	high = 0;
	putstr(win, winbuf, 22, 0, 6, "HIGH:00000000");

restart:
	score = 0;
	point = 1;
	putstr(win, winbuf,  4, 0, 7, "SCORE:00000000");
	movewait0 = 20;
	fx = 18;
	putstr(win, winbuf, fx, 13, 6, "efg"); //paint fighter
	wait(100, timer, keyflag);

next_group:
	wait(100, timer, keyflag);
	ix = 7;
	iy = 1;
	invline = 6;
	for (i = 0; i < 6; i++) {
		for (j = 0; j < 27; j++) {
			invstr[i * 32 + j] = invstr0[j];
		}
		putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32); //paint invaders line bye line
	}
	keyflag[0] = 0;
	keyflag[1] = 0;
	keyflag[2] = 0;

	ly = 0; /* not shown */
	laserwait = 0;
	movewait = movewait0;
	idir = +1;
	wait(100, timer, keyflag);

	for (;;) {
		if (laserwait != 0) {
			laserwait--;
			keyflag[2 /* space */] = 0;
		}

		wait(4, timer, keyflag);

		/* handling fighter */
		if (keyflag[0 /* left */]  != 0 && fx > 0) {
			fx--;
			putstr(win, winbuf, fx, 13, 6, "efg ");
			keyflag[0 /* left */]  = 0;
		}
		if (keyflag[1 /* right */] != 0 && fx < 37) {
			putstr(win, winbuf, fx, 13, 6, " efg");
			fx++;
			keyflag[1 /* right */] = 0;
		}
		if (keyflag[2 /* space */] != 0 && laserwait == 0) {
			laserwait = 15;
			lx = fx + 1;
			ly = 13;
		}

		/* invaders movement */
		if (movewait != 0) {
			movewait--;
		} else {
			movewait = movewait0;
			if (ix + idir > 14 || ix + idir < 0) {
				if (iy + invline == 13) {
					break; /* GAME OVER */
				}
				idir = - idir;
				putstr(win, winbuf, ix + 1, iy, 0, "                         ");//remove the first row
				iy++;
			} else {
				ix += idir;
			}
			for (i = 0; i < invline; i++) {
				putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32);//paint again
			}
		}

		/* handling laser */
		if (ly > 0) {
			if (ly < 13) {
				if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) {
					putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32);
				} else {
					putstr(win, winbuf, lx, ly, 0, " ");
				}
			}
			ly--;
			if (ly > 0) {
				putstr(win, winbuf, lx, ly, 3, "h");
			} else {
				point -= 10;
				if (point <= 0) {
					point = 1;
				}
			}
			if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) {
				p = invstr + (ly - iy) * 32 + (lx - ix);
				if (*p != ' ') {
					/* hit ! */
					score += point;
					point++;
					sprintf(s, "%08d", score);
					putstr(win, winbuf, 10, 0, 7, s);
					if (high < score) {
						high = score;
						putstr(win, winbuf, 27, 0, 7, s);
					}
					for (p--; *p != ' '; p--) { }
					for (i = 1; i < 5; i++) {	//remove hit invader
						p[i] = ' ';
					}
					putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32);
					for (; invline > 0; invline--) {
						for (p = invstr + (invline - 1) * 32; *p != 0; p++) {
							if (*p != ' ') {
								goto alive;
							}
						}
					}
					/* all invaders killed */
					movewait0 -= movewait0 / 3;
					goto next_group;
	alive:
					ly = 0;
				}
			}
		}
	}

	/* GAME OVER */
	putstr(win, winbuf, 15, 6, 1, "GAME OVER");
	wait(0, timer, keyflag);
	for (i = 1; i < 14; i++) {
		putstr(win, winbuf, 0, i, 0, "                                        ");
	}
	goto restart;
}
Пример #13
0
void HariMain(void)
{
	char winbuf[256 * 112], txtbuf[100 * 1024];
	char s[32], *p, *r;
	int win, timer, i, j, t = 120, l = 192 / 4, o = 4, q = 7, note_old = 0;

	/*音号与频率(mHz)的对照表*/
	/*例如,04A为440Hz,即440000 */
	/*第16八度的A为1802240Hz,即1802240000 */
	/*以下为第16八度的列表(C~B) */
	static int tonetable[12] = {
		1071618315, 1135340056, 1202850889, 1274376125, 1350154473, 1430438836,
		1515497155, 1605613306, 1701088041, 1802240000, 1909406767, 2022946002
	};
	static int notetable[7] = { +9, +11, +0 /* C */, +2, +4, +5, +7 };

	/*命令行解析*/
	api_cmdline(s, 30);
	for (p = s; *p > ' '; p++) { }	/*一直读到空格为止*/
	for (; *p == ' '; p++) { }	/*跳过空格*/
	i = strlen(p);
	if (i > 12) {
file_error:
		end("file open error.\n");
	}
	if (i == 0) {
		end(0);
	}

	/*准备窗口*/
	win = api_openwin(winbuf, 256, 112, -1, "mmlplay");
	api_putstrwin(win, 128, 32, 0, i, p);
	api_boxfilwin(win, 8, 60, 247,  76, 7);
	api_boxfilwin(win, 6, 86, 249, 105, 7);

	/*载入文件*/
	i = api_fopen(p);
	if (i == 0) {
		goto file_error;
	}
	j = api_fsize(i, 0);
	if (j >= 100 * 1024) {
		j = 100 * 1024 - 1;
	}
	api_fread(txtbuf, j, i);
	api_fclose(i);
	txtbuf[j] = 0;
	r = txtbuf;
	i = 0; /*通常模式*/
	for (p = txtbuf; *p != 0; p++) {	/*为了方便处理,将注释和空白删去*/
		if (i == 0 && *p > ' ') {	/*不是空格或换行符*/
			if (*p == '/') {
				if (p[1] == '*') {
					i = 1;
				} else if (p[1] == '/') {
					i = 2;
				} else {
					*r = *p;
					if ('a' <= *p && *p <= 'z') {
						*r += 'A' - 'a';	/*将小写字母转换为大写字母*/
					}
					r++;
				}
			} else if (*p == 0x22) {
				*r = *p;
				r++;
				i = 3;
			} else {
				*r = *p;
				r++;
			}
		} else if (i == 1 && *p == '*' && p[1] == '/') {	/*段注释*/
			p++;
			i = 0;
		} else if (i == 2 && *p == 0x0a) {	/*行注释*/
			i = 0;
		} else if (i == 3) {	/*字符串*/
			*r = *p;
			r++;
			if (*p == 0x22) {
				i = 0;
			} else if (*p == '%') {
				p++;
				*r = *p;
				r++;
			}
		}
	}
	*r = 0;

	/*定时器准备*/
	timer = api_alloctimer();
	api_inittimer(timer, 128);

	/*主体*/
	p = txtbuf;
	for (;;) {
		if (('A' <= *p && *p <= 'G') || *p == 'R') {	/*音符、休止符*/
			/*计算频率*/
			if (*p == 'R') {
				i = 0;
				s[0] = 0;
			} else {
				i = o * 12 + notetable[*p - 'A'] + 12;
				s[0] = 'O';
				s[1] = '0' + o;
				s[2] = *p;
				s[3] = ' ';
				s[4] = 0;
			}
			p++;
			if (*p == '+' || *p == '-' || *p == '#') {
				s[3] = *p;
				if (*p == '-') {
					i--;
				} else {
					i++;
				}
				p++;
			}
			if (i != note_old) {
				api_boxfilwin(win + 1, 32, 36, 63, 51, 8);
				if (s[0] != 0) {
					api_putstrwin(win + 1, 32, 36, 10, 4, s);
				}
				api_refreshwin(win, 32, 36, 64, 52);
				if (28 <= note_old && note_old <= 107) {
					api_boxfilwin(win, (note_old - 28) * 3 + 8, 60, (note_old - 28) * 3 + 10,  76, 7);
				}
				if (28 <= i && i <= 107) {
					api_boxfilwin(win, (i - 28) * 3 + 8, 60, (i - 28) * 3 + 10,  76, 4);
				}
				if (s[0] != 0) {
					api_beep(tonetable[i % 12] >> (17 - i / 12));
				} else {
					api_beep(0);
				}
				note_old = i;
			}
Пример #14
0
void HariMain(void)
{


	char *buf;
	int win, i, x, y, timer;
	api_initmalloc();
	buf = api_malloc(200 * 200);
	char* title;
	char keyflag[4];
	char *last_direction;
	*last_direction = '4';


	//snake
	struct snakeNode *head = api_malloc(sizeof(struct snakeNode));
	head->preNode = NULL;
	head->posX = 75;
	head->posY = 55;
	head->moveDirection = 4;

	struct snakeNode *tail = head;
	//snake

	//food
	struct Food food;
	food.posX = 69;
	food.posY = 61;
	food.isEaten = 1;// not eaten;
	//food



	sprintf(title, "posX: %d, posY: %d, mp: %d", tail->posX, tail->posY, tail->moveDirection);
	//sprintf(title, "Hungry Snake");
	win = api_openwin(buf, 200, 200, -1, title);
	timer = api_alloctimer();

	api_inittimer(timer, 128);

	api_boxfilwin(win, 5, 25, 195, 195, 0);
	x = 75;
	y = 55;
	tail->posX = 75;
	tail->posY = 55;
	api_putstrwin(win, tail->posX, tail->posY, 3, 1, "*");
	//scrnRefresher(win, tail, 3, "*");





	for (;;) {

		i = *last_direction;
		scrnRefresher(win, tail, 0, "*");
		// updateSnake(head);
		updateSnake(tail);
		scrnRefresher(win, tail, 3, "*");

		//add food here
		foodInit(&food, win, 4, "+");
		//add food here


		/*detecting*/
		detecting(head, &tail, &food);



		delay();
		//if (snakeLength < 10) {tail = addSegment(tail, &snakeLength);}

		wait(1, timer, keyflag, last_direction, head);
	}




	api_closewin(win);
	api_end();
}
Пример #15
0
void HariMain(void)
{
	int win, timer, i, j, fx, laserwait, lx = 0, ly;
	int ix, iy, movewait0, movewait, idir;
	int invline, score, high, point;
	char winbuf[336 * 261 * osak_getbuflen()], invstr[32 * 6], s[12], keyflag[4], *p;
	static char invstr0[32] = " abcd abcd abcd abcd abcd ";

	win = api_openwin(winbuf, 336, 261, -1, "invader");
	api_boxfilwin(win, 6, 27, 329, 254, 0);
	timer = api_alloctimer();
	api_inittimer(timer, 128);

	high = 0;
	putstr(win, winbuf, 22, 0, 7, "HIGH:00000000");

restart:
	score = 0;
	point = 1;
	putstr(win, winbuf,  4, 0, 7, "SCORE:00000000");
	movewait0 = 20;
	fx = 18;
	putstr(win, winbuf, fx, 13, 6, "efg");
	wait(100, timer, keyflag);

next_group:
	wait(100, timer, keyflag);
	ix = 7;
	iy = 1;
	invline = 6;
	for (i = 0; i < 6; i++) {
		for (j = 0; j < 27; j++) {
			invstr[i * 32 + j] = invstr0[j];
		}
		putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32);
	}
	keyflag[0] = 0;
	keyflag[1] = 0;
	keyflag[2] = 0;

	ly = 0; /* 非表示 */
	laserwait = 0;
	movewait = movewait0;
	idir = +1;
	wait(100, timer, keyflag);

	for (;;) {
		if (laserwait != 0) {
			laserwait--;
			keyflag[2 /* space */] = 0;
		}

		wait(4, timer, keyflag);

		/* 自機の処理 */
		if (keyflag[0 /* left */]  != 0 && fx > 0) {
			fx--;
			putstr(win, winbuf, fx, 13, 6, "efg ");
			keyflag[0 /* left */]  = 0;
		}
		if (keyflag[1 /* right */] != 0 && fx < 37) {
			putstr(win, winbuf, fx, 13, 6, " efg");
			fx++;
			keyflag[1 /* right */] = 0;
		}
		if (keyflag[2 /* space */] != 0 && laserwait == 0) {
			laserwait = 15;
			lx = fx + 1;
			ly = 13;
		}

		/* インベーダ移動 */
		if (movewait != 0) {
			movewait--;
		} else {
			movewait = movewait0;
			if (ix + idir > 14 || ix + idir < 0) {
				if (iy + invline == 13) {
					break; /* GAME OVER */
				}
				idir = - idir;
				putstr(win, winbuf, ix + 1, iy, 0, "                         ");
				iy++;
			} else {
				ix += idir;
			}
			for (i = 0; i < invline; i++) {
				putstr(win, winbuf, ix, iy + i, 2, invstr + i * 32);
			}
		}

		/* レーザー処理 */
		if (ly > 0) {
			if (ly < 13) {
				if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) {
					putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32);
				} else {
					putstr(win, winbuf, lx, ly, 0, " ");
				}
			}
			ly--;
			if (ly > 0) {
				putstr(win, winbuf, lx, ly, 3, "h");
			} else {
				point -= 10;
				if (point <= 0) {
					point = 1;
				}
			}
			if (ix < lx && lx < ix + 25 && iy <= ly && ly < iy + invline) {
				p = invstr + (ly - iy) * 32 + (lx - ix);
				if (*p != ' ') {
					/* hit ! */
					score += point;
					point++;
				//	sprintf(s, "%08d", score);
					setdec8(s, score);
					putstr(win, winbuf, 10, 0, 7, s);
					if (high < score) {
						high = score;
						putstr(win, winbuf, 27, 0, 7, s);
					}
					for (p--; *p != ' '; p--) { }
					for (i = 1; i < 5; i++) {
						p[i] = ' ';
					}
					putstr(win, winbuf, ix, ly, 2, invstr + (ly - iy) * 32);
					for (; invline > 0; invline--) {
						for (p = invstr + (invline - 1) * 32; *p != 0; p++) {
							if (*p != ' ') {
								goto alive;
							}
						}
					}
					/* 全部やっつけられた */
					movewait0 -= movewait0 / 3;
					goto next_group;
	alive:
					ly = 0;
				}
			}
		}
	}

	/* GAME OVER */
	putstr(win, winbuf, 15, 6, 1, "GAME OVER");
	wait(0, timer, keyflag);
	for (i = 1; i < 14; i++) {
		putstr(win, winbuf, 0, i, 0, "                                        ");
	}
	goto restart;
}