From 9aef02bc329305dbdcb2729e974bb96035585ad4 Mon Sep 17 00:00:00 2001 From: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Date: Thu, 11 Nov 2021 22:27:49 +0000 Subject: [PATCH 1/8] epiread.c OK (#410) * epiread.c OK * uintptr_t --- src/libultra/io/epirawread.c | 2 +- src/libultra/io/epiread.c | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libultra/io/epirawread.c b/src/libultra/io/epirawread.c index 317f7d63e..df0c6b603 100644 --- a/src/libultra/io/epirawread.c +++ b/src/libultra/io/epirawread.c @@ -1,6 +1,6 @@ #include "global.h" -s32 __osEPiRawReadIo(OSPiHandle* handle, u32 devAddr, u32* data) { +s32 __osEPiRawReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data) { s32 status; OSPiHandle* curHandle; diff --git a/src/libultra/io/epiread.c b/src/libultra/io/epiread.c index efab23bbb..5a2205bdc 100644 --- a/src/libultra/io/epiread.c +++ b/src/libultra/io/epiread.c @@ -1,3 +1,11 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/epiread/osEPiReadIo.s") +s32 osEPiReadIo(OSPiHandle* handle, uintptr_t devAddr, u32* data) { + register s32 ret; + + __osPiGetAccess(); + ret = __osEPiRawReadIo(handle, devAddr, data); + __osPiRelAccess(); + + return ret; +} From 1dba23c323cb690667e159c5b8c18416442d8c8e Mon Sep 17 00:00:00 2001 From: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Date: Thu, 11 Nov 2021 23:24:30 +0000 Subject: [PATCH 2/8] pfsinitpak OK (#425) * pfsinitpak OK * Review * Remove unnecessary if (1) {} --- include/PR/pfs.h | 1 + src/libultra/io/pfsinitpak.c | 123 ++++++++++++++++++++++++++++++++++- 2 files changed, 122 insertions(+), 2 deletions(-) diff --git a/include/PR/pfs.h b/include/PR/pfs.h index 135a6b56c..596fafbfe 100644 --- a/include/PR/pfs.h +++ b/include/PR/pfs.h @@ -134,6 +134,7 @@ typedef struct { /* 0x101 */ u8 map[PFS_INODE_DIST_MAP]; } __OSInodeCache; // size = 0x202 +s32 __osCheckPackId(OSPfs* pfs, __OSPackId* check); s32 __osGetId(OSPfs* pfs); s32 osPfsChecker(OSPfs* pfs); diff --git a/src/libultra/io/pfsinitpak.c b/src/libultra/io/pfsinitpak.c index 6d8a59c1a..cc226f834 100644 --- a/src/libultra/io/pfsinitpak.c +++ b/src/libultra/io/pfsinitpak.c @@ -1,5 +1,124 @@ +#include "PR/pfs.h" #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/pfsinitpak/osPfsInitPak.s") +s32 __osPfsCheckRamArea(OSPfs* pfs); -#pragma GLOBAL_ASM("asm/non_matchings/boot/pfsinitpak/__osPfsCheckRamArea.s") +s32 osPfsInitPak(OSMesgQueue* queue, OSPfs* pfs, s32 channel) { + s32 ret; + u16 sum; + u16 isum; + u8 buf[BLOCKSIZE]; + __OSPackId* id; + __OSPackId newid; + + __osSiGetAccess(); + + ret = __osPfsGetStatus(queue, channel); + + __osSiRelAccess(); + + if (ret != 0) { + return ret; + } + + pfs->queue = queue; + pfs->channel = channel; + pfs->status = 0; + + ret = __osPfsCheckRamArea(pfs); + if (ret != 0) { + return ret; + } + + ret = __osPfsSelectBank(pfs, PFS_ID_BANK_256K); + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(pfs->queue, pfs->channel, PFS_ID_0AREA, buf); + if (ret != 0) { + return ret; + } + + __osIdCheckSum((u16*)buf, &sum, &isum); + id = (__OSPackId*)buf; + if ((id->checksum != sum) || (id->invertedChecksum != isum)) { + ret = __osCheckPackId(pfs, id); + if (ret != 0) { + pfs->status |= PFS_ID_BROKEN; + return ret; + } + } + + if (!(id->deviceid & 1)) { + ret = __osRepairPackId(pfs, id, &newid); + if (ret != 0) { + if (ret == PFS_ERR_ID_FATAL) { + pfs->status |= PFS_ID_BROKEN; + } + return ret; + } + id = &newid; + if (!(id->deviceid & 1)) { + return PFS_ERR_DEVICE; + } + } + + bcopy(id, pfs->id, BLOCKSIZE); + + pfs->version = id->version; + pfs->banks = id->banks; + pfs->inodeStartPage = 1 + DEF_DIR_PAGES + (2 * pfs->banks); + pfs->dir_size = DEF_DIR_PAGES * PFS_ONE_PAGE; + pfs->inode_table = 1 * PFS_ONE_PAGE; + pfs->minode_table = (1 + pfs->banks) * PFS_ONE_PAGE; + pfs->dir_table = pfs->minode_table + (pfs->banks * PFS_ONE_PAGE); + + ret = __osContRamRead(pfs->queue, pfs->channel, PFS_LABEL_AREA, pfs->label); + if (ret != 0) { + return ret; + } + + ret = osPfsChecker(pfs); + pfs->status |= PFS_INITIALIZED; + + return ret; +} + +s32 __osPfsCheckRamArea(OSPfs* pfs) { + s32 i = 0; + s32 ret = 0; + u8 writeBuf[BLOCKSIZE]; + u8 readBuf[BLOCKSIZE]; + u8 saveReg[BLOCKSIZE]; + + ret = __osPfsSelectBank(pfs, PFS_ID_BANK_256K); + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(pfs->queue, pfs->channel, 0, saveReg); + if (ret != 0) { + return ret; + } + + for (i = 0; i < BLOCKSIZE; i++) { + writeBuf[i] = i; + } + + ret = __osContRamWrite(pfs->queue, pfs->channel, 0, writeBuf, 0); + if (ret != 0) { + return ret; + } + + ret = __osContRamRead(pfs->queue, pfs->channel, 0, readBuf); + if (ret != 0) { + return ret; + } + + if (bcmp(writeBuf, readBuf, BLOCKSIZE) != 0) { + return PFS_ERR_DEVICE; + } + + return __osContRamWrite(pfs->queue, pfs->channel, 0, saveReg, 0); +} From a5d8165cd1f2dc8dbc23292fdb4fcea0ad6f44e9 Mon Sep 17 00:00:00 2001 From: Tom Overton Date: Thu, 11 Nov 2021 16:46:11 -0800 Subject: [PATCH 3/8] Use ITEM_MASK_GIBDO enum in En_Hg (#451) --- src/overlays/actors/ovl_En_Hg/z_en_hg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/overlays/actors/ovl_En_Hg/z_en_hg.c b/src/overlays/actors/ovl_En_Hg/z_en_hg.c index e5a4448d0..d7eec060d 100644 --- a/src/overlays/actors/ovl_En_Hg/z_en_hg.c +++ b/src/overlays/actors/ovl_En_Hg/z_en_hg.c @@ -364,7 +364,7 @@ void func_80BCFC0C(EnHg* this, GlobalContext* globalCtx) { } if (globalCtx->msgCtx.unk1202A == 3) { if (globalCtx->msgCtx.unk1202E == 7 && gSaveContext.playerForm == PLAYER_FORM_HUMAN) { - if (INV_CONTENT(0x41) == 0x41) { + if (INV_CONTENT(ITEM_MASK_GIBDO) == ITEM_MASK_GIBDO) { this->unk218 = 3; } else { this->unk218 = 1; From 602f348928b66a58ca377bee00365684ab3371a9 Mon Sep 17 00:00:00 2001 From: Maide <34639600+Kelebek1@users.noreply.github.com> Date: Fri, 12 Nov 2021 01:41:59 +0000 Subject: [PATCH 4/8] En_Pm (#309) * En_Pm * Format * PR * a * a * Finally fixed? * PR * Fix enum --- include/functions.h | 12 +- include/variables.h | 2 +- spec | 3 +- src/overlays/actors/ovl_En_Dno/z_en_dno.h | 2 +- src/overlays/actors/ovl_En_Pm/z_en_pm.c | 1887 ++++++++++++++++- src/overlays/actors/ovl_En_Pm/z_en_pm.h | 48 +- .../actors/ovl_En_Suttari/z_en_suttari.c | 14 +- undefined_syms.txt | 14 + 8 files changed, 1894 insertions(+), 88 deletions(-) diff --git a/include/functions.h b/include/functions.h index 20dabac38..1102363d5 100644 --- a/include/functions.h +++ b/include/functions.h @@ -1308,7 +1308,7 @@ s16 Camera_ClearFlags(Camera* camera, s16 flags); // UNK_TYPE4 func_800E0228(void); // void func_800E0238(void); void func_800E02AC(Camera* camera, Actor* actor); -// void func_800E0308(void); +void func_800E0308(Camera* camera, Actor* actor); // void func_800E031C(void); void func_800E0348(Camera* camera); DamageTable* DamageTable_Get(s32 index); @@ -2675,17 +2675,17 @@ void func_8013A46C(s32 flag); u32 func_8013A4C4(s32 flag); s16 func_8013A504(s16 val); s32 func_8013A530(GlobalContext* globalCtx, Actor* actor, s32 flag, Vec3f* pos, Vec3s* rot, f32 distanceMin, f32 distanceMax, s16 angleError); -// void func_8013A7C0(void); +Actor* func_8013A7C0(GlobalContext* globalCtx, s32 arg1); // void func_8013A860(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); Gfx* func_8013AB00(GlobalContext* globalCtx, void** skeleton, Vec3s* jointTable, s32 dListCount, void* func1, void* func2, void* func3, Actor* actor, Gfx* gfx); s32 func_8013AD6C(GlobalContext* globalCtx); -// void func_8013AD9C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); +void func_8013AD9C(s16 arg0, s16 arg1, Vec3f* arg2, Vec3s* arg3, s32 arg4, s32 arg5); void func_8013AED4(u16* param_1, u16 param_2, u16 param_3); -void func_8013AF00(UNK_PTR arg0, UNK_TYPE arg1, UNK_TYPE arg2); +void func_8013AF00(f32 arg0[], UNK_TYPE arg1, UNK_TYPE arg2); // void func_8013B010(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); // void func_8013B0C8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5); // void func_8013B350(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7); -s32 func_8013B6B0(Path* path, UNK_PTR arg1, s32* arg2, s32 arg3, s32 arg4, s32* arg5, UNK_PTR arg6, Vec3f* arg7, s16 arg8); +s32 func_8013B6B0(Path* path, UNK_PTR arg1, s32* arg2, s32 arg3, s32 arg4, s32* arg5, f32 arg6[], Vec3f* arg7, s16 arg8); void func_8013B878(GlobalContext* globalCtx, Path* path, s32 arg2, Vec3f* arg3); Path* func_8013BB34(GlobalContext* globalCtx, u8 arg1, s32 arg2); Actor* func_8013BB7C(Actor* actor, GlobalContext* globalCtx, s32 actorCategory, s32 actorId); @@ -2709,7 +2709,7 @@ UNK_TYPE func_8013D768(Actor* actor, UNK_PTR arg1, s16 arg2); // void func_8013D83C(void); s32 func_8013D8DC(s8 arg0, GlobalContext* globalCtx); s8 func_8013D924(s32 arg0, GlobalContext* globalCtx); -Actor* func_ActorCategoryIterateById(GlobalContext* globalCtx, Actor* actorListStart, s32 actorCategory, s32 actorId); +Actor* func_ActorCategoryIterateById(GlobalContext* globalCtx, Actor* actorListStart, u8 actorCategory, s16 actorId); void func_8013D9C8(GlobalContext* globalCtx, s16* arg1, s16* arg2, UNK_TYPE arg3); u8 func_8013DB90(GlobalContext* globalCtx, UNK_PTR arg1, f32 arg2); // void func_8013DC40(void); diff --git a/include/variables.h b/include/variables.h index 281996873..14a4f340e 100644 --- a/include/variables.h +++ b/include/variables.h @@ -3272,7 +3272,7 @@ extern u8 D_801F4E30; // extern UNK_TYPE1 D_801F4E68; extern f32 D_801F4E70; // extern UNK_TYPE1 D_801F4E74; -// extern UNK_TYPE1 D_801F4E78; +extern u16 D_801F4E78; extern s16 D_801F4E7A; // extern UNK_TYPE1 D_801F4E80; // extern UNK_TYPE1 D_801F4EE0; diff --git a/spec b/spec index d619034f3..95f2a48d7 100644 --- a/spec +++ b/spec @@ -3828,8 +3828,7 @@ beginseg name "ovl_En_Pm" compress include "build/src/overlays/actors/ovl_En_Pm/z_en_pm.o" - include "build/data/ovl_En_Pm/ovl_En_Pm.data.o" - include "build/data/ovl_En_Pm/ovl_En_Pm.reloc.o" + include "build/src/overlays/actors/ovl_En_Pm/ovl_En_Pm_reloc.o" endseg beginseg diff --git a/src/overlays/actors/ovl_En_Dno/z_en_dno.h b/src/overlays/actors/ovl_En_Dno/z_en_dno.h index a99162694..1f7bff87f 100644 --- a/src/overlays/actors/ovl_En_Dno/z_en_dno.h +++ b/src/overlays/actors/ovl_En_Dno/z_en_dno.h @@ -7,7 +7,7 @@ struct EnDno; typedef void (*EnDnoActionFunc)(struct EnDno*, GlobalContext*); -#define ENDNO_GET_F(thisx) (u32)((thisx)->params & 0xF) +#define ENDNO_GET_F(thisx) ((thisx)->params & 0xF) #define ENDNO_GET_7F(thisx) ((thisx)->params & 0x7F) #define ENDNO_GET_7F0(thisx) (((thisx)->params >> 4) & 0x7F) #define ENDNO_GET_3F80(thisx) (((thisx)->params >> 7) & 0x7F) diff --git a/src/overlays/actors/ovl_En_Pm/z_en_pm.c b/src/overlays/actors/ovl_En_Pm/z_en_pm.c index be1efeaf7..55b888a53 100644 --- a/src/overlays/actors/ovl_En_Pm/z_en_pm.c +++ b/src/overlays/actors/ovl_En_Pm/z_en_pm.c @@ -1,10 +1,11 @@ /* * File: z_en_pm.c * Overlay: ovl_En_Pm - * Description: Postman delivering letters + * Description: Postman */ #include "z_en_pm.h" +#include "overlays/actors/ovl_En_Door/z_en_door.h" #define FLAGS 0x00000039 @@ -18,7 +19,181 @@ void EnPm_Draw(Actor* thisx, GlobalContext* globalCtx); void func_80AFA4D0(EnPm* this, GlobalContext* globalCtx); void func_80AFA5FC(EnPm* this, GlobalContext* globalCtx); -#if 0 +extern AnimationHeader D_06000468; +extern AnimationHeader D_0600099C; +extern AnimationHeader D_06000FC4; +extern AnimationHeader D_06001F84; +extern AnimationHeader D_06002238; +extern UNK_PTR D_06002750; +extern UNK_PTR D_06002950; +extern Gfx D_06008348[]; +extern Gfx D_060083E0[]; +extern Gfx D_060085C8[]; +extern FlexSkeletonHeader D_060096E8; +extern AnimationHeader D_060099B4; +extern AnimationHeader D_0600A4E0; +extern AnimationHeader D_0600A8D8; +extern AnimationHeader D_0600B09C; +extern AnimationHeader D_0600BA78; +extern AnimationHeader D_0600C32C; +extern AnimationHeader D_0600C640; + +// Game scripts +static UNK_TYPE D_80AFAD80[] = { + 0x0D000102, 0x3B030900, 0x0C00010B, 0x030C000D, 0x0100F902, 0x0D010F00, 0x12020F00, 0x00050105, 0x0A002E06, + 0x0E0F0000, 0x0508050A, 0x006D3102, 0x0D010D04, 0x25020D04, 0x0D151902, 0x0E300E38, 0x0D020E38, 0x0F000105, + 0x0E0E380F, 0x00020E0E, 0x300E383E, 0x0E0D040D, 0x15350E0D, 0x010D0401, 0x0A006F31, 0x020D040D, 0x1525020D, + 0x150D2719, 0x020E260E, 0x300D020E, 0x300E3801, 0x050E0E30, 0x0E383D0E, 0x0E260E30, 0x3C0E0D15, 0x0D27370E, + 0x0D040D15, 0x360A006C, 0x31020D27, 0x0D382502, 0x0D380E00, 0x19020E1A, 0x0E1E0D02, 0x0E1E0E26, 0x01050E0E, + 0x1E0E263B, 0x0E0E1A0E, 0x1E0B0E0D, 0x380E000A, 0x0E0D270D, 0x38380A00, 0x613D020D, 0x380E0031, 0x020E000E, + 0x0825020E, 0x080E1219, 0x020E120E, 0x1A0D020E, 0x1A0E1E01, 0x050E0E1A, 0x0E1E0D0E, 0x0E120E1A, 0x3A0E0E08, + 0x0E12100E, 0x0E000E08, 0x390E0D38, 0x0E000C05, 0x0A002E06, 0x0E0C000D, 0x0109050A, 0x006D3102, 0x09000903, + 0x25020903, 0x09111902, 0x0B2B0B39, 0x0D020B39, 0x0C000105, 0x0E0B390C, 0x00020E0B, 0x2B0B3934, 0x0E090309, + 0x11260E09, 0x00090301, 0x0A006F61, 0x02090309, 0x11550209, 0x11091F49, 0x02091F09, 0x233D0209, 0x23093131, + 0x020A390B, 0x0B25020B, 0x0B0B1919, 0x020B190B, 0x1D0D020B, 0x1D0B2B01, 0x050E0B1D, 0x0B2B320E, 0x0B190B1D, + 0x070E0B0B, 0x0B19300E, 0x0A390B0B, 0x2F0E0923, 0x0931290E, 0x091F0923, 0x030E0911, 0x091F280E, 0x09030911, + 0x270A006E, 0x25020931, 0x0A031902, 0x0A030A07, 0x0D020A07, 0x0A150105, 0x0E0A070A, 0x152B0E0A, 0x030A0704, + 0x0E09310A, 0x032A0A00, 0x6C61020A, 0x150A2355, 0x020A230A, 0x2749020A, 0x270A353D, 0x020A350A, 0x3931020A, + 0x390B0B25, 0x020B0B0B, 0x1919020B, 0x190B1D0D, 0x020B1D0B, 0x2B01050E, 0x0B1D0B2B, 0x330E0B19, 0x0B1D070E, + 0x0B0B0B19, 0x310E0A39, 0x0B0B2E0E, 0x0A350A39, 0x060E0A27, 0x0A352D0E, 0x0A230A27, 0x050E0A15, 0x0A232C05, + 0x0D000201, 0xCF011C08, 0x00A50309, 0x000C00FE, 0xC6030C00, 0x0D01008C, 0x020D010F, 0x007E0200, 0x00020001, + 0x050A006D, 0x31020000, 0x00042502, 0x0004001F, 0x1902011D, 0x01380D02, 0x01380200, 0x01050E01, 0x38020002, + 0x0E011D01, 0x384F0E00, 0x04001F4A, 0x0E000000, 0x04010A00, 0x6F3D0200, 0x04001F31, 0x02001F00, 0x3A250200, + 0x3A010219, 0x02010201, 0x1D0D0201, 0x1D013801, 0x050E011D, 0x01384E0E, 0x0102011D, 0x4D0E003A, 0x0102120E, + 0x001F003A, 0x4C0E0004, 0x001F4B05, 0x0A002E03, 0x04000E05, 0x0A002E06, 0x0E0C000D, 0x01140503, 0x09000C00, + 0xFE21030C, 0x000D0101, 0x0C020D01, 0x11001202, 0x11000005, 0x01050A00, 0x2E060E11, 0x00000508, 0x050A006D, + 0x31020D01, 0x0D042502, 0x0D040D0F, 0x19021023, 0x10390D02, 0x10391100, 0x01050E10, 0x39110002, 0x0E102310, + 0x39490E0D, 0x040D0F3F, 0x0E0D010D, 0x04010A00, 0x6F31020D, 0x040D0F25, 0x020D0F0D, 0x1E19020D, 0x340E2D0D, + 0x02100F10, 0x2301050E, 0x100F1023, 0x480E0D34, 0x0E2D430E, 0x0D0F0D1E, 0x410E0D04, 0x0D0F400A, 0x006C1902, + 0x0D1E0D34, 0x0D020D34, 0x0E320105, 0x0E0D340E, 0x32440E0D, 0x1E0D3442, 0x0A007068, 0x020E2D0F, 0x055C0C00, + 0x0231020F, 0x050F1425, 0x020F140F, 0x1919020F, 0x190F280D, 0x020F2810, 0x0F01050E, 0x0F28100F, 0x510E0F19, + 0x0F28110E, 0x0F140F19, 0x500E0F05, 0x0F141702, 0x0F050F14, 0x1B020F14, 0x0F320F02, 0x0F32100F, 0x03040000, + 0x0E0F3210, 0x0F470E0F, 0x140F3219, 0x0E0F050F, 0x14170E0E, 0x2D0F0546, 0x050A002E, 0x060E0C00, 0x0D011505, + 0x0D000301, 0x6F011C08, 0x013F011C, 0x10010C03, 0x09000C00, 0xFCED030C, 0x000D0100, 0xF6020D01, 0x0F000F02, + 0x12000600, 0x01050A00, 0x2E030400, 0x18050A00, 0x6D31020D, 0x000D0125, 0x020D050D, 0x0F19020E, 0x2D0E370D, + 0x020E370F, 0x0001050E, 0x0E370F00, 0x020E0E2D, 0x0E37340E, 0x0D050D0F, 0x260E0D00, 0x0D01010A, 0x006F4902, + 0x0D050D0F, 0x3D020D0F, 0x0D193102, 0x0D190D23, 0x25020E0F, 0x0E191902, 0x0E190E23, 0x0D020E23, 0x0E2D0105, + 0x0E0E230E, 0x2D320E0E, 0x190E2330, 0x0E0E0F0E, 0x192F0E0D, 0x190D2329, 0x0E0D0F0D, 0x19280E0D, 0x050D0F27, + 0x0A006E19, 0x020D230D, 0x2D0D020D, 0x2D0D3701, 0x050E0D2D, 0x0D372B0E, 0x0D230D2D, 0x2A0A006C, 0x3D020D37, + 0x0E053102, 0x0E050E0F, 0x25020E0F, 0x0E191902, 0x0E190E23, 0x0D020E23, 0x0E2D0105, 0x0E0E230E, 0x2D330E0E, + 0x190E2331, 0x0E0E0F0E, 0x192E0E0E, 0x050E0F2D, 0x0E0D370E, 0x052C050A, 0x002E0304, 0x00160503, 0x09000C00, + 0xFBE1020C, 0x000D0116, 0x030D0111, 0x00FDD202, 0x12000600, 0x01050A00, 0x2E030400, 0x18050A00, 0x2E060E0C, + 0x000D0115, 0x05030900, 0x0C00FBB3, 0x020C000D, 0x0116030D, 0x010F00FE, 0xD5021200, 0x06000105, 0x0A002E03, + 0x04001805, 0x0A002E03, 0x04001405, 0x05000000, +}; + +static UNK_TYPE D_80AFB30C[] = { + 0x0A002E2E, 0x02000000, 0x0A220200, 0x0A000D19, 0x02000D00, 0x170D0200, 0x17001A01, 0x050E0017, 0x001A200E, + 0x000D0017, 0x5304001B, 0x0E000000, 0x0A520A00, 0x6D190200, 0x17001A0D, 0x02001A00, 0x2401050E, 0x001A0024, + 0x540E0017, 0x001A210A, 0x006F1902, 0x001A0024, 0x0D020024, 0x002E0105, 0x0E002400, 0x2E560E00, 0x1A002455, + 0x0A006C19, 0x02002E00, 0x380D0200, 0x38003B01, 0x050E0038, 0x003B220E, 0x002E0038, 0x570A0015, 0x25020038, + 0x003B1902, 0x003B0109, 0x0D020109, 0x01280105, 0x0E010901, 0x281C0E00, 0x3B010958, 0x0E003800, 0x3B240500, +}; + +static UNK_TYPE D_80AFB3C0[] = { + 0x0A006C19, 0x02000A00, 0x0D0D0200, 0x0D001701, 0x050E000D, 0x00175A0E, 0x000A000D, 0x230A0015, + 0x19020000, 0x000A0D02, 0x000A000D, 0x01050E00, 0x0A000D25, 0x0E000000, 0x0A590500, +}; + +static UNK_TYPE D_80AFB3FC[] = { + 0x0A006C19, 0x02120006, 0x000D0205, 0x00050A01, 0x050E0500, 0x050A5B0E, 0x12000600, 0x1D050000, +}; + +static UNK_TYPE D_80AFB41C[] = { + 0x0A006C0D, 0x02000000, 0x0A01050E, 0x0000000A, 0x5B050000, +}; + +static s32 D_80AFB430[] = { + -1, 0, 4, 1, 0, 0, 1, 4, -1, -1, 15, 5, 0, 3, -1, -1, 1, 2, 11, 3, -1, -1, -1, 0, 0, 0, 0, 0, 1, 12, -1, + -1, 2, 0, 10, 11, 0, 3, 1, 0, 1, 2, 0, 1, 0, 1, 2, 3, 4, 3, 5, 14, 3, 1, 0, 6, 4, 1, 2, 6, 7, 8, + 2, 1, 0, 6, 7, 9, 8, -1, 0, 1, 10, 3, 1, 0, 11, 12, 8, 2, 2, 3, 0, 1, 1, 0, 6, 9, 1, 2, 12, 13, +}; + +// Game scripts +static UNK_TYPE D_80AFB5A0[] = { + 0x00560800, 0x45090000, 0x170E28BA, 0x0C090000, 0x180E28BB, 0x0C090000, 0x170E28BC, 0x0C090000, 0x180E28BD, + 0x0C090000, 0x170E28BE, 0x0C090000, 0x180E28BF, 0x0C090000, 0x170E28C0, 0x2D00012D, 0x000B0C09, 0x00001156, + 0x08100900, 0x00170E29, 0x5C0C0900, 0x00180E29, 0x5D0C0900, 0x00170E29, 0x5E2D0001, 0x2D000B0C, 0x09000010, +}; + +static UNK_TYPE D_80AFB60C[] = { + 0x0E27742D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB614[] = { + 0x0E27752D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB61C[] = { + 0x0E27772D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB624[] = { + 0x0E27782D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB62C[] = { + 0x0E27792D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB634[] = { + 0x0E27812D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB63C[] = { + 0x0E277A2D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB644[] = { + 0x0E27822D, + 0x000B0C11, + 0x58021000, +}; + +static UNK_TYPE D_80AFB650[] = { + 0x0E27832D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB658[] = { + 0x25002E00, 0x1A005280, 0x000C0E27, 0x7C2D000B, 0x0C115280, 0x12100E27, 0x7D2D000B, 0x0C12100E, 0x277C0C0E, + 0x00FF1E00, 0x33000000, 0x1800282C, 0xFFFF0900, 0x000E277E, 0x2D000B0C, 0x11528011, 0x56012A00, 0x2E12102C, + 0x277D0C2F, 0x00002D00, 0x0B0C1152, 0x8012100E, 0x277D2D00, 0x0B0C1152, 0x80121000, +}; + +static UNK_TYPE D_80AFB6BC[] = { + 0x0900000E, 0x27A50C09, 0x0000170E, 0x27A60C09, 0x0000180E, 0x27A70C09, 0x0000170E, + 0x27A80C09, 0x0000180E, 0x27A90C09, 0x0000170E, 0x27AA0C09, 0x0000180E, 0x27AB0C09, + 0x0000170E, 0x27AC0C09, 0x0000180E, 0x27AD2D00, 0x0B2D0008, 0x0C115908, 0x09000010, +}; + +static UNK_TYPE D_80AFB710[] = { + 0x25003E00, 0x230E2780, 0x0C0F27AE, 0x0C120600, 0x84000013, 0x0084115A, 0x042F0000, + 0x2E2D000B, 0x2D00310C, 0x115A0110, 0x0E27802D, 0x000B0C11, 0x5A011210, +}; + +static UNK_TYPE D_80AFB744[] = { + 0x0E23692D, + 0x000B0C10, +}; + +static UNK_TYPE D_80AFB74C[] = { + 0x2CFFFF09, 0x00000E27, 0x7E2D000B, 0x0C115280, 0x1156012A, 0x002E1210, +}; + +static UNK_TYPE D_80AFB764[] = { + 0x2C277D2D, + 0x000B0C11, + 0x52801210, +}; + const ActorInit En_Pm_InitVars = { ACTOR_EN_PM, ACTORCAT_NPC, @@ -31,128 +206,1704 @@ const ActorInit En_Pm_InitVars = { (ActorFunc)EnPm_Draw, }; -// static ColliderCylinderInit sCylinderInit = { -static ColliderCylinderInit D_80AFB790 = { - { COLTYPE_HIT1, AT_NONE, AC_NONE, OC1_ON | OC1_TYPE_ALL, OC2_TYPE_1, COLSHAPE_CYLINDER, }, - { ELEMTYPE_UNK1, { 0x00000000, 0x00, 0x00 }, { 0x00000000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_NONE, OCELEM_ON, }, +static ColliderCylinderInit sCylinderInit = { + { + COLTYPE_HIT1, + AT_NONE, + AC_NONE, + OC1_ON | OC1_TYPE_ALL, + OC2_TYPE_1, + COLSHAPE_CYLINDER, + }, + { + ELEMTYPE_UNK1, + { 0x00000000, 0x00, 0x00 }, + { 0x00000000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_NONE, + OCELEM_ON, + }, { 14, 62, 0, { 0, 0, 0 } }, }; -// static ColliderSphereInit sSphereInit = { -static ColliderSphereInit D_80AFB7BC = { - { COLTYPE_NONE, AT_NONE, AC_NONE, OC1_ON | OC1_TYPE_ALL, OC2_TYPE_1, COLSHAPE_SPHERE, }, - { ELEMTYPE_UNK0, { 0x00000000, 0x00, 0x00 }, { 0x00000000, 0x00, 0x00 }, TOUCH_NONE | TOUCH_SFX_NORMAL, BUMP_NONE, OCELEM_ON, }, +static ColliderSphereInit sSphereInit = { + { + COLTYPE_NONE, + AT_NONE, + AC_NONE, + OC1_ON | OC1_TYPE_ALL, + OC2_TYPE_1, + COLSHAPE_SPHERE, + }, + { + ELEMTYPE_UNK0, + { 0x00000000, 0x00, 0x00 }, + { 0x00000000, 0x00, 0x00 }, + TOUCH_NONE | TOUCH_SFX_NORMAL, + BUMP_NONE, + OCELEM_ON, + }, { 0, { { 0, 0, 0 }, 26 }, 100 }, }; -// sColChkInfoInit -static CollisionCheckInfoInit2 D_80AFB7E8 = { 0, 0, 0, 0, MASS_IMMOVABLE }; +static CollisionCheckInfoInit2 sColChkInfoInit = { 0, 0, 0, 0, MASS_IMMOVABLE }; -#endif +static ActorAnimationEntryS sAnimations[] = { + { &D_06002238, 1.0f, 0, -1, 0, 0 }, { &D_06002238, 1.0f, 0, -1, 0, -4 }, { &D_0600A4E0, 1.0f, 0, -1, 2, 0 }, + { &D_0600B09C, 1.0f, 0, -1, 0, 0 }, { &D_0600B09C, 1.0f, 0, -1, 0, -4 }, { &D_0600BA78, 1.0f, 0, -1, 2, 0 }, + { &D_0600C32C, 1.0f, 0, -1, 0, -4 }, { &D_060099B4, 1.0f, 0, -1, 0, 0 }, { &D_06000FC4, 1.0f, 0, -1, 0, 0 }, + { &D_0600A8D8, 1.0f, 0, -1, 0, 0 }, { &D_0600099C, 1.0f, 0, -1, 0, 0 }, { &D_06001F84, 1.0f, 0, -1, 2, 0 }, + { &D_06000468, 1.0f, 0, -1, 0, 0 }, { &D_0600C640, 1.0f, 0, -1, 0, 0 }, +}; -extern ColliderCylinderInit D_80AFB790; -extern ColliderSphereInit D_80AFB7BC; -extern CollisionCheckInfoInit2 D_80AFB7E8; +s32 func_80AF7B40(void) { + if (gSaveContext.weekEventReg[90] & 1) { + return 4; + } -extern UNK_TYPE D_06008348; -extern UNK_TYPE D_060096E8; + if (gSaveContext.weekEventReg[89] & 0x40) { + return 3; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7B40.s") + if (gSaveContext.weekEventReg[89] & 8) { + return 2; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7BAC.s") + if (gSaveContext.weekEventReg[86] & 1) { + return 1; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7CB0.s") + return 0; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7D60.s") +s32 func_80AF7BAC(EnPm* this) { + switch (this->unk_38C) { + case 0: + if (gSaveContext.weekEventReg[86] & 1) { + D_801F4E78 = gSaveContext.time; + this->unk_38C++; + } + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7DC4.s") + case 1: + if (gSaveContext.weekEventReg[89] & 8) { + D_801F4E78 = gSaveContext.time; + this->unk_38C++; + } + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7E6C.s") + case 2: + if (gSaveContext.weekEventReg[89] & 0x40) { + D_801F4E78 = 0; + this->unk_38C++; + } + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7E98.s") + case 3: + if (gSaveContext.weekEventReg[90] & 1) { + D_801F4E78 = gSaveContext.time; + this->unk_38C++; + } + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF7F68.s") + return true; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8040.s") +Actor* func_80AF7CB0(EnPm* this, GlobalContext* globalCtx, u8 actorCat, s16 actorId) { + Actor* phi_s0 = NULL; + Actor* actor; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF80F4.s") + while (true) { + actor = func_ActorCategoryIterateById(globalCtx, phi_s0, actorCat, actorId); + phi_s0 = actor; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8170.s") + if (actor == NULL) { + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF81E8.s") + if (((EnPm*)phi_s0 != this) && (actor->update != NULL)) { + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8348.s") + actor = actor->next; + if (actor == NULL) { + phi_s0 = NULL; + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8478.s") + phi_s0 = actor; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8540.s") + return phi_s0; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF86F0.s") +Actor* func_80AF7D60(GlobalContext* globalCtx, s32 arg1) { + s32 phi_a1; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF87C4.s") + switch (arg1) { + case 1: + case 2: + case 32: + case 33: + phi_a1 = 1; + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8890.s") + case 34: + case 35: + case 36: + case 37: + phi_a1 = 10; + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF898C.s") + case 10: + case 11: + case 12: + case 13: + phi_a1 = 11; + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8AC8.s") + default: + return NULL; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8BA8.s") + return func_8013A7C0(globalCtx, phi_a1); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8C68.s") +Actor* func_80AF7DC4(EnPm* this, GlobalContext* globalCtx, s32 arg2) { + Actor* phi_s0 = NULL; + Actor* actor; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8D84.s") + while (true) { + actor = func_ActorCategoryIterateById(globalCtx, phi_s0, ACTORCAT_PROP, ACTOR_EN_PST); + phi_s0 = actor; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8DD4.s") + if (actor == NULL) { + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF8ED4.s") + if (((EnPm*)actor != this) && (actor->update != NULL) && (actor->params == (s16)arg2)) { + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF9008.s") + actor = actor->next; + if (actor == NULL) { + phi_s0 = NULL; + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF91E8.s") + phi_s0 = actor; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF94AC.s") + return phi_s0; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF95E8.s") +void func_80AF7E6C(EnPm* this) { + this->skelAnime.playSpeed = this->unk_35C; + SkelAnime_Update(&this->skelAnime); +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF98A0.s") +s32 func_80AF7E98(EnPm* this, s32 arg1) { + s32 phi_v1 = false; + s32 ret = false; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF992C.s") + switch (arg1) { + case 0: + case 1: + if ((this->unk_384 != 0) && (this->unk_384 != 1)) { + phi_v1 = true; + } + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF9A0C.s") + case 3: + case 4: + if ((this->unk_384 != 3) && (this->unk_384 != 4)) { + phi_v1 = true; + } + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF9AB0.s") + default: + if (arg1 != this->unk_384) { + phi_v1 = true; + } + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF9B54.s") + if (phi_v1) { + this->unk_384 = arg1; + ret = func_8013BC6C(&this->skelAnime, sAnimations, arg1); + this->unk_35C = this->skelAnime.playSpeed; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF9BF8.s") + return ret; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF9D04.s") +void func_80AF7F68(EnPm* this, GlobalContext* globalCtx) { + f32 temp; + s32 pad; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AF9E7C.s") + switch (this->unk_258) { + case 9: + case 20: + case 21: + case 22: + case 24: + temp = this->colliderSphere.dim.modelSphere.radius * this->colliderSphere.dim.scale; + this->colliderSphere.dim.worldSphere.radius = temp; + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->colliderSphere.base); + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFA170.s") + default: + Collider_UpdateCylinder(&this->actor, &this->colliderCylinder); + temp = this->actor.focus.pos.y - this->actor.world.pos.y; + this->colliderCylinder.dim.height = temp; + CollisionCheck_SetOC(globalCtx, &globalCtx->colChkCtx, &this->colliderCylinder.base); + break; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFA334.s") +Actor* func_80AF8040(EnPm* this, GlobalContext* globalCtx) { + Actor* actor; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFA438.s") + switch (this->unk_258) { + case 16: + actor = func_80AF7CB0(this, globalCtx, ACTORCAT_NPC, ACTOR_EN_AN); + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFA4D0.s") + case 17: + actor = func_80AF7CB0(this, globalCtx, ACTORCAT_NPC, ACTOR_EN_TEST3); + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFA5FC.s") + case 28: + actor = func_80AF7CB0(this, globalCtx, ACTORCAT_NPC, ACTOR_EN_AL); + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFA724.s") + case 3: + case 4: + case 5: + case 6: + case 7: + actor = func_80AF7DC4(this, globalCtx, this->unk_258 - 3); + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/EnPm_Init.s") + case 19: + actor = func_80AF7DC4(this, globalCtx, 4); + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/EnPm_Destroy.s") + case 18: + actor = func_80AF7DC4(this, globalCtx, 4); + break; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/EnPm_Update.s") + default: + actor = &GET_PLAYER(globalCtx)->actor; + break; + } -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFAA04.s") + return actor; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFAA44.s") +s32 func_80AF80F4(EnPm* this, s16 arg1) { + s32 ret = false; -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/func_80AFABAC.s") + if (ActorCutscene_GetCurrentIndex() == 0x7C) { + ActorCutscene_Stop(0x7C); + ActorCutscene_SetIntentToPlay(arg1); + } else if (ActorCutscene_GetCanPlayNext(arg1)) { + ActorCutscene_StartAndSetUnkLinkFields(arg1, &this->actor); + ret = true; + } else { + ActorCutscene_SetIntentToPlay(arg1); + } + return ret; +} -#pragma GLOBAL_ASM("asm/non_matchings/overlays/ovl_En_Pm/EnPm_Draw.s") +s16 func_80AF8170(EnPm* this, s32 arg1) { + s32 i; + s16 cs = -1; + + if ((this->actor.child != NULL) && (this->actor.child->update != NULL)) { + cs = this->actor.child->cutscene; + + for (i = 0; i < arg1; i++) { + cs = ActorCutscene_GetAdditionalCutscene(cs); + } + } + return cs; +} + +s32 func_80AF81E8(EnPm* this, GlobalContext* globalCtx) { + s32 pad; + s16 sp2A = func_80AF8170(this, 0); + s32 ret = false; + + switch (this->unk_378) { + case 0: + if (!func_80AF80F4(this, sp2A)) { + break; + } + + case 2: + case 4: + case 6: + if ((this->actor.child != NULL) && (this->actor.child->update != NULL)) { + func_800E0308(Play_GetCamera(globalCtx, ActorCutscene_GetCurrentCamera(sp2A)), this->actor.child); + } + this->unk_378++; + ret = true; + break; + + case 1: + case 3: + case 5: + if ((gSaveContext.weekEventReg[86] & 8) && (this->unk_378 == 3)) { + ActorCutscene_Stop(sp2A); + } else { + func_800E0308(Play_GetCamera(globalCtx, ActorCutscene_GetCurrentCamera(sp2A)), &this->actor); + } + this->unk_378++; + ret = true; + break; + + case 7: + ActorCutscene_Stop(sp2A); + this->unk_378++; + ret = true; + break; + } + return ret; +} + +s32 func_80AF8348(EnPm* this, GlobalContext* globalCtx) { + s32 pad; + s16 sp2A = func_80AF8170(this, 0); + s32 ret = false; + + switch (this->unk_378) { + case 0: + if (!func_80AF80F4(this, sp2A)) { + break; + } + + case 2: + case 4: + case 6: + case 8: + func_800E0308(Play_GetCamera(globalCtx, ActorCutscene_GetCurrentCamera(sp2A)), &this->actor); + this->unk_378++; + ret = true; + break; + + case 1: + case 3: + case 5: + case 7: + if ((this->actor.child != NULL) && (this->actor.child->update != NULL)) { + func_800E0308(Play_GetCamera(globalCtx, ActorCutscene_GetCurrentCamera(sp2A)), this->actor.child); + } + this->unk_378++; + ret = true; + break; + + case 9: + ActorCutscene_Stop(sp2A); + this->unk_378++; + ret = true; + break; + } + + return ret; +} + +s32 func_80AF8478(EnPm* this, GlobalContext* globalCtx) { + s32 pad; + s32 ret = false; + + switch (this->unk_378) { + case 0: + func_80AF7E98(this, 2); + this->unk_356 &= ~0x20; + this->unk_356 |= 0x200; + this->unk_378++; + break; + + case 1: + if (Animation_OnFrame(&this->skelAnime, this->skelAnime.endFrame)) { + func_80AF7E98(this, 4); + this->unk_356 &= ~0x200; + this->unk_356 |= 0x20; + this->unk_378++; + ret = true; + } + break; + } + return ret; +} + +UNK_TYPE* func_80AF8540(EnPm* this, GlobalContext* globalCtx) { + switch (this->unk_258) { + case 28: + this->unk_37C = func_80AF8348; + return D_80AFB6BC; + + case 29: + return D_80AFB710; + + case 16: + this->unk_37C = func_80AF81E8; + return D_80AFB5A0; + + case 17: + return D_80AFB644; + + case 24: + if (this->unk_356 & 0x2000) { + this->unk_37C = func_80AF8478; + return D_80AFB74C; + } else if (this->unk_356 & 0x4000) { + return D_80AFB764; + } else { + this->unk_37C = func_80AF8478; + return D_80AFB658; + } + break; + + case 25: + return D_80AFB650; + + default: + if (Player_GetMask(globalCtx) == PLAYER_MASK_KAFEI) { + return D_80AFB744; + } + + switch (this->unk_258) { + case 9: + return D_80AFB614; + + case 14: + return D_80AFB624; + + case 20: + return D_80AFB61C; + + case 21: + return D_80AFB634; + + case 22: + return D_80AFB63C; + + case 18: + case 74: + case 75: + case 76: + case 77: + case 78: + case 79: + return D_80AFB62C; + + default: + return D_80AFB60C; + } + break; + } +} + +s32 func_80AF86F0(EnPm* this, GlobalContext* globalCtx) { + s32 ret = false; + + if ((this->unk_356 & 7) && func_800B84D0(&this->actor, globalCtx)) { + func_8013AED4(&this->unk_356, 0, 7); + this->unk_398 = 0; + this->unk_378 = 0; + this->unk_37C = NULL; + this->actor.child = this->unk_268; + this->unk_25C = func_80AF8540(this, globalCtx); + if ((this->unk_258 != 24) && (this->unk_258 != 9) && (this->unk_258 != 20) && (this->unk_258 != 21) && + (this->unk_258 != 22)) { + this->unk_356 |= 0x20; + } + this->actionFunc = func_80AFA5FC; + ret = true; + } + return ret; +} + +s32 func_80AF87C4(EnPm* this, GlobalContext* globalCtx) { + s32 ret = false; + + if ((globalCtx->csCtx.state != 0) && (globalCtx->sceneNum == SCENE_00KEIKOKU) && + (gSaveContext.sceneSetupIndex == 9) && (globalCtx->curSpawn == 1)) { + if (!this->unk_380) { + func_80AF7E98(this, 0); + this->unk_258 = 255; + this->unk_380 = true; + this->actor.speedXZ = 4.0f; + this->actor.gravity = -1.0f; + } + ret = true; + } else if (this->unk_380) { + this->unk_258 = 0; + this->unk_380 = false; + this->actor.speedXZ = 0.0f; + } + return ret; +} + +void func_80AF8890(EnPm* this, Gfx** gfx, s32 arg2) { + Matrix_StatePush(); + + switch (arg2) { + case 0: + if (this->unk_356 & 0x800) { + gSPDisplayList((*gfx)++, D_06008348); + } + break; + + case 1: + if (this->unk_356 & 0x1000) { + gSPDisplayList((*gfx)++, D_060085C8); + } + break; + + case 2: + if (this->unk_356 & 0x1000) { + gSPDisplayList((*gfx)++, D_060083E0); + } + break; + } + + Matrix_StatePop(); +} + +void func_80AF898C(EnPm* this) { + s32 pad; + Vec3f sp40; + Vec3f sp34; + s32 pad2; + + Math_Vec3f_Copy(&sp40, &this->unk_268->world.pos); + Math_Vec3f_Copy(&sp34, &this->actor.world.pos); + Math_ApproachS(&this->unk_372, Math_Vec3f_Yaw(&sp34, &sp40) - this->actor.shape.rot.y, 4, 0x2AA8); + this->unk_372 = CLAMP(this->unk_372, -0x1FFE, 0x1FFE); + Math_Vec3f_Copy(&sp34, &this->actor.focus.pos); + if (this->unk_268->id == ACTOR_PLAYER) { + sp40.y = ((Player*)this->unk_268)->bodyPartsPos[7].y + 3.0f; + } else { + Math_Vec3f_Copy(&sp40, &this->unk_268->focus.pos); + } + Math_ApproachS(&this->unk_370, Math_Vec3f_Pitch(&sp34, &sp40), 4, 0x2AA8); + this->unk_370 = CLAMP(this->unk_370, -0x1554, 0x1554); +} + +void func_80AF8AC8(EnPm* this) { + if ((this->unk_356 & 0x20) && (this->unk_268 != NULL) && (this->unk_268->update != NULL)) { + if (DECR(this->unk_376) == 0) { + func_80AF898C(this); + this->unk_356 &= ~0x200; + this->unk_356 |= 0x80; + return; + } + } + + if (this->unk_356 & 0x80) { + this->unk_356 &= ~0x80; + this->unk_370 = 0; + this->unk_372 = 0; + this->unk_376 = 20; + } else if (DECR(this->unk_376) == 0) { + this->unk_356 |= 0x200; + } +} + +void func_80AF8BA8(s32 arg0) { + static u16 D_80AFB8D4[] = { + 0x1B02, 0x1B04, 0x1B08, 0x1B10, 0x1B20, 0x0000, + }; + static u16 D_80AFB8E0[] = { + 0x1B40, 0x1B80, 0x1C01, 0x1C02, 0x1C04, 0x0000, + }; + s32 temp; + + if (!(gSaveContext.weekEventReg[88] & 2)) { + if (gSaveContext.weekEventReg[D_80AFB8D4[arg0] >> 8] & (D_80AFB8D4[arg0] & 0xFF)) { + switch (gSaveContext.day) { + case 2: + gSaveContext.weekEventReg[28] |= 8; + break; + + case 3: + gSaveContext.weekEventReg[28] |= 0x10; + break; + } + gSaveContext.weekEventReg[51] |= 2; + gSaveContext.weekEventReg[90] |= 8; + } + } + + temp = gSaveContext.weekEventReg[D_80AFB8E0[arg0] >> 8]; + gSaveContext.weekEventReg[D_80AFB8E0[arg0] >> 8] = temp | (D_80AFB8E0[arg0] & 0xFF); +} + +void func_80AF8C68(EnPm* this, GlobalContext* globalCtx) { + Player* player = GET_PLAYER(globalCtx); + s32 sp28 = func_80152498(&globalCtx->msgCtx); + u16 temp_a0 = globalCtx->msgCtx.unk11F04; + + if ((player->targetActor == &this->actor) && ((temp_a0 < 255) || (temp_a0 > 512)) && (sp28 == 3) && + (this->unk_388 == 3)) { + if ((globalCtx->state.frames % 3) == 0) { + if (this->unk_360 == 120.0f) { + this->unk_360 = 0.0f; + } else { + this->unk_360 = 120.0f; + } + } + } else { + this->unk_360 = 0.0f; + } + Math_SmoothStepToF(&this->unk_364, this->unk_360, 0.8f, 40.0f, 10.0f); + Matrix_InsertTranslation(this->unk_364, 0.0f, 0.0f, 1); + this->unk_388 = sp28; +} + +s32 func_80AF8D84(EnPm* this, GlobalContext* globalCtx) { + switch (this->unk_384) { + case 10: + func_80AF7E98(this, 9); + break; + + case 7: + func_80AF7E98(this, 0); + break; + } + return true; +} + +s32 func_80AF8DD4(EnPm* this, GlobalContext* globalCtx) { + Player* player = GET_PLAYER(globalCtx); + u16 temp = globalCtx->msgCtx.unk11F04; + s32 pad; + + if (player->stateFlags1 & (0x400 | 0x40)) { + this->unk_356 |= 0x400; + if (this->unk_358 != temp) { + if ((this->unk_384 == 0) || (this->unk_384 == 1)) { + func_80AF7E98(this, 7); + } + if ((temp == 0x277C) || (temp == 0x277D)) { + func_80AF7E98(this, 10); + } + } + this->unk_358 = temp; + } else { + if (this->unk_356 & 0x400) { + this->unk_358 = 0; + this->unk_356 &= ~0x400; + func_80AF8D84(this, globalCtx); + } + } + + if (this->unk_18C != NULL) { + this->unk_18C(this, globalCtx); + } + + return 0; +} + +s32 func_80AF8ED4(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2, u8 actorCat, s16 actorId) { + u8 sp4F = this->actor.params & 0xFF; + Vec3s* sp48; + Vec3f sp3C; + Vec3f sp30; + Actor* sp2C; + s32 pad; + s32 ret = false; + + this->unk_234 = NULL; + sp2C = func_80AF7CB0(this, globalCtx, actorCat, actorId); + if (D_80AFB430[arg2->unk0] >= 0) { + this->unk_234 = func_8013BB34(globalCtx, sp4F, D_80AFB430[arg2->unk0]); + } + + if ((sp2C != NULL) && (sp2C->update != NULL)) { + if (this->unk_234 != NULL) { + sp48 = (Vec3s*)Lib_SegmentedToVirtual(this->unk_234->points); + Math_Vec3s_ToVec3f(&sp3C, &sp48[this->unk_234->count - 2]); + Math_Vec3s_ToVec3f(&sp30, &sp48[this->unk_234->count - 1]); + this->actor.shape.shadowDraw = NULL; + this->actor.world.rot.y = Math_Vec3f_Yaw(&sp3C, &sp30); + Math_Vec3f_Copy(&this->actor.world.pos, &sp30); + ret = true; + } + } + + return ret; +} + +s32 func_80AF9008(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + u16 sp56 = gSaveContext.time - 0x3FFC; + u8 sp55 = this->actor.params & 0xFF; + Actor* sp50; + Vec3s* sp4C; + Vec3f sp40; + Vec3f sp34; + s16 temp; + s32 ret = false; + + this->unk_234 = NULL; + sp50 = func_80AF7D60(globalCtx, arg2->unk0); + if (D_80AFB430[arg2->unk0] >= 0) { + this->unk_234 = func_8013BB34(globalCtx, sp55, D_80AFB430[arg2->unk0]); + } + + if ((sp50 != NULL) && (sp50->update != NULL)) { + if (this->unk_234 != 0) { + sp4C = (Vec3s*)Lib_SegmentedToVirtual(this->unk_234->points); + Math_Vec3s_ToVec3f(&sp40, &sp4C[0]); + Math_Vec3s_ToVec3f(&sp34, &sp4C[1]); + Math_Vec3f_Copy(&this->unk_26C, &sp40); + Math_Vec3f_Copy(&this->unk_278, &sp34); + this->actor.world.rot.y = Math_Vec3f_Yaw(&sp40, &sp34); + Math_Vec3f_Copy(&this->actor.world.pos, &sp40); + temp = this->actor.world.rot.y - sp50->shape.rot.y; + if (ABS_ALT(temp) <= 0x4000) { + this->unk_260 = -0x4B; + } else { + this->unk_260 = 0x4B; + } + + this->unk_36C = arg2->unk8 - arg2->unk4; + this->unk_36E = sp56 - arg2->unk4; + this->actor.flags &= ~1; + if (gSaveContext.weekEventReg[90] & 8) { + this->unk_356 |= 0x800; + } + this->unk_356 |= 0x9000; + this->unk_356 |= 0x200; + func_80AF7E98(this, 0); + this->actor.gravity = 0.0f; + ret = true; + } + } + return ret; +} + +s32 func_80AF91E8(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + u16 sp2E = (u16)(gSaveContext.time - 0x3FFC); + u16 phi_v1; + u8 sp2B = this->actor.params & 0xFF; + s32 pad; + s32 ret = false; + + this->unk_234 = NULL; + + if (D_80AFB430[arg2->unk0] >= 0) { + this->unk_234 = func_8013BB34(globalCtx, sp2B, D_80AFB430[arg2->unk0]); + } + + if ((this->unk_234 != NULL) && (this->unk_234->count < 3)) { + this->unk_234 = NULL; + } + + if (this->unk_234 != 0) { + if ((this->unk_258 < 38) && (this->unk_258 != 0) && (this->unk_374 >= 0)) { + phi_v1 = sp2E; + } else { + phi_v1 = arg2->unk4; + } + + if (arg2->unk8 < phi_v1) { + this->unk_248 = (phi_v1 - arg2->unk8) + 0xFFFF; + } else { + this->unk_248 = arg2->unk8 - phi_v1; + } + + this->unk_254 = sp2E - phi_v1; + phi_v1 = this->unk_234->count - 2; + this->unk_24C = this->unk_248 / phi_v1; + this->unk_250 = (this->unk_254 / this->unk_24C) + 2; + this->unk_356 &= ~8; + this->unk_356 &= ~0x10; + if (this->unk_258 == 27) { + Audio_PlayActorSound2(&this->actor, NA_SE_EV_ROOM_CARTAIN); + Actor_UnsetSwitchFlag(globalCtx, 0); + } + + switch (arg2->unk0) { + case 83: + case 84: + case 85: + case 86: + case 87: + case 88: + case 89: + case 90: + this->unk_356 |= 0x9000; + this->unk_356 |= 0x200; + + case 82: + func_80AF7E98(this, 0); + break; + + case 91: + this->unk_356 |= 0x9000; + func_80AF7E98(this, 12); + break; + + default: + func_8013AED4(&this->unk_356, 3, 7); + func_80AF7E98(this, 0); + if (gSaveContext.weekEventReg[90] & 8) { + this->unk_356 |= 0x800; + } + this->unk_356 |= 0x9000; + this->unk_356 |= 0x200; + break; + } + + this->actor.gravity = -1.0f; + ret = true; + } + + return ret; +} + +s32 func_80AF94AC(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + u8 sp4F = this->actor.params & 0xFF; + Vec3f sp40; + Vec3f sp34; + Vec3s* sp30; + s32 pad; + s32 ret = false; + + this->unk_234 = NULL; + if (D_80AFB430[arg2->unk0] >= 0) { + this->unk_234 = func_8013BB34(globalCtx, sp4F, D_80AFB430[arg2->unk0]); + } + + if ((this->unk_234 != 0) && (this->unk_234->count >= 2)) { + sp30 = (Vec3s*)Lib_SegmentedToVirtual(this->unk_234->points); + Math_Vec3s_ToVec3f(&sp40, &sp30[0]); + Math_Vec3s_ToVec3f(&sp34, &sp30[1]); + this->actor.world.rot.y = Math_Vec3f_Yaw(&sp40, &sp34); + Math_Vec3s_Copy(&this->actor.shape.rot, &this->actor.world.rot); + Math_Vec3f_Copy(&this->actor.world.pos, &sp40); + Math_Vec3f_Copy(&this->actor.prevPos, &sp40); + if (arg2->unk0 == 24) { + Actor_UnsetSwitchFlag(globalCtx, 0); + Actor_UnsetSwitchFlag(globalCtx, 1); + this->unk_394 = 0; + this->unk_368 = 60.0f; + func_80AF7E98(this, 9); + } + ret = true; + } + return ret; +} + +s32 func_80AF95E8(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + u8 sp4F = this->actor.params & 0xFF; + Vec3f sp40; + Vec3f sp34; + Vec3s* sp30; + s32 pad; + s32 ret = false; + s32 phi_a3 = -1; + + switch (arg2->unk0) { + case 3: + case 4: + case 5: + case 6: + case 7: + phi_a3 = arg2->unk0 - 3; + break; + + case 19: + phi_a3 = 4; + break; + } + + if ((phi_a3 >= 0) && !func_80AF7DC4(this, globalCtx, phi_a3)) { + return ret; + } + + this->unk_234 = NULL; + phi_a3 = D_80AFB430[arg2->unk0]; + if (phi_a3 >= 0) { + this->unk_234 = func_8013BB34(globalCtx, sp4F, phi_a3); + } + + if ((this->unk_234 != 0) && (this->unk_234->count >= 2)) { + sp30 = (Vec3s*)Lib_SegmentedToVirtual(this->unk_234->points); + Math_Vec3s_ToVec3f(&sp40, &sp30[this->unk_234->count - 1]); + Math_Vec3s_ToVec3f(&sp34, &sp30[this->unk_234->count - 2]); + this->actor.world.rot.y = Math_Vec3f_Yaw(&sp34, &sp40); + Math_Vec3s_Copy(&this->actor.shape.rot, &this->actor.world.rot); + Math_Vec3f_Copy(&this->actor.world.pos, &sp40); + Math_Vec3f_Copy(&this->actor.prevPos, &sp40); + + switch (arg2->unk0) { + case 27: + Audio_PlayActorSound2(&this->actor, NA_SE_EV_ROOM_CARTAIN); + Actor_SetSwitchFlag(globalCtx, 0); + this->unk_36C = 20; + func_8013AED4(&this->unk_356, 3, 7); + func_80AF7E98(this, 3); + break; + + case 3: + case 4: + case 5: + case 6: + case 7: + case 19: + this->unk_356 |= 0x9000; + func_80AF7E98(this, 11); + break; + + case 18: + this->unk_356 |= 0x9000; + this->unk_356 |= 0x800; + func_80AF7E98(this, 5); + break; + + case 23: + if (gSaveContext.weekEventReg[90] & 8) { + this->unk_356 |= 0x800; + } + gSaveContext.weekEventReg[60] |= 4; + + default: + if (arg2->unk0 == 0x1D) { + this->actor.world.rot.y = BINANG_ROT180(this->actor.world.rot.y); + } + func_8013AED4(&this->unk_356, 3, 7); + this->unk_356 |= 0x9000; + func_80AF7E98(this, 3); + break; + } + ret = true; + } + return ret; +} + +s32 func_80AF98A0(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + s32 ret = false; + + if (Actor_SpawnAsChild(&globalCtx->actorCtx, &this->actor, globalCtx, ACTOR_EN_MM3, 116.0f, 26.0f, -219.0f, 0, + -0x3F46, 0, 0) != NULL) { + Actor_MarkForDeath(&this->actor); + ret = true; + } + return ret; +} + +s32 func_80AF992C(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + static Vec3f D_80AFB8EC = { 116.0f, 26.0f, -219.0f }; + static Vec3s D_80AFB8F8 = { 0x0000, 0xC0BA, 0x0000 }; + s32 pad; + + Math_Vec3f_Copy(&this->actor.world.pos, &D_80AFB8EC); + Math_Vec3s_Copy(&this->actor.world.rot, &D_80AFB8F8); + Math_Vec3s_Copy(&this->actor.shape.rot, &this->actor.world.rot); + func_8013AED4(&this->unk_356, 3, 7); + this->actor.targetMode = 6; + this->actor.gravity = -1.0f; + this->unk_368 = 80.0f; + if (arg2->unk0 == 14) { + this->unk_356 &= ~0x200; + func_80AF7E98(this, 13); + } else { + this->unk_356 &= ~0x200; + func_80AF7E98(this, 8); + } + return true; +} + +s32 func_80AF9A0C(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + s32 ret = false; + + if (func_80AF8ED4(this, globalCtx, arg2, ACTORCAT_NPC, ACTOR_EN_AN)) { + func_8013AED4(&this->unk_356, 3, 7); + this->unk_356 |= 0x20; + this->unk_356 |= 0x9000; + if (this->unk_258 != 0) { + this->unk_356 |= 0x800; + func_80AF7E98(this, 5); + } else { + func_80AF7E98(this, 3); + } + ret = true; + } + return ret; +} + +s32 func_80AF9AB0(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + s32 ret = false; + + if (func_80AF8ED4(this, globalCtx, arg2, ACTORCAT_NPC, ACTOR_EN_TEST3)) { + func_8013AED4(&this->unk_356, 3, 7); + this->unk_356 |= 0x20; + this->unk_356 |= 0x9000; + if (this->unk_258 != 0) { + this->unk_356 |= 0x800; + func_80AF7E98(this, 5); + } else { + func_80AF7E98(this, 3); + } + ret = true; + } + return ret; +} + +s32 func_80AF9B54(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + s32 ret = false; + + if (func_80AF8ED4(this, globalCtx, arg2, ACTORCAT_NPC, ACTOR_EN_AL)) { + func_8013AED4(&this->unk_356, 3, 7); + this->unk_356 |= 0x9000; + this->unk_356 |= 0x20; + if (this->unk_258 != 0) { + this->unk_356 |= 0x800; + func_80AF7E98(this, 5); + } else { + func_80AF7E98(this, 3); + } + ret = true; + } + return ret; +} + +s32 func_80AF9BF8(EnPm* this, GlobalContext* globalCtx, struct_80133038_arg2* arg2) { + s32 ret; + + this->actor.flags |= 1; + this->actor.targetMode = 0; + this->unk_394 = 0; + this->unk_356 = 0; + this->unk_368 = 40.0f; + + switch (arg2->unk0) { + case 16: + ret = func_80AF9A0C(this, globalCtx, arg2); + break; + + case 17: + ret = func_80AF9AB0(this, globalCtx, arg2); + break; + + case 28: + ret = func_80AF9B54(this, globalCtx, arg2); + break; + + case 24: + ret = func_80AF94AC(this, globalCtx, arg2); + break; + + case 29: + ret = func_80AF95E8(this, globalCtx, arg2); + break; + + case 1: + case 2: + case 10: + case 11: + case 12: + case 13: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + ret = func_80AF9008(this, globalCtx, arg2); + break; + + case 3: + case 4: + case 5: + case 6: + case 7: + case 18: + case 19: + case 23: + case 25: + case 27: + ret = func_80AF95E8(this, globalCtx, arg2); + break; + + case 8: + ret = func_80AF98A0(this, globalCtx, arg2); + break; + + case 9: + case 14: + case 20: + case 21: + case 22: + ret = func_80AF992C(this, globalCtx, arg2); + break; + + case 38: + case 39: + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + case 48: + case 49: + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 62: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + case 70: + case 71: + case 72: + case 73: + case 74: + case 75: + case 76: + case 77: + case 78: + case 79: + case 80: + case 81: + case 82: + case 83: + case 84: + case 85: + case 86: + case 87: + case 88: + case 89: + case 90: + case 91: + ret = func_80AF91E8(this, globalCtx, arg2); + break; + + default: + ret = false; + break; + } + return ret; +} + +s32 func_80AF9D04(EnPm* this, GlobalContext* globalCtx) { + EnDoor* sp44 = (EnDoor*)func_80AF7D60(globalCtx, this->unk_258); + Vec3f sp38; + Vec3f* sp28; + f32 temp; + + if (!func_8013AD6C(globalCtx) && (this->unk_374 != 0)) { + if ((sp44 != NULL) && (sp44->actor.update != NULL)) { + if (((f32)this->unk_36E / this->unk_36C) <= 0.9f) { + sp44->unk1A7 = this->unk_260; + } else { + sp44->unk1A7 = 0; + } + } + this->unk_36E = CLAMP(this->unk_36E, 0, this->unk_36C); + temp = Math_Vec3f_DistXZ(&this->unk_26C, &this->unk_278) / this->unk_36C; + sp38.x = 0.0f; + sp38.y = 0.0f; + sp38.z = this->unk_36E * temp; + Lib_Vec3f_TranslateAndRotateY(&this->unk_26C, this->actor.world.rot.y, &sp38, &this->actor.world.pos); + this->unk_36E += this->unk_374; + if (Animation_OnFrame(&this->skelAnime, 3.0f) || Animation_OnFrame(&this->skelAnime, 8.0f)) { + Audio_PlayActorSound2(&this->actor, NA_SE_EV_POSTMAN_WALK); + } + } + return false; +} + +s32 func_80AF9E7C(EnPm* this, GlobalContext* globalCtx) { + f32 sp7C[265]; + Vec3f sp70; + Vec3f sp64; + Vec3f sp58; + s32 sp54; + s32 sp50; + + sp50 = 0; + sp54 = 0; + + func_8013AF00(sp7C, 3, this->unk_234->count + 3); + if (!(this->unk_356 & 8)) { + sp58 = D_801D15B0; + func_8013B6B0(this->unk_234, &this->unk_244, &this->unk_254, this->unk_24C, this->unk_248, &this->unk_250, sp7C, + &sp58, this->unk_374); + func_8013B878(globalCtx, this->unk_234, this->unk_250, &sp58); + this->actor.world.pos.y = sp58.y; + this->unk_356 |= 8; + } else { + sp58 = this->unk_238; + } + + this->actor.world.pos.x = sp58.x; + this->actor.world.pos.z = sp58.z; + + if (func_8013AD6C(globalCtx)) { + sp54 = this->unk_254; + sp50 = this->unk_250; + sp58 = this->actor.world.pos; + } + + this->unk_238 = D_801D15B0; + + if (func_8013B6B0(this->unk_234, &this->unk_244, &this->unk_254, this->unk_24C, this->unk_248, &this->unk_250, sp7C, + &this->unk_238, this->unk_374)) { + this->unk_356 |= 0x10; + } else { + sp70 = this->actor.world.pos; + sp64 = this->unk_238; + this->actor.world.rot.y = Math_Vec3f_Yaw(&sp70, &sp64); + } + + if (func_8013AD6C(globalCtx)) { + this->unk_254 = sp54; + this->unk_250 = sp50; + this->unk_238 = sp58; + } else if ((this->unk_258 != 91) && + (Animation_OnFrame(&this->skelAnime, 3.0f) || Animation_OnFrame(&this->skelAnime, 8.0f))) { + Audio_PlayActorSound2(&this->actor, NA_SE_EV_POSTMAN_WALK); + } + + if ((this->unk_356 & 0x10) && (this->unk_258 == 90)) { + u8 val = gSaveContext.weekEventReg[89] | 0x40; + + gSaveContext.weekEventReg[89] = val; + if (val == 0) { + gSaveContext.weekEventReg[89] |= 0x40; + } + } + + return false; +} + +s32 func_80AFA170(EnPm* this, GlobalContext* globalCtx) { + Vec3f sp34; + Vec3f sp28; + + switch (this->unk_258) { + case 28: + if (gSaveContext.time >= CLOCK_TIME(1, 39)) { + gSaveContext.weekEventReg[89] |= 8; + } + + case 16: + case 17: + case 18: + if ((this->unk_384 == 5) && Animation_OnFrame(&this->skelAnime, this->skelAnime.endFrame)) { + func_80AF7E98(this, 6); + this->unk_36C = 40; + } else if ((this->unk_384 == 6) && (DECR(this->unk_36C) == 0)) { + this->unk_356 &= ~0x800; + func_80AF7E98(this, 4); + } + break; + + case 3: + case 4: + case 5: + case 6: + case 7: + case 19: + if ((this->unk_384 == 11) && Animation_OnFrame(&this->skelAnime, this->skelAnime.endFrame)) { + func_80AF7E98(this, 4); + } + + if ((this->unk_384 == 11) && Animation_OnFrame(&this->skelAnime, 8.0f)) { + Audio_PlayActorSound2(&this->actor, NA_SE_EV_POSTMACHINE_HIT_OPEN); + } + + if (this->unk_258 == 19) { + func_80AF8BA8(4); + } else { + func_80AF8BA8(this->unk_258 - 3); + } + break; + } + + if ((this->unk_268 != NULL) && (this->unk_268->update != NULL)) { + Math_Vec3f_Copy(&sp34, &this->unk_268->world.pos); + Math_Vec3f_Copy(&sp28, &this->actor.world.pos); + this->actor.world.rot.y = Math_Vec3f_Yaw(&sp28, &sp34); + } + + return true; +} + +s32 func_80AFA334(EnPm* this, GlobalContext* globalCtx) { + s16 temp_v0; + + switch (this->unk_258) { + case 14: + case 24: + temp_v0 = this->actor.yawTowardsPlayer - this->actor.shape.rot.y; + if (ABS_ALT(temp_v0) < 0x4000) { + func_8013AED4(&this->unk_356, 3, 7); + } else { + func_8013AED4(&this->unk_356, 0, 7); + } + break; + + case 27: + if (DECR(this->unk_36C) == 0) { + Actor_SetSwitchFlag(globalCtx, 1); + } + break; + + case 9: + case 20: + case 21: + case 22: + if (Animation_OnFrame(&this->skelAnime, 0.0f)) { + Audio_PlayActorSound2(&this->actor, NA_SE_VO_NP_SLEEP_OUT); + } + break; + + case 29: + break; + } + + return false; +} + +void func_80AFA438(EnPm* this, GlobalContext* globalCtx) { + switch (this->unk_258) { + case 3: + case 4: + case 5: + case 6: + case 7: + case 16: + case 17: + case 18: + case 28: + func_80AFA170(this, globalCtx); + break; + + case 1: + case 2: + case 10: + case 11: + case 12: + case 13: + case 32: + case 33: + case 34: + case 35: + case 36: + case 37: + func_80AF9D04(this, globalCtx); + break; + + case 9: + case 14: + case 20: + case 21: + case 22: + case 23: + case 24: + case 25: + case 27: + case 29: + func_80AFA334(this, globalCtx); + break; + + case 38: + case 39: + case 40: + case 41: + case 42: + case 43: + case 44: + case 45: + case 46: + case 47: + case 48: + case 49: + case 50: + case 51: + case 52: + case 53: + case 54: + case 55: + case 56: + case 57: + case 58: + case 59: + case 60: + case 61: + case 62: + case 63: + case 64: + case 65: + case 66: + case 67: + case 68: + case 69: + case 70: + case 71: + case 72: + case 73: + case 74: + case 75: + case 76: + case 77: + case 78: + case 79: + case 80: + case 81: + case 82: + case 83: + case 84: + case 85: + case 86: + case 87: + case 88: + case 89: + case 90: + case 91: + func_80AF9E7C(this, globalCtx); + break; + } + + Math_ApproachS(&this->actor.shape.rot.y, this->actor.world.rot.y, 3, 0x2AA8); +} + +void func_80AFA4D0(EnPm* this, GlobalContext* globalCtx) { + static UNK_PTR D_80AFB900[] = { + D_80AFAD80, D_80AFB30C, D_80AFB3C0, D_80AFB3FC, D_80AFB41C, + }; + u16 time = gSaveContext.time; + u16 sp3C = 0; + u32* unk_14 = &gSaveContext.unk_14; + struct_80133038_arg2 sp2C; + + this->unk_374 = REG(15) + *unk_14; + if (this->unk_38C != 0) { + time = gSaveContext.time - D_801F4E78; + sp3C = gSaveContext.time; + gSaveContext.time = time; + } + + if (!func_80133038(globalCtx, D_80AFB900[this->unk_38C], &sp2C) || + ((this->unk_258 != sp2C.unk0) && !func_80AF9BF8(this, globalCtx, &sp2C))) { + this->actor.shape.shadowDraw = NULL; + this->actor.flags &= ~1; + sp2C.unk0 = 0; + } else { + this->actor.shape.shadowDraw = func_800B3FC0; + this->actor.flags |= 1; + } + + this->unk_258 = sp2C.unk0; + this->unk_268 = func_80AF8040(this, globalCtx); + func_80AFA438(this, globalCtx); + if (this->unk_38C != 0) { + gSaveContext.time = sp3C; + } +} + +void func_80AFA5FC(EnPm* this, GlobalContext* globalCtx) { + s16 yaw; + Vec3f sp38; + Vec3f sp2C; + + if (func_8010BF58(&this->actor, globalCtx, this->unk_25C, this->unk_37C, &this->unk_264)) { + func_8013AED4(&this->unk_356, 3, 7); + this->unk_356 &= ~0x20; + this->unk_356 |= 0x200; + this->actor.child = NULL; + this->unk_376 = 20; + this->unk_264 = 0; + this->actionFunc = func_80AFA4D0; + return; + } + + if ((this->unk_258 != 9) && (this->unk_258 != 14) && (this->unk_258 != 16) && (this->unk_258 != 17) && + (this->unk_258 != 20) && (this->unk_258 != 21) && (this->unk_258 != 22) && (this->unk_258 != 24) && + (this->unk_258 != 25)) { + if ((this->unk_268 != NULL) && (this->unk_268->update != NULL)) { + Math_Vec3f_Copy(&sp38, &this->unk_268->world.pos); + Math_Vec3f_Copy(&sp2C, &this->actor.world.pos); + yaw = Math_Vec3f_Yaw(&sp2C, &sp38); + Math_ApproachS(&this->actor.shape.rot.y, yaw, 4, 0x2AA8); + } + } +} + +void func_80AFA724(EnPm* this, GlobalContext* globalCtx) { + Actor_SetVelocityAndMoveYRotationAndGravity(&this->actor); + Actor_UpdateBgCheckInfo(globalCtx, &this->actor, 30.0f, 12.0f, 0.0f, 4); + if (Animation_OnFrame(&this->skelAnime, 3.0f) || Animation_OnFrame(&this->skelAnime, 8.0f)) { + Audio_PlayActorSound2(&this->actor, NA_SE_EV_POSTMAN_WALK); + } +} + +void EnPm_Init(Actor* thisx, GlobalContext* globalCtx) { + EnPm* this = THIS; + + ActorShape_Init(&this->actor.shape, 0.0f, NULL, 14.0f); + SkelAnime_InitFlex(globalCtx, &this->skelAnime, &D_060096E8, NULL, this->jointTable, this->morphTable, 16); + this->unk_384 = -1; + func_80AF7E98(this, 0); + Collider_InitAndSetCylinder(globalCtx, &this->colliderCylinder, &this->actor, &sCylinderInit); + Collider_InitAndSetSphere(globalCtx, &this->colliderSphere, &this->actor, &sSphereInit); + CollisionCheck_SetInfo2(&this->actor.colChkInfo, DamageTable_Get(0x16), &sColChkInfoInit); + Actor_SetScale(&this->actor, 0.01f); + this->unk_38C = func_80AF7B40(); + this->unk_258 = 0; + this->unk_356 = 0; + this->actionFunc = func_80AFA4D0; + this->actionFunc(this, globalCtx); +} + +void EnPm_Destroy(Actor* thisx, GlobalContext* globalCtx) { + EnPm* this = THIS; + + Collider_DestroyCylinder(globalCtx, &this->colliderCylinder); + Collider_DestroySphere(globalCtx, &this->colliderSphere); +} + +void EnPm_Update(Actor* thisx, GlobalContext* globalCtx) { + EnPm* this = THIS; + + if (!func_80AF86F0(this, globalCtx) && func_80AF87C4(this, globalCtx)) { + func_80AFA724(this, globalCtx); + func_80AF7E6C(this); + func_80AF8AC8(this); + } else { + this->actionFunc(this, globalCtx); + func_80AF7BAC(this); + if (this->unk_258 != 0) { + func_80AF8DD4(this, globalCtx); + func_80AF7E6C(this); + func_80AF8AC8(this); + func_8013C964(&this->actor, globalCtx, this->unk_368, 30.0f, this->unk_394, this->unk_356 & 7); + Actor_SetVelocityAndMoveYRotationAndGravity(&this->actor); + Actor_UpdateBgCheckInfo(globalCtx, &this->actor, 30.0f, 12.0f, 0.0f, 4); + func_80AF7F68(this, globalCtx); + } + } +} + +s32 func_80AFAA04(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3f* pos, Vec3s* rot, Actor* thisx, + Gfx** gfx) { + EnPm* this = THIS; + + if (limbIndex == 15) { + func_80AF8C68(this, globalCtx); + } + return false; +} + +void func_80AFAA44(GlobalContext* globalCtx, s32 limbIndex, Gfx** dList, Vec3s* rot, Actor* thisx, Gfx** gfx) { + EnPm* this = THIS; + s32 pad; + Vec3f sp2C; + + switch (limbIndex) { + case 15: + if (ActorCutscene_GetCurrentIndex() == -1) { + Matrix_MultiplyVector3fByState(&D_801D15B0, &this->actor.focus.pos); + Math_Vec3s_Copy(&this->actor.focus.rot, &this->actor.world.rot); + } + if ((this->unk_356 & 0x8000) && !(gSaveContext.weekEventReg[90] & 4)) { + func_80AF8890(this, gfx, 1); + } + break; + + case 11: + if (this->unk_356 & 0x800) { + func_80AF8890(this, gfx, 0); + } + break; + + case 8: + if ((this->unk_258 == 9) || (this->unk_258 == 20) || (this->unk_258 == 21) || (this->unk_258 == 22)) { + Matrix_MultiplyVector3fByState(&D_801D15B0, &sp2C); + Math_Vec3f_ToVec3s(&this->colliderSphere.dim.worldSphere.center, &sp2C); + } else if (this->unk_258 == 24) { + Matrix_MultiplyVector3fByState(&D_801D15B0, &sp2C); + Math_Vec3f_ToVec3s(&this->colliderSphere.dim.worldSphere.center, &sp2C); + } + func_80AF8890(this, gfx, 2); + break; + } +} + +void func_80AFABAC(GlobalContext* globalCtx, s32 arg1, EnPm* this, Gfx** gfx) { + s32 phi_v0; + s32 phi_v1; + + if (!(this->unk_356 & 0x200)) { + if (this->unk_356 & 0x80) { + phi_v1 = 1; + } else { + phi_v1 = 0; + } + phi_v0 = 1; + } else { + phi_v1 = 0; + phi_v0 = 0; + } + + if (arg1 == 15) { + func_8013AD9C(this->unk_370 + 0x4000, this->unk_372 + this->actor.shape.rot.y + 0x4000, &this->unk_284, + &this->unk_290, phi_v0, phi_v1); + Matrix_StatePop(); + Matrix_InsertTranslation(this->unk_284.x, this->unk_284.y, this->unk_284.z, MTXMODE_NEW); + Matrix_Scale(this->actor.scale.x, this->actor.scale.y, this->actor.scale.z, MTXMODE_APPLY); + Matrix_RotateY(this->unk_290.y, MTXMODE_APPLY); + Matrix_InsertXRotation_s(this->unk_290.x, MTXMODE_APPLY); + Matrix_InsertZRotation_s(this->unk_290.z, MTXMODE_APPLY); + Matrix_StatePush(); + } +} + +void EnPm_Draw(Actor* thisx, GlobalContext* globalCtx) { + static UNK_PTR D_80AFB914[] = { + &D_06002950, + &D_06002750, + }; + EnPm* this = THIS; + s32 pad; + + if (this->unk_258 != 0) { + func_8012C28C(globalCtx->state.gfxCtx); + + OPEN_DISPS(globalCtx->state.gfxCtx); + + Scene_SetRenderModeXlu(globalCtx, 0, 1); + + gSPSegment(POLY_OPA_DISP++, 0x08, Lib_SegmentedToVirtual(D_80AFB914[0])); + + POLY_OPA_DISP = + func_8013AB00(globalCtx, this->skelAnime.skeleton, this->skelAnime.jointTable, this->skelAnime.dListCount, + func_80AFAA04, func_80AFAA44, func_80AFABAC, &this->actor, POLY_OPA_DISP); + + CLOSE_DISPS(globalCtx->state.gfxCtx); + } +} diff --git a/src/overlays/actors/ovl_En_Pm/z_en_pm.h b/src/overlays/actors/ovl_En_Pm/z_en_pm.h index 6e3024bf1..0261221d7 100644 --- a/src/overlays/actors/ovl_En_Pm/z_en_pm.h +++ b/src/overlays/actors/ovl_En_Pm/z_en_pm.h @@ -6,12 +6,56 @@ struct EnPm; typedef void (*EnPmActionFunc)(struct EnPm*, GlobalContext*); +typedef s32 (*EnPmFunc)(struct EnPm*, GlobalContext*); +typedef s32 (*EnPmFunc2)(struct EnPm*, GlobalContext*); typedef struct EnPm { /* 0x0000 */ Actor actor; - /* 0x0144 */ char unk_144[0x44]; + /* 0x0144 */ SkelAnime skelAnime; /* 0x0188 */ EnPmActionFunc actionFunc; - /* 0x018C */ char unk_18C[0x214]; + /* 0x018C */ EnPmFunc2 unk_18C; + /* 0x0190 */ ColliderCylinder colliderCylinder; + /* 0x01DC */ ColliderSphere colliderSphere; + /* 0x0234 */ Path* unk_234; + /* 0x0238 */ Vec3f unk_238; + /* 0x0244 */ s32 unk_244; + /* 0x0248 */ s32 unk_248; + /* 0x024C */ s32 unk_24C; + /* 0x0250 */ s32 unk_250; + /* 0x0254 */ s32 unk_254; + /* 0x0258 */ u8 unk_258; + /* 0x026C */ UNK_TYPE* unk_25C; + /* 0x0260 */ s8 unk_260; + /* 0x0264 */ s32 unk_264; + /* 0x0268 */ Actor* unk_268; + /* 0x0268 */ Vec3f unk_26C; + /* 0x0278 */ Vec3f unk_278; + /* 0x0284 */ Vec3f unk_284; + /* 0x0290 */ Vec3s unk_290; + /* 0x0296 */ Vec3s jointTable[16]; + /* 0x02F6 */ Vec3s morphTable[16]; + /* 0x0356 */ u16 unk_356; + /* 0x0358 */ u16 unk_358; + /* 0x035C */ f32 unk_35C; + /* 0x0360 */ f32 unk_360; + /* 0x0364 */ f32 unk_364; + /* 0x0368 */ f32 unk_368; + /* 0x036C */ s16 unk_36C; + /* 0x036E */ s16 unk_36E; + /* 0x0370 */ s16 unk_370; + /* 0x0372 */ s16 unk_372; + /* 0x0374 */ s16 unk_374; + /* 0x0376 */ s16 unk_376; + /* 0x0378 */ s16 unk_378; + /* 0x037C */ EnPmFunc unk_37C; + /* 0x0380 */ s32 unk_380; + /* 0x0384 */ s32 unk_384; + /* 0x0388 */ s32 unk_388; + /* 0x038C */ s32 unk_38C; + /* 0x0390 */ UNK_TYPE1 unk390[0x4]; + /* 0x0394 */ s32 unk_394; + /* 0x0398 */ s32 unk_398; + /* 0x039C */ UNK_TYPE1 unk39C[0x4]; } EnPm; // size = 0x3A0 extern const ActorInit En_Pm_InitVars; diff --git a/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c b/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c index 6f6ec34c4..3a8db7839 100644 --- a/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c +++ b/src/overlays/actors/ovl_En_Suttari/z_en_suttari.c @@ -748,20 +748,18 @@ s32 func_80BABF64(EnSuttari* this, GlobalContext* globalCtx, struct_80133038_arg } s32 func_80BABFD4(EnSuttari* this, GlobalContext* globalCtx) { - UNK_TYPE1 sp7C[0x424]; + f32 sp7C[265]; Vec3f sp70; Vec3f sp64; Vec3f sp58; - s32 sp54; - s32 sp50; + s32 sp54 = 0; + s32 sp50 = 0; s32 pad; - sp54 = 0; - sp50 = 0; - func_8013AF00(&sp7C, 3, this->unk404->count + 3); + func_8013AF00(sp7C, 3, this->unk404->count + 3); if (this->unk42C == 0) { sp58 = D_801D15B0; - func_8013B6B0(this->unk404, &this->unk414, &this->unk424, this->unk41C, this->unk418, &this->unk420, &sp7C, + func_8013B6B0(this->unk404, &this->unk414, &this->unk424, this->unk41C, this->unk418, &this->unk420, sp7C, &sp58, this->unk42A); func_8013B878(globalCtx, this->unk404, this->unk420, &sp58); this->actor.world.pos.y = sp58.y; @@ -777,7 +775,7 @@ s32 func_80BABFD4(EnSuttari* this, GlobalContext* globalCtx) { sp58 = this->actor.world.pos; } this->unk408 = D_801D15B0; - if (func_8013B6B0(this->unk404, &this->unk414, &this->unk424, this->unk41C, this->unk418, &this->unk420, &sp7C, + if (func_8013B6B0(this->unk404, &this->unk414, &this->unk424, this->unk41C, this->unk418, &this->unk420, sp7C, &this->unk408, this->unk42A)) { this->unk430 = 1; } else { diff --git a/undefined_syms.txt b/undefined_syms.txt index 058ec41a8..56f4cb1b1 100644 --- a/undefined_syms.txt +++ b/undefined_syms.txt @@ -3187,6 +3187,20 @@ D_06008348 = 0x06008348; D_060083E0 = 0x060083E0; D_060085C8 = 0x060085C8; D_060096E8 = 0x060096E8; +D_06002238 = 0x06002238; +D_0600A4E0 = 0x0600A4E0; +D_0600B09C = 0x0600B09C; +D_0600BA78 = 0x0600BA78; +D_0600C32C = 0x0600C32C; +D_060099B4 = 0x060099B4; +D_06000FC4 = 0x06000FC4; +D_0600A8D8 = 0x0600A8D8; +D_0600099C = 0x0600099C; +D_06001F84 = 0x06001F84; +D_06000468 = 0x06000468; +D_0600C640 = 0x0600C640; +D_06002950 = 0x06002950; +D_06002750 = 0x06002750; // ovl_En_Poh From 0a953f7aeac13df5aad6cfb96e36f88f8cc473ff Mon Sep 17 00:00:00 2001 From: Anghelo Carvajal Date: Sun, 14 Nov 2021 18:38:27 -0300 Subject: [PATCH 5/8] sched.h (#341) * sched.h * format * screen.h * sched.h and scheduler.h * empty commit * remove screen.h * format * Fix * fix bss * remove line * Whoops * remove dupllicated structs * ... * c'mon * Add TASK_FRAMEBUFFER macro * format --- include/PR/sched.h | 38 ++++++++++++++++++ include/irqmgr.h | 27 +++++++++++++ include/macros.h | 6 +++ include/scheduler.h | 47 ++++++++++++++++++++++ include/ultra64/vi.h | 1 + include/variables.h | 1 + include/z64.h | 94 ++------------------------------------------ src/code/sched.c | 6 +-- 8 files changed, 126 insertions(+), 94 deletions(-) create mode 100644 include/PR/sched.h create mode 100644 include/irqmgr.h create mode 100644 include/scheduler.h diff --git a/include/PR/sched.h b/include/PR/sched.h new file mode 100644 index 000000000..d0aac1d0e --- /dev/null +++ b/include/PR/sched.h @@ -0,0 +1,38 @@ +#ifndef SCHED_H +#define SCHED_H + +#include "PR/ultratypes.h" +#include "ultra64/vi.h" +#include "ultra64/sptask.h" + +#define OS_SC_NEEDS_RDP 0x0001 +#define OS_SC_NEEDS_RSP 0x0002 +#define OS_SC_DRAM_DLIST 0x0004 +#define OS_SC_PARALLEL_TASK 0x0010 +#define OS_SC_LAST_TASK 0x0020 +#define OS_SC_SWAPBUFFER 0x0040 + +#define OS_SC_RCP_MASK 0x0003 +#define OS_SC_TYPE_MASK 0x0007 + +#define OS_SC_DP 0x0001 +#define OS_SC_SP 0x0002 +#define OS_SC_YIELD 0x0010 +#define OS_SC_YIELDED 0x0020 + +typedef struct OSScTask { + /* 0x00 */ struct OSScTask* next; + /* 0x04 */ u32 state; + /* 0x08 */ u32 flags; + /* 0x0C */ void* framebuffer; + /* 0x10 */ OSTask list; + /* 0x50 */ OSMesgQueue* msgQ; + /* 0x54 */ OSMesg msg; +} OSScTask; // size = 0x58 + +typedef struct { + /* 0x0 */ s16 type; + /* 0x2 */ u8 misc[30]; +} OSScMsg; + +#endif diff --git a/include/irqmgr.h b/include/irqmgr.h new file mode 100644 index 000000000..40ed322d1 --- /dev/null +++ b/include/irqmgr.h @@ -0,0 +1,27 @@ +#ifndef IRQMGR_H +#define IRQMGR_H + +#include "PR/ultratypes.h" +#include "PR/sched.h" +#include "ultra64/message.h" + +typedef struct IrqMgrClient { + /* 0x0 */ struct IrqMgrClient* next; + /* 0x4 */ OSMesgQueue* queue; +} IrqMgrClient; // size = 0x8 + +typedef struct { + /* 0x000 */ OSScMsg verticalRetraceMesg; + /* 0x020 */ OSScMsg prenmiMsg; + /* 0x040 */ OSScMsg nmiMsg; + /* 0x060 */ OSMesgQueue irqQueue; + /* 0x078 */ OSMesg irqBuffer[8]; + /* 0x098 */ OSThread thread; + /* 0x248 */ IrqMgrClient* callbacks; + /* 0x24C */ u8 prenmiStage; + /* 0x250 */ OSTime lastPrenmiTime; + /* 0x258 */ OSTimer prenmiTimer; + /* 0x278 */ OSTime lastFrameTime; +} IrqMgr; // size = 0x280 + +#endif diff --git a/include/macros.h b/include/macros.h index 6d1e6f4bf..15adcc697 100644 --- a/include/macros.h +++ b/include/macros.h @@ -5,6 +5,12 @@ #include "convert.h" #include "z64.h" +#define SCREEN_WIDTH 320 +#define SCREEN_HEIGHT 240 + +#define SCREEN_WIDTH_HIGH_RES 576 +#define SCREEN_HEIGHT_HIGH_RES 454 + #define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0])) #define ARRAY_COUNTU(arr) (u32)(sizeof(arr) / sizeof(arr[0])) diff --git a/include/scheduler.h b/include/scheduler.h new file mode 100644 index 000000000..3cf588b1f --- /dev/null +++ b/include/scheduler.h @@ -0,0 +1,47 @@ +#ifndef SCHEDULER_H +#define SCHEDULER_H + +#include "PR/ultratypes.h" +#include "PR/sched.h" +#include "ultra64/vi.h" +#include "ultra64/sptask.h" +#include "irqmgr.h" + +#define TASK_FRAMEBUFFER(task) ((CfbInfo*)(task)->framebuffer) + +typedef struct { + /* 0x00 */ u16* fb1; + /* 0x04 */ u16* swapBuffer; + /* 0x08 */ OSViMode* viMode; + /* 0x0C */ u32 features; + /* 0x10 */ u8 unk_10; + /* 0x11 */ s8 updateRate; + /* 0x12 */ s8 updateRate2; + /* 0x13 */ u8 unk_13; + /* 0x14 */ f32 xScale; + /* 0x18 */ f32 yScale; +} CfbInfo; // size = 0x1C + +typedef struct { + /* 0x000 */ OSMesgQueue interruptQ; + /* 0x018 */ OSMesg intBuf[64]; + /* 0x118 */ OSMesgQueue cmdQ; + /* 0x130 */ OSMesg cmdMsgBuf[8]; + /* 0x150 */ OSThread thread; + /* 0x300 */ OSScTask* audioListHead; + /* 0x304 */ OSScTask* gfxListHead; + /* 0x308 */ OSScTask* audioListTail; + /* 0x30C */ OSScTask* gfxListTail; + /* 0x310 */ OSScTask* curRSPTask; + /* 0x314 */ OSScTask* curRDPTask; + /* 0x318 */ s32 retraceCount; + /* 0x318 */ s32 doAudio; + /* 0x320 */ CfbInfo* curBuf; + /* 0x324 */ CfbInfo* pendingSwapBuf1; + /* 0x328 */ CfbInfo* pendingSwapBuf2; + /* 0x32C */ char unk_32C[0x3]; + /* 0x32F */ u8 shouldUpdateVi; + /* 0x330 */ IrqMgrClient irqClient; +} SchedContext; // size = 0x338 + +#endif diff --git a/include/ultra64/vi.h b/include/ultra64/vi.h index 67d7f681d..471665e3e 100644 --- a/include/ultra64/vi.h +++ b/include/ultra64/vi.h @@ -1,6 +1,7 @@ #ifndef _ULTRA64_VI_H_ #define _ULTRA64_VI_H_ +#include "PR/ultratypes.h" #include "ultra64/message.h" /* Special Features */ diff --git a/include/variables.h b/include/variables.h index 14a4f340e..033443d66 100644 --- a/include/variables.h +++ b/include/variables.h @@ -3,6 +3,7 @@ #include "z64.h" #include "segment_symbols.h" +#include "macros.h" // pre-boot variables extern u32 osTvType; diff --git a/include/z64.h b/include/z64.h index 4acffe880..5118d0c35 100644 --- a/include/z64.h +++ b/include/z64.h @@ -13,12 +13,14 @@ #include "io/controller.h" #include "osint.h" #include "os.h" +#include "irqmgr.h" +#include "scheduler.h" #include "xstdio.h" #include "bgm.h" -#include "sfx.h" #include "color.h" #include "ichain.h" +#include "sfx.h" #include "z64actor.h" #include "z64animation.h" @@ -37,12 +39,6 @@ #include "z64transition.h" #include "regs.h" -#define SCREEN_WIDTH 320 -#define SCREEN_HEIGHT 240 - -#define SCREEN_WIDTH_HIGH_RES 576 -#define SCREEN_HEIGHT_HIGH_RES 454 - #define Z_THREAD_ID_IDLE 1 #define Z_THREAD_ID_SLOWLY 2 #define Z_THREAD_ID_MAIN 3 @@ -249,30 +245,6 @@ typedef struct { /* 0x14 */ s16 data[REG_GROUPS * REG_PER_GROUP]; // 0xAE0 entries } GameInfo; // size = 0x15D4 -typedef struct IrqMgrClient { - /* 0x0 */ struct IrqMgrClient* next; - /* 0x4 */ OSMesgQueue* queue; -} IrqMgrClient; // size = 0x8 - -typedef struct { - /* 0x0 */ s16 type; - /* 0x2 */ u8 misc[30]; -} OSScMsg; - -typedef struct { - /* 0x000 */ OSScMsg verticalRetraceMesg; - /* 0x020 */ OSScMsg prenmiMsg; - /* 0x040 */ OSScMsg nmiMsg; - /* 0x060 */ OSMesgQueue irqQueue; - /* 0x078 */ OSMesg irqBuffer[8]; - /* 0x098 */ OSThread thread; - /* 0x248 */ IrqMgrClient* callbacks; - /* 0x24C */ u8 prenmiStage; - /* 0x250 */ OSTime lastPrenmiTime; - /* 0x258 */ OSTimer prenmiTimer; - /* 0x278 */ OSTime lastFrameTime; -} IrqMgr; // size = 0x280 - typedef struct { /* 0x0000 */ u32 size; /* 0x0004 */ void* bufp; @@ -316,44 +288,6 @@ typedef struct { /* 0x20308 */ u16 tailMagic; // 5678 } GfxPool; // size = 0x20310 -typedef struct { - /* 0x00 */ u16* fb1; - /* 0x04 */ u16* swapBuffer; - /* 0x08 */ OSViMode* viMode; - /* 0x0C */ u32 features; - /* 0x10 */ u8 unk_10; - /* 0x11 */ s8 updateRate; - /* 0x12 */ s8 updateRate2; - /* 0x13 */ u8 unk_13; - /* 0x14 */ f32 xScale; - /* 0x18 */ f32 yScale; -} CfbInfo; // size = 0x1C - -#define OS_SC_NEEDS_RDP 0x0001 -#define OS_SC_NEEDS_RSP 0x0002 -#define OS_SC_DRAM_DLIST 0x0004 -#define OS_SC_PARALLEL_TASK 0x0010 -#define OS_SC_LAST_TASK 0x0020 -#define OS_SC_SWAPBUFFER 0x0040 - -#define OS_SC_RCP_MASK 0x0003 -#define OS_SC_TYPE_MASK 0x0007 - -#define OS_SC_DP 0x0001 -#define OS_SC_SP 0x0002 -#define OS_SC_YIELD 0x0010 -#define OS_SC_YIELDED 0x0020 - -typedef struct OSScTask { - /* 0x00 */ struct OSScTask* next; - /* 0x04 */ u32 state; - /* 0x08 */ u32 flags; - /* 0x0C */ CfbInfo* framebuffer; - /* 0x10 */ OSTask list; - /* 0x50 */ OSMesgQueue* msgQ; - /* 0x54 */ OSMesg msg; -} OSScTask; // size = 0x58 - typedef struct GraphicsContext { /* 0x000 */ Gfx* polyOpaBuffer; // Pointer to "Zelda 0" /* 0x004 */ Gfx* polyXluBuffer; // Pointer to "Zelda 1" @@ -392,28 +326,6 @@ typedef struct GraphicsContext { /* 0x2FC */ GfxMasterList* masterList; } GraphicsContext; // size = 0x300 -typedef struct { - /* 0x000 */ OSMesgQueue interruptQ; - /* 0x018 */ OSMesg intBuf[64]; - /* 0x118 */ OSMesgQueue cmdQ; - /* 0x130 */ OSMesg cmdMsgBuf[8]; - /* 0x150 */ OSThread thread; - /* 0x300 */ OSScTask* audioListHead; - /* 0x304 */ OSScTask* gfxListHead; - /* 0x308 */ OSScTask* audioListTail; - /* 0x30C */ OSScTask* gfxListTail; - /* 0x310 */ OSScTask* curRSPTask; - /* 0x314 */ OSScTask* curRDPTask; - /* 0x318 */ s32 retraceCount; - /* 0x318 */ s32 doAudio; - /* 0x320 */ CfbInfo* curBuf; - /* 0x324 */ CfbInfo* pendingSwapBuf1; - /* 0x328 */ CfbInfo* pendingSwapBuf2; - /* 0x32C */ char unk_32C[0x3]; - /* 0x32F */ u8 shouldUpdateVi; - /* 0x330 */ IrqMgrClient irqClient; -} SchedContext; // size = 0x338 - typedef enum IRQ_MSG_TYPE { IRQ_VERTICAL_RETRACE_MSG = 0x1, IRQ_PRENMI_2_MSG = 0x3, diff --git a/src/code/sched.c b/src/code/sched.c index ecd984b05..927a48f66 100644 --- a/src/code/sched.c +++ b/src/code/sched.c @@ -225,7 +225,7 @@ s32 Sched_TaskCheckFramebuffers(SchedContext* sched, OSScTask* task) { void* nextFB = osViGetNextFramebuffer(); void* curFB = osViGetCurrentFramebuffer(); - if (task == NULL || sched->pendingSwapBuf1 != NULL || (curFB == task->framebuffer->fb1 && curFB != nextFB)) { + if (task == NULL || sched->pendingSwapBuf1 != NULL || (curFB == TASK_FRAMEBUFFER(task)->fb1 && curFB != nextFB)) { return 0; } return 1; @@ -257,7 +257,7 @@ s32 Sched_Schedule(SchedContext* sched, OSScTask** spTask, OSScTask** dpTask, s3 } } } else if (ret == (OS_SC_SP | OS_SC_DP)) { - if (gfxTask->framebuffer == NULL || Sched_TaskCheckFramebuffers(sched, gfxTask)) { + if (TASK_FRAMEBUFFER(gfxTask) == NULL || Sched_TaskCheckFramebuffers(sched, gfxTask)) { *spTask = *dpTask = gfxTask; ret &= ~(OS_SC_SP | OS_SC_DP); sched->gfxListHead = sched->gfxListHead->next; @@ -271,7 +271,7 @@ s32 Sched_Schedule(SchedContext* sched, OSScTask** spTask, OSScTask** dpTask, s3 } void Sched_TaskUpdateFramebuffer(SchedContext* sched, OSScTask* task) { - sched->pendingSwapBuf1 = task->framebuffer; + sched->pendingSwapBuf1 = TASK_FRAMEBUFFER(task); if (sched->curBuf != NULL && sched->curBuf->updateRate2 > 0) { return; From 0c3bba3ff6b78e8b03265f01d7ee4cb6bb09d6d3 Mon Sep 17 00:00:00 2001 From: Kenix3 Date: Sun, 14 Nov 2021 17:06:34 -0500 Subject: [PATCH 6/8] Moves func_800CB000 to z_bg_item, decompiles func_800CB000, and documents z_bg_item and a few DynaPolyActor struct members. (#407) * Moves func_800CB000 to z_bg_item, decompiles func_800CB000, and documents z_bg_item and a few DynaPolyActor struct members. * Adding usage of dynapoly state flag defines. * Formats z_bg_item * Update z_bg_item.c * Update z_bg_collect.c * Update z_bg_item.c * Update z_bg_item.c * Renames z_bg_item system to DynaPolyActor * Format --- include/functions.h | 34 ++-- include/z64actor.h | 8 +- spec | 1 - src/code/code_800CB000.c | 3 - src/code/z_actor.c | 4 +- src/code/z_bg_collect.c | 12 +- src/code/z_bg_item.c | 146 +++++++++++------- .../ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c | 8 +- .../ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c | 8 +- .../actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c | 2 +- .../ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c | 4 +- .../actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c | 4 +- .../ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c | 4 +- .../actors/ovl_Bg_Icicle/z_bg_icicle.c | 4 +- .../ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c | 4 +- .../ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c | 4 +- .../actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c | 4 +- .../ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c | 4 +- .../actors/ovl_Bg_Ladder/z_bg_ladder.c | 10 +- .../actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c | 4 +- src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c | 6 +- .../ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c | 4 +- .../actors/ovl_Bg_Tobira01/z_bg_tobira01.c | 4 +- .../actors/ovl_Dm_Char07/z_dm_char07.c | 4 +- src/overlays/actors/ovl_En_Dnb/z_en_dnb.c | 4 +- .../actors/ovl_En_Encount2/z_en_encount2.c | 2 +- src/overlays/actors/ovl_En_Fu/z_en_fu.c | 3 +- src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c | 4 +- .../actors/ovl_Obj_Etcetera/z_obj_etcetera.c | 10 +- .../actors/ovl_Obj_Ghaka/z_obj_ghaka.c | 8 +- .../actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c | 2 +- .../actors/ovl_Obj_HsStump/z_obj_hsstump.c | 4 +- .../ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c | 4 +- .../actors/ovl_Obj_Kibako2/z_obj_kibako2.c | 4 +- .../ovl_Obj_Lightblock/z_obj_lightblock.c | 4 +- .../actors/ovl_Obj_Raillift/z_obj_raillift.c | 8 +- .../ovl_Obj_Tokei_Step/z_obj_tokei_step.c | 6 +- .../ovl_Obj_Visiblock/z_obj_visiblock.c | 4 +- tools/disasm/files.txt | 3 +- tools/disasm/functions.txt | 32 ++-- tools/sizes/code_functions.csv | 32 ++-- 41 files changed, 231 insertions(+), 193 deletions(-) delete mode 100644 src/code/code_800CB000.c diff --git a/include/functions.h b/include/functions.h index 1102363d5..55945e4c8 100644 --- a/include/functions.h +++ b/include/functions.h @@ -995,7 +995,7 @@ s32 func_800C45C4(CollisionContext* colCtx, u32 arg1, Vec3f* arg2, Vec3f* arg3, // void func_800C5538(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10); s32 func_800C55C4(CollisionContext* colCtx, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, CollisionPoly** arg4, u32 arg5, u32 arg6, u32 arg7, u32 arg8, u32* arg9); // void func_800C5650(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11); -// void func_800C56E0(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9, UNK_TYPE4 param_10, UNK_TYPE4 param_11, UNK_TYPE4 param_12); +s32 func_800C56E0(CollisionContext* colCtx, Vec3f* posA, Vec3f* posB, Vec3f* posResult, CollisionPoly** outPoly, s32 chkWall, s32 chkFloor, s32 chkCeil, s32 chkOneFace, s32* bgId, Actor* actor, f32 chkDist); s32 func_800C576C(CollisionContext* colCtx, Vec3f* arg1, Vec3f* arg2, Vec3f* arg3, CollisionPoly** arg4, u32 arg5, u32 arg6, u32 arg7, u32 arg8, u32* arg9); // void func_800C57F8(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6); // void func_800C583C(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE4 param_5, UNK_TYPE4 param_6, UNK_TYPE4 param_7, UNK_TYPE4 param_8, UNK_TYPE4 param_9); @@ -1109,22 +1109,22 @@ void BgCheck2_UpdateActorPosition(CollisionContext* colCtx, s32 index, Actor* ac void BgCheck2_UpdateActorYRotation(CollisionContext* colCtx, s32 index, Actor* actor); void BgCheck2_AttachToMesh(CollisionContext* colCtx, Actor* actor, s32 index); u32 BgCheck2_UpdateActorAttachedToMesh(CollisionContext* colCtx, s32 index, Actor* actor); -void BcCheck3_BgActorInit(DynaPolyActor* actor, UNK_TYPE4 param_2); -void BgCheck3_LoadMesh(GlobalContext* globalCtx, DynaPolyActor* actor, CollisionHeader* meshHeader); -void BgCheck3_ResetFlags(DynaPolyActor* actor); -void func_800CAE88(DynaPolyActor* actor); -void func_800CAE9C(DynaPolyActor* actor); -void func_800CAEB0(CollisionContext* colCtx, s32 index); -void func_800CAEE0(DynaPolyActor* actor); -void func_800CAEF4(CollisionContext* colCtx, s32 index); -void func_800CAF24(DynaPolyActor* actor); -void func_800CAF38(DynaPolyActor* actor); -s32 func_800CAF4C(DynaPolyActor* actor); -s32 func_800CAF70(DynaPolyActor* actor); -s32 func_800CAF94(DynaPolyActor* actor); -s32 func_800CAFB8(DynaPolyActor* actor); -s32 func_800CAFDC(DynaPolyActor* actor); -// void func_800CB000(UNK_TYPE1 param_1, UNK_TYPE1 param_2, UNK_TYPE1 param_3, UNK_TYPE1 param_4, UNK_TYPE2 param_5); +void DynaPolyActor_Init(DynaPolyActor* dynaActor, s32 flags); +void DynaPolyActor_LoadMesh(GlobalContext* globalCtx, DynaPolyActor* dynaActor, CollisionHeader* meshHeader); +void DynaPolyActor_ResetState(DynaPolyActor* dynaActor); +void DynaPolyActor_SetRidingFallingState(DynaPolyActor* dynaActor); +void DynaPolyActor_SetRidingMovingState(DynaPolyActor* dynaActor); +void DynaPolyActor_SetRidingMovingStateByIndex(CollisionContext* colCtx, s32 index); +void DynaPolyActor_SetRidingRotatingState(DynaPolyActor* dynaActor); +void DynaPolyActor_SetRidingRotatingStateByIndex(CollisionContext* colCtx, s32 index); +void DynaPolyActor_SetSwitchPressedState(DynaPolyActor* dynaActor); +void DynaPolyActor_SetHeavySwitchPressedState(DynaPolyActor* dynaActor); +s32 DynaPolyActor_IsInRidingFallingState(DynaPolyActor* dynaActor); +s32 DynaPolyActor_IsInRidingMovingState(DynaPolyActor* dynaActor); +s32 DynaPolyActor_IsInRidingRotatingState(DynaPolyActor* dynaActor); +s32 DynaPolyActor_IsInSwitchPressedState(DynaPolyActor* dynaActor); +s32 DynaPolyActor_IsInHeavySwitchPressedState(DynaPolyActor* dynaActor); +s32 DynaPolyActor_ValidateMove(GlobalContext* globalCtx, DynaPolyActor* dynaActor, s16 arg2, s16 arg3, s16 arg4); f32 Camera_fabsf(f32 f); f32 Camera_LengthVec3f(Vec3f* v); // void func_800CB270(void); diff --git a/include/z64actor.h b/include/z64actor.h index 9e75f0f9e..7923e3da9 100644 --- a/include/z64actor.h +++ b/include/z64actor.h @@ -228,12 +228,12 @@ typedef enum { typedef struct { /* 0x000 */ Actor actor; /* 0x144 */ s32 bgId; - /* 0x148 */ f32 unk148; + /* 0x148 */ f32 pushForce; /* 0x14C */ f32 unk14C; - /* 0x150 */ s16 unk150; + /* 0x150 */ s16 yRotation; /* 0x152 */ u16 unk152; - /* 0x154 */ u32 unk154; - /* 0x158 */ u8 unk_158; + /* 0x154 */ u32 flags; + /* 0x158 */ u8 stateFlags; /* 0x15A */ s16 pad15A; } DynaPolyActor; // size = 0x15C diff --git a/spec b/spec index 95f2a48d7..05efcb13c 100644 --- a/spec +++ b/spec @@ -457,7 +457,6 @@ beginseg include "build/data/code/z_bgcheck.bss.o" include "build/src/code/z_bg_collect.o" include "build/src/code/z_bg_item.o" - include "build/src/code/code_800CB000.o" include "build/src/code/z_camera.o" include "build/data/code/z_camera.data.o" include "build/data/code/z_camera.bss.o" diff --git a/src/code/code_800CB000.c b/src/code/code_800CB000.c deleted file mode 100644 index 7642d35c4..000000000 --- a/src/code/code_800CB000.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "global.h" - -#pragma GLOBAL_ASM("asm/non_matchings/code/code_800CB000/func_800CB000.s") diff --git a/src/code/z_actor.c b/src/code/z_actor.c index 03a362fc6..42f67987a 100644 --- a/src/code/z_actor.c +++ b/src/code/z_actor.c @@ -509,8 +509,8 @@ f32 Actor_YDistance(Actor* actor1, Actor* actor2) { #pragma GLOBAL_ASM("asm/non_matchings/code/z_actor/func_800B72E0.s") void func_800B72F8(DynaPolyActor* dpactor, f32 a1, s16 a2) { - dpactor->unk150 = a2; - dpactor->unk148 += a1; + dpactor->yRotation = a2; + dpactor->pushForce += a1; } #pragma GLOBAL_ASM("asm/non_matchings/code/z_actor/Actor_IsLinkFacingActor.s") diff --git a/src/code/z_bg_collect.c b/src/code/z_bg_collect.c index 29c4cf7da..706c4b80a 100644 --- a/src/code/z_bg_collect.c +++ b/src/code/z_bg_collect.c @@ -61,13 +61,13 @@ void BgCheck2_AttachToMesh(CollisionContext* colCtx, Actor* actor, s32 index) { meshActor = BgCheck_GetActorOfMesh(colCtx, index); if (meshActor != NULL) { - func_800CAE88(meshActor); + DynaPolyActor_SetRidingFallingState(meshActor); if ((actor->flags & 0x4000000) == 0x4000000) { - func_800CAF24(meshActor); + DynaPolyActor_SetSwitchPressedState(meshActor); } if ((actor->flags & 0x20000) == 0x20000) { - func_800CAF38(meshActor); + DynaPolyActor_SetHeavySwitchPressedState(meshActor); } } } @@ -80,7 +80,7 @@ u32 BgCheck2_UpdateActorAttachedToMesh(CollisionContext* colCtx, s32 index, Acto return 0; } - if (((colCtx->dyna.bgActorFlags[index] & 2) != 0) || ((colCtx->dyna.bgActorFlags[index] & 1) == 0)) { + if (colCtx->dyna.bgActorFlags[index] & 2 || !(colCtx->dyna.bgActorFlags[index] & 1)) { return 0; } @@ -90,12 +90,12 @@ u32 BgCheck2_UpdateActorAttachedToMesh(CollisionContext* colCtx, s32 index, Acto return 0; } - if ((meshActor->unk154 & 1) != 0) { + if (meshActor->flags & 1) { BgCheck2_UpdateActorPosition(colCtx, index, actor); wasUpdated = 1; } - if ((meshActor->unk154 & 2) != 0) { + if (meshActor->flags & 2) { BgCheck2_UpdateActorYRotation(colCtx, index, actor); wasUpdated = 1; } diff --git a/src/code/z_bg_item.c b/src/code/z_bg_item.c index 77cc014b4..92a300e43 100644 --- a/src/code/z_bg_item.c +++ b/src/code/z_bg_item.c @@ -1,99 +1,141 @@ #include "global.h" -void BcCheck3_BgActorInit(DynaPolyActor* actor, UNK_TYPE4 param_2) { - actor->bgId = -1; - actor->unk148 = 0; - actor->unk14C = 0; - actor->unk154 = param_2; - actor->unk_158 = 0; +#define DYNAPOLY_STATE_NONE 0 +#define DYNAPOLY_STATE_RIDING_FALLING (1 << 0) +#define DYNAPOLY_STATE_RIDING_MOVING (1 << 1) +#define DYNAPOLY_STATE_RIDING_ROTATING (1 << 2) +#define DYNAPOLY_STATE_SWITCH_PRESSED (1 << 3) +#define DYNAPOLY_STATE_HEAVY_SWITCH_PRESSED (1 << 4) + +void DynaPolyActor_Init(DynaPolyActor* dynaActor, s32 flags) { + dynaActor->bgId = -1; + dynaActor->pushForce = 0.0f; + dynaActor->unk14C = 0.0f; + dynaActor->flags = flags; + dynaActor->stateFlags = DYNAPOLY_STATE_NONE; } -void BgCheck3_LoadMesh(GlobalContext* globalCtx, DynaPolyActor* actor, CollisionHeader* meshHeader) { - CollisionHeader* header; +void DynaPolyActor_LoadMesh(GlobalContext* globalCtx, DynaPolyActor* dynaActor, CollisionHeader* meshHeader) { + CollisionHeader* header = NULL; - header = NULL; BgCheck_RelocateMeshHeader(meshHeader, &header); - actor->bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, actor, header); + dynaActor->bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, dynaActor, header); } -void BgCheck3_ResetFlags(DynaPolyActor* actor) { - actor->unk_158 = 0; +void DynaPolyActor_ResetState(DynaPolyActor* dynaActor) { + dynaActor->stateFlags = DYNAPOLY_STATE_NONE; } -void func_800CAE88(DynaPolyActor* actor) { - actor->unk_158 |= 1; +void DynaPolyActor_SetRidingFallingState(DynaPolyActor* dynaActor) { + dynaActor->stateFlags |= DYNAPOLY_STATE_RIDING_FALLING; } -void func_800CAE9C(DynaPolyActor* actor) { - actor->unk_158 |= 2; +void DynaPolyActor_SetRidingMovingState(DynaPolyActor* dynaActor) { + dynaActor->stateFlags |= DYNAPOLY_STATE_RIDING_MOVING; } -void func_800CAEB0(CollisionContext* colCtx, s32 index) { - DynaPolyActor* actor; +void DynaPolyActor_SetRidingMovingStateByIndex(CollisionContext* colCtx, s32 index) { + DynaPolyActor* dynaActor = BgCheck_GetActorOfMesh(colCtx, index); - actor = BgCheck_GetActorOfMesh(colCtx, index); - if (actor != (DynaPolyActor*)0x0) { - func_800CAE9C(actor); + if (dynaActor != NULL) { + DynaPolyActor_SetRidingMovingState(dynaActor); } } -void func_800CAEE0(DynaPolyActor* actor) { - actor->unk_158 |= 4; +void DynaPolyActor_SetRidingRotatingState(DynaPolyActor* dynaActor) { + dynaActor->stateFlags |= DYNAPOLY_STATE_RIDING_ROTATING; } -void func_800CAEF4(CollisionContext* colCtx, s32 index) { - DynaPolyActor* actor; +void DynaPolyActor_SetRidingRotatingStateByIndex(CollisionContext* colCtx, s32 index) { + DynaPolyActor* dynaActor = BgCheck_GetActorOfMesh(colCtx, index); - actor = BgCheck_GetActorOfMesh(colCtx, index); - if (actor != (DynaPolyActor*)0x0) { - func_800CAEE0(actor); + if (dynaActor != NULL) { + DynaPolyActor_SetRidingRotatingState(dynaActor); } } -void func_800CAF24(DynaPolyActor* actor) { - actor->unk_158 |= 8; +void DynaPolyActor_SetSwitchPressedState(DynaPolyActor* dynaActor) { + dynaActor->stateFlags |= DYNAPOLY_STATE_SWITCH_PRESSED; } -void func_800CAF38(DynaPolyActor* actor) { - actor->unk_158 |= 0x10; +void DynaPolyActor_SetHeavySwitchPressedState(DynaPolyActor* dynaActor) { + dynaActor->stateFlags |= DYNAPOLY_STATE_HEAVY_SWITCH_PRESSED; } -s32 func_800CAF4C(DynaPolyActor* actor) { - if (actor->unk_158 & 1) { - return 1; +s32 DynaPolyActor_IsInRidingFallingState(DynaPolyActor* dynaActor) { + if (dynaActor->stateFlags & DYNAPOLY_STATE_RIDING_FALLING) { + return true; } else { - return 0; + return false; } } -s32 func_800CAF70(DynaPolyActor* actor) { - if (actor->unk_158 & 2) { - return 1; +s32 DynaPolyActor_IsInRidingMovingState(DynaPolyActor* dynaActor) { + if (dynaActor->stateFlags & DYNAPOLY_STATE_RIDING_MOVING) { + return true; } else { - return 0; + return false; } } -s32 func_800CAF94(DynaPolyActor* actor) { - if (actor->unk_158 & 4) { - return 1; +s32 DynaPolyActor_IsInRidingRotatingState(DynaPolyActor* dynaActor) { + if (dynaActor->stateFlags & DYNAPOLY_STATE_RIDING_ROTATING) { + return true; } else { - return 0; + return false; } } -s32 func_800CAFB8(DynaPolyActor* actor) { - if (actor->unk_158 & 8) { - return 1; +s32 DynaPolyActor_IsInSwitchPressedState(DynaPolyActor* dynaActor) { + if (dynaActor->stateFlags & DYNAPOLY_STATE_SWITCH_PRESSED) { + return true; } else { - return 0; + return false; } } -s32 func_800CAFDC(DynaPolyActor* actor) { - if (actor->unk_158 & 0x10) { - return 1; +s32 DynaPolyActor_IsInHeavySwitchPressedState(DynaPolyActor* dynaActor) { + if (dynaActor->stateFlags & DYNAPOLY_STATE_HEAVY_SWITCH_PRESSED) { + return true; } else { - return 0; + return false; } } + +s32 DynaPolyActor_ValidateMove(GlobalContext* globalCtx, DynaPolyActor* dynaActor, s16 startRadius, s16 endRadius, + s16 startHeight) { + Vec3f startPos; + Vec3f endPos; + Vec3f intersectionPos; + f32 sin = Math_SinS(dynaActor->yRotation); + f32 cos = Math_CosS(dynaActor->yRotation); + s32 bgId; + CollisionPoly* poly; + f32 adjustedStartRadius; + f32 adjustedEndRadius; + f32 sign = (0.0f <= dynaActor->pushForce) ? 1.0f : -1.0f; + + adjustedStartRadius = (f32)startRadius - 0.1f; + startPos.x = dynaActor->actor.world.pos.x + (adjustedStartRadius * cos); + startPos.y = dynaActor->actor.world.pos.y + startHeight; + startPos.z = dynaActor->actor.world.pos.z - (adjustedStartRadius * sin); + + adjustedEndRadius = (f32)endRadius - 0.1f; + endPos.x = sign * adjustedEndRadius * sin + startPos.x; + endPos.y = startPos.y; + endPos.z = sign * adjustedEndRadius * cos + startPos.z; + + if (func_800C56E0(&globalCtx->colCtx, &startPos, &endPos, &intersectionPos, &poly, true, false, false, true, &bgId, + &dynaActor->actor, 0.0f)) { + return false; + } + startPos.x = (dynaActor->actor.world.pos.x * 2.0f) - startPos.x; + startPos.z = (dynaActor->actor.world.pos.z * 2.0f) - startPos.z; + endPos.x = sign * adjustedEndRadius * sin + startPos.x; + endPos.z = sign * adjustedEndRadius * cos + startPos.z; + if (func_800C56E0(&globalCtx->colCtx, &startPos, &endPos, &intersectionPos, &poly, true, false, false, true, &bgId, + &dynaActor->actor, 0.0f)) { + return false; + } + return true; +} diff --git a/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c b/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c index 18b8a343c..e41b4ef73 100644 --- a/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c +++ b/src/overlays/actors/ovl_Bg_Ctower_Gear/z_bg_ctower_gear.c @@ -143,11 +143,11 @@ void BgCtowerGear_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_ProcessInitChain(&this->dyna.actor, sInitChain); } if (type == WATER_WHEEL) { - BcCheck3_BgActorInit(&this->dyna, 3); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06018588); + DynaPolyActor_Init(&this->dyna, 3); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06018588); } else if (type == ORGAN) { - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06016E70); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06016E70); func_800C62BC(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); } } diff --git a/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c b/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c index 68371797b..df56b42a0 100644 --- a/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c +++ b/src/overlays/actors/ovl_Bg_Ctower_Rot/z_bg_ctower_rot.c @@ -53,18 +53,18 @@ void BgCtowerRot_Init(Actor* thisx, GlobalContext* globalCtx) { Vec3f offset; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 1); + DynaPolyActor_Init(&this->dyna, 1); if (this->dyna.actor.params == CORRIDOR) { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_060142E8); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_060142E8); this->actionFunc = BgCtowerRot_CorridorRotate; return; } player = GET_PLAYER(globalCtx); if (this->dyna.actor.params == MAIN_DOOR) { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06017410); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06017410); this->dyna.actor.world.rot.y = this->dyna.actor.shape.rot.y + 0x4000; } else { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06017650); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06017650); this->dyna.actor.world.rot.y = this->dyna.actor.shape.rot.y - 0x4000; } Actor_CalcOffsetOrientedToDrawRotation(&this->dyna.actor, &offset, &player->actor.world.pos); diff --git a/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c b/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c index f9447ba03..f757f54ab 100644 --- a/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c +++ b/src/overlays/actors/ovl_Bg_Fu_Kaiten/z_bg_fu_kaiten.c @@ -36,7 +36,7 @@ void BgFuKaiten_Init(Actor* thisx, GlobalContext* globalCtx) { CollisionHeader* header = 0; Actor_SetScale(thisx, 1.0); - BcCheck3_BgActorInit(&THIS->bg, 3); + DynaPolyActor_Init(&THIS->bg, 3); BgCheck_RelocateMeshHeader(&D_06002D30, &header); THIS->bg.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &THIS->bg, header); diff --git a/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c b/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c index d6f3bdcdb..dfe04cbba 100644 --- a/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c +++ b/src/overlays/actors/ovl_Bg_Haka_Curtain/z_bg_haka_curtain.c @@ -51,8 +51,8 @@ void BgHakaCurtain_Init(Actor* thisx, GlobalContext* globalCtx) { BgHakaCurtain* this = THIS; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06001588); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06001588); if (Actor_GetRoomCleared(globalCtx, this->dyna.actor.room)) { func_80B6DE80(this); return; diff --git a/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c b/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c index 6a610470e..e05c84282 100644 --- a/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c +++ b/src/overlays/actors/ovl_Bg_Haka_Tomb/z_bg_haka_tomb.c @@ -47,8 +47,8 @@ void BgHakaTomb_Init(Actor* thisx, GlobalContext* globalCtx) { BgHakaTomb* this = THIS; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, D_06000EE8); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, D_06000EE8); func_8013E3B8(&this->dyna.actor, this->cutscenes, ARRAY_COUNT(this->cutscenes)); func_80BD6624(this); } diff --git a/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c b/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c index 453bd919c..13facec77 100644 --- a/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c +++ b/src/overlays/actors/ovl_Bg_Hakugin_Post/z_bg_hakugin_post.c @@ -704,8 +704,8 @@ void BgHakuginPost_Init(Actor* thisx, GlobalContext* globalCtx) { this->dyna.actor.world.rot.z = 0; this->dyna.actor.shape.rot.x = 0; this->dyna.actor.shape.rot.z = 0; - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_0600D3B0); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_0600D3B0); func_80A9B3BC(this, globalCtx); func_80A9CA94(this); } else { diff --git a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c index 2695cb996..965a999bc 100644 --- a/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c +++ b/src/overlays/actors/ovl_Bg_Icicle/z_bg_icicle.c @@ -70,8 +70,8 @@ void BgIcicle_Init(Actor* thisx, GlobalContext* globalCtx) { s32 paramsMid; Actor_ProcessInitChain(thisx, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000294); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000294); Collider_InitAndSetCylinder(globalCtx, &this->collider, thisx, &sCylinderInit); Collider_UpdateCylinder(thisx, &this->collider); diff --git a/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c b/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c index 9d5a36ba5..6643aeab7 100644 --- a/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c +++ b/src/overlays/actors/ovl_Bg_Ikana_Shutter/z_bg_ikana_shutter.c @@ -67,8 +67,8 @@ void BgIkanaShutter_Init(Actor* thisx, GlobalContext* globalCtx) { BgIkanaShutter* this = THIS; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000F28); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000F28); if (!((this->dyna.actor.params >> 8) & 1)) { if (BgIkanaShutter_AllSwitchesPressed(this, globalCtx)) { func_80BD599C(this); diff --git a/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c b/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c index 5b68e1363..9ffd1e549 100644 --- a/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c +++ b/src/overlays/actors/ovl_Bg_Iknin_Susceil/z_bg_iknin_susceil.c @@ -115,8 +115,8 @@ void BgIkninSusceil_Init(Actor* thisx, GlobalContext* globalCtx) { BgIkninSusceil* this = THIS; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_0600CBAC); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_0600CBAC); this->animatedTexture = Lib_SegmentedToVirtual(&D_0600C670); func_80C0AC74(this); } diff --git a/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c b/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c index 8c6380aaf..90984244c 100644 --- a/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c +++ b/src/overlays/actors/ovl_Bg_Iknv_Obj/z_bg_iknv_obj.c @@ -74,7 +74,7 @@ void BgIknvObj_Init(Actor* thisx, GlobalContext* globalCtx) { break; case IKNV_OBJ_RAISED_DOOR: this->displayListPtr = D_06011880; - BcCheck3_BgActorInit(&this->dyna, 0); + DynaPolyActor_Init(&this->dyna, 0); BgCheck_RelocateMeshHeader(&D_060119D4, &colHeader); this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); this->actionFunc = BgIknvObj_UpdateRaisedDoor; @@ -83,7 +83,7 @@ void BgIknvObj_Init(Actor* thisx, GlobalContext* globalCtx) { case IKNV_OBJ_SAKON_DOOR: this->displayListPtr = D_060129C8; this->actionFunc = BgIknvObj_UpdateSakonDoor; - BcCheck3_BgActorInit(&this->dyna, 0); + DynaPolyActor_Init(&this->dyna, 0); BgCheck_RelocateMeshHeader(&D_06012CA4, &colHeader); this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); Collider_InitAndSetCylinder(globalCtx, &this->collider, &this->dyna.actor, &sCylinderInit); diff --git a/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c b/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c index 39b22417c..4b98ed4e0 100644 --- a/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c +++ b/src/overlays/actors/ovl_Bg_Kin2_Fence/z_bg_kin2_fence.c @@ -158,8 +158,8 @@ void BgKin2Fence_Init(Actor* thisx, GlobalContext* globalCtx) { s32 i = 0; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000908); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000908); Collider_InitJntSph(globalCtx, &this->collider); Collider_SetJntSph(globalCtx, &this->collider, &this->dyna.actor, &sJntSphInit, this->colliderElements); Matrix_SetStateRotationAndTranslation(this->dyna.actor.world.pos.x, this->dyna.actor.world.pos.y, diff --git a/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c b/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c index 0c391f43b..81c1f6a97 100644 --- a/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c +++ b/src/overlays/actors/ovl_Bg_Ladder/z_bg_ladder.c @@ -61,17 +61,17 @@ void BgLadder_Init(Actor* thisx, GlobalContext* globalCtx) { // Has to be `thisx` instead of `&this->actor` to match this->switchFlag = GET_BGLADDER_SWITCHFLAG(thisx); thisx->params = GET_BGLADDER_SIZE(thisx); - BcCheck3_BgActorInit(&this->dyna, 0); + DynaPolyActor_Init(&this->dyna, 0); size = thisx->params; if (size == LADDER_SIZE_12RUNG) { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_060001D8); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_060001D8); } else if (size == LADDER_SIZE_16RUNG) { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000408); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000408); } else if (size == LADDER_SIZE_20RUNG) { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000638); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000638); } else if (size == LADDER_SIZE_24RUNG) { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000868); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000868); } else { Actor_MarkForDeath(&this->dyna.actor); return; diff --git a/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c b/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c index 2b77f73ac..19a6e3668 100644 --- a/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c +++ b/src/overlays/actors/ovl_Bg_Lbfshot/z_bg_lbfshot.c @@ -38,8 +38,8 @@ void BgLbfshot_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_ProcessInitChain(&this->dyna.actor, sInitChain); this->dyna.actor.uncullZoneForward = 4000.0f; - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_060014D8); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_060014D8); } void BgLbfshot_Destroy(Actor* thisx, GlobalContext* globalCtx) { BgLbfshot* this = THIS; diff --git a/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c b/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c index 02e9517f5..d8141abc3 100644 --- a/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c +++ b/src/overlays/actors/ovl_Bg_Lotus/z_bg_lotus.c @@ -44,8 +44,8 @@ void BgLotus_Init(Actor* thisx, GlobalContext* globalCtx) { s32 sp2C; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000A20); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000A20); this->dyna.actor.floorHeight = func_800C411C(&globalCtx->colCtx, &thisx->floorPoly, &sp2C, &this->dyna.actor, &this->dyna.actor.world.pos); this->timer2 = 96; @@ -93,7 +93,7 @@ void BgLotus_Wait(BgLotus* this, GlobalContext* globalCtx) { } else { this->dyna.actor.world.pos.y = this->height; - if (func_800CAF70(&this->dyna)) { + if (DynaPolyActor_IsInRidingMovingState(&this->dyna)) { if (this->hasSpawnedRipples == 0) { EffectSsGRipple_Spawn(globalCtx, &this->dyna.actor.world.pos, 1000, 1400, 0); EffectSsGRipple_Spawn(globalCtx, &this->dyna.actor.world.pos, 1000, 1400, 8); diff --git a/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c b/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c index 43022630a..112eabfbc 100644 --- a/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c +++ b/src/overlays/actors/ovl_Bg_Mbar_Chair/z_bg_mbar_chair.c @@ -41,8 +41,8 @@ void BgMbarChair_Init(Actor* thisx, GlobalContext* globalCtx) { BgMbarChair* this = THIS; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_060019B4); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_060019B4); } void BgMbarChair_Destroy(Actor* thisx, GlobalContext* globalCtx) { diff --git a/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c b/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c index 506b508b2..e759edfb3 100644 --- a/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c +++ b/src/overlays/actors/ovl_Bg_Tobira01/z_bg_tobira01.c @@ -78,8 +78,8 @@ void BgTobira01_Init(Actor* thisx, GlobalContext* globalCtx) { BgTobira01* this = THIS; s32 pad; - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_060011C0); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_060011C0); gSaveContext.weekEventReg[88] &= (u8)~0x40; Actor_SetScale(&this->dyna.actor, 1.0f); this->timer2 = gSaveContext.isNight; diff --git a/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c b/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c index c80f7222d..c5ff12452 100644 --- a/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c +++ b/src/overlays/actors/ovl_Dm_Char07/z_dm_char07.c @@ -61,8 +61,8 @@ void DmChar07_Init(Actor* thisx, GlobalContext* globalCtx) { if (this->dyna.actor.params == DMCHAR07_STAGE) { Actor_SetScale(&this->dyna.actor, 0.1f); this->isStage = 1; - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06006688); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06006688); } else { Actor_SetScale(&this->dyna.actor, 1.0f); } diff --git a/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c b/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c index 780ce1cda..945e9365d 100644 --- a/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c +++ b/src/overlays/actors/ovl_En_Dnb/z_en_dnb.c @@ -108,8 +108,8 @@ void EnDnb_Init(Actor* thisx, GlobalContext* globalCtx) { s32 i; s16* alloc; - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06004D8C); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06004D8C); alloc = (s16*)Lib_SegmentedToVirtual(D_06004710); for (i = 0; i < ARRAY_COUNT(this->particles); i++) { diff --git a/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c b/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c index 6071137ce..20bd44fe7 100644 --- a/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c +++ b/src/overlays/actors/ovl_En_Encount2/z_en_encount2.c @@ -106,7 +106,7 @@ void EnEncount2_Init(Actor* thisx, GlobalContext* globalCtx) { s32 pad; CollisionHeader* colHeader = NULL; - BcCheck3_BgActorInit(&this->dyna, 0); + DynaPolyActor_Init(&this->dyna, 0); BgCheck_RelocateMeshHeader(&D_06002420, &colHeader); this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); ActorShape_Init(&this->dyna.actor.shape, 0.0f, func_800B3FC0, 25.0f); diff --git a/src/overlays/actors/ovl_En_Fu/z_en_fu.c b/src/overlays/actors/ovl_En_Fu/z_en_fu.c index 550a54f62..737c142bf 100644 --- a/src/overlays/actors/ovl_En_Fu/z_en_fu.c +++ b/src/overlays/actors/ovl_En_Fu/z_en_fu.c @@ -781,7 +781,8 @@ void func_80962F4C(EnFu* this, GlobalContext* globalCtx) { func_801518B0(globalCtx, 0x288B, &this->actor); } - if ((!func_800CAF94((DynaPolyActor*)this->actor.child) && (player->actor.bgCheckFlags & 1)) || + if ((!DynaPolyActor_IsInRidingRotatingState((DynaPolyActor*)this->actor.child) && + (player->actor.bgCheckFlags & 1)) || (gSaveContext.unk_3DE0[4] < 1) || (this->unk_548 == this->unk_54C)) { player->stateFlags3 &= ~0x400000; func_80961E88(globalCtx); diff --git a/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c b/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c index de7f30fbd..4a70dc0ec 100644 --- a/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c +++ b/src/overlays/actors/ovl_Obj_Bell/z_obj_bell.c @@ -264,8 +264,8 @@ void func_80A35BD4(Actor* thisx, GlobalContext* globalCtx) { void ObjBell_Init(Actor* thisx, GlobalContext* globalCtx) { ObjBell* this = THIS; - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06001BA8); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06001BA8); Actor_SetScale(&this->dyna.actor, 0.08f); Collider_InitAndSetSphere(globalCtx, &this->collider1, &this->dyna.actor, &sCylinderInit1); Collider_InitAndSetSphere(globalCtx, &this->collider2, &this->dyna.actor, &sCylinderInit2); diff --git a/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c b/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c index e4d9707be..b08f690d4 100644 --- a/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c +++ b/src/overlays/actors/ovl_Obj_Etcetera/z_obj_etcetera.c @@ -147,7 +147,7 @@ void ObjEtcetera_Idle(ObjEtcetera* this, GlobalContext* globalCtx) { this->oscillationTimer = minOscillationTimer; } } else { - if (func_800CAF70(&this->dyna)) { + if (DynaPolyActor_IsInRidingMovingState(&this->dyna)) { if (!(this->burrowFlag & 1)) { // Player is walking onto the Deku Flower, or falling on it from a height this->oscillationTimer = 10; @@ -175,7 +175,7 @@ void ObjEtcetera_Idle(ObjEtcetera* this, GlobalContext* globalCtx) { } void ObjEtcetera_PlaySmallFlutterAnimation(ObjEtcetera* this, GlobalContext* globalCtx) { - if (func_800CAF70(&this->dyna)) { + if (DynaPolyActor_IsInRidingMovingState(&this->dyna)) { this->burrowFlag |= 1; } else { this->burrowFlag &= ~1; @@ -190,11 +190,11 @@ void ObjEtcetera_PlaySmallFlutterAnimation(ObjEtcetera* this, GlobalContext* glo void ObjEtcetera_DoIntenseOscillation(ObjEtcetera* this, GlobalContext* globalCtx) { // In order to match, we are seemingly required to access scale.x at one point // without using this. We can create a thisx or dyna pointer to achieve that, but - // it's more likely they used dyna given that func_800CAF70 takes a DynaPolyActor. + // it's more likely they used dyna given that DynaPolyActor_IsInRidingMovingState takes a DynaPolyActor. DynaPolyActor* dyna = &this->dyna; f32 scaleTemp; - if (func_800CAF70(dyna)) { + if (DynaPolyActor_IsInRidingMovingState(dyna)) { this->burrowFlag |= 1; } else { this->burrowFlag &= ~1; @@ -233,7 +233,7 @@ void ObjEtcetera_Setup(ObjEtcetera* this, GlobalContext* globalCtx) { if (Object_IsLoaded(&globalCtx->objectCtx, this->objIndex)) { this->dyna.actor.objBankIndex = this->objIndex; Actor_SetObjectSegment(globalCtx, &this->dyna.actor); - BcCheck3_BgActorInit(&this->dyna, 1); + DynaPolyActor_Init(&this->dyna, 1); thisCollisionHeader = collisionHeaders[type]; if (thisCollisionHeader != 0) { BgCheck_RelocateMeshHeader(thisCollisionHeader, &colHeader); diff --git a/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c b/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c index 7a20bab74..6a7bf18e4 100644 --- a/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c +++ b/src/overlays/actors/ovl_Obj_Ghaka/z_obj_ghaka.c @@ -87,12 +87,12 @@ void func_80B3C39C(ObjGhaka* this, GlobalContext* globalCtx) { } } } - if (this->dyna.unk148 < 0.0f && !(gSaveContext.weekEventReg[20] & 0x20) && + if (this->dyna.pushForce < 0.0f && !(gSaveContext.weekEventReg[20] & 0x20) && player->transformation == PLAYER_FORM_GORON) { func_80B3C2B0(this); } else { player->stateFlags2 &= ~0x10; - this->dyna.unk148 = 0.0f; + this->dyna.pushForce = 0.0f; } } @@ -136,7 +136,7 @@ void func_80B3C624(ObjGhaka* this, GlobalContext* globalCtx) { if (stepTemp) { player->stateFlags2 &= ~0x10; - this->dyna.unk148 = 0.0f; + this->dyna.pushForce = 0.0f; func_80B3C2C4(this, globalCtx); gSaveContext.weekEventReg[20] |= 0x20; func_80B3C260(this); @@ -153,7 +153,7 @@ void ObjGhaka_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_ProcessInitChain(&this->dyna.actor, D_80B3C96C); Actor_SetScale(&this->dyna.actor, 0.1f); - BcCheck3_BgActorInit(&this->dyna, 1); + DynaPolyActor_Init(&this->dyna, 1); BgCheck_RelocateMeshHeader(&D_06003CD0, &colHeader); this->dyna.bgId = BgCheck_AddActorMesh(globalCtx, &globalCtx->colCtx.dyna, &this->dyna, colHeader); Actor_UpdateBgCheckInfo(globalCtx, &this->dyna.actor, 0.0f, 0.0f, 0.0f, 0x4); diff --git a/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c b/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c index 9632088b7..31184fc30 100644 --- a/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c +++ b/src/overlays/actors/ovl_Obj_Hgdoor/z_obj_hgdoor.c @@ -78,7 +78,7 @@ void ObjHgdoor_Init(Actor* thisx, GlobalContext* globalCtx) { CollisionHeader* header = NULL; Actor_SetScale(&this->dyna.actor, 0.1f); - BcCheck3_BgActorInit(&this->dyna, 1); + DynaPolyActor_Init(&this->dyna, 1); if (OBJHGDOOR_IS_RIGHT_DOOR(&this->dyna.actor)) { BgCheck_RelocateMeshHeader(&D_06001D10, &header); } else { diff --git a/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c b/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c index 3a61c41e8..e3813efb5 100644 --- a/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c +++ b/src/overlays/actors/ovl_Obj_HsStump/z_obj_hsstump.c @@ -47,8 +47,8 @@ void ObjHsStump_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_ProcessInitChain(&this->dyna.actor, sInitChain); this->isHidden = OBJHSSTUMP_GET_ISHIDDEN(thisx); this->switchFlag = OBJHSSTUMP_GET_SWITCHFLAG(thisx); // Must be thisx to match - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_060011B0); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_060011B0); switch (this->isHidden) { case true: if (Flags_GetSwitch(globalCtx, this->switchFlag)) { diff --git a/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c b/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c index 9b3d19051..f7901f708 100644 --- a/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c +++ b/src/overlays/actors/ovl_Obj_Kepn_Koya/z_obj_kepn_koya.c @@ -40,8 +40,8 @@ void ObjKepnKoya_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_ProcessInitChain(&this->dyna.actor, sInitChain); Actor_SetScale(&this->dyna.actor, 0.1f); - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_0600805C); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_0600805C); if (this->dyna.bgId == 0x32) { Actor_MarkForDeath(&this->dyna.actor); } diff --git a/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c b/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c index 87d3f9145..abd04dc65 100644 --- a/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c +++ b/src/overlays/actors/ovl_Obj_Kibako2/z_obj_kibako2.c @@ -149,10 +149,10 @@ void ObjKibako2_Init(Actor* thisx, GlobalContext* globalCtx) { s32 pad; ObjKibako2Contents contents = KIBAKO2_CONTENTS(&this->dyna.actor); - BcCheck3_BgActorInit(&this->dyna, 0); + DynaPolyActor_Init(&this->dyna, 0); Collider_InitCylinder(globalCtx, &this->collider); Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000B70); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000B70); Collider_SetCylinder(globalCtx, &this->collider, &this->dyna.actor, &sCylinderInit); Collider_UpdateCylinder(&this->dyna.actor, &this->collider); this->dyna.actor.home.rot.z = 0; diff --git a/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c b/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c index d955a5aa3..6a123c6ca 100644 --- a/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c +++ b/src/overlays/actors/ovl_Obj_Lightblock/z_obj_lightblock.c @@ -91,12 +91,12 @@ void ObjLightblock_Init(Actor* thisx, GlobalContext* globalCtx) { Actor_ProcessInitChain(&this->dyna.actor, sInitChain); Actor_SetScale(&this->dyna.actor, typeVars->scale); - BcCheck3_BgActorInit(&this->dyna, 0); + DynaPolyActor_Init(&this->dyna, 0); Collider_InitCylinder(globalCtx, &this->collider); if (Flags_GetSwitch(globalCtx, LIGHTBLOCK_DESTROYED(&this->dyna.actor))) { Actor_MarkForDeath(&this->dyna.actor); } else { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000B80); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000B80); Collider_SetCylinder(globalCtx, &this->collider, &this->dyna.actor, &sCylinderInit); Collider_UpdateCylinder(&this->dyna.actor, &this->collider); this->collider.dim.radius = typeVars->radius; diff --git a/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c b/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c index eb9202197..969326cf4 100644 --- a/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c +++ b/src/overlays/actors/ovl_Obj_Raillift/z_obj_raillift.c @@ -70,8 +70,8 @@ void ObjRaillift_Init(Actor* thisx, GlobalContext* globalCtx) { thisx->world.rot.x = 0; thisx->shape.rot.z = 0; thisx->world.rot.z = 0; - BcCheck3_BgActorInit(&this->dyna, 1); - BgCheck3_LoadMesh(globalCtx, &this->dyna, sColHeaders[type]); + DynaPolyActor_Init(&this->dyna, 1); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, sColHeaders[type]); this->speed = OBJRAILLIFT_GET_SPEED(thisx); if (this->speed < 0.0f) { this->speed = -this->speed; @@ -187,7 +187,7 @@ void ObjRaillift_Move(ObjRaillift* this, GlobalContext* globalCtx) { Will teleport to what ever curpoint is set to */ void ObjRaillift_Teleport(ObjRaillift* this, GlobalContext* globalCtx) { - if (!func_800CAF70(&this->dyna)) { + if (!DynaPolyActor_IsInRidingMovingState(&this->dyna)) { ObjRaillift_UpdatePosition(this, this->curPoint); func_800C6314(globalCtx, &globalCtx->colCtx.dyna, this->dyna.bgId); this->actionFunc = ObjRaillift_Move; @@ -237,7 +237,7 @@ void ObjRaillift_Update(Actor* thisx, GlobalContext* globalCtx) { s32 requiredScopeTemp; this->isWeightOnPrev = this->isWeightOn; - if (func_800CAF70(&this->dyna)) { + if (DynaPolyActor_IsInRidingMovingState(&this->dyna)) { this->isWeightOn = true; } else { this->isWeightOn = false; diff --git a/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c b/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c index 22bcddc57..c5e00241c 100644 --- a/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c +++ b/src/overlays/actors/ovl_Obj_Tokei_Step/z_obj_tokei_step.c @@ -195,9 +195,9 @@ void ObjTokeiStep_Init(Actor* thisx, GlobalContext* globalCtx) { ObjTokeiStep* this = THIS; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 0); + DynaPolyActor_Init(&this->dyna, 0); if ((globalCtx->sceneNum == 0x6F) && (gSaveContext.sceneSetupIndex == 2) && (globalCtx->csCtx.unk_12 == 0)) { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000968); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000968); ObjTokeiStep_InitSteps(this); ObjTokeiStep_SetupBeginOpen(this); } else if (!((CURRENT_DAY != 3) || (gSaveContext.time >= 0x4000)) || gSaveContext.day >= 4) { @@ -205,7 +205,7 @@ void ObjTokeiStep_Init(Actor* thisx, GlobalContext* globalCtx) { ObjTokeiStep_InitStepsOpen(this); ObjTokeiStep_SetupDoNothingOpen(this); } else { - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000968); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000968); ObjTokeiStep_InitSteps(this); ObjTokeiStep_SetupDoNothing(this); } diff --git a/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c b/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c index 23178e9c1..5f5b25cb3 100644 --- a/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c +++ b/src/overlays/actors/ovl_Obj_Visiblock/z_obj_visiblock.c @@ -40,8 +40,8 @@ void ObjVisiblock_Init(Actor* thisx, GlobalContext* globalCtx) { ObjVisiblock* this = THIS; Actor_ProcessInitChain(&this->dyna.actor, sInitChain); - BcCheck3_BgActorInit(&this->dyna, 0); - BgCheck3_LoadMesh(globalCtx, &this->dyna, &D_06000AD0); + DynaPolyActor_Init(&this->dyna, 0); + DynaPolyActor_LoadMesh(globalCtx, &this->dyna, &D_06000AD0); } void ObjVisiblock_Destroy(Actor* thisx, GlobalContext* globalCtx) { diff --git a/tools/disasm/files.txt b/tools/disasm/files.txt index 8dc09cca4..bf786209c 100644 --- a/tools/disasm/files.txt +++ b/tools/disasm/files.txt @@ -366,7 +366,6 @@ 0x800BFB80 : "z_bgcheck", 0x800CAAD0 : "z_bg_collect", 0x800CAE10 : "z_bg_item", - 0x800CB000 : "code_800CB000", 0x800CB210 : "z_camera", 0x800E03A0 : "z_collision_btltbls", 0x800E0400 : "[PADDING]", @@ -592,7 +591,7 @@ 0x801DC9D0 : "z_actor", 0x801DCBB0 : "z_actor_dlftbls", 0x801DCC00 : "z_bgcheck", - 0x801DCDB0 : "code_800CB000", + 0x801DCDB0 : "z_bg_item", 0x801DCDC0 : "z_camera", 0x801DD5C0 : "z_collision_check", 0x801DD600 : "z_debug_mode", diff --git a/tools/disasm/functions.txt b/tools/disasm/functions.txt index b6ec70b65..7dab11b4d 100644 --- a/tools/disasm/functions.txt +++ b/tools/disasm/functions.txt @@ -1096,22 +1096,22 @@ 0x800CAC0C:("BgCheck2_UpdateActorYRotation",), 0x800CACA0:("BgCheck2_AttachToMesh",), 0x800CAD2C:("BgCheck2_UpdateActorAttachedToMesh",), - 0x800CAE10:("BcCheck3_BgActorInit",), - 0x800CAE34:("BgCheck3_LoadMesh",), - 0x800CAE7C:("BgCheck3_ResetFlags",), - 0x800CAE88:("func_800CAE88",), - 0x800CAE9C:("func_800CAE9C",), - 0x800CAEB0:("func_800CAEB0",), - 0x800CAEE0:("func_800CAEE0",), - 0x800CAEF4:("func_800CAEF4",), - 0x800CAF24:("func_800CAF24",), - 0x800CAF38:("func_800CAF38",), - 0x800CAF4C:("func_800CAF4C",), - 0x800CAF70:("func_800CAF70",), - 0x800CAF94:("func_800CAF94",), - 0x800CAFB8:("func_800CAFB8",), - 0x800CAFDC:("func_800CAFDC",), - 0x800CB000:("func_800CB000",), + 0x800CAE10:("DynaPolyActor_Init",), + 0x800CAE34:("DynaPolyActor_LoadMesh",), + 0x800CAE7C:("DynaPolyActor_ResetState",), + 0x800CAE88:("DynaPolyActor_SetRidingFallingState",), + 0x800CAE9C:("DynaPolyActor_SetRidingMovingState",), + 0x800CAEB0:("DynaPolyActor_SetRidingMovingStateByIndex",), + 0x800CAEE0:("DynaPolyActor_SetRidingRotatingState",), + 0x800CAEF4:("DynaPolyActor_SetRidingRotatingStateByIndex",), + 0x800CAF24:("DynaPolyActor_SetSwitchPressedState",), + 0x800CAF38:("DynaPolyActor_SetHeavySwitchPressedState",), + 0x800CAF4C:("DynaPolyActor_IsInRidingFallingState",), + 0x800CAF70:("DynaPolyActor_IsInRidingMovingState",), + 0x800CAF94:("DynaPolyActor_IsInRidingRotatingState",), + 0x800CAFB8:("DynaPolyActor_IsInSwitchPressedState",), + 0x800CAFDC:("DynaPolyActor_IsInHeavySwitchPressedState",), + 0x800CB000:("DynaPolyActor_ValidateMove",), 0x800CB210:("Camera_fabsf",), 0x800CB240:("Camera_LengthVec3f",), 0x800CB270:("func_800CB270",), diff --git a/tools/sizes/code_functions.csv b/tools/sizes/code_functions.csv index 9737ede4d..44250fc0c 100644 --- a/tools/sizes/code_functions.csv +++ b/tools/sizes/code_functions.csv @@ -610,22 +610,22 @@ asm/non_matchings/code/z_bg_collect/BgCheck2_UpdateActorPosition.s,BgCheck2_Upda asm/non_matchings/code/z_bg_collect/BgCheck2_UpdateActorYRotation.s,BgCheck2_UpdateActorYRotation,0x800CAC0C,0x25 asm/non_matchings/code/z_bg_collect/BgCheck2_AttachToMesh.s,BgCheck2_AttachToMesh,0x800CACA0,0x23 asm/non_matchings/code/z_bg_collect/BgCheck2_UpdateActorAttachedToMesh.s,BgCheck2_UpdateActorAttachedToMesh,0x800CAD2C,0x39 -asm/non_matchings/code/z_bg_item/BcCheck3_BgActorInit.s,BcCheck3_BgActorInit,0x800CAE10,0x9 -asm/non_matchings/code/z_bg_item/BgCheck3_LoadMesh.s,BgCheck3_LoadMesh,0x800CAE34,0x12 -asm/non_matchings/code/z_bg_item/BgCheck3_ResetFlags.s,BgCheck3_ResetFlags,0x800CAE7C,0x3 -asm/non_matchings/code/z_bg_item/func_800CAE88.s,func_800CAE88,0x800CAE88,0x5 -asm/non_matchings/code/z_bg_item/func_800CAE9C.s,func_800CAE9C,0x800CAE9C,0x5 -asm/non_matchings/code/z_bg_item/func_800CAEB0.s,func_800CAEB0,0x800CAEB0,0xC -asm/non_matchings/code/z_bg_item/func_800CAEE0.s,func_800CAEE0,0x800CAEE0,0x5 -asm/non_matchings/code/z_bg_item/func_800CAEF4.s,func_800CAEF4,0x800CAEF4,0xC -asm/non_matchings/code/z_bg_item/func_800CAF24.s,func_800CAF24,0x800CAF24,0x5 -asm/non_matchings/code/z_bg_item/func_800CAF38.s,func_800CAF38,0x800CAF38,0x5 -asm/non_matchings/code/z_bg_item/func_800CAF4C.s,func_800CAF4C,0x800CAF4C,0x9 -asm/non_matchings/code/z_bg_item/func_800CAF70.s,func_800CAF70,0x800CAF70,0x9 -asm/non_matchings/code/z_bg_item/func_800CAF94.s,func_800CAF94,0x800CAF94,0x9 -asm/non_matchings/code/z_bg_item/func_800CAFB8.s,func_800CAFB8,0x800CAFB8,0x9 -asm/non_matchings/code/z_bg_item/func_800CAFDC.s,func_800CAFDC,0x800CAFDC,0x9 -asm/non_matchings/code/code_800CB000/func_800CB000.s,func_800CB000,0x800CB000,0x84 +asm/non_matchings/code/z_bg_item/DynaPoly_Init.s,DynaPoly_Init,0x800CAE10,0x9 +asm/non_matchings/code/z_bg_item/DynaPoly_LoadMesh.s,DynaPoly_LoadMesh,0x800CAE34,0x12 +asm/non_matchings/code/z_bg_item/DynaPoly_ResetState.s,DynaPoly_ResetState,0x800CAE7C,0x3 +asm/non_matchings/code/z_bg_item/DynaPoly_SetRidingFallingState.s,DynaPoly_SetRidingFallingState,0x800CAE88,0x5 +asm/non_matchings/code/z_bg_item/DynaPoly_SetRidingMovingState.s,DynaPoly_SetRidingMovingState,0x800CAE9C,0x5 +asm/non_matchings/code/z_bg_item/DynaPoly_SetRidingMovingStateByIndex.s,DynaPoly_SetRidingMovingStateByIndex,0x800CAEB0,0xC +asm/non_matchings/code/z_bg_item/DynaPoly_SetRidingRotatingState.s,DynaPoly_SetRidingRotatingState,0x800CAEE0,0x5 +asm/non_matchings/code/z_bg_item/DynaPoly_SetRidingRotatingStateByIndex.s,DynaPoly_SetRidingRotatingStateByIndex,0x800CAEF4,0xC +asm/non_matchings/code/z_bg_item/DynaPoly_SetSwitchPressedState.s,DynaPoly_SetSwitchPressedState,0x800CAF24,0x5 +asm/non_matchings/code/z_bg_item/DynaPoly_SetHeavySwitchPressedState.s,DynaPoly_SetHeavySwitchPressedState,0x800CAF38,0x5 +asm/non_matchings/code/z_bg_item/DynaPoly_IsInRidingFallingState.s,DynaPoly_IsInRidingFallingState,0x800CAF4C,0x9 +asm/non_matchings/code/z_bg_item/DynaPoly_IsInRidingMovingState.s,DynaPoly_IsInRidingMovingState,0x800CAF70,0x9 +asm/non_matchings/code/z_bg_item/DynaPoly_IsInRidingRotatingState.s,DynaPoly_IsInRidingRotatingState,0x800CAF94,0x9 +asm/non_matchings/code/z_bg_item/DynaPoly_IsInSwitchPressedState.s,DynaPoly_IsInSwitchPressedState,0x800CAFB8,0x9 +asm/non_matchings/code/z_bg_item/DynaPoly_IsInHeavySwitchPressedState.s,DynaPoly_IsInHeavySwitchPressedState,0x800CAFDC,0x9 +asm/non_matchings/code/z_bg_item/DynaPoly_ValidateMove.s,DynaPoly_ValidateMove,0x800CB000,0x84 asm/non_matchings/code/z_camera/Camera_fabsf.s,Camera_fabsf,0x800CB210,0xC asm/non_matchings/code/z_camera/Camera_LengthVec3f.s,Camera_LengthVec3f,0x800CB240,0xC asm/non_matchings/code/z_camera/func_800CB270.s,func_800CB270,0x800CB270,0x30 From 20f3a190f49570254f756d1bf7dfab0dc3cd3fc7 Mon Sep 17 00:00:00 2001 From: kyleburnette Date: Sun, 14 Nov 2021 15:01:22 -0800 Subject: [PATCH 7/8] xldtob OK (#439) * Initial work * xldtob OK * Update src/libultra/rmon/xldtob.c Co-authored-by: Anghelo Carvajal Co-authored-by: Kenix3 Co-authored-by: Anghelo Carvajal --- src/libultra/rmon/xldtob.c | 274 ++++++++++++++++++++++++++++++++++++- 1 file changed, 271 insertions(+), 3 deletions(-) diff --git a/src/libultra/rmon/xldtob.c b/src/libultra/rmon/xldtob.c index be5ad3acb..65ffc7a92 100644 --- a/src/libultra/rmon/xldtob.c +++ b/src/libultra/rmon/xldtob.c @@ -1,7 +1,275 @@ #include "global.h" -#pragma GLOBAL_ASM("asm/non_matchings/boot/xldtob/_Ldtob.s") +#define BUFF_LEN 0x20 -#pragma GLOBAL_ASM("asm/non_matchings/boot/xldtob/_Ldunscale.s") +s16 _Ldunscale(s16*, _Pft*); +void _Genld(_Pft*, u8, u8*, s16, s16); -#pragma GLOBAL_ASM("asm/non_matchings/boot/xldtob/_Genld.s") +const f64 digs[] = { 10e0L, 10e1L, 10e3L, 10e7L, 10e15L, 10e31L, 10e63L, 10e127L, 10e255L }; + +/* float properties */ +#define _D0 0 +#define _DBIAS 0x3ff +#define _DLONG 1 +#define _DOFF 4 +#define _FBIAS 0x7e +#define _FOFF 7 +#define _FRND 1 +#define _LBIAS 0x3ffe +#define _LOFF 15 +/* integer properties */ +#define _C2 1 +#define _CSIGN 1 +#define _ILONG 0 +#define _MBMAX 8 +#define NAN 2 +#define INF 1 +#define FINITE -1 +#define _DFRAC ((1 << _DOFF) - 1) +#define _DMASK (0x7fff & ~_DFRAC) +#define _DMAX ((1 << (15 - _DOFF)) - 1) +#define _DNAN (0x8000 | _DMAX << _DOFF | 1 << (_DOFF - 1)) +#define _DSIGN 0x8000 +#if _D0 == 3 +#define _D1 2 /* little-endian order */ +#define _D2 1 +#define _D3 0 +#else +#define _D1 1 /* big-endian order */ +#define _D2 2 +#define _D3 3 +#endif + +void _Ldtob(_Pft* args, u8 type) { + u8 buff[BUFF_LEN]; + u8* ptr = buff; + u32 sp70; + f64 val = args->v.ld; + /* maybe struct? */ + s16 err; + s16 nsig; + s16 exp; + s32 i; + s32 n; + f64 factor; + s32 gen; + s32 j; + s32 lo; + ldiv_t qr; + u8 drop; + s32 n2; + + if (args->prec < 0) { + args->prec = 6; + } else if (args->prec == 0 && (type == 'g' || type == 'G')) { + args->prec = 1; + } + err = _Ldunscale(&exp, (_Pft*)args); + if (err > 0) { + memcpy(args->s, err == 2 ? "NaN" : "Inf", args->n1 = 3); + return; + } + if (err == 0) { + nsig = 0; + exp = 0; + } else { + if (val < 0) { + val = -val; + } + exp = exp * 30103 / 0x000186A0 - 4; + if (exp < 0) { + n = (3 - exp) & ~3; + exp = -n; + for (i = 0; n > 0; n >>= 1, i++) { + if ((n & 1) != 0) { + val *= digs[i]; + } + } + } else if (exp > 0) { + factor = 1; + exp &= ~3; + + for (n = exp, i = 0; n > 0; n >>= 1, i++) { + if ((n & 1) != 0) { + factor *= digs[i]; + } + } + val /= factor; + } + gen = ((type == 'f') ? exp + 10 : 6) + args->prec; + if (gen > 0x13) { + gen = 0x13; + } + *ptr++ = '0'; + while (gen > 0 && 0 < val) { + lo = val; + if ((gen -= 8) > 0) { + val = (val - lo) * 1.0e8; + } + ptr = ptr + 8; + for (j = 8; lo > 0 && --j >= 0;) { + qr = ldiv(lo, 10); + *--ptr = qr.rem + '0'; + lo = qr.quot; + } + while (--j >= 0) { + ptr--; + *ptr = '0'; + } + ptr += 8; + } + + gen = ptr - &buff[1]; + for (ptr = &buff[1], exp += 7; *ptr == '0'; ptr++) { + --gen, --exp; + } + + nsig = ((type == 'f') ? exp + 1 : ((type == 'e' || type == 'E') ? 1 : 0)) + args->prec; + if (gen < nsig) { + nsig = gen; + } + if (nsig > 0) { + if (nsig < gen && ptr[nsig] > '4') { + drop = '9'; + } else { + drop = '0'; + } + + for (n2 = nsig; ptr[--n2] == drop;) { + nsig--; + } + if (drop == '9') { + ptr[n2]++; + } + if (n2 < 0) { + --ptr, ++nsig, ++exp; + } + } + } + _Genld((_Pft*)args, type, ptr, nsig, exp); +} + +s16 _Ldunscale(s16* pex, _Pft* px) { + u16* ps = (u16*)px; + s16 xchar = (ps[_D0] & _DMASK) >> _DOFF; + + if (xchar == _DMAX) { /* NaN or INF */ + *pex = 0; + return (s16)(ps[_D0] & _DFRAC || ps[_D1] || ps[_D2] || ps[_D3] ? NAN : INF); + } else if (0 < xchar) { + ps[_D0] = (ps[_D0] & ~_DMASK) | (_DBIAS << _DOFF); + *pex = xchar - (_DBIAS - 1); + return FINITE; + } + if (0 > xchar) { + return NAN; + } else { + *pex = 0; + return 0; + } +} + +void _Genld(_Pft* px, u8 code, u8* p, s16 nsig, s16 xexp) { + u8 point = '.'; + + if (nsig <= 0) { + nsig = 1, + + p = (u8*)"0"; + } + + if (code == 'f' || ((code == 'g' || code == 'G') && (-4 <= xexp) && (xexp < px->prec))) { /* 'f' format */ + ++xexp; /* change to leading digit count */ + if (code != 'f') { /* fixup for 'g' */ + if (!(px->flags & FLAGS_HASH) && nsig < px->prec) { + px->prec = nsig; + } + if ((px->prec -= xexp) < 0) { + px->prec = 0; + } + } + if (xexp <= 0) { /* digits only to right of point */ + px->s[px->n1++] = '0'; + if (0 < px->prec || px->flags & FLAGS_HASH) { + px->s[px->n1++] = point; + } + if (px->prec < -xexp) { + xexp = -px->prec; + } + px->nz1 = -xexp; + px->prec += xexp; + if (px->prec < nsig) { + nsig = px->prec; + } + memcpy(&px->s[px->n1], p, px->n2 = nsig); + px->nz2 = px->prec - nsig; + } else if (nsig < xexp) { /* zeros before point */ + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = xexp - nsig; + if (0 < px->prec || px->flags & FLAGS_HASH) { + px->s[px->n1] = point, ++px->n2; + } + px->nz2 = px->prec; + } else { /* enough digits before point */ + memcpy(&px->s[px->n1], p, xexp); + px->n1 += xexp; + nsig -= xexp; + if (0 < px->prec || px->flags & FLAGS_HASH) { + px->s[px->n1++] = point; + } + if (px->prec < nsig) { + nsig = px->prec; + } + memcpy(&px->s[px->n1], p + xexp, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + } else { /* 'e' format */ + if (code == 'g' || code == 'G') { /* fixup for 'g' */ + if (nsig < px->prec) { + px->prec = nsig; + } + if (--px->prec < 0) { + px->prec = 0; + } + code = code == 'g' ? 'e' : 'E'; + } + px->s[px->n1++] = *p++; + if (0 < px->prec || px->flags & FLAGS_HASH) { + px->s[px->n1++] = point; + } + if (0 < px->prec) { /* put fraction digits */ + if (px->prec < --nsig) { + nsig = px->prec; + } + memcpy(&px->s[px->n1], p, nsig); + px->n1 += nsig; + px->nz1 = px->prec - nsig; + } + p = (u8*)&px->s[px->n1]; /* put exponent */ + *p++ = code; + if (0 <= xexp) { + *p++ = '+'; + } else { /* negative exponent */ + *p++ = '-'; + xexp = -xexp; + } + if (100 <= xexp) { /* put oversize exponent */ + if (1000 <= xexp) { + *p++ = xexp / 1000 + '0', xexp %= 1000; + } + *p++ = xexp / 100 + '0', xexp %= 100; + } + *p++ = xexp / 10 + '0', xexp %= 10; + *p++ = xexp + '0'; + px->n2 = p - (u8*)&px->s[px->n1]; + } + if ((px->flags & (FLAGS_ZERO | FLAGS_MINUS)) == FLAGS_ZERO) { /* pad with leading zeros */ + s32 n = px->n0 + px->n1 + px->nz1 + px->n2 + px->nz2; + + if (n < px->width) { + px->nz0 = px->width - n; + } + } +} From 7134e81898d548266b8c45b389cf6a17b12a5105 Mon Sep 17 00:00:00 2001 From: EllipticEllipsis <73679967+EllipticEllipsis@users.noreply.github.com> Date: Mon, 15 Nov 2021 22:57:16 +0000 Subject: [PATCH 8/8] sys_initial_check OK, documented, error message files debinarised (#437) * OK * Symbols and other documentation * Remove externs * spec * More documentation, decompile the texture files, some uintptr_t and size_t * Top-of-file comment * Move symbols back into right order * Use some defines * Missed an osTvType and a size_t * Add missing header to os.h * Use segment symbol macros * Remove duplicate header * Address review suggestions --- assets/xml/misc/locerrmsg.xml | 5 ++ assets/xml/misc/memerrmsg.xml | 6 ++ include/color.h | 3 + include/functions.h | 16 ++--- include/os.h | 3 +- include/segment_symbols.h | 2 + include/ultra64/vi.h | 16 ++--- include/variables.h | 2 +- include/z64.h | 7 ++ spec | 6 +- src/boot_O2_g3/CIC6105.c | 1 - src/boot_O2_g3/fault.c | 2 +- src/boot_O2_g3/fault_drawer.c | 2 +- src/boot_O2_g3/idle.c | 18 +++--- src/boot_O2_g3/viconfig.c | 10 +-- src/boot_O2_g3/z_std_dma.c | 20 +++--- src/code/sys_initial_check.c | 115 ++++++++++++++++++++++++++++++--- src/libultra/io/viblack.c | 2 +- src/libultra/io/visetspecial.c | 39 ++++++----- 19 files changed, 199 insertions(+), 76 deletions(-) create mode 100644 assets/xml/misc/locerrmsg.xml create mode 100644 assets/xml/misc/memerrmsg.xml diff --git a/assets/xml/misc/locerrmsg.xml b/assets/xml/misc/locerrmsg.xml new file mode 100644 index 000000000..d6f8bfdaa --- /dev/null +++ b/assets/xml/misc/locerrmsg.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/assets/xml/misc/memerrmsg.xml b/assets/xml/misc/memerrmsg.xml new file mode 100644 index 000000000..92c15f474 --- /dev/null +++ b/assets/xml/misc/memerrmsg.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/include/color.h b/include/color.h index 06cf63972..438d857ad 100644 --- a/include/color.h +++ b/include/color.h @@ -3,6 +3,9 @@ #include "PR/ultratypes.h" +// For checking the alpha bit in an RGBA16 pixel +#define RGBA16_PIXEL_OPAQUE 1 + typedef struct { /* 0x0 */ u8 r; /* 0x1 */ u8 g; diff --git a/include/functions.h b/include/functions.h index 55945e4c8..3c8c8a2f2 100644 --- a/include/functions.h +++ b/include/functions.h @@ -15,9 +15,9 @@ s32 DmaMgr_FindDmaIndex(u32 vromAddr); const char* func_800809F4(u32 param_1); void DmaMgr_ProcessMsg(DmaRequest* req); void DmaMgr_ThreadEntry(void* arg); -s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, u32 vromStart, size_t size, UNK_TYPE4 unused, +s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, uintptr_t vromStart, size_t size, UNK_TYPE4 unused, OSMesgQueue* callback, void* callbackMesg); -s32 DmaMgr_SendRequest0(void* vramStart, u32 vromStart, size_t size); +s32 DmaMgr_SendRequest0(void* vramStart, uintptr_t vromStart, size_t size); void DmaMgr_Start(void); void DmaMgr_Stop(void); void* Yaz0_FirstDMA(void); @@ -356,8 +356,8 @@ const char* strchr(const char* __s, s32 __c); size_t strlen(const char* __s); void* memcpy(void* __dest, const void* __src, size_t __n); void osCreateMesgQueue(OSMesgQueue* mq, OSMesg* msq, s32 count); -void osInvalICache(void* vaddr, s32 nbytes); -void osInvalDCache(void* vaddr, s32 nbytes); +void osInvalICache(void* vaddr, size_t nbytes); +void osInvalDCache(void* vaddr, size_t nbytes); void __osTimerServicesInit(void); void __osTimerInterrupt(void); void __osSetTimerIntr(OSTime tim); @@ -3257,10 +3257,10 @@ s32 func_80178A94(s32 param_1, s32 param_2); // void func_80178DAC(void); // void func_80178E3C(void); // void func_80178E7C(void); -void Check_WriteRGBA16Pixel(u16* buffer, u32 x, u32 y, u16 value); -void Check_WriteI4Pixel(u16* buffer, u32 x, u32 y, u32 value); -void Check_DrawI4Texture(u16* buffer, u32 x, u32 y, u32 width, u32 height, u8* texture); -void Check_ClearRGBA16(s16* buffer); +// void Check_WriteRGBA16Pixel(u16* buffer, u32 x, u32 y, u32 value); +// void Check_WriteI4Pixel(u16* buffer, u32 x, u32 y, u32 value); +// void Check_DrawI4Texture(u16* buffer, u32 x, u32 y, u32 width, u32 height, u8* texture); +// void Check_ClearRGBA16(u16* buffer); // void Check_DrawExpansionPakErrorMessage(void); // void Check_DrawRegionLockErrorMessage(void); void Check_ExpansionPak(void); diff --git a/include/os.h b/include/os.h index 568cc1794..904d78a29 100644 --- a/include/os.h +++ b/include/os.h @@ -1,6 +1,7 @@ #ifndef _OS_H_ #define _OS_H_ +#include "libc/stdint.h" #include "libc/stdlib.h" #include "ultra64/thread.h" #include "ultra64/message.h" @@ -84,7 +85,7 @@ typedef struct { typedef struct { /* 0x00 */ OSIoMesgHdr hdr; /* 0x08 */ void* dramAddr; - /* 0x0C */ u32 devAddr; + /* 0x0C */ uintptr_t devAddr; /* 0x10 */ size_t size; /* 0x14 */ OSPiHandle* piHandle; } OSIoMesg; // size = 0x88 diff --git a/include/segment_symbols.h b/include/segment_symbols.h index a2dc30ff3..004493672 100644 --- a/include/segment_symbols.h +++ b/include/segment_symbols.h @@ -1161,7 +1161,9 @@ DECLARE_ROM_SEGMENT(scene_texture_07) DECLARE_ROM_SEGMENT(scene_texture_08) DECLARE_ROM_SEGMENT(nintendo_rogo_static) DECLARE_ROM_SEGMENT(title_static) +DECLARE_SEGMENT(memerrmsg) DECLARE_ROM_SEGMENT(memerrmsg) +DECLARE_SEGMENT(locerrmsg) DECLARE_ROM_SEGMENT(locerrmsg) DECLARE_ROM_SEGMENT(parameter_static) DECLARE_ROM_SEGMENT(week_static) diff --git a/include/ultra64/vi.h b/include/ultra64/vi.h index 471665e3e..ca9b8e45e 100644 --- a/include/ultra64/vi.h +++ b/include/ultra64/vi.h @@ -5,14 +5,14 @@ #include "ultra64/message.h" /* Special Features */ -#define OS_VI_GAMMA_ON 0x0001 -#define OS_VI_GAMMA_OFF 0x0002 -#define OS_VI_GAMMA_DITHER_ON 0x0004 -#define OS_VI_GAMMA_DITHER_OFF 0x0008 -#define OS_VI_DIVOT_ON 0x0010 -#define OS_VI_DIVOT_OFF 0x0020 -#define OS_VI_DITHER_FILTER_ON 0x0040 -#define OS_VI_DITHER_FILTER_OFF 0x0080 +#define OS_VI_GAMMA_ON (1 << 0) +#define OS_VI_GAMMA_OFF (1 << 1) +#define OS_VI_GAMMA_DITHER_ON (1 << 2) +#define OS_VI_GAMMA_DITHER_OFF (1 << 3) +#define OS_VI_DIVOT_ON (1 << 4) +#define OS_VI_DIVOT_OFF (1 << 5) +#define OS_VI_DITHER_FILTER_ON (1 << 6) +#define OS_VI_DITHER_FILTER_OFF (1 << 7) #define OS_VI_GAMMA 0x08 #define OS_VI_GAMMA_DITHER 0x04 diff --git a/include/variables.h b/include/variables.h index 033443d66..93b7790cb 100644 --- a/include/variables.h +++ b/include/variables.h @@ -12,7 +12,7 @@ extern u32 osRomBase; extern u32 osResetType; extern u32 osCicId; extern u32 osVersion; -extern u32 osMemSize; +extern size_t osMemSize; extern s32 osAppNmiBuffer[0x10]; extern u16 gFramebuffer1[SCREEN_HEIGHT][SCREEN_WIDTH]; // at 0x80000500 extern u8 D_80025D00[]; diff --git a/include/z64.h b/include/z64.h index 5118d0c35..dbc7b60f4 100644 --- a/include/z64.h +++ b/include/z64.h @@ -513,6 +513,13 @@ typedef union { F3DVertexNormal normal; } F3DVertex; // size = 0x10 +// End of RDRAM without the Expansion Pak installed +#define NORMAL_RDRAM_END 0x80400000 +// End of RDRAM with the Expansion Pak installed +#define EXPANDED_RDRAM_END 0x80800000 +// Address at the end of normal RDRAM after which is room for a screen buffer +#define FAULT_FB_ADDRESS (NORMAL_RDRAM_END - sizeof(u16[SCREEN_HEIGHT][SCREEN_WIDTH])) + typedef struct { /* 0x00 */ u16* fb; /* 0x04 */ u16 w; diff --git a/spec b/spec index 05efcb13c..c68c1cf91 100644 --- a/spec +++ b/spec @@ -8860,14 +8860,16 @@ beginseg name "memerrmsg" compress romalign 0x1000 - include "build/baserom/memerrmsg.o" + include "build/assets/misc/memerrmsg/memerrmsg.o" + number 1 endseg beginseg name "locerrmsg" compress romalign 0x1000 - include "build/baserom/locerrmsg.o" + include "build/assets/misc/locerrmsg/locerrmsg.o" + number 1 endseg beginseg diff --git a/src/boot_O2_g3/CIC6105.c b/src/boot_O2_g3/CIC6105.c index 7e9d960bf..4745ad5c8 100644 --- a/src/boot_O2_g3/CIC6105.c +++ b/src/boot_O2_g3/CIC6105.c @@ -1,6 +1,5 @@ #include "prevent_bss_reordering.h" #include "global.h" -#include "prevent_bss_reordering.h" UNK_TYPE4 D_8009BE30; UNK_TYPE4 D_8009BE34; diff --git a/src/boot_O2_g3/fault.c b/src/boot_O2_g3/fault.c index b32b5aa98..4c9a1a28c 100644 --- a/src/boot_O2_g3/fault.c +++ b/src/boot_O2_g3/fault.c @@ -714,7 +714,7 @@ void Fault_CommitFB() { osViSetYScale(1.0f); osViSetMode(&osViModeNtscLan1); osViSetSpecialFeatures(0x42); // gama_disable|dither_fliter_enable_aa_mode3_disable - osViBlack(0); + osViBlack(false); if (sFaultContext->fb) { fb = sFaultContext->fb; diff --git a/src/boot_O2_g3/fault_drawer.c b/src/boot_O2_g3/fault_drawer.c index 949faadf1..41f6c1762 100644 --- a/src/boot_O2_g3/fault_drawer.c +++ b/src/boot_O2_g3/fault_drawer.c @@ -5,7 +5,7 @@ extern const u32 sFaultDrawerFont[]; FaultDrawer* sFaultDrawContext = &sFaultDrawerStruct; FaultDrawer sFaultDrawerDefault = { - (u16*)0x803DA800, // fb - TODO map out buffers in this region and avoid hard-coded pointer + (u16*)FAULT_FB_ADDRESS, // fb SCREEN_WIDTH, // w SCREEN_HEIGHT, // h 16, // yStart diff --git a/src/boot_O2_g3/idle.c b/src/boot_O2_g3/idle.c index f2cded98c..7a1d63643 100644 --- a/src/boot_O2_g3/idle.c +++ b/src/boot_O2_g3/idle.c @@ -19,11 +19,11 @@ OSMesgQueue gPiMgrCmdQ; void Idle_ClearMemory(void* begin, void* end) { if (begin < end) { - bzero(begin, (u32)end - (u32)begin); + bzero(begin, (uintptr_t)end - (uintptr_t)begin); } } -void Idle_InitFramebuffer(u32* ptr, u32 numBytes, u32 value) { +void Idle_InitFramebuffer(u32* ptr, size_t numBytes, u32 value) { s32 temp = sizeof(u32); while (numBytes) { @@ -36,7 +36,7 @@ void Idle_InitScreen(void) { Idle_InitFramebuffer((u32*)gFramebuffer1, 0x25800, 0x00010001); ViConfig_UpdateVi(0); osViSwapBuffer(gFramebuffer1); - osViBlack(0); + osViBlack(false); } void Idle_InitMemory(void) { @@ -52,7 +52,7 @@ void Idle_InitCodeAndMemory(void) { DmaRequest dmaReq; OSMesgQueue queue; OSMesg mesg; - u32 oldSize; + size_t oldSize; osCreateMesgQueue(&queue, &mesg, 1); @@ -71,7 +71,7 @@ void Idle_InitCodeAndMemory(void) { } void Main_ThreadEntry(void* arg) { - StackCheck_Init(&sIrqMgrStackInfo, sIrqMgrStack, sIrqMgrStack + sizeof(sIrqMgrStack), 0, 256, "irqmgr"); + StackCheck_Init(&sIrqMgrStackInfo, sIrqMgrStack, sIrqMgrStack + sizeof(sIrqMgrStack), 0, 0x100, "irqmgr"); IrqMgr_Init(&gIrqMgr, &sIrqMgrStackInfo, Z_PRIORITY_IRQMGR, 1); DmaMgr_Start(); Idle_InitCodeAndMemory(); @@ -87,15 +87,15 @@ void Idle_InitVideo(void) { gViConfigYScale = 1.0; switch (osTvType) { - case 1: + case OS_TV_NTSC: D_8009B290 = 2; gViConfigMode = osViModeNtscLan1; break; - case 2: + case OS_TV_MPAL: D_8009B290 = 30; gViConfigMode = osViModeMpalLan1; break; - case 0: + case OS_TV_PAL: D_8009B290 = 44; gViConfigMode = osViModeFpalLan1; gViConfigYScale = 0.833f; @@ -108,7 +108,7 @@ void Idle_InitVideo(void) { void Idle_ThreadEntry(void* arg) { Idle_InitVideo(); osCreatePiManager(150, &gPiMgrCmdQ, sPiMgrCmdBuff, ARRAY_COUNT(sPiMgrCmdBuff)); - StackCheck_Init(&sMainStackInfo, sMainStack, sMainStack + sizeof(sMainStack), 0, 1024, "main"); + StackCheck_Init(&sMainStackInfo, sMainStack, sMainStack + sizeof(sMainStack), 0, 0x400, "main"); osCreateThread(&gMainThread, Z_THREAD_ID_MAIN, Main_ThreadEntry, arg, sMainStack + sizeof(sMainStack), Z_PRIORITY_MAIN); osStartThread(&gMainThread); diff --git a/src/boot_O2_g3/viconfig.c b/src/boot_O2_g3/viconfig.c index d32fc9b91..6539421e6 100644 --- a/src/boot_O2_g3/viconfig.c +++ b/src/boot_O2_g3/viconfig.c @@ -3,13 +3,13 @@ void ViConfig_UpdateVi(u32 mode) { if (mode != 0) { switch (osTvType) { - case 2: + case OS_TV_MPAL: osViSetMode(&osViModeMpalLan1); break; - case 0: + case OS_TV_PAL: osViSetMode(&osViModePalLan1); break; - case 1: + case OS_TV_NTSC: default: osViSetMode(&osViModeNtscLan1); break; @@ -47,8 +47,8 @@ void ViConfig_UpdateVi(u32 mode) { void ViConfig_UpdateBlack(void) { if (gViConfigUseDefault != 0) { - osViBlack(1); + osViBlack(true); } else { - osViBlack(0); + osViBlack(false); } } diff --git a/src/boot_O2_g3/z_std_dma.c b/src/boot_O2_g3/z_std_dma.c index 2903b488f..25fc8fbb0 100644 --- a/src/boot_O2_g3/z_std_dma.c +++ b/src/boot_O2_g3/z_std_dma.c @@ -9,12 +9,12 @@ OSMesg sDmaMgrMsgs[32]; OSThread sDmaMgrThread; u8 sDmaMgrStack[0x500]; -s32 DmaMgr_DMARomToRam(u32 rom, void* ram, size_t size) { +s32 DmaMgr_DMARomToRam(uintptr_t rom, void* ram, size_t size) { OSIoMesg ioMsg; OSMesgQueue queue; OSMesg msg[1]; s32 ret; - u32 buffSize = sDmaMgrDmaBuffSize; + size_t buffSize = sDmaMgrDmaBuffSize; osInvalDCache(ram, size); osCreateMesgQueue(&queue, msg, ARRAY_COUNT(msg)); @@ -23,7 +23,7 @@ s32 DmaMgr_DMARomToRam(u32 rom, void* ram, size_t size) { while (buffSize < size) { ioMsg.hdr.pri = 0; ioMsg.hdr.retQueue = &queue; - ioMsg.devAddr = (u32)rom; + ioMsg.devAddr = rom; ioMsg.dramAddr = ram; ioMsg.size = buffSize; ret = osEPiStartDma(gCartHandle, &ioMsg, 0); @@ -39,9 +39,9 @@ s32 DmaMgr_DMARomToRam(u32 rom, void* ram, size_t size) { } ioMsg.hdr.pri = 0; ioMsg.hdr.retQueue = &queue; - ioMsg.devAddr = (u32)rom; + ioMsg.devAddr = rom; ioMsg.dramAddr = ram; - ioMsg.size = (u32)size; + ioMsg.size = size; ret = osEPiStartDma(gCartHandle, &ioMsg, 0); if (ret) { goto END; @@ -109,11 +109,11 @@ const char* func_800809F4(u32 a0) { } void DmaMgr_ProcessMsg(DmaRequest* req) { - u32 vrom; + uintptr_t vrom; void* ram; size_t size; - u32 romStart; - u32 romSize; + uintptr_t romStart; + size_t romSize; DmaEntry* dmaEntry; s32 index; @@ -172,7 +172,7 @@ void DmaMgr_ThreadEntry(void* a0) { } } -s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, u32 vromStart, size_t size, UNK_TYPE4 unused, +s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, uintptr_t vromStart, size_t size, UNK_TYPE4 unused, OSMesgQueue* queue, OSMesg msg) { if (gIrqMgrResetStatus >= 2) { return -2; @@ -190,7 +190,7 @@ s32 DmaMgr_SendRequestImpl(DmaRequest* request, void* vramStart, u32 vromStart, return 0; } -s32 DmaMgr_SendRequest0(void* vramStart, u32 vromStart, size_t size) { +s32 DmaMgr_SendRequest0(void* vramStart, uintptr_t vromStart, size_t size) { DmaRequest req; OSMesgQueue queue; OSMesg msg[1]; diff --git a/src/code/sys_initial_check.c b/src/code/sys_initial_check.c index 7b0a26cc8..84871255b 100644 --- a/src/code/sys_initial_check.c +++ b/src/code/sys_initial_check.c @@ -1,17 +1,116 @@ +/** + * File: sys_initial_check.c + * Description: Functions for checking for the presence of the Expansion Pak and the correct TV type (PAL/NTSC/MPAL), + * and functions for printing error messages directly to screen if not found or incorrect. + * + * These checks are some of the first functions run in Main, before even setting up the system heap, and any image files + * are DMA'd directly to fixed RAM addresses. + */ #include "global.h" +#include "misc/locerrmsg/locerrmsg.h" +#include "misc/memerrmsg/memerrmsg.h" -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_WriteRGBA16Pixel.s") +#define SIZEOF_LOCERRMSG (sizeof(gNotDesignedForSystemErrorTex)) +#define SIZEOF_MEMERRMSG (sizeof(gExpansionPakNotInstalledErrorTex) + sizeof(gSeeInstructionBookletErrorTex)) -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_WriteI4Pixel.s") +// Address with enough room after to load either of the error message image files before the fault screen buffer at the +// end of RDRAM +#define CHECK_ERRMSG_STATIC_SEGMENT (u8*)(FAULT_FB_ADDRESS - MAX(SIZEOF_LOCERRMSG, SIZEOF_MEMERRMSG)) -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_DrawI4Texture.s") +void Check_WriteRGBA16Pixel(u16* buffer, u32 x, u32 y, u32 value) { + if (value & RGBA16_PIXEL_OPAQUE) { + (&buffer[x])[y * SCREEN_WIDTH] = value; + } +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_ClearRGBA16.s") +void Check_WriteI4Pixel(u16* buffer, u32 x, u32 y, u32 value) { + Check_WriteRGBA16Pixel(buffer, x, y, value * GPACK_RGBA5551(16, 16, 16, 0) + GPACK_RGBA5551(12, 12, 12, 1)); +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_DrawExpansionPakErrorMessage.s") +/** + * x and y are the coordinates of the bottom-left corner. + */ +void Check_DrawI4Texture(u16* buffer, s32 x, s32 y, s32 width, s32 height, u8* texture) { + s32 v; + s32 u; + u8 pixelPair; + u8* pixelPairPtr = texture; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_DrawRegionLockErrorMessage.s") + // I4 textures are bitpacked 2 pixels per byte, so this writes a pair of pixels in each iteration using bitmasking. + for (v = 0; v < height; v++) { + for (u = 0; u < width; u += 2, pixelPairPtr++) { + pixelPair = *pixelPairPtr; + Check_WriteI4Pixel(buffer, x + u, y + v, pixelPair >> 4); + pixelPair = *pixelPairPtr; + Check_WriteI4Pixel(buffer, x + u + 1, y + v, pixelPair & 0xF); + } + } +} -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_ExpansionPak.s") +void Check_ClearRGBA16(u16* buffer) { + u32 x; + u32 y; -#pragma GLOBAL_ASM("asm/non_matchings/code/sys_initial_check/Check_RegionIsSupported.s") + for (y = 0; y < SCREEN_HEIGHT; y++) { + for (x = 0; x < SCREEN_WIDTH; x++) { + Check_WriteRGBA16Pixel(buffer, x, y, 1); + } + } +} + +/** + * Draw error message textures directly to a screen buffer at the end of normal RDRAM + */ +void Check_DrawExpansionPakErrorMessage(void) { + DmaMgr_SendRequest0(CHECK_ERRMSG_STATIC_SEGMENT, SEGMENT_ROM_START(memerrmsg), SEGMENT_SIZE(memerrmsg)); + Check_ClearRGBA16((u16*)FAULT_FB_ADDRESS); + Check_DrawI4Texture((u16*)FAULT_FB_ADDRESS, 96, 71, 128, 37, CHECK_ERRMSG_STATIC_SEGMENT); + Check_DrawI4Texture((u16*)FAULT_FB_ADDRESS, 96, 127, 128, 37, + CHECK_ERRMSG_STATIC_SEGMENT + sizeof(gExpansionPakNotInstalledErrorTex)); + osWritebackDCacheAll(); + osViSwapBuffer((u16*)FAULT_FB_ADDRESS); + osViBlack(false); +} + +/** + * Draw error message texture directly to a screen buffer at the end of normal RDRAM + */ +void Check_DrawRegionLockErrorMessage(void) { + DmaMgr_SendRequest0(CHECK_ERRMSG_STATIC_SEGMENT, SEGMENT_ROM_START(locerrmsg), SEGMENT_SIZE(locerrmsg)); + Check_ClearRGBA16((u16*)FAULT_FB_ADDRESS); + Check_DrawI4Texture((u16*)FAULT_FB_ADDRESS, 56, 112, 208, 16, CHECK_ERRMSG_STATIC_SEGMENT); + osWritebackDCacheAll(); + osViSwapBuffer((u16*)FAULT_FB_ADDRESS); + osViBlack(false); +} + +/** + * If Expansion pak is not installed, display error message until console is turned off + */ +void Check_ExpansionPak(void) { + // Expansion pak installed + if (osMemSize >= 0x800000) { + return; + } + + Check_DrawExpansionPakErrorMessage(); + osDestroyThread(NULL); + while (true) {} +} + +/** + * If region is not NTSC or MPAL, display error message until console is turned off + */ +void Check_RegionIsSupported(void) { + s32 regionSupported = false; + + if ((osTvType == OS_TV_NTSC) || (osTvType == OS_TV_MPAL)) { + regionSupported = true; + } + + if (!regionSupported) { + Check_DrawRegionLockErrorMessage(); + osDestroyThread(NULL); + while (true) {} + } +} diff --git a/src/libultra/io/viblack.c b/src/libultra/io/viblack.c index abc0b3b20..6b8fec953 100644 --- a/src/libultra/io/viblack.c +++ b/src/libultra/io/viblack.c @@ -8,7 +8,7 @@ void osViBlack(u8 active) { if (active) { __osViNext->state |= 0x20; } else { - __osViNext->state &= 0xffdf; + __osViNext->state &= ~0x20; } __osRestoreInt(saveMask); diff --git a/src/libultra/io/visetspecial.c b/src/libultra/io/visetspecial.c index 6e7a6ac43..a5ef1220a 100644 --- a/src/libultra/io/visetspecial.c +++ b/src/libultra/io/visetspecial.c @@ -3,34 +3,33 @@ void osViSetSpecialFeatures(u32 func) { register u32 saveMask = __osDisableInt(); - if (func & 1) { - __osViNext->features |= 8; + if (func & OS_VI_GAMMA_ON) { + __osViNext->features |= OS_VI_GAMMA; } - if (func & 2) { - __osViNext->features &= ~8; + if (func & OS_VI_GAMMA_OFF) { + __osViNext->features &= ~OS_VI_GAMMA; } - if (func & 4) { - __osViNext->features |= 4; + if (func & OS_VI_GAMMA_DITHER_ON) { + __osViNext->features |= OS_VI_GAMMA_DITHER; } - if (func & 8) { + if (func & OS_VI_GAMMA_DITHER_OFF) { + __osViNext->features &= ~OS_VI_GAMMA_DITHER; + } + if (func & OS_VI_DIVOT_ON) { - __osViNext->features &= ~4; + __osViNext->features |= OS_VI_DIVOT; } - if (func & 0x10) { + if (func & OS_VI_DIVOT_OFF) { - __osViNext->features |= 0x10; + __osViNext->features &= ~OS_VI_DIVOT; } - if (func & 0x20) { - - __osViNext->features &= ~0x10; + if (func & OS_VI_DITHER_FILTER_ON) { + __osViNext->features |= OS_VI_DITHER_FILTER; + __osViNext->features &= ~(OS_VI_UNK100 | OS_VI_UNK200); } - if (func & 0x40) { - __osViNext->features |= 0x10000; - __osViNext->features &= ~0x300; - } - if (func & 0x80) { - __osViNext->features &= ~0x10000; - __osViNext->features |= __osViNext->modep->comRegs.ctrl & 0x300; + if (func & OS_VI_DITHER_FILTER_OFF) { + __osViNext->features &= ~OS_VI_DITHER_FILTER; + __osViNext->features |= __osViNext->modep->comRegs.ctrl & (OS_VI_UNK100 | OS_VI_UNK200); } __osViNext->state |= 8;