From 016a543ef3a1cf14c300eec87232cf338e6332bf Mon Sep 17 00:00:00 2001 From: luigi__ Date: Sat, 23 May 2009 19:30:29 +0000 Subject: [PATCH] I finally figured out why 2D and 3D get desynced when skipping 3D frames. Thus, I fixed the frameskip system so it'll also skip 3D frames. 2D and 3D stay synchronized, and frameskip is now much faster when using the soft rasterizer, for example. --- desmume/src/NDSSystem.cpp | 39 +++++++++++++++++++++++++++--------- desmume/src/NDSSystem.h | 3 ++- desmume/src/windows/main.cpp | 16 +++++++++------ 3 files changed, 41 insertions(+), 17 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 837cd4b71..b1d20f30d 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -1587,10 +1587,10 @@ int NDS_LoadFirmware(const char *filename) void NDS_Sleep() { nds.sleeping = TRUE; } -bool skipThisFrame = false; -bool skipThisFrame3D = false; +bool SkipCur2DFrame = false, SkipNext2DFrame = false; +bool SkipCur3DFrame = false; -void NDS_SkipFrame(bool skip) { skipThisFrame = skip; } +void NDS_SkipNextFrame() { SkipNext2DFrame = true; SkipCur3DFrame = true; } #define INDEX(i) ((((i)>>16)&0xFF0)|(((i)>>4)&0xF)) @@ -1699,7 +1699,7 @@ u32 NDS_exec(s32 nb) } #ifdef EXPERIMENTAL_WIFI - /* TODO: the wifi stuff isn't actually clocked by the ARM7 clock, */ + /* FIXME: the wifi stuff isn't actually clocked by the ARM7 clock, */ /* but by a 22 mhz oscillator. */ if(nds7old < nds.ARM7Cycle) { @@ -1713,11 +1713,14 @@ u32 NDS_exec(s32 nb) } } #endif - } + } // for (j = 0; j < INSTRUCTIONS_PER_BATCH && (!FORCE) && (execute); j++) if(!nds.sleeping) { + // for(i = 0; i < INSTRUCTIONS_PER_BATCH && (!FORCE) && (execute); i++) + // { + nds.cycles = std::min(nds.ARM9Cycle,nds.ARM7Cycle); //debug(); @@ -1733,14 +1736,12 @@ u32 NDS_exec(s32 nb) if(nds.VCount<192) { - if(!skipThisFrame) + if(!SkipCur2DFrame) { GPU_ligne(&MainScreen, nds.VCount); GPU_ligne(&SubScreen, nds.VCount); } - skipThisFrame3D = skipThisFrame; - if(MMU.DMAStartTime[0][0] == 2) MMU_doDMA(0); if(MMU.DMAStartTime[0][1] == 2) @@ -1819,6 +1820,14 @@ u32 NDS_exec(s32 nb) //osdA->update(); gfx3d_VBlankSignal(); + if(SkipNext2DFrame) + { + SkipCur2DFrame = true; + SkipNext2DFrame = false; + } + else + SkipCur2DFrame = false; + T1WriteWord(ARM9Mem.ARM9_REG, 4, T1ReadWord(ARM9Mem.ARM9_REG, 4) | 1); T1WriteWord(MMU.ARM7_REG, 4, T1ReadWord(MMU.ARM7_REG, 4) | 1); NDS_ARM9VBlankInt(); @@ -1851,7 +1860,8 @@ u32 NDS_exec(s32 nb) } else if(nds.VCount==214) { - gfx3d_VBlankEndSignal(false); + gfx3d_VBlankEndSignal(SkipCur3DFrame); + SkipCur3DFrame = false; } else if(nds.VCount==263) { @@ -1929,7 +1939,16 @@ u32 NDS_exec(s32 nb) else T1WriteWord(MMU.ARM7_REG, 4, T1ReadWord(MMU.ARM7_REG, 4) & 0xFFFB); } - } + } // if(nds.cycles >= nds.nextHBlank) + + /* } // for(i = 0; i < INSTRUCTIONS_PER_BATCH && (!FORCE) && (execute); i++) + + } // if(!nds.sleeping) + + } // for (j = 0; j < INSTRUCTIONS_PER_BATCH && (!FORCE) && (execute); j++) + + if(!nds.sleeping) + {*/ if(MMU.divRunning) { diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index a6b3904ba..c85a18ef7 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -287,7 +287,8 @@ int NDS_CreateDummyFirmware( struct NDS_fw_config_data *user_settings); void NDS_Sleep(); -void NDS_SkipFrame(bool skip); +void NDS_SkipNextFrame(); +#define NDS_SkipFrame(s) if(s) NDS_SkipNext2DFrame(); template u32 NDS_exec(s32 nb); diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index ba2cdb0b3..b5d53a283 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -1160,11 +1160,14 @@ DWORD WINAPI run() } + // TODO: make that thing properly threaded + // because, here, if the emu is slower, the tools will refresh less often tools_frames++; if(tools_frames == 10) { if(MemView_IsOpened(ARMCPU_ARM9)) MemView_Refresh(ARMCPU_ARM9); if(MemView_IsOpened(ARMCPU_ARM7)) MemView_Refresh(ARMCPU_ARM7); + // if(IORegView_IsOpened()) IORegView_Refresh(); tools_frames = 0; } @@ -1201,8 +1204,6 @@ DWORD WINAPI run() if (framestoskip > 0) skipnextframe = 1; - - NDS_SkipFrame(false); } else { @@ -1215,8 +1216,9 @@ DWORD WINAPI run() framesskipped++; - NDS_SkipFrame(true); + NDS_SkipNextFrame(); } + if(FastForward) { if(framesskipped < 9) @@ -1246,7 +1248,7 @@ DWORD WINAPI run() QueryPerformanceCounter((LARGE_INTEGER *)&curticks); diffticks = curticks-lastticks; - if(ThrottleIsBehind() && framesskipped < 9) + if(ThrottleIsBehind() && (framesskipped < 9)) { skipnextframe = 1; framestoskip = 1; @@ -1934,6 +1936,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, MemView_DlgClose(ARMCPU_ARM9); MemView_DlgClose(ARMCPU_ARM7); + //IORegView_DlgClose(); MemView_DeInit(); @@ -3103,6 +3106,7 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM return 0; case IDM_IOREG: ViewRegisters->open(); + //IORegView_DlgOpen(HWND_DESKTOP, "I/O registers"); return 0; case IDM_MEMORY: /* ViewMem_ARM7->regClass("MemViewBox7", ViewMem_ARM7BoxProc); @@ -3111,8 +3115,8 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM ViewMem_ARM9->regClass("MemViewBox9", ViewMem_ARM9BoxProc); if (!ViewMem_ARM9->open()) ViewMem_ARM9->unregClass();*/ - if(!MemView_IsOpened(ARMCPU_ARM9)) MemView_DlgOpen(hwnd, "ARM9 memory", ARMCPU_ARM9); - if(!MemView_IsOpened(ARMCPU_ARM7)) MemView_DlgOpen(hwnd, "ARM7 memory", ARMCPU_ARM7); + if(!MemView_IsOpened(ARMCPU_ARM9)) MemView_DlgOpen(HWND_DESKTOP, "ARM9 memory", ARMCPU_ARM9); + if(!MemView_IsOpened(ARMCPU_ARM7)) MemView_DlgOpen(HWND_DESKTOP, "ARM7 memory", ARMCPU_ARM7); return 0; case IDM_DISASSEMBLER: ViewDisasm_ARM7->regClass("DesViewBox7",ViewDisasm_ARM7BoxProc);