PageRenderTime 68ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 1ms

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

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