Decompile MinecartDoor

This commit is contained in:
octorock 2022-02-22 17:53:06 +01:00
parent ab853d9f44
commit f252083539
5 changed files with 197 additions and 467 deletions

View File

@ -1,452 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start MinecartDoor
MinecartDoor: @ 0x08096AD4
push {lr}
ldr r2, _08096AE8 @ =gUnk_0812323C
ldrb r1, [r0, #0xc]
lsls r1, r1, #2
adds r1, r1, r2
ldr r1, [r1]
bl _call_via_r1
pop {pc}
.align 2, 0
_08096AE8: .4byte gUnk_0812323C
thumb_func_start sub_08096AEC
sub_08096AEC: @ 0x08096AEC
push {r4, r5, r6, lr}
adds r4, r0, #0
bl sub_080837B0
cmp r0, #0
beq _08096BB6
ldrb r1, [r4, #0xa]
movs r0, #4
ands r0, r1
cmp r0, #0
beq _08096B12
adds r1, r4, #0
adds r1, #0x7e
movs r0, #1
strb r0, [r1]
ldrb r1, [r4, #0xa]
movs r0, #3
ands r0, r1
strb r0, [r4, #0xa]
_08096B12:
movs r0, #0xc0
lsls r0, r0, #2
strh r0, [r4, #0x24]
ldrh r1, [r4, #0x2e]
adds r0, r4, #0
adds r0, #0x70
strh r1, [r0]
ldrh r0, [r4, #0x32]
adds r1, r4, #0
adds r1, #0x72
strh r0, [r1]
adds r2, r4, #0
adds r2, #0x29
ldrb r1, [r2]
movs r0, #8
rsbs r0, r0, #0
ands r0, r1
movs r1, #5
orrs r0, r1
strb r0, [r2]
movs r0, #0x2e
ldrsh r1, [r4, r0]
ldr r2, _08096B90 @ =gRoomControls
ldrh r0, [r2, #6]
subs r1, r1, r0
asrs r1, r1, #4
movs r3, #0x3f
ands r1, r3
movs r5, #0x32
ldrsh r0, [r4, r5]
ldrh r2, [r2, #8]
subs r0, r0, r2
asrs r0, r0, #4
ands r0, r3
lsls r0, r0, #6
orrs r1, r0
adds r5, r4, #0
adds r5, #0x76
strh r1, [r5]
ldrh r0, [r5]
adds r6, r4, #0
adds r6, #0x38
ldrb r1, [r6]
bl GetTileIndex
adds r1, r4, #0
adds r1, #0x74
strh r0, [r1]
ldrb r0, [r4, #0xa]
strb r0, [r4, #0x1e]
adds r0, r4, #0
bl sub_08096CEC
cmp r0, #0
beq _08096B9C
adds r0, r4, #0
adds r0, #0x7e
ldrb r0, [r0]
cmp r0, #0
beq _08096B94
bl DeleteThisEntity
b _08096BB6
.align 2, 0
_08096B90: .4byte gRoomControls
_08096B94:
adds r0, r4, #0
bl sub_08096E04
b _08096BB6
_08096B9C:
movs r2, #1
movs r0, #1
strb r0, [r4, #0xc]
ldrb r1, [r4, #0x18]
subs r0, #5
ands r0, r1
orrs r0, r2
strb r0, [r4, #0x18]
ldr r0, _08096BB8 @ =0x00004022
ldrh r1, [r5]
ldrb r2, [r6]
bl SetTile
_08096BB6:
pop {r4, r5, r6, pc}
.align 2, 0
_08096BB8: .4byte 0x00004022
thumb_func_start sub_08096BBC
sub_08096BBC: @ 0x08096BBC
push {r4, lr}
adds r4, r0, #0
bl sub_08096CEC
cmp r0, #0
beq _08096BF2
movs r0, #2
strb r0, [r4, #0xc]
movs r0, #7
strb r0, [r4, #0xe]
ldrb r0, [r4, #0xa]
lsls r0, r0, #3
strb r0, [r4, #0x15]
adds r0, r4, #0
adds r0, #0x74
ldrh r0, [r0]
adds r1, r4, #0
adds r1, #0x76
ldrh r1, [r1]
adds r2, r4, #0
adds r2, #0x38
ldrb r2, [r2]
bl SetTile
ldr r0, _08096BF4 @ =0x0000010B
bl EnqueueSFX
_08096BF2:
pop {r4, pc}
.align 2, 0
_08096BF4: .4byte 0x0000010B
thumb_func_start sub_08096BF8
sub_08096BF8: @ 0x08096BF8
push {r4, lr}
adds r4, r0, #0
bl LinearMoveUpdate
ldrb r0, [r4, #0xe]
subs r0, #1
strb r0, [r4, #0xe]
lsls r0, r0, #0x18
cmp r0, #0
bne _08096C3A
adds r0, r4, #0
bl sub_08096E04
ldrb r1, [r4, #0x18]
movs r0, #4
rsbs r0, r0, #0
ands r0, r1
strb r0, [r4, #0x18]
adds r0, r4, #0
adds r0, #0x70
ldrh r0, [r0]
strh r0, [r4, #0x2e]
adds r0, r4, #0
adds r0, #0x72
ldrh r0, [r0]
strh r0, [r4, #0x32]
adds r0, r4, #0
adds r0, #0x7e
ldrb r0, [r0]
cmp r0, #0
beq _08096C3A
bl DeleteThisEntity
_08096C3A:
pop {r4, pc}
thumb_func_start sub_08096C3C
sub_08096C3C: @ 0x08096C3C
push {r4, lr}
adds r4, r0, #0
adds r0, #0x7e
ldrb r0, [r0]
cmp r0, #0
beq _08096C56
adds r0, r4, #0
adds r0, #0x86
ldrh r0, [r0]
bl CheckFlags
cmp r0, #0
bne _08096CAE
_08096C56:
ldr r0, _08096C80 @ =gPlayerState
ldr r0, [r0, #0x30]
movs r1, #0x80
lsls r1, r1, #5
ands r0, r1
cmp r0, #0
beq _08096C92
ldrb r2, [r4, #0xa]
lsls r1, r2, #1
ldr r0, _08096C84 @ =gPlayerEntity
ldrb r0, [r0, #0x14]
cmp r1, r0
bne _08096C88
adds r0, r4, #0
adds r1, r2, #0
bl sub_08083734
cmp r0, #0
beq _08096CAE
b _08096C9C
.align 2, 0
_08096C80: .4byte gPlayerState
_08096C84: .4byte gPlayerEntity
_08096C88:
ldrb r0, [r4, #0xe]
subs r0, #1
strb r0, [r4, #0xe]
lsls r0, r0, #0x18
b _08096C98
_08096C92:
adds r0, r4, #0
bl sub_08096D84
_08096C98:
cmp r0, #0
bne _08096CAE
_08096C9C:
movs r0, #4
strb r0, [r4, #0xc]
ldrb r1, [r4, #0xa]
adds r0, r4, #0
adds r0, #0x76
ldrh r2, [r0]
adds r0, r4, #0
bl sub_080836DC
_08096CAE:
pop {r4, pc}
thumb_func_start sub_08096CB0
sub_08096CB0: @ 0x08096CB0
push {r4, lr}
adds r4, r0, #0
bl LinearMoveUpdate
ldrb r0, [r4, #0xe]
subs r0, #1
strb r0, [r4, #0xe]
lsls r0, r0, #0x18
cmp r0, #0
bne _08096CE6
movs r0, #1
strb r0, [r4, #0xc]
adds r0, r4, #0
adds r0, #0x70
ldrh r0, [r0]
strh r0, [r4, #0x2e]
adds r0, r4, #0
adds r0, #0x72
ldrh r0, [r0]
strh r0, [r4, #0x32]
ldrb r1, [r4, #0xa]
adds r0, r4, #0
bl sub_08083814
ldr r0, _08096CE8 @ =0x0000010B
bl EnqueueSFX
_08096CE6:
pop {r4, pc}
.align 2, 0
_08096CE8: .4byte 0x0000010B
thumb_func_start sub_08096CEC
sub_08096CEC: @ 0x08096CEC
push {r4, r5, lr}
adds r4, r0, #0
adds r0, #0x7e
ldrb r0, [r0]
cmp r0, #0
beq _08096D06
adds r0, r4, #0
adds r0, #0x86
ldrh r0, [r0]
bl CheckFlags
cmp r0, #0
bne _08096D60
_08096D06:
ldr r0, _08096D40 @ =gPlayerState
ldr r0, [r0, #0x30]
movs r1, #0x80
lsls r1, r1, #5
ands r0, r1
cmp r0, #0
beq _08096D64
ldr r3, _08096D44 @ =gPlayerEntity
ldrb r2, [r4, #0xa]
lsls r0, r2, #1
ldrb r1, [r3, #0x14]
eors r0, r1
movs r1, #2
ands r0, r1
cmp r0, #0
bne _08096D64
movs r0, #1
ands r2, r0
cmp r2, #0
beq _08096D48
movs r1, #0x32
ldrsh r0, [r3, r1]
movs r2, #0x32
ldrsh r1, [r4, r2]
movs r5, #0x2e
ldrsh r2, [r3, r5]
movs r5, #0x2e
ldrsh r3, [r4, r5]
b _08096D58
.align 2, 0
_08096D40: .4byte gPlayerState
_08096D44: .4byte gPlayerEntity
_08096D48:
movs r1, #0x2e
ldrsh r0, [r3, r1]
movs r2, #0x2e
ldrsh r1, [r4, r2]
movs r5, #0x32
ldrsh r2, [r3, r5]
movs r5, #0x32
ldrsh r3, [r4, r5]
_08096D58:
bl sub_08096D68
cmp r0, #0
beq _08096D64
_08096D60:
movs r0, #1
b _08096D66
_08096D64:
movs r0, #0
_08096D66:
pop {r4, r5, pc}
thumb_func_start sub_08096D68
sub_08096D68: @ 0x08096D68
push {lr}
subs r0, r0, r1
adds r0, #8
cmp r0, #0x10
bhi _08096D7E
subs r0, r2, r3
adds r0, #0x30
cmp r0, #0x60
bhi _08096D7E
movs r0, #1
b _08096D80
_08096D7E:
movs r0, #0
_08096D80:
pop {pc}
.align 2, 0
thumb_func_start sub_08096D84
sub_08096D84: @ 0x08096D84
push {lr}
adds r1, r0, #0
ldrb r0, [r1, #0xa]
cmp r0, #1
beq _08096DB4
cmp r0, #1
bgt _08096D98
cmp r0, #0
beq _08096DA2
b _08096E00
_08096D98:
cmp r0, #2
beq _08096DC8
cmp r0, #3
beq _08096DE4
b _08096E00
_08096DA2:
movs r0, #0x32
ldrsh r1, [r1, r0]
ldr r0, _08096DB0 @ =gPlayerEntity
movs r2, #0x32
ldrsh r0, [r0, r2]
b _08096DEE
.align 2, 0
_08096DB0: .4byte gPlayerEntity
_08096DB4:
ldr r0, _08096DC4 @ =gPlayerEntity
movs r2, #0x2e
ldrsh r0, [r0, r2]
adds r0, #0xa
movs r2, #0x2e
ldrsh r1, [r1, r2]
b _08096DD4
.align 2, 0
_08096DC4: .4byte gPlayerEntity
_08096DC8:
ldr r0, _08096DE0 @ =gPlayerEntity
movs r2, #0x32
ldrsh r0, [r0, r2]
adds r0, #0xa
movs r2, #0x32
ldrsh r1, [r1, r2]
_08096DD4:
subs r0, r0, r1
cmp r0, #0x64
bhi _08096E00
movs r0, #1
b _08096E02
.align 2, 0
_08096DE0: .4byte gPlayerEntity
_08096DE4:
movs r0, #0x2e
ldrsh r1, [r1, r0]
ldr r0, _08096DFC @ =gPlayerEntity
movs r2, #0x2e
ldrsh r0, [r0, r2]
_08096DEE:
subs r0, #0xa
subs r1, r1, r0
cmp r1, #0x64
bhi _08096E00
movs r0, #1
b _08096E02
.align 2, 0
_08096DFC: .4byte gPlayerEntity
_08096E00:
movs r0, #0
_08096E02:
pop {pc}
thumb_func_start sub_08096E04
sub_08096E04: @ 0x08096E04
movs r1, #3
strb r1, [r0, #0xc]
movs r1, #8
strb r1, [r0, #0xe]
bx lr
.align 2, 0

View File

@ -1,12 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.section .rodata
.align 2
gUnk_0812323C:: @ 0812323C
.4byte sub_08096AEC
.4byte sub_08096BBC
.4byte sub_08096BF8
.4byte sub_08096C3C
.4byte sub_08096CB0

View File

@ -334,7 +334,7 @@ void Object68(Entity*);
void Object69(Entity*);
void Object6A(Entity*);
void CrenelBeanSprout();
void MinecartDoor(Entity*);
void MinecartDoor();
void ObjectOnPillar();
void MineralWaterSource(Entity*);
void MinishSizedArchway(Entity*);

View File

@ -754,7 +754,7 @@ SECTIONS {
asm/object/object69.o(.text);
src/object/object6A.o(.text);
src/object/crenelBeanSprout.o(.text);
asm/object/minecartDoor.o(.text);
src/object/minecartDoor.o(.text);
src/object/objectOnPillar.o(.text);
src/object/mineralWaterSource.o(.text);
src/object/minishSizedArchway.o(.text);
@ -1500,7 +1500,7 @@ SECTIONS {
data/animations/object/object6A.o(.rodata);
src/object/crenelBeanSprout.o(.rodata);
data/animations/object/crenelBeanSprout.o(.rodata);
data/const/object/minecartDoor.o(.rodata);
src/object/minecartDoor.o(.rodata);
src/object/objectOnPillar.o(.rodata);
data/const/object/mineralWaterSource.o(.rodata);
data/const/object/object70.o(.rodata);

194
src/object/minecartDoor.c Normal file
View File

@ -0,0 +1,194 @@
/**
* @file minecartDoor.c
* @ingroup Objects
*
* @brief Minecart Door object
*/
#define NENT_DEPRECATED
#include "global.h"
#include "object.h"
#include "functions.h"
typedef struct {
/*0x00*/ Entity base;
/*0x68*/ u8 unk_68[8];
/*0x70*/ u16 unk_70;
/*0x72*/ u16 unk_72;
/*0x74*/ u16 unk_74;
/*0x76*/ u16 unk_76;
/*0x78*/ u8 unk_78[0x6];
/*0x7e*/ u8 unk_7e;
/*0x7f*/ u8 unk_7f[0x7];
/*0x86*/ u16 unk_86;
} MinecartDoorEntity;
extern bool32 sub_080837B0(Entity*); // lockedDoor
extern void sub_080836DC(Entity*, u32, u32); // lockedDoor
extern void sub_08083814(Entity*, u32); // lockedDoor
bool32 sub_08096CEC(MinecartDoorEntity*);
void sub_08096E04(MinecartDoorEntity*);
bool32 sub_08096D84(MinecartDoorEntity*);
bool32 sub_08096D68(s32, s32, s32, s32);
void MinecartDoor_Init(MinecartDoorEntity*);
void MinecartDoor_Action1(MinecartDoorEntity*);
void MinecartDoor_Action2(MinecartDoorEntity*);
void MinecartDoor_Action3(MinecartDoorEntity*);
void MinecartDoor_Action4(MinecartDoorEntity*);
void MinecartDoor(MinecartDoorEntity* this) {
static void (*const MinecartDoor_Actions[])(MinecartDoorEntity*) = { MinecartDoor_Init, MinecartDoor_Action1,
MinecartDoor_Action2, MinecartDoor_Action3,
MinecartDoor_Action4 };
MinecartDoor_Actions[super->action](this);
}
void MinecartDoor_Init(MinecartDoorEntity* this) {
if (sub_080837B0(super)) {
if ((super->type & 4) != 0) {
this->unk_7e = 1;
super->type &= 3;
}
super->speed = 0x300;
this->unk_70 = super->x.HALF.HI;
this->unk_72 = super->y.HALF.HI;
super->spritePriority.b0 = 5;
this->unk_76 = COORD_TO_TILE(super);
this->unk_74 = GetTileIndex(this->unk_76, super->collisionLayer);
super->frameIndex = super->type;
if (sub_08096CEC(this)) {
if (this->unk_7e != 0) {
DeleteThisEntity();
} else {
sub_08096E04(this);
}
} else {
super->action = 1;
super->spriteSettings.draw = 1;
SetTile(0x4022, this->unk_76, super->collisionLayer);
}
}
}
void MinecartDoor_Action1(MinecartDoorEntity* this) {
if (sub_08096CEC(this)) {
super->action = 2;
super->actionDelay = 7;
super->direction = super->type << 3;
SetTile(this->unk_74, this->unk_76, super->collisionLayer);
EnqueueSFX(SFX_10B);
}
}
void MinecartDoor_Action2(MinecartDoorEntity* this) {
LinearMoveUpdate(super);
if (--super->actionDelay == 0) {
sub_08096E04(this);
super->spriteSettings.draw = 0;
super->x.HALF.HI = this->unk_70;
super->y.HALF.HI = this->unk_72;
if (this->unk_7e != 0) {
DeleteThisEntity();
}
}
}
void MinecartDoor_Action3(MinecartDoorEntity* this) {
bool32 bVar3;
if ((this->unk_7e != 0) && (CheckFlags(this->unk_86))) {
return;
}
if ((gPlayerState.flags & PL_IN_MINECART) != 0) {
if (super->type * 2 - (u32)gPlayerEntity.animationState == 0) {
if (sub_08083734(super, super->type) == 0) {
return;
}
goto label;
} else {
bVar3 = --super->actionDelay * 0x1000000;
}
} else {
bVar3 = sub_08096D84(this);
}
if (bVar3 == FALSE) {
label:
super->action = 4;
sub_080836DC(super, super->type, this->unk_76);
}
}
void MinecartDoor_Action4(MinecartDoorEntity* this) {
LinearMoveUpdate(super);
if (--super->actionDelay == 0) {
super->action = 1;
super->x.HALF.HI = this->unk_70;
super->y.HALF.HI = this->unk_72;
sub_08083814(super, super->type);
EnqueueSFX(SFX_10B);
}
}
bool32 sub_08096CEC(MinecartDoorEntity* this) {
if (this->unk_7e != 0 && CheckFlags(this->unk_86)) {
return TRUE;
} else {
if ((gPlayerState.flags & PL_IN_MINECART) != 0) {
Entity* player = &gPlayerEntity;
if ((((super->type << 1) ^ player->animationState) & 2) == 0) {
if ((super->type & 1) != 0) {
if (sub_08096D68(gPlayerEntity.y.HALF.HI, super->y.HALF.HI, gPlayerEntity.x.HALF.HI,
super->x.HALF.HI)) {
return TRUE;
}
} else {
if (sub_08096D68(gPlayerEntity.x.HALF.HI, super->x.HALF.HI, gPlayerEntity.y.HALF.HI,
super->y.HALF.HI)) {
return TRUE;
}
}
}
}
}
return FALSE;
}
bool32 sub_08096D68(s32 param_1, s32 param_2, s32 param_3, s32 param_4) {
if (((param_1 - param_2) + 8U < 0x11) && ((param_3 - param_4) + 0x30U < 0x61)) {
return TRUE;
} else {
return FALSE;
}
}
bool32 sub_08096D84(MinecartDoorEntity* this) {
switch (super->type) {
case 0:
if (((super->y.HALF.HI + 10) - (gPlayerEntity.y.HALF.HI)) < 0x65U) {
return TRUE;
}
break;
case 1:
if (((gPlayerEntity.x.HALF.HI) - (super->x.HALF.HI - 10)) < 0x65U) {
return TRUE;
}
break;
case 2:
if (((gPlayerEntity.y.HALF.HI) - (super->y.HALF.HI - 10)) < 0x65U) {
return TRUE;
}
break;
case 3:
if (((super->x.HALF.HI + 10) - (gPlayerEntity.x.HALF.HI)) < 0x65U) {
return TRUE;
}
break;
}
return FALSE;
}
void sub_08096E04(MinecartDoorEntity* this) {
super->action = 3;
super->actionDelay = 8;
}