From c4591b7f20f5fa8ceecc1cef62df3509cef84ba7 Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 10 Jan 2024 17:39:55 +0000 Subject: [PATCH] Fix big-endian incompatibility in float-related CPU code This would cause all 3D to break in games like Ocarina of Time and Mario Kart 64, being reduced to a few unmoving triangles in the middle of the screen. --- src/device/r4300/cp1.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/device/r4300/cp1.c b/src/device/r4300/cp1.c index ec55230d..ff3b401a 100644 --- a/src/device/r4300/cp1.c +++ b/src/device/r4300/cp1.c @@ -29,6 +29,12 @@ #define FCR31_FS_BIT UINT32_C(0x1000000) +#ifdef M64P_BIG_ENDIAN +#define DOUBLE_HALF_XOR 1 +#else +#define DOUBLE_HALF_XOR 0 +#endif + void init_cp1(struct cp1* cp1, struct new_dynarec_hot_state* new_dynarec_hot_state) { #ifdef NEW_DYNAREC @@ -104,7 +110,7 @@ void set_fpr_pointers(struct cp1* cp1, uint32_t newStatus) { for (i = 0; i < 32; i++) { - (r4300_cp1_regs_simple(cp1))[i] = &cp1->regs[i & ~1].float32[i & 1]; + (r4300_cp1_regs_simple(cp1))[i] = &cp1->regs[i & ~1].float32[i & 1 ^ DOUBLE_HALF_XOR]; (r4300_cp1_regs_double(cp1))[i] = &cp1->regs[i & ~1].float64; } }