summaryrefslogtreecommitdiff
path: root/Source
diff options
context:
space:
mode:
authorShawn Hoffman <godisgovernment@gmail.com>2010-02-22 21:57:05 +0000
committerShawn Hoffman <godisgovernment@gmail.com>2010-02-22 21:57:05 +0000
commita4e9bf3fd2b70fc0e190d0746aaaf7a83a5edea4 (patch)
tree837c89b2c5bc2e4840866089f6778980a88d6bb5 /Source
parent303769d31c27c29e46f7cd3792fd82e49baf0955 (diff)
first implementation of support for multi GBAs. Probably something wrong with thread safety or something - but hey, it works...and I would need help to make it threadsafe *hint* :)
git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5111 8ced0084-cf51-0410-be5f-012b33b47a6e
Diffstat (limited to 'Source')
-rw-r--r--Source/Core/Core/Src/HW/SI_DeviceGBA.cpp67
-rw-r--r--Source/Core/Core/Src/HW/SI_DeviceGBA.h16
2 files changed, 51 insertions, 32 deletions
diff --git a/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp b/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp
index 1e913fe6a9..c46702afd3 100644
--- a/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp
+++ b/Source/Core/Core/Src/HW/SI_DeviceGBA.cpp
@@ -19,26 +19,66 @@
#include "SI_DeviceGBA.h"
#include "SFML/Network.hpp"
-#include <algorithm>
+#include "Thread.h"
+#include <queue>
+
+static Common::Thread *connectionThread = NULL;
+static std::queue<sf::SocketTCP> waiting_socks;
// --- GameBoy Advance "Link Cable" ---
-GBASockServer::GBASockServer()
+
+THREAD_RETURN ConnectionWaiter(void*)
{
- if (!server.Listen(8080))
- return;
+ Common::SetCurrentThreadName("GBA Connection Waiter");
+
+ sf::SocketTCP server;
+ if (!server.Listen(0xd6ba))
+ return 0;
+
+ server.SetBlocking(false);
+
+ for (;;)
+ {
+ sf::SocketTCP new_client;
+ if (server.Accept(new_client) == sf::Socket::Done)
+ {
+ waiting_socks.push(new_client);
+ PanicAlert("Connected");
+ }
+ }
+ server.Close();
+ return 0;
+}
- server.Accept(client, &client_addr);
+bool GetAvailableSock(sf::SocketTCP& sock_to_fill)
+{
+ if (waiting_socks.size() > 0)
+ {
+ sock_to_fill = waiting_socks.front();
+ waiting_socks.pop();
+ return true;
+ }
+ return false;
+}
+
+GBASockServer::GBASockServer()
+{
+ if (!connectionThread)
+ connectionThread = new Common::Thread(ConnectionWaiter, (void*)0);
}
GBASockServer::~GBASockServer()
{
client.Close();
- server.Close();
}
// Blocking, since GBA must always send lower byte of REG_JOYSTAT
void GBASockServer::Transfer(char* si_buffer)
{
+ if (!client.IsValid())
+ if (!GetAvailableSock(client))
+ return;
+
current_data[0] = si_buffer[3];
current_data[1] = si_buffer[2];
current_data[2] = si_buffer[1];
@@ -87,23 +127,8 @@ CSIDevice_GBA::CSIDevice_GBA(int _iDeviceNumber)
{
}
-CSIDevice_GBA::~CSIDevice_GBA()
-{
-}
-
int CSIDevice_GBA::RunBuffer(u8* _pBuffer, int _iLength)
{
Transfer((char*)_pBuffer);
return _iLength;
}
-
-bool CSIDevice_GBA::GetData(u32& _Hi, u32& _Low)
-{
- DEBUG_LOG(SERIALINTERFACE, "GBA %i GetData Hi: 0x%08x Low: 0x%08x", m_iDeviceNumber, _Hi, _Low);
- return true;
-}
-
-void CSIDevice_GBA::SendCommand(u32 _Cmd, u8 _Poll)
-{
- DEBUG_LOG(SERIALINTERFACE, "GBA %i SendCommand: (0x%08x)", m_iDeviceNumber, _Cmd);
-}
diff --git a/Source/Core/Core/Src/HW/SI_DeviceGBA.h b/Source/Core/Core/Src/HW/SI_DeviceGBA.h
index c3da5e9528..41cde2587c 100644
--- a/Source/Core/Core/Src/HW/SI_DeviceGBA.h
+++ b/Source/Core/Core/Src/HW/SI_DeviceGBA.h
@@ -30,10 +30,8 @@ public:
void Transfer(char* si_buffer);
- char current_data[5];
-
private:
- enum EBufferCommands
+ enum EJoybusCmds
{
CMD_RESET = 0xff,
CMD_STATUS = 0x00,
@@ -41,25 +39,21 @@ private:
CMD_WRITE = 0x15
};
- sf::SocketTCP server;
sf::SocketTCP client;
- sf::IPAddress client_addr;
+ char current_data[5];
};
class CSIDevice_GBA : public ISIDevice, private GBASockServer
{
public:
CSIDevice_GBA(int _iDeviceNumber);
- ~CSIDevice_GBA();
+ ~CSIDevice_GBA() {}
// Run the SI Buffer
virtual int RunBuffer(u8* _pBuffer, int _iLength);
- // Return true on new data
- virtual bool GetData(u32& _Hi, u32& _Low);
-
- // Send a command directly
- virtual void SendCommand(u32 _Cmd, u8 _Poll);
+ virtual bool GetData(u32& _Hi, u32& _Low) { return true; }
+ virtual void SendCommand(u32 _Cmd, u8 _Poll) {}
};
#endif