Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SI_DeviceGBA: refactor and make GBASockServer a member rather than parent #5169

Merged
merged 10 commits into from Aug 4, 2017

Conversation

ligfx
Copy link
Contributor

@ligfx ligfx commented Mar 26, 2017

Inspired by, and a replacement for, #5147.

@ligfx ligfx force-pushed the sidevicegbastate branch 3 times, most recently from df8fcd6 to 217f989 Compare March 26, 2017 05:10
};

ConnectionState m_state = ConnectionState::AcceptCommand;
u8 m_cmd;

This comment was marked as off-topic.

This comment was marked as off-topic.

@ligfx ligfx changed the title SI_DeviceGBA: clarify request-response state machine SI_DeviceGBA: refactor and make GBASockServer a member rather than parent Mar 31, 2017
@ligfx ligfx force-pushed the sidevicegbastate branch 6 times, most recently from 193b068 to c2b2be2 Compare March 31, 2017 23:15
m_timestamp_sent = CoreTiming::GetTicks();
m_waiting_for_response = true;
m_state = ConnectionState::WaitForTransferTime;

This comment was marked as off-topic.

This comment was marked as off-topic.

}
else
{
num_data_received = 5;

This comment was marked as off-topic.

This comment was marked as off-topic.


if (m_cmd != CMD_STATUS)
m_booted = true;
status = m_client->send(send_data.data(), 1);

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

void Send(const u8* si_buffer);
int Receive(u8* si_buffer);

private:
void Disconnect();

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@ligfx
Copy link
Contributor Author

ligfx commented May 4, 2017

@skidau @endrift I see you've worked on this before, would you mind taking a glance if you have the time?

@endrift
Copy link
Contributor

endrift commented May 4, 2017

I can't look at this right now, but please don't merge it until I get a chance to look over it. Add me as a reviewer, etc.

@ligfx
Copy link
Contributor Author

ligfx commented May 4, 2017

@endrift I don't think I can add reviewers, but if you post a review comment I think GitHub will automatically add you.

Copy link
Contributor

@endrift endrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty dang different from the fixes I had for this, but it's worth pointing out that SI_DeviceGBA is quite buggy and incorrect atm. I didn't bother with a PR because I was probably going to yank out a lot of the changes when I got around to Orca, and it would break VBA-M too, but if you're here already, now's a good time to fix them.


if (m_cmd != CMD_STATUS)
m_booted = true;
status = m_client->send(send_data.data(), 1);

This comment was marked as off-topic.

}
if (num_data_received > 0)
m_state = ConnectionState::AcceptCommand;
return num_data_received;

This comment was marked as off-topic.

@endrift
Copy link
Contributor

endrift commented May 5, 2017

Relevant commits from Orca:
endrift@ed68c3c
endrift@1dba026

Copy link
Contributor

@endrift endrift left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revised my review with the understanding that you don't want to update the visible logic.

@@ -136,39 +128,29 @@ void GBAConnectionWaiter_Shutdown()
s_connection_thread.join();
}

static bool GetAvailableSock(std::unique_ptr<sf::TcpSocket>& sock_to_fill)
template <typename T>
static std::unique_ptr<T> MoveFromFront(std::queue<std::unique_ptr<T>>& ptrs)

This comment was marked as off-topic.

This comment was marked as off-topic.

if (!m_client)
if (!GetAvailableSock(m_client))
return;
return m_client || (m_client = GetNextSock());

This comment was marked as off-topic.

This comment was marked as off-topic.

m_num_data_received = 0;
ClockSync();
Send(buffer);
case ConnectionState::AcceptCommand:

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

buffer[2], buffer[1], buffer[0], buffer[7]);
#endif
m_sock_server.Send(buffer);
}

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@ligfx ligfx force-pushed the sidevicegbastate branch 3 times, most recently from 7c97e98 to c2503a4 Compare May 17, 2017 22:06
@shuffle2
Copy link
Contributor

Just to state the obvious here, but please make sure to actually test it :D

@ligfx
Copy link
Contributor Author

ligfx commented Jun 16, 2017

@shuffle2 tested on Four Swords Adventures (multiple GBAs), Crystal Chronicles (multiple GBAs), Metroid Prime, and Billy Hatcher and the Giant Egg :)

}
else
{
constexpr u32 reply = SI_ERROR_NO_RESPONSE;

This comment was marked as off-topic.

This comment was marked as off-topic.

}
else
{
num_data_received = RECV_MAX_SIZE;

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

{
return 0;
int num_data_received = m_sock_server.Receive(buffer);
if (!m_sock_server.IsConnected())

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

@endrift
Copy link
Contributor

endrift commented Jul 14, 2017

Ship it

m_client->receive(m_recv_data.data(), m_recv_data.size(), num_received);
if (recv_stat == sf::Socket::Disconnected)
m_client->receive(recv_data.data(), recv_data.size(), num_received);
if (recv_stat == sf::Socket::Disconnected || recv_stat == sf::Socket::NotReady ||

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

ligfx added 10 commits July 14, 2017 13:57
Inspired by "dolphin-emu#5147: GBASockServer: remove m_device_number (fixes
warning)," trying to wrap my head around how this file works.
Slight behavior change, but fills a gaping hole in the state logic.
Rather than returning 0 / not creating an expected SI interrupt. You can
test this by running VBA-M in a debugger and stopping it while it's
connected to Dolphin: on current master, Dolphin will freeze-up until it
gets a response. With this PR, Dolphin will gracefully disconnect the device, and reconnect if it starts responding again.
@leoetlino leoetlino merged commit 284aa99 into dolphin-emu:master Aug 4, 2017
Steelskin pushed a commit to Steelskin/dolphin that referenced this pull request Sep 8, 2020
In the refactore done in dolphin-emu#5169, the logic was slightly altered to no
longer wait in case the answer from the GBA is delayed. This broke
some games like Final Fantasy Crystal Chronicles.
This fixes Final Fantasy Crystal Chronicles GBA connection on trunk.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
5 participants