Skip to content

Commit

Permalink
Merge pull request #166 from retr0s4ge/master
Browse files Browse the repository at this point in the history
Implement basic support for multiple WiFi emulation levels
  • Loading branch information
retr0s4ge committed Jul 30, 2018
2 parents ad7083e + cf5ed05 commit 07d7588
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 18 deletions.
22 changes: 16 additions & 6 deletions desmume/src/NDSSystem.cpp
Expand Up @@ -102,6 +102,8 @@ int TotalLagFrames;

TSCalInfo TSCal;

WifiEmulationLevel wifiEmulationLevel;

namespace DLDI
{
bool tryPatch(void* data, size_t size, unsigned int device);
Expand Down Expand Up @@ -1334,8 +1336,13 @@ void Sequencer::init()


#ifdef EXPERIMENTAL_WIFI_COMM
wifi.enabled = true;
wifi.timestamp = kWifiCycles;
if(wifiEmulationLevel > WifiEmulationLevel_Off)
{
wifi.enabled = true;
wifi.timestamp = kWifiCycles;
}
else
wifi.enabled = false;
#else
wifi.enabled = false;
#endif
Expand Down Expand Up @@ -1665,7 +1672,7 @@ u64 Sequencer::findNext()
if(readslot1.isEnabled()) next = _fast_min(next,readslot1.next());

#ifdef EXPERIMENTAL_WIFI_COMM
next = _fast_min(next,wifi.next());
if (wifiEmulationLevel > WifiEmulationLevel_Off) next = _fast_min(next,wifi.next());
#endif

#define test(X,Y) if(dma_##X##_##Y .isEnabled()) next = _fast_min(next,dma_##X##_##Y .next());
Expand Down Expand Up @@ -1723,10 +1730,13 @@ void Sequencer::execHardware()
}

#ifdef EXPERIMENTAL_WIFI_COMM
if(wifi.isTriggered())
if(wifiEmulationLevel > WifiEmulationLevel_Off)
{
WIFI_usTrigger();
wifi.timestamp += kWifiCycles;
if(wifi.isTriggered())
{
WIFI_usTrigger();
wifi.timestamp += kWifiCycles;
}
}
#endif

Expand Down
11 changes: 10 additions & 1 deletion desmume/src/NDSSystem.h
Expand Up @@ -217,6 +217,14 @@ enum NDS_CONSOLE_TYPE
NDS_CONSOLE_TYPE_DSI = 0xFE
};

enum WifiEmulationLevel
{
WifiEmulationLevel_Off = 0,
WifiEmulationLevel_Normal = 10000,
WifiEmulationLevel_Compatibility = 65535,
};
extern WifiEmulationLevel wifiEmulationLevel;

struct NDSSystem
{
s32 wifiCycle;
Expand Down Expand Up @@ -701,7 +709,8 @@ extern struct TCommonSettings

std::string run_advanscene_import;

} CommonSettings;
};
extern TCommonSettings CommonSettings;

void NDS_RunAdvansceneAutoImport();

Expand Down
34 changes: 34 additions & 0 deletions desmume/src/frontend/windows/main.cpp
Expand Up @@ -3328,6 +3328,16 @@ int _main()
Piano.Enabled = (slot2_device_type == NDS_SLOT2_EASYPIANO)?true:false;
Paddle.Enabled = (slot2_device_type == NDS_SLOT2_PADDLE)?true:false;

if (GetPrivateProfileBool("Wifi", "Enabled", false, IniName))
{
if (GetPrivateProfileBool("Wifi", "Compatibility Mode", false, IniName))
wifiEmulationLevel = WifiEmulationLevel_Compatibility;
else
wifiEmulationLevel = WifiEmulationLevel_Normal;
}
else
wifiEmulationLevel = WifiEmulationLevel_Off;

CommonSettings.wifi.mode = GetPrivateProfileInt("Wifi", "Mode", 0, IniName);
CommonSettings.wifi.infraBridgeAdapter = GetPrivateProfileInt("Wifi", "BridgeAdapter", 0, IniName);

Expand Down Expand Up @@ -7066,6 +7076,17 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM
int i;
HWND cur;

if (wifiEmulationLevel > WifiEmulationLevel_Off)
{
CheckDlgItem(hDlg, IDC_WIFI_ENABLED, true);
CheckDlgItem(hDlg, IDC_WIFI_COMPAT, wifiEmulationLevel == WifiEmulationLevel_Compatibility);
}
else
{
CheckDlgItem(hDlg, IDC_WIFI_ENABLED, false);
CheckDlgItem(hDlg, IDC_WIFI_COMPAT, GetPrivateProfileBool("Wifi", "Compatibility Mode", false, IniName));
}

if (bSocketsAvailable && bWinPCapAvailable)
CheckRadioButton(hDlg, IDC_WIFIMODE0, IDC_WIFIMODE1, IDC_WIFIMODE0 + CommonSettings.wifi.mode);
else if(bSocketsAvailable)
Expand Down Expand Up @@ -7119,6 +7140,19 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM
if(romloaded)
val = MessageBox(hDlg, "The current ROM needs to be reset to apply changes.\nReset now ?", "DeSmuME", (MB_YESNO | MB_ICONQUESTION));

if (IsDlgCheckboxChecked(hDlg, IDC_WIFI_ENABLED))
{
if (IsDlgCheckboxChecked(hDlg, IDC_WIFI_COMPAT))
wifiEmulationLevel = WifiEmulationLevel_Compatibility;
else
wifiEmulationLevel = WifiEmulationLevel_Normal;
}
else
wifiEmulationLevel = WifiEmulationLevel_Off;

WritePrivateProfileBool("Wifi", "Enabled", IsDlgCheckboxChecked(hDlg, IDC_WIFI_ENABLED), IniName);
WritePrivateProfileBool("Wifi", "Compatibility Mode", IsDlgCheckboxChecked(hDlg, IDC_WIFI_COMPAT), IniName);

if (IsDlgButtonChecked(hDlg, IDC_WIFIMODE0))
CommonSettings.wifi.mode = 0;
else
Expand Down
4 changes: 3 additions & 1 deletion desmume/src/frontend/windows/resource.h
Expand Up @@ -466,8 +466,10 @@
#define IDC_EVALUE 1065
#define IDC_TEX_DEPOSTERIZE2 1065
#define IDC_TEX_SMOOTH 1065
#define IDC_WIFI_ENABLED 1065
#define IDC_STATIC_RANGE 1066
#define IDC_TEXSCALE_1 1066
#define IDC_WIFI_COMPAT 1066
#define IDC_TEXSCALE_2 1067
#define IDC_BADD 1068
#define IDC_LIST 1069
Expand Down Expand Up @@ -1080,7 +1082,7 @@
#define _APS_NO_MFC 1
#define _APS_NEXT_RESOURCE_VALUE 128
#define _APS_NEXT_COMMAND_VALUE 40150
#define _APS_NEXT_CONTROL_VALUE 1065
#define _APS_NEXT_CONTROL_VALUE 1066
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif
22 changes: 12 additions & 10 deletions desmume/src/frontend/windows/resources.rc
Expand Up @@ -1236,19 +1236,21 @@ BEGIN
LTEXT "frames",IDC_STATIC,428,167,16,8
END

IDD_WIFISETTINGS DIALOGEX 0, 0, 331, 142
IDD_WIFISETTINGS DIALOGEX 0, 0, 331, 158
STYLE DS_SETFONT | DS_CENTER | WS_CAPTION | WS_SYSMENU
CAPTION "Wifi settings"
FONT 8, "Ms Shell Dlg", 0, 0, 0x0
BEGIN
DEFPUSHBUTTON "OK",IDOK,222,120,50,14
PUSHBUTTON "Cancel",IDCANCEL,276,120,50,14
GROUPBOX "Infrastructure settings",IDC_STATIC,6,60,319,54
LTEXT "Bridge network adapter:",IDC_STATIC,12,78,306,8
COMBOBOX IDC_BRIDGEADAPTER,12,90,306,45,CBS_DROPDOWNLIST | CBS_HASSTRINGS
GROUPBOX "Wifi mode",IDC_STATIC,6,6,318,48
CONTROL "Ad-hoc",IDC_WIFIMODE0,"Button",BS_AUTORADIOBUTTON,12,24,306,10
CONTROL "Infrastructure",IDC_WIFIMODE1,"Button",BS_AUTORADIOBUTTON,12,36,306,10
DEFPUSHBUTTON "OK",IDOK,222,136,50,14
PUSHBUTTON "Cancel",IDCANCEL,276,136,50,14
GROUPBOX "Infrastructure settings",IDC_STATIC,6,76,319,54
LTEXT "Bridge network adapter:",IDC_STATIC,12,94,306,8
COMBOBOX IDC_BRIDGEADAPTER,12,106,306,45,CBS_DROPDOWNLIST | CBS_HASSTRINGS
GROUPBOX "Wifi mode",IDC_STATIC,6,22,318,48
CONTROL "Ad-hoc",IDC_WIFIMODE0,"Button",BS_AUTORADIOBUTTON,12,40,306,10
CONTROL "Infrastructure",IDC_WIFIMODE1,"Button",BS_AUTORADIOBUTTON,12,52,306,10
CONTROL "Enable WiFi Emulation",IDC_WIFI_ENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,6,150,10
CONTROL "Compatibility Mode",IDC_WIFI_COMPAT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,170,6,150,10
END

IDD_INPUTCONFIG DIALOGEX 0, 0, 339, 148
Expand Down Expand Up @@ -1915,7 +1917,7 @@ BEGIN

IDD_WIFISETTINGS, DIALOG
BEGIN
BOTTOMMARGIN, 140
BOTTOMMARGIN, 156
END

IDD_INPUTCONFIG, DIALOG
Expand Down

0 comments on commit 07d7588

Please sign in to comment.