Use a 32 bit seed for new game seeding in HQ mode. (#4218)

Also adjust some comments
This commit is contained in:
tertu 2024-02-28 00:04:47 -06:00 committed by GitHub
parent 918a0be312
commit e3d9a19f45
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 31 additions and 8 deletions

View File

@ -215,15 +215,37 @@ void SetMainCallback2(MainCallback callback)
void StartTimer1(void)
{
REG_TM1CNT_H = 0x80;
if (HQ_RANDOM)
{
REG_TM2CNT_L = 0;
REG_TM2CNT_H = TIMER_ENABLE | TIMER_COUNTUP;
}
REG_TM1CNT_H = TIMER_ENABLE;
}
void SeedRngAndSetTrainerId(void)
{
u16 val = REG_TM1CNT_L;
SeedRng(val);
REG_TM1CNT_H = 0;
sTrainerId = val;
u32 val;
if (HQ_RANDOM)
{
REG_TM1CNT_H = 0;
REG_TM2CNT_H = 0;
val = ((u32)REG_TM2CNT_L) << 16;
val |= REG_TM1CNT_L;
SeedRng(val);
sTrainerId = Random();
}
else
{
// Do it exactly like it was originally done, including not stopping
// the timer beforehand.
val = REG_TM1CNT_L;
SeedRng((u16)val);
REG_TM1CNT_H = 0;
sTrainerId = val;
}
}
u16 GetGeneratedTrainerIdLower(void)

View File

@ -41,7 +41,8 @@ static void SFC32_Seed(struct Sfc32State *state, u32 seed, u8 stream)
}
/*This ASM implementation uses some shortcuts and is generally faster on the GBA.
* It's not necessarily faster if inlined, or on other platforms. */
* It's not necessarily faster if inlined, or on other platforms.
* In addition, it's extremely non-portable. */
u32 NAKED Random32(void)
{
asm(".thumb\n\
@ -49,7 +50,7 @@ u32 NAKED Random32(void)
mov r6, #11\n\
ldr r5, =gRngValue\n\
ldmia r5!, {r1, r2, r3, r4}\n\
@ e (result) = a + b + d++\n\
@ result = a + b + (d+=STREAM1)\n\
add r1, r1, r2\n\
add r0, r1, r4\n\
add r4, r4, #" STR(STREAM1) "\n\
@ -59,7 +60,7 @@ u32 NAKED Random32(void)
@ b = c + (c << 3) [c * 9]\n\
lsl r2, r3, #3\n\
add r2, r2, r3\n\
@ c = rol(c, 21) + e\n\
@ c = rol(c, 21) + result\n\
ror r3, r3, r6\n\
add r3, r3, r0\n\
sub r5, r5, #16\n\