bgklink merged to trunk.

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@1239 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
squall-leonhart 2015-03-20 14:23:14 +00:00
parent 9a5e6d107f
commit ffd7277f6d
22 changed files with 1437 additions and 2101 deletions

View File

@ -201,7 +201,6 @@
<ClInclude Include="..\..\src\common\SoundDriver.h" /> <ClInclude Include="..\..\src\common\SoundDriver.h" />
<ClInclude Include="..\..\src\gba\gbalink.h" /> <ClInclude Include="..\..\src\gba\gbalink.h" />
<ClInclude Include="..\..\src\gba\GBASockClient.h" /> <ClInclude Include="..\..\src\gba\GBASockClient.h" />
<ClInclude Include="..\..\src\win32\JoybusOptions.h" />
<ClInclude Include="..\..\src\win32\LinkOptions.h" /> <ClInclude Include="..\..\src\win32\LinkOptions.h" />
<ClInclude Include="..\..\src\win32\stdafx.h" /> <ClInclude Include="..\..\src\win32\stdafx.h" />
<ClInclude Include="..\..\src\win32\targetver.h" /> <ClInclude Include="..\..\src\win32\targetver.h" />
@ -349,7 +348,6 @@
<ClCompile Include="..\..\src\gba\GBASockClient.cpp"> <ClCompile Include="..\..\src\gba\GBASockClient.cpp">
<PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions> <PreprocessorDefinitions Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">_SCL_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\win32\JoybusOptions.cpp" />
<ClCompile Include="..\..\src\win32\LinkOptions.cpp" /> <ClCompile Include="..\..\src\win32\LinkOptions.cpp" />
<ClCompile Include="..\..\src\win32\stdafx.cpp"> <ClCompile Include="..\..\src\win32\stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader> <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>

View File

@ -208,9 +208,6 @@
<ClInclude Include="..\..\src\gba\GBASockClient.h"> <ClInclude Include="..\..\src\gba\GBASockClient.h">
<Filter>Linking</Filter> <Filter>Linking</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\..\src\win32\JoybusOptions.h">
<Filter>Linking</Filter>
</ClInclude>
<ClInclude Include="..\..\src\win32\LinkOptions.h"> <ClInclude Include="..\..\src\win32\LinkOptions.h">
<Filter>Linking</Filter> <Filter>Linking</Filter>
</ClInclude> </ClInclude>
@ -625,9 +622,6 @@
<ClCompile Include="..\..\src\gba\GBASockClient.cpp"> <ClCompile Include="..\..\src\gba\GBASockClient.cpp">
<Filter>Linking</Filter> <Filter>Linking</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\..\src\win32\JoybusOptions.cpp">
<Filter>Linking</Filter>
</ClCompile>
<ClCompile Include="..\..\src\win32\LinkOptions.cpp"> <ClCompile Include="..\..\src\win32\LinkOptions.cpp">
<Filter>Linking</Filter> <Filter>Linking</Filter>
</ClCompile> </ClCompile>

View File

@ -3591,7 +3591,7 @@ void CPULoop(int ticks)
#ifndef NO_LINK #ifndef NO_LINK
// shuffle2: what's the purpose? // shuffle2: what's the purpose?
//if(gba_link_enabled) //if(GetLinkMode() != LINK_DISCONNECTED)
//cpuNextEvent = 1; //cpuNextEvent = 1;
#endif #endif
@ -4042,11 +4042,8 @@ void CPULoop(int ticks)
ticks -= clockTicks; ticks -= clockTicks;
#ifndef NO_LINK #ifndef NO_LINK
if (gba_link_enabled) if (GetLinkMode() != LINK_DISCONNECTED)
LinkUpdate(clockTicks); LinkUpdate(clockTicks);
if (gba_joybus_enabled)
JoyBusUpdate(clockTicks);
#endif #endif
cpuNextEvent = CPUUpdateTicks(); cpuNextEvent = CPUUpdateTicks();
@ -4064,7 +4061,7 @@ void CPULoop(int ticks)
#ifndef NO_LINK #ifndef NO_LINK
// shuffle2: what's the purpose? // shuffle2: what's the purpose?
if(gba_link_enabled || gba_joybus_active) if (GetLinkMode() != LINK_DISCONNECTED || gba_joybus_active)
cpuNextEvent = 1; cpuNextEvent = 1;
#endif #endif

File diff suppressed because it is too large Load Diff

View File

@ -1,23 +1,143 @@
#ifndef GBA_GBALINK_H #ifndef GBA_GBALINK_H
#define GBA_GBALINK_H #define GBA_GBALINK_H
#pragma once /**
* Link modes to be passed to InitLink
*/
enum LinkMode
{
LINK_DISCONNECTED,
LINK_CABLE_IPC,
LINK_CABLE_SOCKET,
LINK_RFU_IPC,
LINK_GAMECUBE_DOLPHIN
};
// register definitions; these are always present /**
* State of the connection attempt
*/
enum ConnectionState
{
LINK_OK,
LINK_ERROR,
LINK_NEEDS_UPDATE,
LINK_ABORT
};
#define UNSUPPORTED -1 /**
#define MULTIPLAYER 0 * Initialize GBA linking
#define NORMAL8 1 *
#define NORMAL32 2 * @param mode Device to emulate, plugged to the GBA link port.
#define UART 3 * @return success
#define JOYBUS 4 */
#define GP 5 extern ConnectionState InitLink(LinkMode mode);
#define RFU_INIT 0 /**
#define RFU_COMM 1 * Update a link connection request
#define RFU_SEND 2 *
#define RFU_RECV 3 * @param message Information message
* @param size Maximum message size
*/
extern ConnectionState ConnectLinkUpdate(char * const message, size_t size);
/**
* Get the currently enabled link mode
*
* @return link mode
*/
extern LinkMode GetLinkMode();
/**
* Is this instance going to host a LAN link server?
*
* @param enabled Server mode
* @param numSlaves Number of expected clients
*/
extern void EnableLinkServer(bool enable, int numSlaves);
/**
* Should speed hacks be used?
*
* @param enabled Speed hacks
*/
extern void EnableSpeedHacks(bool enable);
/**
* Set the host to connect to when in socket mode
*
* @return false if the address is invalid
*/
extern bool SetLinkServerHost(const char *host);
/**
* Get the host relevant to context
*
* If in lan server mode, returns the external IP adress
* If in lan client mode, returns the IP adress of the host to connect to
* If in gamecube mode, returns the IP adress of the dolphin host
*
*/
extern void GetLinkServerHost(char * const host, size_t size);
/**
* Set the value in milliseconds of the timeout after which a connection is
* deemed lost.
*
* @param value timeout
*/
extern void SetLinkTimeout(int value);
/**
* Verify that the link between the emulators is still active
*/
extern void CheckLinkConnection();
/**
* Set the current link mode to LINK_DISCONNECTED
*/
extern void CloseLink();
/**
* Get the id of the player of this VBA instance
*
* @return id -1 means disconnected, 0 means master, > 0 means slave
*/
extern int GetLinkPlayerId();
/**
* Start a link transfer
*
* @param siocnt the value of SIOCNT to be written
*/
extern void StartLink(u16 siocnt);
/**
* Start a general purpose link transfer
*
* @param rcnt the value of RCNT to be written
*/
extern void StartGPLink(u16 rcnt);
/**
* Emulate the linked device
*/
extern void LinkUpdate(int);
/**
* Clean up IPC shared memory
*/
extern void CleanLocalLink();
/**
* Append the current VBA ID to a filemane
*
* @param Input filename to complete
* @return completed filename
*/
extern const char *MakeInstanceFilename(const char *Input);
// register definitions
#define COMM_SIODATA32_L 0x120 #define COMM_SIODATA32_L 0x120
#define COMM_SIODATA32_H 0x122 #define COMM_SIODATA32_H 0x122
#define COMM_SIOCNT 0x128 #define COMM_SIOCNT 0x128
@ -43,146 +163,4 @@
#define JOYCNT_SEND_COMPLETE 4 #define JOYCNT_SEND_COMPLETE 4
#define JOYCNT_INT_ENABLE 0x40 #define JOYCNT_INT_ENABLE 0x40
enum
{
JOY_CMD_RESET = 0xff,
JOY_CMD_STATUS = 0x00,
JOY_CMD_READ = 0x14,
JOY_CMD_WRITE = 0x15
};
extern const char *MakeInstanceFilename(const char *Input);
#ifndef NO_LINK
// Link implementation
#include <SFML/System.hpp>
#include <SFML/Network.hpp>
class ServerInfoDisplay
{
public:
virtual void ShowServerIP(const sf::IPAddress& addr) = 0;
virtual void ShowConnect(const int player) = 0;
virtual void Ping() = 0;
virtual void Connected() = 0;
};
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);
bool Init(ServerInfoDisplay *);
void Send(void);
void Recv(void);
};
class ClientInfoDisplay {
public:
virtual void ConnectStart(const sf::IPAddress& addr) = 0;
virtual void Ping() = 0;
virtual void ShowConnect(const int player, const int togo) = 0;
virtual void Connected() = 0;
};
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);
bool Init(sf::IPAddress, ClientInfoDisplay *);
void Send(void);
void Recv(void);
void CheckConn(void);
};
typedef struct {
sf::SocketTCP tcpsocket;
//sf::SocketUDP udpsocket;
int numslaves;
sf::Thread *thread;
int type;
bool server;
bool terminate;
bool connected;
bool speed;
bool active;
} LANLINKDATA;
extern bool gba_joybus_enabled;
extern bool gba_joybus_active;
extern bool gba_link_enabled;
extern sf::IPAddress joybusHostAddr;
extern void JoyBusConnect();
extern void JoyBusShutdown();
extern void JoyBusUpdate(int ticks);
extern bool InitLink();
extern void CloseLink();
extern void StartLink(u16);
extern void StartGPLink(u16);
extern void LinkUpdate(int);
extern void CleanLocalLink();
extern LANLINKDATA lanlink;
extern int vbaid;
extern bool rfu_enabled;
extern int linktimeout;
extern lclient lc;
extern lserver ls;
extern int linkid;
#else
// stubs to keep #ifdef's out of mainline
const bool gba_joybus_enabled = false;
const bool gba_link_enabled = false;
inline void JoyBusConnect() { }
inline void JoyBusShutdown() { }
inline void JoyBusUpdate(int) { }
inline bool InitLink() { return true; }
inline void CloseLink() { }
inline void StartLink(u16) { }
inline void StartGPLink(u16) { }
inline void LinkUpdate(int) { }
inline void CleanLocalLink() { }
#endif
#endif /* GBA_GBALINK_H */ #endif /* GBA_GBALINK_H */

View File

@ -3,12 +3,13 @@
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include "../common/Types.h" #include "../common/Types.h"
class GBASockClient : public sf::SocketTCP class GBASockClient
{ {
public: public:
GBASockClient(sf::IPAddress server_addr); GBASockClient(sf::IPAddress _server_addr);
~GBASockClient(); ~GBASockClient();
bool Connect(sf::IPAddress server_addr);
void Send(std::vector<char> data); void Send(std::vector<char> data);
char ReceiveCmd(char* data_in, bool block); char ReceiveCmd(char* data_in, bool block);
void ReceiveClock(bool block); void ReceiveClock(bool block);

View File

@ -1,80 +0,0 @@
#ifndef NO_LINK
#include "stdafx.h"
#include "vba.h"
#include "JoybusOptions.h"
#include "../gba/GBALink.h"
// JoybusOptions dialog
IMPLEMENT_DYNAMIC(JoybusOptions, CDialog)
JoybusOptions::JoybusOptions(CWnd* pParent /*=NULL*/)
: CDialog(JoybusOptions::IDD, pParent)
{
}
JoybusOptions::~JoybusOptions()
{
}
void JoybusOptions::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_JOYBUS_ENABLE, enable_check);
DDX_Control(pDX, IDC_JOYBUS_HOSTNAME, hostname);
}
BEGIN_MESSAGE_MAP(JoybusOptions, CDialog)
ON_BN_CLICKED(IDC_JOYBUS_ENABLE, &JoybusOptions::OnBnClickedJoybusEnable)
ON_BN_CLICKED(IDOK, &JoybusOptions::OnBnClickedOk)
END_MESSAGE_MAP()
BOOL JoybusOptions::OnInitDialog()
{
CDialog::OnInitDialog();
enable_check.SetCheck(gba_joybus_enabled ? BST_CHECKED : BST_UNCHECKED);
hostname.EnableWindow(enable_check.GetCheck() == BST_CHECKED);
hostname.SetWindowText(joybusHostAddr.ToString().c_str());
return TRUE;
}
void JoybusOptions::OnBnClickedJoybusEnable()
{
hostname.EnableWindow(enable_check.GetCheck() == BST_CHECKED);
}
void JoybusOptions::OnBnClickedOk()
{
if ( (hostname.GetWindowTextLength() == 0)
&& (enable_check.GetCheck() == BST_CHECKED) )
{
hostname.SetWindowText("Enter IP or Hostname");
return;
}
gba_joybus_enabled = enable_check.GetCheck() == BST_CHECKED;
CString address;
hostname.GetWindowText(address);
sf::IPAddress new_server;
new_server = std::string(address);
if (!new_server.IsValid())
{
hostname.SetWindowText("Enter IP or Hostname");
return;
}
joybusHostAddr = new_server;
JoyBusConnect();
OnOK();
}
#endif // NO_LINK

View File

@ -1,27 +0,0 @@
#pragma once
#include "afxwin.h"
// JoybusOptions dialog
class JoybusOptions : public CDialog
{
DECLARE_DYNAMIC(JoybusOptions)
public:
JoybusOptions(CWnd* pParent = NULL); // standard constructor
virtual ~JoybusOptions();
// Dialog Data
enum { IDD = IDD_JOYBUS_DIALOG };
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
DECLARE_MESSAGE_MAP()
public:
virtual BOOL OnInitDialog();
afx_msg void OnBnClickedJoybusEnable();
CButton enable_check;
CEdit hostname;
afx_msg void OnBnClickedOk();
};

View File

@ -5,39 +5,46 @@
#include "LinkOptions.h" #include "LinkOptions.h"
#include "../gba/GBALink.h" #include "../gba/GBALink.h"
extern lserver ls;
#ifdef _DEBUG #ifdef _DEBUG
#define new DEBUG_NEW #define new DEBUG_NEW
#undef THIS_FILE #undef THIS_FILE
static char THIS_FILE[] = __FILE__; static char THIS_FILE[] = __FILE__;
#endif #endif
template <class T>
void DDX_CBData(CDataExchange* pDX, int nIDC, T& data)
{
HWND hWndCtrl = pDX->PrepareCtrl(nIDC);
if (pDX->m_bSaveAndValidate)
{
int index = static_cast<int>(::SendMessage(hWndCtrl, CB_GETCURSEL, 0, 0L));
data = (index == CB_ERR ? NULL : static_cast<T>(::SendMessage(hWndCtrl, CB_GETITEMDATA, index, 0L)));
}
else
{
int count = static_cast<int>(::SendMessage(hWndCtrl, CB_GETCOUNT, 0, 0L));
for (int i = 0; i != count; ++i)
{
if (static_cast<T>(::SendMessage(hWndCtrl, CB_GETITEMDATA, i, 0L)) == data)
{
::SendMessage(hWndCtrl, CB_SETCURSEL, i, 0L);
return;
}
}
::SendMessage(hWndCtrl, CB_SETCURSEL, -1, 0L);
}
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// LinkOptions dialog // LinkOptions dialog
CMyTabCtrl::CMyTabCtrl(){
m_tabdialog[0] = new LinkGeneral;
m_tabdialog[1] = new LinkServer;
m_tabdialog[2] = new LinkClient;
}
CMyTabCtrl::~CMyTabCtrl()
{
m_tabdialog[0]->DestroyWindow();
m_tabdialog[1]->DestroyWindow();
m_tabdialog[2]->DestroyWindow();
delete m_tabdialog[0];
delete m_tabdialog[1];
delete m_tabdialog[2];
}
LinkOptions::LinkOptions(CWnd* pParent /*=NULL*/) LinkOptions::LinkOptions(CWnd* pParent /*=NULL*/)
: CDialog(LinkOptions::IDD, pParent) : CDialog(LinkOptions::IDD, pParent)
{ {
//{{AFX_DATA_INIT(LinkOptions) //{{AFX_DATA_INIT(LinkOptions)
// NOTE: the ClassWizard will add member initialization here m_numplayers = 0;
m_type = theApp.linkMode;
m_server = FALSE;
//}}AFX_DATA_INIT //}}AFX_DATA_INIT
} }
@ -46,54 +53,51 @@ void LinkOptions::DoDataExchange(CDataExchange* pDX)
{ {
CDialog::DoDataExchange(pDX); CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LinkOptions) //{{AFX_DATA_MAP(LinkOptions)
DDX_CBData(pDX, IDC_LINK_MODE, m_type);
DDX_Control(pDX, IDC_LINKTIMEOUT, m_timeout);
DDX_Control(pDX, IDC_LINK_MODE, m_mode);
DDX_Control(pDX, IDC_SERVERIP, m_serverip);
DDX_Check(pDX, IDC_SSPEED, m_hacks);
DDX_Radio(pDX, IDC_LINK2P, m_numplayers);
DDX_Radio(pDX, IDC_LINK_CLIENT, m_server);
//}}AFX_DATA_MAP //}}AFX_DATA_MAP
} }
BOOL LinkOptions::OnInitDialog(){ BOOL LinkOptions::OnInitDialog(){
TCITEM tabitem; char timeout[6];
char tabtext[3][8] = {"General", "Server", "Client"};
int i;
CDialog::OnInitDialog(); CDialog::OnInitDialog();
m_tabctrl.SubclassDlgItem(IDC_TAB1, this); AddMode("Nothing (Disconnect)", LINK_DISCONNECTED);
AddMode("Cable - Single Computer", LINK_CABLE_IPC);
AddMode("Cable - Network", LINK_CABLE_SOCKET);
AddMode("GameCube - Dolphin", LINK_GAMECUBE_DOLPHIN);
AddMode("Wireless adapter - Single Computer", LINK_RFU_IPC);
tabitem.mask = TCIF_TEXT; sprintf(timeout, "%d", theApp.linkTimeout);
for(i=0;i<3;i++){ m_timeout.LimitText(5);
tabitem.pszText = tabtext[i]; m_timeout.SetWindowText(timeout);
m_tabctrl.InsertItem(i, &tabitem);
}
m_tabctrl.m_tabdialog[0]->Create(IDD_LINKTAB1, this);
m_tabctrl.m_tabdialog[1]->Create(IDD_LINKTAB2, this);
m_tabctrl.m_tabdialog[2]->Create(IDD_LINKTAB3, this);
m_tabctrl.m_tabdialog[0]->ShowWindow(SW_SHOW); m_serverip.SetWindowText(theApp.linkHost);
m_tabctrl.m_tabdialog[1]->ShowWindow(SW_HIDE);
m_tabctrl.m_tabdialog[2]->ShowWindow(SW_HIDE);
m_tabctrl.SetCurSel(0); UpdateAvailability();
m_tabctrl.OnSwitchTabs();
UpdateData(FALSE);
return TRUE; return TRUE;
} }
BOOL LinkOptions::PreTranslateMessage(MSG* pMsg)
{
return m_tabctrl.TranslatePropSheetMsg(pMsg) ? TRUE :
CDialog::PreTranslateMessage(pMsg);
}
BEGIN_MESSAGE_MAP(LinkOptions, CDialog) BEGIN_MESSAGE_MAP(LinkOptions, CDialog)
//{{AFX_MSG_MAP(LinkOptions) //{{AFX_MSG_MAP(LinkOptions)
ON_NOTIFY(TCN_SELCHANGE, IDC_TAB1, OnSelchangeTab1) ON_CBN_SELCHANGE(IDC_LINK_MODE, &LinkOptions::OnCbnSelchangeLinkMode)
ON_BN_CLICKED(ID_OK, OnOk) ON_BN_CLICKED(ID_OK, OnOk)
ON_BN_CLICKED(ID_CANCEL, OnCancel) ON_BN_CLICKED(ID_CANCEL, OnCancel)
ON_BN_CLICKED(IDC_LINK_SERVER, &LinkOptions::OnBnClickedLinkServer)
ON_BN_CLICKED(IDC_LINK_CLIENT, &LinkOptions::OnBnClickedLinkClient)
//}}AFX_MSG_MAP //}}AFX_MSG_MAP
END_MESSAGE_MAP() END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -102,584 +106,123 @@ END_MESSAGE_MAP()
// LinkGeneral dialog // LinkGeneral dialog
LinkGeneral::LinkGeneral(CWnd* pParent /*=NULL*/) void LinkOptions::AddMode(LPCTSTR name, int value) {
: CDialog(LinkGeneral::IDD, pParent) m_mode.AddString(name);
{ int index = m_mode.FindStringExact(-1, name);
//{{AFX_DATA_INIT(LinkGeneral) m_mode.SetItemData(index, value);
//}}AFX_DATA_INIT
} }
void LinkGeneral::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LinkGeneral)
DDX_Radio(pDX, IDC_LINK_SINGLE, m_type);
DDX_Control(pDX, IDC_LINKTIMEOUT, m_timeout);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(LinkGeneral, CDialog)
//{{AFX_MSG_MAP(LinkGeneral)
ON_BN_CLICKED(IDC_LINK_SINGLE, OnRadio1)
ON_BN_CLICKED(IDC_LINK_LAN, OnRadio2)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LinkGeneral message handlers
/////////////////////////////////////////////////////////////////////////////
// LinkServer dialog
LinkServer::LinkServer(CWnd* pParent /*=NULL*/)
: CDialog(LinkServer::IDD, pParent)
{
//{{AFX_DATA_INIT(LinkServer)
m_numplayers = -1;
m_prottype = -1;
m_speed = FALSE;
//}}AFX_DATA_INIT
}
void LinkServer::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LinkServer)
DDX_Radio(pDX, IDC_LINK2P, m_numplayers);
DDX_Radio(pDX, IDC_LINKTCP, m_prottype);
DDX_Check(pDX, IDC_SSPEED, m_speed);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(LinkServer, CDialog)
//{{AFX_MSG_MAP(LinkServer)
ON_BN_CLICKED(IDC_SERVERSTART, OnServerStart)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LinkServer message handlers
LinkClient::LinkClient(CWnd* pParent /*=NULL*/)
: CDialog(LinkClient::IDD, pParent)
{
//{{AFX_DATA_INIT(LinkClient)
m_prottype = -1;
m_hacks = -1;
//}}AFX_DATA_INIT
}
void LinkClient::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(LinkClient)
DDX_Control(pDX, IDC_SERVERIP, m_serverip);
DDX_Radio(pDX, IDC_CLINKTCP, m_prottype);
DDX_Radio(pDX, IDC_SPEEDOFF, m_hacks);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(LinkClient, CDialog)
//{{AFX_MSG_MAP(LinkClient)
ON_BN_CLICKED(IDC_LINKCONNECT, OnLinkConnect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// LinkClient message handlers
BOOL LinkServer::OnInitDialog()
{
CDialog::OnInitDialog();
m_numplayers = lanlink.numslaves;
m_prottype = lanlink.type;
m_speed = lanlink.speed;
UpdateData(FALSE);
return TRUE;
}
void LinkOptions::OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult)
{
m_tabctrl.OnSwitchTabs();
*pResult = 0;
}
IMPLEMENT_DYNAMIC(CMyTabCtrl, CTabCtrl)
BEGIN_MESSAGE_MAP(CMyTabCtrl, CTabCtrl)
ON_NOTIFY_REFLECT(TCN_SELCHANGING, OnSelChanging)
END_MESSAGE_MAP()
BOOL CMyTabCtrl::SubclassDlgItem(UINT nID, CWnd* pParent)
{
if (!CTabCtrl::SubclassDlgItem(nID, pParent))
return FALSE;
ModifyStyle(0, TCS_OWNERDRAWFIXED);
// If first tab is disabled, go to next enabled tab
if (!IsTabEnabled(0)) {
int iTab = NextEnabledTab(0, TRUE);
SetActiveTab(iTab);
}
return TRUE;
}
BOOL CMyTabCtrl::IsTabEnabled(int iTab)
{
if (!lanlink.active && iTab > 0)
return false;
return true;
}
//////////////////
// Draw the tab: mimic SysTabControl32, except use gray if tab is disabled
//
void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
DRAWITEMSTRUCT& ds = *lpDrawItemStruct;
int iItem = ds.itemID;
// Get tab item info
char text[128];
TCITEM tci;
tci.mask = TCIF_TEXT;
tci.pszText = text;
tci.cchTextMax = sizeof(text);
GetItem(iItem, &tci);
// use draw item DC
CDC dc;
dc.Attach(ds.hDC);
// calculate text rectangle and color
CRect rc = ds.rcItem;
rc += CPoint(1,4); // ?? by trial and error
// draw the text
OnDrawText(dc, rc, text, !IsTabEnabled(iItem));
dc.Detach();
}
//////////////////
// Draw tab text. You can override to use different color/font.
//
void CMyTabCtrl::OnDrawText(CDC& dc, CRect rc,
CString sText, BOOL bDisabled)
{
dc.SetTextColor(GetSysColor(bDisabled ? COLOR_3DHILIGHT : COLOR_BTNTEXT));
dc.DrawText(sText, &rc, DT_CENTER|DT_VCENTER);
if (bDisabled) {
// disabled: draw again shifted northwest for shadow effect
rc += CPoint(-1,-1);
dc.SetTextColor(GetSysColor(COLOR_GRAYTEXT));
dc.DrawText(sText, &rc, DT_CENTER|DT_VCENTER);
}
}
//////////////////
// Selection is changing: disallow if tab is disabled
//
void CMyTabCtrl::OnSelChanging(NMHDR* pnmh, LRESULT* pRes)
{
TRACE("CMyTabCtrl::OnSelChanging\n");
// Figure out index of new tab we are about to go to, as opposed
// to the current one we're at. Believe it or not, Windows doesn't
// pass this info
//
TC_HITTESTINFO htinfo;
GetCursorPos(&htinfo.pt);
ScreenToClient(&htinfo.pt);
int iNewTab = HitTest(&htinfo);
if (iNewTab >= 0 && !IsTabEnabled(iNewTab))
*pRes = TRUE; // tab disabled: prevent selection
}
//////////////////
// Trap arrow-left key to skip disabled tabs.
// This is the only way to know where we're coming from--ie from
// arrow-left (prev) or arrow-right (next).
//
BOOL CMyTabCtrl::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_KEYDOWN &&
(pMsg->wParam == VK_LEFT || pMsg->wParam == VK_RIGHT)) {
int iNewTab = (pMsg->wParam == VK_LEFT) ?
PrevEnabledTab(GetCurSel(), FALSE) :
NextEnabledTab(GetCurSel(), FALSE);
if (iNewTab >= 0)
SetActiveTab(iNewTab);
return TRUE;
}
return CTabCtrl::PreTranslateMessage(pMsg);
}
////////////////
// Translate parent property sheet message. Translates Control-Tab and
// Control-Shift-Tab keys. These are normally handled by the property
// sheet, so you must call this function from your prop sheet's
// PreTranslateMessage function.
//
BOOL CMyTabCtrl::TranslatePropSheetMsg(MSG* pMsg)
{
WPARAM key = pMsg->wParam;
if (pMsg->message == WM_KEYDOWN && GetAsyncKeyState(VK_CONTROL) < 0 &&
(key == VK_TAB || key == VK_PRIOR || key == VK_NEXT)) {
int iNewTab = (key==VK_PRIOR || GetAsyncKeyState(VK_SHIFT) < 0) ?
PrevEnabledTab(GetCurSel(), TRUE) :
NextEnabledTab(GetCurSel(), TRUE);
if (iNewTab >= 0)
SetActiveTab(iNewTab);
return TRUE;
}
return FALSE;
}
//////////////////
// Helper to set the active page, when moving backwards (left-arrow and
// Control-Shift-Tab). Must simulate Windows messages to tell parent I
// am changing the tab; SetCurSel does not do this!!
//
// In normal operation, this fn will always succeed, because I don't call it
// unless I already know IsTabEnabled() = TRUE; but if you call SetActiveTab
// with a random value, it could fail.
//
BOOL CMyTabCtrl::SetActiveTab(UINT iNewTab)
{
TRACE("CMyTabCtrl::SetActiveTab\n");
// send the parent TCN_SELCHANGING
NMHDR nmh;
nmh.hwndFrom = m_hWnd;
nmh.idFrom = GetDlgCtrlID();
nmh.code = TCN_SELCHANGING;
if (GetParent()->SendMessage(WM_NOTIFY, nmh.idFrom, (LPARAM)&nmh) >=0) {
// OK to change: set the new tab
SetCurSel(iNewTab);
// send parent TCN_SELCHANGE
nmh.code = TCN_SELCHANGE;
GetParent()->SendMessage(WM_NOTIFY, nmh.idFrom, (LPARAM)&nmh);
return TRUE;
}
return FALSE;
}
/////////////////
// Return the index of the next enabled tab after a given index, or -1 if none
// (0 = first tab).
// If bWrap is TRUE, wrap from beginning to end; otherwise stop at zero.
//
int CMyTabCtrl::NextEnabledTab(int iCurrentTab, BOOL bWrap)
{
int nTabs = GetItemCount();
for (int iTab = iCurrentTab+1; iTab != iCurrentTab; iTab++) {
if (iTab >= nTabs) {
if (!bWrap)
return -1;
iTab = 0;
}
if (IsTabEnabled(iTab)) {
return iTab;
}
}
return -1;
}
/////////////////
// Return the index of the previous enabled tab before a given index, or -1.
// (0 = first tab).
// If bWrap is TRUE, wrap from beginning to end; otherwise stop at zero.
//
int CMyTabCtrl::PrevEnabledTab(int iCurrentTab, BOOL bWrap)
{
for (int iTab = iCurrentTab-1; iTab != iCurrentTab; iTab--) {
if (iTab < 0) {
if (!bWrap)
return -1;
iTab = GetItemCount() - 1;
}
if (IsTabEnabled(iTab)) {
return iTab;
}
}
return -1;
}
void CMyTabCtrl::OnSwitchTabs(void)
{
CRect clientRect, wndRect;
int i;
GetClientRect(clientRect);
AdjustRect(FALSE, clientRect);
GetWindowRect(wndRect);
GetParent()->ScreenToClient(wndRect);
clientRect.OffsetRect(wndRect.left, wndRect.top);
if(lanlink.active==0)
SetCurSel(0);
for(i=0;i<3;i++){
if(i==GetCurSel()){
m_tabdialog[i]->SetWindowPos(&wndTop, clientRect.left, clientRect.top, clientRect.Width(), clientRect.Height(), SWP_SHOWWINDOW);
} else {
m_tabdialog[i]->ShowWindow(SW_HIDE);
}
}
return;
}
void LinkOptions::OnOk() void LinkOptions::OnOk()
{ {
GetAllData((LinkGeneral*)m_tabctrl.m_tabdialog[0]); static const int length = 256;
CDialog::OnOK(); int timeout;
CString timeoutStr;
CString host;
CString title;
CString addressMessage;
UpdateData(TRUE);
// Close any previous link
CloseLink();
m_serverip.GetWindowText(host);
m_timeout.GetWindowText(timeoutStr);
sscanf(timeoutStr, "%d", &timeout);
SetLinkTimeout(timeout);
LinkMode newMode = (LinkMode) m_type;
bool needsServerHost = newMode == LINK_GAMECUBE_DOLPHIN || (newMode == LINK_CABLE_SOCKET && !m_server);
if (needsServerHost) {
bool valid = SetLinkServerHost(host);
if (!valid) {
AfxMessageBox("You must enter a valid host name", MB_OK | MB_ICONSTOP);
return;
}
}
EnableSpeedHacks(m_hacks);
EnableLinkServer(m_server, m_numplayers + 1);
if (m_server) {
char localhost[length];
GetLinkServerHost(localhost, length);
title = "Waiting for clients...";
addressMessage.Format("Server IP address is: %s\n", localhost);
} else {
title = "Waiting for connection...";
addressMessage.Format("Connecting to %s\n", host);
}
// Init link
ConnectionState state = InitLink(newMode);
// Display a progress dialog while the connection is establishing
if (state == LINK_NEEDS_UPDATE) {
ServerWait *dlg = new ServerWait();
dlg->Create(ServerWait::IDD, this);
dlg->m_plconn[1] = title;
dlg->m_serveraddress = addressMessage;
dlg->ShowWindow(SW_SHOW);
while (state == LINK_NEEDS_UPDATE) {
// Ask the core for updates
char message[length];
state = ConnectLinkUpdate(message, length);
// Update the wait message
if (strlen(message)) {
dlg->m_plconn[1] = message;
}
// Step the progress bar and update dialog data
dlg->m_prgctrl.StepIt();
dlg->UpdateData(false);
// Process Windows messages
MSG msg;
while (PeekMessage (&msg, 0, 0, 0, PM_NOREMOVE)) {
AfxGetApp()->PumpMessage();
}
// Check whether the user has aborted
if (dlg->m_userAborted) {
state = LINK_ABORT;
}
}
delete dlg;
}
// The user canceled the connection attempt
if (state == LINK_ABORT) {
CloseLink();
return; return;
} }
void LinkGeneral::OnRadio1() // Something failed during init
{ if (state == LINK_ERROR) {
m_type = 0; AfxMessageBox("Error occurred.\nPlease try again.", MB_OK | MB_ICONSTOP);
lanlink.active = 0; return;
GetParent()->Invalidate();
} }
void LinkGeneral::OnRadio2() theApp.linkTimeout = timeout;
{ theApp.linkMode = GetLinkMode();
m_type = 1; theApp.linkHost = host;
lanlink.active = 1;
GetParent()->Invalidate(); CDialog::OnOK();
return;
} }
BOOL LinkGeneral::OnInitDialog(){
char timeout[6];
CDialog::OnInitDialog();
m_timeout.LimitText(5);
sprintf(timeout, "%d", linktimeout);
m_timeout.SetWindowText(timeout);
m_type = lanlink.active;
UpdateData(FALSE);
return TRUE;
}
void LinkOptions::OnCancel() void LinkOptions::OnCancel()
{ {
CDialog::OnCancel(); CDialog::OnCancel();
return; return;
} }
class Win32ServerInfoDisplay : public ServerInfoDisplay
{
public:
Win32ServerInfoDisplay(ServerWait *_dlg)
{
dlg = _dlg;
}
~Win32ServerInfoDisplay()
{
if (dlg)
{
// not connected
MessageBox(NULL, "Failed to connect.", "Link", MB_OK);
dlg->SendMessage(WM_CLOSE, 0, 0);
}
delete dlg;
dlg = NULL;
}
void ShowServerIP(const sf::IPAddress& addr)
{
dlg->m_serveraddress.Format("Server IP address is: %s", addr.ToString());
}
void ShowConnect(const int player)
{
dlg->m_plconn[0].Format("Player %d connected", player);
dlg->UpdateData(false);
}
void Ping()
{
dlg->m_prgctrl.StepIt();
}
void Connected()
{
MessageBox(NULL, "All players connected", "Link", MB_OK);
dlg->SendMessage(WM_CLOSE, 0, 0);
delete dlg;
dlg = NULL;
}
private:
ServerWait *dlg;
};
void LinkServer::OnServerStart()
{
UpdateData(TRUE);
lanlink.numslaves = m_numplayers+1;
lanlink.type = m_prottype;
lanlink.server = true;
lanlink.speed = m_speed==1 ? true : false;
sf::IPAddress addr;
// These must be created on the heap - referenced from the connection thread
ServerWait *dlg = new ServerWait();
dlg->Create(IDD_SERVERWAIT, this);
dlg->ShowWindow(SW_SHOW);
// Owns the ServerWait*
Win32ServerInfoDisplay *dlginfo = new Win32ServerInfoDisplay(dlg);
// ls thread will own the dlginfo
if (!ls.Init(dlginfo))
{
// Thread didn't get created
delete dlginfo;
MessageBox("Error occurred.\nPlease try again.", "Error", MB_OK);
}
return;
}
BOOL LinkClient::OnInitDialog()
{
CDialog::OnInitDialog();
m_prottype = lanlink.type;
m_hacks = lanlink.speed;
UpdateData(FALSE);
return TRUE;
}
class Win32ClientInfoDisplay : public ClientInfoDisplay
{
public:
Win32ClientInfoDisplay(ServerWait *_dlg)
{
dlg = _dlg;
}
~Win32ClientInfoDisplay()
{
if (dlg)
{
// not connected
MessageBox(NULL, "Failed to connect.", "Link", MB_OK);
dlg->SendMessage(WM_CLOSE, 0, 0);
}
delete dlg;
dlg = NULL;
}
void ConnectStart(const sf::IPAddress& addr)
{
dlg->SetWindowText("Connecting...");
}
void ShowConnect(const int player, const int togo)
{
dlg->m_serveraddress.Format("Connected as #%d", player);
if (togo)
dlg->m_plconn[0].Format("Waiting for %d players to join", togo);
else
dlg->m_plconn[0].Format("All players joined.");
}
void Ping()
{
dlg->m_prgctrl.StepIt();
}
void Connected()
{
MessageBox(NULL, "Connected.", "Link", MB_OK);
dlg->SendMessage(WM_CLOSE, 0, 0);
delete dlg;
dlg = NULL;
}
private:
ServerWait *dlg;
};
void LinkClient::OnLinkConnect()
{
char ipaddress[31];
UpdateData(TRUE);
lanlink.type = m_prottype;
lanlink.server = false;
lanlink.speed = m_hacks==1 ? true : false;
m_serverip.GetWindowText(ipaddress, 30);
// These must be created on the heap - referenced from the connection thread
ServerWait *dlg = new ServerWait();
dlg->Create(IDD_SERVERWAIT, this);
dlg->ShowWindow(SW_SHOW);
// Owns the ServerWait*
Win32ClientInfoDisplay *dlginfo = new Win32ClientInfoDisplay(dlg);
// lc thread will own the dlginfo
if (!lc.Init(sf::IPAddress(std::string(ipaddress)), dlginfo))
{
// Thread didn't get created
delete dlginfo;
MessageBox("Error occurred.\nPlease try again.", "Error", MB_OK);
}
return;
}
void LinkOptions::GetAllData(LinkGeneral *src)
{
char timeout[6];
src->UpdateData(true);
src->m_timeout.GetWindowText(timeout, 5);
sscanf(timeout, "%d", &linktimeout);
if(src->m_type==0){
lanlink.speed = 0;
}
return;
}
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// ServerWait dialog // ServerWait dialog
@ -693,6 +236,8 @@ ServerWait::ServerWait(CWnd* pParent /*=NULL*/)
m_plconn[1] = _T(""); m_plconn[1] = _T("");
m_plconn[2] = _T(""); m_plconn[2] = _T("");
//}}AFX_DATA_INIT //}}AFX_DATA_INIT
m_userAborted = false;
} }
@ -719,35 +264,47 @@ END_MESSAGE_MAP()
void ServerWait::OnCancel() void ServerWait::OnCancel()
{ {
lanlink.terminate = true; m_userAborted = true;
CDialog::OnCancel(); ShowWindow(SW_HIDE);
} }
BOOL LinkGeneral::PreTranslateMessage(MSG* pMsg) void LinkOptions::OnCbnSelchangeLinkMode()
{ {
if(pMsg->message==WM_KEYDOWN) UpdateData(TRUE);
if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_ESCAPE) UpdateAvailability();
pMsg->wParam = NULL;
return CDialog::PreTranslateMessage(pMsg);
} }
BOOL LinkClient::PreTranslateMessage(MSG* pMsg) void LinkOptions::UpdateAvailability()
{ {
if(pMsg->message==WM_KEYDOWN) bool isDisconnected = m_type == LINK_DISCONNECTED;
if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_ESCAPE) bool isNetwork = m_type == LINK_CABLE_SOCKET;
pMsg->wParam = NULL; bool canHaveServer = (m_type == LINK_CABLE_SOCKET && !m_server) || m_type == LINK_GAMECUBE_DOLPHIN;
bool hasHacks = m_type == LINK_CABLE_SOCKET;
return CDialog::PreTranslateMessage(pMsg); GetDlgItem(IDC_LINK_CLIENT)->EnableWindow(isNetwork);
} GetDlgItem(IDC_LINK_SERVER)->EnableWindow(isNetwork);
GetDlgItem(IDC_SSPEED)->EnableWindow(isNetwork);
BOOL LinkServer::PreTranslateMessage(MSG* pMsg) m_serverip.EnableWindow(canHaveServer);
{ m_timeout.EnableWindow(!isDisconnected);
if(pMsg->message==WM_KEYDOWN)
if(pMsg->wParam==VK_RETURN||pMsg->wParam==VK_ESCAPE)
pMsg->wParam = NULL;
return CDialog::PreTranslateMessage(pMsg); GetDlgItem(IDC_LINK2P)->EnableWindow(isNetwork && m_server);
GetDlgItem(IDC_LINK3P)->EnableWindow(isNetwork && m_server);
GetDlgItem(IDC_LINK4P)->EnableWindow(isNetwork && m_server);
} }
#endif // NO_LINK #endif // NO_LINK
void LinkOptions::OnBnClickedLinkServer()
{
UpdateData(TRUE);
UpdateAvailability();
}
void LinkOptions::OnBnClickedLinkClient()
{
UpdateData(TRUE);
UpdateAvailability();
}

View File

@ -1,74 +1,5 @@
#pragma once #pragma once
class CMyTabCtrl : public CTabCtrl {
DECLARE_DYNAMIC(CMyTabCtrl)
public:
CMyTabCtrl(void);
~CMyTabCtrl(void);
BOOL IsTabEnabled(int iTab); // you must override
BOOL TranslatePropSheetMsg(MSG* pMsg); // call from prop sheet
BOOL SubclassDlgItem(UINT nID, CWnd* pParent); // non-virtual override
// helpers
int NextEnabledTab(int iTab, BOOL bWrap); // get next enabled tab
int PrevEnabledTab(int iTab, BOOL bWrap); // get prev enabled tab
BOOL SetActiveTab(UINT iNewTab); // set tab (fail if disabled)
CDialog *m_tabdialog[3];
void OnSwitchTabs(void);
protected:
DECLARE_MESSAGE_MAP()
afx_msg void OnSelChanging(NMHDR* pNmh, LRESULT* pRes);
// MFC overrides
virtual BOOL PreTranslateMessage(MSG* pMsg);
virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
// override to draw text only; eg, colored text or different font
virtual void OnDrawText(CDC& dc, CRect rc, CString sText, BOOL bDisabled);
};
/////////////////////////////////////////////////////////////////////////////
// LinkGeneral dialog
class LinkGeneral : public CDialog
{
// Construction
public:
LinkGeneral(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(LinkGeneral)
enum { IDD = IDD_LINKTAB1 };
int m_type;
CEdit m_timeout;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(LinkGeneral)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(LinkGeneral)
virtual BOOL OnInitDialog();
afx_msg void OnRadio1();
afx_msg void OnRadio2();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// LinkOptions dialog // LinkOptions dialog
@ -77,19 +8,22 @@ class LinkOptions : public CDialog
// Construction // Construction
public: public:
LinkOptions(CWnd* pParent = NULL); // standard constructor LinkOptions(CWnd* pParent = NULL); // standard constructor
void GetAllData(LinkGeneral*);
// Dialog Data // Dialog Data
//{{AFX_DATA(LinkOptions) //{{AFX_DATA(LinkOptions)
enum { IDD = IDD_LINKTAB }; enum { IDD = IDD_LINKTAB };
CMyTabCtrl m_tabctrl; int m_type;
CEdit m_timeout;
CComboBox m_mode;
CEdit m_serverip;
BOOL m_server;
int m_numplayers;
BOOL m_hacks;
//}}AFX_DATA //}}AFX_DATA
// Overrides // Overrides
// ClassWizard generated virtual function overrides // ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(LinkOptions) //{{AFX_VIRTUAL(LinkOptions)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected: protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL //}}AFX_VIRTUAL
@ -97,88 +31,22 @@ public:
// Implementation // Implementation
protected: protected:
void AddMode(LPCTSTR name, int value);
void UpdateAvailability();
// Generated message map functions // Generated message map functions
//{{AFX_MSG(LinkOptions) //{{AFX_MSG(LinkOptions)
afx_msg void OnSelchangeTab1(NMHDR* pNMHDR, LRESULT* pResult); afx_msg void OnCbnSelchangeLinkMode();
virtual BOOL OnInitDialog(); virtual BOOL OnInitDialog();
afx_msg void OnOk(); afx_msg void OnOk();
afx_msg void OnCancel(); afx_msg void OnCancel();
//}}AFX_MSG //}}AFX_MSG
DECLARE_MESSAGE_MAP() DECLARE_MESSAGE_MAP()
public:
afx_msg void OnBnClickedLinkServer();
afx_msg void OnBnClickedLinkClient();
}; };
/////////////////////////////////////////////////////////////////////////////
// LinkServer dialog
class LinkServer : public CDialog
{
// Construction
public:
LinkServer(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(LinkServer)
enum { IDD = IDD_LINKTAB2 };
int m_numplayers;
int m_prottype;
BOOL m_speed;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(LinkServer)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(LinkServer)
virtual BOOL OnInitDialog();
afx_msg void OnServerStart();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
class LinkClient : public CDialog
{
// Construction
public:
LinkClient(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(LinkClient)
enum { IDD = IDD_LINKTAB3 };
CEdit m_serverip;
int m_prottype;
int m_hacks;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(LinkClient)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(LinkClient)
virtual BOOL OnInitDialog();
afx_msg void OnLinkConnect();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
@ -196,10 +64,9 @@ public:
CProgressCtrl m_prgctrl; CProgressCtrl m_prgctrl;
CString m_serveraddress; CString m_serveraddress;
CString m_plconn[3]; CString m_plconn[3];
//CString m_p2conn;
//CString m_p3conn;
//}}AFX_DATA //}}AFX_DATA
bool m_userAborted;
// Overrides // Overrides
// ClassWizard generated virtual function overrides // ClassWizard generated virtual function overrides

View File

@ -323,11 +323,6 @@ BEGIN_MESSAGE_MAP(MainWnd, CWnd)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_GAMEOVERRIDES, OnUpdateOptionsEmulatorGameoverrides) ON_UPDATE_COMMAND_UI(ID_OPTIONS_EMULATOR_GAMEOVERRIDES, OnUpdateOptionsEmulatorGameoverrides)
ON_COMMAND(ID_HELP_GNUPUBLICLICENSE, OnHelpGnupubliclicense) ON_COMMAND(ID_HELP_GNUPUBLICLICENSE, OnHelpGnupubliclicense)
ON_COMMAND(ID_OPTIONS_LINK_OPTIONS, OnLinkOptions) ON_COMMAND(ID_OPTIONS_LINK_OPTIONS, OnLinkOptions)
ON_COMMAND(ID_OPTIONS_LINK_WIRELESSADAPTER, OnOptionsLinkRFU)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_WIRELESSADAPTER, OnUpdateOptionsLinkRFU)
ON_COMMAND(ID_OPTIONS_LINK_ENABLE, OnOptionsLinkEnable)
ON_UPDATE_COMMAND_UI(ID_OPTIONS_LINK_ENABLE, OnUpdateOptionsLinkEnable)
ON_COMMAND(ID_OPTIONS_JOYBUS, &MainWnd::OnOptionsJoybus)
//}}AFX_MSG_MAP //}}AFX_MSG_MAP
ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE10, OnFileRecentFile) ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE10, OnFileRecentFile)

View File

@ -330,11 +330,6 @@ protected:
afx_msg void OnOptionsSoundHardwareacceleration(); afx_msg void OnOptionsSoundHardwareacceleration();
afx_msg void OnUpdateOptionsSoundHardwareacceleration(CCmdUI *pCmdUI); afx_msg void OnUpdateOptionsSoundHardwareacceleration(CCmdUI *pCmdUI);
afx_msg void OnLinkOptions(); afx_msg void OnLinkOptions();
afx_msg void OnOptionsLinkRFU();
afx_msg void OnUpdateOptionsLinkRFU(CCmdUI* pCmdUI);
afx_msg void OnOptionsLinkEnable();
afx_msg void OnUpdateOptionsLinkEnable(CCmdUI* pCmdUI);
afx_msg void OnOptionsJoybus();
afx_msg void OnOutputapiDirectsound(); afx_msg void OnOutputapiDirectsound();
afx_msg void OnUpdateOutputapiDirectsound(CCmdUI *pCmdUI); afx_msg void OnUpdateOutputapiDirectsound(CCmdUI *pCmdUI);

View File

@ -7,7 +7,6 @@
#include "FileDlg.h" #include "FileDlg.h"
#include "GameOverrides.h" #include "GameOverrides.h"
#include "LinkOptions.h" #include "LinkOptions.h"
#include "JoybusOptions.h"
#include "GBColorDlg.h" #include "GBColorDlg.h"
#include "Joypad.h" #include "Joypad.h"
#include "MaxScale.h" #include "MaxScale.h"
@ -1579,42 +1578,8 @@ void MainWnd::OnLinkOptions()
dlg.DoModal(); dlg.DoModal();
} }
void MainWnd::OnOptionsLinkRFU()
{
if(rfu_enabled) rfu_enabled = false;
else {
rfu_enabled = true;
MessageBox("Please note this is the first version\nof RFU emulation code and it's not 100% bug free.\nAlso only 2 players single computer are supported at this time.", "Warning", MB_OK);
}
}
void MainWnd::OnUpdateOptionsLinkEnable(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(gba_link_enabled);
}
void MainWnd::OnOptionsLinkEnable()
{
gba_link_enabled = !gba_link_enabled;
}
void MainWnd::OnUpdateOptionsLinkRFU(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(rfu_enabled);
}
void MainWnd::OnOptionsJoybus()
{
JoybusOptions dlg;
dlg.DoModal();
}
#else #else
void MainWnd::OnLinkOptions() { } void MainWnd::OnLinkOptions() { }
void MainWnd::OnOptionsLinkRFU() { }
void MainWnd::OnUpdateOptionsLinkEnable(CCmdUI*) { }
void MainWnd::OnOptionsLinkEnable() { }
void MainWnd::OnUpdateOptionsLinkRFU(CCmdUI*) { }
void MainWnd::OnOptionsJoybus() { }
#endif #endif
void MainWnd::OnOptionsEmulatorGameoverrides() void MainWnd::OnOptionsEmulatorGameoverrides()

View File

@ -119,9 +119,6 @@ void winlog(const char *msg, ...);
/* Link /* Link
---------------------*/ ---------------------*/
extern bool InitLink(void);
extern void CloseLink(void);
//extern int linkid;
extern char inifile[]; extern char inifile[];
/* ------------------- */ /* ------------------- */
#ifdef _DEBUG #ifdef _DEBUG
@ -358,7 +355,7 @@ VBA::~VBA()
regInit(winBuffer); regInit(winBuffer);
JoyBusShutdown(); CloseLink();
saveSettings(); saveSettings();
@ -453,9 +450,6 @@ BOOL VBA::InitInstance()
if(p) if(p)
*p = 0; *p = 0;
if(!InitLink())
return FALSE;
bool force = false; bool force = false;
if (m_lpCmdLine[0]) if (m_lpCmdLine[0])
@ -1280,8 +1274,8 @@ BOOL VBA::OnIdle(LONG lCount)
emulator.emuMain(emulator.emuCount); emulator.emuMain(emulator.emuCount);
#ifndef NO_LINK #ifndef NO_LINK
if (lanlink.connected && linkid && lc.numtransfers == 0) if (GetLinkMode() != LINK_DISCONNECTED)
lc.CheckConn(); CheckLinkConnection();
#endif #endif
if(rewindSaveNeeded && rewindMemory && emulator.emuWriteMemState) { if(rewindSaveNeeded && rewindMemory && emulator.emuWriteMemState) {
@ -1647,18 +1641,12 @@ void VBA::loadSettings()
updateThrottle( (unsigned short)regQueryDwordValue( "throttle", 0 ) ); updateThrottle( (unsigned short)regQueryDwordValue( "throttle", 0 ) );
#ifndef NO_LINK #ifndef NO_LINK
linktimeout = regQueryDwordValue("LinkTimeout", 1000); linkTimeout = regQueryDwordValue("LinkTimeout", 1000);
rfu_enabled = regQueryDwordValue("RFU", false) ? true : false; linkMode = regQueryDwordValue("LinkMode", LINK_DISCONNECTED);
gba_link_enabled = regQueryDwordValue("linkEnabled", false) ? true : false;
gba_joybus_enabled = regQueryDwordValue("joybusEnabled", false) ? true : false;
buffer = regQueryStringValue("joybusHostAddr", "");
if(!buffer.IsEmpty()) { linkHost = regQueryStringValue("LinkHostAddr", "localhost");
joybusHostAddr = std::string(buffer);
}
lanlink.active = regQueryDwordValue("LAN", 0) ? true : false;
#endif #endif
Sm60FPS::bSaveMoreCPU = regQueryDwordValue("saveMoreCPU", 0); Sm60FPS::bSaveMoreCPU = regQueryDwordValue("saveMoreCPU", 0);
@ -2585,11 +2573,9 @@ void VBA::saveSettings()
regSetDwordValue("saveMoreCPU", Sm60FPS::bSaveMoreCPU); regSetDwordValue("saveMoreCPU", Sm60FPS::bSaveMoreCPU);
#ifndef NO_LINK #ifndef NO_LINK
regSetDwordValue("LinkTimeout", linktimeout); regSetDwordValue("LinkTimeout", linkTimeout);
regSetDwordValue("RFU", rfu_enabled); regSetDwordValue("LinkMode", linkMode);
regSetDwordValue("linkEnabled", gba_link_enabled); regSetStringValue("LinkHostAddr", linkHost);
regSetDwordValue("joybusEnabled", gba_joybus_enabled);
regSetStringValue("joybusHostAddr", joybusHostAddr.ToString().c_str());
#endif #endif
regSetDwordValue("lastFullscreen", lastFullscreen); regSetDwordValue("lastFullscreen", lastFullscreen);

View File

@ -207,6 +207,10 @@ class VBA : public CWinApp
CString wndClass; CString wndClass;
int linkTimeout;
int linkMode;
CString linkHost;
public: public:
VBA(); VBA();
~VBA(); ~VBA();

View File

@ -112,54 +112,28 @@ BEGIN
LTEXT "Please select filter plugin:",IDC_STATIC,6,6,162,8 LTEXT "Please select filter plugin:",IDC_STATIC,6,6,162,8
END END
IDD_LINKTAB DIALOGEX 0, 0, 254, 203 IDD_LINKTAB DIALOGEX 0, 0, 254, 198
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Link Options" CAPTION "Connect Link"
FONT 8, "MS Sans Serif", 0, 0, 0x1 FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN BEGIN
CONTROL "Tab1",IDC_TAB1,"SysTabControl32",0x0,9,7,240,162 CONTROL "Client",IDC_LINK_CLIENT,"Button",BS_AUTORADIOBUTTON | WS_GROUP,53,46,33,10
PUSHBUTTON "OK",ID_OK,57,180,60,15 CONTROL "Server",IDC_LINK_SERVER,"Button",BS_AUTORADIOBUTTON,95,46,37,10
PUSHBUTTON "Cancel",ID_CANCEL,140,180,57,15 LTEXT "Link with",IDC_LINK_WITH,11,10,38,10
END COMBOBOX IDC_LINK_MODE,50,8,194,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
LTEXT "Link timeout (in milliseconds)",IDC_STATIC_TIMEOUT,11,153,92,12
IDD_LINKTAB1 DIALOGEX 0, 0, 184, 79 EDITTEXT IDC_LINKTIMEOUT,111,150,53,14,ES_AUTOHSCROLL | ES_NUMBER
STYLE DS_SETFONT | WS_CHILD | WS_VISIBLE LTEXT "Server IP address or hostname:",IDC_STATIC,25,70,75,18
FONT 8, "MS Sans Serif", 0, 0, 0x1 EDITTEXT IDC_SERVERIP,114,73,105,12,ES_AUTOHSCROLL | WS_GROUP
BEGIN LTEXT "Expected number of players:",IDC_STATIC,25,94,89,10
LTEXT "Link timeout (in milliseconds)",IDC_STATIC,17,12,92,16 CONTROL "2",IDC_LINK2P,"Button",BS_AUTORADIOBUTTON | WS_GROUP,53,106,21,13
EDITTEXT IDC_LINKTIMEOUT,116,10,53,14,ES_AUTOHSCROLL | ES_NUMBER CONTROL "3",IDC_LINK3P,"Button",BS_AUTORADIOBUTTON,99,106,21,13
CONTROL "Single Computer",IDC_LINK_SINGLE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,17,27,71,16 CONTROL "4",IDC_LINK4P,"Button",BS_AUTORADIOBUTTON,145,106,21,13
CONTROL "Network",IDC_LINK_LAN,"Button",BS_AUTORADIOBUTTON,17,43,70,16 CONTROL "Enable speed hacks",IDC_SSPEED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,121,138,12
END PUSHBUTTON "OK",ID_OK,60,176,60,15
PUSHBUTTON "Cancel",ID_CANCEL,136,176,57,15
IDD_LINKTAB2 DIALOGEX 0, 0, 210, 113 GROUPBOX "Network options",IDC_GROUP_NETWORK,11,28,231,113
STYLE DS_SETFONT | WS_CHILD LTEXT "Role:",IDC_LINK_ROLE,25,46,18,8
FONT 8, "MS Sans Serif", 0, 0, 0x0
BEGIN
CONTROL "2",IDC_LINK2P,"Button",BS_AUTORADIOBUTTON | WS_GROUP,46,16,21,13
CONTROL "3",IDC_LINK3P,"Button",BS_AUTORADIOBUTTON,94,16,21,13
CONTROL "4",IDC_LINK4P,"Button",BS_AUTORADIOBUTTON,142,16,21,13
CONTROL "TCP/IP",IDC_LINKTCP,"Button",BS_AUTORADIOBUTTON | WS_GROUP,54,47,42,14
CONTROL "UDP",IDC_LINKUDP,"Button",BS_AUTORADIOBUTTON | WS_DISABLED,121,47,33,14
PUSHBUTTON "Start!",IDC_SERVERSTART,79,89,50,17,WS_DISABLED
LTEXT "Select number of players:",IDC_STATIC,60,7,89,10
LTEXT "Select protocol:",IDC_STATIC,78,33,53,11
CONTROL "Speed hacks",IDC_SSPEED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,76,70,57,12
END
IDD_LINKTAB3 DIALOGEX 0, 0, 188, 108
STYLE DS_SETFONT | WS_CHILD
FONT 8, "MS Sans Serif", 0, 0, 0x1
BEGIN
CONTROL "TCP/IP",IDC_CLINKTCP,"Button",BS_AUTORADIOBUTTON | WS_GROUP,58,20,39,12
CONTROL "UDP",IDC_CLINKUDP,"Button",BS_AUTORADIOBUTTON | WS_DISABLED,118,20,32,12
EDITTEXT IDC_SERVERIP,84,39,79,12,ES_AUTOHSCROLL | WS_GROUP
PUSHBUTTON "Connect",IDC_LINKCONNECT,75,81,59,16,WS_DISABLED
LTEXT "Select protocol:",IDC_STATIC,78,7,53,9
LTEXT "Server IP address or hostname:",IDC_STATIC,7,37,62,18
LTEXT "Speed hacks:",IDC_STATIC,7,64,47,10
CONTROL "Off (accurate)",IDC_SPEEDOFF,"Button",BS_AUTORADIOBUTTON | WS_GROUP,60,63,57,12
CONTROL "On (fast)",IDC_SPEEDON,"Button",BS_AUTORADIOBUTTON,128,63,48,12
END END
IDD_SERVERWAIT DIALOG 0, 0, 186, 90 IDD_SERVERWAIT DIALOG 0, 0, 186, 90
@ -1203,17 +1177,6 @@ BEGIN
COMBOBOX IDC_SAMPLE_RATE,66,54,66,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_SAMPLE_RATE,66,54,66,12,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
END END
IDD_JOYBUS_DIALOG DIALOGEX 0, 0, 209, 57
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION
EXSTYLE WS_EX_TOOLWINDOW
CAPTION "Joybus Options"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
DEFPUSHBUTTON "OK",IDOK,152,36,50,14
CONTROL "Enable Joybus Connection",IDC_JOYBUS_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,7,7,195,10
EDITTEXT IDC_JOYBUS_HOSTNAME,7,20,195,14,ES_AUTOHSCROLL
END
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////
// //
@ -1243,15 +1206,7 @@ BEGIN
BEGIN BEGIN
END END
IDD_LINKTAB1, DIALOG IDD_SERVERWAIT, DIALOG
BEGIN
END
IDD_LINKTAB2, DIALOG
BEGIN
END
IDD_LINKTAB3, DIALOG
BEGIN BEGIN
END END
@ -1587,14 +1542,6 @@ BEGIN
TOPMARGIN, 7 TOPMARGIN, 7
BOTTOMMARGIN, 163 BOTTOMMARGIN, 163
END END
IDD_JOYBUS_DIALOG, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 202
TOPMARGIN, 7
BOTTOMMARGIN, 50
END
END END
#endif // APSTUDIO_INVOKED #endif // APSTUDIO_INVOKED
@ -1653,6 +1600,8 @@ BEGIN
MENUITEM "Open GB...", ID_FILE_OPEN_GB MENUITEM "Open GB...", ID_FILE_OPEN_GB
MENUITEM "Close", ID_FILE_CLOSE MENUITEM "Close", ID_FILE_CLOSE
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "&Link with...", ID_OPTIONS_LINK_OPTIONS
MENUITEM SEPARATOR
POPUP "Recent" POPUP "Recent"
BEGIN BEGIN
MENUITEM "&Reset", ID_FILE_RECENT_RESET MENUITEM "&Reset", ID_FILE_RECENT_RESET
@ -1977,14 +1926,6 @@ BEGIN
MENUITEM SEPARATOR MENUITEM SEPARATOR
MENUITEM "&Colors...", ID_OPTIONS_GAMEBOY_COLORS MENUITEM "&Colors...", ID_OPTIONS_GAMEBOY_COLORS
END END
POPUP "&Link"
BEGIN
MENUITEM "Enable GBA Linking", ID_OPTIONS_LINK_ENABLE
MENUITEM "&Wireless Adapter", ID_OPTIONS_LINK_WIRELESSADAPTER
MENUITEM "&Options...", ID_OPTIONS_LINK_OPTIONS
MENUITEM SEPARATOR
MENUITEM "&Joybus Options...", ID_OPTIONS_JOYBUS
END
END END
POPUP "&Cheats" POPUP "&Cheats"
BEGIN BEGIN

View File

@ -107,7 +107,6 @@
#define IDD_FULLSCREEN 162 #define IDD_FULLSCREEN 162
#define IDD_XAUDIO2_CONFIG 163 #define IDD_XAUDIO2_CONFIG 163
#define IDD_AUDIO_CORE_SETTINGS 164 #define IDD_AUDIO_CORE_SETTINGS 164
#define IDD_JOYBUS_DIALOG 165
#define IDC_R0 1000 #define IDC_R0 1000
#define IDC_EDIT_UP 1000 #define IDC_EDIT_UP 1000
#define IDC_R1 1001 #define IDC_R1 1001
@ -564,8 +563,13 @@
#define IDC_SOUND_FILTERING 1294 #define IDC_SOUND_FILTERING 1294
#define IDC_COMBO1 1296 #define IDC_COMBO1 1296
#define IDC_SAMPLE_RATE 1296 #define IDC_SAMPLE_RATE 1296
#define IDC_JOYBUS_HOSTNAME 1297 #define IDC_LINK_MODE 1296
#define IDC_JOYBUS_ENABLE 1298 #define IDC_LINK_WITH 1300
#define IDC_STATIC_TIMEOUT 1301
#define IDC_LINK_SERVER 1302
#define IDC_LINK_CLIENT 1303
#define IDC_GROUP_NETWORK 1304
#define IDC_LINK_ROLE 1305
#define IDS_OAL_NODEVICE 2000 #define IDS_OAL_NODEVICE 2000
#define IDS_OAL_NODLL 2001 #define IDS_OAL_NODLL 2001
#define IDS_AVI_CANNOT_CREATE_AVI 2002 #define IDS_AVI_CANNOT_CREATE_AVI 2002
@ -815,34 +819,26 @@
#define ID_OPTIONS_SOUND_PCMINTERPOLATION_CUBIC 40296 #define ID_OPTIONS_SOUND_PCMINTERPOLATION_CUBIC 40296
#define ID_OPTIONS_SOUND_PCMINTERPOLATION_FIR 40297 #define ID_OPTIONS_SOUND_PCMINTERPOLATION_FIR 40297
#define ID_OPTIONS_SOUND_PCMINTERPOLATION_LIBRESAMPLE 40298 #define ID_OPTIONS_SOUND_PCMINTERPOLATION_LIBRESAMPLE 40298
#define IDD_LINKTAB1 40300
#define IDD_LINKTAB 40301 #define IDD_LINKTAB 40301
#define IDD_LINKTAB2 40302
#define IDD_LINKTAB3 40303
#define IDD_SERVERWAIT 40304 #define IDD_SERVERWAIT 40304
#define IDC_TAB1 40305 #define IDC_TAB1 40305
#define IDC_LINK_SINGLE 40306 #define IDC_LINK_SINGLE 40306
#define IDC_LINK_TIMEOUT 40307 #define IDC_LINK_TIMEOUT 40307
#define IDC_LINK_DISCONNECTED 40307
#define IDC_LINK_LAN 40308 #define IDC_LINK_LAN 40308
#define IDC_LINK2P 40309 #define IDC_LINK2P 40309
#define IDC_LINKTCP 40310 #define IDC_LINK_RFU 40309
#define IDC_LINK_GAMECUBE 40310
#define IDC_SSPEED 40311 #define IDC_SSPEED 40311
#define IDC_SERVERSTART 40312
#define IDC_SERVERIP 40313 #define IDC_SERVERIP 40313
#define IDC_CLINKIP 40314 #define IDC_CLINKIP 40314
#define IDC_SPEEDOFF 40315
#define IDC_LINKCONNECT 40316
#define ID_OPTIONS_LINK_OPTIONS 40318 #define ID_OPTIONS_LINK_OPTIONS 40318
#define ID_OPTIONS_LINK_LOG 40319 #define ID_OPTIONS_LINK_LOG 40319
#define ID_OPTIONS_LINK_WIRELESSADAPTER 40320 #define ID_OPTIONS_LINK_WIRELESSADAPTER 40320
#define IDC_LINKTIMEOUT 40321 #define IDC_LINKTIMEOUT 40321
#define IDC_CLINKTCP 40322
#define IDC_SERVERWAIT 40323 #define IDC_SERVERWAIT 40323
#define IDC_LINKUDP 40324
#define IDC_LINK3P 40325 #define IDC_LINK3P 40325
#define IDC_LINK4P 40326 #define IDC_LINK4P 40326
#define IDC_CLINKUDP 40327
#define IDC_SPEEDON 40328
#define ID_OPTIONS_EMULATOR_REMOVEINTROSGBA 40331 #define ID_OPTIONS_EMULATOR_REMOVEINTROSGBA 40331
#define ID_Menu 40332 #define ID_Menu 40332
#define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLANISOTROPIC 40333 #define ID_OPTIONS_VIDEO_RENDEROPTIONS_GLANISOTROPIC 40333

View File

@ -1159,15 +1159,17 @@ EVT_HANDLER(JoypadAutofireR, "Autofire R (toggle)")
EVT_HANDLER_MASK(LanLink, "Start LAN link", CMDEN_LINK_ANY) EVT_HANDLER_MASK(LanLink, "Start LAN link", CMDEN_LINK_ANY)
{ {
#ifndef NO_LINK #ifndef NO_LINK
if(lanlink.connected) { LinkMode mode = GetLinkMode();
if (mode == LINK_CABLE_SOCKET) {
// while we could deactivate the command when connected, it is more // while we could deactivate the command when connected, it is more
// user-friendly to display a message indidcating why // user-friendly to display a message indidcating why
wxLogError(_("LAN link is already active. Disable link mode to disconnect.")); wxLogError(_("LAN link is already active. Disable link mode to disconnect."));
return; return;
} }
if(rfu_enabled) { if (mode == LINK_RFU_IPC || mode == LINK_GAMECUBE_DOLPHIN) {
// see above comment // see above comment
wxLogError(_("RFU is currently only supported in local mode.")); wxLogError(_("RFU and Joybus are only supported in local mode."));
return; return;
} }
wxDialog *dlg = GetXRCDialog("NetLink"); wxDialog *dlg = GetXRCDialog("NetLink");
@ -2118,33 +2120,38 @@ EVT_HANDLER(JoypadConfigure, "Joypad options...")
EVT_HANDLER(LinkConfigure, "Link options...") EVT_HANDLER(LinkConfigure, "Link options...")
{ {
#ifndef NO_LINK #ifndef NO_LINK
bool jb = gba_joybus_enabled;
wxString jh = gopts.joybus_host; wxString jh = gopts.joybus_host;
wxDialog *dlg = GetXRCDialog("LinkConfig"); wxDialog *dlg = GetXRCDialog("LinkConfig");
if (ShowModal(dlg) != wxID_OK) if (ShowModal(dlg) != wxID_OK)
return; return;
bool valid = SetLinkServerHost(gopts.joybus_host.mb_str());
if (!valid) {
wxMessageBox(_("You must enter a valid host name"),
_("Host name invalid"), wxICON_ERROR | wxOK);
return;
}
update_opts(); update_opts();
if(jb != gba_joybus_enabled) {
if(gba_joybus_enabled) SetLinkTimeout(gopts.linktimeout);
JoyBusConnect();
else LinkMode oldLinkMode = GetLinkMode();
JoyBusShutdown(); LinkMode newLinkMode = getOptionsLinkMode();
} else if(jh != gopts.joybus_host) { bool dolphinHostChanged = jh != gopts.joybus_host;
joybusHostAddr = std::string(gopts.joybus_host.mb_str());
JoyBusConnect(); if (newLinkMode != oldLinkMode || dolphinHostChanged) {
}
if(gba_link_enabled != did_link_init) {
if(gba_link_enabled) {
if((did_link_init = InitLink()))
cmd_enable |= CMDEN_LINK_ANY;
} else {
did_link_init = false;
CloseLink(); CloseLink();
lanlink.active = false; InitLink(newLinkMode);
}
cmd_enable &= ~CMDEN_LINK_ANY; cmd_enable &= ~CMDEN_LINK_ANY;
if (GetLinkMode() != LINK_DISCONNECTED) {
cmd_enable |= CMDEN_LINK_ANY;
} }
enable_menus(); enable_menus();
}
#endif #endif
} }

View File

@ -50,7 +50,8 @@ static class NetLink_t : public wxEvtHandler
public: public:
wxDialog *dlg; wxDialog *dlg;
int n_players; int n_players;
NetLink_t() : n_players(2) {} bool server;
NetLink_t() : n_players(2), server(false) {}
wxButton *okb; wxButton *okb;
void ServerOKButton(wxCommandEvent &ev) void ServerOKButton(wxCommandEvent &ev)
{ {
@ -63,150 +64,79 @@ public:
// attached to OK, so skip when OK // attached to OK, so skip when OK
void NetConnect(wxCommandEvent &ev) void NetConnect(wxCommandEvent &ev)
{ {
static const int length = 256;
if(!dlg->Validate() || !dlg->TransferDataFromWindow()) if(!dlg->Validate() || !dlg->TransferDataFromWindow())
return; return;
if (!server) {
bool valid = SetLinkServerHost(gopts.link_host.mb_str());
if (!valid) {
wxMessageBox(_("You must enter a valid host name"),
_("Host name invalid"), wxICON_ERROR | wxOK);
return;
}
}
update_opts(); // save fast flag and client host update_opts(); // save fast flag and client host
wxString connmsg, pmsg; // Close any previous link
CloseLink();
wxMutex lock; wxString connmsg;
wxCondition sig(lock); wxString title;
lock.Lock();
bool done = false; SetLinkTimeout(gopts.linktimeout);
EnableSpeedHacks(gopts.lanlink_speed);
EnableLinkServer(server, n_players - 1);
if(lanlink.server) { if (server) {
lanlink.numslaves = n_players - 1; char host[length];
class sid_t : public ServerInfoDisplay GetLinkServerHost(host, length);
{
wxMutex *lock;
wxCondition *sig;
wxString *connmsg, *pmsg;
bool *done;
bool conn[3];
public:
sid_t(wxMutex *m, wxCondition *c, wxString *cm, wxString *pm,
bool *d) :
lock(m), sig(c), connmsg(cm), pmsg(pm), done(d) {}
void ShowServerIP(const sf::IPAddress &addr) {
wxString addr_s(addr.ToString().c_str(), wxConvLibc);
wxString msg;
msg.Printf(_("Server IP address is: %s\n"), addr_s.c_str());
connmsg->append(msg);
conn[0] = conn[1] = conn[2] = false;
}
void ShowConnect(int player) {
wxString msg;
conn[player - 1] = true;
lock->Lock();
pmsg->clear();
for(int i = 0; i < 3; i++)
if(conn[i]) {
msg.Printf(_("Player %d connected\n"), i + 2);
pmsg->append(msg);
}
sig->Signal();
lock->Unlock();
}
void Ping() {
lock->Lock();
sig->Signal();
if(*done)
lanlink.terminate = true;
lock->Unlock();
}
void Connected() {
lock->Lock();
*done = true;
sig->Signal();
lock->Unlock();
}
};
sid_t* sid = new sid_t(&lock, &sig, &connmsg, &pmsg, &done); title.Printf(_("Waiting for clients..."));
connmsg.Printf(_("Server IP address is: %s\n"), wxString(host, wxConvLibc).c_str());
if (!ls.Init(sid)) {
wxLogError(_("Error occurred.\nPlease try again."));
lock.Unlock();
delete sid;
return;
}
wxProgressDialog
pdlg(_("Waiting for clients..."), connmsg,
100, dlg, wxPD_APP_MODAL|wxPD_CAN_ABORT|wxPD_ELAPSED_TIME);
while(!done) {
if(!pdlg.Pulse(connmsg + pmsg))
done = true;
sig.Wait();
}
} else { } else {
class cid_t : public ClientInfoDisplay title.Printf(_("Waiting for connection..."));
{ connmsg.Printf(_("Connecting to %s\n"), gopts.link_host.c_str());
wxMutex *lock;
wxCondition *sig;
wxString *connmsg, *pmsg;
bool *done;
public:
cid_t(wxMutex *m, wxCondition *c, wxString *cm, wxString *pm,
bool *d) :
lock(m), sig(c), connmsg(cm), pmsg(pm), done(d) {}
void ConnectStart(const sf::IPAddress &addr) {
wxString addr_s(addr.ToString().c_str(), wxConvLibc);
connmsg->Printf(_("Connecting to %s\n"), addr_s.c_str());
}
void ShowConnect(int player, int togo) {
wxString msg;
lock->Lock();
pmsg->Printf(_("Connected as #%d\n"), player);
if(togo)
msg.Printf(_("Waiting for %d players to join"), togo);
else
msg = _("All players joined.");
pmsg->append(msg);
sig->Signal();
lock->Unlock();
}
void Ping() {
lock->Lock();
sig->Signal();
if(*done)
lanlink.terminate = true;
lock->Unlock();
}
void Connected() {
lock->Lock();
*done = true;
sig->Signal();
lock->Unlock();
}
};
cid_t* cid = new cid_t(&lock, &sig, &connmsg, &pmsg, &done);
if (!lc.Init(sf::IPAddress(std::string(gopts.link_host.mb_str())), cid)) {
wxLogError(_("Error occurred.\nPlease try again."));
lock.Unlock();
delete cid;
return;
} }
wxProgressDialog // Init link
pdlg(_("Waiting for connection..."), connmsg, ConnectionState state = InitLink(LINK_CABLE_SOCKET);
// Display a progress dialog while the connection is establishing
if (state == LINK_NEEDS_UPDATE) {
wxProgressDialog pdlg(title, connmsg,
100, dlg, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME); 100, dlg, wxPD_APP_MODAL | wxPD_CAN_ABORT | wxPD_ELAPSED_TIME);
while(!done) { while (state == LINK_NEEDS_UPDATE) {
if(!pdlg.Pulse(connmsg + pmsg)) // Ask the core for updates
done = true; char message[length];
sig.Wait(); state = ConnectLinkUpdate(message, length);
connmsg = wxString(message, wxConvLibc);
// Does the user want to abort?
if (!pdlg.Pulse(connmsg)) {
state = LINK_ABORT;
} }
} }
lock.Unlock(); }
if(lanlink.connected) {
pmsg.Replace(wxT("\n"), wxT(" ")); // The user canceled the connection attempt
systemScreenMessage(pmsg); if (state == LINK_ABORT) {
lanlink.active = true; CloseLink();
}
// Something failed during init
if (state == LINK_ERROR) {
CloseLink();
wxLogError(_("Error occurred.\nPlease try again."));
}
if(GetLinkMode() != LINK_DISCONNECTED) {
connmsg.Replace(wxT("\n"), wxT(" "));
systemScreenMessage(connmsg);
ev.Skip(); // all OK ev.Skip(); // all OK
} }
} }
@ -1438,45 +1368,6 @@ public:
} }
} JoyPadConfigHandler[4]; } JoyPadConfigHandler[4];
#ifndef NO_LINK
// tc validator for IP addresses using SFML for validation instead of wx
class IPHostValidator : public wxValidator
{
wxString *valp;
public:
IPHostValidator(wxString *v) : wxValidator(), valp(v) {}
IPHostValidator(const IPHostValidator &e) : wxValidator(), valp(e.valp) {}
wxObject *Clone() const { return new IPHostValidator(*this); }
bool Validate(wxWindow *p) {
wxTextCtrl *tc = wxStaticCast(GetWindow(), wxTextCtrl);
if(!tc->IsEnabled())
return true;
wxString val = tc->GetValue();
bool isv = true;
if(val.empty())
isv = false;
else {
sf::IPAddress srv = std::string(val.mb_str());
isv = srv.IsValid();
}
if(!isv)
wxMessageBox(_("You must enter a valid host name"),
_("Host name invalid"), wxICON_ERROR|wxOK);
return isv;
}
bool TransferToWindow() {
wxTextCtrl *tc = wxStaticCast(GetWindow(), wxTextCtrl);
tc->SetValue(*valp);
return true;
}
bool TransferFromWindow() {
wxTextCtrl *tc = wxStaticCast(GetWindow(), wxTextCtrl);
*valp = tc->GetValue();
return true;
}
};
#endif
// manage fullscreen mode widget // manage fullscreen mode widget
// technically, it's more than a validator: it modifies the widget as well // technically, it's more than a validator: it modifies the widget as well
class ScreenModeList : public wxValidator class ScreenModeList : public wxValidator
@ -2227,7 +2118,7 @@ bool MainFrame::InitMore(void)
// so just set individual flags here // so just set individual flags here
cmd_enable = CMDEN_NGDB_ANY | CMDEN_NREC_ANY; cmd_enable = CMDEN_NGDB_ANY | CMDEN_NREC_ANY;
update_state_ts(true); update_state_ts(true);
enable_menus();
// set pointers for checkable menu items // set pointers for checkable menu items
// and set initial checked status // and set initial checked status
if(checkable_mi.size()) { if(checkable_mi.size()) {
@ -2464,8 +2355,8 @@ bool MainFrame::InitMore(void)
#ifndef NO_LINK #ifndef NO_LINK
{ {
net_link_handler.dlg = d; net_link_handler.dlg = d;
getrbbe("Server", lanlink.server); getrbbe("Server", net_link_handler.server);
getrbbd("Client", lanlink.server); getrbbd("Client", net_link_handler.server);
getlab("PlayersLab"); getlab("PlayersLab");
addrber(lab, false); addrber(lab, false);
getrbi("Link2P", net_link_handler.n_players, 2); getrbi("Link2P", net_link_handler.n_players, 2);
@ -2478,9 +2369,8 @@ bool MainFrame::InitMore(void)
addrber(lab, true); addrber(lab, true);
gettc("ServerIP", gopts.link_host); gettc("ServerIP", gopts.link_host);
addrber(tc, true); addrber(tc, true);
tc->SetValidator(IPHostValidator(&gopts.link_host)); getrbbr("SpeedOff", gopts.lanlink_speed);
getrbbr("SpeedOff", lanlink.speed); getrbb("SpeedOn", gopts.lanlink_speed);
getrbb("SpeedOn", lanlink.speed);
wxWindow *okb = d->FindWindow(wxID_OK); wxWindow *okb = d->FindWindow(wxID_OK);
if(okb) { // may be gone if style guidlines removed it if(okb) { // may be gone if style guidlines removed it
net_link_handler.okb = wxStaticCast(okb, wxButton); net_link_handler.okb = wxStaticCast(okb, wxButton);
@ -2847,8 +2737,8 @@ bool MainFrame::InitMore(void)
addbier(lab, true); addbier(lab, true);
/// Boot ROM /// Boot ROM
getcbbe("BootRomEn", gopts.gb_use_bios); getcbbe("BootRomEn", gopts.gba_use_bios);
getfp("BootRom", gopts.gb_bios); getfp("BootRom", gopts.gba_bios);
addbe(fp); addbe(fp);
getlab("BootRomLab"); getlab("BootRomLab");
addbe(lab); addbe(lab);
@ -3072,18 +2962,17 @@ bool MainFrame::InitMore(void)
#ifndef NO_LINK #ifndef NO_LINK
LoadXRCDialog("LinkConfig"); LoadXRCDialog("LinkConfig");
{ {
getcbbe("Joybus", gba_joybus_enabled); getcbbe("Joybus", gopts.gba_joybus_enabled);
getlab("JoybusHostLab"); getlab("JoybusHostLab");
addbe(lab); addbe(lab);
gettc("JoybusHost", gopts.joybus_host); gettc("JoybusHost", gopts.joybus_host);
tc->SetValidator(IPHostValidator(&gopts.joybus_host));
addbe(tc); addbe(tc);
getcbbe("Link", gba_link_enabled); getcbbe("Link", gopts.gba_link_enabled);
getcbb("RFU", rfu_enabled); getcbb("RFU", gopts.rfu_enabled);
addbe(cb); addbe(cb);
getlab("LinkTimeoutLab"); getlab("LinkTimeoutLab");
addbe(lab); addbe(lab);
getsc("LinkTimeout", linktimeout); getsc("LinkTimeout", gopts.linktimeout);
addbe(sc); addbe(sc);
} }
#endif #endif
@ -3205,23 +3094,33 @@ bool MainFrame::InitMore(void)
panel->ShowFullScreen(true); panel->ShowFullScreen(true);
#ifndef NO_LINK #ifndef NO_LINK
if(gba_joybus_enabled) { LinkMode linkMode = getOptionsLinkMode();
if (linkMode == LINK_GAMECUBE_DOLPHIN) {
bool isv = !gopts.joybus_host.empty(); bool isv = !gopts.joybus_host.empty();
if(isv) { if(isv) {
joybusHostAddr = std::string(gopts.joybus_host.mb_str()); isv = SetLinkServerHost(gopts.joybus_host.mb_str());
isv = joybusHostAddr.IsValid();
} }
if(!isv) { if(!isv) {
wxLogError(_("JoyBus host invalid; disabling")); wxLogError(_("JoyBus host invalid; disabling"));
gba_joybus_enabled = false; gopts.gba_joybus_enabled = false;
} else } else {
JoyBusConnect(); linkMode = LINK_DISCONNECTED;
}
} }
if(gba_link_enabled)
if((did_link_init = InitLink()))
cmd_enable |= CMDEN_LINK_ANY;
ConnectionState linkState = InitLink(linkMode);
if (linkState != LINK_OK) {
CloseLink();
}
if (GetLinkMode() != LINK_DISCONNECTED)
cmd_enable |= CMDEN_LINK_ANY;
#endif #endif
enable_menus();
panel->SetFrameTitle(); panel->SetFrameTitle();
// All OK; activate idle loop // All OK; activate idle loop

View File

@ -279,9 +279,10 @@ void GameArea::LoadGame(const wxString &name)
wxString bname = loaded_game.GetFullName(); wxString bname = loaded_game.GetFullName();
#ifndef NO_LINK #ifndef NO_LINK
// MakeInstanceFilename doesn't do wxString, so just add slave ID here // MakeInstanceFilename doesn't do wxString, so just add slave ID here
if(vbaid) { int playerId = GetLinkPlayerId();
if(playerId >= 0) {
bname.append(wxT('-')); bname.append(wxT('-'));
bname.append(wxChar(wxT('1') + vbaid)); bname.append(wxChar(wxT('1') + playerId));
} }
#endif #endif
bname.append(wxT(".sav")); bname.append(wxT(".sav"));
@ -331,9 +332,10 @@ void GameArea::SetFrameTitle()
} else } else
tit = wxT("VisualBoyAdvance-M " VERSION); tit = wxT("VisualBoyAdvance-M " VERSION);
#ifndef NO_LINK #ifndef NO_LINK
if(vbaid > 0 || linkid > 0) { int playerId = GetLinkPlayerId();
if (playerId >= 0) {
tit.append(_(" player ")); tit.append(_(" player "));
tit.append(wxChar(wxT('1') + (linkid > 0 ? linkid : vbaid))); tit.append(wxChar(wxT('1') + playerId));
} }
#endif #endif
wxGetApp().frame->SetTitle(tit); wxGetApp().frame->SetTitle(tit);
@ -516,9 +518,10 @@ void GameArea::SaveBattery(bool quiet)
// MakeInstanceFilename doesn't do wxString, so just add slave ID here // MakeInstanceFilename doesn't do wxString, so just add slave ID here
wxString bname = game_name(); wxString bname = game_name();
#ifndef NO_LINK #ifndef NO_LINK
if(vbaid) { int playerId = GetLinkPlayerId();
if (playerId >= 0) {
bname.append(wxT('-')); bname.append(wxT('-'));
bname.append(wxChar(wxT('1') + vbaid)); bname.append(wxChar(wxT('1') + playerId));
} }
#endif #endif
bname.append(wxT(".sav")); bname.append(wxT(".sav"));
@ -836,8 +839,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;

View File

@ -391,12 +391,11 @@ bool wxvbamApp::OnCmdLineParsed(wxCmdLineParser &cl)
return true; return true;
} }
MainFrame::MainFrame() : wxFrame(), did_link_init(false), focused(false), MainFrame::MainFrame() : wxFrame(), focused(false),
paused(false), menus_opened(0), dialog_opened(0) {} paused(false), menus_opened(0), dialog_opened(0) {}
MainFrame::~MainFrame() MainFrame::~MainFrame()
{ {
if(did_link_init)
CloseLink(); CloseLink();
} }
@ -642,6 +641,18 @@ void MainFrame::StopModal()
panel->Resume(); panel->Resume();
} }
LinkMode MainFrame::getOptionsLinkMode() {
if (gopts.gba_joybus_enabled) {
return LINK_GAMECUBE_DOLPHIN;
} else if (gopts.rfu_enabled) {
return LINK_RFU_IPC;
} else if (gopts.gba_link_enabled) {
return LINK_CABLE_IPC;
}
return LINK_DISCONNECTED;
}
// global event filter // global event filter
// apparently required for win32; just setting accel table still misses // apparently required for win32; just setting accel table still misses
// a few keys (e.g. only ctrl-x works for exit, but not esc & ctrl-q; // a few keys (e.g. only ctrl-x works for exit, but not esc & ctrl-q;

View File

@ -205,7 +205,6 @@ public:
// required for event handling // required for event handling
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
private: private:
bool did_link_init;
GameArea *panel; GameArea *panel;
// the various reasons the game might be paused // the various reasons the game might be paused
@ -244,6 +243,8 @@ private:
void OnDropFile(wxDropFilesEvent&); void OnDropFile(wxDropFilesEvent&);
// pop up menu in fullscreen mode // pop up menu in fullscreen mode
void OnMenu(wxContextMenuEvent &); void OnMenu(wxContextMenuEvent &);
// Returns the link mode to set according to the options
LinkMode getOptionsLinkMode();
#include "cmdhandlers.h" #include "cmdhandlers.h"
}; };