From a7a7be39c8d1b255eb309ecf1d545204c0779d49 Mon Sep 17 00:00:00 2001 From: ProjectOblivion Date: Mon, 24 Feb 2025 01:05:41 +0000 Subject: [PATCH 1/6] Decompiled lib func_us_801BBAB4/func_psp_09256018 --- config/symbols.pspeu.stlib.txt | 1 + src/st/lib/e_lesser_demon.c | 104 ++++++++++++++++++++++++++++++++- src/st/lib_psp/unk_1D9E8.c | 104 ++++++++++++++++++++++++++++++++- 3 files changed, 206 insertions(+), 3 deletions(-) diff --git a/config/symbols.pspeu.stlib.txt b/config/symbols.pspeu.stlib.txt index 2b487264fe..91d34d5b7d 100644 --- a/config/symbols.pspeu.stlib.txt +++ b/config/symbols.pspeu.stlib.txt @@ -106,6 +106,7 @@ func_us_801BB53C = 0x09254288; EntityBreakable = 0x092546D0; EntityChair = 0x09254DC0; func_us_801BB8DC = 0x09255D78; +func_us_801BBAB4 = 0x09256018; GetLang = 0x0925A830; DrawCutsceneActorName = 0x0925A8D0; CutsceneUnk3 = 0x0925ABE8; diff --git a/src/st/lib/e_lesser_demon.c b/src/st/lib/e_lesser_demon.c index c1662cda96..4ec51275e1 100644 --- a/src/st/lib/e_lesser_demon.c +++ b/src/st/lib/e_lesser_demon.c @@ -4,8 +4,108 @@ // Lesser demon start INCLUDE_ASM("st/lib/nonmatchings/e_lesser_demon", func_us_801BB8DC); -u8 func_us_801BBAB4(void); -INCLUDE_ASM("st/lib/nonmatchings/e_lesser_demon", func_us_801BBAB4); +// Seems to be the windup just before the spit attack +u8 func_us_801BBAB4(void) { + Primitive* prim; + Pos tempPrim; + s32 primIndex; + s32 unkVar; + u8 randomVal; + u8 ret; +#ifdef VERSION_US + s32 dummy[2]; +#endif + + ret = false; + switch (g_CurrentEntity->ext.lesserDemon.unk84) { + case 0: + primIndex = g_api.AllocPrimitives(PRIM_TILE, 0x18); + if (primIndex != -1) { + g_CurrentEntity->primIndex = primIndex; + g_CurrentEntity->flags |= FLAG_HAS_PRIMS; + prim = &g_PrimBuf[primIndex]; + g_CurrentEntity->ext.prim = prim; + for (; prim != NULL; prim = prim->next) { + PGREY_ALT(prim, 0, 0) + prim->u0 = 2; + prim->v0 = 2; + prim->priority = g_CurrentEntity->zPriority + 2; + prim->drawMode = + DRAW_TPAGE2 | DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP; + randomVal = Random() & 0x7F; + if (g_CurrentEntity->facingLeft) { + // These look like they could be -= and += respectively, + // but that oddly does not match + randomVal = randomVal - 0x40; + } else { + randomVal = randomVal + 0x40; + } + prim->x0 = (g_CurrentEntity->posX.i.hi + + ((rcos((randomVal) * 0x10) * 0x60) >> 0xC) + + (Random() & 0x3F)) - + 0x1F; + prim->y0 = (g_CurrentEntity->posY.i.hi + + ((rsin((randomVal) * 0x10) * 0x60) >> 0xC) + + (Random() & 0x3F)) - + 0x1F; + prim->x1 = 0; + prim->y1 = 0; + if (g_CurrentEntity->facingLeft) { + unkVar = + prim->x0 - (g_CurrentEntity->posX.i.hi + 0xA) << 0x10; + } else { + unkVar = + prim->x0 - (g_CurrentEntity->posX.i.hi - 0xA) << 0x10; + } + LOW(prim->x2) = -unkVar / 48; + unkVar = + (prim->y0 - (g_CurrentEntity->posY.i.hi - 0xB) << 0x10); + LOW(prim->x3) = -unkVar / 48; + } + } else { + ret = true; + g_CurrentEntity->ext.lesserDemon.unk84 = 2; + } + g_CurrentEntity->ext.lesserDemon.unk80 = 0; + g_CurrentEntity->ext.lesserDemon.unk84++; + break; + case 1: + prim = g_CurrentEntity->ext.prim; + for (; prim != NULL; prim = prim->next) { + tempPrim.x.i.hi = prim->x0; + tempPrim.x.i.lo = prim->x1; + tempPrim.y.i.hi = prim->y0; + tempPrim.y.i.lo = prim->y1; + tempPrim.x.val += LOWU(prim->x2); + tempPrim.y.val += LOWU(prim->x3); +#ifdef VERSION_PSP + prim->x0 = LOH(tempPrim.x.i.hi); + prim->x1 = LOH(tempPrim.x.i.lo); + prim->y0 = LOH(tempPrim.y.i.hi); + prim->y1 = LOH(tempPrim.y.i.lo); +#else + prim->x0 = tempPrim.x.i.hi; + prim->x1 = tempPrim.x.i.lo; + prim->y0 = tempPrim.y.i.hi; + prim->y1 = tempPrim.y.i.lo; +#endif + prim->r0 += 3; + } + prim = g_CurrentEntity->ext.prim; + PrimToggleVisibility(prim, 0x18); + if (g_CurrentEntity->ext.lesserDemon.unk80++ > 0x30) { + primIndex = g_CurrentEntity->primIndex; + g_api.FreePrimitives(primIndex); + g_CurrentEntity->flags &= ~FLAG_HAS_PRIMS; + g_CurrentEntity->ext.lesserDemon.unk84++; + g_CurrentEntity->ext.lesserDemon.unk80 = 0; + } + break; + case 2: + ret = true; + } + return ret; +} INCLUDE_ASM("st/lib/nonmatchings/e_lesser_demon", func_us_801BBEB0); diff --git a/src/st/lib_psp/unk_1D9E8.c b/src/st/lib_psp/unk_1D9E8.c index 41d4b31544..ee15ac712f 100644 --- a/src/st/lib_psp/unk_1D9E8.c +++ b/src/st/lib_psp/unk_1D9E8.c @@ -5,7 +5,109 @@ INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_psp_09255068); INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_us_801BB8DC); -INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_psp_09256018); +// func_us_801BBAB4 code is shared with PSX and is ready for merge +/// Seems to be the windup just before the spit attack +u8 func_us_801BBAB4(void) { + Primitive* prim; + Pos tempPrim; + s32 primIndex; + s32 unkVar; + u8 randomVal; + u8 ret; +#ifdef VERSION_US + s32 dummy[2]; +#endif + + ret = false; + switch (g_CurrentEntity->ext.lesserDemon.unk84) { + case 0: + primIndex = g_api.AllocPrimitives(PRIM_TILE, 0x18); + if (primIndex != -1) { + g_CurrentEntity->primIndex = primIndex; + g_CurrentEntity->flags |= FLAG_HAS_PRIMS; + prim = &g_PrimBuf[primIndex]; + g_CurrentEntity->ext.prim = prim; + for (; prim != NULL; prim = prim->next) { + PGREY_ALT(prim, 0, 0) + prim->u0 = 2; + prim->v0 = 2; + prim->priority = g_CurrentEntity->zPriority + 2; + prim->drawMode = + DRAW_TPAGE2 | DRAW_TPAGE | DRAW_UNK02 | DRAW_TRANSP; + randomVal = Random() & 0x7F; + if (g_CurrentEntity->facingLeft) { + // These look like they could be -= and += respectively, + // but that oddly does not match + randomVal = randomVal - 0x40; + } else { + randomVal = randomVal + 0x40; + } + prim->x0 = (g_CurrentEntity->posX.i.hi + + ((rcos((randomVal) * 0x10) * 0x60) >> 0xC) + + (Random() & 0x3F)) - + 0x1F; + prim->y0 = (g_CurrentEntity->posY.i.hi + + ((rsin((randomVal) * 0x10) * 0x60) >> 0xC) + + (Random() & 0x3F)) - + 0x1F; + prim->x1 = 0; + prim->y1 = 0; + if (g_CurrentEntity->facingLeft) { + unkVar = + prim->x0 - (g_CurrentEntity->posX.i.hi + 0xA) << 0x10; + } else { + unkVar = + prim->x0 - (g_CurrentEntity->posX.i.hi - 0xA) << 0x10; + } + LOW(prim->x2) = -unkVar / 48; + unkVar = + (prim->y0 - (g_CurrentEntity->posY.i.hi - 0xB) << 0x10); + LOW(prim->x3) = -unkVar / 48; + } + } else { + ret = true; + g_CurrentEntity->ext.lesserDemon.unk84 = 2; + } + g_CurrentEntity->ext.lesserDemon.unk80 = 0; + g_CurrentEntity->ext.lesserDemon.unk84++; + break; + case 1: + prim = g_CurrentEntity->ext.prim; + for (; prim != NULL; prim = prim->next) { + tempPrim.x.i.hi = prim->x0; + tempPrim.x.i.lo = prim->x1; + tempPrim.y.i.hi = prim->y0; + tempPrim.y.i.lo = prim->y1; + tempPrim.x.val += LOWU(prim->x2); + tempPrim.y.val += LOWU(prim->x3); +#ifdef VERSION_PSP + prim->x0 = LOH(tempPrim.x.i.hi); + prim->x1 = LOH(tempPrim.x.i.lo); + prim->y0 = LOH(tempPrim.y.i.hi); + prim->y1 = LOH(tempPrim.y.i.lo); +#else + prim->x0 = tempPrim.x.i.hi; + prim->x1 = tempPrim.x.i.lo; + prim->y0 = tempPrim.y.i.hi; + prim->y1 = tempPrim.y.i.lo; +#endif + prim->r0 += 3; + } + prim = g_CurrentEntity->ext.prim; + PrimToggleVisibility(prim, 0x18); + if (g_CurrentEntity->ext.lesserDemon.unk80++ > 0x30) { + primIndex = g_CurrentEntity->primIndex; + g_api.FreePrimitives(primIndex); + g_CurrentEntity->flags &= ~FLAG_HAS_PRIMS; + g_CurrentEntity->ext.lesserDemon.unk84++; + g_CurrentEntity->ext.lesserDemon.unk80 = 0; + } + break; + case 2: + ret = true; + } + return ret; +} INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_psp_092564B8); From 949920b918f768b7d2551b03fbc831040cfd3d53 Mon Sep 17 00:00:00 2001 From: ProjectOblivion Date: Mon, 24 Feb 2025 01:08:51 +0000 Subject: [PATCH 2/6] Added an alternate PGREY macro to support PSP --- include/primitive.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/primitive.h b/include/primitive.h index b25468900a..45d0f6e808 100644 --- a/include/primitive.h +++ b/include/primitive.h @@ -26,6 +26,13 @@ typedef enum { // prim->r0 = prim->g0 = prim->b0 = 255 becomes // PGREY(prim, 0) = 255 #define PGREY(p, n) p->r##n = p->g##n = p->b##n +// TODO: Merge these two macros +// This one was created to work for both PSP and PSX, but touches +// enough files to justify a separate PR to change the original. +#define PGREY_ALT(p, n, v) \ + p->r##n = v; \ + p->g##n = v; \ + p->b##n = v; typedef enum { PRIM_NONE, From 44f9a7f49db9d4a37dadd305c5831adf11dc4350 Mon Sep 17 00:00:00 2001 From: ProjectOblivion Date: Mon, 24 Feb 2025 01:09:51 +0000 Subject: [PATCH 3/6] Updated EntitySpittleBoneSpit to use Pos struct and remove the previously used unkstruct --- include/unkstruct.h | 17 ----------------- src/st/nz0/e_spittle_bone.c | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/include/unkstruct.h b/include/unkstruct.h index ef4ff6e5ce..fbca4a65ed 100644 --- a/include/unkstruct.h +++ b/include/unkstruct.h @@ -72,23 +72,6 @@ typedef struct { s32 unkC; } Unkstruct_800FDB18; -typedef struct Unkstruct_801C6C6C { - union { - struct { - u16 w; - u16 x; - } c; - s32 p; - } x; - union { - struct { - u16 h; - u16 y; - } c; - s32 p; - } y; -} Unkstruct_801C6C6C; - typedef struct { u16 start; s16 current; diff --git a/src/st/nz0/e_spittle_bone.c b/src/st/nz0/e_spittle_bone.c index 0f42091585..11e816fc48 100644 --- a/src/st/nz0/e_spittle_bone.c +++ b/src/st/nz0/e_spittle_bone.c @@ -187,7 +187,7 @@ void EntityRotateSpittlebone(Entity* self) { // spit projectile from spittle bone void EntitySpittleBoneSpit(Entity* self) { Collider collider; - Unkstruct_801C6C6C test; + Pos tempPrim; s16 primIndex; Primitive* prim; Entity* entity; @@ -277,16 +277,16 @@ void EntitySpittleBoneSpit(Entity* self) { prim = *(s32*)&self->ext.spittleBone.unk84; while (prim != NULL) { - test.x.c.x = prim->x0; - test.x.c.w = prim->x1; - test.y.c.y = prim->y0; - test.y.c.h = prim->y1; - test.x.p += LOW(prim->x2); - test.y.p += LOW(prim->x3); - prim->x0 = test.x.c.x; - prim->x1 = test.x.c.w; - prim->y0 = test.y.c.y; - prim->y1 = test.y.c.h; + tempPrim.x.i.hi = prim->x0; + tempPrim.x.i.lo = prim->x1; + tempPrim.y.i.hi = prim->y0; + tempPrim.y.i.lo = prim->y1; + tempPrim.x.val += LOW(prim->x2); + tempPrim.y.val += LOW(prim->x3); + prim->x0 = tempPrim.x.i.hi; + prim->x1 = tempPrim.x.i.lo; + prim->y0 = tempPrim.y.i.hi; + prim->y1 = tempPrim.y.i.lo; LOW(prim->x3) += 0x1800; if (LOW(prim->x3) > 0) { g_api.CheckCollision( From 8ebe4656267861a58ea94a2d8c3007fc9a6075ca Mon Sep 17 00:00:00 2001 From: ProjectOblivion Date: Mon, 24 Feb 2025 02:27:06 +0000 Subject: [PATCH 4/6] Typo fix --- src/st/lib_psp/unk_1D9E8.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/st/lib_psp/unk_1D9E8.c b/src/st/lib_psp/unk_1D9E8.c index ee15ac712f..cc408279b2 100644 --- a/src/st/lib_psp/unk_1D9E8.c +++ b/src/st/lib_psp/unk_1D9E8.c @@ -6,7 +6,7 @@ INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_psp_09255068); INCLUDE_ASM("st/lib_psp/psp/lib_psp/unk_1D9E8", func_us_801BB8DC); // func_us_801BBAB4 code is shared with PSX and is ready for merge -/// Seems to be the windup just before the spit attack +// Seems to be the windup just before the spit attack u8 func_us_801BBAB4(void) { Primitive* prim; Pos tempPrim; From f88c8bb07365bae8f5e227939d711c4e45805eef Mon Sep 17 00:00:00 2001 From: ProjectOblivion Date: Mon, 24 Feb 2025 02:36:08 +0000 Subject: [PATCH 5/6] Added PSP conditional to EntitySpittleBoneSpit --- src/st/nz0/e_spittle_bone.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/st/nz0/e_spittle_bone.c b/src/st/nz0/e_spittle_bone.c index 11e816fc48..35435d4b3d 100644 --- a/src/st/nz0/e_spittle_bone.c +++ b/src/st/nz0/e_spittle_bone.c @@ -281,12 +281,21 @@ void EntitySpittleBoneSpit(Entity* self) { tempPrim.x.i.lo = prim->x1; tempPrim.y.i.hi = prim->y0; tempPrim.y.i.lo = prim->y1; - tempPrim.x.val += LOW(prim->x2); - tempPrim.y.val += LOW(prim->x3); + tempPrim.x.val += LOWU(prim->x2); + tempPrim.y.val += LOWU(prim->x3); +// This conditional added on the unvalidated assumption that +// it will be needed to code share in the future +#ifdef VERSION_PSP + prim->x0 = LOH(tempPrim.x.i.hi); + prim->x1 = LOH(tempPrim.x.i.lo); + prim->y0 = LOH(tempPrim.y.i.hi); + prim->y1 = LOH(tempPrim.y.i.lo); +#else prim->x0 = tempPrim.x.i.hi; prim->x1 = tempPrim.x.i.lo; prim->y0 = tempPrim.y.i.hi; prim->y1 = tempPrim.y.i.lo; +#endif LOW(prim->x3) += 0x1800; if (LOW(prim->x3) > 0) { g_api.CheckCollision( From 84487addbc11bbc28dd400440b8034c89b51c576 Mon Sep 17 00:00:00 2001 From: ProjectOblivion Date: Mon, 24 Feb 2025 13:53:27 +0000 Subject: [PATCH 6/6] Review fixes --- src/st/lib/e_lesser_demon.c | 21 +++++++-------------- src/st/lib_psp/unk_1D9E8.c | 21 +++++++-------------- src/st/nz0/e_spittle_bone.c | 17 ++++------------- 3 files changed, 18 insertions(+), 41 deletions(-) diff --git a/src/st/lib/e_lesser_demon.c b/src/st/lib/e_lesser_demon.c index 4ec51275e1..790caf6dbf 100644 --- a/src/st/lib/e_lesser_demon.c +++ b/src/st/lib/e_lesser_demon.c @@ -24,7 +24,7 @@ u8 func_us_801BBAB4(void) { g_CurrentEntity->primIndex = primIndex; g_CurrentEntity->flags |= FLAG_HAS_PRIMS; prim = &g_PrimBuf[primIndex]; - g_CurrentEntity->ext.prim = prim; + g_CurrentEntity->ext.lesserDemon.unk7C = prim; for (; prim != NULL; prim = prim->next) { PGREY_ALT(prim, 0, 0) prim->u0 = 2; @@ -70,7 +70,7 @@ u8 func_us_801BBAB4(void) { g_CurrentEntity->ext.lesserDemon.unk84++; break; case 1: - prim = g_CurrentEntity->ext.prim; + prim = g_CurrentEntity->ext.lesserDemon.unk7C; for (; prim != NULL; prim = prim->next) { tempPrim.x.i.hi = prim->x0; tempPrim.x.i.lo = prim->x1; @@ -78,20 +78,13 @@ u8 func_us_801BBAB4(void) { tempPrim.y.i.lo = prim->y1; tempPrim.x.val += LOWU(prim->x2); tempPrim.y.val += LOWU(prim->x3); -#ifdef VERSION_PSP - prim->x0 = LOH(tempPrim.x.i.hi); - prim->x1 = LOH(tempPrim.x.i.lo); - prim->y0 = LOH(tempPrim.y.i.hi); - prim->y1 = LOH(tempPrim.y.i.lo); -#else - prim->x0 = tempPrim.x.i.hi; - prim->x1 = tempPrim.x.i.lo; - prim->y0 = tempPrim.y.i.hi; - prim->y1 = tempPrim.y.i.lo; -#endif + LOH(prim->x0) = tempPrim.x.i.hi; + LOH(prim->x1) = tempPrim.x.i.lo; + LOH(prim->y0) = tempPrim.y.i.hi; + LOH(prim->y1) = tempPrim.y.i.lo; prim->r0 += 3; } - prim = g_CurrentEntity->ext.prim; + prim = g_CurrentEntity->ext.lesserDemon.unk7C; PrimToggleVisibility(prim, 0x18); if (g_CurrentEntity->ext.lesserDemon.unk80++ > 0x30) { primIndex = g_CurrentEntity->primIndex; diff --git a/src/st/lib_psp/unk_1D9E8.c b/src/st/lib_psp/unk_1D9E8.c index cc408279b2..ab57211d37 100644 --- a/src/st/lib_psp/unk_1D9E8.c +++ b/src/st/lib_psp/unk_1D9E8.c @@ -26,7 +26,7 @@ u8 func_us_801BBAB4(void) { g_CurrentEntity->primIndex = primIndex; g_CurrentEntity->flags |= FLAG_HAS_PRIMS; prim = &g_PrimBuf[primIndex]; - g_CurrentEntity->ext.prim = prim; + g_CurrentEntity->ext.lesserDemon.unk7C = prim; for (; prim != NULL; prim = prim->next) { PGREY_ALT(prim, 0, 0) prim->u0 = 2; @@ -72,7 +72,7 @@ u8 func_us_801BBAB4(void) { g_CurrentEntity->ext.lesserDemon.unk84++; break; case 1: - prim = g_CurrentEntity->ext.prim; + prim = g_CurrentEntity->ext.lesserDemon.unk7C; for (; prim != NULL; prim = prim->next) { tempPrim.x.i.hi = prim->x0; tempPrim.x.i.lo = prim->x1; @@ -80,20 +80,13 @@ u8 func_us_801BBAB4(void) { tempPrim.y.i.lo = prim->y1; tempPrim.x.val += LOWU(prim->x2); tempPrim.y.val += LOWU(prim->x3); -#ifdef VERSION_PSP - prim->x0 = LOH(tempPrim.x.i.hi); - prim->x1 = LOH(tempPrim.x.i.lo); - prim->y0 = LOH(tempPrim.y.i.hi); - prim->y1 = LOH(tempPrim.y.i.lo); -#else - prim->x0 = tempPrim.x.i.hi; - prim->x1 = tempPrim.x.i.lo; - prim->y0 = tempPrim.y.i.hi; - prim->y1 = tempPrim.y.i.lo; -#endif + LOH(prim->x0) = tempPrim.x.i.hi; + LOH(prim->x1) = tempPrim.x.i.lo; + LOH(prim->y0) = tempPrim.y.i.hi; + LOH(prim->y1) = tempPrim.y.i.lo; prim->r0 += 3; } - prim = g_CurrentEntity->ext.prim; + prim = g_CurrentEntity->ext.lesserDemon.unk7C; PrimToggleVisibility(prim, 0x18); if (g_CurrentEntity->ext.lesserDemon.unk80++ > 0x30) { primIndex = g_CurrentEntity->primIndex; diff --git a/src/st/nz0/e_spittle_bone.c b/src/st/nz0/e_spittle_bone.c index 35435d4b3d..ce6df40760 100644 --- a/src/st/nz0/e_spittle_bone.c +++ b/src/st/nz0/e_spittle_bone.c @@ -283,19 +283,10 @@ void EntitySpittleBoneSpit(Entity* self) { tempPrim.y.i.lo = prim->y1; tempPrim.x.val += LOWU(prim->x2); tempPrim.y.val += LOWU(prim->x3); -// This conditional added on the unvalidated assumption that -// it will be needed to code share in the future -#ifdef VERSION_PSP - prim->x0 = LOH(tempPrim.x.i.hi); - prim->x1 = LOH(tempPrim.x.i.lo); - prim->y0 = LOH(tempPrim.y.i.hi); - prim->y1 = LOH(tempPrim.y.i.lo); -#else - prim->x0 = tempPrim.x.i.hi; - prim->x1 = tempPrim.x.i.lo; - prim->y0 = tempPrim.y.i.hi; - prim->y1 = tempPrim.y.i.lo; -#endif + LOH(prim->x0) = tempPrim.x.i.hi; + LOH(prim->x1) = tempPrim.x.i.lo; + LOH(prim->y0) = tempPrim.y.i.hi; + LOH(prim->y1) = tempPrim.y.i.lo; LOW(prim->x3) += 0x1800; if (LOW(prim->x3) > 0) { g_api.CheckCollision(