Added a Auto-start link option

git-svn-id: https://svn.code.sf.net/p/vbam/code/trunk@1244 a31d4220-a93d-0410-bf67-fe4944624d44
This commit is contained in:
skidau 2015-03-24 13:30:49 +00:00 committed by Arthur Moore
parent ad29903c8e
commit 9154353721
10 changed files with 118 additions and 28 deletions

View File

@ -803,7 +803,8 @@ void gbWriteMemory(register u16 address, register u8 value)
case 0x02: {
gbSerialOn = (value & 0x80);
#ifndef NO_LINK
if (EmuReseted || (gbMemory[0xff02] & 0x7c) || (value & 0x7c) || (!(value & 0x81))) { //trying to detect whether the game has exited multiplay mode, pokemon blue start w/ 0x7e while pocket racing start w/ 0x7c
//trying to detect whether the game has exited multiplay mode, pokemon blue start w/ 0x7e while pocket racing start w/ 0x7c
if (EmuReseted || (gbMemory[0xff02] & 0x7c) || (value & 0x7c) || (!(value & 0x81))) {
LinkFirstTime = true;
}
EmuReseted = false;

View File

@ -238,14 +238,15 @@ struct LinkDriver {
StartFunc *start;
UpdateFunc *update;
CloseFunc *close;
bool uses_socket;
};
static const LinkDriver linkDrivers[] =
{
{ LINK_CABLE_IPC, InitIPC, NULL, StartCableIPC, UpdateCableIPC, CloseIPC },
{ LINK_CABLE_SOCKET, InitSocket, ConnectUpdateSocket, StartCableSocket, UpdateSocket, CloseSocket },
{ LINK_RFU_IPC, InitIPC, NULL, StartRFU, UpdateRFUIPC, CloseIPC },
{ LINK_GAMECUBE_DOLPHIN, JoyBusConnect, NULL, NULL, JoyBusUpdate, JoyBusShutdown },
{ LINK_GAMEBOY, InitIPC, NULL, NULL, NULL, CloseIPC }
{ LINK_CABLE_IPC, InitIPC, NULL, StartCableIPC, UpdateCableIPC, CloseIPC, false },
{ LINK_CABLE_SOCKET, InitSocket, ConnectUpdateSocket, StartCableSocket, UpdateSocket, CloseSocket, true },
{ LINK_RFU_IPC, InitIPC, NULL, StartRFU, UpdateRFUIPC, CloseIPC, false },
{ LINK_GAMECUBE_DOLPHIN, JoyBusConnect, NULL, NULL, JoyBusUpdate, JoyBusShutdown, false },
{ LINK_GAMEBOY, InitIPC, NULL, NULL, NULL, CloseIPC, false }
};
@ -2044,7 +2045,7 @@ static void UpdateSocket(int ticks)
void LinkUpdate(int ticks)
{
if (!linkDriver) {
if (!linkDriver || !linkDriver->update) {
return;
}
@ -2248,7 +2249,7 @@ ConnectionState InitLink(LinkMode mode)
}
}
if (linkDriver == NULL) {
if (!linkDriver || !linkDriver->connect) {
systemMessage(0, N_("Unable to find link driver"));
return LINK_ERROR;
}
@ -2349,7 +2350,7 @@ ConnectionState ConnectLinkUpdate(char * const message, size_t size)
{
message[0] = '\0';
if (!linkDriver || gba_connection_state != LINK_NEEDS_UPDATE) {
if (!linkDriver || !linkDriver->connectUpdate || gba_connection_state != LINK_NEEDS_UPDATE) {
gba_connection_state = LINK_ERROR;
snprintf(message, size, N_("Link connection does not need updates."));
@ -2486,7 +2487,7 @@ static void CloseSocket() {
}
void CloseLink(void) {
if (!linkDriver) {
if (!linkDriver || !linkDriver->close) {
return; // Nothing to do
}
@ -2803,6 +2804,58 @@ u16 gbLinkUpdate(u8 b, int gbSerialOn) //used on external clock
return ((dat << 8) | (recvd & (u8)0xff));
}
void BootLink(int m_type, const char *hostAddr, int timeout, bool m_hacks, int m_numplayers)
{
if (linkDriver) {
// Connection has already been established
return;
}
LinkMode mode = (LinkMode)m_type;
if (mode == LINK_DISCONNECTED || mode == LINK_CABLE_SOCKET) {
return;
}
// Close any previous link
CloseLink();
bool needsServerHost = (mode == LINK_GAMECUBE_DOLPHIN);
if (needsServerHost) {
bool valid = SetLinkServerHost(hostAddr);
if (!valid) {
return;
}
}
SetLinkTimeout(timeout);
EnableSpeedHacks(m_hacks);
// Init link
ConnectionState state = InitLink(mode);
if (!linkDriver->uses_socket)
{
// The user canceled the connection attempt
if (state == LINK_ABORT) {
CloseLink();
return;
}
// Something failed during init
if (state == LINK_ERROR) {
return;
}
}
else
{
CloseLink();
return;
}
}
#else
bool gba_joybus_active = false;
#endif

View File

@ -202,4 +202,6 @@ extern void gbLinkReset();
extern u8 gbStartLink(u8 b);
extern u16 gbLinkUpdate(u8 b, int gbSerialOn);
extern void BootLink(int m_type, const char *host, int timeout, bool m_hacks, int m_numplayers);
#endif /* GBA_GBALINK_H */

View File

@ -42,7 +42,6 @@ LinkOptions::LinkOptions(CWnd* pParent /*=NULL*/)
: CDialog(LinkOptions::IDD, pParent)
{
//{{AFX_DATA_INIT(LinkOptions)
m_numplayers = 0;
m_type = theApp.linkMode;
m_server = FALSE;
//}}AFX_DATA_INIT
@ -55,10 +54,11 @@ void LinkOptions::DoDataExchange(CDataExchange* pDX)
//{{AFX_DATA_MAP(LinkOptions)
DDX_CBData(pDX, IDC_LINK_MODE, m_type);
DDX_Control(pDX, IDC_LINKTIMEOUT, m_timeout);
DDX_Check(pDX, IDC_AUTOLINK, theApp.linkAuto);
DDX_Check(pDX, IDC_SSPEED, theApp.linkHacks);
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_LINK2P, theApp.linkNumPlayers);
DDX_Radio(pDX, IDC_LINK_CLIENT, m_server);
//}}AFX_DATA_MAP
}
@ -80,7 +80,27 @@ BOOL LinkOptions::OnInitDialog(){
m_timeout.LimitText(5);
m_timeout.SetWindowText(timeout);
m_serverip.SetWindowText(theApp.linkHost);
m_serverip.SetWindowText(theApp.linkHostAddr);
CheckDlgButton(IDC_AUTOLINK, theApp.linkAuto);
CheckDlgButton(IDC_SSPEED, theApp.linkHacks);
int player_radio = 0;
switch (theApp.linkNumPlayers)
{
case 2:
player_radio = IDC_LINK2P;
case 3:
player_radio = IDC_LINK3P;
case 4:
player_radio = IDC_LINK4P;
default:
player_radio = IDC_LINK2P;
}
CButton* pButton = (CButton*)GetDlgItem(player_radio);
pButton->SetCheck(true);
UpdateAvailability();
@ -137,7 +157,7 @@ void LinkOptions::OnOk()
if (newMode == LINK_DISCONNECTED) {
theApp.linkTimeout = timeout;
theApp.linkMode = LINK_DISCONNECTED;
theApp.linkHost = host;
theApp.linkHostAddr = host;
CDialog::OnOK();
return;
}
@ -152,8 +172,8 @@ void LinkOptions::OnOk()
}
}
EnableSpeedHacks(m_hacks);
EnableLinkServer(m_server, m_numplayers + 1);
EnableSpeedHacks(theApp.linkHacks);
EnableLinkServer(m_server, theApp.linkNumPlayers + 1);
if (m_server) {
char localhost[length];
@ -220,7 +240,7 @@ void LinkOptions::OnOk()
theApp.linkTimeout = timeout;
theApp.linkMode = GetLinkMode();
theApp.linkHost = host;
theApp.linkHostAddr = host;
CDialog::OnOK();
return;

View File

@ -16,8 +16,6 @@ public:
CComboBox m_mode;
CEdit m_serverip;
BOOL m_server;
int m_numplayers;
BOOL m_hacks;
//}}AFX_DATA

View File

@ -626,7 +626,10 @@ bool MainWnd::FileRun()
theApp.rewindSaveNeeded = false;
toolsClearLog();
#ifndef NO_LINK
if (theApp.linkAuto)
BootLink(theApp.linkMode, theApp.linkHostAddr, theApp.linkTimeout, theApp.linkHacks, theApp.linkNumPlayers);
#endif
return true;
}

View File

@ -1699,8 +1699,13 @@ void VBA::loadSettings()
linkMode = regQueryDwordValue("LinkMode", LINK_DISCONNECTED);
linkHost = regQueryStringValue("LinkHostAddr", "localhost");
linkHostAddr = regQueryStringValue("LinkHostAddr", "localhost");
linkAuto = regQueryDwordValue("LinkAuto", true);
linkHacks = regQueryDwordValue("LinkHacks", false);
linkNumPlayers = regQueryDwordValue("LinkNumPlayers", 2);
#endif
Sm60FPS::bSaveMoreCPU = regQueryDwordValue("saveMoreCPU", 0);
@ -2631,7 +2636,10 @@ void VBA::saveSettings()
#ifndef NO_LINK
regSetDwordValue("LinkTimeout", linkTimeout);
regSetDwordValue("LinkMode", linkMode);
regSetStringValue("LinkHostAddr", linkHost);
regSetStringValue("LinkHostAddr", linkHostAddr);
regSetDwordValue("LinkAuto", linkAuto);
regSetDwordValue("LinkHacks", linkHacks);
regSetDwordValue("LinkNumPlayers", linkNumPlayers);
#endif
regSetDwordValue("lastFullscreen", lastFullscreen);

View File

@ -209,7 +209,10 @@ class VBA : public CWinApp
int linkTimeout;
int linkMode;
CString linkHost;
CString linkHostAddr;
BOOL linkAuto;
BOOL linkHacks;
int linkNumPlayers;
public:
VBA();

View File

@ -112,7 +112,7 @@ BEGIN
LTEXT "Please select filter plugin:",IDC_STATIC,6,6,162,8
END
IDD_LINKTAB DIALOGEX 0, 0, 254, 198
IDD_LINKTAB DIALOGEX 0, 0, 254, 208
STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Connect Link"
FONT 8, "MS Sans Serif", 0, 0, 0x1
@ -123,15 +123,16 @@ BEGIN
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
EDITTEXT IDC_LINKTIMEOUT,111,150,53,14,ES_AUTOHSCROLL | ES_NUMBER
LTEXT "Server IP address or hostname:",IDC_STATIC,25,70,75,18
CONTROL "Auto-start link (single computer only)", IDC_AUTOLINK, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 11, 165, 138, 12
LTEXT "Server IP address or hostname:", IDC_STATIC, 25, 70, 75, 18
EDITTEXT IDC_SERVERIP,114,73,105,12,ES_AUTOHSCROLL | WS_GROUP
LTEXT "Expected number of players:",IDC_STATIC,25,94,89,10
CONTROL "2",IDC_LINK2P,"Button",BS_AUTORADIOBUTTON | WS_GROUP,53,106,21,13
CONTROL "3",IDC_LINK3P,"Button",BS_AUTORADIOBUTTON,99,106,21,13
CONTROL "4",IDC_LINK4P,"Button",BS_AUTORADIOBUTTON,145,106,21,13
CONTROL "Enable speed hacks",IDC_SSPEED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,25,121,138,12
PUSHBUTTON "OK",ID_OK,60,176,60,15
PUSHBUTTON "Cancel",ID_CANCEL,136,176,57,15
PUSHBUTTON "OK",ID_OK,60,186,60,15
PUSHBUTTON "Cancel",ID_CANCEL,136,186,57,15
GROUPBOX "Network options",IDC_GROUP_NETWORK,11,28,231,113
LTEXT "Role:",IDC_LINK_ROLE,25,46,18,8
END

View File

@ -837,6 +837,7 @@
#define ID_OPTIONS_LINK_LOG 40319
#define ID_OPTIONS_LINK_WIRELESSADAPTER 40320
#define IDC_LINKTIMEOUT 40321
#define IDC_AUTOLINK 40322
#define IDC_SERVERWAIT 40323
#define IDC_LINK3P 40325
#define IDC_LINK4P 40326