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
Conversation
df8fcd6
to
217f989
Compare
}; | ||
|
||
ConnectionState m_state = ConnectionState::AcceptCommand; | ||
u8 m_cmd; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
193b068
to
c2b2be2
Compare
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
} | ||
else | ||
{ | ||
num_data_received = 5; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
||
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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. |
@endrift I don't think I can add reviewers, but if you post a review comment I think GitHub will automatically add you. |
There was a problem hiding this 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.
This comment was marked as off-topic.
Sorry, something went wrong.
} | ||
if (num_data_received > 0) | ||
m_state = ConnectionState::AcceptCommand; | ||
return num_data_received; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
Relevant commits from Orca: |
There was a problem hiding this 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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
7c97e98
to
c2503a4
Compare
Just to state the obvious here, but please make sure to actually test it :D |
@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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
} | ||
else | ||
{ | ||
num_data_received = RECV_MAX_SIZE; |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
{ | ||
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
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.
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.
Inspired by, and a replacement for, #5147.