From 0498cbb210f0c0c415d37de2620812ee775c957c Mon Sep 17 00:00:00 2001 From: Jonathan Haylett Date: Thu, 22 Jun 2023 13:57:43 +0100 Subject: [PATCH] Check for POLL command in GamecubeConsole::Detect BootMii sends POLL from the very start, rather than sending probe/origin commands first, so the console detection should take this case into account. Resolves #4 --- src/GamecubeConsole.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/GamecubeConsole.cpp b/src/GamecubeConsole.cpp index 19eb434..8c88b70 100644 --- a/src/GamecubeConsole.cpp +++ b/src/GamecubeConsole.cpp @@ -22,7 +22,7 @@ bool __no_inline_not_in_flash_func(GamecubeConsole::Detect)() { // We make at most 10 attempts to receive and respond to PROBE commands from a console. GameCube // and N64 both have the same PROBE command (0x00), so we don't know for sure that we're - // connected to a GameCube until we receive a GameCube ORIGIN command. + // connected to a GameCube until we receive a GameCube ORIGIN, RECALIBRATE, or POLL command. for (uint8_t attempts = 0; attempts < 10; attempts++) { // Always apply timeout (10ms), so that we don't block indefinitely if nothing is connected. if (joybus_receive_bytes(&_port, received, 1, 10'000, true) != 1) { @@ -30,17 +30,20 @@ bool __no_inline_not_in_flash_func(GamecubeConsole::Detect)() { } switch ((GamecubeCommand)received[0]) { - case GamecubeCommand::RESET: case GamecubeCommand::PROBE: + case GamecubeCommand::RESET: busy_wait_us(reply_delay); joybus_send_bytes(&_port, (uint8_t *)&default_gc_status, sizeof(gc_status_t)); break; - case GamecubeCommand::RECALIBRATE: case GamecubeCommand::ORIGIN: + case GamecubeCommand::RECALIBRATE: + return true; + case GamecubeCommand::POLL: + WaitForPollEnd(); return true; default: - // If we received an invalid command, wait long enough for command - // to finish, then reset receiving. + // If we received an invalid command, wait long enough for command to finish, then + // reset receiving. busy_wait_us(reset_wait_period_us); joybus_port_reset(&_port); } @@ -55,8 +58,7 @@ bool __no_inline_not_in_flash_func(GamecubeConsole::WaitForPoll)() { PollStatus status = WaitForPollEnd(); if (status == PollStatus::ERROR) { - // If poll is invalid, wait long enough for command to finish, then - // reset receiving. + // If poll is invalid, wait long enough for command to finish, then reset receiving. busy_wait_us(reset_wait_period_us); joybus_port_reset(&_port); continue;