summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsceptillion <33798691+sceptillion@users.noreply.github.com>2017-12-11 09:18:22 -0800
committersceptillion <33798691+sceptillion@users.noreply.github.com>2017-12-11 09:18:22 -0800
commit041c0891d8516a4c6a60652347ce77de996edb1d (patch)
tree4179bbd334339cd89d34a74fca90ab0ee9428f21
parentb0ef8f839bebb39c1806352cc8f87274927063b6 (diff)
decompile other_random
-rw-r--r--asm/other_random.s48
-rw-r--r--include/other_random.h7
-rw-r--r--ld_script.txt2
-rw-r--r--src/other_random.c20
-rw-r--r--sym_ewram2.txt2
5 files changed, 29 insertions, 50 deletions
diff --git a/asm/other_random.s b/asm/other_random.s
deleted file mode 100644
index 751fc20..0000000
--- a/asm/other_random.s
+++ /dev/null
@@ -1,48 +0,0 @@
- .include "constants/gba_constants.inc"
- .include "asm/macros.inc"
-
- .syntax unified
-
- .text
-
- thumb_func_start OtherRandom
-OtherRandom:
- ldr r1, _08004514
- ldrh r2, [r1]
- movs r0, 0x6D
- muls r0, r2
- ldr r2, _08004518
- adds r0, r2
- strh r0, [r1]
- ldrh r0, [r1]
- bx lr
- .align 2, 0
-_08004514: .4byte gUnknown_203B070
-_08004518: .4byte 0x000003fd
- thumb_func_end OtherRandom
-
- thumb_func_start OtherRandomCapped
-OtherRandomCapped:
- push {r4,lr}
- adds r4, r0, 0
- bl OtherRandom
- muls r0, r4
- asrs r0, 16
- pop {r4}
- pop {r1}
- bx r1
- thumb_func_end OtherRandomCapped
-
- thumb_func_start OtherRandomRange
-OtherRandomRange:
- push {r4,lr}
- adds r4, r0, 0
- subs r0, r1, r4
- bl OtherRandomCapped
- adds r0, r4
- pop {r4}
- pop {r1}
- bx r1
- thumb_func_end OtherRandomRange
-
- .align 2, 0 @ Don't pad with nop.
diff --git a/include/other_random.h b/include/other_random.h
new file mode 100644
index 0000000..83a1b60
--- /dev/null
+++ b/include/other_random.h
@@ -0,0 +1,7 @@
+#ifndef GUARD_OTHER_RANDOM_H
+#define GUARD_OTHER_RANDOM_H
+
+s32 OtherRandomCapped(s32 cap);
+s32 OtherRandomRange(s32 a, s32 b);
+
+#endif // GUARD_OTHER_RANDOM_H
diff --git a/ld_script.txt b/ld_script.txt
index 1eb1602..07163b1 100644
--- a/ld_script.txt
+++ b/ld_script.txt
@@ -37,7 +37,7 @@ SECTIONS {
asm/code.o(.text);
asm/memory.o(.text);
asm/code_80035F0.o(.text);
- asm/other_random.o(.text);
+ src/other_random.o(.text);
asm/util.o(.text);
asm/bg_palette_buffer.o(.text);
asm/code_80047E8.o(.text);
diff --git a/src/other_random.c b/src/other_random.c
new file mode 100644
index 0000000..847530e
--- /dev/null
+++ b/src/other_random.c
@@ -0,0 +1,20 @@
+#include "global.h"
+#include "other_random.h"
+
+extern u16 gOtherRngState;
+
+static s32 OtherRandom16(void)
+{
+ gOtherRngState = 109 * gOtherRngState + 1021;
+ return gOtherRngState;
+}
+
+s32 OtherRandomCapped(s32 cap)
+{
+ return (OtherRandom16() * cap) >> 16;
+}
+
+s32 OtherRandomRange(s32 a, s32 b)
+{
+ return OtherRandomCapped(b - a) + a;
+}
diff --git a/sym_ewram2.txt b/sym_ewram2.txt
index 2785f4e..9c9ec5b 100644
--- a/sym_ewram2.txt
+++ b/sym_ewram2.txt
@@ -73,7 +73,7 @@ gUnknown_203B03C: @ 203B03C
gUnknown_203B040: @ 203B040
.space 0x30
-gUnknown_203B070: @ 203B070
+gOtherRngState: @ 203B070
.space 0x4
gUnknown_203B074: @ 203B074