From 09a545902dbbf3feb10f1e99275383213027d56f Mon Sep 17 00:00:00 2001 From: retr0s4ge Date: Sat, 28 Jul 2018 05:40:44 +0200 Subject: [PATCH 1/3] Don't emulate wifi unless wifi.emulated flag is set in common settings. Changes: 1- Add wifi.emulated flag to common settings 2- Don't emulate wifi unless wifi.emulated is set 3- Add a check box in windows frontend to toggle it, and read/write setting from/to ini file. --- desmume/src/NDSSystem.cpp | 20 ++++++++++++++------ desmume/src/NDSSystem.h | 2 ++ desmume/src/frontend/windows/main.cpp | 6 ++++++ desmume/src/frontend/windows/resource.h | 3 ++- desmume/src/frontend/windows/resources.rc | 21 +++++++++++---------- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 422e05591..a72192831 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -1334,8 +1334,13 @@ void Sequencer::init() #ifdef EXPERIMENTAL_WIFI_COMM - wifi.enabled = true; - wifi.timestamp = kWifiCycles; + if(CommonSettings.wifi.emulated) + { + wifi.enabled = true; + wifi.timestamp = kWifiCycles; + } + else + wifi.enabled = false; #else wifi.enabled = false; #endif @@ -1665,7 +1670,7 @@ u64 Sequencer::findNext() if(readslot1.isEnabled()) next = _fast_min(next,readslot1.next()); #ifdef EXPERIMENTAL_WIFI_COMM - next = _fast_min(next,wifi.next()); + if (CommonSettings.wifi.emulated) next = _fast_min(next,wifi.next()); #endif #define test(X,Y) if(dma_##X##_##Y .isEnabled()) next = _fast_min(next,dma_##X##_##Y .next()); @@ -1723,10 +1728,13 @@ void Sequencer::execHardware() } #ifdef EXPERIMENTAL_WIFI_COMM - if(wifi.isTriggered()) + if(CommonSettings.wifi.emulated) { - WIFI_usTrigger(); - wifi.timestamp += kWifiCycles; + if(wifi.isTriggered()) + { + WIFI_usTrigger(); + wifi.timestamp += kWifiCycles; + } } #endif diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 88c6e195d..a0cea5f8c 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -565,6 +565,7 @@ extern struct TCommonSettings strcpy(ARM7BIOS, "biosnds7.bin"); strcpy(Firmware, "firmware.bin"); + wifi.emulated = false; /* WIFI mode: adhoc = 0, infrastructure = 1 */ wifi.mode = 1; wifi.infraBridgeAdapter = 0; @@ -648,6 +649,7 @@ extern struct TCommonSettings u32 jit_max_block_size; struct _Wifi { + bool emulated; int mode; int infraBridgeAdapter; } wifi; diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 5292aa40f..8eb1cf9a7 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -3328,6 +3328,7 @@ int _main() Piano.Enabled = (slot2_device_type == NDS_SLOT2_EASYPIANO)?true:false; Paddle.Enabled = (slot2_device_type == NDS_SLOT2_PADDLE)?true:false; + CommonSettings.wifi.emulated = GetPrivateProfileBool("Wifi", "Emulated", false, IniName); CommonSettings.wifi.mode = GetPrivateProfileInt("Wifi", "Mode", 0, IniName); CommonSettings.wifi.infraBridgeAdapter = GetPrivateProfileInt("Wifi", "BridgeAdapter", 0, IniName); @@ -7066,6 +7067,8 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM int i; HWND cur; + CheckDlgItem(hDlg, IDC_WIFI_EMULATED, CommonSettings.wifi.emulated); + if (bSocketsAvailable && bWinPCapAvailable) CheckRadioButton(hDlg, IDC_WIFIMODE0, IDC_WIFIMODE1, IDC_WIFIMODE0 + CommonSettings.wifi.mode); else if(bSocketsAvailable) @@ -7119,6 +7122,9 @@ 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)); + CommonSettings.wifi.emulated = IsDlgCheckboxChecked(hDlg, IDC_WIFI_EMULATED); + WritePrivateProfileBool("Wifi", "Emulated", CommonSettings.wifi.emulated, IniName); + if (IsDlgButtonChecked(hDlg, IDC_WIFIMODE0)) CommonSettings.wifi.mode = 0; else diff --git a/desmume/src/frontend/windows/resource.h b/desmume/src/frontend/windows/resource.h index b4d6d7997..abcbd5656 100644 --- a/desmume/src/frontend/windows/resource.h +++ b/desmume/src/frontend/windows/resource.h @@ -466,6 +466,7 @@ #define IDC_EVALUE 1065 #define IDC_TEX_DEPOSTERIZE2 1065 #define IDC_TEX_SMOOTH 1065 +#define IDC_WIFI_EMULATED 1065 #define IDC_STATIC_RANGE 1066 #define IDC_TEXSCALE_1 1066 #define IDC_TEXSCALE_2 1067 @@ -1080,7 +1081,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 diff --git a/desmume/src/frontend/windows/resources.rc b/desmume/src/frontend/windows/resources.rc index 32227d745..884c03f76 100644 --- a/desmume/src/frontend/windows/resources.rc +++ b/desmume/src/frontend/windows/resources.rc @@ -1236,19 +1236,20 @@ 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_EMULATED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,6,319,10 END IDD_INPUTCONFIG DIALOGEX 0, 0, 339, 148 @@ -1915,7 +1916,7 @@ BEGIN IDD_WIFISETTINGS, DIALOG BEGIN - BOTTOMMARGIN, 140 + BOTTOMMARGIN, 156 END IDD_INPUTCONFIG, DIALOG From 259ca8579fecdd6bf6d8908e2342fefad2463c57 Mon Sep 17 00:00:00 2001 From: retr0s4ge Date: Mon, 30 Jul 2018 00:17:44 +0200 Subject: [PATCH 2/3] Implement basic support for multiple WiFi emulation levels --- desmume/src/NDSSystem.cpp | 8 +++-- desmume/src/NDSSystem.h | 13 ++++++-- desmume/src/frontend/windows/main.cpp | 36 ++++++++++++++++++++--- desmume/src/frontend/windows/resource.h | 3 +- desmume/src/frontend/windows/resources.rc | 3 +- 5 files changed, 51 insertions(+), 12 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index a72192831..fbb156fcf 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -102,6 +102,8 @@ int TotalLagFrames; TSCalInfo TSCal; +WifiEmulationLevel wifiEmulationLevel; + namespace DLDI { bool tryPatch(void* data, size_t size, unsigned int device); @@ -1334,7 +1336,7 @@ void Sequencer::init() #ifdef EXPERIMENTAL_WIFI_COMM - if(CommonSettings.wifi.emulated) + if(wifiEmulationLevel > WifiEmulationLevel::Off) { wifi.enabled = true; wifi.timestamp = kWifiCycles; @@ -1670,7 +1672,7 @@ u64 Sequencer::findNext() if(readslot1.isEnabled()) next = _fast_min(next,readslot1.next()); #ifdef EXPERIMENTAL_WIFI_COMM - if (CommonSettings.wifi.emulated) 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()); @@ -1728,7 +1730,7 @@ void Sequencer::execHardware() } #ifdef EXPERIMENTAL_WIFI_COMM - if(CommonSettings.wifi.emulated) + if(wifiEmulationLevel > WifiEmulationLevel::Off) { if(wifi.isTriggered()) { diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index a0cea5f8c..0b140b007 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -217,6 +217,14 @@ enum NDS_CONSOLE_TYPE NDS_CONSOLE_TYPE_DSI = 0xFE }; +enum class WifiEmulationLevel +{ + Off = 0, + Normal = 10000, + Compatibility = 65535, +}; +extern WifiEmulationLevel wifiEmulationLevel; + struct NDSSystem { s32 wifiCycle; @@ -565,7 +573,6 @@ extern struct TCommonSettings strcpy(ARM7BIOS, "biosnds7.bin"); strcpy(Firmware, "firmware.bin"); - wifi.emulated = false; /* WIFI mode: adhoc = 0, infrastructure = 1 */ wifi.mode = 1; wifi.infraBridgeAdapter = 0; @@ -649,7 +656,6 @@ extern struct TCommonSettings u32 jit_max_block_size; struct _Wifi { - bool emulated; int mode; int infraBridgeAdapter; } wifi; @@ -703,7 +709,8 @@ extern struct TCommonSettings std::string run_advanscene_import; -} CommonSettings; +}; +extern TCommonSettings CommonSettings; void NDS_RunAdvansceneAutoImport(); diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 8eb1cf9a7..a8ce3273c 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -3328,7 +3328,16 @@ int _main() Piano.Enabled = (slot2_device_type == NDS_SLOT2_EASYPIANO)?true:false; Paddle.Enabled = (slot2_device_type == NDS_SLOT2_PADDLE)?true:false; - CommonSettings.wifi.emulated = GetPrivateProfileBool("Wifi", "Emulated", false, IniName); + 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); @@ -7067,7 +7076,16 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM int i; HWND cur; - CheckDlgItem(hDlg, IDC_WIFI_EMULATED, CommonSettings.wifi.emulated); + 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); @@ -7122,8 +7140,18 @@ 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)); - CommonSettings.wifi.emulated = IsDlgCheckboxChecked(hDlg, IDC_WIFI_EMULATED); - WritePrivateProfileBool("Wifi", "Emulated", CommonSettings.wifi.emulated, IniName); + 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; diff --git a/desmume/src/frontend/windows/resource.h b/desmume/src/frontend/windows/resource.h index abcbd5656..f2ba95b63 100644 --- a/desmume/src/frontend/windows/resource.h +++ b/desmume/src/frontend/windows/resource.h @@ -466,9 +466,10 @@ #define IDC_EVALUE 1065 #define IDC_TEX_DEPOSTERIZE2 1065 #define IDC_TEX_SMOOTH 1065 -#define IDC_WIFI_EMULATED 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 diff --git a/desmume/src/frontend/windows/resources.rc b/desmume/src/frontend/windows/resources.rc index 884c03f76..7e366a437 100644 --- a/desmume/src/frontend/windows/resources.rc +++ b/desmume/src/frontend/windows/resources.rc @@ -1249,7 +1249,8 @@ BEGIN 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_EMULATED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,6,6,319,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 From cf5ed05cabcdb57dde5831e1ff12841fc92cac44 Mon Sep 17 00:00:00 2001 From: retr0s4ge Date: Mon, 30 Jul 2018 06:26:49 +0200 Subject: [PATCH 3/3] Replace scoped enum used for WifiEmulationLevel with unscoped enum for code compatibility with older compilers. --- desmume/src/NDSSystem.cpp | 6 +++--- desmume/src/NDSSystem.h | 8 ++++---- desmume/src/frontend/windows/main.cpp | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index fbb156fcf..d8c57f72f 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -1336,7 +1336,7 @@ void Sequencer::init() #ifdef EXPERIMENTAL_WIFI_COMM - if(wifiEmulationLevel > WifiEmulationLevel::Off) + if(wifiEmulationLevel > WifiEmulationLevel_Off) { wifi.enabled = true; wifi.timestamp = kWifiCycles; @@ -1672,7 +1672,7 @@ u64 Sequencer::findNext() if(readslot1.isEnabled()) next = _fast_min(next,readslot1.next()); #ifdef EXPERIMENTAL_WIFI_COMM - if (wifiEmulationLevel > WifiEmulationLevel::Off) 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()); @@ -1730,7 +1730,7 @@ void Sequencer::execHardware() } #ifdef EXPERIMENTAL_WIFI_COMM - if(wifiEmulationLevel > WifiEmulationLevel::Off) + if(wifiEmulationLevel > WifiEmulationLevel_Off) { if(wifi.isTriggered()) { diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 0b140b007..4f653dc57 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -217,11 +217,11 @@ enum NDS_CONSOLE_TYPE NDS_CONSOLE_TYPE_DSI = 0xFE }; -enum class WifiEmulationLevel +enum WifiEmulationLevel { - Off = 0, - Normal = 10000, - Compatibility = 65535, + WifiEmulationLevel_Off = 0, + WifiEmulationLevel_Normal = 10000, + WifiEmulationLevel_Compatibility = 65535, }; extern WifiEmulationLevel wifiEmulationLevel; diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index a8ce3273c..efcad8a1b 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -3331,12 +3331,12 @@ int _main() if (GetPrivateProfileBool("Wifi", "Enabled", false, IniName)) { if (GetPrivateProfileBool("Wifi", "Compatibility Mode", false, IniName)) - wifiEmulationLevel = WifiEmulationLevel::Compatibility; + wifiEmulationLevel = WifiEmulationLevel_Compatibility; else - wifiEmulationLevel = WifiEmulationLevel::Normal; + wifiEmulationLevel = WifiEmulationLevel_Normal; } else - wifiEmulationLevel = WifiEmulationLevel::Off; + wifiEmulationLevel = WifiEmulationLevel_Off; CommonSettings.wifi.mode = GetPrivateProfileInt("Wifi", "Mode", 0, IniName); CommonSettings.wifi.infraBridgeAdapter = GetPrivateProfileInt("Wifi", "BridgeAdapter", 0, IniName); @@ -7076,10 +7076,10 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM int i; HWND cur; - if (wifiEmulationLevel > WifiEmulationLevel::Off) + if (wifiEmulationLevel > WifiEmulationLevel_Off) { CheckDlgItem(hDlg, IDC_WIFI_ENABLED, true); - CheckDlgItem(hDlg, IDC_WIFI_COMPAT, wifiEmulationLevel == WifiEmulationLevel::Compatibility); + CheckDlgItem(hDlg, IDC_WIFI_COMPAT, wifiEmulationLevel == WifiEmulationLevel_Compatibility); } else { @@ -7143,12 +7143,12 @@ LRESULT CALLBACK WifiSettingsDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM if (IsDlgCheckboxChecked(hDlg, IDC_WIFI_ENABLED)) { if (IsDlgCheckboxChecked(hDlg, IDC_WIFI_COMPAT)) - wifiEmulationLevel = WifiEmulationLevel::Compatibility; + wifiEmulationLevel = WifiEmulationLevel_Compatibility; else - wifiEmulationLevel = WifiEmulationLevel::Normal; + wifiEmulationLevel = WifiEmulationLevel_Normal; } else - wifiEmulationLevel = WifiEmulationLevel::Off; + wifiEmulationLevel = WifiEmulationLevel_Off; WritePrivateProfileBool("Wifi", "Enabled", IsDlgCheckboxChecked(hDlg, IDC_WIFI_ENABLED), IniName); WritePrivateProfileBool("Wifi", "Compatibility Mode", IsDlgCheckboxChecked(hDlg, IDC_WIFI_COMPAT), IniName);