mirror of
https://github.com/Ninjdai1/pokeemerald.git
synced 2024-12-26 19:54:21 +01:00
decompile rng
This commit is contained in:
parent
39299306e0
commit
8f9ed6e585
@ -850,7 +850,7 @@ sub_80D7DE8: @ 80D7DE8
|
||||
adds r0, r5
|
||||
ldr r1, =sub_80D80C8
|
||||
str r1, [r0]
|
||||
ldr r1, =gUnknown_03005D80
|
||||
ldr r1, =gRngValue
|
||||
ldr r0, =gUnknown_030060B8
|
||||
ldr r0, [r0]
|
||||
str r0, [r1]
|
||||
@ -2191,7 +2191,7 @@ sub_80D8A88: @ 80D8A88
|
||||
strb r0, [r1, 0x10]
|
||||
ldr r0, [r2]
|
||||
ldr r1, [r0]
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
ldr r0, [r0]
|
||||
str r0, [r1, 0x18]
|
||||
ldr r0, =gUnknown_02039F2A
|
||||
@ -5369,7 +5369,7 @@ _080DA65C:
|
||||
bl sub_80DF750
|
||||
_080DA668:
|
||||
ldr r1, =gUnknown_030060B8
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
ldr r0, [r0]
|
||||
str r0, [r1]
|
||||
ldr r4, =gStringVar4
|
||||
|
@ -416,7 +416,7 @@ _080FC830:
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _080FC880
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
movs r1, 0x4
|
||||
bl sub_80FC4F4
|
||||
cmp r0, 0x1
|
||||
@ -429,7 +429,7 @@ _080FC858:
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _080FC880
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
ldr r4, =gUnknown_020223C4
|
||||
adds r1, r4, 0
|
||||
movs r2, 0x4
|
||||
|
65
asm/rng.s
65
asm/rng.s
@ -1,65 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "constants/constants.inc"
|
||||
|
||||
.syntax unified
|
||||
|
||||
.text
|
||||
|
||||
thumb_func_start Random
|
||||
@ u16 GenerateRandomNumber()
|
||||
Random: @ 806F5CC
|
||||
ldr r2, =gUnknown_03005D80
|
||||
ldr r1, [r2]
|
||||
ldr r0, =0x41c64e6d
|
||||
muls r0, r1
|
||||
ldr r1, =0x00006073
|
||||
adds r0, r1
|
||||
str r0, [r2]
|
||||
ldr r2, =gUnknown_020249C0
|
||||
ldr r1, [r2]
|
||||
adds r1, 0x1
|
||||
str r1, [r2]
|
||||
lsrs r0, 16
|
||||
bx lr
|
||||
.pool
|
||||
thumb_func_end Random
|
||||
|
||||
thumb_func_start SeedRng
|
||||
@ void SeedRng(u16 seed)
|
||||
SeedRng: @ 806F5F8
|
||||
lsls r0, 16
|
||||
lsrs r0, 16
|
||||
ldr r1, =gUnknown_03005D80
|
||||
str r0, [r1]
|
||||
ldr r1, =gUnknown_020249BC
|
||||
movs r0, 0
|
||||
strb r0, [r1]
|
||||
bx lr
|
||||
.pool
|
||||
thumb_func_end SeedRng
|
||||
|
||||
thumb_func_start SeedRng2
|
||||
SeedRng2: @ 806F610
|
||||
lsls r0, 16
|
||||
lsrs r0, 16
|
||||
ldr r1, =gUnknown_03005D84
|
||||
str r0, [r1]
|
||||
bx lr
|
||||
.pool
|
||||
thumb_func_end SeedRng2
|
||||
|
||||
thumb_func_start Random2
|
||||
Random2: @ 806F620
|
||||
ldr r2, =gUnknown_03005D84
|
||||
ldr r1, [r2]
|
||||
ldr r0, =0x41c64e6d
|
||||
muls r0, r1
|
||||
ldr r1, =0x00006073
|
||||
adds r0, r1
|
||||
str r0, [r2]
|
||||
lsrs r0, 16
|
||||
bx lr
|
||||
.pool
|
||||
thumb_func_end Random2
|
||||
|
||||
.align 2, 0 @ Don't pad with nop.
|
@ -13834,7 +13834,7 @@ _0803C628:
|
||||
ldrb r0, [r0]
|
||||
cmp r0, 0
|
||||
bne _0803C690
|
||||
ldr r1, =gUnknown_03005D80
|
||||
ldr r1, =gRngValue
|
||||
ldr r0, =gUnknown_0203BD30
|
||||
ldr r0, [r0]
|
||||
str r0, [r1]
|
||||
@ -71061,7 +71061,7 @@ sub_805C158: @ 805C158
|
||||
cmp r0, 0
|
||||
bne _0805C194
|
||||
ldr r1, =gUnknown_0203BD30
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
ldr r0, [r0]
|
||||
str r0, [r1]
|
||||
bl sub_805D19C
|
||||
|
@ -96,7 +96,7 @@ sub_8184E58: @ 8184E58
|
||||
cmp r0, 0x1
|
||||
bne _08184EA0
|
||||
ldr r1, =gUnknown_0203BD2C
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
ldr r0, [r0]
|
||||
str r0, [r1]
|
||||
ldr r4, =gUnknown_0203C7AE
|
||||
@ -111,7 +111,7 @@ sub_8184E58: @ 8184E58
|
||||
_08184EA0:
|
||||
cmp r0, 0x2
|
||||
bne _08184EAC
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
ldr r1, =gUnknown_0203BD2C
|
||||
ldr r1, [r1]
|
||||
str r1, [r0]
|
||||
|
@ -60550,7 +60550,7 @@ _081DA284:
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _081DA2D4
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
movs r1, 0x4
|
||||
bl sub_80FC4F4
|
||||
cmp r0, 0x1
|
||||
@ -60563,7 +60563,7 @@ _081DA2AC:
|
||||
lsls r0, 24
|
||||
cmp r0, 0
|
||||
beq _081DA2D4
|
||||
ldr r0, =gUnknown_03005D80
|
||||
ldr r0, =gRngValue
|
||||
ldr r4, =gUnknown_020223C4
|
||||
adds r1, r4, 0
|
||||
movs r2, 0x4
|
||||
|
18
include/rng.h
Normal file
18
include/rng.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef GUARD_RNG_H
|
||||
#define GUARD_RNG_H
|
||||
|
||||
extern u32 gRngValue;
|
||||
extern u32 gRng2Value;
|
||||
|
||||
//Returns a 16-bit pseudorandom number
|
||||
u16 Random(void);
|
||||
u16 Random2(void);
|
||||
|
||||
//Returns a 32-bit pseudorandom number
|
||||
#define Random32() (Random() | (Random() << 16))
|
||||
|
||||
//Sets the initial seed value of the pseudorandom number generator
|
||||
void SeedRng(u16 seed);
|
||||
void SeedRng2(u16 seed);
|
||||
|
||||
#endif // GUARD_RNG_H
|
@ -60,7 +60,7 @@ SECTIONS {
|
||||
asm/pokemon_2.o(.text);
|
||||
asm/pokemon_3.o(.text);
|
||||
asm/trig.o(.text);
|
||||
asm/rng.o(.text);
|
||||
src/rng.o(.text);
|
||||
asm/util.o(.text);
|
||||
asm/blend_palette.o(.text);
|
||||
asm/daycare.o(.text);
|
||||
|
35
src/rng.c
Normal file
35
src/rng.c
Normal file
@ -0,0 +1,35 @@
|
||||
#include "global.h"
|
||||
#include "rng.h"
|
||||
|
||||
// The number 1103515245 comes from the example implementation of rand and srand
|
||||
// in the ISO C standard.
|
||||
|
||||
extern u32 gRngValue;
|
||||
extern u32 gRng2Value;
|
||||
|
||||
EWRAM_DATA u8 sUnknown = 0;
|
||||
EWRAM_DATA u32 sRandCount = 0;
|
||||
|
||||
u16 Random()
|
||||
{
|
||||
gRngValue = 1103515245 * gRngValue + 24691;
|
||||
sRandCount++;
|
||||
return gRngValue >> 16;
|
||||
}
|
||||
|
||||
void SeedRng(u16 seed)
|
||||
{
|
||||
gRngValue = seed;
|
||||
sUnknown = 0;
|
||||
}
|
||||
|
||||
void SeedRng2(u16 seed)
|
||||
{
|
||||
gRng2Value = seed;
|
||||
}
|
||||
|
||||
u16 Random2(void)
|
||||
{
|
||||
gRng2Value = 1103515245 * gRng2Value + 24691;
|
||||
return gRng2Value >> 16;
|
||||
}
|
@ -267,10 +267,10 @@ gUnknown_03005D78: @ 3005D78
|
||||
gUnknown_03005D7C: @ 3005D7C
|
||||
.space 0x4
|
||||
|
||||
gUnknown_03005D80: @ 3005D80
|
||||
gRngValue: @ 3005D80
|
||||
.space 0x4
|
||||
|
||||
gUnknown_03005D84: @ 3005D84
|
||||
gRng2Value: @ 3005D84
|
||||
.space 0x4
|
||||
|
||||
gUnknown_03005D88: @ 3005D88
|
||||
|
@ -699,12 +699,9 @@ gUnknown_0202499C: @ 202499C
|
||||
gUnknown_020249B4: @ 20249B4
|
||||
.space 0x8
|
||||
|
||||
gUnknown_020249BC: @ 20249BC
|
||||
.space 0x4
|
||||
|
||||
gUnknown_020249C0: @ 20249C0
|
||||
.space 0x4
|
||||
.include "src/rng.o"
|
||||
|
||||
.align 2
|
||||
gUnknown_020249C4: @ 20249C4
|
||||
.space 0x64
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user