From d1819a0abaebaba7acfa22c28148c1fc7f186f9b Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Mon, 25 Jul 2022 17:43:17 +0300 Subject: [PATCH 01/15] Match sub_0802E9B0 --- asm/enemy/gleerok.s | 378 ---------------------- asm/non_matching/gleerok/sub_0802E768.inc | 61 ++++ asm/non_matching/gleerok/sub_0802E7CC.inc | 16 + asm/non_matching/gleerok/sub_0802E7E4.inc | 246 ++++++++++++++ src/enemy/gleerok.c | 40 ++- 5 files changed, 362 insertions(+), 379 deletions(-) create mode 100644 asm/non_matching/gleerok/sub_0802E768.inc create mode 100644 asm/non_matching/gleerok/sub_0802E7CC.inc create mode 100644 asm/non_matching/gleerok/sub_0802E7E4.inc diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s index 3d81c214..dd341326 100644 --- a/asm/enemy/gleerok.s +++ b/asm/enemy/gleerok.s @@ -7,384 +7,6 @@ .text - thumb_func_start sub_0802E768 -sub_0802E768: @ 0x0802E768 - push {r4, r5, r6, lr} - adds r4, r0, #0 - movs r2, #0 - movs r6, #0x1f -_0802E770: - lsls r3, r2, #2 - adds r0, r4, r3 - ldrb r1, [r0, #1] - adds r2, #1 - lsls r0, r2, #2 - adds r0, r4, r0 - ldrb r0, [r0, #1] - subs r0, r1, r0 - ands r0, r6 - adds r5, r2, #0 - cmp r0, #0x10 - ble _0802E790 - cmp r0, #0x1e - bgt _0802E798 - adds r1, #1 - b _0802E796 -_0802E790: - cmp r0, #1 - ble _0802E798 - subs r1, #1 -_0802E796: - ands r1, r6 -_0802E798: - adds r0, r4, r3 - strb r1, [r0, #1] - ldrb r1, [r0, #0x19] - lsls r0, r5, #2 - adds r0, r4, r0 - ldrb r0, [r0, #0x19] - subs r0, r1, r0 - movs r2, #0x1f - ands r0, r2 - cmp r0, #0x10 - ble _0802E7B6 - cmp r0, #0x1d - bgt _0802E7BE - adds r1, #1 - b _0802E7BC -_0802E7B6: - cmp r0, #2 - ble _0802E7BE - subs r1, #1 -_0802E7BC: - ands r1, r2 -_0802E7BE: - adds r0, r4, r3 - strb r1, [r0, #0x19] - adds r2, r5, #0 - cmp r2, #4 - bls _0802E770 - pop {r4, r5, r6, pc} - .align 2, 0 - - thumb_func_start sub_0802E7CC -sub_0802E7CC: @ 0x0802E7CC - lsls r1, r1, #0x18 - lsrs r1, r1, #0x16 - adds r2, r0, #0 - adds r2, #0x3c - adds r2, r2, r1 - ldr r3, [r2] - adds r0, r0, r1 - ldrb r0, [r0, #1] - strb r0, [r3, #0x14] - ldr r0, [r2] - ldrb r0, [r0, #0x14] - bx lr - - thumb_func_start sub_0802E7E4 -sub_0802E7E4: @ 0x0802E7E4 - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, sb - mov r5, r8 - push {r5, r6, r7} - mov ip, r0 - ldr r0, [r0, #0x50] - adds r0, #0x5a - ldrb r1, [r0] - movs r0, #0x40 - ands r0, r1 - cmp r0, #0 - beq _0802E8D0 - movs r6, #0 - movs r5, #0 - mov r7, ip - adds r7, #0x3c - movs r0, #0x30 - add r0, ip - mov r8, r0 - movs r1, #8 - rsbs r1, r1, #0 - mov sl, r1 - movs r2, #4 - rsbs r2, r2, #0 - mov sb, r2 -_0802E818: - lsls r0, r5, #2 - adds r4, r7, r0 - ldr r3, [r4] - adds r3, #0x29 - movs r1, #7 - ands r1, r6 - ldrb r2, [r3] - mov r0, sl - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - adds r6, #1 - mov r1, r8 - adds r0, r1, r5 - ldrb r0, [r0] - cmp r0, #0 - bne _0802E852 - ldr r3, [r4] - ldrb r2, [r3, #0x18] - lsls r1, r2, #0x1e - lsrs r1, r1, #0x1e - movs r0, #2 - rsbs r0, r0, #0 - ands r1, r0 - mov r0, sb - ands r0, r2 - orrs r0, r1 - strb r0, [r3, #0x18] - b _0802E860 -_0802E852: - ldr r2, [r4] - ldrb r1, [r2, #0x18] - mov r0, sb - ands r0, r1 - movs r1, #1 - orrs r0, r1 - strb r0, [r2, #0x18] -_0802E860: - adds r5, #1 - cmp r5, #5 - bls _0802E818 - movs r5, #0 - movs r2, #7 - mov sb, r2 - movs r0, #8 - rsbs r0, r0, #0 - mov r8, r0 -_0802E872: - lsls r1, r5, #2 - mov r2, ip - adds r0, r2, r1 - ldrb r0, [r0, #1] - subs r0, #8 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - adds r5, #1 - cmp r0, #0x10 - bhi _0802E8BA - adds r0, r7, r1 - ldr r3, [r0] - adds r3, #0x29 - ldrb r4, [r3] - lsls r0, r4, #0x1d - lsrs r6, r0, #0x1d - lsls r2, r5, #2 - adds r2, r7, r2 - ldr r0, [r2] - adds r0, #0x29 - ldrb r1, [r0] - lsls r1, r1, #0x1d - lsrs r1, r1, #0x1d - mov r0, r8 - ands r0, r4 - orrs r0, r1 - strb r0, [r3] - ldr r1, [r2] - adds r1, #0x29 - mov r0, sb - ands r6, r0 - ldrb r2, [r1] - mov r0, r8 - ands r0, r2 - orrs r0, r6 - strb r0, [r1] -_0802E8BA: - cmp r5, #4 - bls _0802E872 - mov r1, ip - ldr r0, [r1, #0x38] - adds r0, #0x29 - ldrb r2, [r0] - movs r1, #8 - rsbs r1, r1, #0 - ands r1, r2 - strb r1, [r0] - b _0802E9A4 -_0802E8D0: - movs r6, #5 - movs r5, #0 - mov r7, ip - adds r7, #0x3c - movs r2, #0x30 - add r2, ip - mov r8, r2 - movs r0, #8 - rsbs r0, r0, #0 - mov sl, r0 - movs r1, #4 - rsbs r1, r1, #0 - mov sb, r1 -_0802E8EA: - lsls r0, r5, #2 - adds r4, r7, r0 - ldr r3, [r4] - adds r3, #0x29 - movs r1, #7 - ands r1, r6 - ldrb r2, [r3] - mov r0, sl - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - subs r6, #1 - mov r2, r8 - adds r0, r2, r5 - ldrb r0, [r0] - cmp r0, #0 - bne _0802E924 - ldr r3, [r4] - ldrb r2, [r3, #0x18] - lsls r1, r2, #0x1e - lsrs r1, r1, #0x1e - movs r0, #2 - rsbs r0, r0, #0 - ands r1, r0 - mov r0, sb - ands r0, r2 - orrs r0, r1 - strb r0, [r3, #0x18] - b _0802E932 -_0802E924: - ldr r2, [r4] - ldrb r1, [r2, #0x18] - mov r0, sb - ands r0, r1 - movs r1, #1 - orrs r0, r1 - strb r0, [r2, #0x18] -_0802E932: - adds r5, #1 - cmp r5, #5 - bls _0802E8EA - movs r5, #0 - movs r0, #7 - mov sb, r0 - movs r1, #8 - rsbs r1, r1, #0 - mov r8, r1 -_0802E944: - lsls r1, r5, #2 - mov r2, ip - adds r0, r2, r1 - ldrb r0, [r0, #1] - subs r0, #8 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - adds r5, #1 - cmp r0, #0x10 - bls _0802E98C - adds r0, r7, r1 - ldr r3, [r0] - adds r3, #0x29 - ldrb r4, [r3] - lsls r0, r4, #0x1d - lsrs r6, r0, #0x1d - lsls r2, r5, #2 - adds r2, r7, r2 - ldr r0, [r2] - adds r0, #0x29 - ldrb r1, [r0] - lsls r1, r1, #0x1d - lsrs r1, r1, #0x1d - mov r0, r8 - ands r0, r4 - orrs r0, r1 - strb r0, [r3] - ldr r1, [r2] - adds r1, #0x29 - mov r0, sb - ands r6, r0 - ldrb r2, [r1] - mov r0, r8 - ands r0, r2 - orrs r0, r6 - strb r0, [r1] -_0802E98C: - cmp r5, #4 - bls _0802E944 - mov r1, ip - ldr r2, [r1, #0x38] - adds r2, #0x29 - ldrb r1, [r2] - movs r0, #8 - rsbs r0, r0, #0 - ands r0, r1 - movs r1, #6 - orrs r0, r1 - strb r0, [r2] -_0802E9A4: - pop {r3, r4, r5} - mov r8, r3 - mov sb, r4 - mov sl, r5 - pop {r4, r5, r6, r7, pc} - .align 2, 0 - - thumb_func_start sub_0802E9B0 -sub_0802E9B0: @ 0x0802E9B0 - push {r4, lr} - adds r4, r0, #0 - ldr r0, _0802E9D0 @ =gPlayerEntity - movs r2, #0x2e - ldrsh r1, [r0, r2] - movs r3, #0x32 - ldrsh r2, [r0, r3] - adds r0, r4, #0 - bl sub_080041DC - lsrs r2, r0, #4 - cmp r2, #0x5f - bgt _0802E9D4 - movs r2, #0xa - b _0802E9EA - .align 2, 0 -_0802E9D0: .4byte gPlayerEntity -_0802E9D4: - adds r1, r2, #0 - subs r1, #0x60 - cmp r1, #0 - bge _0802E9DE - adds r1, #3 -_0802E9DE: - asrs r1, r1, #2 - movs r0, #0xa - subs r2, r0, r1 - cmp r2, #3 - bgt _0802E9EA - movs r2, #4 -_0802E9EA: - adds r0, r4, #0 - adds r0, #0x84 - ldr r3, [r0] - adds r0, r3, #0 - adds r0, #0x2d - ldrb r0, [r0] - cmp r2, r0 - beq _0802EA10 - cmp r2, r0 - ble _0802EA04 - ldrh r0, [r3, #0x2c] - adds r0, #0x20 - b _0802EA08 -_0802EA04: - ldrh r0, [r3, #0x2c] - subs r0, #0x20 -_0802EA08: - ldr r2, _0802EA14 @ =0x00001FFF - adds r1, r2, #0 - ands r0, r1 - strh r0, [r3, #0x2c] -_0802EA10: - pop {r4, pc} - .align 2, 0 -_0802EA14: .4byte 0x00001FFF - thumb_func_start sub_0802EA18 sub_0802EA18: @ 0x0802EA18 push {lr} diff --git a/asm/non_matching/gleerok/sub_0802E768.inc b/asm/non_matching/gleerok/sub_0802E768.inc new file mode 100644 index 00000000..0a99cd88 --- /dev/null +++ b/asm/non_matching/gleerok/sub_0802E768.inc @@ -0,0 +1,61 @@ + .syntax unified + + .text + push {r4, r5, r6, lr} + adds r4, r0, #0 + movs r2, #0 + movs r6, #0x1f +_0802E770: + lsls r3, r2, #2 + adds r0, r4, r3 + ldrb r1, [r0, #1] + adds r2, #1 + lsls r0, r2, #2 + adds r0, r4, r0 + ldrb r0, [r0, #1] + subs r0, r1, r0 + ands r0, r6 + adds r5, r2, #0 + cmp r0, #0x10 + ble _0802E790 + cmp r0, #0x1e + bgt _0802E798 + adds r1, #1 + b _0802E796 +_0802E790: + cmp r0, #1 + ble _0802E798 + subs r1, #1 +_0802E796: + ands r1, r6 +_0802E798: + adds r0, r4, r3 + strb r1, [r0, #1] + ldrb r1, [r0, #0x19] + lsls r0, r5, #2 + adds r0, r4, r0 + ldrb r0, [r0, #0x19] + subs r0, r1, r0 + movs r2, #0x1f + ands r0, r2 + cmp r0, #0x10 + ble _0802E7B6 + cmp r0, #0x1d + bgt _0802E7BE + adds r1, #1 + b _0802E7BC +_0802E7B6: + cmp r0, #2 + ble _0802E7BE + subs r1, #1 +_0802E7BC: + ands r1, r2 +_0802E7BE: + adds r0, r4, r3 + strb r1, [r0, #0x19] + adds r2, r5, #0 + cmp r2, #4 + bls _0802E770 + pop {r4, r5, r6, pc} + .align 2, 0 + .syntax divided diff --git a/asm/non_matching/gleerok/sub_0802E7CC.inc b/asm/non_matching/gleerok/sub_0802E7CC.inc new file mode 100644 index 00000000..b4899ff7 --- /dev/null +++ b/asm/non_matching/gleerok/sub_0802E7CC.inc @@ -0,0 +1,16 @@ + .syntax unified + + .text + lsls r1, r1, #0x18 + lsrs r1, r1, #0x16 + adds r2, r0, #0 + adds r2, #0x3c + adds r2, r2, r1 + ldr r3, [r2] + adds r0, r0, r1 + ldrb r0, [r0, #1] + strb r0, [r3, #0x14] + ldr r0, [r2] + ldrb r0, [r0, #0x14] + bx lr + .syntax divided diff --git a/asm/non_matching/gleerok/sub_0802E7E4.inc b/asm/non_matching/gleerok/sub_0802E7E4.inc new file mode 100644 index 00000000..93394c16 --- /dev/null +++ b/asm/non_matching/gleerok/sub_0802E7E4.inc @@ -0,0 +1,246 @@ + .syntax unified + + .text + push {r4, r5, r6, r7, lr} + mov r7, sl + mov r6, sb + mov r5, r8 + push {r5, r6, r7} + mov ip, r0 + ldr r0, [r0, #0x50] + adds r0, #0x5a + ldrb r1, [r0] + movs r0, #0x40 + ands r0, r1 + cmp r0, #0 + beq _0802E8D0 + movs r6, #0 + movs r5, #0 + mov r7, ip + adds r7, #0x3c + movs r0, #0x30 + add r0, ip + mov r8, r0 + movs r1, #8 + rsbs r1, r1, #0 + mov sl, r1 + movs r2, #4 + rsbs r2, r2, #0 + mov sb, r2 +_0802E818: + lsls r0, r5, #2 + adds r4, r7, r0 + ldr r3, [r4] + adds r3, #0x29 + movs r1, #7 + ands r1, r6 + ldrb r2, [r3] + mov r0, sl + ands r0, r2 + orrs r0, r1 + strb r0, [r3] + adds r6, #1 + mov r1, r8 + adds r0, r1, r5 + ldrb r0, [r0] + cmp r0, #0 + bne _0802E852 + ldr r3, [r4] + ldrb r2, [r3, #0x18] + lsls r1, r2, #0x1e + lsrs r1, r1, #0x1e + movs r0, #2 + rsbs r0, r0, #0 + ands r1, r0 + mov r0, sb + ands r0, r2 + orrs r0, r1 + strb r0, [r3, #0x18] + b _0802E860 +_0802E852: + ldr r2, [r4] + ldrb r1, [r2, #0x18] + mov r0, sb + ands r0, r1 + movs r1, #1 + orrs r0, r1 + strb r0, [r2, #0x18] +_0802E860: + adds r5, #1 + cmp r5, #5 + bls _0802E818 + movs r5, #0 + movs r2, #7 + mov sb, r2 + movs r0, #8 + rsbs r0, r0, #0 + mov r8, r0 +_0802E872: + lsls r1, r5, #2 + mov r2, ip + adds r0, r2, r1 + ldrb r0, [r0, #1] + subs r0, #8 + lsls r0, r0, #0x18 + lsrs r0, r0, #0x18 + adds r5, #1 + cmp r0, #0x10 + bhi _0802E8BA + adds r0, r7, r1 + ldr r3, [r0] + adds r3, #0x29 + ldrb r4, [r3] + lsls r0, r4, #0x1d + lsrs r6, r0, #0x1d + lsls r2, r5, #2 + adds r2, r7, r2 + ldr r0, [r2] + adds r0, #0x29 + ldrb r1, [r0] + lsls r1, r1, #0x1d + lsrs r1, r1, #0x1d + mov r0, r8 + ands r0, r4 + orrs r0, r1 + strb r0, [r3] + ldr r1, [r2] + adds r1, #0x29 + mov r0, sb + ands r6, r0 + ldrb r2, [r1] + mov r0, r8 + ands r0, r2 + orrs r0, r6 + strb r0, [r1] +_0802E8BA: + cmp r5, #4 + bls _0802E872 + mov r1, ip + ldr r0, [r1, #0x38] + adds r0, #0x29 + ldrb r2, [r0] + movs r1, #8 + rsbs r1, r1, #0 + ands r1, r2 + strb r1, [r0] + b _0802E9A4 +_0802E8D0: + movs r6, #5 + movs r5, #0 + mov r7, ip + adds r7, #0x3c + movs r2, #0x30 + add r2, ip + mov r8, r2 + movs r0, #8 + rsbs r0, r0, #0 + mov sl, r0 + movs r1, #4 + rsbs r1, r1, #0 + mov sb, r1 +_0802E8EA: + lsls r0, r5, #2 + adds r4, r7, r0 + ldr r3, [r4] + adds r3, #0x29 + movs r1, #7 + ands r1, r6 + ldrb r2, [r3] + mov r0, sl + ands r0, r2 + orrs r0, r1 + strb r0, [r3] + subs r6, #1 + mov r2, r8 + adds r0, r2, r5 + ldrb r0, [r0] + cmp r0, #0 + bne _0802E924 + ldr r3, [r4] + ldrb r2, [r3, #0x18] + lsls r1, r2, #0x1e + lsrs r1, r1, #0x1e + movs r0, #2 + rsbs r0, r0, #0 + ands r1, r0 + mov r0, sb + ands r0, r2 + orrs r0, r1 + strb r0, [r3, #0x18] + b _0802E932 +_0802E924: + ldr r2, [r4] + ldrb r1, [r2, #0x18] + mov r0, sb + ands r0, r1 + movs r1, #1 + orrs r0, r1 + strb r0, [r2, #0x18] +_0802E932: + adds r5, #1 + cmp r5, #5 + bls _0802E8EA + movs r5, #0 + movs r0, #7 + mov sb, r0 + movs r1, #8 + rsbs r1, r1, #0 + mov r8, r1 +_0802E944: + lsls r1, r5, #2 + mov r2, ip + adds r0, r2, r1 + ldrb r0, [r0, #1] + subs r0, #8 + lsls r0, r0, #0x18 + lsrs r0, r0, #0x18 + adds r5, #1 + cmp r0, #0x10 + bls _0802E98C + adds r0, r7, r1 + ldr r3, [r0] + adds r3, #0x29 + ldrb r4, [r3] + lsls r0, r4, #0x1d + lsrs r6, r0, #0x1d + lsls r2, r5, #2 + adds r2, r7, r2 + ldr r0, [r2] + adds r0, #0x29 + ldrb r1, [r0] + lsls r1, r1, #0x1d + lsrs r1, r1, #0x1d + mov r0, r8 + ands r0, r4 + orrs r0, r1 + strb r0, [r3] + ldr r1, [r2] + adds r1, #0x29 + mov r0, sb + ands r6, r0 + ldrb r2, [r1] + mov r0, r8 + ands r0, r2 + orrs r0, r6 + strb r0, [r1] +_0802E98C: + cmp r5, #4 + bls _0802E944 + mov r1, ip + ldr r2, [r1, #0x38] + adds r2, #0x29 + ldrb r1, [r2] + movs r0, #8 + rsbs r0, r0, #0 + ands r0, r1 + movs r1, #6 + orrs r0, r1 + strb r0, [r2] +_0802E9A4: + pop {r3, r4, r5} + mov r8, r3 + mov sb, r4 + mov sl, r5 + pop {r4, r5, r6, r7, pc} + .align 2, 0 + .syntax divided diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index a95d0607..b6893819 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -7,7 +7,9 @@ #include "object.h" typedef struct { - /*0x00*/ u8 filler[0x30]; + /*0x00*/ u8 filler[0x2c]; + /*0x2c*/ union SplitHWord unk_2c; + /*0x2e*/ u16 filler_2e; /*0x30*/ u8 unk_30[6]; /*0x36*/ u8 filler_36[0x2]; /*0x38*/ Entity* ent; @@ -1251,3 +1253,39 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE } } END_NONMATCH + +ASM_FUNC("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1)); + +ASM_FUNC("asm/non_matching/gleerok/sub_0802E7CC.inc", + bool32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4)); + +ASM_FUNC("asm/non_matching/gleerok/sub_0802E7E4.inc", void sub_0802E7E4(Gleerok_HeapStruct* this)); + +void sub_0802E9B0(GleerokEntity* this) { + u32 uVar1; + s32 iVar2; + s32 uVar4; + Gleerok_HeapStruct* heap; + + iVar2 = sub_080041DC(super, gPlayerEntity.x.HALF.HI, gPlayerEntity.y.HALF.HI) >> 4; + if (iVar2 < 0x60) { + iVar2 = 10; + } else { + uVar4 = iVar2 - 0x60; + if (uVar4 < 0) { + uVar4 = iVar2 - 0x5d; + } + iVar2 = 10 - (uVar4 >> 2); + if (iVar2 < 4) { + iVar2 = 4; + } + } + heap = this->unk_84; + if (iVar2 != heap->unk_2c.HALF.HI) { + if (iVar2 > heap->unk_2c.HALF.HI) { + heap->unk_2c.HWORD = (heap->unk_2c.HWORD + 0x20) & 0x1fff; + } else { + heap->unk_2c.HWORD = (heap->unk_2c.HWORD - 0x20) & 0x1fff; + } + } +} From 526915b40fe3211121f88951679181bd0be726ce Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Mon, 25 Jul 2022 18:21:00 +0300 Subject: [PATCH 02/15] Add a nonmatching function for sub_0802E7CC --- src/enemy/gleerok.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index b6893819..f30fd405 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -1256,8 +1256,21 @@ END_NONMATCH ASM_FUNC("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1)); -ASM_FUNC("asm/non_matching/gleerok/sub_0802E7CC.inc", - bool32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4)); +typedef struct { + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; +} sub_0802E7CC_HeapStruct; + +NONMATCH("asm/non_matching/gleerok/sub_0802E7CC.inc", + bool32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4)) { + u8* ptr; + + param_1->entities[(u8)param_2]->animationState = ((sub_0802E7CC_HeapStruct*)param_1->filler)[(u8)param_2].unk1; + return param_1->entities[(u8)param_2]->animationState; +} +END_NONMATCH ASM_FUNC("asm/non_matching/gleerok/sub_0802E7E4.inc", void sub_0802E7E4(Gleerok_HeapStruct* this)); From 28aa81248455d1d4238b99b217abbfd9e510214c Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Mon, 25 Jul 2022 19:24:48 +0300 Subject: [PATCH 03/15] Match sub_0802E7CC --- asm/non_matching/gleerok/sub_0802E7CC.inc | 16 --- src/enemy/gleerok.c | 143 +++++++++++----------- 2 files changed, 69 insertions(+), 90 deletions(-) delete mode 100644 asm/non_matching/gleerok/sub_0802E7CC.inc diff --git a/asm/non_matching/gleerok/sub_0802E7CC.inc b/asm/non_matching/gleerok/sub_0802E7CC.inc deleted file mode 100644 index b4899ff7..00000000 --- a/asm/non_matching/gleerok/sub_0802E7CC.inc +++ /dev/null @@ -1,16 +0,0 @@ - .syntax unified - - .text - lsls r1, r1, #0x18 - lsrs r1, r1, #0x16 - adds r2, r0, #0 - adds r2, #0x3c - adds r2, r2, r1 - ldr r3, [r2] - adds r0, r0, r1 - ldrb r0, [r0, #1] - strb r0, [r3, #0x14] - ldr r0, [r2] - ldrb r0, [r0, #0x14] - bx lr - .syntax divided diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index f30fd405..1cc2aaa0 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -7,7 +7,14 @@ #include "object.h" typedef struct { - /*0x00*/ u8 filler[0x2c]; + u8 unk0; + u8 unk1; + u8 unk2; + u8 unk3; +} Gleerok_HeapStruct2; + +typedef struct { + /*0x00*/ Gleerok_HeapStruct2 filler[11]; /*0x2c*/ union SplitHWord unk_2c; /*0x2e*/ u16 filler_2e; /*0x30*/ u8 unk_30[6]; @@ -45,7 +52,7 @@ extern void (*const gUnk_080CD828[])(GleerokEntity*); extern void (*const gUnk_080CD848[])(GleerokEntity*); extern u8 gUnk_080CD774[]; -extern u8 gUnk_080CD7C4[]; +extern Gleerok_HeapStruct2 gUnk_080CD7C4[]; extern u8 gUnk_080CD884[]; extern u8 gUnk_080CD7F8[]; extern u8 gUnk_080CD840[]; @@ -136,8 +143,8 @@ void sub_0802D170(GleerokEntity* this) { return; if (super->action == 1) { - this->unk_84->filler[1] = 0x10; - this->unk_84->filler[0x19] = 0x10; + this->unk_84->filler[0].unk1 = 0x10; + this->unk_84->filler[6].unk1 = 0x10; if (sub_0802EB08(this->unk_84, 0x40, 2) == 0 && sub_0802EA88(this->unk_84) == 0) { super->action = 2; gPlayerEntity.x.HALF.HI = gRoomControls.origin_x + 0x98; @@ -151,7 +158,7 @@ void sub_0802D170(GleerokEntity* this) { super->action = 3; this->unk_80 = 0; ((Entity*)this->unk_84)->parent->timer = 24; - this->unk_84->filler[0x19] = 0; + this->unk_84->filler[6].unk1 = 0; } } @@ -249,8 +256,8 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE Entity* ent; Gleerok_HeapStruct* heap; u32 val; - u8* ptr; - u8* ptr2; + Gleerok_HeapStruct2* ptr; + Gleerok_HeapStruct2* ptr2; if (CheckGlobalFlag(LV2_CLEAR)) { gScreen.lcd.displayControl &= 0xFDFF; @@ -294,10 +301,10 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE ((GleerokEntity*)super->child)->unk_84 = this->unk_84; this->unk_84->entities[uvar1] = super->child; ptr = this->unk_84->filler; - ptr2 = ptr + uvar1 * 4; - ptr2[1] = 0x10; - ptr2[0x19] = 0; - ptr[0x35] = 0; + ptr2 = ptr + uvar1; + ptr2[0].unk1 = 0x10; + ptr2[6].unk1 = 0; + ptr[13].unk1 = 0; } } while (++uvar1 < 5); @@ -310,9 +317,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE super->child->parent = super; ((GleerokEntity*)super->child)->unk_84 = this->unk_84; heap->ent2 = super->child; - heap->filler[0x15] = 0x10; - heap->filler[0x2d] = 0; - heap->filler[0x35] = 0; + heap->filler[3].unk1 = 0x10; + heap->filler[11].unk1 = 0; + heap->filler[13].unk1 = 0; } #ifndef EU gPlayerState.controlMode = CONTROL_DISABLED; @@ -325,8 +332,8 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE super->flags2 |= 0x80; } ptr = gUnk_080CD7C4; - ptr += super->type2 * 4; - super->spritePriority.b0 = *(ptr + 1); + ptr += super->type2; + super->spritePriority.b0 = ptr->unk1; super->subtimer = 0; InitializeAnimation(super, 0x24); break; @@ -413,15 +420,14 @@ void sub_0802D714(GleerokEntity* this) { Entity* enemy; u32 index; u32 val1, val2; - u8* ptr; + Gleerok_HeapStruct2* ptr; Gleerok_HeapStruct* heap; if (--this->unk_7c.WORD != -1) return; - for (heap = this->unk_84, index = 0, val1 = 0, val2 = 0x10, ptr = this->unk_84->filler; index < 6; - ptr += 4, ++index) { - *(u16*)(ptr + 0x18) = val1; - *(ptr + 1) = val2; + for (heap = this->unk_84, index = 0, val1 = 0, val2 = 0x10, ptr = this->unk_84->filler; index < 6; ptr++, ++index) { + *(u16*)(ptr + 6) = val1; + ptr->unk1 = val2; } super->subAction = 3; @@ -579,7 +585,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE super->child = enemy; if (enemy) { enemy->parent = super->parent; - super->timer = this->unk_84->filler[1]; + super->timer = this->unk_84->filler[0].unk1; this->unk_84->ent = super->child; ((GleerokEntity*)super->child)->unk_84 = this->unk_84; } @@ -610,8 +616,8 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE SoundReq(SFX_BUTTON_PRESS); } } else { - if (super->timer != this->unk_84->filler[1]) { - if (((super->timer - this->unk_84->filler[1]) & 0x1f) > 0x10) { + if (super->timer != this->unk_84->filler[0].unk1) { + if (((super->timer - this->unk_84->filler[0].unk1) & 0x1f) > 0x10) { if (++super->frameIndex >= 0x31) { super->frameIndex = 0x28; } @@ -621,7 +627,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE } } - super->timer = this->unk_84->filler[1]; + super->timer = this->unk_84->filler[0].unk1; } } @@ -656,13 +662,13 @@ END_NONMATCH void sub_0802DB84(GleerokEntity* this) { u32 timer; super->direction = GetFacingDirection(super, &gPlayerEntity); - if (this->unk_84->filler[0x1] == super->direction) { + if (this->unk_84->filler[0].unk1 == super->direction) { super->subAction = 1; this->unk_78 = 0; return; } - if (((this->unk_84->filler[0x1] - super->direction) & 0x1f) > 0x10) { + if (((this->unk_84->filler[0].unk1 - super->direction) & 0x1f) > 0x10) { timer = 0; super->timer &= 0xfe; } else { @@ -690,7 +696,7 @@ void sub_0802DB84(GleerokEntity* this) { void sub_0802DC1C(GleerokEntity* this) { u32 diff = GetFacingDirection(super, &gPlayerEntity); - diff = (this->unk_84->filler[1] - diff) & 0x1f; + diff = (this->unk_84->filler[0].unk1 - diff) & 0x1f; if (diff > 0x10) { if (diff <= 0x1d) { @@ -713,11 +719,11 @@ void sub_0802DC1C(GleerokEntity* this) { } sub_0802EA48(this->unk_84, 5, 0x20, diff); - if (sub_0802EA18(*(u16*)&this->unk_84->filler[0], *(u16*)&this->unk_84->filler[0x14], 4)) { + if (sub_0802EA18(*(u16*)this->unk_84->filler, *(u16*)&this->unk_84->filler[5], 4)) { if (super->timer == 1) { - *(u16*)&this->unk_84->filler[0x14] = (((this->unk_84->filler[0x1] - 4) & 0x1f) << 8) | 0xff; + *(u16*)&this->unk_84->filler[5] = (((this->unk_84->filler[0].unk1 - 4) & 0x1f) << 8) | 0xff; } else { - *(u16*)&this->unk_84->filler[0x14] = (((this->unk_84->filler[0x1] + 4) & 0x1f) << 8); + *(u16*)&this->unk_84->filler[5] = (((this->unk_84->filler[0].unk1 + 4) & 0x1f) << 8); } super->timer ^= 1; @@ -734,13 +740,13 @@ void sub_0802DC1C(GleerokEntity* this) { void sub_0802DCE0(GleerokEntity* this) { if (this->unk_84->ent2->timer != 12) { super->direction = GetFacingDirection(super, &gPlayerEntity); - if (this->unk_84->filler[0x15] == super->direction) { + if (this->unk_84->filler[5].unk1 == super->direction) { this->unk_84->ent2->timer = 12; this->unk_82 = 4; super->subtimer = 0; } else { s32 svar1, diff; - diff = ((this->unk_84->filler[0x15] - super->direction) & 0x1f); + diff = ((this->unk_84->filler[5].unk1 - super->direction) & 0x1f); svar1 = 1; if (diff > 0x10) { svar1 = 0; @@ -763,7 +769,7 @@ void sub_0802DCE0(GleerokEntity* this) { super->child = CreateProjectileWithParent(super, GLEEROK_PROJECTILE, 0); if (super->child != NULL) { - super->child->direction = this->unk_84->filler[0x15]; + super->child->direction = this->unk_84->filler[5].unk1; super->child->type2 = this->unk_84->ent2->frame & 0xf; super->child->parent = this->unk_84->ent2; super->child->child = this->unk_84->entities[0]; @@ -807,10 +813,10 @@ void sub_0802DDD8(GleerokEntity* this) { if ((Random() & 1) == 0) { super->direction = 0; - this->unk_7a = (this->unk_84->filler[1] + uvar1) & 0x1f; + this->unk_7a = (this->unk_84->filler[0].unk1 + uvar1) & 0x1f; } else { super->direction = 1; - this->unk_7a = (this->unk_84->filler[1] - uvar1) & 0x1f; + this->unk_7a = (this->unk_84->filler[0].unk1 - uvar1) & 0x1f; } break; @@ -830,7 +836,7 @@ void sub_0802DDD8(GleerokEntity* this) { if (this->unk_84->ent2->subtimer == 1) { super->child = CreateProjectileWithParent(super, GLEEROK_PROJECTILE, r2); if (super->child != NULL) { - super->child->direction = this->unk_84->filler[0x15]; + super->child->direction = this->unk_84->filler[5].unk1; super->child->type2 = this->unk_84->ent2->frame & 0xf; super->child->parent = this->unk_84->ent2; super->child->child = this->unk_84->entities[0]; @@ -860,7 +866,7 @@ void sub_0802DDD8(GleerokEntity* this) { } sub_0802E768(this->unk_84); - if (this->unk_7a == this->unk_84->filler[0x15]) { + if (this->unk_7a == this->unk_84->filler[5].unk1) { if (super->type2 == 1) { super->type2 = 2; super->direction ^= 1; @@ -890,7 +896,7 @@ void sub_0802DFA8(GleerokEntity* this) { } void sub_0802DFC0(GleerokEntity* this) { - u32 val = this->unk_84->filler[1] & 7; + u32 val = this->unk_84->filler[0].unk1 & 7; if (val) { if (val > 4) { super->direction = 0; @@ -923,10 +929,10 @@ void sub_0802E034(GleerokEntity* this) { val = 0; } else { super->direction = 3; - val = gUnk_080CD840[heap->filler[1] >> 3]; + val = gUnk_080CD840[heap->filler[0].unk1 >> 3]; } - if (val != heap->filler[0x19]) { + if (val != heap->filler[6].unk1) { sub_0802EA68(heap, 0, 0x40, super->direction); sub_0802EB08(heap, 0x40, 2); } else { @@ -938,7 +944,7 @@ void sub_0802E034(GleerokEntity* this) { } super->type2++; - heap->filler[0x19] = 1; + heap->filler[6].unk1 = 1; } } @@ -1045,7 +1051,7 @@ void sub_0802E1D0(GleerokEntity* this) { void sub_0802E300(GleerokEntity* this) { u32 dir, tmp; u32 index; - u8* ptr; + Gleerok_HeapStruct2* ptr; u8* ptr2; Entity* ent; Gleerok_HeapStruct* heap; @@ -1085,8 +1091,8 @@ void sub_0802E300(GleerokEntity* this) { ptr = heap->filler; do { ((u16*)ptr)[0xc] = tmp; - ptr[1] = dir; - ptr += 4; + ptr->unk1 = dir; + ptr++; index++; } while (index <= 5); @@ -1120,7 +1126,7 @@ void sub_0802E448(GleerokEntity* this) { Gleerok_HeapStruct* heap = this->unk_84; s32 index; for (index = 5; index >= 0; index--) { - u8* ptr = &heap->filler[0x30]; + u8* ptr = heap->unk_30; if (ptr[index] == 0) { CreateFx(heap->entities[0], FX_LAVA_SPLASH, 0); SoundReq(SFX_PLY_LAND); @@ -1134,7 +1140,7 @@ void sub_0802E448(GleerokEntity* this) { } } - if (heap->filler[0x2d] <= 9) { + if (heap->unk_2c.HALF.HI <= 9) { sub_0802EA68(heap, 5, 0x40, 3); } @@ -1173,9 +1179,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE s32 r7; Gleerok_HeapStruct* heap = this->unk_84; CopyPosition(heap->entities[0]->parent, heap->entities[0]); - heap->entities[0]->direction = heap->filler[1]; + heap->entities[0]->direction = heap->filler[0].unk1; - r6 = heap->filler[1]; + r6 = heap->filler[0].unk1; if (r6 > 0x10) { r6 ^= 0xf; r6 = (r6 + 1) & 0xf; @@ -1187,29 +1193,29 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE heap->entities[0]->speed = ((r6 ^ 0xf) + 0x12) << 8; LinearMoveUpdate(heap->entities[0]); - sp4 = *(u32*)&heap->filler[0x30]; + sp4 = *(u32*)heap->unk_30; sp8 = this->unk_80; for (index = 0; index <= 4; index++) { s32 result; CopyPosition(heap->entities[index], heap->entities[index + 1]); - result = FixedMul(gSineTable[heap->filler[0x19 + (index + 1) * 4]], ((u8*)sp4)[r6]); + result = FixedMul(gSineTable[heap->filler[6 + (index + 1)].unk1], ((u8*)sp4)[r6]); result = FixedDiv(result, 0x100); - result = FixedMul(gSineTable[heap->filler[0x1 + (index + 1) * 4]], result); + result = FixedMul(gSineTable[heap->filler[(index + 1)].unk1], result); result = FixedDiv(result, 0x100); heap->entities[index]->x.WORD += result << 8; - result = FixedMul(gSineTable[heap->filler[0x19 + (index + 1) * 4]], ((u8*)sp4)[r6]); + result = FixedMul(gSineTable[heap->filler[6 + (index + 1)].unk1], ((u8*)sp4)[r6]); result = FixedDiv(result, 0x100); heap->entities[index]->y.WORD -= result << 8; } if (heap->ent2->timer == 24) { - r7 = (heap->filler[0x15] >> 3) << 2; - if (heap->filler[0x2d] > 0xc) { + r7 = (heap->filler[5].unk1 >> 3) << 2; + if (heap->unk_2c.HALF.HI > 0xc) { r7 += 3; } else { - r7 += heap->filler[0x2d] >> 2; + r7 += heap->unk_2c.HALF.HI >> 2; } if (heap->ent2->animIndex != r7 + 0x18) { @@ -1222,11 +1228,11 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE r7 += heap->ent2->timer; } else { if (super->iframes == 0) { - if ((super->animIndex != (heap->filler[0x15] >> 3) + 0x2f) || (super->frame & ANIM_DONE) != 0) { - r7 = (heap->filler[0x15] >> 3) + 0x28; + if ((super->animIndex != (heap->filler[5].unk1 >> 3) + 0x2f) || (super->frame & ANIM_DONE) != 0) { + r7 = (heap->filler[5].unk1 >> 3) + 0x28; } } else { - r7 = (heap->filler[0x15] >> 3) + 0x2f; + r7 = (heap->filler[5].unk1 >> 3) + 0x2f; } } @@ -1242,9 +1248,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE u32 val; sub_0802E7CC(heap, (u8)index, 0, 0); r7 = heap->entities[index]->animationState * 12; - r7 += (((s32)heap->filler[0x19 + (index + 1) * 4]) / 3) * 12; + r7 += (((s32)heap->filler[6 + (index + 1)].unk1) / 3) * 12; } else { - r7 = heap->filler[0x1 + index * 4] >> 3; + r7 = heap->filler[index].unk1 >> 3; r7 += 0x48; } if (heap->entities[index]->animIndex != r7) { @@ -1256,21 +1262,10 @@ END_NONMATCH ASM_FUNC("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1)); -typedef struct { - u8 unk0; - u8 unk1; - u8 unk2; - u8 unk3; -} sub_0802E7CC_HeapStruct; - -NONMATCH("asm/non_matching/gleerok/sub_0802E7CC.inc", - bool32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4)) { - u8* ptr; - - param_1->entities[(u8)param_2]->animationState = ((sub_0802E7CC_HeapStruct*)param_1->filler)[(u8)param_2].unk1; +u32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4) { + param_1->entities[(u8)param_2]->animationState = param_1->filler[(u8)param_2].unk1; return param_1->entities[(u8)param_2]->animationState; } -END_NONMATCH ASM_FUNC("asm/non_matching/gleerok/sub_0802E7E4.inc", void sub_0802E7E4(Gleerok_HeapStruct* this)); From c0014dbcf62a7d0ffd282e8747bc2ab495378443 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Mon, 25 Jul 2022 19:38:22 +0300 Subject: [PATCH 04/15] Match sub_0802D33C --- asm/non_matching/gleerok/sub_0802D33C.inc | 45 ----------------------- src/enemy/gleerok.c | 29 ++++++--------- 2 files changed, 11 insertions(+), 63 deletions(-) delete mode 100644 asm/non_matching/gleerok/sub_0802D33C.inc diff --git a/asm/non_matching/gleerok/sub_0802D33C.inc b/asm/non_matching/gleerok/sub_0802D33C.inc deleted file mode 100644 index 9d5969e8..00000000 --- a/asm/non_matching/gleerok/sub_0802D33C.inc +++ /dev/null @@ -1,45 +0,0 @@ - .syntax unified - push {r4, r5, r6, r7, lr} - adds r0, #0x84 - ldr r6, [r0] - movs r4, #0 - adds r7, r6, #0 - adds r7, #0x3c - adds r5, r7, #0 -_0802D34A: - ldm r5!, {r0} - bl DeleteEntity - adds r4, #1 - cmp r4, #3 - bls _0802D34A - lsls r1, r4, #2 - adds r1, r7, r1 - ldr r0, [r1] - adds r0, #0x45 - movs r3, #0 - strb r3, [r0] - ldr r1, [r1] - adds r1, #0x6d - ldrb r2, [r1] - movs r0, #1 - orrs r0, r2 - strb r0, [r1] - ldr r0, [r6, #0x50] - adds r0, #0x45 - strb r3, [r0] - ldr r0, [r6, #0x50] - strb r3, [r0, #0xb] - ldr r3, [r6, #0x50] - ldrb r2, [r3, #0x18] - lsls r1, r2, #0x1e - lsrs r1, r1, #0x1e - movs r0, #2 - rsbs r0, r0, #0 - ands r1, r0 - subs r0, #2 - ands r0, r2 - orrs r0, r1 - strb r0, [r3, #0x18] - bl DeleteThisEntity - pop {r4, r5, r6, r7, pc} - .syntax divided diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index 1cc2aaa0..7f34d511 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -223,28 +223,21 @@ void sub_0802D258(GleerokEntity* this) { sub_0802E768(this->unk_84); } -NONMATCH("asm/non_matching/gleerok/sub_0802D33C.inc", void sub_0802D33C(GleerokEntity* this)) { - u8* unk_84 = (u8*)this->unk_84; - u8* ptr = unk_84; - u8* ptr2; - u32 i = 0; - ptr += 0x3c; - ptr2 = ptr; +void sub_0802D33C(GleerokEntity* this) { + Gleerok_HeapStruct* unk_84 = this->unk_84; + u32 i; - do { - DeleteEntity(*(Entity**)ptr); - ptr += 4; - } while (i < 4); + for (i = 0; i < 4; i++) { + DeleteEntity(unk_84->entities[i]); + } - ptr2 += (i << 2); - *(u32*)((*(u8**)ptr2) + 0x45) = 0; - *((*(u8**)ptr2) + 0x6d) |= 1; - ((Entity*)(*(u8**)(unk_84 + 0x50)))->health = 0; - ((Entity*)(*(u8**)(unk_84 + 0x50)))->type2 = 0; - ((Entity*)(*(u8**)(unk_84 + 0x50)))->spriteSettings.draw &= ~1; + unk_84->entities[i]->health = 0; + ((GenericEntity*)unk_84->entities[i])->field_0x6c.HALF.HI |= 1; + unk_84->ent2->health = 0; + unk_84->ent2->type2 = 0; + unk_84->ent2->spriteSettings.draw &= ~1; DeleteThisEntity(); } -END_NONMATCH void Gleerok_OnTick(GleerokEntity* this) { gUnk_080CD7B8[super->action](this); From e2050f2eb8af400e066a9ca94839934294432ae0 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Mon, 25 Jul 2022 19:49:16 +0300 Subject: [PATCH 05/15] Minor corrections in sub_0802D3B8 nonmatching --- src/enemy/gleerok.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index 7f34d511..bdafc0a8 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -283,10 +283,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE uvar1 = 0; do { - ent = CreateEnemy(GLEEROK, 1); - super->child = ent; - if (ent != NULL) { - ent->type2 = uvar1 + 1; + super->child = CreateEnemy(GLEEROK, 1); + if (super->child != NULL) { + super->child->type2 = uvar1 + 1; super->child->collisionLayer = super->collisionLayer; super->child->x.HALF.HI = super->x.HALF.HI; super->child->y.HALF.HI = super->y.HALF.HI + ((uvar1 + 1) * 12); @@ -310,7 +309,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE super->child->parent = super; ((GleerokEntity*)super->child)->unk_84 = this->unk_84; heap->ent2 = super->child; - heap->filler[3].unk1 = 0x10; + heap->filler[5].unk1 = 0x10; heap->filler[11].unk1 = 0; heap->filler[13].unk1 = 0; } @@ -324,9 +323,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE COLLISION_ON(super); super->flags2 |= 0x80; } - ptr = gUnk_080CD7C4; - ptr += super->type2; - super->spritePriority.b0 = ptr->unk1; + super->spritePriority.b0 = gUnk_080CD7C4[super->type2].unk1; super->subtimer = 0; InitializeAnimation(super, 0x24); break; From ba2bbbc0ec545788b5f10397385c0ca5c3409e42 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 09:12:43 +0300 Subject: [PATCH 06/15] Match sub_0802EA18 --- asm/enemy/gleerok.s | 29 ----------------------------- src/enemy/gleerok.c | 18 +++++++++++++++++- 2 files changed, 17 insertions(+), 30 deletions(-) diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s index dd341326..5c60ac94 100644 --- a/asm/enemy/gleerok.s +++ b/asm/enemy/gleerok.s @@ -6,35 +6,6 @@ .text - - thumb_func_start sub_0802EA18 -sub_0802EA18: @ 0x0802EA18 - push {lr} - adds r3, r2, #0 - movs r2, #0x80 - lsls r2, r2, #5 - adds r1, r1, r2 - subs r1, r1, r0 - ldr r0, _0802EA40 @ =0x00001FFF - ands r1, r0 - lsls r3, r3, #8 - subs r2, r2, r3 - cmp r1, r2 - blo _0802EA44 - movs r2, #0x80 - lsls r2, r2, #5 - adds r0, r3, r2 - cmp r1, r0 - bhi _0802EA44 - movs r0, #0 - b _0802EA46 - .align 2, 0 -_0802EA40: .4byte 0x00001FFF -_0802EA44: - movs r0, #1 -_0802EA46: - pop {pc} - thumb_func_start sub_0802EA48 sub_0802EA48: @ 0x0802EA48 push {r4, lr} diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index bdafc0a8..e6fa9f9b 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -70,7 +70,7 @@ extern void sub_0802EBC4(GleerokEntity* this); extern void sub_0802E9B0(GleerokEntity* this); extern bool32 sub_0802EB08(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3); -extern bool32 sub_0802EA18(u16 param_1, u16 param_2, u32 param_3); +extern bool32 sub_0802EA18(u32 param_1, u32 param_2, u32 param_3); extern bool32 sub_0802EA48(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern bool32 sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern bool32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); @@ -1287,3 +1287,19 @@ void sub_0802E9B0(GleerokEntity* this) { } } } + +bool32 sub_0802EA18(u32 arg0, u32 arg1, u32 arg2) { + u32 r1; + + r1 = arg1 + 0x1000; + r1 -= arg0; + r1 &= 0x1FFF; + arg2 <<= 8; + + if (r1 >= 0x1000 - arg2) { + if (r1 <= 0x1000 + arg2) { + return FALSE; + } + } + return TRUE; +} From c314ccd671d057cf83ff46cc6b2a45c4197fa693 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 15:51:55 +0300 Subject: [PATCH 07/15] Adjust gleerok heap structure --- src/enemy/gleerok.c | 155 ++++++++++++++++++++++++++++---------------- 1 file changed, 100 insertions(+), 55 deletions(-) diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index e6fa9f9b..44aa1ac6 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -7,14 +7,14 @@ #include "object.h" typedef struct { - u8 unk0; - u8 unk1; + union SplitHWord unk0; u8 unk2; u8 unk3; } Gleerok_HeapStruct2; typedef struct { - /*0x00*/ Gleerok_HeapStruct2 filler[11]; + /*0x00*/ Gleerok_HeapStruct2 filler[6]; + /*0x00*/ Gleerok_HeapStruct2 filler2[5]; /*0x2c*/ union SplitHWord unk_2c; /*0x2e*/ u16 filler_2e; /*0x30*/ u8 unk_30[6]; @@ -143,8 +143,8 @@ void sub_0802D170(GleerokEntity* this) { return; if (super->action == 1) { - this->unk_84->filler[0].unk1 = 0x10; - this->unk_84->filler[6].unk1 = 0x10; + this->unk_84->filler[0].unk0.HALF.HI = 0x10; + this->unk_84->filler2[0].unk0.HALF.HI = 0x10; if (sub_0802EB08(this->unk_84, 0x40, 2) == 0 && sub_0802EA88(this->unk_84) == 0) { super->action = 2; gPlayerEntity.x.HALF.HI = gRoomControls.origin_x + 0x98; @@ -158,7 +158,7 @@ void sub_0802D170(GleerokEntity* this) { super->action = 3; this->unk_80 = 0; ((Entity*)this->unk_84)->parent->timer = 24; - this->unk_84->filler[6].unk1 = 0; + this->unk_84->filler2[0].unk0.HALF.HI = 0; } } @@ -171,7 +171,7 @@ void sub_0802D218(GleerokEntity* this) { super->subtimer = 0; this->unk_7c.HALF_U.LO = 0xb4; ((Entity*)(this->unk_84))->parent->timer = 12; - CreateObjectWithParent(super, 0x67, 0x2, this->unk_7c.HALF_U.LO); + CreateObjectWithParent(super, OBJECT_67, 0x2, this->unk_7c.HALF_U.LO); } void sub_0802D258(GleerokEntity* this) { @@ -294,9 +294,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE this->unk_84->entities[uvar1] = super->child; ptr = this->unk_84->filler; ptr2 = ptr + uvar1; - ptr2[0].unk1 = 0x10; - ptr2[6].unk1 = 0; - ptr[13].unk1 = 0; + ptr2[0].unk0.HALF.HI = 0x10; + ptr2[6].unk0.HALF.HI = 0; + ptr[13].unk0.HALF.HI = 0; } } while (++uvar1 < 5); @@ -309,9 +309,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE super->child->parent = super; ((GleerokEntity*)super->child)->unk_84 = this->unk_84; heap->ent2 = super->child; - heap->filler[5].unk1 = 0x10; - heap->filler[11].unk1 = 0; - heap->filler[13].unk1 = 0; + heap->filler[5].unk0.HALF.HI = 0x10; + heap->filler2[5].unk0.HALF.HI = 0; + heap->filler[13].unk0.HALF.HI = 0; } #ifndef EU gPlayerState.controlMode = CONTROL_DISABLED; @@ -323,7 +323,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D3B8.inc", void sub_0802D3B8(GleerokE COLLISION_ON(super); super->flags2 |= 0x80; } - super->spritePriority.b0 = gUnk_080CD7C4[super->type2].unk1; + super->spritePriority.b0 = gUnk_080CD7C4[super->type2].unk0.HALF.HI; super->subtimer = 0; InitializeAnimation(super, 0x24); break; @@ -416,8 +416,8 @@ void sub_0802D714(GleerokEntity* this) { return; for (heap = this->unk_84, index = 0, val1 = 0, val2 = 0x10, ptr = this->unk_84->filler; index < 6; ptr++, ++index) { - *(u16*)(ptr + 6) = val1; - ptr->unk1 = val2; + ptr[6].unk0.HWORD = val1; + ptr->unk0.HALF.HI = val2; } super->subAction = 3; @@ -575,7 +575,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE super->child = enemy; if (enemy) { enemy->parent = super->parent; - super->timer = this->unk_84->filler[0].unk1; + super->timer = this->unk_84->filler[0].unk0.HALF.HI; this->unk_84->ent = super->child; ((GleerokEntity*)super->child)->unk_84 = this->unk_84; } @@ -606,8 +606,8 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE SoundReq(SFX_BUTTON_PRESS); } } else { - if (super->timer != this->unk_84->filler[0].unk1) { - if (((super->timer - this->unk_84->filler[0].unk1) & 0x1f) > 0x10) { + if (super->timer != this->unk_84->filler[0].unk0.HALF.HI) { + if (((super->timer - this->unk_84->filler[0].unk0.HALF.HI) & 0x1f) > 0x10) { if (++super->frameIndex >= 0x31) { super->frameIndex = 0x28; } @@ -617,7 +617,7 @@ NONMATCH("asm/non_matching/gleerok/sub_0802D86C.inc", void sub_0802D86C(GleerokE } } - super->timer = this->unk_84->filler[0].unk1; + super->timer = this->unk_84->filler[0].unk0.HALF.HI; } } @@ -652,13 +652,13 @@ END_NONMATCH void sub_0802DB84(GleerokEntity* this) { u32 timer; super->direction = GetFacingDirection(super, &gPlayerEntity); - if (this->unk_84->filler[0].unk1 == super->direction) { + if (this->unk_84->filler[0].unk0.HALF.HI == super->direction) { super->subAction = 1; this->unk_78 = 0; return; } - if (((this->unk_84->filler[0].unk1 - super->direction) & 0x1f) > 0x10) { + if (((this->unk_84->filler[0].unk0.HALF.HI - super->direction) & 0x1f) > 0x10) { timer = 0; super->timer &= 0xfe; } else { @@ -686,7 +686,7 @@ void sub_0802DB84(GleerokEntity* this) { void sub_0802DC1C(GleerokEntity* this) { u32 diff = GetFacingDirection(super, &gPlayerEntity); - diff = (this->unk_84->filler[0].unk1 - diff) & 0x1f; + diff = (this->unk_84->filler[0].unk0.HALF.HI - diff) & 0x1f; if (diff > 0x10) { if (diff <= 0x1d) { @@ -709,11 +709,11 @@ void sub_0802DC1C(GleerokEntity* this) { } sub_0802EA48(this->unk_84, 5, 0x20, diff); - if (sub_0802EA18(*(u16*)this->unk_84->filler, *(u16*)&this->unk_84->filler[5], 4)) { + if (sub_0802EA18(this->unk_84->filler[0].unk0.HWORD, this->unk_84->filler[5].unk0.HWORD, 4)) { if (super->timer == 1) { - *(u16*)&this->unk_84->filler[5] = (((this->unk_84->filler[0].unk1 - 4) & 0x1f) << 8) | 0xff; + this->unk_84->filler[5].unk0.HWORD = (((this->unk_84->filler[0].unk0.HALF.HI - 4) & 0x1f) << 8) | 0xff; } else { - *(u16*)&this->unk_84->filler[5] = (((this->unk_84->filler[0].unk1 + 4) & 0x1f) << 8); + this->unk_84->filler[5].unk0.HWORD = (((this->unk_84->filler[0].unk0.HALF.HI + 4) & 0x1f) << 8); } super->timer ^= 1; @@ -730,13 +730,13 @@ void sub_0802DC1C(GleerokEntity* this) { void sub_0802DCE0(GleerokEntity* this) { if (this->unk_84->ent2->timer != 12) { super->direction = GetFacingDirection(super, &gPlayerEntity); - if (this->unk_84->filler[5].unk1 == super->direction) { + if (this->unk_84->filler[5].unk0.HALF.HI == super->direction) { this->unk_84->ent2->timer = 12; this->unk_82 = 4; super->subtimer = 0; } else { s32 svar1, diff; - diff = ((this->unk_84->filler[5].unk1 - super->direction) & 0x1f); + diff = ((this->unk_84->filler[5].unk0.HALF.HI - super->direction) & 0x1f); svar1 = 1; if (diff > 0x10) { svar1 = 0; @@ -759,7 +759,7 @@ void sub_0802DCE0(GleerokEntity* this) { super->child = CreateProjectileWithParent(super, GLEEROK_PROJECTILE, 0); if (super->child != NULL) { - super->child->direction = this->unk_84->filler[5].unk1; + super->child->direction = this->unk_84->filler[5].unk0.HALF.HI; super->child->type2 = this->unk_84->ent2->frame & 0xf; super->child->parent = this->unk_84->ent2; super->child->child = this->unk_84->entities[0]; @@ -803,10 +803,10 @@ void sub_0802DDD8(GleerokEntity* this) { if ((Random() & 1) == 0) { super->direction = 0; - this->unk_7a = (this->unk_84->filler[0].unk1 + uvar1) & 0x1f; + this->unk_7a = (this->unk_84->filler[0].unk0.HALF.HI + uvar1) & 0x1f; } else { super->direction = 1; - this->unk_7a = (this->unk_84->filler[0].unk1 - uvar1) & 0x1f; + this->unk_7a = (this->unk_84->filler[0].unk0.HALF.HI - uvar1) & 0x1f; } break; @@ -826,7 +826,7 @@ void sub_0802DDD8(GleerokEntity* this) { if (this->unk_84->ent2->subtimer == 1) { super->child = CreateProjectileWithParent(super, GLEEROK_PROJECTILE, r2); if (super->child != NULL) { - super->child->direction = this->unk_84->filler[5].unk1; + super->child->direction = this->unk_84->filler[5].unk0.HALF.HI; super->child->type2 = this->unk_84->ent2->frame & 0xf; super->child->parent = this->unk_84->ent2; super->child->child = this->unk_84->entities[0]; @@ -856,7 +856,7 @@ void sub_0802DDD8(GleerokEntity* this) { } sub_0802E768(this->unk_84); - if (this->unk_7a == this->unk_84->filler[5].unk1) { + if (this->unk_7a == this->unk_84->filler[5].unk0.HALF.HI) { if (super->type2 == 1) { super->type2 = 2; super->direction ^= 1; @@ -886,7 +886,7 @@ void sub_0802DFA8(GleerokEntity* this) { } void sub_0802DFC0(GleerokEntity* this) { - u32 val = this->unk_84->filler[0].unk1 & 7; + u32 val = this->unk_84->filler[0].unk0.HALF.HI & 7; if (val) { if (val > 4) { super->direction = 0; @@ -919,10 +919,10 @@ void sub_0802E034(GleerokEntity* this) { val = 0; } else { super->direction = 3; - val = gUnk_080CD840[heap->filler[0].unk1 >> 3]; + val = gUnk_080CD840[heap->filler[0].unk0.HALF.HI >> 3]; } - if (val != heap->filler[6].unk1) { + if (val != heap->filler2[0].unk0.HALF.HI) { sub_0802EA68(heap, 0, 0x40, super->direction); sub_0802EB08(heap, 0x40, 2); } else { @@ -934,7 +934,7 @@ void sub_0802E034(GleerokEntity* this) { } super->type2++; - heap->filler[6].unk1 = 1; + heap->filler2[0].unk0.HALF.HI = 1; } } @@ -1080,8 +1080,8 @@ void sub_0802E300(GleerokEntity* this) { tmp = 0; ptr = heap->filler; do { - ((u16*)ptr)[0xc] = tmp; - ptr->unk1 = dir; + ptr[6].unk0.HWORD = tmp; + ptr->unk0.HALF.HI = dir; ptr++; index++; } while (index <= 5); @@ -1169,9 +1169,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE s32 r7; Gleerok_HeapStruct* heap = this->unk_84; CopyPosition(heap->entities[0]->parent, heap->entities[0]); - heap->entities[0]->direction = heap->filler[0].unk1; + heap->entities[0]->direction = heap->filler->unk0.HALF.HI; - r6 = heap->filler[0].unk1; + r6 = heap->filler->unk0.HALF.HI; if (r6 > 0x10) { r6 ^= 0xf; r6 = (r6 + 1) & 0xf; @@ -1183,25 +1183,25 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE heap->entities[0]->speed = ((r6 ^ 0xf) + 0x12) << 8; LinearMoveUpdate(heap->entities[0]); - sp4 = *(u32*)heap->unk_30; + sp4 = *(u32*)&heap->unk_30; sp8 = this->unk_80; for (index = 0; index <= 4; index++) { s32 result; CopyPosition(heap->entities[index], heap->entities[index + 1]); - result = FixedMul(gSineTable[heap->filler[6 + (index + 1)].unk1], ((u8*)sp4)[r6]); + result = FixedMul(gSineTable[heap->filler2[(index + 1)].unk0.HALF.HI * 8], (heap->unk_30)[r6] << 8); result = FixedDiv(result, 0x100); - result = FixedMul(gSineTable[heap->filler[(index + 1)].unk1], result); + result = FixedMul(gSineTable[heap->filler[(index + 1)].unk0.HALF.HI * 8], result); result = FixedDiv(result, 0x100); heap->entities[index]->x.WORD += result << 8; - result = FixedMul(gSineTable[heap->filler[6 + (index + 1)].unk1], ((u8*)sp4)[r6]); + result = FixedMul(gSineTable[heap->filler2[(index + 1)].unk0.HALF.HI * 8 + 0x40], (heap->unk_30)[r6] << 8); result = FixedDiv(result, 0x100); heap->entities[index]->y.WORD -= result << 8; } if (heap->ent2->timer == 24) { - r7 = (heap->filler[5].unk1 >> 3) << 2; + r7 = (heap->filler[5].unk0.HALF.HI >> 3) << 2; if (heap->unk_2c.HALF.HI > 0xc) { r7 += 3; } else { @@ -1214,15 +1214,21 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE } else { if (this->unk_80 == 0) { sub_0802E7CC(heap, 5, 0, 0); - r7 = (heap->ent2->animationState / 2 + heap->ent2->animationState) / 4; - r7 += heap->ent2->timer; + r7 = (heap->ent2->animationState + (heap->ent2->animationState >> 1)); + r7 = (r7 >> 2) + heap->ent2->timer; } else { if (super->iframes == 0) { - if ((super->animIndex != (heap->filler[5].unk1 >> 3) + 0x2f) || (super->frame & ANIM_DONE) != 0) { - r7 = (heap->filler[5].unk1 >> 3) + 0x28; + if ((super->animIndex != (heap->filler[5].unk0.HALF.HI >> 3) + 0x2f)) { + r7 = (heap->filler[5].unk0.HALF.HI >> 3) + 0x28; + } else { + if ((super->frame & ANIM_DONE) != 0) { + r7 = (heap->filler[5].unk0.HALF.HI >> 3) + 0x28; + } else { + r7 = super->animIndex; + } } } else { - r7 = (heap->filler[5].unk1 >> 3) + 0x2f; + r7 = (heap->filler[5].unk0.HALF.HI >> 3) + 0x2f; } } @@ -1238,9 +1244,9 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE u32 val; sub_0802E7CC(heap, (u8)index, 0, 0); r7 = heap->entities[index]->animationState * 12; - r7 += (((s32)heap->filler[6 + (index + 1)].unk1) / 3) * 12; + r7 += (((s32)heap->filler2[(index + 1)].unk0.HALF.HI) / 3) * 12; } else { - r7 = heap->filler[index].unk1 >> 3; + r7 = heap->filler[index].unk0.HALF.HI >> 3; r7 += 0x48; } if (heap->entities[index]->animIndex != r7) { @@ -1250,10 +1256,49 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE } END_NONMATCH -ASM_FUNC("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1)); +NONMATCH("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1)) { + u32 cVar1; + s32 bVar2; + s32 bVar2a; + u32 bVar3; + + // solves regalloc + // register u32 bVar3 asm("r1"); + u32 bVar3a; + u32 uVar4; + s32 iVar5; + + for (uVar4 = 0; uVar4 <= 4; uVar4++) { + bVar3 = param_1->filler[uVar4].unk0.HALF.HI; + bVar2 = (bVar3 - param_1->filler[uVar4 + 1].unk0.HALF.HI) & 0x1f; + + if (bVar2 > 0x10) { + if (bVar2 <= 0x1e) { + bVar3 = (bVar3 + 1) & 0x1f; + } + } else if (bVar2 > 1) { + bVar3 = (bVar3 - 1) & 0x1f; + } + + param_1->filler[uVar4].unk0.HALF.HI = bVar3; + bVar3 = param_1->filler2[uVar4].unk0.HALF.HI; + bVar2 = (bVar3 - param_1->filler2[uVar4 + 1].unk0.HALF.HI) & 0x1f; + + if (bVar2 > 0x10) { + if (bVar2 <= 0x1d) { + bVar3 = (bVar3 + 1) & 0x1f; + } + } else if (bVar2 > 2) { + bVar3 = (bVar3 - 1) & 0x1f; + } + + param_1->filler2[uVar4].unk0.HALF.HI = bVar3; + } +} +END_NONMATCH u32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4) { - param_1->entities[(u8)param_2]->animationState = param_1->filler[(u8)param_2].unk1; + param_1->entities[(u8)param_2]->animationState = param_1->filler[(u8)param_2].unk0.HALF.HI; return param_1->entities[(u8)param_2]->animationState; } From e6d37e8ca83586433f46464c89611945a4f3a363 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 16:19:03 +0300 Subject: [PATCH 08/15] Match sub_0802E7E4 --- asm/non_matching/gleerok/sub_0802E7E4.inc | 246 ---------------------- src/enemy/gleerok.c | 45 +++- 2 files changed, 44 insertions(+), 247 deletions(-) delete mode 100644 asm/non_matching/gleerok/sub_0802E7E4.inc diff --git a/asm/non_matching/gleerok/sub_0802E7E4.inc b/asm/non_matching/gleerok/sub_0802E7E4.inc deleted file mode 100644 index 93394c16..00000000 --- a/asm/non_matching/gleerok/sub_0802E7E4.inc +++ /dev/null @@ -1,246 +0,0 @@ - .syntax unified - - .text - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, sb - mov r5, r8 - push {r5, r6, r7} - mov ip, r0 - ldr r0, [r0, #0x50] - adds r0, #0x5a - ldrb r1, [r0] - movs r0, #0x40 - ands r0, r1 - cmp r0, #0 - beq _0802E8D0 - movs r6, #0 - movs r5, #0 - mov r7, ip - adds r7, #0x3c - movs r0, #0x30 - add r0, ip - mov r8, r0 - movs r1, #8 - rsbs r1, r1, #0 - mov sl, r1 - movs r2, #4 - rsbs r2, r2, #0 - mov sb, r2 -_0802E818: - lsls r0, r5, #2 - adds r4, r7, r0 - ldr r3, [r4] - adds r3, #0x29 - movs r1, #7 - ands r1, r6 - ldrb r2, [r3] - mov r0, sl - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - adds r6, #1 - mov r1, r8 - adds r0, r1, r5 - ldrb r0, [r0] - cmp r0, #0 - bne _0802E852 - ldr r3, [r4] - ldrb r2, [r3, #0x18] - lsls r1, r2, #0x1e - lsrs r1, r1, #0x1e - movs r0, #2 - rsbs r0, r0, #0 - ands r1, r0 - mov r0, sb - ands r0, r2 - orrs r0, r1 - strb r0, [r3, #0x18] - b _0802E860 -_0802E852: - ldr r2, [r4] - ldrb r1, [r2, #0x18] - mov r0, sb - ands r0, r1 - movs r1, #1 - orrs r0, r1 - strb r0, [r2, #0x18] -_0802E860: - adds r5, #1 - cmp r5, #5 - bls _0802E818 - movs r5, #0 - movs r2, #7 - mov sb, r2 - movs r0, #8 - rsbs r0, r0, #0 - mov r8, r0 -_0802E872: - lsls r1, r5, #2 - mov r2, ip - adds r0, r2, r1 - ldrb r0, [r0, #1] - subs r0, #8 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - adds r5, #1 - cmp r0, #0x10 - bhi _0802E8BA - adds r0, r7, r1 - ldr r3, [r0] - adds r3, #0x29 - ldrb r4, [r3] - lsls r0, r4, #0x1d - lsrs r6, r0, #0x1d - lsls r2, r5, #2 - adds r2, r7, r2 - ldr r0, [r2] - adds r0, #0x29 - ldrb r1, [r0] - lsls r1, r1, #0x1d - lsrs r1, r1, #0x1d - mov r0, r8 - ands r0, r4 - orrs r0, r1 - strb r0, [r3] - ldr r1, [r2] - adds r1, #0x29 - mov r0, sb - ands r6, r0 - ldrb r2, [r1] - mov r0, r8 - ands r0, r2 - orrs r0, r6 - strb r0, [r1] -_0802E8BA: - cmp r5, #4 - bls _0802E872 - mov r1, ip - ldr r0, [r1, #0x38] - adds r0, #0x29 - ldrb r2, [r0] - movs r1, #8 - rsbs r1, r1, #0 - ands r1, r2 - strb r1, [r0] - b _0802E9A4 -_0802E8D0: - movs r6, #5 - movs r5, #0 - mov r7, ip - adds r7, #0x3c - movs r2, #0x30 - add r2, ip - mov r8, r2 - movs r0, #8 - rsbs r0, r0, #0 - mov sl, r0 - movs r1, #4 - rsbs r1, r1, #0 - mov sb, r1 -_0802E8EA: - lsls r0, r5, #2 - adds r4, r7, r0 - ldr r3, [r4] - adds r3, #0x29 - movs r1, #7 - ands r1, r6 - ldrb r2, [r3] - mov r0, sl - ands r0, r2 - orrs r0, r1 - strb r0, [r3] - subs r6, #1 - mov r2, r8 - adds r0, r2, r5 - ldrb r0, [r0] - cmp r0, #0 - bne _0802E924 - ldr r3, [r4] - ldrb r2, [r3, #0x18] - lsls r1, r2, #0x1e - lsrs r1, r1, #0x1e - movs r0, #2 - rsbs r0, r0, #0 - ands r1, r0 - mov r0, sb - ands r0, r2 - orrs r0, r1 - strb r0, [r3, #0x18] - b _0802E932 -_0802E924: - ldr r2, [r4] - ldrb r1, [r2, #0x18] - mov r0, sb - ands r0, r1 - movs r1, #1 - orrs r0, r1 - strb r0, [r2, #0x18] -_0802E932: - adds r5, #1 - cmp r5, #5 - bls _0802E8EA - movs r5, #0 - movs r0, #7 - mov sb, r0 - movs r1, #8 - rsbs r1, r1, #0 - mov r8, r1 -_0802E944: - lsls r1, r5, #2 - mov r2, ip - adds r0, r2, r1 - ldrb r0, [r0, #1] - subs r0, #8 - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - adds r5, #1 - cmp r0, #0x10 - bls _0802E98C - adds r0, r7, r1 - ldr r3, [r0] - adds r3, #0x29 - ldrb r4, [r3] - lsls r0, r4, #0x1d - lsrs r6, r0, #0x1d - lsls r2, r5, #2 - adds r2, r7, r2 - ldr r0, [r2] - adds r0, #0x29 - ldrb r1, [r0] - lsls r1, r1, #0x1d - lsrs r1, r1, #0x1d - mov r0, r8 - ands r0, r4 - orrs r0, r1 - strb r0, [r3] - ldr r1, [r2] - adds r1, #0x29 - mov r0, sb - ands r6, r0 - ldrb r2, [r1] - mov r0, r8 - ands r0, r2 - orrs r0, r6 - strb r0, [r1] -_0802E98C: - cmp r5, #4 - bls _0802E944 - mov r1, ip - ldr r2, [r1, #0x38] - adds r2, #0x29 - ldrb r1, [r2] - movs r0, #8 - rsbs r0, r0, #0 - ands r0, r1 - movs r1, #6 - orrs r0, r1 - strb r0, [r2] -_0802E9A4: - pop {r3, r4, r5} - mov r8, r3 - mov sb, r4 - mov sl, r5 - pop {r4, r5, r6, r7, pc} - .align 2, 0 - .syntax divided diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index 44aa1ac6..13061a2e 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -1302,7 +1302,50 @@ u32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 para return param_1->entities[(u8)param_2]->animationState; } -ASM_FUNC("asm/non_matching/gleerok/sub_0802E7E4.inc", void sub_0802E7E4(Gleerok_HeapStruct* this)); +void sub_0802E7E4(Gleerok_HeapStruct* this) { + u32 i; + u32 bVar6; + + if ((this->ent2->frame & 0x40) != 0) { + bVar6 = 0; + for (i = 0; i < 6; i++) { + this->entities[i]->spritePriority.b0 = bVar6++; + if (this->unk_30[i] == 0) { + this->entities[i]->spriteSettings.draw &= ~1; + } else { + this->entities[i]->spriteSettings.draw = 1; + } + } + for (i = 0; i < 5; i++) { + if ((u8)(this->filler[i].unk0.HALF.HI - 8) < 0x11) { + bVar6 = this->entities[i]->spritePriority.b0; + this->entities[i]->spritePriority.b0 = this->entities[i + 1]->spritePriority.b0; + this->entities[i + 1]->spritePriority.b0 = bVar6; + } + } + this->ent->spritePriority.b0 = 0; + } else { + bVar6 = 5; + + for (i = 0; i < 6; i++) { + this->entities[i]->spritePriority.b0 = bVar6--; + if (this->unk_30[i] == 0) { + this->entities[i]->spriteSettings.draw &= ~1; + } else { + this->entities[i]->spriteSettings.draw = 1; + } + } + + for (i = 0; i < 5; i++) { + if (0x10 < (u8)(this->filler[i].unk0.HALF.HI - 8)) { + bVar6 = this->entities[i]->spritePriority.b0; + this->entities[i]->spritePriority.b0 = this->entities[i + 1]->spritePriority.b0; + this->entities[i + 1]->spritePriority.b0 = bVar6; + } + } + this->ent->spritePriority.b0 = 6; + } +} void sub_0802E9B0(GleerokEntity* this) { u32 uVar1; From 76e523285851cda571671941e24ba6a16352f628 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 16:26:59 +0300 Subject: [PATCH 09/15] Match sub_0802EA48 --- asm/enemy/gleerok.s | 20 -------------------- src/enemy/gleerok.c | 9 ++++++++- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s index 5c60ac94..c8cc487d 100644 --- a/asm/enemy/gleerok.s +++ b/asm/enemy/gleerok.s @@ -6,26 +6,6 @@ .text - thumb_func_start sub_0802EA48 -sub_0802EA48: @ 0x0802EA48 - push {r4, lr} - adds r4, r0, #0 - cmp r3, #1 - bne _0802EA52 - rsbs r2, r2, #0 -_0802EA52: - lsls r0, r1, #2 - adds r0, r4, r0 - ldrh r1, [r0] - adds r1, r1, r2 - ldr r3, _0802EA64 @ =0x00001FFF - adds r2, r3, #0 - ands r1, r2 - strh r1, [r0] - pop {r4, pc} - .align 2, 0 -_0802EA64: .4byte 0x00001FFF - thumb_func_start sub_0802EA68 sub_0802EA68: @ 0x0802EA68 push {r4, lr} diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index 13061a2e..e2fb7165 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -71,7 +71,7 @@ extern void sub_0802E9B0(GleerokEntity* this); extern bool32 sub_0802EB08(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3); extern bool32 sub_0802EA18(u32 param_1, u32 param_2, u32 param_3); -extern bool32 sub_0802EA48(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); +extern void sub_0802EA48(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern bool32 sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern bool32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern bool32 sub_0802EA88(Gleerok_HeapStruct* param_1); @@ -1391,3 +1391,10 @@ bool32 sub_0802EA18(u32 arg0, u32 arg1, u32 arg2) { } return TRUE; } + +void sub_0802EA48(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4) { + if (param_4 == 1) { + param_3 = -param_3; + } + param_1->filler[param_2].unk0.HWORD = (param_1->filler[param_2].unk0.HWORD + param_3) & 0x1fff; +} From 9661378a814d98438b777fe048cbc7ce08c7e864 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 16:29:02 +0300 Subject: [PATCH 10/15] Match sub_0802EA68 --- asm/enemy/gleerok.s | 19 ------------------- src/enemy/gleerok.c | 9 ++++++++- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s index c8cc487d..46e90cd1 100644 --- a/asm/enemy/gleerok.s +++ b/asm/enemy/gleerok.s @@ -6,25 +6,6 @@ .text - thumb_func_start sub_0802EA68 -sub_0802EA68: @ 0x0802EA68 - push {r4, lr} - adds r4, r0, #0 - cmp r3, #2 - bne _0802EA72 - rsbs r2, r2, #0 -_0802EA72: - lsls r0, r1, #2 - adds r0, r4, r0 - ldrh r1, [r0, #0x18] - adds r1, r1, r2 - ldr r3, _0802EA84 @ =0x00001FFF - adds r2, r3, #0 - ands r1, r2 - strh r1, [r0, #0x18] - pop {r4, pc} - .align 2, 0 -_0802EA84: .4byte 0x00001FFF thumb_func_start sub_0802EA88 sub_0802EA88: @ 0x0802EA88 diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index e2fb7165..d7542be3 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -72,7 +72,7 @@ extern void sub_0802E9B0(GleerokEntity* this); extern bool32 sub_0802EB08(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3); extern bool32 sub_0802EA18(u32 param_1, u32 param_2, u32 param_3); extern void sub_0802EA48(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); -extern bool32 sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); +extern void sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern bool32 sub_0802E7CC(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern bool32 sub_0802EA88(Gleerok_HeapStruct* param_1); extern bool32 sub_0802E768(Gleerok_HeapStruct* param_1); @@ -1398,3 +1398,10 @@ void sub_0802EA48(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 par } param_1->filler[param_2].unk0.HWORD = (param_1->filler[param_2].unk0.HWORD + param_3) & 0x1fff; } + +void sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4) { + if (param_4 == 2) { + param_3 = -param_3; + } + param_1->filler2[param_2].unk0.HWORD = (param_1->filler2[param_2].unk0.HWORD + param_3) & 0x1fff; +} From 90536b532101623e4ef93f5e9aadf96b125077f7 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 17:02:39 +0300 Subject: [PATCH 11/15] Add non matching sub_0802EA88 --- asm/enemy/gleerok.s | 74 ---------------------- asm/non_matching/gleerok/sub_0802EA88.inc | 75 +++++++++++++++++++++++ src/enemy/gleerok.c | 41 +++++++++++++ 3 files changed, 116 insertions(+), 74 deletions(-) create mode 100644 asm/non_matching/gleerok/sub_0802EA88.inc diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s index 46e90cd1..104034f9 100644 --- a/asm/enemy/gleerok.s +++ b/asm/enemy/gleerok.s @@ -7,80 +7,6 @@ .text - thumb_func_start sub_0802EA88 -sub_0802EA88: @ 0x0802EA88 - push {r4, r5, r6, lr} - adds r5, r0, #0 - movs r6, #0 - movs r3, #0 -_0802EA90: - lsls r0, r3, #2 - adds r4, r5, r0 - adds r2, r3, #1 - lsls r0, r2, #2 - adds r1, r5, r0 - ldrb r0, [r4, #1] - ldrb r3, [r1, #1] - cmp r0, r3 - beq _0802EAC2 - movs r6, #1 - ldrb r0, [r1, #1] - ldrb r1, [r4, #1] - subs r0, r0, r1 - movs r1, #0x1f - ands r0, r1 - movs r3, #1 - cmp r0, #0x10 - ble _0802EAB6 - movs r3, #0 -_0802EAB6: - adds r0, r5, #0 - adds r1, r2, #0 - movs r2, #0x20 - bl sub_0802EA48 - b _0802EAC8 -_0802EAC2: - adds r3, r2, #0 - cmp r3, #4 - bls _0802EA90 -_0802EAC8: - movs r3, #0 - movs r4, #0x1f -_0802EACC: - adds r2, r3, #1 - lsls r0, r2, #2 - adds r0, r5, r0 - ldrb r1, [r0, #1] - lsls r0, r3, #2 - adds r0, r5, r0 - ldrb r0, [r0, #1] - subs r0, r1, r0 - ands r0, r4 - adds r3, r1, #0 - adds r1, r2, #0 - cmp r0, #0x10 - ble _0802EAEE - cmp r0, #0x1e - bgt _0802EAF6 - adds r3, #1 - b _0802EAF4 -_0802EAEE: - cmp r0, #1 - ble _0802EAF6 - subs r3, #1 -_0802EAF4: - ands r3, r4 -_0802EAF6: - lsls r0, r1, #2 - adds r0, r5, r0 - strb r3, [r0, #1] - adds r3, r1, #0 - cmp r3, #4 - bls _0802EACC - adds r0, r6, #0 - pop {r4, r5, r6, pc} - .align 2, 0 - thumb_func_start sub_0802EB08 sub_0802EB08: @ 0x0802EB08 push {r4, r5, r6, r7, lr} diff --git a/asm/non_matching/gleerok/sub_0802EA88.inc b/asm/non_matching/gleerok/sub_0802EA88.inc new file mode 100644 index 00000000..b419969b --- /dev/null +++ b/asm/non_matching/gleerok/sub_0802EA88.inc @@ -0,0 +1,75 @@ + .syntax unified + + .text +push {r4, r5, r6, lr} + adds r5, r0, #0 + movs r6, #0 + movs r3, #0 +_0802EA90: + lsls r0, r3, #2 + adds r4, r5, r0 + adds r2, r3, #1 + lsls r0, r2, #2 + adds r1, r5, r0 + ldrb r0, [r4, #1] + ldrb r3, [r1, #1] + cmp r0, r3 + beq _0802EAC2 + movs r6, #1 + ldrb r0, [r1, #1] + ldrb r1, [r4, #1] + subs r0, r0, r1 + movs r1, #0x1f + ands r0, r1 + movs r3, #1 + cmp r0, #0x10 + ble _0802EAB6 + movs r3, #0 +_0802EAB6: + adds r0, r5, #0 + adds r1, r2, #0 + movs r2, #0x20 + bl sub_0802EA48 + b _0802EAC8 +_0802EAC2: + adds r3, r2, #0 + cmp r3, #4 + bls _0802EA90 +_0802EAC8: + movs r3, #0 + movs r4, #0x1f +_0802EACC: + adds r2, r3, #1 + lsls r0, r2, #2 + adds r0, r5, r0 + ldrb r1, [r0, #1] + lsls r0, r3, #2 + adds r0, r5, r0 + ldrb r0, [r0, #1] + subs r0, r1, r0 + ands r0, r4 + adds r3, r1, #0 + adds r1, r2, #0 + cmp r0, #0x10 + ble _0802EAEE + cmp r0, #0x1e + bgt _0802EAF6 + adds r3, #1 + b _0802EAF4 +_0802EAEE: + cmp r0, #1 + ble _0802EAF6 + subs r3, #1 +_0802EAF4: + ands r3, r4 +_0802EAF6: + lsls r0, r1, #2 + adds r0, r5, r0 + strb r3, [r0, #1] + adds r3, r1, #0 + cmp r3, #4 + bls _0802EACC + adds r0, r6, #0 + pop {r4, r5, r6, pc} + .align 2, 0 + .syntax divided diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index d7542be3..6fa86ea0 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -1405,3 +1405,44 @@ void sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 par } param_1->filler2[param_2].unk0.HWORD = (param_1->filler2[param_2].unk0.HWORD + param_3) & 0x1fff; } + +NONMATCH("asm/non_matching/gleerok/sub_0802EA88.inc", bool32 sub_0802EA88(Gleerok_HeapStruct* this)) { + u32 cVar1; + s32 bVar2; + u32 uVar3; + u32 bVar4; + u32 uVar5; + u32 uVar6; + + uVar6 = FALSE; + + for (uVar5 = 0; uVar5 < 5; uVar5++) { + if (this->filler[uVar5].unk0.HALF.HI != this->filler[uVar5 + 1].unk0.HALF.HI) { + uVar6 = TRUE; + if ((s32)((this->filler[uVar5 + 1].unk0.HALF.HI - this->filler[uVar5].unk0.HALF.HI) & 0x1fU) > 0x10) { + uVar3 = 0; + } else { + uVar3 = 1; + } + sub_0802EA48(this, uVar5 + 1, 0x20, uVar3); + break; + } + } + + for (uVar5 = 0; uVar5 <= 4; uVar5++) { + bVar4 = this->filler[uVar5 + 1].unk0.HALF.HI; + bVar2 = (bVar4 - this->filler[uVar5].unk0.HALF.HI) & 0x1f; + if (bVar2 >= 0x11) { + if (bVar2 < 0x1f) { + bVar4 = (bVar4 + 1) & 0x1f; + } + } else { + if (1 < bVar2) { + bVar4 = (bVar4 - 1) & 0x1f; + } + } + this->filler[uVar5 + 1].unk0.HALF.HI = bVar4; + } + return uVar6; +} +END_NONMATCH From 66e1362dc6fabdda45b5d90f0800bcb3cdaac862 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 17:12:53 +0300 Subject: [PATCH 12/15] Add nonmatching sub_0802EB08 --- asm/enemy/gleerok.s | 84 ---------------------- asm/non_matching/gleerok/sub_0802EB08.inc | 85 +++++++++++++++++++++++ src/enemy/gleerok.c | 44 +++++++++++- 3 files changed, 128 insertions(+), 85 deletions(-) create mode 100644 asm/non_matching/gleerok/sub_0802EB08.inc diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s index 104034f9..62242ca2 100644 --- a/asm/enemy/gleerok.s +++ b/asm/enemy/gleerok.s @@ -7,90 +7,6 @@ .text - thumb_func_start sub_0802EB08 -sub_0802EB08: @ 0x0802EB08 - push {r4, r5, r6, r7, lr} - mov r7, r8 - push {r7} - adds r5, r0, #0 - adds r6, r1, #0 - adds r7, r2, #0 - movs r0, #0 - mov r8, r0 - movs r3, #0 -_0802EB1A: - lsls r0, r3, #2 - adds r4, r5, r0 - adds r2, r3, #1 - lsls r0, r2, #2 - adds r1, r5, r0 - ldrb r0, [r4, #0x19] - ldrb r3, [r1, #0x19] - cmp r0, r3 - beq _0802EB4E - movs r0, #1 - mov r8, r0 - ldrb r0, [r1, #0x19] - ldrb r1, [r4, #0x19] - subs r0, r0, r1 - movs r1, #0x1f - ands r0, r1 - movs r3, #2 - cmp r0, #0x10 - ble _0802EB42 - movs r3, #3 -_0802EB42: - adds r0, r5, #0 - adds r1, r2, #0 - adds r2, r6, #0 - bl sub_0802EA68 - b _0802EB54 -_0802EB4E: - adds r3, r2, #0 - cmp r3, #4 - bls _0802EB1A -_0802EB54: - movs r3, #0 - movs r4, #0x1f - rsbs r6, r7, #0 - ands r6, r4 -_0802EB5C: - adds r2, r3, #1 - lsls r0, r2, #2 - adds r0, r5, r0 - ldrb r1, [r0, #0x19] - lsls r0, r3, #2 - adds r0, r5, r0 - ldrb r0, [r0, #0x19] - subs r0, r1, r0 - ands r0, r4 - adds r3, r1, #0 - adds r1, r2, #0 - cmp r0, #0x10 - ble _0802EB7E - cmp r6, r0 - ble _0802EB86 - adds r3, #1 - b _0802EB84 -_0802EB7E: - cmp r7, r0 - bge _0802EB86 - subs r3, #1 -_0802EB84: - ands r3, r4 -_0802EB86: - lsls r0, r1, #2 - adds r0, r5, r0 - strb r3, [r0, #0x19] - adds r3, r1, #0 - cmp r3, #4 - bls _0802EB5C - mov r0, r8 - pop {r3} - mov r8, r3 - pop {r4, r5, r6, r7, pc} - .align 2, 0 - thumb_func_start sub_0802EB9C sub_0802EB9C: @ 0x0802EB9C push {r4, lr} diff --git a/asm/non_matching/gleerok/sub_0802EB08.inc b/asm/non_matching/gleerok/sub_0802EB08.inc new file mode 100644 index 00000000..f859c19d --- /dev/null +++ b/asm/non_matching/gleerok/sub_0802EB08.inc @@ -0,0 +1,85 @@ + .syntax unified + + .text + push {r4, r5, r6, r7, lr} + mov r7, r8 + push {r7} + adds r5, r0, #0 + adds r6, r1, #0 + adds r7, r2, #0 + movs r0, #0 + mov r8, r0 + movs r3, #0 +_0802EB1A: + lsls r0, r3, #2 + adds r4, r5, r0 + adds r2, r3, #1 + lsls r0, r2, #2 + adds r1, r5, r0 + ldrb r0, [r4, #0x19] + ldrb r3, [r1, #0x19] + cmp r0, r3 + beq _0802EB4E + movs r0, #1 + mov r8, r0 + ldrb r0, [r1, #0x19] + ldrb r1, [r4, #0x19] + subs r0, r0, r1 + movs r1, #0x1f + ands r0, r1 + movs r3, #2 + cmp r0, #0x10 + ble _0802EB42 + movs r3, #3 +_0802EB42: + adds r0, r5, #0 + adds r1, r2, #0 + adds r2, r6, #0 + bl sub_0802EA68 + b _0802EB54 +_0802EB4E: + adds r3, r2, #0 + cmp r3, #4 + bls _0802EB1A +_0802EB54: + movs r3, #0 + movs r4, #0x1f + rsbs r6, r7, #0 + ands r6, r4 +_0802EB5C: + adds r2, r3, #1 + lsls r0, r2, #2 + adds r0, r5, r0 + ldrb r1, [r0, #0x19] + lsls r0, r3, #2 + adds r0, r5, r0 + ldrb r0, [r0, #0x19] + subs r0, r1, r0 + ands r0, r4 + adds r3, r1, #0 + adds r1, r2, #0 + cmp r0, #0x10 + ble _0802EB7E + cmp r6, r0 + ble _0802EB86 + adds r3, #1 + b _0802EB84 +_0802EB7E: + cmp r7, r0 + bge _0802EB86 + subs r3, #1 +_0802EB84: + ands r3, r4 +_0802EB86: + lsls r0, r1, #2 + adds r0, r5, r0 + strb r3, [r0, #0x19] + adds r3, r1, #0 + cmp r3, #4 + bls _0802EB5C + mov r0, r8 + pop {r3} + mov r8, r3 + pop {r4, r5, r6, r7, pc} + .align 2, 0 + .syntax divided diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index 6fa86ea0..d4805db2 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -69,7 +69,7 @@ extern void sub_0802E430(GleerokEntity* this); extern void sub_0802EBC4(GleerokEntity* this); extern void sub_0802E9B0(GleerokEntity* this); -extern bool32 sub_0802EB08(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3); +extern bool32 sub_0802EB08(Gleerok_HeapStruct* param_1, u32 param_2, s32 param_3); extern bool32 sub_0802EA18(u32 param_1, u32 param_2, u32 param_3); extern void sub_0802EA48(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); extern void sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 param_4); @@ -1446,3 +1446,45 @@ NONMATCH("asm/non_matching/gleerok/sub_0802EA88.inc", bool32 sub_0802EA88(Gleero return uVar6; } END_NONMATCH + +NONMATCH("asm/non_matching/gleerok/sub_0802EB08.inc", + bool32 sub_0802EB08(Gleerok_HeapStruct* param_1, u32 param_2, s32 param_3)) { + s32 uVar2; + u32 bVar4; + u32 uVar5; + u32 uVar6; + u32 uVar7; + + uVar7 = FALSE; + + for (uVar6 = 0; uVar6 < 5; uVar6++) { + if (param_1->filler2[uVar6].unk0.HALF.HI != param_1->filler2[uVar6 + 1].unk0.HALF.HI) { + uVar7 = TRUE; + if (0x10 < + (s32)((param_1->filler2[uVar6 + 1].unk0.HALF.HI - param_1->filler2[uVar6].unk0.HALF.HI) & 0x1fU)) { + uVar5 = 3; + } else { + uVar5 = 2; + } + sub_0802EA68(param_1, uVar6 + 1, param_2, uVar5); + break; + } + } + + for (uVar6 = 0; uVar6 <= 4; uVar6++) { + bVar4 = param_1->filler2[uVar6 + 1].unk0.HALF.HI; + uVar2 = (bVar4 - param_1->filler2[uVar6].unk0.HALF.HI) & 0x1f; + if (uVar2 >= 0x11) { + if ((-param_3 & 0x1f) > uVar2) { + bVar4 = (bVar4 + 1) & 0x1f; + } + } else { + if (param_3 < (int)uVar2) { + bVar4 = (bVar4 - 1) & 0x1f; + } + } + param_1->filler2[uVar6 + 1].unk0.HALF.HI = bVar4; + } + return uVar7; +} +END_NONMATCH From 17a7755083e9561d4b6e11bc3b30c4632a63cb1f Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 17:20:24 +0300 Subject: [PATCH 13/15] Match sub_0802EB9C --- asm/enemy/gleerok.s | 20 -------------------- src/enemy/gleerok.c | 9 ++++++++- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s index 62242ca2..74dd5bb8 100644 --- a/asm/enemy/gleerok.s +++ b/asm/enemy/gleerok.s @@ -7,26 +7,6 @@ .text - thumb_func_start sub_0802EB9C -sub_0802EB9C: @ 0x0802EB9C - push {r4, lr} - adds r4, r0, #0 - ldr r0, _0802EBBC @ =gUnk_080CD850 - bl GetRandomByWeight - ldr r1, _0802EBC0 @ =gUnk_080CD854 - adds r0, r0, r1 - ldrb r1, [r0] - adds r0, r4, #0 - adds r0, #0x74 - strb r1, [r0] - adds r4, #0x75 - ldrb r0, [r4] - adds r0, #1 - strb r0, [r4] - pop {r4, pc} - .align 2, 0 -_0802EBBC: .4byte gUnk_080CD850 -_0802EBC0: .4byte gUnk_080CD854 thumb_func_start sub_0802EBC4 sub_0802EBC4: @ 0x0802EBC4 diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index d4805db2..169a599b 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -57,13 +57,15 @@ extern u8 gUnk_080CD884[]; extern u8 gUnk_080CD7F8[]; extern u8 gUnk_080CD840[]; extern u8 gUnk_080CD844[]; +extern u8 gUnk_080CD850[]; +extern u8 gUnk_080CD854[]; extern u32 sub_0806FC80(Entity*, Entity*, s32); extern void sub_0802E518(GleerokEntity* this); extern void sub_0802E7E4(Gleerok_HeapStruct* this); extern void sub_0802E1D0(GleerokEntity* this); -extern u32 sub_0802EB9C(GleerokEntity* this); +extern void sub_0802EB9C(GleerokEntity* this); extern void sub_0802D86C(GleerokEntity* this); extern void sub_0802E430(GleerokEntity* this); extern void sub_0802EBC4(GleerokEntity* this); @@ -1488,3 +1490,8 @@ NONMATCH("asm/non_matching/gleerok/sub_0802EB08.inc", return uVar7; } END_NONMATCH + +void sub_0802EB9C(GleerokEntity* this) { + this->unk_74 = gUnk_080CD854[GetRandomByWeight(gUnk_080CD850)]; + this->unk_75++; +} From 9c47da96e62439932bb4a02f3b1828109ed22d5f Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Tue, 26 Jul 2022 17:34:48 +0300 Subject: [PATCH 14/15] Match sub_0802EBC4 --- asm/enemy/gleerok.s | 99 --------------------------------------------- linker.ld | 1 - src/enemy/gleerok.c | 38 ++++++++++++++++- 3 files changed, 36 insertions(+), 102 deletions(-) delete mode 100644 asm/enemy/gleerok.s diff --git a/asm/enemy/gleerok.s b/asm/enemy/gleerok.s deleted file mode 100644 index 74dd5bb8..00000000 --- a/asm/enemy/gleerok.s +++ /dev/null @@ -1,99 +0,0 @@ - .include "asm/macros.inc" - - .include "constants/constants.inc" - - .syntax unified - - .text - - - - thumb_func_start sub_0802EBC4 -sub_0802EBC4: @ 0x0802EBC4 - push {r4, r5, r6, lr} - adds r4, r0, #0 - adds r1, r4, #0 - adds r1, #0x74 - ldrb r0, [r1] - adds r6, r0, #0 - cmp r6, #0 - bne _0802EC66 - ldr r1, _0802EC18 @ =gUnk_080CD86C - adds r5, r4, #0 - adds r5, #0x79 - ldrb r0, [r5] - lsls r0, r0, #2 - adds r0, r0, r1 - ldr r0, [r0] - bl GetRandomByWeight - ldr r2, _0802EC1C @ =gUnk_080CD878 - ldrb r1, [r5] - lsls r1, r1, #2 - adds r1, r1, r2 - ldr r1, [r1] - adds r1, r1, r0 - adds r2, r4, #0 - adds r2, #0x75 - ldrb r0, [r1] - ldrb r1, [r2] - cmp r0, r1 - bhs _0802EC60 - strb r6, [r2] - ldrb r1, [r5] - cmp r1, #0 - bne _0802EC20 - adds r0, r4, #0 - adds r0, #0x76 - strb r1, [r0] - adds r1, r4, #0 - adds r1, #0x77 - movs r0, #3 - strb r0, [r1] - b _0802EC56 - .align 2, 0 -_0802EC18: .4byte gUnk_080CD86C -_0802EC1C: .4byte gUnk_080CD878 -_0802EC20: - bl Random - adds r1, r0, #0 - movs r5, #1 - ands r1, r5 - adds r3, r4, #0 - adds r3, #0x76 - ldrb r0, [r3] - cmp r1, r0 - beq _0802EC3E - strb r1, [r3] - adds r0, r4, #0 - adds r0, #0x77 - strb r5, [r0] - b _0802EC56 -_0802EC3E: - adds r2, r4, #0 - adds r2, #0x77 - ldrb r0, [r2] - adds r0, #1 - strb r0, [r2] - lsls r0, r0, #0x18 - lsrs r0, r0, #0x18 - cmp r0, #2 - bls _0802EC54 - eors r1, r5 - strb r5, [r2] -_0802EC54: - strb r1, [r3] -_0802EC56: - movs r1, #0 - movs r0, #3 - strb r0, [r4, #0xd] - strb r1, [r4, #0xb] - b _0802EC6A -_0802EC60: - movs r0, #2 - strb r0, [r4, #0xd] - b _0802EC6A -_0802EC66: - subs r0, #1 - strb r0, [r1] -_0802EC6A: - pop {r4, r5, r6, pc} diff --git a/linker.ld b/linker.ld index f9f4e0f6..81e26aff 100644 --- a/linker.ld +++ b/linker.ld @@ -328,7 +328,6 @@ SECTIONS { src/enemy/bobomb.o(.text); src/enemy/wallMaster2.o(.text); src/enemy/gleerok.o(.text); - asm/enemy/gleerok.o(.text); src/enemy/vaatiEyesMacro.o(.text); src/enemy/tektite.o(.text); src/enemy/wizzrobeWind.o(.text); diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index 169a599b..e498719e 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -59,6 +59,8 @@ extern u8 gUnk_080CD840[]; extern u8 gUnk_080CD844[]; extern u8 gUnk_080CD850[]; extern u8 gUnk_080CD854[]; +extern const u8* gUnk_080CD86C[]; +extern const u8* gUnk_080CD878[]; extern u32 sub_0806FC80(Entity*, Entity*, s32); @@ -1259,7 +1261,6 @@ NONMATCH("asm/non_matching/gleerok/sub_0802E518.inc", void sub_0802E518(GleerokE END_NONMATCH NONMATCH("asm/non_matching/gleerok/sub_0802E768.inc", bool32 sub_0802E768(Gleerok_HeapStruct* param_1)) { - u32 cVar1; s32 bVar2; s32 bVar2a; u32 bVar3; @@ -1409,7 +1410,6 @@ void sub_0802EA68(Gleerok_HeapStruct* param_1, u32 param_2, u32 param_3, u32 par } NONMATCH("asm/non_matching/gleerok/sub_0802EA88.inc", bool32 sub_0802EA88(Gleerok_HeapStruct* this)) { - u32 cVar1; s32 bVar2; u32 uVar3; u32 bVar4; @@ -1495,3 +1495,37 @@ void sub_0802EB9C(GleerokEntity* this) { this->unk_74 = gUnk_080CD854[GetRandomByWeight(gUnk_080CD850)]; this->unk_75++; } + +void sub_0802EBC4(GleerokEntity* this) { + u32 bVar3; + s32 iVar4; + + if (this->unk_74 == 0) { + iVar4 = GetRandomByWeight(gUnk_080CD86C[this->unk_79]); + if (gUnk_080CD878[this->unk_79][iVar4] < this->unk_75) { + this->unk_75 = 0; + if (this->unk_79 == 0) { + this->unk_76 = 0; + this->unk_77 = 3; + } else { + bVar3 = Random() & 1; + if (bVar3 != this->unk_76) { + this->unk_76 = bVar3; + this->unk_77 = 1; + } else { + if (++this->unk_77 > 2) { + bVar3 ^= 1; + this->unk_77 = 1; + } + this->unk_76 = bVar3; + } + } + this->base.subAction = 3; + this->base.type2 = 0; + } else { + this->base.subAction = 2; + } + } else { + this->unk_74--; + } +} From bd4da6b692f9b297d7bf1445fcf204c794581182 Mon Sep 17 00:00:00 2001 From: Tal Hayon Date: Wed, 27 Jul 2022 07:40:58 +0300 Subject: [PATCH 15/15] Fix object enum rename --- src/enemy/gleerok.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/enemy/gleerok.c b/src/enemy/gleerok.c index e498719e..ed55e2c2 100644 --- a/src/enemy/gleerok.c +++ b/src/enemy/gleerok.c @@ -175,7 +175,7 @@ void sub_0802D218(GleerokEntity* this) { super->subtimer = 0; this->unk_7c.HALF_U.LO = 0xb4; ((Entity*)(this->unk_84))->parent->timer = 12; - CreateObjectWithParent(super, OBJECT_67, 0x2, this->unk_7c.HALF_U.LO); + CreateObjectWithParent(super, GLEEROK_PARTICLE, 0x2, this->unk_7c.HALF_U.LO); } void sub_0802D258(GleerokEntity* this) {