diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index f6f8ae716..06210096c 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -47,6 +47,8 @@ //#define USE_REAL_BIOS TCommonSettings CommonSettings; +static Driver _stub_driver; +Driver* driver = &_stub_driver; static BOOL LidClosed = FALSE; static u8 countLid = 0; @@ -509,7 +511,8 @@ int NDS_Init( void) { #ifdef EXPERIMENTAL_WIFI WIFI_Init(&wifiMac) ; - WIFI_SoftAP_Init(&wifiMac); + if(wifiMac.netEnabled) + WIFI_SoftAP_Init(&wifiMac); #endif nds.FW_ARM9BootCode = NULL; @@ -529,7 +532,8 @@ void NDS_DeInit(void) { gpu3D->NDS_3D_Close(); #ifdef EXPERIMENTAL_WIFI - WIFI_SoftAP_Shutdown(&wifiMac); + if(wifiMac.netEnabled) + WIFI_SoftAP_Shutdown(&wifiMac); #endif } @@ -1023,8 +1027,10 @@ void NDS_Reset( void) #ifdef EXPERIMENTAL_WIFI WIFI_Init(&wifiMac); - WIFI_SoftAP_Shutdown(&wifiMac); - WIFI_SoftAP_Init(&wifiMac); + if(wifiMac.netEnabled) { + WIFI_SoftAP_Shutdown(&wifiMac); + WIFI_SoftAP_Init(&wifiMac); + } #endif memcpy(FW_Mac, (MMU.fw.data + 0x36), 6); diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index c247eb2c7..fccb4cc07 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -317,6 +317,15 @@ extern struct TCommonSettings { extern char ROMserial[20]; +//this should be moved to a driver.h later, but for now, here they are. +//each platform needs to implement this, although it doesnt need to implement any functions +class Driver { +public: + virtual BOOL WIFI_Host_InitSystem() { return FALSE; } + virtual void WIFI_Host_ShutdownSystem() {} +}; +extern Driver* driver; + #endif diff --git a/desmume/src/wifi.cpp b/desmume/src/wifi.cpp index 9d585df50..23fa458ce 100644 --- a/desmume/src/wifi.cpp +++ b/desmume/src/wifi.cpp @@ -18,6 +18,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include #include "wifi.h" #include "armcpu.h" #include "NDSSystem.h" @@ -427,8 +428,12 @@ static void WIFI_triggerIRQ(wifimac_t *wifi, u8 irq) void WIFI_Init(wifimac_t *wifi) { WIFI_resetRF(&wifi->RF) ; - WIFI_Host_InitSystem() ; - wifi->udpSocket = WIFI_Host_OpenChannel(1) ; + wifi->netEnabled = false; + if(driver->WIFI_Host_InitSystem()) + { + wifi->netEnabled = true; + wifi->udpSocket = WIFI_Host_OpenChannel(1) ; + } wifi->powerOn = FALSE; wifi->powerOnPending = FALSE; } @@ -922,7 +927,8 @@ u16 WIFI_read16(wifimac_t *wifi,u32 address) //printf("wifi: read reg 0x0214\n"); return 0x0009; case 0x19C: - break; + assert(false); //luigi, please pick something to return from here + return 0; default: // printf("wifi: read unhandled reg %03X\n", address); return wifi->ioMem[address >> 1]; @@ -1502,24 +1508,4 @@ u16 WIFI_Host_RecvData(socket_t sock, u8 *data, u16 maxLength) return 0 ; } -BOOL WIFI_Host_InitSystem(void) -{ - #ifdef WIN32 - WSADATA wsaData ; - WORD version = MAKEWORD(1,1) ; - if (WSAStartup(version,&wsaData)) - { - return FALSE ; - } - #endif - return TRUE ; -} - -void WIFI_Host_ShutdownSystem(void) -{ - #ifdef WIN32 - WSACleanup() ; - #endif -} - #endif diff --git a/desmume/src/wifi.h b/desmume/src/wifi.h index f75f1347b..f228c5942 100644 --- a/desmume/src/wifi.h +++ b/desmume/src/wifi.h @@ -494,6 +494,7 @@ typedef struct } SoftAP; /* desmume host communication */ + bool netEnabled; socket_t udpSocket ; u8 channel ; diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/desmume/src/windows/DeSmuME_2005.vcproj index 4f5fad8f8..182e2f03a 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/desmume/src/windows/DeSmuME_2005.vcproj @@ -76,6 +76,7 @@ AdditionalDependencies="gdiplus\gdiplus.lib vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib winpcap\wpcap.lib" OutputFile="$(OutDir)\$(ProjectName)_debug.exe" AdditionalLibraryDirectories=".\zlib123;.\zziplib" + DelayLoadDLLs="wpcap.dll" GenerateDebugInformation="true" GenerateMapFile="true" /> @@ -165,6 +166,7 @@ AdditionalDependencies="gdiplus\gdiplus.lib vfw32.lib winmm.lib opengl32.lib glu32.lib ws2_32.lib user32.lib gdi32.lib directx\dxguid.lib shell32.lib comdlg32.lib directx\dxerr8.lib directx\dsound.lib directx\dinput8.lib directx\ddraw.lib zlib-2005-x32.lib zziplib-2005-x32.lib shlwapi.lib" OutputFile="$(OutDir)\$(ProjectName).exe" AdditionalLibraryDirectories=".\zlib123;.\zziplib" + DelayLoadDLLs="wpcap.dll" GenerateDebugInformation="true" /> @@ -27,54 +27,54 @@ #include #include -enum HotkeyPage { - HOTKEY_PAGE_MAIN=0, - HOTKEY_PAGE_STATE, - HOTKEY_PAGE_STATE_SLOTS, - NUM_HOTKEY_PAGE, -}; - -static LPCTSTR hotkeyPageTitle[] = { - _T("Main"), - _T("Savestates"), - _T("Savestate Slots"), - _T("NUM_HOTKEY_PAGE"), -}; +enum HotkeyPage { + HOTKEY_PAGE_MAIN=0, + HOTKEY_PAGE_STATE, + HOTKEY_PAGE_STATE_SLOTS, + NUM_HOTKEY_PAGE, +}; - -struct SCustomKey -{ - typedef void (*THandler) (int param); - WORD key; - WORD modifiers; - THandler handleKeyDown; - THandler handleKeyUp; - HotkeyPage page; - std::wstring name; - const char* code; - int param; - //HotkeyTiming timing; -}; - -struct SCustomKeys -{ - SCustomKey Save[10]; - SCustomKey Load[10]; - SCustomKey Slot[10]; - SCustomKey QuickSave, QuickLoad; - - SCustomKey Pause, FrameAdvance; - - SCustomKey ToggleRasterizer; - - SCustomKey PrintScreen; - SCustomKey LastItem; // dummy, must be last - - //--methods-- - SCustomKey &key(int i) { return ((SCustomKey*)this)[i]; } - SCustomKey const &key(int i) const { return ((SCustomKey*)this)[i]; } -}; -//SCustomKey key[]; +static LPCTSTR hotkeyPageTitle[] = { + _T("Main"), + _T("Savestates"), + _T("Savestate Slots"), + _T("NUM_HOTKEY_PAGE"), +}; + + +struct SCustomKey +{ + typedef void (*THandler) (int param); + WORD key; + WORD modifiers; + THandler handleKeyDown; + THandler handleKeyUp; + HotkeyPage page; + std::wstring name; + const char* code; + int param; + //HotkeyTiming timing; +}; + +struct SCustomKeys +{ + SCustomKey Save[10]; + SCustomKey Load[10]; + SCustomKey Slot[10]; + SCustomKey QuickSave, QuickLoad; + + SCustomKey Pause, FrameAdvance; + + SCustomKey ToggleRasterizer; + + SCustomKey PrintScreen; + SCustomKey LastItem; // dummy, must be last + + //--methods-- + SCustomKey &key(int i) { return ((SCustomKey*)this)[i]; } + SCustomKey const &key(int i) const { return ((SCustomKey*)this)[i]; } +}; +//SCustomKey key[]; extern SCustomKeys CustomKeys; @@ -89,166 +89,166 @@ void HK_StateSaveSlot(int); void HK_StateLoadSlot(int); void HK_StateSetSlot(int); void HK_Pause(int); - + #endif //HOTKEY_H_INCLUDED -/********************************************************************************** - Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. - - (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), - Jerremy Koot (jkoot@snes9x.com) - - (c) Copyright 2002 - 2004 Matthew Kendora - - (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) - - (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) - - (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) - - (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), - Kris Bleakley (codeviolation@hotmail.com) - - (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), - Nach (n-a-c-h@users.sourceforge.net), - zones (kasumitokoduck@yahoo.com) - - (c) Copyright 2006 - 2007 nitsuja - - - BS-X C emulator code - (c) Copyright 2005 - 2006 Dreamer Nom, - zones - - C4 x86 assembler and some C emulation code - (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), - Nach, - zsKnight (zsknight@zsnes.com) - - C4 C++ code - (c) Copyright 2003 - 2006 Brad Jorsch, - Nach - - DSP-1 emulator code - (c) Copyright 1998 - 2006 _Demo_, - Andreas Naive (andreasnaive@gmail.com) - Gary Henderson, - Ivar (ivar@snes9x.com), - John Weidman, - Kris Bleakley, - Matthew Kendora, - Nach, - neviksti (neviksti@hotmail.com) - - DSP-2 emulator code - (c) Copyright 2003 John Weidman, - Kris Bleakley, - Lord Nightmare (lord_nightmare@users.sourceforge.net), - Matthew Kendora, - neviksti - - - DSP-3 emulator code - (c) Copyright 2003 - 2006 John Weidman, - Kris Bleakley, - Lancer, - z80 gaiden - - DSP-4 emulator code - (c) Copyright 2004 - 2006 Dreamer Nom, - John Weidman, - Kris Bleakley, - Nach, - z80 gaiden - - OBC1 emulator code - (c) Copyright 2001 - 2004 zsKnight, - pagefault (pagefault@zsnes.com), - Kris Bleakley, - Ported from x86 assembler to C by sanmaiwashi - - SPC7110 and RTC C++ emulator code - (c) Copyright 2002 Matthew Kendora with research by - zsKnight, - John Weidman, - Dark Force - - S-DD1 C emulator code - (c) Copyright 2003 Brad Jorsch with research by - Andreas Naive, - John Weidman - - S-RTC C emulator code - (c) Copyright 2001-2006 byuu, - John Weidman - - ST010 C++ emulator code - (c) Copyright 2003 Feather, - John Weidman, - Kris Bleakley, - Matthew Kendora - - Super FX x86 assembler emulator code - (c) Copyright 1998 - 2003 _Demo_, - pagefault, - zsKnight, - - Super FX C emulator code - (c) Copyright 1997 - 1999 Ivar, - Gary Henderson, - John Weidman - - Sound DSP emulator code is derived from SNEeSe and OpenSPC: - (c) Copyright 1998 - 2003 Brad Martin - (c) Copyright 1998 - 2006 Charles Bilyue' - - SH assembler code partly based on x86 assembler code - (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) - - 2xSaI filter - (c) Copyright 1999 - 2001 Derek Liauw Kie Fa - - HQ2x, HQ3x, HQ4x filters - (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) - - Win32 GUI code - (c) Copyright 2003 - 2006 blip, - funkyass, - Matthew Kendora, - Nach, - nitsuja - - Mac OS GUI code - (c) Copyright 1998 - 2001 John Stiles - (c) Copyright 2001 - 2007 zones - - - Specific ports contains the works of other authors. See headers in - individual files. - - - Snes9x homepage: http://www.snes9x.com - - Permission to use, copy, modify and/or distribute Snes9x in both binary - and source form, for non-commercial purposes, is hereby granted without - fee, providing that this license information and copyright notice appear - with all copies and any derived work. - - This software is provided 'as-is', without any express or implied - warranty. In no event shall the authors be held liable for any damages - arising from the use of this software or it's derivatives. - - Snes9x is freeware for PERSONAL USE only. Commercial users should - seek permission of the copyright holders first. Commercial use includes, - but is not limited to, charging money for Snes9x or software derived from - Snes9x, including Snes9x or derivatives in commercial game bundles, and/or - using Snes9x as a promotion for your commercial product. - - The copyright holders request that bug fixes and improvements to the code - should be forwarded to them so everyone can benefit from the modifications - in future versions. - - Super NES and Super Nintendo Entertainment System are trademarks of - Nintendo Co., Limited and its subsidiary companies. -**********************************************************************************/ - +/********************************************************************************** + Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. + + (c) Copyright 1996 - 2002 Gary Henderson (gary.henderson@ntlworld.com), + Jerremy Koot (jkoot@snes9x.com) + + (c) Copyright 2002 - 2004 Matthew Kendora + + (c) Copyright 2002 - 2005 Peter Bortas (peter@bortas.org) + + (c) Copyright 2004 - 2005 Joel Yliluoma (http://iki.fi/bisqwit/) + + (c) Copyright 2001 - 2006 John Weidman (jweidman@slip.net) + + (c) Copyright 2002 - 2006 funkyass (funkyass@spam.shaw.ca), + Kris Bleakley (codeviolation@hotmail.com) + + (c) Copyright 2002 - 2007 Brad Jorsch (anomie@users.sourceforge.net), + Nach (n-a-c-h@users.sourceforge.net), + zones (kasumitokoduck@yahoo.com) + + (c) Copyright 2006 - 2007 nitsuja + + + BS-X C emulator code + (c) Copyright 2005 - 2006 Dreamer Nom, + zones + + C4 x86 assembler and some C emulation code + (c) Copyright 2000 - 2003 _Demo_ (_demo_@zsnes.com), + Nach, + zsKnight (zsknight@zsnes.com) + + C4 C++ code + (c) Copyright 2003 - 2006 Brad Jorsch, + Nach + + DSP-1 emulator code + (c) Copyright 1998 - 2006 _Demo_, + Andreas Naive (andreasnaive@gmail.com) + Gary Henderson, + Ivar (ivar@snes9x.com), + John Weidman, + Kris Bleakley, + Matthew Kendora, + Nach, + neviksti (neviksti@hotmail.com) + + DSP-2 emulator code + (c) Copyright 2003 John Weidman, + Kris Bleakley, + Lord Nightmare (lord_nightmare@users.sourceforge.net), + Matthew Kendora, + neviksti + + + DSP-3 emulator code + (c) Copyright 2003 - 2006 John Weidman, + Kris Bleakley, + Lancer, + z80 gaiden + + DSP-4 emulator code + (c) Copyright 2004 - 2006 Dreamer Nom, + John Weidman, + Kris Bleakley, + Nach, + z80 gaiden + + OBC1 emulator code + (c) Copyright 2001 - 2004 zsKnight, + pagefault (pagefault@zsnes.com), + Kris Bleakley, + Ported from x86 assembler to C by sanmaiwashi + + SPC7110 and RTC C++ emulator code + (c) Copyright 2002 Matthew Kendora with research by + zsKnight, + John Weidman, + Dark Force + + S-DD1 C emulator code + (c) Copyright 2003 Brad Jorsch with research by + Andreas Naive, + John Weidman + + S-RTC C emulator code + (c) Copyright 2001-2006 byuu, + John Weidman + + ST010 C++ emulator code + (c) Copyright 2003 Feather, + John Weidman, + Kris Bleakley, + Matthew Kendora + + Super FX x86 assembler emulator code + (c) Copyright 1998 - 2003 _Demo_, + pagefault, + zsKnight, + + Super FX C emulator code + (c) Copyright 1997 - 1999 Ivar, + Gary Henderson, + John Weidman + + Sound DSP emulator code is derived from SNEeSe and OpenSPC: + (c) Copyright 1998 - 2003 Brad Martin + (c) Copyright 1998 - 2006 Charles Bilyue' + + SH assembler code partly based on x86 assembler code + (c) Copyright 2002 - 2004 Marcus Comstedt (marcus@mc.pp.se) + + 2xSaI filter + (c) Copyright 1999 - 2001 Derek Liauw Kie Fa + + HQ2x, HQ3x, HQ4x filters + (c) Copyright 2003 Maxim Stepin (maxim@hiend3d.com) + + Win32 GUI code + (c) Copyright 2003 - 2006 blip, + funkyass, + Matthew Kendora, + Nach, + nitsuja + + Mac OS GUI code + (c) Copyright 1998 - 2001 John Stiles + (c) Copyright 2001 - 2007 zones + + + Specific ports contains the works of other authors. See headers in + individual files. + + + Snes9x homepage: http://www.snes9x.com + + Permission to use, copy, modify and/or distribute Snes9x in both binary + and source form, for non-commercial purposes, is hereby granted without + fee, providing that this license information and copyright notice appear + with all copies and any derived work. + + This software is provided 'as-is', without any express or implied + warranty. In no event shall the authors be held liable for any damages + arising from the use of this software or it's derivatives. + + Snes9x is freeware for PERSONAL USE only. Commercial users should + seek permission of the copyright holders first. Commercial use includes, + but is not limited to, charging money for Snes9x or software derived from + Snes9x, including Snes9x or derivatives in commercial game bundles, and/or + using Snes9x as a promotion for your commercial product. + + The copyright holders request that bug fixes and improvements to the code + should be forwarded to them so everyone can benefit from the modifications + in future versions. + + Super NES and Super Nintendo Entertainment System are trademarks of + Nintendo Co., Limited and its subsidiary companies. +**********************************************************************************/ + diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 98fd91516..f2552e384 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -1204,12 +1204,45 @@ static void ExitRunLoop() emu_halt(); } +class WinDriver : public Driver +{ + virtual BOOL WIFI_Host_InitSystem() { + #ifdef EXPERIMENTAL_WIFI + //require winsock initialization + WSADATA wsaData ; + WORD version = MAKEWORD(1,1) ; + if (WSAStartup(version,&wsaData)) + { + printf("Failed initializing WSAStartup - softAP support disabled\n"); + return FALSE ; + } + //require winpcap.dll + HMODULE temp = LoadLibrary("winpcap.dll"); + if(temp == NULL) { + printf("Failed initializing winpcap.dll - softAP support disabled\n"); + return FALSE; + } + FreeLibrary(temp); + return TRUE; + #else + return FALSE ; + #endif + } + virtual void WIFI_Host_ShutdownSystem() { + #ifdef EXPERIMENTAL_WIFI + WSACleanup() ; + #endif + } +}; + int WINAPI WinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPSTR lpszArgument, int nFunsterStil) { + driver = new WinDriver(); + ULONG_PTR GdiplusToken; GdiplusStartupInput GdiplusSI;