From 418af6e266c88da5e54cfcc5e9cc52e46db56b11 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sun, 22 Dec 2024 11:12:01 -0800 Subject: [PATCH 1/8] finish up code_8002774_2 --- asm/code_8002774_2.s | 497 ----------------------------------------- include/code_8002774.h | 8 + ld_script.txt | 1 - src/code_8002774.c | 338 ++++++++++++++++++++++++++++ src/ground_script_1.c | 41 ++-- 5 files changed, 365 insertions(+), 520 deletions(-) delete mode 100644 asm/code_8002774_2.s diff --git a/asm/code_8002774_2.s b/asm/code_8002774_2.s deleted file mode 100644 index f369a8534..000000000 --- a/asm/code_8002774_2.s +++ /dev/null @@ -1,497 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - - - thumb_func_start sub_8002B5C -sub_8002B5C: - push {lr} - lsls r0, 24 - asrs r2, r0, 24 - lsls r1, 24 - asrs r1, 24 - movs r0, 0x1 - negs r0, r0 - cmp r1, r0 - beq _08002BAE - adds r0, r2, 0 - subs r0, 0x8 - subs r1, r0 - adds r0, r1, 0 - cmp r1, 0 - bge _08002B7C - adds r0, r1, 0x7 -_08002B7C: - asrs r0, 3 - lsls r0, 3 - subs r0, r1, r0 - cmp r0, 0 - beq _08002BAE - cmp r0, 0x3 - bgt _08002B98 - adds r1, r2, 0x2 - adds r0, r1, 0 - cmp r1, 0 - bge _08002BA4 - adds r0, r2, 0 - adds r0, 0x9 - b _08002BA4 -_08002B98: - adds r1, r2, 0x6 - adds r0, r1, 0 - cmp r1, 0 - bge _08002BA4 - adds r0, r2, 0 - adds r0, 0xD -_08002BA4: - asrs r0, 3 - lsls r0, 3 - subs r0, r1, r0 - lsls r0, 24 - asrs r2, r0, 24 -_08002BAE: - movs r0, 0x6 - ands r2, r0 - adds r0, r2, 0 - pop {r1} - bx r1 - thumb_func_end sub_8002B5C - - thumb_func_start SetVecFromDirectionSpeed -SetVecFromDirectionSpeed: - push {r4,r5,lr} - lsls r1, 24 - asrs r1, 21 - ldr r3, _08002BD8 - adds r1, r3 - ldr r5, [r1] - adds r3, r5, 0 - muls r3, r2 - ldr r1, [r1, 0x4] - adds r4, r1, 0 - muls r4, r2 - str r3, [r0] - str r4, [r0, 0x4] - pop {r4,r5} - pop {r2} - bx r2 - .align 2, 0 -_08002BD8: .4byte gVectorDirections - thumb_func_end SetVecFromDirectionSpeed - - thumb_func_start VecDirection8Sign -VecDirection8Sign: - push {lr} - ldr r1, [r0] - cmp r1, 0 - bge _08002BFA - ldr r0, [r0, 0x4] - cmp r0, 0 - bge _08002BEE - movs r0, 0x5 - b _08002C2A -_08002BEE: - cmp r0, 0 - ble _08002BF6 - movs r0, 0x7 - b _08002C2A -_08002BF6: - movs r0, 0x6 - b _08002C2A -_08002BFA: - cmp r1, 0 - ble _08002C14 - ldr r0, [r0, 0x4] - cmp r0, 0 - bge _08002C08 - movs r0, 0x3 - b _08002C2A -_08002C08: - cmp r0, 0 - ble _08002C10 - movs r0, 0x1 - b _08002C2A -_08002C10: - movs r0, 0x2 - b _08002C2A -_08002C14: - ldr r0, [r0, 0x4] - cmp r0, 0 - bge _08002C1E - movs r0, 0x4 - b _08002C2A -_08002C1E: - cmp r0, 0 - bgt _08002C28 - movs r0, 0x1 - negs r0, r0 - b _08002C2A -_08002C28: - movs r0, 0 -_08002C2A: - pop {r1} - bx r1 - thumb_func_end VecDirection8Sign - - thumb_func_start VecDirection4SignYX -VecDirection4SignYX: - push {lr} - ldr r1, [r0, 0x4] - cmp r1, 0 - bge _08002C3C - movs r0, 0x4 - b _08002C5A -_08002C3C: - cmp r1, 0 - ble _08002C44 - movs r0, 0 - b _08002C5A -_08002C44: - ldr r0, [r0] - cmp r0, 0 - bge _08002C4E - movs r0, 0x6 - b _08002C5A -_08002C4E: - cmp r0, 0 - bgt _08002C58 - movs r0, 0x1 - negs r0, r0 - b _08002C5A -_08002C58: - movs r0, 0x2 -_08002C5A: - pop {r1} - bx r1 - thumb_func_end VecDirection4SignYX - - thumb_func_start VecDirection8Radial -VecDirection8Radial: - push {r4,r5,lr} - adds r4, r0, 0 - ldr r0, [r4] - cmp r0, 0 - bge _08002C6C - negs r0, r0 -_08002C6C: - adds r1, r0, 0 - ldr r3, [r4, 0x4] - adds r5, r3, 0 - cmp r3, 0 - bge _08002C78 - negs r5, r3 -_08002C78: - adds r2, r5, 0 - ldr r4, [r4] - cmp r4, 0 - bge _08002CA8 - cmp r3, 0 - bge _08002C94 - lsls r0, 1 - cmp r2, r0 - bgt _08002CD8 - lsls r0, r5, 1 - cmp r1, r0 - bgt _08002CA0 - movs r0, 0x5 - b _08002CE8 -_08002C94: - lsls r0, 1 - cmp r2, r0 - bgt _08002CE6 - lsls r0, r5, 1 - cmp r1, r0 - ble _08002CA4 -_08002CA0: - movs r0, 0x6 - b _08002CE8 -_08002CA4: - movs r0, 0x7 - b _08002CE8 -_08002CA8: - cmp r4, 0 - ble _08002CD4 - cmp r3, 0 - bge _08002CC0 - lsls r0, 1 - cmp r2, r0 - bgt _08002CD8 - lsls r0, r5, 1 - cmp r1, r0 - bgt _08002CCC - movs r0, 0x3 - b _08002CE8 -_08002CC0: - lsls r0, 1 - cmp r2, r0 - bgt _08002CE6 - lsls r0, r5, 1 - cmp r1, r0 - ble _08002CD0 -_08002CCC: - movs r0, 0x2 - b _08002CE8 -_08002CD0: - movs r0, 0x1 - b _08002CE8 -_08002CD4: - cmp r3, 0 - bge _08002CDC -_08002CD8: - movs r0, 0x4 - b _08002CE8 -_08002CDC: - cmp r3, 0 - bgt _08002CE6 - movs r0, 0x1 - negs r0, r0 - b _08002CE8 -_08002CE6: - movs r0, 0 -_08002CE8: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end VecDirection8Radial - - thumb_func_start VecDirection4Radial -VecDirection4Radial: - push {r4,lr} - adds r4, r0, 0 - ldr r3, [r4] - cmp r3, 0 - bge _08002CFC - negs r3, r3 -_08002CFC: - adds r1, r3, 0 - ldr r3, [r4, 0x4] - adds r0, r3, 0 - cmp r3, 0 - bge _08002D08 - negs r0, r3 -_08002D08: - adds r2, r0, 0 - ldr r0, [r4] - cmp r0, 0 - bge _08002D22 - cmp r3, 0 - bge _08002D1A - cmp r2, r1 - bgt _08002D3C - b _08002D1E -_08002D1A: - cmp r2, r1 - bgt _08002D4A -_08002D1E: - movs r0, 0x6 - b _08002D4C -_08002D22: - cmp r0, 0 - ble _08002D38 - cmp r3, 0 - bge _08002D30 - cmp r2, r1 - bgt _08002D3C - b _08002D34 -_08002D30: - cmp r2, r1 - bgt _08002D4A -_08002D34: - movs r0, 0x2 - b _08002D4C -_08002D38: - cmp r3, 0 - bge _08002D40 -_08002D3C: - movs r0, 0x4 - b _08002D4C -_08002D40: - cmp r3, 0 - bgt _08002D4A - movs r0, 0x1 - negs r0, r0 - b _08002D4C -_08002D4A: - movs r0, 0 -_08002D4C: - pop {r4} - pop {r1} - bx r1 - thumb_func_end VecDirection4Radial - - thumb_func_start SizedDeltaDirection4 -SizedDeltaDirection4: - push {r4,r5,lr} - sub sp, 0x8 - adds r4, r1, 0 - adds r5, r3, 0 - ldr r3, [r2] - ldr r1, [r0] - subs r3, r1 - str r3, [sp] - ldr r1, [r2, 0x4] - ldr r0, [r0, 0x4] - subs r1, r0 - str r1, [sp, 0x4] - adds r2, r3, 0 - cmp r2, 0 - blt _08002D8A - adds r2, 0x1 - ldr r0, [r4] - ldr r1, [r5] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - subs r2, r0 - str r2, [sp] - cmp r2, 0 - bge _08002DA4 - b _08002DA0 -_08002D8A: - subs r2, r3, 0x1 - ldr r0, [r4] - ldr r1, [r5] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - adds r2, r0 - str r2, [sp] - cmp r2, 0 - ble _08002DA4 -_08002DA0: - movs r0, 0 - str r0, [sp] -_08002DA4: - ldr r2, [sp, 0x4] - cmp r2, 0 - blt _08002DC2 - adds r2, 0x1 - ldr r0, [r4, 0x4] - ldr r1, [r5, 0x4] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - subs r2, r0 - str r2, [sp, 0x4] - cmp r2, 0 - bge _08002DDC - b _08002DD8 -_08002DC2: - subs r2, 0x1 - ldr r0, [r4, 0x4] - ldr r1, [r5, 0x4] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - adds r2, r0 - str r2, [sp, 0x4] - cmp r2, 0 - ble _08002DDC -_08002DD8: - movs r0, 0 - str r0, [sp, 0x4] -_08002DDC: - mov r0, sp - bl VecDirection4Radial - lsls r0, 24 - asrs r0, 24 - add sp, 0x8 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end SizedDeltaDirection4 - - thumb_func_start SizedDeltaDirection8 -SizedDeltaDirection8: - push {r4,r5,lr} - sub sp, 0x8 - adds r4, r1, 0 - adds r5, r3, 0 - ldr r3, [r2] - ldr r1, [r0] - subs r3, r1 - str r3, [sp] - ldr r1, [r2, 0x4] - ldr r0, [r0, 0x4] - subs r1, r0 - str r1, [sp, 0x4] - adds r2, r3, 0 - cmp r2, 0 - blt _08002E26 - adds r2, 0x1 - ldr r0, [r4] - ldr r1, [r5] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - subs r2, r0 - str r2, [sp] - cmp r2, 0 - bge _08002E40 - b _08002E3C -_08002E26: - subs r2, r3, 0x1 - ldr r0, [r4] - ldr r1, [r5] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - adds r2, r0 - str r2, [sp] - cmp r2, 0 - ble _08002E40 -_08002E3C: - movs r0, 0 - str r0, [sp] -_08002E40: - ldr r2, [sp, 0x4] - cmp r2, 0 - blt _08002E5E - adds r2, 0x1 - ldr r0, [r4, 0x4] - ldr r1, [r5, 0x4] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - subs r2, r0 - str r2, [sp, 0x4] - cmp r2, 0 - bge _08002E78 - b _08002E74 -_08002E5E: - subs r2, 0x1 - ldr r0, [r4, 0x4] - ldr r1, [r5, 0x4] - adds r0, r1 - lsrs r1, r0, 31 - adds r0, r1 - asrs r0, 1 - adds r2, r0 - str r2, [sp, 0x4] - cmp r2, 0 - ble _08002E78 -_08002E74: - movs r0, 0 - str r0, [sp, 0x4] -_08002E78: - mov r0, sp - bl VecDirection8Radial - lsls r0, 24 - asrs r0, 24 - add sp, 0x8 - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end SizedDeltaDirection8 - - .align 2, 0 @ Don't pad with nop. diff --git a/include/code_8002774.h b/include/code_8002774.h index 334ffef80..0d3d6c4d5 100644 --- a/include/code_8002774.h +++ b/include/code_8002774.h @@ -1,7 +1,15 @@ #ifndef GUARD_CODE_8002774_H #define GUARD_CODE_8002774_H +#include "structs/str_position.h" + s32 sub_8002A70(s32 a0, s32 a1, s32 a2); s32 sub_8002B04(s32, s32); +s32 VecDirection8Sign(PixelPos *param_1); +s32 VecDirection4SignYX(PixelPos *param_1); +s8 VecDirection8Radial(PixelPos *param_1); +s8 VecDirection4Radial(PixelPos *param_1); +s8 SizedDeltaDirection4(PixelPos *r0, PixelPos *r1, PixelPos *r2, PixelPos *r3); +s8 SizedDeltaDirection8(PixelPos *r0, PixelPos *r1, PixelPos *r2, PixelPos *r3); #endif diff --git a/ld_script.txt b/ld_script.txt index 3cdd0617b..461f0ccb7 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -56,7 +56,6 @@ SECTIONS { src/event_flag.o(.text); asm/code_8002774.o(.text); src/code_8002774.o(.text); - asm/code_8002774_2.o(.text); src/memory.o(.text); asm/code_80035F0.o(.text); src/other_random.o(.text); diff --git a/src/code_8002774.c b/src/code_8002774.c index b7e52b77e..4f768d31e 100644 --- a/src/code_8002774.c +++ b/src/code_8002774.c @@ -1,6 +1,7 @@ #include "global.h" #include "code_8002774.h" #include "constants/direction.h" +#include "structs/str_position.h" s32 sub_8002A70(s32 _direction1, s32 _direction2, s32 _caseId) { @@ -66,3 +67,340 @@ s32 sub_8002B04(s32 _direction1, s32 _direction2) } return direction1; } + +s32 sub_8002B5C(int _direction1, int _direction2) +{ + int newDirection; + int iVar2; + int direction1; + int direction2; + + direction1 = (s8)_direction1; + direction2 = (s8)_direction2; + + if (direction2 != -1) { + iVar2 = (direction2 + NUM_DIRECTIONS) - direction1; + newDirection = iVar2; + if (iVar2 < 0) { + newDirection = iVar2 + 7; + } + newDirection = iVar2 + ((newDirection >> 3) * -8); + + if (newDirection != 0) { + if (newDirection < 4) { + iVar2 = direction1 + 2; + newDirection = iVar2; + if (iVar2 < 0) { + newDirection = direction1 + 9; + } + } + else { + iVar2 = direction1 + 6; + newDirection = iVar2; + if (iVar2 < 0) { + newDirection = direction1 + 0xd; + } + } + direction1 = (s8)(iVar2 + (newDirection >> 3) * -8); + } + } + return direction1 & 6; +} + +NAKED void SetVecFromDirectionSpeed(void) +{ + asm_unified( + "\tpush {r4,r5,lr}\n" + "\tlsls r1, 24\n" + "\tasrs r1, 21\n" + "\tldr r3, _08002BD8\n" + "\tadds r1, r3\n" + "\tldr r5, [r1]\n" + "\tadds r3, r5, 0\n" + "\tmuls r3, r2\n" + "\tldr r1, [r1, 0x4]\n" + "\tadds r4, r1, 0\n" + "\tmuls r4, r2\n" + "\tstr r3, [r0]\n" + "\tstr r4, [r0, 0x4]\n" + "\tpop {r4,r5}\n" + "\tpop {r2}\n" + "\tbx r2\n" + "\t.align 2, 0\n" +"_08002BD8: .4byte gVectorDirections"); +} + +s32 VecDirection8Sign(PixelPos *param_1) +{ + if (param_1->x < 0) { + if (param_1->y < 0) { + return 5; + } + else if (param_1->y >= 1) { + return 7; + } + else { + return 6; + } + } + else if (param_1->x >= 1) { + if (param_1->y < 0) { + return 3; + } + else if (param_1->y > 0) { + return 1; + } + else { + return 2; + } + } + else if (param_1->y < 0) { + return 4; + } + else if (param_1->y > 0) { + return 0; + } + else { + return -1; + } +} + +s32 VecDirection4SignYX(PixelPos *param_1) +{ + if (param_1->y < 0) { + return 4; + } + else if (param_1->y > 0) { + return 0; + } + else { + if (param_1->x < 0) { + return 6; + } + else if (param_1->x > 0) { + return 2; + } + else { + return -1; + } + } +} + +// https://decomp.me/scratch/bD5wO +s8 VecDirection8Radial(PixelPos *param_1) +{ + register s32 r0; + register s32 r1 asm("r1"); + register s32 r2 asm("r2"); + register s32 r3 asm("r3"); + register s32 r4 asm("r4"); + register s32 r5; + + + r0 = param_1->x; + if (r0 < 0) { + r0 = -r0; + } + r1 = r0; + r3 = param_1->y; + r5 = r3; + if (r3 < 0) { + r5 = -r3; + } + r2 = r5; + r4 = param_1->x; + if (r4 < 0) { + if (r3 < 0) { + if (r2 > r0 * 2) { + return 4; + } + if (r1 <= r5 * 2) { + return 5; + } + return 6; + } + if (r2 <= r0 * 2) { + if (r1 > r5 * 2) { + return 6; + } + return 7; + } + } + else { + if (0 < r4) { + if (r3 < 0) { + if (r2 > r0 * 2) { + return 4; + } + if (r1 <= r5 * 2) { + return 3; + } + return 2; + } + else { + if (r2 > r0 * 2) { + return 0; + } + if (r1 > r5 * 2) { + return 2; + } + return 1; + } + + } + if (0 > r3) { + return 4; + } + if (r3 < 1) { + return -1; + } + } + return 0; +} + +// https://decomp.me/scratch/Bgbxc +s8 VecDirection4Radial(PixelPos *param_1) +{ + register s32 r0 asm("r3"); + register s32 r1 asm("r1"); + register s32 r2 asm("r2"); + register s32 r3; + register s32 r4; + register s32 r5 asm("r0"); + + r0 = param_1->x; + if (r0 < 0) { + r0 = -r0; + } + r1 = r0; + r3 = param_1->y; + r5 = r3; + if (r3 < 0) { + r5 = -r3; + } + r2 = r5; + r4 = param_1->x; + if (r4 < 0) { + if (r3 < 0) { + if (r2 > r1) { + return 4; + } + else + return 6; + } + if (r2 <= r1) { + return 6; + } + } + else { + if (0 < r4) { + if (r3 < 0) { + if (r2 > r1) { + return 4; + } + else + return 2; + } + else { + if (r2 > r1) { + return 0; + } + return 2; + } + + } + if (0 > r3) { + return 4; + } + if (r3 < 1) { + return -1; + } + } + return 0; +} + +s8 SizedDeltaDirection4(PixelPos *r0, PixelPos *r1, PixelPos *r2, PixelPos *r3) { + PixelPos stack; + s32 iVar1; + s32 iVar2; + s32 iVar3; + + stack.x = r2->x - r0->x; + stack.y = r2->y - r0->y; + + if(stack.x >= 0) + { + iVar3 = (stack.x + 1); + iVar3 -= ((r1->x + r3->x) / 2); + stack.x = iVar3; + if(stack.x < 0) stack.x = 0; + } + else + { + iVar1 = (stack.x - 1); + iVar1 += ((r1->x + r3->x) / 2); + stack.x = iVar1; + if(stack.x > 0) stack.x = 0; + } + + if(stack.y >= 0) + { + iVar2 = (stack.y + 1); + iVar2 -= ((r1->y + r3->y) / 2); + stack.y = iVar2; + if(stack.y < 0) stack.y = 0; + } + else + { + iVar1 = (stack.y - 1); + iVar1 += ((r1->y + r3->y) / 2); + stack.y = iVar1; + if(stack.y > 0) stack.y = 0; + } + + + return VecDirection4Radial(&stack); +} + +s8 SizedDeltaDirection8(PixelPos *r0, PixelPos *r1, PixelPos *r2, PixelPos *r3) { + PixelPos stack; + s32 iVar1; + s32 iVar2; + s32 iVar3; + + stack.x = r2->x - r0->x; + stack.y = r2->y - r0->y; + + if(stack.x >= 0) + { + iVar3 = (stack.x + 1); + iVar3 -= ((r1->x + r3->x) / 2); + stack.x = iVar3; + if(stack.x < 0) stack.x = 0; + } + else + { + iVar1 = (stack.x - 1); + iVar1 += ((r1->x + r3->x) / 2); + stack.x = iVar1; + if(stack.x > 0) stack.x = 0; + } + + if(stack.y >= 0) + { + iVar2 = (stack.y + 1); + iVar2 -= ((r1->y + r3->y) / 2); + stack.y = iVar2; + if(stack.y < 0) stack.y = 0; + } + else + { + iVar1 = (stack.y - 1); + iVar1 += ((r1->y + r3->y) / 2); + stack.y = iVar1; + if(stack.y > 0) stack.y = 0; + } + + + return VecDirection8Radial(&stack); +} diff --git a/src/ground_script_1.c b/src/ground_script_1.c index e59716a85..2cd9d1ac6 100644 --- a/src/ground_script_1.c +++ b/src/ground_script_1.c @@ -1,4 +1,5 @@ #include "global.h" +#include "code_8002774.h" #include "debug.h" #include "event_flag.h" #include "ground_link.h" @@ -15,6 +16,7 @@ #include "math.h" #include "ground_main.h" #include "code_80A26CC.h" +#include "wigglytuff_shop1.h" // Size: unknown typedef struct UnkAction3D @@ -51,11 +53,6 @@ s16 GroundEffect_Add(s16 id, GroundEffectData*, s16 group, s8 sector); // Beware of the declarations without specified arguments, returning u32 or s32, these were quickly hacked in to get the code to compile and link // The return values are almost certainly NOT correct and will need to be rechecked when moving to header files char sub_8002984(s32, u8); -s8 VecDirection8Radial(PixelPos*); -s8 SizedDeltaDirection4(PixelPos*, PixelPos*, PixelPos*, PixelPos*); -s8 SizedDeltaDirection8(PixelPos*, PixelPos*, PixelPos*, PixelPos*); - -bool8 sub_8021700(s32); bool8 sub_802FCF0(void); @@ -204,7 +201,7 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0x03: { - if ((s8)sub_8021700(curCmd.arg1)) { + if (sub_8021700(curCmd.arg1)) { action->scriptData.script.ptr = ResolveJump(action, -1); } else { sub_8098D80(curCmd.argShort); @@ -628,7 +625,7 @@ s32 ExecuteScriptCommand(Action *action) { case 0x2c: { if (!(s8)sub_809A768()) break; sub_80A87AC(0, 10); - if ((s8)GroundScriptCheckLockCondition(action, 0)) return 2; + if (GroundScriptCheckLockCondition(action, 0)) return 2; break; } case 0x30: { @@ -737,20 +734,20 @@ s32 ExecuteScriptCommand(Action *action) { } if (ret) { sub_80A87AC(0, 10); - if ((s8)GroundScriptCheckLockCondition(action, 0)) return 2; + if (GroundScriptCheckLockCondition(action, 0)) return 2; } break; } case 0x39: { if ((s8)sub_809AF6C(curCmd.argShort, curCmd.argPtr) && curCmd.argShort >= 0) { sub_80A87AC(0, 10); - if ((s8)GroundScriptCheckLockCondition(action, 0)) return 2; + if (GroundScriptCheckLockCondition(action, 0)) return 2; } break; } case 0x3a: { sub_809AFC8((u8)curCmd.argByte > 0, curCmd.arg1, (s16)curCmd.arg2, curCmd.argPtr); - if ((s8)GroundScriptCheckLockCondition(action, 1)) { + if (GroundScriptCheckLockCondition(action, 1)) { sub_80A87AC(0, 11); return 2; } @@ -1481,19 +1478,19 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0xb3: { - if ((u8)JudgeVarWithImmediate(NULL, curCmd.argShort, curCmd.arg1, JUDGE_EQ)) { + if (JudgeVarWithImmediate(NULL, curCmd.argShort, curCmd.arg1, JUDGE_EQ)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xb4: { - if ((s8)JudgeVarWithImmediate(scriptData->localVars.buf, (s16)curCmd.arg1, curCmd.arg2, (u8)curCmd.argByte)) { + if (JudgeVarWithImmediate(scriptData->localVars.buf, (s16)curCmd.arg1, curCmd.arg2, (u8)curCmd.argByte)) { scriptData->script.ptr = FindLabel(action, curCmd.argShort); } break; } case 0xb5: { - if ((s8)JudgeVarWithVar(scriptData->localVars.buf, (s16)curCmd.arg1, (s16)curCmd.arg2, (u8)curCmd.argByte)) { + if (JudgeVarWithVar(scriptData->localVars.buf, (s16)curCmd.arg1, (s16)curCmd.arg2, (u8)curCmd.argByte)) { scriptData->script.ptr = FindLabel(action, curCmd.argShort); } break; @@ -1505,43 +1502,43 @@ s32 ExecuteScriptCommand(Action *action) { break; } case 0xb7: { - if ((s8)FlagJudge(GetScriptVarArraySum(scriptData->localVars.buf, (s16)curCmd.arg1), curCmd.arg2, (u8)curCmd.argByte)) { + if (FlagJudge(GetScriptVarArraySum(scriptData->localVars.buf, (s16)curCmd.arg1), curCmd.arg2, (u8)curCmd.argByte)) { scriptData->script.ptr = FindLabel(action, curCmd.argShort); } break; } case 0xb8: { - if ((s8)ScriptVarScenarioBefore(curCmd.argShort, curCmd.arg1, curCmd.arg2)) { + if (ScriptVarScenarioBefore(curCmd.argShort, curCmd.arg1, curCmd.arg2)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xb9: { - if ((s8)ScriptVarScenarioEqual(curCmd.argShort, curCmd.arg1, curCmd.arg2)) { + if (ScriptVarScenarioEqual(curCmd.argShort, curCmd.arg1, curCmd.arg2)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xba: { - if ((s8)ScriptVarScenarioAfter(curCmd.argShort, curCmd.arg1, curCmd.arg2)) { + if (ScriptVarScenarioAfter(curCmd.argShort, curCmd.arg1, curCmd.arg2)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xbb: { - if ((s8)sub_80023E4(curCmd.argShort)) { + if (sub_80023E4(curCmd.argShort)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xbc: { - if ((s8)sub_8098100((u8)curCmd.argShort)) { + if (sub_8098100(curCmd.argShort)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; } case 0xbd: { - if ((s8)sub_80026CC((s16)curCmd.arg1)) { + if (sub_80026CC(curCmd.arg1)) { scriptData->script.ptr = FindLabel(action, (u8)curCmd.argByte); } break; @@ -1718,7 +1715,7 @@ s32 ExecuteScriptCommand(Action *action) { break; } } - if ((s8)GroundScriptCheckLockCondition(action, 1)) { + if (GroundScriptCheckLockCondition(action, 1)) { sub_80A87AC(0, 11); return 2; } @@ -1754,7 +1751,7 @@ s32 ExecuteScriptCommand(Action *action) { } case 0xe5: { scriptData->branchDiscriminant = curCmd.argShort; - if ((s8)GroundScriptLockCond(action, curCmd.argShort, curCmd.argByte)) { + if (GroundScriptLockCond(action, curCmd.argShort, curCmd.argByte)) { return 2; } break; From eb8acf66c00132f466ca0d42bea435c0af1cc1ee Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sun, 22 Dec 2024 21:10:31 -0800 Subject: [PATCH 2/8] decomp more and clean up of code --- asm/code_8002774.s | 194 ------------------------------- src/code_8002774.c | 277 ++++++++++++++++++++++++++++++--------------- src/code_809D148.c | 85 +++++++------- 3 files changed, 223 insertions(+), 333 deletions(-) diff --git a/asm/code_8002774.s b/asm/code_8002774.s index 9cd18cc4c..0091081d4 100644 --- a/asm/code_8002774.s +++ b/asm/code_8002774.s @@ -223,198 +223,4 @@ _08002904: .4byte 0x3f800000 _08002908: .4byte 0x43800000 thumb_func_end sub_800282C - thumb_func_start sub_800290C -sub_800290C: - push {lr} - ldr r3, [r0] - cmp r3, r1 - ble _08002918 - str r1, [r0] - b _08002920 -_08002918: - negs r2, r1 - cmp r3, r2 - bge _08002920 - str r2, [r0] -_08002920: - ldr r2, [r0, 0x4] - cmp r2, r1 - bgt _0800292C - negs r1, r1 - cmp r2, r1 - bge _0800292E -_0800292C: - str r1, [r0, 0x4] -_0800292E: - pop {r0} - bx r0 - thumb_func_end sub_800290C - - thumb_func_start sub_8002934 -sub_8002934: - push {r4-r6,lr} - mov r6, r10 - mov r5, r9 - mov r4, r8 - push {r4-r6} - mov r10, r0 - adds r6, r1, 0 - mov r8, r2 - adds r4, r3, 0 - ldr r5, [sp, 0x1C] - adds r0, r4, r5 - mov r9, r0 - ldr r0, [r6] - muls r0, r4 - ldr r1, [r2] - muls r1, r5 - adds r0, r1 - mov r1, r9 - bl __divsi3 - mov r1, r10 - str r0, [r1] - ldr r0, [r6, 0x4] - muls r0, r4 - mov r2, r8 - ldr r1, [r2, 0x4] - muls r1, r5 - adds r0, r1 - mov r1, r9 - bl __divsi3 - mov r1, r10 - str r0, [r1, 0x4] - pop {r3-r5} - mov r8, r3 - mov r9, r4 - mov r10, r5 - pop {r4-r6} - pop {r0} - bx r0 - thumb_func_end sub_8002934 - - thumb_func_start sub_8002984 -sub_8002984: - push {r4,lr} - lsls r0, 24 - asrs r4, r0, 24 - lsls r1, 24 - lsrs r1, 24 - subs r0, r1, 0x1 - cmp r0, 0x8 - bhi _08002A68 - lsls r0, 2 - ldr r1, _080029A0 - adds r0, r1 - ldr r0, [r0] - mov pc, r0 - .align 2, 0 -_080029A0: .4byte _080029A4 - .align 2, 0 -_080029A4: - .4byte _080029C8 - .4byte _080029D0 - .4byte _080029D8 - .4byte _080029E0 - .4byte _080029E8 - .4byte _080029F4 - .4byte _08002A34 - .4byte _08002A4E - .4byte _08002A5E -_080029C8: - cmp r4, 0 - blt _08002A68 - adds r4, 0x7 - b _080029EE -_080029D0: - cmp r4, 0 - blt _08002A68 - adds r4, 0x1 - b _080029EE -_080029D8: - cmp r4, 0 - blt _08002A68 - adds r4, 0x6 - b _080029EE -_080029E0: - cmp r4, 0 - blt _08002A68 - adds r4, 0x2 - b _080029EE -_080029E8: - cmp r4, 0 - blt _08002A68 - adds r4, 0x4 -_080029EE: - movs r0, 0x7 - ands r4, r0 - b _08002A68 -_080029F4: - movs r0, 0x1 - ands r0, r4 - cmp r0, 0 - beq _08002A18 - movs r0, 0x2 - bl OtherRandInt - adds r1, r4, 0x7 - lsls r0, 1 - adds r1, r0 - adds r0, r1, 0 - cmp r1, 0 - bge _08002A10 - adds r0, r1, 0x7 -_08002A10: - asrs r0, 3 - lsls r0, 3 - subs r0, r1, r0 - b _08002A64 -_08002A18: - movs r0, 0x3 - bl OtherRandInt - adds r1, r4, 0x6 - lsls r0, 1 - adds r1, r0 - adds r0, r1, 0 - cmp r1, 0 - bge _08002A2C - adds r0, r1, 0x7 -_08002A2C: - asrs r0, 3 - lsls r0, 3 - subs r0, r1, r0 - b _08002A64 -_08002A34: - movs r0, 0x3 - bl OtherRandInt - adds r1, r4, 0x7 - adds r1, r0 - adds r0, r1, 0 - cmp r1, 0 - bge _08002A46 - adds r0, r1, 0x7 -_08002A46: - asrs r0, 3 - lsls r0, 3 - subs r0, r1, r0 - b _08002A64 -_08002A4E: - movs r0, 0x8 - bl OtherRandInt - movs r2, 0x2 - negs r2, r2 - adds r1, r2, 0 - ands r0, r1 - b _08002A64 -_08002A5E: - movs r0, 0x8 - bl OtherRandInt -_08002A64: - lsls r0, 24 - asrs r4, r0, 24 -_08002A68: - adds r0, r4, 0 - pop {r4} - pop {r1} - bx r1 - thumb_func_end sub_8002984 - .align 2, 0 @ Don't pad with nop. diff --git a/src/code_8002774.c b/src/code_8002774.c index 4f768d31e..806d6f959 100644 --- a/src/code_8002774.c +++ b/src/code_8002774.c @@ -2,6 +2,93 @@ #include "code_8002774.h" #include "constants/direction.h" #include "structs/str_position.h" +#include "other_random.h" + + +void sub_800290C(PixelPos *param_1, s32 param_2) +{ + if (param_1->x > param_2) + param_1->x = param_2; + else if (param_1->x < -param_2) + param_1->x = -param_2; + if (param_1->y > param_2) + param_1->y = param_2; + else if(param_1->y < -param_2) + param_1->y = -param_2; +} + +void sub_8002934(PixelPos *param_1, PixelPos *param_2, PixelPos *param_3, s32 param_4, s32 param_5) +{ + s32 r9 = (param_4 + param_5); + param_1->x = (param_4 * param_2->x + param_5 * param_3->x) / r9; + param_1->y = (param_4 * param_2->y + param_5 * param_3->y) / r9; +} + +static inline s8 sub_8002984_sub(s32 direction1, s32 rand, s32 add, s32 multi) +{ + return (s8)(((direction1 + add) + OtherRandInt(rand) * multi) % NUM_DIRECTIONS); +} + +s32 sub_8002984(s32 _direction1, u32 caseID) +{ + s32 direction1; + + direction1 = (s8)_direction1; + switch((u8)caseID) { + case 1: + if (direction1 >= 0) { + direction1 += 7; + direction1 &= DIRECTION_MASK; + } + break; + case 2: + if (direction1 >= 0) { + direction1 += 1; + direction1 &= DIRECTION_MASK; + } + break; + case 3: + if (direction1 >= 0) { + direction1 += 6; + direction1 &= DIRECTION_MASK; + } + break; + case 4: + if (direction1 >= 0) { + direction1 += 2; + direction1 &= DIRECTION_MASK; + } + break; + case 5: + if (direction1 >= 0) { + direction1 += 4; + direction1 &= DIRECTION_MASK; + } + break; + case 6: + if ((direction1 & 1) != 0) { + direction1 = sub_8002984_sub(direction1, 2, 7, 2); + } + else + { + direction1 = sub_8002984_sub(direction1, 3, 6, 2); + } + break; + case 7: + direction1 = sub_8002984_sub(direction1, 3, 7, 1); + break; + case 8: + direction1 = (s8)(OtherRandInt(NUM_DIRECTIONS) & 0xfe); + break; + case 9: + direction1 = (s8)OtherRandInt(NUM_DIRECTIONS); + break; + default: + break; + } + return direction1; +} + s32 sub_8002A70(s32 _direction1, s32 _direction2, s32 _caseId) { @@ -68,43 +155,29 @@ s32 sub_8002B04(s32 _direction1, s32 _direction2) return direction1; } -s32 sub_8002B5C(int _direction1, int _direction2) +UNUSED s32 sub_8002B5C(s32 _direction1, s32 _direction2) { - int newDirection; - int iVar2; - int direction1; - int direction2; - - direction1 = (s8)_direction1; - direction2 = (s8)_direction2; - - if (direction2 != -1) { - iVar2 = (direction2 + NUM_DIRECTIONS) - direction1; - newDirection = iVar2; - if (iVar2 < 0) { - newDirection = iVar2 + 7; - } - newDirection = iVar2 + ((newDirection >> 3) * -8); - - if (newDirection != 0) { - if (newDirection < 4) { - iVar2 = direction1 + 2; - newDirection = iVar2; - if (iVar2 < 0) { - newDirection = direction1 + 9; - } - } - else { - iVar2 = direction1 + 6; - newDirection = iVar2; - if (iVar2 < 0) { - newDirection = direction1 + 0xd; + int newDirection; + int direction1; + int direction2; + + direction1 = (s8)_direction1; + direction2 = (s8)_direction2; + + if (direction2 != -1) { + newDirection = ((direction2 + NUM_DIRECTIONS) - direction1) % NUM_DIRECTIONS; + + if (newDirection != 0) { + if (newDirection < 4) { + newDirection = (direction1 + 2) % NUM_DIRECTIONS; + } + else { + newDirection = (direction1 + 6) % NUM_DIRECTIONS; + } + direction1 = (s8)(newDirection); } - } - direction1 = (s8)(iVar2 + (newDirection >> 3) * -8); } - } - return direction1 & 6; + return direction1 & DIRECTION_MASK_CARDINAL; } NAKED void SetVecFromDirectionSpeed(void) @@ -132,69 +205,76 @@ NAKED void SetVecFromDirectionSpeed(void) s32 VecDirection8Sign(PixelPos *param_1) { - if (param_1->x < 0) { - if (param_1->y < 0) { - return 5; - } - else if (param_1->y >= 1) { - return 7; + if (param_1->x < 0) { + if (param_1->y < 0) { + return DIRECTION_NORTHWEST; + } + else if (param_1->y > 0) { + return DIRECTION_SOUTHWEST; + } + else { + return DIRECTION_WEST; + } } - else { - return 6; + else if (param_1->x > 0) { + if (param_1->y < 0) { + return DIRECTION_NORTHEAST; + } + else if (param_1->y > 0) { + return DIRECTION_SOUTHEAST; + } + else { + return DIRECTION_EAST; + } } - } - else if (param_1->x >= 1) { - if (param_1->y < 0) { - return 3; + else if (param_1->y < 0) { + return DIRECTION_NORTH; } else if (param_1->y > 0) { - return 1; + return DIRECTION_SOUTH; } else { - return 2; + return -1; } - } - else if (param_1->y < 0) { - return 4; - } - else if (param_1->y > 0) { - return 0; - } - else { - return -1; - } } s32 VecDirection4SignYX(PixelPos *param_1) { - if (param_1->y < 0) { - return 4; - } - else if (param_1->y > 0) { - return 0; - } - else { - if (param_1->x < 0) { - return 6; + if (param_1->y < 0) { + return DIRECTION_NORTH; + } + else if (param_1->y > 0) { + return DIRECTION_SOUTH; + } + else if (param_1->x < 0) { + return DIRECTION_WEST; } else if (param_1->x > 0) { - return 2; + return DIRECTION_EAST; } else { - return -1; + return -1; } - } } // https://decomp.me/scratch/bD5wO s8 VecDirection8Radial(PixelPos *param_1) { +#ifdef NONMATCHING + s32 r0; + s32 r1; + s32 r2; + s32 r3; + s32 r4; + s32 r5; +#else register s32 r0; register s32 r1 asm("r1"); register s32 r2 asm("r2"); register s32 r3 asm("r3"); register s32 r4 asm("r4"); register s32 r5; +#endif r0 = param_1->x; @@ -212,61 +292,70 @@ s8 VecDirection8Radial(PixelPos *param_1) if (r4 < 0) { if (r3 < 0) { if (r2 > r0 * 2) { - return 4; + return DIRECTION_NORTH; } if (r1 <= r5 * 2) { - return 5; + return DIRECTION_NORTHWEST; } - return 6; + return DIRECTION_WEST; } if (r2 <= r0 * 2) { if (r1 > r5 * 2) { - return 6; + return DIRECTION_WEST; } - return 7; + return DIRECTION_SOUTHWEST; } } else { if (0 < r4) { if (r3 < 0) { if (r2 > r0 * 2) { - return 4; + return DIRECTION_NORTH; } if (r1 <= r5 * 2) { - return 3; + return DIRECTION_NORTHEAST; } - return 2; + return DIRECTION_EAST; } else { if (r2 > r0 * 2) { - return 0; + return DIRECTION_SOUTH; } if (r1 > r5 * 2) { - return 2; + return DIRECTION_EAST; } - return 1; + return DIRECTION_SOUTHEAST; } } - if (0 > r3) { - return 4; + if (r3 < 0) { + return DIRECTION_NORTH; } if (r3 < 1) { return -1; } } - return 0; + return DIRECTION_SOUTH; } // https://decomp.me/scratch/Bgbxc s8 VecDirection4Radial(PixelPos *param_1) { +#ifdef NONMATCHING + s32 r0; + s32 r1; + s32 r2; + s32 r3; + s32 r4; + s32 r5; +#else register s32 r0 asm("r3"); register s32 r1 asm("r1"); register s32 r2 asm("r2"); register s32 r3; register s32 r4; register s32 r5 asm("r0"); +#endif r0 = param_1->x; if (r0 < 0) { @@ -283,40 +372,40 @@ s8 VecDirection4Radial(PixelPos *param_1) if (r4 < 0) { if (r3 < 0) { if (r2 > r1) { - return 4; + return DIRECTION_NORTH; } else - return 6; + return DIRECTION_WEST; } if (r2 <= r1) { - return 6; + return DIRECTION_WEST; } } else { if (0 < r4) { if (r3 < 0) { if (r2 > r1) { - return 4; + return DIRECTION_NORTH; } else - return 2; + return DIRECTION_EAST; } else { if (r2 > r1) { - return 0; + return DIRECTION_SOUTH; } - return 2; + return DIRECTION_EAST; } } - if (0 > r3) { - return 4; + if (r3 < 0) { + return DIRECTION_NORTH; } if (r3 < 1) { return -1; } } - return 0; + return DIRECTION_SOUTH; } s8 SizedDeltaDirection4(PixelPos *r0, PixelPos *r1, PixelPos *r2, PixelPos *r3) { diff --git a/src/code_809D148.c b/src/code_809D148.c index f0b85c674..07294bebc 100644 --- a/src/code_809D148.c +++ b/src/code_809D148.c @@ -1,14 +1,9 @@ #include "global.h" +#include "structs/str_position.h" #include "other_random.h" #include "math.h" #include "memory.h" -struct unkStruct_809D158 -{ - s32 a0; - s32 a4; -}; - struct unkStruct_20399E8 { u32 unk0; @@ -16,15 +11,15 @@ struct unkStruct_20399E8 u32 unk8; s32 unkC; s32 unk10; - struct unkStruct_809D158 unk14; - struct unkStruct_809D158 unk1C; + PixelPos unk14; + PixelPos unk1C; s32 unk24; s32 unk28; s32 unk2C; s32 unk30; s32 unk34; s32 unk38; - struct unkStruct_809D158 unk3C; + PixelPos unk3C; u8 unk44; }; @@ -32,7 +27,7 @@ extern struct unkStruct_20399E8 gUnknown_20399E8; void sub_809D0BC(void); void sub_809D4B0(void); -void sub_809D158(s32 r0, const struct unkStruct_809D158 *r1); +void sub_809D158(s32 r0, const PixelPos *r1); s32 sub_809CFE8(u16 param_1) { @@ -105,7 +100,7 @@ void nullsub_119(void) { } -extern const struct unkStruct_809D158 gZeroPos_8116478; +extern const PixelPos gZeroPos_8116478; void sub_809D0BC(void) { @@ -162,7 +157,7 @@ struct Test1 u64 ukn0; }; -void sub_809D158(s32 r0, const struct unkStruct_809D158 *r1) +void sub_809D158(s32 r0, const PixelPos *r1) { gUnknown_20399E8.unk0 = r0; gUnknown_20399E8.unk8 = 0; @@ -183,7 +178,7 @@ void sub_809D180(s32 r0, s32 r1) gUnknown_20399E8.unkC = r1; } -void sub_809D190(s32 r0, struct unkStruct_809D158 *r1, s32 r2) +void sub_809D190(s32 r0, PixelPos *r1, s32 r2) { gUnknown_20399E8.unk0 = r0; gUnknown_20399E8.unk8 = 1; @@ -206,7 +201,7 @@ void sub_809D1BC(s32 r0, s32 r1) gUnknown_20399E8.unk10 = r1; } -void sub_809D1CC(s32 r0, struct unkStruct_809D158 *r1, s32 r2) +void sub_809D1CC(s32 r0, PixelPos *r1, s32 r2) { gUnknown_20399E8.unk0 = r0; gUnknown_20399E8.unk8 = 2; @@ -229,7 +224,7 @@ void sub_809D1F8(s32 r0, s32 r1) gUnknown_20399E8.unkC = r1; } -void sub_809D208(s32 r0, struct unkStruct_809D158 *r1, s32 r2) +void sub_809D208(s32 r0, PixelPos *r1, s32 r2) { gUnknown_20399E8.unk0 = r0; gUnknown_20399E8.unk8 = 3; @@ -250,27 +245,27 @@ bool8 sub_809D234(void) return gUnknown_20399E8.unk8 != 0; } -u8 sub_809D248(struct unkStruct_809D158 *r0) +u8 sub_809D248(PixelPos *r0) { *r0 = gUnknown_20399E8.unk3C; return gUnknown_20399E8.unk44; } // Todo: move these to appropriate header files -extern s32 sub_80A8FD8(s16 a0, struct unkStruct_809D158 *a1); -extern s32 sub_80AC448(s16 a0, struct unkStruct_809D158 *a1); -extern s32 sub_80AD360(s16 a0, struct unkStruct_809D158 *a1); -extern void sub_800290C(struct unkStruct_809D158 *a0, s32 a1); -extern void sub_8002934(struct unkStruct_809D158 *a0, struct unkStruct_809D158 *a1, struct unkStruct_809D158 *a2, u32 a3, u32 a4); -extern bool8 sub_80A579C(struct unkStruct_809D158 *a0, struct unkStruct_809D158 *a1); +extern s32 sub_80A8FD8(s16 a0, PixelPos *a1); +extern s32 sub_80AC448(s16 a0, PixelPos *a1); +extern s32 sub_80AD360(s16 a0, PixelPos *a1); +extern void sub_800290C(PixelPos *a0, s32 a1); +extern void sub_8002934(PixelPos *a0, PixelPos *a1, PixelPos *a2, u32 a3, u32 a4); +extern bool8 sub_80A579C(PixelPos *a0, PixelPos *a1); void sub_809D25C(void) { s32 r2, r1, r3; - struct unkStruct_809D158 sp4; - struct unkStruct_809D158 spC; - struct unkStruct_809D158 sp14; - struct unkStruct_809D158 sp1C; + PixelPos sp4; + PixelPos spC; + PixelPos sp14; + PixelPos sp1C; u16 val; // For some reason I have to compare with 0xFFFF instead of -1. Maybe it has to do with return value of the functions? switch (gUnknown_20399E8.unk0) @@ -295,22 +290,22 @@ void sub_809D25C(void) switch (gUnknown_20399E8.unk8) { case 1: - sp4.a0 = gUnknown_20399E8.unk1C.a0 - gUnknown_20399E8.unk14.a0; - sp4.a4 = gUnknown_20399E8.unk1C.a4 - gUnknown_20399E8.unk14.a4; + sp4.x = gUnknown_20399E8.unk1C.x - gUnknown_20399E8.unk14.x; + sp4.y = gUnknown_20399E8.unk1C.y - gUnknown_20399E8.unk14.y; sub_800290C(&sp4, gUnknown_20399E8.unkC); - if (sp4.a0 == 0 && sp4.a4 == 0) + if (sp4.x == 0 && sp4.y == 0) { gUnknown_20399E8.unk8 = 0; } else { - gUnknown_20399E8.unk14.a0 += sp4.a0; - gUnknown_20399E8.unk14.a4 += sp4.a4; + gUnknown_20399E8.unk14.x += sp4.x; + gUnknown_20399E8.unk14.y += sp4.y; } break; case 3: - r2 = (gUnknown_20399E8.unk1C.a0 - gUnknown_20399E8.unk14.a0) / 256; - r1 = (gUnknown_20399E8.unk1C.a4 - gUnknown_20399E8.unk14.a4) / 256; + r2 = (gUnknown_20399E8.unk1C.x - gUnknown_20399E8.unk14.x) / 256; + r1 = (gUnknown_20399E8.unk1C.y - gUnknown_20399E8.unk14.y) / 256; gUnknown_20399E8.unk10 = (F248ToInt(FP24_8_Hypot(IntToF248(r2), IntToF248(r1))) << 8) / gUnknown_20399E8.unkC; if (gUnknown_20399E8.unk10 <= 0) gUnknown_20399E8.unk10 = 1; @@ -353,21 +348,21 @@ void sub_809D25C(void) if (sub_80A579C(&sp14, &sp1C)) { - r2 = gUnknown_20399E8.unk14.a0 + gUnknown_20399E8.unk34 - 0x80; - r3 = gUnknown_20399E8.unk14.a4 + gUnknown_20399E8.unk38 - 2944; + r2 = gUnknown_20399E8.unk14.x + gUnknown_20399E8.unk34 - 0x80; + r3 = gUnknown_20399E8.unk14.y + gUnknown_20399E8.unk38 - 2944; - if (r2 < sp14.a0) - r2 = sp14.a0; - if (r2 >= sp1C.a0) - r2 = sp1C.a0 - 1; + if (r2 < sp14.x) + r2 = sp14.x; + if (r2 >= sp1C.x) + r2 = sp1C.x - 1; - if (r3 < sp14.a4) - r3 = sp14.a4; - if (r3 >= sp1C.a4) - r3 = sp1C.a4 - 1; + if (r3 < sp14.y) + r3 = sp14.y; + if (r3 >= sp1C.y) + r3 = sp1C.y - 1; - gUnknown_20399E8.unk3C.a0 = (r2 - 30976) / 256; - gUnknown_20399E8.unk3C.a4 = (r3 - 20480) / 256; + gUnknown_20399E8.unk3C.x = (r2 - 30976) / 256; + gUnknown_20399E8.unk3C.y = (r3 - 20480) / 256; gUnknown_20399E8.unk44 = 1; } } From abac63ccb4e3b7e6a8c781f215eabc1a387974c9 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Wed, 25 Dec 2024 13:26:41 -0800 Subject: [PATCH 3/8] decomp another file --- asm/code_80130A8.s | 304 ---------------------------------------- include/menu_input.h | 4 + include/string_format.h | 3 - ld_script.txt | 1 - src/menu_input.c | 55 ++++++++ src/string_format.c | 15 -- 6 files changed, 59 insertions(+), 323 deletions(-) delete mode 100644 asm/code_80130A8.s diff --git a/asm/code_80130A8.s b/asm/code_80130A8.s deleted file mode 100644 index b5ff8020e..000000000 --- a/asm/code_80130A8.s +++ /dev/null @@ -1,304 +0,0 @@ - #include "asm/constants/gba_constants.inc" - #include "asm/macros.inc" - - .syntax unified - - .text - -@ SpriteOAM memes. Same as sub_8013F84 except instead of a 0x60 it's a 0x80 - thumb_func_start sub_8013E54 -sub_8013E54: - push {r4-r6,lr} - sub sp, 0x8 - ldr r6, _08013F60 - movs r0, 0 - movs r1, 0 - str r0, [sp] - str r1, [sp, 0x4] - mov r0, sp - ldrh r0, [r0] - ldr r1, _08013F64 - ands r1, r0 - ldr r3, _08013F68 - ldr r0, [sp] - ands r0, r3 - orrs r0, r1 - str r0, [sp] - mov r1, sp - ldrh r1, [r1] - adds r2, r3, 0 - ands r2, r0 - orrs r2, r1 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013F6C - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r5, _08013F70 - adds r0, r5, 0 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013F74 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013F78 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - movs r4, 0x80 - lsls r4, 7 - mov r0, sp - ldrh r1, [r0] - ldr r0, _08013F7C - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - orrs r4, r0 - ands r3, r1 - orrs r3, r4 - str r3, [sp] - mov r3, sp - movs r2, 0xFC - lsls r2, 2 - ldrh r1, [r3, 0x4] - movs r0, 0xFC - lsls r0, 8 - ands r0, r1 - orrs r0, r2 - ands r0, r5 - movs r2, 0xF - movs r1, 0xF0 - lsls r1, 8 - ldr r4, _08013F80 - ands r0, r4 - orrs r0, r1 - strh r0, [r3, 0x4] - movs r1, 0x2 - ldrsh r0, [r6, r1] - lsls r0, 3 - adds r0, 0x80 - ands r0, r4 - lsls r0, 4 - ldrh r1, [r3, 0x6] - ands r2, r1 - orrs r2, r0 - strh r2, [r3, 0x6] - movs r0, 0x70 - strh r0, [r3, 0x2] - movs r1, 0x80 - lsls r1, 1 - mov r0, sp - movs r2, 0 - movs r3, 0 - bl AddSprite - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_08013F60: .4byte gUnknown_2027370 -_08013F64: .4byte 0x0000feff -_08013F68: .4byte 0xffff0000 -_08013F6C: .4byte 0x0000fdff -_08013F70: .4byte 0x0000f3ff -_08013F74: .4byte 0x0000efff -_08013F78: .4byte 0x0000dfff -_08013F7C: .4byte 0x00003fff -_08013F80: .4byte 0x00000fff - thumb_func_end sub_8013E54 - -@ SpriteOAM memes https://decomp.me/scratch/GROyH - thumb_func_start sub_8013F84 -sub_8013F84: - push {r4-r6,lr} - sub sp, 0x8 - ldr r6, _08014090 - movs r0, 0 - movs r1, 0 - str r0, [sp] - str r1, [sp, 0x4] - mov r0, sp - ldrh r0, [r0] - ldr r1, _08014094 - ands r1, r0 - ldr r3, _08014098 - ldr r0, [sp] - ands r0, r3 - orrs r0, r1 - str r0, [sp] - mov r1, sp - ldrh r1, [r1] - adds r2, r3, 0 - ands r2, r0 - orrs r2, r1 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _0801409C - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r5, _080140A0 - adds r0, r5, 0 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _080140A4 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - mov r0, sp - ldrh r1, [r0] - ldr r0, _080140A8 - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - adds r2, r3, 0 - ands r2, r1 - orrs r2, r0 - str r2, [sp] - movs r4, 0x80 - lsls r4, 7 - mov r0, sp - ldrh r1, [r0] - ldr r0, _080140AC - ands r0, r1 - adds r1, r3, 0 - ands r1, r2 - orrs r1, r0 - str r1, [sp] - mov r0, sp - ldrh r0, [r0] - orrs r4, r0 - ands r3, r1 - orrs r3, r4 - str r3, [sp] - mov r3, sp - movs r2, 0xFC - lsls r2, 2 - ldrh r1, [r3, 0x4] - movs r0, 0xFC - lsls r0, 8 - ands r0, r1 - orrs r0, r2 - ands r0, r5 - movs r2, 0xF - movs r1, 0xF0 - lsls r1, 8 - ldr r4, _080140B0 - ands r0, r4 - orrs r0, r1 - strh r0, [r3, 0x4] - movs r1, 0x2 - ldrsh r0, [r6, r1] - lsls r0, 3 - adds r0, 0x60 - ands r0, r4 - lsls r0, 4 - ldrh r1, [r3, 0x6] - ands r2, r1 - orrs r2, r0 - strh r2, [r3, 0x6] - movs r0, 0x70 - strh r0, [r3, 0x2] - movs r1, 0x80 - lsls r1, 1 - mov r0, sp - movs r2, 0 - movs r3, 0 - bl AddSprite - add sp, 0x8 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_08014090: .4byte gUnknown_2027370 -_08014094: .4byte 0x0000feff -_08014098: .4byte 0xffff0000 -_0801409C: .4byte 0x0000fdff -_080140A0: .4byte 0x0000f3ff -_080140A4: .4byte 0x0000efff -_080140A8: .4byte 0x0000dfff -_080140AC: .4byte 0x00003fff -_080140B0: .4byte 0x00000fff - thumb_func_end sub_8013F84 - - .align 2,0 diff --git a/include/menu_input.h b/include/menu_input.h index 0ffe36cda..0d897b526 100644 --- a/include/menu_input.h +++ b/include/menu_input.h @@ -47,5 +47,9 @@ void sub_8013AA0(unkStructFor8013AA0 *); u32 sub_8013BBC(unkStructFor8013AA0 *); void sub_8013C68(unkStructFor8013AA0 *); void sub_8013D10(unkStructFor8013AA0 *); +void sub_8013E54(void); +void sub_8013F84(void); +void sub_80140B4(UnkTextStruct2 *); + #endif // GUARD_MENU_INPUT_H diff --git a/include/string_format.h b/include/string_format.h index 3a8f24c7b..ad038c796 100644 --- a/include/string_format.h +++ b/include/string_format.h @@ -8,9 +8,6 @@ // TODO: once the files close to string_format.c are decompiled, check if these should be included here. Most likely, they should be declared elsewhere. // code_80130A8.s -void sub_8013E54(void); -void sub_8013F84(void); -void sub_80140B4(UnkTextStruct2 *); void sub_80140DC(void); void sub_8014114(void); s32 sub_80144A4(s32 *); diff --git a/ld_script.txt b/ld_script.txt index 461f0ccb7..e033ea727 100755 --- a/ld_script.txt +++ b/ld_script.txt @@ -102,7 +102,6 @@ SECTIONS { src/quick_save_write.o(.text); src/code_8012A18.o(.text); src/menu_input.o(.text); - asm/code_80130A8.o(.text); src/string_format.o(.text); src/code_8015080.o(.text); asm/code_8015080.o(.text); diff --git a/src/menu_input.c b/src/menu_input.c index 75eb20772..3a19b7e9e 100644 --- a/src/menu_input.c +++ b/src/menu_input.c @@ -1148,3 +1148,58 @@ static bool8 sub_8013DD0(unkStructFor8013AA0 *a0) return FALSE; } } + +void sub_8013E54(void) +{ + UnkTextStruct1 *ptr = &gUnknown_2027370[0]; + SpriteOAM SStack_18 = {0}; + + SpriteSetAffine1(&SStack_18, 0); + SpriteSetAffine2(&SStack_18, 0); + SpriteSetObjMode(&SStack_18, 0); + SpriteSetMosaic(&SStack_18, 0); + SpriteSetBpp(&SStack_18, 0); + SpriteSetShape(&SStack_18, 1); + SpriteSetMatrixNum(&SStack_18, 0); + SpriteSetSize(&SStack_18, 0); + SpriteSetTileNum(&SStack_18, 0x3F0); + SpriteSetPriority(&SStack_18, 0); + SpriteSetPalNum(&SStack_18, 15); + SpriteSetY(&SStack_18, (ptr->unk2 * 8) + 0x80); + SpriteSetX(&SStack_18, 112); + + AddSprite(&SStack_18,0x100,0,0x0); +} + +void sub_8013F84(void) +{ + UnkTextStruct1 *ptr = &gUnknown_2027370[0]; + SpriteOAM SStack_18 = {0}; + + SpriteSetAffine1(&SStack_18, 0); + SpriteSetAffine2(&SStack_18, 0); + SpriteSetObjMode(&SStack_18, 0); + SpriteSetMosaic(&SStack_18, 0); + SpriteSetBpp(&SStack_18, 0); + SpriteSetShape(&SStack_18, 1); + SpriteSetMatrixNum(&SStack_18, 0); + SpriteSetSize(&SStack_18, 0); + SpriteSetTileNum(&SStack_18, 0x3F0); + SpriteSetPriority(&SStack_18, 0); + SpriteSetPalNum(&SStack_18, 15); + SpriteSetY(&SStack_18, (ptr->unk2 * 8) + 0x60); + SpriteSetX(&SStack_18, 112); + + AddSprite(&SStack_18,0x100,0,0x0); +} + +void sub_80140B4(UnkTextStruct2 *a0) +{ + s32 i; + + for(i = 0; i < 4; i++) + { + a0[i] = gUnknown_80D47C8[i]; + } +} + diff --git a/src/string_format.c b/src/string_format.c index 7516b9934..66c7dde8d 100644 --- a/src/string_format.c +++ b/src/string_format.c @@ -16,21 +16,6 @@ #include "data/code_80140DC.h" -// TODO: move to menu_input -extern UnkTextStruct2 gUnknown_80D47C8[4]; - -void sub_80140B4(UnkTextStruct2 *a0) -{ - s32 i; - - for(i = 0; i < 4; i++) - { - a0[i] = gUnknown_80D47C8[i]; - } -} - -// End of menu_input.c - void sub_80140DC(void) { DungeonPos pos; From b05a66923c42469bbde52ed7832dd46ed012f682 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Thu, 26 Dec 2024 14:17:38 -0800 Subject: [PATCH 4/8] decomp sub_809922E0 --- asm/code_8098BDC.s | 41 ----------------------------------------- src/code_8099328.c | 17 +++++++++++++++++ 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/asm/code_8098BDC.s b/asm/code_8098BDC.s index aeefbc895..43e11bddf 100644 --- a/asm/code_8098BDC.s +++ b/asm/code_8098BDC.s @@ -255,44 +255,3 @@ _080992D4: .4byte gUnknown_20398C4 _080992D8: .4byte gUnknown_2039950 _080992DC: .4byte gUnknown_20398C8 + 0x10 thumb_func_end sub_809927C - - thumb_func_start sub_80992E0 -sub_80992E0: - push {r4,r5,lr} - adds r4, r0, 0 - adds r5, r1, 0 - movs r0, 0 - movs r1, 0x13 - bl GetScriptVarValue - lsls r0, 16 - asrs r1, r0, 16 - movs r0, 0x1 - negs r0, r0 - cmp r1, r0 - beq _08099316 - cmp r1, 0x50 - beq _08099316 - cmp r1, 0x51 - beq _08099316 - cmp r1, 0x52 - beq _08099316 - strh r1, [r4] - movs r0, 0 - movs r1, 0x14 - bl GetScriptVarValue - strh r0, [r5] - movs r0, 0x1 - b _08099322 -_08099316: - movs r1, 0x1 - negs r1, r1 - adds r0, r1, 0 - strh r0, [r4] - strh r0, [r5] - movs r0, 0 -_08099322: - pop {r4,r5} - pop {r1} - bx r1 - thumb_func_end sub_80992E0 - diff --git a/src/code_8099328.c b/src/code_8099328.c index af2688964..c2c1d5d8d 100644 --- a/src/code_8099328.c +++ b/src/code_8099328.c @@ -2,6 +2,23 @@ #include "code_80A26CC.h" #include "event_flag.h" +u8 sub_80992E0(s16 *param_1, s16 *param_2) +{ + s32 sVar2; + + sVar2 = (s16)GetScriptVarValue(NULL,DUNGEON_ENTER); + if ((((sVar2 != -1) && (sVar2 != 0x50)) && (sVar2 != 0x51)) && (sVar2 != 0x52)) { + *param_1 = sVar2; + *param_2 = GetScriptVarValue(NULL,DUNGEON_ENTER_INDEX); + return TRUE; + } + else { + *param_1 = -1; + *param_2 = -1; + return FALSE; + } +} + bool8 sub_8099328(u8 *dungeonId) { s16 script_disc; DungeonInfo* dungeonInfo; From 918747501b834828c2cde46a18553908790fdaba Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sat, 28 Dec 2024 07:22:48 -0800 Subject: [PATCH 5/8] match SetVecFromDirectionSpeed thanks to @Kermalis --- src/code_8002774.c | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/src/code_8002774.c b/src/code_8002774.c index 806d6f959..3fb71ff38 100644 --- a/src/code_8002774.c +++ b/src/code_8002774.c @@ -4,6 +4,13 @@ #include "structs/str_position.h" #include "other_random.h" +typedef struct Vector +{ + s32 x; + s32 y; +} Vector; + +extern Vector gVectorDirections[8]; void sub_800290C(PixelPos *param_1, s32 param_2) { @@ -180,27 +187,11 @@ UNUSED s32 sub_8002B5C(s32 _direction1, s32 _direction2) return direction1 & DIRECTION_MASK_CARDINAL; } -NAKED void SetVecFromDirectionSpeed(void) +Vector SetVecFromDirectionSpeed(s8 r1, u32 r2) { - asm_unified( - "\tpush {r4,r5,lr}\n" - "\tlsls r1, 24\n" - "\tasrs r1, 21\n" - "\tldr r3, _08002BD8\n" - "\tadds r1, r3\n" - "\tldr r5, [r1]\n" - "\tadds r3, r5, 0\n" - "\tmuls r3, r2\n" - "\tldr r1, [r1, 0x4]\n" - "\tadds r4, r1, 0\n" - "\tmuls r4, r2\n" - "\tstr r3, [r0]\n" - "\tstr r4, [r0, 0x4]\n" - "\tpop {r4,r5}\n" - "\tpop {r2}\n" - "\tbx r2\n" - "\t.align 2, 0\n" -"_08002BD8: .4byte gVectorDirections"); + Vector *vec = &gVectorDirections[r1]; + + return (Vector){ .x = vec->x * r2, .y = vec->y * r2 }; } s32 VecDirection8Sign(PixelPos *param_1) From 46ce586097d2753ccde49bc98a7eaf223332dea1 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sat, 28 Dec 2024 07:23:13 -0800 Subject: [PATCH 6/8] match sub_8047158 --- asm/code_8046CE4.s | 34 ---------------------------------- src/dungeon_items.c | 13 +++++++++++++ 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/asm/code_8046CE4.s b/asm/code_8046CE4.s index daa8afec3..34c302ab3 100644 --- a/asm/code_8046CE4.s +++ b/asm/code_8046CE4.s @@ -5,40 +5,6 @@ .text - thumb_func_start sub_8047158 -sub_8047158: - push {r4-r6,lr} - movs r3, 0 - ldr r5, _0804718C - movs r6, 0x1 - movs r4, 0x4 -_08047162: - lsls r1, r3, 2 - ldr r0, [r5] - adds r2, r0, r1 - ldrb r1, [r2] - adds r0, r6, 0 - ands r0, r1 - cmp r0, 0 - beq _08047180 - adds r0, r4, 0 - ands r0, r1 - cmp r0, 0 - beq _08047180 - movs r0, 0xFB - ands r0, r1 - strb r0, [r2] -_08047180: - adds r3, 0x1 - cmp r3, 0x13 - ble _08047162 - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0804718C: .4byte gTeamInventoryRef - thumb_func_end sub_8047158 - thumb_func_start sub_8047190 sub_8047190: push {r4-r7,lr} diff --git a/src/dungeon_items.c b/src/dungeon_items.c index 84d27fab5..8217dad7d 100644 --- a/src/dungeon_items.c +++ b/src/dungeon_items.c @@ -306,3 +306,16 @@ void sub_8047104(void) } FillInventoryGaps(); } + +void sub_8047158(void) +{ + s32 index; + + index = 0; + for(index = 0; index < INVENTORY_SIZE; index++) { + Item *item = &gTeamInventoryRef->teamItems[index]; + if (ItemExists(item) && item->flags & ITEM_FLAG_UNPAID) { + item->flags &= ~(ITEM_FLAG_UNPAID); + } + } +} From ba39c6175f724a3ad6ff75fa0a762e157490d5f2 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sat, 28 Dec 2024 13:34:06 -0800 Subject: [PATCH 7/8] match sub_800F7D0 thanks to @DizzyEggg --- asm/code_800ED38.s | 125 ------------------------------ include/dungeon_pokemon_sprites.h | 4 +- src/code_800F958.c | 47 +++++++++++ 3 files changed, 49 insertions(+), 127 deletions(-) diff --git a/asm/code_800ED38.s b/asm/code_800ED38.s index 4889218e0..49ee41eda 100644 --- a/asm/code_800ED38.s +++ b/asm/code_800ED38.s @@ -1153,129 +1153,4 @@ _0800F7C6: _0800F7CC: .4byte gDungeonPokemonSprites thumb_func_end sub_800F794 - thumb_func_start sub_800F7D0 -sub_800F7D0: - push {r4-r7,lr} - mov r7, r8 - push {r7} - mov r8, r0 - ldr r0, _0800F800 - ldr r0, [r0] - cmp r0, 0 - beq _0800F8C0 - ldr r1, [r0] - adds r0, r1, 0 - cmp r1, 0 - bge _0800F7EA - adds r0, r1, 0x3 -_0800F7EA: - asrs r0, 2 - lsls r0, 2 - subs r0, r1, r0 - cmp r0, 0x1 - beq _0800F82A - cmp r0, 0x1 - bgt _0800F804 - cmp r0, 0 - beq _0800F80E - b _0800F888 - .align 2, 0 -_0800F800: .4byte gDungeonPokemonSprites -_0800F804: - cmp r0, 0x2 - beq _0800F846 - cmp r0, 0x3 - beq _0800F868 - b _0800F888 -_0800F80E: - movs r0, 0x1 - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0x2 - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0x3 - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0x4 - b _0800F860 -_0800F82A: - movs r0, 0x5 - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0x6 - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0x7 - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0x8 - b _0800F860 -_0800F846: - movs r0, 0x9 - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0xA - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0xB - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0xC -_0800F860: - movs r1, 0x1 - bl LoadStatusGraphics - b _0800F888 -_0800F868: - movs r0, 0xD - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0xE - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0xF - movs r1, 0x1 - bl LoadStatusGraphics - movs r0, 0x10 - movs r1, 0x1 - bl LoadStatusGraphics -_0800F888: - movs r5, 0 - movs r6, 0x4 -_0800F88C: - ldr r7, _0800F8CC - ldr r4, [r7] - lsls r0, r5, 6 - adds r0, r4, r0 - ldrb r0, [r0, 0x4] - cmp r0, 0 - beq _0800F8B0 - adds r4, r6 - adds r0, r4, 0 - movs r1, 0 - mov r2, r8 - bl sub_800F2EC - adds r0, r4, 0 - movs r1, 0x1 - mov r2, r8 - bl sub_800F2EC -_0800F8B0: - adds r6, 0x40 - adds r5, 0x1 - cmp r5, 0x15 - ble _0800F88C - ldr r1, [r7] - ldr r0, [r1] - adds r0, 0x1 - str r0, [r1] -_0800F8C0: - pop {r3} - mov r8, r3 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0800F8CC: .4byte gDungeonPokemonSprites - thumb_func_end sub_800F7D0 - .align 2,0 diff --git a/include/dungeon_pokemon_sprites.h b/include/dungeon_pokemon_sprites.h index b013ba9ab..8e345aa64 100644 --- a/include/dungeon_pokemon_sprites.h +++ b/include/dungeon_pokemon_sprites.h @@ -33,10 +33,10 @@ typedef struct DungeonPokemonSprite // size: 0x584 typedef struct DungeonPokemonSprites { - /* 0x0 */ u32 frame; + /* 0x0 */ s32 frame; /* 0x4 */ DungeonPokemonSprite sprites[22]; } DungeonPokemonSprites; extern DungeonPokemonSprites *gDungeonPokemonSprites; -#endif // GUARD_DUNGEON_POKEMON_SPRITES_H \ No newline at end of file +#endif // GUARD_DUNGEON_POKEMON_SPRITES_H diff --git a/src/code_800F958.c b/src/code_800F958.c index 212267bdf..da605ba7b 100644 --- a/src/code_800F958.c +++ b/src/code_800F958.c @@ -8,6 +8,53 @@ extern DungeonPokemonSprite* GetDungeonPokemonSprite(s32 id); extern DungeonPos gUnknown_80D3564; +void LoadStatusGraphics(s32, s32); +void sub_800F2EC(DungeonPokemonSprite *, s32, s16 *); + +void sub_800F7D0(s16 *r0) +{ + s32 index; + + if (gDungeonPokemonSprites == NULL) + return; + + switch(gDungeonPokemonSprites->frame % 4) { + case 0: + LoadStatusGraphics(1, 1); + LoadStatusGraphics(2, 1); + LoadStatusGraphics(3, 1); + LoadStatusGraphics(4, 1); + break; + case 1: + LoadStatusGraphics(5, 1); + LoadStatusGraphics(6, 1); + LoadStatusGraphics(7, 1); + LoadStatusGraphics(8, 1); + break; + case 2: + LoadStatusGraphics(9, 1); + LoadStatusGraphics(0xA, 1); + LoadStatusGraphics(0xB, 1); + LoadStatusGraphics(0xC, 1); + break; + case 3: + LoadStatusGraphics(0xD, 1); + LoadStatusGraphics(0xE, 1); + LoadStatusGraphics(0xF, 1); + LoadStatusGraphics(0x10, 1); + break; + } + + for (index = 0; index < 22; index++) { + if (gDungeonPokemonSprites->sprites[index].exists) { + DungeonPokemonSprite *spritePtr = &gDungeonPokemonSprites->sprites[index]; + sub_800F2EC(spritePtr, 0, r0); + sub_800F2EC(spritePtr, 1, r0); + } + } + gDungeonPokemonSprites->frame++; +} + void AddPokemonDungeonSprite(s32 id, s16 species, DungeonPos *pos, u32 r3) { DungeonPokemonSprite *dSprite; DungeonPokemonSprite *newSprite; From 6d4f6a7fef71e1a8b83036e61954736094d8e0a6 Mon Sep 17 00:00:00 2001 From: Seth Barberee Date: Sat, 28 Dec 2024 14:39:01 -0800 Subject: [PATCH 8/8] decomp more status graphics func --- asm/code_800ED38.s | 228 ------------------------------ include/dungeon_pokemon_sprites.h | 1 + src/code_800F958.c | 113 ++++++++++++++- 3 files changed, 113 insertions(+), 229 deletions(-) diff --git a/asm/code_800ED38.s b/asm/code_800ED38.s index 49ee41eda..5a089b655 100644 --- a/asm/code_800ED38.s +++ b/asm/code_800ED38.s @@ -925,232 +925,4 @@ _0800F5F8: .4byte 0x00000fff _0800F5FC: .4byte 0x000003ff thumb_func_end DrawStatusSprite - thumb_func_start LoadStatusGraphics -LoadStatusGraphics: - push {r4-r7,lr} - mov r7, r9 - mov r6, r8 - push {r6,r7} - lsls r1, 24 - lsrs r1, 24 - mov r9, r1 - lsls r1, r0, 1 - adds r1, r0 - lsls r1, 3 - ldr r0, _0800F660 - adds r1, r0 - ldr r7, [r1, 0x14] - ldr r3, [r1, 0x10] - ldr r2, [r1] - ldr r0, [r1, 0x4] - muls r0, r2 - lsls r4, r0, 5 - mov r8, r4 - ldr r0, [r1, 0x8] - ldr r1, _0800F664 - adds r0, r1 - lsls r5, r0, 5 - adds r6, r5, 0 - ldr r0, _0800F668 - ldr r0, [r0] - ldr r0, [r0] - cmp r0, 0 - bge _0800F63C - adds r0, 0x3 -_0800F63C: - asrs r0, 2 - adds r1, r3, 0 - bl __modsi3 - muls r0, r4 - ldr r1, _0800F66C - adds r0, r1 - adds r1, r7, r0 - mov r2, r9 - cmp r2, 0 - beq _0800F674 - ldr r2, _0800F670 - adds r0, r5, r2 - adds r2, r4, 0 - bl sub_80098BC - b _0800F67E - .align 2, 0 -_0800F660: .4byte gStatusGraphics -_0800F664: .4byte 0x0000032b -_0800F668: .4byte gDungeonPokemonSprites -_0800F66C: .4byte gStatusGraphics4bpp -_0800F670: .4byte 0x06010000 -_0800F674: - ldr r2, _0800F68C - adds r0, r6, r2 - mov r2, r8 - bl CpuCopy -_0800F67E: - pop {r3,r4} - mov r8, r3 - mov r9, r4 - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0800F68C: .4byte 0x06010000 - thumb_func_end LoadStatusGraphics - - thumb_func_start InitDungeonPokemonSprites -InitDungeonPokemonSprites: - push {r4,r5,lr} - ldr r5, _0800F738 - ldr r0, [r5] - cmp r0, 0 - bne _0800F6AC - ldr r4, _0800F73C - adds r0, r4, 0 - movs r1, 0xC - bl MemoryAlloc - str r0, [r5] - adds r1, r4, 0 - bl MemoryClear8 -_0800F6AC: - ldr r1, [r5] - movs r0, 0 - str r0, [r1] - movs r0, 0x1 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x2 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x3 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x4 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x5 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x6 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x7 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x8 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x9 - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0xA - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0xB - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0xC - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0xD - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0xE - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0xF - movs r1, 0 - bl LoadStatusGraphics - movs r0, 0x10 - movs r1, 0 - bl LoadStatusGraphics - pop {r4,r5} - pop {r0} - bx r0 - .align 2, 0 -_0800F738: .4byte gDungeonPokemonSprites -_0800F73C: .4byte 0x00000584 - thumb_func_end InitDungeonPokemonSprites - - thumb_func_start FreeDungeonPokemonSprites -FreeDungeonPokemonSprites: - push {r4,lr} - ldr r4, _0800F758 - ldr r0, [r4] - cmp r0, 0 - beq _0800F752 - bl MemoryFree - movs r0, 0 - str r0, [r4] -_0800F752: - pop {r4} - pop {r0} - bx r0 - .align 2, 0 -_0800F758: .4byte gDungeonPokemonSprites - thumb_func_end FreeDungeonPokemonSprites - - thumb_func_start UpdateDungeonPokemonSprite - @ void UpdateDungeonPokemonSprite(int id, short species, int status, char visible) -UpdateDungeonPokemonSprite: - push {r4-r7,lr} - adds r4, r0, 0 - adds r7, r2, 0 - lsls r1, 16 - asrs r5, r1, 16 - lsls r3, 24 - lsrs r6, r3, 24 - ldr r0, _0800F790 - ldr r0, [r0] - cmp r0, 0 - beq _0800F788 - adds r0, r4, 0 - bl GetDungeonPokemonSprite - cmp r0, 0 - beq _0800F788 - movs r1, 0 - strh r5, [r0, 0x8] - str r7, [r0, 0xC] - strb r6, [r0, 0x10] - adds r0, 0x38 - strb r1, [r0] -_0800F788: - pop {r4-r7} - pop {r0} - bx r0 - .align 2, 0 -_0800F790: .4byte gDungeonPokemonSprites - thumb_func_end UpdateDungeonPokemonSprite - - thumb_func_start sub_800F794 -sub_800F794: - push {r4-r6,lr} - adds r1, r0, 0 - adds r4, r2, 0 - adds r5, r3, 0 - ldr r6, [sp, 0x10] - ldr r0, _0800F7CC - ldr r0, [r0] - cmp r0, 0 - beq _0800F7C6 - adds r0, r1, 0 - bl GetDungeonPokemonSprite - adds r2, r0, 0 - cmp r2, 0 - beq _0800F7C6 - adds r1, r2, 0 - adds r1, 0x38 - movs r0, 0x1 - strb r0, [r1] - strh r4, [r2, 0x3C] - strh r5, [r2, 0x3E] - ldr r0, [r6] - str r0, [r2, 0x20] - ldr r0, [r6, 0xC] - str r0, [r2, 0x24] -_0800F7C6: - pop {r4-r6} - pop {r0} - bx r0 - .align 2, 0 -_0800F7CC: .4byte gDungeonPokemonSprites - thumb_func_end sub_800F794 - .align 2,0 diff --git a/include/dungeon_pokemon_sprites.h b/include/dungeon_pokemon_sprites.h index 8e345aa64..2508b8f62 100644 --- a/include/dungeon_pokemon_sprites.h +++ b/include/dungeon_pokemon_sprites.h @@ -26,6 +26,7 @@ typedef struct DungeonPokemonSprite /* 0x24 */ u32 unk24; /* 0x28 */ DungeonPokemonStatusSprite statusSprites[2]; /* 0x38 */ u8 unk38; + u16 fill3A; /* 0x3C */ u16 unk3C; /* 0x3E */ u16 unk3E; } DungeonPokemonSprite; diff --git a/src/code_800F958.c b/src/code_800F958.c index da605ba7b..ffdb727ad 100644 --- a/src/code_800F958.c +++ b/src/code_800F958.c @@ -1,16 +1,127 @@ #include "global.h" #include "code_800F958.h" +#include "code_8009804.h" +#include "cpu.h" #include "dungeon_pokemon_sprites.h" #include "memory.h" +struct StatusGraphicsInfo +{ + /* 0x0 */ s32 width; + /* 0x4 */ s32 height; + /* 0x8 */ s32 vramIndex; + /* 0xC */ s32 unk; + /* 0x10 */ s32 graphicsCount; + /* 0x14 */ s32 offsetIntoGraphic; +}; + +extern struct StatusGraphicsInfo gStatusGraphics[]; // 0x80CE79C +extern u8 *gStatusGraphics4bpp[]; // TODO use INCBIN_U8 + extern DungeonPokemonSprite *NewDungeonPokemonSprite(void); extern DungeonPokemonSprite* GetDungeonPokemonSprite(s32 id); extern DungeonPos gUnknown_80D3564; -void LoadStatusGraphics(s32, s32); void sub_800F2EC(DungeonPokemonSprite *, s32, s16 *); +void LoadStatusGraphics(s32 graphicIndex, bool8 param_2) +{ + s32 frame; + s32 size; + s32 vramIndex; + s32 offset; + u8 *ptr; + s32 graphicsCount; + + + struct StatusGraphicsInfo *graphic = &gStatusGraphics[graphicIndex]; + + + offset = graphic->offsetIntoGraphic; + graphicsCount = graphic->graphicsCount; + size = graphic->width * graphic->height * 0x20; + vramIndex = (graphic->vramIndex + 0x32b) * 0x20; + frame = (gDungeonPokemonSprites->frame / 4) % graphicsCount; + frame *= size; + ptr = (u8 *)gStatusGraphics4bpp + (offset) + (frame); + + if (param_2) { + sub_80098BC((void *)(VRAM + 0x10000 + vramIndex), (void *)ptr, size); + } + else { + CpuCopy((void *)(VRAM + 0x10000 + vramIndex), ptr, size); + } + return; +} + +void InitDungeonPokemonSprites(void) +{ + if (gDungeonPokemonSprites == NULL) { + gDungeonPokemonSprites = MemoryAlloc(sizeof(DungeonPokemonSprites),0xc); + MemoryClear8(gDungeonPokemonSprites,sizeof(DungeonPokemonSprites)); + } + gDungeonPokemonSprites->frame = 0; + LoadStatusGraphics(1,0); + LoadStatusGraphics(2,0); + LoadStatusGraphics(3,0); + LoadStatusGraphics(4,0); + LoadStatusGraphics(5,0); + LoadStatusGraphics(6,0); + LoadStatusGraphics(7,0); + LoadStatusGraphics(8,0); + LoadStatusGraphics(9,0); + LoadStatusGraphics(10,0); + LoadStatusGraphics(0xb,0); + LoadStatusGraphics(0xc,0); + LoadStatusGraphics(0xd,0); + LoadStatusGraphics(0xe,0); + LoadStatusGraphics(0xf,0); + LoadStatusGraphics(0x10,0); + return; +} + +void FreeDungeonPokemonSprites(void) +{ + if (gDungeonPokemonSprites != 0) { + MemoryFree(gDungeonPokemonSprites); + gDungeonPokemonSprites = NULL; + } +} + +void UpdateDungeonPokemonSprite(s32 id, s32 species, s32 status, u32 visible) +{ + DungeonPokemonSprite *sprite; + s32 species_s32 = (s16)species; + u32 visible_u8 = (u8)visible; + + if (gDungeonPokemonSprites != 0) { + sprite = GetDungeonPokemonSprite(id); + if (sprite != 0) { + sprite->species = species_s32; + sprite->status = status; + sprite->visible = visible_u8; + sprite->unk38 = 0; + } + } +} + +void sub_800F794(s32 id, s32 r1, s32 r2, s32 r3, s32 *r4) +{ + if(gDungeonPokemonSprites) + { + DungeonPokemonSprite *sprite = GetDungeonPokemonSprite(id); + if(sprite) + { + sprite->unk38 = 1; + sprite->unk3C = r2; + sprite->unk3E = r3; + sprite->unk20 = r4[0]; + sprite->unk24 = r4[3]; + } + } +} + void sub_800F7D0(s16 *r0) { s32 index;