/*
 * Copyright (c) 1999-2000, Qute Corporation. All rights reserved. 
 */
/*
 * rec_cnt: serial communication program for exnos cnt.
 *	$Id: $
 */
/*
 * 2000/ 8/16 : 通信による設定の取込、在車状態の表示、カーソル移動までサポート
 * 2000/ 8/17 : ほぼ基本機能は完成、メッセージの強化が必要
 * 2000/10/ 9 : メッセージの強化のviwsw2として再開発開始 
 * 2001/01/10 : Ver1.0 として出荷 
 */

#include "../std.h"
#include "../biosinl.h"
#include "../resource.h"
#include <sys/fcntl.h>
#include <sys/bios.h>
#include <string.h>

/* 以下それぞれの表示テーブルの番号　*/
/* cursor wind に対応 */

#define	jdg_comm	68	/* 通信頻度　*/
#define jdg_pc		69
#define jdg_full	67
#define	set_near	70
#define	set_far		71
#define set_intv	72


void disp_char(char line_tmp[],int l_start,int l_num);
void set_00();
void set_10();
void set_20();
void set_30();
void set_40();
void set_50();
void set_60();
void set_70();

extern BYTE *_heap;
char *read_data();
void read_set();
void read_num();
void read_wave();
void disp_set();
void set_reverce();
void set_chng();
void disp_imag(char te[30],int iab,int iret_set);
void disp_enph(int iab,int iret_set);
void disp_msg(char msg[],int l_start);
void disp_clear_line(int l_start,int l_num);
void disp_wave_ab();
void disp_wave(int iab);
void disp_cmnt();
void text_put_lstring(int ix,int iy,char *text_out); 
void disp_data();
void disp_on_off();
void disp_space(int iab);

/* 以下それぞれの表示テーブルの番号　*/
/* cursor wind に対応 */
char ctest;
int gtb_jdg[2] ={64,66} ;
int gtb_lin_u[2] ={1,32};
int gtb_lin_d[2] ={17,48};
int gtb_set[2] ={63,65};

int gasc='０'-'0';			/* １バイト→２バイト文字変換用 */
int gasc_small='ａ'-'a';	/* １バイト→２バイト文字変換用 */
int gif_sumAB=0;			/* 0:独立判定 1:AB合算 */
int gicount=0;
int gisetline=6;			/* 6種類の表示メニュー */
int giline=1;				/* 0〜7 起動画面〜終了 */
int gifirst=0;				/* ０の時のみ最初の通信　*/
int giarrow=0;				/* 0 to 2 */
int gy=0;					/* 何行目の表示(メモリ)か　*/
int giend=0;				/* 通信強制終了で１ */

/***** 読み込んだデータの保管 *****/
char *gcrev();				/* Ver */
int	ginear=0;				/* 近距離設定値 */
int gifar=0;				/* 近距離設定値 */
int gijdg[2]={0,0};			/* A/Bline 0/1 満車判定数 */
int giset[2]={0,0};			/* A/Bline 0/1 在車設定数 */
int gic=0;					/* 設定可能な何番目のテーブルか */
int giturn[8]={1,0,3,2,5,4,7,6};
							/* データの並びがHL逆なので */
int gistart_ab[2]={1,32};
static char data_setting[2][30];
							/* [0][0]:FF71H 13*2		*/
							/* [1][0]:FF7EH */
							
int gicancel=0;				/* いつでも終了 */
char gcver[]="　∈ｘｎｏｓ　制御基板モニタ　Ｖ１．０　";
char *gctitle[]={
	"０：起動画面",
	"１：在庫状況",
	"２：詳細設定",
	"３：波形表示",
	"４：動作確認",
	"５：受信信号",
	"６：保存読書",
	};

char *send_ab[2]={"WAA","WAB"};
char *arrow_lr[]={"→","←"};
					/* 0:右 1:左　*/
char *disp_car[2][2]={
	"○","●","□","■"
	};
struct cursor{
	int cx,cy,cw,dir1,dir2,dir3,dir4;
};

struct cursor wind[]={
	/* x,y,幅,UPが押された時の次の番地,RIGHT,DOWN,LEFT */
		{1,1,1,		1,1,1,1},			/* ダミー */
		
		/* A-line上 */
		{8,3,1,		63,2,17,63},		/* 1：A-line上 */
		{9,3,1,		63,3,18,1},
		{10,3,1,	63,4,19,2},
		{11,3,1,	63,5,20,3},

		{13,3,1,	63,6,21,4},
		{14,3,1,	63,7,22,5},
		{15,3,1,	63,8,23,6},
		{16,3,1,	63,9,24,7},

		{18,3,1,	63,10,25,8},
		{19,3,1,	63,11,26,9},		/* 10 */
		{20,3,1,	63,12,27,10},
		{21,3,1,	63,13,28,11},

		{23,3,1,	63,14,29,12},
		{24,3,1,	63,15,30,13},
		{25,3,1,	63,16,31,14},
		{26,3,1,	63,17,17,15},

		{8,5,1,		1,18,32,16},		/* 1：A-line下 */
		{9,5,1,		2,19,33,17},
		{10,5,1,	3,20,34,18},
		{11,5,1,	4,21,35,19},		/* 20： */

		{13,5,1,	5,22,36,20},
		{14,5,1,	6,23,37,21},
		{15,5,1,	7,24,38,22},
		{16,5,1,	8,25,39,23},

		{18,5,1,	9,26,40,24},
		{19,5,1,	11,27,41,25},
		{20,5,1,	12,28,42,26},
		{21,5,1,	13,29,43,27},

		{23,5,1,	14,30,44,28},
		{24,5,1,	15,31,45,29},		/* 30： */
		{25,5,1,	16,32,46,30},
		
		/* B-line上 */
		{8,7,1,		17,33,48,65},		/* 32：B-line上 */
		{9,7,1,		18,34,49,32},
		{10,7,1,	19,35,50,33},
		{11,7,1,	20,36,51,34},

		{13,7,1,	21,37,52,35},
		{14,7,1,	22,38,53,36},
		{15,7,1,	23,39,54,37},
		{16,7,1,	24,40,55,38},

		{18,7,1,	25,41,56,39},		/* 40 */
		{19,7,1,	26,42,57,40},
		{20,7,1,	27,43,58,41},
		{21,7,1,	28,44,59,42},

		{23,7,1,	29,45,60,43},
		{24,7,1,	30,46,61,44},
		{25,7,1,	31,47,62,45},
		{26,7,1,	31,48,48,46},

		{8,9,1,		32,49,67,47},		/* 48：B-line下 */
		{9,9,1,		33,50,67,48},
		{10,9,1,	34,51,67,49},		/* 50： */
		{11,9,1,	35,52,67,50},

		{13,9,1,	36,53,67,51},
		{14,9,1,	37,54,67,52},
		{15,9,1,	38,55,67,53},
		{16,9,1,	39,56,67,54},

		{18,9,1,	40,57,67,55},
		{19,9,1,	41,58,67,56},
		{20,9,1,	42,59,67,57},
		{21,9,1,	43,60,67,58},

		{23,9,1,	44,61,67,59},		/* 60： */
		{24,9,1,	45,62,67,60},
		{25,9,1,	46,67,67,61},
	
		{5,3,2,		72,1,64,72},		/* 63 Ａ利用設定 */
		{5,4,2,		63,1,65,63},		/* 64 Ａ判定設定 */
		
		{5,6,2,		64,32,66,64},		/* 65 Ｂ利用設定 */
		{5,7,2,		65,32,67,65},		/* 66 Ｂ判定設定 */

		{8,10,14,	66,70,68,66},		/* 67 満空 */
	
		{1,12,14,	67,72,69,67},		/* 68 通信 */
		{1,13,14,	68,72,70,68},		/* 69 判定 */
		{5,14,3,	69,72,71,69},		/* 70 近距離 */
		{6,15,2,	70,72,72,70},		/* 71 遠距離 */

		{16,12,5,	71,63,63,71}		/* 72 動作間隔 */
		
	};
	
/****************************************************/
/* 波形の元データ読込								*/
/****************************************************/
size_t read_file(char *path, void *buffer){
	int fd;
	size_t size;
	if((fd = open(path, FMODE_R, 0)) >= 0) {
		size = read(fd, buffer, -(int)buffer);
		close(fd);
		*((BYTE*)buffer + size) = '\0';
		return size;
	} else {
		int x = text_put_string(0, 0, "cannot read ");
		text_put_string(x, 0, path);
		key_wait();
		return 0;
	}
}

/****************************************************/
/* 1バイト文字→２バイト文字<汎用>					*/
/*	パラメータの内容は、text_put_stringに順ずる		*/
/*	２バイト文字は受け付けないので注意				*/
/****************************************************/
void text_put_lstring(int ix,int iy,char *text_out)
{
	int i=0;
	int itmp;
	static char line_tmp[290];
	
	strcpy(line_tmp,text_out);
	while ((itmp=text_out[i]) != '\0'){
		if ( itmp>= 'a'){	
					/* 小文字だけ１キャラずれているWSのバグ対策 */
			text_put_char(ix+i,iy,itmp+gasc_small);
		}
		else{
			text_put_char(ix+i,iy,itmp+gasc);
		}
		i++;
	}
}

/****************************************************/
/*　アスキーのＨＥＸを数字に　						*/
/****************************************************/
int asc2num(char a)
{
	if (a>=48 && a<=57)
		return a-48;
	if (a>=65 && a<=70)
		return a-55;
	else
		return 0;

	/*  取りあえず０を返すので要注意　*/
	
}

/****************************************************/
/*　数字をアスキーHEXに		　						*/
/****************************************************/
char num2asc(int a)
{
	if (a>=0 && a<=9)
		return a+48;
	if (a>=10 && a<=15)
		return a+55;
	else
		return 48;

	/*  取りあえず０を返すので要注意　*/
	
}

/****************************************************/
/*	DATAを制御基板に書き込む						*/
/****************************************************/
void write_data()
{
	int i,j,k;
	static char *addr[2][2]={
		"SET FF71,","SET FF77,","SET FF7E,","SET FF84,"
	};
	static char tmp_data[15];
	static char tmp_rec[30];
	comm_open();
    /* comm_set_cancel_key(KEY_START); */

	text_put_string(18, 17, "書込中");

	for (i=0;i<2;i++){
		for (j=0;j<2;j++){
			for (k=0;k<14;k++){
				tmp_data[k]=data_setting[i][j*12+k];
				tmp_data[14]='\0';			/* @@@@@@@@ */
			}

		do{  
				comm_send_string(addr[i][j]);
				comm_send_string(tmp_data);
				comm_send_string("\r\n");
				strcpy(tmp_rec,read_data());
			}while (tmp_rec[0] != '*');
		}
	}

	do{			/* リセット　*/
		comm_send_string("JP0\r\n");
		strcpy(tmp_rec,read_data());
	}
	while (tmp_rec[0] != '*');
	text_put_string(18, 17, "OK!");
	comm_close();
}


/****************************************************/
/*	メッセージを中央に表示							*/
/*		msg			:  メッセージ					*/
/*		l_start		:　表示開始行					*/
/****************************************************/
void disp_msg(char msg[],int l_start)
{
	int ilen;
	ilen=strlen(msg);
	text_put_string(14- ilen/2, l_start,msg);

	cursor_set_type(7,30);			/* カーソル表示　*/
	cursor_set_location(14- ilen/2,l_start,ilen,1);
	cursor_display(1);
}

/****************************************************/
/*	画面の一部をクリア								*/
/*		l_start		:　表示開始行					*/
/*		l_num		:　表示行数						*/
/****************************************************/
void disp_clear_line(int l_start,int l_num)
{
	int i;
	for (i=0 ;i <l_num ;i++){
		/* text_put_string(0, l_start+i,"                            "); */
		text_put_string(0, l_start+i,"　　　　　　　　　　　　　　　　　　　　　　　　　　　　");
	}
}
/****************************************************/
/*	通信内容スクロール表示							*/
/*		line_tmp	:　通信内容						*/
/*		l_start		:　表示開始行					*/
/*		l_num		:　表示行数						*/
/****************************************************/
void disp_char(char line_tmp[],int l_start,int l_num)
{
	int a;
	static char line_rec[10][30];
	if (gifirst==0){
		gifirst=1;
		gy=0;
		giarrow=0;
		disp_clear_line(l_start,l_num);
	}
	if (gy > l_num-1 ){
		for (gy=0;gy<=l_num -1;gy++){
			strcpy(line_rec[gy], line_rec[gy+1]);
			text_put_lstring(0, gy+l_start, line_rec[gy+1]);
							/* lstring(2バイトへの変換をしている点に注意
							波形表示で１バイト文字が使用できなくなっている為 */
		}
		gy=l_num-1;
	}
	strcpy(line_rec[gy], line_tmp);

	a=0x8;
	lcd_set_segments((a = a << giarrow)|1);			/* ★”表示の為　*/
	text_put_string(0, gy+l_start, line_rec[gy]);
	giarrow++;
	if (giarrow==3){
		giarrow=0;
	}
	gy++;
	/*
	text_put_char(17,1,tmp_data[20]+gasc);
	*/
}

/****************************************************/
/* NUM FONT 読込									*/
/****************************************************/
void read_num()
{
	char *path;			/* = argv[1]; 波形データ読込 */

	res_image_t *res = (res_image_t*)_heap+1;
	path = "/rom0/NUM.fr";
	
	if(!read_file(path, _heap)) {
									/* 波形データ不在時の処理 */
									/* ＠＠要機能確認 */
		text_put_string(0, 0, "イメージファイルがありません");
		key_wait();
	}
	
	text_set_ank_font(0x30,0,39,res);	/* NUMデータのセット 
									途中から読み込んでも全て壊れる為 */	
}

/****************************************************/
/* 波形読込											*/
/****************************************************/
void read_wave()
{
	char *path;			/* = argv[1]; 波形データ読込 */

	res_image_t *res = (res_image_t*)_heap+1;
	path = "/rom0/allblk28.fr";
	
	if(!read_file(path, _heap)) {
									/* 波形データ不在時の処理 */
									/* ＠＠要機能確認 */
		text_put_string(0, 0, "イメージファイルがありません");
		key_wait();
	}
	
	text_set_ank_font(0,0,256,res);	/* 波形データのセット */
}

/****************************************************/
/* 波形表示の元										*/
/****************************************************/

void disp_wave_ab(){
	int	iab;
	int a;
	static char tmp_data[290];		/* @@ */
	cursor_set_location(20,9,8,1);
	
	while(1){
		comm_send_string("*\r\n");
		strcpy(tmp_data , read_data());		/* CR検出待	*/
		for (iab=0;iab<2;iab++){
			disp_wave(iab);
			text_put_string(22,17,"　Ｙ３：終了");
			if (giend==1){
			/*	text_put_string(26,9,"開始"); */
				lcd_set_segments(0); 
				giend=0;
											/* STARTで開始の意味(中断中) */
				return;
			}
			else {
			/*	text_put_string(26,9,"中断"); */
				lcd_set_segments(1);
				/*return;*/
			}
		}
		a=0x8;
		lcd_set_segments((a = a << gicount++)|1);
		if (gicount>2){
			gicount=0;
		}
	}
}

/****************************************************/
/* 波形表示											*/
/****************************************************/
void disp_wave(int iab)
{
	int iiy,iix,inum_car;
	static char tmp_data[290];		/* @@ */
	comm_send_string(send_ab[iab]);
	comm_send_string("\r\n");
	strcpy(tmp_data , read_data());
	if (giend==1)
		return;
	for (iiy=0;iiy<8;iiy++){
		for (inum_car=0;inum_car<4;inum_car++){
			for (iix=0;iix<4;iix++){
				if(iix==0){
					if ((iiy*4+inum_car+1) >= 10){
						text_put_char(inum_car * 7+1,iab*9+iiy+1,'０'+((iiy * 4+inum_car+1) / 10));
					} else
					{
						text_put_char(inum_car*7+1,iab*9+iiy+1,'　');
					}
					text_put_char(inum_car*7+2,iab*9+iiy+1,'０'+((iiy*4+inum_car+1) % 10));
				}
				text_put_char(inum_car*7+3+iix,iab*9+iiy+1,asc2num(tmp_data[2+(iiy*4+inum_car)*9+(3-iix)*2])*16+asc2num(tmp_data[2+(iiy*4+inum_car)*9+(3-iix)*2+1])); 
			}
		}
	}
}


/****************************************************/
/*	カーソル表示									*/
/****************************************************/
void set_curs(int in)
{
	text_put_string(18, 17, "　　　");
	switch(in){
	case KEY_X1:
		gic=wind[gic].dir1;
		break;
	case KEY_X2:
		gic=wind[gic].dir2;
		break;
	case KEY_X3:
		gic=wind[gic].dir3;
		break;
	case KEY_X4:
		gic=wind[gic].dir4;
		break;
	case KEY_Y1:					/* 再読込 */
		lcd_set_segments(1);
		read_set();
		disp_set();
		disp_enph(0,2);				/* A-line ■ */
		disp_enph(1,2);				/* B-line ■ */
		lcd_set_segments(0);
		break;
	case KEY_Y2:					/* 設定書込 */
		lcd_set_segments(1);
		write_data();
		lcd_set_segments(0);
		break;
	case KEY_A:
		if (gic<63){				/* (1 to 62) 強制在車枠　■だったら */
			set_reverce();
			break;
		}
		else
			set_chng();
		break;
	}
	cursor_set_type(7,30);
	if (gic==72)
		cursor_set_location(wind[gic].cx,wind[gic].cy,wind[gic].cw,4);
	else
		cursor_set_location(wind[gic].cx,wind[gic].cy,wind[gic].cw,1);
	
}
/****************************************************/
/*	強制在車設定の変更								*/
/****************************************************/
void set_reverce()
{
	int i,iblock,imod,imask;
	int iab=0;
	char block4;
	if (gic>=gtb_lin_u[1])
		iab=1;
	i=gic-gtb_lin_u[iab];
	iblock=giturn[i/4]+iab*8;
	imod=i % 4;
	imask=1 << (imod);
	block4=data_setting[1][10+iblock];
	block4=num2asc(asc2num(block4) ^ imask);	/* xor で特定BITのみ反転　*/
	data_setting[1][10+iblock]=block4;
	disp_enph(iab,2);							/* 通信内容表示 ■ */
}

/****************************************************/
/*	設定の変更										*/
/****************************************************/
void set_chng()
{
	int key,iud,ilr,iab,j;
	int iset_sum=0;					/* 利用数と判定数を変化させた時１ */
	int ichng_enph=0;				/* 1なら子機の数を変更して表示　*/
	int ihl[2];						/* 1:下位ビット　0:上位ビット　*/	
	int iline;						/* 0:71 to 7D 1:7E to 8A	*/
	int iblock;						/* 何番目のキャラか	*/
	int ilen=1;						/* 0で← 2/3:数字の桁　*/
	int idisp;
	cursor_set_type(7,10);			/* カーソル表示を3倍速　*/
	while ((key = key_wait()) != KEY_A ){
		ichng_enph=0;
		ilen=1;
		iset_sum=0;
		switch (key) {
		case KEY_UP1:
			iud=1;
			ilr=0;
		    break;

		case KEY_DOWN1:
			iud=-1;
			ilr=0;
		    break;

		case KEY_X2:	/* 右 */
			iud=0;
			ilr=1;
		    break;

		case KEY_X4:	/* 左 */
			iud=0;
			ilr=2;
		    break;
		}

		if (iud != 0){
			/* タイマー変更	*/
			if (gic==set_intv){
				ilen=0;
				switch (asc2num(data_setting[0][1])){
				case 0:
					if (iud==-1)
						data_setting[0][1]='4';
					break;
				case 4:
					if (iud==-1)
						data_setting[0][1]='A';
					if (iud==1)
						data_setting[0][1]='0';
					break;
				case 0x0A:
					if (iud==1)
						data_setting[0][1]='4';
					break;
				}
			}
			
			/* 判定数変更	*/
			if (gic==gtb_jdg[0] || gic==gtb_jdg[1]){
				iset_sum=1;
				iab=gic-gtb_jdg[0];
				if (gic==gtb_jdg[0]){
					iab=0;
				}
				else{
					iab=1;
				}
				gijdg[iab] = gijdg[iab] + iud;
				if (gijdg[iab]<0)
					gijdg[iab]=0;
				if (gijdg[iab]>32)
					gijdg[iab]=32;
				ilen=2;
				idisp=gijdg[iab];
				iline=1;
				iblock=iab*2;
			}

			/* 使用数変更	*/
			if (gic==gtb_set[0] || gic == gtb_set[1]){
				iset_sum=1;
				if (gic==gtb_set[0]){
					iab=0;
					ichng_enph=1;
				}
				else{
					iab=1;
					ichng_enph=2;
				}
				giset[iab] = giset[iab] + iud;
				if (giset[iab]<0)
					giset[iab]=0;
				if (giset[iab]>31)
					giset[iab]=31;
				ilen=2;
				idisp=giset[iab];
				iline=1;
				iblock=iab*2+6;
			}

			/* 近距離変更	*/
			if (gic==set_near){
				ginear = ginear + iud;
				if (ginear<0)
					ginear=0;
				if (ginear>150)
					ginear=150;
				ilen=3;
				idisp=ginear;
				iline=0;
				iblock=12;
			}
			/* 遠距離変更	*/
			if (gic==set_far){
				gifar = gifar + iud;
				if (gifar<0)
					gifar=0;
				if (gifar>31)
					gifar=31;
				ilen=2;
				idisp=gifar;
				iline=0;
				iblock=14;
			}
			if (ilen >=2) {
				text_put_numeric(wind[gic].cx
					,wind[gic].cy,ilen,NUM_PADZERO,idisp);
				ihl[1]=idisp % 16;
				ihl[0]=idisp / 16;
				for (j=0;j<2;j++){			/* データ書込準備　*/
					data_setting[iline][iblock+j]=num2asc(ihl[j]);
				}
				if (iset_sum==1){			/* 合計 */
					text_put_numeric(5,9,2,NUM_PADZERO,giset[0]+giset[1]);
					text_put_numeric(5,10,2,NUM_PADZERO,gijdg[0]+gijdg[1]);
				}
			}
		}
		else{
			/* 通信頻度変更	*/
			if (gic==jdg_comm){
				ilen=0;
				if (ilr==1)						/* 確定時　*/
					data_setting[1][4] = num2asc(asc2num(data_setting[1][4]) & 0xB);
				if (ilr==2)
					data_setting[1][4] = num2asc(asc2num(data_setting[1][4]) | 0x4);
			}
			/* 判定手段変更	*/
			if (gic==jdg_pc){
				ilen=0;
				if (ilr==1)						/* PC判定　*/
					data_setting[0][3] = num2asc(asc2num(data_setting[0][3]) & 0x7);
				if (ilr==2)
					data_setting[0][3] = num2asc(asc2num(data_setting[0][3]) | 0x8);
			}
			/* 満空出力変更	*/
			if (gic==jdg_full){
				ilen=0;
				if (ilr==1)						/* 合算判定　*/
					data_setting[1][5] = num2asc(asc2num(data_setting[1][5]) & 0xE);
				if (ilr==2)
					data_setting[1][5] = num2asc(asc2num(data_setting[1][5]) | 0x1);
			}
		}
		if (ilen==0)
			disp_set();
	}
	
	if (ichng_enph !=0 )
		disp_enph(ichng_enph-1,2);		/* ■□再表示			*/

}

/****************************************************/
/*	データ読み出し（汎用）							*/
/****************************************************/
char *read_data()
{
    int x = 0;	
    int high = 0;
    int c;
	static char line_tmp[290];

	while (1){
		c= comm_receive_char();

		switch (c) {
		case ERR_SIO_CANCEL:
		    /* comm_send_string("ERR_SIO_TIMEOUT");
		     FALL THROUGH */
			if (key_hit_check()==KEY_Y3){
				giend=1;
			}
			return "end";			/* 実際は使用しない　giendで判定　*/
		case ERR_SIO_TIMEOUT:
		    break;
		case ERR_SIO_OVERRUN:
		    /* comm_send_string("ERR_SIO_OVERRUN");
			 */
		    break;
		case 0x0A:
			/* 制御基板は 0A を出力しないが、
				秀termで検証する時のため　*/
			break;
		case 0x0D:
			line_tmp[x]='\0';
			return line_tmp;
		default:
		    if (high != 0) {
				c |= high;
				high = 0;
		    } 
			else if (c & 0x80) {
				high = c << 8;
				continue;
		    }
			line_tmp[x]=c;
		    x++;
		    if (x > 289) {		/*@@要注意@@*/
				x = 289;
		    }
		}
	
    }

}

/****************************************************/
/*	通常データの表示								*/
/****************************************************/
void disp_data()
{
	static char tmp_data[30]; /* @@@ 重要！　
							static にしないと内容が安定しない
							原因不明　*/
	comm_open();

	while (giend == 0){
		strcpy(tmp_data , read_data());
		comm_send_string("*\r\n");		/* ACK 	*/
		disp_char(tmp_data,2,14); 		/* 通信内容表示 キャラクタスクロール */
	}
	giend=0;
	comm_close();
	lcd_set_segments(0);
}

/****************************************************/
/*	●○■の表示								*/
/****************************************************/
void disp_on_off()
{
	int i,iab;
	static int itmp_sum;
	static int icut_ab[2]={3,16};	/* 何番目のデータがABlineか */
	static char tmp_data[30]; /* @@@ 重要！　
							static にしないと内容が安定しない
							原因不明　*/
	static char cut_data[9];
	lcd_set_segments(0x1);
	comm_open();
 	
	while (giend == 0){
		itmp_sum=0;
		strcpy(tmp_data , read_data());
		comm_send_string("*\r\n");		/* ACK 	*/
	
		if (strlen(tmp_data)==28){
			disp_char(tmp_data,15,1); 	/* 通信内容表示 キャラクタスクロール */
			for (iab=1;iab>=0;iab--){	/* 逆順 合算の表示を楽にする為 */
				for(i=0;i<2;i++){
					cut_data[i]=tmp_data[i + icut_ab[iab]];	
										/* ABlineそれぞれ２文字づつ採取 */
				}
				cut_data[2]='\0';
				if (gif_sumAB==0){		/* 独立判定 */
					text_put_string(5,3+4*iab,cut_data);
					if (tmp_data[icut_ab[iab]+3]=='E')
						text_put_string(5,2+4*iab,"空車");
					else
						text_put_string(5,2+4*iab,"満車");
				}
				else{					/* 合算の場合は上書き */
					itmp_sum =itmp_sum + asc2num(cut_data[0])*16+asc2num(cut_data[1]);
					text_put_numeric(5,12,2,NUM_PADZERO,itmp_sum);
					if (tmp_data[icut_ab[iab]+3]=='E')
						text_put_string(5,11,"空車");
					else
						text_put_string(5,11,"満車");
				}
					
				for(i=0;i<8;i++){
					cut_data[i]=tmp_data[i + icut_ab[iab]+4];	
										/* ABlineそれぞれ８文字づつ採取 */
				}
				cut_data[8]='\0';
									/* 通信内容表示 ○●　*/
				disp_imag(cut_data,iab,0);
			}
	  								
			for (iab=0;iab<2;iab++){
									/* 通信内容表示 ■　　*/
				disp_enph(iab,1);
				disp_space(iab);
			}
		}
	}
	giend=0;
	lcd_set_segments(0x0);
	comm_close();
}

/****************************************************/
/*	■の表示										*/
/*			iret_set	: 1/□非表示:2/表示			*/
/****************************************************/
void disp_enph(int iab,int iret_set)
{
	int i;
	static	char cut_data[9];
	for(i=0;i<8;i++){
		cut_data[i]=data_setting[1][i + 10 + iab * 8];
	}
	cut_data[8]='\0';
	disp_imag(cut_data,iab,iret_set);
	/* disp_space(iab); */
}

/****************************************************/
/*	駐車状況の設定外個所を・表示					*/
/****************************************************/
void disp_space(int iab)
{	
	int i;
	for (i=giset[iab];i<31;i++){
		text_put_char(wind[gistart_ab[iab]+i].cx
			,wind[gistart_ab[iab]+i].cy,'・');
	}
}

/****************************************************/
/*	駐車状況を○●＿■で表示						*/
/*		te			: 8文字のデータ　				*/
/*		iab			: A/Bライン 0/1　				*/
/*		iret_set	: 結果(0) or 					*/
/*					  設定(1/□非表示:2/表示)　		*/
/*		giset_a/b により、設定数以上は、・表示　	*/
/****************************************************/
void disp_imag(char te[9],int iab,int iret_set)
{
	int i,j;
	int i4_car;
	int itmp_set;
	int imod,ibase;
	int iSen;	/* 何番目のセンサーか 0〜30 */

	for (i=0;i<8;i++){
		i4_car=asc2num(te[giturn[i]]);
		ibase = i / 5;
		for (j=0;j<4;j++){
			iSen=i * 4 + j;
			imod = i4_car % 2;
			i4_car = i4_car / 2;
			if (iret_set != 1 || imod != 0 ){	/* □を書く　*/
				itmp_set=iret_set;
				if (iret_set==2){
					itmp_set=1;
				}
				if (iSen != 31){
				text_put_string(wind[gistart_ab[iab] + iSen].cx
				,wind[gistart_ab[iab] + iSen].cy 
				, disp_car[itmp_set][imod]);
				}
			}
		}
	}
}

/****************************************************/
/*	設定内容読込									*/
/****************************************************/
void read_set()
{
	int i;
	char tmp_data[30];
	char cut_data[5];
	lcd_set_segments(1);
    comm_open();
    
	comm_send_string("*\r\n");
	
	strcpy(tmp_data , read_data());		/* CR検出待	*/
 	lcd_set_segments(0x09);
 	
/******** 	Ver取込 	**********/
	comm_send_string("VER\r\n");			
	strcpy(tmp_data, read_data());			/* @@値の吟味必要 */
	if (tmp_data[0] != 'P')
		return;								/* 通信できない時に終了する為 */
	gicancel=0;								/* 終了防止 */
	for(i=0;i<4;i++){
		cut_data[i]=tmp_data[i+16];
	}
	cut_data[4]='\0';
	/*@@ gcrev=cut_data[]; @@*/							/* Ver 記録 */

	lcd_set_segments(0x19);
	
/******** 	設定前半 	**********/
	comm_send_string("MEM FF71,0D\r\n");
	strcpy(tmp_data, read_data());
	strcpy(data_setting[0],tmp_data);		/* 保存　*/
	ctest=tmp_data[1];						/* @@@ */
	ginear=asc2num(tmp_data[12])*16+ asc2num(tmp_data[13]);
	gifar=asc2num(tmp_data[14])*16+ asc2num(tmp_data[15]);
	lcd_set_segments(0x39);

/******** 	設定後半 	**********/
	comm_send_string("MEM FF7E,0D\r\n");
	strcpy(tmp_data, read_data());
	strcpy(data_setting[1],tmp_data);		/* 保存　*/	
	for ( i=0 ; i<2 ; i++){
		/* 満車判定数 */
		gijdg[i]=asc2num(tmp_data[i*2])*16+ asc2num(tmp_data[i*2+1]);
		/* 使用子機数 */
		giset[i]=asc2num(tmp_data[i*2+6])*16+ asc2num(tmp_data[i*2+7]);
	}
	
	comm_send_string("*\r\n");				/* ACK 	*/
	comm_close();
	if ((asc2num(data_setting[1][5]) & 0x1)==0)
											/* 合算
											(disp_setと重複するがここで必要) */
		gif_sumAB=1;
	else
		gif_sumAB=0;
	lcd_set_segments(0);
}

/****************************************************/
/*	設定内容表示									*/
/****************************************************/
void disp_set()
{
	int i;
	int iset;	
	
/******** 	設定前半 	**********/
	/* タイマー */
	switch (asc2num(data_setting[0][1])){
	case 0:
		iset=0;
		break;
	case 4:
		iset=1;
		break;
	case 0x0A:
		iset=2;
		break;
	default:
		iset=3;
	}
	for (i=0;i<3;i++)
		text_put_string(wind[set_intv].cx+1,wind[set_intv].cy+1+i, "○");
	text_put_string(wind[set_intv].cx+1,wind[set_intv].cy+1+iset, "●");
	
	/* 自律/PC判定 */
	if ((asc2num(data_setting[0][3]) & 0x8)==0)	/* PC */
		iset=1;
	else						/* 自律 */
		iset=0;
		
	for (i=0;i<2;i++)
		text_put_string(wind[jdg_pc].cx+5+4*i,wind[jdg_pc].cy, "○");
	text_put_string(wind[jdg_pc].cx+5+4*iset,wind[jdg_pc].cy, "●");
	
	/* 近距離/遠距離 */
	text_put_numeric(wind[set_near].cx,wind[set_near].cy,3,NUM_PADZERO,ginear);
	text_put_numeric(wind[set_far].cx,wind[set_far].cy,2,NUM_PADZERO,gifar);

/******** 	設定後半 	**********/
	for ( i=0 ; i<2 ; i++){
		/* 満車判定数 */
		text_put_numeric(wind[gtb_jdg[i]].cx
			,wind[gtb_jdg[i]].cy
			,2,NUM_PADZERO,gijdg[i]);
		/* 使用子機数 */
		text_put_numeric(wind[gtb_set[i]].cx
			,wind[gtb_set[i]].cy
			,2,NUM_PADZERO,giset[i]);
		/* 合計 */
		text_put_numeric(5,9,2,NUM_PADZERO,giset[0]+giset[1]);
		text_put_numeric(5,10,2,NUM_PADZERO,gijdg[0]+gijdg[1]);
		
	}
	/* 通信頻度 */
	if ((asc2num(data_setting[1][4]) & 0x4)==0)		/* 確定時 */
		iset=1;
	else
		iset=0;										/* 変化時 */
		
	for (i=0;i<2;i++)
		text_put_string(wind[jdg_comm].cx+5+4*i,wind[jdg_comm].cy, "○");
	text_put_string(wind[jdg_comm].cx+5+4*iset,wind[jdg_comm].cy, "●");
	
	/* 満空表示 */
	if ((asc2num(data_setting[1][5]) & 0x1)==0){	/* 合算 */
		iset=1;
		gif_sumAB=1;
	}
	else{
		iset=0;	
		gif_sumAB=0;
	}
	for (i=0;i<2;i++)
		text_put_string(wind[jdg_full].cx+5+4*i,wind[jdg_full].cy, "○");
	text_put_string(wind[jdg_full].cx+5+4*iset,wind[jdg_full].cy, "●");
	
}

/****************************************************/
/* Ａ：操作画面										*/
/*													*/
/****************************************************/

void set_A0()
{
	int i;
	text_screen_init();
	cursor_display(1);
	
    text_put_string(0, 0, "　　再読込　　　┏━━━━┓");
    text_put_string(0, 1, "　　┏━━┓　　┃基本操作┃");
    text_put_string(0, 2, "　┏┛Y1┗┓　┗━━━━┛WonderSwan");
    text_put_string(0, 3, "　┃　＼／Y┃書┏━━━━━━━━━━━━━━┓");
    text_put_string(0, 4, "　┃　／＼2┃込┃　　　　　　　　　　　　　　┃");
    text_put_string(0, 5, "　┗┓Y3┏┛　┃　　　　　　　　　　　　　　┃");
    text_put_string(0, 6, "　　┗━━┛　　┃　　　　　　　　　　　　　　┃");
    text_put_string(0, 7, "　　　終了　　　┃　　Aボタンで次画面へ　　　┃");
    text_put_string(0, 8, "　　　　　　　　┃　　　　　　　　　　　　　　┃");
    text_put_string(0, 9, "　　　　　　　　┃　　　　　　　　　　　　　　┃");
    text_put_string(0, 10, "　　　↑選択　　┃　　　　　　　　　　　　　　┃");
    text_put_string(0, 11, "　　┏━━┓　　┠─通信中──────更新中─┨決定／");
    text_put_string(0, 12, "　┏┛X1┗┓　┃　　★’　　　　　 ・　●　┃　OK");
    text_put_string(0, 13, "　┃X＼／X┃　┗━━━━━━━━━━━━━━┛　／┓");
    text_put_string(0, 14, "←┃4／＼2┃→　　　　　　　　　　　　　　　　／A┃");
    text_put_string(0, 15, "　┗┓X3┏┛　　┏━━┓　┏━━┓　　　　　／　┏┛");
    text_put_string(0, 16, "　　┗━━┛　　　┗━━┛　┗━━┛　　　　　┗━┛");
    text_put_string(0, 17, "　　　↓");
	lcd_set_segments(0x39);
	i=0;
	while (key_press_check() != KEY_A ){
		sys_wait(2);
		if (i==20){
			i=0;
		}
		if (i<10){
			text_put_string(11, 7, "Aボタンで次画面へ");
			text_put_string(25, 14,"　" );
			i++;
		}
		else{
			text_put_string(11, 7, "　　　　　　　　　");
			text_put_string(25, 14, "A");
			i++;
		}
	}
	lcd_set_segments(0x00);
}

/****************************************************/
/* Ｂ：操作画面										*/
/*													*/
/****************************************************/

void set_B0()
{
	text_screen_init();
	cursor_display(1);
	
	text_put_string(1, 2, "　１０秒待っても次の画面に切り替わらない場合");
    text_put_string(1, 4, "　□　制御基板の電源は入っていますか？");
	text_put_string(1, 6, "　□　制御基板のDIP SW　は");
	text_put_string(1, 8, "　　　OFF ON OFF ONになっていますか？");
	text_put_string(1,10 , "　□　シリアルはクロスケーブルで接続されていますか？");
	text_put_string(1,12, "　□　制御基板の設定が１０分タイマーモードの場合は");
	text_put_string(1,14, "　　　このまま、基板の電源をＯＮ／ＯＦＦして下さい");
	
	text_put_string(0, 16, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
	text_put_string(22, 17, "　Ｙ３：終了");
}

/****************************************************/
/* ０：起動画面										*/
/*													*/
/****************************************************/

void set_00()
{
	int i;
	int ibreak;
	int key;

	text_screen_init();
	cursor_display(1);
	
    text_put_string(0, 0, gcver);
    text_put_string(20, 0,"┃");
    text_put_string(22, 0, gctitle[0]);
	text_put_string(0, 1, "━━━━━━━━━━━━━━━━━━━━┻━━━━━━━");
	text_put_string(1,2,"┏━━━━━━━┓");
	for (i=0;i<gisetline;i++){
		text_put_string(1,3+i*2,"┃　　　　　　　┃");
		text_put_string(2,3+i*2,gctitle[i+1]);
		text_put_string(1,4+i*2,"┣━━━━━━━┫");
	}
	text_put_string(1,gisetline*2+2,"┗━━━━━━━┛");
	
	text_put_string(0, 16, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
	text_put_string(0, 17, "　Ｘ１：↑　Ｘ３：↓　　Ａ：選択");
	text_put_string(23, 17, "Ｙ３：終了");
	
	ibreak=0;
	
	cursor_set_location(2,1+giline*2,6,1);
	disp_cmnt();
	
	while ((key = key_wait()) != KEY_Y3 ){

		switch (key) {
		case KEY_A:
			ibreak=1;
			break;
		case KEY_X1:	/* ↑ */
			giline=giline-1;
			if (giline<1){
				giline=1;
			}
			break;
		case KEY_X3:	/* ↓ */
			giline=giline+1;
			if (giline>gisetline){
				giline=gisetline;
			}
			break;
		}
		if (ibreak==1){
			break;
		}
		disp_cmnt();
		cursor_set_location(2,1+giline*2,6,1);
	}
	if (key == KEY_Y3)
		giline=7;		/* 終了 */
}

/****************************************************/
/* 0.5：コメント表示								*/
/****************************************************/
void disp_cmnt()
{
	int i;
	for (i=2 ;i <16 ;i++){
		text_put_string(10, i,"　　　　　　　　　　　　　　　　　　");
	}
	switch (giline){
	case 1:
		text_put_string(10,3,"──　在車状況を表示　　（○●）");
		break;
	case 2:
		text_put_string(10,3,"　┌　強制在車位置設定　（□■）");
		text_put_string(10,4,"　│");
		text_put_string(10,5,"─┼　満車判定数／判定距離設定");
		text_put_string(10,6,"　│");
		text_put_string(10,7,"　└　その他詳細設定");
		break;
	case 3:
		text_put_string(10,7,"──　受信波形表示");
		break;
	case 4:
		text_put_string(10,8,"　┌　不良センサ検出");
		text_put_string(10,9,"─┼　");
		text_put_string(10,10,"　└　結線確認");
		break;
	case 5:
		text_put_string(10,10,"　┌　受信テキスト表示");
		text_put_string(10,11,"─┤");
		text_put_string(10,12,"　└　ＲＳ２３２Ｃ（９６００ｂｐｓ）");
		break;
	case 6:
		text_put_string(10,11,"　┌　基本設定の読込");
		text_put_string(10,12,"　│");
		text_put_string(10,13,"─┴　現在の設定の保存");
		break;
	}
}

/****************************************************/
/*	１：在庫画面									*/
/*			一旦No表示用の外字を読込ます			*/
/****************************************************/
void set_10()
{
	int key;
	read_num();
	text_screen_init();
	
	cursor_display(0);
    text_put_string(0, 0, gcver);
	text_put_string(20, 0,"┃");
    text_put_string(22, 0, gctitle[1]);
	text_put_string(0, 1, "━━━━━━━┯━━━━━━━━━━━━┻━━━━━━━");
	text_put_string(0, 2, "PRS　　　　│1234　5678　9:;<　=>?@");
	text_put_string(0, 3, "　在車数：　　│");
	text_put_string(0, 4, "　判定数：　　│ABCD　EFGH　IJKL　MNO");
	text_put_string(0, 5, "　　　　　　　│");
	text_put_string(0, 6, "QRS　　　　│1234　5678　9:;<　=>?@");
	text_put_string(0, 7, "　在車数：　　│");
	text_put_string(0, 8, "　判定数：　　│ABCD　EFGH　IJKL　MNO");
	text_put_string(0, 9, "　　　　　　　│");
	text_put_string(0, 10, "───────┼──────┬─────────────");
	text_put_string(0, 11, "TUV　　　　│満車判定方法│凡例");
	text_put_string(0, 12, "　在車数：　　│　　ＡＢ独立│　●：在車　／　○：空車");
	text_put_string(0, 13, "　判定数：　　│　　ＡＢ合計│　■：強制在車");
	text_put_string(0, 14, "───────┴──────┴─────────────");
	text_put_string(0, 16, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
	text_put_string(22, 17, "　Ｙ３：終了");
	
	text_reset_ank_font();		/* 外字を元に戻す */
	if (gif_sumAB==0){			/* 独立 */
		text_put_numeric(5,4,2,NUM_PADZERO,gijdg[0]);
		text_put_numeric(5,8,2,NUM_PADZERO,gijdg[1]);
		text_put_string(9,12,"●");
		text_put_string(9,13,"○");
	}
	else{
		text_put_numeric(5,13,2,NUM_PADZERO,gijdg[0]+gijdg[1]);
		text_put_string(9,12,"○");
		text_put_string(9,13,"●");
	}
	disp_on_off();
	while ((key = key_wait()) != KEY_Y3 ){		
	}	

}

/****************************************************/
/*	２：変更設定									*/
/*													*/
/****************************************************/
void set_20()
{
	int key;
	read_num();
	text_screen_init();
    text_put_string(0, 0, gcver);
	text_put_string(20, 0,"┃");
    text_put_string(22, 0, gctitle[2]);
	text_put_string(0, 1, "━━━━━━━┯━━━━━━━━━━━━┻━━━━━━━");
	text_put_string(0, 2, "PRS　　　　│1234　5678　9:;<　=>?@");
	text_put_string(0, 3, "　利用数：　　│");
	text_put_string(0, 4, "　判定数：　　│ABCD　EFGH　IJKL　MNO");
	text_put_string(0, 5, "QRS　　　　│");
	text_put_string(0, 6, "　利用数：　　│1234　5678　9:;<　=>?@");
	text_put_string(0, 7, "　判定数：　　│");
	text_put_string(0, 8, "TUV────┤ABCD　EFGH　IJKL　MNO");
	text_put_string(0, 9, "　利用数：　　│");
	text_put_string(0, 10, "　判定数：　　│満車判定：　独立／　ＡＢ合計┏━━━━┓");
	text_put_string(0, 11, "───────┴───────┬──────┃再読込　┃");
	text_put_string(0, 12, "　通信頻度：　変化／　確定時　│動作間隔：　┃（Ｙ１）┃");
	text_put_string(0, 13, "　判定方法：　自律／　ＰＣ　　│　　連続　　┣━━━━┫");
	text_put_string(0, 14, "　近距離：　　　（　　　ｃｍ）│　　４秒　　┃設定書込┃");
	text_put_string(0, 15, "　遠距離：　　　（　　　ｃｍ）│　　１０分　┃（Ｙ２）┃");
	text_put_string(0, 16, "━━━━━━━━━━━━━━━┷━━━━━━┗━━━━┛");
	text_put_string(0, 17, "　Ｘ：移動／増減　Ａ：選択／決定　　　　　　　Ｙ３：終了");

	text_reset_ank_font();		/* 外字を元に戻す */

	disp_set();
	disp_enph(0,2);				/* A-line ■ */
	disp_enph(1,2);				/* B-line ■ */
	cursor_display(1);
	gic=63;
	cursor_set_location(wind[gic].cx,wind[gic].cy,wind[gic].cw,1);
	while ((key = key_wait()) != KEY_Y3 ){		
		set_curs(key);
	}	
}

/****************************************************/
/*	３：波形表示									*/
/*			一旦波形表示用の外字を読込ます			*/
/****************************************************/
void set_30()
{
	int key;
	text_screen_init();
    text_put_string(0, 0, gcver);
	text_put_string(20, 0,"┃");
    text_put_string(22, 0, gctitle[3]);
    text_put_string(23, 17, "Ｙ３：終了");
	read_wave();					/* 波形データ読込 */
	key=0;
	comm_open();
	
	lcd_set_segments(1);
									/* Aで通信キャンセル	*/
	disp_wave_ab();					/* 波形表示				*/
	
	while ((key = key_wait()) != KEY_Y3 ){
	}
	comm_close();
	text_reset_ank_font();		/*フォントセットを元に戻す*/
}
/****************************************************/
/*	４：動作確認									*/
/*													*/
/****************************************************/
void set_40()
{
	static char tmp_data[5];
	static char tmp_rec[30];
	int i;
	lcd_set_segments(1);
	comm_open();
	do{  							/* 一旦近距離を０に */
		comm_send_string("SET FF77,0012");
		comm_send_string("\r\n");
		strcpy(tmp_rec,read_data());
	}while (tmp_rec[0] != '*');
	do{			/* リセット　*/
		comm_send_string("JP0\r\n");
		strcpy(tmp_rec,read_data());
	}while (tmp_rec[0] != '*');
	comm_close();
	set_30();
	comm_open();
	for (i=0;i<4;i++){
		tmp_data[i]=data_setting[0][12+i];
	}
	tmp_data[4]='\0';
	do{  							/* 元の設定に戻す */
		comm_send_string("SET FF77,");
		comm_send_string(tmp_data);
		comm_send_string("\r\n");
		strcpy(tmp_rec,read_data());
	}while (tmp_rec[0] != '*');
	do{			/* リセット　*/
		comm_send_string("JP0\r\n");
		strcpy(tmp_rec,read_data());
	}while (tmp_rec[0] != '*');
	comm_close();
}

/****************************************************/
/*	５：受信信号									*/
/*													*/
/****************************************************/
void set_50()
{
	int key;
	text_screen_init();

    text_put_string(0, 0, gcver);
	text_put_string(20, 0,"┃");
    text_put_string(22, 0, gctitle[5]);
		
	text_put_string(0, 1, "━━━━━━━━━━━━━━━━━━━━┻━━━━━━━");
	text_put_string(0, 16, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
	text_put_string(22, 17, "　Ｙ３：終了");
	
	lcd_set_segments(1);
	/* comm_open(); */
	disp_data();
	while ((key = key_wait()) != KEY_Y3 ){
	}
	
}

/****************************************************/
/*	６：保存/読出									*/
/*													*/
/****************************************************/
void set_60()
{
	int key;
	text_screen_init();
	cursor_display(1);
    text_put_string(0, 0, gcver);
	text_put_string(20, 0,"┃");
    text_put_string(22, 0, gctitle[6]);
		
	text_put_string(0, 1, "━━━━━━━━━━━━━━━━━━━━┻━━━━━━━");
	text_put_string(10, 8, "未サポート");
	text_put_string(0, 16, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
	text_put_string(22, 17, "　Ｙ３：終了");
	while ((key = key_wait()) != KEY_Y3 ){
	}
}


/****************************************************/
/*	７：終了画面									*/
/*													*/
/****************************************************/
void set_70()
{
	int key;
	text_screen_init();
	cursor_display(1);

	text_put_string(5, 1, "┏━━━━━━━━━━━━━━━━┓");
	text_put_string(5, 2, "┃　制御基板モニタを終了しますか　┃");
	text_put_string(5, 3, "┃　　　　　　　　　　　　　　　　┃");
	text_put_string(5, 4, "┃　　　　　　はい：Ｙ３　　　　　┃");
	text_put_string(5, 5, "┃　　　　　いいえ：Ａ　　　　　　┃");
	text_put_string(5, 6, "┗━━━━━━━━━━━━━━━━┛");
	text_put_string(10, 8,"エクノス株式会社");
	text_put_string(5, 10,"〒２２８−０８０３");
	text_put_string(8, 11,"相模原市相模大野３−１１−１７");
	text_put_string(6, 13,"ＴＥＬ：０４２−７６７−５０３４");
	text_put_string(6, 14,"ＴＥＬ：０４２−７６７−５０３５");
	text_put_string(2, 16,"∈−ｍａｉｌ：ｉｎｆｏ＠ｅｘｎｏｓ．ｃｏ．ｊｐ");
	text_put_string(3, 17,"ｈｔｔｐ：／／ｗｗｗ．ｅｘｎｏｓ．ｃｏ．ｊｐ");
	
	cursor_set_location(7,4,14,1);
	
	while ((key = key_wait()) != KEY_Y3 ){
		if (key== KEY_A){
			giline=1;
			break;
		}
	}
}

/****************************************************/
/* MAIN												*/
/****************************************************/
void main(int argc, char *argv[])
{
	text_set_screen(0);				/* カーソル表示の為、裏を消す　*/
	text_screen_init();
	text_set_screen(1);
	text_screen_init();
									/* ＠＠PORT OPENは各SUBで */
	comm_set_baudrate(COMM_SPEED_9600);
	comm_set_timeout(50,-1);		/*　受信待ち=50　送信待ち=無限
										短いと終了を何度も拾う?　*/
	comm_set_cancel_key(KEY_Y3);	
									/* Ｙ３で通信キャンセル	*/
	cursor_set_type(7,20);			/* カーソル表示　*/
	cursor_display(0);
	set_A0();
	set_B0();
	gicancel=1;
	read_set();
	if (gicancel==1)
		goto end_prg;				/* 終了 */
	while (1){  
		set_00();
		cursor_display(0);
		switch (giline) {
		case 1:
			set_10();
			break;
		case 2:
			set_20();
			break;
		case 3:
			set_30();
			break;
		case 4:
			set_40();
			break;
		case 5:
			set_50();
			break;
		case 6:
			set_60();
			break;
		case 7:
			set_70();
			break;
		}
		if (giline==7){
			break;
		}
	}
end_prg:;
}
