move mempak command line tools to main directory

This commit is contained in:
Raphael Assenat 2015-10-25 22:41:44 -04:00
parent 9c7088377f
commit f3129ed377
13 changed files with 66 additions and 47 deletions

View File

@ -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 $<

View File

@ -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; i<MEMPAK_NUM_NOTES; i++) {
unsigned char tmp = 0;
fwrite(mpk->note_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;

View File

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#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");
}

Binary file not shown.

View File

@ -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"