From c4cc962619b82caf5a39da9944a2821c05d978cd Mon Sep 17 00:00:00 2001 From: Oliver Bell Date: Tue, 21 Jan 2025 01:49:06 +0000 Subject: [PATCH] some progress on rotating handle and input_buffer --- src/game/interactables_1/rotating_handle.c | 124 ++++++++++++--------- src/game/sa1_sa2_shared/input_buffer.c | 69 ++++-------- src/input_recorder.c | 3 + 3 files changed, 100 insertions(+), 96 deletions(-) diff --git a/src/game/interactables_1/rotating_handle.c b/src/game/interactables_1/rotating_handle.c index 06aef3de4..cbcb3b96e 100644 --- a/src/game/interactables_1/rotating_handle.c +++ b/src/game/interactables_1/rotating_handle.c @@ -145,41 +145,48 @@ static void Task_Idle(void) } // (95.52%) https://decomp.me/scratch/RaPDV +// (99.80%) https://decomp.me/scratch/zEnJP NONMATCH("asm/non_matching/game/interactables_1/Task_Rotating.inc", void Task_Rotating()) { - Sprite_RotatingHandle *rotatingHandle = TASK_DATA(gCurTask); - Sprite *s = &rotatingHandle->s; - MapEntity *me = rotatingHandle->base.me; - u64 temp; - u32 cycle; - s32 x, y; + MapEntity *me; + Sprite *sprite; + Sprite_RotatingHandle *rotatingHandle; + u16 temp; + u16 temp2; + u16 temp3; + + s32 posX, posY; s32 cos; s32 sin; - x = TO_WORLD_POS(rotatingHandle->base.spriteX, rotatingHandle->base.regionX); - y = TO_WORLD_POS(me->y, rotatingHandle->base.regionY); + rotatingHandle = TASK_DATA(gCurTask); + // asm("":::"r8", "r9"); + sprite = &rotatingHandle->s; + me = rotatingHandle->base.me; + + posX = TO_WORLD_POS(rotatingHandle->base.spriteX, rotatingHandle->base.regionX); + posY = TO_WORLD_POS(me->y, rotatingHandle->base.regionY); rotatingHandle->unk3C = (rotatingHandle->unk3C + rotatingHandle->unk3E) & 0x3FF0; - cycle = ONE_CYCLE; - temp = rotatingHandle->unk3C >> 4; + // unused but required for match + temp3 = CLAMP_SIN_PERIOD(rotatingHandle->unk3C) + 0; + // asm("":::"r8", "r9"); + temp2 = rotatingHandle->unk3C >> 4; + temp = temp2; - s->x = x - gCamera.x; - s->y = y - gCamera.y; + sprite->x = posX - gCamera.x; + sprite->y = posY - gCamera.y; if (!PLAYER_IS_ALIVE) { gCurTask->main = Task_AfterJump; - DisplaySprite(s); + DisplaySprite(sprite); return; } if (gPlayer.frameInput & gPlayerControls.jump) { -#ifndef NON_MATCHING - register u32 temp2 asm("r4"); -#else - u32 temp2; -#endif - gPlayer.transition = PLTRANS_PT5; + s16 r4; + gPlayer.transition = 5; me->x = rotatingHandle->base.spriteX; Player_TransitionCancelFlyingAndBoost(&gPlayer); sub_8023B5C(&gPlayer, 9); @@ -190,34 +197,37 @@ NONMATCH("asm/non_matching/game/interactables_1/Task_Rotating.inc", void Task_Ro switch (rotatingHandle->unk40) { case 0: - temp2 = (0x20 - temp) & cycle; + r4 = CLAMP_SIN_PERIOD(0x20 - temp) + 0; sin = SIN(temp); gPlayer.qWorldX += sin >> 1; cos = COS(temp); gPlayer.qWorldY += cos >> 1; break; case 1: - temp2 = (temp + 0x20) & cycle; - sin = SIN(temp); +#ifndef NON_MATCHING + do { +#endif + r4 = CLAMP_SIN_PERIOD(temp + 0x20) + 0; + sin = SIN(temp); +#ifndef NON_MATCHING + } while (0); +#endif gPlayer.qWorldX += sin >> 1; cos = COS(temp); gPlayer.qWorldY -= cos >> 1; break; case 2: - temp2 = (temp + 0x1E0) & cycle; + r4 = CLAMP_SIN_PERIOD(temp + 0x1E0) + 0; sin = SIN(temp); gPlayer.qWorldX -= sin >> 1; cos = COS(temp); +#ifndef NON_MATCHING + asm("" ::: "r0"); +#endif gPlayer.qWorldY += cos >> 1; - break; case 3: { -#ifndef NON_MATCHING - register s32 r1 asm("r1") = 0x220; -#else - s32 r1 = 0x220; -#endif - temp2 = (r1 - temp) & cycle; + r4 = CLAMP_SIN_PERIOD(0x220 - temp) + 0; sin = SIN(temp); gPlayer.qWorldX -= sin >> 1; cos = COS(temp); @@ -225,48 +235,60 @@ NONMATCH("asm/non_matching/game/interactables_1/Task_Rotating.inc", void Task_Ro break; } default: - temp2 = 0; + r4 = 0; break; } - gPlayer.speedAirX = Div(COS(temp2) << 1, 0x11); - gPlayer.speedAirY = Div(SIN(temp2) << 1, 0x11); + gPlayer.speedAirX = Div(COS(r4) << 1, 0x11); + gPlayer.speedAirY = Div(SIN(r4) << 1, 0x11); gPlayer.charState = CHARSTATE_CURLED_IN_AIR; gPlayer.unk6C = 1; } else { u8 r2; if (gPlayer.charState == CHARSTATE_GRABBING_HANDLE_A) { - s32 new_var; r2 = Div(temp, 0x56); - new_var = 0xB; - if (r2 > new_var) { + if (r2 > 0xB) { r2 = 0xB; } + sprite->graphics.anim = SA2_ANIM_ROTATING_HANDLE; + sprite->variant = r2; + sprite->prevVariant = 0xFF; + gPlayer.variant = r2; + gPlayer.unk6C = 1; + gPlayer.qWorldX = Q_24_8(posX); + gPlayer.qWorldY = Q_24_8(posY); + gPlayer.speedAirX = 0; + gPlayer.speedAirY = 0; } else { r2 = Div(temp, 0x56); if (r2 > 0xB) { r2 = 0xB; } + sprite->graphics.anim = SA2_ANIM_ROTATING_HANDLE; + sprite->variant = r2; + sprite->prevVariant = 0xFF; + gPlayer.variant = r2; + gPlayer.unk6C = 1; + gPlayer.qWorldX = Q_24_8(posX); + gPlayer.qWorldY = Q_24_8(posY); + gPlayer.speedAirX = 0; + gPlayer.speedAirY = 0; } - - s->graphics.anim = SA2_ANIM_ROTATING_HANDLE; - s->variant = r2; - s->prevVariant = -1; - gPlayer.variant = r2; - gPlayer.unk6C = 1; - gPlayer.qWorldX = Q(x); - gPlayer.qWorldY = Q(y); - gPlayer.speedAirX = 0; - gPlayer.speedAirY = 0; } - if (IS_OUT_OF_CAM_RANGE(s->x, s->y)) { - me->x = rotatingHandle->base.spriteX; - TaskDestroy(gCurTask); + if (IS_OUT_OF_CAM_RANGE(sprite->x, sprite->y)) { +#ifndef NON_MATCHING + do { +#endif + me->x = rotatingHandle->base.spriteX; + TaskDestroy(gCurTask); +#ifndef NON_MATCHING + } while (0); +#endif return; } - UpdateSpriteAnimation(s); - DisplaySprite(s); + UpdateSpriteAnimation(sprite); + DisplaySprite(sprite); } END_NONMATCH diff --git a/src/game/sa1_sa2_shared/input_buffer.c b/src/game/sa1_sa2_shared/input_buffer.c index a4b0cfa49..c08d35d77 100644 --- a/src/game/sa1_sa2_shared/input_buffer.c +++ b/src/game/sa1_sa2_shared/input_buffer.c @@ -69,17 +69,7 @@ typedef struct { NONMATCH("asm/non_matching/game/sa1_sa2_shared/input_buf__sub_800DF8C.inc", void sub_800DF8C(Player *p)) { const u8 **unk0; - u32 unk4; - u8 *unk8; -#ifndef NON_MATCHING - register u32 r6 asm("r6"); - register u32 r8 asm("r8"); -#else - u32 r6; - u32 r8; -#endif const u8 *data; - StrcUnkInBuf *bytes; if (p->moveState & (MOVESTATE_IGNORE_INPUT | MOVESTATE_DEAD)) { sub_800E0C0(0, 0); @@ -90,63 +80,52 @@ NONMATCH("asm/non_matching/game/sa1_sa2_shared/input_buf__sub_800DF8C.inc", void sub_800E0C0(p->frameInput, p->frameInput); if (p->unk70 != 0) { - unk4 = 0; + u16 unk4 = 0; unk0 = gUnknown_08C871D4[p->character]; - data = *unk0; if (data != INPUTBUF_NULL_PTR) { // __0800DFEC - r6 = *data++; - r8 = *data++; + u32 r6 = *data++; + u32 r8 = *data++; // _0800E002 while (p->unk71 != r8) { - u8 cid; - cid = gNewInputCountersIndex; + u8 cid = gNewInputCountersIndex; // _0800E012 while (r6 != 0) { + u32 maskFF = 0xFF, mask1F = 0x1F; + s32 r2; + s16 r1; u32 r7, ip; + r6 = (u16)(r6 - 1); -#ifndef NON_MATCHING - register u32 maskFF asm("sl") = 0xFF; - register u32 mask1F asm("r9") = 0x1F; - register u32 r0_2 asm("r0") = r6 - 1; - register s32 r2 asm("r2"); - asm("" ::"r"(mask1F)); - asm("" ::"r"(maskFF)); - -#else - u32 maskFF = 0xFF; - u32 mask1F = 0x1F; - u32 r0_2 = r6 - 1; - s32 r2; -#endif - r6 = (u16)r0_2; - - bytes = (StrcUnkInBuf *)&data[r6 * 3]; - ip = bytes->unk0; - r7 = bytes->unk1; - r1 = bytes->unk2 & maskFF; + ip = data[r6 * 3 + 0]; + r7 = data[r6 * 3 + 1]; + r1 = data[r6 * 3 + 2] & maskFF; // _0800E02A while (1) { + s32 r0; u32 r3 = gNewInputCounters[cid].unk0 & r7; r2 = gNewInputCounters[cid].unk1; - if ((s16)r1 >= (signed)(r2 & maskFF)) { + r0 = r1; + r2 &= maskFF; + if (r0 >= r2) { if (ip == r3) { - cid = (cid - 1); + cid--; r2 = mask1F; cid &= r2; break; } else { cid = (cid - 1) & mask1F; - r1 = ((s16)(r1 - 1)) - r2; + r0 -= 1; + r0 -= r2; + r1 = r0; } } else { - // r2 should be set to 0 here, actually r2 = 0; break; } @@ -162,13 +141,11 @@ NONMATCH("asm/non_matching/game/sa1_sa2_shared/input_buf__sub_800DF8C.inc", void } // _0800E082 - unk4 = (u16)(unk4 + 1); - - if (unk0[unk4] == INPUTBUF_NULL_PTR) { + unk4++; + data = unk0[unk4]; + if (data == INPUTBUF_NULL_PTR) { break; } - - data = unk0[unk4]; r6 = *data++; r8 = *data++; } @@ -186,7 +163,9 @@ void sub_800E0C0(u16 param0, u16 param1) r3 |= r2; param1 = 0xF0; +#ifndef NON_MATCHING asm("" ::"r"(param1)); +#endif r5 = param0; r5 &= param1; r5 = (r5) | r3; diff --git a/src/input_recorder.c b/src/input_recorder.c index e47954b64..f0e8b3605 100644 --- a/src/input_recorder.c +++ b/src/input_recorder.c @@ -5,6 +5,9 @@ #include "input_recorder.h" #if TAS_TESTING +#if PORTABLE +#include +#endif // This is the size of any any% speed run TAS run #define TAPE_LENGTH 0x20000 #else