diff --git a/tool/Makefile b/tool/Makefile index 609278f..c54c6d1 100644 --- a/tool/Makefile +++ b/tool/Makefile @@ -13,17 +13,18 @@ ifeq ($(shell uname -o), Msys) COMPAT_OBJS=sleep.o memmem.o endif -CFLAGS=-Wall -g `pkg-config $(HIDAPI_NAME) --cflags` +CFLAGS=-Wall -g `pkg-config $(HIDAPI_NAME) --cflags` --std=c99 LDFLAGS=`pkg-config $(HIDAPI_NAME) --libs` -g GTK_CFLAGS=`pkg-config --cflags gtk+-3.0 gmodule-2.0` GTK_LDFLAGS=`pkg-config --libs gtk+-3.0 gmodule-2.0` PREFIX=/usr/local +MEMPAKLIB_OBJS=mempak.o mempak_fs.o .PHONY : clean install -all: gcn64ctl gcn64ctl_gui +all: gcn64ctl gcn64ctl_gui mempak_ls mempak_format mempak_extract_note mempak_insert_note mempak_rm mempak_convert gcn64ctl_gui: gcn64ctl_gui.o gcn64.o gcn64lib.o mempak_old.o hexdump.o ihex.o $(COMPAT_OBJS) $(LD) $^ $(LDFLAGS) $(GTK_LDFLAGS) -o $@ @@ -34,6 +35,25 @@ gcn64ctl: main.o gcn64.o mempak_old.o gcn64lib.o hexdump.o gc2n64_adapter.o ihex gcn64ctl_gui.o: gcn64ctl_gui.c $(CC) $(CFLAGS) $(GTK_CFLAGS) -c $< +mempak_convert: mempak_convert.o $(MEMPAKLIB_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + +mempak_rm: mempak_rm.o $(MEMPAKLIB_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + +mempak_insert_note: mempak_insert_note.o $(MEMPAKLIB_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + +mempak_extract_note: mempak_extract_note.o $(MEMPAKLIB_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + +mempak_ls: mempak_ls.o $(MEMPAKLIB_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + +mempak_format: mempak_format.o $(MEMPAKLIB_OBJS) + $(LD) $^ $(LDFLAGS) -o $@ + + %.o: %.c %.h $(CC) $(CFLAGS) -c $< diff --git a/tool/n64savetool/mempak.c b/tool/mempak.c similarity index 90% rename from tool/n64savetool/mempak.c rename to tool/mempak.c index 0dd00f5..1255f68 100644 --- a/tool/n64savetool/mempak.c +++ b/tool/mempak.c @@ -232,6 +232,7 @@ int mempak_exportNote(mempak_structure_t *mpk, int note_id, const char *dst_file int mempak_saveToFile(mempak_structure_t *mpk, const char *dst_filename, unsigned char format) { FILE *fptr; + int i; if (!mpk) return -1; @@ -265,8 +266,30 @@ int mempak_saveToFile(mempak_structure_t *mpk, const char *dst_filename, unsigne // only look for the 123-456-STD header and then // seek to the data. // - // Real .N64 files contain more info. TODO: Support it + // Real .N64 files contain more info other info. Often + // 0x12: 01 00 00 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 00 + // .... + // 0x3F: 00 + // + // Then at 0x40, there are 0x1000 bytes. I think there are 256 + // bytes available for each of block. See comments in + // mempak_loadFromFile for more info. fprintf(fptr, "123-456-STD"); + + fseek(fptr, DEXDRIVE_COMMENT_OFFSET, SEEK_SET); + for (i=0; inote_comments[i], 255, 1, fptr); + // I'm not sure about the exact convention of the + // original format. Is is that comments are zero-terminated, + // but if the length is 256 then non-terminated (implcit termination?) + // + // Just to make sure nothing crashes by loading a file generated + // by this tool, I make sure there is always a zero. + fwrite(&tmp, 1, 1, fptr); + } + + fseek(fptr, DEXDRIVE_DATA_OFFSET, SEEK_SET); fwrite(mpk->data, sizeof(mpk->data), 1, fptr); break; diff --git a/tool/n64savetool/mempak.h b/tool/mempak.h similarity index 100% rename from tool/n64savetool/mempak.h rename to tool/mempak.h diff --git a/tool/n64savetool/mempak_convert.c b/tool/mempak_convert.c similarity index 100% rename from tool/n64savetool/mempak_convert.c rename to tool/mempak_convert.c diff --git a/tool/n64savetool/mempak_extract_note.c b/tool/mempak_extract_note.c similarity index 100% rename from tool/n64savetool/mempak_extract_note.c rename to tool/mempak_extract_note.c diff --git a/tool/n64savetool/mempak_format.c b/tool/mempak_format.c similarity index 100% rename from tool/n64savetool/mempak_format.c rename to tool/mempak_format.c diff --git a/tool/n64savetool/mempak_fs.c b/tool/mempak_fs.c similarity index 100% rename from tool/n64savetool/mempak_fs.c rename to tool/mempak_fs.c diff --git a/tool/n64savetool/mempak_fs.h b/tool/mempak_fs.h similarity index 100% rename from tool/n64savetool/mempak_fs.h rename to tool/mempak_fs.h diff --git a/tool/n64savetool/mempak_insert_note.c b/tool/mempak_insert_note.c similarity index 67% rename from tool/n64savetool/mempak_insert_note.c rename to tool/mempak_insert_note.c index 6f11ea5..b0386fd 100644 --- a/tool/n64savetool/mempak_insert_note.c +++ b/tool/mempak_insert_note.c @@ -1,5 +1,6 @@ #include #include +#include #include #include "mempak.h" @@ -25,7 +26,7 @@ int main(int argc, char **argv) { "dst", required_argument, 0, 'd' }, { }, // terminator }; - const char *comment = ""; + const char *comment = NULL; int used_note_id = -1; int dst_id = -1; @@ -37,7 +38,7 @@ int main(int argc, char **argv) while(1) { int c; - c = getopt_long(argc, argv, "f:h", long_options, NULL); + c = getopt_long(argc, argv, "f:hc:d:", long_options, NULL); if (c==-1) break; @@ -48,10 +49,17 @@ int main(int argc, char **argv) return 0; case 'c': comment = optarg; + if (strlen(optarg) > (MAX_NOTE_COMMENT_SIZE-2)) { + fprintf(stderr, "Comment too long (%d characters max.)\n", (MAX_NOTE_COMMENT_SIZE-2)); + return -1; + } break; case 'd': dst_id = atoi(optarg); break; + case '?': + fprintf(stderr, "Unknown argument. Try -h\n"); + return -1; } } @@ -73,6 +81,16 @@ int main(int argc, char **argv) printf("Note imported and written to slot %d\n", used_note_id); + if (comment) { + if (mpk->file_format != MPK_FORMAT_N64) { + printf("Warning: Ignoring comment since it cannot be stored in %s file format. Use the N64 format instead.\n", mempak_format2string(mpk->file_format)); + } else { + strncpy(mpk->note_comments[used_note_id], comment, MAX_NOTE_COMMENT_SIZE); + mpk->note_comments[used_note_id][256] = 0; + mpk->note_comments[used_note_id][255] = 0; + } + } + if (0 != mempak_saveToFile(mpk, pakfile, mpk->file_format)) { fprintf(stderr, "could not write to memory pak file\n"); } diff --git a/tool/n64savetool/mempak_ls.c b/tool/mempak_ls.c similarity index 100% rename from tool/n64savetool/mempak_ls.c rename to tool/mempak_ls.c diff --git a/tool/n64savetool/mempak_rm.c b/tool/mempak_rm.c similarity index 100% rename from tool/n64savetool/mempak_rm.c rename to tool/mempak_rm.c diff --git a/tool/n64savetool/.nfs000000000025a4d700000004 b/tool/n64savetool/.nfs000000000025a4d700000004 new file mode 100644 index 0000000..5c64bcd Binary files /dev/null and b/tool/n64savetool/.nfs000000000025a4d700000004 differ diff --git a/tool/n64savetool/Makefile b/tool/n64savetool/Makefile deleted file mode 100644 index 1c08e28..0000000 --- a/tool/n64savetool/Makefile +++ /dev/null @@ -1,42 +0,0 @@ -CC=gcc -LD=$(CC) - -CFLAGS=-Wall -g --std=c99 -LDFLAGS=-g - -PREFIX=/usr/local - -PROGRAMS=mempak_ls mempak_format mempak_extract_note mempak_insert_note mempak_rm mempak_convert -MEMPAKLIB_OBJS=mempak.o mempak_fs.o - -.PHONY : clean install - -all: $(PROGRAMS) - -mempak_convert: mempak_convert.o $(MEMPAKLIB_OBJS) - $(LD) $^ $(LDFLAGS) -o $@ - -mempak_rm: mempak_rm.o $(MEMPAKLIB_OBJS) - $(LD) $^ $(LDFLAGS) -o $@ - -mempak_insert_note: mempak_insert_note.o $(MEMPAKLIB_OBJS) - $(LD) $^ $(LDFLAGS) -o $@ - -mempak_extract_note: mempak_extract_note.o $(MEMPAKLIB_OBJS) - $(LD) $^ $(LDFLAGS) -o $@ - -mempak_ls: mempak_ls.o $(MEMPAKLIB_OBJS) - $(LD) $^ $(LDFLAGS) -o $@ - -mempak_format: mempak_format.o $(MEMPAKLIB_OBJS) - $(LD) $^ $(LDFLAGS) -o $@ - -%.o: %.c %.h - $(CC) $(CFLAGS) -c $< - -clean: - rm -f *.o $(PROGRAMS) - -install: - @echo "Install not done yet. Sorry" -