Ejemplo n.º 1
0
void HariMain(void)
{
	char buf[214 * 82 * osak_getbuflen()], s[2];
	int win, col;

	win = api_openwin(buf, 25 * 8 + 14, 3 * 16 + 34, -1, "LuckyNum");
	api_boxfilwin(win, BPX, BPY, 25 * 8 + BPX, 3 * 16 + BPY, 0);

	api_putstrwin(win, BPX,      BPY, 6, 12, "LuckyNumber=");
	api_putstrwin(win, BPX, 16 + BPY, 6, 12, "LuckyColor =");
	api_putstrwin(win, BPX, 32 + BPY, 3, 17, "Good Luck!(^o^)/~");

	srand(tomo_gettick()); /* seedを与える */

	s[0] = '0' + rand() % 10;
	s[1] = '\0';
	api_putstrwin(win, 13 * 8 + BPX, BPY, 6, 1, s);

	col = rand() % 9;	/* Hariboteは明るい色が前に集まっているので変なループはいらない */

	api_boxfilwin(win, 13 * 8 + BPX, 16 + BPY, 14 * 8 + BPX - 1, 32 + BPY - 1, col);

	while (api_getkey(1) != 0x0a);

	api_closewin(win);
	api_end();
}
Ejemplo n.º 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();
}
Ejemplo n.º 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;
}
Ejemplo n.º 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();
}
Ejemplo n.º 5
0
void HariMain(void)
{
	int win, i, j, dis;
	char buf[216 * 237];
	struct POINT {
		int x, y;
	};
	static struct POINT table[16] = {
		{ 204, 129 }, { 195,  90 }, { 172,  58 }, { 137,  38 }, {  98,  34 },
		{  61,  46 }, {  31,  73 }, {  15, 110 }, {  15, 148 }, {  31, 185 },
		{  61, 212 }, {  98, 224 }, { 137, 220 }, { 172, 200 }, { 195, 168 },
		{ 204, 129 }
	};

	win = api_openwin(buf, 216, 237, -1, "bball");
	api_boxfilwin(win, 8, 29, 207, 228, 0);
	for (i = 0; i <= 14; i++) {
		for (j = i + 1; j <= 15; j++) {
			dis = j - i; /*两点间的距离*/
			if (dis >= 8) {
				dis = 15 - dis; /*逆向计数*/
			}
			if (dis != 0) {
				api_linewin(win, table[i].x, table[i].y, table[j].x, table[j].y, 8 - dis);
			}
		}
	}

	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; /*按下回车键则break; */
		}
	}
	api_end();
}
Ejemplo n.º 6
0
void HariMain(){
    char *buf;
    int win;
    api_initmalloc();
    buf = api_malloc(150 * 100);
	win = api_openwin(buf, 150, 100, -1, "timer");
    api_end();
}
Ejemplo n.º 7
0
void HariMain(void)
{
    int win;
    win = api_openwin(buf, 150, 50, -1, "hello");
	api_boxfilwin(win,  8, 36, 141, 43, 3);
	api_putstrwin(win, 28, 28, 0, 12, "hello, world");
    api_end();
}
Ejemplo n.º 8
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;
}
Ejemplo n.º 9
0
void HariMain(void)
{
    char *buf;
    int win;
    api_initmalloc();
    buf = api_malloc(150 * 100);
    win = api_openwin(buf, 150, 100, -1, "star1");
    api_boxfilwin(win,  6, 26, 143, 93, 0 /* 黒 */);
    api_point(win, 75, 59, 3 /* 黄 */);
    api_end();
}
Ejemplo n.º 10
0
void HariMain(void)
{
	char *buf;
	int win;

	api_initmalloc();
	buf = api_malloc(150 * 50);
	win = api_openwin(buf, 150, 50, -1, "hello");
	api_boxfilwin(win,  8, 36, 141, 43, 6 /* ���F */);
	api_putstrwin(win, 28, 28, 0 /* �� */, 12, "hello, world");
	api_end();
}
Ejemplo n.º 11
0
void HariMain(void)
{
	int win;
	char buf[150 * 50];

	win = api_openwin(buf, 150, 50, -1, "hello");
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; /*按下回车键则break; */
		}
	}
	api_end();
}
Ejemplo n.º 12
0
void HariMain(void)
{
	int win;
	win = api_openwin(buf, 150, 50, -1, "hello");
	api_boxfilwin(win,  8, 36, 141, 43, 3 /* �� */);
	api_putstrwin(win, 28, 28, 0 /* �� */, 12, "hello, world");
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; /* Enter�Ȃ�break; */
		}
	}
	api_end();
}
Ejemplo n.º 13
0
void HariMain (void)
{
  api_initmalloc ();
  char *buf = api_malloc (144 * 164);
  int win = api_openwin (buf, 144, 164, -1, "color");
  for (int y = 0; y < 128; y++) {
	for (int x = 0; x < 128; x++) {
	  buf [(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y);
	}
  }
  api_refreshwin (win, 8,28, 136, 156);
  api_getkey (1);
  api_end();
}
Ejemplo n.º 14
0
void HariMain()
{
	int win, xsize = 400, ysize = 200;
	char win_buf[xsize * ysize];
	api_initmalloc();
	
	struct MOUSE_INFO *minfo;
	minfo = api_malloc(sizeof(struct MOUSE_INFO));
	minfo->flag = -589;
	int counter = 0;
	int index = 0;
	char cbuf[20];
	
	win = api_openwin((char *)win_buf, xsize, ysize, -1 /*ºÚÉ«*/, "minesweeper");
    api_refreshwin(win, 0, 0, xsize-1, ysize-1);

	char s[20];
	for(;;)
	{
		sprintf(cbuf, "%10d", counter);
		api_boxfilwin(win, 30, 30, 30 + strlen(cbuf) * 8, 30 + 16, 8/*ÁÁ»Ò*/);
		api_putstrwin(win, 30, 30, 0 /*ºÚÉ«*/, strlen(cbuf),  cbuf);
		
		api_getmouse(1, minfo);
			
		if(minfo->flag == 1)
		{	
			sprintf(s,"%5d %5d, [l m r] %d", minfo->x, minfo->y, minfo->btn);
			//sprintf(s,"%d", (int)minfo);
			if( (minfo->btn & 0x01) != 0 ){
				s[14] = 'L';
			}
			if( (minfo->btn & 0x02) != 0 ){
				s[18] = 'R';
			}
			if( (minfo->btn & 0x04) != 0 ){
				s[16] = 'M';
			}
			api_boxfilwin(win, 30, 50, 30 + 40 * 8, 50 + 16, 8/*ÁÁ»Ò*/);
			api_putstrwin(win, 30, 50, 0, strlen(s),  s);
			minfo->flag = -1;
		}
		counter++;
	}
	
	api_free(minfo, sizeof(struct MOUSE_INFO));
	api_closewin(win);
	api_end();
}
Ejemplo n.º 15
0
void HariMain(void)
{
	char *buf;
	int win, i, x, y;
	api_initmalloc();
	buf = api_malloc(150 * 100);
	win = api_openwin(buf, 150, 100, -1, "stars");
	api_boxfilwin(win,  6, 26, 143, 93, 0 /* 黒 */);
	for (i = 0; i < 50; i++) {
		x = (rand() % 137) +  6;
		y = (rand() %  67) + 26;
		api_point(win, x, y, 3 /* 黄 */);
	}
	api_end();
}
Ejemplo n.º 16
0
void CHNMain(void)
{
	uchar *buf;
	uint winID;

	api_initmalloc();
	buf = api_malloc(150 * 100);
	winID = api_openwin(buf, 150, 100, -1, "star1");
	api_boxfilwin(winID, 6, 26, 143, 93, black);
	api_point(winID, 75, 59, yellow);
	for(;;){
		if(api_getkey(true) == 0x0a) break;
	}
	api_end();
}
Ejemplo n.º 17
0
void HariMain(void)
{
    int win;
    char buf[150 * 70];
    win = api_openwin(buf, 150, 70, 255, "notrec");
    api_boxfilwin(win,   0, 50,  34, 69, 255);
    api_boxfilwin(win, 115, 50, 149, 69, 255);
    api_boxfilwin(win,  50, 30,  99, 49, 255);
    for (;;) {
	if (api_getkey(1) == 0x0a) {
		break;
	}
    }
    api_end();
}
Ejemplo n.º 18
0
void UcanMain(void)
{
	char *buf;
	int win, x, y;
	api_initmalloc();
	buf = api_malloc(144 * 164);
	win = api_openwin(buf, 144, 164, -1, "color2");
	for (y = 0; y < 128; y++) {
		for (x = 0; x < 128; x++) {
			buf[(x + 8) + (y + 28) * 144] = rgb2pal(x * 2, y * 2, 0, x, y);
		}
	}
	api_refreshwin(win, 8, 28, 136, 156);
	api_getkey(1); /* 等待任意键按下 */
	api_end();
}
Ejemplo n.º 19
0
Archivo: star1.c Proyecto: OSPROJ/LOS
void HariMain(void)
{
	char *buf;
	int win;
	api_initmalloc();
	buf = api_malloc(150 * 100);
	win = api_openwin(buf, 150, 100, -1, "star1");
	api_boxfilwin(win,  6, 26, 143, 93, 0 /* �� */);
	api_point(win, 75, 59, 3 /* �� */);
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; /* Enter�Ȃ�break; */
		}
	}
	api_end();
}
Ejemplo n.º 20
0
void HariMain(void)
{
	char *buf;
	int win;

	api_initmalloc();
	buf = api_malloc(150 * 50);
	win = api_openwin(buf, 150, 50, -1, "hello");
	api_boxfilwin(win,  8, 36, 141, 43, 6 /* 물색 */);
	api_putstrwin(win, 28, 28, 0 /* 검정 */, 12, "hello, world");
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; /* Enter라면 break; */
		}
	}
	api_end();
}
Ejemplo n.º 21
0
void main()
{
	char buf[144 * 164];
	int win, x, y , r, g, b;
	win = api_openwin(buf, 144, 164, -1, "color");
	for(y = 0; y < 128; y++)
		for(x = 0; x < 128; x++)
		{
			r = x * 2;
			g = y * 2;
			b = 0;
			buf[(x + 8) + (y + 28) * 144] = rgb2pal(r, g, b, x, y);
		}
	api_refreshwin(win, 8, 28, 136, 156);
	api_getkey(1);
	return;
}
Ejemplo n.º 22
0
void HariMain(void)
{
	char *buf;
	int win;

	api_initmalloc();
	buf = api_malloc(150 * 150);
	win = api_openwin(buf, 150, 150, -1, "hello");
	api_boxfilwin(win,  8, 36, 141, 43, 6);
	api_putstrwin(win, 0, 0, 0, 12, "hello my world");
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break;
		}
	}
	api_end();
}
Ejemplo n.º 23
0
void HariMain(void)
{
	char *buf;
	int win;

	api_initmalloc();
	buf = api_malloc(150 * 50);
	win = api_openwin(buf, 150, 50, -1, "hello");
	api_boxfilwin(win,  8, 36, 141, 43, 6); /*浅蓝色*/
	api_putstrwin(win, 28, 28, 0 , 12, "hello, world");/*黑色*/
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; /*按下回车键则break; */
		}
	}
	api_end();
}
Ejemplo n.º 24
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();
}
Ejemplo n.º 25
0
void HariMain(void)
{
    char* buf;
    int win, x, y, r, g, b;
    api_initmalloc();
    buf = api_malloc(144 * 164);
    win = api_openwin(buf, 144, 164, -1, "color");
    for (y = 0; y < 128; y++) {
        for (x = 0; x < 128; x++) {
            r = x * 2;
            g = y * 2;
            b = 0;
            buf[(x + 8) + (y + 28) * 144] = 16 + (r / 43) + (g / 43) * 6 + (b / 43) * 36;
        }
    }
    api_refreshwin(win, 8, 28, 136, 156);
    api_getkey(1); /* 按下任意键 */
    api_end();
}
Ejemplo n.º 26
0
void HariMain(void)
{
	char *buf;
	int win, i;
	api_initmalloc();
	buf = api_malloc(160 * 100);
	win = api_openwin(buf, 160, 100, -1, "lines");
	for (i = 0; i < 8; i++) {
		api_linewin(win + 1, 8, 26, 77, i * 9 + 26, i);
		api_linewin(win + 1, 88, 26, i * 9 + 88, 89, i);
	}
	api_refreshwin(win, 6, 26, 154, 90);
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; //enter
		}
	}
	api_closewin(win);
	api_end();
}
Ejemplo n.º 27
0
Archivo: stars.c Proyecto: barmi/bxos
void HariMain(void)
{
	char *buf;
	int win, i, x, y;
	api_initmalloc();
	buf = api_malloc(150 * 100);
	win = api_openwin(buf, 150, 100, -1, "stars");
	api_boxfilwin(win,  6, 26, 143, 93, 0 /* 검정 */);
	for (i = 0; i < 50; i++) {
		x = (rand() % 137) +  6;
		y = (rand() %  67) + 26;
		api_point(win, x, y, 3 /* 노랑 */);
	}
	for (;;) {
		if (api_getkey(1) == 0x0a) {
			break; /* Enter라면 break; */
		}
	}
	api_end();
}
Ejemplo n.º 28
0
void HariMain(void)
{
	char *buf;
	int win, i, x, y;
	api_initmalloc();
	buf = api_malloc(160 * 100);
	win = api_openwin(buf, 160, 100, -1, "walk");
	api_boxfilwin(win, 4, 24, 155, 95, 0);/*黑色*/
	x = 76;
	y = 56;
	api_putstrwin(win, x, y, 3, 1, "*");/*黄色*/
	for (;;) {
		i = api_getkey(1);
		api_putstrwin(win, x, y, 0 , 1, "*"); /*用黑色擦除*/
		if (i == '4' && x >   4) { x -= 8; }
		if (i == '6' && x < 148) { x += 8; }
		if (i == '8' && y >  24) { y -= 8; }
		if (i == '2' && y <  80) { y += 8; }
		if (i == 0x0a) { break; } /*按回车键结束*/
		api_putstrwin(win, x, y, 3 , 1, "*");/*黄色*/
	}	
	api_closewin(win);
	api_end();
}
Ejemplo n.º 29
0
void HariMain()
{
	char buf[WND_X * WND_Y * osak_getbuflen()];
	char cmdline[30], *p = 0;

	struct CSV_INFO csvinfo;
	int sig, cx, cy, basex, basey, i, mode;
	int *p_com1, *p_com2;
	char c;

	/* CSVデータの初期化 */
	p_com2 = &csvinfo.comma[MAX_COMMA_Y - 1][MAX_COMMA_X - 1];
	for (p_com1 = &csvinfo.comma[0][0]; p_com1 <= p_com2; p_com1++)
		*p_com1 = -1;
	csvinfo.max_x = csvinfo.max_y = csvinfo.filesize = 0;

	/* コマンドライン取得 */
	api_cmdline(cmdline, 30);
	for (p = cmdline; *p > ' '; p++);	/* スペースが来るまで読み飛ばす */
	for (; *p == ' '; p++);				/* スペースを読み飛ばす */

	i = api_fopen(p);
	if (i == 0) {
		api_putstr0("File not found.\n");
		api_end();
	}
	csvinfo.filesize = api_fsize(i, 0);
	if (csvinfo.filesize >= MAX_FILESIZ - 1) {
		/* 読めない */
		api_putstr0("Filesize is too big.\n");
		api_end();
	}
	api_fread(csvinfo.buf, csvinfo.filesize, i);
	api_fclose(i);
	p = csvinfo.buf;

	i = cx = cy = mode = 0;
	if (*p != ',')
		csvinfo.comma[0][0] = 0;

	while (i < csvinfo.filesize) {
		c = csvinfo.buf[i++];

		if (c == 0x22) {
			if  (i == 1 || mode == 0) {
				mode++;
				continue;
			}
			if (mode && (csvinfo.buf[i] == ',' || csvinfo.buf[i] == 0x0a || csvinfo.buf[i] == 0x0d))
				mode--;
		}

		if (mode == 0 && c == ',') {
			cx++;
			// 「,,」「,\n」のように、セルに何もない状態ではない
			if (csvinfo.buf[i] != ',' && csvinfo.buf[i] != 0x0a && csvinfo.buf[i] != 0x0d)
				csvinfo.comma[cy][cx] = i;		// コンマの次の文字の場所が記録される
		}

		/* 改行コード */
		if ((c == 0x0d /* CR */ && csvinfo.buf[i] == 0x0a /* LF */) ||
			(c == 0x0a /* LF */ && csvinfo.buf[i] == 0x0d /* CR */)) {
			if (i < csvinfo.filesize) {
				if (csvinfo.max_x < cx)
					csvinfo.max_x = cx;
				cy++;
				cx = 0;
				i++;
				if (i >= csvinfo.filesize)
					break;
				csvinfo.max_y++;
				if (csvinfo.buf[i] != ',' && csvinfo.buf[i] != 0x0a && csvinfo.buf[i] != 0x0d)
					csvinfo.comma[cy][cx] = i;		// コンマの次の文字の場所が記録される
				if (csvinfo.buf[i] == 0x22)
					mode++;
			}
		}
	}
	csvinfo.max_x++;
	csvinfo.max_y++;

	win = api_openwin(buf, WND_X, WND_Y, -1, "CSV-Viewer");
	api_boxfilwin(win, 6, 26+16, GBOX_X+6, GBOX_Y+26+16, 7);

	/* ワークシート作成 */
	for (i = 0; i <= GBOX_X; i += CELLSIZ_X)
		api_linewin(win, i + 6, 42, i + 6, GBOX_Y + 42, 15);
	for (i = 0; i <= GBOX_Y; i += CELLSIZ_Y)
		api_linewin(win, 6, i + 42, GBOX_X + 6, i + 42, 15);

	/* CSVデータ表示 */
	cx = cy = basex = basey = 1;
	PutCell(1, 1, &csvinfo);
	my_drawboxId(4, cx, cy);
	Putcellinfo(basex+cx-2, basey+cy-2, &csvinfo);

	/* メインループ */
	for (;;) {
		sig = api_getkey(1);
		if (sig == 0xb4) {
			 /* left */
			if (1 < cx) {
				my_drawboxId(15, cx, cy);
				cx--;
				sig = 0;
			} else if (1 < basex) {
				basex--;
				PutCell(basex, basey, &csvinfo);
				sig = 0;
			}
		}
		if (sig == 0xb6) {
			/* rigth */
			if (cx < maxell_x-1) {
				my_drawboxId(15, cx, cy);
				cx++;
				sig = 0;
			} else if (basex+cx < MAX_COMMA_X) {
				basex++;
				PutCell(basex, basey, &csvinfo);
				sig = 0;
			}
		}
		if (sig == 0xb8) {
			/* up */
			if (cy >  1) {
				my_drawboxId(15, cx, cy);
				cy--;
				sig = 0;
			} else if (1 < basey) {
				basey--;
				PutCell(basex, basey, &csvinfo);
				sig = 0;
			}
		}
		if (sig == 0xb2) {
			/* down */
			if (cy <  maxell_y-1) {
				my_drawboxId(15, cx, cy);
				cy++;
				sig = 0;
			} else if (basey+cy < MAX_COMMA_Y) {
				basey++;
				PutCell(basex, basey, &csvinfo);
				sig = 0;
			}
		}
		if (sig == 0xb9) {
			/* Page Up */
			if (basey > 1) {
				basey -= maxell_y - 1;
				if (basey < 1) {
					my_drawboxId(15, cx, cy);
					basey = cy = 1;
				}
				PutCell(basex, basey, &csvinfo);
				sig = 0;
			}
		}
		if (sig == 0xb3) {
			/* Page Down */
			if (basey <= MAX_COMMA_Y - maxell_y) {
				basey += maxell_y - 1;
				if (basey > MAX_COMMA_Y - maxell_y) {
					my_drawboxId(15, cx, cy);
					basey = MAX_COMMA_Y - maxell_y + 1;
					cy = maxell_y - 1;
				}
				PutCell(basex, basey, &csvinfo);
				sig = 0;
			}
		}

		if (sig == 0) {
			my_drawboxId(4, cx, cy);
			Putcellinfo(basex+cx-2, basey+cy-2, &csvinfo);
		}
	}
}
Ejemplo n.º 30
0
Archivo: mmlplay.c Proyecto: 1m69/OSASK
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;
			}