2015-10-25 01:57:10 -04:00
|
|
|
#include <stdio.h>
|
2015-10-25 15:22:18 -04:00
|
|
|
#include <getopt.h>
|
2015-10-25 01:57:10 -04:00
|
|
|
#include "mempak.h"
|
|
|
|
|
2015-10-25 15:22:18 -04:00
|
|
|
#define DEFAULT_FORMAT_STR "n64"
|
|
|
|
|
|
|
|
static void print_usage(void)
|
|
|
|
{
|
|
|
|
printf("Usage: ./mempak_format file <options>\n");
|
|
|
|
printf("\n");
|
|
|
|
printf("Options:\n");
|
|
|
|
printf(" -h Display help\n");
|
|
|
|
printf(" -f format Write file in specified format (default: %s)\n", DEFAULT_FORMAT_STR);
|
|
|
|
printf("\n");
|
|
|
|
printf("Formats:\n");
|
|
|
|
printf(" mpk Standard 32kB .mpk file format\n");
|
|
|
|
printf(" mpk4 128kB .mpk file (4 copies or the 32kB block)\n");
|
|
|
|
printf(" n64 .N64 file format\n");
|
|
|
|
}
|
2015-10-25 01:57:10 -04:00
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
mempak_structure_t *mpk;
|
|
|
|
const char *outfile;
|
2015-10-25 02:41:54 -04:00
|
|
|
unsigned char type;
|
2015-10-25 15:22:18 -04:00
|
|
|
struct option long_options[] = {
|
|
|
|
{ "format", required_argument, 0, 'f' },
|
|
|
|
{ "help", no_argument, 0, 'h' },
|
|
|
|
{ }, // terminator
|
|
|
|
};
|
|
|
|
const char *format = DEFAULT_FORMAT_STR;
|
2015-10-25 01:57:10 -04:00
|
|
|
|
|
|
|
if (argc < 2) {
|
2015-10-25 15:22:18 -04:00
|
|
|
print_usage();
|
2015-10-25 01:57:10 -04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-25 15:22:18 -04:00
|
|
|
while(1) {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
c = getopt_long(argc, argv, "f:h", long_options, NULL);
|
|
|
|
if (c==-1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
switch(c)
|
|
|
|
{
|
|
|
|
case 'h':
|
|
|
|
print_usage();
|
|
|
|
return 0;
|
|
|
|
case 'f':
|
|
|
|
format = optarg;
|
|
|
|
break;
|
2015-10-25 16:29:23 -04:00
|
|
|
case '?':
|
|
|
|
fprintf(stderr, "Unknown argument. Try -h\n");
|
|
|
|
return -1;
|
2015-10-25 15:22:18 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type = mempak_string2format(format);
|
|
|
|
if (type == MPK_FORMAT_INVALID) {
|
|
|
|
fprintf(stderr, "Unknown format specified\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
outfile = argv[optind];
|
2015-10-25 01:57:10 -04:00
|
|
|
mpk = mempak_new();
|
|
|
|
if (!mpk) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:41:54 -04:00
|
|
|
mempak_saveToFile(mpk, outfile, type);
|
2015-10-25 01:57:10 -04:00
|
|
|
mempak_free(mpk);
|
|
|
|
|
2015-10-25 15:22:18 -04:00
|
|
|
printf("Wrote empty (formatted) memory card file '%s' in '%s' format\n", outfile, mempak_format2string(type));
|
|
|
|
|
2015-10-25 01:57:10 -04:00
|
|
|
return 0;
|
|
|
|
}
|