diff --git a/asm/include/overlay_29_022E9618.inc b/asm/include/overlay_29_022E9618.inc index 22602b4e..a1688bb0 100644 --- a/asm/include/overlay_29_022E9618.inc +++ b/asm/include/overlay_29_022E9618.inc @@ -9,7 +9,6 @@ .public DISPLACEMENTS_WITHIN_3 .public DisplayUi .public DUNGEON_PRNG_STATE -.public DUNGEON_PRNG_STATE_SECONDARY_VALUES .public DUNGEON_PTR .public DungeonRandInt .public EntityIsValid__022E95F4 diff --git a/asm/include/overlay_29_022EAA20.inc b/asm/include/overlay_29_022EAA20.inc new file mode 100644 index 00000000..b8c60004 --- /dev/null +++ b/asm/include/overlay_29_022EAA20.inc @@ -0,0 +1,3 @@ +#pragma once +.public DUNGEON_PRNG_STATE +.public DUNGEON_PRNG_STATE_SECONDARY_VALUES diff --git a/asm/main_02000DE0.s b/asm/main_02000DE0.s index 7066389c..0c43734c 100644 --- a/asm/main_02000DE0.s +++ b/asm/main_02000DE0.s @@ -1942,6 +1942,7 @@ _020025F0: .word _0229AFC0 _020025F4: .word _0229AFE4 arm_func_end sub_02002580 +; https://decomp.me/scratch/mYHOs arm_func_start sub_020025F8 sub_020025F8: ; 0x020025F8 stmdb sp!, {r4, lr} diff --git a/asm/main_02003DB8.s b/asm/main_02003DB8.s index acfeda77..1aa14e5c 100644 --- a/asm/main_02003DB8.s +++ b/asm/main_02003DB8.s @@ -5150,6 +5150,7 @@ _02008160: ldmia sp!, {r3, pc} arm_func_end sub_02008138 +; https://decomp.me/scratch/w0Zq6 arm_func_start FileRom_InitDataTransfer FileRom_InitDataTransfer: ; 0x02008168 stmdb sp!, {r3, lr} diff --git a/asm/overlay_29_022E9618.s b/asm/overlay_29_022E9618.s index 709bad74..ecc7e81f 100644 --- a/asm/overlay_29_022E9618.s +++ b/asm/overlay_29_022E9618.s @@ -1562,59 +1562,3 @@ SetDungeonRngPreseed: ; 0x022EA9DC .align 2, 0 _022EA9E8: .word DUNGEON_PRNG_STATE arm_func_end SetDungeonRngPreseed - - arm_func_start InitDungeonRng -InitDungeonRng: ; 0x022EA9EC - ldr r1, _022EAA18 ; =DUNGEON_PRNG_STATE - orr r2, r0, #1 - str r2, [r1, #0xc] - mov r2, #0 - str r2, [r1, #4] - ldr r1, _022EAA1C ; =DUNGEON_PRNG_STATE_SECONDARY_VALUES -_022EAA04: - str r0, [r1, r2, lsl #2] - add r2, r2, #1 - cmp r2, #5 - blt _022EAA04 - bx lr - .align 2, 0 -_022EAA18: .word DUNGEON_PRNG_STATE -_022EAA1C: .word DUNGEON_PRNG_STATE_SECONDARY_VALUES - arm_func_end InitDungeonRng - - arm_func_start DungeonRand16Bit -DungeonRand16Bit: ; 0x022EAA20 - stmdb sp!, {r3, lr} - ldr r1, _022EAA88 ; =DUNGEON_PRNG_STATE - ldrb r0, [r1] - cmp r0, #0 - ldr r0, _022EAA8C ; =0x5D588B65 - beq _022EAA5C - ldr lr, [r1, #0x10] - ldr r3, _022EAA90 ; =DUNGEON_PRNG_STATE_SECONDARY_VALUES - ldr r1, _022EAA94 ; =0x00269EC3 - ldr r2, [r3, lr, lsl #2] - umull ip, r0, r2, r0 - adds r1, ip, r1 - mov r0, r1, lsl #0x10 - str r1, [r3, lr, lsl #2] - b _022EAA80 -_022EAA5C: - ldr r2, [r1, #4] - add r2, r2, #1 - str r2, [r1, #4] - ldr r2, [r1, #0xc] - mul r0, r2, r0 - add r2, r0, #1 - mov r0, r2, lsr #0x10 - mov r0, r0, lsl #0x10 - str r2, [r1, #0xc] -_022EAA80: - mov r0, r0, lsr #0x10 - ldmia sp!, {r3, pc} - .align 2, 0 -_022EAA88: .word DUNGEON_PRNG_STATE -_022EAA8C: .word 0x5D588B65 -_022EAA90: .word DUNGEON_PRNG_STATE_SECONDARY_VALUES -_022EAA94: .word 0x00269EC3 - arm_func_end DungeonRand16Bit diff --git a/asm/overlay_29_022EAA20.s b/asm/overlay_29_022EAA20.s new file mode 100644 index 00000000..10a98a1d --- /dev/null +++ b/asm/overlay_29_022EAA20.s @@ -0,0 +1,42 @@ + .include "asm/macros.inc" + .include "overlay_29_022EAA20.inc" + + .text + +; https://decomp.me/scratch/UiD3J + arm_func_start DungeonRand16Bit +DungeonRand16Bit: ; 0x022EAA20 + stmdb sp!, {r3, lr} + ldr r1, _022EAA88 ; =DUNGEON_PRNG_STATE + ldrb r0, [r1] + cmp r0, #0 + ldr r0, _022EAA8C ; =0x5D588B65 + beq _022EAA5C + ldr lr, [r1, #0x10] + ldr r3, _022EAA90 ; =DUNGEON_PRNG_STATE_SECONDARY_VALUES + ldr r1, _022EAA94 ; =0x00269EC3 + ldr r2, [r3, lr, lsl #2] + umull ip, r0, r2, r0 + adds r1, ip, r1 + mov r0, r1, lsl #0x10 + str r1, [r3, lr, lsl #2] + b _022EAA80 +_022EAA5C: + ldr r2, [r1, #4] + add r2, r2, #1 + str r2, [r1, #4] + ldr r2, [r1, #0xc] + mul r0, r2, r0 + add r2, r0, #1 + mov r0, r2, lsr #0x10 + mov r0, r0, lsl #0x10 + str r2, [r1, #0xc] +_022EAA80: + mov r0, r0, lsr #0x10 + ldmia sp!, {r3, pc} + .align 2, 0 +_022EAA88: .word DUNGEON_PRNG_STATE +_022EAA8C: .word 0x5D588B65 +_022EAA90: .word DUNGEON_PRNG_STATE_SECONDARY_VALUES +_022EAA94: .word 0x00269EC3 + arm_func_end DungeonRand16Bit diff --git a/include/overlay_29_022EA9EC.h b/include/overlay_29_022EA9EC.h new file mode 100644 index 00000000..adb012b5 --- /dev/null +++ b/include/overlay_29_022EA9EC.h @@ -0,0 +1,6 @@ +#ifndef PMDSKY_OVERLAY_29_022EA9EC_H +#define PMDSKY_OVERLAY_29_022EA9EC_H + +void InitDungeonRng(u32 seed); + +#endif //PMDSKY_OVERLAY_29_022EA9EC_H diff --git a/main.lsf b/main.lsf index 73009aeb..95725160 100644 --- a/main.lsf +++ b/main.lsf @@ -230,6 +230,8 @@ Overlay OVY_29 Object asm/overlay_29_022E37DC.o Object src/dg_uty.o Object asm/overlay_29_022E9618.o + Object src/overlay_29_022EA9EC.o + Object asm/overlay_29_022EAA20.o Object src/dg_random.o Object asm/overlay_29_022EAB50.o Object src/overlay_29_022EC608.o diff --git a/src/overlay_29_022EA9EC.c b/src/overlay_29_022EA9EC.c new file mode 100644 index 00000000..b8d0c1c3 --- /dev/null +++ b/src/overlay_29_022EA9EC.c @@ -0,0 +1,14 @@ +#include "overlay_29_022EA9EC.h" + +extern u32 DUNGEON_PRNG_STATE[]; +extern u32 DUNGEON_PRNG_STATE_SECONDARY_VALUES[]; + +void InitDungeonRng(u32 seed) { + DUNGEON_PRNG_STATE[3] = seed|1; + s32 scratch_0 = 0; + DUNGEON_PRNG_STATE[1] = scratch_0; + do { + DUNGEON_PRNG_STATE_SECONDARY_VALUES[scratch_0]=seed; + scratch_0++; + } while (scratch_0<5); +}