From 90c8411cbfb8f6cae50e181e8c6b52f6b147c443 Mon Sep 17 00:00:00 2001 From: rogerman Date: Tue, 28 Feb 2023 01:34:27 -0800 Subject: [PATCH] GFX3D: Fix clear color on big-endian systems. (Regression from commit 97848fc.) --- desmume/src/MMU.cpp | 8 ++++---- desmume/src/gfx3d.cpp | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/desmume/src/MMU.cpp b/desmume/src/MMU.cpp index 97200fddb..be6a874c3 100644 --- a/desmume/src/MMU.cpp +++ b/desmume/src/MMU.cpp @@ -3665,22 +3665,22 @@ void FASTCALL _MMU_ARM9_write08(u32 adr, u8 val) case REG_IF+3: REG_IF_WriteByte(3,val); break; case eng_3D_CLEAR_COLOR: - HostWriteByte(MMU.ARM9_REG, 0x0350, val); + T1WriteByte(MMU.ARM9_REG, 0x0350, val); gfx3d_glClearColor(0, val); return; case eng_3D_CLEAR_COLOR+1: - HostWriteByte(MMU.ARM9_REG, 0x0351, val); + T1WriteByte(MMU.ARM9_REG, 0x0351, val); gfx3d_glClearColor(1, val); return; case eng_3D_CLEAR_COLOR+2: - HostWriteByte(MMU.ARM9_REG, 0x0352, val); + T1WriteByte(MMU.ARM9_REG, 0x0352, val); gfx3d_glClearColor(2, val); return; case eng_3D_CLEAR_COLOR+3: - HostWriteByte(MMU.ARM9_REG, 0x0353, val); + T1WriteByte(MMU.ARM9_REG, 0x0353, val); gfx3d_glClearColor(3, val); return; diff --git a/desmume/src/gfx3d.cpp b/desmume/src/gfx3d.cpp index f4379b278..4a0bc2cf4 100644 --- a/desmume/src/gfx3d.cpp +++ b/desmume/src/gfx3d.cpp @@ -2809,7 +2809,27 @@ void gfx3d_glFogOffset(const u32 v) template void gfx3d_glClearColor(const u8 offset, const T v) { +#ifndef MSB_FIRST ((T *)&gfx3d.pendingState.clearColor)[offset >> (sizeof(T) >> 1)] = v; +#else + switch (sizeof(T)) + { + case 1: + ((T *)&gfx3d.pendingState.clearColor)[offset >> (sizeof(T) >> 1)] = v; + break; + + case 2: + ((T *)&gfx3d.pendingState.clearColor)[offset >> (sizeof(T) >> 1)] = LE_TO_LOCAL_16(v); + break; + + case 4: + ((T *)&gfx3d.pendingState.clearColor)[offset >> (sizeof(T) >> 1)] = LE_TO_LOCAL_32(v); + break; + + default: + break; + } +#endif } template void gfx3d_glClearColor< u8>(const u8 offset, const u8 v);