From ba6e8e0babbb54833449c8d47dcdf9e01b12f4a4 Mon Sep 17 00:00:00 2001 From: rogerman Date: Mon, 16 Oct 2017 17:03:01 -0700 Subject: [PATCH] Cocoa Port: Fix a bunch of HUD coloring issues on PowerPC Macs. - Also fix a display backlight intensity issue on big-endian systems. --- desmume/src/GPU.h | 4 ++-- .../src/frontend/cocoa/ClientDisplayView.cpp | 24 +++++++++---------- .../src/frontend/cocoa/ClientInputHandler.cpp | 2 +- desmume/src/frontend/cocoa/cocoa_util.mm | 16 +++++++++++++ .../src/frontend/cocoa/macosx_10_5_compat.cpp | 4 ++-- .../userinterface/DisplayWindowController.mm | 12 +++++----- 6 files changed, 39 insertions(+), 23 deletions(-) diff --git a/desmume/src/GPU.h b/desmume/src/GPU.h index 113f5da1d..0c6fdc81b 100644 --- a/desmume/src/GPU.h +++ b/desmume/src/GPU.h @@ -777,11 +777,11 @@ typedef union u8 MainBacklight_Enable:1; // 3: Main display backlight; 0=Disable, 1=Enable u8 PowerLEDBlink_Enable:1; // 4: Power LED blink control; 0=Disable (Power LED remains steadily ON), 1=Enable u8 PowerLEDBlinkSpeed:1; // 5: Power LED blink speed when enabled; 0=Slow, 1=Fast - u8 SystemPowerState:2; // 6: NDS system power state; 0=System is powered ON, 1=System is powered OFF + u8 SystemPowerState:1; // 6: NDS system power state; 0=System is powered ON, 1=System is powered OFF u8 :1; // 7: Unused bit (should always be read as 0) #else u8 :1; // 7: Unused bit (should always be read as 0) - u8 SystemPowerState:2; // 6: NDS system power state; 0=System is powered ON, 1=System is powered OFF + u8 SystemPowerState:1; // 6: NDS system power state; 0=System is powered ON, 1=System is powered OFF u8 PowerLEDBlinkSpeed:1; // 5: Power LED blink speed when enabled; 0=Slow, 1=Fast u8 PowerLEDBlink_Enable:1; // 4: Power LED blink control; 0=Disable (LED is steady ON), 1=Enable u8 MainBacklight_Enable:1; // 3: Main display backlight; 0=Disable, 1=Enable diff --git a/desmume/src/frontend/cocoa/ClientDisplayView.cpp b/desmume/src/frontend/cocoa/ClientDisplayView.cpp index e3d61feeb..a0792e732 100644 --- a/desmume/src/frontend/cocoa/ClientDisplayView.cpp +++ b/desmume/src/frontend/cocoa/ClientDisplayView.cpp @@ -89,15 +89,15 @@ void ClientDisplayPresenter::__InstanceInit(const ClientDisplayPresenterProperti _showRTC = false; _showInputs = false; - _hudColorVideoFPS = 0xFFFFFFFF; - _hudColorRender3DFPS = 0xFFFFFFFF; - _hudColorFrameIndex = 0xFFFFFFFF; - _hudColorLagFrameCount = 0xFFFFFFFF; - _hudColorCPULoadAverage = 0xFFFFFFFF; - _hudColorRTC = 0xFFFFFFFF; - _hudColorInputAppliedAndPending = 0xFFFFFFFF; - _hudColorInputAppliedOnly = 0xFF3030FF; - _hudColorInputPendingOnly = 0xFF00C000; + _hudColorVideoFPS = LE_TO_LOCAL_32(0xFFFFFFFF); + _hudColorRender3DFPS = LE_TO_LOCAL_32(0xFFFFFFFF); + _hudColorFrameIndex = LE_TO_LOCAL_32(0xFFFFFFFF); + _hudColorLagFrameCount = LE_TO_LOCAL_32(0xFFFFFFFF); + _hudColorCPULoadAverage = LE_TO_LOCAL_32(0xFFFFFFFF); + _hudColorRTC = LE_TO_LOCAL_32(0xFFFFFFFF); + _hudColorInputAppliedAndPending = LE_TO_LOCAL_32(0xFFFFFFFF); + _hudColorInputAppliedOnly = LE_TO_LOCAL_32(0xFF3030FF); + _hudColorInputPendingOnly = LE_TO_LOCAL_32(0xFF00C000); _clientFrameInfo.videoFPS = 0; _ndsFrameInfo.clear(); @@ -755,7 +755,7 @@ uint32_t ClientDisplayPresenter::GetInputColorUsingStates(bool pendingState, boo } else { - color = 0x80808080; + color = LE_TO_LOCAL_32(0x80808080); } return color; @@ -1785,7 +1785,7 @@ void ClientDisplay3DPresenter::SetHUDColorVertices(uint32_t *vtxColorBufferPtr) const char *cString = hudString.c_str(); const size_t textLength = (hudString.length() <= HUD_TEXT_MAX_CHARACTERS) ? hudString.length() : HUD_TEXT_MAX_CHARACTERS; - uint32_t currentColor = 0x40000000; + uint32_t currentColor = LE_TO_LOCAL_32(0x40000000); // First, calculate the color of the text box. // The text box should always be the first character in the string. @@ -1917,7 +1917,7 @@ void ClientDisplay3DPresenter::SetHUDColorVertices(uint32_t *vtxColorBufferPtr) vtxColorBufferPtr[j+3] = inputColors[k]; // Bottom Left } - touchColor = ((this->_ndsFrameInfo.inputStatesPending.Touch != 0) && (this->_ndsFrameInfo.inputStatesApplied.Touch != 0)) ? 0x00000000 : (touchColor & 0x00FFFFFF) | (0x60000000); + touchColor = ((this->_ndsFrameInfo.inputStatesPending.Touch != 0) && (this->_ndsFrameInfo.inputStatesApplied.Touch != 0)) ? 0x00000000 : (touchColor & LE_TO_LOCAL_32(0x00FFFFFF)) | LE_TO_LOCAL_32(0x60000000); for (size_t k = 0; k < HUD_INPUT_TOUCH_LINE_ELEMENTS; i++, j+=4, k++) { diff --git a/desmume/src/frontend/cocoa/ClientInputHandler.cpp b/desmume/src/frontend/cocoa/ClientInputHandler.cpp index 0d4484979..5f3eeaa71 100644 --- a/desmume/src/frontend/cocoa/ClientInputHandler.cpp +++ b/desmume/src/frontend/cocoa/ClientInputHandler.cpp @@ -227,7 +227,7 @@ void ClientInputHandler::SetClientInputStateUsingID(NDSInputID inputID, bool pre if (this->_execControl != NULL) { NDSFrameInfo &frameInfoMutable = (NDSFrameInfo &)this->_execControl->GetNDSFrameInfo(); - const uint64_t bitValue = (1 << this->_inputStateBitMap[inputID]); + const uint64_t bitValue = LOCAL_TO_LE_64(1ULL << this->_inputStateBitMap[inputID]); frameInfoMutable.inputStatesPending.value = (this->_clientInputPending[inputID].isPressed) ? frameInfoMutable.inputStatesPending.value & ~bitValue : frameInfoMutable.inputStatesPending.value | bitValue; } diff --git a/desmume/src/frontend/cocoa/cocoa_util.mm b/desmume/src/frontend/cocoa/cocoa_util.mm index ece192fd0..fcbbcd9b3 100644 --- a/desmume/src/frontend/cocoa/cocoa_util.mm +++ b/desmume/src/frontend/cocoa/cocoa_util.mm @@ -158,10 +158,17 @@ static NSDate *distantFutureDate = [[NSDate distantFuture] retain]; + (NSColor *) NSColorFromRGBA8888:(uint32_t)theColor { +#ifdef MSB_FIRST + const CGFloat a = (CGFloat)((theColor >> 0) & 0xFF) / 255.0f; + const CGFloat b = (CGFloat)((theColor >> 8) & 0xFF) / 255.0f; + const CGFloat g = (CGFloat)((theColor >> 16) & 0xFF) / 255.0f; + const CGFloat r = (CGFloat)((theColor >> 24) & 0xFF) / 255.0f; +#else const CGFloat r = (CGFloat)((theColor >> 0) & 0xFF) / 255.0f; const CGFloat g = (CGFloat)((theColor >> 8) & 0xFF) / 255.0f; const CGFloat b = (CGFloat)((theColor >> 16) & 0xFF) / 255.0f; const CGFloat a = (CGFloat)((theColor >> 24) & 0xFF) / 255.0f; +#endif return [NSColor colorWithDeviceRed:r green:g blue:b alpha:a]; } @@ -180,10 +187,17 @@ static NSDate *distantFutureDate = [[NSDate distantFuture] retain]; CGFloat r, g, b, a; [theColor getRed:&r green:&g blue:&b alpha:&a]; +#ifdef MSB_FIRST + return (((uint32_t)(a * 255.0f)) << 0) | + (((uint32_t)(b * 255.0f)) << 8) | + (((uint32_t)(g * 255.0f)) << 16) | + (((uint32_t)(r * 255.0f)) << 24); +#else return (((uint32_t)(r * 255.0f)) << 0) | (((uint32_t)(g * 255.0f)) << 8) | (((uint32_t)(b * 255.0f)) << 16) | (((uint32_t)(a * 255.0f)) << 24); +#endif } + (NSInteger) appVersionNumeric @@ -425,6 +439,7 @@ static NSDate *distantFutureDate = [[NSDate distantFuture] retain]; [NSException raise:NSInternalInconsistencyException format:@"Value (%@) does not respond to -unsignedIntegerValue, -unsignedIntValue, -integerValue or -intValue.", [value class]]; } + color32 = LE_TO_LOCAL_32(color32); return [CocoaDSUtil NSColorFromRGBA8888:color32]; } @@ -443,6 +458,7 @@ static NSDate *distantFutureDate = [[NSDate distantFuture] retain]; } color32 = [CocoaDSUtil RGBA8888FromNSColor:(NSColor *)value]; + color32 = LE_TO_LOCAL_32(color32); return [NSNumber numberWithUnsignedInteger:color32]; } diff --git a/desmume/src/frontend/cocoa/macosx_10_5_compat.cpp b/desmume/src/frontend/cocoa/macosx_10_5_compat.cpp index 5e07eb109..86c77d632 100644 --- a/desmume/src/frontend/cocoa/macosx_10_5_compat.cpp +++ b/desmume/src/frontend/cocoa/macosx_10_5_compat.cpp @@ -1,5 +1,5 @@ /* - Copyright (C) 2013-2015 DeSmuME team + Copyright (C) 2013-2017 DeSmuME team This file is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ #include -#if MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5 +#if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED <= MAC_OS_X_VERSION_10_5) #include #include diff --git a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm index cc124b33d..271e874a8 100644 --- a/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm +++ b/desmume/src/frontend/cocoa/userinterface/DisplayWindowController.mm @@ -493,12 +493,12 @@ static std::unordered_map _screenMap; // [[self view] setIsHUDRealTimeClockVisible:[[NSUserDefaults standardUserDefaults] boolForKey:@"HUD_ShowRTC"]]; [[self view] setIsHUDInputVisible:[[NSUserDefaults standardUserDefaults] boolForKey:@"HUD_ShowInput"]]; - [[self view] setHudColorVideoFPS:[CocoaDSUtil NSColorFromRGBA8888:[[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_VideoFPS"]]]; - [[self view] setHudColorRender3DFPS:[CocoaDSUtil NSColorFromRGBA8888:[[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_Render3DFPS"]]]; - [[self view] setHudColorFrameIndex:[CocoaDSUtil NSColorFromRGBA8888:[[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_FrameIndex"]]]; - [[self view] setHudColorLagFrameCount:[CocoaDSUtil NSColorFromRGBA8888:[[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_LagFrameCount"]]]; - [[self view] setHudColorCPULoadAverage:[CocoaDSUtil NSColorFromRGBA8888:[[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_CPULoadAverage"]]]; - [[self view] setHudColorRTC:[CocoaDSUtil NSColorFromRGBA8888:[[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_RTC"]]]; + [[self view] setHudColorVideoFPS:[CocoaDSUtil NSColorFromRGBA8888:LE_TO_LOCAL_32([[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_VideoFPS"])]]; + [[self view] setHudColorRender3DFPS:[CocoaDSUtil NSColorFromRGBA8888:LE_TO_LOCAL_32([[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_Render3DFPS"])]]; + [[self view] setHudColorFrameIndex:[CocoaDSUtil NSColorFromRGBA8888:LE_TO_LOCAL_32([[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_FrameIndex"])]]; + [[self view] setHudColorLagFrameCount:[CocoaDSUtil NSColorFromRGBA8888:LE_TO_LOCAL_32([[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_LagFrameCount"])]]; + [[self view] setHudColorCPULoadAverage:[CocoaDSUtil NSColorFromRGBA8888:LE_TO_LOCAL_32([[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_CPULoadAverage"])]]; + [[self view] setHudColorRTC:[CocoaDSUtil NSColorFromRGBA8888:LE_TO_LOCAL_32([[NSUserDefaults standardUserDefaults] integerForKey:@"HUD_Color_RTC"])]]; } - (BOOL) masterStatusBarState