From 1ce2cb86f5592cf9d44d34615eee341d60d0e509 Mon Sep 17 00:00:00 2001 From: zeromus Date: Sun, 31 May 2009 23:53:38 +0000 Subject: [PATCH] fix bugs in wifi no-winpcap handling. make vs2008 debug build able to load savestates. add some notes for luigi with "luigi:" --- desmume/src/NDSSystem.cpp | 12 +++------ desmume/src/wifi.cpp | 36 +++++++++++++++---------- desmume/src/windows/DeSmuME_2008.vcproj | 6 ++--- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index f2295d3ed..91ff8ea23 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -520,8 +520,7 @@ int NDS_Init( void) { #ifdef EXPERIMENTAL_WIFI WIFI_Init(&wifiMac) ; - if(wifiMac.netEnabled) - WIFI_SoftAP_Init(&wifiMac); + WIFI_SoftAP_Init(&wifiMac); #endif nds.FW_ARM9BootCode = NULL; @@ -541,8 +540,7 @@ void NDS_DeInit(void) { gpu3D->NDS_3D_Close(); #ifdef EXPERIMENTAL_WIFI - if(wifiMac.netEnabled) - WIFI_SoftAP_Shutdown(&wifiMac); + WIFI_SoftAP_Shutdown(&wifiMac); #endif } @@ -1079,10 +1077,8 @@ void NDS_Reset(BOOL resetBySavestate) #ifdef EXPERIMENTAL_WIFI WIFI_Init(&wifiMac); - if(wifiMac.netEnabled) { - WIFI_SoftAP_Shutdown(&wifiMac); - WIFI_SoftAP_Init(&wifiMac); - } + WIFI_SoftAP_Shutdown(&wifiMac); + WIFI_SoftAP_Init(&wifiMac); #endif memcpy(FW_Mac, (MMU.fw.data + 0x36), 6); diff --git a/desmume/src/wifi.cpp b/desmume/src/wifi.cpp index 29ac2d85a..6a5b65e5a 100644 --- a/desmume/src/wifi.cpp +++ b/desmume/src/wifi.cpp @@ -483,9 +483,10 @@ static void WIFI_TXStart(wifimac_t *wifi,u8 slot) { u16 txLen ; /* the address has to be somewhere in the circular buffer, so drop the other bits */ - u16 address = (wifi->TXSlot[slot] & 0x7FFF) ; + u16 address = (wifi->TXSlot[slot] & 0x7FFF) ; //luigi: shouldnt this be 0xFFF (see W_TXBUF_LOC3 in gbatek) /* is there even enough space for the header (6 hwords) in the tx buffer? */ - if (address > 0x1000-6) return ; + if (address > 0x1000-6) return ; //luigi: you shouldnt do this. put assertions or LOG() calls in spots like this. + //when an emulation is in the state that wifi is at, silently swallowing errors will make it hard to debug /* 12 byte header TX Header: http://www.akkit.org/info/dswifi.htm#FmtTx */ txLen = /*ntohs*/(wifi->circularBuffer[address+5]) ; @@ -1155,28 +1156,34 @@ int WIFI_SoftAP_Init(wifimac_t *wifi) SoftAP_CRC32Table[i] = reflect(SoftAP_CRC32Table[i], 32); } - if(PCAP::pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1) + if(wifiMac.netEnabled) { - printf("SoftAP: PCAP error with pcap_findalldevs_ex(): %s\n", errbuf); - return 0; - } + if(PCAP::pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1) + { + printf("SoftAP: PCAP error with pcap_findalldevs_ex(): %s\n", errbuf); + return 0; + } - wifi->SoftAP.bridge = PCAP::pcap_open(WIFI_index_device(alldevs,CommonSettings.wifiBridgeAdapterNum)->name, PACKET_SIZE, 0, 1, NULL, errbuf); - if(wifi->SoftAP.bridge == NULL) - { - printf("SoftAP: PCAP error with pcap_open(): %s\n", errbuf); - return 0; - } + wifi->SoftAP.bridge = PCAP::pcap_open(WIFI_index_device(alldevs,CommonSettings.wifiBridgeAdapterNum)->name, PACKET_SIZE, 0, 1, NULL, errbuf); + if(wifi->SoftAP.bridge == NULL) + { + printf("SoftAP: PCAP error with pcap_open(): %s\n", errbuf); + return 0; + } - PCAP::pcap_freealldevs(alldevs); + PCAP::pcap_freealldevs(alldevs); + } return 1; } void WIFI_SoftAP_Shutdown(wifimac_t *wifi) { + if(wifiMac.netEnabled) + { if(wifi->SoftAP.bridge != NULL) PCAP::pcap_close(wifi->SoftAP.bridge); + } } void WIFI_SoftAP_RecvPacketFromDS(wifimac_t *wifi, u8 *packet, int len) @@ -1334,7 +1341,8 @@ void WIFI_SoftAP_RecvPacketFromDS(wifimac_t *wifi, u8 *packet, int len) /* Checksum */ /* TODO ? */ - PCAP::pcap_sendpacket(wifi->SoftAP.bridge, ethernetframe, eflen); + if(wifi->netEnabled) //dont try to pcap out the packet unless network is enabled + PCAP::pcap_sendpacket(wifi->SoftAP.bridge, ethernetframe, eflen); delete ethernetframe; } diff --git a/desmume/src/windows/DeSmuME_2008.vcproj b/desmume/src/windows/DeSmuME_2008.vcproj index cb485b316..b75e85ade 100644 --- a/desmume/src/windows/DeSmuME_2008.vcproj +++ b/desmume/src/windows/DeSmuME_2008.vcproj @@ -52,10 +52,10 @@ EnableFiberSafeOptimizations="false" WholeProgramOptimization="false" AdditionalIncludeDirectories=".;..;"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig" - PreprocessorDefinitions="DEBUG;_CRT_SECURE_NO_DEPRECATE;WIN32;BETA_VERSION;SPU_INTERPOLATE;NOMINMAX;EXPERIMENTAL_WIFI;HAVE_LIBZZIP" + PreprocessorDefinitions="DEBUG;_CRT_SECURE_NO_DEPRECATE;WIN32;BETA_VERSION;SPU_INTERPOLATE;NOMINMAX;EXPERIMENTAL_WIFI;HAVE_LIBZ;HAVE_LIBZZIP" ExceptionHandling="1" - BasicRuntimeChecks="0" - BufferSecurityCheck="false" + BasicRuntimeChecks="3" + BufferSecurityCheck="true" EnableEnhancedInstructionSet="2" FloatingPointModel="2" DebugInformationFormat="4"