From 06618d7236576d764221d4224c0cb39ed1660dd4 Mon Sep 17 00:00:00 2001 From: YohannDR Date: Wed, 24 May 2023 12:17:16 +0200 Subject: [PATCH] Match GadoraHatchUpdate --- README.md | 2 +- asm/disasm_0x0804ed08.s | 36 +++++++-------- asm/disasm_0x0805745c.s | 99 ----------------------------------------- linker.ld | 2 +- src/gadora_hatch.c | 43 +++++++++++------- src/projectile.c | 47 ++++++++++--------- 6 files changed, 70 insertions(+), 159 deletions(-) delete mode 100644 asm/disasm_0x0805745c.s diff --git a/README.md b/README.md index 3ee10330..6672752e 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This is a work in progress decompilation of Metroid - Zero Mission. -2503/2721 functions decompiled (91.99%, 218 left) +2504/2721 functions decompiled (92.02%, 217 left) Progress can be seen here : https://docs.google.com/spreadsheets/d/1X8XarD5evY8ZI7r_GQqh1pYmdVMbBcINYfRBUlogmKY/edit#gid=0 **This decomp is not shiftable, don't use it as a base to work on anything** diff --git a/asm/disasm_0x0804ed08.s b/asm/disasm_0x0804ed08.s index 08e44c1f..a2c790c9 100644 --- a/asm/disasm_0x0804ed08.s +++ b/asm/disasm_0x0804ed08.s @@ -1939,8 +1939,8 @@ lbl_0804fc2e: pop {r1} bx r1 - thumb_func_start set_projectile_trail -set_projectile_trail: @ 0x0804fc38 + thumb_func_start ProjectileSetTrail +ProjectileSetTrail: @ 0x0804fc38 push {r4, r5, r6, lr} adds r4, r0, #0 lsls r1, r1, #0x18 @@ -4232,7 +4232,7 @@ lbl_08050d80: movs r1, #0x16 lbl_08050d84: movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08050e3c lbl_08050d8c: cmp r0, #1 @@ -4638,7 +4638,7 @@ lbl_080510a0: movs r1, #0x16 lbl_080510a4: movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051166 lbl_080510ac: cmp r5, #1 @@ -4817,7 +4817,7 @@ lbl_0805120c: movs r1, #0x16 lbl_08051210: movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_0805132a lbl_08051218: cmp r5, #1 @@ -5247,7 +5247,7 @@ ProjectileProcessChargedLongBeam: @ 0x08051538 adds r0, r4, #0 movs r1, #0x18 movs r2, #7 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_0805161c .align 2, 0 lbl_08051568: .4byte gCurrentClipdataAffectingAction @@ -5378,7 +5378,7 @@ ProjectileProcessChargedIceBeam: @ 0x08051630 adds r0, r4, #0 movs r1, #0x17 movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051676 .align 2, 0 lbl_08051668: .4byte gCurrentClipdataAffectingAction @@ -5386,12 +5386,12 @@ lbl_0805166c: adds r0, r4, #0 movs r1, #0x16 movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail lbl_08051676: adds r0, r4, #0 movs r1, #0x19 movs r2, #7 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051734 lbl_08051682: cmp r0, #1 @@ -5532,7 +5532,7 @@ ProjectileProcessChargedWaveBeam: @ 0x08051764 adds r0, r4, #0 movs r1, #0x17 movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_080517aa .align 2, 0 lbl_0805179c: .4byte gEquipment @@ -5540,12 +5540,12 @@ lbl_080517a0: adds r0, r4, #0 movs r1, #0x16 movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail lbl_080517aa: adds r0, r4, #0 movs r1, #0x1a movs r2, #7 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_0805186e lbl_080517b6: cmp r5, #1 @@ -5715,7 +5715,7 @@ lbl_080518e2: adds r0, r4, #0 movs r1, #0x17 movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051922 .align 2, 0 lbl_08051914: .4byte gEquipment @@ -5723,7 +5723,7 @@ lbl_08051918: adds r0, r4, #0 movs r1, #0x16 movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail lbl_08051922: cmp r6, #0 beq lbl_08051936 @@ -5741,7 +5741,7 @@ lbl_08051936: movs r1, #0x1b lbl_0805193a: movs r2, #7 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051a50 lbl_08051942: cmp r5, #1 @@ -5920,7 +5920,7 @@ ProjectileProcessChargedPistol: @ 0x08051a7c adds r0, r4, #0 movs r1, #0x1d movs r2, #7 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051b60 .align 2, 0 lbl_08051aac: .4byte gCurrentClipdataAffectingAction @@ -6084,7 +6084,7 @@ lbl_08051bda: adds r0, r4, #0 movs r1, #0x14 movs r2, #7 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051cbe .align 2, 0 lbl_08051be8: .4byte gCurrentClipdataAffectingAction @@ -6255,7 +6255,7 @@ lbl_08051d2a: adds r0, r4, #0 movs r1, #0x15 movs r2, #3 - bl set_projectile_trail + bl ProjectileSetTrail b lbl_08051e0e .align 2, 0 lbl_08051d38: .4byte gCurrentClipdataAffectingAction diff --git a/asm/disasm_0x0805745c.s b/asm/disasm_0x0805745c.s deleted file mode 100644 index e04bab00..00000000 --- a/asm/disasm_0x0805745c.s +++ /dev/null @@ -1,99 +0,0 @@ - .include "asm/macros.inc" - - .syntax unified - - thumb_func_start GadoraHatchUpdate -GadoraHatchUpdate: @ 0x0805790c - push {r4, r5, r6, r7, lr} - mov r7, sl - mov r6, sb - mov r5, r8 - push {r5, r6, r7} - sub sp, #4 - lsls r0, r0, #0x10 - lsls r1, r1, #0x10 - lsls r2, r2, #0x18 - lsrs r2, r2, #0x18 - rsbs r3, r2, #0 - orrs r3, r2 - lsrs r3, r3, #0x1f - str r3, [sp] - movs r6, #0 - movs r7, #0 - movs r4, #0 - lsrs r0, r0, #0x16 - lsls r0, r0, #0x10 - mov r8, r0 - lsrs r1, r1, #0x16 - lsls r1, r1, #0x10 - mov ip, r1 - mov sb, r3 - ldr r3, lbl_08057990 @ =gHatchData - movs r0, #2 - rsbs r0, r0, #0 - mov sl, r0 -lbl_08057944: - ldrb r0, [r3, #1] - lsls r0, r0, #0x1e - cmp r0, #0 - bne lbl_08057994 - ldrb r1, [r3, #5] - adds r0, r1, r6 - mov r5, r8 - lsrs r2, r5, #0x10 - cmp r0, r2 - blt lbl_08057974 - subs r0, r1, r6 - cmp r0, r2 - bgt lbl_08057974 - ldrb r1, [r3, #6] - adds r0, r1, #3 - mov r5, ip - lsrs r2, r5, #0x10 - cmp r0, r2 - blt lbl_08057974 - movs r5, #0 - subs r0, r1, r5 - cmp r0, r2 - bgt lbl_08057974 - movs r7, #1 -lbl_08057974: - cmp r7, #0 - beq lbl_08057994 - ldrb r1, [r3] - lsls r0, r1, #0x1f - lsrs r0, r0, #0x1f - ldr r2, [sp] - cmp r0, r2 - beq lbl_080579a2 - mov r0, sl - ands r0, r1 - mov r5, sb - orrs r0, r5 - strb r0, [r3] - b lbl_0805799c - .align 2, 0 -lbl_08057990: .4byte gHatchData -lbl_08057994: - adds r3, #8 - adds r4, #1 - cmp r4, #0xf - ble lbl_08057944 -lbl_0805799c: - adds r4, #1 - cmp r7, #0 - bne lbl_080579a4 -lbl_080579a2: - movs r4, #0 -lbl_080579a4: - adds r0, r4, #0 - add sp, #4 - pop {r3, r4, r5} - mov r8, r3 - mov sb, r4 - mov sl, r5 - pop {r4, r5, r6, r7} - pop {r1} - bx r1 - .align 2, 0 - diff --git a/linker.ld b/linker.ld index 402ccac1..2a5b1491 100644 --- a/linker.ld +++ b/linker.ld @@ -500,7 +500,7 @@ SECTIONS { src/particle.o(.text); asm/disasm_0x08055344.o(.text); src/power_bomb_explosion.o(.text); - asm/disasm_0x0805745c.o(.text); + src/gadora_hatch.o(.text); src/in_game_timer.o(.text); src/display.o(.text); src/process_pause_press.o(.text); diff --git a/src/gadora_hatch.c b/src/gadora_hatch.c index 63d02df0..b8b5c447 100644 --- a/src/gadora_hatch.c +++ b/src/gadora_hatch.c @@ -4,16 +4,23 @@ #include "structs/connection.h" +/** + * @brief 5790c | ac | Activates/deactivates the hatch for a gadora + * + * @param xPosition X position + * @param yPosition Y position + * @param action Action (0 = Close, 1 = Open) + * @return u32 Iterator + */ u32 GadoraHatchUpdate(u16 xPosition, u16 yPosition, u8 action) { - // https://decomp.me/scratch/GcieN - i32 i; u32 exists; u8 found; i32 xOffset; i32 yOffset; + // Get should the hatch exists or not if (action) exists = TRUE; else @@ -25,24 +32,28 @@ u32 GadoraHatchUpdate(u16 xPosition, u16 yPosition, u8 action) for (i = 0; i < MAX_AMOUNT_OF_HATCHES; i++) { - if (!(gHatchData[i].opening)) - { - if (gHatchData[i].xPosition + xOffset >= xPosition / BLOCK_SIZE && gHatchData[i].xPosition - xOffset <= xPosition / BLOCK_SIZE && - gHatchData[i].yPosition + 3 >= yPosition / BLOCK_SIZE && gHatchData[i].yPosition - yOffset <= yPosition / BLOCK_SIZE) - found = TRUE; + if (gHatchData[i].opening) + continue; + + // Try find door at position + if (gHatchData[i].xPosition + xOffset >= xPosition / BLOCK_SIZE && gHatchData[i].xPosition - xOffset <= xPosition / BLOCK_SIZE && + gHatchData[i].yPosition + 3 >= yPosition / BLOCK_SIZE && gHatchData[i].yPosition - yOffset <= yPosition / BLOCK_SIZE) + found = TRUE; - if (found) - { - if (gHatchData[i].exists != exists) - gHatchData[i].exists = exists; - else; - break; - } + if (found) + { + // Apply exists status + if (gHatchData[i].exists != exists) + gHatchData[i].exists = exists; + else + found = FALSE; + break; } } - i++; - if (!found) + if (found) + i++; + else i = 0; return i; diff --git a/src/projectile.c b/src/projectile.c index 06a74207..17ca8002 100644 --- a/src/projectile.c +++ b/src/projectile.c @@ -985,10 +985,10 @@ void ProjectileSetTrail(struct ProjectileData* pProj, u8 effect, u8 delay) { // https://decomp.me/scratch/4n6pN - /*u16 xPosition; + u16 xPosition; u16 yPosition; u16 movement; - u8 status; + u16 tmp; if (gFrameCounter8Bit & delay) return; @@ -1009,18 +1009,16 @@ void ProjectileSetTrail(struct ProjectileData* pProj, u8 effect, u8 delay) break; case ACD_DIAGONALLY_UP: - status = PROJ_STATUS_XFLIP; yPosition += 0x18; - if (status & pProj->status) + if (pProj->status & PROJ_STATUS_XFLIP) xPosition -= 0x18; else xPosition += 0x18; break; case ACD_DIAGONALLY_DOWN: - status = PROJ_STATUS_XFLIP; yPosition -= 0x18; - if (status & pProj->status) + if (pProj->status & PROJ_STATUS_XFLIP) xPosition -= 0x18; else xPosition += 0x18; @@ -1034,7 +1032,7 @@ void ProjectileSetTrail(struct ProjectileData* pProj, u8 effect, u8 delay) break; } - ParticleSet(yPosition, xPosition, effect);*/ + ParticleSet(yPosition, xPosition, effect); } /** @@ -1048,27 +1046,28 @@ void ProjectileMoveTumbling(struct ProjectileData* pProj) i16 movement; u32 newPosition; - if ((pProj->status & PROJ_STATUS_ON_SCREEN) == 0x0) + if (!(pProj->status & PROJ_STATUS_ON_SCREEN)) + { pProj->status = 0x0; + return; + } + + timer = pProj->timer; + movement = sTumblingMissileSpeed[timer]; + if (movement == SHORT_MAX) + newPosition = sTumblingMissileSpeed[timer - 1] + pProj->yPosition; else { - timer = pProj->timer; - movement = sTumblingMissileSpeed[timer]; - if (movement == SHORT_MAX) - newPosition = sTumblingMissileSpeed[timer - 1] + pProj->yPosition; - else - { - pProj->timer = timer + 1; - newPosition = pProj->yPosition + movement; - } - pProj->yPosition = newPosition; - - if (pProj->status & PROJ_STATUS_XFLIP) - newPosition = pProj->xPosition + 0x4; - else - newPosition = pProj->xPosition - 0x4; - pProj->xPosition = newPosition; + pProj->timer = timer + 1; + newPosition = pProj->yPosition + movement; } + pProj->yPosition = newPosition; + + if (pProj->status & PROJ_STATUS_XFLIP) + newPosition = pProj->xPosition + 0x4; + else + newPosition = pProj->xPosition - 0x4; + pProj->xPosition = newPosition; } /**