Decomp the generic-LFO and note-random-region track events

Decompile from asm:

  DseTrackEvent_SetNoteRandomRegion  0x02072144
  DseTrackEvent_SetupLfoEnvelope     0x020727C8
  DseTrackEvent_UseLfo               0x02072938

SetNoteRandomRegion reads two bytes and stores the smaller in
note_random_region_begin and the larger in note_random_region_end, so the pair
is sorted regardless of the order it was written in.

SetupLfoEnvelope and UseLfo are the indexed forms of the per-slot handlers added
in the previous commit: instead of a fixed lfo_settings entry they take the
index from channel + 0x61, which UseLfo also writes. That byte falls inside
dse.h's field_0x5A[10], so it is spelled field_0x5A[7]; a name for it would have
to come from a real pmdsky-debug sync.

UseLfo needed the sub-struct bound to a pointer local. Indexing
channel->lfo_settings[idx] directly folds the array's 0x74 base into each
store's offset, giving strb [r1, #0x75]; the target computes the element address
once, add r1, r3, #0x74 then add r1, r1, idx lsl #4, and stores at [r1, #1] and
[r1, #2]. Binding struct dse_lfo_settings *lfo also reproduces the frame push
the target has, which no arrangement of the indexed form did.

No comments are added to any pmd-sky file.

Authored by Claude (Opus 5) under human direction. Confirmed by a matching
build: build/pmdsky.us/pmdsky.us.nds: OK.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
cecilarmitais
2026-08-16 15:29:55 -07:00
parent 909484fb99
commit acff5cf391
13 changed files with 204 additions and 166 deletions

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -0,0 +1 @@
#pragma once

View File

@@ -195,17 +195,3 @@ _0207212C:
.align 2, 0
_02072140: .word 0x04000208
arm_func_end DseTrackEvent_TuningFade
arm_func_start DseTrackEvent_SetNoteRandomRegion
DseTrackEvent_SetNoteRandomRegion: ; 0x02072144
ldrb r1, [r0]
ldrb ip, [r0, #1]
add r0, r0, #2
mov r2, r1
cmp r1, ip
movhi r2, ip
movhi ip, r1
strb r2, [r3, #0xc]
strb ip, [r3, #0xd]
bx lr
arm_func_end DseTrackEvent_SetNoteRandomRegion

View File

@@ -28,155 +28,3 @@ DseTrackEvent_SetupLfo: ; 0x02072770
add r0, r0, #5
ldmia sp!, {r4, pc}
arm_func_end DseTrackEvent_SetupLfo
arm_func_start DseTrackEvent_SetupLfoEnvelope
DseTrackEvent_SetupLfoEnvelope: ; 0x020727C8
ldrb ip, [r3, #0x61]
ldrb r2, [r0]
ldrb r1, [r0, #1]
add r3, r3, #0x74
add r3, r3, ip, lsl #4
add r1, r2, r1, lsl #8
strh r1, [r3, #0xa]
ldrb r2, [r0, #2]
ldrb r1, [r0, #3]
add r0, r0, #4
add r1, r2, r1, lsl #8
strh r1, [r3, #0xc]
bx lr
arm_func_end DseTrackEvent_SetupLfoEnvelope
arm_func_start DseTrackEvent_SetLfoParameter
DseTrackEvent_SetLfoParameter: ; 0x020727FC
ldrb r1, [r3, #0x61]
ldrb ip, [r0]
add r2, r3, #0x74
add r1, r2, r1, lsl #4
ldrb r2, [r0, #1]
cmp ip, #0xa
addls pc, pc, ip, lsl #2
b _02072930
_0207281C: ; jump table
b _02072930 ; case 0
b _02072848 ; case 1
b _02072850 ; case 2
b _02072858 ; case 3
b _02072860 ; case 4
b _02072868 ; case 5
b _020728E0 ; case 6
b _020728EC ; case 7
b _020728FC ; case 8
b _02072910 ; case 9
b _02072924 ; case 10
_02072848:
strb r2, [r3, #0x61]
b _02072930
_02072850:
strb r2, [r1, #1]
b _02072930
_02072858:
strb r2, [r1, #2]
b _02072930
_02072860:
strb r2, [r1, #3]
b _02072930
_02072868:
ldrb r3, [r1, #2]
cmp r3, #4
addls pc, pc, r3, lsl #2
b _020728CC
_02072878: ; jump table
b _020728CC ; case 0
b _0207288C ; case 1
b _0207289C ; case 2
b _020728AC ; case 3
b _020728BC ; case 4
_0207288C:
mov r3, #0xa
mul r3, r2, r3
mov r2, r3
b _020728D8
_0207289C:
mvn r3, #0x13
mul r3, r2, r3
mov r2, r3
b _020728D8
_020728AC:
mov r3, #0x14
mul r3, r2, r3
mov r2, r3
b _020728D8
_020728BC:
mov r3, #0xa
mul r3, r2, r3
mov r2, r3
b _020728D8
_020728CC:
mov r3, #0x14
mul r3, r2, r3
mov r2, r3
_020728D8:
str r2, [r1, #4]
b _02072930
_020728E0:
add r2, r2, r2, lsl #2
strh r2, [r1, #8]
b _02072930
_020728EC:
mov r3, #0x14
mul r3, r2, r3
strh r3, [r1, #0xa]
b _02072930
_020728FC:
ldrh r3, [r1, #0xa]
and r3, r3, #0xff00
orr r2, r3, r2
strh r2, [r1, #0xa]
b _02072930
_02072910:
ldrh r3, [r1, #0xa]
and r3, r3, #0xff
orr r2, r3, r2, lsl #8
strh r2, [r1, #0xa]
b _02072930
_02072924:
mov r3, #0x14
mul r3, r2, r3
strh r3, [r1, #0xc]
_02072930:
add r0, r0, #2
bx lr
arm_func_end DseTrackEvent_SetLfoParameter
arm_func_start DseTrackEvent_UseLfo
DseTrackEvent_UseLfo: ; 0x02072938
stmdb sp!, {r3, lr}
ldrb ip, [r0, #1]
ldrb r2, [r0]
ldrb lr, [r0, #2]
add r1, r3, #0x74
cmp ip, #2
strb r2, [r3, #0x61]
add r1, r1, r2, lsl #4
moveq ip, #1
strb ip, [r1, #1]
strb lr, [r1, #2]
add r0, r0, #3
ldmia sp!, {r3, pc}
arm_func_end DseTrackEvent_UseLfo
arm_func_start DseTrackEvent_Signal
DseTrackEvent_Signal: ; 0x0207296C
stmdb sp!, {r4, lr}
mov r4, r0
ldrb r2, [r4]
mov ip, r1
mov r1, #8
strb r2, [ip, #0x16]
ldr r0, [ip, #0x28]
ldr r3, [ip, #0xa0]
ldr ip, [ip, #0x9c]
blx ip
add r0, r4, #1
ldmia sp!, {r4, pc}
arm_func_end DseTrackEvent_Signal

106
lib/DSE/asm/main_020727FC.s Normal file
View File

@@ -0,0 +1,106 @@
.include "asm/macros.inc"
.include "include/main_020727FC.inc"
.text
arm_func_start DseTrackEvent_SetLfoParameter
DseTrackEvent_SetLfoParameter: ; 0x020727FC
ldrb r1, [r3, #0x61]
ldrb ip, [r0]
add r2, r3, #0x74
add r1, r2, r1, lsl #4
ldrb r2, [r0, #1]
cmp ip, #0xa
addls pc, pc, ip, lsl #2
b _02072930
_0207281C: ; jump table
b _02072930 ; case 0
b _02072848 ; case 1
b _02072850 ; case 2
b _02072858 ; case 3
b _02072860 ; case 4
b _02072868 ; case 5
b _020728E0 ; case 6
b _020728EC ; case 7
b _020728FC ; case 8
b _02072910 ; case 9
b _02072924 ; case 10
_02072848:
strb r2, [r3, #0x61]
b _02072930
_02072850:
strb r2, [r1, #1]
b _02072930
_02072858:
strb r2, [r1, #2]
b _02072930
_02072860:
strb r2, [r1, #3]
b _02072930
_02072868:
ldrb r3, [r1, #2]
cmp r3, #4
addls pc, pc, r3, lsl #2
b _020728CC
_02072878: ; jump table
b _020728CC ; case 0
b _0207288C ; case 1
b _0207289C ; case 2
b _020728AC ; case 3
b _020728BC ; case 4
_0207288C:
mov r3, #0xa
mul r3, r2, r3
mov r2, r3
b _020728D8
_0207289C:
mvn r3, #0x13
mul r3, r2, r3
mov r2, r3
b _020728D8
_020728AC:
mov r3, #0x14
mul r3, r2, r3
mov r2, r3
b _020728D8
_020728BC:
mov r3, #0xa
mul r3, r2, r3
mov r2, r3
b _020728D8
_020728CC:
mov r3, #0x14
mul r3, r2, r3
mov r2, r3
_020728D8:
str r2, [r1, #4]
b _02072930
_020728E0:
add r2, r2, r2, lsl #2
strh r2, [r1, #8]
b _02072930
_020728EC:
mov r3, #0x14
mul r3, r2, r3
strh r3, [r1, #0xa]
b _02072930
_020728FC:
ldrh r3, [r1, #0xa]
and r3, r3, #0xff00
orr r2, r3, r2
strh r2, [r1, #0xa]
b _02072930
_02072910:
ldrh r3, [r1, #0xa]
and r3, r3, #0xff
orr r2, r3, r2, lsl #8
strh r2, [r1, #0xa]
b _02072930
_02072924:
mov r3, #0x14
mul r3, r2, r3
strh r3, [r1, #0xc]
_02072930:
add r0, r0, #2
bx lr
arm_func_end DseTrackEvent_SetLfoParameter

View File

@@ -0,0 +1,20 @@
.include "asm/macros.inc"
.include "include/main_0207296C.inc"
.text
arm_func_start DseTrackEvent_Signal
DseTrackEvent_Signal: ; 0x0207296C
stmdb sp!, {r4, lr}
mov r4, r0
ldrb r2, [r4]
mov ip, r1
mov r1, #8
strb r2, [ip, #0x16]
ldr r0, [ip, #0x28]
ldr r3, [ip, #0xa0]
ldr ip, [ip, #0x9c]
blx ip
add r0, r4, #1
ldmia sp!, {r4, pc}
arm_func_end DseTrackEvent_Signal

View File

@@ -0,0 +1,8 @@
#ifndef PMDSKY_MAIN_02072144_H
#define PMDSKY_MAIN_02072144_H
#include "dse.h"
u8* DseTrackEvent_SetNoteRandomRegion(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel);
#endif

View File

@@ -0,0 +1,8 @@
#ifndef PMDSKY_MAIN_020727C8_H
#define PMDSKY_MAIN_020727C8_H
#include "dse.h"
u8* DseTrackEvent_SetupLfoEnvelope(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel);
#endif

View File

@@ -0,0 +1,8 @@
#ifndef PMDSKY_MAIN_02072938_H
#define PMDSKY_MAIN_02072938_H
#include "dse.h"
u8* DseTrackEvent_UseLfo(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel);
#endif

View File

@@ -0,0 +1,18 @@
#include "main_02072144.h"
u8* DseTrackEvent_SetNoteRandomRegion(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel)
{
u8 a = ptr_next_byte[0];
u8 b = ptr_next_byte[1];
u8 lo = a;
u8 hi = b;
ptr_next_byte += 2;
if (a > b) {
lo = b;
hi = a;
}
channel->note_random_region_begin = lo;
channel->note_random_region_end = hi;
return ptr_next_byte;
}

View File

@@ -0,0 +1,11 @@
#include "main_020727C8.h"
u8* DseTrackEvent_SetupLfoEnvelope(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel)
{
struct dse_lfo_settings *lfo = &channel->lfo_settings[channel->field_0x5A[7]];
lfo->msec_until_lfo_started = ptr_next_byte[0] + (ptr_next_byte[1] << 8);
lfo->lfo_envelope_len_msec = ptr_next_byte[2] + (ptr_next_byte[3] << 8);
ptr_next_byte += 4;
return ptr_next_byte;
}

View File

@@ -0,0 +1,18 @@
#include "main_02072938.h"
u8* DseTrackEvent_UseLfo(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel)
{
u8 idx = ptr_next_byte[0];
u8 type = ptr_next_byte[1];
u8 out = ptr_next_byte[2];
struct dse_lfo_settings *lfo = &channel->lfo_settings[idx];
channel->field_0x5A[7] = idx;
if (type == 2) {
type = 1;
}
lfo->type = type;
lfo->output_type = out;
ptr_next_byte += 3;
return ptr_next_byte;
}

View File

@@ -259,6 +259,7 @@ Static main
Object lib/DSE/asm/main_02071AE0.o
Object lib/DSE/src/main_02071BF4.o
Object lib/DSE/asm/main_02071EB4.o
Object lib/DSE/src/main_02072144.o
Object lib/DSE/src/main_0207216C.o
Object lib/DSE/asm/main_02072184.o
Object lib/DSE/src/main_020721B0.o
@@ -269,6 +270,10 @@ Static main
Object lib/DSE/asm/main_02072554.o
Object lib/DSE/src/main_02072720.o
Object lib/DSE/asm/main_02072770.o
Object lib/DSE/src/main_020727C8.o
Object lib/DSE/asm/main_020727FC.o
Object lib/DSE/src/main_02072938.o
Object lib/DSE/asm/main_0207296C.o
Object lib/DSE/src/main_0207299C.o
Object lib/DSE/asm/main_020729A4.o
Object lib/DSE/src/dc_envelope.o