#include	<stdio.h>
#include	<strings.h>
#include	<math.h>

FILE	*fpr0,*fpw;

main(argc,argv)
int	argc;
char	**argv;
{
	static char	cpcom1[] = "mv ";
	static char	cpcom2[] = " ../char/";
	static char	cpcom3[] = ".CH7";
	static char	cpcom4[] = ".CPD";

	char	readfile[125],savefile[125];
	char	c[125];

	printf("\n\n\n");

	if(argc != 2){
		fprintf(stderr,"Usage: cnvscr0 [ ファイル名 ]\n");
		exit(1);
	}

	strcpy(readfile,cpcom2+1);
	strcat(readfile,argv[1]);
	strcat(readfile,cpcom3);
	printf("read file = %s\n",readfile);

	strcpy(savefile,argv[1]);
	strcat(savefile,cpcom4);
	printf("save file = %s\n",savefile);

	printf("\n\n\n<<<<< chip screen chara data cnv START !! >>>>>\t\n\n\n");

	if(( fpr0 = fopen(readfile,"rb")) == NULL){
		fprintf(stderr,"\tRead file open error !!\n");
		exit(1);
	}

	if(( fpw = fopen(savefile,"wb")) == NULL){
		fprintf(stderr,"\tWrite file open error !!\n");
		exit(1);
	}

	data_cnv();

	fclose(fpr0);
	fclose(fpw);

	printf("\n\n<<<<< chip screen chara data cnv END !! >>>>>\n\n\n");
/**************************/
	strcpy(c,cpcom1);
	strcat(c,savefile);
	strcat(c, cpcom2);
	strcat(c,savefile);
	printf("\n%s\n",c);
	system(c);
/**************************/
}

data_cnv()
{
	char	a[16][8][8];
	int	h,i,j;

	for(h=0; h<32; h++){
		for(i=0; i<16; i++){
			for(j=0; j<8; j++){
				fread(a[i][j],sizeof(char),8,fpr0);
			}
		printf(".");
		}

		for(i=0; i<8; i++){
			for(j=0; j<16; j++){
				fwrite(a[j][i],sizeof(char),8,fpw);
			}
		}
	}
	printf("\n");
}

