From e1f77790ccf35a54a08c2d213640dee67350e267 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 2 Apr 2009 22:27:06 +0000 Subject: [PATCH] tweaks to lag frame --- desmume/src/MMU.cpp | 31 ++++++++++++++++--------------- desmume/src/MMU.h | 1 - desmume/src/NDSSystem.cpp | 10 ++++++++++ desmume/src/NDSSystem.h | 3 +++ desmume/src/softrender_config.h | 2 +- desmume/src/windows/main.cpp | 2 +- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index c0bcf674a..f1d23b949 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -52,9 +52,6 @@ #define ASSERT_UNALIGNED(x) #endif -int LagFrameFlag=0; - - //http://home.utah.edu/~nahaj/factoring/isqrt.c.html static u64 isqrt (u64 x) { u64 squaredbit, remainder, root; @@ -2864,12 +2861,6 @@ void FASTCALL _MMU_ARM9_write32(u32 adr, u32 val) T1WriteLong(MMU.MMU_MEM[ARMCPU_ARM9][adr>>20], adr&MMU.MMU_MASK[ARMCPU_ARM9][adr>>20], val); } -void CheckLag(u32 adr) { - - if (adr == 0x04000130 || 0x04000136) - LagFrameFlag=0; -} - //================================================= MMU ARM9 read 08 u8 FASTCALL _MMU_ARM9_read08(u32 adr) { @@ -2891,7 +2882,6 @@ u8 FASTCALL _MMU_ARM9_read08(u32 adr) if ((adr>=0x9000000)&&(adr<0x9900000)) return (unsigned char)cflash_read(adr); #endif - CheckLag(adr); #ifdef _MMU_DEBUG mmu_log_debug_ARM9(adr, "(read08) %0x%X", @@ -2926,13 +2916,12 @@ u16 FASTCALL _MMU_ARM9_read16(u32 adr) adr &= 0x0FFFFFFF; - CheckLag(adr); - if (adr >> 24 == 4) { - /* Address is an IO register */ + // Address is an IO register switch(adr) { + // ============================================= 3D case 0x04000604: return (gfx3d_GetNumPolys()&2047); case 0x04000606: @@ -2960,6 +2949,12 @@ u16 FASTCALL _MMU_ARM9_read16(u32 adr) case REG_TM2CNTL : case REG_TM3CNTL : return MMU.timer[ARMCPU_ARM9][(adr&0xF)>>2]; + + case 0x04000130: + case 0x04000136: + //not sure whether these should trigger from byte reads + LagFrameFlag=0; + break; case REG_POSTFLG : return 1; @@ -3011,8 +3006,6 @@ u32 FASTCALL _MMU_ARM9_read32(u32 adr) adr &= 0x0FFFFFFF; - CheckLag(adr); - // Address is an IO register if((adr >> 24) == 4) { @@ -4014,6 +4007,14 @@ u16 FASTCALL _MMU_ARM7_read16(u32 adr) case REG_TM2CNTL : case REG_TM3CNTL : return MMU.timer[ARMCPU_ARM7][(adr&0xF)>>2]; + + + case 0x04000130: + case 0x04000136: + //here is an example of what not to do: + //since the arm7 polls this every frame, we shouldnt count this as an input check + //LagFrameFlag=0; + break; case REG_POSTFLG : return 1; diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index b18737757..8ab88fdc1 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -126,7 +126,6 @@ struct MMU_struct { extern MMU_struct MMU; -extern int LagFrameFlag; struct armcpu_memory_iface { /** the 32 bit instruction prefetch */ diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index 29c86ddc0..79f3d8f78 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -65,6 +65,8 @@ BOOL fw_success = FALSE; NDSSystem nds; int lagframecounter=0; +int LagFrameFlag=0; +int lastLag=0; /* ------------------------------------------------------------------------- */ /* FIRMWARE DECRYPTION */ @@ -1422,6 +1424,7 @@ u32 NDS_exec(s32 nb) { int i, j; + //TODO - since NDS_exec is not necessarily called one frame at a time, this could be wrong. LagFrameFlag=1; nb += nds.cycles;//(nds.cycles>>26)<<26; @@ -2213,7 +2216,14 @@ u32 NDS_exec(s32 nb) } if(LagFrameFlag) + { lagframecounter++; + } + else + { + lastLag = lagframecounter; + lagframecounter = 0; + } return nds.cycles; } diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 45113a7b0..36af8407f 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -331,6 +331,9 @@ public: extern Driver* driver; extern std::string InputDisplayString; +extern int LagFrameFlag; +extern int lastLag; + #endif diff --git a/desmume/src/softrender_config.h b/desmume/src/softrender_config.h index c01bf43ac..1e6c43189 100644 --- a/desmume/src/softrender_config.h +++ b/desmume/src/softrender_config.h @@ -11,4 +11,4 @@ typedef unsigned int quad; } -#endif \ No newline at end of file +#endif diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 518e0a600..4e85326c7 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -1015,7 +1015,7 @@ DWORD WINAPI run() frameCounter++; if (frameCounterDisplay) osd->addFixed(0, 25, "%d",frameCounter); if (ShowInputDisplay) osd->addFixed(0, 45, "%s",InputDisplayString.c_str()); - if (ShowLagFrameCounter) osd->addFixed(0, 65, "%d",lagframecounter); + if (ShowLagFrameCounter) osd->addFixed(0, 65, "%d",lastLag); DisplayMessage(); CheckMessages(); }