summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoroctorock <79596758+octorock@users.noreply.github.com>2022-08-19 23:02:55 +0200
committeroctorock <79596758+octorock@users.noreply.github.com>2022-08-19 23:02:55 +0200
commitb2264f562f205ca928889342cff4910ee45ef15b (patch)
treec87d46245380c103110c220d032f51bc6108e172 /src
parent373ab92156ddc4f11c9898ff48d497b4f3a49a23 (diff)
Decompile some functions
Diffstat (limited to 'src')
-rw-r--r--src/code_0805EC04.c84
-rw-r--r--src/demo.c50
-rw-r--r--src/object/pullableMushroom.c51
-rw-r--r--src/physics.c3
-rw-r--r--src/playerUtils.c140
-rw-r--r--src/staffroll.c8
6 files changed, 246 insertions, 90 deletions
diff --git a/src/code_0805EC04.c b/src/code_0805EC04.c
index 7892299d..28301be4 100644
--- a/src/code_0805EC04.c
+++ b/src/code_0805EC04.c
@@ -1,8 +1,11 @@
+#include "common.h"
#include "entity.h"
#include "player.h"
-#include "structures.h"
#include "room.h"
-#include "common.h"
+#include "structures.h"
+
+extern const u8 gUnk_08109202[];
+u32 ConvInputToState(u32 keys);
bool32 sub_0805EC04(Entity* this) {
u32 i = 1;
@@ -64,7 +67,82 @@ void InitPlayerMacro(PlayerMacroEntry* playerMacro) {
gPlayerState.playerInput.playerMacroHeldKeys = 0;
}
-ASM_FUNC("asm/non_matching/code_0805EC04/UpdatePlayerInput.inc", void UpdatePlayerInput())
+void UpdatePlayerInput(void) {
+ u32 flags;
+ u32 state;
+ u32 keys;
+ u32 prevState;
+ PlayerInput* playerInput;
+ PlayerMacroEntry* playerMacro;
+ u32 zero;
+
+ if (gPlayerState.playerInput.playerMacro != NULL) {
+ // Player is controlled by macro.
+ playerInput = &gPlayerState.playerInput;
+ playerMacro = playerInput->playerMacro;
+ if (playerInput->playerMacroWaiting == 0) { // Execute next macro entry.
+ zero = 0;
+ goto code_2;
+ code_0:
+ if (flags != 2) {
+ playerInput->playerMacroWaiting = playerMacro->flags;
+ playerInput->playerMacroHeldKeys = playerMacro->keys;
+ }
+ playerMacro++;
+ playerInput->playerMacro = playerMacro;
+ goto code_4;
+ code_2:
+ do {
+ flags = playerMacro->flags >> 0xe;
+ if (flags != 1) {
+ break;
+ }
+ (u8*)playerMacro += ((s16)playerMacro->keys);
+ } while (TRUE);
+
+ if (flags == 3) {
+ playerInput->playerMacroWaiting = zero;
+ playerInput->playerMacroHeldKeys = zero;
+ playerMacro = NULL;
+ playerInput->playerMacro = playerMacro;
+ } else {
+ goto code_0;
+ }
+ }
+ code_4:
+ playerInput->playerMacroWaiting--;
+ keys = playerInput->playerMacroHeldKeys;
+ } else {
+ // Player has control.
+ switch (gPlayerState.controlMode) {
+ case CONTROL_DISABLED:
+ case CONTROL_1:
+ case CONTROL_2:
+ case CONTROL_ENABLED:
+ keys = 0;
+ break;
+ }
+ switch (gPlayerState.controlMode) {
+ case CONTROL_DISABLED:
+ case CONTROL_2:
+ keys = 0;
+ break;
+ case CONTROL_1:
+ gPlayerState.controlMode = CONTROL_ENABLED;
+ gPlayerState.playerInput.heldInput = ConvInputToState(gInput.heldKeys);
+ // fallthrough
+ case CONTROL_ENABLED:
+ keys = gInput.heldKeys;
+ break;
+ }
+ }
+ state = ConvInputToState(keys);
+ prevState = ~gPlayerState.playerInput.heldInput;
+ gPlayerState.playerInput.heldInput = state;
+ gPlayerState.playerInput.newInput = state & prevState;
+ // Calculate the direction from the currently held input.
+ gPlayerState.direction = gUnk_08109202[(state & PLAYER_INPUT_ANY_DIRECTION) >> 8];
+}
u32 ConvInputToState(u32 keys) {
u32 result;
diff --git a/src/demo.c b/src/demo.c
index fd8f2aaa..2c481990 100644
--- a/src/demo.c
+++ b/src/demo.c
@@ -5,14 +5,16 @@
* @brief Demo task
*/
-#include "global.h"
+#include "common.h"
+#include "fileselect.h"
#include "functions.h"
+#include "game.h"
+#include "global.h"
#include "main.h"
-#include "common.h"
+#include "menu.h"
#include "message.h"
-#include "fileselect.h"
#include "screen.h"
-#include "game.h"
+#include "menu.h"
void sub_080A30AC(void);
void sub_080A2E40(void);
@@ -154,54 +156,42 @@ void sub_080A2FD0(void) {
}
}
-NONMATCH("asm/non_matching/demoScreen/sub_080A30AC.inc", void sub_080A30AC(void)) {
- u32 unk_0x10;
+void sub_080A30AC(void) {
+ s32 unk_0x10;
u8* ptr;
u8* currentPtr;
u32 offset;
- u32 xoffset;
gOamCmd._4 = 0x2000;
gOamCmd._6 = 0;
gOamCmd._8 = 0xc00;
gOamCmd.y = 0x40;
- unk_0x10 = gChooseFileState.unk_0x10;
- gOamCmd.x = 0xFFFFFED8 - unk_0x10;
+ unk_0x10 = (s16)gGenericMenu.unk10.h[0];
+ gOamCmd.x = -0x128 - unk_0x10;
offset = *(u32*)gUnk_08A068BF;
ptr = gUnk_08A068BF - 0xc;
sub_080ADA04(&gOamCmd, ptr + offset);
- // FIX: original assembly uses r1 for xoffset for no apparent reason. Could not make it compile to do the same.
- // Maybe the original code was some sort of loop unrolling.
- xoffset = -0xc0;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = -0xc0 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(ptr + 4));
- xoffset = -0x58;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = -0x58 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(ptr + 8));
- xoffset = 0x10;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = 0x10 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(gUnk_08A068BF));
- xoffset = 0x78;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = 0x78 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(ptr + 4));
- xoffset = 0xe0;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = 0xe0 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(ptr + 8));
- xoffset = 0xa4 << 1;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = 0x148 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(gUnk_08A068BF));
- xoffset = 0xd8 << 1;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = 0x1b0 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(ptr + 4));
- xoffset = 0x86 << 2;
- gOamCmd.x = xoffset - unk_0x10;
+ gOamCmd.x = 0x218 - unk_0x10;
sub_080ADA04(&gOamCmd, ptr + *(u32*)(ptr + 8));
}
-END_NONMATCH
void sub_080A3198(u32 param_1, u32 param_2) {
static const Font gUnk_08127C98[] = {
- { gUnk_0203508E, (void*)0x0600d000, (void*)0x02000d00, 0, 0x1080, 0xd0, 1, 0, 0, 1, 9, 0, 0, 1, 1 },
- { gUnk_0203510E, (void*)0x0600d000, (void*)0x02000d00, 0, 0x80, 0xd0, 1, 0, 0, 1, 9, 0, 0, 1, 1 },
+ { gUnk_0203508E, BG_TILE_ADDR(0x1a0), gTextGfxBuffer, 0, 0x1080, 0xd0, 1, 0, 0, 1, 9, 0, 0, 1, 1 },
+ { gUnk_0203510E, BG_TILE_ADDR(0x1a0), gTextGfxBuffer, 0, 0x80, 0xd0, 1, 0, 0, 1, 9, 0, 0, 1, 1 },
};
static const u16 gUnk_08127CC8[4] = {
0x71c,
diff --git a/src/object/pullableMushroom.c b/src/object/pullableMushroom.c
index 22982728..3200afbf 100644
--- a/src/object/pullableMushroom.c
+++ b/src/object/pullableMushroom.c
@@ -126,9 +126,56 @@ void PullableMushroom_Action1_Type1(PullableMushroomEntity* this) {
sub_0808B168(this, 0);
}
}
+void sub_0808ABC4(PullableMushroomEntity* this) {
+ static const s8 gUnk_081211CC[] = { 0, -128, 0, -6, 0, 0, 5, -4, 0, 0, 0, 0, 0, -128, -5, -4 };
+ u32 tmp;
+ const s8* ptr;
-const u16 gUnk_081211CC[] = { 32768, 64000, 0, 64517, 0, 0, 32768, 64763 };
-ASM_FUNC("asm/non_matching/pullableMushroom/sub_0808ABC4.inc", void sub_0808ABC4(PullableMushroomEntity* this))
+ if (super->parent->action == 1 && super->parent->subAction == 2) {
+ DeleteThisEntity();
+ }
+ tmp = sub_0808B1F0((PullableMushroomEntity*)super->child, super->parent);
+ if (tmp < 8) {
+ tmp = 0;
+ }
+ ptr = &gUnk_081211CC[super->animationState * 4];
+ if (tmp < 0x20) {
+ if (tmp != 0) {
+ tmp -= 6;
+ }
+ this->unk_70 = (*(u16*)ptr);
+ super->x.HALF.HI = (s16)ptr[2] + super->parent->x.HALF.HI;
+ super->y.HALF.HI = (s16)ptr[3] + super->parent->y.HALF.HI;
+ if (super->animationState & 1) {
+ this->unk_74 = 0x200 - (tmp << 4);
+ this->unk_78 = (tmp << 3) + 0x120;
+ super->frameIndex = 0x0f;
+ } else {
+ this->unk_78 = 0x200 - (tmp << 4);
+ this->unk_74 = (tmp << 3) + 0x120;
+ super->frameIndex = 0x14;
+ }
+ } else if (super->animationState & 1) {
+ this->unk_74 = 0x100 - 4 * (tmp - 0x20);
+ this->unk_78 = (tmp << 3) + 0x140;
+ super->frameIndex = 0x10;
+ if (super->animationState & 2) {
+ super->x.HALF.HI = (super->parent)->x.HALF.HI - (tmp >> 1);
+ } else {
+ super->x.HALF.HI = (super->parent)->x.HALF.HI + (tmp >> 1);
+ }
+ } else {
+ this->unk_78 = 0x100 - 4 * (tmp - 0x20);
+ this->unk_74 = (tmp << 3) + 0x140;
+ super->frameIndex = 0x15;
+ if (super->animationState & 2) {
+ super->y.HALF.HI = (super->parent)->y.HALF_U.HI + (tmp >> 1) + ptr[3];
+ } else {
+ super->y.HALF.HI = (super->parent)->y.HALF_U.HI - (tmp >> 1) + ptr[3];
+ }
+ }
+ SetAffineInfo(super, this->unk_74, this->unk_78, this->unk_70);
+}
void sub_0808ACEC(PullableMushroomEntity* this) {
if (super->animIndex != 0) {
diff --git a/src/physics.c b/src/physics.c
index dcc2eaa3..9c740228 100644
--- a/src/physics.c
+++ b/src/physics.c
@@ -399,7 +399,7 @@ bool32 CheckPlayerProximity(u32 x, u32 y, u32 distX, u32 DistY) {
return rv;
}
-NONMATCH("asm/non_matching/coord/sub_0806FC24.inc", bool32 sub_0806FC24(u32 param_1, u32 param_2)) {
+bool32 sub_0806FC24(u32 param_1, u32 param_2) {
register u32 rv asm("r0");
u32 val = sub_08007DD6(param_1, gUnk_080046A4);
if (val) {
@@ -409,7 +409,6 @@ NONMATCH("asm/non_matching/coord/sub_0806FC24.inc", bool32 sub_0806FC24(u32 para
}
return rv;
}
-END_NONMATCH
const u16* sub_0806FC50(u32 param_1, u32 param_2) {
const u16* rv;
diff --git a/src/playerUtils.c b/src/playerUtils.c
index bda35fd8..89a538f3 100644
--- a/src/playerUtils.c
+++ b/src/playerUtils.c
@@ -166,6 +166,7 @@ extern s8* gUnk_0811C0B0[];
extern u8 gUnk_0811C01C[];
extern u32 gUnk_02022830[];
+extern u16* gUnk_0800823C[];
void UpdateActiveItems(PlayerEntity* this) {
u32 index;
@@ -2087,7 +2088,74 @@ u32 GetPlayerTilePos(void) {
ASM_FUNC("asm/non_matching/playerUtils/sub_0807A5B8.inc", void sub_0807A5B8(u32 a))
-ASM_FUNC("asm/non_matching/playerUtils/sub_0807A750.inc", void sub_0807A750())
+void sub_0807A750(u32 param_1, u32 param_2, u8* param_3, u32 param_4) {
+ u32 uVar2;
+ u16* ptr;
+ u32 uVar5;
+ s32 index;
+
+ if ((param_4 & 1) == 0) {
+ index = param_2 % 16;
+ } else {
+ index = param_1 % 16;
+ }
+ if ((index != 0) && (index != 0xf)) {
+ uVar2 = sub_080B1B44((param_1 >> 4 & 0x3f) | (param_2 >> 4 & 0x3f) << 6, gPlayerEntity.collisionLayer);
+ if (uVar2 > 0xf) {
+ if (uVar2 != 0xff) {
+ uVar2 = param_3[uVar2 - 0x10];
+ } else {
+ uVar2 = 0xf;
+ }
+ }
+ ptr = gUnk_0800823C[uVar2];
+ if ((param_4 & 1) == 0) {
+ uVar5 = 0x8000 >> (param_1 % 16);
+ if (param_4 == 0) {
+ while (index < 0xf) {
+ if ((ptr[index] & uVar5) == 0) {
+ break;
+ }
+ index++;
+ }
+ index--;
+ } else {
+ while (index > 0) {
+ if ((ptr[index] & uVar5) == 0) {
+ break;
+ }
+ index--;
+ }
+ index++;
+ }
+ gPlayerEntity.y.HALF.HI += index - (param_2 % 16);
+ } else {
+ uVar5 = ptr[param_2 % 16];
+ if (param_4 == 1) {
+ uVar5 = uVar5 >> ((0xf - index));
+ while (index > 0) {
+ if ((uVar5 & 1) == 0) {
+ break;
+ }
+ uVar5 >>= 1;
+ index--;
+ }
+ index++;
+ } else {
+ uVar5 = uVar5 << index;
+ while (index < 0xf) {
+ if ((uVar5 & 0x8000) == 0) {
+ break;
+ }
+ uVar5 <<= 1;
+ index++;
+ }
+ index--;
+ }
+ gPlayerEntity.x.HALF.HI += (index - (param_1 % 16));
+ }
+ }
+}
u32 GetCollisionTileInFront(Entity* this) {
s32 x;
@@ -3226,7 +3294,7 @@ void sub_0807C5B0(void) {
roomControls->scroll_flags |= 2;
}
-NONMATCH("asm/non_matching/playerUtils/sub_0807C5F4.inc", void sub_0807C5F4(u16* param_1, u16* param_2)) {
+void sub_0807C5F4(u16* param_1, u16* param_2) {
s32 iVar1;
u16* puVar2;
u16* puVar3;
@@ -3234,76 +3302,50 @@ NONMATCH("asm/non_matching/playerUtils/sub_0807C5F4.inc", void sub_0807C5F4(u16*
u32 index;
u32 innerIndex;
- /*
- for (index = 0; index < 0x20; index++) {
- for (innerIndex = 0; innerIndex < 0x20; innerIndex++) {
- param_1[index*0x81+innerIndex] = param_2[innerIndex];
- }
- }
-
- */
puVar2 = param_1;
- iVar1 = 0x20;
- do {
- uVar4 = 0;
- iVar1--;
- do {
+ for (iVar1 = 0x20; iVar1 != 0; iVar1--) {
+ for (uVar4 = 0; uVar4 < 0x20; uVar4++) {
*puVar2 = *param_2;
param_2++;
puVar2++;
- uVar4++;
- } while (uVar4 < 0x20);
+ }
puVar2 += 0x60;
- } while (iVar1 != 0);
+ }
- if (0xff < gRoomControls.width) {
+ if (gRoomControls.width > 0xff) {
puVar2 = param_1 + 0x20;
- iVar1 = 0x20;
- do {
- uVar4 = 0;
- iVar1--;
- do {
+ for (iVar1 = 0x20; iVar1 != 0; iVar1--) {
+ for (uVar4 = 0; uVar4 < 0x20; uVar4++) {
*puVar2 = *param_2;
param_2++;
puVar2++;
- uVar4++;
- } while (uVar4 < 0x20);
+ }
puVar2 += 0x60;
- } while (iVar1 != 0);
+ }
}
- if (0xff < gRoomControls.height) {
+ if (gRoomControls.height > 0xff) {
puVar2 = param_1 + 0x1000;
- iVar1 = 0x20;
- do {
- uVar4 = 0;
- iVar1--;
- do {
+ for (iVar1 = 0x20; iVar1 != 0; iVar1--) {
+ for (uVar4 = 0; uVar4 < 0x20; uVar4++) {
*puVar2 = *param_2;
param_2++;
puVar2++;
- uVar4++;
- } while (uVar4 < 0x20);
+ }
puVar2 += 0x60;
- } while (iVar1 != 0);
+ }
}
- if ((0xff < gRoomControls.width) && (0xff < gRoomControls.height)) {
+ if (gRoomControls.width > 0xff && gRoomControls.height > 0xff) {
param_1 += 0x1020;
puVar2 = param_1;
- iVar1 = 0x20;
- do {
- uVar4 = 0;
- iVar1--;
- do {
- *puVar2 = *param_2;
- param_2++;
- puVar2++;
- uVar4++;
- } while (uVar4 < 0x20);
+
+ for (iVar1 = 0x20; iVar1 != 0; iVar1--) {
+ for (uVar4 = 0; uVar4 < 0x20; uVar4++) {
+ *puVar2++ = *param_2++;
+ }
puVar2 += 0x60;
- } while (iVar1 != 0);
+ }
}
}
-END_NONMATCH
void sub_0807C69C(u8* data, u32 width, u32 height) {
u8* ptr1;
diff --git a/src/staffroll.c b/src/staffroll.c
index e5d32e14..0d64b765 100644
--- a/src/staffroll.c
+++ b/src/staffroll.c
@@ -26,16 +26,16 @@ typedef struct {
#define gStaffrollMenu (*(StaffrollMenu*)&gMenu)
const Font gUnk_08127280 = {
- (u16*)0x02021f72, (void*)0x0600c400, gTextGfxBuffer, 0, 61472, 240, 0, 0, 0, 0, 0, 5, 0, 1, 0
+ &gBG1Buffer[0x21], BG_TILE_ADDR(0x188), gTextGfxBuffer, 0, 61472, 240, 0, 0, 0, 0, 0, 5, 0, 1, 0
};
const Font gUnk_08127298 = {
- (u16*)0x02021f90, (void*)0x0600c400, gTextGfxBuffer, 0, 61472, 240, 0, 0, 0, 0, 0, 5, 0, 1, 0
+ &gBG1Buffer[0x30], BG_TILE_ADDR(0x188), gTextGfxBuffer, 0, 61472, 240, 0, 0, 0, 0, 0, 5, 0, 1, 0
};
const Font gUnk_081272B0 = {
- (u16*)0x0202204e, (void*)0x0600c400, gTextGfxBuffer, 0, 61472, 240, 1, 0, 0, 0, 0, 5, 0, 1, 0
+ &gBG1Buffer[0x8f], BG_TILE_ADDR(0x188), gTextGfxBuffer, 0, 61472, 240, 1, 0, 0, 0, 0, 5, 0, 1, 0
};
const Font gUnk_081272C8 = {
- (u16*)0x020222ce, (void*)0x0600c400, gTextGfxBuffer, 0, 61472, 240, 1, 0, 0, 0, 0, 5, 0, 1, 0
+ &gBG1Buffer[0x1cf], BG_TILE_ADDR(0x188), gTextGfxBuffer, 0, 61472, 240, 1, 0, 0, 0, 0, 5, 0, 1, 0
};
const Font* const gUnk_081272E0[] = {