Add code to convert the 16bit float format used by the hardware back into float 754 format. 16bit floats are used for the culling radiuses in the nodes.

This commit is contained in:
Ian Curtis 2016-06-03 00:01:34 +00:00
parent 6dc5845d47
commit 5081ee99dc
2 changed files with 23 additions and 1 deletions

View file

@ -351,7 +351,7 @@ void CNew3D::DescendCullingNode(UINT32 addr)
sibling2Ptr = node[0x08 - m_offset] & 0x1FFFFFF; // mask colour table bits
matrixOffset = node[0x03 - m_offset] & 0xFFF;
short extent = node[9 - m_offset] >> 16;
float test = ToFloat(Convert16BitProFloat(node[9 - m_offset] >> 16));
if ((node[0x00] & 0x07) != 0x06) { // colour table seems to indicate no siblings
if (!(sibling2Ptr & 0x1000000) && sibling2Ptr) {
@ -1175,5 +1175,24 @@ void CNew3D::CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX
newY += ((oldPage + page) & 1) * 1024; // max page 0-1
}
UINT32 CNew3D::ConvertProFloat(UINT32 a1)
{
int exponent = ((a1 & 0x7E000000) >> 25) + 127;
int mantissa = (a1 & 0x1FFFFFF) >> 2;
return (a1 & 0x80000000) | (exponent << 23) | mantissa;
}
UINT32 CNew3D::Convert16BitProFloat(UINT32 a1)
{
return ConvertProFloat(a1 << 15);
}
float CNew3D::ToFloat(UINT32 a1)
{
return *(float*)(&a1);
}
} // New3D

View file

@ -178,6 +178,9 @@ private:
void CalcTexOffset(int offX, int offY, int page, int x, int y, int& newX, int& newY);
UINT32 ConvertProFloat(UINT32 a1); // return float in hex or integer format
UINT32 Convert16BitProFloat(UINT32 a1);
float ToFloat(UINT32 a1); // integer float to actual IEEE 754 float
/*
* Data