From 05224c5eabb883dc975d4d589e7fc88b8a6c3738 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Thu, 1 Oct 2015 00:02:28 -0400 Subject: [PATCH] Tool features --- gcn64_protocol.h | 1 + tool/gcn64.c | 1 + tool/gcn64lib.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++ tool/gcn64lib.h | 4 +++ tool/main.c | 26 ++++++++++++++++++++ 5 files changed, 96 insertions(+) diff --git a/gcn64_protocol.h b/gcn64_protocol.h index 06be7a2..077d5a4 100644 --- a/gcn64_protocol.h +++ b/gcn64_protocol.h @@ -10,6 +10,7 @@ /* Return many unknown bits, but two are about the expansion port. */ #define N64_GET_CAPABILITIES 0x00 +#define N64_RESET 0xFF #define N64_CAPS_REPLY_LENGTH 24 #define OFFSET_EXT_REMOVED 22 diff --git a/tool/gcn64.c b/tool/gcn64.c index f5ca6fe..50b0808 100644 --- a/tool/gcn64.c +++ b/tool/gcn64.c @@ -217,3 +217,4 @@ int gcn64_exchange(gcn64_hdl_t hdl, unsigned char *outcmd, int outlen, unsigned return n; } + diff --git a/tool/gcn64lib.c b/tool/gcn64lib.c index f74c0fb..f65e40c 100644 --- a/tool/gcn64lib.c +++ b/tool/gcn64lib.c @@ -1,6 +1,8 @@ #include +#include #include "gcn64lib.h" #include "../requests.h" +#include "hexdump.h" int gcn64lib_getConfig(gcn64_hdl_t hdl, unsigned char param, unsigned char *rx, unsigned char rx_max) { @@ -75,3 +77,65 @@ int gcn64lib_rawSiCommand(gcn64_hdl_t hdl, unsigned char channel, unsigned char return rx_len; } + +int gcn64lib_16bit_scan(gcn64_hdl_t hdl, unsigned short min, unsigned short max) +{ + int id, n; + unsigned char buf[64]; + + for (id = min; id<=max; id++) { + buf[0] = id >> 8; + buf[1] = id & 0xff; + n = gcn64lib_rawSiCommand(hdl, 0, buf, 2, buf, sizeof(buf)); + if (n > 0) { + printf("CMD 0x%04x answer: ", id); + printHexBuf(buf, n); + } + } + + return 0; +} + +int gcn64lib_8bit_scan(gcn64_hdl_t hdl, unsigned char min, unsigned char max) +{ + int id, n; + unsigned char buf[64]; + + for (id = min; id<=max; id++) { + buf[0] = id; + n = gcn64lib_rawSiCommand(hdl, 0, buf, 1, buf, sizeof(buf)); + if (n > 0) { + printf("CMD 0x%02x answer: ", id); + printHexBuf(buf, n); + } + } + + return 0; +} + +int gcn64lib_raphnet_gc_to_n64_getInfo(gcn64_hdl_t hdl) +{ + unsigned char buf[64]; + int n; + + buf[0] = 'R'; + buf[1] = 0x01; // Get device info + + n = gcn64lib_rawSiCommand(hdl, 0, buf, 2, buf, sizeof(buf)); + if (n<0) + return n; + + if (n > 0) { + printf("gc_to_n64 adapter info: {\n"); + printf("\tFirmware version: %s\n", buf+10); + printf("\tDefault mapping id: %d\n", buf[0]); + printf("\tDeadzone enabled: %d\n", buf[1]); + printf("\tOld v1.5 conversion: %d\n", buf[2]); + printf("}\n"); + } else { + printf("No answer (old version?)\n"); + } + + return 0; +} + diff --git a/tool/gcn64lib.h b/tool/gcn64lib.h index 54d89a8..ab1e362 100644 --- a/tool/gcn64lib.h +++ b/tool/gcn64lib.h @@ -8,4 +8,8 @@ int gcn64lib_setConfig(gcn64_hdl_t hdl, unsigned char param, unsigned char *data int gcn64lib_getConfig(gcn64_hdl_t hdl, unsigned char param, unsigned char *rx, unsigned char rx_max); int gcn64lib_rawSiCommand(gcn64_hdl_t hdl, unsigned char channel, unsigned char *tx, unsigned char tx_len, unsigned char *rx, unsigned char max_rx); +int gcn64lib_8bit_scan(gcn64_hdl_t hdl, unsigned char min, unsigned char max); +int gcn64lib_16bit_scan(gcn64_hdl_t hdl, unsigned short min, unsigned short max); +int gcn64lib_raphnet_gc_to_n64_getInfo(gcn64_hdl_t hdl); + #endif // _gcn64_lib_h__ diff --git a/tool/main.c b/tool/main.c index 5f8a5f1..4ca00d9 100644 --- a/tool/main.c +++ b/tool/main.c @@ -62,6 +62,13 @@ static void printUsage(void) printf(" --n64_getcaps Get N64 controller capabilities (or status such as pak present)\n"); printf(" --n64_mempak_dump Dump N64 mempak contents (Use with --outfile to write to file)\n"); printf(" --n64_mempak_write file Write file to N64 mempak\n"); + printf("\n"); + printf("GC to N64 adapter commands: (For GC to N64 adapter connected to GC/N64 to USB adapter)\n"); + printf(" --gc_to_n64_info Display info on adapter (version, config, etc)\n"); + printf("\n"); + printf("Development/Experimental/Research commands: (use at your own risk)\n"); + printf(" --si_8bit_scan Try all possible 1-byte commands, to see which one a controller responds to.\n"); + printf(" --si_16bit_scan Try all possible 2-byte commands, to see which one a controller responds to.\n"); } @@ -79,6 +86,9 @@ static void printUsage(void) #define OPT_SET_POLL_INTERVAL 308 #define OPT_GET_POLL_INTERVAL 309 #define OPT_N64_MEMPAK_WRITE 310 +#define OPT_SI8BIT_SCAN 311 +#define OPT_SI16BIT_SCAN 312 +#define OPT_GC_TO_N64_INFO 313 struct option longopts[] = { { "help", 0, NULL, 'h' }, @@ -98,6 +108,9 @@ struct option longopts[] = { { "set_poll_rate", 1, NULL, OPT_SET_POLL_INTERVAL }, { "get_poll_rate", 0, NULL, OPT_GET_POLL_INTERVAL }, { "n64_mempak_write", 1, NULL, OPT_N64_MEMPAK_WRITE }, + { "si_8bit_scan", 0, NULL, OPT_SI8BIT_SCAN }, + { "si_16bit_scan", 0, NULL, OPT_SI16BIT_SCAN }, + { "gc_to_n64_info", 0, NULL, OPT_GC_TO_N64_INFO }, { }, }; @@ -296,6 +309,7 @@ int main(int argc, char **argv) case OPT_N64_GETCAPS: cmd[0] = N64_GET_CAPABILITIES; + //cmd[0] = 0xff; n = gcn64lib_rawSiCommand(hdl, 0, cmd, 1, cmd, sizeof(cmd)); if (n >= 0) { printf("N64 Get caps[%d]: ", n); @@ -315,6 +329,18 @@ int main(int argc, char **argv) printf("Input file: %s\n", optarg); mempak_writeFromFile(hdl, optarg); break; + + case OPT_SI8BIT_SCAN: + gcn64lib_8bit_scan(hdl, 0, 255); + break; + + case OPT_SI16BIT_SCAN: + gcn64lib_16bit_scan(hdl, 0, 0xffff); + break; + + case OPT_GC_TO_N64_INFO: + gcn64lib_raphnet_gc_to_n64_getInfo(hdl); + break; } if (do_exchange) {