1 /****************************************************************************
3 * ____ ___ ____ __ ______ ___ ____ ____/ / *
4 * / __ `__ \/ __ `/ |/ / __ `__ \/ __ \/ __ / *
5 * / / / / / / /_/ /> </ / / / / / /_/ / /_/ / *
6 * /_/ /_/ /_/\__,_/_/|_/_/ /_/ /_/\____/\__,_/ *
8 * Copyright (c) 2008, Mukunda Johnson (mukunda@maxmod.org) *
10 * Permission to use, copy, modify, and/or distribute this software for any *
11 * purpose with or without fee is hereby granted, provided that the above *
12 * copyright notice and this permission notice appear in all copies. *
14 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES *
15 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF *
16 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR *
17 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES *
18 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN *
19 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF *
20 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. *
21 ****************************************************************************/
45 #include "samplefix.h"
47 extern void kiwi_start(void);
57 ************************\n\
59 ************************\n\
62 mmutil [options] input files ...\n\
64 Input may be MOD, S3M, XM, IT, and/or WAV\n\
66 .------------.----------------------------------------------------.\n\
67 | Option | Description |\n\
68 |------------|----------------------------------------------------|\n\
69 | -o<output> | Set output file. |\n\
70 | -h<header> | Set header output file. |\n\
71 | -m | Output MAS file rather than soundbank. |\n\
72 | -d | Use for NDS projects. |\n\
73 | -b | Create test ROM. (use -d for .nds, otherwise .gba) |\n\
74 | -i | Ignore sample flags. |\n\
75 | -v | Enable verbose output. |\n\
76 | -p | Set initial panning separation for MOD/S3M. |\n\
77 `-----------------------------------------------------------------'\n\
79 .-----------------------------------------------------------------.\n\
81 |-----------------------------------------------------------------|\n\
82 | Create DS soundbank file (soundbank.bin) from input1.xm |\n\
83 | and input2.it Also output header file (soundbank.h) |\n\
85 | mmutil -d input1.xm input2.it -osoundbank.bin -hsoundbank.h |\n\
86 |-----------------------------------------------------------------|\n\
87 | Create test GBA ROM from two inputs |\n\
89 | mmutil -b input1.mod input2.s3m -oTEST.gba |\n\
90 |-----------------------------------------------------------------|\n\
91 | Create test NDS ROM from three inputs |\n\
93 | mmutil -d -b input1.xm input2.s3m testsound.wav |\n\
94 `-----------------------------------------------------------------'\n\
98 void print_usage( void )
103 void print_error( int err )
107 case ERR_INVALID_MODULE:
108 printf( "Invalid module!\n" );
111 printf( "Too many arguments!\n" );
114 printf( "No input file!\n" );
117 printf( "Unable to write file!\n" );
120 printf( "Cannot parse input filename!\n" );
128 c = tolower(getchar());
129 while( getchar() != '\n' );
130 while( c != 'y' && c != 'n' )
132 printf( "Was that a yes? " );
133 c = tolower(getchar());
134 while( getchar() != '\n' );
136 return c == 'y' ? 1 : 0;
139 //------------------------------------------------------------------------------------------------
140 int main(int argc, char* argv[])
141 //------------------------------------------------------------------------------------------------
143 char* str_input=NULL;
144 char* str_output=NULL;
145 char* str_header=NULL;
170 //------------------------------------------------------------------------
172 //------------------------------------------------------------------------
174 for( a = 1; a < argc; a++ )
176 if( argv[a][0] == '-' )
178 if( argv[a][1] == 'b' )
180 else if( argv[a][1] == 'v' )
182 else if( argv[a][1] == 'd' )
183 target_system = SYSTEM_NDS;
184 else if( argv[a][1] == 'i' )
185 ignore_sflags = true;
186 else if( argv[a][1] == 'p' )
187 PANNING_SEP = ((argv[a][2] - '0') * 256)/9;
188 else if( argv[a][1] == 'o' )
189 str_output = argv[a]+2;
190 else if( argv[a][1] == 'h' )
191 str_header = argv[a]+2;
192 else if( argv[a][1] == 'm' )
194 else if( argv[a][1] == 'z' )
197 else if( !str_input )
208 if( number_of_inputs==0 )
217 file_open_read( str_input );
220 Load_WAV( &s, false,false );
229 file_open_write( str_output );
232 for( i = 0; i < s.sample_length; i++ )
233 write8( ((u8*)s.data)[i] );
240 if( m_flag & g_flag )
242 printf("-m and -g cannot be combined.\n");
246 if( m_flag && number_of_inputs != 1 )
248 printf( "-m only supports one input.\n" );
252 //---------------------------------------------------------------------------
253 // m/g generate output target if not given
254 //---------------------------------------------------------------------------
256 if( m_flag || g_flag)
260 if( number_of_inputs == 1 )
262 if( strlen(str_input) < 4 )
264 print_error( ERR_BADINPUT );
267 strp = strlen(str_input);
268 str_output = (char*)malloc( strp+2 );
269 strcpy(str_output, str_input);
270 strp=strlen(str_output)-1;
272 for( strpi=strp; str_output[strpi] != '.' && strpi != 0; strpi-- );
275 print_error( ERR_BADINPUT );
279 str_output[strpi++] = '.';
282 str_output[strpi++] = 'm';
283 str_output[strpi++] = 'a';
284 str_output[strpi++] = 's';
285 str_output[strpi++] = 0;
289 if( target_system == SYSTEM_GBA )
291 str_output[strpi++] = 'g';
292 str_output[strpi++] = 'b';
293 str_output[strpi++] = 'a';
294 str_output[strpi++] = 0;
296 else if( target_system == SYSTEM_NDS )
298 str_output[strpi++] = 'n';
299 str_output[strpi++] = 'd';
300 str_output[strpi++] = 's';
301 str_output[strpi++] = 0;
308 str_output[strpi++] = 0;
312 printf( "No output file! (-o option)\n" );
318 // catch filename too small
319 strl=strlen(str_input);
322 print_error( ERR_BADINPUT );
328 if( file_open_read( str_input ) )
330 printf( "Cannot open %s for reading!\n", str_input );
333 input_type = get_ext( str_input );
337 //------------------------------------------------------
339 //------------------------------------------------------
340 if( Load_MOD( &mod, v_flag ) )
342 print_error( ERR_INVALID_MODULE );
347 //------------------------------------------------------
349 //------------------------------------------------------
350 if( Load_S3M( &mod, v_flag ) )
352 print_error( ERR_INVALID_MODULE );
357 //------------------------------------------------------
359 //------------------------------------------------------
360 if( Load_XM( &mod, v_flag ) )
362 print_error( ERR_INVALID_MODULE );
367 //------------------------------------------------------
369 //------------------------------------------------------
370 if( Load_IT( &mod, v_flag ) )
373 print_error( ERR_INVALID_MODULE );
382 if( file_exists( str_output ) )
384 printf( "Output file exists! Overwrite? (y/n) " );
387 printf( "Operation Canceled!\n" );
393 if( file_open_write( str_output ) )
395 print_error( ERR_NOWRITE );
399 printf( "Writing .mas............\n" );
402 output_size = Write_MAS( &mod, v_flag, false );
407 Delete_Module( &mod );
412 printf( "Success! \x02 \n" );
414 printf( "Success! :) \n" );
422 MSL_Create( argv, argc, "tempSH308GK.bin", 0, v_flag );
424 if( file_exists( str_output ) )
426 printf( "Output file exists! Overwrite? (y/n) " );
429 printf( "Operation Canceled!\n" );
435 if( file_open_write( str_output ) )
437 print_error( ERR_NOWRITE );
441 if( target_system == SYSTEM_GBA )
444 printf( "Making GBA ROM.......\n" );
447 else if( target_system == SYSTEM_NDS )
450 printf( "Making NDS ROM.......\n" );
454 output_size = file_size( "tempSH308GK.bin" );
455 file_open_read( "tempSH308GK.bin" );
457 if( target_system == SYSTEM_GBA )
459 write32( (output_size < 248832) ? 1 : 0 );
462 for( i = 0; i < output_size; i++ )
470 file_delete( "tempSH308GK.bin" );
472 if( g_flag && target_system == SYSTEM_NDS )
473 Validate_NDS( str_output, output_size );
477 printf( "Success! :D\n" );
479 if( g_flag && target_system == SYSTEM_GBA )
481 if( output_size < 262144 )
483 printf("ROM can be multibooted!!\n" );
490 MSL_Create( argv, argc, str_output, str_header, v_flag );