diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 3c1c9c396..c0bcf674a 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -52,6 +52,7 @@ #define ASSERT_UNALIGNED(x) #endif +int LagFrameFlag=0; //http://home.utah.edu/~nahaj/factoring/isqrt.c.html @@ -2863,6 +2864,12 @@ 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) { @@ -2884,6 +2891,7 @@ 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", @@ -2918,6 +2926,8 @@ u16 FASTCALL _MMU_ARM9_read16(u32 adr) adr &= 0x0FFFFFFF; + CheckLag(adr); + if (adr >> 24 == 4) { /* Address is an IO register */ @@ -3001,6 +3011,8 @@ u32 FASTCALL _MMU_ARM9_read32(u32 adr) adr &= 0x0FFFFFFF; + CheckLag(adr); + // Address is an IO register if((adr >> 24) == 4) { diff --git a/desmume/src/MMU.h b/desmume/src/MMU.h index 8ab88fdc1..b18737757 100644 --- a/desmume/src/MMU.h +++ b/desmume/src/MMU.h @@ -126,6 +126,7 @@ 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 fa910a8a1..29c86ddc0 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -64,6 +64,8 @@ BOOL fw_success = FALSE; NDSSystem nds; +int lagframecounter=0; + /* ------------------------------------------------------------------------- */ /* FIRMWARE DECRYPTION */ @@ -1420,6 +1422,8 @@ u32 NDS_exec(s32 nb) { int i, j; + LagFrameFlag=1; + nb += nds.cycles;//(nds.cycles>>26)<<26; //increase this to execute more instructions in each batch (reducing overhead) @@ -2208,6 +2212,9 @@ u32 NDS_exec(s32 nb) } } + if(LagFrameFlag) + lagframecounter++; + return nds.cycles; } diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index 4230b3a41..45113a7b0 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -235,6 +235,8 @@ void NDS_SkipFrame(bool skip); template u32 NDS_exec(s32 nb); +extern int lagframecounter; + inline u32 NDS_exec(s32 nb) { return NDS_exec(nb); } static INLINE void NDS_ARM9HBlankInt(void) diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 4fe15fde5..518e0a600 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -225,6 +225,7 @@ bool frameAdvance = false; bool frameCounterDisplay = false; bool FpsDisplay = false; bool ShowInputDisplay = false; +bool ShowLagFrameCounter = false; unsigned short windowSize = 0; unsigned int lastSaveState = 0; //Keeps track of last savestate used for quick save/load functions @@ -1014,6 +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); DisplayMessage(); CheckMessages(); } @@ -1072,6 +1074,7 @@ BOOL LoadROM(char * filename, const char *cflash_disk_image) { INFO("Loading %s was successful\n",filename); frameCounter=0; + lagframecounter=0; UpdateRecentRoms(filename); osd->setRotate(GPU_rotation); return TRUE; @@ -1108,6 +1111,7 @@ int MenuInit() MainWindow->checkMenu(ID_VIEW_DISPLAYFPS, FpsDisplay ? MF_CHECKED : MF_UNCHECKED); MainWindow->checkMenu(ID_VIEW_DISPLAYINPUT, ShowInputDisplay ? MF_CHECKED : MF_UNCHECKED); + MainWindow->checkMenu(ID_VIEW_DISPLAYLAG, ShowLagFrameCounter ? MF_CHECKED : MF_UNCHECKED); MainWindow->checkMenu(IDC_WINDOW1X, MF_BYCOMMAND | ((windowSize==1)?MF_CHECKED:MF_UNCHECKED)); MainWindow->checkMenu(IDC_WINDOW1_5X, MF_BYCOMMAND | ((windowSize==65535)?MF_CHECKED:MF_UNCHECKED)); @@ -1344,6 +1348,7 @@ int WINAPI WinMain (HINSTANCE hThisInstance, WndY = GetPrivateProfileInt("Video","WindowPosY", CW_USEDEFAULT, IniName); frameCounterDisplay = GetPrivateProfileInt("Display","FrameCounter", 0, IniName); ShowInputDisplay = GetPrivateProfileInt("Display","Display Input", 0, IniName); + ShowLagFrameCounter = GetPrivateProfileInt("Display","Display Lag Counter", 0, IniName); ScreenGap = GetPrivateProfileInt("Display", "ScreenGap", 0, IniName); FrameLimit = GetPrivateProfileInt("FrameLimit", "FrameLimit", 1, IniName); //sprintf(text, "%s", DESMUME_NAME_AND_VERSION); @@ -2756,6 +2761,13 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM osd->clear(); return 0; + case ID_VIEW_DISPLAYLAG: + ShowLagFrameCounter ^= 1; + MainWindow->checkMenu(ID_VIEW_DISPLAYINPUT, ShowLagFrameCounter ? MF_CHECKED : MF_UNCHECKED); + WritePrivateProfileInt("Display", "Display Lag Counter", ShowLagFrameCounter, IniName); + osd->clear(); + return 0; + #define clearsaver() \ MainWindow->checkMenu(IDC_SAVETYPE1, MF_BYCOMMAND | MF_UNCHECKED); \ MainWindow->checkMenu(IDC_SAVETYPE2, MF_BYCOMMAND | MF_UNCHECKED); \ diff --git a/desmume/src/windows/resource.h b/desmume/src/windows/resource.h index 45c7155b9..2d8a2b3dc 100644 --- a/desmume/src/windows/resource.h +++ b/desmume/src/windows/resource.h @@ -416,6 +416,7 @@ #define ID_VIEW_FRAMECOUNTER 40009 #define ID_VIEW_DISPLAYFPS 40010 #define ID_VIEW_DISPLAYINPUT 40011 +#define ID_VIEW_DISPLAYLAG 40012 #define IDM_FILE_RECORDAVI 40015 #define IDM_FILE_STOPAVI 40016 #define ACCEL_CTRL_O 40032 diff --git a/desmume/src/windows/resources.rc b/desmume/src/windows/resources.rc index 900dbabba..ed4d27373 100644 --- a/desmume/src/windows/resources.rc +++ b/desmume/src/windows/resources.rc @@ -114,6 +114,7 @@ BEGIN MENUITEM "Display Frame Counter", ID_VIEW_FRAMECOUNTER MENUITEM "Display Fps", ID_VIEW_DISPLAYFPS MENUITEM "Display Input", ID_VIEW_DISPLAYINPUT + MENUITEM "Display Lag Counter", ID_VIEW_DISPLAYLAG END POPUP "&Konfigure" BEGIN @@ -282,6 +283,7 @@ BEGIN MENUITEM "Display Frame Counter", ID_VIEW_FRAMECOUNTER MENUITEM "Display FPS", ID_VIEW_DISPLAYFPS MENUITEM "Display Input", ID_VIEW_DISPLAYINPUT + MENUITEM "Display Lag Counter", ID_VIEW_DISPLAYLAG END POPUP "&Config" BEGIN @@ -449,6 +451,7 @@ BEGIN MENUITEM "Compteur d'images", ID_VIEW_FRAMECOUNTER MENUITEM "Framerate", ID_VIEW_DISPLAYFPS MENUITEM "Display Input", ID_VIEW_DISPLAYINPUT + MENUITEM "Display Lag Counter", ID_VIEW_DISPLAYLAG END POPUP "&Config" BEGIN