decompile spark

This commit is contained in:
Behemoth 2020-09-20 03:20:51 +02:00
parent 00938e5caf
commit 4a01e1601b
6 changed files with 160 additions and 332 deletions

View File

@ -1,319 +0,0 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.syntax unified
.text
thumb_func_start Spark
Spark: @ 0x0802B2AC
push {r4, r5, lr}
adds r5, r0, #0
ldr r4, _0802B2C4 @ =gUnk_080CD234
bl GetNextFunction
lsls r0, r0, #2
adds r0, r0, r4
ldr r1, [r0]
adds r0, r5, #0
bl _call_via_r1
pop {r4, r5, pc}
.align 2, 0
_0802B2C4: .4byte gUnk_080CD234
thumb_func_start sub_0802B2C8
sub_0802B2C8: @ 0x0802B2C8
push {lr}
ldr r2, _0802B2DC @ =gUnk_080CD24C
ldrb r1, [r0, #0xc]
lsls r1, r1, #2
adds r1, r1, r2
ldr r1, [r1]
bl _call_via_r1
pop {pc}
.align 2, 0
_0802B2DC: .4byte gUnk_080CD24C
thumb_func_start sub_0802B2E0
sub_0802B2E0: @ 0x0802B2E0
push {r4, lr}
adds r4, r0, #0
adds r0, #0x41
ldrb r1, [r0]
movs r0, #0x80
ands r0, r1
cmp r0, #0
beq _0802B334
movs r2, #0x7f
adds r0, r2, #0
ands r0, r1
cmp r0, #0x14
bne _0802B334
ldrb r1, [r4, #0x10]
adds r0, r2, #0
ands r0, r1
movs r1, #0
strb r0, [r4, #0x10]
adds r0, r4, #0
adds r0, #0x3d
strb r1, [r0]
ldrb r1, [r4, #0x18]
movs r0, #4
rsbs r0, r0, #0
ands r0, r1
strb r0, [r4, #0x18]
movs r0, #2
strb r0, [r4, #0xc]
adds r0, r4, #0
movs r1, #2
movs r2, #0
bl CreateFx
adds r1, r0, #0
cmp r1, #0
beq _0802B334
str r1, [r4, #0x54]
movs r0, #0xe
strb r0, [r4, #0xe]
adds r0, r4, #0
bl CopyPosition
_0802B334:
pop {r4, pc}
.align 2, 0
thumb_func_start nullsub_15
nullsub_15: @ 0x0802B338
bx lr
.align 2, 0
thumb_func_start sub_0802B33C
sub_0802B33C: @ 0x0802B33C
push {r4, lr}
adds r4, r0, #0
bl sub_0804A720
movs r0, #1
strb r0, [r4, #0xc]
ldrb r0, [r4, #0xb]
strb r0, [r4, #0x15]
movs r0, #0x78
strb r0, [r4, #0xf]
adds r0, r4, #0
movs r1, #0
bl InitializeAnimation
pop {r4, pc}
.align 2, 0
thumb_func_start sub_0802B35C
sub_0802B35C: @ 0x0802B35C
push {r4, lr}
adds r4, r0, #0
bl GetNextFrame
adds r0, r4, #0
bl ProcessMovement
movs r3, #0
ldrb r0, [r4, #0xa]
cmp r0, #0
bne _0802B374
movs r3, #1
_0802B374:
ldrh r0, [r4, #0x2a]
adds r2, r0, #0
cmp r2, #0
bne _0802B3A4
ldrb r0, [r4, #0xf]
subs r0, #1
strb r0, [r4, #0xf]
lsls r0, r0, #0x18
cmp r0, #0
beq _0802B38A
b _0802B4A6
_0802B38A:
movs r0, #0x78
strb r0, [r4, #0xf]
ldrb r0, [r4, #0x15]
cmp r3, #0
beq _0802B39A
adds r1, r0, #0
adds r1, #8
b _0802B39E
_0802B39A:
adds r1, r0, #0
adds r1, #0x18
_0802B39E:
movs r0, #0x18
ands r0, r1
b _0802B4A4
_0802B3A4:
movs r0, #0x78
strb r0, [r4, #0xf]
ldrb r0, [r4, #0x15]
movs r1, #0x18
ands r1, r0
cmp r1, #8
beq _0802B474
cmp r1, #8
bgt _0802B3BC
cmp r1, #0
beq _0802B3C6
b _0802B4A6
_0802B3BC:
cmp r1, #0x10
beq _0802B404
cmp r1, #0x18
beq _0802B442
b _0802B4A6
_0802B3C6:
movs r0, #0xe
ands r0, r2
cmp r0, #0
beq _0802B3D8
movs r0, #8
cmp r3, #0
beq _0802B4A4
movs r0, #0x18
b _0802B4A4
_0802B3D8:
movs r0, #0xe0
lsls r0, r0, #8
ands r0, r2
movs r1, #0x80
lsls r1, r1, #7
cmp r0, r1
bne _0802B3EE
cmp r3, #0
beq _0802B3EE
movs r0, #8
strb r0, [r4, #0x15]
_0802B3EE:
movs r0, #0xe0
lsls r0, r0, #4
ands r0, r2
movs r1, #0x80
lsls r1, r1, #3
cmp r0, r1
bne _0802B4A6
cmp r3, #0
bne _0802B4A6
movs r0, #0x18
b _0802B4A4
_0802B404:
movs r0, #0xe0
ands r0, r2
cmp r0, #0
beq _0802B416
movs r0, #0x18
cmp r3, #0
beq _0802B4A4
movs r0, #8
b _0802B4A4
_0802B416:
movs r0, #0xe0
lsls r0, r0, #8
ands r0, r2
movs r1, #0x80
lsls r1, r1, #6
cmp r0, r1
bne _0802B42C
cmp r3, #0
bne _0802B42C
movs r0, #8
strb r0, [r4, #0x15]
_0802B42C:
movs r0, #0xe0
lsls r0, r0, #4
ands r0, r2
movs r1, #0x80
lsls r1, r1, #2
cmp r0, r1
bne _0802B4A6
cmp r3, #0
beq _0802B4A6
movs r0, #0x18
b _0802B4A4
_0802B442:
movs r1, #0xe0
lsls r1, r1, #4
ands r1, r2
cmp r1, #0
beq _0802B458
rsbs r0, r3, #0
orrs r0, r3
asrs r0, r0, #0x1f
movs r1, #0x10
ands r0, r1
b _0802B4A4
_0802B458:
movs r0, #0xe
ands r0, r2
cmp r0, #4
bne _0802B466
cmp r3, #0
beq _0802B466
strb r1, [r4, #0x15]
_0802B466:
movs r0, #0xe0
ands r0, r2
cmp r0, #0x40
bne _0802B4A6
cmp r3, #0
bne _0802B4A6
b _0802B4A2
_0802B474:
movs r0, #0xe0
lsls r0, r0, #8
ands r0, r2
cmp r0, #0
beq _0802B488
movs r0, #0
cmp r3, #0
bne _0802B4A4
movs r0, #0x10
b _0802B4A4
_0802B488:
movs r0, #0xe
ands r0, r2
cmp r0, #2
bne _0802B496
cmp r3, #0
bne _0802B496
strb r3, [r4, #0x15]
_0802B496:
movs r0, #0xe0
ands r0, r2
cmp r0, #0x20
bne _0802B4A6
cmp r3, #0
beq _0802B4A6
_0802B4A2:
movs r0, #0x10
_0802B4A4:
strb r0, [r4, #0x15]
_0802B4A6:
pop {r4, pc}
thumb_func_start sub_0802B4A8
sub_0802B4A8: @ 0x0802B4A8
push {r4, lr}
adds r4, r0, #0
ldrb r0, [r4, #0xe]
subs r0, #1
strb r0, [r4, #0xe]
lsls r0, r0, #0x18
cmp r0, #0
bne _0802B4D6
adds r0, r4, #0
movs r1, #0
movs r2, #0x60
movs r3, #0
bl CreateObjectWithParent
adds r1, r0, #0
cmp r1, #0
beq _0802B4D0
ldrh r0, [r1, #0x32]
subs r0, #4
strh r0, [r1, #0x32]
_0802B4D0:
adds r0, r4, #0
bl DeleteEntity
_0802B4D6:
pop {r4, pc}

10
data/animations/spark.s Normal file
View File

@ -0,0 +1,10 @@
.include "asm/macros.inc"
.include "constants/constants.inc"
.section .rodata
gUnk_080CD258:: @ 080CD258
.incbin "baserom.gba", 0x0CD258, 0x000001C
gUnk_080CD274:: @ 080CD274
.incbin "baserom.gba", 0x0CD274, 0x0000008

View File

@ -3,18 +3,6 @@
.section .rodata .section .rodata
gUnk_080CD234:: @ 080CD234
.incbin "baserom.gba", 0x0CD234, 0x0000018
gUnk_080CD24C:: @ 080CD24C
.incbin "baserom.gba", 0x0CD24C, 0x000000C
gUnk_080CD258:: @ 080CD258
.incbin "baserom.gba", 0x0CD258, 0x000001C
gUnk_080CD274:: @ 080CD274
.incbin "baserom.gba", 0x0CD274, 0x0000008
gUnk_080CD27C:: @ 080CD27C gUnk_080CD27C:: @ 080CD27C
.incbin "baserom.gba", 0x0CD27C, 0x000001C .incbin "baserom.gba", 0x0CD27C, 0x000001C

View File

@ -169,6 +169,13 @@ extern void CopyPosition(Entity*, Entity*);
extern void DeleteEntity(Entity*); extern void DeleteEntity(Entity*);
extern void PositionRelative(Entity*, Entity*, s32, s32); extern void PositionRelative(Entity*, Entity*, s32, s32);
enum {
DirectionNorth = 0x00,
DirectionEast = 0x08,
DirectionSouth = 0x10,
DirectionWest = 0x18,
};
#define DirectionRound(expr) ((expr) & 0x18) #define DirectionRound(expr) ((expr) & 0x18)
#define DirectionRoundUp(expr) DirectionRound((expr) + 4) #define DirectionRoundUp(expr) DirectionRound((expr) + 4)
#define DirectionIsHorizontal(expr) ((expr) & 0x08) #define DirectionIsHorizontal(expr) ((expr) & 0x08)

View File

@ -353,7 +353,7 @@ SECTIONS {
src/enemy/waterDrop.o(.text); src/enemy/waterDrop.o(.text);
src/enemy/wallMaster.o(.text); src/enemy/wallMaster.o(.text);
src/enemy/bombPeahat.o(.text); src/enemy/bombPeahat.o(.text);
asm/spark.o(.text); src/enemy/spark.o(.text);
asm/chaser.o(.text); asm/chaser.o(.text);
asm/spikedBeetle.o(.text); asm/spikedBeetle.o(.text);
asm/sensorBladeTrap.o(.text); asm/sensorBladeTrap.o(.text);
@ -958,6 +958,8 @@ SECTIONS {
data/animations/wallMaster.o(.rodata); data/animations/wallMaster.o(.rodata);
src/enemy/bombPeahat.o(.rodata); src/enemy/bombPeahat.o(.rodata);
data/animations/bombPeahat.o(.rodata); data/animations/bombPeahat.o(.rodata);
src/enemy/spark.o(.rodata);
data/animations/spark.o(.rodata);
data/data_080CC6FC.o(.rodata); data/data_080CC6FC.o(.rodata);
src/enemy.o(.rodata); src/enemy.o(.rodata);
data/data_080D3D94.o(.rodata); data/data_080D3D94.o(.rodata);

140
src/enemy/spark.c Normal file
View File

@ -0,0 +1,140 @@
#include "enemy.h"
#include "entity.h"
#include "functions.h"
extern void (*const gUnk_080CD234[])(Entity*);
extern void (*const gUnk_080CD24C[])(Entity*);
void Spark(Entity* this) {
gUnk_080CD234[GetNextFunction(this)](this);
}
void sub_0802B2C8(Entity* this) {
gUnk_080CD24C[this->action](this);
}
void sub_0802B2E0(Entity* this) {
Entity* ent;
if (this->bitfield & 0x80) {
if ((this->bitfield & 0x7f) == 0x14) {
this->flags &= ~0x80;
this->hurtBlinkTime = 0;
this->spriteSettings.b.draw = 0;
this->action = 2;
ent = CreateFx(this, 2, 0);
if (ent) {
this->attachedEntity = ent;
this->actionDelay = 14;
CopyPosition(this, ent);
}
}
}
}
void nullsub_15(Entity* this) {
/* ... */
}
void sub_0802B33C(Entity* this) {
sub_0804A720(this);
this->action = 1;
this->direction = (this->entityType).parameter;
this->field_0xf = 0x78;
InitializeAnimation(this, 0);
}
void sub_0802B35C(Entity* this) {
bool32 is_head;
GetNextFrame(this);
ProcessMovement(this);
is_head = this->entityType.form == 0;
if (this->collisions == 0) {
if (--this->field_0xf == 0) {
this->field_0xf = 0x78;
this->direction += is_head ? 0x08 : 0x18;
this->direction = DirectionRound(this->direction);
}
} else {
this->field_0xf = 0x78;
switch (DirectionRound(this->direction)) {
case DirectionNorth:
if (this->collisions & 0xe) {
this->direction = is_head ? DirectionWest : DirectionEast;
} else {
if ((this->collisions & 0xe000) == 0x4000 && is_head) {
this->direction = DirectionEast;
}
if ((this->collisions & 0xe00) == 0x400 && !is_head) {
this->direction = DirectionWest;
}
}
break;
case DirectionSouth:
if (this->collisions & 0xe0) {
this->direction = is_head ? DirectionEast : DirectionWest;
} else {
if ((this->collisions & 0xe000) == 0x2000 && !is_head) {
this->direction = DirectionEast;
}
if ((this->collisions & 0xe00) == 0x200 && is_head) {
this->direction = DirectionWest;
}
}
break;
case DirectionWest:
if (this->collisions & 0xe00) {
this->direction = is_head ? DirectionSouth : DirectionNorth;
} else {
if ((this->collisions & 0xe) == 4 && is_head) {
this->direction = DirectionNorth;
}
if ((this->collisions & 0xe0) == 0x40 && !is_head) {
this->direction = DirectionSouth;
}
}
break;
case DirectionEast:
if (this->collisions & 0xe000) {
this->direction = is_head ? DirectionNorth : DirectionSouth;
} else {
if ((this->collisions & 0xe) == 2 && !is_head) {
this->direction = DirectionNorth;
}
if ((this->collisions & 0xe0) == 0x20 && is_head) {
this->direction = DirectionSouth;
}
}
break;
}
}
}
void sub_0802B4A8(Entity* this) {
if (--this->actionDelay == 0) {
Entity* ent = CreateObjectWithParent(this, 0, 0x60, 0);
if (ent) {
ent->y.HALF.HI -= 4;
}
DeleteEntity(this);
}
}
// clang-format off
void (*const gUnk_080CD234[])(Entity*) = {
sub_0802B2C8,
sub_0802B2E0,
sub_08001324,
sub_0804A7D4,
sub_08001242,
nullsub_15,
};
void (*const gUnk_080CD24C[])(Entity*) = {
sub_0802B33C,
sub_0802B35C,
sub_0802B4A8,
};
// clang-format on