PageRenderTime 280ms CodeModel.GetById 60ms app.highlight 177ms RepoModel.GetById 14ms app.codeStats 2ms

/ppmckc/datamake.c

https://bitbucket.org/ramsus/ppmckc-and-nesasm
C | 5606 lines | 4789 code | 277 blank | 540 comment | 787 complexity | ec8af2f8f0773d4ea183522580841e27 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1#include	<stddef.h>

   2#include	<ctype.h>

   3#include	<stdio.h>

   4#include	<stdlib.h>

   5#include	<string.h>

   6
   7#include	"mckc.h"

   8
   9extern char	*mml_names[MML_MAX];
  10int		mml_idx = 0;
  11extern	int	mml_num;
  12char	songlabel[64];
  13extern int	debug_flag;
  14extern char ef_name[256];
  15extern char inc_name[256];
  16extern char out_name[256];
  17extern int	warning_flag;
  18extern int	message_flag;
  19extern int	include_flag;
  20
  21
  22extern int	getFileSize( char *ptr );
  23extern int  Asc2Int( char *ptr, int *cnt );
  24extern void strupper( char *ptr );
  25extern char *readTextFile( char *filename );
  26extern FILE *openDmc(char *name);
  27extern char *skipSpaceOld( char *ptr );
  28extern char *skipSpace( char *ptr );
  29
  30void	putBankOrigin(FILE *fp, int bank);
  31int checkBankRange(int bank);
  32int double2int(double d);
  33#define arraysizeof(x) ( sizeof(x) / sizeof(x[0]) )

  34
  35
  36int		error_flag;					// ???????????0???
  37int		octave;						// ?????????
  38double	length;						// ??????
  39int		octave_flag = 0;			// ????????? ("<" ">" ???)
  40int		gate_denom = 8;				//q???????
  41int		pitch_correction = 0;			//??????????????????????LFO?????
  42
  43int		loop_flag;					// ????????????0???
  44int		putAsm_pos;					//
  45
  46char		*mml_file_name;				//???mml?????(???????????)
  47int		mml_line_pos;				//
  48int		mml_trk;				//
  49
  50int		nest;						// ?????????
  51LEN		track_count[MML_MAX][_TRACK_MAX][2];			// ??????????(??/????/?????/???????)
  52
  53int		volume_flag;				// ?????
  54double		tbase = 0.625;						// ????[frame/count]??
  55
  56int		transpose;					// ???????????
  57
  58int		sndgen_flag = 0;			// ???????
  59// ?????????
  60unsigned long	track_allow_flag = (TRACK(0)|TRACK(1)|TRACK(2)|NOISETRACK|DPCMTRACK);
  61//??????????
  62unsigned long	actual_track_flag = 0;
  63int		dpcm_track_num = 1;			// DPCM????
  64int		fds_track_num = 0;			// FDS????
  65int		vrc7_track_num = 0;			// VRC7????
  66int		vrc6_track_num = 0;			// VRC6????
  67int		n106_track_num = 0;			// ????(namco106)???????
  68int		fme7_track_num = 0;			// FME7????
  69int		mmc5_track_num = 0;			// MMC5????
  70
  71
  72int		bank_sel[_TRACK_MAX];	// 0 ? 127 = ??????? , 0xFF = ????
  73int		allow_bankswitching = 1;
  74int		dpcm_bankswitch = 0;
  75int		auto_bankswitch = 0;
  76int		curr_bank = 0x00;
  77int		bank_usage[128];		//bank_usage[0]?????????
  78int		bank_maximum = 0;		//8KB
  79int		dpcm_extra_bank_num = 0;	//8KB
  80
  81int tone_tbl[          _TONE_MAX][1024];	// Tone
  82int envelope_tbl[  _ENVELOPE_MAX][1024];	// Envelope
  83int pitch_env_tbl[_PITCH_ENV_MAX][1024];	// Pitch Envelope
  84int pitch_mod_tbl[_PITCH_MOD_MAX][   5];	// LFO
  85int arpeggio_tbl[  _ARPEGGIO_MAX][1024];	// Arpeggio
  86int fm_tone_tbl[    _FM_TONE_MAX][2+64];	// FM Tone
  87int vrc7_tone_tbl[_VRC7_TONE_MAX][2+64];	// VRC7 Tone(???????????)
  88int n106_tone_tbl[_N106_TONE_MAX][2+64];	// NAMCO106 Tone
  89int hard_effect_tbl[_HARD_EFFECT_MAX][5];	// FDS Hardware Effect
  90int effect_wave_tbl[_EFFECT_WAVE_MAX][33];	// Effect Wave (4088) Data
  91
  92DPCMTBL	dpcm_tbl[_DPCM_MAX];				// DPCM
  93unsigned char	*dpcm_data;	// DPCM?????
  94int	dpcm_size = 0;
  95int	dpcm_reststop = 0;
  96
  97char	song_name[1024] = "Song Name\0";
  98char	composer[1024] = "Artist\0";
  99char	maker[1024] = "Maker\0";
 100char	programer_buf[1024] = "";
 101char	*programer = NULL;
 102
 103const	char	str_track[] = _TRACK_STR;
 104
 105// ?????
 106enum {
 107	COMMAND_NOT_DEFINED = 0,
 108	DATA_ENDED_BY_LOOP_DEPTH_EXCEPT_0,
 109	DEFINITION_IS_WRONG,
 110	TONE_DEFINITION_IS_WRONG,
 111	ENVELOPE_DEFINITION_IS_WRONG,
 112	PITCH_ENVELOPE_DEFINITION_IS_WRONG,
 113	NOTE_ENVELOPE_DEFINITION_IS_WRONG,
 114	LFO_DEFINITION_IS_WRONG,
 115	DPCM_DEFINITION_IS_WRONG,
 116	DPCM_PARAMETER_IS_LACKING,
 117	FM_TONE_DEFINITION_IS_WRONG,
 118	ABNORMAL_PARAMETERS_OF_FM_TONE,
 119	N106_TONE_DEFINITION_IS_WRONG,
 120	ABNORMAL_PARAMETERS_OF_N106_TONE,
 121	ABNORMAL_VALUE_OF_REPEAT_COUNT,
 122	ABNORMAL_TONE_NUMBER,
 123	ABNORMAL_ENVELOPE_NUMBER,
 124	ABNORMAL_ENVELOPE_VALUE,
 125	ABNORMAL_PITCH_ENVELOPE_NUMBER,
 126	ABNORMAL_NOTE_ENVELOPE_NUMBER,
 127	ABNORMAL_LFO_NUMBER,
 128	ABNORMAL_PITCH_VALUE,
 129	ABNORMAL_VOLUME_VALUE,
 130	ABNORMAL_TEMPO_VALUE,
 131	ABNORMAL_QUANTIZE_VALUE,
 132	ABNORMAL_SHUFFLE_QUANTIZE_VALUE,
 133	ABNORMAL_SWEEP_VALUE,
 134	ABNORMAL_DETUNE_VALUE,
 135	ABNORMAL_SHIFT_AMOUNT,
 136	RELATIVE_VOLUME_WAS_USED_WITHOUT_SPECIFYING_VOLUME,
 137	VOLUME_RANGE_OVER_OF_RELATIVE_VOLUME,
 138	VOLUME_RANGE_UNDER_OF_RELATIVE_VOLUME,
 139	DATA_ENDED_BY_CONTINUATION_NOTE,
 140	DPCM_FILE_NOT_FOUND,
 141	DPCM_FILE_SIZE_OVER,
 142	DPCM_FILE_TOTAL_SIZE_OVER,
 143	INVALID_TRACK_HEADER,
 144	HARD_EFFECT_DEFINITION_IS_WRONG,
 145	EFFECT_WAVE_DEFINITION_IS_WRONG,
 146	ABNORMAL_HARD_EFFECT_NUMBER,
 147	ABNORMAL_TRANSPOSE_VALUE,
 148	TUPLET_BRACE_EMPTY,
 149	BANK_IDX_OUT_OF_RANGE,
 150	FRAME_LENGTH_LESSTHAN_0,
 151	ABNORMAL_NOTE_LENGTH_VALUE,
 152	PARAMETER_IS_LACKING,
 153	ABNORMAL_SELFDELAY_VALUE,
 154	CANT_USE_BANK_2_OR_3_WITH_DPCMBANKSWITCH,
 155	CANT_USE_SHIFT_AMOUNT_WITHOUT_PITCH_CORRECTION,
 156	UNUSE_COMMAND_IN_THIS_TRACK,
 157};
 158
 159// ??????
 160const	char	*ErrorlMessage[] = {
 161	"?????????????",							"Command not defined",
 162	"??????0?????????????",				"Data ended by loop depth except 0",
 163	"??????????",									"Definition is wrong",
 164	"PSG????????????",							"PSG Tone definition is wrong",
 165	"????????????????",						"Envelope definition is wrong",
 166	"???????????????????",				"Pitch envelope definition is wrong",
 167	"???????????????????",				"Note envelope definition is wrong",
 168	"LFO??????????",								"LFO definition is wrong",
 169	"DPCM??????????",								"DPCM definition is wrong",
 170	"DPCM??????????????",						"DPCM parameter is lacking",
 171	"FM????????????",							"FM tone definition is wrong",
 172	"FM??????????????",						"Abnormal parameters of FM tone",
 173	"namco106????????????",						"namco106 tone definition is wrong",
 174	"namco106??????????????",					"Abnormal parameters of namco106 tone",
 175	"?????????????",							"Abnormal value of repeat count",
 176	"?????????",									"Abnormal tone number",
 177	"?????????????",							"Abnormal envelope number",
 178	"?????????????",							"Abnormal envelope value",
 179	"??????????????????",					"Abnormal pitch envelope number",
 180	"??????????????????",					"Abnormal note envelope number",
 181	"LFO?????????",								"Abnormal LFO number",
 182	"?????????",									"Abnormal pitch value",
 183	"?????????",									"Abnormal volume value",
 184	"??????????",									"Abnormal tempo value",
 185	"?????????????",							"Abnormal quantize value",
 186	"??????????????????",							"Abnormal shuffle quantize value",
 187	"???????????",								"Abnormal sweep value",
 188	"?????????????",							"Abnormal detune value",
 189	"??????????????",							"Abnormal pitch shift amount value",
 190	"?????????????????????????",	"Relative volume was used without specifying volume",
 191	"????(+)????????????",					"Volume range over(+) of relative volume",
 192	"????(-)????????????",					"Volume range under(-) of relative volume",
 193	"??????????????????",					"Data ended by Continuation note",
 194	"DPCM??????????",								"DPCM file not found",
 195	"DPCM????????4081byte??????",				"DPCM file size over",
 196	"DPCM????????????????????",			"DPCM file total size over",
 197	"???????????????",						"Invalid track header",
 198	"??????????????????????",			"Hardware effect definition is wrong",
 199	"??????????????????",					"Effect wavetable definition is wrong",
 200	"?????????????????????",			"Abnormal hardware effect number",
 201	"??????????????",							"Abnormal transpose value",
 202	"???{}???????????",						"Tuplet {} empty",
 203	"????????????",						"Bank index out of range",
 204	"????????(unexpected error)",			"Frame length is negative value (unexpected error)",
 205	"?????????",					"Abnormal note length value",
 206	"??????????????",						"Parameter is lacking",
 207	"??????????????",						"Abnormal self-delay value",
 208	"DPCM????0x4000??????????2?3????????",		"Cannot use bank 2 or 3 if DPCM size is greater than 0x4000",
 209	"#PITCH-CORRECTION???????????????????????????",		"Cannot use SA<num> without #PITCH-CORRECTION",
 210	"????????????????????",				"Unuse command in this track",
 211};
 212
 213
 214
 215enum {
 216	TOO_MANY_INCLUDE_FILES = 0,
 217	FRAME_LENGTH_IS_0,
 218	REPEAT2_FRAME_ERROR_OVER_3,
 219	IGNORE_PMCKC_BANK_CHANGE,
 220	THIS_NUMBER_IS_ALREADY_USED,
 221	DPCM_FILE_SIZE_ERROR,
 222};
 223
 224const	char	*WarningMessage[] = {
 225	"??????????????????",					"Too many include files",
 226	"???????0???????",						"frame length is 0",
 227	"????2????????3????????????",	"Repeat2 frame error over 3 frames",
 228	"#BANK-CHANGE????#SETBANK, NB??????",		"Ignoring #SETBANK and NB if #BANK-CHANGE used",
 229	"????????????",				"This definition number is already used",
 230	"DPCM??? mod 16 ?1???????",			"DPCM size mod 16 is not 1",
 231};
 232
 233
 234
 235/*--------------------------------------------------------------
 236	?????
 237 Input:
 238	
 239 Output:
 240	none
 241--------------------------------------------------------------*/
 242void dispError( int no, char *file, int line )
 243{
 244	no = no*2;
 245	if( message_flag != 0 ) {
 246		no++;
 247	}
 248	if( file != NULL ) {
 249		printf( "Error  : %s %6d: %s\n", file, line, ErrorlMessage[no] );
 250	} else {
 251		printf( "Error  : %s\n", ErrorlMessage[no] );
 252	}
 253	error_flag = 1;
 254}
 255
 256
 257
 258/*--------------------------------------------------------------
 259	???????
 260 Input:
 261	
 262 Output:
 263	none
 264--------------------------------------------------------------*/
 265void dispWarning( int no, char *file, int line )
 266{
 267	if( warning_flag != 0 ) {
 268		no = no*2;
 269		if( message_flag != 0 ) {
 270			no++;
 271		}
 272		if( file != NULL ) {
 273			printf( "Warning: %s %6d: %s\n", file, line, WarningMessage[no] );
 274		} else {
 275			printf( "Warning: %s\n", WarningMessage[no] );
 276		}
 277	}
 278}
 279
 280
 281
 282/*--------------------------------------------------------------
 283	C?????????????
 284 Input:
 285	char	*ptr		:?????????
 286 Output:
 287	none
 288--------------------------------------------------------------*/
 289void deleteCRemark( char *ptr )
 290{
 291	int within_com = 0;
 292	while ( *ptr != '\0' ) {
 293		if ( *ptr == '/' && *(ptr + 1) == '*' ) {
 294			within_com = 1;
 295			*ptr++ = ' ';
 296			*ptr++ = ' ';
 297			while (*ptr) {
 298				if (*ptr == '*' && *(ptr + 1) == '/') {
 299					*ptr++ = ' ';
 300					*ptr++ = ' ';
 301					within_com = 0;
 302					break;
 303				}
 304				if ( *ptr != '\n' ) {
 305					*ptr = ' ';
 306				}
 307				ptr++;
 308			}
 309		} else {
 310			++ptr;
 311		}
 312	}
 313	if (within_com) {
 314		printf("Warning :");
 315		printf( message_flag 	? "Reached EOF in comment"
 316					: "?????????????????????????");
 317		printf("\n");
 318	}
 319}
 320
 321
 322//??
 323/*--------------------------------------------------------------
 324	???????
 325 Input:
 326	char	*ptr	:?????????
 327 Output:
 328	??
 329--------------------------------------------------------------*/
 330void deleteRemark( char *ptr )
 331{
 332	while( *ptr != '\0' ) {
 333		if ( *ptr == '/' || *ptr == ';' ) {
 334			while( *ptr != '\0' ) {
 335				if( *ptr != '\n' ) {
 336					*ptr++ = ' ';
 337				} else {
 338					ptr++;
 339					break;
 340				}
 341			}
 342		} else {
 343			ptr++;
 344		}
 345	}
 346}
 347
 348
 349
 350/*----------------------------------------------------------*/
 351/*	??????????								    */
 352/* Input:												    */
 353/*	char	*data		:?????????				    */
 354/* Output:												    */
 355/*	none												    */
 356/*----------------------------------------------------------*/
 357int getLineCount( char *ptr )
 358{
 359	int	line;
 360
 361	line = 0;
 362
 363	while( *ptr != '\0' ) {
 364		if( *ptr == '\n' ) {
 365			line++;
 366		}
 367		ptr++;
 368	}
 369	if( *(ptr-1) != '\n' ) {
 370		line++;
 371	}
 372	return line;
 373}
 374
 375
 376/*--------------------------------------------------------------
 377--------------------------------------------------------------*/
 378LINE *readMmlFile(char *fname)
 379{
 380	LINE *lptr;
 381	int line_count;
 382	int i;
 383	char *filestr;
 384	filestr = readTextFile(fname);
 385	
 386	if (filestr == NULL) {
 387		error_flag = 1;
 388		return NULL;
 389	}
 390	
 391	deleteCRemark(filestr);
 392	
 393	//skipSpace?????
 394	//deleteRemark(filestr);
 395
 396	line_count = getLineCount(filestr);
 397	lptr = (LINE *)malloc( (line_count+1)*sizeof(LINE) );	/* ?????????? */
 398
 399	lptr[0].status = _HEADER;		/* LINE?????[0]?malloc???	*/
 400	lptr[0].str    = filestr;		/* ???????????????? */
 401	lptr[0].line   = line_count;
 402	lptr[0].filename = fname;
 403	for( i = 1; i <= line_count; i++ ) {
 404		lptr[i].filename = fname;
 405		lptr[i].line = i;
 406	}
 407	return lptr;
 408}
 409
 410
 411
 412
 413/*--------------------------------------------------------------
 414	??/EOF?0(NULL)???(?????????????)
 415 Input:
 416	char	*ptr	:?????????
 417 Output:
 418	??
 419--------------------------------------------------------------*/
 420char *changeNULL( char *ptr )
 421{
 422	while( *ptr != '\n' ) {
 423		if( *ptr == '\0' ) break;
 424		ptr++;
 425	}
 426	*ptr = '\0';
 427	ptr++;
 428
 429	return ptr;
 430}
 431
 432
 433/*---------------------------------------------------------
 434  @hoge123 = { ag ae aeag g} ???
 435  
 436  @HOGE\s*(\d+)\s*(=|)\s*{.*?(}.*|)$
 437-----------------------------------------------------------*/
 438int setEffectSub(LINE *lptr, int line, int *ptr_status_end_flag, int min, int max, const int error_no)
 439{
 440	int param, cnt;
 441	char *temp;
 442	temp = skipSpace( lptr[line].str );
 443	param = Asc2Int( temp, &cnt );
 444	
 445	if (cnt == 0)
 446		goto on_error;
 447	if (param < min || max <= param)
 448		goto on_error;
 449	
 450	lptr[line].param = param;
 451	temp = skipSpace( temp+cnt );
 452	
 453	if ( *temp == '=' ) {
 454		temp++;
 455		temp = skipSpace( temp );
 456	}
 457	
 458	if ( *temp != '{' )
 459		goto on_error;
 460	
 461	lptr[line].str = temp;
 462	*ptr_status_end_flag = 1;
 463	
 464	while ( *temp != '\0' ) {
 465		if( *temp == '}' ) {
 466			*ptr_status_end_flag = 0;
 467		}
 468		temp++;
 469	}
 470	return 1;
 471on_error:
 472	lptr[line].status = 0;
 473	dispError( error_no, lptr[line].filename, line );
 474	return 0;
 475}
 476
 477
 478
 479
 480/*--------------------------------------------------------------
 481	????????
 482 Input:
 483	char	*ptr	:?????????
 484 Output:
 485	??
 486--------------------------------------------------------------*/
 487void getLineStatus(LINE *lptr, int inc_nest )
 488{
 489	const HEAD head[] = {
 490		{ "#TITLE",          _TITLE          },
 491		{ "#COMPOSER",       _COMPOSER       },
 492		{ "#MAKER",          _MAKER          },
 493		{ "#PROGRAMER",      _PROGRAMER      },
 494		{ "#OCTAVE-REV",     _OCTAVE_REV     },
 495		{ "#GATE-DENOM",        _GATE_DENOM  },
 496		{ "#INCLUDE",        _INCLUDE        },
 497		{ "#EX-DISKFM",      _EX_DISKFM      },
 498		{ "#EX-NAMCO106",    _EX_NAMCO106    },
 499		{ "#EX-VRC7",		 _EX_VRC7		 },
 500		{ "#EX-VRC6",		 _EX_VRC6		 },
 501		{ "#EX-FME7",		 _EX_FME7		 },
 502		{ "#EX-MMC5",		 _EX_MMC5		 },
 503		{ "#NO-BANKSWITCH",    _NO_BANKSWITCH    },
 504		{ "#AUTO-BANKSWITCH",    _AUTO_BANKSWITCH    },
 505		{ "#PITCH-CORRECTION",       _PITCH_CORRECTION    },
 506		{ "#BANK-CHANGE",    _BANK_CHANGE    },
 507		{ "#SETBANK",    	 _SET_SBANK	     },
 508		{ "#EFFECT-INCLUDE", _EFFECT_INCLUDE },
 509		{ "#DPCM-RESTSTOP", _DPCM_RESTSTOP },
 510		{ "@DPCM",           _SET_DPCM_DATA  },
 511		{ "@MP",             _SET_PITCH_MOD  },
 512		{ "@EN",             _SET_ARPEGGIO   },
 513		{ "@EP",             _SET_PITCH_ENV  },
 514		{ "@FM",             _SET_FM_TONE    },
 515		{ "@MH",             _SET_HARD_EFFECT},
 516		{ "@MW",             _SET_EFFECT_WAVE},
 517		{ "@OP",             _SET_VRC7_TONE  },
 518		{ "@N",              _SET_N106_TONE  },			
 519		{ "@V",              _SET_ENVELOPE   },
 520		{ "@",               _SET_TONE       },
 521		{ "",                -1              },
 522	};
 523
 524	int	line, i, param, cnt, track_flag, status_end_flag, bank,bank_ch;
 525	char	*temp, *temp2;
 526	char *ptr;
 527	ptr = lptr[0].str;
 528
 529	status_end_flag = 0;
 530
 531	for( line = 1; line <= lptr->line; line++ ) {
 532		ptr = skipSpace( ptr );
 533		/* ????????????????? */
 534		if( ((lptr[line-1].status&_SET_EFFECT) != 0) && (status_end_flag != 0) ) {
 535			lptr[line].status = lptr[line-1].status|_SAME_LINE;
 536			lptr[line].param  = lptr[line-1].param;
 537			lptr[line].str = ptr;
 538			temp = ptr;
 539			ptr = changeNULL( ptr );
 540			status_end_flag = 1;
 541			while( *temp != '\0' ) {
 542				if( *temp == '}' ) {
 543					status_end_flag = 0;
 544				}
 545				temp++;
 546			}
 547		/* ?????????????????? */
 548		} else if( *ptr == '\n' || *ptr == '\0' ) {
 549			lptr[line].status = 0;
 550			lptr[line].str = ptr;
 551			ptr = changeNULL( ptr );
 552		} else {
 553			/* #/@???????????????????????? */
 554			if( *ptr == '#' || *ptr == '@' ) {
 555				i = 1;
 556				while( (*(ptr+i) != ' ') && (*(ptr+i) != '\t') && (*(ptr+i) != '\n') ) {
 557					*(ptr+i) = (char)toupper( *(ptr+i) );
 558					i++;
 559				}
 560				/* ?????????????????? */
 561				for( i = 0; head[i].status != -1; i++ ) {
 562					if( strncmp( ptr, head[i].str, strlen(head[i].str) ) == 0 ) {
 563						break;
 564					}
 565				}
 566				lptr[line].status = head[i].status;
 567				lptr[line].str = skipSpaceOld( ptr+strlen(head[i].str) );	/* ??????????????????? */
 568			} else if( strchr( str_track, *ptr ) ) {
 569				track_flag = 0;
 570				while( strchr( str_track, *ptr ) ) {
 571					temp = strchr( str_track, *ptr );
 572					if( temp == NULL ) {
 573						dispError( INVALID_TRACK_HEADER, lptr[line].filename, line );
 574					} else {
 575						track_flag |= (1<<(temp-str_track));
 576					}
 577					ptr++;
 578				}
 579				// ???????????
 580				for (i = 0; i < _TRACK_MAX; i++) {
 581					if( (TRACK(i) & track_flag) && !(TRACK(i) & track_allow_flag) ) {
 582						dispError( INVALID_TRACK_HEADER, lptr[line].filename, line );
 583						track_flag &= ~TRACK(i);
 584					}
 585				}
 586				
 587				if( track_flag != 0 ) {
 588					lptr[line].status = _TRACK;
 589					lptr[line].param = track_flag;
 590					lptr[line].str = skipSpace( ptr );
 591					actual_track_flag |= track_flag;				
 592				} else {
 593					lptr[line].status = 0;
 594					lptr[line].param = 0;
 595				}
 596			} else {
 597				lptr[line].status = -1;
 598				lptr[line].str = skipSpace( ptr );
 599			}
 600			ptr = changeNULL( ptr );
 601
 602			switch( lptr[line].status ) {
 603			/* Include??????? */
 604			  case _INCLUDE:
 605				if( inc_nest > 16 ) {				/* ????16???(???????????????) */
 606					dispWarning( TOO_MANY_INCLUDE_FILES, lptr[line].filename, line );
 607					lptr[line].status = 0;
 608				} else {
 609					LINE *ltemp;
 610					temp = skipSpaceOld( lptr[line].str ); /* /????????????? */
 611					ltemp = readMmlFile(temp);
 612					if( ltemp != NULL ) {
 613						lptr[line].inc_ptr = ltemp;
 614						++inc_nest;
 615						getLineStatus(lptr[line].inc_ptr, inc_nest);
 616						--inc_nest;
 617					} else {
 618						lptr[line].status = 0;					/* ???????????????? */
 619						error_flag = 1;
 620					}
 621				}
 622				break;
 623			/* LFO???? */
 624			  case _SET_PITCH_MOD:
 625				setEffectSub(lptr, line, &status_end_flag, 0, _PITCH_MOD_MAX, LFO_DEFINITION_IS_WRONG);
 626				break;
 627			/* ????????????? */
 628			  case _SET_PITCH_ENV:
 629				setEffectSub(lptr, line, &status_end_flag, 0, _PITCH_ENV_MAX, PITCH_ENVELOPE_DEFINITION_IS_WRONG);
 630				break;
 631			/* ???????????? */
 632			  case _SET_ENVELOPE:
 633				setEffectSub(lptr, line, &status_end_flag, 0, _ENVELOPE_MAX, ENVELOPE_DEFINITION_IS_WRONG);
 634				break;
 635			/* ???? */
 636			  case _SET_TONE:
 637				setEffectSub(lptr, line, &status_end_flag, 0, _TONE_MAX, TONE_DEFINITION_IS_WRONG);
 638				break;
 639			/* ????? */
 640			  case _SET_ARPEGGIO:
 641				setEffectSub(lptr, line, &status_end_flag, 0, _ARPEGGIO_MAX, NOTE_ENVELOPE_DEFINITION_IS_WRONG);
 642				break;
 643			/* DPCM?????? */
 644			  case _SET_DPCM_DATA:
 645				setEffectSub(lptr, line, &status_end_flag, 0, _DPCM_MAX, DPCM_DEFINITION_IS_WRONG);
 646				break;
 647			  /* VRC7 Tone */
 648			  case _SET_VRC7_TONE:
 649				setEffectSub(lptr, line, &status_end_flag, 0, _VRC7_TONE_MAX, FM_TONE_DEFINITION_IS_WRONG);
 650				break;
 651			/* FM?? */
 652			  case _SET_FM_TONE:
 653				setEffectSub(lptr, line, &status_end_flag, 0, _FM_TONE_MAX, FM_TONE_DEFINITION_IS_WRONG);
 654				break;
 655			/* namco106???? */
 656			  case _SET_N106_TONE:
 657				setEffectSub(lptr, line, &status_end_flag, 0, _N106_TONE_MAX, N106_TONE_DEFINITION_IS_WRONG);
 658				break;
 659			/* ??????????? */
 660			  case _SET_HARD_EFFECT:
 661				setEffectSub(lptr, line, &status_end_flag, 0, _HARD_EFFECT_MAX, HARD_EFFECT_DEFINITION_IS_WRONG);
 662				break;
 663			/* ??????? */
 664			  case _SET_EFFECT_WAVE:
 665				setEffectSub(lptr, line, &status_end_flag, 0, _EFFECT_WAVE_MAX, EFFECT_WAVE_DEFINITION_IS_WRONG);
 666				break;
 667			/* DISKSYSTEM FM??????? */
 668			  case _EX_DISKFM:
 669				sndgen_flag |= BDISKFM;
 670				track_allow_flag |= FMTRACK;
 671				fds_track_num = 1;
 672				break;
 673			/* VRC7 FM??????? */
 674			  case _EX_VRC7:
 675				sndgen_flag |= BVRC7;
 676				track_allow_flag |= VRC7TRACK;
 677				vrc7_track_num = 6;
 678				break;
 679			/* VRC6 ??????? */
 680			  case _EX_VRC6:
 681				sndgen_flag |= BVRC6;
 682				track_allow_flag |= VRC6TRACK;
 683				vrc6_track_num = 3;
 684				break;
 685			/* FME7 ??????? */
 686			  case _EX_FME7:
 687				sndgen_flag |= BFME7;
 688				track_allow_flag |= FME7TRACK;
 689				fme7_track_num = 3;
 690				break;
 691			/* MMC5 ??????? */
 692			  case _EX_MMC5:
 693				sndgen_flag |= BMMC5;
 694				track_allow_flag |= MMC5TRACK;
 695				mmc5_track_num = 2;
 696				break;
 697			/* namco106 ????????? */
 698			  case _EX_NAMCO106:
 699				temp = skipSpace( lptr[line].str );
 700				param = Asc2Int( temp, &cnt );
 701				if( cnt != 0 && (0 <= param && param <= 8) ) {
 702					if( param == 0 ) {
 703						param = 1;
 704					}
 705					lptr[line].param = param;
 706					n106_track_num = param;
 707					sndgen_flag |= BNAMCO106;
 708					for (i = 0; i < param; i++) {
 709						track_allow_flag |= TRACK(BN106TRACK+i);
 710					}
 711				} else {
 712					dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 713					lptr[line].status = 0;
 714				}
 715				break;
 716			/* DPCM sound stops on 'r' command */
 717			  case _DPCM_RESTSTOP:
 718				dpcm_reststop = 1;
 719				break;
 720			/* NSF mapper ? bankswitching ?? */
 721			  case _NO_BANKSWITCH:
 722				allow_bankswitching = 0;
 723				break;
 724			/* ????????? */
 725			  case _AUTO_BANKSWITCH:
 726				temp = skipSpace( lptr[line].str );
 727				param = Asc2Int( temp, &cnt );
 728				if ( cnt != 0 && (0 <= param && param <= 8192)) {
 729					// ?????????????
 730					if (!auto_bankswitch) {
 731						bank_usage[0] = 8192 - param;
 732					}
 733					auto_bankswitch = 1;
 734				} else {
 735					dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 736				}
 737				break;
 738			/* ???????????(?????????) */
 739			  case _BANK_CHANGE:
 740				/*
 741					#BANK-CHANGE <num0>,<num1>
 742					?????????????????<num0>???????0?2???
 743					?????<num1>????????1?14???????1?A?????
 744					????????2=B?3=C?�P=7????????
 745					??????????????????
 746					#BANK-CHANGE	n
 747					#BANK-CHANGE	0,n
 748					
 749					#BANK-CHANGE?????????????????????
 750					???????????????????????????????????
 751					ppmck????????????????????
 752					
 753					mckc????MML????????????
 754					??????????
 755				
 756				*/
 757				/*
 758					???????????????
 759				
 760					mckc
 761					A B C D E | F | P Q R  S  T  U  V  W
 762					1 2 3 4 5 | 6 | 7 8 9 10 11 12 13 14
 763					pmckc
 764					A B C D E | F | G H I  J  K  L |  P  Q  R  S  T  U  V  W
 765					1 2 3 4 5 | 6 | 7 8 9 10 11 12 | 13 14 15 16 17 18 19 20
 766					ppmckc
 767					A B C D E | F | G H I  J  K  L |  M  N  O |  P  Q  R  S  T  U  V  W |  X  Y  Z |  a  b
 768					1 2 3 4 5 | 6 | 7 8 9 10 11 12 | 13 14 15 | 16 17 18 19 20 21 22 23 | 24 25 26 | 27 28
 769				
 770					mckc????MML????????????
 771					P??? ??? 9 ????OK?(????????????????)
 772					??????????????????????(ry
 773				*/
 774				temp = skipSpace( lptr[line].str );
 775				param = Asc2Int( temp, &cnt );
 776				if( cnt != 0 ) {
 777					temp += cnt;
 778					temp = skipSpace( temp );
 779					if( *temp == ',' ) {
 780						/* ???? */
 781						temp++;
 782						if( (0 <= param) && (param <= 2) ) {
 783							bank = param; /* 0,1,2?1,2,3??? */
 784							//printf( "bank: %d\n", bank );
 785							temp = skipSpace( temp );
 786							param = Asc2Int( temp, &cnt ); /* 1,2,3 ?ABC??? ??? 0,1,2??? */
 787							if( cnt != 0 && (1 <= param && param <= _TRACK_MAX) ) {
 788								//bank_change[bank] = param-1;
 789								bank_sel[param-1] = bank+1;
 790							} else {
 791								dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 792								lptr[line].status = 0;
 793								//bank_change[bank] = 0xff;
 794							}
 795						} else {
 796							dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 797							lptr[line].status = 0;
 798						}
 799					} else {
 800						/* ????? bank 1???? */
 801						if( cnt != 0 && (1 <= param && param <= _TRACK_MAX) ) {
 802							//bank_change[0] = param-1;
 803							bank_sel[param-1] = 1;
 804						} else {
 805							dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 806							lptr[line].status = 0;
 807							//bank_change[0] = 0xff;
 808						}
 809					}
 810				} else {
 811					dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 812					lptr[line].status = 0;
 813				}
 814				break;
 815			/* ??????? */
 816			  case _SET_SBANK:
 817				temp = skipSpace( lptr[line].str );
 818				
 819				if ((temp2 = strchr(str_track, *temp)) != NULL) {
 820					/* ABC..????????? */
 821					param = (temp2 - str_track) + 1;
 822					temp++;
 823				} else {
 824					/* ??????????? */
 825					param = Asc2Int( temp, &cnt );
 826					if (cnt == 0) {
 827						dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 828						lptr[line].status = 0;
 829						break;
 830					} else {
 831						temp += cnt;
 832					}
 833				}
 834				
 835				temp = skipSpace( temp );
 836				if( *temp == ',' ) {		/* ????? */
 837					temp++;
 838					if( (1 <= param) && (param <= _TRACK_MAX) ) {
 839						bank_ch = param;
 840						// printf( "bank: %d\n", bank );
 841						temp = skipSpace( temp );
 842						param = Asc2Int( temp, &cnt );
 843						if( cnt != 0) {
 844							if (checkBankRange(param) == 0) {
 845								dispError( BANK_IDX_OUT_OF_RANGE, lptr[line].filename, line );
 846								break;
 847							}
 848							bank_sel[bank_ch-1] = param;
 849						} else {
 850							dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 851							lptr[line].status = 0;
 852						}
 853					} else {
 854						dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 855						lptr[line].status = 0;
 856					}
 857				} else {
 858					dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 859					lptr[line].status = 0;
 860				}
 861				break;
 862
 863			/*  */
 864			  case _EFFECT_INCLUDE:
 865				include_flag = 1;
 866				break;
 867			/* ???? */
 868			  case _TITLE:
 869				temp = skipSpaceOld( lptr[line].str );
 870				strncpy( song_name, temp, 1023 );
 871				break;
 872			/* ??? */
 873			  case _COMPOSER:
 874				temp = skipSpaceOld( lptr[line].str );
 875				strncpy( composer, temp, 1023 );
 876				break;
 877			/* ???? */
 878			  case _MAKER:
 879				temp = skipSpaceOld( lptr[line].str );
 880				strncpy( maker, temp, 1023 );
 881				break;
 882			/* ????? */
 883			  case _PROGRAMER:
 884				temp = skipSpaceOld( lptr[line].str );
 885				strncpy( programer_buf, temp, 1023 );
 886				programer = programer_buf;
 887				break;
 888			/* ?????????? */
 889			  case _OCTAVE_REV:
 890				temp = skipSpace( lptr[line].str );
 891				param = Asc2Int( temp, &cnt );
 892				if( cnt != 0) {
 893					if( param == 0 ) {
 894						octave_flag = 0;
 895					} else {
 896						octave_flag = 1;
 897					}
 898				} else {
 899					octave_flag = 1;
 900				}
 901				break;
 902			/* q???????? */
 903			  case _GATE_DENOM:
 904				temp = skipSpace( lptr[line].str );
 905				param = Asc2Int( temp, &cnt );
 906				if( cnt != 0 && param > 0) {
 907					gate_denom = param;
 908				} else {
 909					dispError( DEFINITION_IS_WRONG, lptr[line].filename, line );
 910					lptr[line].status = 0;
 911				}
 912				break;
 913			/*?????????????????LFO????? */
 914			  case _PITCH_CORRECTION:
 915				pitch_correction = 1;
 916				break;
 917			/* ????? */
 918			  case -1:
 919				if( (lptr[line-1].status&_SET_EFFECT) != 0 ) {
 920					lptr[line].status = lptr[line-1].status|_SAME_LINE;
 921					lptr[line].str = ptr;
 922				} else {
 923					/* ??????? */
 924					dispError( COMMAND_NOT_DEFINED, lptr[line].filename, line );
 925					lptr[line].status = 0;
 926					lptr[line].str = ptr;
 927				}
 928				break;
 929			}
 930		}
 931	}
 932}
 933
 934
 935
 936/*--------------------------------------------------------------
 937	?????
 938 Input:
 939	
 940 Output:
 941	??
 942--------------------------------------------------------------*/
 943void getTone( LINE *lptr )
 944{
 945	int		line, i, no, end_flag, offset, num, cnt;
 946	char	*ptr;
 947
 948	cnt = 0;
 949
 950	for( line = 1; line <= lptr->line; line++ ) {
 951		/* ???????? */
 952		if( lptr[line].status == _SET_TONE ) {
 953			no = lptr[line].param;				/* ?????? */
 954			ptr = lptr[line].str;
 955			ptr++;								/* '{'?????? */
 956			if (tone_tbl[no][0] != 0) {
 957				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
 958			}
 959			tone_tbl[no][0] = 0;
 960			offset = 0;
 961			i = 1;
 962			end_flag = 0;
 963			while( end_flag == 0 ) {
 964				ptr = skipSpace( ptr );
 965				switch( *ptr ) {
 966				  case '}':
 967					if (tone_tbl[no][0] >= 1) {
 968						tone_tbl[no][i] = EFTBL_END;
 969						tone_tbl[no][0]++;
 970					} else {
 971						dispError( PARAMETER_IS_LACKING, lptr[line].filename, line );
 972						tone_tbl[no][0] = 0;
 973					}
 974					end_flag = 1;
 975					line += offset;
 976					break;
 977				  case '|':
 978					tone_tbl[no][i] = EFTBL_LOOP;
 979					tone_tbl[no][0]++;
 980					i++;
 981					ptr++;
 982					break;
 983				  case '\0':
 984					offset++;
 985					if( line+offset <= lptr->line ) {
 986						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
 987							ptr = lptr[line+offset].str;
 988						}
 989					} else {
 990						dispError( TONE_DEFINITION_IS_WRONG, lptr[line].filename, line );
 991						tone_tbl[no][0] = 0;
 992						end_flag = 1;
 993					}
 994					break;
 995				  default:
 996					num = Asc2Int( ptr, &cnt );
 997					//vrc6???????(??????MMC5?3??)
 998					//if( cnt != 0 && (0 <= num && num <= 3) ) {
 999					if( cnt != 0 && (0 <= num && num <= 7) ) {
1000						tone_tbl[no][i] = num;
1001						tone_tbl[no][0]++;
1002						ptr += cnt;
1003						i++;
1004					} else {
1005						dispError( TONE_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1006						tone_tbl[no][0] = 0;
1007						end_flag = 1;
1008					}
1009					break;
1010				}
1011				ptr = skipSpace( ptr );
1012				if( *ptr == ',' ) {
1013					ptr++;
1014				}
1015			}
1016		/* ???????_SAME_LINE?????? */
1017		} else if( lptr[line].status == (_SET_TONE|_SAME_LINE) ) {
1018			dispError( TONE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1019		/* ???????????? */
1020		} else if( lptr[line].status == _INCLUDE ) {
1021			getTone( lptr[line].inc_ptr );
1022		}
1023	}
1024}
1025
1026
1027
1028/*--------------------------------------------------------------
1029	?????????
1030 Input:
1031	
1032 Output:
1033	??
1034--------------------------------------------------------------*/
1035void getEnvelope( LINE *lptr )
1036{
1037	int		line, i, no, end_flag, offset, num, cnt;
1038	char	*ptr;
1039
1040	cnt = 0;
1041
1042	for( line = 1; line <= lptr->line; line++ ) {
1043		/* ???????????? */
1044		if( lptr[line].status == _SET_ENVELOPE ) {
1045			no = lptr[line].param;				/* ?????????? */
1046			ptr = lptr[line].str;
1047			ptr++;								/* '{'?????? */
1048			if (envelope_tbl[no][0] != 0) {
1049				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1050			}
1051			envelope_tbl[no][0] = 0;
1052			offset = 0;
1053			i = 1;
1054			end_flag = 0;
1055			while( end_flag == 0 ) {
1056				ptr = skipSpace( ptr );
1057				switch( *ptr ) {
1058				  case '}':
1059					if (envelope_tbl[no][0] >= 1) {
1060						envelope_tbl[no][i] = EFTBL_END;
1061						envelope_tbl[no][0]++;
1062					} else {
1063						dispError( PARAMETER_IS_LACKING, lptr[line].filename, line );
1064						envelope_tbl[no][0] = 0;
1065					}
1066					end_flag = 1;
1067					line += offset;
1068					break;
1069				  case '|':
1070					envelope_tbl[no][i] = EFTBL_LOOP;
1071					envelope_tbl[no][0]++;
1072					i++;
1073					ptr++;
1074					break;
1075				  case '\0':
1076					offset++;
1077					if( line+offset <= lptr->line ) {
1078						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
1079							ptr = lptr[line+offset].str;
1080						}
1081					} else {
1082						dispError( ENVELOPE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1083						envelope_tbl[no][0] = 0;
1084						end_flag = 1;
1085					}
1086					break;
1087				  default:
1088					num = Asc2Int( ptr, &cnt );
1089					if( cnt != 0 && (0 <= num && num <= 63) ) {
1090						envelope_tbl[no][i] = num;
1091						envelope_tbl[no][0]++;
1092						ptr += cnt;
1093						i++;
1094					} else {
1095						dispError( ENVELOPE_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1096						envelope_tbl[no][0] = 0;
1097						end_flag = 1;
1098					}
1099					break;
1100				}
1101				ptr = skipSpace( ptr );
1102				if( *ptr == ',' ) {
1103					ptr++;
1104				}
1105			}
1106		/* ???????????_SAME_LINE?????? */
1107		} else if( lptr[line].status == (_SET_ENVELOPE|_SAME_LINE) ) {
1108			dispError( ENVELOPE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1109		/* ???????????? */
1110		} else if( lptr[line].status == _INCLUDE ) {
1111			getEnvelope( lptr[line].inc_ptr );
1112		}
1113	}
1114}
1115
1116/*--------------------------------------------------------------
1117	????????????
1118 Input:
1119	
1120 Output:
1121	??
1122--------------------------------------------------------------*/
1123void getPitchEnv( LINE *lptr )
1124{
1125	int		line, i, no, end_flag, offset, num, cnt;
1126	char	*ptr;
1127
1128	cnt = 0;
1129
1130	for( line = 1; line <= lptr->line; line++ ) {
1131		/* ??????????????? */
1132		if( lptr[line].status == _SET_PITCH_ENV ) {
1133			no = lptr[line].param;				/* ????????????? */
1134			ptr = lptr[line].str;
1135			ptr++;								/* '{'?????? */
1136			if (pitch_env_tbl[no][0] != 0) {
1137				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1138			}
1139			pitch_env_tbl[no][0] = 0;
1140			offset = 0;
1141			i = 1;
1142			end_flag = 0;
1143			while( end_flag == 0 ) {
1144				ptr = skipSpace( ptr );
1145				switch( *ptr ) {
1146				  case '}':
1147					if (pitch_env_tbl[no][0] >= 1) {
1148						pitch_env_tbl[no][i] = EFTBL_END;
1149						pitch_env_tbl[no][0]++;
1150					} else {
1151						dispError( PARAMETER_IS_LACKING, lptr[line].filename, line );
1152						pitch_env_tbl[no][0] = 0;
1153					}
1154					end_flag = 1;
1155					line += offset;
1156					break;
1157				  case '|':
1158					pitch_env_tbl[no][i] = EFTBL_LOOP;
1159					pitch_env_tbl[no][0]++;
1160					i++;
1161					ptr++;
1162					break;
1163				  case '\0':
1164					offset++;
1165					if( line+offset <= lptr->line ) {
1166						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
1167							ptr = lptr[line+offset].str;
1168						}
1169					} else {
1170						dispError( PITCH_ENVELOPE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1171						pitch_env_tbl[no][0] = 0;
1172						end_flag = 1;
1173					}
1174					break;
1175				  default:
1176					num = Asc2Int( ptr, &cnt );
1177					if( cnt != 0 && (-127 <= num && num <= 127) ) {
1178						pitch_env_tbl[no][i] = num;
1179						pitch_env_tbl[no][0]++;
1180						ptr += cnt;
1181						i++;
1182					} else {
1183						dispError( PITCH_ENVELOPE_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1184						pitch_env_tbl[no][0] = 0;
1185						end_flag = 1;
1186					}
1187					break;
1188				}
1189				ptr = skipSpace( ptr );
1190				if( *ptr == ',' ) {
1191					ptr++;
1192				}
1193			}
1194		/* ??????????????_SAME_LINE?????? */
1195		} else if( lptr[line].status == (_SET_PITCH_ENV|_SAME_LINE) ) {
1196			dispError( PITCH_ENVELOPE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1197		/* ???????????? */
1198		} else if( lptr[line].status == _INCLUDE ) {
1199			getPitchEnv( lptr[line].inc_ptr );
1200		}
1201	}
1202}
1203
1204/*--------------------------------------------------------------
1205	??????????????
1206 Input:
1207	
1208 Output:
1209	??
1210--------------------------------------------------------------*/
1211void getPitchMod( LINE *lptr )
1212{
1213	int		line, i, no, end_flag, offset, num, cnt;
1214	char	*ptr;
1215
1216	cnt = 0;
1217
1218	for( line = 1; line <= lptr->line; line++ ) {
1219		/* ???????? */
1220		if( lptr[line].status == _SET_PITCH_MOD ) {
1221			no = lptr[line].param;				/* LFO???? */
1222			ptr = lptr[line].str;
1223			ptr++;								/* '{'?????? */
1224			if (pitch_mod_tbl[no][0] != 0) {
1225				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1226			}
1227			pitch_mod_tbl[no][0] = 0;
1228			offset = 0;
1229			i = 1;
1230			end_flag = 0;
1231			while( end_flag == 0 ) {
1232				ptr = skipSpace( ptr );
1233				switch( *ptr ) {
1234				  case '}':
1235					if (pitch_mod_tbl[no][0] >= 3) {
1236						//OK.
1237					} else {
1238						dispError( PARAMETER_IS_LACKING, lptr[line].filename, line );
1239						pitch_mod_tbl[no][0] = 0;
1240					}
1241					end_flag = 1;
1242					line += offset;
1243					break;
1244				  case '\0':
1245					offset++;
1246					if( line+offset <= lptr->line ) {
1247						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
1248							ptr = lptr[line+offset].str;
1249						}
1250					} else {
1251						dispError( LFO_DEFINITION_IS_WRONG, lptr[line].filename, line );
1252						pitch_mod_tbl[no][0] = 0;
1253						end_flag = 1;
1254					}
1255					break;
1256				  default:
1257					num = Asc2Int( ptr, &cnt );
1258					if( cnt != 0 ) {
1259						switch( i ) {
1260						  case 1:
1261						  case 2:
1262						  case 3:
1263							if( 0 <= num && num <= 255 ) {
1264								pitch_mod_tbl[no][i] = num;
1265								pitch_mod_tbl[no][0]++;
1266								ptr += cnt;
1267								i++;
1268							} else {
1269								dispError( LFO_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1270								pitch_mod_tbl[no][0] = 0;
1271								end_flag = 1;
1272							}
1273							break;
1274						  case 4:
1275							if( 0 <= num && num <= 255 ) {
1276								pitch_mod_tbl[no][i] = num;
1277								pitch_mod_tbl[no][0]++;
1278								ptr += cnt;
1279								i++;
1280							} else {
1281								dispError( LFO_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1282								pitch_mod_tbl[no][0] = 0;
1283								end_flag = 1;
1284							}
1285							break;
1286						  default:
1287							dispError( LFO_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1288							pitch_mod_tbl[no][0] = 0;
1289							end_flag = 1;
1290							break;
1291						}
1292					} else {
1293						dispError( LFO_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1294						pitch_mod_tbl[no][0] = 0;
1295						end_flag = 1;
1296					}
1297					break;
1298				}
1299				ptr = skipSpace( ptr );
1300				if( *ptr == ',' ) {
1301					ptr++;
1302				}
1303			}
1304		/* ???????_SAME_LINE?????? */
1305		} else if( lptr[line].status == (_SET_PITCH_MOD|_SAME_LINE) ) {
1306			dispError( LFO_DEFINITION_IS_WRONG, lptr[line].filename, line );
1307		/* ???????????? */
1308		} else if( lptr[line].status == _INCLUDE ) {
1309			getPitchMod( lptr[line].inc_ptr );
1310		}
1311	}
1312}
1313
1314
1315
1316/*--------------------------------------------------------------
1317	????????????
1318 Input:
1319	
1320 Output:
1321	??
1322--------------------------------------------------------------*/
1323void getArpeggio( LINE *lptr )
1324{
1325	int		line, i, no, end_flag, offset, num, cnt;
1326	char	*ptr;
1327
1328	cnt = 0;
1329
1330	for( line = 1; line <= lptr->line; line++ ) {
1331		/* ??????????? */
1332		if( lptr[line].status == _SET_ARPEGGIO ) {
1333			no = lptr[line].param;				/* ?????????? */
1334			ptr = lptr[line].str;
1335			ptr++;								/* '{'?????? */
1336			if (arpeggio_tbl[no][0] != 0) {
1337				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1338			}
1339			arpeggio_tbl[no][0] = 0;
1340			offset = 0;
1341			i = 1;
1342			end_flag = 0;
1343			while( end_flag == 0 ) {
1344				ptr = skipSpace( ptr );
1345				switch( *ptr ) {
1346				  case '}':
1347					if (arpeggio_tbl[no][0] >= 1) {
1348						arpeggio_tbl[no][i] = EFTBL_END;
1349						arpeggio_tbl[no][0]++;
1350					} else {
1351						dispError( PARAMETER_IS_LACKING, lptr[line].filename, line );
1352						arpeggio_tbl[no][0] = 0;
1353					}
1354					end_flag = 1;
1355					line += offset;
1356					break;
1357				  case '|':
1358					arpeggio_tbl[no][i] = EFTBL_LOOP;
1359					arpeggio_tbl[no][0]++;
1360					i++;
1361					ptr++;
1362					break;
1363				  case '\0':
1364					offset++;
1365					if( line+offset <= lptr->line ) {
1366						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
1367							ptr = lptr[line+offset].str;
1368						}
1369					} else {
1370						dispError( NOTE_ENVELOPE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1371						arpeggio_tbl[no][0] = 0;
1372						end_flag = 1;
1373					}
1374					break;
1375				  default:
1376					num = Asc2Int( ptr, &cnt );
1377					if( cnt != 0 ) {
1378						if( num >= 0 ) {
1379							arpeggio_tbl[no][i] = num;
1380						} else {
1381							arpeggio_tbl[no][i] = (-num)|0x80;
1382						}	
1383						arpeggio_tbl[no][0]++;
1384						ptr += cnt;
1385						i++;
1386					} else {
1387						dispError( NOTE_ENVELOPE_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1388						arpeggio_tbl[no][0] = 0;
1389						end_flag = 1;
1390					}
1391					break;
1392				}
1393				ptr = skipSpace( ptr );
1394				if( *ptr == ',' ) {
1395					ptr++;
1396				}
1397			}
1398		/* ??????????_SAME_LINE?????? */
1399		} else if( lptr[line].status == (_SET_ARPEGGIO|_SAME_LINE) ) {
1400			dispError( NOTE_ENVELOPE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1401		/* ???????????? */
1402		} else if( lptr[line].status == _INCLUDE ) {
1403			getArpeggio( lptr[line].inc_ptr );
1404		}
1405	}
1406}
1407
1408
1409
1410/*--------------------------------------------------------------
1411	DPCM???
1412 Input:
1413	
1414 Output:
1415	??
1416--------------------------------------------------------------*/
1417void getDPCM( LINE *lptr )
1418{
1419	int		line, i, no, offset, end_flag, num, cnt;
1420	char	*ptr;
1421	FILE	*fp;
1422	DPCMTBL	*tbl;
1423
1424	cnt = 0;
1425
1426	for( line = 1; line <= lptr->line; line++ ) {
1427		// DPCM??????
1428		if( lptr[line].status == _SET_DPCM_DATA ) {
1429			no = lptr[line].param;				// DPCM????
1430			ptr = lptr[line].str;
1431			ptr++;								// '{'??????
1432			tbl = &dpcm_tbl[no];
1433			if (tbl->flag != 0) {
1434				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1435			}
1436			tbl->flag = 1;						// ????????
1437			tbl->index = -1;
1438			tbl->fname = NULL;
1439			tbl->freq = 0;
1440			tbl->size = 0;
1441			tbl->delta_init = 0;
1442			offset = 0;
1443			i = 0;
1444			end_flag = 0;
1445			while( end_flag == 0 ) {
1446				ptr = skipSpace( ptr );
1447				switch( *ptr ) {
1448				// ?????
1449				  case '}':
1450					switch( i ) {
1451					  case 0:
1452					  case 1:
1453						dispError( DPCM_PARAMETER_IS_LACKING, lptr[line].filename, line );
1454						tbl->flag = 0;
1455						break;
1456					  default:
1457						line += offset;
1458						break;
1459					}
1460					end_flag = 1;
1461					break;
1462				// ??
1463				  case '\0':
1464					offset++;
1465					if( line+offset <= lptr->line ) {
1466						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
1467							ptr = lptr[line+offset].str;
1468						}
1469					} else {
1470						dispError( DPCM_DEFINITION_IS_WRONG, lptr[line].filename, line );
1471						tbl->flag = 0;
1472						end_flag = 1;
1473					}
1474					break;
1475				  default:
1476					switch( i ) {
1477					// ????????
1478					  case 0:
1479						// ??????"..."????????
1480						if( *ptr == '\"' ) {
1481							ptr++;
1482							//ptr = skipSpace( ptr );
1483							//"file.dmc"?OK. " file.dmc"?NG.
1484							tbl->fname = ptr;
1485							while( *ptr != '\"' && *ptr != '\0' ) {
1486								ptr++;
1487							}
1488						} else {
1489							tbl->fname = ptr;
1490							//????????????????
1491							// '/'';'??????
1492							while( *ptr != ' ' && *ptr != '\t' && *ptr != '\0' ) {
1493								ptr++;
1494							}
1495						}
1496						*ptr = '\0';
1497						ptr++;
1498						// ??????????/???????
1499						if( (fp = openDmc( tbl->fname )) == NULL ) {
1500							dispError( DPCM_FILE_NOT_FOUND, lptr[line+offset].filename, line );
1501							tbl->flag = 0;
1502							end_flag = 1;
1503						} else {
1504							fseek( fp, 0, SEEK_END );
1505							tbl->size = ftell( fp );
1506							fseek( fp, 0, SEEK_SET );
1507							fclose( fp );
1508						}
1509						i++;
1510						break;
1511					// ????????
1512					  case 1:
1513						num = Asc2Int( ptr, &cnt );
1514						if( cnt != 0 && (0 <= num && num <= 15) ) {
1515								tbl->freq = num;
1516						} else {
1517							dispError( DPCM_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1518							tbl->flag = 0;
1519							end_flag = 1;
1520						}
1521						ptr += cnt;
1522						i++;
1523						break;
1524					// ????????
1525					  case 2:
1526						num = Asc2Int( ptr, &cnt );
1527						if (cnt != 0 && num == 0) {
1528							//??0?????????
1529							ptr += cnt;
1530							i++;
1531							break;
1532						}
1533						if( cnt != 0 && (0 < num && num < 16384) ) {
1534							tbl->size = num;
1535						} else {
1536							dispError( DPCM_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1537							tbl->flag = 0;
1538							end_flag = 1;
1539						}
1540						ptr += cnt;
1541						i++;
1542						break;
1543					// ???????($4011)??????
1544					  case 3:
1545						num = Asc2Int(ptr, &cnt);
1546						if (cnt != 0 && ((0 <= num && num <= 0x7f) || num == 0xff)) {
1547							tbl->delta_init = num;
1548						} else {
1549							dispError( DPCM_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1550							tbl->flag = 0;
1551							end_flag = 1;
1552						}
1553						ptr += cnt;
1554						i++;
1555						break;
1556					// ?????($4010?bit7,6)???
1557					  case 4:
1558						num = Asc2Int(ptr, &cnt);
1559						if (cnt != 0 && (0 <= num && num <= 2)) {
1560							tbl->freq |= (num<<6);
1561						} else {
1562							dispError( DPCM_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1563							tbl->flag = 0;
1564							end_flag = 1;
1565						}
1566						ptr += cnt;
1567						i++;
1568						break;
1569					  default:
1570						dispError( DPCM_DEFINITION_IS_WRONG, lptr[line+offset].filename, line );
1571						tbl->flag = 0;
1572						end_flag = 1;
1573						break;
1574					}
1575					break;
1576				}
1577				ptr = skipSpace( ptr );
1578				if( *ptr == ',' ) {
1579					ptr++;
1580				}
1581			}
1582			if( tbl->size > (0xff)*16+1 ) {
1583				dispError( DPCM_FILE_SIZE_OVER, lptr[line+offset].filename, line );
1584				tbl->flag = 0;
1585			} else if ((tbl->size % 16) != 1) {
1586				dispWarning( DPCM_FILE_SIZE_ERROR, lptr[line+offset].filename, line );
1587			}
1588		// DPCM?????_SAME_LINE??????
1589		} else if( lptr[line].status == (_SET_DPCM_DATA|_SAME_LINE) ) {
1590			dispError( DPCM_DEFINITION_IS_WRONG, lptr[line].filename, line );
1591		// ????????????
1592		} else if( lptr[line].status == _INCLUDE ) {
1593			getDPCM( lptr[line].inc_ptr );
1594		}
1595	}
1596}
1597
1598
1599
1600/*--------------------------------------------------------------
1601	FDS FM?????
1602 Input:
1603	
1604 Output:
1605	??
1606--------------------------------------------------------------*/
1607void getFMTone( LINE *lptr )
1608{
1609	int		line, i, no, end_flag, offset, num, cnt;
1610	char	*ptr;
1611
1612	cnt = 0;
1613
1614	for( line = 1; line <= lptr->line; line++ ) {
1615		/* ???????? */
1616		if( lptr[line].status == _SET_FM_TONE ) {
1617			no = lptr[line].param;				/* ?????? */
1618			ptr = lptr[line].str;
1619			ptr++;								/* '{'?????? */
1620			if (fm_tone_tbl[no][0] != 0) {
1621				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1622			}
1623			fm_tone_tbl[no][0] = 0;
1624			offset = 0;
1625			i = 1;
1626			end_flag = 0;
1627			while( end_flag == 0 ) {
1628				ptr = skipSpace( ptr );
1629				switch( *ptr ) {
1630				  case '}':
1631					if (fm_tone_tbl[no][0] == 64) {
1632						//OK.
1633					} else {
1634						dispError( PARAMETER_IS_LACKING, lptr[line].filename, line );
1635						fm_tone_tbl[no][0] = 0;
1636					}
1637					end_flag = 1;
1638					line += offset;
1639					break;
1640				  case '\0':
1641					offset++;
1642					if( line+offset <= lptr->line ) {
1643						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
1644							ptr = lptr[line+offset].str;
1645						}
1646					} else {
1647						dispError( FM_TONE_DEFINITION_IS_WRONG, lptr[line].filename, line+offset );
1648						fm_tone_tbl[no][0] = 0;
1649						line += offset;
1650						end_flag = 1;
1651					}
1652					break;
1653				  default:
1654					num = Asc2Int( ptr, &cnt );
1655					if( cnt != 0 && (0 <= num && num <= 0x3f) ) {
1656						fm_tone_tbl[no][i] = num;
1657						fm_tone_tbl[no][0]++;
1658						ptr += cnt;
1659						i++;
1660						if( i > 65 ) {
1661							dispError( ABNORMAL_PARAMETERS_OF_FM_TONE, lptr[line+offset].filename, line+offset );
1662							fm_tone_tbl[no][0] = 0;
1663							line += offset;
1664							end_flag = 1;
1665						}
1666					} else {
1667						dispError( FM_TONE_DEFINITION_IS_WRONG, lptr[line+offset].filename, line+offset );
1668						fm_tone_tbl[no][0] = 0;
1669						line += offset;
1670						end_flag = 1;
1671					}
1672					break;
1673				}
1674				ptr = skipSpace( ptr );
1675				if( *ptr == ',' ) {
1676					ptr++;
1677				}
1678			}
1679		/* ???????_SAME_LINE?????? */
1680		} else if( lptr[line].status == (_SET_FM_TONE|_SAME_LINE) ) {
1681			dispError( FM_TONE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1682		/* ???????????? */
1683		} else if( lptr[line].status == _INCLUDE ) {
1684			getFMTone( lptr[line].inc_ptr );
1685		}
1686	}
1687}
1688
1689
1690/*--------------------------------------------------------------
1691	VRC7?????
1692 Input:
1693	
1694 Output:
1695	??
1696--------------------------------------------------------------*/
1697void getVRC7Tone( LINE *lptr )
1698{
1699	int		line, i, no, end_flag, offset, num, cnt;
1700	char	*ptr;
1701
1702	cnt = 0;
1703
1704	for( line = 1; line <= lptr->line; line++ ) {
1705		/* ???????? */
1706		if( lptr[line].status == _SET_VRC7_TONE ) {
1707			no = lptr[line].param;				/* ?????? */
1708			ptr = lptr[line].str;
1709			ptr++;								/* '{'?????? */
1710			if (vrc7_tone_tbl[no][0] != 0) {
1711				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1712			}
1713			vrc7_tone_tbl[no][0] = 0;
1714			offset = 0;
1715			i = 1;
1716			end_flag = 0;
1717			while( end_flag == 0 ) {
1718				ptr = skipSpace( ptr );
1719				switch( *ptr ) {
1720				  case '}':
1721					if (vrc7_tone_tbl[no][0] == 8) {
1722						//OK.
1723					} else {
1724						dispError( PARAMETER_IS_LACKING, lptr[line].filename, line );
1725						vrc7_tone_tbl[no][0] = 0;
1726					}
1727					end_flag = 1;
1728					line += offset;
1729					break;
1730				  case '\0':
1731					offset++;
1732					if( line+offset <= lptr->line ) {
1733						if( (lptr[line+offset].status&_SAME_LINE) == _SAME_LINE ) {
1734							ptr = lptr[line+offset].str;
1735						}
1736					} else {
1737						dispError( FM_TONE_DEFINITION_IS_WRONG, lptr[line].filename, line+offset );
1738						vrc7_tone_tbl[no][0] = 0;
1739						line += offset;
1740						end_flag = 1;
1741					}
1742					break;
1743				  default:
1744					num = Asc2Int( ptr, &cnt );
1745					if( cnt != 0 && (0 <= num && num <= 0xff) ) {
1746						vrc7_tone_tbl[no][i] = num;
1747						vrc7_tone_tbl[no][0]++;
1748						ptr += cnt;
1749						i++;
1750						if( i > 9 ) {
1751							dispError( ABNORMAL_PARAMETERS_OF_FM_TONE, lptr[line+offset].filename, line+offset );
1752							vrc7_tone_tbl[no][0] = 0;
1753							line += offset;
1754							end_flag = 1;
1755						}
1756					} else {
1757						dispError( FM_TONE_DEFINITION_IS_WRONG, lptr[line+offset].filename, line+offset );
1758						vrc7_tone_tbl[no][0] = 0;
1759						line += offset;
1760						end_flag = 1;
1761					}
1762					break;
1763				}
1764				ptr = skipSpace( ptr );
1765				if( *ptr == ',' ) {
1766					ptr++;
1767				}
1768			}
1769			if( i != 9 ) {
1770				if (!error_flag) {
1771					dispError( ABNORMAL_PARAMETERS_OF_FM_TONE, lptr[line].filename, line);
1772					vrc7_tone_tbl[no][0] = 0;
1773				}
1774			}
1775
1776
1777		/* ???????_SAME_LINE?????? */
1778		} else if( lptr[line].status == (_SET_VRC7_TONE|_SAME_LINE) ) {
1779			dispError( FM_TONE_DEFINITION_IS_WRONG, lptr[line].filename, line );
1780		/* ???????????? */
1781		} else if( lptr[line].status == _INCLUDE ) {
1782			getVRC7Tone( lptr[line].inc_ptr );
1783		}
1784	}
1785}
1786
1787
1788
1789/*--------------------------------------------------------------
1790	namco106?????
1791 Input:
1792	
1793 Output:
1794	??
1795--------------------------------------------------------------*/
1796void getN106Tone( LINE *lptr )
1797{
1798	int		line, i, no, end_flag, offset, num, cnt;
1799	char	*ptr;
1800					//	   16 14 12 10  8  6  4  2 			
1801	int	n106_tone_max[] = { 4, 4, 5, 6, 8,10,16,32 }; 
1802	int	n106_tone_num;
1803
1804	cnt = 0;
1805	for( line = 1; line <= lptr->line; line++ ) {
1806		/* ???????? */
1807		if( lptr[line].status == _SET_N106_TONE ) {
1808			no = lptr[line].param;				/* ?????? */
1809			ptr = lptr[line].str;
1810			ptr++;								/* '{'?????? */
1811			if (n106_tone_tbl[no][0] != 0) {
1812				dispWarning( THIS_NUMBER_IS_ALREADY_USED, lptr[line].filename, line );
1813			}
1814			n106_tone_tbl[no][0] = 0;
1815			offset = 0;
1816			i = 1;
1817			end_flag = 0;
1818			while( end_flag == 0 ) {
1819				ptr = skipSpace( ptr );
1820				switch( *ptr ) {
1821				  case '}':
1822					//?????while??????????
1823					end_flag = 1;
1824					line += offset;
1825					break;
1826				  case '\0':
1827					offset++;
1828					if( line+offset <= lptr->line ) {
1829

Large files files are truncated, but you can click here to view the full file