From 2fbd0685d127e9a9bfa26f1da69d9f2bc034c0da Mon Sep 17 00:00:00 2001 From: rogerman Date: Wed, 28 Oct 2015 05:29:17 +0000 Subject: [PATCH] Cocoa Port: - Add support for displaying the CPU load average in the HUD. --- desmume/src/NDSSystem.cpp | 32 +++ desmume/src/NDSSystem.h | 1 + desmume/src/cocoa/DefaultUserPrefs.plist | 2 + desmume/src/cocoa/OGLDisplayOutput.cpp | 34 ++- desmume/src/cocoa/OGLDisplayOutput.h | 7 +- desmume/src/cocoa/cocoa_core.h | 5 +- desmume/src/cocoa/cocoa_core.mm | 25 +- desmume/src/cocoa/cocoa_output.h | 5 + desmume/src/cocoa/cocoa_output.mm | 23 +- .../English.lproj/MainMenu.strings | Bin 350944 -> 351650 bytes .../translations/English.lproj/MainMenu.xib | 245 +++++++++++++----- .../userinterface/DisplayWindowController.h | 2 + .../userinterface/DisplayWindowController.mm | 40 ++- .../src/cocoa/userinterface/appDelegate.mm | 3 + desmume/src/windows/main.cpp | 28 +- 15 files changed, 359 insertions(+), 93 deletions(-) diff --git a/desmume/src/NDSSystem.cpp b/desmume/src/NDSSystem.cpp index d6fddbf1d..5248f07e4 100644 --- a/desmume/src/NDSSystem.cpp +++ b/desmume/src/NDSSystem.cpp @@ -2966,6 +2966,38 @@ bool ValidateSlot2Access(u32 procnum, u32 demandSRAMSpeed, u32 demand1stROMSpeed return true; } +void NDS_GetCPULoadAverage(u32 &outLoadAvgARM9, u32 &outLoadAvgARM7) +{ + //calculate a 16 frame arm9 load average + u32 calcLoad = 0; + for (size_t i = 0; i < 16; i++) + { + //blend together a few frames to keep low-framerate games from having a jittering load average + //(they will tend to work 100% for a frame and then sleep for a while) + //4 frames should handle even the slowest of games + u32 sample = nds.runCycleCollector[ARMCPU_ARM9][(i + 0 + nds.idleFrameCounter) & 15] + + nds.runCycleCollector[ARMCPU_ARM9][(i + 1 + nds.idleFrameCounter) & 15] + + nds.runCycleCollector[ARMCPU_ARM9][(i + 2 + nds.idleFrameCounter) & 15] + + nds.runCycleCollector[ARMCPU_ARM9][(i + 3 + nds.idleFrameCounter) & 15]; + sample /= 4; + calcLoad = calcLoad/8 + sample*7/8; + } + outLoadAvgARM9 = std::min( 100, std::max(0, (u32)(calcLoad*100/1120380)) ); + + //calculate a 16 frame arm7 load average + calcLoad = 0; + for (size_t i = 0; i < 16; i++) + { + u32 sample = nds.runCycleCollector[ARMCPU_ARM7][(i + 0 + nds.idleFrameCounter) & 15] + + nds.runCycleCollector[ARMCPU_ARM7][(i + 1 + nds.idleFrameCounter) & 15] + + nds.runCycleCollector[ARMCPU_ARM7][(i + 2 + nds.idleFrameCounter) & 15] + + nds.runCycleCollector[ARMCPU_ARM7][(i + 3 + nds.idleFrameCounter) & 15]; + sample /= 4; + calcLoad = calcLoad/8 + sample*7/8; + } + outLoadAvgARM7 = std::min( 100, std::max(0, (u32)(calcLoad*100/1120380)) ); +} + //these templates needed to be instantiated manually template void NDS_exec(s32 nb); template void NDS_exec(s32 nb); diff --git a/desmume/src/NDSSystem.h b/desmume/src/NDSSystem.h index d4c350cb6..d72968850 100644 --- a/desmume/src/NDSSystem.h +++ b/desmume/src/NDSSystem.h @@ -462,6 +462,7 @@ void NDS_debug_continue(); void NDS_debug_step(); int NDS_GetCPUCoreCount(); +void NDS_GetCPULoadAverage(u32 &outLoadAvgARM9, u32 &outLoadAvgARM7); void NDS_SetupDefaultFirmware(); //void execHardware_doAllDma(EDMAMode modeNum); diff --git a/desmume/src/cocoa/DefaultUserPrefs.plist b/desmume/src/cocoa/DefaultUserPrefs.plist index f14c0b004..de83dcf97 100644 --- a/desmume/src/cocoa/DefaultUserPrefs.plist +++ b/desmume/src/cocoa/DefaultUserPrefs.plist @@ -110,6 +110,8 @@ HUD_ShowInput + HUD_ShowCPULoadAverage + HUD_ShowRTC Input_AudioInputMode diff --git a/desmume/src/cocoa/OGLDisplayOutput.cpp b/desmume/src/cocoa/OGLDisplayOutput.cpp index d1b86d6c6..98b6d7cf0 100644 --- a/desmume/src/cocoa/OGLDisplayOutput.cpp +++ b/desmume/src/cocoa/OGLDisplayOutput.cpp @@ -5708,12 +5708,15 @@ OGLHUDLayer::OGLHUDLayer(OGLVideoOutput *oglVO) _showRender3DFPS = false; _showFrameIndex = false; _showLagFrameCount = false; + _showCPULoadAverage = false; _showRTC = false; _lastVideoFPS = 0; _lastRender3DFPS = 0; _lastFrameIndex = 0; _lastLagFrameCount = 0; + _lastCpuLoadAvgARM9 = 0; + _lastCpuLoadAvgARM7 = 0; memset(_lastRTCString, 0, sizeof(_lastRTCString)); _textBoxLines = 0; _textBoxWidth = 0; @@ -5923,12 +5926,14 @@ void OGLHUDLayer::SetFontUsingPath(const char *filePath) glBindTexture(GL_TEXTURE_2D, 0); } -void OGLHUDLayer::SetInfo(const uint32_t videoFPS, const uint32_t render3DFPS, const uint32_t frameIndex, const uint32_t lagFrameCount, const char *rtcString) +void OGLHUDLayer::SetInfo(const uint32_t videoFPS, const uint32_t render3DFPS, const uint32_t frameIndex, const uint32_t lagFrameCount, const char *rtcString, const uint32_t cpuLoadAvgARM9, const uint32_t cpuLoadAvgARM7) { this->_lastVideoFPS = videoFPS; this->_lastRender3DFPS = render3DFPS; this->_lastFrameIndex = frameIndex; this->_lastLagFrameCount = lagFrameCount; + this->_lastCpuLoadAvgARM9 = cpuLoadAvgARM9; + this->_lastCpuLoadAvgARM7 = cpuLoadAvgARM7; memcpy(this->_lastRTCString, rtcString, sizeof(this->_lastRTCString)); this->RefreshInfo(); @@ -5981,11 +5986,26 @@ void OGLHUDLayer::RefreshInfo() } } + if (this->_showCPULoadAverage) + { + static char buffer[32]; + memset(buffer, 0, sizeof(buffer)); + snprintf(buffer, 25, "CPU Load Avg: %02d%% / %02d%%\n", this->_lastCpuLoadAvgARM9, this->_lastCpuLoadAvgARM7); + + ss << buffer; + + const GLint newTextBoxWidth = (charSize * 9.2f) + 6.5f; + if (newTextBoxWidth > this->_textBoxWidth) + { + this->_textBoxWidth = newTextBoxWidth; + } + } + if (this->_showRTC) { ss << "RTC: " << this->_lastRTCString << "\n"; - const GLint newTextBoxWidth = (charSize * 10.7f) + 6.5f; + const GLint newTextBoxWidth = (charSize * 10.8f) + 6.5f; if (newTextBoxWidth > this->_textBoxWidth) { this->_textBoxWidth = newTextBoxWidth; @@ -6056,6 +6076,16 @@ bool OGLHUDLayer::GetShowLagFrameCount() const return this->_showLagFrameCount; } +void OGLHUDLayer::SetShowCPULoadAverage(const bool visibleState) +{ + this->_SetShowInfoItemOGL(this->_showCPULoadAverage, visibleState); +} + +bool OGLHUDLayer::GetShowCPULoadAverage() const +{ + return this->_showCPULoadAverage; +} + void OGLHUDLayer::SetShowRTC(const bool visibleState) { this->_SetShowInfoItemOGL(this->_showRTC, visibleState); diff --git a/desmume/src/cocoa/OGLDisplayOutput.h b/desmume/src/cocoa/OGLDisplayOutput.h index 973d129b5..1b78fa205 100644 --- a/desmume/src/cocoa/OGLDisplayOutput.h +++ b/desmume/src/cocoa/OGLDisplayOutput.h @@ -318,12 +318,15 @@ protected: bool _showRender3DFPS; bool _showFrameIndex; bool _showLagFrameCount; + bool _showCPULoadAverage; bool _showRTC; uint32_t _lastVideoFPS; uint32_t _lastRender3DFPS; uint32_t _lastFrameIndex; uint32_t _lastLagFrameCount; + uint32_t _lastCpuLoadAvgARM9; + uint32_t _lastCpuLoadAvgARM7; char _lastRTCString[25]; GLint _textBoxLines; @@ -338,7 +341,7 @@ public: void SetFontUsingPath(const char *filePath); - void SetInfo(const uint32_t videoFPS, const uint32_t render3DFPS, const uint32_t frameIndex, const uint32_t lagFrameCount, const char *rtcString); + void SetInfo(const uint32_t videoFPS, const uint32_t render3DFPS, const uint32_t frameIndex, const uint32_t lagFrameCount, const char *rtcString, const uint32_t cpuLoadAvgARM9, const uint32_t cpuLoadAvgARM7); void RefreshInfo(); void SetShowVideoFPS(const bool visibleState); @@ -349,6 +352,8 @@ public: bool GetShowFrameIndex() const; void SetShowLagFrameCount(const bool visibleState); bool GetShowLagFrameCount() const; + void SetShowCPULoadAverage(const bool visibleState); + bool GetShowCPULoadAverage() const; void SetShowRTC(const bool visibleState); bool GetShowRTC() const; diff --git a/desmume/src/cocoa/cocoa_core.h b/desmume/src/cocoa/cocoa_core.h index f944741e2..de5dd0fed 100644 --- a/desmume/src/cocoa/cocoa_core.h +++ b/desmume/src/cocoa/cocoa_core.h @@ -51,6 +51,8 @@ struct NDSFrameInfo uint32_t render3DFPS; uint32_t frameIndex; uint32_t lagFrameCount; + uint32_t cpuLoadAvgARM9; + uint32_t cpuLoadAvgARM7; char rtcString[25]; }; @@ -72,6 +74,7 @@ typedef struct NDSFrameInfo NDSFrameInfo; std::string _slot1R4Path; NSTimer *_fpsTimer; + BOOL _isTimerAtSecond; BOOL isGdbStubStarted; BOOL isInDebugTrap; @@ -163,7 +166,7 @@ typedef struct NDSFrameInfo NDSFrameInfo; - (void) restoreCoreState; - (void) reset; -- (void) fpsUpdate:(NSTimer *)timer; +- (void) getTimedEmulatorStatistics:(NSTimer *)timer; - (NSUInteger) frameNumber; - (void) frameJumpTo:(NSUInteger)targetFrameNum; - (void) frameJump:(NSUInteger)relativeFrameNum; diff --git a/desmume/src/cocoa/cocoa_core.mm b/desmume/src/cocoa/cocoa_core.mm index b6dcc09be..bd4bad87c 100644 --- a/desmume/src/cocoa/cocoa_core.mm +++ b/desmume/src/cocoa/cocoa_core.mm @@ -145,6 +145,7 @@ volatile bool execute = true; } _fpsTimer = nil; + _isTimerAtSecond = NO; cdsController = nil; cdsFirmware = nil; @@ -682,10 +683,11 @@ volatile bool execute = true; if (_fpsTimer == nil) { + _isTimerAtSecond = NO; _fpsTimer = [[NSTimer alloc] initWithFireDate:[NSDate date] - interval:1.0 + interval:0.5 target:self - selector:@selector(fpsUpdate:) + selector:@selector(getTimedEmulatorStatistics:) userInfo:nil repeats:YES]; @@ -936,13 +938,28 @@ volatile bool execute = true; [[self cdsController] updateMicLevel]; } -- (void) fpsUpdate:(NSTimer *)timer +- (void) getTimedEmulatorStatistics:(NSTimer *)timer { + uint32_t loadAvgARM9; + uint32_t loadAvgARM7; + + pthread_rwlock_rdlock(&threadParam.rwlockCoreExecute); + NDS_GetCPULoadAverage(loadAvgARM9, loadAvgARM7); + pthread_rwlock_unlock(&threadParam.rwlockCoreExecute); + for (CocoaDSOutput *cdsOutput in cdsOutputList) { if ([cdsOutput isKindOfClass:[CocoaDSDisplay class]]) { - [(CocoaDSDisplay *)cdsOutput takeFrameCount]; + // The timer should fire every 0.5 seconds, so only take the frame + // count every other instance the timer fires. + _isTimerAtSecond = !_isTimerAtSecond; + if (_isTimerAtSecond) + { + [(CocoaDSDisplay *)cdsOutput takeFrameCount]; + } + + [(CocoaDSDisplay *)cdsOutput setCPULoadAvgARM9:loadAvgARM9 ARM7:loadAvgARM7]; } } } diff --git a/desmume/src/cocoa/cocoa_output.h b/desmume/src/cocoa/cocoa_output.h index fcf99ec52..22ee2f475 100644 --- a/desmume/src/cocoa/cocoa_output.h +++ b/desmume/src/cocoa/cocoa_output.h @@ -147,8 +147,12 @@ typedef struct uint32_t _currentReceivedFrameIndex; uint32_t _receivedFrameCount; + uint32_t _cpuLoadAvgARM9; + uint32_t _cpuLoadAvgARM7; + OSSpinLock spinlockDisplayType; OSSpinLock spinlockReceivedFrameIndex; + OSSpinLock spinlockCPULoadAverage; } @property (retain) id delegate; @@ -162,6 +166,7 @@ typedef struct - (void) handleCopyToPasteboard; - (void) takeFrameCount; +- (void) setCPULoadAvgARM9:(uint32_t)loadAvgARM9 ARM7:(uint32_t)loadAvgARM7; - (NSImage *) image; - (NSBitmapImageRep *) bitmapImageRep; diff --git a/desmume/src/cocoa/cocoa_output.mm b/desmume/src/cocoa/cocoa_output.mm index a8680fd46..2baf58bba 100644 --- a/desmume/src/cocoa/cocoa_output.mm +++ b/desmume/src/cocoa/cocoa_output.mm @@ -516,6 +516,7 @@ spinlockDisplayType = OS_SPINLOCK_INIT; spinlockReceivedFrameIndex = OS_SPINLOCK_INIT; + spinlockCPULoadAverage = OS_SPINLOCK_INIT; delegate = nil; displayMode = DS_DISPLAY_TYPE_DUAL; @@ -526,6 +527,9 @@ _currentReceivedFrameIndex = 0; _receivedFrameCount = 0; + _cpuLoadAvgARM9 = 0; + _cpuLoadAvgARM7 = 0; + [property setValue:[NSNumber numberWithInteger:displayMode] forKey:@"displayMode"]; [property setValue:NSSTRING_DISPLAYMODE_MAIN forKey:@"displayModeString"]; @@ -679,6 +683,14 @@ OSSpinLockUnlock(&spinlockReceivedFrameIndex); } +- (void) setCPULoadAvgARM9:(uint32_t)loadAvgARM9 ARM7:(uint32_t)loadAvgARM7 +{ + OSSpinLockLock(&spinlockCPULoadAverage); + _cpuLoadAvgARM9 = loadAvgARM9; + _cpuLoadAvgARM7 = loadAvgARM7; + OSSpinLockUnlock(&spinlockCPULoadAverage); +} + - (NSImage *) image { NSImage *newImage = [[NSImage alloc] initWithSize:[self displaySize]]; @@ -824,10 +836,19 @@ [super handleEmuFrameProcessed]; NDSFrameInfo frameInfo; - frameInfo.videoFPS = _receivedFrameCount; frameInfo.render3DFPS = Render3DFramesPerSecond; frameInfo.frameIndex = currFrameCounter; frameInfo.lagFrameCount = TotalLagFrames; + + OSSpinLockLock(&spinlockReceivedFrameIndex); + frameInfo.videoFPS = _receivedFrameCount; + OSSpinLockUnlock(&spinlockReceivedFrameIndex); + + OSSpinLockLock(&spinlockCPULoadAverage); + frameInfo.cpuLoadAvgARM9 = _cpuLoadAvgARM9; + frameInfo.cpuLoadAvgARM7 = _cpuLoadAvgARM7; + OSSpinLockUnlock(&spinlockCPULoadAverage); + rtcGetTimeAsString(frameInfo.rtcString); [(id)delegate doProcessVideoFrameWithInfo:frameInfo]; diff --git a/desmume/src/cocoa/translations/English.lproj/MainMenu.strings b/desmume/src/cocoa/translations/English.lproj/MainMenu.strings index 9289fc00cb28ccc31174bcf7c8f83df640d11ac6..f3ea854d85e68637f6d0ed04d032e8456c35be0c 100644 GIT binary patch delta 291 zcmaE`RdmsA(S{br7N!>F7M3ln52B|33u2X?9^NJ#IG>haiUf>5hgh+S3){nDvM-aQYJ^ zCWwiQmXi}#Na8g!L6p%<)|nxIAr$C340}=BIY|U&>U73gjMCE^iWxc7@M;BmRf)lx Hfr|kEWD`g* delta 19 acmZ3qTlB$J(S{br7N!>F7M3ln52654v YES - - + YES @@ -1660,10 +1659,9 @@ - + - YES - Input + CPU Load Average 2147483647 @@ -1677,6 +1675,15 @@ + + + YES + Input + + 2147483647 + + + @@ -3943,7 +3950,7 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXAInputPrefsView - + 268 YES @@ -3959,7 +3966,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA {{13, 10}, {463, 413}} - YES @@ -3984,7 +3990,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA268 {{72, 44}, {84, 17}} - YES @@ -4004,7 +4009,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA268 {{44, 16}, {112, 17}} - YES @@ -4024,7 +4028,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA268 {{158, 38}, {126, 26}} - YES @@ -4118,7 +4121,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA {{289, 14}, {72, 22}} - YES @@ -4212,7 +4214,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA268 {{63, 72}, {93, 17}} - YES @@ -4232,7 +4233,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA268 {{158, 66}, {126, 26}} - YES @@ -4302,7 +4302,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA268 {{158, 11}, {126, 26}} - YES @@ -4405,13 +4404,11 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA {{1, 1}, {429, 100}} - {{6, 218}, {431, 116}} - {0, 0} @@ -4453,7 +4450,6 @@ L3d3dy5hZHZhbnNjZW5lLmNvbS9vZmZsaW5lL2RhdGFzL0FEVkFOc0NFbmVfUlRvb2xEUy56aXA268 {{18, 14}, {100, 38}} - YES NO @@ -4701,13 +4697,11 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 {{1, 1}, {194, 62}} - {{15, 53}, {196, 78}} - {0, 0} @@ -4739,7 +4733,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{18, 14}, {150, 38}} - YES NO @@ -4985,13 +4978,11 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 {{1, 1}, {194, 62}} - {{218, 53}, {196, 78}} - {0, 0} @@ -5013,7 +5004,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{15, 18}, {126, 17}} - YES @@ -5033,7 +5023,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{339, 16}, {72, 22}} - YES -1804599231 @@ -5117,7 +5106,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{144, 12}, {189, 26}} - YES @@ -5141,7 +5129,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{305, 38}, {38, 11}} - YES @@ -5165,7 +5152,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{263, 38}, {38, 11}} - YES @@ -5185,7 +5171,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{220, 38}, {38, 11}} - YES @@ -5205,7 +5190,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{178, 38}, {38, 11}} - YES @@ -5225,7 +5209,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 {{137, 38}, {38, 11}} - YES @@ -5243,13 +5226,11 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 {{1, 1}, {429, 141}} - {{6, 57}, {431, 157}} - {0, 0} @@ -5269,7 +5250,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 {{10, 33}, {443, 367}} - Display Views @@ -5961,7 +5941,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 - {{15, 221}, {103, 18}} + {{15, 181}, {103, 18}} _NS:682 YES @@ -6008,6 +5988,31 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 NO + + + 268 + {{15, 221}, {184, 18}} + + _NS:682 + YES + + 67108864 + 0 + Show CPU Load Average + + _NS:682 + + 1211912448 + 2 + + + + + 200 + 25 + + NO + 12 @@ -6051,8 +6056,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 {489, 437} - - NSView @@ -20919,7 +20922,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 279 2 - {{170, 51}, {194, 210}} + {{170, 35}, {194, 226}} -461896704 HUD Settings NSPanel @@ -20927,14 +20930,14 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 {1.7976931348623157e+308, 1.7976931348623157e+308} - + 256 YES 268 - {{16, 103}, {99, 18}} + {{16, 119}, {99, 18}} YES @@ -20957,7 +20960,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 - {{16, 143}, {84, 18}} + {{16, 159}, {84, 18}} YES @@ -20980,7 +20983,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 - {{16, 63}, {60, 18}} + {{16, 39}, {60, 18}} YES @@ -21003,7 +21006,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 - {{16, 123}, {121, 18}} + {{16, 139}, {121, 18}} YES @@ -21026,7 +21029,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 - {{16, 83}, {98, 18}} + {{16, 99}, {98, 18}} YES @@ -21049,7 +21052,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 - {{16, 43}, {121, 18}} + {{16, 59}, {121, 18}} YES @@ -21069,10 +21072,33 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 NO + + + 268 + {{17, 79}, {130, 18}} + + YES + + 67108864 + 131072 + CPU Load Average + + + 1211912448 + 2 + + + + + 200 + 25 + + NO + 268 - {{16, 13}, {162, 19}} + {{16, 11}, {162, 19}} YES @@ -21093,7 +21119,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 268 - {{16, 174}, {167, 18}} + {{16, 190}, {167, 18}} YES @@ -21116,7 +21142,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 12 - {{12, 165}, {170, 5}} + {{12, 181}, {170, 5}} {0, 0} @@ -21133,8 +21159,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 NO - {194, 210} - + {194, 226} {{0, 0}, {1920, 1177}} {1.7976931348623157e+308, 1.7976931348623157e+308} @@ -29814,6 +29839,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 mainWindow.view.isHUDFrameIndexVisible mainWindow.view.isHUDLagFrameCountVisible mainWindow.view.isHUDRealTimeClockVisible + mainWindow.view.isHUDCPULoadAverageVisible EmuControllerDelegate @@ -30083,10 +30109,6 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 YES - - YES - HUD_ShowRTC - YES @@ -42692,6 +42714,46 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 10189 + + + value: selection.mainWindow.view.isHUDCPULoadAverageVisible + + + + + + value: selection.mainWindow.view.isHUDCPULoadAverageVisible + value + selection.mainWindow.view.isHUDCPULoadAverageVisible + 2 + + + 10194 + + + + toggleShowHUDCPULoadAverage: + + + + 10195 + + + + value: values.HUD_ShowCPULoadAverage + + + + + + value: values.HUD_ShowCPULoadAverage + value + values.HUD_ShowCPULoadAverage + 2 + + + 10199 + @@ -43232,6 +43294,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 + @@ -57605,10 +57668,11 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 YES - + + @@ -57664,6 +57728,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 + @@ -57770,6 +57835,39 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 + + 10190 + + + + + 10191 + + + YES + + + + + + 10192 + + + + + 10196 + + + YES + + + + + + 10197 + + + @@ -57902,6 +58000,13 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 10179.IBPluginDependency 10179.IBViewBoundsToFrameTransform 10180.IBPluginDependency + 10190.IBPluginDependency + 10191.IBPluginDependency + 10191.IBViewBoundsToFrameTransform + 10192.IBPluginDependency + 10196.IBPluginDependency + 10196.IBViewBoundsToFrameTransform + 10197.IBPluginDependency 1034.IBPluginDependency 1035.IBPluginDependency 1036.IBPluginDependency @@ -60337,7 +60442,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{603, 622}, {181, 123}} + {{603, 602}, {181, 143}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -60378,7 +60483,18 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - P4AAAL+AAABBcAAAw1kAAA + P4AAAL+AAABBcAAAw20AAA + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABBiAAAwvQAAA + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + + P4AAAL+AAABBcAAAw20AAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -60472,7 +60588,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{66, 482}, {489, 437}} + {{372, 123}, {489, 437}} {796.5, 896.5} com.apple.InterfaceBuilder.CocoaPlugin @@ -62763,9 +62879,9 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{703, 808}, {194, 210}} + {{703, 792}, {194, 226}} com.apple.InterfaceBuilder.CocoaPlugin - {{703, 808}, {194, 210}} + {{703, 792}, {194, 226}} YES @@ -62988,7 +63104,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - P4AAAL+AAABBgAAAwmwAAA + P4AAAL+AAABBgAAAwswAAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -63752,7 +63868,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 - 10189 + 10199 @@ -64281,6 +64397,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 toggleFullScreenDisplay: toggleHUDVisibility: toggleKeepMinDisplaySizeAtNormal: + toggleShowHUDCPULoadAverage: toggleShowHUDFrameIndex: toggleShowHUDInput: toggleShowHUDLagFrameCount: @@ -64333,6 +64450,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 id id id + id @@ -64360,6 +64478,7 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 toggleFullScreenDisplay: toggleHUDVisibility: toggleKeepMinDisplaySizeAtNormal: + toggleShowHUDCPULoadAverage: toggleShowHUDFrameIndex: toggleShowHUDInput: toggleShowHUDLagFrameCount: @@ -64461,6 +64580,10 @@ y7bMNcy1zTXNtc42zrbPN8+40DnQutE80b7SP9LB00TTxtRJ1MvVTtXR1lXW2Ndc1+DYZNjo2WzZ8dp2 toggleKeepMinDisplaySizeAtNormal: id + + toggleShowHUDCPULoadAverage: + id + toggleShowHUDFrameIndex: id diff --git a/desmume/src/cocoa/userinterface/DisplayWindowController.h b/desmume/src/cocoa/userinterface/DisplayWindowController.h index 6fce7a689..be2662705 100644 --- a/desmume/src/cocoa/userinterface/DisplayWindowController.h +++ b/desmume/src/cocoa/userinterface/DisplayWindowController.h @@ -60,6 +60,7 @@ class OGLVideoOutput; @property (assign) BOOL isHUDRender3DFPSVisible; @property (assign) BOOL isHUDFrameIndexVisible; @property (assign) BOOL isHUDLagFrameCountVisible; +@property (assign) BOOL isHUDCPULoadAverageVisible; @property (assign) BOOL isHUDRealTimeClockVisible; @property (assign) BOOL useVerticalSync; @property (assign) BOOL videoFiltersPreferGPU; @@ -188,6 +189,7 @@ class OGLVideoOutput; - (IBAction) toggleShowHUDFrameIndex:(id)sender; - (IBAction) toggleShowHUDLagFrameCount:(id)sender; - (IBAction) toggleShowHUDInput:(id)sender; +- (IBAction) toggleShowHUDCPULoadAverage:(id)sender; - (IBAction) toggleShowHUDRealTimeClock:(id)sender; - (IBAction) toggleKeepMinDisplaySizeAtNormal:(id)sender; - (IBAction) toggleStatusBar:(id)sender; diff --git a/desmume/src/cocoa/userinterface/DisplayWindowController.mm b/desmume/src/cocoa/userinterface/DisplayWindowController.mm index 96a8dc613..0727e8ab0 100644 --- a/desmume/src/cocoa/userinterface/DisplayWindowController.mm +++ b/desmume/src/cocoa/userinterface/DisplayWindowController.mm @@ -740,6 +740,11 @@ static std::unordered_map _screenMap; // //[[self view] setIsHUDInputVisible:![[self view] isHUDInputVisible]]; } +- (IBAction) toggleShowHUDCPULoadAverage:(id)sender +{ + [[self view] setIsHUDCPULoadAverageVisible:![[self view] isHUDCPULoadAverageVisible]]; +} + - (IBAction) toggleShowHUDRealTimeClock:(id)sender { [[self view] setIsHUDRealTimeClockVisible:![[self view] isHUDRealTimeClockVisible]]; @@ -935,6 +940,7 @@ static std::unordered_map _screenMap; // [[NSUserDefaults standardUserDefaults] setBool:[[self view] isHUDRender3DFPSVisible] forKey:@"HUD_ShowRender3DFPS"]; [[NSUserDefaults standardUserDefaults] setBool:[[self view] isHUDFrameIndexVisible] forKey:@"HUD_ShowFrameIndex"]; [[NSUserDefaults standardUserDefaults] setBool:[[self view] isHUDLagFrameCountVisible] forKey:@"HUD_ShowLagFrameCount"]; + [[NSUserDefaults standardUserDefaults] setBool:[[self view] isHUDCPULoadAverageVisible] forKey:@"HUD_ShowCPULoadAverage"]; [[NSUserDefaults standardUserDefaults] setBool:[[self view] isHUDRealTimeClockVisible] forKey:@"HUD_ShowRTC"]; // TODO: Show HUD Input. //[[NSUserDefaults standardUserDefaults] setBool:[[self view] isHUDInputVisible] forKey:@"HUD_ShowInput"]; @@ -1122,6 +1128,13 @@ static std::unordered_map _screenMap; // [(NSMenuItem *)theItem setState:([[self view] isHUDLagFrameCountVisible]) ? NSOnState : NSOffState]; } } + else if (theAction == @selector(toggleShowHUDCPULoadAverage:)) + { + if ([(id)theItem isMemberOfClass:[NSMenuItem class]]) + { + [(NSMenuItem *)theItem setState:([[self view] isHUDCPULoadAverageVisible]) ? NSOnState : NSOffState]; + } + } else if (theAction == @selector(toggleShowHUDRealTimeClock:)) { if ([(id)theItem isMemberOfClass:[NSMenuItem class]]) @@ -1378,6 +1391,7 @@ static std::unordered_map _screenMap; // @dynamic isHUDRender3DFPSVisible; @dynamic isHUDFrameIndexVisible; @dynamic isHUDLagFrameCountVisible; +@dynamic isHUDCPULoadAverageVisible; @dynamic isHUDRealTimeClockVisible; @dynamic useVerticalSync; @dynamic videoFiltersPreferGPU; @@ -1593,6 +1607,28 @@ static std::unordered_map _screenMap; // return theState; } +- (void) setIsHUDCPULoadAverageVisible:(BOOL)theState +{ + OSSpinLockLock(&spinlockIsHUDVisible); + + CGLLockContext(cglDisplayContext); + CGLSetCurrentContext(cglDisplayContext); + oglv->GetHUDLayer()->SetShowCPULoadAverage((theState) ? true : false); + [self drawVideoFrame]; + CGLUnlockContext(cglDisplayContext); + + OSSpinLockUnlock(&spinlockIsHUDVisible); +} + +- (BOOL) isHUDCPULoadAverageVisible +{ + OSSpinLockLock(&spinlockIsHUDVisible); + const BOOL theState = (oglv->GetHUDLayer()->GetShowCPULoadAverage()) ? YES : NO; + OSSpinLockUnlock(&spinlockIsHUDVisible); + + return theState; +} + - (void) setIsHUDRealTimeClockVisible:(BOOL)theState { OSSpinLockLock(&spinlockIsHUDVisible); @@ -2076,7 +2112,9 @@ static std::unordered_map _screenMap; // frameInfo.render3DFPS, frameInfo.frameIndex, frameInfo.lagFrameCount, - frameInfo.rtcString); + frameInfo.rtcString, + frameInfo.cpuLoadAvgARM9, + frameInfo.cpuLoadAvgARM7); hudLayer->ProcessOGL(); } diff --git a/desmume/src/cocoa/userinterface/appDelegate.mm b/desmume/src/cocoa/userinterface/appDelegate.mm index 3dca10d2d..0128b26a5 100644 --- a/desmume/src/cocoa/userinterface/appDelegate.mm +++ b/desmume/src/cocoa/userinterface/appDelegate.mm @@ -632,6 +632,7 @@ const BOOL hudShowRender3DFPS = [(NSNumber *)[windowProperties valueForKey:@"hudShowRender3DFPS"] boolValue]; const BOOL hudShowFrameIndex = [(NSNumber *)[windowProperties valueForKey:@"hudShowFrameIndex"] boolValue]; const BOOL hudShowLagFrameCount = [(NSNumber *)[windowProperties valueForKey:@"hudShowLagFrameCount"] boolValue]; + const BOOL hudShowCPULoadAverage = [(NSNumber *)[windowProperties valueForKey:@"hudShowCPULoadAverage"] boolValue]; const BOOL hudShowRTC = [(NSNumber *)[windowProperties valueForKey:@"hudShowRTC"] boolValue]; // TODO: Show HUD Input. //const BOOL hudShowInput = [(NSNumber *)[windowProperties valueForKey:@"hudShowInput"] boolValue]; @@ -670,6 +671,7 @@ [[windowController view] setIsHUDRender3DFPSVisible:hudShowRender3DFPS]; [[windowController view] setIsHUDFrameIndexVisible:hudShowFrameIndex]; [[windowController view] setIsHUDLagFrameCountVisible:hudShowLagFrameCount]; + [[windowController view] setIsHUDCPULoadAverageVisible:hudShowCPULoadAverage]; [[windowController view] setIsHUDRealTimeClockVisible:hudShowRTC]; [[windowController masterWindow] setFrameOrigin:NSMakePoint(frameX, frameY)]; @@ -742,6 +744,7 @@ [NSNumber numberWithBool:[[windowController view] isHUDRender3DFPSVisible]], @"hudShowRender3DFPS", [NSNumber numberWithBool:[[windowController view] isHUDFrameIndexVisible]], @"hudShowFrameIndex", [NSNumber numberWithBool:[[windowController view] isHUDLagFrameCountVisible]], @"hudShowLagFrameCount", + [NSNumber numberWithBool:[[windowController view] isHUDCPULoadAverageVisible]], @"hudShowCPULoadAverage", [NSNumber numberWithBool:[[windowController view] isHUDRealTimeClockVisible]], @"hudShowRTC", [NSNumber numberWithBool:[windowController isMinSizeNormal]], @"isMinSizeNormal", [NSNumber numberWithBool:[windowController isShowingStatusBar]], @"isShowingStatusBar", diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index d13cee1ef..d1e462ce0 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -2208,28 +2208,12 @@ static void StepRunLoop_User() if(nds.idleFrameCounter==0 || oneSecond) { - //calculate a 16 frame arm9 load average - for(int cpu=0;cpu<2;cpu++) - { - int load = 0; - //printf("%d: ",cpu); - for(int i=0;i<16;i++) - { - //blend together a few frames to keep low-framerate games from having a jittering load average - //(they will tend to work 100% for a frame and then sleep for a while) - //4 frames should handle even the slowest of games - s32 sample = - nds.runCycleCollector[cpu][(i+0+nds.idleFrameCounter)&15] - + nds.runCycleCollector[cpu][(i+1+nds.idleFrameCounter)&15] - + nds.runCycleCollector[cpu][(i+2+nds.idleFrameCounter)&15] - + nds.runCycleCollector[cpu][(i+3+nds.idleFrameCounter)&15]; - sample /= 4; - load = load/8 + sample*7/8; - } - //printf("\n"); - load = std::min(100,std::max(0,(int)(load*100/1120380))); - Hud.cpuload[cpu] = load; - } + u32 loadAvgARM9; + u32 loadAvgARM7; + NDS_GetCPULoadAverage(loadAvgARM9, loadAvgARM7); + + Hud.cpuload[ARMCPU_ARM9] = (int)loadAvgARM9; + Hud.cpuload[ARMCPU_ARM7] = (int)loadAvgARM7; } Hud.cpuloopIterationCount = nds.cpuloopIterationCount;