mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2024-10-31 15:45:09 -04:00
Add dump memcard to file
This commit is contained in:
parent
df95fd8856
commit
fd83e0ae7d
@ -26,6 +26,7 @@
|
||||
|
||||
#include "version.h"
|
||||
#include "gcn64.h"
|
||||
#include "mempak.h"
|
||||
#include "../requests.h"
|
||||
#include "../gcn64_protocol.h"
|
||||
|
||||
@ -54,7 +55,7 @@ static void printUsage(void)
|
||||
printf(" --gc_getstatus Read GC controller status now (turns rumble OFF)\n");
|
||||
printf(" --gc_getstatus_rumble Read GC controller status now (turns rumble ON)\n");
|
||||
printf(" --n64_getcaps Get N64 controller capabilities (or status such as pak present)\n");
|
||||
printf(" --n64_mempak_dump Dump (display) N64 mempak contents\n");
|
||||
printf(" --n64_mempak_dump Dump N64 mempak contents (Use with --outfile to write to file)\n");
|
||||
}
|
||||
|
||||
#define OPT_OUTFILE 'o'
|
||||
@ -81,7 +82,7 @@ struct option longopts[] = {
|
||||
{ "n64_getcaps", 0, NULL, OPT_N64_GETCAPS },
|
||||
{ "n64_mempak_dump", 0, NULL, OPT_N64_MEMPAK_DUMP },
|
||||
{ "suspend_polling", 0, NULL, OPT_SUSPEND_POLLING },
|
||||
{ "outfile", 0, NULL, OPT_OUTFILE },
|
||||
{ "outfile", 1, NULL, OPT_OUTFILE },
|
||||
{ },
|
||||
};
|
||||
|
||||
@ -273,7 +274,11 @@ int main(int argc, char **argv)
|
||||
break;
|
||||
|
||||
case OPT_N64_MEMPAK_DUMP:
|
||||
if (outfile) {
|
||||
mempak_dumpToFile(hdl, outfile);
|
||||
} else {
|
||||
mempak_dump(hdl);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <ctype.h>
|
||||
#include <stdint.h>
|
||||
#include "gcn64.h"
|
||||
#include "mempak.h"
|
||||
#include "../gcn64_protocol.h"
|
||||
#include "../requests.h"
|
||||
|
||||
@ -207,3 +208,38 @@ void mempak_dump(gcn64_hdl_t hdl)
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
#define NUM_COPIES 4
|
||||
|
||||
int mempak_dumpToFile(gcn64_hdl_t hdl, const char *out_filename)
|
||||
{
|
||||
unsigned char cardbuf[0x8000];
|
||||
FILE *fptr;
|
||||
int copies;
|
||||
|
||||
printf("Init pak\n");
|
||||
mempak_init(hdl);
|
||||
printf("Reading card...\n");
|
||||
mempak_readAll(hdl, cardbuf);
|
||||
|
||||
printf("Writing to file '%s'\n", out_filename);
|
||||
fptr = fopen(out_filename, "w");
|
||||
if (!fptr) {
|
||||
perror("fopen");
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (copies = 0; copies < NUM_COPIES; copies++) {
|
||||
if (1 != fwrite(cardbuf, sizeof(cardbuf), 1, fptr)) {
|
||||
perror("fwrite");
|
||||
fclose(fptr);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Done\n");
|
||||
|
||||
fclose(fptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
void mempak_dump(gcn64_hdl_t hdl);
|
||||
int mempak_readBlock(gcn64_hdl_t hdl, unsigned short addr, unsigned char dst[32]);
|
||||
int mempak_dumpToFile(gcn64_hdl_t hdl, const char *out_filename);
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user