Skip to content

Commit

Permalink
Check for POLL command in GamecubeConsole::Detect
Browse files Browse the repository at this point in the history
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
  • Loading branch information
JonnyHaystack committed Jun 22, 2023
1 parent 38f20c5 commit 0498cbb
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/GamecubeConsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,28 @@ 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) {
continue;
}

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);
}
Expand All @@ -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;
Expand Down

0 comments on commit 0498cbb

Please sign in to comment.