Decomped InitDungeonRng

Decomped by @chordtoll
This commit is contained in:
AnonymousRandomPerson 2024-10-28 21:19:41 -04:00
parent 00acb2eded
commit 0e988e9444
9 changed files with 69 additions and 57 deletions

View File

@ -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

View File

@ -0,0 +1,3 @@
#pragma once
.public DUNGEON_PRNG_STATE
.public DUNGEON_PRNG_STATE_SECONDARY_VALUES

View File

@ -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}

View File

@ -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}

View File

@ -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

42
asm/overlay_29_022EAA20.s Normal file
View File

@ -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

View File

@ -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

View File

@ -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

14
src/overlay_29_022EA9EC.c Normal file
View File

@ -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);
}