From 17f024a5179351f68eba823f61f02f2c2f934112 Mon Sep 17 00:00:00 2001 From: SNBeast Date: Sun, 27 Jun 2021 19:03:01 -0400 Subject: Decompile unk_02088DD8.s --- arm9/asm/unk_02088DD8.s | 172 ----------------------------------- arm9/global.inc | 2 +- arm9/src/scrcmd_24.c | 8 +- arm9/src/unk_02088DD8.c | 76 ++++++++++++++++ files/graphic/poketch/narc_0010.NCGR | Bin 0 -> 2112 bytes include/unk_02088DD8.h | 9 ++ 6 files changed, 88 insertions(+), 179 deletions(-) delete mode 100644 arm9/asm/unk_02088DD8.s create mode 100644 arm9/src/unk_02088DD8.c create mode 100644 files/graphic/poketch/narc_0010.NCGR diff --git a/arm9/asm/unk_02088DD8.s b/arm9/asm/unk_02088DD8.s deleted file mode 100644 index 3df58ffe..00000000 --- a/arm9/asm/unk_02088DD8.s +++ /dev/null @@ -1,172 +0,0 @@ - .include "asm/macros.inc" - .include "global.inc" - - .text - - thumb_func_start FUN_02088DD8 -FUN_02088DD8: ; 0x02088DD8 - push {r3, lr} - mov r1, #0x18 - bl AllocFromHeap - add r3, r0, #0x0 - mov r2, #0x18 - mov r1, #0x0 -_02088DE6: - strb r1, [r3, #0x0] - add r3, r3, #0x1 - sub r2, r2, #0x1 - bne _02088DE6 - pop {r3, pc} - - thumb_func_start FUN_02088DF0 -FUN_02088DF0: ; 0x02088DF0 - ldr r3, _02088DF4 ; =FreeToHeap - bx r3 - .balign 4 -_02088DF4: .word FreeToHeap - - thumb_func_start FUN_02088DF8 -FUN_02088DF8: ; 0x02088DF8 - push {r3-r7, lr} - sub sp, #0x18 - str r1, [sp, #0x0] - mov r1, #0x5 - mov r2, #0x0 - add r5, r0, #0x0 - bl GetMonData - lsl r0, r0, #0x10 - lsr r0, r0, #0x10 - str r0, [sp, #0xc] - add r0, r5, #0x0 - mov r1, #0x70 - mov r2, #0x0 - bl GetMonData - lsl r0, r0, #0x18 - lsr r0, r0, #0x18 - str r0, [sp, #0x8] - add r0, r5, #0x0 - mov r1, #0xa0 - mov r2, #0x0 - bl GetMonData - lsl r0, r0, #0x18 - lsr r0, r0, #0x18 - mov r4, #0x0 - str r0, [sp, #0x4] - add r7, r4, #0x0 - add r6, sp, #0x10 -_02088E34: - add r1, r4, #0x0 - add r0, r5, #0x0 - add r1, #0x36 - add r2, r7, #0x0 - bl GetMonData - lsl r1, r4, #0x1 - strh r0, [r6, r1] - add r0, r4, #0x1 - lsl r0, r0, #0x18 - lsr r4, r0, #0x18 - cmp r4, #0x4 - blo _02088E34 - ldr r0, [sp, #0x0] - mov r1, #0x2c - bl AllocFromHeap - add r7, r0, #0x0 - ldr r0, [sp, #0x0] - mov r1, #0x2c - bl AllocFromHeap - add r4, r0, #0x0 - ldr r0, [sp, #0xc] - ldr r1, [sp, #0x8] - add r2, r7, #0x0 - bl LoadWotbl_HandleAlternateForme - mov r2, #0x0 - mov r12, r2 -_02088E70: - mov r0, r12 - lsl r0, r0, #0x1 - ldrh r5, [r7, r0] - ldr r6, _02088EF4 ; =0x0000FFFF - cmp r5, r6 - bne _02088E82 - lsl r0, r2, #0x1 - strh r6, [r4, r0] - b _02088EE8 -_02088E82: - mov r1, #0xfe - lsl r1, r1, #0x8 - and r1, r5 - asr r3, r1, #0x9 - ldr r1, [sp, #0x4] - cmp r3, r1 - bgt _02088EDA - lsr r1, r6, #0x7 - and r1, r5 - strh r1, [r7, r0] - ldrh r3, [r7, r0] - mov r1, #0x0 - add r6, sp, #0x10 -_02088E9C: - lsl r5, r1, #0x1 - ldrh r5, [r6, r5] - cmp r3, r5 - beq _02088EAE - add r1, r1, #0x1 - lsl r1, r1, #0x18 - lsr r1, r1, #0x18 - cmp r1, #0x4 - blo _02088E9C -_02088EAE: - cmp r1, #0x4 - bne _02088EDA - mov r1, #0x0 - cmp r2, #0x0 - bls _02088ECA -_02088EB8: - lsl r5, r1, #0x1 - ldrh r5, [r4, r5] - cmp r5, r3 - beq _02088ECA - add r1, r1, #0x1 - lsl r1, r1, #0x18 - lsr r1, r1, #0x18 - cmp r1, r2 - blo _02088EB8 -_02088ECA: - cmp r1, r2 - bne _02088EDA - ldrh r1, [r7, r0] - lsl r0, r2, #0x1 - strh r1, [r4, r0] - add r0, r2, #0x1 - lsl r0, r0, #0x18 - lsr r2, r0, #0x18 -_02088EDA: - mov r0, r12 - add r0, r0, #0x1 - lsl r0, r0, #0x18 - lsr r0, r0, #0x18 - mov r12, r0 - cmp r0, #0x16 - blo _02088E70 -_02088EE8: - add r0, r7, #0x0 - bl FreeToHeap - add r0, r4, #0x0 - add sp, #0x18 - pop {r3-r7, pc} - .balign 4 -_02088EF4: .word 0x0000FFFF - - thumb_func_start FUN_02088EF8 -FUN_02088EF8: ; 0x02088EF8 - ldrh r1, [r0, #0x0] - ldr r0, _02088F08 ; =0x0000FFFF - cmp r1, r0 - beq _02088F04 - mov r0, #0x1 - bx lr -_02088F04: - mov r0, #0x0 - bx lr - .balign 4 -_02088F08: .word 0x0000FFFF diff --git a/arm9/global.inc b/arm9/global.inc index 086d9b5f..e1952cc2 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -5450,7 +5450,7 @@ .extern FUN_02088DBC .extern FUN_02088DD8 .extern FUN_02088DF0 -.extern FUN_02088DF8 +.extern Maybe_GetEligibleLevelUpMoves .extern FUN_02088EF8 .extern FUN_02088F0C .extern FUN_02088F4C diff --git a/arm9/src/scrcmd_24.c b/arm9/src/scrcmd_24.c index b38ed05a..f4330150 100644 --- a/arm9/src/scrcmd_24.c +++ b/arm9/src/scrcmd_24.c @@ -10,10 +10,6 @@ extern struct UnkStruct_02037CF0* FUN_02037CF0(u32 heap_id, struct UnkSavStruct8 extern u8 FUN_02037D5C(struct UnkStruct_02037CF0*); extern void FUN_02038864(struct UnkSavStruct80*, struct UnkStruct_02088DD8*); extern BOOL FUN_0203BC04(struct ScriptContext* ctx); -extern struct UnkStruct_02088DD8* FUN_02088DD8(u32 heap_id); -extern void FUN_02088DF0(struct UnkStruct_02037CF0*); -extern void* FUN_02088DF8(struct Pokemon* pokemon, u32 heap_id); -extern BOOL FUN_02088EF8(void*); THUMB_FUNC BOOL ScrCmd_Unk01C6(struct ScriptContext* ctx) { @@ -57,7 +53,7 @@ THUMB_FUNC BOOL ScrCmd_Unk021F(struct ScriptContext* ctx) u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2); struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); - void* unk_ptr = FUN_02088DF8(pokemon, 32); + void* unk_ptr = Maybe_GetEligibleLevelUpMoves(pokemon, 32); *ret_ptr = (u16)FUN_02088EF8(unk_ptr); FreeToHeap(unk_ptr); @@ -96,7 +92,7 @@ THUMB_FUNC BOOL ScrCmd_Unk0221(struct ScriptContext* ctx) u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2); struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); - void* unk_ptr = FUN_02088DF8(pokemon, 32); + void* unk_ptr = Maybe_GetEligibleLevelUpMoves(pokemon, 32); FUN_02045E74(ctx, 1, pokemon, unk_ptr); return TRUE; diff --git a/arm9/src/unk_02088DD8.c b/arm9/src/unk_02088DD8.c new file mode 100644 index 00000000..acc59701 --- /dev/null +++ b/arm9/src/unk_02088DD8.c @@ -0,0 +1,76 @@ +#include "global.h" +#include "heap.h" +#include "pokemon.h" +#include "unk_02088DD8.h" + +THUMB_FUNC struct UnkStruct_02088DD8* FUN_02088DD8(u32 r0) { + struct UnkStruct_02088DD8 *returnPointer = AllocFromHeap(r0, 24); + __builtin__clear(returnPointer, 24); + return returnPointer; +} + +THUMB_FUNC void FUN_02088DF0(struct UnkStruct_02037CF0 *r0) { + FreeToHeap(r0); +} + +#define WOTBL_END 0xFFFF +#define WOTBL_MOVE_MASK 0x01FF +#define WOTBL_MOVE_SHIFT 0 +#define WOTBL_LVL_MASK 0xFE00 +#define WOTBL_LVL_SHIFT 9 +#define WOTBL_MOVE(x) ((u16)(((x) & WOTBL_MOVE_MASK) >> WOTBL_MOVE_SHIFT)) +#define WOTBL_LVL(x) (/*(u8)*/(((x) & WOTBL_LVL_MASK) >> WOTBL_LVL_SHIFT)) +// i don't know why either. + +THUMB_FUNC void* Maybe_GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { + u16 species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, 0); + u8 forme = (u8)GetMonData(pokemon, MON_DATA_FORME, 0); + u8 level = (u8)GetMonData(pokemon, MON_DATA_LEVEL, 0); + u16 moves[4]; + + for (u8 i = 0; i < 4; ++i) { + moves[i] = (u16)GetMonData(pokemon, MON_DATA_MOVE1 + i, 0); + } + + u16 *tableFromFile = AllocFromHeap(heap_id, 44); + u16 *returnTable = AllocFromHeap(heap_id, 44); + + LoadWotbl_HandleAlternateForme(species, forme, tableFromFile); + + for (u8 i = 0, j, k = 0; i < 22; i++) { + if (tableFromFile[i] == WOTBL_END) { + returnTable[k] = WOTBL_END; + break; + } + else { + if (WOTBL_LVL(tableFromFile[i]) > level) continue; + + tableFromFile[i] = WOTBL_MOVE(tableFromFile[i]); + + j = 0; + for (; j < 4; j++) { + if (tableFromFile[i] == moves[j]) break; + } + if (j != 4) continue; + + j = 0; + if (k >= 0) { + // don't know when that would be false + for (; j < k; j++) { + if (returnTable[j] == tableFromFile[i]) break; + } + } + if (j != k) continue; + + returnTable[k] = tableFromFile[i]; + k++; + } + } + + FreeToHeap(tableFromFile); + return returnTable; +} + +THUMB_FUNC BOOL FUN_02088EF8(u16 *r0) { + return *r0 != 0xFFFF; +} \ No newline at end of file diff --git a/files/graphic/poketch/narc_0010.NCGR b/files/graphic/poketch/narc_0010.NCGR new file mode 100644 index 00000000..9dcdc01b Binary files /dev/null and b/files/graphic/poketch/narc_0010.NCGR differ diff --git a/include/unk_02088DD8.h b/include/unk_02088DD8.h index 318a98fb..41e7232e 100644 --- a/include/unk_02088DD8.h +++ b/include/unk_02088DD8.h @@ -1,6 +1,10 @@ #ifndef POKEDIAMOND_UNK_02088DD8_H #define POKEDIAMOND_UNK_02088DD8_H +#include "unk_020377F0.h" + +extern void LoadWotbl_HandleAlternateForme(int species, int forme, u16 * wotbl); + struct Options; struct PlayerData; struct Pokemon; @@ -16,4 +20,9 @@ struct UnkStruct_02088DD8 u8 padding2[0x2]; }; +struct UnkStruct_02088DD8* FUN_02088DD8(u32 r0); +void FUN_02088DF0(struct UnkStruct_02037CF0 *r0); +void* Maybe_GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id); +BOOL FUN_02088EF8(u16 *r0); + #endif -- cgit v1.2.3 From 93c3498a65ff4e47367a5d98bd9c6f8fe1f33f89 Mon Sep 17 00:00:00 2001 From: SNBeast Date: Sun, 27 Jun 2021 19:16:57 -0400 Subject: Not maybe, if I am wrong let me be corrected --- arm9/global.inc | 2 +- arm9/src/scrcmd_24.c | 4 ++-- arm9/src/unk_02088DD8.c | 2 +- include/unk_02088DD8.h | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arm9/global.inc b/arm9/global.inc index e1952cc2..590bf428 100644 --- a/arm9/global.inc +++ b/arm9/global.inc @@ -5450,7 +5450,7 @@ .extern FUN_02088DBC .extern FUN_02088DD8 .extern FUN_02088DF0 -.extern Maybe_GetEligibleLevelUpMoves +.extern GetEligibleLevelUpMoves .extern FUN_02088EF8 .extern FUN_02088F0C .extern FUN_02088F4C diff --git a/arm9/src/scrcmd_24.c b/arm9/src/scrcmd_24.c index f4330150..bfa737be 100644 --- a/arm9/src/scrcmd_24.c +++ b/arm9/src/scrcmd_24.c @@ -53,7 +53,7 @@ THUMB_FUNC BOOL ScrCmd_Unk021F(struct ScriptContext* ctx) u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2); struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); - void* unk_ptr = Maybe_GetEligibleLevelUpMoves(pokemon, 32); + void* unk_ptr = GetEligibleLevelUpMoves(pokemon, 32); *ret_ptr = (u16)FUN_02088EF8(unk_ptr); FreeToHeap(unk_ptr); @@ -92,7 +92,7 @@ THUMB_FUNC BOOL ScrCmd_Unk0221(struct ScriptContext* ctx) u16 mon_idx = VarGet(ctx->unk80, ScriptReadHalfword(ctx)); struct PlayerParty* party = SavArray_PlayerParty_get(ctx->unk80->saveBlock2); struct Pokemon* pokemon = GetPartyMonByIndex(party, mon_idx); - void* unk_ptr = Maybe_GetEligibleLevelUpMoves(pokemon, 32); + void* unk_ptr = GetEligibleLevelUpMoves(pokemon, 32); FUN_02045E74(ctx, 1, pokemon, unk_ptr); return TRUE; diff --git a/arm9/src/unk_02088DD8.c b/arm9/src/unk_02088DD8.c index acc59701..d0a08f20 100644 --- a/arm9/src/unk_02088DD8.c +++ b/arm9/src/unk_02088DD8.c @@ -22,7 +22,7 @@ THUMB_FUNC void FUN_02088DF0(struct UnkStruct_02037CF0 *r0) { #define WOTBL_LVL(x) (/*(u8)*/(((x) & WOTBL_LVL_MASK) >> WOTBL_LVL_SHIFT)) // i don't know why either. -THUMB_FUNC void* Maybe_GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { +THUMB_FUNC void* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { u16 species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, 0); u8 forme = (u8)GetMonData(pokemon, MON_DATA_FORME, 0); u8 level = (u8)GetMonData(pokemon, MON_DATA_LEVEL, 0); diff --git a/include/unk_02088DD8.h b/include/unk_02088DD8.h index 41e7232e..78ff4827 100644 --- a/include/unk_02088DD8.h +++ b/include/unk_02088DD8.h @@ -22,7 +22,7 @@ struct UnkStruct_02088DD8 struct UnkStruct_02088DD8* FUN_02088DD8(u32 r0); void FUN_02088DF0(struct UnkStruct_02037CF0 *r0); -void* Maybe_GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id); +void* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id); BOOL FUN_02088EF8(u16 *r0); #endif -- cgit v1.2.3 From e22de9da55977f1dce79c7fcebd4a8a60f272b5b Mon Sep 17 00:00:00 2001 From: SNBeast Date: Sun, 27 Jun 2021 22:55:50 -0400 Subject: Minor naming tweak and sizeof As suggested by review --- arm9/src/unk_02088DD8.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arm9/src/unk_02088DD8.c b/arm9/src/unk_02088DD8.c index d0a08f20..572d274f 100644 --- a/arm9/src/unk_02088DD8.c +++ b/arm9/src/unk_02088DD8.c @@ -3,9 +3,9 @@ #include "pokemon.h" #include "unk_02088DD8.h" -THUMB_FUNC struct UnkStruct_02088DD8* FUN_02088DD8(u32 r0) { - struct UnkStruct_02088DD8 *returnPointer = AllocFromHeap(r0, 24); - __builtin__clear(returnPointer, 24); +THUMB_FUNC struct UnkStruct_02088DD8* FUN_02088DD8(u32 heap_id) { + struct UnkStruct_02088DD8 *returnPointer = AllocFromHeap(heap_id, sizeof(struct UnkStruct_02088DD8)); + __builtin__clear(returnPointer, sizeof(struct UnkStruct_02088DD8)); return returnPointer; } -- cgit v1.2.3 From 029dab952d33320442fe2a46879b32175c536a79 Mon Sep 17 00:00:00 2001 From: SNBeast Date: Mon, 28 Jun 2021 23:18:38 -0400 Subject: Another code review's suggestions --- arm9/src/unk_02088DD8.c | 12 ++++++------ files/graphic/poketch/narc_0010.NCGR | Bin 2112 -> 0 bytes include/unk_02088DD8.h | 6 ++---- 3 files changed, 8 insertions(+), 10 deletions(-) delete mode 100644 files/graphic/poketch/narc_0010.NCGR diff --git a/arm9/src/unk_02088DD8.c b/arm9/src/unk_02088DD8.c index 572d274f..b4633d25 100644 --- a/arm9/src/unk_02088DD8.c +++ b/arm9/src/unk_02088DD8.c @@ -3,6 +3,8 @@ #include "pokemon.h" #include "unk_02088DD8.h" +extern void LoadWotbl_HandleAlternateForme(int species, int forme, u16 * wotbl); + THUMB_FUNC struct UnkStruct_02088DD8* FUN_02088DD8(u32 heap_id) { struct UnkStruct_02088DD8 *returnPointer = AllocFromHeap(heap_id, sizeof(struct UnkStruct_02088DD8)); __builtin__clear(returnPointer, sizeof(struct UnkStruct_02088DD8)); @@ -22,7 +24,7 @@ THUMB_FUNC void FUN_02088DF0(struct UnkStruct_02037CF0 *r0) { #define WOTBL_LVL(x) (/*(u8)*/(((x) & WOTBL_LVL_MASK) >> WOTBL_LVL_SHIFT)) // i don't know why either. -THUMB_FUNC void* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { +THUMB_FUNC u16* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { u16 species = (u16)GetMonData(pokemon, MON_DATA_SPECIES, 0); u8 forme = (u8)GetMonData(pokemon, MON_DATA_FORME, 0); u8 level = (u8)GetMonData(pokemon, MON_DATA_LEVEL, 0); @@ -47,16 +49,14 @@ THUMB_FUNC void* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { tableFromFile[i] = WOTBL_MOVE(tableFromFile[i]); - j = 0; - for (; j < 4; j++) { + for (j = 0; j < 4; j++) { if (tableFromFile[i] == moves[j]) break; } if (j != 4) continue; - j = 0; if (k >= 0) { // don't know when that would be false - for (; j < k; j++) { + for (j = 0; j < k; j++) { if (returnTable[j] == tableFromFile[i]) break; } } @@ -73,4 +73,4 @@ THUMB_FUNC void* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id) { THUMB_FUNC BOOL FUN_02088EF8(u16 *r0) { return *r0 != 0xFFFF; -} \ No newline at end of file +} diff --git a/files/graphic/poketch/narc_0010.NCGR b/files/graphic/poketch/narc_0010.NCGR deleted file mode 100644 index 9dcdc01b..00000000 Binary files a/files/graphic/poketch/narc_0010.NCGR and /dev/null differ diff --git a/include/unk_02088DD8.h b/include/unk_02088DD8.h index 78ff4827..7b023c56 100644 --- a/include/unk_02088DD8.h +++ b/include/unk_02088DD8.h @@ -3,8 +3,6 @@ #include "unk_020377F0.h" -extern void LoadWotbl_HandleAlternateForme(int species, int forme, u16 * wotbl); - struct Options; struct PlayerData; struct Pokemon; @@ -20,9 +18,9 @@ struct UnkStruct_02088DD8 u8 padding2[0x2]; }; -struct UnkStruct_02088DD8* FUN_02088DD8(u32 r0); +struct UnkStruct_02088DD8* FUN_02088DD8(u32 heap_id); void FUN_02088DF0(struct UnkStruct_02037CF0 *r0); -void* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id); +u16* GetEligibleLevelUpMoves(struct Pokemon* pokemon, u32 heap_id); BOOL FUN_02088EF8(u16 *r0); #endif -- cgit v1.2.3