diff --git a/ld/gamefiles.jpn-final.inc b/ld/gamefiles.jpn-final.inc index 0ee9c13ad..4f88c56e4 100644 --- a/ld/gamefiles.jpn-final.inc +++ b/ld/gamefiles.jpn-final.inc @@ -168,7 +168,7 @@ build/ROMID/game/sky.o (section); \ build/ROMID/game/playermgr.o (section); \ build/ROMID/game/crc.o (section); \ - build/ROMID/game/rng2.o (section); \ + build/ROMID/game/rng2asm.o (section); \ build/ROMID/game/vtxstore.o (section); \ build/ROMID/game/explosions.o (section); \ build/ROMID/game/smoke.o (section); \ diff --git a/ld/gamefiles.ntsc-beta.inc b/ld/gamefiles.ntsc-beta.inc index 08c291f42..dcf5ef1f5 100644 --- a/ld/gamefiles.ntsc-beta.inc +++ b/ld/gamefiles.ntsc-beta.inc @@ -169,7 +169,7 @@ build/ROMID/game/sky.o (section); \ build/ROMID/game/playermgr.o (section); \ build/ROMID/game/crc.o (section); \ - build/ROMID/game/rng2.o (section); \ + build/ROMID/game/rng2asm.o (section); \ build/ROMID/game/vtxstore.o (section); \ build/ROMID/game/explosions.o (section); \ build/ROMID/game/smoke.o (section); \ diff --git a/ld/gamefiles.ntsc-final.inc b/ld/gamefiles.ntsc-final.inc index 0ee9c13ad..4f88c56e4 100644 --- a/ld/gamefiles.ntsc-final.inc +++ b/ld/gamefiles.ntsc-final.inc @@ -168,7 +168,7 @@ build/ROMID/game/sky.o (section); \ build/ROMID/game/playermgr.o (section); \ build/ROMID/game/crc.o (section); \ - build/ROMID/game/rng2.o (section); \ + build/ROMID/game/rng2asm.o (section); \ build/ROMID/game/vtxstore.o (section); \ build/ROMID/game/explosions.o (section); \ build/ROMID/game/smoke.o (section); \ diff --git a/ld/gamefiles.pal-beta.inc b/ld/gamefiles.pal-beta.inc index 067965ff3..5bb37b96d 100644 --- a/ld/gamefiles.pal-beta.inc +++ b/ld/gamefiles.pal-beta.inc @@ -169,7 +169,7 @@ build/ROMID/game/sky.o (section); \ build/ROMID/game/playermgr.o (section); \ build/ROMID/game/crc.o (section); \ - build/ROMID/game/rng2.o (section); \ + build/ROMID/game/rng2asm.o (section); \ build/ROMID/game/vtxstore.o (section); \ build/ROMID/game/explosions.o (section); \ build/ROMID/game/smoke.o (section); \ diff --git a/ld/gamefiles.pal-final.inc b/ld/gamefiles.pal-final.inc index 0ee9c13ad..4f88c56e4 100644 --- a/ld/gamefiles.pal-final.inc +++ b/ld/gamefiles.pal-final.inc @@ -168,7 +168,7 @@ build/ROMID/game/sky.o (section); \ build/ROMID/game/playermgr.o (section); \ build/ROMID/game/crc.o (section); \ - build/ROMID/game/rng2.o (section); \ + build/ROMID/game/rng2asm.o (section); \ build/ROMID/game/vtxstore.o (section); \ build/ROMID/game/explosions.o (section); \ build/ROMID/game/smoke.o (section); \ diff --git a/src/game/chr.c b/src/game/chr.c index 8ba9a473c..ca9e087d7 100644 --- a/src/game/chr.c +++ b/src/game/chr.c @@ -20,7 +20,7 @@ #include "game/player.h" #include "game/game_0c33f0.h" #include "game/playermgr.h" -#include "game/game_1291b0.h" +#include "game/rng2.h" #include "game/vtxstore.h" #include "game/gfxmemory.h" #include "game/explosions.h" @@ -48,6 +48,8 @@ #include "gbiex.h" #include "types.h" +void rng2SetSeed(u32 seed); + void *var8009ccc0[20]; s32 g_NumChrs; s16 *g_Chrnums; diff --git a/src/game/propobj.c b/src/game/propobj.c index 1ff58804a..340dd0e52 100644 --- a/src/game/propobj.c +++ b/src/game/propobj.c @@ -33,7 +33,7 @@ #include "game/menu.h" #include "game/inv.h" #include "game/playermgr.h" -#include "game/game_1291b0.h" +#include "game/rng2.h" #include "game/vtxstore.h" #include "game/explosions.h" #include "game/smoke.h" @@ -78,6 +78,8 @@ #include "types.h" #include "string.h" +void rng2SetSeed(u32 seed); + struct weaponobj *g_Proxies[30]; f32 g_GasReleaseTimerMax240; bool g_GasEnableDamage; diff --git a/src/game/proptick.c b/src/game/proptick.c index aab0be465..39324c901 100644 --- a/src/game/proptick.c +++ b/src/game/proptick.c @@ -19,7 +19,6 @@ #include "game/player.h" #include "game/game_0c33f0.h" #include "game/playermgr.h" -#include "game/game_1291b0.h" #include "game/vtxstore.h" #include "game/gfxmemory.h" #include "game/explosions.h" diff --git a/src/game/rng2.c b/src/game/rng2.c new file mode 100644 index 000000000..d14a68c90 --- /dev/null +++ b/src/game/rng2.c @@ -0,0 +1,27 @@ +#include +#include "constants.h" +#include "bss.h" +#include "lib/rng.h" +#include "data.h" +#include "types.h" + +u64 g_Rng2Seed = 0xab8d9f7781280783; + +/** + * Generate a random number between 0 and 4294967295. + */ +u32 random2(void) +{ + g_Rng2Seed = ((g_Rng2Seed << 63) >> 31 | (g_Rng2Seed << 31) >> 32) ^ (g_Rng2Seed << 44) >> 32; + g_Rng2Seed = ((g_Rng2Seed >> 20) & 0xfff) ^ g_Rng2Seed; + + return g_Rng2Seed; +} + +/** + * Set the given seed as the RNG seed. Add 1 to make sure it isn't 0. + */ +void rng2SetSeed(u64 seed) +{ + g_Rng2Seed = seed + 1; +} diff --git a/src/game/rng2.s b/src/game/rng2asm.s similarity index 94% rename from src/game/rng2.s rename to src/game/rng2asm.s index 7eb419b65..d1507193d 100644 --- a/src/game/rng2.s +++ b/src/game/rng2asm.s @@ -11,7 +11,7 @@ glabel g_Rng2Seed .text /** - * u32 random(void) + * u32 random2(void) * * Generate a random number between 0 and 4294967295. */ @@ -36,7 +36,7 @@ glabel random2 dsra32 $v0, $v0, 0 /** - * void rngSetSeed(u32 seed) + * void rng2SetSeed(u64 seed) * * Set the given seed as the RNG seed. Add 1 to make sure it isn't 0. */ diff --git a/src/include/game/game_1291b0.h b/src/include/game/game_1291b0.h deleted file mode 100644 index 4bf7bd303..000000000 --- a/src/include/game/game_1291b0.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef IN_GAME_GAME_1291B0_H -#define IN_GAME_GAME_1291B0_H -#include -#include "data.h" -#include "types.h" - -u32 random2(void); -void rng2SetSeed(u32 seed); - -#endif diff --git a/src/include/game/rng2.h b/src/include/game/rng2.h new file mode 100644 index 000000000..dbdb3913b --- /dev/null +++ b/src/include/game/rng2.h @@ -0,0 +1,9 @@ +#ifndef IN_GAME_RNG2_H +#define IN_GAME_RNG2_H +#include +#include "data.h" +#include "types.h" + +u32 random2(void); + +#endif