summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorengineer124 <47598039+engineer124@users.noreply.github.com>2023-11-10 10:28:16 +1100
committerGitHub <noreply@github.com>2023-11-10 10:28:16 +1100
commit2823a720bc1081a48cd142788622087adfd3e5dc (patch)
tree9e7b84998154fbd620d835da2f4066e4bb56a80f
parente96f18d4e720663f79c6a7dc74c19b3c7f83ea5f (diff)
Match `Environment_DrawSkyboxStarsImpl` (z_kankyo OK), introduce `rand.h` (#1476)
* match Environment_DrawSkyboxStarsImpl * revert * PR Review * small fix * group pads together * Color_RGBA8_u32
-rw-r--r--include/alignment.h6
-rw-r--r--include/color.h4
-rw-r--r--include/functions.h9
-rw-r--r--include/rand.h23
-rw-r--r--include/variables.h1
-rw-r--r--include/z64.h1
-rw-r--r--src/boot/O2/rand.c8
-rw-r--r--src/code/z_kankyo.c49
8 files changed, 55 insertions, 46 deletions
diff --git a/include/alignment.h b/include/alignment.h
index f2fd65750..9e6fe11e6 100644
--- a/include/alignment.h
+++ b/include/alignment.h
@@ -14,6 +14,12 @@
#endif
#ifdef __sgi /* IDO compiler */
+#define UNALIGNED __unaligned
+#else
+#define UNALIGNED
+#endif
+
+#ifdef __sgi /* IDO compiler */
#define ALIGNOF(x) __builtin_alignof(x)
#elif (__STDC_VERSION__ >= 201112L) /* C11 */
#define ALIGNOF(x) _Alignof(x)
diff --git a/include/color.h b/include/color.h
index def50caa8..7c0cd7d9f 100644
--- a/include/color.h
+++ b/include/color.h
@@ -1,5 +1,5 @@
-#ifndef _COLOR_H_
-#define _COLOR_H_
+#ifndef COLOR_H
+#define COLOR_H
#include "PR/ultratypes.h"
diff --git a/include/functions.h b/include/functions.h
index 0e0e3dcbb..330510a1d 100644
--- a/include/functions.h
+++ b/include/functions.h
@@ -65,15 +65,6 @@ void MtxConv_L2F(MtxF* mtx, Mtx* mf);
s32 func_80086620(OSMesgQueue* param_1, PadMgr* param_2, OSContStatus* param_3);
-u32 Rand_Next(void);
-void Rand_Seed(u32 seed);
-f32 Rand_ZeroOne(void);
-f32 Rand_Centered(void);
-void Rand_Seed_Variable(u32* rndNum, u32 seed);
-u32 Rand_Next_Variable(u32* rndNum);
-f32 Rand_ZeroOne_Variable(u32* rndNum);
-f32 Rand_Centered_Variable(u32* rndNum);
-
s32 PrintUtils_VPrintf(PrintCallback* pfn, const char* fmt, va_list args);
s32 PrintUtils_Printf(PrintCallback* pfn, const char* fmt, ...);
void Sleep_Cycles(OSTime time);
diff --git a/include/rand.h b/include/rand.h
new file mode 100644
index 000000000..ad13e22a4
--- /dev/null
+++ b/include/rand.h
@@ -0,0 +1,23 @@
+#ifndef RAND_H
+#define RAND_H
+
+#include "PR/ultratypes.h"
+
+//! These values are recommended by the algorithms book *Numerical Recipes in C. The Art of Scientific Computing*, 2nd
+//! Edition, 1992, ISBN 0-521-43108-5. (p. 284):
+//! > This is about as good as any 32-bit linear congruential generator, entirely adequate for many uses.
+#define RAND_MULTIPLIER 1664525
+#define RAND_INCREMENT 1013904223
+
+u32 Rand_Next(void);
+void Rand_Seed(u32 seed);
+f32 Rand_ZeroOne(void);
+f32 Rand_Centered(void);
+void Rand_Seed_Variable(u32* rndNum, u32 seed);
+u32 Rand_Next_Variable(u32* rndNum);
+f32 Rand_ZeroOne_Variable(u32* rndNum);
+f32 Rand_Centered_Variable(u32* rndNum);
+
+extern u32 gRandFloat;
+
+#endif
diff --git a/include/variables.h b/include/variables.h
index 7b1313415..a2e1c6f63 100644
--- a/include/variables.h
+++ b/include/variables.h
@@ -31,7 +31,6 @@ extern u8* sYaz0MaxPtr;
extern void* gYaz0DecompressDstEnd;
// extern UNK_TYPE4 D_8009CD10;
-extern u32 gRandFloat;
// extern UNK_TYPE4 sArenaLockMsg;
extern DmaEntry dmadata[1568];
diff --git a/include/z64.h b/include/z64.h
index 28ae04de7..d8aa31074 100644
--- a/include/z64.h
+++ b/include/z64.h
@@ -24,6 +24,7 @@
#include "gfx.h"
#include "gfxprint.h"
#include "padutils.h"
+#include "rand.h"
#include "sys_matrix.h"
#include "tha.h"
#include "thga.h"
diff --git a/src/boot/O2/rand.c b/src/boot/O2/rand.c
index 9f3051717..152c8a0e7 100644
--- a/src/boot/O2/rand.c
+++ b/src/boot/O2/rand.c
@@ -1,4 +1,4 @@
-#include "global.h"
+#include "rand.h"
//! The latest generated random number, used to generate the next number in the sequence.
static u32 sRandInt = 1;
@@ -7,12 +7,6 @@ static u32 sRandInt = 1;
//! This can't be static because it is used in z_kankyo.
u32 gRandFloat;
-//! These values are recommended by the algorithms book *Numerical Recipes in C. The Art of Scientific Computing*, 2nd
-//! Edition, 1992, ISBN 0-521-43108-5. (p. 284):
-//! > This is about as good as any 32-bit linear congruential generator, entirely adequate for many uses.
-#define RAND_MULTIPLIER 1664525
-#define RAND_INCREMENT 1013904223
-
/**
* Generates the next pseudo-random integer.
*/
diff --git a/src/code/z_kankyo.c b/src/code/z_kankyo.c
index 82a7a8df5..933d9f3b7 100644
--- a/src/code/z_kankyo.c
+++ b/src/code/z_kankyo.c
@@ -3108,10 +3108,6 @@ void Environment_DrawSkyboxStar(Gfx** gfxp, f32 x, f32 y, s32 width, s32 height)
*gfxp = gfx;
}
-#ifdef NON_MATCHING
-// `D_801DD900`is loading unaligned but storing aligned
-// Also small float regalloc at the gRandFloat section
-// https://decomp.me/scratch/3zFop
void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
static const Vec3s D_801DD880[] = {
{ 0x0384, 0x2328, 0xD508 }, { 0x09C4, 0x2328, 0xDA1C }, { 0x0E74, 0x22D8, 0xDA1C }, { 0x1450, 0x2468, 0xD8F0 },
@@ -3119,24 +3115,26 @@ void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
{ 0xD058, 0x4C2C, 0x3A98 }, { 0xD8F0, 0x36B0, 0x47E0 }, { 0xD954, 0x3264, 0x3E1C }, { 0xD8F0, 0x3070, 0x37DC },
{ 0xD8F0, 0x1F40, 0x5208 }, { 0xD760, 0x1838, 0x27D8 }, { 0x0000, 0x4E20, 0x4A38 }, { 0x076C, 0x2328, 0xDCD8 },
};
- // Possibly Color_RGBA8_u32
- static const u32 D_801DD8E0[] = {
- 0x41A4FFFF, 0x83A4E6FF, 0x62CDFFFF, 0x5252FFFF, 0x7BA4A4FF, 0x62CDFFFF, 0x62A4E6FF, 0xFF5A00FF,
+ static const Color_RGBA8_u32 D_801DD8E0[] = {
+ { 65, 164, 255, 255 }, { 131, 164, 230, 255 }, { 98, 205, 255, 255 }, { 82, 82, 255, 255 },
+ { 123, 164, 164, 255 }, { 98, 205, 255, 255 }, { 98, 164, 230, 255 }, { 255, 90, 0, 255 },
};
- static const u32 D_801DD900[] = {
- 0x405070FF, 0x606080FF, 0x807090FF, 0xA080A0FF, 0xC090A8FF, 0xE0A0B0FF, 0xE0A0B0FF, 0x686888FF,
- 0x887898FF, 0xA888A8FF, 0xC898B8FF, 0xE8A8B8FF, 0xE0B0B8FF, 0xF0C0C0FF, 0xE8B8C0FF, 0xF8C8C0FF,
+ UNALIGNED static const Color_RGBA8_u32 D_801DD900[] = {
+ { 64, 80, 112, 255 }, { 96, 96, 128, 255 }, { 128, 112, 144, 255 }, { 160, 128, 160, 255 },
+ { 192, 144, 168, 255 }, { 224, 160, 176, 255 }, { 224, 160, 176, 255 }, { 104, 104, 136, 255 },
+ { 136, 120, 152, 255 }, { 168, 136, 168, 255 }, { 200, 152, 184, 255 }, { 232, 168, 184, 255 },
+ { 224, 176, 184, 255 }, { 240, 192, 192, 255 }, { 232, 184, 192, 255 }, { 248, 200, 192, 255 },
};
Vec3f pos;
- s32 pad1;
- f32 imgY; // spF4
- f32 imgX; // spF0
+ f32 temp;
+ f32 imgY;
+ f32 imgX;
Gfx* gfx;
- s32 phi_v1; // spE8
- s32 negateY; // spE4
+ s32 phi_v1;
+ s32 negateY;
f32 invScale;
f32 temp_f20;
- Gfx* gfxTemp; // spD8
+ Gfx* gfxTemp;
f32 scale;
s32 i;
u32 randInt;
@@ -3190,17 +3188,18 @@ void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
f32 temp_f2;
// temp_f4 = Rand_ZeroOne_Variable(&randInt);
- randInt = (randInt * 1664525) + 1013904223;
+ randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
gRandFloat = (randInt >> 9) | 0x3F800000;
- temp_f4 = *((f32*)&gRandFloat) - 1.0f;
+ temp = *((f32*)&gRandFloat);
+ temp_f4 = temp - 1.0f;
// temp_f20 = Rand_ZeroOne_Variable(&randInt);
- randInt = (randInt * 1664525) + 1013904223;
+ randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
gRandFloat = (randInt >> 9) | 0x3F800000;
temp_f20 = ((*((f32*)&gRandFloat) - 1.0f) + temp_f4) * 0.5f;
// randInt = Rand_Next_Variable(&randInt);
- randInt = (randInt * 1664525) + 1013904223;
+ randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
// Set random position
pos.y = play->view.eye.y + (SQ(temp_f20) * SQ(128.0f)) - 1000.0f;
@@ -3208,7 +3207,7 @@ void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
pos.z = play->view.eye.z + (Math_CosS(randInt) * (1.2f - temp_f20) * SQ(128.0f));
// temp_f2 = Rand_ZeroOne_Variable(&randInt);
- randInt = (randInt * 1664525) + 1013904223;
+ randInt = (randInt * RAND_MULTIPLIER) + RAND_INCREMENT;
gRandFloat = ((randInt >> 9) | 0x3F800000);
temp_f2 = *((f32*)&gRandFloat) - 1.0f;
@@ -3221,9 +3220,9 @@ void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
}
if ((i < 15) || ((i == 15) && ((((void)0, gSaveContext.save.day) % 7) == 0))) {
- gDPSetColor(gfx++, G_SETPRIMCOLOR, D_801DD8E0[i % ARRAY_COUNTU(D_801DD8E0)]);
+ gDPSetColor(gfx++, G_SETPRIMCOLOR, D_801DD8E0[i % ARRAY_COUNTU(D_801DD8E0)].rgba);
} else if (((i & 0x3F) == 0) || (i == 16)) {
- gDPSetColor(gfx++, G_SETPRIMCOLOR, D_801DD900[phi_v1 % ARRAY_COUNTU(D_801DD900)]);
+ gDPSetColor(gfx++, G_SETPRIMCOLOR, D_801DD900[phi_v1 % ARRAY_COUNTU(D_801DD900)].rgba);
phi_v1++;
}
@@ -3265,10 +3264,6 @@ void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP) {
gDPPipeSync(gfx++);
*gfxP = gfx;
}
-#else
-void Environment_DrawSkyboxStarsImpl(PlayState* play, Gfx** gfxP);
-#pragma GLOBAL_ASM("asm/non_matchings/code/z_kankyo/Environment_DrawSkyboxStarsImpl.s")
-#endif
void Environment_Draw(PlayState* play) {
Environment_SetupSkyboxStars(play);