GFX3D: Clean up the big-endian compatibility code.

This commit is contained in:
rogerman 2023-03-03 13:58:37 -08:00
parent 111292ff15
commit 56251cafd1
3 changed files with 25 additions and 63 deletions

View File

@ -1198,16 +1198,8 @@ void NDSGeometryEngine::SetLightColor(const u32 param)
void NDSGeometryEngine::SetShininess(const u32 param)
{
#ifdef MSB_FIRST
u8 *targetShininess = (u8 *)this->_shininessTablePending;
targetShininess[this->_shininessTablePendingIndex+0] = (u8)(param & 0x000000FF);
targetShininess[this->_shininessTablePendingIndex+1] = (u8)(((param >> 8) & 0x000000FF));
targetShininess[this->_shininessTablePendingIndex+2] = (u8)(((param >> 16) & 0x000000FF));
targetShininess[this->_shininessTablePendingIndex+3] = (u8)(((param >> 24) & 0x000000FF));
#else
u32 &targetShininess = (u32 &)this->_shininessTablePending[this->_shininessTablePendingIndex];
targetShininess = param;
#endif
targetShininess = LE_TO_LOCAL_32(param);
this->_shininessTablePendingIndex += 4;
@ -1403,11 +1395,8 @@ void NDSGeometryEngine::SetTexturePalette(const u32 texPalette)
void NDSGeometryEngine::SetTextureCoordinates2s16(const u32 param)
{
Vector2s16 inTexCoord2s16;
#ifndef MSB_FIRST
inTexCoord2s16.value = param;
#else
inTexCoord2s16.value = (param << 16) | (param >> 16);
#endif
inTexCoord2s16.value = LE_TO_LOCAL_WORDS_32(param);
this->SetTextureCoordinates2s16(inTexCoord2s16);
}
@ -1450,11 +1439,8 @@ void NDSGeometryEngine::VertexListEnd()
bool NDSGeometryEngine::SetCurrentVertexPosition2s16(const u32 param)
{
Vector2s16 inVtxCoord2s16;
#ifndef MSB_FIRST
inVtxCoord2s16.value = param;
#else
inVtxCoord2s16.value = (param >> 16) | (param << 16);
#endif
inVtxCoord2s16.value = LE_TO_LOCAL_WORDS_32(param);
return this->SetCurrentVertexPosition2s16(inVtxCoord2s16);
}
@ -1492,11 +1478,7 @@ template <size_t ONE, size_t TWO>
void NDSGeometryEngine::SetCurrentVertexPosition2s16Immediate(const u32 param)
{
Vector2s16 inVtxCoord2s16;
#ifndef MSB_FIRST
inVtxCoord2s16.value = param;
#else
inVtxCoord2s16.value = (param >> 16) | (param << 16);
#endif
inVtxCoord2s16.value = LE_TO_LOCAL_WORDS_32(param);
this->SetCurrentVertexPosition2s16Immediate<ONE, TWO>(inVtxCoord2s16);
}
@ -2805,27 +2787,7 @@ void gfx3d_glFogOffset(const u32 v)
template <typename T>
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);

View File

@ -702,10 +702,9 @@ Render3DError Render3D::Render(const GFX3D_State &renderState, const GFX3D_Geome
Render3DError error = RENDER3DERROR_NOERR;
this->_isPoweredOn = true;
const u32 clearColorSwapped = LE_TO_LOCAL_32(renderState.clearColor);
this->_clearColor6665.value = LE_TO_LOCAL_32( COLOR555TO6665(clearColorSwapped & 0x7FFF, (clearColorSwapped >> 16) & 0x1F) );
this->_clearColor6665.value = LE_TO_LOCAL_32( COLOR555TO6665(renderState.clearColor & 0x7FFF, (renderState.clearColor >> 16) & 0x1F) );
this->_clearAttributes.opaquePolyID = (renderState.clearColor >> 24) & 0x3F;
this->_clearAttributes.opaquePolyID = (clearColorSwapped >> 24) & 0x3F;
//special value for uninitialized translucent polyid. without this, fires in spiderman2 dont display
//I am not sure whether it is right, though. previously this was cleared to 0, as a guess,
//but in spiderman2 some fires with polyid 0 try to render on top of the background
@ -714,7 +713,7 @@ Render3DError Render3D::Render(const GFX3D_State &renderState, const GFX3D_Geome
this->_clearAttributes.stencil = 0;
this->_clearAttributes.isTranslucentPoly = 0;
this->_clearAttributes.polyFacing = PolyFacing_Unwritten;
this->_clearAttributes.isFogged = BIT15(clearColorSwapped);
this->_clearAttributes.isFogged = BIT15(renderState.clearColor);
error = this->BeginRender(renderState, renderGList);
if (error != RENDER3DERROR_NOERR)

View File

@ -709,23 +709,24 @@ enum BESwapFlags
BESwapSrcDst = 0x03 // An alternate name for "BESwapInOut"
};
/* little endian (ds' endianess) to local endianess convert macros */
#ifdef MSB_FIRST /* local arch is big endian */
# define LE_TO_LOCAL_16(x) ((((x)&0xff)<<8)|(((x)>>8)&0xff))
# define LE_TO_LOCAL_32(x) ((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)>>8)&0xff00)|(((x)>>24)&0xff))
# define LE_TO_LOCAL_64(x) ((((x)&0xff)<<56)|(((x)&0xff00)<<40)|(((x)&0xff0000)<<24)|(((x)&0xff000000)<<8)|(((x)>>8)&0xff000000)|(((x)>>24)&0xff0000)|(((x)>>40)&0xff00)|(((x)>>56)&0xff))
# define LOCAL_TO_LE_16(x) ((((x)&0xff)<<8)|(((x)>>8)&0xff))
# define LOCAL_TO_LE_32(x) ((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)>>8)&0xff00)|(((x)>>24)&0xff))
# define LOCAL_TO_LE_64(x) ((((x)&0xff)<<56)|(((x)&0xff00)<<40)|(((x)&0xff0000)<<24)|(((x)&0xff000000)<<8)|(((x)>>8)&0xff000000)|(((x)>>24)&0xff0000)|(((x)>>40)&0xff00)|(((x)>>56)&0xff))
#else /* local arch is little endian */
# define LE_TO_LOCAL_16(x) (x)
# define LE_TO_LOCAL_32(x) (x)
# define LE_TO_LOCAL_64(x) (x)
# define LOCAL_TO_LE_16(x) (x)
# define LOCAL_TO_LE_32(x) (x)
# define LOCAL_TO_LE_64(x) (x)
// little endian (ds' endianess) to local endianess convert macros
#ifdef MSB_FIRST // local arch is big endian
#define LE_TO_LOCAL_16(x) ((((x)&0xff)<<8)|(((x)>>8)&0xff))
#define LE_TO_LOCAL_32(x) ((((x)&0xff)<<24)|(((x)&0xff00)<<8)|(((x)>>8)&0xff00)|(((x)>>24)&0xff))
#define LE_TO_LOCAL_64(x) ((((x)&0xff)<<56)|(((x)&0xff00)<<40)|(((x)&0xff0000)<<24)|(((x)&0xff000000)<<8)|(((x)>>8)&0xff000000)|(((x)>>24)&0xff0000)|(((x)>>40)&0xff00)|(((x)>>56)&0xff))
#define LE_TO_LOCAL_WORDS_32(x) (((x)<<16)|((x)>>16))
#else // local arch is little endian
#define LE_TO_LOCAL_16(x) (x)
#define LE_TO_LOCAL_32(x) (x)
#define LE_TO_LOCAL_64(x) (x)
#define LE_TO_LOCAL_WORDS_32(x) (x)
#endif
#define LOCAL_TO_LE_16(x) LE_TO_LOCAL_16(x)
#define LOCAL_TO_LE_32(x) LE_TO_LOCAL_32(x)
#define LOCAL_TO_LE_64(x) LE_TO_LOCAL_64(x)
#define LOCAL_WORDS_TO_LE_32(x) LE_TO_LOCAL_WORDS_32(x)
// kilobytes and megabytes macro
#define MB(x) ((x)*1024*1024)
#define KB(x) ((x)*1024)