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

#define	unchar	unsigned char
#define	unshort	unsigned short

#define	PI	3.1415927

FILE	*fp;

void main()
{

	/****** 変数宣言 ******/
	int	ywide;		/* データ幅	*/
	int	centy;		/* 中心までの幅	*/
	int	upz;		/* 上の倍率	*/
	int	dwz;		/* 下の倍率	*/
	int	yzoom;		/* 縦の倍率	*/

	double	stz,enz;
	double	y;
	double	sty,eny;
	double	dy;
	double	z;
	double	p;
	double	centz;
	int	maxz;
	double	zstep;
	double	dz;
	double	c;

	int	i;

	/******	書き込みファイルＯＰＥＮ ******/
	if( !( fp = fopen( "pars.DAT","w" ) ) ){
		printf( "can't open (pars.DAT) !!\n" );
		exit(1);
	}

	/******	設定データ入力 ******/
	printf( "データ幅      ＝　" );
	scanf( "%x",&ywide );
	printf( "中心までの幅  ＝　" );
	scanf( "%x",&centy );
	printf( "上の倍率　    ＝　" );
	scanf( "%x",&upz );
	printf( "下の倍率    　＝　" );
	scanf( "%x",&dwz );
	printf( "縦の倍率      ＝　" );
	scanf( "%x",&yzoom );

	/******	パースデータ作成 ******/
	stz = (double)upz / 256.0; 
	enz = (double)dwz / 256.0; 

	y = (double)( ywide ) / ( 1.0 / enz - 1.0 / stz ); 

	sty = y / stz;
	eny = y / enz;

	fprintf( fp,"PARSY\t\tEQU\t%04XH\n",yzoom );
	fprintf( fp,"PARSDT\t\tEQU\t$" );

	for( dy=sty,i=0;dy<eny;dy++,i++ ){

		z = y / dy;
		p = z * 256.0;

		if( i & 0x7 ){
			fprintf( fp,",%05XH",(unshort)( p + 0.5 ) );
		}
		else{
			fprintf( fp,"\n\t\tWORD\t%05XH",(unshort)( p + 0.5 ) );
		}

	}		
	fprintf( fp,"\n;\n" );

	/******	パース座標変換データ作成 ******/
	fprintf( fp,"PARSYP\t\tEQU\t%04XH\n",(unshort)( y + 0.5 ) );


/*	maxz  = (int)( (double)ywide / enz * ( (double)yzoom / 256.0 ) + 0.5 );
*/
	maxz  = (int)( (double)ywide * ( (double)yzoom / 256.0 ) + 0.5 );

	zstep = ( stz - enz ) / (double)maxz;


	centz = ( ( y / ( sty + (double)centy ) ) - enz ) / ( stz - enz ) * (double)maxz;

	fprintf( fp,"CENTZ\t\tEQU\t080H\n" );

	fprintf( fp,"PARSDV\t\tEQU\t$" );

	dz = enz + ( ( centz - (double)0x80 ) * zstep );
	for( i=0;i<0x100;dz+=zstep,i++ ){

		p = (double)0x4000 / dz;
		if( i & 0x7 ){
			fprintf( fp,",%05XH",(unshort)( p + 0.5 ) );
		}
		else{
			fprintf( fp,"\n\t\tWORD\t%05XH",(unshort)( p + 0.5 ) );
		}

	}
	fprintf( fp,"\n;\n" );
	
	/******	書き込みファイルＣＬＯＳＥ ******/
	fclose( fp );

}
