diff options
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/pica.h | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 858335d44..24b39a3ad 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h | |||
| @@ -161,6 +161,81 @@ ASSERT_REG_POSITION(vertex_descriptor, 0x200); | |||
| 161 | // The total number of registers is chosen arbitrarily, but let's make sure it's not some odd value anyway. | 161 | // The total number of registers is chosen arbitrarily, but let's make sure it's not some odd value anyway. |
| 162 | static_assert(sizeof(Regs) == 0x300 * sizeof(u32), "Invalid total size of register set"); | 162 | static_assert(sizeof(Regs) == 0x300 * sizeof(u32), "Invalid total size of register set"); |
| 163 | 163 | ||
| 164 | |||
| 165 | struct float24 { | ||
| 166 | static float24 FromFloat32(float val) { | ||
| 167 | float24 ret; | ||
| 168 | ret.value = val; | ||
| 169 | return ret; | ||
| 170 | } | ||
| 171 | |||
| 172 | // 16 bit mantissa, 7 bit exponent, 1 bit sign | ||
| 173 | // TODO: No idea if this works as intended | ||
| 174 | static float24 FromRawFloat24(u32 hex) { | ||
| 175 | float24 ret; | ||
| 176 | if ((hex & 0xFFFFFF) == 0) { | ||
| 177 | ret.value = 0; | ||
| 178 | } else { | ||
| 179 | u32 mantissa = hex & 0xFFFF; | ||
| 180 | u32 exponent = (hex >> 16) & 0x7F; | ||
| 181 | u32 sign = hex >> 23; | ||
| 182 | ret.value = powf(2.0f, (float)exponent-63.0f) * (1.0f + mantissa * powf(2.0f, -16.f)); | ||
| 183 | if (sign) | ||
| 184 | ret.value = -ret.value; | ||
| 185 | } | ||
| 186 | return ret; | ||
| 187 | } | ||
| 188 | |||
| 189 | // Not recommended for anything but logging | ||
| 190 | float ToFloat32() const { | ||
| 191 | return value; | ||
| 192 | } | ||
| 193 | |||
| 194 | float24 operator * (const float24& flt) const { | ||
| 195 | return float24::FromFloat32(ToFloat32() * flt.ToFloat32()); | ||
| 196 | } | ||
| 197 | |||
| 198 | float24 operator / (const float24& flt) const { | ||
| 199 | return float24::FromFloat32(ToFloat32() / flt.ToFloat32()); | ||
| 200 | } | ||
| 201 | |||
| 202 | float24 operator + (const float24& flt) const { | ||
| 203 | return float24::FromFloat32(ToFloat32() + flt.ToFloat32()); | ||
| 204 | } | ||
| 205 | |||
| 206 | float24 operator - (const float24& flt) const { | ||
| 207 | return float24::FromFloat32(ToFloat32() - flt.ToFloat32()); | ||
| 208 | } | ||
| 209 | |||
| 210 | float24 operator - () const { | ||
| 211 | return float24::FromFloat32(-ToFloat32()); | ||
| 212 | } | ||
| 213 | |||
| 214 | bool operator < (const float24& flt) const { | ||
| 215 | return ToFloat32() < flt.ToFloat32(); | ||
| 216 | } | ||
| 217 | |||
| 218 | bool operator > (const float24& flt) const { | ||
| 219 | return ToFloat32() > flt.ToFloat32(); | ||
| 220 | } | ||
| 221 | |||
| 222 | bool operator >= (const float24& flt) const { | ||
| 223 | return ToFloat32() >= flt.ToFloat32(); | ||
| 224 | } | ||
| 225 | |||
| 226 | bool operator <= (const float24& flt) const { | ||
| 227 | return ToFloat32() <= flt.ToFloat32(); | ||
| 228 | } | ||
| 229 | |||
| 230 | private: | ||
| 231 | float24() = default; | ||
| 232 | |||
| 233 | // Stored as a regular float, merely for convenience | ||
| 234 | // TODO: Perform proper arithmetic on this! | ||
| 235 | float value; | ||
| 236 | }; | ||
| 237 | |||
| 238 | |||
| 164 | union CommandHeader { | 239 | union CommandHeader { |
| 165 | CommandHeader(u32 h) : hex(h) {} | 240 | CommandHeader(u32 h) : hex(h) {} |
| 166 | 241 | ||