mirror of
https://github.com/pret/pmd-sky.git
synced 2026-10-01 06:37:50 -05:00
Decomp five team-member index accessors
Decompile GetHeroMemberIdx, GetPartnerMemberIdx, GetMainCharacter1MemberIdx, GetMainCharacter2MemberIdx and GetMainCharacter3MemberIdx from asm/main_02054E4C.s. Each returns the index of a TEAM_MEMBER_TABLE_PTR->members entry when that entry's is_valid bit is set, or -1 otherwise: hero is index 0, partner index 1, and the GetMainCharacter functions choose the index by game mode -- 2/3/4 during a special episode, 0/1/none otherwise. They are the index returning counterparts of the pointer accessors in the previous commit and merge into a new src/main_0205567C.c. The return type is u32. This matters: with a signed int return, the compiler recognises `valid ? 0 : -1` as the idiom -(!valid) and emits an arithmetic negate, but the target uses a conditional-move select. Under u32, -1 is 0xFFFFFFFF, the negate idiom no longer applies, and the compiler emits the select the target has. The distinction is only observable for hero, whose index is the constant 0; for the others the index is non-zero or runtime, so both signednesses produce the select. The whole family is typed u32 for consistency, and sub_02065050, which calls two of these, was rebuilt to confirm the type change leaves it byte-identical. No new names are introduced. struct team_member_table, struct ground_monster and TEAM_MEMBER_TABLE_PTR already exist in the tree, and the five function names were already labelled; this commit only fills in bodies. No comments are added to any pmd-sky file. Authored by Claude (Opus 4.8) under human direction. Confirmed by a matching build: build/pmdsky.us/pmdsky.us.nds: OK. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -616,100 +616,3 @@ _02055638:
|
||||
_02055648: .word TEAM_MEMBER_TABLE_PTR
|
||||
_0205564C: .word 0x0000022B
|
||||
arm_func_end GetRecruitMentryIdBySpecies
|
||||
|
||||
arm_func_start GetHeroMemberIdx
|
||||
GetHeroMemberIdx: ; 0x02055650
|
||||
ldr r0, _02055678 ; =TEAM_MEMBER_TABLE_PTR
|
||||
ldr r0, [r0]
|
||||
ldrb r0, [r0]
|
||||
tst r0, #1
|
||||
movne r0, #1
|
||||
moveq r0, #0
|
||||
tst r0, #0xff
|
||||
movne r0, #0
|
||||
mvneq r0, #0
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_02055678: .word TEAM_MEMBER_TABLE_PTR
|
||||
arm_func_end GetHeroMemberIdx
|
||||
|
||||
arm_func_start GetPartnerMemberIdx
|
||||
GetPartnerMemberIdx: ; 0x0205567C
|
||||
ldr r0, _020556A4 ; =TEAM_MEMBER_TABLE_PTR
|
||||
ldr r0, [r0]
|
||||
ldrb r0, [r0, #0x44]
|
||||
tst r0, #1
|
||||
movne r0, #1
|
||||
moveq r0, #0
|
||||
tst r0, #0xff
|
||||
movne r0, #1
|
||||
mvneq r0, #0
|
||||
bx lr
|
||||
.align 2, 0
|
||||
_020556A4: .word TEAM_MEMBER_TABLE_PTR
|
||||
arm_func_end GetPartnerMemberIdx
|
||||
|
||||
arm_func_start GetMainCharacter1MemberIdx
|
||||
GetMainCharacter1MemberIdx: ; 0x020556A8
|
||||
stmdb sp!, {r3, lr}
|
||||
bl GetGameMode
|
||||
cmp r0, #3
|
||||
moveq r0, #2
|
||||
ldr r2, _020556E8 ; =TEAM_MEMBER_TABLE_PTR
|
||||
movne r0, #0
|
||||
mov r1, #0x44
|
||||
smulbb r1, r0, r1
|
||||
ldr r2, [r2]
|
||||
ldrb r1, [r2, r1]
|
||||
tst r1, #1
|
||||
movne r1, #1
|
||||
moveq r1, #0
|
||||
tst r1, #0xff
|
||||
mvneq r0, #0
|
||||
ldmia sp!, {r3, pc}
|
||||
.align 2, 0
|
||||
_020556E8: .word TEAM_MEMBER_TABLE_PTR
|
||||
arm_func_end GetMainCharacter1MemberIdx
|
||||
|
||||
arm_func_start GetMainCharacter2MemberIdx
|
||||
GetMainCharacter2MemberIdx: ; 0x020556EC
|
||||
stmdb sp!, {r3, lr}
|
||||
bl GetGameMode
|
||||
cmp r0, #3
|
||||
moveq r0, #3
|
||||
ldr r2, _0205572C ; =TEAM_MEMBER_TABLE_PTR
|
||||
movne r0, #1
|
||||
mov r1, #0x44
|
||||
smulbb r1, r0, r1
|
||||
ldr r2, [r2]
|
||||
ldrb r1, [r2, r1]
|
||||
tst r1, #1
|
||||
movne r1, #1
|
||||
moveq r1, #0
|
||||
tst r1, #0xff
|
||||
mvneq r0, #0
|
||||
ldmia sp!, {r3, pc}
|
||||
.align 2, 0
|
||||
_0205572C: .word TEAM_MEMBER_TABLE_PTR
|
||||
arm_func_end GetMainCharacter2MemberIdx
|
||||
|
||||
arm_func_start GetMainCharacter3MemberIdx
|
||||
GetMainCharacter3MemberIdx: ; 0x02055730
|
||||
stmdb sp!, {r3, lr}
|
||||
bl GetGameMode
|
||||
cmp r0, #3
|
||||
mvnne r0, #0
|
||||
ldmneia sp!, {r3, pc}
|
||||
ldr r0, _0205576C ; =TEAM_MEMBER_TABLE_PTR
|
||||
ldr r0, [r0]
|
||||
ldrb r0, [r0, #0x110]
|
||||
tst r0, #1
|
||||
movne r0, #1
|
||||
moveq r0, #0
|
||||
tst r0, #0xff
|
||||
movne r0, #4
|
||||
mvneq r0, #0
|
||||
ldmia sp!, {r3, pc}
|
||||
.align 2, 0
|
||||
_0205576C: .word TEAM_MEMBER_TABLE_PTR
|
||||
arm_func_end GetMainCharacter3MemberIdx
|
||||
|
||||
10
include/main_0205567C.h
Normal file
10
include/main_0205567C.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef PMDSKY_MAIN_0205567C_H
|
||||
#define PMDSKY_MAIN_0205567C_H
|
||||
|
||||
u32 GetHeroMemberIdx(void);
|
||||
u32 GetPartnerMemberIdx(void);
|
||||
u32 GetMainCharacter1MemberIdx(void);
|
||||
u32 GetMainCharacter2MemberIdx(void);
|
||||
u32 GetMainCharacter3MemberIdx(void);
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include "common.h"
|
||||
#include "main_02055770.h"
|
||||
#include "main_0205567C.h"
|
||||
|
||||
struct unk_02064F94 {
|
||||
u8 field_0x0[8];
|
||||
@@ -31,8 +32,6 @@ extern struct team_member_table *TEAM_MEMBER_TABLE_PTR;
|
||||
void sub_0201E380(u8* a, u32* b, s16 c, s16 d);
|
||||
|
||||
int GetAppointedLeaderMemberIdx(void);
|
||||
int GetMainCharacter1MemberIdx(void);
|
||||
int GetMainCharacter2MemberIdx(void);
|
||||
int OverlayIsLoaded(s32 overlay_id);
|
||||
int ov11_022E96E4(void);
|
||||
int GetUnitNpcIds(void* buf);
|
||||
|
||||
1
main.lsf
1
main.lsf
@@ -152,6 +152,7 @@ Static main
|
||||
Object src/main_02054C24.o
|
||||
Object src/main_02054DC4.o
|
||||
Object asm/main_02054E4C.o
|
||||
Object src/main_0205567C.o
|
||||
Object src/main_02055770.o
|
||||
Object asm/main_02055894.o
|
||||
Object src/main_02058C3C.o
|
||||
|
||||
61
src/main_0205567C.c
Normal file
61
src/main_0205567C.c
Normal file
@@ -0,0 +1,61 @@
|
||||
#include "main_0205567C.h"
|
||||
#include "common.h"
|
||||
#include "game_mode.h"
|
||||
|
||||
extern struct team_member_table *TEAM_MEMBER_TABLE_PTR;
|
||||
|
||||
u32 GetHeroMemberIdx(void)
|
||||
{
|
||||
bool8 valid = (TEAM_MEMBER_TABLE_PTR->members[0].is_valid & 1) != 0;
|
||||
if (valid) {
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetPartnerMemberIdx(void)
|
||||
{
|
||||
bool8 valid = (TEAM_MEMBER_TABLE_PTR->members[1].is_valid & 1) != 0;
|
||||
if (valid) {
|
||||
return 1;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetMainCharacter1MemberIdx(void)
|
||||
{
|
||||
int idx = (GetGameMode() == GAME_MODE_SPECIAL_EPISODE) ? 2 : 0;
|
||||
bool8 valid = (TEAM_MEMBER_TABLE_PTR->members[(s16)idx].is_valid & 1) != 0;
|
||||
if (valid) {
|
||||
return idx;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetMainCharacter2MemberIdx(void)
|
||||
{
|
||||
int idx = (GetGameMode() == GAME_MODE_SPECIAL_EPISODE) ? 3 : 1;
|
||||
bool8 valid = (TEAM_MEMBER_TABLE_PTR->members[(s16)idx].is_valid & 1) != 0;
|
||||
if (valid) {
|
||||
return idx;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
u32 GetMainCharacter3MemberIdx(void)
|
||||
{
|
||||
bool8 valid;
|
||||
if (GetGameMode() != GAME_MODE_SPECIAL_EPISODE) {
|
||||
return -1;
|
||||
}
|
||||
valid = (TEAM_MEMBER_TABLE_PTR->members[4].is_valid & 1) != 0;
|
||||
if (valid) {
|
||||
return 4;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user