From 334ca5680570412fbb3c13716af23673624e7558 Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Fri, 12 Mar 2021 11:57:00 +0900 Subject: [PATCH 1/8] Add Support Pokemon Colosseum,XD --- src/Gamecube.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/Gamecube.c b/src/Gamecube.c index 66b6642..28391ec 100644 --- a/src/Gamecube.c +++ b/src/Gamecube.c @@ -149,6 +149,45 @@ uint8_t gc_write(const uint8_t pin, Gamecube_Status_t* status, Gamecube_Origin_t ret = 6; } } + // Add Support Pokemon Colosseum,XD + // Get data. Do not check last byte (command[2]), as the flags are unknown + else if (receivedBytes == 3 && command[0] == 0x40 && command[1] == 0x00) + { + gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask); + ret = 3; + // The first byte probably flags a gamecube reading (0x40), as the same + // protocol is also used for N64. The lower nibble seems to be the mode: + // 0x40 (followed by 2 bytes) reading + // 0x41 get origin (1 byte) + // 0x42 (followed by 2 bytes) seems to force mode 0x02 below + // 0x43 (followed by 2 bytes) seems to force mode 0x02 below + + // The 2nd byte (command[1]) seems to request a special data format. + // I've noticed formats that merge the L + R data. + // There seem to be only 4 data formats, the rest is ignore. + // 0x00 First 4 bytes: buttons0+1 + X + Y, C-Stick, L+R minimum of both, 0x00 fixed + // 0x01 First 4 bytes: buttons0+1 + X + Y, C-Stick Horizontal only, R, L, 0x00 fixed + // 0x02 First 4 bytes: buttons0+1 + X + Y, C-Stick Horizontal only, L+R minimum of both, 0x02 fixed, 0x01 fixed + // 0x03 Normal reading + + // I've seen 3 last options for the last byte (command[2]): + // 0x00 Normal reading + // 0x01 Enable rumble + // 0x02 Normal reading, rumble was at least called once + // 0x03 ??? - never seen so far + // Rumble: 1, 5, 9, 13, 17, ... + // You can see that only 4 of those requests are possible, + // the gamecube will ignore the left 6 MSB. + if((command[2] % 4) == 0x01){ + ret = 4; + } + else if((command[2] % 4) == 0x02){ + ret = 5; + } + else if((command[2] % 4) == 0x03){ + ret = 6; + } + } // End of time sensitive code SREG = oldSREG; From 4f1eb28f32d395d034ab2c80567ffebc070fce72 Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Thu, 8 Jul 2021 22:33:16 +0900 Subject: [PATCH 2/8] Update Gamecube.c --- src/Gamecube.c | 103 +++++++++++++++++++++++++++++-------------------- 1 file changed, 62 insertions(+), 41 deletions(-) diff --git a/src/Gamecube.c b/src/Gamecube.c index 28391ec..7191c45 100644 --- a/src/Gamecube.c +++ b/src/Gamecube.c @@ -78,6 +78,58 @@ bool gc_read(const uint8_t pin, Gamecube_Report_t* report, const bool rumble) // Gamecube Console //================================================================================ +void gc_report_convert(Gamecube_Report_t* report, Gamecube_Different_Report_t* dif, uint8_t mode) +{ + dif->a = report->a; + dif->b = report->b; + dif->x = report->x; + dif->y = report->y; + dif->start = report->start; + dif->dleft = report->dleft; + dif->dright = report->dright; + dif->ddown = report->ddown; + dif->dup = report->dup; + dif->z = report->z; + dif->r = report->r; + dif->l = report->l; + dif->xAxis = report->xAxis; + dif->yAxis = report->yAxis; + if (mode == 0 || mode == 5 || mode == 6 || mode == 7) + { + dif->Mode0.cxAxis = report->cxAxis; + dif->Mode0.cyAxis = report->cyAxis; + dif->Mode0.left = report->left >> 4; + dif->Mode0.right = report->right >> 4; + dif->Mode0.analogA = 0; + dif->Mode0.analogB = 0; + } + else if (mode == 1) + { + dif->Mode1.cxAxis = report->cxAxis >> 4; + dif->Mode1.cyAxis = report->cyAxis >> 4; + dif->Mode1.left = report->left; + dif->Mode1.right = report->right; + dif->Mode1.analogA = 0; + dif->Mode1.analogB = 0; + } + else if (mode == 2) + { + dif->Mode2.cxAxis = report->cxAxis >> 4; + dif->Mode2.cyAxis = report->cyAxis >> 4; + dif->Mode2.left = report->left >> 4; + dif->Mode2.right = report->right >> 4; + dif->Mode2.analogA = 0; + dif->Mode2.analogB = 0; + } + else if (mode == 4) + { + dif->Mode4.cxAxis = report->cxAxis; + dif->Mode4.cyAxis = report->cyAxis; + dif->Mode4.analogA = 0; + dif->Mode4.analogB = 0; + } +} + uint8_t gc_write(const uint8_t pin, Gamecube_Status_t* status, Gamecube_Origin_t* origin, Gamecube_Report_t* report) { // 0 = no input/error, 1 = init, 2 = origin, 3 = read, 4 = read with rumble @@ -112,49 +164,18 @@ uint8_t gc_write(const uint8_t pin, Gamecube_Status_t* status, Gamecube_Origin_t ret = 2; } // Get data. Do not check last byte (command[2]), as the flags are unknown - else if (receivedBytes == 3 && command[0] == 0x40 && command[1] == 0x03) + else if (receivedBytes == 3 && command[0] == 0x40 && command[1] <= 0x07) { - gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask); - ret = 3; - // The first byte probably flags a gamecube reading (0x40), as the same - // protocol is also used for N64. The lower nibble seems to be the mode: - // 0x40 (followed by 2 bytes) reading - // 0x41 get origin (1 byte) - // 0x42 (followed by 2 bytes) seems to force mode 0x02 below - // 0x43 (followed by 2 bytes) seems to force mode 0x02 below - - // The 2nd byte (command[1]) seems to request a special data format. - // I've noticed formats that merge the L + R data. - // There seem to be only 4 data formats, the rest is ignore. - // 0x00 First 4 bytes: buttons0+1 + X + Y, C-Stick, L+R minimum of both, 0x00 fixed - // 0x01 First 4 bytes: buttons0+1 + X + Y, C-Stick Horizontal only, R, L, 0x00 fixed - // 0x02 First 4 bytes: buttons0+1 + X + Y, C-Stick Horizontal only, L+R minimum of both, 0x02 fixed, 0x01 fixed - // 0x03 Normal reading - - // I've seen 3 last options for the last byte (command[2]): - // 0x00 Normal reading - // 0x01 Enable rumble - // 0x02 Normal reading, rumble was at least called once - // 0x03 ??? - never seen so far - // Rumble: 1, 5, 9, 13, 17, ... - // You can see that only 4 of those requests are possible, - // the gamecube will ignore the left 6 MSB. - if((command[2] % 4) == 0x01){ - ret = 4; - } - else if((command[2] % 4) == 0x02){ - ret = 5; + if (command[1] == 0x03) + { + gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask); + ret = 3; + } else { + Gamecube_Different_Report_t dif; + gc_report_convert(report, &dif, command[1]); + gc_n64_send(dif.raw8, sizeof(Gamecube_Different_Report_t), modePort, outPort, bitMask); + ret = 3; } - else if((command[2] % 4) == 0x03){ - ret = 6; - } - } - // Add Support Pokemon Colosseum,XD - // Get data. Do not check last byte (command[2]), as the flags are unknown - else if (receivedBytes == 3 && command[0] == 0x40 && command[1] == 0x00) - { - gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask); - ret = 3; // The first byte probably flags a gamecube reading (0x40), as the same // protocol is also used for N64. The lower nibble seems to be the mode: // 0x40 (followed by 2 bytes) reading From 596da5f53e52488512c15a3625102f504710c642 Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Thu, 8 Jul 2021 22:34:56 +0900 Subject: [PATCH 3/8] Update Gamecube.h --- src/Gamecube.h | 174 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) diff --git a/src/Gamecube.h b/src/Gamecube.h index db2922d..9723ab6 100644 --- a/src/Gamecube.h +++ b/src/Gamecube.h @@ -88,6 +88,180 @@ typedef union{ }; } Gamecube_Report_t; +typedef union{ + // 8 bytes of datareport that we get from the controller + uint8_t raw8[8]; + uint16_t raw16[0]; + uint32_t raw32[0]; + + struct{ + uint8_t buttons0; + union{ + uint8_t buttons1; + uint8_t dpad : 4; + }; + }; + + struct { + // first data byte (bitfields are sorted in LSB order) + uint8_t a : 1; + uint8_t b : 1; + uint8_t x : 1; + uint8_t y : 1; + uint8_t start : 1; + uint8_t origin : 1; // Indicates if GetOrigin(0x41) was called (LOW) + uint8_t errlatch : 1; + uint8_t errstat : 1; + + // second data byte + uint8_t dleft : 1; + uint8_t dright : 1; + uint8_t ddown : 1; + uint8_t dup : 1; + uint8_t z : 1; + uint8_t r : 1; + uint8_t l : 1; + uint8_t high1 : 1; + + // 3rd-8th data byte + uint8_t xAxis; + uint8_t yAxis; + uint8_t cxAxis; + uint8_t cyAxis; + uint8_t left; + uint8_t right; + }; + + struct { + // first data byte (bitfields are sorted in LSB order) + uint8_t a : 1; + uint8_t b : 1; + uint8_t x : 1; + uint8_t y : 1; + uint8_t start : 1; + uint8_t origin : 1; // Indicates if GetOrigin(0x41) was called (LOW) + uint8_t errlatch : 1; + uint8_t errstat : 1; + + // second data byte + uint8_t dleft : 1; + uint8_t dright : 1; + uint8_t ddown : 1; + uint8_t dup : 1; + uint8_t z : 1; + uint8_t r : 1; + uint8_t l : 1; + uint8_t high1 : 1; + + // 3rd-8th data byte + uint8_t xAxis; + uint8_t yAxis; + uint8_t cxAxis; + uint8_t cyAxis; + /* + uint8_t left; + uint8_t right; + */ + uint8_t left : 4; + uint8_t right : 4; + uint8_t analogA : 4; + uint8_t analogB : 4; + } Mode0; + + struct { + // first data byte (bitfields are sorted in LSB order) + uint8_t a : 1; + uint8_t b : 1; + uint8_t x : 1; + uint8_t y : 1; + uint8_t start : 1; + uint8_t origin : 1; // Indicates if GetOrigin(0x41) was called (LOW) + uint8_t errlatch : 1; + uint8_t errstat : 1; + + // second data byte + uint8_t dleft : 1; + uint8_t dright : 1; + uint8_t ddown : 1; + uint8_t dup : 1; + uint8_t z : 1; + uint8_t r : 1; + uint8_t l : 1; + uint8_t high1 : 1; + + // 3rd-8th data byte + uint8_t xAxis; + uint8_t yAxis; + uint8_t cxAxis : 4; + uint8_t cyAxis : 4; + uint8_t left; + uint8_t right; + uint8_t analogA : 4; + uint8_t analogB : 4; + } Mode1; + + struct { + // first data byte (bitfields are sorted in LSB order) + uint8_t a : 1; + uint8_t b : 1; + uint8_t x : 1; + uint8_t y : 1; + uint8_t start : 1; + uint8_t origin : 1; // Indicates if GetOrigin(0x41) was called (LOW) + uint8_t errlatch : 1; + uint8_t errstat : 1; + + // second data byte + uint8_t dleft : 1; + uint8_t dright : 1; + uint8_t ddown : 1; + uint8_t dup : 1; + uint8_t z : 1; + uint8_t r : 1; + uint8_t l : 1; + uint8_t high1 : 1; + + // 3rd-8th data byte + uint8_t xAxis; + uint8_t yAxis; + uint8_t cxAxis : 4; + uint8_t cyAxis : 4; + uint8_t left : 4; + uint8_t right : 4; + uint8_t analogA; + uint8_t analogB; + } Mode2; + + struct { + // first data byte (bitfields are sorted in LSB order) + uint8_t a : 1; + uint8_t b : 1; + uint8_t x : 1; + uint8_t y : 1; + uint8_t start : 1; + uint8_t origin : 1; // Indicates if GetOrigin(0x41) was called (LOW) + uint8_t errlatch : 1; + uint8_t errstat : 1; + + // second data byte + uint8_t dleft : 1; + uint8_t dright : 1; + uint8_t ddown : 1; + uint8_t dup : 1; + uint8_t z : 1; + uint8_t r : 1; + uint8_t l : 1; + uint8_t high1 : 1; + + // 3rd-8th data byte + uint8_t xAxis; + uint8_t yAxis; + uint8_t cxAxis; + uint8_t cyAxis; + uint8_t analogA; + uint8_t analogB; + } Mode4; +} Gamecube_Different_Report_t; // Gamecube an N64 use the same status schema typedef Gamecube_N64_Status_t Gamecube_Status_t; From cf33bcebb615adb662b4c81381b6212d6dce65db Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Fri, 9 Jul 2021 02:52:42 +0900 Subject: [PATCH 4/8] Update Gamecube.c --- src/Gamecube.c | 75 +++++++++++++++++++++----------------------------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/src/Gamecube.c b/src/Gamecube.c index 7191c45..8dcd9db 100644 --- a/src/Gamecube.c +++ b/src/Gamecube.c @@ -80,53 +80,40 @@ bool gc_read(const uint8_t pin, Gamecube_Report_t* report, const bool rumble) void gc_report_convert(Gamecube_Report_t* report, Gamecube_Different_Report_t* dif, uint8_t mode) { - dif->a = report->a; - dif->b = report->b; - dif->x = report->x; - dif->y = report->y; - dif->start = report->start; - dif->dleft = report->dleft; - dif->dright = report->dright; - dif->ddown = report->ddown; - dif->dup = report->dup; - dif->z = report->z; - dif->r = report->r; - dif->l = report->l; - dif->xAxis = report->xAxis; - dif->yAxis = report->yAxis; - if (mode == 0 || mode == 5 || mode == 6 || mode == 7) + memcpy(dif->raw8, report->raw8, 4); + if (mode == 1) { - dif->Mode0.cxAxis = report->cxAxis; - dif->Mode0.cyAxis = report->cyAxis; - dif->Mode0.left = report->left >> 4; - dif->Mode0.right = report->right >> 4; - dif->Mode0.analogA = 0; - dif->Mode0.analogB = 0; - } - else if (mode == 1) - { - dif->Mode1.cxAxis = report->cxAxis >> 4; - dif->Mode1.cyAxis = report->cyAxis >> 4; - dif->Mode1.left = report->left; - dif->Mode1.right = report->right; - dif->Mode1.analogA = 0; - dif->Mode1.analogB = 0; + dif->mode1.cxAxis = report->cxAxis >> 4; + dif->mode1.cyAxis = report->cyAxis >> 4; + dif->mode1.left = report->left; + dif->mode1.right = report->right; + dif->mode1.analogA = 0; + dif->mode1.analogB = 0; } else if (mode == 2) { - dif->Mode2.cxAxis = report->cxAxis >> 4; - dif->Mode2.cyAxis = report->cyAxis >> 4; - dif->Mode2.left = report->left >> 4; - dif->Mode2.right = report->right >> 4; - dif->Mode2.analogA = 0; - dif->Mode2.analogB = 0; + dif->mode2.cxAxis = report->cxAxis >> 4; + dif->mode2.cyAxis = report->cyAxis >> 4; + dif->mode2.left = report->left >> 4; + dif->mode2.right = report->right >> 4; + dif->mode2.analogA = 0; + dif->mode2.analogB = 0; } else if (mode == 4) { - dif->Mode4.cxAxis = report->cxAxis; - dif->Mode4.cyAxis = report->cyAxis; - dif->Mode4.analogA = 0; - dif->Mode4.analogB = 0; + dif->mode4.cxAxis = report->cxAxis; + dif->mode4.cyAxis = report->cyAxis; + dif->mode4.analogA = 0; + dif->mode4.analogB = 0; + } + else + { + dif->mode0.cxAxis = report->cxAxis; + dif->mode0.cyAxis = report->cyAxis; + dif->mode0.left = report->left >> 4; + dif->mode0.right = report->right >> 4; + dif->mode0.analogA = 0; + dif->mode0.analogB = 0; } } @@ -151,14 +138,14 @@ uint8_t gc_write(const uint8_t pin, Gamecube_Status_t* status, Gamecube_Origin_t uint8_t command[3]; uint8_t receivedBytes = gc_n64_get(command, sizeof(command), modePort, outPort, inPort, bitMask); - // Init - if (receivedBytes == 1 && command[0] == 0x00) + // Init or reset + if (receivedBytes == 1 && (command[0] == 0x00 || command[0] == 0xFF)) { gc_n64_send(status->raw8, sizeof(Gamecube_Status_t), modePort, outPort, bitMask); ret = 1; } - // Get origin - else if (receivedBytes == 1 && command[0] == 0x41) + // Get origin or recalibrate + else if (receivedBytes == 1 && (command[0] == 0x41 || command[0] == 0x42)) { gc_n64_send(origin->raw8, sizeof(Gamecube_Origin_t), modePort, outPort, bitMask); ret = 2; From de1468c7a4b5e698876c74b2a5588a750a8c1722 Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Fri, 9 Jul 2021 02:54:58 +0900 Subject: [PATCH 5/8] Update Gamecube.h --- src/Gamecube.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Gamecube.h b/src/Gamecube.h index 9723ab6..cde8f1d 100644 --- a/src/Gamecube.h +++ b/src/Gamecube.h @@ -130,7 +130,7 @@ typedef union{ uint8_t cyAxis; uint8_t left; uint8_t right; - }; + }; // mode3 (default reading mode) struct { // first data byte (bitfields are sorted in LSB order) @@ -166,7 +166,7 @@ typedef union{ uint8_t right : 4; uint8_t analogA : 4; uint8_t analogB : 4; - } Mode0; + } mode0; struct { // first data byte (bitfields are sorted in LSB order) @@ -198,7 +198,7 @@ typedef union{ uint8_t right; uint8_t analogA : 4; uint8_t analogB : 4; - } Mode1; + } mode1; struct { // first data byte (bitfields are sorted in LSB order) @@ -230,7 +230,7 @@ typedef union{ uint8_t right : 4; uint8_t analogA; uint8_t analogB; - } Mode2; + } mode2; struct { // first data byte (bitfields are sorted in LSB order) @@ -260,7 +260,7 @@ typedef union{ uint8_t cyAxis; uint8_t analogA; uint8_t analogB; - } Mode4; + } mode4; } Gamecube_Different_Report_t; // Gamecube an N64 use the same status schema From b008b8754f7e558ccc4e86b95e7fde7cc3b7ee4b Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Fri, 9 Jul 2021 18:01:40 +0900 Subject: [PATCH 6/8] Update Gamecube.c --- src/Gamecube.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/Gamecube.c b/src/Gamecube.c index 8dcd9db..9d7dfa9 100644 --- a/src/Gamecube.c +++ b/src/Gamecube.c @@ -80,7 +80,7 @@ bool gc_read(const uint8_t pin, Gamecube_Report_t* report, const bool rumble) void gc_report_convert(Gamecube_Report_t* report, Gamecube_Different_Report_t* dif, uint8_t mode) { - memcpy(dif->raw8, report->raw8, 4); + memcpy(dif, report, sizeof(dif)); if (mode == 1) { dif->mode1.cxAxis = report->cxAxis >> 4; @@ -106,6 +106,10 @@ void gc_report_convert(Gamecube_Report_t* report, Gamecube_Different_Report_t* d dif->mode4.analogA = 0; dif->mode4.analogB = 0; } + else if (mode == 3) + { + return; + } else { dif->mode0.cxAxis = report->cxAxis; @@ -153,16 +157,10 @@ uint8_t gc_write(const uint8_t pin, Gamecube_Status_t* status, Gamecube_Origin_t // Get data. Do not check last byte (command[2]), as the flags are unknown else if (receivedBytes == 3 && command[0] == 0x40 && command[1] <= 0x07) { - if (command[1] == 0x03) - { - gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask); - ret = 3; - } else { - Gamecube_Different_Report_t dif; - gc_report_convert(report, &dif, command[1]); - gc_n64_send(dif.raw8, sizeof(Gamecube_Different_Report_t), modePort, outPort, bitMask); - ret = 3; - } + Gamecube_Different_Report_t dif; + gc_report_convert(report, &dif, command[1]); + gc_n64_send(dif.raw8, sizeof(Gamecube_Different_Report_t), modePort, outPort, bitMask); + ret = 3; // The first byte probably flags a gamecube reading (0x40), as the same // protocol is also used for N64. The lower nibble seems to be the mode: // 0x40 (followed by 2 bytes) reading From 8154019826000cfa177a4cd37f3e68687e1387ba Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Fri, 9 Jul 2021 21:04:40 +0900 Subject: [PATCH 7/8] Update Gamecube.c --- src/Gamecube.c | 48 +++++++++++++++++++++--------------------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/src/Gamecube.c b/src/Gamecube.c index 9d7dfa9..413db92 100644 --- a/src/Gamecube.c +++ b/src/Gamecube.c @@ -78,33 +78,30 @@ bool gc_read(const uint8_t pin, Gamecube_Report_t* report, const bool rumble) // Gamecube Console //================================================================================ -void gc_report_convert(Gamecube_Report_t* report, Gamecube_Different_Report_t* dif, uint8_t mode) +void gc_report_convert(Gamecube_Report_t* report, uint8_t mode) { - memcpy(dif, report, sizeof(dif)); if (mode == 1) { - dif->mode1.cxAxis = report->cxAxis >> 4; - dif->mode1.cyAxis = report->cyAxis >> 4; - dif->mode1.left = report->left; - dif->mode1.right = report->right; - dif->mode1.analogA = 0; - dif->mode1.analogB = 0; + report->mode1.cxAxis = report->cxAxis >> 4; + report->mode1.cyAxis = report->cyAxis >> 4; + report->mode1.left = report->left; + report->mode1.right = report->right; + report->mode1.analogA = 0; + report->mode1.analogB = 0; } else if (mode == 2) { - dif->mode2.cxAxis = report->cxAxis >> 4; - dif->mode2.cyAxis = report->cyAxis >> 4; - dif->mode2.left = report->left >> 4; - dif->mode2.right = report->right >> 4; - dif->mode2.analogA = 0; - dif->mode2.analogB = 0; + report->mode2.cxAxis = report->cxAxis >> 4; + report->mode2.cyAxis = report->cyAxis >> 4; + report->mode2.left = report->left >> 4; + report->mode2.right = report->right >> 4; + report->mode2.analogA = 0; + report->mode2.analogB = 0; } else if (mode == 4) { - dif->mode4.cxAxis = report->cxAxis; - dif->mode4.cyAxis = report->cyAxis; - dif->mode4.analogA = 0; - dif->mode4.analogB = 0; + report->mode4.analogA = 0; + report->mode4.analogB = 0; } else if (mode == 3) { @@ -112,12 +109,10 @@ void gc_report_convert(Gamecube_Report_t* report, Gamecube_Different_Report_t* d } else { - dif->mode0.cxAxis = report->cxAxis; - dif->mode0.cyAxis = report->cyAxis; - dif->mode0.left = report->left >> 4; - dif->mode0.right = report->right >> 4; - dif->mode0.analogA = 0; - dif->mode0.analogB = 0; + report->mode0.left = report->left >> 4; + report->mode0.right = report->right >> 4; + report->mode0.analogA = 0; + report->mode0.analogB = 0; } } @@ -157,9 +152,8 @@ uint8_t gc_write(const uint8_t pin, Gamecube_Status_t* status, Gamecube_Origin_t // Get data. Do not check last byte (command[2]), as the flags are unknown else if (receivedBytes == 3 && command[0] == 0x40 && command[1] <= 0x07) { - Gamecube_Different_Report_t dif; - gc_report_convert(report, &dif, command[1]); - gc_n64_send(dif.raw8, sizeof(Gamecube_Different_Report_t), modePort, outPort, bitMask); + gc_report_convert(report, command[1]); + gc_n64_send(report->raw8, sizeof(Gamecube_Report_t), modePort, outPort, bitMask); ret = 3; // The first byte probably flags a gamecube reading (0x40), as the same // protocol is also used for N64. The lower nibble seems to be the mode: From f410bc0708e371cd405b509132b802ea4afebffe Mon Sep 17 00:00:00 2001 From: mizuyoukan-ao <48982871+mizuyoukanao@users.noreply.github.com> Date: Fri, 9 Jul 2021 21:06:11 +0900 Subject: [PATCH 8/8] Update Gamecube.h --- src/Gamecube.h | 48 ++---------------------------------------------- 1 file changed, 2 insertions(+), 46 deletions(-) diff --git a/src/Gamecube.h b/src/Gamecube.h index cde8f1d..86ff03b 100644 --- a/src/Gamecube.h +++ b/src/Gamecube.h @@ -43,51 +43,6 @@ THE SOFTWARE. // Gamecube Typedefs //================================================================================ -typedef union{ - // 8 bytes of datareport that we get from the controller - uint8_t raw8[8]; - uint16_t raw16[0]; - uint32_t raw32[0]; - - struct{ - uint8_t buttons0; - union{ - uint8_t buttons1; - uint8_t dpad : 4; - }; - }; - - struct { - // first data byte (bitfields are sorted in LSB order) - uint8_t a : 1; - uint8_t b : 1; - uint8_t x : 1; - uint8_t y : 1; - uint8_t start : 1; - uint8_t origin : 1; // Indicates if GetOrigin(0x41) was called (LOW) - uint8_t errlatch : 1; - uint8_t errstat : 1; - - // second data byte - uint8_t dleft : 1; - uint8_t dright : 1; - uint8_t ddown : 1; - uint8_t dup : 1; - uint8_t z : 1; - uint8_t r : 1; - uint8_t l : 1; - uint8_t high1 : 1; - - // 3rd-8th data byte - uint8_t xAxis; - uint8_t yAxis; - uint8_t cxAxis; - uint8_t cyAxis; - uint8_t left; - uint8_t right; - }; -} Gamecube_Report_t; - typedef union{ // 8 bytes of datareport that we get from the controller uint8_t raw8[8]; @@ -261,7 +216,8 @@ typedef union{ uint8_t analogA; uint8_t analogB; } mode4; -} Gamecube_Different_Report_t; + +} Gamecube_Report_t; // Gamecube an N64 use the same status schema typedef Gamecube_N64_Status_t Gamecube_Status_t;