diff options
author | Marcus Huderle <huderlem@gmail.com> | 2018-10-06 12:02:06 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-06 12:02:06 -0500 |
commit | 2e774667c86ea2b003102bc4e3308fbbde246353 (patch) | |
tree | 09df160c08662da1aae9610a1af6d4da5a47ce64 | |
parent | 2cb551cf0df29e2602d6a80c16f8bac0a136b134 (diff) | |
parent | 77e95d1309f5da9306c69c7aee23587e0c169ceb (diff) |
Merge pull request #14 from SatoMew/master
decompile random.c
-rw-r--r-- | asm/random.s | 36 | ||||
-rw-r--r-- | common_syms/random.txt | 1 | ||||
-rw-r--r-- | src/random.c | 18 | ||||
-rw-r--r-- | sym_common.txt | 6 |
4 files changed, 22 insertions, 39 deletions
diff --git a/asm/random.s b/asm/random.s deleted file mode 100644 index dcf706524..000000000 --- a/asm/random.s +++ /dev/null @@ -1,36 +0,0 @@ - .include "asm/macros.inc" - .include "constants/constants.inc" - - .syntax unified - - .text - - thumb_func_start Random -Random: @ 8044EC8 - ldr r2, _08044EDC @ =gUnknown_3005000 - ldr r1, [r2] - ldr r0, _08044EE0 @ =0x41c64e6d - muls r0, r1 - ldr r1, _08044EE4 @ =0x00006073 - adds r0, r1 - str r0, [r2] - lsrs r0, 16 - bx lr - .align 2, 0 -_08044EDC: .4byte gUnknown_3005000 -_08044EE0: .4byte 0x41c64e6d -_08044EE4: .4byte 0x00006073 - thumb_func_end Random - - thumb_func_start SeedRng -SeedRng: @ 8044EE8 - lsls r0, 16 - lsrs r0, 16 - ldr r1, _08044EF4 @ =gUnknown_3005000 - str r0, [r1] - bx lr - .align 2, 0 -_08044EF4: .4byte gUnknown_3005000 - thumb_func_end SeedRng - - .align 2, 0 @ Don't pad with nop. diff --git a/common_syms/random.txt b/common_syms/random.txt new file mode 100644 index 000000000..794439ea5 --- /dev/null +++ b/common_syms/random.txt @@ -0,0 +1 @@ +gRngValue diff --git a/src/random.c b/src/random.c new file mode 100644 index 000000000..54dae0824 --- /dev/null +++ b/src/random.c @@ -0,0 +1,18 @@ +#include "global.h" +#include "random.h" + +// The number 1103515245 comes from the example implementation +// of rand and srand in the ISO C standard. + +u32 gRngValue; + +u16 Random(void) +{ + gRngValue = 1103515245 * gRngValue + 24691; + return gRngValue >> 16; +} + +void SeedRng(u16 seed) +{ + gRngValue = seed; +} diff --git a/sym_common.txt b/sym_common.txt index db9a63d4f..4049c48f5 100644 --- a/sym_common.txt +++ b/sym_common.txt @@ -132,9 +132,9 @@ gUnknown_3004FF8: @ 3004FF8 gUnknown_3004FFC: @ 3004FFC .space 0x4 -gUnknown_3005000: @ 3005000 - .space 0x4 - + .include "random.o" + + .align 2 gUnknown_3005004: @ 3005004 .space 0x4 |