#include #include FILE *fp, *fq, *fr; main(int argc,char **argv){ int i, d, ct, debug=0, mtr=0, address=0; unsigned char ss, st[20], mix[120]; long ctr; st[16]=0; if( argc < 3 ){ printf("\n\tUsage :"); printf("\n\t\t./NAGASM target_SMF(*.mid) param_TXT (debug)"); printf("\n\n\tparam_TXT(111 bytes text file) Format :"); printf("\n\t\t- NAGASM - ID (6)"); printf("\n\t\t- 2005 - creation year (4)"); printf("\n\t\t- 100 bytes parameters ASCII(0-9,A-Z)"); printf("\n\t\t- 1 byte space\n\n"); exit(1); } else if( argc == 4 ){ debug = 1; } if( (fp=fopen( argv[1], "rb" )) == NULL ){ printf("\n... target file [ %s ] is not found (;_;) ...\n\n", argv[1]); exit(1); } if( (fq=fopen( argv[2], "rb" )) == NULL ){ printf("\n... target file [ %s ] is not found (;_;) ...\n\n", argv[2]); exit(1); } strcpy( st, "nagasm.tmp" ); fr=fopen( st, "wb" ); if( debug == 1 ){ printf("\nPhase 1 - copy target file to temporary [ nagasm.tmp ]"); } while( (d = fgetc(fp)) >= 0 ){ fputc(d,fr); } fclose(fp); fclose(fr); if( debug == 1 ){ printf("\n\nPhase 2 - add parameters [ %s ]", argv[2]); } while( (d = fgetc(fq)) >= 0 ){ ss = d & 0xff; if( ( ss > 0x1f ) && ( ss < 0x7f ) ){ mix[mtr++] = ss; } if( mtr > 115 ) break; } mix[mtr] = 0; if( debug == 1 ){ printf("\n\n\t%s", mix); } fclose(fq); strcpy( st, "nagasm.tmp" ); fp=fopen( st, "rb" ); fr=fopen( argv[1], "wb" ); address=0; while( (d = fgetc(fp)) >= 0 ){ if(( address < 18 )||( address >= 22 )){ fputc(d,fr); } else{ switch(address){ case 18: ctr = d*256*256*256; break; case 19: ctr = ctr + d*256*256; break; case 20: ctr = ctr + d*256; break; case 21: ctr = ctr + d + mtr + 6; fputc((int)(ctr/256/256/256),fr); fputc((int)((ctr/256/256)%256),fr); fputc((int)((ctr/256)%256),fr); fputc((int)(ctr%256),fr); fputc(0,fr); fputc(0xFF,fr); fputc(0x02,fr); fputc(112,fr); for( i=0; i<10; i++){ fputc(mix[i],fr); } fputc(0xA9,fr); for( i=10; i= 0 ){ if( ( address % 16 ) == 0 ){ printf("\n %08X : ", address); ct = 0; } ss = d & 0xff; printf("%02X ",ss); if( ( address % 16 ) == 7 ){ printf("- "); } if( ( ss > 0x1f ) && ( ss < 0x7f ) ) st[ct++] = ss; else st[ct++] = '.'; if( ( address++ % 16 ) == 15 ){ printf(" %s", st); } } fclose(fp); printf("\n\n"); exit(0); }