From c6a8854e927a9f4d186652a1977a8b5602a3a1ff Mon Sep 17 00:00:00 2001 From: zeromus Date: Mon, 27 Jul 2009 10:39:56 +0000 Subject: [PATCH] integrate desync fixes from 094 branch. many extra files touched due to svn merge info tracking being poopy --- desmume/src/FIFO.cpp | 2 + desmume/src/GPU.cpp | 5 +- desmume/src/GPU_osd.cpp | 1 + desmume/src/MMU.cpp | 2 +- desmume/src/MMU.h | 3 +- desmume/src/NDSSystem.cpp | 6 +- desmume/src/SPU.cpp | 18 ++- desmume/src/gfx3d.cpp | 3 +- desmume/src/mc.cpp | 7 +- desmume/src/rtc.cpp | 39 ++++++- desmume/src/saves.cpp | 143 ++++++++++++++++++++---- desmume/src/types.h | 1 + desmume/src/wifi.cpp | 56 +++++----- desmume/src/wifi.h | 37 +++--- desmume/src/windows/DeSmuME_2005.vcproj | 9 +- desmume/src/windows/main.cpp | 2 +- 16 files changed, 239 insertions(+), 95 deletions(-) diff --git a/desmume/src/FIFO.cpp b/desmume/src/FIFO.cpp index 1364c2588..632ae7068 100644 --- a/desmume/src/FIFO.cpp +++ b/desmume/src/FIFO.cpp @@ -243,7 +243,9 @@ BOOL FORCEINLINE GFX_FIFOrecv(u8 *cmd, u32 *param) if (gxFIFO.tail < 128) { gxstat |= 0x02000000; +#ifdef USE_GEOMETRY_FIFO_EMULATION execHardware_doAllDma(EDMAMode_GXFifo); +#endif } if (gxFIFO.tail == 0) // empty diff --git a/desmume/src/GPU.cpp b/desmume/src/GPU.cpp index 891d2fee5..79659e5f9 100644 --- a/desmume/src/GPU.cpp +++ b/desmume/src/GPU.cpp @@ -2933,8 +2933,9 @@ bool gpu_loadstate(std::istream* is, int size) read32le(&SubScreen.gpu->affineInfo[0].y,is); read32le(&SubScreen.gpu->affineInfo[1].x,is); read32le(&SubScreen.gpu->affineInfo[1].y,is); - MainScreen.gpu->refreshAffineStartRegs(-1,-1); - SubScreen.gpu->refreshAffineStartRegs(-1,-1); + //removed per nitsuja feedback. anyway, this same thing will happen almost immediately in gpu line=0 + //MainScreen.gpu->refreshAffineStartRegs(-1,-1); + //SubScreen.gpu->refreshAffineStartRegs(-1,-1); } MainScreen.gpu->updateBLDALPHA(); diff --git a/desmume/src/GPU_osd.cpp b/desmume/src/GPU_osd.cpp index 116d93e6d..08a7881d9 100644 --- a/desmume/src/GPU_osd.cpp +++ b/desmume/src/GPU_osd.cpp @@ -27,6 +27,7 @@ #include //mem funcs #include //va_start, etc #include +#include #include #include "debug.h" diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 9c7b99559..b2e3507f5 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -83,7 +83,7 @@ static u64 isqrt (u64 x) { return root; } -u16 partie = 1; +u32 partie = 1; u32 _MMU_MAIN_MEM_MASK = 0x3FFFFF; #define ROM_MASK 3 diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index d54297309..424fce1e0 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -125,7 +125,6 @@ struct MMU_struct { u8 powerMan_Reg[4]; memory_chip_t fw; - memory_chip_t bupmem; nds_dscard dscard[2]; u32 CheckTimers; @@ -289,6 +288,8 @@ u8 FASTCALL _MMU_ARM7_read08(u32 adr); u16 FASTCALL _MMU_ARM7_read16(u32 adr); u32 FASTCALL _MMU_ARM7_read32(u32 adr); +extern u32 partie; + extern u32 _MMU_MAIN_MEM_MASK; inline void SetupMMU(BOOL debugConsole) { if(debugConsole) _MMU_MAIN_MEM_MASK = 0x7FFFFF; diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index ce37b547a..0cc2ca19d 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -1,3 +1,4 @@ + /* Copyright (C) 2006 yopyop yopyop156@ifrance.com yopyop156.ifrance.com @@ -968,9 +969,6 @@ void NDS_FreeROM(void) if (MMU.CART_ROM != MMU.UNUSED_RAM) delete [] MMU.CART_ROM; MMU_unsetRom(); - if (MMU.bupmem.fp) - fclose(MMU.bupmem.fp); - MMU.bupmem.fp = NULL; } @@ -1494,7 +1492,9 @@ void NDS_SkipNextFrame() { SkipNext2DFrame = true; SkipCur3DFrame = true; } static void execHardware_doDma(int procnum, int chan, EDMAMode modeNum) { +#ifdef USE_GEOMETRY_FIFO_EMULATION if(MMU.DMAStartTime[procnum][chan] == modeNum) +#endif { if(procnum == ARMCPU_ARM9) MMU_doDMA(chan); else MMU_doDMA(chan); diff --git a/desmume/src/SPU.cpp b/desmume/src/SPU.cpp index 7333dbf77..5a744ade2 100644 --- a/desmume/src/SPU.cpp +++ b/desmume/src/SPU.cpp @@ -1242,7 +1242,7 @@ void WAV_WavSoundUpdate(void* soundData, int numSamples) void spu_savestate(std::ostream* os) { //version - write32le(0,os); + write32le(2,os); SPU_struct *spu = SPU_core; @@ -1270,14 +1270,17 @@ void spu_savestate(std::ostream* os) write16le(chan.x,os); write16le(chan.psgnoise_last,os); } + + write64le(double_to_u64(samples),os); } bool spu_loadstate(std::istream* is, int size) { + u64 temp64; + //read version int version; if(read32le(&version,is) != 1) return false; - SPU_struct *spu = SPU_core; @@ -1298,11 +1301,10 @@ bool spu_loadstate(std::istream* is, int size) read32le(&chan.length,is); chan.totlength = chan.length + chan.loopstart; chan.double_totlength_shifted = (double)(chan.totlength << format_shift[chan.format]); - if(version == 0) + if(version != 1) { - u64 temp; - read64le(&temp,is); chan.sampcnt = u64_to_double(temp); - read64le(&temp,is); chan.sampinc = u64_to_double(temp); + read64le(&temp64,is); chan.sampcnt = u64_to_double(temp64); + read64le(&temp64,is); chan.sampinc = u64_to_double(temp64); } else { @@ -1320,6 +1322,10 @@ bool spu_loadstate(std::istream* is, int size) chan.buf8 = (s8*)&MMU.MMU_MEM[1][(chan.addr>>20)&0xFF][(chan.addr & MMU.MMU_MASK[1][(chan.addr >> 20) & 0xFF])]; } + if(version==2) { + read64le(&temp64,is); samples = u64_to_double(temp64); + } + //copy the core spu (the more accurate) to the user spu if(SPU_user) { for(int i=0;i<16;i++) diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index 8d283a11d..87e754b10 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -337,6 +337,7 @@ void gfx3d_reset() { gfx3d = GFX3D(); + control = 0; drawPending = FALSE; flushPending = FALSE; memset(polylists, 0, sizeof(polylists)); @@ -2347,7 +2348,7 @@ void gfx3d_GetLineData(int line, u16** dst, u8** dstAlpha) //consider building a little state structure that looks exactly like this describes SFORMAT SF_GFX3D[]={ - { "GCTL", 4, 1, &control}, + //{ "GCTL", 4, 1, &control}, //this gets regenerated by the code i hate which regenerates gpu regs { "GPAT", 4, 1, &polyAttr}, { "GPAP", 4, 1, &polyAttrPending}, { "GINB", 4, 1, &inBegin}, diff --git a/desmume/src/mc.cpp b/desmume/src/mc.cpp index e267c43c4..f3ab326d6 100644 --- a/desmume/src/mc.cpp +++ b/desmume/src/mc.cpp @@ -228,7 +228,7 @@ u8 fw_transfer(memory_chip_t *mc, u8 data) bool BackupDevice::save_state(std::ostream* os) { - int version = 0; + int version = 1; write32le(version,os); write32le(write_enable,os); write32le(com,os); @@ -237,6 +237,7 @@ bool BackupDevice::save_state(std::ostream* os) write32le((u32)state,os); writebuffer(data,os); writebuffer(data_autodetect,os); + write32le(addr,os); return true; } @@ -244,7 +245,7 @@ bool BackupDevice::load_state(std::istream* is) { int version; if(read32le(&version,is)!=1) return false; - if(version==0) { + if(version==0 || version==1) { read32le(&write_enable,is); read32le(&com,is); read32le(&addr_size,is); @@ -254,6 +255,8 @@ bool BackupDevice::load_state(std::istream* is) state = (STATE)temp; readbuffer(data,is); readbuffer(data_autodetect,is); + if(version==1) + read32le(&addr,is); } return true; } diff --git a/desmume/src/rtc.cpp b/desmume/src/rtc.cpp index 2fbcf61b4..3dfd91907 100644 --- a/desmume/src/rtc.cpp +++ b/desmume/src/rtc.cpp @@ -30,6 +30,7 @@ #include "armcpu.h" #include #include +#include "saves.h" #ifdef WIN32 #include "windows/main.h" #endif @@ -58,11 +59,38 @@ typedef struct u8 cmdStat; u8 bitsCount; u8 data[8]; + + u8 cmdBitsSize[8]; } _RTC; _RTC rtc; -u8 cmdBitsSize[8] = {8, 8, 56, 24, 0, 24, 8, 8}; +SFORMAT SF_RTC[]={ + { "R000", 1, 1, &rtc.regStatus1}, + { "R010", 1, 1, &rtc.regStatus2}, + { "R020", 1, 1, &rtc.regAdjustment}, + { "R030", 1, 1, &rtc.regFree}, + + { "R040", 1, 1, &rtc._prevSCK}, + { "R050", 1, 1, &rtc._prevCS}, + { "R060", 1, 1, &rtc._prevSIO}, + { "R070", 1, 1, &rtc._SCK}, + { "R080", 1, 1, &rtc._CS}, + { "R090", 1, 1, &rtc._SIO}, + { "R100", 1, 1, &rtc._DD}, + { "R110", 2, 1, &rtc._REG}, + + { "R120", 1, 1, &rtc.cmd}, + { "R130", 1, 1, &rtc.cmdStat}, + { "R140", 1, 1, &rtc.bitsCount}, + { "R150", 1, 8, &rtc.data[0]}, + + { "R160", 1, 8, &rtc.cmdBitsSize[0]}, + + { 0 } +}; + +static const u8 kDefaultCmdBitsSize[8] = {8, 8, 56, 24, 0, 24, 8, 8}; #define toBCD(x) ((x / 10) << 4) | (x % 10); @@ -254,6 +282,7 @@ static void rtcSend() void rtcInit() { memset(&rtc, 0, sizeof(_RTC)); + memcpy(rtc.cmdBitsSize,kDefaultCmdBitsSize,8); rtc.regStatus1 |= 0x02; } @@ -316,9 +345,9 @@ void rtcWrite(u16 val) if ((rtc.cmd >> 1) == 0x04) { if ((rtc.regStatus2 & 0x0F) == 0x04) - cmdBitsSize[rtc.cmd >> 1] = 24; + rtc.cmdBitsSize[rtc.cmd >> 1] = 24; else - cmdBitsSize[rtc.cmd >> 1] = 8; + rtc.cmdBitsSize[rtc.cmd >> 1] = 8; } if (rtc.cmd & 0x01) { @@ -339,7 +368,7 @@ void rtcWrite(u16 val) { if(rtc._SIO) rtc.data[rtc.bitsCount >> 3] |= (1 << (rtc.bitsCount & 0x07)); rtc.bitsCount++; - if (rtc.bitsCount == cmdBitsSize[rtc.cmd >> 1]) + if (rtc.bitsCount == rtc.cmdBitsSize[rtc.cmd >> 1]) { rtcSend(); rtc.cmdStat = 0; @@ -357,7 +386,7 @@ void rtcWrite(u16 val) rtc._REG &= ~0x01; rtc.bitsCount++; - if (rtc.bitsCount == cmdBitsSize[rtc.cmd >> 1]) + if (rtc.bitsCount == rtc.cmdBitsSize[rtc.cmd >> 1]) rtc.cmdStat = 0; } break; diff --git a/desmume/src/saves.cpp b/desmume/src/saves.cpp index 2897d4c87..01c7fbc14 100644 --- a/desmume/src/saves.cpp +++ b/desmume/src/saves.cpp @@ -223,15 +223,12 @@ SFORMAT SF_MMU[]={ { "MSQ4", 8, 1, &MMU.sqrtCycles}, //begin memory chips - //we are skipping the firmware, because we really don't want to save the firmware to the savestate - //but, we will need to think about the philosophy of this. - //should we perhaps hash the current firmware and save it, so that we can match it against the loader's firmware? - { "BUCO", 1, 1, &MMU.bupmem.com}, - { "BUAD", 4, 1, &MMU.bupmem.addr}, - { "BUAS", 1, 1, &MMU.bupmem.addr_shift}, - { "BUAZ", 1, 1, &MMU.bupmem.addr_size}, - { "BUWE", 4, 1, &MMU.bupmem.write_enable}, - //writeable_buffer ??? + { "BUCO", 1, 1, &MMU.fw.com}, + { "BUAD", 4, 1, &MMU.fw.addr}, + { "BUAS", 1, 1, &MMU.fw.addr_shift}, + { "BUAZ", 1, 1, &MMU.fw.addr_size}, + { "BUWE", 4, 1, &MMU.fw.write_enable}, + { "BUWR", 4, 1, &MMU.fw.writeable_buffer}, //end memory chips { "MC0A", 4, 1, &MMU.dscard[0].address}, @@ -269,6 +266,105 @@ static void mmu_savestate(std::ostream* os) MMU_new.backupDevice.save_state(os); } +SFORMAT SF_WIFI[]={ + { "W000", 4, 1, &wifiMac.powerOn}, + { "W010", 4, 1, &wifiMac.powerOnPending}, + + { "W020", 2, 1, &wifiMac.rfStatus}, + { "W030", 2, 1, &wifiMac.rfPins}, + + { "W040", 2, 1, &wifiMac.IE.val}, + { "W050", 2, 1, &wifiMac.IF.val}, + + { "W060", 2, 1, &wifiMac.macMode}, + { "W070", 2, 1, &wifiMac.wepMode}, + { "W080", 4, 1, &wifiMac.WEP_enable}, + + { "W090", 2, 3, &wifiMac.TXSlot[0]}, + { "W100", 2, 1, &wifiMac.TXCnt}, + { "W110", 2, 1, &wifiMac.TXOpt}, + { "W120", 2, 1, &wifiMac.TXStat}, + { "W130", 2, 1, &wifiMac.BEACONSlot}, + { "W140", 4, 1, &wifiMac.BEACON_enable}, + { "W150", 1, 1, &wifiMac.txCurSlot}, + { "W160", 1, 3, &wifiMac.txSlotBusy[0]}, + { "W170", 4, 3, &wifiMac.txSlotAddr[0]}, + { "W180", 4, 3, &wifiMac.txSlotLen[0]}, + { "W190", 4, 3, &wifiMac.txSlotRemainingBytes[0]}, + + { "W200", 2, 1, &wifiMac.RXCnt}, + { "W210", 2, 1, &wifiMac.RXCheckCounter}, + + { "W220", 1, 6, &wifiMac.mac.bytes}, + { "W230", 1, 6, &wifiMac.bss.bytes}, + + { "W240", 2, 1, &wifiMac.aid}, + { "W250", 2, 1, &wifiMac.pid}, + { "W260", 2, 1, &wifiMac.retryLimit}, + + { "W270", 4, 1, &wifiMac.crystalEnabled}, + { "W280", 8, 1, &wifiMac.usec}, + { "W290", 4, 1, &wifiMac.usecEnable}, + { "W300", 8, 1, &wifiMac.ucmp}, + { "W310", 4, 1, &wifiMac.ucmpEnable}, + { "W320", 2, 1, &wifiMac.eCount}, + { "W330", 4, 1, &wifiMac.eCountEnable}, + + { "WR00", 4, 1, &wifiMac.RF.CFG1.val}, + { "WR01", 4, 1, &wifiMac.RF.IFPLL1.val}, + { "WR02", 4, 1, &wifiMac.RF.IFPLL2.val}, + { "WR03", 4, 1, &wifiMac.RF.IFPLL3.val}, + { "WR04", 4, 1, &wifiMac.RF.RFPLL1.val}, + { "WR05", 4, 1, &wifiMac.RF.RFPLL2.val}, + { "WR06", 4, 1, &wifiMac.RF.RFPLL3.val}, + { "WR07", 4, 1, &wifiMac.RF.RFPLL4.val}, + { "WR08", 4, 1, &wifiMac.RF.CAL1.val}, + { "WR09", 4, 1, &wifiMac.RF.TXRX1.val}, + { "WR10", 4, 1, &wifiMac.RF.PCNT1.val}, + { "WR11", 4, 1, &wifiMac.RF.PCNT2.val}, + { "WR12", 4, 1, &wifiMac.RF.VCOT1.val}, + + { "W340", 1, 105, &wifiMac.BB.data[0]}, + + { "W350", 2, 1, &wifiMac.rfIOCnt.val}, + { "W360", 2, 1, &wifiMac.rfIOStatus.val}, + { "W370", 4, 1, &wifiMac.rfIOData.val}, + { "W380", 2, 1, &wifiMac.bbIOCnt.val}, + + { "W390", 1, 1, &wifiMac.bbDataToWrite}, + + { "W400", 2, 0x1000, &wifiMac.circularBuffer[0]}, + { "W410", 2, 1, &wifiMac.RXRangeBegin}, + { "W420", 2, 1, &wifiMac.RXRangeEnd}, + { "W430", 2, 1, &wifiMac.RXHWWriteCursor}, + { "W440", 2, 1, &wifiMac.RXHWWriteCursorReg}, + { "W450", 2, 1, &wifiMac.RXHWWriteCursorLatched}, + { "W460", 2, 1, &wifiMac.RXReadCursor}, + { "W470", 2, 1, &wifiMac.RXUnits}, + { "W480", 2, 1, &wifiMac.RXBufCount}, + { "W490", 2, 1, &wifiMac.CircBufReadAddress}, + { "W500", 2, 1, &wifiMac.CircBufWriteAddress}, + { "W510", 2, 1, &wifiMac.CircBufRdEnd}, + { "W520", 2, 1, &wifiMac.CircBufRdSkip}, + { "W530", 2, 1, &wifiMac.CircBufWrEnd}, + { "W540", 2, 1, &wifiMac.CircBufWrSkip}, + + { "W540", 4, 1, &wifiMac.curPacketSize[0]}, + { "W550", 4, 1, &wifiMac.curPacketPos[0]}, + { "W560", 4, 1, &wifiMac.curPacketSending[0]}, + + { "W570", 2, 0x800, &wifiMac.ioMem[0]}, + { "W580", 2, 1, &wifiMac.randomSeed}, + + { "WX00", 8, 1, &wifiMac.SoftAP.usecCounter}, + { "WX10", 1, 4096, &wifiMac.SoftAP.curPacket[0]}, + { "WX20", 4, 1, &wifiMac.SoftAP.curPacketSize}, + { "WX30", 4, 1, &wifiMac.SoftAP.curPacketPos}, + { "WX40", 4, 1, &wifiMac.SoftAP.curPacketSending}, + + { 0 } +}; + static bool mmu_loadstate(std::istream* is, int size) { //read version @@ -453,7 +549,7 @@ void clear_savestates() void scan_savestates() { struct stat sbuf; - char filename[MAX_PATH]; + char filename[MAX_PATH+1]; u8 i; clear_savestates(); @@ -466,7 +562,7 @@ void scan_savestates() sprintf(filename+strlen(filename), ".ds%d", i); if( stat(filename,&sbuf) == -1 ) continue; savestates[i-1].exists = TRUE; - strncpy(savestates[i-1].date, format_time(sbuf.st_mtime),40-strlen(savestates[i-1].date)); + strncpy(savestates[i-1].date, format_time(sbuf.st_mtime),MAX_PATH); } return ; @@ -475,7 +571,7 @@ void scan_savestates() void savestate_slot(int num) { struct stat sbuf; - char filename[MAX_PATH]; + char filename[MAX_PATH+1]; lastSaveState = num; //Set last savestate used @@ -496,9 +592,9 @@ void savestate_slot(int num) return; } - savestates[num-1].exists = TRUE; + savestates[num].exists = TRUE; if( stat(filename,&sbuf) == -1 ) return; - strncpy(savestates[num-1].date, format_time(sbuf.st_mtime),40-strlen(savestates[num-1].date)); + strncpy(savestates[num].date, format_time(sbuf.st_mtime),MAX_PATH); } void loadstate_slot(int num) @@ -582,7 +678,7 @@ int sram_save (const char *file_name) { } -static SFORMAT *CheckS(SFORMAT *sf, u32 size, u32 count, char *desc) +static const SFORMAT *CheckS(const SFORMAT *sf, u32 size, u32 count, char *desc) { while(sf->v) { @@ -607,9 +703,9 @@ static SFORMAT *CheckS(SFORMAT *sf, u32 size, u32 count, char *desc) } -static bool ReadStateChunk(std::istream* is, SFORMAT *sf, int size) +static bool ReadStateChunk(std::istream* is, const SFORMAT *sf, int size) { - SFORMAT *tmp; + const SFORMAT *tmp; int temp = is->tellg(); while(is->tellg()(0x04000304, _MMU_read16(0x04000304)); // This should regenerate the graphics configuration - for (int i = REG_BASE_DISPA; i<=REG_BASE_DISPA + 0x7F; i+=2) + //zero 27-jul-09 : was formerly up to 7F but that wrote to dispfifo which is dumb (one of nitsuja's desynch bugs) + for (int i = REG_BASE_DISPA; i<=REG_BASE_DISPA + 0x66; i+=2) _MMU_write16(i, _MMU_read16(i)); for (int i = REG_BASE_DISPB; i<=REG_BASE_DISPB + 0x7F; i+=2) _MMU_write16(i, _MMU_read16(i)); diff --git a/desmume/src/types.h b/desmume/src/types.h index 501b7fb0a..474c097d6 100644 --- a/desmume/src/types.h +++ b/desmume/src/types.h @@ -41,6 +41,7 @@ #ifdef _WIN32 #define strcasecmp(x,y) _stricmp(x,y) +#define snprintf _snprintf #else #define WINAPI #endif diff --git a/desmume/src/wifi.cpp b/desmume/src/wifi.cpp index b19773327..bb2c415b3 100644 --- a/desmume/src/wifi.cpp +++ b/desmume/src/wifi.cpp @@ -1,5 +1,5 @@ -/* - Copyright (C) 2007 Tim Seidel +/* Copyright (C) 2007 Tim Seidel + Copyright (C) 2008-2009 DeSmuME team This file is part of DeSmuME @@ -26,7 +26,15 @@ #ifdef EXPERIMENTAL_WIFI -wifimac_t wifiMac ; +#ifdef WIN32 +#include "windriver.h" +#else +#include "pcap/pcap.h" +#endif + +wifimac_t wifiMac; +bool wifi_netEnabled = false; +pcap_t *wifi_bridge = NULL; #endif @@ -306,6 +314,10 @@ static u32 WIFI_getCRC32(u8 *data, int len) static void WIFI_initCRC32Table() { + static bool initialized = false; + if(initialized) return; + initialized = true; + u32 polynomial = 0x04C11DB7; for(int i = 0; i < 0x100; i++) @@ -539,13 +551,15 @@ static void WIFI_triggerIRQ(wifimac_t *wifi, u8 irq) void WIFI_Init(wifimac_t *wifi) { + memset(wifi,0,sizeof(wifimac_t)); + WIFI_initCRC32Table(); WIFI_resetRF(&wifi->RF) ; - wifi->netEnabled = false; + wifi_netEnabled = false; if(driver->WIFI_Host_InitSystem()) { - wifi->netEnabled = true; + wifi_netEnabled = true; } wifi->powerOn = FALSE; wifi->powerOnPending = FALSE; @@ -1254,12 +1268,11 @@ int WIFI_SoftAP_Init(wifimac_t *wifi) wifi->SoftAP.usecCounter = 0; - wifi->SoftAP.curPacket = NULL; wifi->SoftAP.curPacketSize = 0; wifi->SoftAP.curPacketPos = 0; wifi->SoftAP.curPacketSending = FALSE; - if(wifiMac.netEnabled) + if(wifi_netEnabled) { if(desmume_pcap_findalldevs(&alldevs, errbuf) == -1) { @@ -1267,8 +1280,8 @@ int WIFI_SoftAP_Init(wifimac_t *wifi) return 0; } - wifi->SoftAP.bridge = desmume_pcap_open(WIFI_index_device(alldevs,CommonSettings.wifiBridgeAdapterNum)->name, PACKET_SIZE, 0, 1, errbuf); - if(wifi->SoftAP.bridge == NULL) + wifi_bridge = desmume_pcap_open(WIFI_index_device(alldevs,CommonSettings.wifiBridgeAdapterNum)->name, PACKET_SIZE, 0, 1, errbuf); + if(wifi_bridge == NULL) { printf("SoftAP: PCAP error with pcap_open(): %s\n", errbuf); return 0; @@ -1282,14 +1295,11 @@ int WIFI_SoftAP_Init(wifimac_t *wifi) void WIFI_SoftAP_Shutdown(wifimac_t *wifi) { - if(wifiMac.netEnabled) + if(wifi_netEnabled) { - if(wifi->SoftAP.bridge != NULL) - desmume_pcap_close(wifi->SoftAP.bridge); + if(wifi_bridge != NULL) + desmume_pcap_close(wifi_bridge); } - - if(wifi->SoftAP.curPacket) - delete wifi->SoftAP.curPacket; } static void WIFI_SoftAP_MakeRXHeader(wifimac_t *wifi, u16 flags, u16 xferRate, u16 len, u8 maxRSSI, u8 minRSSI) @@ -1331,8 +1341,6 @@ void WIFI_SoftAP_RecvPacketFromDS(wifimac_t *wifi, u8 *packet, int len) int packetLen = sizeof(SoftAP_ProbeResponse); int totalLen = (packetLen + 12); - wifi->SoftAP.curPacket = new u8[totalLen]; - // Make the RX header // About the packet length: // GBATek says the length entry of the RX header is the length of the IEEE @@ -1368,8 +1376,6 @@ void WIFI_SoftAP_RecvPacketFromDS(wifimac_t *wifi, u8 *packet, int len) int packetLen = sizeof(SoftAP_AuthFrame); int totalLen = (packetLen + 12); - wifi->SoftAP.curPacket = new u8[totalLen]; - // Make the RX header WIFI_SoftAP_MakeRXHeader(wifi, 0x0010, 20, packetLen, 0, 0); @@ -1395,8 +1401,6 @@ void WIFI_SoftAP_RecvPacketFromDS(wifimac_t *wifi, u8 *packet, int len) int packetLen = sizeof(SoftAP_AssocResponse); int totalLen = (packetLen + 12); - wifi->SoftAP.curPacket = new u8[totalLen]; - // Make the RX header WIFI_SoftAP_MakeRXHeader(wifi, 0x0010, 20, packetLen, 0, 0); @@ -1453,8 +1457,8 @@ void WIFI_SoftAP_RecvPacketFromDS(wifimac_t *wifi, u8 *packet, int len) // Checksum // TODO ? - if(wifi->netEnabled) //dont try to pcap out the packet unless network is enabled - desmume_pcap_sendpacket(wifi->SoftAP.bridge, ethernetframe, eflen); + if(wifi_netEnabled) //dont try to pcap out the packet unless network is enabled + desmume_pcap_sendpacket(wifi_bridge, ethernetframe, eflen); delete ethernetframe; } @@ -1467,9 +1471,6 @@ static void WIFI_SoftAP_SendBeacon(wifimac_t *wifi) int packetLen = sizeof(SoftAP_Beacon); int totalLen = (packetLen + 12); - if(wifi->SoftAP.curPacket) delete wifi->SoftAP.curPacket; - wifi->SoftAP.curPacket = new u8[totalLen]; - // Make the RX header WIFI_SoftAP_MakeRXHeader(wifi, 0x0011, 20, packetLen, 0, 0); @@ -1541,9 +1542,6 @@ void WIFI_SoftAP_usTrigger(wifimac_t *wifi) wifi->SoftAP.curPacketPos = 0; wifi->SoftAP.curPacketSending = FALSE; - delete wifi->SoftAP.curPacket; - wifi->SoftAP.curPacket = NULL; - wifi->RXHWWriteCursorReg = ((wifi->RXHWWriteCursor + 1) & (~1)); WIFI_triggerIRQ(wifi, WIFI_IRQ_RECVCOMPLETE); diff --git a/desmume/src/wifi.h b/desmume/src/wifi.h index ce552962c..11a2b740b 100644 --- a/desmume/src/wifi.h +++ b/desmume/src/wifi.h @@ -1,5 +1,5 @@ -/* - Copyright (C) 2007 Tim Seidel +/* Copyright (C) 2007 Tim Seidel + Copyright (C) 2008-2009 DeSmuME team This file is part of DeSmuME @@ -25,12 +25,6 @@ #ifdef EXPERIMENTAL_WIFI -#ifdef WIN32 -#include "windriver.h" -#else -#include "pcap/pcap.h" -#endif - #define HAVE_REMOTE #define WPCAP #define PACKET_SIZE 65535 @@ -261,6 +255,7 @@ typedef struct rffilter_t /* 6*/ unsigned MID_POWER:6; /*12*/ unsigned MAX_POWER:6; } bits ; + u32 val ; } PCNT2 ; union VCOT1 { @@ -365,6 +360,7 @@ typedef union /* wifimac_t: the buildin mac (arm7 addressrange: 0x04800000-0x04FFFFFF )*/ /* http://www.akkit.org/info/dswifi.htm#WifiIOMap */ + typedef struct { /* power */ @@ -404,6 +400,7 @@ typedef struct /* addressing/handshaking */ union { + //TODO - is this endian safe? don't think so u16 words[3] ; u8 bytes[6] ; } mac ; @@ -455,9 +452,8 @@ typedef struct u16 CircBufWrSkip ; /* tx packets */ - u8 *curPacket[3]; - int curPacketSize[3]; - int curPacketPos[3]; + s32 curPacketSize[3]; + s32 curPacketPos[3]; BOOL curPacketSending[3]; /* i/o mem */ @@ -469,23 +465,24 @@ typedef struct /* SoftAP */ struct _SoftAP { - pcap_t *bridge; - u64 usecCounter; - u8 *curPacket; - int curPacketSize; - int curPacketPos; + u8 curPacket[4096]; + s32 curPacketSize; + s32 curPacketPos; BOOL curPacketSending; } SoftAP; - /* desmume host communication */ - bool netEnabled; - } wifimac_t ; -extern wifimac_t wifiMac ; + +// desmume host communication +typedef struct pcap pcap_t; +extern bool wifi_netEnabled; +extern pcap_t *wifi_bridge; + +extern wifimac_t wifiMac; void WIFI_Init(wifimac_t *wifi); diff --git a/desmume/src/windows/DeSmuME_2005.vcproj b/desmume/src/windows/DeSmuME_2005.vcproj index 1c8bdf933..dd5b67054 100644 --- a/desmume/src/windows/DeSmuME_2005.vcproj +++ b/desmume/src/windows/DeSmuME_2005.vcproj @@ -52,7 +52,7 @@ EnableFiberSafeOptimizations="false" WholeProgramOptimization="false" AdditionalIncludeDirectories=".;..;"lua\lua-5.1.4\src";"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig;.\7z;.\agg\include;.\agg\examples" - PreprocessorDefinitions="DEBUG;_CRT_SECURE_NO_DEPRECATE;GLIB_STATIC_COMPILATION;WIN32;SPU_INTERPOLATE;HAVE_LIBZ;HAVE_LIBZZIP;NOMINMAX;EXPERIMENTAL_WIFI" + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;DEBUG;_CRT_SECURE_NO_DEPRECATE;GLIB_STATIC_COMPILATION;WIN32;SPU_INTERPOLATE;HAVE_LIBZ;HAVE_LIBZZIP;NOMINMAX;EXPERIMENTAL_WIFI" ExceptionHandling="1" BasicRuntimeChecks="0" BufferSecurityCheck="true" @@ -146,7 +146,7 @@ EnableFiberSafeOptimizations="true" WholeProgramOptimization="true" AdditionalIncludeDirectories=".;..;"lua\lua-5.1.4\src";"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig;.\7z;.\agg\include;.\agg\examples" - PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;GLIB_STATIC_COMPILATION;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SPU_INTERPOLATE;NOMINMAX;NDEBUG;RELEASE;EXPERIMENTAL_WIFI" + PreprocessorDefinitions="_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_DEPRECATE;GLIB_STATIC_COMPILATION;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SPU_INTERPOLATE;NOMINMAX;NDEBUG;RELEASE;EXPERIMENTAL_WIFI" StringPooling="true" ExceptionHandling="1" BasicRuntimeChecks="0" @@ -244,7 +244,7 @@ EnableFiberSafeOptimizations="true" WholeProgramOptimization="false" AdditionalIncludeDirectories=".;..;"lua\lua-5.1.4\src";"glib-2.20.1\build";"glib-2.20.1\build\glib";.\zlib123;.\zziplib;.\winpcap;userconfig;defaultconfig;.\7z;.\agg\include;.\agg\examples" - PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;GLIB_STATIC_COMPILATION;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SPU_INTERPOLATE;NOMINMAX;NDEBUG;RELEASE;EXPERIMENTAL_WIFI" + PreprocessorDefinitions="_CRT_SECURE_NO_DEPRECATE;_CRT_NONSTDC_NO_DEPRECATE;GLIB_STATIC_COMPILATION;WIN32;HAVE_LIBZ;HAVE_LIBZZIP;SPU_INTERPOLATE;NOMINMAX;NDEBUG;RELEASE;EXPERIMENTAL_WIFI" StringPooling="true" ExceptionHandling="1" BasicRuntimeChecks="0" @@ -254,7 +254,8 @@ EnableEnhancedInstructionSet="2" FloatingPointModel="2" RuntimeTypeInfo="false" - WarningLevel="2" + WarningLevel="3" + WarnAsError="false" DebugInformationFormat="3" CallingConvention="0" CompileAs="0" diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index dc462a9cd..1ebef450e 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -2458,7 +2458,7 @@ void RunConfig(CONFIGSCREEN which) break; case CONFIGSCREEN_WIFI: #ifdef EXPERIMENTAL_WIFI - if(wifiMac.netEnabled) + if(wifi_netEnabled) { DialogBox(hAppInst,MAKEINTRESOURCE(IDD_WIFISETTINGS), hwnd, (DLGPROC) WifiSettingsDlgProc); }