Merge pull request #43 from AnonymousRandomPerson/main

Decomped LFO functions
This commit is contained in:
AnonymousRandomPerson 2023-12-10 13:52:01 -05:00 committed by GitHub
commit 84cc8892e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 543 additions and 471 deletions

View File

@ -405,6 +405,10 @@
.public SoundEnvelopeStop
.public SoundEnvelopeStop2
.public SoundEnvelopeTick
.public SoundLfoBankReset
.public SoundLfoBankSet
.public SoundLfoBankSetConstEnvelopes
.public SoundLfoBankTick
.public SPECIAL_BAND_STAT_BOOST
.public SprintfStatic__02054A60
.public StartThread
@ -571,10 +575,6 @@
.public sub_020534BC
.public sub_02053D1C
.public sub_02053F10
.public sub_0207509C
.public sub_020750B4
.public sub_020752AC
.public sub_020752F8
.public sub_02075600
.public sub_020756E8
.public sub_02079800

View File

@ -1517,7 +1517,6 @@
.public _020A9EA4
.public _020A9EB8
.public _020A9ECC
.public _020A9FA0
.public _020AE0B4
.public _020AE0C4
.public _020AE0C6
@ -1536,7 +1535,6 @@
.public _020AEEF0
.public _020AF38C
.public _020AFE44
.public _020B1250
.public _020B2B94
.public _020B2B98
.public _020B2B9C
@ -1716,7 +1714,6 @@
.public ARM9_UNKNOWN_TABLE__NA_20ADFB0
.public ARM9_UNKNOWN_TABLE__NA_20AE924
.public BaseFormsEqual
.public DRIVER_WORK
.public DTCM_BSS
.public GetKeyM2N
.public GetKeyM2NBaseForm
@ -1727,8 +1724,6 @@
.public MIi_UncompressBackward
.public MISSION_FLOOR_RANKS_AND_ITEM_LISTS_1
.public MISSION_FLOOR_RANKS_AND_ITEM_LISTS_2
.public MUSIC_DURATION_LOOKUP_TABLE_1
.public MUSIC_DURATION_LOOKUP_TABLE_2
.public OS_IRQTable
.public OSi_ReferSymbol
.public RANK_STRINGS_1
@ -1747,6 +1742,16 @@
.public SDK_SECTION_ARENA_DTCM_START
.public SDK_SECTION_ARENA_EX_START
.public SDK_SECTION_ARENA_ITCM_START
.public SoundLfoWaveFullNoiseFunc
.public SoundLfoWaveFullSquareFunc
.public SoundLfoWaveFullTriangleFunc
.public SoundLfoWaveHalfNoiseFunc
.public SoundLfoWaveHalfSquareFunc
.public SoundLfoWaveHalfTriangleFunc
.public SoundLfoWaveInvalidFunc
.public SoundLfoWaveReverseSawFunc
.public SoundLfoWaveSawFunc
.public SoundUtilGetRandomNumber
.public STRING_BALANCE_M_LEVEL_BIN
.public STRING_DUNGEON_DUNGEON_BIN
.public STRING_EFFECT_EFFECT_BIN
@ -1891,7 +1896,6 @@
.public sub_0206074C
.public sub_02060804
.public sub_02060904
.public sub_0206C8F4
.public sub_0206CC14
.public sub_0206F808
.public sub_0206FD88

View File

@ -28987,8 +28987,8 @@ sub_0206C8C4: ; 0x0206C8C4
bx lr
arm_func_end sub_0206C8C4
arm_func_start sub_0206C8F4
sub_0206C8F4: ; 0x0206C8F4
arm_func_start SoundUtilGetRandomNumber
SoundUtilGetRandomNumber: ; 0x0206C8F4
ldr r1, _0206C914 ; =DRIVER_WORK
ldr r0, _0206C918 ; =0x00007FFF
ldr r2, [r1, #0x34]
@ -29000,7 +29000,7 @@ sub_0206C8F4: ; 0x0206C8F4
.align 2, 0
_0206C914: .word DRIVER_WORK
_0206C918: .word 0x00007FFF
arm_func_end sub_0206C8F4
arm_func_end SoundUtilGetRandomNumber
arm_func_start sub_0206C91C
sub_0206C91C: ; 0x0206C91C
@ -33178,7 +33178,7 @@ _0206FFE0:
mov r1, fp
bl SoundEnvelopeForceVolume
add r0, r7, #0x5c
bl sub_0207509C
bl SoundLfoBankReset
mov r0, #1
strh r0, [r7, #6]
ldrb r0, [sl, #0x1f]
@ -33686,7 +33686,7 @@ FlushChannels: ; 0x02070674
mvn r1, #0xc0000000
bl SoundEnvelopeForceVolume
add r0, r5, #0x5c
bl sub_0207509C
bl SoundLfoBankReset
mov r0, #0
strh r0, [r5, #6]
mov r0, #0x10
@ -33811,7 +33811,7 @@ _02070810:
add r0, sl, #0x3c
bl SoundEnvelopeForceVolume
add r0, sl, #0x5c
bl sub_0207509C
bl SoundLfoBankReset
add sb, sb, #1
strh r5, [sl, #6]
cmp sb, #2
@ -37986,7 +37986,7 @@ sub_02073C5C: ; 0x02073C5C
_02073C74:
mov r1, r5
add r0, r4, #0x5c
bl sub_020752AC
bl SoundLfoBankSetConstEnvelopes
ldr r4, [r4, #0x154]
cmp r4, #0
bne _02073C74
@ -38027,7 +38027,7 @@ sub_02073CD8: ; 0x02073CD8
ldrb r0, [r5, #0xc]
sub r0, r2, r0
add r6, r0, #1
bl sub_0206C8F4
bl SoundUtilGetRandomNumber
mul r1, r6, r0
mov r0, r1, asr #0xe
ldrb r2, [r5, #0xc]
@ -38188,7 +38188,7 @@ sub_02073EDC: ; 0x02073EDC
moveq r0, #0
streq r0, [sp]
beq _02073F28
bl sub_0206C8F4
bl SoundUtilGetRandomNumber
mov r1, r4, lsl #1
mul r2, r1, r0
mov r0, r2, asr #0xe
@ -38317,7 +38317,7 @@ _020740B0:
orr r2, r2, #0xff0
strh r2, [r4, #6]
ldrsb r2, [sl, #0x51]
bl sub_020750B4
bl SoundLfoBankSet
add r0, r5, #0x20
add r8, r4, #0x3c
ldmia r0, {r0, r1, r2, r3}
@ -38514,7 +38514,7 @@ _02074364:
strb r5, [sb, #0x17]
bl SoundEnvelopeReset
add r0, sb, #0x5c
bl sub_0207509C
bl SoundLfoBankReset
str r4, [sb, #0x154]
str r4, [sb, #0x158]
ldrh r0, [sl, #0x2e]
@ -38602,7 +38602,7 @@ _020744B0:
cmp r1, #1
bne _02074514
add r0, r5, #0x5c
bl sub_020752F8
bl SoundLfoBankTick
ldrh r1, [r5, #6]
orr r0, r1, r0
strh r0, [r5, #6]

View File

@ -1,430 +1,8 @@
.include "asm/macros.inc"
.include "main_0207509C.inc"
.include "main_02075600.inc"
.text
arm_func_start sub_0207509C
sub_0207509C: ; 0x0207509C
mov r1, #0
str r1, [r0]
str r1, [r0, #4]
str r1, [r0, #8]
str r1, [r0, #0xc]
bx lr
arm_func_end sub_0207509C
arm_func_start sub_020750B4
sub_020750B4: ; 0x020750B4
stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, lr}
sub sp, sp, #0x20
mov sb, r0
ldr ip, _0207529C ; =_020A9FA0
add r7, sp, #0
mov r8, r1
add r4, sb, #0xc
add r5, sb, #0x10
mov r6, #0
mov r3, #4
_020750DC:
ldrh r1, [ip]
ldrh r0, [ip, #2]
add ip, ip, #4
strh r1, [r7]
strh r0, [r7, #2]
add r7, r7, #4
subs r3, r3, #1
bne _020750DC
ldr r1, _020752A0 ; =0x81020409
mov r3, r2, lsl #8
smull r0, r7, r1, r3
add r7, r7, r2, lsl #8
mov r0, r3, lsr #0x1f
add r7, r0, r7, asr #6
mov r7, r7, lsl #0x10
_02075118:
ldrb lr, [r8, #1]
cmp lr, #0
beq _02075278
add ip, sp, #0
add r3, sp, #0x10
mov r2, #4
_02075130:
ldrh r1, [ip]
ldrh r0, [ip, #2]
add ip, ip, #4
strh r1, [r3]
strh r0, [r3, #2]
add r3, r3, #4
subs r2, r2, #1
bne _02075130
strb lr, [r5, #1]
mov r1, #0
strb r1, [r5]
str r1, [r5, #8]
ldrb r0, [r8, #1]
cmp r0, #1
bne _020751D8
ldrh r2, [r8, #0xa]
mov r0, #0x3e8
ldr r1, _020752A4 ; =DRIVER_WORK
mul r0, r2, r0
ldrsh r1, [r1, #0x28]
bl _s32_div_f
strh r0, [r5, #0x1a]
ldr r1, _020752A4 ; =DRIVER_WORK
ldrh r2, [r8, #0xc]
mov r0, #0x3e8
ldrsh r1, [r1, #0x28]
mul r0, r2, r0
bl _s32_div_f
movs r1, r0
strh r1, [r5, #0x1e]
beq _020751C4
mov r0, #0
str r0, [r5, #0x20]
mov r0, #0x1000000
bl _s32_div_f
str r0, [r5, #0x24]
b _020751E4
_020751C4:
mov r0, #0x1000000
str r0, [r5, #0x20]
mov r0, #0
str r0, [r5, #0x24]
b _020751E4
_020751D8:
strh r1, [r5, #0x1a]
strh r1, [r5, #0x1e]
str r7, [r5, #0x20]
_020751E4:
mov r0, #0
strh r0, [r5, #6]
str r0, [r5, #0x14]
ldrh r1, [r8, #8]
cmp r1, #0
streqh r0, [r5, #6]
streqh r0, [r5, #4]
beq _02075240
mov r0, #0x3e8
mul r0, r1, r0
ldr r1, _020752A4 ; =DRIVER_WORK
ldrsh r1, [r1, #0x28]
bl _s32_div_f
movs r1, r0
addeq r1, r1, #1
strh r1, [r5, #4]
mov r0, #0
strh r0, [r5, #6]
ldr r0, [r8, #4]
mov r0, r0, lsl #0xa
str r0, [r5, #0xc]
bl _s32_div_f
str r0, [r5, #0x14]
_02075240:
ldrb r2, [r8, #3]
ldr r1, _020752A8 ; =_020B1250
add r0, sp, #0x10
ldr r1, [r1, r2, lsl #2]
str r1, [r5, #0x2c]
ldrb r1, [r8, #2]
add r1, sb, r1, lsl #1
str r1, [r5, #0x28]
ldrb r1, [r8, #2]
mov r1, r1, lsl #1
ldrh r0, [r0, r1]
strh r0, [r5, #2]
str r5, [r4]
add r4, r5, #0x30
_02075278:
add r6, r6, #1
cmp r6, #4
add r8, r8, #0x10
add r5, r5, #0x34
blt _02075118
mov r0, #0
str r0, [r4]
add sp, sp, #0x20
ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, pc}
.align 2, 0
_0207529C: .word _020A9FA0
_020752A0: .word 0x81020409
_020752A4: .word DRIVER_WORK
_020752A8: .word _020B1250
arm_func_end sub_020750B4
arm_func_start sub_020752AC
sub_020752AC: ; 0x020752AC
stmdb sp!, {r3, lr}
ldr lr, [r0, #0xc]
cmp lr, #0
ldmeqia sp!, {r3, pc}
ldr r2, _020752F4 ; =0x81020409
mov r3, r1, lsl #8
smull r0, ip, r2, r3
add ip, ip, r1, lsl #8
mov r0, r3, lsr #0x1f
add ip, r0, ip, asr #6
mov r1, ip, lsl #0x10
_020752D8:
ldrb r0, [lr, #1]
cmp r0, #3
streq r1, [lr, #0x20]
ldr lr, [lr, #0x30]
cmp lr, #0
bne _020752D8
ldmia sp!, {r3, pc}
.align 2, 0
_020752F4: .word 0x81020409
arm_func_end sub_020752AC
arm_func_start sub_020752F8
sub_020752F8: ; 0x020752F8
stmdb sp!, {r4, r5, r6, lr}
mov r6, #0
str r6, [r0]
str r6, [r0, #4]
str r6, [r0, #8]
ldr r5, [r0, #0xc]
cmp r5, #0
beq _020753A4
mov r4, #0x1000000
_0207531C:
ldrh r0, [r5, #0x1a]
cmp r0, #0
subne r0, r0, #1
strneh r0, [r5, #0x1a]
bne _02075398
ldr r1, [r5, #0x2c]
mov r0, r5
blx r1
ldrh r1, [r5, #0x1e]
mov r0, r0, asr #8
cmp r1, #0
beq _02075374
sub r1, r1, #1
strh r1, [r5, #0x1e]
ldrh r1, [r5, #0x1e]
cmp r1, #0
streq r4, [r5, #0x20]
beq _02075374
ldr r2, [r5, #0x20]
ldr r1, [r5, #0x24]
add r1, r2, r1
str r1, [r5, #0x20]
_02075374:
ldr r2, [r5, #0x20]
ldr r1, [r5, #0x28]
mov r2, r2, lsr #8
mul r2, r0, r2
ldrsh r0, [r1]
add r0, r0, r2, asr #16
strh r0, [r1]
ldrh r0, [r5, #2]
orr r6, r6, r0
_02075398:
ldr r5, [r5, #0x30]
cmp r5, #0
bne _0207531C
_020753A4:
mov r0, r6
ldmia sp!, {r4, r5, r6, pc}
arm_func_end sub_020752F8
arm_func_start sub_020753AC
sub_020753AC: ; 0x020753AC
mov r1, #0
strb r1, [r0]
strb r1, [r0, #1]
mov r0, r1
bx lr
arm_func_end sub_020753AC
arm_func_start sub_020753C0
sub_020753C0: ; 0x020753C0
ldrh r1, [r0, #6]
cmp r1, #0
bne _020753E8
ldrh r1, [r0, #4]
strh r1, [r0, #6]
ldr r1, [r0, #8]
cmp r1, #0
movne r1, #0
ldreq r1, [r0, #0xc]
str r1, [r0, #8]
_020753E8:
ldrh r1, [r0, #6]
sub r1, r1, #1
strh r1, [r0, #6]
ldr r0, [r0, #8]
bx lr
arm_func_end sub_020753C0
arm_func_start sub_020753FC
sub_020753FC: ; 0x020753FC
ldrh r1, [r0, #6]
cmp r1, #0
bne _02075430
ldrh r1, [r0, #4]
strh r1, [r0, #6]
ldrb r1, [r0]
tst r1, #2
ldr r1, [r0, #0xc]
rsbne r1, r1, #0
str r1, [r0, #8]
ldrb r1, [r0]
eor r1, r1, #2
strb r1, [r0]
_02075430:
ldrh r1, [r0, #6]
sub r1, r1, #1
strh r1, [r0, #6]
ldr r0, [r0, #8]
bx lr
arm_func_end sub_020753FC
arm_func_start sub_02075444
sub_02075444: ; 0x02075444
ldrh r1, [r0, #6]
cmp r1, #0
bne _02075474
ldrb r2, [r0]
ldrh r1, [r0, #4]
tst r2, #1
strh r1, [r0, #6]
ldrne r1, [r0, #0x14]
rsbne r1, r1, #0
strne r1, [r0, #0x14]
orr r1, r2, #1
strb r1, [r0]
_02075474:
ldrh r1, [r0, #6]
sub r1, r1, #1
strh r1, [r0, #6]
ldr r2, [r0, #8]
ldr r1, [r0, #0x14]
add r1, r2, r1
str r1, [r0, #8]
mov r0, r1
bx lr
arm_func_end sub_02075444
arm_func_start sub_02075498
sub_02075498: ; 0x02075498
ldrh r2, [r0, #6]
cmp r2, #0
bne _020754DC
ldrb r3, [r0]
ldrh r2, [r0, #4]
tst r3, #1
beq _020754C4
ldr r1, [r0, #0x14]
rsb r1, r1, #0
str r1, [r0, #0x14]
b _020754D4
_020754C4:
mov r1, r2, lsl #0xf
mov r2, r1, lsr #0x10
cmp r2, #1
movlo r2, #1
_020754D4:
orr r1, r3, #1
strb r1, [r0]
_020754DC:
sub r1, r2, #1
strh r1, [r0, #6]
ldr r2, [r0, #8]
ldr r1, [r0, #0x14]
add r1, r2, r1
str r1, [r0, #8]
mov r0, r1
bx lr
arm_func_end sub_02075498
arm_func_start sub_020754FC
sub_020754FC: ; 0x020754FC
ldrh r1, [r0, #6]
cmp r1, #0
ldrne r2, [r0, #8]
ldrne r1, [r0, #0x14]
addne r1, r2, r1
bne _02075520
ldrh r2, [r0, #4]
mov r1, #0
strh r2, [r0, #6]
_02075520:
str r1, [r0, #8]
ldrh r1, [r0, #6]
sub r1, r1, #1
strh r1, [r0, #6]
ldr r0, [r0, #8]
bx lr
arm_func_end sub_020754FC
arm_func_start sub_02075538
sub_02075538: ; 0x02075538
ldrh r1, [r0, #6]
cmp r1, #0
ldrne r2, [r0, #8]
ldrne r1, [r0, #0x14]
subne r1, r2, r1
bne _0207555C
ldrh r1, [r0, #4]
strh r1, [r0, #6]
ldr r1, [r0, #0xc]
_0207555C:
str r1, [r0, #8]
ldrh r1, [r0, #6]
sub r1, r1, #1
strh r1, [r0, #6]
ldr r0, [r0, #8]
bx lr
arm_func_end sub_02075538
arm_func_start sub_02075574
sub_02075574: ; 0x02075574
stmdb sp!, {r4, lr}
mov r4, r0
ldrh r0, [r4, #6]
cmp r0, #0
bne _020755A4
ldrh r0, [r4, #4]
strh r0, [r4, #6]
bl sub_0206C8F4
ldr r1, [r4, #0xc]
mov r1, r1, asr #0x10
mul r0, r1, r0
str r0, [r4, #8]
_020755A4:
ldrh r0, [r4, #6]
sub r0, r0, #1
strh r0, [r4, #6]
ldr r0, [r4, #8]
ldmia sp!, {r4, pc}
arm_func_end sub_02075574
arm_func_start sub_020755B8
sub_020755B8: ; 0x020755B8
stmdb sp!, {r3, r4, r5, lr}
mov r4, r0
ldrh r0, [r4, #6]
cmp r0, #0
bne _020755EC
ldrh r0, [r4, #4]
strh r0, [r4, #6]
ldr r5, [r4, #0xc]
bl sub_0206C8F4
mov r1, r5, asr #0xf
mul r0, r1, r0
sub r0, r0, r5, asr #1
str r0, [r4, #8]
_020755EC:
ldrh r0, [r4, #6]
sub r0, r0, #1
strh r0, [r4, #6]
ldr r0, [r4, #8]
ldmia sp!, {r3, r4, r5, pc}
arm_func_end sub_020755B8
arm_func_start sub_02075600
sub_02075600: ; 0x02075600
ldr r0, _0207561C ; =_022B9208
@ -51230,8 +50808,8 @@ _020A9F84:
.global _020A9F98
_020A9F98:
.byte 0x65, 0x72, 0x72, 0x6F, 0x72, 0x21, 0x00, 0x00
.global _020A9FA0
_020A9FA0:
.global LFO_OUTPUT_VOICE_UPDATE_FLAGS
LFO_OUTPUT_VOICE_UPDATE_FLAGS:
.byte 0x00, 0x00, 0x10, 0x00
.byte 0x20, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
.global TRIG_TABLE
@ -54120,24 +53698,24 @@ MUSIC_DURATION_LOOKUP_TABLE_2:
.byte 0x41, 0xAA, 0x03, 0x00, 0x21, 0xC0, 0x03, 0x00, 0x54, 0xD6, 0x03, 0x00, 0xDA, 0xEC, 0x03, 0x00
.byte 0xB5, 0x03, 0x04, 0x00, 0xE5, 0x1A, 0x04, 0x00, 0x6A, 0x32, 0x04, 0x00, 0x45, 0x4A, 0x04, 0x00
.byte 0x77, 0x62, 0x04, 0x00, 0x00, 0x7B, 0x04, 0x00, 0xFF, 0xFF, 0xFF, 0x7F
.global _020B1250
_020B1250:
.word sub_020753C0
.word sub_020753FC
.word sub_02075444
.word sub_02075498
.word sub_020754FC
.word sub_02075538
.word sub_02075574
.word sub_020755B8
.word sub_020753AC
.word sub_020753AC
.word sub_020753AC
.word sub_020753AC
.word sub_020753AC
.word sub_020753AC
.word sub_020753AC
.word sub_020753AC
.global LFO_WAVEFORM_CALLBACKS
LFO_WAVEFORM_CALLBACKS:
.word SoundLfoWaveHalfSquareFunc
.word SoundLfoWaveFullSquareFunc
.word SoundLfoWaveHalfTriangleFunc
.word SoundLfoWaveFullTriangleFunc
.word SoundLfoWaveSawFunc
.word SoundLfoWaveReverseSawFunc
.word SoundLfoWaveHalfNoiseFunc
.word SoundLfoWaveFullNoiseFunc
.word SoundLfoWaveInvalidFunc
.word SoundLfoWaveInvalidFunc
.word SoundLfoWaveInvalidFunc
.word SoundLfoWaveInvalidFunc
.word SoundLfoWaveInvalidFunc
.word SoundLfoWaveInvalidFunc
.word SoundLfoWaveInvalidFunc
.word SoundLfoWaveInvalidFunc
.global _020B1290
_020B1290:
.byte 0x00, 0x01, 0x02, 0x03

View File

@ -77,11 +77,11 @@ PRECOMPILE_OBJ_DIR := $(dir $(PRECOMPILE_OBJ))
PRECOMPILE_DEPFILE := $(BUILD_DIR)/precompile/global.d
# Directories
LIB_SUBDIRS := NitroSDK
LIB_SUBDIRS := DSE
SRC_SUBDIR := src
ASM_SUBDIR := asm
LIB_SRC_SUBDIR := lib/src $(LIB_SUBDIRS:%=lib/%/src)
LIB_ASM_SUBDIR := lib/asm
LIB_ASM_SUBDIR := lib/asm $(LIB_SUBDIRS:%=lib/%/asm)
ALL_SUBDIRS := $(SRC_SUBDIR) $(ASM_SUBDIR) $(LIB_SRC_SUBDIR) $(LIB_ASM_SUBDIR)
SRC_BUILDDIR := $(addprefix $(BUILD_DIR)/,$(SRC_SUBDIR))

144
lib/DSE/asm/dc_lfo_1.s Normal file
View File

@ -0,0 +1,144 @@
.include "asm/macros.inc"
.include "include/dc_lfo_1.inc"
.text
; https://decomp.me/scratch/Md0hi
arm_func_start SoundLfoBankSet
SoundLfoBankSet: ; 0x020750B4
stmdb sp!, {r3, r4, r5, r6, r7, r8, sb, lr}
sub sp, sp, #0x20
mov sb, r0
ldr ip, _0207529C ; =LFO_OUTPUT_VOICE_UPDATE_FLAGS
add r7, sp, #0
mov r8, r1
add r4, sb, #0xc
add r5, sb, #0x10
mov r6, #0
mov r3, #4
_020750DC:
ldrh r1, [ip]
ldrh r0, [ip, #2]
add ip, ip, #4
strh r1, [r7]
strh r0, [r7, #2]
add r7, r7, #4
subs r3, r3, #1
bne _020750DC
ldr r1, _020752A0 ; =0x81020409
mov r3, r2, lsl #8
smull r0, r7, r1, r3
add r7, r7, r2, lsl #8
mov r0, r3, lsr #0x1f
add r7, r0, r7, asr #6
mov r7, r7, lsl #0x10
_02075118:
ldrb lr, [r8, #1]
cmp lr, #0
beq _02075278
add ip, sp, #0
add r3, sp, #0x10
mov r2, #4
_02075130:
ldrh r1, [ip]
ldrh r0, [ip, #2]
add ip, ip, #4
strh r1, [r3]
strh r0, [r3, #2]
add r3, r3, #4
subs r2, r2, #1
bne _02075130
strb lr, [r5, #1]
mov r1, #0
strb r1, [r5]
str r1, [r5, #8]
ldrb r0, [r8, #1]
cmp r0, #1
bne _020751D8
ldrh r2, [r8, #0xa]
mov r0, #0x3e8
ldr r1, _020752A4 ; =DRIVER_WORK
mul r0, r2, r0
ldrsh r1, [r1, #0x28]
bl _s32_div_f
strh r0, [r5, #0x1a]
ldr r1, _020752A4 ; =DRIVER_WORK
ldrh r2, [r8, #0xc]
mov r0, #0x3e8
ldrsh r1, [r1, #0x28]
mul r0, r2, r0
bl _s32_div_f
movs r1, r0
strh r1, [r5, #0x1e]
beq _020751C4
mov r0, #0
str r0, [r5, #0x20]
mov r0, #0x1000000
bl _s32_div_f
str r0, [r5, #0x24]
b _020751E4
_020751C4:
mov r0, #0x1000000
str r0, [r5, #0x20]
mov r0, #0
str r0, [r5, #0x24]
b _020751E4
_020751D8:
strh r1, [r5, #0x1a]
strh r1, [r5, #0x1e]
str r7, [r5, #0x20]
_020751E4:
mov r0, #0
strh r0, [r5, #6]
str r0, [r5, #0x14]
ldrh r1, [r8, #8]
cmp r1, #0
streqh r0, [r5, #6]
streqh r0, [r5, #4]
beq _02075240
mov r0, #0x3e8
mul r0, r1, r0
ldr r1, _020752A4 ; =DRIVER_WORK
ldrsh r1, [r1, #0x28]
bl _s32_div_f
movs r1, r0
addeq r1, r1, #1
strh r1, [r5, #4]
mov r0, #0
strh r0, [r5, #6]
ldr r0, [r8, #4]
mov r0, r0, lsl #0xa
str r0, [r5, #0xc]
bl _s32_div_f
str r0, [r5, #0x14]
_02075240:
ldrb r2, [r8, #3]
ldr r1, _020752A8 ; =LFO_WAVEFORM_CALLBACKS
add r0, sp, #0x10
ldr r1, [r1, r2, lsl #2]
str r1, [r5, #0x2c]
ldrb r1, [r8, #2]
add r1, sb, r1, lsl #1
str r1, [r5, #0x28]
ldrb r1, [r8, #2]
mov r1, r1, lsl #1
ldrh r0, [r0, r1]
strh r0, [r5, #2]
str r5, [r4]
add r4, r5, #0x30
_02075278:
add r6, r6, #1
cmp r6, #4
add r8, r8, #0x10
add r5, r5, #0x34
blt _02075118
mov r0, #0
str r0, [r4]
add sp, sp, #0x20
ldmia sp!, {r3, r4, r5, r6, r7, r8, sb, pc}
.align 2, 0
_0207529C: .word LFO_OUTPUT_VOICE_UPDATE_FLAGS
_020752A0: .word 0x81020409
_020752A4: .word DRIVER_WORK
_020752A8: .word LFO_WAVEFORM_CALLBACKS
arm_func_end SoundLfoBankSet

View File

@ -0,0 +1,5 @@
#pragma once
.public _s32_div_f
.public DRIVER_WORK
.public LFO_OUTPUT_VOICE_UPDATE_FLAGS
.public LFO_WAVEFORM_CALLBACKS

53
lib/DSE/include/dc_lfo.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef PMDSKY_DC_LFO_H
#define PMDSKY_DC_LFO_H
#define SOUND_LFO_TYPE_INVALID 0
#define SOUND_LFO_TYPE_USE_ENVELOPE 1
#define SOUND_LFO_TYPE_CONST_ENVELOPE 3
struct dse_lfo;
typedef s32 (*SoundLfoWaveformCallback)(struct dse_lfo *lfo);
struct dse_lfo
{
u8 phase_flags;
u8 type;
u16 voice_update_flags;
u16 ticks_per_phase_change;
u16 ticks_until_phase_change;
s32 current_output;
s32 amplitude;
//+0x10
u32 unknown;
s32 output_delta;
u16 unknown_2;
u16 ticks_until_lfo_started;
u16 unknown_3;
u16 lfo_envelope_ticks_left;
//+0x20
s32 envelope_level;
s32 envelope_delta;
s16 *output_ptr;
SoundLfoWaveformCallback waveform_callback;
//+0x30
struct dse_lfo *next;
//+0x34
};
struct dse_lfo_bank
{
s16 outputs[6];
struct dse_lfo *lfo_list;
//+0x10
struct dse_lfo lfos[4]; //Size: 4 * 0x34 = 0xd0
//+0xe0
};
void SoundLfoBankReset(struct dse_lfo_bank *lfo_bank);
#endif //PMDSKY_DC_LFO_H

View File

@ -0,0 +1,20 @@
#ifndef PMDSKY_DC_LFO_2_H
#define PMDSKY_DC_LFO_2_H
#include "dc_lfo.h"
void SoundLfoBankSetConstEnvelopes(struct dse_lfo_bank *lfo_bank, s8 level);
u16 SoundLfoBankTick(struct dse_lfo_bank *lfo_bank);
//Waveform callbacks
s32 SoundLfoWaveInvalidFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveHalfSquareFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveFullSquareFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveHalfTriangleFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveFullTriangleFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveSawFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveReverseSawFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveHalfNoiseFunc(struct dse_lfo *lfo);
s32 SoundLfoWaveFullNoiseFunc(struct dse_lfo *lfo);
#endif //PMDSKY_DC_LFO_2_H

19
lib/DSE/src/dc_lfo.c Normal file
View File

@ -0,0 +1,19 @@
#include "dc_lfo.h"
void SoundLfoBankReset(struct dse_lfo_bank *lfo_bank)
{
/*
lfo_bank->outputs[0] = 0;
lfo_bank->outputs[1] = 0;
lfo_bank->outputs[2] = 0;
lfo_bank->outputs[3] = 0;
lfo_bank->outputs[4] = 0;
lfo_bank->outputs[5] = 0;
*/
*(u32 *)(&lfo_bank->outputs[0]) = 0;
*(u32 *)(&lfo_bank->outputs[2]) = 0;
*(u32 *)(&lfo_bank->outputs[4]) = 0;
lfo_bank->lfo_list = NULL;
}

246
lib/DSE/src/dc_lfo_2.c Normal file
View File

@ -0,0 +1,246 @@
#include "dc_lfo_2.h"
extern s32 SoundUtilGetRandomNumber();
void SoundLfoBankSetConstEnvelopes(struct dse_lfo_bank *lfo_bank, s8 level)
{
struct dse_lfo *lfo;
lfo = lfo_bank->lfo_list;
while (lfo != NULL)
{
if (lfo->type == SOUND_LFO_TYPE_CONST_ENVELOPE)
{
lfo->envelope_level = (((s32)level << 8) / 127 * 0x10000);
}
lfo = lfo->next;
}
}
u16 SoundLfoBankTick(struct dse_lfo_bank *lfo_bank)
{
s32 output;
struct dse_lfo *lfo;
u16 new_flags;
new_flags = 0;
//Clear all outputs
*(u32 *)(&lfo_bank->outputs[0]) = 0;
*(u32 *)(&lfo_bank->outputs[2]) = 0;
*(u32 *)(&lfo_bank->outputs[4]) = 0;
for (lfo = lfo_bank->lfo_list; lfo != NULL; lfo = lfo->next)
{
if (lfo->ticks_until_lfo_started != 0)
{
lfo->ticks_until_lfo_started--;
}
else
{
u32 envelope_level;
output = ((*lfo->waveform_callback)(lfo) >> 8);
if (lfo->lfo_envelope_ticks_left != 0)
{
lfo->lfo_envelope_ticks_left--;
if (lfo->lfo_envelope_ticks_left != 0)
{
lfo->envelope_level += lfo->envelope_delta;
}
else
{
lfo->envelope_level = 0x1000000;
}
}
envelope_level = (u32)lfo->envelope_level;
envelope_level = output * (envelope_level >> 8);
*lfo->output_ptr += ((s32) envelope_level >> 16);
new_flags |= lfo->voice_update_flags;
}
}
return new_flags;
}
s32 SoundLfoWaveInvalidFunc(struct dse_lfo *lfo)
{
lfo->phase_flags = 0;
lfo->type = SOUND_LFO_TYPE_INVALID;
return 0;
}
s32 SoundLfoWaveHalfSquareFunc(struct dse_lfo *lfo)
{
s32 new_output;
/* square: 0 to amplitude */
if (lfo->ticks_until_phase_change == 0)
{
lfo->ticks_until_phase_change = lfo->ticks_per_phase_change;
if (lfo->current_output != 0)
{
new_output = 0;
}
else
{
new_output = lfo->amplitude;
}
lfo->current_output = new_output;
}
lfo->ticks_until_phase_change--;
return lfo->current_output;
}
s32 SoundLfoWaveFullSquareFunc(struct dse_lfo *lfo)
{
s32 new_output;
/* square: switch between amplitude and -amplitude */
if (lfo->ticks_until_phase_change == 0)
{
lfo->ticks_until_phase_change = lfo->ticks_per_phase_change;
if ((lfo->phase_flags & 2) != 0)
{
new_output = -lfo->amplitude;
}
else
{
new_output = lfo->amplitude;
}
lfo->current_output = new_output;
lfo->phase_flags ^= 2;
}
lfo->ticks_until_phase_change--;
return lfo->current_output;
}
s32 SoundLfoWaveHalfTriangleFunc(struct dse_lfo *lfo)
{
u8 flags;
if (lfo->ticks_until_phase_change == 0)
{
flags = lfo->phase_flags;
lfo->ticks_until_phase_change = lfo->ticks_per_phase_change;
if ((flags & 1) != 0)
{
lfo->output_delta = -lfo->output_delta;
}
lfo->phase_flags = (u8)(flags | 0x1);
}
lfo->ticks_until_phase_change--;
lfo->current_output += lfo->output_delta;
return lfo->current_output;
}
s32 SoundLfoWaveFullTriangleFunc(struct dse_lfo *lfo)
{
s32 new_output;
u16 ticks_left;
u8 flags;
ticks_left = lfo->ticks_until_phase_change;
if (ticks_left == 0)
{
ticks_left = lfo->ticks_per_phase_change;
flags = lfo->phase_flags;
if ((flags & 1) != 0)
{
lfo->output_delta = -lfo->output_delta;
}
else
{
ticks_left /= 2;
if (ticks_left < 1)
{
ticks_left = 1;
}
}
lfo->phase_flags = (u8)(flags | 0x1);
}
lfo->ticks_until_phase_change = (u16)(ticks_left - 1u);
new_output = lfo->current_output + lfo->output_delta;
lfo->current_output = new_output;
return new_output;
}
s32 SoundLfoWaveSawFunc(struct dse_lfo *lfo)
{
u16 ticks_left;
ticks_left = lfo->ticks_until_phase_change;
if (ticks_left == 0)
{
lfo->ticks_until_phase_change = lfo->ticks_per_phase_change;
lfo->current_output = 0;
}
else
{
lfo->current_output += lfo->output_delta;
}
lfo->ticks_until_phase_change--;
return lfo->current_output;
}
s32 SoundLfoWaveReverseSawFunc(struct dse_lfo *lfo)
{
s32 new_output;
if (lfo->ticks_until_phase_change == 0)
{
lfo->ticks_until_phase_change = lfo->ticks_per_phase_change;
new_output = lfo->amplitude;
}
else
{
new_output = lfo->current_output - lfo->output_delta;
}
lfo->current_output = new_output;
lfo->ticks_until_phase_change--;
return lfo->current_output;
}
s32 SoundLfoWaveHalfNoiseFunc(struct dse_lfo *lfo)
{
s32 random;
if (lfo->ticks_until_phase_change == 0)
{
lfo->ticks_until_phase_change = lfo->ticks_per_phase_change;
random = SoundUtilGetRandomNumber();
lfo->current_output = (s32)((lfo->amplitude >> 0x10) * random);
}
lfo->ticks_until_phase_change--;
return lfo->current_output;
}
s32 SoundLfoWaveFullNoiseFunc(struct dse_lfo *lfo)
{
s32 random;
s32 amplitude;
if (lfo->ticks_until_phase_change == 0)
{
lfo->ticks_until_phase_change = lfo->ticks_per_phase_change;
amplitude = lfo->amplitude;
random = SoundUtilGetRandomNumber();
lfo->current_output = (s32)((amplitude >> 0xf) * random - (amplitude >> 1));
}
lfo->ticks_until_phase_change--;
return lfo->current_output;
}

View File

@ -15,8 +15,11 @@ Static main
Object asm/main_0200C4CC.o
Object src/main_02054BE0.o
Object asm/main_02054C24.o
Object lib/NitroSDK/src/dc_envelope.o
Object asm/main_0207509C.o
Object lib/DSE/src/dc_envelope.o
Object lib/DSE/src/dc_lfo.o
Object lib/DSE/asm/dc_lfo_1.o
Object lib/DSE/src/dc_lfo_2.o
Object asm/main_02075600.o
}
Autoload ITCM

View File

@ -209,7 +209,7 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma
# Write the new symbol within the header file.
symbol_header_path = os.path.join(HEADER_FOLDER, symbol.file_path.replace('.o', '.h'))
if not os.path.exists(symbol_header_path):
symbol_header_path = os.path.join('lib', 'NitroSDK', symbol_header_path)
symbol_header_path = os.path.join('lib', 'DSE', symbol_header_path)
if symbol.is_data:
if string_length is not None:
symbol_header = f'extern char {base_symbol_name}[{string_length}];\n'
@ -225,7 +225,7 @@ def sync_xmap_symbol(address: int, symbol: SymbolDetails, language: str, yaml_ma
symbol_header = symbol_header.replace('u32', 'uint32_t')
symbol_header = symbol_header.replace('u16', 'uint16_t')
symbol_header = symbol_header.replace('u8', 'uint8_t')
symbol_header = symbol_header.replace('s32', 'int32_t')
symbol_header = symbol_header.replace('s32', 'int')
symbol_header = symbol_header.replace('s16', 'int16_t')
symbol_header = symbol_header.replace('s8', 'int8_t')
else: