From 259ca8579fecdd6bf6d8908e2342fefad2463c57 Mon Sep 17 00:00:00 2001 From: retr0s4ge Date: Mon, 30 Jul 2018 00:17:44 +0200 Subject: [PATCH] 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