LINK: Remove some of the internal linn state from the interface
git-svn-id: https://svn.code.sf.net/p/vbam/code/branches/bgk-link@1128 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
parent
e0ece3f35b
commit
55ce3002f4
|
@ -147,6 +147,59 @@ int WaitForSingleObject(sem_t *s, int t)
|
||||||
|
|
||||||
#define UPDATE_REG(address, value) WRITE16LE(((u16 *)&ioMem[address]),value)
|
#define UPDATE_REG(address, value) WRITE16LE(((u16 *)&ioMem[address]),value)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
u16 linkdata[5];
|
||||||
|
u16 linkcmd;
|
||||||
|
u16 numtransfers;
|
||||||
|
int lastlinktime;
|
||||||
|
u8 numgbas;
|
||||||
|
u8 trgbas;
|
||||||
|
u8 linkflags;
|
||||||
|
int rfu_q[4];
|
||||||
|
u8 rfu_request[4];
|
||||||
|
int rfu_linktime[4];
|
||||||
|
u32 rfu_bdata[4][7];
|
||||||
|
u32 rfu_data[4][32];
|
||||||
|
} LINKDATA;
|
||||||
|
|
||||||
|
class lserver{
|
||||||
|
int numbytes;
|
||||||
|
sf::Selector<sf::SocketTCP> fdset;
|
||||||
|
//timeval udptimeout;
|
||||||
|
char inbuffer[256], outbuffer[256];
|
||||||
|
s32 *intinbuffer;
|
||||||
|
u16 *u16inbuffer;
|
||||||
|
s32 *intoutbuffer;
|
||||||
|
u16 *u16outbuffer;
|
||||||
|
int counter;
|
||||||
|
int done;
|
||||||
|
public:
|
||||||
|
int howmanytimes;
|
||||||
|
sf::SocketTCP tcpsocket[4];
|
||||||
|
sf::IPAddress udpaddr[4];
|
||||||
|
lserver(void);
|
||||||
|
void Send(void);
|
||||||
|
void Recv(void);
|
||||||
|
};
|
||||||
|
|
||||||
|
class lclient{
|
||||||
|
sf::Selector<sf::SocketTCP> fdset;
|
||||||
|
char inbuffer[256], outbuffer[256];
|
||||||
|
s32 *intinbuffer;
|
||||||
|
u16 *u16inbuffer;
|
||||||
|
s32 *intoutbuffer;
|
||||||
|
u16 *u16outbuffer;
|
||||||
|
int numbytes;
|
||||||
|
public:
|
||||||
|
sf::IPAddress serveraddr;
|
||||||
|
unsigned short serverport;
|
||||||
|
int numtransfers;
|
||||||
|
lclient(void);
|
||||||
|
void Send(void);
|
||||||
|
void Recv(void);
|
||||||
|
void CheckConn(void);
|
||||||
|
};
|
||||||
|
|
||||||
static LinkMode gba_link_mode = LINK_DISCONNECTED;
|
static LinkMode gba_link_mode = LINK_DISCONNECTED;
|
||||||
static ConnectionState gba_connection_state = LINK_OK;
|
static ConnectionState gba_connection_state = LINK_OK;
|
||||||
|
|
||||||
|
@ -165,7 +218,7 @@ sf::IPAddress joybusHostAddr = sf::IPAddress::LocalHost;
|
||||||
// Hodgepodge
|
// Hodgepodge
|
||||||
u8 tspeed = 3;
|
u8 tspeed = 3;
|
||||||
u8 transfer = 0;
|
u8 transfer = 0;
|
||||||
LINKDATA *linkmem = NULL;
|
static LINKDATA *linkmem = NULL;
|
||||||
int linkid = 0;
|
int linkid = 0;
|
||||||
#if (defined __WIN32__ || defined _WIN32)
|
#if (defined __WIN32__ || defined _WIN32)
|
||||||
HANDLE linksync[4];
|
HANDLE linksync[4];
|
||||||
|
@ -187,8 +240,8 @@ static int i, j;
|
||||||
int linktimeout = 1000;
|
int linktimeout = 1000;
|
||||||
LANLINKDATA lanlink;
|
LANLINKDATA lanlink;
|
||||||
u16 linkdata[4];
|
u16 linkdata[4];
|
||||||
lserver ls;
|
static lserver ls;
|
||||||
lclient lc;
|
static lclient lc;
|
||||||
bool oncewait = false, after = false;
|
bool oncewait = false, after = false;
|
||||||
|
|
||||||
// RFU crap (except for numtransfers note...should probably check that out)
|
// RFU crap (except for numtransfers note...should probably check that out)
|
||||||
|
@ -254,8 +307,6 @@ void StartLink(u16 value)
|
||||||
}
|
}
|
||||||
if (start) {
|
if (start) {
|
||||||
if (GetLinkMode() == LINK_CABLE_SOCKET)
|
if (GetLinkMode() == LINK_CABLE_SOCKET)
|
||||||
{
|
|
||||||
if (lanlink.connected)
|
|
||||||
{
|
{
|
||||||
linkdata[0] = READ16LE(&ioMem[COMM_SIODATA8]);
|
linkdata[0] = READ16LE(&ioMem[COMM_SIODATA8]);
|
||||||
savedlinktime = linktime;
|
savedlinktime = linktime;
|
||||||
|
@ -266,12 +317,10 @@ void StartLink(u16 value)
|
||||||
UPDATE_REG(COMM_SIOMULTI0, linkdata[0]);
|
UPDATE_REG(COMM_SIOMULTI0, linkdata[0]);
|
||||||
UPDATE_REG(COMM_SIOMULTI1, 0xffff);
|
UPDATE_REG(COMM_SIOMULTI1, 0xffff);
|
||||||
WRITE32LE(&ioMem[COMM_SIOMULTI2], 0xffffffff);
|
WRITE32LE(&ioMem[COMM_SIOMULTI2], 0xffffffff);
|
||||||
if (lanlink.speed&&oncewait == false)
|
if (lanlink.speed && oncewait == false)
|
||||||
ls.howmanytimes++;
|
ls.howmanytimes++;
|
||||||
after = false;
|
after = false;
|
||||||
value &= ~0x40;
|
value &= ~0x40;
|
||||||
} else
|
|
||||||
value |= 0x40; // comm error
|
|
||||||
}
|
}
|
||||||
else if (linkmem->numgbas > 1)
|
else if (linkmem->numgbas > 1)
|
||||||
{
|
{
|
||||||
|
@ -316,6 +365,8 @@ void StartLink(u16 value)
|
||||||
WRITE32LE(&ioMem[COMM_SIOMULTI0], 0xffffffff);
|
WRITE32LE(&ioMem[COMM_SIOMULTI0], 0xffffffff);
|
||||||
WRITE32LE(&ioMem[COMM_SIOMULTI2], 0xffffffff);
|
WRITE32LE(&ioMem[COMM_SIOMULTI2], 0xffffffff);
|
||||||
value &= ~0x40;
|
value &= ~0x40;
|
||||||
|
} else {
|
||||||
|
value |= 0x40; // comm error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
value |= (transfer != 0) << 7;
|
value |= (transfer != 0) << 7;
|
||||||
|
@ -464,8 +515,6 @@ void LinkUpdate(int ticks)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (GetLinkMode() == LINK_CABLE_SOCKET)
|
if (GetLinkMode() == LINK_CABLE_SOCKET)
|
||||||
{
|
|
||||||
if (lanlink.connected)
|
|
||||||
{
|
{
|
||||||
if (after)
|
if (after)
|
||||||
{
|
{
|
||||||
|
@ -528,7 +577,6 @@ void LinkUpdate(int ticks)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1172,8 +1220,6 @@ ConnectionState ConnectLinkUpdate(char * const message, size_t size)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lanlink.numslaves == lanlink.connectedSlaves) {
|
if (lanlink.numslaves == lanlink.connectedSlaves) {
|
||||||
lanlink.connected = true;
|
|
||||||
|
|
||||||
for (int i = 1; i <= lanlink.numslaves; i++) {
|
for (int i = 1; i <= lanlink.numslaves; i++) {
|
||||||
sf::Packet packet;
|
sf::Packet packet;
|
||||||
packet << true;
|
packet << true;
|
||||||
|
@ -1210,7 +1256,6 @@ ConnectionState ConnectLinkUpdate(char * const message, size_t size)
|
||||||
packet >> gameReady;
|
packet >> gameReady;
|
||||||
|
|
||||||
if (packet && gameReady) {
|
if (packet && gameReady) {
|
||||||
lanlink.connected = true;
|
|
||||||
gba_connection_state = LINK_OK;
|
gba_connection_state = LINK_OK;
|
||||||
snprintf(message, size, N_("All players joined."));
|
snprintf(message, size, N_("All players joined."));
|
||||||
}
|
}
|
||||||
|
@ -1268,7 +1313,7 @@ void CloseLink(void){
|
||||||
JoyBusShutdown();
|
JoyBusShutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lanlink.connected){
|
if (gba_link_mode == LINK_CABLE_SOCKET) {
|
||||||
if(linkid){
|
if(linkid){
|
||||||
char outbuffer[4];
|
char outbuffer[4];
|
||||||
outbuffer[0] = 4;
|
outbuffer[0] = 4;
|
||||||
|
@ -1424,7 +1469,6 @@ void lserver::Recv(void){
|
||||||
if(howmanytimes>1) memmove(inbuffer, inbuffer+inbuffer[0]*(howmanytimes-1), inbuffer[0]);
|
if(howmanytimes>1) memmove(inbuffer, inbuffer+inbuffer[0]*(howmanytimes-1), inbuffer[0]);
|
||||||
if(inbuffer[1]==-32){
|
if(inbuffer[1]==-32){
|
||||||
char message[30];
|
char message[30];
|
||||||
lanlink.connected = false;
|
|
||||||
sprintf(message, _("Player %d disconnected."), i+2);
|
sprintf(message, _("Player %d disconnected."), i+2);
|
||||||
systemScreenMessage(message);
|
systemScreenMessage(message);
|
||||||
outbuffer[0] = 4;
|
outbuffer[0] = 4;
|
||||||
|
@ -1435,6 +1479,7 @@ void lserver::Recv(void){
|
||||||
tcpsocket[i].Receive(inbuffer, 256, nr);
|
tcpsocket[i].Receive(inbuffer, 256, nr);
|
||||||
tcpsocket[i].Close();
|
tcpsocket[i].Close();
|
||||||
}
|
}
|
||||||
|
CloseLink();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
linkdata[i+1] = READ16LE(&u16inbuffer[1]);
|
linkdata[i+1] = READ16LE(&u16inbuffer[1]);
|
||||||
|
@ -1445,6 +1490,13 @@ void lserver::Recv(void){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CheckLinkConnection() {
|
||||||
|
if (GetLinkMode() == LINK_CABLE_SOCKET) {
|
||||||
|
if (linkid && lc.numtransfers == 0) {
|
||||||
|
lc.CheckConn();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Client
|
// Client
|
||||||
lclient::lclient(void){
|
lclient::lclient(void){
|
||||||
|
@ -1468,8 +1520,8 @@ void lclient::CheckConn(void){
|
||||||
if(inbuffer[1]==-32){
|
if(inbuffer[1]==-32){
|
||||||
outbuffer[0] = 4;
|
outbuffer[0] = 4;
|
||||||
lanlink.tcpsocket.Send(outbuffer, 4);
|
lanlink.tcpsocket.Send(outbuffer, 4);
|
||||||
lanlink.connected = false;
|
|
||||||
systemScreenMessage(_("Server disconnected."));
|
systemScreenMessage(_("Server disconnected."));
|
||||||
|
CloseLink();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
numtransfers = 1;
|
numtransfers = 1;
|
||||||
|
@ -1507,8 +1559,8 @@ void lclient::Recv(void){
|
||||||
if(inbuffer[1]==-32){
|
if(inbuffer[1]==-32){
|
||||||
outbuffer[0] = 4;
|
outbuffer[0] = 4;
|
||||||
lanlink.tcpsocket.Send(outbuffer, 4);
|
lanlink.tcpsocket.Send(outbuffer, 4);
|
||||||
lanlink.connected = false;
|
|
||||||
systemScreenMessage(_("Server disconnected."));
|
systemScreenMessage(_("Server disconnected."));
|
||||||
|
CloseLink();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
tspeed = inbuffer[1] & 3;
|
tspeed = inbuffer[1] & 3;
|
||||||
|
|
|
@ -62,6 +62,11 @@ extern void SetLinkServerHost(const char *host);
|
||||||
*/
|
*/
|
||||||
extern void GetLinkServerHost(char * const host, size_t size);
|
extern void GetLinkServerHost(char * const host, size_t size);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verify that the link between the emulators is still active
|
||||||
|
*/
|
||||||
|
extern void CheckLinkConnection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the current link mode to LINK_DISCONNECTED
|
* Set the current link mode to LINK_DISCONNECTED
|
||||||
*/
|
*/
|
||||||
|
@ -121,67 +126,12 @@ extern const char *MakeInstanceFilename(const char *Input);
|
||||||
// Link implementation
|
// Link implementation
|
||||||
#include <SFML/Network.hpp>
|
#include <SFML/Network.hpp>
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
u16 linkdata[5];
|
|
||||||
u16 linkcmd;
|
|
||||||
u16 numtransfers;
|
|
||||||
int lastlinktime;
|
|
||||||
u8 numgbas;
|
|
||||||
u8 trgbas;
|
|
||||||
u8 linkflags;
|
|
||||||
int rfu_q[4];
|
|
||||||
u8 rfu_request[4];
|
|
||||||
int rfu_linktime[4];
|
|
||||||
u32 rfu_bdata[4][7];
|
|
||||||
u32 rfu_data[4][32];
|
|
||||||
} LINKDATA;
|
|
||||||
|
|
||||||
class lserver{
|
|
||||||
int numbytes;
|
|
||||||
sf::Selector<sf::SocketTCP> fdset;
|
|
||||||
//timeval udptimeout;
|
|
||||||
char inbuffer[256], outbuffer[256];
|
|
||||||
s32 *intinbuffer;
|
|
||||||
u16 *u16inbuffer;
|
|
||||||
s32 *intoutbuffer;
|
|
||||||
u16 *u16outbuffer;
|
|
||||||
int counter;
|
|
||||||
int done;
|
|
||||||
public:
|
|
||||||
int howmanytimes;
|
|
||||||
sf::SocketTCP tcpsocket[4];
|
|
||||||
sf::IPAddress udpaddr[4];
|
|
||||||
lserver(void);
|
|
||||||
void Send(void);
|
|
||||||
void Recv(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
class lclient{
|
|
||||||
sf::Selector<sf::SocketTCP> fdset;
|
|
||||||
char inbuffer[256], outbuffer[256];
|
|
||||||
s32 *intinbuffer;
|
|
||||||
u16 *u16inbuffer;
|
|
||||||
s32 *intoutbuffer;
|
|
||||||
u16 *u16outbuffer;
|
|
||||||
int numbytes;
|
|
||||||
public:
|
|
||||||
sf::IPAddress serveraddr;
|
|
||||||
unsigned short serverport;
|
|
||||||
sf::SocketTCP noblock;
|
|
||||||
int numtransfers;
|
|
||||||
lclient(void);
|
|
||||||
void Send(void);
|
|
||||||
void Recv(void);
|
|
||||||
void CheckConn(void);
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
sf::SocketTCP tcpsocket;
|
sf::SocketTCP tcpsocket;
|
||||||
int numslaves;
|
int numslaves;
|
||||||
int connectedSlaves;
|
int connectedSlaves;
|
||||||
int type;
|
int type;
|
||||||
bool server;
|
bool server;
|
||||||
bool connected;
|
|
||||||
bool speed;
|
bool speed;
|
||||||
} LANLINKDATA;
|
} LANLINKDATA;
|
||||||
|
|
||||||
|
@ -195,8 +145,6 @@ extern void CleanLocalLink();
|
||||||
extern LANLINKDATA lanlink;
|
extern LANLINKDATA lanlink;
|
||||||
extern int vbaid;
|
extern int vbaid;
|
||||||
extern int linktimeout;
|
extern int linktimeout;
|
||||||
extern lclient lc;
|
|
||||||
extern lserver ls;
|
|
||||||
extern int linkid;
|
extern int linkid;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -122,7 +122,7 @@ public:
|
||||||
wxLogError(_("Error occurred.\nPlease try again."));
|
wxLogError(_("Error occurred.\nPlease try again."));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lanlink.connected) {
|
if(GetLinkMode() != LINK_DISCONNECTED) {
|
||||||
connmsg.Replace(wxT("\n"), wxT(" "));
|
connmsg.Replace(wxT("\n"), wxT(" "));
|
||||||
systemScreenMessage(connmsg);
|
systemScreenMessage(connmsg);
|
||||||
|
|
||||||
|
|
|
@ -836,8 +836,8 @@ void GameArea::OnIdle(wxIdleEvent &event)
|
||||||
}
|
}
|
||||||
emusys->emuMain(emusys->emuCount);
|
emusys->emuMain(emusys->emuCount);
|
||||||
#ifndef NO_LINK
|
#ifndef NO_LINK
|
||||||
if(loaded == IMAGE_GBA && lanlink.connected && linkid && lc.numtransfers == 0)
|
if (loaded == IMAGE_GBA && GetLinkMode() != LINK_DISCONNECTED)
|
||||||
lc.CheckConn();
|
CheckLinkConnection();
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
was_paused = true;
|
was_paused = true;
|
||||||
|
|
Loading…
Reference in New Issue