mirror of
https://github.com/pret/pmd-sky.git
synced 2026-08-25 03:55:29 -05:00
Decomp the volume and pan fade track events
Decompile from asm: DseTrackEvent_VolumeFade 0x020723C0 DseTrackEvent_PanFade 0x02072668 Both were deferred near-matches. Each reads a signed byte as the fade target and a little-endian pair as its duration in ticks, writes the target, and then either snaps current to it when the duration is zero, zeroes the duration when there is nothing to travel, or divides the distance by the duration to get the per-tick delta. The two differ only in which struct dse_fade they address -- volume at 0x2c, pan at 0x3c -- both of which already exist in dse.h. What closed them was declaration order, and in the opposite direction to the obvious one. The target loads ptr_next_byte[2] first, then [0] and [1]; writing the target expression first, so that its load comes first in the source, leaves the loads in ascending address order at score 620. Declaring ticks first and the target second emits them in the target's order and scores 0. So for this scheduler the later-declared expression's loads are issued first, and the fix is to write the declarations in the reverse of the order the asm reads them. Seven other spellings of the same two statements were tried -- explicit locals for each byte in the target's load order, s8/s16/s32 intermediates, an inline cast, and a pointer-cast subscript -- and every one of them stayed at 620. Only the declaration swap moves it. The lib/DSE headers extract_function.py generates do not include dse.h, so both were given it; every other header in that directory already does. Three deferred DSE functions remain, and this commit does not close them. DseTrackEvent_TuningFade is the same family with a bend fade plus the SetTuning tail; hoisting container out of channel before the flag test takes it from 935 to 760, which is progress and not a match. DseTrackEvent_SetupKeyBendLfo is unchanged in substance: its instructions have matched for some time and only register assignment differs. All 120 orderings of its five byte locals were tried this time, along with eleven structural variants, and the best is 55 rather than the 65 it sat at; the earlier note suggested exhaustive permutation as the untried move, and it has now been tried and does not close it. 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:
@@ -1,2 +0,0 @@
|
||||
#pragma once
|
||||
.public _s32_div_f
|
||||
@@ -1,2 +0,0 @@
|
||||
#pragma once
|
||||
.public _s32_div_f
|
||||
@@ -1,32 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "include/main_020723C0.inc"
|
||||
|
||||
.text
|
||||
|
||||
arm_func_start DseTrackEvent_VolumeFade
|
||||
DseTrackEvent_VolumeFade: ; 0x020723C0
|
||||
stmdb sp!, {r4, r5, r6, lr}
|
||||
mov r5, r0
|
||||
ldrsb r1, [r5, #2]
|
||||
ldrb r2, [r5]
|
||||
ldrb r0, [r5, #1]
|
||||
mov r4, r3
|
||||
mov r1, r1, lsl #0x10
|
||||
add r0, r2, r0, lsl #8
|
||||
mov r0, r0, lsl #0x10
|
||||
str r1, [r4, #0x34]
|
||||
movs r6, r0, lsr #0x10
|
||||
streq r1, [r4, #0x2c]
|
||||
beq _02072410
|
||||
ldr r0, [r4, #0x2c]
|
||||
subs r0, r1, r0
|
||||
moveq r6, #0
|
||||
beq _02072410
|
||||
mov r1, r6
|
||||
bl _s32_div_f
|
||||
str r0, [r4, #0x30]
|
||||
_02072410:
|
||||
strh r6, [r4, #0x38]
|
||||
add r0, r5, #3
|
||||
ldmia sp!, {r4, r5, r6, pc}
|
||||
arm_func_end DseTrackEvent_VolumeFade
|
||||
@@ -1,32 +0,0 @@
|
||||
.include "asm/macros.inc"
|
||||
.include "include/main_02072668.inc"
|
||||
|
||||
.text
|
||||
|
||||
arm_func_start DseTrackEvent_PanFade
|
||||
DseTrackEvent_PanFade: ; 0x02072668
|
||||
stmdb sp!, {r4, r5, r6, lr}
|
||||
mov r5, r0
|
||||
ldrsb r1, [r5, #2]
|
||||
ldrb r2, [r5]
|
||||
ldrb r0, [r5, #1]
|
||||
mov r4, r3
|
||||
mov r1, r1, lsl #0x10
|
||||
add r0, r2, r0, lsl #8
|
||||
mov r0, r0, lsl #0x10
|
||||
str r1, [r4, #0x44]
|
||||
movs r6, r0, lsr #0x10
|
||||
streq r1, [r4, #0x3c]
|
||||
beq _020726B8
|
||||
ldr r0, [r4, #0x3c]
|
||||
subs r0, r1, r0
|
||||
moveq r6, #0
|
||||
beq _020726B8
|
||||
mov r1, r6
|
||||
bl _s32_div_f
|
||||
str r0, [r4, #0x40]
|
||||
_020726B8:
|
||||
strh r6, [r4, #0x48]
|
||||
add r0, r5, #3
|
||||
ldmia sp!, {r4, r5, r6, pc}
|
||||
arm_func_end DseTrackEvent_PanFade
|
||||
8
lib/DSE/include/main_020723C0.h
Normal file
8
lib/DSE/include/main_020723C0.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef PMDSKY_MAIN_020723C0_H
|
||||
#define PMDSKY_MAIN_020723C0_H
|
||||
|
||||
#include "dse.h"
|
||||
|
||||
u8* DseTrackEvent_VolumeFade(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel);
|
||||
|
||||
#endif
|
||||
8
lib/DSE/include/main_02072668.h
Normal file
8
lib/DSE/include/main_02072668.h
Normal file
@@ -0,0 +1,8 @@
|
||||
#ifndef PMDSKY_MAIN_02072668_H
|
||||
#define PMDSKY_MAIN_02072668_H
|
||||
|
||||
#include "dse.h"
|
||||
|
||||
u8* DseTrackEvent_PanFade(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel);
|
||||
|
||||
#endif
|
||||
22
lib/DSE/src/main_020723C0.c
Normal file
22
lib/DSE/src/main_020723C0.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "main_020723C0.h"
|
||||
|
||||
u8* DseTrackEvent_VolumeFade(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel)
|
||||
{
|
||||
u16 ticks = ptr_next_byte[0] + (ptr_next_byte[1] << 8);
|
||||
s32 target = *(s8 *)&ptr_next_byte[2] << 16;
|
||||
|
||||
channel->volume.target = target;
|
||||
if (ticks == 0) {
|
||||
channel->volume.current = target;
|
||||
} else {
|
||||
s32 diff = target - channel->volume.current;
|
||||
|
||||
if (diff == 0) {
|
||||
ticks = 0;
|
||||
} else {
|
||||
channel->volume.delta = diff / ticks;
|
||||
}
|
||||
}
|
||||
channel->volume.ticks_remaining = ticks;
|
||||
return ptr_next_byte + 3;
|
||||
}
|
||||
22
lib/DSE/src/main_02072668.c
Normal file
22
lib/DSE/src/main_02072668.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "main_02072668.h"
|
||||
|
||||
u8* DseTrackEvent_PanFade(u8 *ptr_next_byte, struct dse_sequence *sequence, struct dse_track *track, struct dse_channel *channel)
|
||||
{
|
||||
u16 ticks = ptr_next_byte[0] + (ptr_next_byte[1] << 8);
|
||||
s32 target = *(s8 *)&ptr_next_byte[2] << 16;
|
||||
|
||||
channel->pan.target = target;
|
||||
if (ticks == 0) {
|
||||
channel->pan.current = target;
|
||||
} else {
|
||||
s32 diff = target - channel->pan.current;
|
||||
|
||||
if (diff == 0) {
|
||||
ticks = 0;
|
||||
} else {
|
||||
channel->pan.delta = diff / ticks;
|
||||
}
|
||||
}
|
||||
channel->pan.ticks_remaining = ticks;
|
||||
return ptr_next_byte + 3;
|
||||
}
|
||||
4
main.lsf
4
main.lsf
@@ -387,13 +387,13 @@ Static main
|
||||
Object lib/DSE/src/main_0207222C.o
|
||||
Object lib/DSE/src/main_0207227C.o
|
||||
Object lib/DSE/src/main_02072310.o
|
||||
Object lib/DSE/asm/main_020723C0.o
|
||||
Object lib/DSE/src/main_020723C0.o
|
||||
Object lib/DSE/src/main_0207241C.o
|
||||
Object lib/DSE/src/main_020724A8.o
|
||||
Object lib/DSE/src/main_02072504.o
|
||||
Object lib/DSE/src/main_02072554.o
|
||||
Object lib/DSE/src/main_020725D4.o
|
||||
Object lib/DSE/asm/main_02072668.o
|
||||
Object lib/DSE/src/main_02072668.o
|
||||
Object lib/DSE/src/main_020726C4.o
|
||||
Object lib/DSE/src/main_02072720.o
|
||||
Object lib/DSE/src/main_02072770.o
|
||||
|
||||
Reference in New Issue
Block a user