/************************************************************************
*									*
*	敵データ変換（ツールデータ　−＞　テキストファイル）		*
*									*
************************************************************************/

#include <stdio.h>
#include <string.h>

typedef unsigned char unchar;

void main()
{
	FILE	*tbl_fp, *text_fp, *tool_fp;
	int	endt_no;
	char	fname[8+3+2];
	char	buf[7];
	char	en_name[5+1];
	unchar	en_x;
	unchar	en_y;

	if ((tbl_fp = fopen("endt.TBL", "r")) == NULL) {
		printf("テーブルファイル(endt.TBL)がオープンできません！！\n");
		exit(1);
	}

	if ((text_fp = fopen("../sfc/ys_endt.asm", "w")) == NULL) {
		printf("テキストファイル(../sfc/ys=endt.asm)がオープンできません！！\n");
		exit(1);
	}

	fprintf(text_fp, ";************************************************************************\n");
	fprintf(text_fp, "*\t\t\t\t\t*\n");
	fprintf(text_fp, ";************************************************************************\n");
	fprintf(text_fp, ";\n");
	fprintf(text_fp, ";\n");

	endt_no = 0;
	while (fgets(fname, 8, tbl_fp) != NULL) {
		strcat(fname, ".end");
		if ((tool_fp = fopen(fname, "r")) == NULL) {
			printf("ツールデータ(%s)がオープンできません！！\n", fname);
			exit(1);
		}

		fprintf(text_fp, "ENDT_%02X\tEQU\t$\n", endt_no);
		while ( fread(buf, sizeof(char), 7, tool_fp) == 7 ) {
			strncpy(en_name, buf, 5);
			en_x = buf[5];
			en_y = buf[6];
			fprintf(text_fp, "\t\tLWORD\t%s|(%02X<<9)|(%02X<<17)\n", en_name, en_x, en_y);
		}
